https://github.com/yronglin updated https://github.com/llvm/llvm-project/pull/100400
>From 6ede7586fc4602ab15be59c58fe5f7181ffaca16 Mon Sep 17 00:00:00 2001 From: yronglin <yronglin...@gmail.com> Date: Wed, 24 Jul 2024 23:12:27 +0800 Subject: [PATCH 1/2] [Clang][Interp] Fix handling of DecompositionDecl Signed-off-by: yronglin <yronglin...@gmail.com> --- clang/lib/AST/Interp/Compiler.cpp | 13 +++++++++++-- clang/test/SemaCXX/cxx1z-decomposition.cpp | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp index 0fc93c14131e6..6e2f0dbc39dcf 100644 --- a/clang/lib/AST/Interp/Compiler.cpp +++ b/clang/lib/AST/Interp/Compiler.cpp @@ -3593,8 +3593,14 @@ VarCreationState Compiler<Emitter>::visitDecl(const VarDecl *VD) { if (R.notCreated()) return R; - if (R) - return true; + if (R) { + bool Ok = true; + if (const auto *DD = dyn_cast<DecompositionDecl>(VD)) + for (const auto *BD : DD->bindings()) + if (const auto *HoldingVar = BD->getHoldingVar()) + Ok &= this->visitDecl(HoldingVar); + return Ok; + } if (!R && Context::shouldBeGloballyIndexed(VD)) { if (auto GlobalIndex = P.getGlobal(VD)) { @@ -5234,6 +5240,9 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) { return false; }; + if (isa<DecompositionDecl>(VD)) + return revisit(VD); + // Visit local const variables like normal. if ((VD->hasGlobalStorage() || VD->isLocalVarDecl() || VD->isStaticDataMember()) && diff --git a/clang/test/SemaCXX/cxx1z-decomposition.cpp b/clang/test/SemaCXX/cxx1z-decomposition.cpp index 305a9ac2ebc24..19c730303625e 100644 --- a/clang/test/SemaCXX/cxx1z-decomposition.cpp +++ b/clang/test/SemaCXX/cxx1z-decomposition.cpp @@ -1,5 +1,6 @@ // RUN: %clang_cc1 -std=c++17 -Wc++20-extensions -verify=expected %s // RUN: %clang_cc1 -std=c++20 -Wpre-c++20-compat -verify=expected %s +// RUN: %clang_cc1 -std=c++20 -Wpre-c++20-compat -fexperimental-new-constant-interpreter -verify=expected %s void use_from_own_init() { auto [a] = a; // expected-error {{binding 'a' cannot appear in the initializer of its own decomposition declaration}} >From 4a4e2c28d48aa944c28db8865cfa0c76f9ce7e9a Mon Sep 17 00:00:00 2001 From: yronglin <yronglin...@gmail.com> Date: Thu, 25 Jul 2024 18:57:05 +0800 Subject: [PATCH 2/2] Address review comments Signed-off-by: yronglin <yronglin...@gmail.com> --- clang/lib/AST/Interp/Compiler.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp index 6e2f0dbc39dcf..1de4f3255007e 100644 --- a/clang/lib/AST/Interp/Compiler.cpp +++ b/clang/lib/AST/Interp/Compiler.cpp @@ -3593,14 +3593,8 @@ VarCreationState Compiler<Emitter>::visitDecl(const VarDecl *VD) { if (R.notCreated()) return R; - if (R) { - bool Ok = true; - if (const auto *DD = dyn_cast<DecompositionDecl>(VD)) - for (const auto *BD : DD->bindings()) - if (const auto *HoldingVar = BD->getHoldingVar()) - Ok &= this->visitDecl(HoldingVar); - return Ok; - } + if (R) + return true; if (!R && Context::shouldBeGloballyIndexed(VD)) { if (auto GlobalIndex = P.getGlobal(VD)) { @@ -5240,6 +5234,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) { return false; }; + // DecompositionDecls are just proxies for us. if (isa<DecompositionDecl>(VD)) return revisit(VD); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits