Skip to content

gccrs: Fix compile_float_literal not compiling negatives properly#4287

Merged
philberty merged 1 commit into
Rust-GCC:masterfrom
Polygonalr:compile-float-literal-neg-fix
Nov 17, 2025
Merged

gccrs: Fix compile_float_literal not compiling negatives properly#4287
philberty merged 1 commit into
Rust-GCC:masterfrom
Polygonalr:compile-float-literal-neg-fix

Conversation

@Polygonalr

@Polygonalr Polygonalr commented Nov 15, 2025

Copy link
Copy Markdown
Contributor

Follow up from my comment in an earlier PR: #4243 (comment)

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 :/

This is a very, very subtle bug that took me quite a while to debug, I'm very surprised none of our tests were able to catch compile_float_literal compiling negatives wrongly.

Edit for more context:

Previously, using -1.2f32..-1.0f32 as a pattern match arm throws E0579 "lower range bound must be less than upper", which is incorrect because -1.2 < -1.0. Meanwhile, -1.0f32..-1.2f32 does not throw that error, which is also incorrect. This is due to compile_float_literal not taking is_negative() into account during code gen, so this PR aims to fix that.

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 <yapzhhg@gmail.com>

@philberty philberty left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@philberty philberty added this pull request to the merge queue Nov 17, 2025
Merged via the queue into Rust-GCC:master with commit c01290e Nov 17, 2025
12 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in libcore 1.49 Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants