This is an archive of the discontinued LLVM Phabricator instance.

Use `<stdatomic.h>` with MSVC and C++
ClosedPublic

Authored by fsb4000 on Jul 23 2022, 4:44 AM.

Details

Reviewers
aaron.ballman
Mordante
Group Reviewers
Restricted Project
Restricted Project
Commits
rGba49d39b20cc: Use `<stdatomic.h>` with MSVC and C++
Summary

and use fallback only for C.

It fixes the isssue with clang-cl:

#include <stdatomic.h>
#include <stdbool.h>
#ifdef __cplusplus
#include <atomic>
using namespace std;
#endif

int main() {
    atomic_bool b = true;
}
$ clang-cl /TC main.cpp
# works
$ clang-cl /TP /std:c++20 main.cpp

stdatomic.h(70,6): error: conflicting types for 'atomic_thread_fence'
void atomic_thread_fence(memory_order);
     ^
atomic(166,24): note: previous definition is here
extern "C" inline void atomic_thread_fence(const memory_order _Order) noexcept {

...

fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

Many errors but
<stdatomic.h> has many macros to built-in functions.

#define atomic_thread_fence(order) __c11_atomic_thread_fence(order)

and MSVC <atomic> has real functions.
and the built-in functions are redefined.

Diff Detail

Event Timeline

fsb4000 created this revision.Jul 23 2022, 4:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 23 2022, 4:44 AM
fsb4000 requested review of this revision.Jul 23 2022, 4:44 AM
fsb4000 added reviewers: Restricted Project, Restricted Project.Jul 23 2022, 4:45 AM
fsb4000 added a project: Restricted Project.

Why did x64 debian tests fail?

Why did x64 debian tests fail?

openmp build is broken on linux pre-commit CI right now. Not related to your patch.

Good. Thanks!

Can you add a dummy file in the libc++ subdirectory? That should trigger the libc++ pre-commit CI.

fsb4000 updated this revision to Diff 447163.Jul 24 2022, 6:11 PM

added a dummy.txt in libcxx directory

Herald added 1 blocking reviewer(s): Restricted Project. · View Herald TranscriptJul 24 2022, 6:11 PM
aaron.ballman accepted this revision.Jul 25 2022, 8:23 AM
aaron.ballman added a subscriber: aaron.ballman.

LGTM (be sure to drop the dummy file before landing), but please add a release note mentioning the fix as well.

fsb4000 updated this revision to Diff 447377.Jul 25 2022, 9:39 AM

drop the dummy file and update the release notes.

drop the dummy file and update the release notes.

Thanks! I forgot to ask -- do you need someone to commit on your behalf? If so, what name and email address would you like used for patch attribution?

Mordante accepted this revision.Jul 25 2022, 9:58 AM

drop the dummy file and update the release notes.

Thanks! I forgot to ask -- do you need someone to commit on your behalf? If so, what name and email address would you like used for patch attribution?

Thanks for asking. I just discussed with fsb4000 and I'll land it after updating the backticks in the documentation.

This revision is now accepted and ready to land.Jul 25 2022, 9:58 AM

drop the dummy file and update the release notes.

Thanks! I forgot to ask -- do you need someone to commit on your behalf? If so, what name and email address would you like used for patch attribution?

Thanks for asking. I just discussed with fsb4000 and I'll land it after updating the backticks in the documentation.

Fantastic, thank you! And thank you @fsb4000 for the fix!

fsb4000 updated this revision to Diff 447388.EditedJul 25 2022, 9:59 AM

Thanks. I already asked Mark de Wever. (Mordante)

My name, email: Igor Zhukov <fsb4000@yandex.ru>

This revision was landed with ongoing or failed builds.Jul 25 2022, 10:00 AM
This revision was automatically updated to reflect the committed changes.