Skip to content

Commit d871919

Browse files
[clang][Driver] Support -fms-volatile as equivalent to /volatile:ms (#74790)
The flag -fms-volatile has existed as a -cc1 flag for a while. It also technically existed as a driver flag, but didn't do anything because it wasn't wired up to anything in the driver. This patch adds -fno-ms-volatile, and makes both -fms-volatile and -fno-ms-volatile work the same way as the cl-mode flags. The defaults are unchanged (default on for x86 in cl mode, default off otherwise).
1 parent f0ac6f9 commit d871919

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,9 +2896,11 @@ defm asm_blocks : BoolFOption<"asm-blocks",
28962896
LangOpts<"AsmBlocks">, Default<fms_extensions.KeyPath>,
28972897
PosFlag<SetTrue, [], [ClangOption, CC1Option]>,
28982898
NegFlag<SetFalse>>;
2899-
def fms_volatile : Flag<["-"], "fms-volatile">, Group<f_Group>,
2900-
Visibility<[ClangOption, CC1Option]>,
2901-
MarshallingInfoFlag<LangOpts<"MSVolatile">>;
2899+
defm ms_volatile : BoolFOption<"ms-volatile",
2900+
LangOpts<"MSVolatile">, DefaultFalse,
2901+
PosFlag<SetTrue, [], [ClangOption, CC1Option],
2902+
"Volatile loads and stores have acquire and release semantics">,
2903+
NegFlag<SetFalse>>;
29022904
def fmsc_version : Joined<["-"], "fmsc-version=">, Group<f_Group>,
29032905
Visibility<[ClangOption, CLOption]>,
29042906
HelpText<"Microsoft compiler version number to report in _MSC_VER (0 = don't define it (default))">;
@@ -8217,7 +8219,7 @@ def _SLASH_winsysroot : CLJoinedOrSeparate<"winsysroot">,
82178219
HelpText<"Same as \"/diasdkdir <dir>/DIA SDK\" /vctoolsdir <dir>/VC/Tools/MSVC/<vctoolsversion> \"/winsdkdir <dir>/Windows Kits/10\"">,
82188220
MetaVarName<"<dir>">;
82198221
def _SLASH_volatile_iso : Option<["/", "-"], "volatile:iso", KIND_FLAG>,
8220-
Group<_SLASH_volatile_Group>, Flags<[NoXarchOption]>, Visibility<[CLOption]>,
8222+
Visibility<[CLOption]>, Alias<fno_ms_volatile>,
82218223
HelpText<"Volatile loads and stores have standard semantics">;
82228224
def _SLASH_vmb : CLFlag<"vmb">,
82238225
HelpText<"Use a best-case representation method for member pointers">;
@@ -8232,7 +8234,7 @@ def _SLASH_vmv : CLFlag<"vmv">,
82328234
HelpText<"Set the default most-general representation to "
82338235
"virtual inheritance">;
82348236
def _SLASH_volatile_ms : Option<["/", "-"], "volatile:ms", KIND_FLAG>,
8235-
Group<_SLASH_volatile_Group>, Flags<[NoXarchOption]>, Visibility<[CLOption]>,
8237+
Visibility<[CLOption]>, Alias<fms_volatile>,
82368238
HelpText<"Volatile loads and stores have acquire and release semantics">;
82378239
def _SLASH_clang : CLJoined<"clang:">,
82388240
HelpText<"Pass <arg> to the clang driver">, MetaVarName<"<arg>">;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5615,6 +5615,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
56155615
options::OPT_fno_auto_import);
56165616
}
56175617

5618+
if (Args.hasFlag(options::OPT_fms_volatile, options::OPT_fno_ms_volatile,
5619+
Triple.isX86() && D.IsCLMode()))
5620+
CmdArgs.push_back("-fms-volatile");
5621+
56185622
// Non-PIC code defaults to -fdirect-access-external-data while PIC code
56195623
// defaults to -fno-direct-access-external-data. Pass the option if different
56205624
// from the default.
@@ -7947,18 +7951,6 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
79477951
CmdArgs.push_back("-P");
79487952
}
79497953

7950-
unsigned VolatileOptionID;
7951-
if (getToolChain().getTriple().isX86())
7952-
VolatileOptionID = options::OPT__SLASH_volatile_ms;
7953-
else
7954-
VolatileOptionID = options::OPT__SLASH_volatile_iso;
7955-
7956-
if (Arg *A = Args.getLastArg(options::OPT__SLASH_volatile_Group))
7957-
VolatileOptionID = A->getOption().getID();
7958-
7959-
if (VolatileOptionID == options::OPT__SLASH_volatile_ms)
7960-
CmdArgs.push_back("-fms-volatile");
7961-
79627954
if (Args.hasFlag(options::OPT__SLASH_Zc_dllexportInlines_,
79637955
options::OPT__SLASH_Zc_dllexportInlines,
79647956
false)) {

clang/test/Driver/cl-options.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,12 @@
272272
// RUN: not %clang_cl /vmg /vmm /vms -### -- %s 2>&1 | FileCheck -check-prefix=VMX %s
273273
// VMX: '/vms' not allowed with '/vmm'
274274

275-
// RUN: %clang_cl /volatile:iso -### -- %s 2>&1 | FileCheck -check-prefix=VOLATILE-ISO %s
275+
// RUN: %clang_cl --target=i686-pc-win32 /volatile:iso -### -- %s 2>&1 | FileCheck -check-prefix=VOLATILE-ISO %s
276+
// RUN: %clang_cl --target=aarch64-pc-win32 -### -- %s 2>&1 | FileCheck -check-prefix=VOLATILE-ISO %s
276277
// VOLATILE-ISO-NOT: "-fms-volatile"
277278

278-
// RUN: %clang_cl /volatile:ms -### -- %s 2>&1 | FileCheck -check-prefix=VOLATILE-MS %s
279+
// RUN: %clang_cl --target=aarch64-pc-win32 /volatile:ms -### -- %s 2>&1 | FileCheck -check-prefix=VOLATILE-MS %s
280+
// RUN: %clang_cl --target=i686-pc-win32 -### -- %s 2>&1 | FileCheck -check-prefix=VOLATILE-MS %s
279281
// VOLATILE-MS: "-fms-volatile"
280282

281283
// RUN: %clang_cl /W0 -### -- %s 2>&1 | FileCheck -check-prefix=W0 %s

clang/test/Driver/clang_f_opts.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,3 +611,9 @@
611611
// CHECK-INT-OBJEMITTER-NOT: unsupported option '-fintegrated-objemitter' for target
612612
// RUN: not %clang -### -fno-integrated-objemitter --target=x86_64 %s 2>&1 | FileCheck -check-prefix=CHECK-NOINT-OBJEMITTER %s
613613
// CHECK-NOINT-OBJEMITTER: unsupported option '-fno-integrated-objemitter' for target
614+
615+
// RUN: %clang -### --target=aarch64-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MS-VOLATILE %s
616+
// RUN: %clang -### --target=aarch64-windows-msvc -fms-volatile %s 2>&1 | FileCheck -check-prefix=CHECK-MS-VOLATILE %s
617+
// RUN: %clang -### --target=aarch64-windows-msvc -fno-ms-volatile %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MS-VOLATILE %s
618+
// CHECK-MS-VOLATILE: -fms-volatile
619+
// CHECK-NO-MS-VOLATILE-NOT: -fms-volatile

0 commit comments

Comments
 (0)