Skip to content

Conversation

@Polygonalr
Copy link
Contributor

@Polygonalr Polygonalr commented Oct 20, 2025

Fixes #4242
Fixes #3659

The ICE for #3659 was initially fixed by #4049, but the test case did not throw E0579 as expected. Moreover, the output GIMPLE was found to be wrong (which led to the creation of #4242). This PR aims to fix both issues by correcting parser behavior for RangePattern-s and adding E0579 error checking.

@Polygonalr Polygonalr changed the title Issue 3659 gccrs: Fix negative bounds in RangePattern being handled incorrectly Oct 20, 2025
@Polygonalr Polygonalr force-pushed the issue-3659 branch 2 times, most recently from 0d81649 to c434d0c Compare October 20, 2025 07:14
Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think LGTM but not sure how it works now with the has_minus removed

@Polygonalr Polygonalr marked this pull request as draft October 21, 2025 08:48
…sitive

GIMPLE output for compile/issue-4242.rs:

...

  x = 1;
  RUSTTMP.2 = x;
  _1 = RUSTTMP.2 >= -55;
  _2 = RUSTTMP.2 < 0;
  _3 = _1 & _2;
  if (_3 != 0) goto <D.112>; else goto <D.113>;
  <D.112>:
  {
    RUSTTMP.1 = 2;
    goto <D.105>;
  }
  <D.113>:
  _4 = RUSTTMP.2 >= -99;
  _5 = RUSTTMP.2 < -55;
  _6 = _4 & _5;
  if (_6 != 0) goto <D.114>; else goto <D.115>;
  <D.114>:
  {
    RUSTTMP.1 = 3;
    goto <D.105>;
  }
...

gcc/rust/ChangeLog:

	* backend/rust-compile-pattern.cc (compile_range_pattern_bound): Set litexpr
	to negative if has_minus is present in the RangePatternBoundLiteral param.

Signed-off-by: Yap Zhi Heng <[email protected]>
Checks whether upper bound of range is not lower or equal to the lower bound.

gcc/rust/ChangeLog:

	* backend/rust-compile-pattern.cc(compilePatternCheckExpr::visit(RangePattern)):
	Add E0579 check to ensure that lower bound is always below upper bound.

Signed-off-by: Yap Zhi Heng <[email protected]>

rust_assert (
(TREE_CODE (upper) == REAL_CST && TREE_CODE (lower) == REAL_CST)
|| (TREE_CODE (upper) == INTEGER_CST && TREE_CODE (lower) == INTEGER_CST));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does 1f32..1.2f32 break anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Triggers an error that shouldn't be triggered lol, maybe we can create a new issue for it.

error: mismatched types, expected ‘f32’ but got ‘<integer>’ [E0308]
    7 |         1f32..1.2f32 => 1,
      |         ^~~~

Anyways, 1.0f32..1.2f32 compiles properly and does not trigger E0579 but -1.2f32..-1.0f32 triggers E0579... not sure what went wrong here :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Negative value bounds does not generate correctly for RangePattern ICE: in visit, at rust/hir/rust-ast-lower-pattern.cc:258 exlusive range pattern

3 participants