Skip to content

Commit e84852b

Browse files
shivanshu3zmodem
authored andcommitted
Add ability to turn off -fpch-instantiate-templates in clang-cl
A lot of our code building with clang-cl.exe using Clang 11 was failing with the following 2 type of errors: 1. explicit specialization of 'foo' after instantiation 2. no matching function for call to 'bar' Note that we also use -fdelayed-template-parsing in our builds. I tried pretty hard to get a small repro for these failures, but couldn't. So there is some subtle edge case in the -fpch-instantiate-templates feature introduced by this change: https://reviews.llvm.org/D69585 When I tried turning this off using -fno-pch-instantiate-templates, builds would silently fail with the same error without any indication that -fno-pch-instantiate-templates was being ignored by the compiler. Then I realized this "no" option wasn't actually working when I ran Clang under a debugger. Differential revision: https://reviews.llvm.org/D88680 (cherry picked from commit 66e4f07)
1 parent 121baba commit e84852b

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,11 +1435,11 @@ def fno_pch_validate_input_files_content:
14351435
Group<f_Group>, Flags<[DriverOption]>;
14361436
def fpch_instantiate_templates:
14371437
Flag <["-"], "fpch-instantiate-templates">,
1438-
Group<f_Group>, Flags<[CC1Option]>,
1438+
Group<f_Group>, Flags<[CC1Option, CoreOption]>,
14391439
HelpText<"Instantiate templates already while building a PCH">;
14401440
def fno_pch_instantiate_templates:
14411441
Flag <["-"], "fno-pch-instantiate-templates">,
1442-
Group<f_Group>, Flags<[CC1Option]>;
1442+
Group<f_Group>, Flags<[CC1Option, CoreOption]>;
14431443
defm pch_codegen: OptInFFlag<"pch-codegen", "Generate ", "Do not generate ",
14441444
"code for uses of this PCH that assumes an explicit object file will be built for the PCH">;
14451445
defm pch_debuginfo: OptInFFlag<"pch-debuginfo", "Generate ", "Do not generate ",

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,11 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
11971197
if (YcArg && JA.getKind() >= Action::PrecompileJobClass &&
11981198
JA.getKind() <= Action::AssembleJobClass) {
11991199
CmdArgs.push_back(Args.MakeArgString("-building-pch-with-obj"));
1200-
CmdArgs.push_back(Args.MakeArgString("-fpch-instantiate-templates"));
1200+
// -fpch-instantiate-templates is the default when creating
1201+
// precomp using /Yc
1202+
if (Args.hasFlag(options::OPT_fpch_instantiate_templates,
1203+
options::OPT_fno_pch_instantiate_templates, true))
1204+
CmdArgs.push_back(Args.MakeArgString("-fpch-instantiate-templates"));
12011205
}
12021206
if (YcArg || YuArg) {
12031207
StringRef ThroughHeader = YcArg ? YcArg->getValue() : YuArg->getValue();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// CL driver test cases
2+
// RUN: %clang_cl -### /Yc /Fpfoo.pch /Fofoo.obj -- %s 2>&1 | FileCheck --check-prefix=CLANG_CL_YC %s
3+
// RUN: %clang_cl -### /Yc /Fpfoo.pch /Fofoo.obj -fno-pch-instantiate-templates -- %s 2>&1 | FileCheck --check-prefix=CLANG_CL_YC_DISABLE %s
4+
5+
// CLANG_CL_YC: "-fpch-instantiate-templates"
6+
// CLANG_CL_YC_DISABLE-NOT: "-fpch-instantiate-templates"
7+
8+
// GCC driver test cases
9+
// RUN: %clang -### -x c-header %s -o %t/foo.pch 2>&1 | FileCheck -check-prefix=GCC_DEFAULT %s
10+
// RUN: %clang -### -x c-header %s -o %t/foo.pch -fpch-instantiate-templates 2>&1 | FileCheck -check-prefix=GCC_DEFAULT_ENABLE %s
11+
12+
// GCC_DEFAULT-NOT: "-fpch-instantiate-templates"
13+
// GCC_DEFAULT_ENABLE: "-fpch-instantiate-templates"

0 commit comments

Comments
 (0)