[clang] [clang][bytecode] Avoid revisiting decomposition decl in visitDeclRef (PR #144226)

via cfe-commits cfe-commits at lists.llvm.org
Sat Jun 14 07:31:02 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Sirui Mu (Lancern)

<details>
<summary>Changes</summary>

This simple patch removes the code to revisit `DecompositionDecl` in `visitDeclRef`. The revisit will try to emit the initializer of the `DecompositionDecl`, which could result in evaluation errors if the `DecompositionDecl` is not within a constexpr context.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (-4) 
- (added) clang/test/AST/ByteCode/structured-binding.cpp (+8) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index bf38b2e5d537d..9fe4803ce98ec 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6591,10 +6591,6 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
     return T->isReferenceType();
   };
 
-  // DecompositionDecls are just proxies for us.
-  if (isa<DecompositionDecl>(VD))
-    return revisit(VD);
-
   if ((VD->hasGlobalStorage() || VD->isStaticDataMember()) &&
       typeShouldBeVisited(VD->getType())) {
     if (const Expr *Init = VD->getAnyInitializer();
diff --git a/clang/test/AST/ByteCode/structured-binding.cpp b/clang/test/AST/ByteCode/structured-binding.cpp
new file mode 100644
index 0000000000000..63eaad8448249
--- /dev/null
+++ b/clang/test/AST/ByteCode/structured-binding.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -std=c++17 -verify %s
+
+void f1() {
+  int arr[2] = {};
+  auto [a, b] = arr;
+  static_assert(&a != &b);  // expected-no-diagnostics
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/144226


More information about the cfe-commits mailing list