52
52
#include < cstddef>
53
53
#include < cstdint>
54
54
#include < cstring>
55
- #include < limits>
56
55
#include < optional>
57
56
#include < string>
58
57
#include < type_traits>
@@ -211,6 +210,8 @@ class PointerAuthQualifier {
211
210
(AuthenticatesNullValues << AuthenticatesNullValuesShift)) {
212
211
assert (Key <= KeyNoneInternal);
213
212
assert (ExtraDiscriminator <= MaxDiscriminator);
213
+ assert ((Data == 0 ) ==
214
+ (getAuthenticationMode () == PointerAuthenticationMode::None));
214
215
}
215
216
216
217
public:
@@ -240,7 +241,9 @@ class PointerAuthQualifier {
240
241
}
241
242
242
243
bool isPresent () const {
243
- return getAuthenticationMode () != PointerAuthenticationMode::None;
244
+ assert ((Data == 0 ) ==
245
+ (getAuthenticationMode () == PointerAuthenticationMode::None));
246
+ return Data != 0 ;
244
247
}
245
248
246
249
explicit operator bool () const { return isPresent (); }
@@ -298,6 +301,8 @@ class PointerAuthQualifier {
298
301
static PointerAuthQualifier fromOpaqueValue (uint32_t Opaque) {
299
302
PointerAuthQualifier Result;
300
303
Result.Data = Opaque;
304
+ assert ((Result.Data == 0 ) ==
305
+ (Result.getAuthenticationMode () == PointerAuthenticationMode::None));
301
306
return Result;
302
307
}
303
308
@@ -312,8 +317,9 @@ class PointerAuthQualifier {
312
317
// / * Objective C: the GC attributes (none, weak, or strong)
313
318
class Qualifiers {
314
319
public:
315
- enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
316
- Const = 0x1 ,
320
+ enum TQ : uint64_t {
321
+ // NOTE: These flags must be kept in sync with DeclSpec::TQ.
322
+ Const = 0x1 ,
317
323
Restrict = 0x2 ,
318
324
Volatile = 0x4 ,
319
325
CVRMask = Const | Volatile | Restrict
@@ -347,7 +353,7 @@ class Qualifiers {
347
353
OCL_Autoreleasing
348
354
};
349
355
350
- enum {
356
+ enum : uint64_t {
351
357
// / The maximum supported address space number.
352
358
// / 23 bits should be enough for anyone.
353
359
MaxAddressSpace = 0x7fffffu ,
@@ -363,8 +369,11 @@ class Qualifiers {
363
369
// / the given sets.
364
370
static Qualifiers removeCommonQualifiers (Qualifiers &L, Qualifiers &R) {
365
371
Qualifiers Q;
366
- if (L.getPointerAuth ().isEquivalent (R.getPointerAuth ())) {
367
- Q.setPointerAuth (L.getPointerAuth ().withoutKeyNone ());
372
+ PointerAuthQualifier LPtrAuth = L.getPointerAuth ();
373
+ if (LPtrAuth.isPresent () &&
374
+ LPtrAuth.getKey () != PointerAuthQualifier::KeyNoneInternal &&
375
+ LPtrAuth == R.getPointerAuth ()) {
376
+ Q.setPointerAuth (LPtrAuth);
368
377
PointerAuthQualifier Empty;
369
378
L.setPointerAuth (Empty);
370
379
R.setPointerAuth (Empty);
@@ -422,18 +431,14 @@ class Qualifiers {
422
431
}
423
432
424
433
// Deserialize qualifiers from an opaque representation.
425
- static Qualifiers fromOpaqueValue (uint64_t Opaque ) {
434
+ static Qualifiers fromOpaqueValue (uint64_t opaque ) {
426
435
Qualifiers Qs;
427
- constexpr uint32_t U32Max = std::numeric_limits<uint32_t >::max ();
428
- Qs.Mask = Opaque & U32Max;
429
- Qs.PtrAuth = PointerAuthQualifier::fromOpaqueValue ((Opaque >> 32 ) & U32Max);
436
+ Qs.Mask = opaque;
430
437
return Qs;
431
438
}
432
439
433
440
// Serialize these qualifiers into an opaque representation.
434
- uint64_t getAsOpaqueValue () const {
435
- return uint64_t (Mask) | (uint64_t (PtrAuth.getAsOpaqueValue ()) << 32 );
436
- }
441
+ uint64_t getAsOpaqueValue () const { return Mask; }
437
442
438
443
bool hasConst () const { return Mask & Const; }
439
444
bool hasOnlyConst () const { return Mask == Const; }
@@ -580,9 +585,19 @@ class Qualifiers {
580
585
setAddressSpace (space);
581
586
}
582
587
583
- PointerAuthQualifier getPointerAuth () const { return PtrAuth; }
584
- void setPointerAuth (PointerAuthQualifier q) { PtrAuth = q; }
585
- void removePtrAuth () { PtrAuth = PointerAuthQualifier (); }
588
+ bool hasPointerAuth () const { return Mask & PtrAuthMask; }
589
+ PointerAuthQualifier getPointerAuth () const {
590
+ return PointerAuthQualifier::fromOpaqueValue (Mask >> PtrAuthShift);
591
+ }
592
+ void setPointerAuth (PointerAuthQualifier Q) {
593
+ Mask = (Mask & ~PtrAuthMask) |
594
+ (uint64_t (Q.getAsOpaqueValue ()) << PtrAuthShift);
595
+ }
596
+ void removePointerAuth () { Mask &= ~PtrAuthMask; }
597
+ void addPointerAuth (PointerAuthQualifier Q) {
598
+ assert (Q.isPresent ());
599
+ setPointerAuth (Q);
600
+ }
586
601
587
602
// Fast qualifiers are those that can be allocated directly
588
603
// on a QualType object.
@@ -606,16 +621,16 @@ class Qualifiers {
606
621
607
622
// / Return true if the set contains any qualifiers which require an ExtQuals
608
623
// / node to be allocated.
609
- bool hasNonFastQualifiers () const { return ( Mask & ~FastMask) || PtrAuth ; }
624
+ bool hasNonFastQualifiers () const { return Mask & ~FastMask; }
610
625
Qualifiers getNonFastQualifiers () const {
611
626
Qualifiers Quals = *this ;
612
627
Quals.setFastQualifiers (0 );
613
628
return Quals;
614
629
}
615
630
616
631
// / Return true if the set contains any qualifiers.
617
- bool hasQualifiers () const { return Mask || PtrAuth ; }
618
- bool empty () const { return !hasQualifiers () ; }
632
+ bool hasQualifiers () const { return Mask; }
633
+ bool empty () const { return !Mask ; }
619
634
620
635
// / Add the qualifiers from the given set to this set.
621
636
void addQualifiers (Qualifiers Q) {
@@ -631,10 +646,9 @@ class Qualifiers {
631
646
addObjCGCAttr (Q.getObjCGCAttr ());
632
647
if (Q.hasObjCLifetime ())
633
648
addObjCLifetime (Q.getObjCLifetime ());
649
+ if (Q.hasPointerAuth ())
650
+ addPointerAuth (Q.getPointerAuth ());
634
651
}
635
-
636
- if (Q.PtrAuth )
637
- PtrAuth = Q.PtrAuth ;
638
652
}
639
653
640
654
// / Remove the qualifiers from the given set from this set.
@@ -651,10 +665,9 @@ class Qualifiers {
651
665
removeObjCLifetime ();
652
666
if (getAddressSpace () == Q.getAddressSpace ())
653
667
removeAddressSpace ();
668
+ if (getPointerAuth () == Q.getPointerAuth ())
669
+ removePointerAuth ();
654
670
}
655
-
656
- if (PtrAuth == Q.PtrAuth )
657
- PtrAuth = PointerAuthQualifier ();
658
671
}
659
672
660
673
// / Add the qualifiers from the given set to this set, given that
@@ -666,10 +679,9 @@ class Qualifiers {
666
679
!hasObjCGCAttr () || !qs.hasObjCGCAttr ());
667
680
assert (getObjCLifetime () == qs.getObjCLifetime () ||
668
681
!hasObjCLifetime () || !qs.hasObjCLifetime ());
669
- assert (!PtrAuth || !qs.PtrAuth || PtrAuth == qs.PtrAuth );
682
+ assert (!hasPointerAuth () || !qs.hasPointerAuth () ||
683
+ getPointerAuth () == qs.getPointerAuth ());
670
684
Mask |= qs.Mask ;
671
- if (qs.PtrAuth )
672
- PtrAuth = qs.PtrAuth ;
673
685
}
674
686
675
687
// / Returns true if address space A is equal to or a superset of B.
@@ -723,7 +735,7 @@ class Qualifiers {
723
735
(getObjCGCAttr () == other.getObjCGCAttr () || !hasObjCGCAttr () ||
724
736
!other.hasObjCGCAttr ()) &&
725
737
// Pointer-auth qualifiers must match exactly.
726
- PtrAuth == other.PtrAuth &&
738
+ getPointerAuth () == other.getPointerAuth () &&
727
739
// ObjC lifetime qualifiers must match exactly.
728
740
getObjCLifetime () == other.getObjCLifetime () &&
729
741
// CVR qualifiers may subset.
@@ -756,12 +768,8 @@ class Qualifiers {
756
768
// / another set of qualifiers, not considering qualifier compatibility.
757
769
bool isStrictSupersetOf (Qualifiers Other) const ;
758
770
759
- bool operator ==(Qualifiers Other) const {
760
- return Mask == Other.Mask && PtrAuth == Other.PtrAuth ;
761
- }
762
- bool operator !=(Qualifiers Other) const {
763
- return Mask != Other.Mask || PtrAuth != Other.PtrAuth ;
764
- }
771
+ bool operator ==(Qualifiers Other) const { return Mask == Other.Mask ; }
772
+ bool operator !=(Qualifiers Other) const { return Mask != Other.Mask ; }
765
773
766
774
explicit operator bool () const { return hasQualifiers (); }
767
775
@@ -797,28 +805,26 @@ class Qualifiers {
797
805
void print (raw_ostream &OS, const PrintingPolicy &Policy,
798
806
bool appendSpaceIfNonEmpty = false ) const ;
799
807
800
- void Profile (llvm::FoldingSetNodeID &ID) const {
801
- ID.AddInteger (Mask);
802
- PtrAuth.Profile (ID);
803
- }
808
+ void Profile (llvm::FoldingSetNodeID &ID) const { ID.AddInteger (Mask); }
804
809
805
810
private:
806
- // bits: |0 1 2|3|4 .. 5|6 .. 8|9 ... 31|
807
- // |C R V|U|GCAttr|Lifetime|AddressSpace|
808
- uint32_t Mask = 0 ;
809
-
810
- PointerAuthQualifier PtrAuth;
811
+ // bits: |0 1 2|3|4 .. 5|6 .. 8|9 ... 31|32 ... 63|
812
+ // |C R V|U|GCAttr|Lifetime|AddressSpace| PtrAuth |
813
+ uint64_t Mask = 0 ;
811
814
static_assert (sizeof (PointerAuthQualifier) == sizeof (uint32_t ),
812
815
" PointerAuthQualifier must be 32 bits" );
813
- static const uint32_t UMask = 0x8 ;
814
- static const uint32_t UShift = 3 ;
815
- static const uint32_t GCAttrMask = 0x30 ;
816
- static const uint32_t GCAttrShift = 4 ;
817
- static const uint32_t LifetimeMask = 0x1C0 ;
818
- static const uint32_t LifetimeShift = 6 ;
819
- static const uint32_t AddressSpaceMask =
816
+
817
+ static constexpr uint64_t UMask = 0x8 ;
818
+ static constexpr uint64_t UShift = 3 ;
819
+ static constexpr uint64_t GCAttrMask = 0x30 ;
820
+ static constexpr uint64_t GCAttrShift = 4 ;
821
+ static constexpr uint64_t LifetimeMask = 0x1C0 ;
822
+ static constexpr uint64_t LifetimeShift = 6 ;
823
+ static constexpr uint64_t AddressSpaceMask =
820
824
~(CVRMask | UMask | GCAttrMask | LifetimeMask);
821
- static const uint32_t AddressSpaceShift = 9 ;
825
+ static constexpr uint64_t AddressSpaceShift = 9 ;
826
+ static constexpr uint64_t PtrAuthShift = 32 ;
827
+ static constexpr uint64_t PtrAuthMask = uint64_t (0xffffffff ) << PtrAuthShift;
822
828
};
823
829
824
830
class QualifiersAndAtomic {
0 commit comments