Skip to content

Commit 4530922

Browse files
authored
[clang] fix serialization for SubstNonTypeTemplateParmPackExpr (#135428)
This fixes a PCM non-determinism regression reported here: #134560 (comment) There was a bit in `SubstNonTypeTemplateParmPackExpr` which we missed to serialize, and that bit eventually propagates to `SubstNonTypeTemplateParmExpr`. As a drive by, improve serialization for PackIndex on SubstNonTypeTemplateParmExpr by using the newly introduced UnsignedOrNone helpers. There are no release notes since this regression was never released.
1 parent 2837fd7 commit 4530922

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

clang/lib/Serialization/ASTReaderStmt.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,10 +2226,7 @@ void ASTStmtReader::VisitSubstNonTypeTemplateParmExpr(
22262226
E->AssociatedDeclAndRef.setPointer(readDeclAs<Decl>());
22272227
E->AssociatedDeclAndRef.setInt(CurrentUnpackingBits->getNextBit());
22282228
E->Index = CurrentUnpackingBits->getNextBits(/*Width=*/12);
2229-
if (CurrentUnpackingBits->getNextBit())
2230-
E->PackIndex = Record.readInt();
2231-
else
2232-
E->PackIndex = 0;
2229+
E->PackIndex = Record.readUnsignedOrNone().toInternalRepresentation();
22332230
E->Final = CurrentUnpackingBits->getNextBit();
22342231
E->SubstNonTypeTemplateParmExprBits.NameLoc = readSourceLocation();
22352232
E->Replacement = Record.readSubExpr();
@@ -2239,6 +2236,7 @@ void ASTStmtReader::VisitSubstNonTypeTemplateParmPackExpr(
22392236
SubstNonTypeTemplateParmPackExpr *E) {
22402237
VisitExpr(E);
22412238
E->AssociatedDecl = readDeclAs<Decl>();
2239+
E->Final = CurrentUnpackingBits->getNextBit();
22422240
E->Index = Record.readInt();
22432241
TemplateArgument ArgPack = Record.readTemplateArgument();
22442242
if (ArgPack.getKind() != TemplateArgument::Pack)

clang/lib/Serialization/ASTWriterStmt.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,9 +2228,7 @@ void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
22282228
Record.AddDeclRef(E->getAssociatedDecl());
22292229
CurrentPackingBits.addBit(E->isReferenceParameter());
22302230
CurrentPackingBits.addBits(E->getIndex(), /*Width=*/12);
2231-
CurrentPackingBits.addBit((bool)E->getPackIndex());
2232-
if (auto PackIndex = E->getPackIndex())
2233-
Record.push_back(*PackIndex + 1);
2231+
Record.writeUnsignedOrNone(E->getPackIndex());
22342232
CurrentPackingBits.addBit(E->getFinal());
22352233

22362234
Record.AddSourceLocation(E->getNameLoc());
@@ -2242,6 +2240,7 @@ void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
22422240
SubstNonTypeTemplateParmPackExpr *E) {
22432241
VisitExpr(E);
22442242
Record.AddDeclRef(E->getAssociatedDecl());
2243+
CurrentPackingBits.addBit(E->getFinal());
22452244
Record.push_back(E->getIndex());
22462245
Record.AddTemplateArgument(E->getArgumentPack());
22472246
Record.AddSourceLocation(E->getParameterPackLocation());

0 commit comments

Comments
 (0)