Skip to content

[clang] fix serialization of SubstNonTypeTemplateParmExpr #134560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2025

Conversation

mizvekov
Copy link
Contributor

@mizvekov mizvekov commented Apr 6, 2025

This fixes a couple of mistakes introduced when merging #132748

Fixes msan failure reported here: #132748 (comment)

This fixes a couple of mistakes introduced when merging
#132748

Fixes msan failure reported here: #132748 (comment)
@mizvekov mizvekov self-assigned this Apr 6, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:modules C++20 modules and Clang Header Modules labels Apr 6, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 6, 2025

@llvm/pr-subscribers-clang-modules

@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)

Changes

This fixes a couple of mistakes introduced when merging #132748

Fixes msan failure reported here: #132748 (comment)


Full diff: https://github.com/llvm/llvm-project/pull/134560.diff

3 Files Affected:

  • (modified) clang/lib/AST/ASTContext.cpp (+1-1)
  • (modified) clang/lib/Serialization/ASTReaderStmt.cpp (+1)
  • (modified) clang/lib/Serialization/ASTWriterStmt.cpp (+1)
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 1b6b3d06ddc1e..320fd4e2f3077 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -7011,7 +7011,7 @@ TemplateName ASTContext::getCanonicalTemplateName(TemplateName Name,
         getCanonicalTemplateArgument(subst->getArgumentPack());
     return getSubstTemplateTemplateParmPack(
         canonArgPack, subst->getAssociatedDecl()->getCanonicalDecl(),
-        subst->getFinal(), subst->getIndex());
+        subst->getIndex(), subst->getFinal());
   }
   case TemplateName::DeducedTemplate: {
     assert(IgnoreDeduced == false);
diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp
index d26152f3780ed..22fe54b526433 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -2229,6 +2229,7 @@ void ASTStmtReader::VisitSubstNonTypeTemplateParmExpr(
     E->PackIndex = Record.readInt();
   else
     E->PackIndex = 0;
+  E->Final = CurrentUnpackingBits->getNextBit();
   E->SubstNonTypeTemplateParmExprBits.NameLoc = readSourceLocation();
   E->Replacement = Record.readSubExpr();
 }
diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp
index 23bb5ff22efaf..d0a0f843c7542 100644
--- a/clang/lib/Serialization/ASTWriterStmt.cpp
+++ b/clang/lib/Serialization/ASTWriterStmt.cpp
@@ -2229,6 +2229,7 @@ void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
   CurrentPackingBits.addBit((bool)E->getPackIndex());
   if (auto PackIndex = E->getPackIndex())
     Record.push_back(*PackIndex + 1);
+  CurrentPackingBits.addBit(E->getFinal());
 
   Record.AddSourceLocation(E->getNameLoc());
   Record.AddStmt(E->getReplacement());

@mizvekov mizvekov merged commit aef000d into main Apr 7, 2025
15 checks passed
@mizvekov mizvekov deleted the users/mizvekov/fix-subst-final branch April 7, 2025 00:57
@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 7, 2025

LLVM Buildbot has detected a new failure on builder clang-cmake-x86_64-avx512-win running on avx512-intel64-win while building clang at step 4 "cmake stage 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/81/builds/6042

Here is the relevant piece of the build log for the reference
Step 4 (cmake stage 1) failure: 'cmake -G ...' (failure)
'cmake' is not recognized as an internal or external command,
operable program or batch file.

@bgra8
Copy link
Contributor

bgra8 commented Apr 10, 2025

Heads-up @mizvekov we have bisected a non-deterministic compilation down to this change. We're working on a reproducer.

@eaeltsin
Copy link
Contributor

Dumping pcm files that occasionally differ, we always get the same diff:

<     <EXPR_SUBST_NON_TYPE_TEMPLATE_PARM op0=25165824 op1=56 op2=360777253048 op3=3 op4=21560934252/>
---
>     <EXPR_SUBST_NON_TYPE_TEMPLATE_PARM op0=8388608 op1=56 op2=360777253048 op3=3 op4=21560934252/>
66200c66200
<     <EXPR_SUBST_NON_TYPE_TEMPLATE_PARM op0=25165824 op1=56 op2=360777253048 op3=2 op4=21560934252/>
---
>     <EXPR_SUBST_NON_TYPE_TEMPLATE_PARM op0=8388608 op1=56 op2=360777253048 op3=2 op4=21560934252/>
66205c66205
<     <EXPR_SUBST_NON_TYPE_TEMPLATE_PARM op0=25165824 op1=56 op2=360777253048 op3=1 op4=21560934252/>
---
>     <EXPR_SUBST_NON_TYPE_TEMPLATE_PARM op0=8388608 op1=56 op2=360777253048 op3=1 op4=21560934252/>
66223c66223
<     <EXPR_SUBST_NON_TYPE_TEMPLATE_PARM op0=25165824 op1=56 op2=360777253048 op3=3 op4=21560934252/>
---
>     <EXPR_SUBST_NON_TYPE_TEMPLATE_PARM op0=8388608 op1=56 op2=360777253048 op3=3 op4=21560934252/>
66228c66228
<     <EXPR_SUBST_NON_TYPE_TEMPLATE_PARM op0=25165824 op1=56 op2=360777253048 op3=2 op4=21560934252/>
---
>     <EXPR_SUBST_NON_TYPE_TEMPLATE_PARM op0=8388608 op1=56 op2=360777253048 op3=2 op4=21560934252/>
66233c66233
<     <EXPR_SUBST_NON_TYPE_TEMPLATE_PARM op0=25165824 op1=56 op2=360777253048 op3=1 op4=21560934252/>
---
>     <EXPR_SUBST_NON_TYPE_TEMPLATE_PARM op0=8388608 op1=56 op2=360777253048 op3=1 op4=21560934252/>

so op0 non-deterministically changes between 25165824 and 8388608

@eaeltsin
Copy link
Contributor

eaeltsin commented Apr 11, 2025

Okay, this is E->Final, which was

@mizvekov - please take a look!

@mizvekov
Copy link
Contributor Author

Yeah I see, so this was actually missed previously in another node, SubstNonTypeTemplateParmPackExpr, which during substitution propagates this flag to SubstNonTypeTemplateParmExpr.

@eaeltsin
Copy link
Contributor

@mizvekov - can this also be related, or it needs a separate investigation?

@mizvekov
Copy link
Contributor Author

It's possible but it's not too closely related.

I will post a patch for this one soon, and then we can try again that one and I will take a fresh look on the serialization code.

mizvekov added a commit that referenced this pull request Apr 11, 2025
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.
mizvekov added a commit that referenced this pull request Apr 11, 2025
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.
@mizvekov
Copy link
Contributor Author

This will be fixed here: #135428

mizvekov added a commit that referenced this pull request Apr 11, 2025
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.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Apr 11, 2025
…Expr (#135428)

This fixes a PCM non-determinism regression reported here:
llvm/llvm-project#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.
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
…135428)

This fixes a PCM non-determinism regression reported here:
llvm#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants