<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57387>57387</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang assertion failure while printing error message
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
gmlueck
</td>
</tr>
</table>
<pre>
The following program causes an assertion failure in clang. This can be reproduced on [godbolt ](https://godbolt.org/z/fnxhjr8dP) 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
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlWllz47gR_jXyC4oq3seDHzSyvXEyyTiWkuybCgRBiWuK4ACgLe-vTwMkJYKWNPbG2pqquGSKwtHo_rrR3ThSlr1eLzcU5aws2UtRrVHN2ZrjLSK4EVQgXCEsBOWyYBXKcVE2nKKiQqTE1XqK0HJT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