|
31 | 31 | #include "clang/Basic/PointerAuthOptions.h" |
32 | 32 | #include "clang/Basic/SourceLocation.h" |
33 | 33 | #include "clang/Basic/Specifiers.h" |
| 34 | +#include "clang/Basic/TargetInfo.h" |
34 | 35 | #include "clang/Basic/Visibility.h" |
35 | 36 | #include "llvm/ADT/APInt.h" |
36 | 37 | #include "llvm/ADT/APSInt.h" |
@@ -329,6 +330,7 @@ class PointerAuthQualifier { |
329 | 330 | /// * Objective C: the GC attributes (none, weak, or strong) |
330 | 331 | class Qualifiers { |
331 | 332 | public: |
| 333 | + Qualifiers() = default; |
332 | 334 | enum TQ : uint64_t { |
333 | 335 | // NOTE: These flags must be kept in sync with DeclSpec::TQ. |
334 | 336 | Const = 0x1, |
@@ -377,8 +379,6 @@ class Qualifiers { |
377 | 379 | FastMask = (1 << FastWidth) - 1 |
378 | 380 | }; |
379 | 381 |
|
380 | | - Qualifiers() : Mask(0) {} |
381 | | - |
382 | 382 | /// Returns the common set of qualifiers while removing them from |
383 | 383 | /// the given sets. |
384 | 384 | static Qualifiers removeCommonQualifiers(Qualifiers &L, Qualifiers &R) { |
@@ -708,45 +708,27 @@ class Qualifiers { |
708 | 708 | /// every address space is a superset of itself. |
709 | 709 | /// CL2.0 adds: |
710 | 710 | /// __generic is a superset of any address space except for __constant. |
711 | | - static bool isAddressSpaceSupersetOf(LangAS A, LangAS B) { |
| 711 | + static bool isAddressSpaceSupersetOf(LangAS A, LangAS B, |
| 712 | + const ASTContext &Ctx) { |
712 | 713 | // Address spaces must match exactly. |
713 | | - return A == B || |
714 | | - // Otherwise in OpenCLC v2.0 s6.5.5: every address space except |
715 | | - // for __constant can be used as __generic. |
716 | | - (A == LangAS::opencl_generic && B != LangAS::opencl_constant) || |
717 | | - // We also define global_device and global_host address spaces, |
718 | | - // to distinguish global pointers allocated on host from pointers |
719 | | - // allocated on device, which are a subset of __global. |
720 | | - (A == LangAS::opencl_global && (B == LangAS::opencl_global_device || |
721 | | - B == LangAS::opencl_global_host)) || |
722 | | - (A == LangAS::sycl_global && (B == LangAS::sycl_global_device || |
723 | | - B == LangAS::sycl_global_host)) || |
724 | | - // Consider pointer size address spaces to be equivalent to default. |
725 | | - ((isPtrSizeAddressSpace(A) || A == LangAS::Default) && |
726 | | - (isPtrSizeAddressSpace(B) || B == LangAS::Default)) || |
727 | | - // Default is a superset of SYCL address spaces. |
728 | | - (A == LangAS::Default && |
729 | | - (B == LangAS::sycl_private || B == LangAS::sycl_local || |
730 | | - B == LangAS::sycl_global || B == LangAS::sycl_global_device || |
731 | | - B == LangAS::sycl_global_host)) || |
732 | | - // In HIP device compilation, any cuda address space is allowed |
733 | | - // to implicitly cast into the default address space. |
734 | | - (A == LangAS::Default && |
735 | | - (B == LangAS::cuda_constant || B == LangAS::cuda_device || |
736 | | - B == LangAS::cuda_shared)); |
| 714 | + return A == B || isTargetAddressSpaceSupersetOf(A, B, Ctx); |
737 | 715 | } |
738 | 716 |
|
| 717 | + static bool isTargetAddressSpaceSupersetOf(LangAS A, LangAS B, |
| 718 | + const ASTContext &Ctx); |
| 719 | + |
739 | 720 | /// Returns true if the address space in these qualifiers is equal to or |
740 | 721 | /// a superset of the address space in the argument qualifiers. |
741 | | - bool isAddressSpaceSupersetOf(Qualifiers other) const { |
742 | | - return isAddressSpaceSupersetOf(getAddressSpace(), other.getAddressSpace()); |
| 722 | + bool isAddressSpaceSupersetOf(Qualifiers other, const ASTContext &Ctx) const { |
| 723 | + return isAddressSpaceSupersetOf(getAddressSpace(), other.getAddressSpace(), |
| 724 | + Ctx); |
743 | 725 | } |
744 | 726 |
|
745 | 727 | /// Determines if these qualifiers compatibly include another set. |
746 | 728 | /// Generally this answers the question of whether an object with the other |
747 | 729 | /// qualifiers can be safely used as an object with these qualifiers. |
748 | | - bool compatiblyIncludes(Qualifiers other) const { |
749 | | - return isAddressSpaceSupersetOf(other) && |
| 730 | + bool compatiblyIncludes(Qualifiers other, const ASTContext &Ctx) const { |
| 731 | + return isAddressSpaceSupersetOf(other, Ctx) && |
750 | 732 | // ObjC GC qualifiers can match, be added, or be removed, but can't |
751 | 733 | // be changed. |
752 | 734 | (getObjCGCAttr() == other.getObjCGCAttr() || !hasObjCGCAttr() || |
@@ -1284,11 +1266,11 @@ class QualType { |
1284 | 1266 |
|
1285 | 1267 | /// Determine whether this type is more qualified than the other |
1286 | 1268 | /// given type, requiring exact equality for non-CVR qualifiers. |
1287 | | - bool isMoreQualifiedThan(QualType Other) const; |
| 1269 | + bool isMoreQualifiedThan(QualType Other, const ASTContext &Ctx) const; |
1288 | 1270 |
|
1289 | 1271 | /// Determine whether this type is at least as qualified as the other |
1290 | 1272 | /// given type, requiring exact equality for non-CVR qualifiers. |
1291 | | - bool isAtLeastAsQualifiedAs(QualType Other) const; |
| 1273 | + bool isAtLeastAsQualifiedAs(QualType Other, const ASTContext &Ctx) const; |
1292 | 1274 |
|
1293 | 1275 | QualType getNonReferenceType() const; |
1294 | 1276 |
|
@@ -1436,11 +1418,12 @@ class QualType { |
1436 | 1418 | /// address spaces overlap iff they are they same. |
1437 | 1419 | /// OpenCL C v2.0 s6.5.5 adds: |
1438 | 1420 | /// __generic overlaps with any address space except for __constant. |
1439 | | - bool isAddressSpaceOverlapping(QualType T) const { |
| 1421 | + bool isAddressSpaceOverlapping(QualType T, const ASTContext &Ctx) const { |
1440 | 1422 | Qualifiers Q = getQualifiers(); |
1441 | 1423 | Qualifiers TQ = T.getQualifiers(); |
1442 | 1424 | // Address spaces overlap if at least one of them is a superset of another |
1443 | | - return Q.isAddressSpaceSupersetOf(TQ) || TQ.isAddressSpaceSupersetOf(Q); |
| 1425 | + return Q.isAddressSpaceSupersetOf(TQ, Ctx) || |
| 1426 | + TQ.isAddressSpaceSupersetOf(Q, Ctx); |
1444 | 1427 | } |
1445 | 1428 |
|
1446 | 1429 | /// Returns gc attribute of this type. |
@@ -8132,24 +8115,26 @@ inline FunctionType::ExtInfo getFunctionExtInfo(QualType t) { |
8132 | 8115 | /// is more qualified than "const int", "volatile int", and |
8133 | 8116 | /// "int". However, it is not more qualified than "const volatile |
8134 | 8117 | /// int". |
8135 | | -inline bool QualType::isMoreQualifiedThan(QualType other) const { |
| 8118 | +inline bool QualType::isMoreQualifiedThan(QualType other, |
| 8119 | + const ASTContext &Ctx) const { |
8136 | 8120 | Qualifiers MyQuals = getQualifiers(); |
8137 | 8121 | Qualifiers OtherQuals = other.getQualifiers(); |
8138 | | - return (MyQuals != OtherQuals && MyQuals.compatiblyIncludes(OtherQuals)); |
| 8122 | + return (MyQuals != OtherQuals && MyQuals.compatiblyIncludes(OtherQuals, Ctx)); |
8139 | 8123 | } |
8140 | 8124 |
|
8141 | 8125 | /// Determine whether this type is at last |
8142 | 8126 | /// as qualified as the Other type. For example, "const volatile |
8143 | 8127 | /// int" is at least as qualified as "const int", "volatile int", |
8144 | 8128 | /// "int", and "const volatile int". |
8145 | | -inline bool QualType::isAtLeastAsQualifiedAs(QualType other) const { |
| 8129 | +inline bool QualType::isAtLeastAsQualifiedAs(QualType other, |
| 8130 | + const ASTContext &Ctx) const { |
8146 | 8131 | Qualifiers OtherQuals = other.getQualifiers(); |
8147 | 8132 |
|
8148 | 8133 | // Ignore __unaligned qualifier if this type is a void. |
8149 | 8134 | if (getUnqualifiedType()->isVoidType()) |
8150 | 8135 | OtherQuals.removeUnaligned(); |
8151 | 8136 |
|
8152 | | - return getQualifiers().compatiblyIncludes(OtherQuals); |
| 8137 | + return getQualifiers().compatiblyIncludes(OtherQuals, Ctx); |
8153 | 8138 | } |
8154 | 8139 |
|
8155 | 8140 | /// If Type is a reference type (e.g., const |
|
0 commit comments