2 // REQUIRES: x86-registered-target
4 // RUN: unset CLANG_NO_DEFAULT_CONFIG
5 // RUN: rm -rf %t && mkdir %t
7 //--- If config file is specified by relative path (workdir/cfg-s2), it is searched for by that path.
9 // RUN: mkdir -p %t/workdir/subdir
10 // RUN: echo "@subdir/cfg-s2" > %t/workdir/cfg-1
11 // RUN: echo "-Wundefined-var-template" > %t/workdir/subdir/cfg-s2
13 // RUN: ( cd %t && %clang --config=workdir/cfg-1 -c -### %s 2>&1 | FileCheck %s -check-prefix CHECK-REL )
15 // CHECK-REL: Configuration file: {{.*}}/workdir/cfg-1
16 // CHECK-REL: -Wundefined-var-template
18 //--- Config files are searched for in binary directory as well.
20 // RUN: mkdir %t/testbin
21 // RUN: ln -s %clang %t/testbin/clang
22 // RUN: echo "-Werror" > %t/testbin/aaa.cfg
23 // RUN: %t/testbin/clang --config-system-dir= --config-user-dir= --config=aaa.cfg -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-BIN
25 // CHECK-BIN: Configuration file: {{.*}}/testbin/aaa.cfg
28 //--- Invocation x86_64-unknown-linux-gnu-clang-g++ tries x86_64-unknown-linux-gnu-clang++.cfg first.
30 // RUN: mkdir %t/testdmode
31 // RUN: ln -s %clang %t/testdmode/cheribsd-riscv64-hybrid-clang++
32 // RUN: ln -s %clang %t/testdmode/qqq-clang-g++
33 // RUN: ln -s %clang %t/testdmode/x86_64-clang
34 // RUN: ln -s %clang %t/testdmode/i386-unknown-linux-gnu-clang-g++
35 // RUN: ln -s %clang %t/testdmode/x86_64-unknown-linux-gnu-clang-g++
36 // RUN: ln -s %clang %t/testdmode/x86_64-unknown-linux-gnu-clang
37 // RUN: touch %t/testdmode/cheribsd-riscv64-hybrid-clang++.cfg
38 // RUN: touch %t/testdmode/cheribsd-riscv64-hybrid.cfg
39 // RUN: touch %t/testdmode/qqq-clang-g++.cfg
40 // RUN: touch %t/testdmode/qqq.cfg
41 // RUN: touch %t/testdmode/x86_64-clang.cfg
42 // RUN: touch %t/testdmode/x86_64.cfg
43 // RUN: touch %t/testdmode/x86_64-unknown-linux-gnu-clang++.cfg
44 // RUN: touch %t/testdmode/x86_64-unknown-linux-gnu-clang-g++.cfg
45 // RUN: touch %t/testdmode/x86_64-unknown-linux-gnu-clang.cfg
46 // RUN: touch %t/testdmode/x86_64-unknown-linux-gnu.cfg
47 // RUN: touch %t/testdmode/i386-unknown-linux-gnu-clang++.cfg
48 // RUN: touch %t/testdmode/i386-unknown-linux-gnu-clang-g++.cfg
49 // RUN: touch %t/testdmode/i386-unknown-linux-gnu-clang.cfg
50 // RUN: touch %t/testdmode/i386-unknown-linux-gnu.cfg
51 // RUN: touch %t/testdmode/clang++.cfg
52 // RUN: touch %t/testdmode/clang-g++.cfg
53 // RUN: touch %t/testdmode/clang.cfg
54 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL1 --implicit-check-not 'Configuration file:'
56 // FULL1: Configuration file: {{.*}}/testdmode/x86_64-unknown-linux-gnu-clang++.cfg
58 //--- -m32 overrides triple.
60 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ -m32 --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL1-I386 --implicit-check-not 'Configuration file:'
62 // FULL1-I386: Configuration file: {{.*}}/testdmode/i386-unknown-linux-gnu-clang++.cfg
64 //--- --target= also works for overriding triple.
66 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ --target=i386-unknown-linux-gnu --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL1-I386 --implicit-check-not 'Configuration file:'
68 //--- With --target= + -m64, -m64 takes precedence.
70 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ --target=i386-unknown-linux-gnu -m64 --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL1 --implicit-check-not 'Configuration file:'
72 //--- i386 prefix also works for 32-bit.
74 // RUN: %t/testdmode/i386-unknown-linux-gnu-clang-g++ --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL1-I386 --implicit-check-not 'Configuration file:'
76 //--- i386 prefix + -m64 also works for 64-bit.
78 // RUN: %t/testdmode/i386-unknown-linux-gnu-clang-g++ -m64 --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL1 --implicit-check-not 'Configuration file:'
80 //--- File specified by --config= is loaded after the one inferred from the executable.
82 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ --config-system-dir=%S/Inputs/config --config-user-dir= --config=i386-qqq.cfg -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix EXPLICIT --implicit-check-not 'Configuration file:'
84 // EXPLICIT: Configuration file: {{.*}}/testdmode/x86_64-unknown-linux-gnu-clang++.cfg
85 // EXPLICIT-NEXT: Configuration file: {{.*}}/Inputs/config/i386-qqq.cfg
87 //--- --no-default-config --config= loads only specified file.
89 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ --config-system-dir=%S/Inputs/config --config-user-dir= --no-default-config --config=i386-qqq.cfg -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix EXPLICIT-ONLY --implicit-check-not 'Configuration file:'
91 // EXPLICIT-ONLY: Configuration file: {{.*}}/Inputs/config/i386-qqq.cfg
93 //--- --no-default-config disables default filenames.
95 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ --config-system-dir=%S/Inputs/config --config-user-dir= --no-default-config -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix NO-CONFIG
97 // NO-CONFIG-NOT: Configuration file:
99 //--- --driver-mode= is respected.
101 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ --driver-mode=gcc --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL1-GCC --implicit-check-not 'Configuration file:'
103 // FULL1-GCC: Configuration file: {{.*}}/testdmode/x86_64-unknown-linux-gnu-clang.cfg
105 //--- "clang" driver symlink should yield the "*-clang" configuration file.
107 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL1-GCC --implicit-check-not 'Configuration file:'
109 //--- "clang" + --driver-mode= should yield "*-clang++".
111 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang --driver-mode=g++ --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL1 --implicit-check-not 'Configuration file:'
113 //--- Clang started via name prefix that is not valid is forcing that prefix instead of target triple.
115 // RUN: %t/testdmode/qqq-clang-g++ --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix QQQ --implicit-check-not 'Configuration file:'
117 // QQQ: Configuration file: {{.*}}/testdmode/qqq-clang-g++.cfg
119 //--- Explicit --target= overrides the triple even with non-standard name prefix.
121 // RUN: %t/testdmode/qqq-clang-g++ --target=x86_64-unknown-linux-gnu --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL1 --implicit-check-not 'Configuration file:'
123 //--- "x86_64" prefix does not form a valid triple either.
125 // RUN: %t/testdmode/x86_64-clang --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix X86_64 --implicit-check-not 'Configuration file:'
127 // X86_64: Configuration file: {{.*}}/testdmode/x86_64-clang.cfg
129 //--- Try cheribsd prefix using misordered triple components.
131 // RUN: %t/testdmode/cheribsd-riscv64-hybrid-clang++ --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix CHERIBSD --implicit-check-not 'Configuration file:'
133 // CHERIBSD: Configuration file: {{.*}}/testdmode/cheribsd-riscv64-hybrid-clang++.cfg
135 //--- Test fallback to x86_64-unknown-linux-gnu-clang-g++.cfg.
137 // RUN: rm %t/testdmode/x86_64-unknown-linux-gnu-clang++.cfg
138 // RUN: rm %t/testdmode/i386-unknown-linux-gnu-clang++.cfg
139 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL2 --implicit-check-not 'Configuration file:'
141 // FULL2: Configuration file: {{.*}}/testdmode/x86_64-unknown-linux-gnu-clang-g++.cfg
145 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ -m32 --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL2-I386 --implicit-check-not 'Configuration file:'
147 // FULL2-I386: Configuration file: {{.*}}/testdmode/i386-unknown-linux-gnu-clang-g++.cfg
149 //--- Test fallback to x86_64-unknown-linux-gnu-clang.cfg + clang++.cfg.
151 // RUN: rm %t/testdmode/cheribsd-riscv64-hybrid-clang++.cfg
152 // RUN: rm %t/testdmode/qqq-clang-g++.cfg
153 // RUN: rm %t/testdmode/x86_64-clang.cfg
154 // RUN: rm %t/testdmode/x86_64-unknown-linux-gnu-clang-g++.cfg
155 // RUN: rm %t/testdmode/i386-unknown-linux-gnu-clang-g++.cfg
156 // RUN: rm %t/testdmode/x86_64-unknown-linux-gnu-clang.cfg
157 // RUN: rm %t/testdmode/i386-unknown-linux-gnu-clang.cfg
158 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL3 --implicit-check-not 'Configuration file:'
160 // FULL3: Configuration file: {{.*}}/testdmode/clang++.cfg
161 // FULL3: Configuration file: {{.*}}/testdmode/x86_64-unknown-linux-gnu.cfg
165 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ -m32 --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL3-I386 --implicit-check-not 'Configuration file:'
167 // FULL3-I386: Configuration file: {{.*}}/testdmode/clang++.cfg
168 // FULL3-I386: Configuration file: {{.*}}/testdmode/i386-unknown-linux-gnu.cfg
170 //--- FULL3 + --driver-mode=.
172 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ --driver-mode=gcc --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL3-GCC --implicit-check-not 'Configuration file:'
174 // FULL3-GCC: Configuration file: {{.*}}/testdmode/clang.cfg
175 // FULL3-GCC: Configuration file: {{.*}}/testdmode/x86_64-unknown-linux-gnu.cfg
179 // RUN: %t/testdmode/qqq-clang-g++ --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix QQQ-FALLBACK --implicit-check-not 'Configuration file:'
181 // QQQ-FALLBACK: Configuration file: {{.*}}/testdmode/clang++.cfg
182 // QQQ-FALLBACK: Configuration file: {{.*}}/testdmode/qqq.cfg
184 //--- "x86_64" falback.
186 // RUN: %t/testdmode/x86_64-clang --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix X86_64-FALLBACK --implicit-check-not 'Configuration file:'
188 // X86_64-FALLBACK: Configuration file: {{.*}}/testdmode/clang.cfg
189 // X86_64-FALLBACK: Configuration file: {{.*}}/testdmode/x86_64.cfg
191 //--- cheribsd fallback.
193 // RUN: %t/testdmode/cheribsd-riscv64-hybrid-clang++ --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix CHERIBSD-FALLBACK --implicit-check-not 'Configuration file:'
195 // CHERIBSD-FALLBACK: Configuration file: {{.*}}/testdmode/clang++.cfg
196 // CHERIBSD-FALLBACK: Configuration file: {{.*}}/testdmode/cheribsd-riscv64-hybrid.cfg
198 //--- Test fallback to x86_64-unknown-linux-gnu.cfg + clang-g++.cfg.
200 // RUN: rm %t/testdmode/clang++.cfg
201 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL4 --implicit-check-not 'Configuration file:'
203 // FULL4: Configuration file: {{.*}}/testdmode/clang-g++.cfg
204 // FULL4: Configuration file: {{.*}}/testdmode/x86_64-unknown-linux-gnu.cfg
206 //--- Test fallback to clang-g++.cfg if x86_64-unknown-linux-gnu-clang.cfg does not exist.
208 // RUN: rm %t/testdmode/x86_64-unknown-linux-gnu.cfg
209 // RUN: rm %t/testdmode/i386-unknown-linux-gnu.cfg
210 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL5 --implicit-check-not 'Configuration file:'
212 // FULL5: Configuration file: {{.*}}/testdmode/clang-g++.cfg
216 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ -m32 --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL5-I386 --implicit-check-not 'Configuration file:'
218 // FULL5-I386: Configuration file: {{.*}}/testdmode/clang-g++.cfg
220 //--- Test that incorrect driver mode config file is not used.
222 // RUN: rm %t/testdmode/clang-g++.cfg
223 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix NO-CONFIG
225 //--- Tilde expansion in user configuration file directory
227 // RUN: HOME=%S/Inputs/config %clang -### --config-user-dir=~ -v 2>&1 | FileCheck %s --check-prefix=CHECK-TILDE
228 // CHECK-TILDE: User configuration file directory: {{.*}}/Inputs/config