[clang] [clang][bytecode] Only block pointers can be partially initialized (PR #160075)

via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 22 04:26:03 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

So ignore the rest in `checkFullyInitialized()`.

Fixes #<!-- -->160071

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/EvaluationResult.cpp (+2) 
- (modified) clang/test/AST/ByteCode/typeid.cpp (+11-4) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/EvaluationResult.cpp b/clang/lib/AST/ByteCode/EvaluationResult.cpp
index ba818788d7026..7c3c21cf28251 100644
--- a/clang/lib/AST/ByteCode/EvaluationResult.cpp
+++ b/clang/lib/AST/ByteCode/EvaluationResult.cpp
@@ -133,6 +133,8 @@ bool EvaluationResult::checkFullyInitialized(InterpState &S,
 
   if (Ptr.isZero())
     return true;
+  if (!Ptr.isBlockPointer())
+    return true;
 
   // We can't inspect dead pointers at all. Return true here so we can
   // diagnose them later.
diff --git a/clang/test/AST/ByteCode/typeid.cpp b/clang/test/AST/ByteCode/typeid.cpp
index 179a66fd7fd0a..00b01c8e40682 100644
--- a/clang/test/AST/ByteCode/typeid.cpp
+++ b/clang/test/AST/ByteCode/typeid.cpp
@@ -32,10 +32,10 @@ static_assert(&typeid(int) < &typeid(long)); // both-error {{not an integral con
 static_assert(&typeid(int) > &typeid(long)); // both-error {{not an integral constant expression}} \
                                              // both-note {{comparison between pointers to unrelated objects '&typeid(int)' and '&typeid(long)' has unspecified value}}
 
- struct Base {
-   virtual void func() ;
- };
- struct Derived : Base {};
+struct Base {
+ virtual void func() ;
+};
+struct Derived : Base {};
 
 constexpr bool test() {
   Derived derived;
@@ -52,3 +52,10 @@ int dontcrash() {
   );
   return pti.__flags == 0 ? 1 : 0;
 }
+
+namespace TypeidPtrInEvaluationResult {
+  struct C {};
+  C c = C();
+  consteval const std::type_info *ftype_info() { return &typeid(c); }
+  const std::type_info *T1 = ftype_info();
+}

``````````

</details>


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


More information about the cfe-commits mailing list