Skip to content

Commit d412047

Browse files
committed
[clang][Interp] Fix "Initializing" zero-size arrays
getIndex() returns 0 here, so we were trying to initalize the 0th element. Fixes #88018
1 parent 62e9257 commit d412047

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

clang/lib/AST/Interp/Pointer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ void Pointer::initialize() const {
177177
if (isStatic() && Base == 0)
178178
return;
179179

180+
// Nothing to do for these.
181+
if (Desc->getNumElems() == 0)
182+
return;
183+
180184
InitMapPtr &IM = getInitMap();
181185
if (!IM)
182186
IM =

clang/test/AST/Interp/arrays.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,7 @@ char melchizedek[2200000000];
566566
typedef decltype(melchizedek[1] - melchizedek[0]) ptrdiff_t;
567567
constexpr ptrdiff_t d1 = &melchizedek[0x7fffffff] - &melchizedek[0]; // ok
568568
constexpr ptrdiff_t d3 = &melchizedek[0] - &melchizedek[0x80000000u]; // ok
569+
570+
/// GH#88018
571+
const int SZA[] = {};
572+
void testZeroSizedArrayAccess() { unsigned c = SZA[4]; }

0 commit comments

Comments
 (0)