Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPIR-V] Verifier fails with invalid uses of intrinsic global variable #110495

Open
bwlodarcz opened this issue Sep 30, 2024 · 1 comment
Open

Comments

@bwlodarcz
Copy link
Contributor

Reproducer

example.cpp

int *ptr_0 = nullptr;
void *ptr_1 = ptr_0;
  1. clang -S -emit-llvm -cl-std=clc++ --target=spir example.cpp
  2. llc --verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown example.ll -o - 2>&1

Stack Trace

invalid uses of intrinsic global variable
ptr @llvm.global_ctors
LLVM ERROR: Broken module found, compilation aborted!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: llc --verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown global_crash.ll -o -
 #0 0x000055e5a16c0e72 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) <truncated>llvm-project/llvm/lib/Support/Unix/Signals.inc:723:22
 #1 0x000055e5a16c1289 PrintStackTraceSignalHandler(void*) <truncated>llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x000055e5a16be659 llvm::sys::RunSignalHandlers() <truncated>llvm-project/llvm/lib/Support/Signals.cpp:105:20
 #3 0x000055e5a16c071d SignalHandler(int) <truncated>llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x00007f2bc2845320 (/lib/x86_64-linux-gnu/libc.so.6+0x45320)
 #5 0x00007f2bc289eb1c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x00007f2bc289eb1c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #7 0x00007f2bc289eb1c pthread_kill ./nptl/pthread_kill.c:89:10
 #8 0x00007f2bc284526e raise ./signal/../sysdeps/posix/raise.c:27:6
 #9 0x00007f2bc28288ff abort ./stdlib/abort.c:81:7
#10 0x000055e5a15eb3c0 llvm::report_fatal_error(llvm::Twine const&, bool) <truncated>llvm-project/llvm/lib/Support/ErrorHandling.cpp:126:9
#11 0x000055e5a15eb194 llvm::report_fatal_error(llvm::StringRef, bool) <truncated>llvm-project/llvm/lib/Support/ErrorHandling.cpp:87:68
#12 0x000055e5a096b006 (anonymous namespace)::VerifierLegacyPass::doFinalization(llvm::Module&) <truncated>llvm-project/llvm/lib/IR/Verifier.cpp:7213:12
#13 0x000055e5a0857edb llvm::FPPassManager::doFinalization(llvm::Module&) <truncated>llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1472:13
#14 0x000055e5a08584bb (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) <truncated>llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1559:13
#15 0x000055e5a08530e3 llvm::legacy::PassManagerImpl::run(llvm::Module&) <truncated>llvm-project/llvm/lib/IR/LegacyPassManager.cpp:541:13
#16 0x000055e5a0858b15 llvm::legacy::PassManager::run(llvm::Module&) <truncated>llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1651:1
#17 0x000055e59edf4eea compileModule(char**, llvm::LLVMContext&) <truncated>llvm-project/llvm/tools/llc/llc.cpp:755:34
#18 0x000055e59edf2605 main <truncated>llvm-project/llvm/tools/llc/llc.cpp:412:35
#19 0x00007f2bc282a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#20 0x00007f2bc282a28b call_init ./csu/../csu/libc-start.c:128:20
#21 0x00007f2bc282a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#22 0x000055e59edf1065 _start (./llvm-project/build-debug/bin/llc+0x801065)
Aborted (core dumped)

Additional info

I localized the source of the fail in Verifier::visitGlobalVariable function during:

    840   if (GV.hasName() && (GV.getName() == "llvm.global_ctors" ||
    841                        GV.getName() == "llvm.global_dtors")) {
    842     Check(!GV.hasInitializer() || GV.hasAppendingLinkage(),
    843           "invalid linkage for intrinsic global variable", &GV);
    844     Check(GV.materialized_use_empty(),
    845           "invalid uses of intrinsic global variable", &GV);

It sets Broken variable to true in Check(GV.materialized_use_empty() which checks if UseList == nullptr if not it fails.
I checked the same example with X86 backend and it works without fail.

@michalpaszkowski
Copy link
Member

@bwlodarcz Could you please attach the input LLVM IR file (Clang output)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants