Skip to content

Commit

Permalink
[clang][Interp] Fix "Initializing" zero-size arrays
Browse files Browse the repository at this point in the history
getIndex() returns 0 here, so we were trying to initalize the 0th
element.

Fixes #88018
  • Loading branch information
tbaederr committed Apr 9, 2024
1 parent 62e9257 commit d412047
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clang/lib/AST/Interp/Pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ void Pointer::initialize() const {
if (isStatic() && Base == 0)
return;

// Nothing to do for these.
if (Desc->getNumElems() == 0)
return;

InitMapPtr &IM = getInitMap();
if (!IM)
IM =
Expand Down
4 changes: 4 additions & 0 deletions clang/test/AST/Interp/arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,7 @@ char melchizedek[2200000000];
typedef decltype(melchizedek[1] - melchizedek[0]) ptrdiff_t;
constexpr ptrdiff_t d1 = &melchizedek[0x7fffffff] - &melchizedek[0]; // ok
constexpr ptrdiff_t d3 = &melchizedek[0] - &melchizedek[0x80000000u]; // ok

/// GH#88018
const int SZA[] = {};
void testZeroSizedArrayAccess() { unsigned c = SZA[4]; }

0 comments on commit d412047

Please sign in to comment.