Skip to content

Commit c089fa5

Browse files
committed
[clang][Interp] Fix assertion in InitElem{,Pop} ops
... when the pointer is an unknown size array.
1 parent 7d55a3b commit c089fa5

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

clang/lib/AST/Interp/Interp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,8 @@ template <PrimType Name, class T = typename PrimConv<Name>::T>
14481448
bool InitElem(InterpState &S, CodePtr OpPC, uint32_t Idx) {
14491449
const T &Value = S.Stk.pop<T>();
14501450
const Pointer &Ptr = S.Stk.peek<Pointer>().atIndex(Idx);
1451+
if (Ptr.isUnknownSizeArray())
1452+
return false;
14511453
if (!CheckInit(S, OpPC, Ptr))
14521454
return false;
14531455
Ptr.initialize();
@@ -1460,6 +1462,8 @@ template <PrimType Name, class T = typename PrimConv<Name>::T>
14601462
bool InitElemPop(InterpState &S, CodePtr OpPC, uint32_t Idx) {
14611463
const T &Value = S.Stk.pop<T>();
14621464
const Pointer &Ptr = S.Stk.pop<Pointer>().atIndex(Idx);
1465+
if (Ptr.isUnknownSizeArray())
1466+
return false;
14631467
if (!CheckInit(S, OpPC, Ptr))
14641468
return false;
14651469
Ptr.initialize();

clang/test/AST/Interp/arrays.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ constexpr int dependent[4] = {
138138
static_assert(dependent[2] == dependent[0], "");
139139
static_assert(dependent[3] == dependent[1], "");
140140

141+
union { char x[]; } r = {0};
142+
141143
#pragma clang diagnostic push
142144
#pragma clang diagnostic ignored "-Wc99-extensions"
143145
#pragma clang diagnostic ignored "-Winitializer-overrides"

0 commit comments

Comments
 (0)