[clang] [clang][bytecode] Handle zero pointers in `isConstexprUnknown()` (PR #191691)

via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 12 01:04:18 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>



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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Interp.cpp (+1-1) 
- (modified) clang/test/AST/ByteCode/cxx17.cpp (+26) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 8cc3c9216f7f4..0a5270bef2b82 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -266,7 +266,7 @@ bool isConstexprUnknown(const Block *B) {
 }
 
 bool isConstexprUnknown(const Pointer &P) {
-  if (!P.isBlockPointer())
+  if (!P.isBlockPointer() || P.isZero())
     return false;
   return isConstexprUnknown(P.block());
 }
diff --git a/clang/test/AST/ByteCode/cxx17.cpp b/clang/test/AST/ByteCode/cxx17.cpp
index 0cf3a4f666d63..583d9879ad245 100644
--- a/clang/test/AST/ByteCode/cxx17.cpp
+++ b/clang/test/AST/ByteCode/cxx17.cpp
@@ -149,3 +149,29 @@ namespace NonConstexprStructuredBinding {
     static_assert(&a != &b);
   }
 }
+
+
+
+
+int d, m;
+struct C {
+  constexpr C() {}
+  constexpr C(const C &) {}
+  template <int I> int &get() const {
+    // static_assert(d == 1 + I);
+    ++d;
+    return m;
+  }
+};
+
+template <> struct std::tuple_size<const C> {
+  static const int value = 3;
+};
+template <int I> struct std::tuple_element<I, const C> {
+  using type = int;
+};
+
+namespace ZeroInCheckInvoke {
+  constexpr C foo(const C &) { return C{}; }
+  thread_local const auto &[s, t, u] = foo(C{}); // both-warning {{thread_local}}
+}

``````````

</details>


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


More information about the cfe-commits mailing list