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

Sirui Mu via cfe-commits cfe-commits at lists.llvm.org
Sat Jun 14 07:30:29 PDT 2025


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

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.

>From 50afed782f9763a545216bf54839eb637befd9c6 Mon Sep 17 00:00:00 2001
From: Sirui Mu <msrlancern at gmail.com>
Date: Sat, 14 Jun 2025 22:25:48 +0800
Subject: [PATCH] [clang][Bytecode] Avoid revisiting decomposition decl

---
 clang/lib/AST/ByteCode/Compiler.cpp            | 4 ----
 clang/test/AST/ByteCode/structured-binding.cpp | 8 ++++++++
 2 files changed, 8 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/AST/ByteCode/structured-binding.cpp

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
+}



More information about the cfe-commits mailing list