Description
pub fn maybe_ptr() -> *const u8 {
static NONE: Option<((), &'static u8)> = None;
unsafe {
*(&NONE as *const _ as *const *const u8)
}
}
Running this in the playpen gives:
rustc: /build/rust-git/src/rust/src/llvm/include/llvm/IR/DerivedTypes.h:285: llvm::Type* llvm::StructType::getElementType(unsigned int) const: Assertion `N < NumContainedTys && "Element number out of range!"' failed.
Aborted (core dumped)
This is actually happening inside LLVM optimizations, in the early-cse
pass (-C opt-level=1
still triggers it). Originally found in a memcpy
optimized into a load
.
Reduced LLVM IR:
target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
@NONE = internal constant { { {}, i8* } } zeroinitializer
define i8* @maybe_ptr() {
entry-block:
%0 = load i8** bitcast ({ { {}, i8* } }* @NONE to i8**)
ret i8* %0
}
cc @dotdash