Closed BeetleFunk closed 6 months ago
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
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!
Thanks!
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 theErrorHandled::Reported
case and avoid the panic.