[RISCV][FMV] Support target_clones (#85786)
[llvm-project.git] / clang / test / Driver / mingw-sysroot.cpp
blobde5cdedcbff1df1c1fd1eed2832bbd61d3677bfe
1 // REQUIRES: shell
2 // UNSUPPORTED: system-windows
4 // RUN: rm -rf %T/testroot-gcc
5 // RUN: mkdir -p %T/testroot-gcc/bin
6 // RUN: ln -s %clang %T/testroot-gcc/bin/x86_64-w64-mingw32-gcc
7 // RUN: ln -s %clang %T/testroot-gcc/bin/x86_64-w64-mingw32-clang
8 // RUN: ln -s %S/Inputs/mingw_ubuntu_posix_tree/usr/x86_64-w64-mingw32 %T/testroot-gcc/x86_64-w64-mingw32
9 // RUN: ln -s %S/Inputs/mingw_ubuntu_posix_tree/usr/lib %T/testroot-gcc/lib
11 // RUN: rm -rf %T/testroot-clang
12 // RUN: mkdir -p %T/testroot-clang/bin
13 // RUN: ln -s %clang %T/testroot-clang/bin/x86_64-w64-mingw32-clang
14 // RUN: ln -s %S/Inputs/mingw_ubuntu_posix_tree/usr/x86_64-w64-mingw32 %T/testroot-clang/x86_64-w64-mingw32
15 // RUN: ln -s %S/Inputs/mingw_arch_tree/usr/i686-w64-mingw32 %T/testroot-clang/i686-w64-mingw32
17 // RUN: rm -rf %T/testroot-clang-native
18 // RUN: mkdir -p %T/testroot-clang-native/bin
19 // RUN: ln -s %clang %T/testroot-clang-native/bin/clang
20 // RUN: mkdir -p %T/testroot-clang-native/include/_mingw.h
21 // RUN: mkdir -p %T/testroot-clang-native/lib/libkernel32.a
23 // RUN: rm -rf %T/testroot-custom-triple
24 // RUN: mkdir -p %T/testroot-custom-triple/bin
25 // RUN: ln -s %clang %T/testroot-custom-triple/bin/clang
26 // RUN: ln -s %S/Inputs/mingw_ubuntu_posix_tree/usr/x86_64-w64-mingw32 %T/testroot-custom-triple/x86_64-w64-mingw32foo
28 // If we find a gcc in the path with the right triplet prefix, pick that as
29 // sysroot:
31 // This test is only executed on non-Windows systems, i.e. only when
32 // cross compiling. Check that we don't add the tool root's plain include
33 // directory to the path - this would end up including /usr/include for
34 // cross toolchains installed in /usr.
36 // RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" %clang --target=x86_64-w64-mingw32 -rtlib=platform -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_GCC %s --implicit-check-not="\"{{.*}}/testroot-gcc{{/|\\\\}}include\""
37 // CHECK_TESTROOT_GCC: "-internal-isystem" "[[BASE:[^"]+]]/testroot-gcc{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}10.2-posix{{/|\\\\}}include{{/|\\\\}}c++"
38 // CHECK_TESTROOT_GCC-SAME: {{^}} "-internal-isystem" "[[BASE]]/testroot-gcc{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}10.2-posix{{/|\\\\}}include{{/|\\\\}}c++{{/|\\\\}}x86_64-w64-mingw32"
39 // CHECK_TESTROOT_GCC-SAME: {{^}} "-internal-isystem" "[[BASE]]/testroot-gcc{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}10.2-posix{{/|\\\\}}include{{/|\\\\}}c++{{/|\\\\}}backward"
40 // CHECK_TESTROOT_GCC: "-internal-isystem" "[[BASE]]/testroot-gcc{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}10.2-posix{{/|\\\\}}include{{/|\\\\}}g++-v10.2-posix"
41 // CHECK_TESTROOT_GCC: "-internal-isystem" "[[BASE]]/testroot-gcc{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}10.2-posix{{/|\\\\}}include{{/|\\\\}}g++-v10.2"
42 // CHECK_TESTROOT_GCC: "-internal-isystem" "[[BASE]]/testroot-gcc{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}10.2-posix{{/|\\\\}}include{{/|\\\\}}g++-v10"
43 // CHECK_TESTROOT_GCC: "-internal-isystem" "[[BASE]]/testroot-gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}include"
46 // If we pass --sysroot explicitly, then we do include <sysroot>/include
47 // even when cross compiling.
48 // RUN: %clang --target=x86_64-w64-mingw32 -rtlib=platform -stdlib=libstdc++ --sysroot="%T/testroot-gcc" -c -### %s 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_GCC_EXPLICIT %s
50 // CHECK_TESTROOT_GCC_EXPLICIT: "-internal-isystem" "{{[^"]+}}/testroot-gcc{{/|\\\\}}include"
53 // If -no-canonical-prefixes and there's a matching sysroot next to the clang binary itself, prefer that
54 // over a gcc in the path:
56 // RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" %T/testroot-clang/bin/x86_64-w64-mingw32-clang --target=x86_64-w64-mingw32 -rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_GCC2 %s
57 // RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" %T/testroot-clang/bin/x86_64-w64-mingw32-clang --target=x86_64-w64-mingw32 -rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s -no-canonical-prefixes 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_CLANG %s
58 // CHECK_TESTROOT_GCC2: "{{[^"]+}}/testroot-gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}include"
59 // CHECK_TESTROOT_CLANG: "{{[^"]+}}/testroot-clang{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}include"
62 // If we pick a root based on a sysroot next to the clang binary, which also
63 // happens to be in the same directory as gcc, make sure we still can pick up
64 // the libgcc directory:
66 // RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" %T/testroot-gcc/bin/x86_64-w64-mingw32-clang --target=x86_64-w64-mingw32 -rtlib=platform -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_GCC %s
69 // If we're executing clang from a directory with what looks like a mingw sysroot,
70 // with headers in <base>/include and libs in <base>/lib, use that rather than looking
71 // for another GCC in the path.
73 // Note, this test has a surprising quirk: We're testing with an install directory,
74 // testroot-clang-native, which lacks the "x86_64-w64-mingw32" subdirectory, it only
75 // has the include and lib subdirectories without any triple prefix.
77 // Since commit fd15cb935d7aae25ad62bfe06fe9f17cea585978, we avoid using the
78 // <base>/include and <base>/lib directories when cross compiling. So technically, this
79 // case testcase only works exactly as expected when running on x86_64 Windows, when
80 // this target isn't considered cross compiling.
82 // However we do still pass the include directory <base>/x86_64-w64-mingw32/include to
83 // the -cc1 interface, even if it is missing. Thus, this test looks for this path name,
84 // that indicates that we did choose the right base, even if this particular directory
85 // actually doesn't exist here.
87 // RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" %T/testroot-clang-native/bin/clang -no-canonical-prefixes --target=x86_64-w64-mingw32 -rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_CLANG_NATIVE %s
88 // CHECK_TESTROOT_CLANG_NATIVE: "{{[^"]+}}/testroot-clang-native{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}include"
91 // If the user requests a different arch via the -m32 option, which changes
92 // x86_64 into i386, check that the driver notices that it can't find a
93 // sysroot for i386 but there is one for i686, and uses that one.
94 // (In practice, the real usecase is when using an unprefixed native clang
95 // that defaults to x86_64 mingw, but it's easier to test this in cross setups
96 // with symlinks, like the other tests here.)
98 // RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" %T/testroot-clang/bin/x86_64-w64-mingw32-clang -no-canonical-prefixes --target=x86_64-w64-mingw32 -m32 -rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_CLANG_I686 %s
99 // CHECK_TESTROOT_CLANG_I686: "{{[^"]+}}/testroot-clang{{/|\\\\}}i686-w64-mingw32{{/|\\\\}}include"
102 // If the user calls clang with a custom literal triple, make sure this maps
103 // to sysroots with the matching spelling.
105 // RUN: %T/testroot-custom-triple/bin/clang -no-canonical-prefixes --target=x86_64-w64-mingw32foo -rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_CUSTOM_TRIPLE %s
106 // CHECK_TESTROOT_CUSTOM_TRIPLE: "{{[^"]+}}/testroot-custom-triple{{/|\\\\}}x86_64-w64-mingw32foo{{/|\\\\}}include"