[clang] 847d046 - [clang][Interp] Fix comparing one-past-the-end pointers
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 26 04:55:07 PDT 2024
Author: Timm Bäder
Date: 2024-06-26T13:54:53+02:00
New Revision: 847d046a82a760caa1b05206d77ed0b3d7bd4be6
URL: https://github.com/llvm/llvm-project/commit/847d046a82a760caa1b05206d77ed0b3d7bd4be6
DIFF: https://github.com/llvm/llvm-project/commit/847d046a82a760caa1b05206d77ed0b3d7bd4be6.diff
LOG: [clang][Interp] Fix comparing one-past-the-end pointers
Added:
Modified:
clang/lib/AST/Interp/Pointer.h
clang/test/AST/Interp/arrays.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h
index 609367a462b00..0cd26ecf73f24 100644
--- a/clang/lib/AST/Interp/Pointer.h
+++ b/clang/lib/AST/Interp/Pointer.h
@@ -513,6 +513,8 @@ class Pointer {
unsigned getByteOffset() const {
if (isIntegralPointer())
return asIntPointer().Value + Offset;
+ if (isOnePastEnd())
+ return PastEndMark;
return Offset;
}
diff --git a/clang/test/AST/Interp/arrays.cpp b/clang/test/AST/Interp/arrays.cpp
index 6f6fca8c1cfd8..7d231d3759421 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -26,6 +26,9 @@ static_assert(foo[2][2] == nullptr, "");
static_assert(foo[2][3] == &m, "");
static_assert(foo[2][4] == nullptr, "");
+constexpr int afterEnd[] = {1,2,3};
+static_assert(&afterEnd[3] == afterEnd + 3, "");
+
constexpr int ZeroSizeArray[] = {};
constexpr int SomeInt[] = {1};
More information about the cfe-commits
mailing list