-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang][Interp] Support AddOffset with 128bit offsets #68679
Conversation
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesWe do a similar things a few lines above for
Full diff: https://github.com/llvm/llvm-project/pull/68679.diff 2 Files Affected:
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.
|
clang/lib/AST/Interp/Interp.h
Outdated
@@ -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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should MaxIndex just be a T
as well? I wonder if this function should just be 'fully dedicated' to being T
instead of just this 1 variable here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dunno, We never compare MaxIndex
with anything of type T
. It's even only used twice and once is in the diagnostic output. The other one is line 1440 above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should make the math operate on a T
consistently, especially given that Offset
and Index
are already a T
. The mixture of types is a bit of a code smell IMO.
10d205d
to
5fff64e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
5fff64e
to
9598f33
Compare
9598f33
to
8aae860
Compare
Local branch amd-gfx b77230b Revert "Revert "ConstantFolding: Constant fold denormal inputs to canonicalize for IEEE"" Remote branch main 3efa479 [clang][Interp] Support AddOffset with 128bit offsets (llvm#68679)
We do a similar thing a few lines above for
Index
: