@@ -433,7 +433,8 @@ bool Pointer::isInitialized() const {
433
433
if (!isBlockPointer ())
434
434
return true ;
435
435
436
- if (isRoot () && BS.Base == sizeof (GlobalInlineDescriptor)) {
436
+ if (isRoot () && BS.Base == sizeof (GlobalInlineDescriptor) &&
437
+ Offset == BS.Base ) {
437
438
const GlobalInlineDescriptor &GD =
438
439
*reinterpret_cast <const GlobalInlineDescriptor *>(block ()->rawData ());
439
440
return GD.InitState == GlobalInitState::Initialized;
@@ -461,7 +462,8 @@ bool Pointer::isElementInitialized(unsigned Index) const {
461
462
if (isStatic () && BS.Base == 0 )
462
463
return true ;
463
464
464
- if (isRoot () && BS.Base == sizeof (GlobalInlineDescriptor)) {
465
+ if (isRoot () && BS.Base == sizeof (GlobalInlineDescriptor) &&
466
+ Offset == BS.Base ) {
465
467
const GlobalInlineDescriptor &GD =
466
468
*reinterpret_cast <const GlobalInlineDescriptor *>(block ()->rawData ());
467
469
return GD.InitState == GlobalInitState::Initialized;
@@ -486,7 +488,8 @@ void Pointer::initialize() const {
486
488
487
489
assert (BS.Pointee && " Cannot initialize null pointer" );
488
490
489
- if (isRoot () && BS.Base == sizeof (GlobalInlineDescriptor)) {
491
+ if (isRoot () && BS.Base == sizeof (GlobalInlineDescriptor) &&
492
+ Offset == BS.Base ) {
490
493
GlobalInlineDescriptor &GD = *reinterpret_cast <GlobalInlineDescriptor *>(
491
494
asBlockPointer ().Pointee ->rawData ());
492
495
GD.InitState = GlobalInitState::Initialized;
@@ -496,35 +499,39 @@ void Pointer::initialize() const {
496
499
const Descriptor *Desc = getFieldDesc ();
497
500
assert (Desc);
498
501
if (Desc->isPrimitiveArray ()) {
499
- // Primitive global arrays don't have an initmap.
500
- if (isStatic () && BS.Base == 0 )
501
- return ;
502
+ if (Desc->getNumElems () != 0 )
503
+ initializeElement (getIndex ());
504
+ return ;
505
+ }
502
506
503
- // Nothing to do for these.
504
- if (Desc->getNumElems () == 0 )
505
- return ;
507
+ // Field has its bit in an inline descriptor.
508
+ assert (BS.Base != 0 && " Only composite fields can be initialised" );
509
+ getInlineDesc ()->IsInitialized = true ;
510
+ }
506
511
507
- InitMapPtr &IM = getInitMap ();
508
- if (!IM)
509
- IM =
510
- std::make_pair ( false , std::make_shared<InitMap>(Desc-> getNumElems ())) ;
512
+ void Pointer::initializeElement ( unsigned Index) const {
513
+ // Primitive global arrays don't have an initmap.
514
+ if ( isStatic () && BS. Base == 0 )
515
+ return ;
511
516
512
- assert (IM );
517
+ assert (Index < getFieldDesc ()-> getNumElems () );
513
518
514
- // All initialized.
515
- if (IM->first )
516
- return ;
519
+ InitMapPtr &IM = getInitMap ();
520
+ if (!IM) {
521
+ const Descriptor *Desc = getFieldDesc ();
522
+ IM = std::make_pair (false , std::make_shared<InitMap>(Desc->getNumElems ()));
523
+ }
517
524
518
- if (IM-> second -> initializeElement ( getIndex ())) {
519
- IM-> first = true ;
520
- IM-> second . reset ();
521
- }
525
+ assert (IM);
526
+
527
+ // All initialized.
528
+ if (IM-> first )
522
529
return ;
523
- }
524
530
525
- // Field has its bit in an inline descriptor.
526
- assert (BS.Base != 0 && " Only composite fields can be initialised" );
527
- getInlineDesc ()->IsInitialized = true ;
531
+ if (IM->second ->initializeElement (Index)) {
532
+ IM->first = true ;
533
+ IM->second .reset ();
534
+ }
528
535
}
529
536
530
537
void Pointer::initializeAllElements () const {
@@ -547,7 +554,8 @@ bool Pointer::allElementsInitialized() const {
547
554
if (isStatic () && BS.Base == 0 )
548
555
return true ;
549
556
550
- if (isRoot () && BS.Base == sizeof (GlobalInlineDescriptor)) {
557
+ if (isRoot () && BS.Base == sizeof (GlobalInlineDescriptor) &&
558
+ Offset == BS.Base ) {
551
559
const GlobalInlineDescriptor &GD =
552
560
*reinterpret_cast <const GlobalInlineDescriptor *>(block ()->rawData ());
553
561
return GD.InitState == GlobalInitState::Initialized;
0 commit comments