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

clang crashes on invalid coroutine code #78426

Open
hokein opened this issue Jan 17, 2024 · 4 comments
Open

clang crashes on invalid coroutine code #78426

hokein opened this issue Jan 17, 2024 · 4 comments
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" coroutines C++20 coroutines regression

Comments

@hokein
Copy link
Collaborator

hokein commented Jan 17, 2024

See godbolt for details.

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

Code:

#include <coroutine>

template<typename T>
struct Task {
  T t;
  struct promise_type {
    std::suspend_always initial_suspend() { return {}; }
    Task get_return_object() {
      return std::coroutine_handle<promise_type>::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_type> promise);

  std::coroutine_handle<promise_type> 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)
@hokein hokein added c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" coroutines C++20 coroutines labels Jan 17, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 17, 2024

@llvm/issue-subscribers-clang-frontend

Author: Haojian Wu (hokein)

See [godbolt](https://godbolt.org/z/arMx39szq) for details.

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

Code:

#include &lt;coroutine&gt;

template&lt;typename T&gt;
struct Task {
  T t;
  struct promise_type {
    std::suspend_always initial_suspend() { return {}; }
    Task get_return_object() {
      return std::coroutine_handle&lt;promise_type&gt;::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&lt;promise_type&gt; promise);

  std::coroutine_handle&lt;promise_type&gt; handle;
};

class Foo {
void test() {
  auto s = 
        [this]() -&gt; Task&lt; {  co_await 1; };
}
};

Stacktrace:

clang++: /root/llvm-project/clang/include/clang/AST/Type.h:753: const clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const: Assertion `!isNull() &amp;&amp; "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 &lt;source&gt;
1.	&lt;source&gt;:26:40: current parser token ';'
2.	&lt;source&gt;:23:1: parsing struct/union/class body 'Foo'
3.	&lt;source&gt;:24:13: parsing function body 'Foo::test'
4.	&lt;source&gt;:24:13: in compound statement ('{}')
5.	&lt;source&gt;:26:9: lambda expression parsing
 #<!-- -->0 0x0000000003801b18 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, 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&amp;, 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&amp;, 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)

@llvmbot
Copy link
Member

llvmbot commented Jan 17, 2024

@llvm/issue-subscribers-c-20

Author: Haojian Wu (hokein)

See [godbolt](https://godbolt.org/z/arMx39szq) for details.

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

Code:

#include &lt;coroutine&gt;

template&lt;typename T&gt;
struct Task {
  T t;
  struct promise_type {
    std::suspend_always initial_suspend() { return {}; }
    Task get_return_object() {
      return std::coroutine_handle&lt;promise_type&gt;::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&lt;promise_type&gt; promise);

  std::coroutine_handle&lt;promise_type&gt; handle;
};

class Foo {
void test() {
  auto s = 
        [this]() -&gt; Task&lt; {  co_await 1; };
}
};

Stacktrace:

clang++: /root/llvm-project/clang/include/clang/AST/Type.h:753: const clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const: Assertion `!isNull() &amp;&amp; "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 &lt;source&gt;
1.	&lt;source&gt;:26:40: current parser token ';'
2.	&lt;source&gt;:23:1: parsing struct/union/class body 'Foo'
3.	&lt;source&gt;:24:13: parsing function body 'Foo::test'
4.	&lt;source&gt;:24:13: in compound statement ('{}')
5.	&lt;source&gt;:26:9: lambda expression parsing
 #<!-- -->0 0x0000000003801b18 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, 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&amp;, 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&amp;, 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)

@llvmbot
Copy link
Member

llvmbot commented Jan 17, 2024

@llvm/issue-subscribers-coroutines

Author: Haojian Wu (hokein)

See [godbolt](https://godbolt.org/z/arMx39szq) for details.

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

Code:

#include &lt;coroutine&gt;

template&lt;typename T&gt;
struct Task {
  T t;
  struct promise_type {
    std::suspend_always initial_suspend() { return {}; }
    Task get_return_object() {
      return std::coroutine_handle&lt;promise_type&gt;::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&lt;promise_type&gt; promise);

  std::coroutine_handle&lt;promise_type&gt; handle;
};

class Foo {
void test() {
  auto s = 
        [this]() -&gt; Task&lt; {  co_await 1; };
}
};

Stacktrace:

clang++: /root/llvm-project/clang/include/clang/AST/Type.h:753: const clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const: Assertion `!isNull() &amp;&amp; "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 &lt;source&gt;
1.	&lt;source&gt;:26:40: current parser token ';'
2.	&lt;source&gt;:23:1: parsing struct/union/class body 'Foo'
3.	&lt;source&gt;:24:13: parsing function body 'Foo::test'
4.	&lt;source&gt;:24:13: in compound statement ('{}')
5.	&lt;source&gt;:26:9: lambda expression parsing
 #<!-- -->0 0x0000000003801b18 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, 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&amp;, 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&amp;, 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)

@yuxuanchen1997
Copy link
Member

yuxuanchen1997 commented Mar 18, 2024

Smaller repro: https://godbolt.org/z/KbTW1a1x7

template <typename T>
struct Task {};

void test() {
  []() -> Task< {  co_await 1; };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" coroutines C++20 coroutines regression
Projects
Status: No status
Development

No branches or pull requests

4 participants