Skip to content

Conversation

@Polygonalr
Copy link
Contributor

Similar to #4243, but for literal patterns. Issue was initially discovered here. Fixes literal pattern matching being compiled without respecting the minus sign.

GIMPLE output for literalpattern_neg.rs test case:

...
  x = -55;
  RUSTTMP.2 = x;
  if (RUSTTMP.2 == 55) goto <D.113>; else goto <D.114>;
  <D.113>:
  {
    RUSTTMP.1 = 1;
    goto <D.107>;
  }
  <D.114>:
  if (RUSTTMP.2 == -55) goto <D.115>; else goto <D.116>;
  <D.115>:
  {
    RUSTTMP.1 = 0;
    goto <D.107>;
  }
  <D.116>:
  if (1 != 0) goto <D.117>; else goto <D.118>;
  <D.117>:
  {
    RUSTTMP.1 = 1;
    goto <D.107>;
  }
...

gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (parse_literal_or_range_pattern): Parse minus sign
	properly for LiteralPattern.
	* ast/rust-pattern.h (LiteralPattern): Add has_minus boolean for LiteralPattern.
	* hir/tree/rust-hir-pattern.h (LiteralPattern): Ditto.
	* ast/rust-pattern.cc (LiteralPattern::as_string): Update to include minus sign
	if present.
	* hir/tree/rust-hir.cc (LiteralPattern::as_string): Ditto.
	* hir/rust-ast-lower-pattern.cc (visit(LiteralPattern)): Pass has_minus boolean
	from AST to HIR.
	* backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit(LiteralPattern)):
	Compile litexpr as negative if minus sign is present.

Signed-off-by: Yap Zhi Heng <[email protected]>
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.

2 participants