Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions clang/lib/AST/ByteCode/Pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
}
Expand Down
10 changes: 10 additions & 0 deletions clang/test/AST/ByteCode/arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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])'}}
}
Loading