@@ -30,39 +30,62 @@ Pointer::Pointer(Block *Pointee)
3030Pointer::Pointer (Block *Pointee, uint64_t BaseAndOffset)
3131 : Pointer(Pointee, BaseAndOffset, BaseAndOffset) {}
3232
33- Pointer::Pointer (const Pointer &P)
34- : Offset(P.Offset), StorageKind(P.StorageKind),
35- PointeeStorage(P.PointeeStorage) {
36-
37- if (isBlockPointer () && PointeeStorage.BS .Pointee )
38- PointeeStorage.BS .Pointee ->addPointer (this );
39- }
40-
4133Pointer::Pointer (Block *Pointee, unsigned Base, uint64_t Offset)
4234 : Offset(Offset), StorageKind(Storage::Block) {
4335 assert ((Base == RootPtrMark || Base % alignof (void *) == 0 ) && " wrong base" );
4436
45- PointeeStorage. BS = {Pointee, Base, nullptr , nullptr };
37+ BS = {Pointee, Base, nullptr , nullptr };
4638
4739 if (Pointee)
4840 Pointee->addPointer (this );
4941}
5042
51- Pointer::Pointer (Pointer &&P)
52- : Offset(P.Offset), StorageKind(P.StorageKind),
53- PointeeStorage(P.PointeeStorage) {
43+ Pointer::Pointer (const Pointer &P)
44+ : Offset(P.Offset), StorageKind(P.StorageKind) {
45+ switch (StorageKind) {
46+ case Storage::Int:
47+ Int = P.Int ;
48+ break ;
49+ case Storage::Block:
50+ BS = P.BS ;
51+ if (BS.Pointee )
52+ BS.Pointee ->addPointer (this );
53+ break ;
54+ case Storage::Fn:
55+ Fn = P.Fn ;
56+ break ;
57+ case Storage::Typeid:
58+ Typeid = P.Typeid ;
59+ break ;
60+ }
61+ }
5462
55- if (StorageKind == Storage::Block && PointeeStorage.BS .Pointee )
56- PointeeStorage.BS .Pointee ->replacePointer (&P, this );
63+ Pointer::Pointer (Pointer &&P) : Offset(P.Offset), StorageKind(P.StorageKind) {
64+ switch (StorageKind) {
65+ case Storage::Int:
66+ Int = P.Int ;
67+ break ;
68+ case Storage::Block:
69+ BS = P.BS ;
70+ if (BS.Pointee )
71+ BS.Pointee ->replacePointer (&P, this );
72+ break ;
73+ case Storage::Fn:
74+ Fn = P.Fn ;
75+ break ;
76+ case Storage::Typeid:
77+ Typeid = P.Typeid ;
78+ break ;
79+ }
5780}
5881
5982Pointer::~Pointer () {
6083 if (!isBlockPointer ())
6184 return ;
6285
63- if (Block *Pointee = PointeeStorage. BS .Pointee ) {
86+ if (Block *Pointee = BS.Pointee ) {
6487 Pointee->removePointer (this );
65- PointeeStorage. BS .Pointee = nullptr ;
88+ BS.Pointee = nullptr ;
6689 Pointee->cleanup ();
6790 }
6891}
@@ -73,13 +96,13 @@ Pointer &Pointer::operator=(const Pointer &P) {
7396 if (isBlockPointer ()) {
7497 if (P.isBlockPointer () && this ->block () == P.block ()) {
7598 Offset = P.Offset ;
76- PointeeStorage. BS .Base = P. PointeeStorage .BS .Base ;
99+ BS.Base = P.BS .Base ;
77100 return *this ;
78101 }
79102
80- if (Block *Pointee = PointeeStorage. BS .Pointee ) {
103+ if (Block *Pointee = BS.Pointee ) {
81104 Pointee->removePointer (this );
82- PointeeStorage. BS .Pointee = nullptr ;
105+ BS.Pointee = nullptr ;
83106 Pointee->cleanup ();
84107 }
85108 }
@@ -88,16 +111,16 @@ Pointer &Pointer::operator=(const Pointer &P) {
88111 Offset = P.Offset ;
89112
90113 if (P.isBlockPointer ()) {
91- PointeeStorage. BS = P. PointeeStorage .BS ;
114+ BS = P.BS ;
92115
93- if (PointeeStorage. BS .Pointee )
94- PointeeStorage. BS .Pointee ->addPointer (this );
116+ if (BS.Pointee )
117+ BS.Pointee ->addPointer (this );
95118 } else if (P.isIntegralPointer ()) {
96- PointeeStorage. Int = P. PointeeStorage .Int ;
119+ Int = P.Int ;
97120 } else if (P.isFunctionPointer ()) {
98- PointeeStorage. Fn = P. PointeeStorage .Fn ;
121+ Fn = P.Fn ;
99122 } else if (P.isTypeidPointer ()) {
100- PointeeStorage. Typeid = P. PointeeStorage .Typeid ;
123+ Typeid = P.Typeid ;
101124 } else {
102125 assert (false && " Unhandled storage kind" );
103126 }
@@ -110,13 +133,13 @@ Pointer &Pointer::operator=(Pointer &&P) {
110133 if (isBlockPointer ()) {
111134 if (P.isBlockPointer () && this ->block () == P.block ()) {
112135 Offset = P.Offset ;
113- PointeeStorage. BS .Base = P. PointeeStorage .BS .Base ;
136+ BS.Base = P.BS .Base ;
114137 return *this ;
115138 }
116139
117- if (Block *Pointee = PointeeStorage. BS .Pointee ) {
140+ if (Block *Pointee = BS.Pointee ) {
118141 Pointee->removePointer (this );
119- PointeeStorage. BS .Pointee = nullptr ;
142+ BS.Pointee = nullptr ;
120143 Pointee->cleanup ();
121144 }
122145 }
@@ -125,16 +148,16 @@ Pointer &Pointer::operator=(Pointer &&P) {
125148 Offset = P.Offset ;
126149
127150 if (P.isBlockPointer ()) {
128- PointeeStorage. BS = P. PointeeStorage .BS ;
151+ BS = P.BS ;
129152
130- if (PointeeStorage. BS .Pointee )
131- PointeeStorage. BS .Pointee ->addPointer (this );
153+ if (BS.Pointee )
154+ BS.Pointee ->addPointer (this );
132155 } else if (P.isIntegralPointer ()) {
133- PointeeStorage. Int = P. PointeeStorage .Int ;
156+ Int = P.Int ;
134157 } else if (P.isFunctionPointer ()) {
135- PointeeStorage. Fn = P. PointeeStorage .Fn ;
158+ Fn = P.Fn ;
136159 } else if (P.isTypeidPointer ()) {
137- PointeeStorage. Typeid = P. PointeeStorage .Typeid ;
160+ Typeid = P.Typeid ;
138161 } else {
139162 assert (false && " Unhandled storage kind" );
140163 }
@@ -163,12 +186,11 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
163186 }
164187
165188 if (isTypeidPointer ()) {
166- TypeInfoLValue TypeInfo (PointeeStorage.Typeid .TypePtr );
167- return APValue (
168- APValue::LValueBase::getTypeInfo (
169- TypeInfo, QualType (PointeeStorage.Typeid .TypeInfoType , 0 )),
170- CharUnits::Zero (), {},
171- /* OnePastTheEnd=*/ false , /* IsNull=*/ false );
189+ TypeInfoLValue TypeInfo (Typeid.TypePtr );
190+ return APValue (APValue::LValueBase::getTypeInfo (
191+ TypeInfo, QualType (Typeid.TypeInfoType , 0 )),
192+ CharUnits::Zero (), {},
193+ /* OnePastTheEnd=*/ false , /* IsNull=*/ false );
172194 }
173195
174196 // Build the lvalue base from the block.
@@ -300,13 +322,13 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
300322void Pointer::print (llvm::raw_ostream &OS) const {
301323 switch (StorageKind) {
302324 case Storage::Block: {
303- const Block *B = PointeeStorage. BS .Pointee ;
325+ const Block *B = BS.Pointee ;
304326 OS << " (Block) " << B << " {" ;
305327
306328 if (isRoot ())
307- OS << " rootptr(" << PointeeStorage. BS .Base << " ), " ;
329+ OS << " rootptr(" << BS.Base << " ), " ;
308330 else
309- OS << PointeeStorage. BS .Base << " , " ;
331+ OS << BS.Base << " , " ;
310332
311333 if (isElementPastEnd ())
312334 OS << " pastend, " ;
@@ -321,8 +343,7 @@ void Pointer::print(llvm::raw_ostream &OS) const {
321343 } break ;
322344 case Storage::Int:
323345 OS << " (Int) {" ;
324- OS << PointeeStorage.Int .Value << " + " << Offset << " , "
325- << PointeeStorage.Int .Desc ;
346+ OS << Int.Value << " + " << Offset << " , " << Int.Desc ;
326347 OS << " }" ;
327348 break ;
328349 case Storage::Fn:
@@ -412,18 +433,17 @@ bool Pointer::isInitialized() const {
412433 if (!isBlockPointer ())
413434 return true ;
414435
415- if (isRoot () && PointeeStorage. BS .Base == sizeof (GlobalInlineDescriptor)) {
436+ if (isRoot () && BS.Base == sizeof (GlobalInlineDescriptor)) {
416437 const GlobalInlineDescriptor &GD =
417438 *reinterpret_cast <const GlobalInlineDescriptor *>(block ()->rawData ());
418439 return GD.InitState == GlobalInitState::Initialized;
419440 }
420441
421- assert (PointeeStorage.BS .Pointee &&
422- " Cannot check if null pointer was initialized" );
442+ assert (BS.Pointee && " Cannot check if null pointer was initialized" );
423443 const Descriptor *Desc = getFieldDesc ();
424444 assert (Desc);
425445 if (Desc->isPrimitiveArray ()) {
426- if (isStatic () && PointeeStorage. BS .Base == 0 )
446+ if (isStatic () && BS.Base == 0 )
427447 return true ;
428448
429449 InitMapPtr &IM = getInitMap ();
@@ -448,9 +468,9 @@ void Pointer::initialize() const {
448468 if (!isBlockPointer ())
449469 return ;
450470
451- assert (PointeeStorage. BS .Pointee && " Cannot initialize null pointer" );
471+ assert (BS.Pointee && " Cannot initialize null pointer" );
452472
453- if (isRoot () && PointeeStorage. BS .Base == sizeof (GlobalInlineDescriptor)) {
473+ if (isRoot () && BS.Base == sizeof (GlobalInlineDescriptor)) {
454474 GlobalInlineDescriptor &GD = *reinterpret_cast <GlobalInlineDescriptor *>(
455475 asBlockPointer ().Pointee ->rawData ());
456476 GD.InitState = GlobalInitState::Initialized;
@@ -461,7 +481,7 @@ void Pointer::initialize() const {
461481 assert (Desc);
462482 if (Desc->isPrimitiveArray ()) {
463483 // Primitive global arrays don't have an initmap.
464- if (isStatic () && PointeeStorage. BS .Base == 0 )
484+ if (isStatic () && BS.Base == 0 )
465485 return ;
466486
467487 // Nothing to do for these.
@@ -487,8 +507,7 @@ void Pointer::initialize() const {
487507 }
488508
489509 // Field has its bit in an inline descriptor.
490- assert (PointeeStorage.BS .Base != 0 &&
491- " Only composite fields can be initialised" );
510+ assert (BS.Base != 0 && " Only composite fields can be initialised" );
492511 getInlineDesc ()->IsInitialized = true ;
493512}
494513
@@ -507,10 +526,9 @@ void Pointer::initializeAllElements() const {
507526
508527void Pointer::activate () const {
509528 // Field has its bit in an inline descriptor.
510- assert (PointeeStorage.BS .Base != 0 &&
511- " Only composite fields can be activated" );
529+ assert (BS.Base != 0 && " Only composite fields can be activated" );
512530
513- if (isRoot () && PointeeStorage. BS .Base == sizeof (GlobalInlineDescriptor))
531+ if (isRoot () && BS.Base == sizeof (GlobalInlineDescriptor))
514532 return ;
515533 if (!getInlineDesc ()->InUnion )
516534 return ;
@@ -592,8 +610,7 @@ bool Pointer::pointToSameBlock(const Pointer &A, const Pointer &B) {
592610}
593611
594612bool Pointer::hasSameArray (const Pointer &A, const Pointer &B) {
595- return hasSameBase (A, B) &&
596- A.PointeeStorage .BS .Base == B.PointeeStorage .BS .Base &&
613+ return hasSameBase (A, B) && A.BS .Base == B.BS .Base &&
597614 A.getFieldDesc ()->IsArray ;
598615}
599616
0 commit comments