Closed dabrahams closed 8 months ago
AFAIK there's no documented precondition on any of the LLVM methods called by this expression. It might be the same possible cause as #28, that is the module owning g
got deinitialized by Swift before g.initializer
was executed.
That the module is live is surely a precondition, then, n'est-ce-pas?
Stack trace:
Thread 1 Queue : com.apple.main-thread (serial)
#0 0x000000018470e0dc in __pthread_kill ()
#1 0x0000000184745cc0 in pthread_kill ()
#2 0x0000000184651a40 in abort ()
#3 0x0000000184650d30 in __assert_rtn ()
#4 0x000000011448a348 in llvm::isa_impl_cl<llvm::Constant, llvm::Value const*>::doit(llvm::Value const*) at /Users/runner/work/llvm-build/llvm-build/SourceCache/llvm-project/llvm/include/llvm/Support/Casting.h:109
#5 0x000000011448a2dc in llvm::isa_impl_wrap<llvm::Constant, llvm::Value const*, llvm::Value const*>::doit(llvm::Value const* const&) at /Users/runner/work/llvm-build/llvm-build/SourceCache/llvm-project/llvm/include/llvm/Support/Casting.h:137
#6 0x000000011448a2b0 in llvm::isa_impl_wrap<llvm::Constant, llvm::Value const* const, llvm::Value const*>::doit(llvm::Value const* const&) at /Users/runner/work/llvm-build/llvm-build/SourceCache/llvm-project/llvm/include/llvm/Support/Casting.h:127
#7 0x000000011448a278 in llvm::CastIsPossible<llvm::Constant, llvm::Value const*, void>::isPossible(llvm::Value const* const&) at /Users/runner/work/llvm-build/llvm-build/SourceCache/llvm-project/llvm/include/llvm/Support/Casting.h:255
#8 0x000000011448a250 in llvm::CastInfo<llvm::Constant, llvm::Value* const, void>::isPossible(llvm::Value* const&) at /Users/runner/work/llvm-build/llvm-build/SourceCache/llvm-project/llvm/include/llvm/Support/Casting.h:509
#9 0x000000011448a1f0 in bool llvm::isa<llvm::Constant, llvm::Value*>(llvm::Value* const&) at /Users/runner/work/llvm-build/llvm-build/SourceCache/llvm-project/llvm/include/llvm/Support/Casting.h:549
#10 0x000000011448a178 in decltype(auto) llvm::cast<llvm::Constant, llvm::Value>(llvm::Value*) at /Users/runner/work/llvm-build/llvm-build/SourceCache/llvm-project/llvm/include/llvm/Support/Casting.h:578
#11 0x0000000118919f9c in llvm::Constant* llvm::unwrap<llvm::Constant>(LLVMOpaqueValue*) at /Users/runner/work/llvm-build/llvm-build/SourceCache/llvm-project/llvm/include/llvm/IR/Value.h:1039
#12 0x000000011891cc30 in ::LLVMSetInitializer(LLVMValueRef, LLVMValueRef) at /Users/runner/work/llvm-build/llvm-build/SourceCache/llvm-project/llvm/lib/IR/Core.cpp:2158
#13 0x00000001142721fc in Module.setInitializer(_:for:) at /Users/dave/src/Swifty-LLVM/Sources/SwiftyLLVM/Module.swift:355
#14 0x000000011426286c in GlobalVariableTests.testInitializer() at /Users/dave/src/Swifty-LLVM/Tests/LLVMTests/Values/GlobalVariableTests.swift:37
#15 0x0000000114262d24 in @objc GlobalVariableTests.testInitializer() ()
The stack trace is incredibly valuable, thanks! Sadly my hopes are down again because this one doesn't involve any surprising code.
Looking at the sources, it seems like the unwrapping of the constant value passed to the initializer (which should be a null pointer) causes the assertion. It is frustrating because llvm::GlobalVariable::setInitializer
clearly documents that it is acceptable usage, but the corresponding C bindings has no documentation at all. AFAICT, the behavior of unwrap
is also undocumented (it is an internal utility of the C bindings) so I'm not sure that it supports converting null pointers.
Yep. It looks like there are LLVM bug reports to file.
https://github.com/hylo-lang/Swifty-LLVM/blob/291474a13e3304e5ac072b1149b6032600744027/Tests/LLVMTests/Values/GlobalVariableTests.swift#L38
Causes an LLVM built with assertions on to assert: