Repository navigation
Conversation
philberty
left a comment
There was a problem hiding this comment.
minor style nit or does cp/constexpr call it report error?
| TyTy::BaseType *expected_type, const Resolver::CanonicalPath &canonical_path, | ||
| HIR::Expr &const_value_expr, location_t locus, location_t expr_locus) | ||
| HIR::Expr &const_value_expr, location_t locus, location_t expr_locus, | ||
| bool report_failure) |
There was a problem hiding this comment.
usually we call this emit_error
There was a problem hiding this comment.
renamed to emit_error
f3eb614 to
8185cf9
Compare
| static mut S: i32 = 4; | ||
| // { dg-message "not initialized with a constant expression" "" { target *-*-* } .-1 } |
There was a problem hiding this comment.
Why would this error out? This is a perfectly valid static initializer
There was a problem hiding this comment.
the static's fine, it's X reading it that errors (rustc gives E0080 too). the note on S is the old one ported from cp, wording's off ig. fix it here or in a follow up?
There was a problem hiding this comment.
rustc gives:
error[E0080]: constant accesses mutable global memory
--> <source>:3:25
|
3 | const X: i32 = unsafe { S };
| ^ evaluation of `X` failed here
hmm i think this is confusing tbh.. because the error message is saying that S is not initilized with a constant but really the error is that S is a mutable static being read in X which is different so i dont think this is right or the locus and wording from cp constexpr is bad.
There was a problem hiding this comment.
yeah the cp note was off, it's gone. a const reading a static now gets E0013 from the const checker, like rustc 1.49 (your E0080 is newer rustc). also found static B: i32 = A; silently gave 0, fixed that too
825edbe to
7c805ec
Compare
If evaluating a constant failed and nothing reported an error, the constant was used anyway and ended up uninitialized. Report E0080 in that case. Reading a static was the usual way to get there. A constant reading one now gets E0013 from the const checker like rustc 1.49, and a static can read another static's initializer, which rustc allows. The note saying the static wasn't initialized with a constant is gone for statics, it pointed at the wrong thing. Fixes Rust-GCC#5012 Assisted-by: Claude Opus 5.5 (Anthropic) gcc/rust/ChangeLog: * backend/rust-constexpr.h (fold_expr): Add an optional non_constant_p out parameter. * backend/rust-constexpr.cc (fold_expr): Set it. (constant_value_1): Return the initializer of a static. (non_const_var_error): Don't add notes for statics. * backend/rust-compile-base.h (HIRCompileBase::compile_constant_item): Add an emit_error parameter. * backend/rust-compile-base.cc (HIRCompileBase::compile_constant_expr): Don't report failures. (HIRCompileBase::compile_constant_item): Return error_mark_node when evaluation fails, and report E0080 if nothing else did. * checks/errors/rust-const-checker.cc (ConstChecker::visit (PathInExpression &)): Report E0013 when a constant refers to a static. gcc/testsuite/ChangeLog: * rust/compile/const-static-mut.rs: New test. * rust/compile/static-extern-read.rs: New test. * rust/execute/torture/static-read-static.rs: New test. Signed-off-by: Utkarsh Bahuguna <utkarshbahuguna10@gmail.com>
7c805ec to
28a2ae7
Compare
If a constant couldn't be evaluated and nothing reported an error, gccrs used it anyway and the program read garbage. This reports E0080 in that case.
Reading a static was the usual way to get there. A constant reading one now gets E0013 from the const checker like rustc 1.49, and a static can read another static's initializer, which rustc allows (
static B: i32 = A;used to leave B as 0). The note about the static not being initialized with a constant is gone for statics, it pointed at the wrong thing.A plain fn nested in a const block is still checked as if it were const. That's an existing const checker thing, it gives the same false E0015 on master, filed as #5130.
Fixes #5012