Skip to content

Commit 476402a

Browse files
committed
[clang][Driver] Support -fms-volatile as equivalent to /volatile:ms
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 04cbfcc commit 476402a

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
@@ -2869,9 +2869,11 @@ defm asm_blocks : BoolFOption<"asm-blocks",
28692869
LangOpts<"AsmBlocks">, Default<fms_extensions.KeyPath>,
28702870
PosFlag<SetTrue, [], [ClangOption, CC1Option]>,
28712871
NegFlag<SetFalse>>;
2872-
def fms_volatile : Flag<["-"], "fms-volatile">, Group<f_Group>,
2873-
Visibility<[ClangOption, CC1Option]>,
2874-
MarshallingInfoFlag<LangOpts<"MSVolatile">>;
2872+
defm ms_volatile : BoolFOption<"ms-volatile",
2873+
LangOpts<"MSVolatile">, DefaultFalse,
2874+
PosFlag<SetTrue, [], [ClangOption, CC1Option],
2875+
"Volatile loads and stores have acquire and release semantics">,
2876+
NegFlag<SetFalse>>;
28752877
def fmsc_version : Joined<["-"], "fmsc-version=">, Group<f_Group>,
28762878
Visibility<[ClangOption, CLOption]>,
28772879
HelpText<"Microsoft compiler version number to report in _MSC_VER (0 = don't define it (default))">;
@@ -8184,7 +8186,7 @@ def _SLASH_winsysroot : CLJoinedOrSeparate<"winsysroot">,
81848186
HelpText<"Same as \"/diasdkdir <dir>/DIA SDK\" /vctoolsdir <dir>/VC/Tools/MSVC/<vctoolsversion> \"/winsdkdir <dir>/Windows Kits/10\"">,
81858187
MetaVarName<"<dir>">;
81868188
def _SLASH_volatile_iso : Option<["/", "-"], "volatile:iso", KIND_FLAG>,
8187-
Group<_SLASH_volatile_Group>, Flags<[NoXarchOption]>, Visibility<[CLOption]>,
8189+
Visibility<[CLOption]>, Alias<fno_ms_volatile>,
81888190
HelpText<"Volatile loads and stores have standard semantics">;
81898191
def _SLASH_vmb : CLFlag<"vmb">,
81908192
HelpText<"Use a best-case representation method for member pointers">;
@@ -8199,7 +8201,7 @@ def _SLASH_vmv : CLFlag<"vmv">,
81998201
HelpText<"Set the default most-general representation to "
82008202
"virtual inheritance">;
82018203
def _SLASH_volatile_ms : Option<["/", "-"], "volatile:ms", KIND_FLAG>,
8202-
Group<_SLASH_volatile_Group>, Flags<[NoXarchOption]>, Visibility<[CLOption]>,
8204+
Visibility<[CLOption]>, Alias<fms_volatile>,
82038205
HelpText<"Volatile loads and stores have acquire and release semantics">;
82048206
def _SLASH_clang : CLJoined<"clang:">,
82058207
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
@@ -5545,6 +5545,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
55455545
options::OPT_fno_auto_import);
55465546
}
55475547

5548+
if (Args.hasFlag(options::OPT_fms_volatile, options::OPT_fno_ms_volatile,
5549+
Triple.isX86() && D.IsCLMode()))
5550+
CmdArgs.push_back("-fms-volatile");
5551+
55485552
// Non-PIC code defaults to -fdirect-access-external-data while PIC code
55495553
// defaults to -fno-direct-access-external-data. Pass the option if different
55505554
// from the default.
@@ -7877,18 +7881,6 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
78777881
CmdArgs.push_back("-P");
78787882
}
78797883

7880-
unsigned VolatileOptionID;
7881-
if (getToolChain().getTriple().isX86())
7882-
VolatileOptionID = options::OPT__SLASH_volatile_ms;
7883-
else
7884-
VolatileOptionID = options::OPT__SLASH_volatile_iso;
7885-
7886-
if (Arg *A = Args.getLastArg(options::OPT__SLASH_volatile_Group))
7887-
VolatileOptionID = A->getOption().getID();
7888-
7889-
if (VolatileOptionID == options::OPT__SLASH_volatile_ms)
7890-
CmdArgs.push_back("-fms-volatile");
7891-
78927884
if (Args.hasFlag(options::OPT__SLASH_Zc_dllexportInlines_,
78937885
options::OPT__SLASH_Zc_dllexportInlines,
78947886
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)