Skip to content

Commit 79e43eb

Browse files
committed
[clang][Interp] Protect ArrayDecay ops against dummy pointers
1 parent df2513c commit 79e43eb

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

clang/lib/AST/Interp/Interp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,9 @@ inline bool ArrayElemPop(InterpState &S, CodePtr OpPC, uint32_t Index) {
18911891
inline bool ArrayDecay(InterpState &S, CodePtr OpPC) {
18921892
const Pointer &Ptr = S.Stk.pop<Pointer>();
18931893

1894+
if (Ptr.isDummy())
1895+
return false;
1896+
18941897
if (!Ptr.isUnknownSizeArray()) {
18951898
S.Stk.push<Pointer>(Ptr.atIndex(0));
18961899
return true;

clang/test/AST/Interp/arrays.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,3 +598,23 @@ namespace NonConstReads {
598598
const int y = 0;
599599
int yy[y];
600600
}
601+
602+
namespace SelfComparison {
603+
struct S {
604+
int field;
605+
static int static_field;
606+
int array[4];
607+
};
608+
609+
struct T {
610+
int field;
611+
static int static_field;
612+
int array[4];
613+
S s;
614+
};
615+
616+
int struct_test(S s1, S s2, S *s3, T t) {
617+
return s3->array[t.field] == s3->array[t.field]; // expected-warning {{self-comparison always evaluates to true}} \
618+
// ref-warning {{self-comparison always evaluates to true}}
619+
};
620+
}

clang/test/SemaCXX/self-comparison.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++2a
2+
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++2a -fexperimental-new-constant-interpreter
23

34
int foo(int x) {
45
return x == x; // expected-warning {{self-comparison always evaluates to true}}

0 commit comments

Comments
 (0)