Skip to content

Commit e9174ba

Browse files
committed
[clang][Interp] Always decay root array pointers to the first element
This is similar to what the current interpreter does.
1 parent 09f19c7 commit e9174ba

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

clang/lib/AST/Interp/Interp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,7 @@ inline bool ArrayDecay(InterpState &S, CodePtr OpPC) {
21942194
if (!CheckRange(S, OpPC, Ptr, CSK_ArrayToPointer))
21952195
return false;
21962196

2197-
if (!Ptr.isUnknownSizeArray() || Ptr.isDummy()) {
2197+
if (Ptr.isRoot() || !Ptr.isUnknownSizeArray() || Ptr.isDummy()) {
21982198
S.Stk.push<Pointer>(Ptr.atIndex(0));
21992199
return true;
22002200
}

clang/test/AST/Interp/arrays.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,3 +615,11 @@ namespace OnePastEndSub {
615615
constexpr A a[3][3];
616616
constexpr int diff2 = &a[1][3] - &a[1][0]; /// Used to crash.
617617
}
618+
619+
static int same_entity_2[3];
620+
constexpr int *get2() {
621+
// This is a redeclaration of the same entity, even though it doesn't
622+
// inherit the type of the prior declaration.
623+
extern int same_entity_2[];
624+
return same_entity_2;
625+
}

clang/test/AST/Interp/literals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ namespace incdecbool {
12091209
constexpr int externvar1() { // both-error {{never produces a constant expression}}
12101210
extern char arr[]; // ref-note {{declared here}}
12111211
return arr[0]; // ref-note {{read of non-constexpr variable 'arr'}} \
1212-
// expected-note {{array-to-pointer decay of array member without known bound is not supported}}
1212+
// expected-note {{indexing of array without known bound}}
12131213
}
12141214
#endif
12151215

0 commit comments

Comments
 (0)