[clang] [clang][bytecode] Don't check lvalue expresions for initialization (PR #181309)

via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 12 21:49:53 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

We're not reading from them, so they don't need to be fully initialized.

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


3 Files Affected:

- (modified) clang/lib/AST/ByteCode/EvalEmitter.cpp (+1-1) 
- (modified) clang/test/AST/ByteCode/cxx23.cpp (+10) 
- (modified) clang/test/CodeGenCXX/cxx2a-consteval.cpp (+2-4) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp
index 7c120b9ecc17c..ee168a82d20a2 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.cpp
+++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp
@@ -37,7 +37,7 @@ EvaluationResult EvalEmitter::interpretExpr(const Expr *E,
                                             bool DestroyToplevelScope) {
   S.setEvalLocation(E->getExprLoc());
   this->ConvertResultToRValue = ConvertResultToRValue && !isa<ConstantExpr>(E);
-  this->CheckFullyInitialized = isa<ConstantExpr>(E);
+  this->CheckFullyInitialized = isa<ConstantExpr>(E) && !E->isGLValue();
   EvalResult.setSource(E);
 
   if (!this->visitExpr(E, DestroyToplevelScope)) {
diff --git a/clang/test/AST/ByteCode/cxx23.cpp b/clang/test/AST/ByteCode/cxx23.cpp
index e3be7887c357e..a1aecf329327a 100644
--- a/clang/test/AST/ByteCode/cxx23.cpp
+++ b/clang/test/AST/ByteCode/cxx23.cpp
@@ -594,3 +594,13 @@ namespace NonCompoundStmtBody {
   }
   static_assert(testS());
 }
+
+namespace LValueConstant {
+  struct D {
+    unsigned y;
+  };
+
+  extern D d;
+  consteval D& c() { return d; }
+  long long f() { return c().y; }
+}
diff --git a/clang/test/CodeGenCXX/cxx2a-consteval.cpp b/clang/test/CodeGenCXX/cxx2a-consteval.cpp
index ace603ffe5713..db284c4108334 100644
--- a/clang/test/CodeGenCXX/cxx2a-consteval.cpp
+++ b/clang/test/CodeGenCXX/cxx2a-consteval.cpp
@@ -7,12 +7,12 @@
 // RUN: %clang_cc1 -emit-llvm %s -Dconsteval="" -std=c++2a -triple x86_64-unknown-linux-gnu -o %t.ll
 // RUN: FileCheck -check-prefix=EXPR -input-file=%t.ll %s
 
-// RUN: %clang_cc1 -emit-llvm %s -DEXPR -std=c++2a -triple x86_64-unknown-linux-gnu -o %t.ll -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -emit-llvm %s -std=c++2a -triple x86_64-unknown-linux-gnu -o %t.ll -fexperimental-new-constant-interpreter
 // RUN: FileCheck -check-prefix=EVAL -input-file=%t.ll %s
 // RUN: FileCheck -check-prefix=EVAL-STATIC -input-file=%t.ll %s
 // RUN: FileCheck -check-prefix=EVAL-FN -input-file=%t.ll %s
 //
-// RUN: %clang_cc1 -emit-llvm %s -DEXPR -Dconsteval="" -std=c++2a -triple x86_64-unknown-linux-gnu -o %t.ll -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -emit-llvm %s -Dconsteval="" -std=c++2a -triple x86_64-unknown-linux-gnu -o %t.ll -fexperimental-new-constant-interpreter
 // RUN: FileCheck -check-prefix=EXPR -input-file=%t.ll %s
 
 // there is two version of symbol checks to ensure
@@ -260,7 +260,6 @@ int test_UserConvOverload_ceval() {
   return test_UserConvOverload_helper_ceval(UserConv());
 }
 
-#ifndef EXPR
 namespace virt {
 struct A { alignas(32) char a[32]; };
 struct B : virtual A {
@@ -280,7 +279,6 @@ long long f() { return c().y; }
 // EVAL-FN-NONEXPR-NEXT: load i64, ptr getelementptr inbounds nuw (%"struct.virt::B", ptr getelementptr (i8, ptr @_ZN4virt1dE, i64 8), i32 0, i32 2), align 8
 // EVAL-FN-NONEXPR-NEXT: ret i64
 } // namespace virt
-#endif
 
 consteval void void_test() {}
 void void_call() { // EVAL-FN-LABEL: define {{.*}} @_Z9void_call

``````````

</details>


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


More information about the cfe-commits mailing list