llvm / llvm/llvm-project

[clang] Assertion `!Qualifier == !QualifierData' failed in -fms-compatibility mode

Open
#210,505 2 comments 0 reactions 0 assignees View on GitHub
clang:frontend crash-on-invalid generated by fuzzer regression:22
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reproducer:
https://godbolt.org/z/svvWrzKh4
```cpp
template struct S {
S* __ptr32 __uptr foo() { return 0; }
};

S::foo();
```

Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/include/clang/AST/TypeLoc.h:812: clang::NestedNameSpecifierLoc clang::TagTypeLoc::getQualifierLoc() const: Assertion `!Qualifier == !QualifierData' 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 -fms-compatibility
1. :5:1: at annotation token
2. :1:30: instantiating class definition 'S'
#0 0x0000000004402488 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4402488)
#1 0x00000000043ff344 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43ff344)
#2 0x00000000043ff96c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43ff96c)
#3 0x000000000433e9b8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x000070ad54845330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x000070ad5489eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#6 0x000070ad5484527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x000070ad548288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x000070ad5482881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x000070ad5483b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x00000000078bbaa1 (anonymous namespace)::TemplateInstantiator::TransformTagType(clang::TypeLocBuilder&, clang::TagTypeLoc) SemaTemplateInstantiate.cpp:0:0
#11 0x000000000789a38b clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeLocBuilder&, clang::TypeLoc) SemaTemplateInstantiate.cpp:0:0
#12 0x00000000078991af clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeLocBuilder&, clang::TypeLoc) SemaTemplateInstantiate.cpp:0:0
#13 0x000000000789d6e5 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformPointerType(clang::TypeLocBuilder&, clang::PointerTypeLoc) SemaTemplateInstantiate.cpp:0:0
#14 0x000000000789a1de clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeLocBuilder&, clang::TypeLoc) SemaTemplateInstantiate.cpp:0:0
#15 0x000000000789bb0e clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformAttributedType(clang::TypeLocBuilder&, clang::AttributedTypeLoc) SemaTemplateInstantiate.cpp:0:0
#16 0x000000000789942b clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeLocBuilder&, clang::TypeLoc) SemaTemplateInstantiate.cpp:0:0
#17 0x00000000078c51e9 clang::Sema::SubstFunctionDeclType(clang::TypeSourceInfo*, clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation, clang::DeclarationName, clang::CXXRecordDecl*, clang::Qualifiers, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x78c51e9)
#18 0x000000000792146c clang::TemplateDeclInstantiator::SubstFunctionType(clang::FunctionDecl*, llvm::SmallVectorImpl&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x792146c)
#19 0x000000000797f208 clang::TemplateDeclInstantiator::VisitCXXMethodDecl(clang::CXXMethodDecl*, clang::TemplateParameterList*, clang::TemplateDeclInstantiator::RewriteKind) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x797f208)
#20 0x00000000078a3a7b clang::Sema::InstantiateClassImpl(clang::SourceLocation, clang::CXXRecordDecl*, clang::CXXRecordDecl*, clang::MultiLevelTemplateArgumentList const&, clang::TemplateSpecializationKind, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x78a3a7b)
#21 0x0000000007911d5a clang::Sema::InstantiateClassTemplateSpecialization(clang::SourceLocation, clang::ClassTemplateSpecializationDecl*, clang::TemplateSpecializationKind, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7911d5a)
#22 0x0000000007991e6e void llvm::function_ref::callback_fn(long) SemaType.cpp:0:0
#23 0x000000000881dca1 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x881dca1)
#24 0x00000000079a82de clang::Sema::RequireCompleteTypeImpl(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, clang::Sema::TypeDiagnoser*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x79a82de)
#25 0x00000000079a875f clang::Sema::RequireCompleteType(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, clang::Sema::TypeDiagnoser&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x79a875f)
#26 0x0000000006f36183 clang::Sema::RequireCompleteDeclContext(clang::CXXScopeSpec&, clang::DeclContext*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f36183)
#27 0x000000000713153b clang::Sema::getTypeName(clang::IdentifierInfo const&, clang::SourceLocation, clang::Scope*, clang::CXXScopeSpec*, bool, bool, clang::OpaquePtr, bool, bool, bool, clang::ImplicitTypenameContext, clang::IdentifierInfo**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x713153b)
#28 0x0000000006d65a1c clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d65a1c)
#29 0x0000000006d212e7 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d212e7)
#30 0x0000000006d21d5f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d21d5f)
#31 0x0000000006d2e5a1 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d2e5a1)
#32 0x0000000006d2f4d5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d2f4d5)
#33 0x0000000006d0c3da clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d0c3da)
#34 0x0000000004f02368 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f02368)
#35 0x000000000522e498 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x522e498)
#36 0x00000000051bb53d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51bb53d)
#37 0x0000000005302ffd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5302ffd)
#38 0x0000000000da7e8c cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda7e8c)
#39 0x0000000000d9ea9a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#40 0x0000000000d9ec1d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#41 0x0000000004f79659 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#42 0x000000000433edf4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x433edf4)
#43 0x0000000004f7a1c5 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#44 0x0000000004f32b72 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f32b72)
#45 0x0000000004f373a7 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f373a7)
#46 0x0000000004f41905 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f41905)
#47 0x0000000000da437a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda437a)
#48 0x0000000000cbfdca main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcbfdca)
#49 0x000070ad5482a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#50 0x000070ad5482a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#51 0x0000000000d9e445 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd9e445)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
```

Contributor guide

Open the contributing guide

Research direction

Start with the provided C++ reproducer under -fms-compatibility and trace the TransformTagType entry point in SemaTemplateInstantiate.cpp to the assertion in clang/AST/TypeLoc.h. Investigate the qualifier state during template instantiation; done means the reproducer no longer aborts with the assertion and has regression coverage.

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
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.