[clang] [clang][Interp] Support AddOffset with 128bit offsets (PR #68679)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 10 02:35:21 PDT 2023
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/68679
We do a similar things a few lines above for `Index`:
```
// Get a version of the index comparable to the type.
T Index = T::from(Ptr.getIndex(), Offset.bitWidth());
```
>From 10d205da4c220227589ce210bf921f86ead4d05f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Tue, 10 Oct 2023 08:52:43 +0200
Subject: [PATCH] [clang][Interp] Support AddOffset with 128bit offsets
---
clang/lib/AST/Interp/Interp.h | 2 +-
clang/test/AST/Interp/intap.cpp | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 47dc1d08c9c4d8b..620d797da27023f 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1437,7 +1437,7 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T &Offset,
return false;
};
- unsigned MaxOffset = MaxIndex - Ptr.getIndex();
+ T MaxOffset = T::from(MaxIndex - Ptr.getIndex(), Offset.bitWidth());
if constexpr (Op == ArithOp::Add) {
// If the new offset would be negative, bail out.
if (Offset.isNegative() && (Offset.isMin() || -Offset > Index))
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index b3f02d2b769531d..e9e68438bb597aa 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -76,6 +76,15 @@ namespace i128 {
// expected-note {{is outside the range of representable values of type}}
}
+namespace AddSubOffset {
+ constexpr __int128 A = 1;
+ constexpr int arr[] = {1,2,3};
+ constexpr const int *P = arr + A;
+ static_assert(*P == 2, "");
+ constexpr const int *P2 = P - A;
+ static_assert(*P2 == 1,"");
+}
+
#else
/// No int128 support, so no expected directives.
More information about the cfe-commits
mailing list