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

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 12 01:03:45 PDT 2026


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

None

>From 03c63ed3b5e4e468143369d5fc97449bc2c1537d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Sun, 12 Apr 2026 10:02:44 +0200
Subject: [PATCH] [clang][bytecode] Handle zero pointers in
 `isConstexprUnknown()`

---
 clang/lib/AST/ByteCode/Interp.cpp |  2 +-
 clang/test/AST/ByteCode/cxx17.cpp | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

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



More information about the cfe-commits mailing list