[driver][Darwin] Add an -ibuiltininc flag that lets Darwin driver

include Clang builtin headers even with -nostdinc

Some projects use -nostdinc, but need to access some intrinsics files when building specific files.
The new -ibuiltininc flag lets them use this flag when compiling these files to ensure they can
find Clang's builtin headers.

The use of -nobuiltininc after the -ibuiltininc flag does not add the builtin header
search path to the list of header search paths.

Differential Revision: https://reviews.llvm.org/D73500
This commit is contained in:
Alex Lorenz 2020-01-27 13:01:06 -08:00
parent cd87e207ec
commit f96f64d0f2
3 changed files with 83 additions and 2 deletions

View File

@ -2081,6 +2081,10 @@ def gno_embed_source : Flag<["-"], "gno-embed-source">, Group<g_flags_Group>,
def headerpad__max__install__names : Joined<["-"], "headerpad_max_install_names">;
def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption]>,
HelpText<"Display available options">;
def ibuiltininc : Flag<["-"], "ibuiltininc">,
HelpText<"Enable builtin #include directories even when -nostdinc is used "
"before or after -ibuiltininc. "
"Using -nobuiltininc after the option disables it">;
def index_header_map : Flag<["-"], "index-header-map">, Flags<[CC1Option]>,
HelpText<"Make the next included directory (-I or -F) an indexer header map">;
def idirafter : JoinedOrSeparate<["-"], "idirafter">, Group<clang_i_Group>, Flags<[CC1Option]>,

View File

@ -1870,7 +1870,10 @@ void DarwinClang::AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs
bool NoStdInc = DriverArgs.hasArg(options::OPT_nostdinc);
bool NoStdlibInc = DriverArgs.hasArg(options::OPT_nostdlibinc);
bool NoBuiltinInc = DriverArgs.hasArg(options::OPT_nobuiltininc);
bool NoBuiltinInc = DriverArgs.hasFlag(
options::OPT_nobuiltininc, options::OPT_ibuiltininc, /*Default=*/false);
bool ForceBuiltinInc = DriverArgs.hasFlag(
options::OPT_ibuiltininc, options::OPT_nobuiltininc, /*Default=*/false);
// Add <sysroot>/usr/local/include
if (!NoStdInc && !NoStdlibInc) {
@ -1880,7 +1883,7 @@ void DarwinClang::AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs
}
// Add the Clang builtin headers (<resource>/include)
if (!NoStdInc && !NoBuiltinInc) {
if (!(NoStdInc && !ForceBuiltinInc) && !NoBuiltinInc) {
SmallString<128> P(D.ResourceDir);
llvm::sys::path::append(P, "include");
addSystemInclude(DriverArgs, CC1Args, P);

View File

@ -101,3 +101,77 @@
// CHECK-NOSYSROOT: "-internal-isystem" "/usr/local/include"
// CHECK-NOSYSROOT: "-internal-isystem" "[[RESOURCE]]/include"
// CHECK-NOSYSROOT: "-internal-externc-isystem" "/usr/include"
// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
// RUN: -target x86_64-apple-darwin \
// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_and_usr_local \
// RUN: -nostdinc -ibuiltininc \
// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_and_usr_local \
// RUN: -DRESOURCE=%S/Inputs/resource_dir \
// RUN: --check-prefix=CHECK-NOSTDINC-BUILTINC %s
// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
// RUN: -target x86_64-apple-darwin \
// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_and_usr_local \
// RUN: -ibuiltininc -nostdinc \
// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_and_usr_local \
// RUN: -DRESOURCE=%S/Inputs/resource_dir \
// RUN: --check-prefix=CHECK-NOSTDINC-BUILTINC %s
// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
// RUN: -target x86_64-apple-darwin \
// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_and_usr_local \
// RUN: -nostdinc -nobuiltininc -ibuiltininc \
// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_and_usr_local \
// RUN: -DRESOURCE=%S/Inputs/resource_dir \
// RUN: --check-prefix=CHECK-NOSTDINC-BUILTINC %s
// CHECK-NOSTDINC-BUILTINC: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
// CHECK-NOSTDINC-BUILTINC-NOT: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
// CHECK-NOSTDINC-BUILTINC: "-internal-isystem" "[[RESOURCE]]/include"
// CHECK-NOSTDINC-BUILTINC-NOT: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
// RUN: -target x86_64-apple-darwin \
// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_and_usr_local \
// RUN: -nobuiltininc -ibuiltininc \
// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_and_usr_local \
// RUN: -DRESOURCE=%S/Inputs/resource_dir \
// RUN: --check-prefix=CHECK-NOBUILTININC-BUILTINC %s
// CHECK-NOBUILTININC-BUILTINC: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
// CHECK-NOBUILTININC-BUILTINC: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
// CHECK-NOBUILTININC-BUILTINC: "-internal-isystem" "[[RESOURCE]]/include"
// CHECK-NOBUILTININC-BUILTINC: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
// RUN: -target x86_64-apple-darwin \
// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_and_usr_local \
// RUN: -nostdinc -ibuiltininc -nobuiltininc \
// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_and_usr_local \
// RUN: -DRESOURCE=%S/Inputs/resource_dir \
// RUN: --check-prefix=CHECK-NOSTDINC-NO-BUILTINC %s
// CHECK-NOSTDINC-NO-BUILTINC: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
// CHECK-NOSTDINC-NO-BUILTINC-NOT: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
// CHECK-NOSTDINC-NO-BUILTINC-NOT: "-internal-isystem" "[[RESOURCE]]/include"
// CHECK-NOSTDINC-NO-BUILTINC-NOT: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
// RUN: -target x86_64-apple-darwin \
// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_and_usr_local \
// RUN: -ibuiltininc -nobuiltininc \
// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_and_usr_local \
// RUN: -DRESOURCE=%S/Inputs/resource_dir \
// RUN: --check-prefix=CHECK-BUILTINC-NOBUILTININC %s
// CHECK-BUILTINC-NOBUILTININC: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
// CHECK-BUILTINC-NOBUILTININC: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
// CHECK-BUILTINC-NOBUILTININC-NOT: "-internal-isystem" "[[RESOURCE]]/include"
// CHECK-BUILTINC-NOBUILTININC: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"