| Issue |
176154
|
| Summary |
__funcref crashes codegen in C++ mode
|
| Labels |
c++,
clang:codegen,
confirmed,
crash-on-valid
|
| Assignees |
|
| Reporter |
AaronBallman
|
> A quick look again after a while
>
> > Ohhhh, I take it back about this being a good first issue (sorry [@moonheart08](https://github.com/moonheart08)!), it might not be. This thing seems to have even more problems: https://godbolt.org/z/3hn7x75Mf (using it at all in C++ crashes always, only seems to work in C and only if you hold it just right). I think we need to find an active wasm maintainer to step in for this, but I'm not certain who to reach out to. CC [@nikic](https://github.com/nikic) who may know someone
>
> If `function` variable is not defined, the type defaults to int and then it crashes. From a look at this, it seems we need a check to ensure that the type of the funcref variable is a function pointer.
>
> Thanks! The fix you posted is pretty close to good, but there is a second (separate) issue that remains. If you enable codegen in C++ mode, any use of `__funcref` crashes even after your patch:
> ```
> clang++: warning: argument unused during compilation: '--gcc-toolchain=/opt/compiler-explorer/gcc-snapshot' [-Wunused-command-line-argument]
> Not a language specific address space
> UNREACHABLE executed at /root/llvm-project/llvm/tools/clang/lib/AST/ItaniumMangle.cpp:2748!
> PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
> Stack dump:
> 0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -target wasm32 <source>
> 1. <eof> parser at end of file
> 2. <source>:1:18: LLVM IR generation of declaration 'ptr'
> 3. <source>:1:18: Generating code for declaration 'ptr'
> #0 0x00000000042fea18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42fea18)
> #1 0x00000000042fbe54 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42fbe54)
> #2 0x000000000423e748 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
> #3 0x0000753577e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
> #4 0x0000753577e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
> #5 0x0000753577e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
> #6 0x0000753577e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
> #7 0x00000000042491da (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42491da)
> #8 0x00000000080226e7 (anonymous namespace)::CXXNameMangler::mangleQualifiers(clang::Qualifiers, clang::DependentAddressSpaceType const*) ItaniumMangle.cpp:0:0
> #9 0x00000000080154d5 (anonymous namespace)::CXXNameMangler::mangleType(clang::QualType) ItaniumMangle.cpp:0:0
> #10 0x00000000080156b5 (anonymous namespace)::CXXNameMangler::mangleType(clang::QualType) ItaniumMangle.cpp:0:0
> #11 0x00000000080135a0 (anonymous namespace)::CXXNameMangler::mangleName(clang::GlobalDecl) ItaniumMangle.cpp:0:0
> #12 0x000000000802569f (anonymous namespace)::CXXNameMangler::mangle(clang::GlobalDecl) ItaniumMangle.cpp:0:0
> #13 0x0000000008027266 (anonymous namespace)::CXXNameMangler::shouldHaveAbiTags((anonymous namespace)::ItaniumMangleContextImpl&, clang::VarDecl const*) ItaniumMangle.cpp:0:0
> #14 0x00000000080276ab (anonymous namespace)::ItaniumMangleContextImpl::shouldMangleCXXName(clang::NamedDecl const*) ItaniumMangle.cpp:0:0
> #15 0x00000000048a4fb4 getMangledNameImpl(clang::CodeGen::CodeGenModule&, clang::GlobalDecl, clang::NamedDecl const*, bool) CodeGenModule.cpp:0:0
> #16 0x00000000048bc7cd clang::CodeGen::CodeGenModule::getMangledName(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48bc7cd)
> #17 0x00000000048d0205 clang::CodeGen::CodeGenModule::GetAddrOfGlobalVar(clang::VarDecl const*, llvm::Type*, clang::CodeGen::ForDefinition_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48d0205)
> #18 0x00000000048cbaee clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48cbaee)
> #19 0x00000000048f4721 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48f4721)
> #20 0x00000000048f4f63 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48f4f63)
> #21 0x000000000490037b clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
> #22 0x0000000004c686e9 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
> #23 0x0000000004c59ad4 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c59ad4)
> #24 0x0000000006a3a774 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a3a774)
> #25 0x0000000004c66488 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c66488)
> #26 0x0000000004f60135 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f60135)
> #27 0x0000000004edff0e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4edff0e)
> #28 0x000000000505a7cd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x505a7cd)
> #29 0x0000000000dce92e cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdce92e)
> #30 0x0000000000dc52fa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
> #31 0x0000000000dc547d int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
> #32 0x0000000004cd96e9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
> #33 0x000000000423ebe4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x423ebe4)
> #34 0x0000000004cd9cff clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
> #35 0x0000000004c9a692 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c9a692)
> #36 0x0000000004c9b63e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c9b63e)
> #37 0x0000000004ca2a95 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ca2a95)
> #38 0x0000000000dcaca1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdcaca1)
> #39 0x0000000000c88434 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc88434)
> #40 0x0000753577e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
> #41 0x0000753577e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
> #42 0x0000000000dc4d95 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdc4d95)
> clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
> Compiler returned: 134
> ```
> https://godbolt.org/z/3hn7x75Mf
>
> I'll file this as a separate issue so we can track it more easily.
_Originally posted by @AaronBallman in [#118233](https://github.com/llvm/llvm-project/issues/118233#issuecomment-3754690376)_
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs