Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang13 parser crashes for invalid code when template function return type is "auto" #53851

Closed
nickhuang99 opened this issue Feb 15, 2022 · 4 comments
Labels
c++20 clang:codegen confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@nickhuang99
Copy link

clang13 crashes with exit code 139 for following invalid template id foo<int>. See compiler explorer. Interestingly, changing return type from auto to void would prevent crash from happening. My guess is that no return code in function body should enable "return-type-deduction" to assign void to auto, isn't it?


template<typename T>
auto foo(decltype([](T t){}) lam){	
}

void test(){
    foo<int>; // crashes compiler
}
  1. :8:1: current parser token '}'
  2. :6:12: parsing function body 'test'
  3. :6:12: in compound statement ('{}')
  4. :3:6: instantiating function definition 'foo'
  5. :3:6: LLVM IR generation of declaration 'foo'
  6. :3:6: Mangling declaration 'foo'

#0 0x0000556c70adf35f PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
#1 0x0000556c70add220 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x34dd220)
#2 0x0000556c70a2e218 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007fa20e9b03c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
#4 0x00007fa20e5c771d (/lib/x86_64-linux-gnu/libc.so.6+0x18e71d)
#5 0x0000556c6e88306a llvm::raw_ostream::operator<<(char const*) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x128306a)
#6 0x0000556c7357511c (anonymous namespace)::CXXNameMangler::mangleExpression(clang::Expr const*, unsigned int, bool) ItaniumMangle.cpp:0:0
#7 0x0000556c7356cf91 (anonymous namespace)::CXXNameMangler::mangleType(clang::QualType) ItaniumMangle.cpp:0:0
#8 0x0000556c7357215c (anonymous namespace)::CXXNameMangler::mangleBareFunctionType(clang::FunctionProtoType const*, bool, clang::FunctionDecl const*) ItaniumMangle.cpp:0:0
#9 0x0000556c73577432 (anonymous namespace)::CXXNameMangler::mangleFunctionEncoding(clang::GlobalDecl) ItaniumMangle.cpp:0:0
#10 0x0000556c73578f77 (anonymous namespace)::ItaniumMangleContextImpl::mangleCXXName(clang::GlobalDecl, llvm::raw_ostream&) ItaniumMangle.cpp:0:0
#11 0x0000556c70e8416a getMangledNameImpl(clang::CodeGen::CodeGenModule&, clang::GlobalDecl, clang::NamedDecl const*, bool) CodeGenModule.cpp:0:0
#12 0x0000556c70e91fb5 clang::CodeGen::CodeGenModule::getMangledName(clang::GlobalDecl) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x3891fb5)
#13 0x0000556c70eb9529 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x38b9529)
#14 0x0000556c70ebf671 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.5272) CodeGenModule.cpp:0:0
#15 0x0000556c71a35f11 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#16 0x0000556c71a29d52 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x4429d52)
#17 0x0000556c730bb163 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x5abb163)
#18 0x0000556c7299cc9f clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x539cc9f)
#19 0x0000556c72ff513d clang::Sema::DeduceReturnType(clang::FunctionDecl*, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x59f513d)
#20 0x0000556c7302729b clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, clang::QualType, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x5a2729b)
#21 0x0000556c73027307 clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x5a27307)
#22 0x0000556c72ee5c65 clang::Sema::ResolveSingleFunctionTemplateSpecialization(clang::OverloadExpr*, bool, clang::DeclAccessPair*) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x58e5c65)
#23 0x0000556c72ee6354 clang::Sema::ResolveAndFixSingleFunctionTemplateSpecialization(clang::ActionResult<clang::Expr*, true>&, bool, bool, clang::SourceRange, clang::QualType, unsigned int) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x58e6354)
#24 0x0000556c72c26e6d clang::Sema::CheckPlaceholderExpr(clang::Expr*) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x5626e6d)
#25 0x0000556c72d2d1d4 clang::Sema::ActOnFinishFullExpr(clang::Expr*, clang::SourceLocation, bool, bool) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x572d1d4)
#26 0x0000556c72f1b114 clang::Sema::ActOnExprStmt(clang::ActionResult<clang::Expr*, true>, bool) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x591b114)
#27 0x0000556c729474a3 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x53474a3)
#28 0x0000556c7293fd7b clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributesWithRange&) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x533fd7b)
#29 0x0000556c72940cbd clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x5340cbd)
#30 0x0000556c7293b862 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x533b862)
#31 0x0000556c7293c693 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x533c693)
#32 0x0000556c728967c4 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x52967c4)
#33 0x0000556c728bf7c1 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x52bf7c1)
#34 0x0000556c72891859 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x5291859)
#35 0x0000556c72891f61 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.280) Parser.cpp:0:0
#36 0x0000556c72897e89 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x5297e89)
#37 0x0000556c728992a9 clang::Parser::ParseTopLevelDecl(clang::OpaquePtrclang::DeclGroupRef&, bool) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x52992a9)
#38 0x0000556c7288cb09 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x528cb09)
#39 0x0000556c71a33e22 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x4433e22)
#40 0x0000556c713e0ff1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x3de0ff1)
#41 0x0000556c7137f2b2 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x3d7f2b2)
#42 0x0000556c714ad733 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x3ead733)
#43 0x0000556c6e88611c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x128611c)
#44 0x0000556c6e8822fd ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#45 0x0000556c7122a605 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optionalllvm::StringRef >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool) const::'lambda'()>(long) Job.cpp:0:0
#46 0x0000556c70a2e803 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x342e803)
#47 0x0000556c7122c6be clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optionalllvm::StringRef >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool) const (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x3c2c6be)
#48 0x0000556c712020ea clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x3c020ea)
#49 0x0000556c71202c3f clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x3c02c3f)
#50 0x0000556c7120c035 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x3c0c035)
#51 0x0000556c6e79b56e main (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x119b56e)
#52 0x00007fa20e4600b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#53 0x0000556c6e881e7a _start (/opt/compiler-explorer/clang-13.0.1/bin/clang+++0x1281e7a)
clang-13: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139

@DimitryAndric
Copy link
Collaborator

This regressed with 22aa368, ping @AaronBallman

$ ~/ins/llvmorg-15-init-00899-g68c1eeb4bad/bin/clang -cc1 -S -std=c++20 pr53851.cpp
non-canonical or dependent type in IR-generation
UNREACHABLE executed at /home/dim/src/llvm/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:226!
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: /home/dim/ins/llvmorg-15-init-00899-g68c1eeb4bad/bin/clang -cc1 -S -std=c++20 pr53851.cpp
1.      <eof> parser at end of file
2.      pr53851.cpp:6:6: LLVM IR generation of declaration 'test'
3.      pr53851.cpp:6:6: Generating code for declaration 'test'
#0 0x0000000003bd4e98 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dim/ins/llvmorg-15-init-00899-g68c1eeb4bad/bin/clang+0x3bd4e98)
#1 0x0000000003bd2c98 llvm::sys::RunSignalHandlers() (/home/dim/ins/llvmorg-15-init-00899-g68c1eeb4bad/bin/clang+0x3bd2c98)
#2 0x0000000003bd5630 SignalHandler(int) Signals.cpp:0:0
#3 0x0000000828250e00 handle_signal /usr/src/lib/libthr/thread/thr_sig.c:0:3
Abort trap

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 15, 2022

@llvm/issue-subscribers-c-20

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 15, 2022

@llvm/issue-subscribers-clang-codegen

@AaronBallman AaronBallman added confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid] labels Feb 16, 2022
@ilya-biryukov
Copy link
Contributor

Closing as clang 15 and trunk don't crash anymore, see godbolt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++20 clang:codegen confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
Status: Done
Development

No branches or pull requests

6 participants