This is an archive of the discontinued LLVM Phabricator instance.

[C2x] Implement the `unreachable` macro for WG14 N2826
ClosedPublic

Authored by aaron.ballman on Feb 6 2023, 11:49 AM.

Details

Summary

This exposes __builtin_unreachable as the expansion for the unreachable macro in C2x. I added this definition under __need_STDDEF_H_misc on the assumption there is no need for a separate need macro to control adding this.

Diff Detail

Event Timeline

aaron.ballman created this revision.Feb 6 2023, 11:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 6 2023, 11:49 AM
aaron.ballman requested review of this revision.Feb 6 2023, 11:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 6 2023, 11:49 AM
erichkeane added inline comments.
clang/lib/Headers/stddef.h
108

Is this REALLY required to be a macro by standard? Is it so they don't have to steal the word/can do #undef? This is going to result in a worse diagnostic here any time we diagnose on this line.

aaron.ballman added inline comments.Feb 15 2023, 6:40 AM
clang/lib/Headers/stddef.h
108

Yes, it's required to be a macro by the C standard. According to my personal notes:

This led us up to a preference poll, does WG14 prefer the syntax variant over the macro variant in N2826? 3/12/5 (no consensus). Does WG14 prefer to put the macro into <stddef.h> as in N2826 in C23? 11/2/7 (consensus). Does WG14 want to adopt the unreachable feature Change 5 & 6 with stddef.h in place of HEADER.h into C23? 13/2/6 (consensus).

I don't think the diagnostic behavior here will be any different than for offsetof (defined a few lines below), right?

erichkeane accepted this revision.Feb 15 2023, 6:43 AM
erichkeane added inline comments.
clang/lib/Headers/stddef.h
108

offsetof is what made me ask this question :D I guess we do the whole 'macro-like' escape in other places, but everything here is already crap, so I guess this is no different.

This revision is now accepted and ready to land.Feb 15 2023, 6:43 AM
jyknight accepted this revision.Feb 15 2023, 11:29 AM