Skip to content

Commit

Permalink
[clang][Interp] Fix assertion in InitElem{,Pop} ops
Browse files Browse the repository at this point in the history
... when the pointer is an unknown size array.
  • Loading branch information
tbaederr committed Mar 4, 2024
1 parent 7d55a3b commit c089fa5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clang/lib/AST/Interp/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,8 @@ template <PrimType Name, class T = typename PrimConv<Name>::T>
bool InitElem(InterpState &S, CodePtr OpPC, uint32_t Idx) {
const T &Value = S.Stk.pop<T>();
const Pointer &Ptr = S.Stk.peek<Pointer>().atIndex(Idx);
if (Ptr.isUnknownSizeArray())
return false;
if (!CheckInit(S, OpPC, Ptr))
return false;
Ptr.initialize();
Expand All @@ -1460,6 +1462,8 @@ template <PrimType Name, class T = typename PrimConv<Name>::T>
bool InitElemPop(InterpState &S, CodePtr OpPC, uint32_t Idx) {
const T &Value = S.Stk.pop<T>();
const Pointer &Ptr = S.Stk.pop<Pointer>().atIndex(Idx);
if (Ptr.isUnknownSizeArray())
return false;
if (!CheckInit(S, OpPC, Ptr))
return false;
Ptr.initialize();
Expand Down
2 changes: 2 additions & 0 deletions clang/test/AST/Interp/arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ constexpr int dependent[4] = {
static_assert(dependent[2] == dependent[0], "");
static_assert(dependent[3] == dependent[1], "");

union { char x[]; } r = {0};

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc99-extensions"
#pragma clang diagnostic ignored "-Winitializer-overrides"
Expand Down

0 comments on commit c089fa5

Please sign in to comment.