Skip to content

Commit d054832

Browse files
committed
[clang][Interp] Handle dummy pointers in ArrayElemPtr{,Pop} differently
Instead of returning false, just ignore the operation and return true; This gives us the desired diagnostic behavior in the added test case.
1 parent 50c5107 commit d054832

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

clang/lib/AST/Interp/Interp.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,7 +1856,7 @@ inline bool ArrayElemPtr(InterpState &S, CodePtr OpPC) {
18561856
const Pointer &Ptr = S.Stk.peek<Pointer>();
18571857

18581858
if (!CheckDummy(S, OpPC, Ptr))
1859-
return false;
1859+
return true;
18601860

18611861
if (!OffsetHelper<T, ArithOp::Add>(S, OpPC, Offset, Ptr))
18621862
return false;
@@ -1869,8 +1869,10 @@ inline bool ArrayElemPtrPop(InterpState &S, CodePtr OpPC) {
18691869
const T &Offset = S.Stk.pop<T>();
18701870
const Pointer &Ptr = S.Stk.pop<Pointer>();
18711871

1872-
if (!CheckDummy(S, OpPC, Ptr))
1873-
return false;
1872+
if (!CheckDummy(S, OpPC, Ptr)) {
1873+
S.Stk.push<Pointer>(Ptr);
1874+
return true;
1875+
}
18741876

18751877
if (!OffsetHelper<T, ArithOp::Add>(S, OpPC, Offset, Ptr))
18761878
return false;

clang/test/AST/Interp/c.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,8 @@ _Static_assert(sizeof(name2) == 0, ""); // expected-error {{failed}} \
129129
// expected-note {{evaluates to}} \
130130
// pedantic-expected-error {{failed}} \
131131
// pedantic-expected-note {{evaluates to}}
132+
133+
void *PR28739d = &(&PR28739d)[(__int128)(unsigned long)-1]; // expected-warning {{refers past the last possible element}} \
134+
// pedantic-expected-warning {{refers past the last possible element}} \
135+
// ref-warning {{refers past the last possible element}} \
136+
// pedantic-ref-warning {{refers past the last possible element}}

0 commit comments

Comments
 (0)