clang crashes on invalid coroutine code · Issue #78426 · llvm/llvm-project (original) (raw)

See godbolt for details.

Looks like this is a regression issue, it is not reproduced with clang-17.

Code:

#include

template struct Task { T t; struct promise_type { std::suspend_always initial_suspend() { return {}; } Task get_return_object() { return std::coroutine_handle::from_promise(*this); } std::suspend_always final_suspend() noexcept { return {}; } std::suspend_always return_void() { return {}; } void unhandled_exception() {}

auto await_transform(int s);

};

Task(std::coroutine_handle promise);

std::coroutine_handle handle; };

class Foo { void test() { auto s = this -> Task< { co_await 1; }; } };

Stacktrace:

clang++: /root/llvm-project/clang/include/clang/AST/Type.h:753: const clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const: Assertion `!isNull() && "Cannot retrieve a NULL type pointer"' 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 -std=c++20 <source>
1.	<source>:26:40: current parser token ';'
2.	<source>:23:1: parsing struct/union/class body 'Foo'
3.	<source>:24:13: parsing function body 'Foo::test'
4.	<source>:24:13: in compound statement ('{}')
5.	<source>:26:9: lambda expression parsing
 #0 0x0000000003801b18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3801b18)
 #1 0x00000000037ff7fc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x37ff7fc)
 #2 0x00000000037482d8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f2a13042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f2a130969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007f2a13042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007f2a130287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007f2a1302871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007f2a13039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000000006312024 checkCoroutineContext(clang::Sema&, clang::SourceLocation, llvm::StringRef, bool) SemaCoroutine.cpp:0:0
#10 0x00000000063139b0 clang::Sema::ActOnCoroutineBodyStart(clang::Scope*, clang::SourceLocation, llvm::StringRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63139b0)
#11 0x0000000006313c7b clang::Sema::ActOnCoawaitExpr(clang::Scope*, clang::SourceLocation, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6313c7b)
#12 0x00000000060804c8 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x60804c8)
#13 0x0000000006082a9a clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6082a9a)
#14 0x0000000006082c39 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6082c39)
#15 0x00000000060a9319 clang::Parser::ParseBraceInitializer() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x60a9319)
#16 0x000000000610dd88 clang::Parser::ParseTemplateArgument() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x610dd88)