Skip to content

Commit 06d2176

Browse files
committed
[clang][Interp][NFC] Move global variable init case to the top
of the respective functions. Previously, we did not properly mark global zero sized arrays as initialized.
1 parent 37be437 commit 06d2176

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

clang/lib/AST/Interp/Pointer.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ bool Pointer::isInitialized() const {
227227
if (isIntegralPointer())
228228
return true;
229229

230+
if (isRoot() && PointeeStorage.BS.Base == sizeof(GlobalInlineDescriptor)) {
231+
const GlobalInlineDescriptor &GD =
232+
*reinterpret_cast<const GlobalInlineDescriptor *>(block()->rawData());
233+
return GD.InitState == GlobalInitState::Initialized;
234+
}
235+
230236
assert(PointeeStorage.BS.Pointee &&
231237
"Cannot check if null pointer was initialized");
232238
const Descriptor *Desc = getFieldDesc();
@@ -249,12 +255,6 @@ bool Pointer::isInitialized() const {
249255
if (asBlockPointer().Base == 0)
250256
return true;
251257

252-
if (isRoot() && PointeeStorage.BS.Base == sizeof(GlobalInlineDescriptor)) {
253-
const GlobalInlineDescriptor &GD =
254-
*reinterpret_cast<const GlobalInlineDescriptor *>(block()->rawData());
255-
return GD.InitState == GlobalInitState::Initialized;
256-
}
257-
258258
// Field has its bit in an inline descriptor.
259259
return getInlineDesc()->IsInitialized;
260260
}
@@ -266,6 +266,13 @@ void Pointer::initialize() const {
266266
assert(PointeeStorage.BS.Pointee && "Cannot initialize null pointer");
267267
const Descriptor *Desc = getFieldDesc();
268268

269+
if (isRoot() && PointeeStorage.BS.Base == sizeof(GlobalInlineDescriptor)) {
270+
GlobalInlineDescriptor &GD = *reinterpret_cast<GlobalInlineDescriptor *>(
271+
asBlockPointer().Pointee->rawData());
272+
GD.InitState = GlobalInitState::Initialized;
273+
return;
274+
}
275+
269276
assert(Desc);
270277
if (Desc->isPrimitiveArray()) {
271278
// Primitive global arrays don't have an initmap.
@@ -294,13 +301,6 @@ void Pointer::initialize() const {
294301
return;
295302
}
296303

297-
if (isRoot() && PointeeStorage.BS.Base == sizeof(GlobalInlineDescriptor)) {
298-
GlobalInlineDescriptor &GD = *reinterpret_cast<GlobalInlineDescriptor *>(
299-
asBlockPointer().Pointee->rawData());
300-
GD.InitState = GlobalInitState::Initialized;
301-
return;
302-
}
303-
304304
// Field has its bit in an inline descriptor.
305305
assert(PointeeStorage.BS.Base != 0 &&
306306
"Only composite fields can be initialised");

0 commit comments

Comments
 (0)