llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.81k stars 11.91k forks source link

ICE in mangleUnresolvedTypeOrSimpleId #40213

Open apolukhin opened 5 years ago

apolukhin commented 5 years ago
Bugzilla Link 40867
Version trunk
OS Linux
CC @apolukhin,@DougGregor,@zygoloid

Extended Description

The following code cause ICE:

template int is_vector(T const&, decltype(static_cast<T>(0)->~vector()) = 0) { return 1; }

template int is_vector(T const&, decltype(static_cast<T>(0)->~deque()) = 0) { return 0; }

template class vector{};

int test() { return is_vector(vector()); }

wheatman commented 1 year ago

This code still crashes on post 16 trunk(9094b3b4ae81e4778ab0b43a65890d8a5ce8d94e) https://godbolt.org/z/aas6T8vGK

It hits the following assert clang++: /root/llvm-project/clang/include/clang/AST/Type.h:752: const clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const: Assertion `!isNull() && "Cannot retrieve a NULL type pointer"' failed.

code

template <class T>
int is_vector(T const&, decltype(static_cast<T*>(0)->~vector())* = 0) {
    return 1;
}

template <class T>
int is_vector(T const&, decltype(static_cast<T*>(0)->~deque())* = 0) {
    return 0;
}

template <class T> class vector{};

int test() {
    return is_vector(vector<int>());
}

dump

clang++: /root/llvm-project/clang/include/clang/AST/Type.h:752: const clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const: Assertion `!isNull() && "Cannot retrieve a NULL type pointer"' failed.
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++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++11 <source>
1.  <eof> parser at end of file
2.  <source>:13:5: LLVM IR generation of declaration 'test'
3.  <source>:13:5: Generating code for declaration 'test'
4.  <source>:2:5: Mangling declaration 'is_vector'
 #0 0x00000000036df178 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x36df178)
 #1 0x00000000036dce3c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x36dce3c)
 #2 0x00000000036261f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007fa33b3ae420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007fa33ae7100b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007fa33ae50859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007fa33ae50729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007fa33ae61fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x00000000070cd39f (anonymous namespace)::CXXNameMangler::mangleUnresolvedTypeOrSimpleId(clang::QualType, llvm::StringRef) ItaniumMangle.cpp:0:0
 #9 0x00000000070c1232 (anonymous namespace)::CXXNameMangler::mangleExpression(clang::Expr const*, unsigned int, bool) ItaniumMangle.cpp:0:0
#10 0x00000000070c2a79 (anonymous namespace)::CXXNameMangler::mangleExpression(clang::Expr const*, unsigned int, bool) ItaniumMangle.cpp:0:0
#11 0x00000000070b338e (anonymous namespace)::CXXNameMangler::mangleType(clang::QualType) ItaniumMangle.cpp:0:0
#12 0x00000000070b2d8b (anonymous namespace)::CXXNameMangler::mangleType(clang::QualType) ItaniumMangle.cpp:0:0
#13 0x00000000070bdb52 (anonymous namespace)::CXXNameMangler::mangleBareFunctionType(clang::FunctionProtoType const*, bool, clang::FunctionDecl const*) ItaniumMangle.cpp:0:0
#14 0x00000000070c6011 (anonymous namespace)::CXXNameMangler::mangleFunctionEncoding(clang::GlobalDecl) ItaniumMangle.cpp:0:0
#15 0x00000000070c9ed1 (anonymous namespace)::ItaniumMangleContextImpl::mangleCXXName(clang::GlobalDecl, llvm::raw_ostream&) ItaniumMangle.cpp:0:0
#16 0x00000000070ebc23 clang::MangleContext::mangleName(clang::GlobalDecl, llvm::raw_ostream&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x70ebc23)
#17 0x0000000003aa1103 getMangledNameImpl(clang::CodeGen::CodeGenModule&, clang::GlobalDecl, clang::NamedDecl const*, bool) CodeGenModule.cpp:0:0
#18 0x0000000003aa40ed clang::CodeGen::CodeGenModule::getMangledName(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3aa40ed)
#19 0x0000000003ad2a23 clang::CodeGen::CodeGenModule::GetAddrOfFunction(clang::GlobalDecl, llvm::Type*, bool, bool, clang::CodeGen::ForDefinition_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ad2a23)
#20 0x0000000003dc858c EmitFunctionDeclPointer(clang::CodeGen::CodeGenModule&, clang::GlobalDecl) CGExpr.cpp:0:0
#21 0x0000000003dd659a EmitDirectCallee(clang::CodeGen::CodeGenFunction&, clang::GlobalDecl) CGExpr.cpp:0:0
#22 0x0000000003df23b6 clang::CodeGen::CodeGenFunction::EmitCallee(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3df23b6)
#23 0x0000000003df2357 clang::CodeGen::CodeGenFunction::EmitCallee(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3df2357)
#24 0x0000000003df2a92 clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3df2a92)
#25 0x0000000003e3a3e9 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) CGExprScalar.cpp:0:0
#26 0x0000000003e31319 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#27 0x0000000003e394ac clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e394ac)
#28 0x00000000039f3814 clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x39f3814)
#29 0x00000000039faccb clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x39faccb)
#30 0x0000000003a00fec clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a00fec)
#31 0x0000000003a5ea06 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a5ea06)
#32 0x0000000003a71b9a clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a71b9a)
#33 0x0000000003ad2ef3 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ad2ef3)
#34 0x0000000003acdfe5 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3acdfe5)
#35 0x0000000003ace5ab clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ace5ab)
#36 0x0000000003ad7a23 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#37 0x00000000049437b6 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#38 0x00000000049343c8 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49343c8)
#39 0x0000000005e39364 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e39364)
#40 0x0000000004940668 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4940668)
#41 0x00000000041a7f39 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41a7f39)
#42 0x0000000004128d3e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4128d3e)
#43 0x000000000428727e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x428727e)
#44 0x0000000000bdaf7e cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbdaf7e)
#45 0x0000000000bd2b0a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#46 0x0000000003f89619 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
#47 0x00000000036266a4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x36266a4)
#48 0x0000000003f89c0f 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
#49 0x0000000003f51f55 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f51f55)
#50 0x0000000003f529bd 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+++0x3f529bd)
#51 0x0000000003f5a8e5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f5a8e5)
#52 0x0000000000bd86ec clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbd86ec)
#53 0x0000000000ad3c51 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xad3c51)
#54 0x00007fa33ae52083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#55 0x0000000000bd25ee _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbd25ee)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-codegen

| | | | --- | --- | | Bugzilla Link | [40867](https://llvm.org/bz40867) | | Version | trunk | | OS | Linux | | CC | @apolukhin,@DougGregor,@zygoloid | ## Extended Description The following code cause ICE: template <class T> int is_vector(T const&, decltype(static_cast<T*>(0)->~vector())* = 0) { return 1; } template <class T> int is_vector(T const&, decltype(static_cast<T*>(0)->~deque())* = 0) { return 0; } template <class T> class vector{}; int test() { return is_vector(vector<int>()); }
Endilll commented 1 year ago

@wheatman Our trunk is post-17 however you look at it

wheatman commented 1 year ago

The trunk that godbolt is using is from 18 hours ago, and I thought that was before the official mark of 17. I wasn't sure, I can start stating post 17

Endilll commented 1 year ago

I'd say we are post-17 since 17 has branched.

shafik commented 1 year ago

Note this fails/crashes on gcc/clang/MVSC: https://godbolt.org/z/ccjecTGMj

It looks like some kind of mangling issue CC @rjmccall @zygoloid