[clang] Assertion `Arg && "expected a default argument"' failed in -fms-compatibility mode
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Reproducer:
https://godbolt.org/z/6cGPdafvr
```cpp
struct S;
template
concept ConstraintT = true;
template struct P {
template > struct CT {};
CT CI;
};
P p;
```
Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/lib/Sema/SemaConcept.cpp:2164: void {anonymous}::SubstituteParameterMappings::buildParameterMapping(clang::NormalizedConstraintWithParamMapping&): Assertion `Arg && "expected a default argument"' 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 -fms-compatibility
1. :10:9: current parser token ';'
2. :5:30: instantiating class definition 'P'
#0 0x0000000004401d18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4401d18)
#1 0x00000000043febc4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43febc4)
#2 0x00000000043ff1fc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43ff1fc)
#3 0x000000000433e2b8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x000071270e445330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x000071270e49eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#6 0x000071270e44527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x000071270e4288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x000071270e42881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x000071270e43b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x0000000007000ef9 (anonymous namespace)::SubstituteParameterMappings::substitute(clang::NormalizedConstraintWithParamMapping&) SemaConcept.cpp:0:0
#11 0x0000000007038f88 (anonymous namespace)::SubstituteParameterMappings::substitute(clang::NormalizedConstraint&) SemaConcept.cpp:0:0
#12 0x000000000703921a (anonymous namespace)::SubstituteParameterMappings::substitute(clang::NormalizedConstraint&) SemaConcept.cpp:0:0
#13 0x0000000007039940 clang::Sema::getNormalizedAssociatedConstraints(llvm::PointerUnion, llvm::ArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7039940)
#14 0x0000000007065751 CheckConstraintSatisfaction(clang::Sema&, clang::NamedDecl const*, llvm::ArrayRef, clang::MultiLevelTemplateArgumentList const&, clang::SourceRange, clang::ConstraintSatisfaction&, clang::Expr**, clang::ConceptReference const*) SemaConcept.cpp:0:0
#15 0x00000000070660f6 clang::Sema::CheckConstraintSatisfaction(llvm::PointerUnion, llvm::ArrayRef, clang::MultiLevelTemplateArgumentList const&, clang::SourceRange, clang::ConstraintSatisfaction&, clang::ConceptReference const*, clang::Expr**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x70660f6)
#16 0x00000000070676e8 clang::Sema::EnsureTemplateArgumentListConstraints(clang::TemplateDecl*, clang::MultiLevelTemplateArgumentList const&, clang::SourceRange) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x70676e8)
#17 0x0000000007749b6d clang::Sema::CheckTemplateArgumentList(clang::TemplateDecl*, clang::TemplateParameterList*, clang::SourceLocation, clang::TemplateArgumentListInfo&, clang::DefaultArguments const&, bool, clang::Sema::CheckTemplateArgumentInfo&, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7749b6d)
#18 0x000000000775e0b7 clang::Sema::CheckTemplateIdType(clang::ElaboratedTypeKeyword, clang::TemplateName, clang::SourceLocation, clang::TemplateArgumentListInfo&, clang::Scope*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x775e0b7)
#19 0x00000000078a771d clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformTemplateSpecializationType(clang::TypeLocBuilder&, clang::TemplateSpecializationTypeLoc, clang::QualType, clang::NamedDecl*, bool) SemaTemplateInstantiate.cpp:0:0
#20 0x0000000007886c84 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeLocBuilder&, clang::TypeLoc) SemaTemplateInstantiate.cpp:0:0
#21 0x000000000788acd7 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeSourceInfo*) SemaTemplateInstantiate.cpp:0:0
#22 0x000000000788f095 clang::Sema::SubstType(clang::TypeSourceInfo*, clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation, clang::DeclarationName, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x788f095)
#23 0x00000000079670fc clang::TemplateDeclInstantiator::VisitFieldDecl(clang::FieldDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x79670fc)
#24 0x00000000078906cb clang::Sema::InstantiateClassImpl(clang::SourceLocation, clang::CXXRecordDecl*, clang::CXXRecordDecl*, clang::MultiLevelTemplateArgumentList const&, clang::TemplateSpecializationKind, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x78906cb)
#25 0x00000000078fe96a clang::Sema::InstantiateClassTemplateSpecialization(clang::SourceLocation, clang::ClassTemplateSpecializationDecl*, clang::TemplateSpecializationKind, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x78fe96a)
#26 0x000000000797e8be void llvm::function_ref::callback_fn(long) SemaType.cpp:0:0
#27 0x000000000880af21 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x880af21)
#28 0x0000000007994d2e clang::Sema::RequireCompleteTypeImpl(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, clang::Sema::TypeDiagnoser*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7994d2e)
#29 0x00000000079951af clang::Sema::RequireCompleteType(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, clang::Sema::TypeDiagnoser&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x79951af)
#30 0x0000000007995805 clang::Sema::RequireCompleteType(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7995805)
#31 0x00000000070f3ffe clang::Sema::ActOnUninitializedDecl(clang::Decl*) (.part.0) SemaDecl.cpp:0:0
#32 0x0000000006d428cb clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d428cb)
#33 0x0000000006d63459 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d63459)
#34 0x0000000006d0eaab clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d0eaab)
#35 0x0000000006d0f29f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d0f29f)
#36 0x0000000006d1bae1 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d1bae1)
#37 0x0000000006d1ca15 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d1ca15)
#38 0x0000000006cf991a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cf991a)
#39 0x0000000004f01ab8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f01ab8)
#40 0x000000000522db68 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x522db68)
#41 0x00000000051bac0d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51bac0d)
#42 0x000000000530272d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x530272d)
#43 0x0000000000dab6ec cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdab6ec)
#44 0x0000000000da22fa ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#45 0x0000000000da247d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#46 0x0000000004f78da9 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#47 0x000000000433e6f4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x433e6f4)
#48 0x0000000004f79915 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#49 0x0000000004f322c2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f322c2)
#50 0x0000000004f36af7 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f36af7)
#51 0x0000000004f41055 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f41055)
#52 0x0000000000da7bda clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda7bda)
#53 0x0000000000cc363a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc363a)
#54 0x000071270e42a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#55 0x000071270e42a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#56 0x0000000000da1ca5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda1ca5)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
```
Contributor guide
Research direction
Start by compiling the provided C++ reproducer with -std=c++20 and -fms-compatibility. Read clang/lib/Sema/SemaConcept.cpp around SubstituteParameterMappings::buildParameterMapping and trace the assertion shown in the backtrace. Done means this input no longer aborts with the “expected a default argument” assertion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100