Skip to content

clang assertion failure while printing error message #57387

Closed
@gmlueck

Description

@gmlueck

The following program causes an assertion failure in clang. This can be reproduced on godbolt with "x86-64 clang (assertion trunk)":

# 1 "<built-in>"
# 1 "clang-crash.cpp"
class helper {
 public:
  template<typename T>
  int foo() {
    return 1;
  }
};

void func() { // return type is wrong
  return helper{};
}


void bar() {
  func().foo<int>();
}

Compiler output (including stack trace):

<source>:10:3: error: void function 'func' should not return a value [-Wreturn-type]
  return helper{};
  ^      ~~~~~~~~
clang++: /root/llvm-project/clang/include/clang/AST/Type.h:7411: const T* clang::Type::castAs() const [with T = clang::TagType]: Assertion `isa<T>(CanonicalType)' failed.
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: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source> -isystem/opt/compiler-explorer/libs/boost_1_79_0
1.	<source>:15:10: current parser token 'foo'
2.	<source>:14:12: parsing function body 'bar'
3.	<source>:14:12: in compound statement ('{}')
 #0 0x000055a7214281a4 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x000055a721425f4c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e71f4c)
 #2 0x000055a72135cf78 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f5c7aaa8420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f5c7a57500b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f5c7a554859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f5c7a554729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f5c7a565fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x000055a7242a75af clang::TagType const* clang::Type::castAs<clang::TagType>() const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cf35af)
 #9 0x000055a7242acc7f clang::Sema::LookupTemplateName(clang::LookupResult&, clang::Scope*, clang::CXXScopeSpec&, clang::QualType, bool, bool&, clang::Sema::RequiredTemplateKind, clang::Sema::AssumedTemplateKind*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cf8c7f)
#10 0x000055a7242ad90d clang::Sema::isTemplateName(clang::Scope*, clang::CXXScopeSpec&, bool, clang::UnqualifiedId const&, clang::OpaquePtr<clang::QualType>, bool, clang::OpaquePtr<clang::TemplateName>&, bool&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cf990d)
#11 0x000055a723a5b406 clang::Parser::ParseOptionalCXXScopeSpecifier(clang::CXXScopeSpec&, clang::OpaquePtr<clang::QualType>, bool, bool, bool*, bool, clang::IdentifierInfo**, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x64a7406)
#12 0x000055a723a4771e clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x649371e)
#13 0x000055a723a40307 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x648c307)
#14 0x000055a723a4324b clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x648f24b)
#15 0x000055a723a432ed clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x648f2ed)
#16 0x000055a723a474ad clang::Parser::ParseExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x64934ad)
#17 0x000055a723abc8cf clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x65088cf)
#18 0x000055a723ab2a3a clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x64fea3a)
#19 0x000055a723ab3955 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x64ff955)
#20 0x000055a723ab49ba clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x65009ba)
#21 0x000055a723ab628a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x650228a)
#22 0x000055a7239ec5e1 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x64385e1)
#23 0x000055a723a1fd6f clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x646bd6f)
#24 0x000055a7239e1189 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x642d189)
#25 0x000055a7239e19e0 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#26 0x000055a7239e719b clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x643319b)
#27 0x000055a7239e802a clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x643402a)
#28 0x000055a7239dc49a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x642849a)
#29 0x000055a7227342c8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51802c8)
#30 0x000055a721fcfdb9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a1bdb9)
#31 0x000055a721f585ee clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49a45ee)
#32 0x000055a7220b01f3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4afc1f3)
#33 0x000055a71e9a6714 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x13f2714)
#34 0x000055a71e99f848 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#35 0x000055a721dc7089 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#36 0x000055a72135d71a llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3da971a)
#37 0x000055a721dc779f clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#38 0x000055a721d90ca9 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47dcca9)
#39 0x000055a721d9172d 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+++0x47dd72d)
#40 0x000055a721d9b4dc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47e74dc)
#41 0x000055a71e9a4af3 clang_main(int, char**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x13f0af3)
#42 0x00007f5c7a556083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#43 0x000055a71e99f43e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x13eb43e)
clang-16: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134

Metadata

Metadata

Assignees

Labels

clang:frontendLanguage frontend issues, e.g. anything involving "Sema"crashPrefer [crash-on-valid] or [crash-on-invalid]

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions