llvm::Module::getOrInsertGlobal returns a Constant*, not always GlobalValue* #91050
Labels
A-codegen
Area: Code generation
A-LLVM
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
C-bug
Category: This is a bug.
I-crash
Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
xref: https://bugzilla.redhat.com/show_bug.cgi?id=1990657
In Fedora, one particular crate has been seeing non-deterministic errors or crashes in the compiler, and I was able to reproduce it with a
rustup
-installed compiler as well. Valgrind gave the following error report, even on runs that otherwise appeared to succeed.Valgrind error
Note that
llvm::Module::getOrInsertGlobal
returns aConstant*
, butLLVMGetVisibility
casts its argument to aGlobalValue*
, which is a subclass. Most of the time you do get aGlobalVariable*
(a further subclass), except whengetOrInsertGlobal
is given different types it instead returns a constant bitcast expression, as you can see in the error backtrace withgetBitCast
.I ran a new rustc with LLVM assertions, and it does fail there trying to cast
GlobalValue*
:So, casting the wrong pointer type is Undefined Behavior, and the non-reproducible aspect of this bug is just "luck" of whatever happens to be in memory there.
I'm not yet sure why
rustc
would have a type mismatch in what it's feedinggetOrInsertGlobal
, but my first suspicion is thisreal_name
indirection incheck_and_apply_linkage
.rust/compiler/rustc_codegen_llvm/src/consts.rs
Lines 180 to 200 in cc946fc
The text was updated successfully, but these errors were encountered: