Skip to content

Commit dcd4d2f

Browse files
committed
gccrs: Fix RangePattern negative literal bounds being treated as positive
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]>
1 parent 0cad640 commit dcd4d2f

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

gcc/rust/backend/rust-compile-pattern.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ compile_range_pattern_bound (HIR::RangePatternBound &bound,
119119

120120
HIR::LiteralExpr litexpr (mappings, ref.get_literal (), locus,
121121
std::vector<AST::Attribute> ());
122+
if (ref.get_has_minus())
123+
litexpr.set_negative();
122124

123125
result = CompileExpr::Compile (litexpr, ctx);
124126
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(exclusive_range_pattern)]
2+
3+
fn main() {
4+
let x = 1;
5+
6+
match x {
7+
-55..0 => 2,
8+
-99..-55 => 3,
9+
};
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(exclusive_range_pattern)]
2+
3+
fn main() -> i32 {
4+
let x = -77;
5+
6+
match x {
7+
-55..99 => 1,
8+
-99..-55 => 0, // the correct case
9+
_ => 1,
10+
}
11+
}

0 commit comments

Comments
 (0)