From dead8f845f2549db5dec16b59b80d3e321948674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Wed, 26 Jun 2024 15:39:49 +0200 Subject: [PATCH] [clang][Interp] Pointers into unknown-size arrays are never one-past-end --- clang/lib/AST/Interp/Pointer.h | 3 +++ clang/test/AST/Interp/arrays.cpp | 1 + 2 files changed, 4 insertions(+) diff --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h index 0cd26ecf73f246..5faec75cc3ec51 100644 --- a/clang/lib/AST/Interp/Pointer.h +++ b/clang/lib/AST/Interp/Pointer.h @@ -553,6 +553,9 @@ class Pointer { if (!asBlockPointer().Pointee) return false; + if (isUnknownSizeArray()) + return false; + return isElementPastEnd() || (getSize() == getOffset() && !isZeroSizeArray()); } diff --git a/clang/test/AST/Interp/arrays.cpp b/clang/test/AST/Interp/arrays.cpp index 7d231d37594211..26ec39e9cca65b 100644 --- a/clang/test/AST/Interp/arrays.cpp +++ b/clang/test/AST/Interp/arrays.cpp @@ -626,3 +626,4 @@ constexpr int *get2() { extern int same_entity_2[]; return same_entity_2; } +static_assert(get2() == same_entity_2, "failed to find previous decl");