https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/152706
None >From 328fa47105c81b659e059e9be93c75a32a30fd28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Fri, 8 Aug 2025 14:18:45 +0200 Subject: [PATCH] [clang][bytecode] Handle reads on zero-size arrays --- clang/lib/AST/ByteCode/Interp.cpp | 4 +--- clang/test/AST/ByteCode/arrays.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index bc14bd3d1bb99..b5c044cad60f8 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -518,7 +518,7 @@ bool CheckNull(InterpState &S, CodePtr OpPC, const Pointer &Ptr, bool CheckRange(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK) { - if (!Ptr.isOnePastEnd()) + if (!Ptr.isOnePastEnd() && !Ptr.isZeroSizeArray()) return true; if (S.getLangOpts().CPlusPlus) { const SourceInfo &Loc = S.Current->getSource(OpPC); @@ -829,8 +829,6 @@ bool CheckFinalLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { return false; if (!CheckExtern(S, OpPC, Ptr)) return false; - if (!CheckRange(S, OpPC, Ptr, AK_Read)) - return false; if (!CheckActive(S, OpPC, Ptr, AK_Read)) return false; if (!CheckLifetime(S, OpPC, Ptr.getLifetime(), AK_Read)) diff --git a/clang/test/AST/ByteCode/arrays.cpp b/clang/test/AST/ByteCode/arrays.cpp index 2dd51c2fa6711..087d0e9bd6630 100644 --- a/clang/test/AST/ByteCode/arrays.cpp +++ b/clang/test/AST/ByteCode/arrays.cpp @@ -779,3 +779,16 @@ namespace DiscardedSubScriptExpr { return true; } } + +namespace ZeroSizeArrayRead { + constexpr char str[0] = {}; + constexpr unsigned checksum(const char *s) { + unsigned result = 0; + for (const char *p = s; *p != '\0'; ++p) { // both-note {{read of dereferenced one-past-the-end pointer}} + result += *p; + } + return result; + } + constexpr unsigned C = checksum(str); // both-error {{must be initialized by a constant expression}} \ + // both-note {{in call to}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits