407 lines · cpp
1// Note: %s and %S must be preceded by --, otherwise it may be interpreted as a2// command-line option, e.g. on Mac where %s is commonly under /Users.3 4// /Yc5// RUN: %clang_cl -Werror /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \6// RUN: | FileCheck -check-prefix=CHECK-YC %s7// 1. Build .pch file.8// CHECK-YC: cc19// CHECK-YC: -emit-pch10// CHECK-YC: -building-pch-with-obj11// CHECK-YC: -o12// CHECK-YC: pchfile.pch13// CHECK-YC: -x14// CHECK-YC: "c++-header"15// 2. Use .pch file.16// CHECK-YC: cc117// CHECK-YC: -emit-obj18// CHECK-YC: -building-pch-with-obj19// CHECK-YC: -include-pch20// CHECK-YC: pchfile.pch21 22// /Yc /Fo23// /Fo overrides the .obj output filename, but not the .pch filename24// RUN: %clang_cl -Werror /Fomyobj.obj /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \25// RUN: | FileCheck -check-prefix=CHECK-YCO %s26// 1. Build .pch file.27// CHECK-YCO: cc128// CHECK-YCO: -emit-pch29// CHECK-YCO: -building-pch-with-obj30// CHECK-YCO: -o31// CHECK-YCO: pchfile.pch32// 2. Use .pch file.33// CHECK-YCO: cc134// CHECK-YCO: -emit-obj35// CHECK-YCO: -building-pch-with-obj36// CHECK-YCO: -include-pch37// CHECK-YCO: pchfile.pch38// CHECK-YCO: -o39// CHECK-YCO: myobj.obj40 41// /Yc /Y-42// /Y- disables pch generation43// RUN: %clang_cl -Werror /Y- /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \44// RUN: | FileCheck -check-prefix=CHECK-YC-Y_ %s45// CHECK-YC-Y_-NOT: -emit-pch46// CHECK-YC-Y_-NOT: -include-pch47 48// /Yu49// RUN: %clang_cl -Werror /Yupchfile.h /FIpchfile.h /c -### -- %s 2>&1 \50// RUN: | FileCheck -check-prefix=CHECK-YU %s51// Use .pch file, but don't build it.52// CHECK-YU-NOT: -emit-pch53// CHECK-YU-NOT: -building-pch-with-obj54// CHECK-YU: cc155// CHECK-YU: -emit-obj56// CHECK-YU: -include-pch57// CHECK-YU: pchfile.pch58 59// /Yu /Y-60// RUN: %clang_cl -Werror /Y- /Yupchfile.h /FIpchfile.h /c -### -- %s 2>&1 \61// RUN: | FileCheck -check-prefix=CHECK-YU-Y_ %s62// CHECK-YU-Y_-NOT: -emit-pch63// CHECK-YU-Y_-NOT: -include-pch64 65// /Yc /Yu -- /Yc overrides /Yc if they both refer to the same file66// RUN: %clang_cl -Werror /Ycpchfile.h /Yupchfile.h /FIpchfile.h /c -### -- %s 2>&1 \67// RUN: | FileCheck -check-prefix=CHECK-YC-YU %s68// 1. Build .pch file.69// CHECK-YC-YU: cc170// CHECK-YC-YU: -emit-pch71// CHECK-YC-YU: -building-pch-with-obj72// CHECK-YC-YU: -o73// CHECK-YC-YU: pchfile.pch74// 2. Use .pch file.75// CHECK-YC-YU: cc176// CHECK-YC-YU: -emit-obj77// CHECK-YC-YU: -include-pch78// CHECK-YC-YU: pchfile.pch79 80// If /Yc /Yu refer to different files, semantics are pretty wonky. Since this81// doesn't seem like something that's important in practice, just punt for now.82// RUN: not %clang_cl -Werror /Ycfoo1.h /Yufoo2.h /FIfoo1.h /FIfoo2.h /c -### -- %s 2>&1 \83// RUN: | FileCheck -check-prefix=CHECK-YC-YU-MISMATCH %s84// CHECK-YC-YU-MISMATCH: error: support for '/Yc' and '/Yu' with different filenames not implemented yet; flags ignored85 86// Similarly, punt on /Yc with more than one input file.87// RUN: not %clang_cl -Werror /Ycfoo1.h /FIfoo1.h /c -### -- %s %s 2>&1 \88// RUN: | FileCheck -check-prefix=CHECK-YC-MULTIINPUT %s89// CHECK-YC-MULTIINPUT: error: support for '/Yc' with more than one source file not implemented yet; flag ignored90 91// /Yc /Yu /Y-92// RUN: %clang_cl -Werror /Ycpchfile.h /Yupchfile.h /FIpchfile.h /Y- /c -### -- %s 2>&1 \93// RUN: | FileCheck -check-prefix=CHECK-YC-YU-Y_ %s94// CHECK-YC-YU-Y_-NOT: -emit-pch95// CHECK-YC-YU-Y_-NOT: -include-pch96 97// Test computation of pch filename in various cases.98 99// /Yu /Fpout.pch => out.pch is filename100// RUN: %clang_cl -Werror /Yupchfile.h /FIpchfile.h /Fpout.pch /c -### -- %s 2>&1 \101// RUN: | FileCheck -check-prefix=CHECK-YUFP1 %s102// /Yu /Fp:out.pch => out.pch is filename103// RUN: %clang_cl -Werror /Yupchfile.h /FIpchfile.h /Fp:out.pch /c -### -- %s 2>&1 \104// RUN: | FileCheck -check-prefix=CHECK-YUFP1 %s105// /Yu /Fp: out.pch => out.pch is filename106// RUN: %clang_cl -Werror /Yupchfile.h /FIpchfile.h /Fp: out.pch /c -### -- %s 2>&1 \107// RUN: | FileCheck -check-prefix=CHECK-YUFP1 %s108// Use .pch file, but don't build it.109// CHECK-YUFP1: -include-pch110// CHECK-YUFP1: out.pch111 112// /Yu /Fpout => out.pch is filename (.pch gets added if no extension present)113// RUN: %clang_cl -Werror /Yupchfile.h /FIpchfile.h /Fpout.pch /c -### -- %s 2>&1 \114// RUN: | FileCheck -check-prefix=CHECK-YUFP2 %s115// Use .pch file, but don't build it.116// CHECK-YUFP2: -include-pch117// CHECK-YUFP2: out.pch118 119// /Yu /Fpout.bmp => out.bmp is filename (.pch not added when extension present)120// RUN: %clang_cl -Werror /Yupchfile.h /FIpchfile.h /Fpout.bmp /c -### -- %s 2>&1 \121// RUN: | FileCheck -check-prefix=CHECK-YUFP3 %s122// Use .pch file, but don't build it.123// CHECK-YUFP3: -include-pch124// CHECK-YUFP3: out.bmp125 126// /Yusub/dir.h => sub/dir.pch127// RUN: %clang_cl -Werror /Yusub/pchfile.h /FIsub/pchfile.h /c -### -- %s 2>&1 \128// RUN: | FileCheck -check-prefix=CHECK-YUFP4 %s129// Use .pch file, but don't build it.130// CHECK-YUFP4: -include-pch131// CHECK-YUFP4: sub/pchfile.pch132 133// /Yudir.h /Isub => dir.pch134// RUN: %clang_cl -Werror /Yupchfile.h /FIpchfile.h /Isub /c -### -- %s 2>&1 \135// RUN: | FileCheck -check-prefix=CHECK-YUFP5 %s136// Use .pch file, but don't build it.137// CHECK-YUFP5: -include-pch138// CHECK-YUFP5: pchfile.pch139 140// FIXME: /Fpdir: use dir/VCx0.pch when dir is directory, where x is major MSVS141// version in use.142 143// Spot-check one use of /Fp with /Yc too, else trust the /Yu test cases above144// also all assume to /Yc.145// RUN: %clang_cl -Werror /Ycpchfile.h /FIpchfile.h /Fpsub/file.pch /c -### -- %s 2>&1 \146// RUN: | FileCheck -check-prefix=CHECK-YCFP %s147// 1. Build .pch file.148// CHECK-YCFP: cc1149// CHECK-YCFP: -emit-pch150// CHECK-YCFP: -o151// CHECK-YCFP: sub/file.pch152// 2. Use .pch file.153// CHECK-YCFP: cc1154// CHECK-YCFP: -emit-obj155// CHECK-YCFP: -include-pch156// CHECK-YCFP: sub/file.pch157 158// /Ycfoo2.h /FIfoo1.h /FIfoo2.h /FIfoo3.h159// => foo1 and foo2 go into pch, foo3 into main compilation160// /Yc161// RUN: %clang_cl -Werror /Ycfoo2.h /FIfoo1.h /FIfoo2.h /FIfoo3.h /c -### -- %s 2>&1 \162// RUN: | FileCheck -check-prefix=CHECK-YCFIFIFI %s163// 1. Build .pch file: Includes foo1.h (but NOT foo3.h) and compiles foo2.h164// CHECK-YCFIFIFI: cc1165// CHECK-YCFIFIFI: -emit-pch166// CHECK-YCFIFIFI: -pch-through-header=foo2.h167// CHECK-YCFIFIFI: -include168// CHECK-YCFIFIFI: foo1.h169// CHECK-YCFIFIFI: -include170// CHECK-YCFIFIFI: foo2.h171// CHECK-YCFIFIFI: -include172// CHECK-YCFIFIFI: foo3.h173// CHECK-YCFIFIFI: -o174// CHECK-YCFIFIFI: foo2.pch175// CHECK-YCFIFIFI: -x176// CHECK-YCFIFIFI: "c++-header"177// CHECK-YCFIFIFI: cl-pch.cpp178// 2. Use .pch file: Inlucdes foo2.pch and foo3.h179// CHECK-YCFIFIFI: cc1180// CHECK-YCFIFIFI: -emit-obj181// CHECK-YCFIFIFI: -include-pch182// CHECK-YCFIFIFI: foo2.pch183// CHECK-YCFIFIFI: -pch-through-header=foo2.h184// CHECK-YCFIFIFI: -include185// CHECK-YCFIFIFI: foo1.h186// CHECK-YCFIFIFI: -include187// CHECK-YCFIFIFI: foo2.h188// CHECK-YCFIFIFI: -include189// CHECK-YCFIFIFI: foo3.h190// CHECK-YCFIFIFI: -o191// CHECK-YCFIFIFI: cl-pch.obj192// CHECK-YCFIFIFI: -x193// CHECK-YCFIFIFI: "c++"194// CHECK-YCFIFIFI: cl-pch.cpp195 196// /Yufoo2.h /FIfoo1.h /FIfoo2.h /FIfoo3.h197// => foo1 foo2 filtered out, foo3 into main compilation198// RUN: %clang_cl -Werror /Yufoo2.h /FIfoo1.h /FIfoo2.h /FIfoo3.h /c -### -- %s 2>&1 \199// RUN: | FileCheck -check-prefix=CHECK-YUFIFIFI %s200// Use .pch file, but don't build it.201// CHECK-YUFIFIFI-NOT: -emit-pch202// CHECK-YUFIFIFI: cc1203// CHECK-YUFIFIFI: -emit-obj204// CHECK-YUFIFIFI: -include-pch205// CHECK-YUFIFIFI: foo2.pch206// CHECK-YUFIFIFI: -pch-through-header=foo2.h207// CHECK-YUFIFIFI: -include208// CHECK-YUFIFIFI: foo1.h209// CHECK-YUFIFIFI: -include210// CHECK-YUFIFIFI: foo2.h211// CHECK-YUFIFIFI: -include212// CHECK-YUFIFIFI: foo3.h213 214// Test /Ycfoo.h / /Yufoo.h without /FIfoo.h215// RUN: %clang_cl -Werror /Ycfoo.h /c -### -- %s 2>&1 \216// RUN: | FileCheck -check-prefix=CHECK-YC-NOFI %s217// 1. Precompile218// CHECK-YC-NOFI: cc1219// CHECK-YC-NOFI: -emit-pch220// CHECK-YC-NOFI: -pch-through-header=foo.h221// CHECK-YC-NOFI: -o222// CHECK-YC-NOFI: foo.pch223// CHECK-YC-NOFI: -x224// CHECK-YC-NOFI: c++-header225// CHECK-YC-NOFI: cl-pch.cpp226// 2. Build PCH object227// CHECK-YC-NOFI: cc1228// CHECK-YC-NOFI: -emit-obj229// CHECK-YC-NOFI: -include-pch230// CHECK-YC-NOFI: foo.pch231// CHECK-YC-NOFI: -pch-through-header=foo.h232// CHECK-YC-NOFI: -x233// CHECK-YC-NOFI: c++234// CHECK-YC-NOFI: cl-pch.cpp235// RUN: %clang_cl -Werror /Yufoo.h /c -### -- %s 2>&1 \236// RUN: | FileCheck -check-prefix=CHECK-YU-NOFI %s237// CHECK-YU-NOFI: cc1238// CHECK-YU-NOFI: -emit-obj239// CHECK-YU-NOFI: -include-pch240// CHECK-YU-NOFI: foo.pch241// CHECK-YU-NOFI: -pch-through-header=foo.h242// CHECK-YU-NOFI: -x243// CHECK-YU-NOFI: c++244// CHECK-YU-NOFI: cl-pch.cpp245 246// With an actual /I argument.247// RUN: %clang_cl -Werror /Ifoo /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \248// RUN: | FileCheck -check-prefix=CHECK-YC-I3 %s249// 1. This writes pchfile.pch into the root dir, even if this will pick up250// foo/pchfile.h251// CHECK-YC-I3: cc1252// CHECK-YC-I3: -emit-pch253// CHECK-YC-I3: -o254// CHECK-YC-I3: pchfile.pch255// 2. Use .pch file.256// CHECK-YC-I3: cc1257// CHECK-YC-I3: -emit-obj258// CHECK-YC-I3: -include-pch259// CHECK-YC-I3: pchfile.pch260 261// But /FIfoo/bar.h /Ycfoo\bar.h does work, as does /FIfOo.h /Ycfoo.H262// RUN: %clang_cl -Werror /YupchFILE.h /FI./pchfile.h /c -### -- %s 2>&1 \263// RUN: | FileCheck -check-prefix=CHECK-YU-CASE %s264// CHECK-YU-CASE: -pch-through-header=pchFILE.h265// CHECK-YU-CASE: -include266// CHECK-YU-CASE: "./pchfile.h"267// RUN: %clang_cl -Werror /Yu./pchfile.h /FI.\\pchfile.h /c -### -- %s 2>&1 \268// RUN: | FileCheck -check-prefix=CHECK-YU-SLASH %s269// CHECK-YU-SLASH: -pch-through-header=./pchfile.h270// CHECK-YU-SLASH: -include271// CHECK-YU-SLASH: ".{{[/\\]+}}pchfile.h"272 273// /Yc without an argument creates a PCH from the code before #pragma hdrstop.274// /Yu without an argument uses a PCH and starts compiling after the275// #pragma hdrstop.276// RUN: %clang_cl -Werror /Yc /Fpycnoarg.pch /c -### -- %s 2>&1 \277// RUN: | FileCheck -check-prefix=CHECK-YC-NOARG %s278// 1. Create .pch file279// CHECK-YC-NOARG: cc1280// CHECK-YC-NOARG: -emit-pch281// CHECK-YC-NOARG: -pch-through-hdrstop-create282// CHECK-YC-NOARG: -o283// CHECK-YC-NOARG: ycnoarg.pch284// CHECK-YC-NOARG: -x285// CHECK-YC-NOARG: "c++-header"286// CHECK-YC-NOARG: cl-pch.cpp287// 2. Use .pch file: Includes ycnoarg.pch288// CHECK-YC-NOARG: cc1289// CHECK-YC-NOARG: -emit-obj290// CHECK-YC-NOARG: -include-pch291// CHECK-YC-NOARG: ycnoarg.pch292// CHECK-YC-NOARG: -pch-through-hdrstop-create293// CHECK-YC-NOARG: -o294// CHECK-YC-NOARG: cl-pch.obj295// CHECK-YC-NOARG: -x296// CHECK-YC-NOARG: "c++"297// CHECK-YC-NOARG: cl-pch.cpp298 299// RUN: %clang_cl -Werror /Yu /Fpycnoarg.pch /c -### -- %s 2>&1 \300// RUN: | FileCheck -check-prefix=CHECK-YU-NOARG %s301// Use .pch file, but don't build it.302// CHECK-YU-NOARG-NOT: -emit-pch303// CHECK-YU-NOARG: cc1304// CHECK-YU-NOARG: -emit-obj305// CHECK-YU-NOARG: -include-pch306// CHECK-YU-NOARG: ycnoarg.pch307// CHECK-YU-NOARG: -pch-through-hdrstop-use308// CHECK-YU-NOARG: -o309// CHECK-YU-NOARG: cl-pch.obj310// CHECK-YU-NOARG: -x311// CHECK-YU-NOARG: "c++"312// CHECK-YU-NOARG: cl-pch.cpp313 314// /Yc with no argument and no /FP315// RUN: %clang_cl -Werror /Yc /c -### -- %s 2>&1 \316// RUN: | FileCheck -check-prefix=CHECK-YC-NOARG-NOFP %s317// 1. Create .pch file318// CHECK-YC-NOARG-NOFP: cc1319// CHECK-YC-NOARG-NOFP: -emit-pch320// CHECK-YC-NOARG-NOFP: -pch-through-hdrstop-create321// CHECK-YC-NOARG-NOFP: -o322// CHECK-YC-NOARG-NOFP: cl-pch.pch323// CHECK-YC-NOARG-NOFP: -x324// CHECK-YC-NOARG-NOFP: "c++-header"325// CHECK-YC-NOARG-NOFP: cl-pch.cpp326// 2. Use .pch file: Includes cl-pch.pch327// CHECK-YC-NOARG-NOFP: cc1328// CHECK-YC-NOARG-NOFP: -emit-obj329// CHECK-YC-NOARG-NOFP: -include-pch330// CHECK-YC-NOARG-NOFP: cl-pch.pch331// CHECK-YC-NOARG-NOFP: -pch-through-hdrstop-create332// CHECK-YC-NOARG-NOFP: -o333// CHECK-YC-NOARG-NOFP: cl-pch.obj334// CHECK-YC-NOARG-NOFP: -x335// CHECK-YC-NOARG-NOFP: "c++"336// CHECK-YC-NOARG-NOFP: cl-pch.cpp337 338// cl.exe warns on multiple /Yc, /Yu, /Fp arguments, but clang-cl silently just339// uses the last one. This is true for e.g. /Fo too, so not warning on this340// is self-consistent with clang-cl's flag handling.341 342// /FI without /Yu => pch file not used, even if it exists (different from343// -include, which picks up .gch files if they exist).344// RUN: touch %t.pch345// RUN: not %clang_cl -Werror /FI%t.pch /Fp%t.pch /c -### -- %s 2>&1 \346// RUN: | FileCheck -check-prefix=CHECK-FI %s347// CHECK-FI-NOT: -include-pch348// CHECK-FI: -include349 350// Test interaction of /Yc with language mode flags.351 352// If /TC changes the input language to C, a c pch file should be produced.353// RUN: %clang_cl /TC -Werror /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \354// RUN: | FileCheck -check-prefix=CHECK-YCTC %s355// CHECK-YCTC: cc1356// CHECK-YCTC: -emit-pch357// CHECK-YCTC: -o358// CHECK-YCTC: pchfile.pch359// CHECK-YCTC: -x360// CHECK-YCTC: "c"361 362// Also check lower-case /Tc variant.363// RUN: %clang_cl -Werror /Ycpchfile.h /FIpchfile.h /c -### /Tc%s 2>&1 \364// RUN: | FileCheck -check-prefix=CHECK-YCTc %s365// CHECK-YCTc: cc1366// CHECK-YCTc: -emit-pch367// CHECK-YCTc: -o368// CHECK-YCTc: pchfile.pch369// CHECK-YCTc: -x370// CHECK-YCTc: "c"371 372// Don't crash when a non-source file is passed.373// RUN: not %clang_cl -Werror /Ycpchfile.h /FIpchfile.h /c -### -- %S/Inputs/file.prof 2>&1 \374// RUN: | FileCheck -check-prefix=CHECK-NoSource %s375// CHECK-NoSource: file.prof:{{.*}}input unused376 377// ...but if an explicit flag turns the file into a source file, handle it:378// RUN: %clang_cl /TP -Werror /Ycpchfile.h /FIpchfile.h /c -### -- %S/Inputs/file.prof 2>&1 \379// RUN: | FileCheck -check-prefix=CHECK-NoSourceTP %s380// CHECK-NoSourceTP: cc1381// CHECK-NoSourceTP: -emit-pch382// CHECK-NoSourceTP: -o383// CHECK-NoSourceTP: pchfile.pch384// CHECK-NoSourceTP: -x385// CHECK-NoSourceTP: "c++"386 387// If only preprocessing, PCH options are ignored.388// RUN: %clang_cl /P /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \389// RUN: | FileCheck -check-prefix=CHECK-YC-P %s390// CHECK-YC-P-NOT: -emit-pch391// CHECK-YC-P-NOT: -include-pch392 393// RUN: %clang_cl /E /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \394// RUN: | FileCheck -check-prefix=CHECK-YC-E %s395// CHECK-YC-E-NOT: -emit-pch396// CHECK-YC-E-NOT: -include-pch397 398// RUN: %clang_cl /P /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \399// RUN: | FileCheck -check-prefix=CHECK-YU-P %s400// CHECK-YU-P-NOT: -emit-pch401// CHECK-YU-P-NOT: -include-pch402 403// RUN: %clang_cl /E /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \404// RUN: | FileCheck -check-prefix=CHECK-YU-E %s405// CHECK-YU-E-NOT: -emit-pch406// CHECK-YU-E-NOT: -include-pch407