This is an archive of the discontinued LLVM Phabricator instance.

Headers: tweak inclusion condition for stdatomic.h
ClosedPublic

Authored by compnerd on Dec 3 2022, 7:02 PM.

Details

Summary

MSVC requires that C++23 be available (_HAS_CXX23) else the entire
content is elided. Conditionalise the inclusion properly so that C/C++
code using stdatomic.h for memory_order_* constants are able to do
so without changing the C++ standard. This repairs builds of Swift and
libdispatch after ba49d39b20cc5358da28af2ac82bd336028780bc.

Diff Detail

Event Timeline

compnerd created this revision.Dec 3 2022, 7:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 3 2022, 7:02 PM
compnerd requested review of this revision.Dec 3 2022, 7:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 3 2022, 7:02 PM

Thanks for the patch!

clang/lib/Headers/stdatomic.h
21

Is __cplusplus-0 intentional? If so please add some comments how this differs from __cplusplus.
Since this is a C header we should test whether the macro exists before querying its value.

compnerd added inline comments.Dec 6 2022, 9:34 AM
clang/lib/Headers/stdatomic.h
21

Yes, that is intentional. The -0 is a trick! That avoids the need to check for the definition, because it will be evaluated to as the value of __cplusplus or be 0 due to the expansion to CPP rules and -0.

compnerd updated this revision to Diff 480531.Dec 6 2022, 9:45 AM

Update to avoid use of the -0 trick.

aaron.ballman accepted this revision.Dec 6 2022, 10:29 AM

Thanks for working on this! The changes LGTM. I've been trying to figure out if there's a way we can add test coverage for this change, but I'm really not coming up with much. However, the changes definitely should have a release note.

clang/lib/Headers/stdatomic.h
23

202002l -> 202002L to make it easier on people's eyeballs.

This revision is now accepted and ready to land.Dec 6 2022, 10:29 AM
Mordante accepted this revision.Dec 6 2022, 10:34 AM

LGTM after addressing @aaron.ballman's comments.

clang/lib/Headers/stdatomic.h
21

Ah yes of course. I really prefer the current version without the trick.

fsb4000 accepted this revision.Dec 11 2022, 10:13 PM
This revision was landed with ongoing or failed builds.Dec 15 2022, 1:51 PM
This revision was automatically updated to reflect the committed changes.
gz83 added a subscriber: gz83.Dec 21 2022, 7:28 AM