Skip to content

Commit 66bd5d7

Browse files
authored
[clang-repl] Fix PCH with delayed template parsing (#103028)
When instantiating a delayed template, the recorded token stream is passed to `Parser::ParseLateTemplatedFuncDef` which will append the current token "so it doesn't get lost". With incremental extensions enabled, this is `repl_input_end` which subsequently needs support for (de)serialization.
1 parent 3f0d3fd commit 66bd5d7

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

clang/lib/Serialization/ASTReader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,7 @@ Token ASTReader::ReadToken(ModuleFile &M, const RecordDataImpl &Record,
18871887
case tok::annot_pragma_unused:
18881888
case tok::annot_pragma_openacc:
18891889
case tok::annot_pragma_openacc_end:
1890+
case tok::annot_repl_input_end:
18901891
break;
18911892
default:
18921893
llvm_unreachable("missing deserialization code for annotation token");

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4734,6 +4734,7 @@ void ASTWriter::AddToken(const Token &Tok, RecordDataImpl &Record) {
47344734
case tok::annot_pragma_unused:
47354735
case tok::annot_pragma_openacc:
47364736
case tok::annot_pragma_openacc_end:
4737+
case tok::annot_repl_input_end:
47374738
break;
47384739
default:
47394740
llvm_unreachable("missing serialization code for annotation token");
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Test the setup without incremental extensions first
2+
// RUN: %clang_cc1 -std=c++17 -fdelayed-template-parsing -fpch-instantiate-templates %s -emit-pch -o %t.pch -verify
3+
// RUN: %clang_cc1 -std=c++17 -fdelayed-template-parsing -include-pch %t.pch %s -verify
4+
5+
// RUN: %clang_cc1 -std=c++17 -fdelayed-template-parsing -fincremental-extensions -fpch-instantiate-templates %s -emit-pch -o %t.incremental.pch -verify
6+
// RUN: %clang_cc1 -std=c++17 -fdelayed-template-parsing -fincremental-extensions -include-pch %t.incremental.pch %s -verify
7+
8+
// expected-no-diagnostics
9+
10+
#ifndef PCH
11+
#define PCH
12+
13+
// Have one template that is instantiated in the PCH (via the passed option
14+
// -fpch-instantiate-templates) and then serialized
15+
template <typename T> T ft1() { return 0; }
16+
inline int f1() { return ft1<int>(); }
17+
18+
// Have a second late-parsed template that needs to be deserialized
19+
template <typename T> T ft2() { return 0; }
20+
21+
#else
22+
23+
int f2() { return ft2<int>(); }
24+
25+
#endif

0 commit comments

Comments
 (0)