Skip to content

ir: Don't mark functions returning a noreturn function pointer as divergent - #3538

Open
HawkForge wants to merge 2 commits into
rust-lang:mainfrom
HawkForge:fix/noreturn-returned-fn-ptr
Open

HawkForge wants to merge 2 commits into
rust-lang:mainfrom
HawkForge:fix/noreturn-returned-fn-ptr

Conversation

@HawkForge

Copy link
Copy Markdown

Fixes #3489. Thanks to @lwz23 for the report.

For void (__attribute__((noreturn)) *take(int t))(int); libclang spells the function type as void (*(int))(int) __attribute__((noreturn)). FunctionSig::from_ty looks for __attribute__((noreturn)) at parenthesis depth 0 of that spelling, but here the attribute belongs to the pointed-to function type, not to take, so take was emitted as -> !.

When the return type is spelled as a raw function pointer, the function's own attributes follow its parameters inside the (*...) group, e.g. void (*(int) __attribute__((noreturn)))(int) __attribute__((noreturn)) for a function that is noreturn itself. So in that case the check now looks at depth 1 instead of 0. A return type spelled through a typedef (fp (int) __attribute__((noreturn))) and plain functions keep the depth-0 check, and argument attributes (the #2715/#2716 case) stay at depth 2+.

The header test covers take, a noreturn function returning a noreturn function pointer, the typedef'd return with and without noreturn, and a plain noreturn function. Only take changes compared to main; the test fails without the change.


Replaces #3537, which got closed when my fork was accidentally detached.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

__attribute__((noreturn)) on a returned function pointer makes take itself -> !

1 participant