[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/cor3ntin closed https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -3492,10 +3492,13 @@ VarDecl *BindingDecl::getHoldingVar() const { return VD; } -llvm::ArrayRef BindingDecl::getBindingPackExprs() const { +llvm::ArrayRef BindingDecl::getBindingPackDecls() const { assert(Binding && "expecting a pack expr"); - auto *RP = cast(Binding); - return RP->getExprs(); + auto *FP = cast(Binding); + ValueDecl *const *First = FP->getNumExpansions() > 0 ? FP->begin() : nullptr; + assert((!First || isa(*First)) && "expecting a BindingDecl"); + return llvm::ArrayRef( + reinterpret_cast(First), FP->getNumExpansions()); zwuis wrote: Can we use `static_cast` here? https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -1197,25 +1197,19 @@ Decl *TemplateDeclInstantiator::VisitDecompositionDecl(DecompositionDecl *D) { for (auto *NewBD : NewBindings) NewBD->setInvalidDecl(); - if (OldResolvedPack) { -// Mark the holding vars (if any) in the pack as instantiated since -// they are created implicitly. + if (OldBindingPack) { +// Mark the bindings in the pack as instantiated. auto Bindings = NewDD->bindings(); -auto BPack = llvm::find_if( +BindingDecl *NewBindingPack = *llvm::find_if( Bindings, [](BindingDecl *D) -> bool { return D->isParameterPack(); }); ricejasonf wrote: What do you think about capturing the index of the old pack in the loop above and using that instead of searching? https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -3492,10 +3492,13 @@ VarDecl *BindingDecl::getHoldingVar() const { return VD; } -llvm::ArrayRef BindingDecl::getBindingPackExprs() const { +llvm::ArrayRef BindingDecl::getBindingPackDecls() const { assert(Binding && "expecting a pack expr"); - auto *RP = cast(Binding); - return RP->getExprs(); + auto *FP = cast(Binding); + ValueDecl *const *First = FP->getNumExpansions() > 0 ? FP->begin() : nullptr; + assert((!First || isa(*First)) && "expecting a BindingDecl"); + return llvm::ArrayRef( + reinterpret_cast(First), FP->getNumExpansions()); ricejasonf wrote: `llvm::cast` will not return a reference to the pointer so it cannot be used for the ArrayRef. https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/zyn0217 edited https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -980,24 +980,24 @@ static bool CheckBindingsCount(Sema &S, DecompositionDecl *DD, if (IsValid && HasPack) { // Create the pack expr and assign it to the binding. unsigned PackSize = MemberCount - Bindings.size() + 1; -QualType PackType = S.Context.getPackExpansionType( -S.Context.DependentTy, std::nullopt, /*ExpectsPackInType=*/false); -BindingDecl *BD = (*BindingWithPackItr); -auto *RP = ResolvedUnexpandedPackExpr::Create(S.Context, DD->getBeginLoc(), - DecompType, PackSize); -BD->setDecomposedDecl(DD); -BD->setBinding(PackType, RP); BindingDecl *BPack = *BindingWithPackItr; +BPack->setDecomposedDecl(DD); +SmallVector NestedBDs(PackSize); // Create the nested BindingDecls. -for (Expr *&E : RP->getExprs()) { - auto *NestedBD = BindingDecl::Create(S.Context, BPack->getDeclContext(), - BPack->getLocation(), - BPack->getIdentifier(), QualType()); +for (ValueDecl *&VD : NestedBDs) { zyn0217 wrote: Maybe we can make it more straightforward like ```cpp for (unsigned I = 0; I < PackSize; ++I) { ... NestedBDs[I] = ... } ``` I feel like `*&` makes it a little visually awkward :) https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/zyn0217 commented: Thanks, a few more comments https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -4649,49 +4649,48 @@ class SubstNonTypeTemplateParmPackExpr : public Expr { /// \endcode class FunctionParmPackExpr final : public Expr, - private llvm::TrailingObjects { + private llvm::TrailingObjects { zyn0217 wrote: Can we also update the attached comments to reflect it now supports structure binding pack? https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -3492,10 +3492,13 @@ VarDecl *BindingDecl::getHoldingVar() const { return VD; } -llvm::ArrayRef BindingDecl::getBindingPackExprs() const { +llvm::ArrayRef BindingDecl::getBindingPackDecls() const { assert(Binding && "expecting a pack expr"); - auto *RP = cast(Binding); - return RP->getExprs(); + auto *FP = cast(Binding); + ValueDecl *const *First = FP->getNumExpansions() > 0 ? FP->begin() : nullptr; + assert((!First || isa(*First)) && "expecting a BindingDecl"); + return llvm::ArrayRef( + reinterpret_cast(First), FP->getNumExpansions()); zyn0217 wrote: can we use llvm::cast here? https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -1178,13 +1178,13 @@ Decl *TemplateDeclInstantiator::VisitDecompositionDecl(DecompositionDecl *D) { // Transform the bindings first. // The transformed DD will have all of the concrete BindingDecls. SmallVector NewBindings; - ResolvedUnexpandedPackExpr *OldResolvedPack = nullptr; + BindingDecl *OldBindingPack = nullptr; for (auto *OldBD : D->bindings()) { Expr *BindingExpr = OldBD->getBinding(); -if (auto *RP = -dyn_cast_if_present(BindingExpr)) { - assert(!OldResolvedPack && "no more than one pack is allowed"); - OldResolvedPack = RP; +if (isa_and_nonnull(BindingExpr)) { zyn0217 wrote: isa_and_present https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -1197,25 +1197,19 @@ Decl *TemplateDeclInstantiator::VisitDecompositionDecl(DecompositionDecl *D) { for (auto *NewBD : NewBindings) NewBD->setInvalidDecl(); - if (OldResolvedPack) { -// Mark the holding vars (if any) in the pack as instantiated since -// they are created implicitly. + if (OldBindingPack) { +// Mark the bindings in the pack as instantiated. auto Bindings = NewDD->bindings(); -auto BPack = llvm::find_if( +BindingDecl *NewBindingPack = *llvm::find_if( Bindings, [](BindingDecl *D) -> bool { return D->isParameterPack(); }); zyn0217 wrote: For sanity (we have lost the assertion of `cast`ing a non-null pointer), we'd better add an non-null assertion here https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/ricejasonf updated https://github.com/llvm/llvm-project/pull/125394 >From a323e058b2c8adf97f7f9a55a9187f74de9b8d17 Mon Sep 17 00:00:00 2001 From: Jason Rice Date: Sun, 2 Feb 2025 00:52:47 -0800 Subject: [PATCH 1/5] [Clang][P1061] Consolidate ResolvedUnexpandedPackExpr into FunctionParmPackExpr --- clang/include/clang/AST/DeclCXX.h | 28 + clang/include/clang/AST/ExprCXX.h | 21 +- clang/include/clang/Sema/Template.h | 2 +- clang/lib/AST/DeclCXX.cpp | 9 +++-- clang/lib/AST/ExprCXX.cpp | 14 +++ clang/lib/Sema/SemaDeclCXX.cpp| 26 ++-- clang/lib/Sema/SemaExpr.cpp | 6 +-- clang/lib/Sema/SemaTemplateInstantiate.cpp| 30 +- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 40 +++ clang/lib/Sema/SemaTemplateVariadic.cpp | 32 +-- clang/lib/Serialization/ASTReaderStmt.cpp | 6 +-- clang/test/AST/ast-dump-binding-pack.cpp | 13 ++ clang/test/SemaCXX/cxx2c-binding-pack.cpp | 11 + 13 files changed, 103 insertions(+), 135 deletions(-) diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index 766821b4fb25cb5..1c630d616903550 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -4194,8 +4194,8 @@ class BindingDecl : public ValueDecl { /// decomposition declaration, and when the initializer is type-dependent. Expr *getBinding() const { return Binding; } - // Get the array of Exprs when the binding represents a pack. - llvm::ArrayRef getBindingPackExprs() const; + // Get the array of nested BindingDecls when the binding represents a pack. + llvm::ArrayRef getBindingPackDecls() const; /// Get the decomposition declaration that this binding represents a /// decomposition of. @@ -4246,10 +4246,8 @@ class DecompositionDecl final for (auto *B : Bindings) { B->setDecomposedDecl(this); if (B->isParameterPack() && B->getBinding()) { -for (Expr *E : B->getBindingPackExprs()) { - auto *DRE = cast(E); - auto *NestedB = cast(DRE->getDecl()); - NestedB->setDecomposedDecl(this); +for (BindingDecl *NestedBD : B->getBindingPackDecls()) { + NestedBD->setDecomposedDecl(this); } } } @@ -4278,25 +4276,21 @@ class DecompositionDecl final // Provide a flattened range to visit each binding. auto flat_bindings() const { llvm::ArrayRef Bindings = bindings(); -llvm::ArrayRef PackExprs; +llvm::ArrayRef PackBindings; // Split the bindings into subranges split by the pack. -auto S1 = Bindings.take_until( +auto BeforePackBindings = Bindings.take_until( [](BindingDecl *BD) { return BD->isParameterPack(); }); -Bindings = Bindings.drop_front(S1.size()); +Bindings = Bindings.drop_front(BeforePackBindings.size()); if (!Bindings.empty()) { - PackExprs = Bindings.front()->getBindingPackExprs(); + PackBindings = Bindings.front()->getBindingPackDecls(); Bindings = Bindings.drop_front(); } -auto S2 = llvm::map_range(PackExprs, [](Expr *E) { - auto *DRE = cast(E); - return cast(DRE->getDecl()); -}); - -return llvm::concat(std::move(S1), std::move(S2), - std::move(Bindings)); +return llvm::concat(std::move(BeforePackBindings), +std::move(PackBindings), +std::move(Bindings)); } void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override; diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 0b6c8cfb163c958..2b23fa51c6232b2 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -4649,13 +4649,13 @@ class SubstNonTypeTemplateParmPackExpr : public Expr { /// \endcode class FunctionParmPackExpr final : public Expr, - private llvm::TrailingObjects { + private llvm::TrailingObjects { friend class ASTReader; friend class ASTStmtReader; friend TrailingObjects; /// The function parameter pack which was referenced. - VarDecl *ParamPack; + ValueDecl *ParamPack; /// The location of the function parameter pack reference. SourceLocation NameLoc; @@ -4663,35 +4663,34 @@ class FunctionParmPackExpr final /// The number of expansions of this pack. unsigned NumParameters; - FunctionParmPackExpr(QualType T, VarDecl *ParamPack, - SourceLocation NameLoc, unsigned NumParams, - VarDecl *const *Params); + FunctionParmPackExpr(QualType T, ValueDecl *ParamPack, SourceLocation NameLoc, + unsigned NumParams, ValueDecl *const *Params); public: static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T, -
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -3492,10 +3492,13 @@ VarDecl *BindingDecl::getHoldingVar() const { return VD; } -llvm::ArrayRef BindingDecl::getBindingPackExprs() const { +llvm::ArrayRef BindingDecl::getBindingPackDecls() const { assert(Binding && "expecting a pack expr"); - auto *RP = cast(Binding); - return RP->getExprs(); + auto *FP = cast(Binding); + ValueDecl *const *First = FP->getNumExpansions() > 0 ? FP->begin() : nullptr; + assert((!First || isa(*First)) && "expecting a BindingDecl"); + return llvm::ArrayRef((BindingDecl *const *)First, erichkeane wrote: This I did with the use of `cast`, which you gave some good reasons to skip. But I separately commented that I want the C cast gone. https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/ricejasonf edited https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -124,6 +125,14 @@ void lambda_capture() { [&x...] { (void)sum(x...); }(); } +struct S2 { +int a, b, c; +}; + +auto X = [] () { ricejasonf wrote: Oh, sorry, I added your test with `clsss` not realizing you were talking about modifying an existing test. :sweat_smile: https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -3492,10 +3492,13 @@ VarDecl *BindingDecl::getHoldingVar() const { return VD; } -llvm::ArrayRef BindingDecl::getBindingPackExprs() const { +llvm::ArrayRef BindingDecl::getBindingPackDecls() const { assert(Binding && "expecting a pack expr"); - auto *RP = cast(Binding); - return RP->getExprs(); + auto *FP = cast(Binding); + ValueDecl *const *First = FP->getNumExpansions() > 0 ? FP->begin() : nullptr; + assert((!First || isa(*First)) && "expecting a BindingDecl"); + return llvm::ArrayRef((BindingDecl *const *)First, ricejasonf wrote: It says you marked this as resolved. https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/shafik commented: I think I would like to see some more test coverage. https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/shafik edited https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -124,6 +125,14 @@ void lambda_capture() { [&x...] { (void)sum(x...); }(); } +struct S2 { +int a, b, c; +}; + +auto X = [] () { shafik wrote: I feel like there are a bunch of varieties on this case we can test as well: https://godbolt.org/z/r9zxxfoW5 https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -4278,25 +4276,21 @@ class DecompositionDecl final // Provide a flattened range to visit each binding. auto flat_bindings() const { llvm::ArrayRef Bindings = bindings(); -llvm::ArrayRef PackExprs; +llvm::ArrayRef PackBindings; // Split the bindings into subranges split by the pack. -auto S1 = Bindings.take_until( +auto BeforePackBindings = Bindings.take_until( [](BindingDecl *BD) { return BD->isParameterPack(); }); -Bindings = Bindings.drop_front(S1.size()); +Bindings = Bindings.drop_front(BeforePackBindings.size()); if (!Bindings.empty()) { - PackExprs = Bindings.front()->getBindingPackExprs(); + PackBindings = Bindings.front()->getBindingPackDecls(); Bindings = Bindings.drop_front(); } -auto S2 = llvm::map_range(PackExprs, [](Expr *E) { - auto *DRE = cast(E); - return cast(DRE->getDecl()); -}); - -return llvm::concat(std::move(S1), std::move(S2), - std::move(Bindings)); +return llvm::concat(std::move(BeforePackBindings), ricejasonf wrote: They add... rvalue don't they? :rofl: . I added them to work around the dangling references. https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
ricejasonf wrote: > Can i merge this for you? @cor3ntin Whenever you think it is ready, yes please. I know Erich did not want the C-style cast. https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
cor3ntin wrote: @ricejasonf Can i merge this for you? https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/cor3ntin approved this pull request. https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/ricejasonf updated https://github.com/llvm/llvm-project/pull/125394 >From a323e058b2c8adf97f7f9a55a9187f74de9b8d17 Mon Sep 17 00:00:00 2001 From: Jason Rice Date: Sun, 2 Feb 2025 00:52:47 -0800 Subject: [PATCH 1/3] [Clang][P1061] Consolidate ResolvedUnexpandedPackExpr into FunctionParmPackExpr --- clang/include/clang/AST/DeclCXX.h | 28 + clang/include/clang/AST/ExprCXX.h | 21 +- clang/include/clang/Sema/Template.h | 2 +- clang/lib/AST/DeclCXX.cpp | 9 +++-- clang/lib/AST/ExprCXX.cpp | 14 +++ clang/lib/Sema/SemaDeclCXX.cpp| 26 ++-- clang/lib/Sema/SemaExpr.cpp | 6 +-- clang/lib/Sema/SemaTemplateInstantiate.cpp| 30 +- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 40 +++ clang/lib/Sema/SemaTemplateVariadic.cpp | 32 +-- clang/lib/Serialization/ASTReaderStmt.cpp | 6 +-- clang/test/AST/ast-dump-binding-pack.cpp | 13 ++ clang/test/SemaCXX/cxx2c-binding-pack.cpp | 11 + 13 files changed, 103 insertions(+), 135 deletions(-) diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index 766821b4fb25cb5..1c630d616903550 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -4194,8 +4194,8 @@ class BindingDecl : public ValueDecl { /// decomposition declaration, and when the initializer is type-dependent. Expr *getBinding() const { return Binding; } - // Get the array of Exprs when the binding represents a pack. - llvm::ArrayRef getBindingPackExprs() const; + // Get the array of nested BindingDecls when the binding represents a pack. + llvm::ArrayRef getBindingPackDecls() const; /// Get the decomposition declaration that this binding represents a /// decomposition of. @@ -4246,10 +4246,8 @@ class DecompositionDecl final for (auto *B : Bindings) { B->setDecomposedDecl(this); if (B->isParameterPack() && B->getBinding()) { -for (Expr *E : B->getBindingPackExprs()) { - auto *DRE = cast(E); - auto *NestedB = cast(DRE->getDecl()); - NestedB->setDecomposedDecl(this); +for (BindingDecl *NestedBD : B->getBindingPackDecls()) { + NestedBD->setDecomposedDecl(this); } } } @@ -4278,25 +4276,21 @@ class DecompositionDecl final // Provide a flattened range to visit each binding. auto flat_bindings() const { llvm::ArrayRef Bindings = bindings(); -llvm::ArrayRef PackExprs; +llvm::ArrayRef PackBindings; // Split the bindings into subranges split by the pack. -auto S1 = Bindings.take_until( +auto BeforePackBindings = Bindings.take_until( [](BindingDecl *BD) { return BD->isParameterPack(); }); -Bindings = Bindings.drop_front(S1.size()); +Bindings = Bindings.drop_front(BeforePackBindings.size()); if (!Bindings.empty()) { - PackExprs = Bindings.front()->getBindingPackExprs(); + PackBindings = Bindings.front()->getBindingPackDecls(); Bindings = Bindings.drop_front(); } -auto S2 = llvm::map_range(PackExprs, [](Expr *E) { - auto *DRE = cast(E); - return cast(DRE->getDecl()); -}); - -return llvm::concat(std::move(S1), std::move(S2), - std::move(Bindings)); +return llvm::concat(std::move(BeforePackBindings), +std::move(PackBindings), +std::move(Bindings)); } void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override; diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 0b6c8cfb163c958..2b23fa51c6232b2 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -4649,13 +4649,13 @@ class SubstNonTypeTemplateParmPackExpr : public Expr { /// \endcode class FunctionParmPackExpr final : public Expr, - private llvm::TrailingObjects { + private llvm::TrailingObjects { friend class ASTReader; friend class ASTStmtReader; friend TrailingObjects; /// The function parameter pack which was referenced. - VarDecl *ParamPack; + ValueDecl *ParamPack; /// The location of the function parameter pack reference. SourceLocation NameLoc; @@ -4663,35 +4663,34 @@ class FunctionParmPackExpr final /// The number of expansions of this pack. unsigned NumParameters; - FunctionParmPackExpr(QualType T, VarDecl *ParamPack, - SourceLocation NameLoc, unsigned NumParams, - VarDecl *const *Params); + FunctionParmPackExpr(QualType T, ValueDecl *ParamPack, SourceLocation NameLoc, + unsigned NumParams, ValueDecl *const *Params); public: static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T, -
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/ricejasonf edited https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -3492,10 +3492,13 @@ VarDecl *BindingDecl::getHoldingVar() const { return VD; } -llvm::ArrayRef BindingDecl::getBindingPackExprs() const { +llvm::ArrayRef BindingDecl::getBindingPackDecls() const { assert(Binding && "expecting a pack expr"); - auto *RP = cast(Binding); - return RP->getExprs(); + auto *FP = cast(Binding); + ValueDecl *const *First = FP->getNumExpansions() > 0 ? FP->begin() : nullptr; + assert((!First || isa(*First)) && "expecting a BindingDecl"); + return llvm::ArrayRef((BindingDecl *const *)First, erichkeane wrote: What you could do here is `&cast(*First)`, plus wrap that in a const-cast. This would make the assert unnecessary. https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/erichkeane commented: A few nits, else this is great, thank you! https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -4278,25 +4276,21 @@ class DecompositionDecl final // Provide a flattened range to visit each binding. auto flat_bindings() const { llvm::ArrayRef Bindings = bindings(); -llvm::ArrayRef PackExprs; +llvm::ArrayRef PackBindings; // Split the bindings into subranges split by the pack. -auto S1 = Bindings.take_until( +auto BeforePackBindings = Bindings.take_until( [](BindingDecl *BD) { return BD->isParameterPack(); }); -Bindings = Bindings.drop_front(S1.size()); +Bindings = Bindings.drop_front(BeforePackBindings.size()); if (!Bindings.empty()) { - PackExprs = Bindings.front()->getBindingPackExprs(); + PackBindings = Bindings.front()->getBindingPackDecls(); Bindings = Bindings.drop_front(); } -auto S2 = llvm::map_range(PackExprs, [](Expr *E) { - auto *DRE = cast(E); - return cast(DRE->getDecl()); -}); - -return llvm::concat(std::move(S1), std::move(S2), - std::move(Bindings)); +return llvm::concat(std::move(BeforePackBindings), erichkeane wrote: I realize you're taking from the previous patch, but these `std::move` calls are a little silly :) All of the types are an `ArrayRef`, so there is nothing to steal. https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -1197,25 +1197,17 @@ Decl *TemplateDeclInstantiator::VisitDecompositionDecl(DecompositionDecl *D) { for (auto *NewBD : NewBindings) NewBD->setInvalidDecl(); - if (OldResolvedPack) { -// Mark the holding vars (if any) in the pack as instantiated since -// they are created implicitly. + if (OldBindingPack) { +// Mark the bindings in the pack as instantiated. auto Bindings = NewDD->bindings(); -auto BPack = llvm::find_if( +auto NewBindingPack = *llvm::find_if( Bindings, [](BindingDecl *D) -> bool { return D->isParameterPack(); }); -auto *NewResolvedPack = -cast((*BPack)->getBinding()); -auto OldExprs = OldResolvedPack->getExprs(); -auto NewExprs = NewResolvedPack->getExprs(); -assert(OldExprs.size() == NewExprs.size()); -for (unsigned I = 0; I < OldResolvedPack->getNumExprs(); I++) { - DeclRefExpr *OldDRE = cast(OldExprs[I]); - BindingDecl *OldNestedBD = cast(OldDRE->getDecl()); - DeclRefExpr *NewDRE = cast(NewExprs[I]); - BindingDecl *NewNestedBD = cast(NewDRE->getDecl()); - SemaRef.CurrentInstantiationScope->InstantiatedLocal(OldNestedBD, - NewNestedBD); -} +auto OldDecls = OldBindingPack->getBindingPackDecls(); erichkeane wrote: We shouldn't be using 'auto' on either of these. I realize they already were, but please change them anyway., https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -4278,25 +4276,21 @@ class DecompositionDecl final // Provide a flattened range to visit each binding. auto flat_bindings() const { llvm::ArrayRef Bindings = bindings(); -llvm::ArrayRef PackExprs; +llvm::ArrayRef PackBindings; // Split the bindings into subranges split by the pack. -auto S1 = Bindings.take_until( +auto BeforePackBindings = Bindings.take_until( erichkeane wrote: ```suggestion llvm::ArrayRef BeforePackBindings = Bindings.take_until( ``` https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/erichkeane edited https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
Sirraide wrote: > @Sirraide I did try it and the bug persists. The `LHS` is a RecoveryExpr, so > I am not sure how to approach that. Yeah, that one did look like the problem is probably elsewhere; thanks for trying though! https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/cor3ntin approved this pull request. https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/cor3ntin edited https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/cor3ntin edited https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
cor3ntin wrote: @ricejasonf yeah... really not a fan but i played with it an i don't see a way to meaningfully improve it. Thanks for trying though https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
ricejasonf wrote: @cor3ntin Sorry, I tried "Commit suggestion", but it didn't look like you can cast like that so I just reverted. https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/ricejasonf updated https://github.com/llvm/llvm-project/pull/125394 >From a323e058b2c8adf97f7f9a55a9187f74de9b8d17 Mon Sep 17 00:00:00 2001 From: Jason Rice Date: Sun, 2 Feb 2025 00:52:47 -0800 Subject: [PATCH 1/2] [Clang][P1061] Consolidate ResolvedUnexpandedPackExpr into FunctionParmPackExpr --- clang/include/clang/AST/DeclCXX.h | 28 + clang/include/clang/AST/ExprCXX.h | 21 +- clang/include/clang/Sema/Template.h | 2 +- clang/lib/AST/DeclCXX.cpp | 9 +++-- clang/lib/AST/ExprCXX.cpp | 14 +++ clang/lib/Sema/SemaDeclCXX.cpp| 26 ++-- clang/lib/Sema/SemaExpr.cpp | 6 +-- clang/lib/Sema/SemaTemplateInstantiate.cpp| 30 +- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 40 +++ clang/lib/Sema/SemaTemplateVariadic.cpp | 32 +-- clang/lib/Serialization/ASTReaderStmt.cpp | 6 +-- clang/test/AST/ast-dump-binding-pack.cpp | 13 ++ clang/test/SemaCXX/cxx2c-binding-pack.cpp | 11 + 13 files changed, 103 insertions(+), 135 deletions(-) diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index 766821b4fb25cb..1c630d61690355 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -4194,8 +4194,8 @@ class BindingDecl : public ValueDecl { /// decomposition declaration, and when the initializer is type-dependent. Expr *getBinding() const { return Binding; } - // Get the array of Exprs when the binding represents a pack. - llvm::ArrayRef getBindingPackExprs() const; + // Get the array of nested BindingDecls when the binding represents a pack. + llvm::ArrayRef getBindingPackDecls() const; /// Get the decomposition declaration that this binding represents a /// decomposition of. @@ -4246,10 +4246,8 @@ class DecompositionDecl final for (auto *B : Bindings) { B->setDecomposedDecl(this); if (B->isParameterPack() && B->getBinding()) { -for (Expr *E : B->getBindingPackExprs()) { - auto *DRE = cast(E); - auto *NestedB = cast(DRE->getDecl()); - NestedB->setDecomposedDecl(this); +for (BindingDecl *NestedBD : B->getBindingPackDecls()) { + NestedBD->setDecomposedDecl(this); } } } @@ -4278,25 +4276,21 @@ class DecompositionDecl final // Provide a flattened range to visit each binding. auto flat_bindings() const { llvm::ArrayRef Bindings = bindings(); -llvm::ArrayRef PackExprs; +llvm::ArrayRef PackBindings; // Split the bindings into subranges split by the pack. -auto S1 = Bindings.take_until( +auto BeforePackBindings = Bindings.take_until( [](BindingDecl *BD) { return BD->isParameterPack(); }); -Bindings = Bindings.drop_front(S1.size()); +Bindings = Bindings.drop_front(BeforePackBindings.size()); if (!Bindings.empty()) { - PackExprs = Bindings.front()->getBindingPackExprs(); + PackBindings = Bindings.front()->getBindingPackDecls(); Bindings = Bindings.drop_front(); } -auto S2 = llvm::map_range(PackExprs, [](Expr *E) { - auto *DRE = cast(E); - return cast(DRE->getDecl()); -}); - -return llvm::concat(std::move(S1), std::move(S2), - std::move(Bindings)); +return llvm::concat(std::move(BeforePackBindings), +std::move(PackBindings), +std::move(Bindings)); } void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override; diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 0b6c8cfb163c95..2b23fa51c6232b 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -4649,13 +4649,13 @@ class SubstNonTypeTemplateParmPackExpr : public Expr { /// \endcode class FunctionParmPackExpr final : public Expr, - private llvm::TrailingObjects { + private llvm::TrailingObjects { friend class ASTReader; friend class ASTStmtReader; friend TrailingObjects; /// The function parameter pack which was referenced. - VarDecl *ParamPack; + ValueDecl *ParamPack; /// The location of the function parameter pack reference. SourceLocation NameLoc; @@ -4663,35 +4663,34 @@ class FunctionParmPackExpr final /// The number of expansions of this pack. unsigned NumParameters; - FunctionParmPackExpr(QualType T, VarDecl *ParamPack, - SourceLocation NameLoc, unsigned NumParams, - VarDecl *const *Params); + FunctionParmPackExpr(QualType T, ValueDecl *ParamPack, SourceLocation NameLoc, + unsigned NumParams, ValueDecl *const *Params); public: static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T, -
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff d5a7a483a65f830a0c7a931781bc90046dc67ff4 b2b85fdbe11dce02c6ba842b5a4949b70c47207b --extensions cpp,h -- clang/include/clang/AST/DeclCXX.h clang/include/clang/AST/ExprCXX.h clang/include/clang/AST/RecursiveASTVisitor.h clang/include/clang/Sema/Sema.h clang/include/clang/Sema/Template.h clang/include/clang/Serialization/ASTBitCodes.h clang/lib/AST/DeclCXX.cpp clang/lib/AST/Expr.cpp clang/lib/AST/ExprCXX.cpp clang/lib/AST/ExprClassification.cpp clang/lib/AST/ExprConstant.cpp clang/lib/AST/ItaniumMangle.cpp clang/lib/AST/StmtPrinter.cpp clang/lib/AST/StmtProfile.cpp clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Sema/SemaExceptionSpec.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaTemplateInstantiate.cpp clang/lib/Sema/SemaTemplateInstantiateDecl.cpp clang/lib/Sema/SemaTemplateVariadic.cpp clang/lib/Sema/TreeTransform.h clang/lib/Serialization/ASTReaderStmt.cpp clang/lib/Serialization/ASTWriter.cpp clang/lib/Serialization/ASTWriterStmt.cpp clang/lib/StaticAnalyzer/Core/ExprEngine.cpp clang/test/AST/ast-dump-binding-pack.cpp clang/test/SemaCXX/cxx2c-binding-pack.cpp clang/tools/libclang/CXCursor.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index 77cbf1362a..b0a14629f2 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -3495,9 +3495,10 @@ VarDecl *BindingDecl::getHoldingVar() const { llvm::ArrayRef BindingDecl::getBindingPackDecls() const { assert(Binding && "expecting a pack expr"); auto *FP = cast(Binding); - if(FP->getNumExpansions() == 0) - return {}; - return llvm::ArrayRef(cast(FP->begin()), FP->getNumExpansions()); + if (FP->getNumExpansions() == 0) +return {}; + return llvm::ArrayRef(cast(FP->begin()), + FP->getNumExpansions()); } void DecompositionDecl::anchor() {} `` https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/ricejasonf updated https://github.com/llvm/llvm-project/pull/125394 >From a323e058b2c8adf97f7f9a55a9187f74de9b8d17 Mon Sep 17 00:00:00 2001 From: Jason Rice Date: Sun, 2 Feb 2025 00:52:47 -0800 Subject: [PATCH 1/3] [Clang][P1061] Consolidate ResolvedUnexpandedPackExpr into FunctionParmPackExpr --- clang/include/clang/AST/DeclCXX.h | 28 + clang/include/clang/AST/ExprCXX.h | 21 +- clang/include/clang/Sema/Template.h | 2 +- clang/lib/AST/DeclCXX.cpp | 9 +++-- clang/lib/AST/ExprCXX.cpp | 14 +++ clang/lib/Sema/SemaDeclCXX.cpp| 26 ++-- clang/lib/Sema/SemaExpr.cpp | 6 +-- clang/lib/Sema/SemaTemplateInstantiate.cpp| 30 +- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 40 +++ clang/lib/Sema/SemaTemplateVariadic.cpp | 32 +-- clang/lib/Serialization/ASTReaderStmt.cpp | 6 +-- clang/test/AST/ast-dump-binding-pack.cpp | 13 ++ clang/test/SemaCXX/cxx2c-binding-pack.cpp | 11 + 13 files changed, 103 insertions(+), 135 deletions(-) diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index 766821b4fb25cb..1c630d61690355 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -4194,8 +4194,8 @@ class BindingDecl : public ValueDecl { /// decomposition declaration, and when the initializer is type-dependent. Expr *getBinding() const { return Binding; } - // Get the array of Exprs when the binding represents a pack. - llvm::ArrayRef getBindingPackExprs() const; + // Get the array of nested BindingDecls when the binding represents a pack. + llvm::ArrayRef getBindingPackDecls() const; /// Get the decomposition declaration that this binding represents a /// decomposition of. @@ -4246,10 +4246,8 @@ class DecompositionDecl final for (auto *B : Bindings) { B->setDecomposedDecl(this); if (B->isParameterPack() && B->getBinding()) { -for (Expr *E : B->getBindingPackExprs()) { - auto *DRE = cast(E); - auto *NestedB = cast(DRE->getDecl()); - NestedB->setDecomposedDecl(this); +for (BindingDecl *NestedBD : B->getBindingPackDecls()) { + NestedBD->setDecomposedDecl(this); } } } @@ -4278,25 +4276,21 @@ class DecompositionDecl final // Provide a flattened range to visit each binding. auto flat_bindings() const { llvm::ArrayRef Bindings = bindings(); -llvm::ArrayRef PackExprs; +llvm::ArrayRef PackBindings; // Split the bindings into subranges split by the pack. -auto S1 = Bindings.take_until( +auto BeforePackBindings = Bindings.take_until( [](BindingDecl *BD) { return BD->isParameterPack(); }); -Bindings = Bindings.drop_front(S1.size()); +Bindings = Bindings.drop_front(BeforePackBindings.size()); if (!Bindings.empty()) { - PackExprs = Bindings.front()->getBindingPackExprs(); + PackBindings = Bindings.front()->getBindingPackDecls(); Bindings = Bindings.drop_front(); } -auto S2 = llvm::map_range(PackExprs, [](Expr *E) { - auto *DRE = cast(E); - return cast(DRE->getDecl()); -}); - -return llvm::concat(std::move(S1), std::move(S2), - std::move(Bindings)); +return llvm::concat(std::move(BeforePackBindings), +std::move(PackBindings), +std::move(Bindings)); } void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override; diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 0b6c8cfb163c95..2b23fa51c6232b 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -4649,13 +4649,13 @@ class SubstNonTypeTemplateParmPackExpr : public Expr { /// \endcode class FunctionParmPackExpr final : public Expr, - private llvm::TrailingObjects { + private llvm::TrailingObjects { friend class ASTReader; friend class ASTStmtReader; friend TrailingObjects; /// The function parameter pack which was referenced. - VarDecl *ParamPack; + ValueDecl *ParamPack; /// The location of the function parameter pack reference. SourceLocation NameLoc; @@ -4663,35 +4663,34 @@ class FunctionParmPackExpr final /// The number of expansions of this pack. unsigned NumParameters; - FunctionParmPackExpr(QualType T, VarDecl *ParamPack, - SourceLocation NameLoc, unsigned NumParams, - VarDecl *const *Params); + FunctionParmPackExpr(QualType T, ValueDecl *ParamPack, SourceLocation NameLoc, + unsigned NumParams, ValueDecl *const *Params); public: static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T, -
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -3492,10 +3492,13 @@ VarDecl *BindingDecl::getHoldingVar() const { return VD; } -llvm::ArrayRef BindingDecl::getBindingPackExprs() const { +llvm::ArrayRef BindingDecl::getBindingPackDecls() const { assert(Binding && "expecting a pack expr"); - auto *RP = cast(Binding); - return RP->getExprs(); + auto *FP = cast(Binding); + ValueDecl *const *First = FP->getNumExpansions() > 0 ? FP->begin() : nullptr; + assert((!First || isa(*First)) && "expecting a BindingDecl"); + return llvm::ArrayRef((BindingDecl *const *)First, + FP->getNumExpansions()); ricejasonf wrote: Ah, I had something like that, but I didn't think to `cast` to a pointer type (or know that you could like that). https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
ricejasonf wrote: @Sirraide I did try it and the bug persists. The `LHS` is a RecoveryExpr, so I am not sure how to approach that. https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
Sirraide wrote: Can you test if that also fixes #125165? https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/cor3ntin commented: Thanks for doing that, this is neat https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
@@ -3492,10 +3492,13 @@ VarDecl *BindingDecl::getHoldingVar() const { return VD; } -llvm::ArrayRef BindingDecl::getBindingPackExprs() const { +llvm::ArrayRef BindingDecl::getBindingPackDecls() const { assert(Binding && "expecting a pack expr"); - auto *RP = cast(Binding); - return RP->getExprs(); + auto *FP = cast(Binding); + ValueDecl *const *First = FP->getNumExpansions() > 0 ? FP->begin() : nullptr; + assert((!First || isa(*First)) && "expecting a BindingDecl"); + return llvm::ArrayRef((BindingDecl *const *)First, + FP->getNumExpansions()); cor3ntin wrote: ```suggestion auto *FP = cast(Binding); if(FP->getNumExpansions() == 0) return {}; return llvm::ArrayRef(cast(FP->begin()), FP->getNumExpansions()); ``` I haven't tested but something like that looks simpler (the cast does the assert, and if there is nothing to expand we can as well return early) https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/cor3ntin edited https://github.com/llvm/llvm-project/pull/125394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
https://github.com/ricejasonf created https://github.com/llvm/llvm-project/pull/125394 This merges the functionality of ResolvedUnexpandedPackExpr into FunctionParmPackExpr. I also added a test to show that https://github.com/llvm/llvm-project/issues/125103 should be fixed with this. I put the removal of ResolvedUnexpandedPackExpr in its own commit. Let me know what you think. @cor3ntin >From a323e058b2c8adf97f7f9a55a9187f74de9b8d17 Mon Sep 17 00:00:00 2001 From: Jason Rice Date: Sun, 2 Feb 2025 00:52:47 -0800 Subject: [PATCH 1/2] [Clang][P1061] Consolidate ResolvedUnexpandedPackExpr into FunctionParmPackExpr --- clang/include/clang/AST/DeclCXX.h | 28 + clang/include/clang/AST/ExprCXX.h | 21 +- clang/include/clang/Sema/Template.h | 2 +- clang/lib/AST/DeclCXX.cpp | 9 +++-- clang/lib/AST/ExprCXX.cpp | 14 +++ clang/lib/Sema/SemaDeclCXX.cpp| 26 ++-- clang/lib/Sema/SemaExpr.cpp | 6 +-- clang/lib/Sema/SemaTemplateInstantiate.cpp| 30 +- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 40 +++ clang/lib/Sema/SemaTemplateVariadic.cpp | 32 +-- clang/lib/Serialization/ASTReaderStmt.cpp | 6 +-- clang/test/AST/ast-dump-binding-pack.cpp | 13 ++ clang/test/SemaCXX/cxx2c-binding-pack.cpp | 11 + 13 files changed, 103 insertions(+), 135 deletions(-) diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index 766821b4fb25cb..1c630d61690355 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -4194,8 +4194,8 @@ class BindingDecl : public ValueDecl { /// decomposition declaration, and when the initializer is type-dependent. Expr *getBinding() const { return Binding; } - // Get the array of Exprs when the binding represents a pack. - llvm::ArrayRef getBindingPackExprs() const; + // Get the array of nested BindingDecls when the binding represents a pack. + llvm::ArrayRef getBindingPackDecls() const; /// Get the decomposition declaration that this binding represents a /// decomposition of. @@ -4246,10 +4246,8 @@ class DecompositionDecl final for (auto *B : Bindings) { B->setDecomposedDecl(this); if (B->isParameterPack() && B->getBinding()) { -for (Expr *E : B->getBindingPackExprs()) { - auto *DRE = cast(E); - auto *NestedB = cast(DRE->getDecl()); - NestedB->setDecomposedDecl(this); +for (BindingDecl *NestedBD : B->getBindingPackDecls()) { + NestedBD->setDecomposedDecl(this); } } } @@ -4278,25 +4276,21 @@ class DecompositionDecl final // Provide a flattened range to visit each binding. auto flat_bindings() const { llvm::ArrayRef Bindings = bindings(); -llvm::ArrayRef PackExprs; +llvm::ArrayRef PackBindings; // Split the bindings into subranges split by the pack. -auto S1 = Bindings.take_until( +auto BeforePackBindings = Bindings.take_until( [](BindingDecl *BD) { return BD->isParameterPack(); }); -Bindings = Bindings.drop_front(S1.size()); +Bindings = Bindings.drop_front(BeforePackBindings.size()); if (!Bindings.empty()) { - PackExprs = Bindings.front()->getBindingPackExprs(); + PackBindings = Bindings.front()->getBindingPackDecls(); Bindings = Bindings.drop_front(); } -auto S2 = llvm::map_range(PackExprs, [](Expr *E) { - auto *DRE = cast(E); - return cast(DRE->getDecl()); -}); - -return llvm::concat(std::move(S1), std::move(S2), - std::move(Bindings)); +return llvm::concat(std::move(BeforePackBindings), +std::move(PackBindings), +std::move(Bindings)); } void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override; diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 0b6c8cfb163c95..2b23fa51c6232b 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -4649,13 +4649,13 @@ class SubstNonTypeTemplateParmPackExpr : public Expr { /// \endcode class FunctionParmPackExpr final : public Expr, - private llvm::TrailingObjects { + private llvm::TrailingObjects { friend class ASTReader; friend class ASTStmtReader; friend TrailingObjects; /// The function parameter pack which was referenced. - VarDecl *ParamPack; + ValueDecl *ParamPack; /// The location of the function parameter pack reference. SourceLocation NameLoc; @@ -4663,35 +4663,34 @@ class FunctionParmPackExpr final /// The number of expansions of this pack. unsigned NumParameters; - FunctionParmPackExpr(QualType T, VarDecl *ParamPack, - SourceLocation NameLoc, unsigned NumParams
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
llvmbot wrote: @llvm/pr-subscribers-clang-modules Author: Jason Rice (ricejasonf) Changes This merges the functionality of ResolvedUnexpandedPackExpr into FunctionParmPackExpr. I also added a test to show that https://github.com/llvm/llvm-project/issues/125103 should be fixed with this. I put the removal of ResolvedUnexpandedPackExpr in its own commit. Let me know what you think. @cor3ntin --- Patch is 46.18 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/125394.diff 29 Files Affected: - (modified) clang/include/clang/AST/DeclCXX.h (+11-17) - (modified) clang/include/clang/AST/ExprCXX.h (+10-64) - (modified) clang/include/clang/AST/RecursiveASTVisitor.h (-1) - (modified) clang/include/clang/Basic/StmtNodes.td (-1) - (modified) clang/include/clang/Sema/Sema.h (+1-2) - (modified) clang/include/clang/Sema/Template.h (+1-1) - (modified) clang/include/clang/Serialization/ASTBitCodes.h (-1) - (modified) clang/lib/AST/DeclCXX.cpp (+6-3) - (modified) clang/lib/AST/Expr.cpp (-1) - (modified) clang/lib/AST/ExprCXX.cpp (+7-56) - (modified) clang/lib/AST/ExprClassification.cpp (-7) - (modified) clang/lib/AST/ExprConstant.cpp (-1) - (modified) clang/lib/AST/ItaniumMangle.cpp (+1-2) - (modified) clang/lib/AST/StmtPrinter.cpp (-9) - (modified) clang/lib/AST/StmtProfile.cpp (-4) - (modified) clang/lib/Sema/SemaDeclCXX.cpp (+13-13) - (modified) clang/lib/Sema/SemaExceptionSpec.cpp (-1) - (modified) clang/lib/Sema/SemaExpr.cpp (+3-3) - (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+11-36) - (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+15-25) - (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (+10-38) - (modified) clang/lib/Sema/TreeTransform.h (-25) - (modified) clang/lib/Serialization/ASTReaderStmt.cpp (+3-19) - (modified) clang/lib/Serialization/ASTWriter.cpp (-1) - (modified) clang/lib/Serialization/ASTWriterStmt.cpp (-10) - (modified) clang/lib/StaticAnalyzer/Core/ExprEngine.cpp (-1) - (modified) clang/test/AST/ast-dump-binding-pack.cpp (+3-10) - (modified) clang/test/SemaCXX/cxx2c-binding-pack.cpp (+11) - (modified) clang/tools/libclang/CXCursor.cpp (-1) ``diff diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index 766821b4fb25cb5..1c630d616903550 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -4194,8 +4194,8 @@ class BindingDecl : public ValueDecl { /// decomposition declaration, and when the initializer is type-dependent. Expr *getBinding() const { return Binding; } - // Get the array of Exprs when the binding represents a pack. - llvm::ArrayRef getBindingPackExprs() const; + // Get the array of nested BindingDecls when the binding represents a pack. + llvm::ArrayRef getBindingPackDecls() const; /// Get the decomposition declaration that this binding represents a /// decomposition of. @@ -4246,10 +4246,8 @@ class DecompositionDecl final for (auto *B : Bindings) { B->setDecomposedDecl(this); if (B->isParameterPack() && B->getBinding()) { -for (Expr *E : B->getBindingPackExprs()) { - auto *DRE = cast(E); - auto *NestedB = cast(DRE->getDecl()); - NestedB->setDecomposedDecl(this); +for (BindingDecl *NestedBD : B->getBindingPackDecls()) { + NestedBD->setDecomposedDecl(this); } } } @@ -4278,25 +4276,21 @@ class DecompositionDecl final // Provide a flattened range to visit each binding. auto flat_bindings() const { llvm::ArrayRef Bindings = bindings(); -llvm::ArrayRef PackExprs; +llvm::ArrayRef PackBindings; // Split the bindings into subranges split by the pack. -auto S1 = Bindings.take_until( +auto BeforePackBindings = Bindings.take_until( [](BindingDecl *BD) { return BD->isParameterPack(); }); -Bindings = Bindings.drop_front(S1.size()); +Bindings = Bindings.drop_front(BeforePackBindings.size()); if (!Bindings.empty()) { - PackExprs = Bindings.front()->getBindingPackExprs(); + PackBindings = Bindings.front()->getBindingPackDecls(); Bindings = Bindings.drop_front(); } -auto S2 = llvm::map_range(PackExprs, [](Expr *E) { - auto *DRE = cast(E); - return cast(DRE->getDecl()); -}); - -return llvm::concat(std::move(S1), std::move(S2), - std::move(Bindings)); +return llvm::concat(std::move(BeforePackBindings), +std::move(PackBindings), +std::move(Bindings)); } void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override; diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 0b6c8cfb163c958..f6cf48cb66b801a 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -4649,13 +4649,13 @@ class SubstNo
[clang] [Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr (PR #125394)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Jason Rice (ricejasonf) Changes This merges the functionality of ResolvedUnexpandedPackExpr into FunctionParmPackExpr. I also added a test to show that https://github.com/llvm/llvm-project/issues/125103 should be fixed with this. I put the removal of ResolvedUnexpandedPackExpr in its own commit. Let me know what you think. @cor3ntin --- Patch is 46.18 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/125394.diff 29 Files Affected: - (modified) clang/include/clang/AST/DeclCXX.h (+11-17) - (modified) clang/include/clang/AST/ExprCXX.h (+10-64) - (modified) clang/include/clang/AST/RecursiveASTVisitor.h (-1) - (modified) clang/include/clang/Basic/StmtNodes.td (-1) - (modified) clang/include/clang/Sema/Sema.h (+1-2) - (modified) clang/include/clang/Sema/Template.h (+1-1) - (modified) clang/include/clang/Serialization/ASTBitCodes.h (-1) - (modified) clang/lib/AST/DeclCXX.cpp (+6-3) - (modified) clang/lib/AST/Expr.cpp (-1) - (modified) clang/lib/AST/ExprCXX.cpp (+7-56) - (modified) clang/lib/AST/ExprClassification.cpp (-7) - (modified) clang/lib/AST/ExprConstant.cpp (-1) - (modified) clang/lib/AST/ItaniumMangle.cpp (+1-2) - (modified) clang/lib/AST/StmtPrinter.cpp (-9) - (modified) clang/lib/AST/StmtProfile.cpp (-4) - (modified) clang/lib/Sema/SemaDeclCXX.cpp (+13-13) - (modified) clang/lib/Sema/SemaExceptionSpec.cpp (-1) - (modified) clang/lib/Sema/SemaExpr.cpp (+3-3) - (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+11-36) - (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+15-25) - (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (+10-38) - (modified) clang/lib/Sema/TreeTransform.h (-25) - (modified) clang/lib/Serialization/ASTReaderStmt.cpp (+3-19) - (modified) clang/lib/Serialization/ASTWriter.cpp (-1) - (modified) clang/lib/Serialization/ASTWriterStmt.cpp (-10) - (modified) clang/lib/StaticAnalyzer/Core/ExprEngine.cpp (-1) - (modified) clang/test/AST/ast-dump-binding-pack.cpp (+3-10) - (modified) clang/test/SemaCXX/cxx2c-binding-pack.cpp (+11) - (modified) clang/tools/libclang/CXCursor.cpp (-1) ``diff diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index 766821b4fb25cb5..1c630d616903550 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -4194,8 +4194,8 @@ class BindingDecl : public ValueDecl { /// decomposition declaration, and when the initializer is type-dependent. Expr *getBinding() const { return Binding; } - // Get the array of Exprs when the binding represents a pack. - llvm::ArrayRef getBindingPackExprs() const; + // Get the array of nested BindingDecls when the binding represents a pack. + llvm::ArrayRef getBindingPackDecls() const; /// Get the decomposition declaration that this binding represents a /// decomposition of. @@ -4246,10 +4246,8 @@ class DecompositionDecl final for (auto *B : Bindings) { B->setDecomposedDecl(this); if (B->isParameterPack() && B->getBinding()) { -for (Expr *E : B->getBindingPackExprs()) { - auto *DRE = cast(E); - auto *NestedB = cast(DRE->getDecl()); - NestedB->setDecomposedDecl(this); +for (BindingDecl *NestedBD : B->getBindingPackDecls()) { + NestedBD->setDecomposedDecl(this); } } } @@ -4278,25 +4276,21 @@ class DecompositionDecl final // Provide a flattened range to visit each binding. auto flat_bindings() const { llvm::ArrayRef Bindings = bindings(); -llvm::ArrayRef PackExprs; +llvm::ArrayRef PackBindings; // Split the bindings into subranges split by the pack. -auto S1 = Bindings.take_until( +auto BeforePackBindings = Bindings.take_until( [](BindingDecl *BD) { return BD->isParameterPack(); }); -Bindings = Bindings.drop_front(S1.size()); +Bindings = Bindings.drop_front(BeforePackBindings.size()); if (!Bindings.empty()) { - PackExprs = Bindings.front()->getBindingPackExprs(); + PackBindings = Bindings.front()->getBindingPackDecls(); Bindings = Bindings.drop_front(); } -auto S2 = llvm::map_range(PackExprs, [](Expr *E) { - auto *DRE = cast(E); - return cast(DRE->getDecl()); -}); - -return llvm::concat(std::move(S1), std::move(S2), - std::move(Bindings)); +return llvm::concat(std::move(BeforePackBindings), +std::move(PackBindings), +std::move(Bindings)); } void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override; diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 0b6c8cfb163c958..f6cf48cb66b801a 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -4649,13 +4649,13 @@ class SubstNonTypeTem