Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid ICE when global_asm const operand fails to evaluate #1467

Merged
merged 1 commit into from
Mar 21, 2024

Conversation

BeetleFunk
Copy link
Contributor

Fixes #1466

Follows the same approach used in rust-lang/rust#122691. The error is reported when calling const_eval_poly(). codegen_global_asm_item() doesn't have a way to propagate the error but can detect the ErrorHandled::Reported case and avoid the panic.

@BeetleFunk
Copy link
Contributor Author

With these changes, compiling the test case file:

//@ build-fail
//@ needs-asm-support
#![feature(asm_const)]

use std::arch::global_asm;

fn main() {}

global_asm!("/* {} */", const 1 << 500); //~ ERROR evaluation of constant value failed [E0080]

global_asm!("/* {} */", const 1 / 0); //~ ERROR evaluation of constant value failed [E0080]

Results in STDERR output:

error[E0080]: evaluation of constant value failed
 --> src/main.rs:9:31
  |
9 | global_asm!("/* {} */", const 1 << 500); //~ ERROR evaluation of constant value failed [E0080]
  |                               ^^^^^^^^ attempt to shift left by `500_i32`, which would overflow

error[E0080]: evaluation of constant value failed
  --> src/main.rs:11:31
   |
11 | global_asm!("/* {} */", const 1 / 0); //~ ERROR evaluation of constant value failed [E0080]
   |                               ^^^^^ attempt to divide `1_i32` by zero

For more information about this error, try `rustc --explain E0080`.
error: could not compile `sandbox` (bin "sandbox") due to 2 previous errors

@BeetleFunk
Copy link
Contributor Author

BeetleFunk commented Mar 21, 2024

What's standard practice on automated tests for compiler errors like this?

I noticed that the test runner in scripts/test_rustc_tests.sh seems to be filtering out most of the rustc test files containing "build-fail" or "ERR" patterns.

EDIT: I see this is being tracked in issue #381. Makes sense!

@bjorn3 bjorn3 merged commit 9ddba16 into rust-lang:master Mar 21, 2024
17 of 18 checks passed
@bjorn3
Copy link
Member

bjorn3 commented Mar 21, 2024

Thanks!

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.

Avoid ICE when global_asm const operand fails to evaluate
2 participants