Author: David Majnemer Date: 2022-08-23T14:29:52Z New Revision: 2c923b88631cda41cbddf58a13ccfb5c04a2fc3c
URL: https://github.com/llvm/llvm-project/commit/2c923b88631cda41cbddf58a13ccfb5c04a2fc3c DIFF: https://github.com/llvm/llvm-project/commit/2c923b88631cda41cbddf58a13ccfb5c04a2fc3c.diff LOG: [clang-cl] Expose the /volatile:{iso,ms} choice via _ISO_VOLATILE MSVC allows interpreting volatile loads and stores, when combined with /volatile:iso, as having acquire/release semantics. MSVC also exposes a define, _ISO_VOLATILE, which allows users to enquire if this feature is enabled or disabled. Added: Modified: clang/include/clang/Basic/CodeGenOptions.def clang/include/clang/Basic/LangOptions.def clang/include/clang/Driver/Options.td clang/lib/Basic/Targets/OSTargets.cpp clang/lib/CodeGen/CGAtomic.cpp clang/test/Preprocessor/predefined-win-macros.c Removed: ################################################################################ diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 0f35420f43133..87c75bb98d433 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -173,7 +173,6 @@ CODEGENOPT(IncrementalLinkerCompatible, 1, 0) ///< Emit an object file which can ///< linker. CODEGENOPT(MergeAllConstants , 1, 1) ///< Merge identical constants. CODEGENOPT(MergeFunctions , 1, 0) ///< Set when -fmerge-functions is enabled. -CODEGENOPT(MSVolatile , 1, 0) ///< Set when /volatile:ms is enabled. CODEGENOPT(NoCommon , 1, 0) ///< Set when -fno-common or C++ is enabled. CODEGENOPT(NoDwarfDirectoryAsm , 1, 0) ///< Set when -fno-dwarf-directory-asm is ///< enabled. diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index ad366821f3cbf..4f3f6fc9da8c0 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -148,6 +148,7 @@ LANGOPT(TraditionalCPP , 1, 0, "traditional CPP emulation") LANGOPT(RTTI , 1, 1, "run-time type information") LANGOPT(RTTIData , 1, 1, "emit run-time type information data") LANGOPT(MSBitfields , 1, 0, "Microsoft-compatible structure layout") +LANGOPT(MSVolatile , 1, 0, "Microsoft-compatible volatile loads and stores") LANGOPT(Freestanding, 1, 0, "freestanding implementation") LANGOPT(NoBuiltin , 1, 0, "disable builtin functions") LANGOPT(NoMathBuiltin , 1, 0, "disable math builtin functions") diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index aadd516cf6209..ec5f553f64584 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2204,7 +2204,7 @@ defm asm_blocks : BoolFOption<"asm-blocks", LangOpts<"AsmBlocks">, Default<fms_extensions.KeyPath>, PosFlag<SetTrue, [CC1Option]>, NegFlag<SetFalse>>; def fms_volatile : Flag<["-"], "fms-volatile">, Group<f_Group>, Flags<[CC1Option]>, - MarshallingInfoFlag<CodeGenOpts<"MSVolatile">>; + MarshallingInfoFlag<LangOpts<"MSVolatile">>; def fmsc_version : Joined<["-"], "fmsc-version=">, Group<f_Group>, Flags<[NoXarchOption, CoreOption]>, HelpText<"Microsoft compiler version number to report in _MSC_VER (0 = don't define it (default))">; def fms_compatibility_version diff --git a/clang/lib/Basic/Targets/OSTargets.cpp b/clang/lib/Basic/Targets/OSTargets.cpp index 5c734024897cb..d11b9f5dbba5a 100644 --- a/clang/lib/Basic/Targets/OSTargets.cpp +++ b/clang/lib/Basic/Targets/OSTargets.cpp @@ -263,6 +263,9 @@ static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder) { } } + if (!Opts.MSVolatile) + Builder.defineMacro("_ISO_VOLATILE"); + if (Opts.Kernel) Builder.defineMacro("_KERNEL_MODE"); diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp index ccc66bc28605f..8ef95bb808468 100644 --- a/clang/lib/CodeGen/CGAtomic.cpp +++ b/clang/lib/CodeGen/CGAtomic.cpp @@ -1594,7 +1594,7 @@ llvm::Value *AtomicInfo::EmitAtomicLoadOp(llvm::AtomicOrdering AO, /// we are operating under /volatile:ms *and* the LValue itself is volatile and /// performing such an operation can be performed without a libcall. bool CodeGenFunction::LValueIsSuitableForInlineAtomic(LValue LV) { - if (!CGM.getCodeGenOpts().MSVolatile) return false; + if (!CGM.getLangOpts().MSVolatile) return false; AtomicInfo AI(*this, LV); bool IsVolatile = LV.isVolatile() || hasVolatileMember(LV.getType()); // An atomic is inline if we don't need to use a libcall. diff --git a/clang/test/Preprocessor/predefined-win-macros.c b/clang/test/Preprocessor/predefined-win-macros.c index df43ae59cef42..f402ce91838d6 100644 --- a/clang/test/Preprocessor/predefined-win-macros.c +++ b/clang/test/Preprocessor/predefined-win-macros.c @@ -5,6 +5,7 @@ // RUN: %clang_cc1 %s -x c++ -E -dM -triple x86_64-pc-win32 -fms-extensions -fms-compatibility \ // RUN: -fms-compatibility-version=19.00 -std=c++14 -o - | grep GCC | count 5 // CHECK-MS64: #define _INTEGRAL_MAX_BITS 64 +// CHECK-MS64: #define _ISO_VOLATILE 1 // CHECK-MS64: #define _MSC_EXTENSIONS 1 // CHECK-MS64: #define _MSC_VER 1900 // CHECK-MS64: #define _MSVC_LANG 201402L @@ -27,6 +28,7 @@ // RUN: %clang_cc1 %s -x c++ -E -dM -triple i686-pc-win32 -fms-extensions -fms-compatibility \ // RUN: -fms-compatibility-version=19.00 -std=c++17 -o - | grep GCC | count 5 // CHECK-MS: #define _INTEGRAL_MAX_BITS 64 +// CHECK-MS: #define _ISO_VOLATILE 1 // CHECK-MS: #define _MSC_EXTENSIONS 1 // CHECK-MS: #define _MSC_VER 1900 // CHECK-MS: #define _MSVC_LANG 201703L _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits