|
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" |
@@ -323,6 +324,7 @@ class PointerAuthQualifier { |
323 | 324 | /// * Objective C: the GC attributes (none, weak, or strong) |
324 | 325 | class Qualifiers { |
325 | 326 | public: |
| 327 | + Qualifiers() = default; |
326 | 328 | enum TQ : uint64_t { |
327 | 329 | // NOTE: These flags must be kept in sync with DeclSpec::TQ. |
328 | 330 | Const = 0x1, |
@@ -697,45 +699,27 @@ class Qualifiers { |
697 | 699 | /// every address space is a superset of itself. |
698 | 700 | /// CL2.0 adds: |
699 | 701 | /// __generic is a superset of any address space except for __constant. |
700 | | - static bool isAddressSpaceSupersetOf(LangAS A, LangAS B) { |
| 702 | + static bool isAddressSpaceSupersetOf(LangAS A, LangAS B, |
| 703 | + const ASTContext &Ctx) { |
701 | 704 | // Address spaces must match exactly. |
702 | | - return A == B || |
703 | | - // Otherwise in OpenCLC v2.0 s6.5.5: every address space except |
704 | | - // for __constant can be used as __generic. |
705 | | - (A == LangAS::opencl_generic && B != LangAS::opencl_constant) || |
706 | | - // We also define global_device and global_host address spaces, |
707 | | - // to distinguish global pointers allocated on host from pointers |
708 | | - // allocated on device, which are a subset of __global. |
709 | | - (A == LangAS::opencl_global && (B == LangAS::opencl_global_device || |
710 | | - B == LangAS::opencl_global_host)) || |
711 | | - (A == LangAS::sycl_global && (B == LangAS::sycl_global_device || |
712 | | - B == LangAS::sycl_global_host)) || |
713 | | - // Consider pointer size address spaces to be equivalent to default. |
714 | | - ((isPtrSizeAddressSpace(A) || A == LangAS::Default) && |
715 | | - (isPtrSizeAddressSpace(B) || B == LangAS::Default)) || |
716 | | - // Default is a superset of SYCL address spaces. |
717 | | - (A == LangAS::Default && |
718 | | - (B == LangAS::sycl_private || B == LangAS::sycl_local || |
719 | | - B == LangAS::sycl_global || B == LangAS::sycl_global_device || |
720 | | - B == LangAS::sycl_global_host)) || |
721 | | - // In HIP device compilation, any cuda address space is allowed |
722 | | - // to implicitly cast into the default address space. |
723 | | - (A == LangAS::Default && |
724 | | - (B == LangAS::cuda_constant || B == LangAS::cuda_device || |
725 | | - B == LangAS::cuda_shared)); |
| 705 | + return A == B || isTargetAddressSpaceSupersetOf(A, B, Ctx); |
726 | 706 | } |
727 | 707 |
|
| 708 | + static bool isTargetAddressSpaceSupersetOf(LangAS A, LangAS B, |
| 709 | + const ASTContext &Ctx); |
| 710 | + |
728 | 711 | /// Returns true if the address space in these qualifiers is equal to or |
729 | 712 | /// a superset of the address space in the argument qualifiers. |
730 | | - bool isAddressSpaceSupersetOf(Qualifiers other) const { |
731 | | - return isAddressSpaceSupersetOf(getAddressSpace(), other.getAddressSpace()); |
| 713 | + bool isAddressSpaceSupersetOf(Qualifiers other, const ASTContext &Ctx) const { |
| 714 | + return isAddressSpaceSupersetOf(getAddressSpace(), other.getAddressSpace(), |
| 715 | + Ctx); |
732 | 716 | } |
733 | 717 |
|
734 | 718 | /// Determines if these qualifiers compatibly include another set. |
735 | 719 | /// Generally this answers the question of whether an object with the other |
736 | 720 | /// qualifiers can be safely used as an object with these qualifiers. |
737 | | - bool compatiblyIncludes(Qualifiers other) const { |
738 | | - return isAddressSpaceSupersetOf(other) && |
| 721 | + bool compatiblyIncludes(Qualifiers other, const ASTContext &Ctx) const { |
| 722 | + return isAddressSpaceSupersetOf(other, Ctx) && |
739 | 723 | // ObjC GC qualifiers can match, be added, or be removed, but can't |
740 | 724 | // be changed. |
741 | 725 | (getObjCGCAttr() == other.getObjCGCAttr() || !hasObjCGCAttr() || |
@@ -1273,11 +1257,11 @@ class QualType { |
1273 | 1257 |
|
1274 | 1258 | /// Determine whether this type is more qualified than the other |
1275 | 1259 | /// given type, requiring exact equality for non-CVR qualifiers. |
1276 | | - bool isMoreQualifiedThan(QualType Other) const; |
| 1260 | + bool isMoreQualifiedThan(QualType Other, const ASTContext &Ctx) const; |
1277 | 1261 |
|
1278 | 1262 | /// Determine whether this type is at least as qualified as the other |
1279 | 1263 | /// given type, requiring exact equality for non-CVR qualifiers. |
1280 | | - bool isAtLeastAsQualifiedAs(QualType Other) const; |
| 1264 | + bool isAtLeastAsQualifiedAs(QualType Other, const ASTContext &Ctx) const; |
1281 | 1265 |
|
1282 | 1266 | QualType getNonReferenceType() const; |
1283 | 1267 |
|
@@ -1425,11 +1409,12 @@ class QualType { |
1425 | 1409 | /// address spaces overlap iff they are they same. |
1426 | 1410 | /// OpenCL C v2.0 s6.5.5 adds: |
1427 | 1411 | /// __generic overlaps with any address space except for __constant. |
1428 | | - bool isAddressSpaceOverlapping(QualType T) const { |
| 1412 | + bool isAddressSpaceOverlapping(QualType T, const ASTContext &Ctx) const { |
1429 | 1413 | Qualifiers Q = getQualifiers(); |
1430 | 1414 | Qualifiers TQ = T.getQualifiers(); |
1431 | 1415 | // Address spaces overlap if at least one of them is a superset of another |
1432 | | - return Q.isAddressSpaceSupersetOf(TQ) || TQ.isAddressSpaceSupersetOf(Q); |
| 1416 | + return Q.isAddressSpaceSupersetOf(TQ, Ctx) || |
| 1417 | + TQ.isAddressSpaceSupersetOf(Q, Ctx); |
1433 | 1418 | } |
1434 | 1419 |
|
1435 | 1420 | /// Returns gc attribute of this type. |
@@ -8112,24 +8097,26 @@ inline FunctionType::ExtInfo getFunctionExtInfo(QualType t) { |
8112 | 8097 | /// is more qualified than "const int", "volatile int", and |
8113 | 8098 | /// "int". However, it is not more qualified than "const volatile |
8114 | 8099 | /// int". |
8115 | | -inline bool QualType::isMoreQualifiedThan(QualType other) const { |
| 8100 | +inline bool QualType::isMoreQualifiedThan(QualType other, |
| 8101 | + const ASTContext &Ctx) const { |
8116 | 8102 | Qualifiers MyQuals = getQualifiers(); |
8117 | 8103 | Qualifiers OtherQuals = other.getQualifiers(); |
8118 | | - return (MyQuals != OtherQuals && MyQuals.compatiblyIncludes(OtherQuals)); |
| 8104 | + return (MyQuals != OtherQuals && MyQuals.compatiblyIncludes(OtherQuals, Ctx)); |
8119 | 8105 | } |
8120 | 8106 |
|
8121 | 8107 | /// Determine whether this type is at last |
8122 | 8108 | /// as qualified as the Other type. For example, "const volatile |
8123 | 8109 | /// int" is at least as qualified as "const int", "volatile int", |
8124 | 8110 | /// "int", and "const volatile int". |
8125 | | -inline bool QualType::isAtLeastAsQualifiedAs(QualType other) const { |
| 8111 | +inline bool QualType::isAtLeastAsQualifiedAs(QualType other, |
| 8112 | + const ASTContext &Ctx) const { |
8126 | 8113 | Qualifiers OtherQuals = other.getQualifiers(); |
8127 | 8114 |
|
8128 | 8115 | // Ignore __unaligned qualifier if this type is a void. |
8129 | 8116 | if (getUnqualifiedType()->isVoidType()) |
8130 | 8117 | OtherQuals.removeUnaligned(); |
8131 | 8118 |
|
8132 | | - return getQualifiers().compatiblyIncludes(OtherQuals); |
| 8119 | + return getQualifiers().compatiblyIncludes(OtherQuals, Ctx); |
8133 | 8120 | } |
8134 | 8121 |
|
8135 | 8122 | /// If Type is a reference type (e.g., const |
|
0 commit comments