Skip to content

Commit fd3e1ad

Browse files
committed
clang-cl: Remove -isystem, add -imsvc.
r260990 exposed -isystem in clang-cl. -isystem adds a directory to the front of the system include search path. The idea was to use this to point to a hermetic msvc install, but as it turns out this doesn't work: -isystem then adds the hermetic headers in front of clang's builtin headers, and clang's headers that are supposed to wrap msvc headers (say, stdarg.h) aren't picked up at all anymore. So revert that, and instead expose -imsvc which works as if the passed directory was part of %INCLUDE%: The header is treated as a system header, but it is searched after clang's lib/Header headers. Fixes half of PRPR26751. llvm-svn: 266108
1 parent b7b6d0f commit fd3e1ad

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

clang/include/clang/Driver/CLCompatOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ def _SLASH_GX : CLFlag<"GX">,
210210
HelpText<"Enable exception handling">;
211211
def _SLASH_GX_ : CLFlag<"GX-">,
212212
HelpText<"Enable exception handling">;
213+
def _SLASH_imsvc : CLJoinedOrSeparate<"imsvc">,
214+
HelpText<"Add directory to system include search path, as if part of %INCLUDE%">,
215+
MetaVarName<"<dir>">;
213216
def _SLASH_LD : CLFlag<"LD">, HelpText<"Create DLL">;
214217
def _SLASH_LDd : CLFlag<"LDd">, HelpText<"Create debug DLL">;
215218
def _SLASH_link : CLRemainingArgs<"link">,

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ def iquote : JoinedOrSeparate<["-"], "iquote">, Group<clang_i_Group>, Flags<[CC1
12541254
def isysroot : JoinedOrSeparate<["-"], "isysroot">, Group<clang_i_Group>, Flags<[CC1Option]>,
12551255
HelpText<"Set the system root directory (usually /)">, MetaVarName<"<dir>">;
12561256
def isystem : JoinedOrSeparate<["-"], "isystem">, Group<clang_i_Group>,
1257-
Flags<[CC1Option, CoreOption]>,
1257+
Flags<[CC1Option]>,
12581258
HelpText<"Add directory to SYSTEM include search path">, MetaVarName<"<directory>">;
12591259
def iwithprefixbefore : JoinedOrSeparate<["-"], "iwithprefixbefore">, Group<clang_i_Group>,
12601260
HelpText<"Set directory to include search path with prefix">, MetaVarName<"<dir>">,

clang/lib/Driver/MSVCToolChain.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,10 @@ void MSVCToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
527527
"include");
528528
}
529529

530+
// Add %INCLUDE%-like directories from the -imsvc flag.
531+
for (const auto &Path : DriverArgs.getAllArgValues(options::OPT__SLASH_imsvc))
532+
addSystemInclude(DriverArgs, CC1Args, Path);
533+
530534
if (DriverArgs.hasArg(options::OPT_nostdlibinc))
531535
return;
532536

clang/test/Driver/cl-options.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@
8282
// RUN: %clang_cl /I myincludedir -### -- %s 2>&1 | FileCheck -check-prefix=SLASH_I %s
8383
// SLASH_I: "-I" "myincludedir"
8484

85+
// RUN: %clang_cl /imsvcmyincludedir -### -- %s 2>&1 | FileCheck -check-prefix=SLASH_imsvc %s
86+
// RUN: %clang_cl /imsvc myincludedir -### -- %s 2>&1 | FileCheck -check-prefix=SLASH_imsvc %s
87+
// Clang's resource header directory should be first:
88+
// SLASH_imsvc: "-internal-isystem" "{{[^"]*}}lib{{.}}clang{{[^"]*}}include"
89+
// SLASH_imsvc: "-internal-isystem" "myincludedir"
90+
8591
// RUN: %clang_cl /J -### -- %s 2>&1 | FileCheck -check-prefix=J %s
8692
// J: -fno-signed-char
8793

@@ -452,7 +458,6 @@
452458
// RUN: -fno-ms-compatibility \
453459
// RUN: -fms-extensions \
454460
// RUN: -fno-ms-extensions \
455-
// RUN: -isystem=some/path \
456461
// RUN: -mllvm -disable-llvm-optzns \
457462
// RUN: -Wunused-variable \
458463
// RUN: -fmacro-backtrace-limit=0 \

clang/test/Driver/cl-pch-search.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,3 @@
44
// REQUIRES: x86-registered-target
55
// Check that pchfile.h next to to pchfile.cc is found correctly.
66
// RUN: %clang_cl -Werror /Ycpchfile.h /FIpchfile.h /c /Fo%t.obj /Fp%t.pch -- %S/Inputs/pchfile.cpp
7-
8-
// Check that i_group flags other than -include aren't skipped (e.g. -isystem).
9-
#include "header0.h"
10-
// RUN: %clang_cl -Werror -isystem%S/Inputs /Yupchfile.h /FIpchfile.h /c /Fo%t.obj /Fp%t.pch -- %s

0 commit comments

Comments
 (0)