Skip to content

Commit 9459866

Browse files
Polygonalrdkm
authored andcommitted
gccrs: Fix compile_float_literal not compiling negatives properly
gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (compile_float_literal): Add is_negative check to compile negative float literals properly. * backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit(RangePattern)): Minor optimization to E0579 checks to reduce memory copy. Signed-off-by: Yap Zhi Heng <[email protected]>
1 parent ce52535 commit 9459866

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,8 @@ CompileExpr::compile_float_literal (const HIR::LiteralExpr &expr,
17121712
rust_error_at (expr.get_locus (), "bad number in literal");
17131713
return error_mark_node;
17141714
}
1715+
if (expr.is_negative ())
1716+
mpfr_neg (fval, fval, MPFR_RNDN);
17151717

17161718
// taken from:
17171719
// see go/gofrontend/expressions.cc:check_float_type

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ CompilePatternCheckExpr::visit (HIR::RangePattern &pattern)
170170
bool error_E0579 = false;
171171
if (TREE_CODE (upper) == REAL_CST)
172172
{
173-
REAL_VALUE_TYPE upper_r = TREE_REAL_CST (upper);
174-
REAL_VALUE_TYPE lower_r = TREE_REAL_CST (lower);
175-
if (real_compare (GE_EXPR, &lower_r, &upper_r))
173+
const REAL_VALUE_TYPE *upper_r = TREE_REAL_CST_PTR (upper);
174+
const REAL_VALUE_TYPE *lower_r = TREE_REAL_CST_PTR (lower);
175+
if (real_compare (GE_EXPR, lower_r, upper_r))
176176
error_E0579 = true;
177177
}
178178
else if (TREE_CODE (upper) == INTEGER_CST)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(exclusive_range_pattern)]
2+
3+
fn main() {
4+
let x = 1.0;
5+
6+
match x { // { dg-message "sorry, unimplemented: match on floating-point types is not yet supported" }
7+
-1.0f32..-1.2f32 => 2, // { dg-error "lower range bound must be less than upper .E0579." }
8+
};
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(exclusive_range_pattern)]
2+
3+
fn main() {
4+
let x = 1.0;
5+
6+
match x { // { dg-message "sorry, unimplemented: match on floating-point types is not yet supported" }
7+
-1.2f32..-1.0f32 => 2,
8+
};
9+
}

0 commit comments

Comments
 (0)