-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][bytecode] Don't set OnePastEnd bit for array elements #136422
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
Conversation
If we refer to arr[N], don't set the OnePastEnd bit of the APValue, since that is already encoded in the array index.
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesIf we refer to arr[N], don't set the OnePastEnd bit of the APValue, since that is already encoded in the array index. Full diff: https://github.com/llvm/llvm-project/pull/136422.diff 2 Files Affected:
diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp
index 686ec381d232a..059503cae3561 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -223,6 +223,7 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
UsePath = false;
// Build the path into the object.
+ bool OnePastEnd = isOnePastEnd();
Pointer Ptr = *this;
while (Ptr.isField() || Ptr.isArrayElement()) {
@@ -251,9 +252,10 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
Ptr = Ptr.expand();
const Descriptor *Desc = Ptr.getFieldDesc();
unsigned Index;
- if (Ptr.isOnePastEnd())
+ if (Ptr.isOnePastEnd()) {
Index = Ptr.getArray().getNumElems();
- else
+ OnePastEnd = false;
+ } else
Index = Ptr.getIndex();
QualType ElemType = Desc->getElemQualType();
@@ -304,8 +306,7 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
std::reverse(Path.begin(), Path.end());
if (UsePath)
- return APValue(Base, Offset, Path,
- /*IsOnePastEnd=*/!isElementPastEnd() && isOnePastEnd());
+ return APValue(Base, Offset, Path, OnePastEnd);
return APValue(Base, Offset, APValue::NoLValuePath());
}
diff --git a/clang/test/AST/ByteCode/arrays.cpp b/clang/test/AST/ByteCode/arrays.cpp
index e50839e0f0877..934c3a3e7aff1 100644
--- a/clang/test/AST/ByteCode/arrays.cpp
+++ b/clang/test/AST/ByteCode/arrays.cpp
@@ -761,3 +761,13 @@ namespace PointerSubscript {
struct S{};
static_assert((foo<S>(), true));
}
+
+namespace OnePastEndDiag {
+
+ constexpr int a(const int *b) {
+ return *b; // both-note {{read of dereferenced one-past-the-end pointer}}
+ }
+ constexpr int foo[] = {1,2};
+ constexpr int k = a(foo + 2); // both-error {{must be initialized by a constant expression}} \
+ // both-note {{in call to 'a(&foo[2])'}}
+}
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/199/builds/2873 Here is the relevant piece of the build log for the reference
|
Update clang/test/AST/ByteCode/cxx20.cpp to align with the new behaviour in 6196b4e (llvm#136422).
…36422) If we refer to arr[N], don't set the OnePastEnd bit of the APValue, since that is already encoded in the array index.
…36422) If we refer to arr[N], don't set the OnePastEnd bit of the APValue, since that is already encoded in the array index.
…36422) If we refer to arr[N], don't set the OnePastEnd bit of the APValue, since that is already encoded in the array index.
If we refer to arr[N], don't set the OnePastEnd bit of the APValue, since that is already encoded in the array index.