Clang crashing unexpectedly

I found that clang crashes when it should not. I brought up the issue in the LLVM IRC channel earlier and was told to send an email describing the problem (the LLVM Bugzilla has not verified me yet).

Here is a simple example of a program which crashes:

int main () {

return __builtin_coro_size();


This behavior happens with many of the coroutine builtins. Take another example:

void* alloc = malloc(1024);

void* ptr = __builtin_coro_begin(alloc);

return __builtin_coro_free(ptr);

Here is a Godbolt to help demonstrate the problem:

I think (but totally might be wrong) that the issue has to do with clang (“CGBuiltin.cpp”) returning a different type than was specified in “Builtins.def”.

Anyway, let me know if you have questions. Hope this helps.

Am I reading this correctly ? The coroutine intrinsics have never worked since introduced in clang 4 ? (At least this is what I am getting on godbolt).

Only 4 of the builtins are documented as being usable by libraries here. The others are listed as being for internal clang usage.

I suspect using these builtins by themselves isn’t triggering the passes in LLVM that handle coroutines. So the intrinsic isn’t being removed from IR before instruction selection.


Thanks for the reply!

I am curious, what are you trying to achieve using the structural coroutine builtins directly?

I actually wasn’t trying to use these at all. What I was trying to do was learn more about how to write builtins for clang. I was adding a simple test builtin under __builtin_coro_size, and was modeling my builtin after it because it seemed like it was a simple enough way to return an integer. Anyway, long story short my builtin crashed clang so I did some investigating and found that many of the coroutine builtins also crashed clang.

I agree that it is probably a good idea to pull them because it doesn’t look like they are used anywhere in either clang or libc++. If they are only for internal use, it is probably not I high priority though. It would be good to figure out what the issue was so that we can make sure it doesn’t effect any other (more important) builtins.