Issue 204178
Summary [clang] Assertion failure when using concepts and type defined in `abi_tag` namespace
Labels
Assignees
Reporter davidstone
    Given the following valid translation unit

```cxx
inline namespace [[gnu::abi_tag("n")]] n {

class s {
};

}

template<typename, typename>
concept c = true;

template<typename T>
auto f(T t, c<decltype(t)> auto) -> s;

auto g() -> void {
	f(0, 0);
}
```

clang since clang-18 and up to current main fails with

```console
clang++: /root/llvm-project/llvm/tools/clang/lib/AST/ItaniumMangle.cpp:255: unsigned int {anonymous}::CXXNameMangler::FunctionTypeDepthState::getNestingDepth(unsigned int) const: Assertion `ParmDepth < Depth && "ParmVarDecl is not visible in current parameter environment"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
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 -std=c++20 <source>
1.	<eof> parser at end of file
2.	<source>:14:6: LLVM IR generation of declaration 'g'
3.	<source>:14:6: Generating code for declaration 'g'
4.	<source>:12:6: Mangling declaration 'f'
 #0 0x000000000433b378 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x433b378)
 #1 0x00000000043382b4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43382b4)
 #2 0x00000000043388d4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43388d4)
 #3 0x0000000004275e18 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #4 0x00007e099de45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #5 0x00007e099de9eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
 #6 0x00007e099de4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
 #7 0x00007e099de288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
 #8 0x00007e099de2881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
 #9 0x00007e099de3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x00000000082ca4ec (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x82ca4ec)
#11 0x00000000082ccf95 (anonymous namespace)::CXXNameMangler::mangleExpression(clang::Expr const*, unsigned int, bool)::'lambda0'(clang::NamedDecl const*)::operator()(clang::NamedDecl const*) const (.isra.0) ItaniumMangle.cpp:0:0
#12 0x00000000082c78d9 (anonymous namespace)::CXXNameMangler::mangleExpression(clang::Expr const*, unsigned int, bool) ItaniumMangle.cpp:0:0
#13 0x00000000082bcdae (anonymous namespace)::CXXNameMangler::mangleType(clang::QualType) ItaniumMangle.cpp:0:0
#14 0x00000000082d6a18 (anonymous namespace)::CXXNameMangler::mangleTemplateArg(clang::TemplateArgument, bool) ItaniumMangle.cpp:0:0
#15 0x00000000082d5373 (anonymous namespace)::CXXNameMangler::mangleTemplateArgs(clang::TemplateName, llvm::ArrayRef<clang::TemplateArgument>) ItaniumMangle.cpp:0:0
#16 0x00000000082d6f81 (anonymous namespace)::CXXNameMangler::mangleTemplateName(clang::TemplateDecl const*, llvm::ArrayRef<clang::TemplateArgument>) ItaniumMangle.cpp:0:0
#17 0x00000000082d4369 (anonymous namespace)::CXXNameMangler::mangleTypeConstraint(clang::TemplateDecl const*, llvm::ArrayRef<clang::TemplateArgument>) ItaniumMangle.cpp:0:0
#18 0x00000000082d445b (anonymous namespace)::CXXNameMangler::mangleTypeConstraint(clang::TypeConstraint const*) ItaniumMangle.cpp:0:0
#19 0x00000000082d4748 (anonymous namespace)::CXXNameMangler::mangleTemplateParamDecl(clang::NamedDecl const*) ItaniumMangle.cpp:0:0
#20 0x00000000082d39bc (anonymous namespace)::CXXNameMangler::mangleTemplateArgs(clang::TemplateName, clang::TemplateArgumentList const&) ItaniumMangle.cpp:0:0
#21 0x00000000082ba841 (anonymous namespace)::CXXNameMangler::mangleNameWithAbiTags(clang::GlobalDecl, llvm::ArrayRef<llvm::StringRef>) ItaniumMangle.cpp:0:0
#22 0x00000000082cbfdf (anonymous namespace)::CXXNameMangler::mangleFunctionEncoding(clang::GlobalDecl) ItaniumMangle.cpp:0:0
#23 0x00000000082cc927 (anonymous namespace)::CXXNameMangler::mangle(clang::GlobalDecl) ItaniumMangle.cpp:0:0
#24 0x00000000082cee82 (anonymous namespace)::ItaniumMangleContextImpl::mangleCXXName(clang::GlobalDecl, llvm::raw_ostream&) ItaniumMangle.cpp:0:0
#25 0x00000000082f532c clang::MangleContext::mangleName(clang::GlobalDecl, llvm::raw_ostream&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x82f532c)
#26 0x0000000004a54fd5 getMangledNameImpl(clang::CodeGen::CodeGenModule&, clang::GlobalDecl, clang::NamedDecl const*, bool) CodeGenModule.cpp:0:0
#27 0x0000000004a70f1c clang::CodeGen::CodeGenModule::getMangledName(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a70f1c)
#28 0x0000000004aabb65 clang::CodeGen::CodeGenModule::GetAddrOfFunction(clang::GlobalDecl, llvm::Type*, bool, bool, clang::CodeGen::ForDefinition_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4aabb65)
#29 0x00000000047ee18e clang::CodeGen::CodeGenModule::getRawFunctionPointer(clang::GlobalDecl, llvm::Type*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47ee18e)
#30 0x0000000004800454 EmitDirectCallee(clang::CodeGen::CodeGenFunction&, clang::GlobalDecl) CGExpr.cpp:0:0
#31 0x000000000481de24 clang::CodeGen::CodeGenFunction::EmitCallee(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x481de24)
#32 0x000000000481da6f clang::CodeGen::CodeGenFunction::EmitCallee(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x481da6f)
#33 0x00000000048226ff clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::CallBase**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48226ff)
#34 0x0000000004825a87 clang::CodeGen::RValue llvm::function_ref<clang::CodeGen::RValue (clang::CodeGen::ReturnValueSlot)>::callback_fn<(anonymous namespace)::AggExprEmitter::VisitCallExpr(clang::CallExpr const*)::'lambda'(clang::CodeGen::ReturnValueSlot)>(long, clang::CodeGen::ReturnValueSlot) CGExprAgg.cpp:0:0
#35 0x00000000048303b8 (anonymous namespace)::AggExprEmitter::withReturnValueSlot(clang::Expr const*, llvm::function_ref<clang::CodeGen::RValue (clang::CodeGen::ReturnValueSlot)>) CGExprAgg.cpp:0:0
#36 0x0000000004830d93 (anonymous namespace)::AggExprEmitter::VisitCallExpr(clang::CallExpr const*) CGExprAgg.cpp:0:0
#37 0x0000000004834801 (anonymous namespace)::AggExprEmitter::Visit(clang::Expr*) CGExprAgg.cpp:0:0
#38 0x000000000483575e clang::CodeGen::CodeGenFunction::EmitAggExpr(clang::Expr const*, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x483575e)
#39 0x00000000047e9dfa clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47e9dfa)
#40 0x000000000481d8ed clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x481d8ed)
#41 0x00000000049b6ab1 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49b6ab1)
#42 0x00000000049be7bb clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49be7bb)
#43 0x0000000004a27bf6 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a27bf6)
#44 0x0000000004a3d9a4 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a3d9a4)
#45 0x0000000004aac94a clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4aac94a)
#46 0x0000000004aa6ef4 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4aa6ef4)
#47 0x0000000004aa76e3 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4aa76e3)
#48 0x0000000004ab3ac3 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#49 0x0000000004e31989 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#50 0x0000000004e21ea4 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e21ea4)
#51 0x0000000006be6e04 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6be6e04)
#52 0x0000000004e2f718 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e2f718)
#53 0x0000000005167258 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5167258)
#54 0x00000000050e30ed clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50e30ed)
#55 0x000000000526606d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x526606d)
#56 0x0000000000dc69bc cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdc69bc)
#57 0x0000000000dbd65a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#58 0x0000000000dbd7dd 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
#59 0x0000000004ea1f49 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
#60 0x0000000004276254 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4276254)
#61 0x0000000004ea2596 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
#62 0x0000000004e5ef32 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e5ef32)
#63 0x0000000004e5fede 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+++0x4e5fede)
#64 0x0000000004e67715 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e67715)
#65 0x0000000000dc2ef2 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdc2ef2)
#66 0x0000000000cc2f7a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc2f7a)
#67 0x00007e099de2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#68 0x00007e099de2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#69 0x0000000000dbd005 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdbd005)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
```

See it live: https://godbolt.org/z/cWKfd7eKW

`s` in this example is similar to `std::string`, at least in libstdc++16.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to