diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2081,6 +2081,10 @@ 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, Flags<[CC1Option]>, diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -1870,7 +1870,10 @@ 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 /usr/local/include if (!NoStdInc && !NoStdlibInc) { @@ -1880,7 +1883,7 @@ } // Add the Clang builtin headers (/include) - if (!NoStdInc && !NoBuiltinInc) { + if (!(NoStdInc && !ForceBuiltinInc) && !NoBuiltinInc) { SmallString<128> P(D.ResourceDir); llvm::sys::path::append(P, "include"); addSystemInclude(DriverArgs, CC1Args, P); diff --git a/clang/test/Driver/darwin-header-search-system.cpp b/clang/test/Driver/darwin-header-search-system.cpp --- a/clang/test/Driver/darwin-header-search-system.cpp +++ b/clang/test/Driver/darwin-header-search-system.cpp @@ -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"