1 // UNSUPPORTED: system-windows 2 3 // General tests that the header search paths for libc++ detected by the driver 4 // and passed to CC1 are correct on Darwin platforms. 5 6 // Check without a sysroot and without headers alongside the installation 7 // (no include path should be added, and no warning or error). 8 // 9 // RUN: %clang -### %s -fsyntax-only 2>&1 \ 10 // RUN: --target=x86_64-apple-darwin \ 11 // RUN: -stdlib=libc++ \ 12 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \ 13 // RUN: | FileCheck --check-prefix=CHECK-LIBCXX-NONE %s 14 // CHECK-LIBCXX-NONE: "-cc1" 15 16 // Check with only headers alongside the installation (those should be used). 17 // 18 // RUN: %clang -### %s -fsyntax-only 2>&1 \ 19 // RUN: --target=x86_64-apple-darwin \ 20 // RUN: -stdlib=libc++ \ 21 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \ 22 // RUN: --sysroot="" \ 23 // RUN: | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \ 24 // RUN: --check-prefix=CHECK-LIBCXX-TOOLCHAIN-1 %s 25 // CHECK-LIBCXX-TOOLCHAIN-1: "-cc1" 26 // CHECK-LIBCXX-TOOLCHAIN-1: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" 27 // CHECK-LIBCXX-TOOLCHAIN-1-NOT: "-internal-isystem" "/usr/include/c++/v1" 28 // 29 // RUN: %clang -### %s -fsyntax-only 2>&1 \ 30 // RUN: --target=x86_64-apple-darwin \ 31 // RUN: -stdlib=libc++ \ 32 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \ 33 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_no_libcxx \ 34 // RUN: | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \ 35 // RUN: -DSYSROOT=%S/Inputs/basic_darwin_sdk_no_libcxx \ 36 // RUN: --check-prefix=CHECK-LIBCXX-TOOLCHAIN-2 %s 37 // CHECK-LIBCXX-TOOLCHAIN-2: "-cc1" 38 // CHECK-LIBCXX-TOOLCHAIN-2: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" 39 // CHECK-LIBCXX-TOOLCHAIN-2-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1" 40 41 // Check with only headers in the sysroot (those should be used). 42 // 43 // RUN: %clang -### %s -fsyntax-only 2>&1 \ 44 // RUN: --target=x86_64-apple-darwin \ 45 // RUN: -stdlib=libc++ \ 46 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \ 47 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_cxx_v1 \ 48 // RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_cxx_v1 \ 49 // RUN: -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx \ 50 // RUN: --check-prefix=CHECK-LIBCXX-SYSROOT-1 %s 51 // CHECK-LIBCXX-SYSROOT-1: "-cc1" 52 // CHECK-LIBCXX-SYSROOT-1: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1" 53 // CHECK-LIBCXX-SYSROOT-1-NOT: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" 54 55 // Check with both headers in the sysroot and headers alongside the installation 56 // (the headers in the toolchain should be preferred over the <sysroot> headers). 57 // Ensure that both -isysroot and --sysroot work, and that isysroot has precedence 58 // over --sysroot. 59 // 60 // RUN: %clang -### %s -fsyntax-only 2>&1 \ 61 // RUN: --target=x86_64-apple-darwin \ 62 // RUN: -stdlib=libc++ \ 63 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \ 64 // RUN: -resource-dir=%S/Inputs/resource_dir \ 65 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_cxx_v1 \ 66 // RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_cxx_v1 \ 67 // RUN: -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \ 68 // RUN: --check-prefix=CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1 %s 69 // 70 // RUN: %clang -### %s -fsyntax-only 2>&1 \ 71 // RUN: --target=x86_64-apple-darwin \ 72 // RUN: -stdlib=libc++ \ 73 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \ 74 // RUN: -resource-dir=%S/Inputs/resource_dir \ 75 // RUN: --sysroot %S/Inputs/basic_darwin_sdk_usr_cxx_v1 \ 76 // RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_cxx_v1 \ 77 // RUN: -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \ 78 // RUN: --check-prefix=CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1 %s 79 // 80 // RUN: %clang -### %s -fsyntax-only 2>&1 \ 81 // RUN: --target=x86_64-apple-darwin \ 82 // RUN: -stdlib=libc++ \ 83 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \ 84 // RUN: -resource-dir=%S/Inputs/resource_dir \ 85 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_cxx_v1 \ 86 // RUN: --sysroot %S/Inputs/basic_darwin_sdk_no_libcxx \ 87 // RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_cxx_v1 \ 88 // RUN: -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \ 89 // RUN: --check-prefix=CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1 %s 90 // 91 // CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-cc1" 92 // CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" 93 // CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1" 94 95 // Make sure that using -nostdinc, -nostdinc++ or -nostdlib will drop both the toolchain 96 // C++ include path and the sysroot one. 97 // 98 // RUN: %clang -### %s -fsyntax-only 2>&1 \ 99 // RUN: --target=x86_64-apple-darwin16 \ 100 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \ 101 // RUN: -resource-dir=%S/Inputs/resource_dir \ 102 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr \ 103 // RUN: -stdlib=platform \ 104 // RUN: -nostdinc \ 105 // RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \ 106 // RUN: -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \ 107 // RUN: --check-prefix=CHECK-LIBCXX-NOSTDLIBINC %s 108 // CHECK-LIBCXX-NOSTDINC: "-cc1" 109 // CHECK-LIBCXX-NOSTDINC-NOT: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" 110 // CHECK-LIBCXX-NOSTDINC-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1" 111 // 112 // RUN: %clang -### %s -fsyntax-only 2>&1 \ 113 // RUN: --target=x86_64-apple-darwin16 \ 114 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \ 115 // RUN: -resource-dir=%S/Inputs/resource_dir \ 116 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_cxx_v1 \ 117 // RUN: -stdlib=platform \ 118 // RUN: -nostdinc++ \ 119 // RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \ 120 // RUN: -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \ 121 // RUN: --check-prefix=CHECK-LIBCXX-NOSTDINCXX %s 122 // CHECK-LIBCXX-NOSTDINCXX: "-cc1" 123 // CHECK-LIBCXX-NOSTDINCXX-NOT: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" 124 // CHECK-LIBCXX-NOSTDINCXX-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1" 125 // 126 // RUN: %clang -### %s -fsyntax-only 2>&1 \ 127 // RUN: --target=x86_64-apple-darwin16 \ 128 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \ 129 // RUN: -resource-dir=%S/Inputs/resource_dir \ 130 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr \ 131 // RUN: -stdlib=platform \ 132 // RUN: -nostdlibinc \ 133 // RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \ 134 // RUN: -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \ 135 // RUN: --check-prefix=CHECK-LIBCXX-NOSTDLIBINC %s 136 // CHECK-LIBCXX-NOSTDLIBINC: "-cc1" 137 // CHECK-LIBCXX-NOSTDLIBINC-NOT: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" 138 // CHECK-LIBCXX-NOSTDLIBINC-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1" 139 140 // Make sure we explain that we considered a path but didn't add it when it 141 // doesn't exist. 142 // 143 // RUN: %clang %s -fsyntax-only -v 2>&1 \ 144 // RUN: --target=x86_64-apple-darwin \ 145 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \ 146 // RUN: -isysroot %S/Inputs/basic_darwin_sdk \ 147 // RUN: -stdlib=libc++ \ 148 // RUN: | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx \ 149 // RUN: --check-prefix=CHECK-LIBCXX-MISSING-TOOLCHAIN %s 150 // CHECK-LIBCXX-MISSING-TOOLCHAIN: ignoring nonexistent directory "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" 151 // 152 // RUN: %clang %s -fsyntax-only -v 2>&1 \ 153 // RUN: --target=x86_64-apple-darwin \ 154 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \ 155 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_no_libcxx \ 156 // RUN: -stdlib=libc++ \ 157 // RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_no_libcxx \ 158 // RUN: -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx \ 159 // RUN: --check-prefix=CHECK-LIBCXX-MISSING-BOTH %s 160 // CHECK-LIBCXX-MISSING-BOTH: ignoring nonexistent directory "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" 161 // CHECK-LIBCXX-MISSING-BOTH: ignoring nonexistent directory "[[SYSROOT]]/usr/include/c++/v1" 162 163 // Make sure that on Darwin, we use libc++ header search paths by default even when 164 // -stdlib= isn't passed. 165 // 166 // RUN: %clang -### %s -fsyntax-only 2>&1 \ 167 // RUN: --target=x86_64-apple-darwin \ 168 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \ 169 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_cxx_v1 \ 170 // RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_cxx_v1 \ 171 // RUN: -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx \ 172 // RUN: --check-prefix=CHECK-LIBCXX-STDLIB-UNSPECIFIED %s 173 // CHECK-LIBCXX-STDLIB-UNSPECIFIED: "-cc1" 174 // CHECK-LIBCXX-STDLIB-UNSPECIFIED: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1" 175 176 // ---------------------------------------------------------------------------- 177 // On Darwin, libc++ can be installed in one of the following places: 178 // 1. Alongside the compiler in <install>/include/c++/v1 179 // 2. Alongside the compiler in <clang-executable-folder>/../include/c++/v1 180 // 3. In a SDK (or a custom sysroot) in <sysroot>/usr/include/c++/v1 181 182 // The build folders do not have an `include/c++/v1`; create a new 183 // local folder hierarchy that meets this requirement. 184 // Note: this might not work with weird RPATH configurations. 185 // RUN: rm -rf %t/install 186 // RUN: mkdir -p %t/install/bin 187 // RUN: cp %clang %t/install/bin/clang 188 // RUN: mkdir -p %t/install/include/c++/v1 189 190 // Headers in (1) and in (2) -> (1) is preferred over (2) 191 // RUN: rm -rf %t/symlinked1 192 // RUN: mkdir -p %t/symlinked1/bin 193 // RUN: ln -sf %t/install/bin/clang %t/symlinked1/bin/clang 194 // RUN: mkdir -p %t/symlinked1/include/c++/v1 195 196 // RUN: %t/symlinked1/bin/clang -### %s -no-canonical-prefixes -fsyntax-only 2>&1 \ 197 // RUN: --target=x86_64-apple-darwin \ 198 // RUN: -stdlib=libc++ \ 199 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_cxx_v1 \ 200 // RUN: | FileCheck -DSYMLINKED=%t/symlinked1 \ 201 // RUN: -DTOOLCHAIN=%t/install \ 202 // RUN: -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_cxx_v1 \ 203 // RUN: --check-prefix=CHECK-SYMLINKED-INCLUDE-CXX-V1 %s 204 // CHECK-SYMLINKED-INCLUDE-CXX-V1: "-internal-isystem" "[[SYMLINKED]]/bin/../include/c++/v1" 205 // CHECK-SYMLINKED-INCLUDE-CXX-V1-NOT: "-internal-isystem" "[[TOOLCHAIN]]/bin/../include/c++/v1" 206 // CHECK-SYMLINKED-INCLUDE-CXX-V1-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1" 207 208 // Headers in (2) and in (3) -> (2) is preferred over (3) 209 // RUN: rm -rf %t/symlinked2 210 // RUN: mkdir -p %t/symlinked2/bin 211 // RUN: ln -sf %t/install/bin/clang %t/symlinked2/bin/clang 212 213 // RUN: %t/symlinked2/bin/clang -### %s -fsyntax-only 2>&1 \ 214 // RUN: --target=x86_64-apple-darwin \ 215 // RUN: -stdlib=libc++ \ 216 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_cxx_v1 \ 217 // RUN: | FileCheck -DTOOLCHAIN=%t/install \ 218 // RUN: -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_cxx_v1 \ 219 // RUN: --check-prefix=CHECK-TOOLCHAIN-INCLUDE-CXX-V1 %s 220 // CHECK-TOOLCHAIN-INCLUDE-CXX-V1: "-internal-isystem" "[[TOOLCHAIN]]/bin/../include/c++/v1" 221 // CHECK-TOOLCHAIN-INCLUDE-CXX-V1-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1" 222 223 // Headers in (2) and nowhere else -> (2) is used 224 // RUN: %t/symlinked2/bin/clang -### %s -fsyntax-only 2>&1 \ 225 // RUN: --target=x86_64-apple-darwin \ 226 // RUN: -stdlib=libc++ \ 227 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_cxx_v1 \ 228 // RUN: | FileCheck -DTOOLCHAIN=%t/install \ 229 // RUN: -DSYSROOT=%S/Inputs/basic_darwin_sdk_no_libcxx \ 230 // RUN: --check-prefix=CHECK-TOOLCHAIN-NO-SYSROOT %s 231 // CHECK-TOOLCHAIN-NO-SYSROOT: "-internal-isystem" "[[TOOLCHAIN]]/bin/../include/c++/v1" 232