3131#include " clang/Basic/PointerAuthOptions.h"
3232#include " clang/Basic/SourceLocation.h"
3333#include " clang/Basic/Specifiers.h"
34+ #include " clang/Basic/TargetInfo.h"
3435#include " clang/Basic/Visibility.h"
3536#include " llvm/ADT/APInt.h"
3637#include " llvm/ADT/APSInt.h"
@@ -323,6 +324,7 @@ class PointerAuthQualifier {
323324// / * Objective C: the GC attributes (none, weak, or strong)
324325class Qualifiers {
325326public:
327+ Qualifiers () = default ;
326328 enum TQ : uint64_t {
327329 // NOTE: These flags must be kept in sync with DeclSpec::TQ.
328330 Const = 0x1 ,
@@ -697,7 +699,8 @@ class Qualifiers {
697699 // / every address space is a superset of itself.
698700 // / CL2.0 adds:
699701 // / __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 TargetInfo &TI) {
701704 // Address spaces must match exactly.
702705 return A == B ||
703706 // Otherwise in OpenCLC v2.0 s6.5.5: every address space except
@@ -722,20 +725,25 @@ class Qualifiers {
722725 // to implicitly cast into the default address space.
723726 (A == LangAS::Default &&
724727 (B == LangAS::cuda_constant || B == LangAS::cuda_device ||
725- B == LangAS::cuda_shared));
728+ B == LangAS::cuda_shared)) ||
729+ // The AMDPGU and NVPTX targets allow all supported address spaces to
730+ // be casted to the default address space.
731+ (TI.getTriple ().isNVPTX () && A == LangAS::Default) ||
732+ (TI.getTriple ().isAMDGPU () && A == LangAS::Default);
726733 }
727734
728735 // / Returns true if the address space in these qualifiers is equal to or
729736 // / a superset of the address space in the argument qualifiers.
730- bool isAddressSpaceSupersetOf (Qualifiers other) const {
731- return isAddressSpaceSupersetOf (getAddressSpace (), other.getAddressSpace ());
737+ bool isAddressSpaceSupersetOf (Qualifiers other, const TargetInfo &TI) const {
738+ return isAddressSpaceSupersetOf (getAddressSpace (), other.getAddressSpace (),
739+ TI);
732740 }
733741
734742 // / Determines if these qualifiers compatibly include another set.
735743 // / Generally this answers the question of whether an object with the other
736744 // / qualifiers can be safely used as an object with these qualifiers.
737- bool compatiblyIncludes (Qualifiers other) const {
738- return isAddressSpaceSupersetOf (other) &&
745+ bool compatiblyIncludes (Qualifiers other, const TargetInfo &TI ) const {
746+ return isAddressSpaceSupersetOf (other, TI ) &&
739747 // ObjC GC qualifiers can match, be added, or be removed, but can't
740748 // be changed.
741749 (getObjCGCAttr () == other.getObjCGCAttr () || !hasObjCGCAttr () ||
@@ -1273,11 +1281,11 @@ class QualType {
12731281
12741282 // / Determine whether this type is more qualified than the other
12751283 // / given type, requiring exact equality for non-CVR qualifiers.
1276- bool isMoreQualifiedThan (QualType Other) const ;
1284+ bool isMoreQualifiedThan (QualType Other, const TargetInfo &TI ) const ;
12771285
12781286 // / Determine whether this type is at least as qualified as the other
12791287 // / given type, requiring exact equality for non-CVR qualifiers.
1280- bool isAtLeastAsQualifiedAs (QualType Other) const ;
1288+ bool isAtLeastAsQualifiedAs (QualType Other, const TargetInfo &TI ) const ;
12811289
12821290 QualType getNonReferenceType () const ;
12831291
@@ -1425,11 +1433,12 @@ class QualType {
14251433 // / address spaces overlap iff they are they same.
14261434 // / OpenCL C v2.0 s6.5.5 adds:
14271435 // / __generic overlaps with any address space except for __constant.
1428- bool isAddressSpaceOverlapping (QualType T) const {
1436+ bool isAddressSpaceOverlapping (QualType T, const TargetInfo &TI ) const {
14291437 Qualifiers Q = getQualifiers ();
14301438 Qualifiers TQ = T.getQualifiers ();
14311439 // Address spaces overlap if at least one of them is a superset of another
1432- return Q.isAddressSpaceSupersetOf (TQ) || TQ.isAddressSpaceSupersetOf (Q);
1440+ return Q.isAddressSpaceSupersetOf (TQ, TI) ||
1441+ TQ.isAddressSpaceSupersetOf (Q, TI);
14331442 }
14341443
14351444 // / Returns gc attribute of this type.
@@ -8112,24 +8121,26 @@ inline FunctionType::ExtInfo getFunctionExtInfo(QualType t) {
81128121// / is more qualified than "const int", "volatile int", and
81138122// / "int". However, it is not more qualified than "const volatile
81148123// / int".
8115- inline bool QualType::isMoreQualifiedThan (QualType other) const {
8124+ inline bool QualType::isMoreQualifiedThan (QualType other,
8125+ const TargetInfo &TI) const {
81168126 Qualifiers MyQuals = getQualifiers ();
81178127 Qualifiers OtherQuals = other.getQualifiers ();
8118- return (MyQuals != OtherQuals && MyQuals.compatiblyIncludes (OtherQuals));
8128+ return (MyQuals != OtherQuals && MyQuals.compatiblyIncludes (OtherQuals, TI ));
81198129}
81208130
81218131// / Determine whether this type is at last
81228132// / as qualified as the Other type. For example, "const volatile
81238133// / int" is at least as qualified as "const int", "volatile int",
81248134// / "int", and "const volatile int".
8125- inline bool QualType::isAtLeastAsQualifiedAs (QualType other) const {
8135+ inline bool QualType::isAtLeastAsQualifiedAs (QualType other,
8136+ const TargetInfo &TI) const {
81268137 Qualifiers OtherQuals = other.getQualifiers ();
81278138
81288139 // Ignore __unaligned qualifier if this type is a void.
81298140 if (getUnqualifiedType ()->isVoidType ())
81308141 OtherQuals.removeUnaligned ();
81318142
8132- return getQualifiers ().compatiblyIncludes (OtherQuals);
8143+ return getQualifiers ().compatiblyIncludes (OtherQuals, TI );
81338144}
81348145
81358146// / If Type is a reference type (e.g., const
0 commit comments