llvm / llvm/llvm-project

[clang] Assertion `!NewT.isNull()' failed.

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

Description

Reproducer:
https://godbolt.org/z/TeYWYhq57
```cpp
template struct S {};
template using A = S;

A foo{42};
```

Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/lib/Sema/SemaTemplateDeductionGuide.cpp:373: clang::NonTypeTemplateParmDecl* {anonymous}::transformTemplateParam(clang::Sema&, clang::DeclContext*, clang::NonTypeTemplateParmDecl*, unsigned int, unsigned int, clang::MultiLevelTemplateArgumentList&): Assertion `!NewT.isNull()' 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
1. :4:10: current parser token ';'
#0 0x00000000043a2c48 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43a2c48)
#1 0x000000000439fb64 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x439fb64)
#2 0x00000000043a0184 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43a0184)
#3 0x00000000042df218 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x0000769d9ba45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x0000769d9ba9eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#6 0x0000769d9ba4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x0000769d9ba288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x0000769d9ba2881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x0000769d9ba3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x0000000007786222 (anonymous namespace)::transformTemplateParam(clang::Sema&, clang::DeclContext*, clang::NonTypeTemplateParmDecl*, unsigned int, unsigned int, clang::MultiLevelTemplateArgumentList&) SemaTemplateDeductionGuide.cpp:0:0
#11 0x0000000007786d80 (anonymous namespace)::transformTemplateParameter(clang::Sema&, clang::DeclContext*, clang::NamedDecl*, clang::MultiLevelTemplateArgumentList&, unsigned int, unsigned int, bool) SemaTemplateDeductionGuide.cpp:0:0
#12 0x000000000778a618 (anonymous namespace)::BuildDeductionGuideForTypeAlias(clang::Sema&, clang::TypeAliasTemplateDecl*, clang::CXXDeductionGuideDecl*, clang::SourceLocation) SemaTemplateDeductionGuide.cpp:0:0
#13 0x00000000077d22a8 clang::Sema::DeclareImplicitDeductionGuides(clang::TemplateDecl*, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x77d22a8)
#14 0x00000000073bd91f LookupDirect(clang::Sema&, clang::LookupResult&, clang::DeclContext const*) SemaLookup.cpp:0:0
#15 0x00000000073bdbd2 clang::Sema::LookupQualifiedName(clang::LookupResult&, clang::DeclContext*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x73bdbd2)
#16 0x0000000007380a85 clang::Sema::DeduceTemplateSpecializationFromInitializer(clang::TypeSourceInfo*, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7380a85)
#17 0x000000000704f60d clang::Sema::deduceVarTypeFromInitializer(clang::VarDecl*, clang::DeclarationName, clang::QualType, clang::TypeSourceInfo*, clang::SourceRange, bool, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x704f60d)
#18 0x000000000705168d clang::Sema::DeduceVariableDeclarationType(clang::VarDecl*, bool, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x705168d)
#19 0x00000000070854c8 clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x70854c8)
#20 0x0000000006cc6cc4 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cc6cc4)
#21 0x0000000006ce6dc2 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+++0x6ce6dc2)
#22 0x0000000006c9244b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c9244b)
#23 0x0000000006c92c4f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c92c4f)
#24 0x0000000006c9f471 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c9f471)
#25 0x0000000006ca0385 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ca0385)
#26 0x0000000006c7d27a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c7d27a)
#27 0x0000000004e930f8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e930f8)
#28 0x00000000051bd7d8 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51bd7d8)
#29 0x000000000514b75d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x514b75d)
#30 0x000000000529506d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x529506d)
#31 0x0000000000d9f3fc cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd9f3fc)
#32 0x0000000000d9600a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#33 0x0000000000d9618d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#34 0x0000000004f05f59 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#35 0x00000000042df654 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42df654)
#36 0x0000000004f06a85 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#37 0x0000000004ec1b62 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ec1b62)
#38 0x0000000004ec2b7e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ec2b7e)
#39 0x0000000004ececb5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ececb5)
#40 0x0000000000d9b8ea clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd9b8ea)
#41 0x0000000000cb80fa main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcb80fa)
#42 0x0000769d9ba2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#43 0x0000769d9ba2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#44 0x0000000000d959b5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd959b5)
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

Reproduce the crash with the C++20 example and inspect transformTemplateParam in llvm/tools/clang/lib/Sema/SemaTemplateDeductionGuide.cpp, as identified by the assertion backtrace. Trace the deduction-guide construction for the type alias and verify that the reproducer no longer aborts on !NewT.isNull().

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.