Clang crashing unexpectedly

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Clang crashing unexpectedly

David Blaikie via cfe-dev
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: https://godbolt.org/z/L1v1rs

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. 

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clang crashing unexpectedly

David Blaikie via cfe-dev


On 16/03/2019 02:18, Zoe Carver via cfe-dev wrote:

> 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: https://godbolt.org/z/L1v1rs
>
> 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).
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clang crashing unexpectedly

David Blaikie via cfe-dev
Only 4 of the builtins are documented as being usable by libraries here. https://clang.llvm.org/docs/LanguageExtensions.html#c-coroutines-support-builtins  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.

~Craig


On Sat, Mar 16, 2019 at 6:31 AM Bruno Ricci via cfe-dev <[hidden email]> wrote:


On 16/03/2019 02:18, Zoe Carver via cfe-dev wrote:
> 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: https://godbolt.org/z/L1v1rs
>
> 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).
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clang crashing unexpectedly

David Blaikie via cfe-dev
In reply to this post by David Blaikie via cfe-dev

Gor,


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. 


Best,

Zoe


On Mon, Mar 18, 2019 at 9:32 AM Gor Nishanov <[hidden email]> wrote:
Hi Zoe, 

Thank you for the problem report.
I am curious, what are you trying to achieve using the structural coroutine builtins directly?

There are library builtins such as:

__builtin_coro_resume, destroy, done and promise that are meant to be used by libraries to implement standard library support for coroutines.

Others, like __builtin_coro_begin, __builtin_coro_size, and are structural coroutine builtins (or more precisely their llvm equivalents) that are used by the front-ends to describe the coroutine structure and mostly were useful during coroutine development when we already had an llvm support, but, front-end work was not done, so, we used them to create simple coroutines in C by calling those builtins.

Going forward, we may pull structural builtins from clang altogether unless there are strong use cases that will justify their existence.

Cheers,
Gor



From: Zoe Carver <[hidden email]>
Sent: Friday, March 15, 2019 7:18 PM
To: Gor Nishanov; [hidden email]
Cc: [hidden email]
Subject: 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: https://godbolt.org/z/L1v1rs

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. 

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev