Skip to content

Commit 52770d8

Browse files
committed
[Serialization] Don't pack bits for the function scope index of ParmVarDecl
Close llvm#76443 Previously we assume the bits of the function scope index of ParmVarDecl won't exceed 8. But this is a misreading. See the implementation of `ParmVarDecl::getParameterIndex()`, which may exceed the size of the normal bitfield. So it may be better to not pack these bits.
1 parent c2c840b commit 52770d8

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1706,10 +1706,10 @@ void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
17061706
void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
17071707
VisitVarDecl(PD);
17081708

1709+
unsigned scopeIndex = Record.readInt();
17091710
BitsUnpacker ParmVarDeclBits(Record.readInt());
17101711
unsigned isObjCMethodParam = ParmVarDeclBits.getNextBit();
17111712
unsigned scopeDepth = ParmVarDeclBits.getNextBits(/*Width=*/7);
1712-
unsigned scopeIndex = ParmVarDeclBits.getNextBits(/*Width=*/8);
17131713
unsigned declQualifier = ParmVarDeclBits.getNextBits(/*Width=*/7);
17141714
if (isObjCMethodParam) {
17151715
assert(scopeDepth == 0);

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,10 +1163,14 @@ void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
11631163
void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
11641164
VisitVarDecl(D);
11651165

1166+
// See the implementation of `ParmVarDecl::getParameterIndex()`, which may
1167+
// exceed the size of the normal bitfield. So it may be better to not pack
1168+
// these bits.
1169+
Record.push_back(D->getFunctionScopeIndex());
1170+
11661171
BitsPacker ParmVarDeclBits;
11671172
ParmVarDeclBits.addBit(D->isObjCMethodParameter());
11681173
ParmVarDeclBits.addBits(D->getFunctionScopeDepth(), /*BitsWidth=*/7);
1169-
ParmVarDeclBits.addBits(D->getFunctionScopeIndex(), /*BitsWidth=*/8);
11701174
// FIXME: stable encoding
11711175
ParmVarDeclBits.addBits(D->getObjCDeclQualifier(), /*BitsWidth=*/7);
11721176
ParmVarDeclBits.addBit(D->isKNRPromoted());
@@ -2350,10 +2354,11 @@ void ASTWriter::WriteDeclAbbrevs() {
23502354
// isARCPseudoStrong, Linkage, ModulesCodegen
23512355
Abv->Add(BitCodeAbbrevOp(0)); // VarKind (local enum)
23522356
// ParmVarDecl
2357+
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex
23532358
Abv->Add(BitCodeAbbrevOp(
23542359
BitCodeAbbrevOp::Fixed,
2355-
27)); // Packed Parm Var Decl bits: IsObjCMethodParameter, ScopeDepth,
2356-
// ScopeIndex, ObjCDeclQualifier, KNRPromoted,
2360+
19)); // Packed Parm Var Decl bits: IsObjCMethodParameter, ScopeDepth,
2361+
// ObjCDeclQualifier, KNRPromoted,
23572362
// HasInheritedDefaultArg, HasUninstantiatedDefaultArg
23582363
// Type Source Info
23592364
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));

clang/test/PCH/pr76443.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
//
4+
// RUN: %clang_cc1 -std=c++17 -emit-pch %s -o %t/h.pcm
5+
6+
//--- header.h
7+
template <int... Nx> int stringData(const char (&...x)[Nx]) {
8+
return 0;
9+
}
10+
int qt_meta_stringdata_CLASSQStyleENDCLASS = stringData(
11+
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
12+
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
13+
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
14+
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
15+
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
16+
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
17+
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
18+
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
19+
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
20+
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
21+
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
22+
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
23+
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
24+
"", "", "", "", "", "", "", "", "", "");

0 commit comments

Comments
 (0)