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

None

>From 3c40c1be3ca32fde3d04888ffb14154bd03e2d00 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Mon, 2 Nov 2026 09:46:38 +0100
Subject: [PATCH] [clang][bytecode] Diagnose one-past-end pointers in
 evaluateStringRepr

---
 clang/lib/AST/ByteCode/Context.cpp         | 10 ++++++++--
 clang/test/SemaCXX/static-assert-cxx26.cpp | 12 ++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Context.cpp 
b/clang/lib/AST/ByteCode/Context.cpp
index 5dd73467dfe914..378a1f6f6538b1 100644
--- a/clang/lib/AST/ByteCode/Context.cpp
+++ b/clang/lib/AST/ByteCode/Context.cpp
@@ -219,8 +219,14 @@ bool Context::evaluateStringRepr(const EvalSettings 
&Settings,
       return false;
     }
 
-    if (!Ptr.isLive() || !Ptr.isInitialized() || Ptr.isUnknownSizeArray() ||
-        !Ptr.inArray())
+    if (Ptr.isOnePastEnd()) {
+      S.FFDiag(S.Current->getSource(OpPC), 
diag::note_constexpr_access_past_end)
+          << AK_Read;
+      return false;
+    }
+
+    if (!Ptr.isLive() || Ptr.isUnknownSizeArray() || !Ptr.inArray() ||
+        !Ptr.isReadablePointerType() || !Ptr.isInitialized())
       return false;
 
     // Must be char.
diff --git a/clang/test/SemaCXX/static-assert-cxx26.cpp 
b/clang/test/SemaCXX/static-assert-cxx26.cpp
index 644805a9e84c7d..043f9dbf189323 100644
--- a/clang/test/SemaCXX/static-assert-cxx26.cpp
+++ b/clang/test/SemaCXX/static-assert-cxx26.cpp
@@ -426,3 +426,15 @@ namespace DataPtrIsNull {
                              // expected-note {{read of dereferenced null 
pointer is not allowed in a constant expression}} \
                              // expected-error {{static assertion failed}}
 }
+
+namespace OnePastEndRead {
+  constexpr const char foo[] = {};
+
+  struct S {
+    constexpr int size() const { return 4; }
+    constexpr const char *data() const { return foo; }
+  };
+  static_assert(false, S{}); // expected-error {{must be produced by a 
constant expression}} \
+                             // expected-note {{read of dereferenced 
one-past-the-end pointer}} \
+                             // expected-error {{static assertion failed}}
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to