Skip to content

Commit 3f2371e

Browse files
authored
[clang-cl] [Driver] Fix clang-cl driver supported colon options (#88216)
Tested locally against msvc 1939. MSVC supports the colon form of various options that take a path even though that isn't documented for all options on MSDN. I added the colon form for all supported msvc options that clang-cl does not intentionally ignore due to being unsupported. I also fixed the existing colon options by ensure we use `JoinedOrSeparate`. `/F[x]` argument must used within the same command line argument. However, `/F[x]:` arguments are allowed to span a command line argument. The following is valid `/F[x]: path` which is 2 separate command line arguments. You can see this documented here, https://learn.microsoft.com/en-us/cpp/build/reference/fo-object-file-name?view=msvc-170, where it says `/Fo:[ ]"pathname"`. This behaviour works for all colon options that take a path and I tested it locally against msvc 1939 for all the option changes in this PR.
1 parent 2b2c4a8 commit 3f2371e

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8346,14 +8346,15 @@ def _SLASH_FI : CLJoinedOrSeparate<"FI">,
83468346
def _SLASH_Fe : CLJoined<"Fe">,
83478347
HelpText<"Set output executable file name">,
83488348
MetaVarName<"<file or dir/>">;
8349-
def _SLASH_Fe_COLON : CLJoined<"Fe:">, Alias<_SLASH_Fe>;
8349+
def _SLASH_Fe_COLON : CLJoinedOrSeparate<"Fe:">, Alias<_SLASH_Fe>;
83508350
def _SLASH_Fi : CLCompileJoined<"Fi">,
83518351
HelpText<"Set preprocess output file name (with /P)">,
83528352
MetaVarName<"<file>">;
8353+
def _SLASH_Fi_COLON : CLJoinedOrSeparate<"Fi:">, Alias<_SLASH_Fi>;
83538354
def _SLASH_Fo : CLCompileJoined<"Fo">,
83548355
HelpText<"Set output object file (with /c)">,
83558356
MetaVarName<"<file or dir/>">;
8356-
def _SLASH_Fo_COLON : CLCompileJoined<"Fo:">, Alias<_SLASH_Fo>;
8357+
def _SLASH_Fo_COLON : CLCompileJoinedOrSeparate<"Fo:">, Alias<_SLASH_Fo>;
83578358
def _SLASH_guard : CLJoined<"guard:">,
83588359
HelpText<"Enable Control Flow Guard with /guard:cf, or only the table with /guard:cf,nochecks. "
83598360
"Enable EH Continuation Guard with /guard:ehcont">;
@@ -8448,6 +8449,7 @@ def _SLASH_Zc_dllexportInlines_ : CLFlag<"Zc:dllexportInlines-">,
84488449
HelpText<"Do not dllexport/dllimport inline member functions of dllexport/import classes">;
84498450
def _SLASH_Fp : CLJoined<"Fp">,
84508451
HelpText<"Set pch file name (with /Yc and /Yu)">, MetaVarName<"<file>">;
8452+
def _SLASH_Fp_COLON : CLJoinedOrSeparate<"Fp:">, Alias<_SLASH_Fp>;
84518453

84528454
def _SLASH_Gd : CLFlag<"Gd">,
84538455
HelpText<"Set __cdecl as a default calling convention">;

clang/test/Driver/cl-outputs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118

119119
// RUN: %clang_cl /Fefoo.ext -### -- %s 2>&1 | FileCheck -check-prefix=FeEXT %s
120120
// RUN: %clang_cl /Fe:foo.ext -### -- %s 2>&1 | FileCheck -check-prefix=FeEXT %s
121+
// RUN: %clang_cl /Fe: foo.ext -### -- %s 2>&1 | FileCheck -check-prefix=FeEXT %s
121122
// FeEXT: "-out:foo.ext"
122123

123124
// RUN: %clang_cl /LD /Fefoo.ext -### -- %s 2>&1 | FileCheck -check-prefix=FeEXTDLL %s
@@ -270,6 +271,8 @@
270271
// P: "-o" "cl-outputs.i"
271272

272273
// RUN: %clang_cl /P /Fifoo -### -- %s 2>&1 | FileCheck -check-prefix=Fi1 %s
274+
// RUN: %clang_cl /P /Fi:foo -### -- %s 2>&1 | FileCheck -check-prefix=Fi1 %s
275+
// RUN: %clang_cl /P /Fi: foo -### -- %s 2>&1 | FileCheck -check-prefix=Fi1 %s
273276
// Fi1: "-E"
274277
// Fi1: "-o" "foo.i"
275278

@@ -302,6 +305,7 @@
302305
// RELATIVE_OBJPATH1: "-object-file-name=a.obj"
303306

304307
// RUN: %clang_cl -fdebug-compilation-dir=. /Z7 /Fo:a.obj -### -- %s 2>&1 | FileCheck -check-prefix=RELATIVE_OBJPATH1_COLON %s
308+
// RUN: %clang_cl -fdebug-compilation-dir=. /Z7 /Fo: a.obj -### -- %s 2>&1 | FileCheck -check-prefix=RELATIVE_OBJPATH1_COLON %s
305309
// RELATIVE_OBJPATH1_COLON: "-object-file-name=a.obj"
306310

307311
// RUN: %clang_cl -fdebug-compilation-dir=. /Z7 /Fofoo/a.obj -### -- %s 2>&1 | FileCheck -check-prefix=RELATIVE_OBJPATH2 %s

clang/test/Driver/cl-pch.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@
9999
// /Yu /Fpout.pch => out.pch is filename
100100
// RUN: %clang_cl -Werror /Yupchfile.h /FIpchfile.h /Fpout.pch /c -### -- %s 2>&1 \
101101
// RUN: | FileCheck -check-prefix=CHECK-YUFP1 %s
102+
// /Yu /Fp:out.pch => out.pch is filename
103+
// RUN: %clang_cl -Werror /Yupchfile.h /FIpchfile.h /Fp:out.pch /c -### -- %s 2>&1 \
104+
// RUN: | FileCheck -check-prefix=CHECK-YUFP1 %s
105+
// /Yu /Fp: out.pch => out.pch is filename
106+
// RUN: %clang_cl -Werror /Yupchfile.h /FIpchfile.h /Fp: out.pch /c -### -- %s 2>&1 \
107+
// RUN: | FileCheck -check-prefix=CHECK-YUFP1 %s
102108
// Use .pch file, but don't build it.
103109
// CHECK-YUFP1: -include-pch
104110
// CHECK-YUFP1: out.pch

0 commit comments

Comments
 (0)