diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2024-04-26 12:05:15 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-26 12:05:15 -0400 |
commit | 72c373bfdc9860b3d75e72c219b2c81c90bc4364 (patch) | |
tree | f660b39fa237cb7f7b71ae7b04a1d8a3ff6d1be4 /clang/lib/Frontend/InitPreprocessor.cpp | |
parent | 0620a637e362d1add1fe506307a25d0353e254f5 (diff) | |
download | llvm-72c373bfdc9860b3d75e72c219b2c81c90bc4364.zip llvm-72c373bfdc9860b3d75e72c219b2c81c90bc4364.tar.gz llvm-72c373bfdc9860b3d75e72c219b2c81c90bc4364.tar.bz2 |
[C++17] Support __GCC_[CON|DE]STRUCTIVE_SIZE (#89446)
These macros are used by STL implementations to support implementation
of std::hardware_destructive_interference_size and
std::hardware_constructive_interference_size
Fixes #60174
---------
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
Diffstat (limited to 'clang/lib/Frontend/InitPreprocessor.cpp')
-rw-r--r-- | clang/lib/Frontend/InitPreprocessor.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 6bdd734..745d1a5 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1308,6 +1308,16 @@ static void InitializePredefinedMacros(const TargetInfo &TI, Builder.defineMacro("__GCC_ATOMIC_TEST_AND_SET_TRUEVAL", "1"); } + // GCC defines these macros in both C and C++ modes despite them being needed + // mostly for STL implementations in C++. + auto [Destructive, Constructive] = TI.hardwareInterferenceSizes(); + Builder.defineMacro("__GCC_DESTRUCTIVE_SIZE", Twine(Destructive)); + Builder.defineMacro("__GCC_CONSTRUCTIVE_SIZE", Twine(Constructive)); + // We need to use push_macro to allow users to redefine these macros from the + // command line with -D and not issue a -Wmacro-redefined warning. + Builder.append("#pragma push_macro(\"__GCC_DESTRUCTIVE_SIZE\")"); + Builder.append("#pragma push_macro(\"__GCC_CONSTRUCTIVE_SIZE\")"); + auto addLockFreeMacros = [&](const llvm::Twine &Prefix) { // Used by libc++ and libstdc++ to implement ATOMIC_<foo>_LOCK_FREE. #define DEFINE_LOCK_FREE_MACRO(TYPE, Type) \ |