diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index b41e09d640ee8644f6b93e186ddb0c8cf885e8a6..e5a31ac16277accad26a2bb01d8199d4fd1021fa 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1295,6 +1295,37 @@ public: /// address space and return the type with qualifiers intact. QualType removePtrSizeAddrSpace(QualType T) const; +#if ENABLE_BSC + /// Return the uniqued reference to the type for a \c owned + /// qualified type. + /// + /// The resulting type has a union of the qualifiers from \p T and + /// the \c owned qualifier. + QualType getOwnedQualType(QualType T) const; + + /// Return the uniqued reference to the type for a \c borrow + /// qualified type. + /// + /// The resulting type has a union of the qualifiers from \p T and + /// the \c borrow qualifier. + QualType getBorrowQualType(QualType T) const; + + /// Remove the \c owned qualifier from the given type. + /// + /// \returns A type with the owned qualifier removed, if it was present. + QualType removeOwnedQualType(QualType T) const; + + /// Remove the \c borrow qualifier from the given type. + /// + /// \returns A type with the borrow qualifier removed, if it was present. + QualType removeBorrowQualType(QualType T) const; + + /// Return a type with CVR qualifiers, properly handling owned/borrow qualifiers in BSC mode. + /// This method correctly handles all CVR qualifiers including owned and borrow, + /// which may require ExtQuals and cannot be handled by fast qualifiers alone. + QualType getCVROBQualifiedType(QualType T, unsigned CVROB) const; +#endif + /// Return the uniqued reference to the type for a \c restrict /// qualified type. /// @@ -2163,7 +2194,6 @@ public: QualType getCVRQualifiedType(QualType T, unsigned CVR) const { return getQualifiedType(T, Qualifiers::fromCVRMask(CVR)); } - /// Un-split a SplitQualType. QualType getQualifiedType(SplitQualType split) const { return getQualifiedType(split.Ty, split.Quals); diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index ccf49eac7dd94c5c25c3d3ae9ac11fc0bb8f46c5..e49534f9c8040b302ff05b073430e37f0c9e1347 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -66,11 +66,7 @@ class TemplateParameterList; class Type; enum { - #if ENABLE_BSC - TypeAlignmentInBits = 6, - #else TypeAlignmentInBits = 4, - #endif TypeAlignment = 1 << TypeAlignmentInBits }; @@ -158,9 +154,11 @@ public: Restrict = 0x2, Volatile = 0x4, #if ENABLE_BSC - Owned = 0x8, - Borrow = 0x10, - CVRMask = Const | Volatile | Restrict | Owned | Borrow + Owned = 0x10, + Borrow = 0x20, + CVRMask = Const | Volatile | Restrict, + OBMask = Owned | Borrow, + CVROBMask = CVRMask | OBMask, #else CVRMask = Const | Volatile | Restrict #endif @@ -204,11 +202,7 @@ public: #endif /// The width of the "fast" qualifier mask. - #if ENABLE_BSC - FastWidth = 5, - #else FastWidth = 3, - #endif /// The fast qualifier mask. FastMask = (1 << FastWidth) - 1 @@ -218,7 +212,7 @@ public: /// the given sets. static Qualifiers removeCommonQualifiers(Qualifiers &L, Qualifiers &R) { // If both are only CVR-qualified, bit operations are sufficient. - if (!(L.Mask & ~CVRMask) && !(R.Mask & ~CVRMask)) { + if (!(L.Mask & ~CVROBMask) && !(R.Mask & ~CVROBMask)) { Qualifiers Q; Q.Mask = L.Mask & R.Mask; L.Mask &= ~Q.Mask; @@ -227,11 +221,17 @@ public: } Qualifiers Q; +#if ENABLE_BSC + unsigned CommonCRV = L.getCVROBQualifiers() & R.getCVROBQualifiers(); + Q.addCVROBQualifiers(CommonCRV); + L.removeCVROBQualifiers(CommonCRV); + R.removeCVROBQualifiers(CommonCRV); +#else unsigned CommonCRV = L.getCVRQualifiers() & R.getCVRQualifiers(); Q.addCVRQualifiers(CommonCRV); L.removeCVRQualifiers(CommonCRV); R.removeCVRQualifiers(CommonCRV); - +#endif if (L.getObjCGCAttr() == R.getObjCGCAttr()) { Q.setObjCGCAttr(L.getObjCGCAttr()); L.removeObjCGCAttr(); @@ -263,7 +263,13 @@ public: Qs.addCVRQualifiers(CVR); return Qs; } - + #if ENABLE_BSC + static Qualifiers fromCVROBMask(unsigned CVROB) { + Qualifiers Qs; + Qs.addCVROBQualifiers(CVROB); + return Qs; + } + #endif static Qualifiers fromCVRUMask(unsigned CVRU) { Qualifiers Qs; Qs.addCVRUQualifiers(CVRU); @@ -335,7 +341,13 @@ public: } bool hasCVRQualifiers() const { return getCVRQualifiers(); } + #if ENABLE_BSC + bool hasCVROBQualifiers() const { return getCVROBQualifiers(); } + #endif unsigned getCVRQualifiers() const { return Mask & CVRMask; } + #if ENABLE_BSC + unsigned getCVROBQualifiers() const { return Mask & CVROBMask; } + #endif unsigned getCVRUQualifiers() const { return Mask & (CVRMask | UMask); } void setCVRQualifiers(unsigned mask) { @@ -346,13 +358,30 @@ public: assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); Mask &= ~mask; } + #if ENABLE_BSC + void removeCVROBQualifiers(unsigned mask) { + assert(!(mask & ~CVROBMask) && "bitmask contains non-CVROB bits"); + Mask &= ~mask; + } + #endif void removeCVRQualifiers() { removeCVRQualifiers(CVRMask); } + #if ENABLE_BSC + void removeCVROBQualifiers() { + removeCVROBQualifiers(CVROBMask); + } + #endif void addCVRQualifiers(unsigned mask) { assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); Mask |= mask; } + #if ENABLE_BSC + void addCVROBQualifiers(unsigned mask) { + assert(!(mask & ~CVROBMask) && "bitmask contains non-CVROB bits"); + Mask |= mask; + } + #endif void addCVRUQualifiers(unsigned mask) { assert(!(mask & ~CVRMask & ~UMask) && "bitmask contains non-CVRU bits"); Mask |= mask; @@ -486,10 +515,10 @@ public: void addQualifiers(Qualifiers Q) { // If the other set doesn't have any non-boolean qualifiers, just // bit-or it in. - if (!(Q.Mask & ~CVRMask)) + if (!(Q.Mask & ~CVROBMask)) Mask |= Q.Mask; else { - Mask |= (Q.Mask & CVRMask); + Mask |= (Q.Mask & CVROBMask); if (Q.hasAddressSpace()) addAddressSpace(Q.getAddressSpace()); if (Q.hasObjCGCAttr()) @@ -503,10 +532,10 @@ public: void removeQualifiers(Qualifiers Q) { // If the other set doesn't have any non-boolean qualifiers, just // bit-and the inverse in. - if (!(Q.Mask & ~CVRMask)) + if (!(Q.Mask & ~CVROBMask)) Mask &= ~Q.Mask; else { - Mask &= ~(Q.Mask & CVRMask); + Mask &= ~(Q.Mask & CVROBMask); if (getObjCGCAttr() == Q.getObjCGCAttr()) removeObjCGCAttr(); if (getObjCLifetime() == Q.getObjCLifetime()) @@ -581,7 +610,7 @@ public: // ObjC lifetime qualifiers must match exactly. getObjCLifetime() == other.getObjCLifetime() && // CVR qualifiers may subset. - (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)) && + (((Mask & CVROBMask) | (other.Mask & CVROBMask)) == (Mask & CVROBMask)) && // U qualifier may superset. (!other.hasUnaligned() || hasUnaligned()); } @@ -652,13 +681,13 @@ public: } private: - // bits: |0 1 2 3 4|5|6 .. 7|8 .. 10|11 ... 31| - // |C R V O B|U|GCAttr|Lifetime|AddressSpace| + // bits: |0 1 2|3|4 5|6 .. 7|8 .. 10|11 ... 31| + // |C R V|U|O B|GCAttr|Lifetime|AddressSpace| uint32_t Mask = 0; #if ENABLE_BSC - static const uint32_t UMask = 0x20; - static const uint32_t UShift = 5; + static const uint32_t UMask = 0x8; + static const uint32_t UShift = 3; static const uint32_t GCAttrMask = 0xC0; static const uint32_t GCAttrShift = 6; static const uint32_t LifetimeMask = 0x700; @@ -672,7 +701,7 @@ private: static const uint32_t LifetimeShift = 6; #endif static const uint32_t AddressSpaceMask = - ~(CVRMask | UMask | GCAttrMask | LifetimeMask); + ~(CVROBMask | UMask | GCAttrMask | LifetimeMask); #if ENABLE_BSC static const uint32_t AddressSpaceShift = 11; #else @@ -824,21 +853,8 @@ class QualType { public: QualType() = default; -#if ENABLE_BSC - QualType(const Type *Ptr, unsigned Quals, bool isOwned = false) - : Value(Ptr, Quals) { - if (isOwned) - addFastQualifiers(Qualifiers::Owned); - } - QualType(const ExtQuals *Ptr, unsigned Quals, bool isOwned = false) - : Value(Ptr, Quals) { - if (isOwned) - addFastQualifiers(Qualifiers::Owned); - } -#else QualType(const Type *Ptr, unsigned Quals) : Value(Ptr, Quals) {} QualType(const ExtQuals *Ptr, unsigned Quals) : Value(Ptr, Quals) {} -#endif unsigned getLocalFastQualifiers() const { return Value.getInt(); } void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); } @@ -897,7 +913,7 @@ public: /// "owned" qualifier set, without looking through typedefs that may have /// added "owned" at a different level. bool isLocalOwnedQualified() const { - return (getLocalFastQualifiers() & Qualifiers::Owned); + return getLocalQualifiers().hasOwned(); } /// Determine whether this type is owned-qualified. @@ -907,7 +923,7 @@ public: /// "borrow" qualifier set, without looking through typedefs that may have /// added "borrow" at a different level. bool isLocalBorrowQualified() const { - return (getLocalFastQualifiers() & Qualifiers::Borrow); + return getLocalQualifiers().hasBorrow(); } /// Determine whether this type is borrow-qualified. @@ -1014,21 +1030,6 @@ public: } #if ENABLE_BSC - /// Add the `owned` type qualifier to this QualType. - void addOwned() { - addFastQualifiers(Qualifiers::Owned); - } - QualType withOwned() const { - return withFastQualifiers(Qualifiers::Owned); - } - - /// Add the `borrow` type qualifier to this QualType. - void addBorrow() { - addFastQualifiers(Qualifiers::Borrow); - } - QualType withBorrow() const { - return withFastQualifiers(Qualifiers::Borrow); - } bool isConstBorrow() const; bool isConstPointee() const; QualType addConstBorrow(const ASTContext &Context); @@ -1063,10 +1064,6 @@ public: } void removeLocalConst(); - #if ENABLE_BSC - void removeLocalOwned(); - void removeLocalBorrow(); - #endif void removeLocalVolatile(); void removeLocalRestrict(); void removeLocalCVRQualifiers(unsigned Mask); @@ -1128,7 +1125,11 @@ public: /// details), and it is not stripped by this function. Use /// getAtomicUnqualifiedType() to strip qualifiers including _Atomic. inline QualType getUnqualifiedType() const; - +#if ENABLE_BSC + /// In BSC, this is used to get the type of a variable that is + /// owned or borrowed, but not qualified with const, volatile, etc. + inline QualType getOwnedAndBorrowQualifiedType() const; +#endif /// Retrieve the unqualified variant of the given type, removing as little /// sugar as possible. /// @@ -2019,10 +2020,9 @@ protected: DependentTemplateSpecializationTypeBitfields DependentTemplateSpecializationTypeBits; PackExpansionTypeBitfields PackExpansionTypeBits; - // Add some debug code. Bellow will fail now. - // static_assert(sizeof(FunctionTypeBitfields) <= 8, - // "FunctionTypeBitfields is larger than 8 bytes!"); - // TODO: Investigate if its worth it to break above static_assert. + + static_assert(sizeof(FunctionTypeBitfields) <= 8, + "FunctionTypeBitfields is larger than 8 bytes!"); }; private: @@ -2039,9 +2039,7 @@ protected: Type(TypeClass tc, QualType canon, TypeDependence Dependence) : ExtQualsTypeCommonBase(this, canon.isNull() ? QualType(this_(), 0) : canon) { - // Add owned, borrow, sizeof(FunctionTypeBitfields) > 8 now. - // sizeof(Type) is larger too. - static_assert(sizeof(*this) <= 16 + sizeof(ExtQualsTypeCommonBase), + static_assert(sizeof(*this) <= 8 + sizeof(ExtQualsTypeCommonBase), "changing bitfields changed sizeof(Type)!"); static_assert(alignof(decltype(*this)) % sizeof(void *) == 0, "Insufficient alignment!"); @@ -4069,13 +4067,8 @@ public: bool getCmseNSCallAttr() const { return getExtInfo().getCmseNSCall(); } CallingConv getCallConv() const { return getExtInfo().getCC(); } ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); } - static_assert((~Qualifiers::FastMask & Qualifiers::CVRMask) == 0, - #if ENABLE_BSC - "Const, volatile, restrict, owned and borrow are assumed to be a subset of " - #else "Const, volatile and restrict are assumed to be a subset of " - #endif "the fast qualifiers."); bool isConst() const { return getFastTypeQuals().hasConst(); } @@ -7011,20 +7004,39 @@ inline bool QualType::hasQualifiers() const { } inline QualType QualType::getUnqualifiedType() const { - #if ENABLE_BSC - int addOwned = getCanonicalType().isOwnedQualified() ? Qualifiers::Owned : 0; - int addBorrow = - getCanonicalType().isBorrowQualified() ? Qualifiers::Borrow : 0; - #else - int addOwned = 0; - int addBorrow = 0; - #endif if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers()) - return QualType(getTypePtr(), addOwned | addBorrow); - - return QualType(getSplitUnqualifiedTypeImpl(*this).Ty, addOwned | addBorrow); + return QualType(getTypePtr(), 0); + return QualType(getSplitUnqualifiedTypeImpl(*this).Ty, 0); } +#if ENABLE_BSC +inline QualType QualType::getOwnedAndBorrowQualifiedType() const{ + if (isOwnedQualified() || isBorrowQualified()) { + if (hasLocalNonFastQualifiers()) { + const ExtQuals *extQuals = getExtQualsUnsafe(); + Qualifiers quals = extQuals->getQualifiers(); + + if (quals.hasOwned()||quals.hasBorrow()) { + return QualType(extQuals, 0); + } + } else { + QualType canonicalType = getCommonPtr()->CanonicalType; + if (canonicalType.hasLocalNonFastQualifiers()) { + const ExtQuals *canonicalExtQuals = canonicalType.getExtQualsUnsafe(); + Qualifiers canonicalQuals = canonicalExtQuals->getQualifiers(); + + if (canonicalQuals.hasOwned()||canonicalQuals.hasBorrow()) { + return QualType(canonicalExtQuals, 0); + } + } + } + } + + if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers()) + return QualType(getTypePtr(), 0); + return QualType(getSplitUnqualifiedTypeImpl(*this).Ty, 0); +} +#endif inline SplitQualType QualType::getSplitUnqualifiedType() const { if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers()) return split(); @@ -7036,17 +7048,6 @@ inline void QualType::removeLocalConst() { removeLocalFastQualifiers(Qualifiers::Const); } -#if ENABLE_BSC -inline void QualType::removeLocalOwned() { - if (!this->getCanonicalType()->isOwnedStructureType()) - removeLocalFastQualifiers(Qualifiers::Owned); -} - -inline void QualType::removeLocalBorrow() { - removeLocalFastQualifiers(Qualifiers::Borrow); -} -#endif - inline void QualType::removeLocalRestrict() { removeLocalFastQualifiers(Qualifiers::Restrict); } diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h index 4f576b9b2dd810c49308dd0b4466f0ba93431e7e..da3729bbe64e229fb5cab9de874b8f9757f63222 100644 --- a/clang/include/clang/Sema/DeclSpec.h +++ b/clang/include/clang/Sema/DeclSpec.h @@ -341,9 +341,9 @@ public: TQ_restrict = 2, TQ_volatile = 4, #if ENABLE_BSC - TQ_owned = 8, - TQ_borrow = 16, - TQ_unaligned = 32, + TQ_unaligned = 8, + TQ_owned = 16, + TQ_borrow = 32, // This has no corresponding Qualifiers::TQ value, because it's not treated // as a qualifier in our type system. TQ_atomic = 64 diff --git a/clang/include/clang/Sema/Initialization.h b/clang/include/clang/Sema/Initialization.h index f5f7f704f943a8b1c5e8404faf4fac03aa39acfd..db4e0c162a8add8e4d694e0165df68cae0628e05 100644 --- a/clang/include/clang/Sema/Initialization.h +++ b/clang/include/clang/Sema/Initialization.h @@ -265,7 +265,7 @@ public: InitializedEntity Entity; Entity.Kind = EK_Parameter; Entity.Type = - Context.getVariableArrayDecayedType(Type.getUnqualifiedType()); + Context.getVariableArrayDecayedType(Type.getOwnedAndBorrowQualifiedType()); #if ENABLE_BSC if (Context.getLangOpts().BSC) if (const AttributedType *AT = Type->getAs()) diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index e334e67fa60d74ac395098df5148cc8068e92d7e..37325bcb5f1506ea5f1cf8fdd1c65180ca1c3493 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -3066,6 +3066,53 @@ ASTContext::getExtQualType(const Type *baseType, Qualifiers quals) const { return QualType(eq, fastQuals); } +#if ENABLE_BSC +QualType ASTContext::getOwnedQualType(QualType T) const { +return getQualifiedType(T, Qualifiers::fromCVROBMask(Qualifiers::Owned)); +} + +QualType ASTContext::getBorrowQualType(QualType T) const { + return getQualifiedType(T, Qualifiers::fromCVROBMask(Qualifiers::Borrow)); +} + +QualType ASTContext::removeOwnedQualType(QualType T) const { + if(T.getCanonicalType()->isOwnedStructureType()) + return T; + QualifierCollector Quals; + const Type *TypeNode = Quals.strip(T); + + if (!Quals.hasOwned()) + return T; + + Quals.removeOwned(); + + if (Quals.hasNonFastQualifiers()) + return getExtQualType(TypeNode, Quals); + return QualType(TypeNode, Quals.getFastQualifiers()); +} + +QualType ASTContext::removeBorrowQualType(QualType T) const { + QualifierCollector Quals; + const Type *TypeNode = Quals.strip(T); + + if (!Quals.hasBorrow()) + return T; + + Quals.removeBorrow(); + + if (Quals.hasNonFastQualifiers()) + return getExtQualType(TypeNode, Quals); + return QualType(TypeNode, Quals.getFastQualifiers()); +} + +QualType ASTContext::getCVROBQualifiedType(QualType T, unsigned CVROB) const { + // Use the existing infrastructure which already handles CVR properly + // Qualifiers::fromCVRMask correctly creates a Qualifiers object with CVR bits + // getQualifiedType properly handles both fast and extended qualifiers + return getQualifiedType(T, Qualifiers::fromCVROBMask(CVROB)); +} +#endif + QualType ASTContext::getAddrSpaceQualType(QualType T, LangAS AddressSpace) const { QualType CanT = getCanonicalType(T); @@ -4748,29 +4795,35 @@ QualType ASTContext::getUsingType(const UsingShadowDecl *Found, } QualType ASTContext::getRecordType(const RecordDecl *Decl) const { - if (Decl->TypeForDecl) - return QualType(Decl->TypeForDecl, 0 + if (Decl->TypeForDecl) { + QualType Result = QualType(Decl->TypeForDecl, 0); #if ENABLE_BSC - , Decl->isOwnedDecl() + if (Decl->isOwnedDecl()) + Result = getOwnedQualType(Result); #endif - ); + return Result; + } if (const RecordDecl *PrevDecl = Decl->getPreviousDecl()) - if (PrevDecl->TypeForDecl) - return QualType(Decl->TypeForDecl = PrevDecl->TypeForDecl, 0 + if (PrevDecl->TypeForDecl) { + Decl->TypeForDecl = PrevDecl->TypeForDecl; + QualType Result = QualType(Decl->TypeForDecl, 0); #if ENABLE_BSC - , Decl->isOwnedDecl() + if (Decl->isOwnedDecl()) + Result = getOwnedQualType(Result); #endif - ); + return Result; + } auto *newType = new (*this, TypeAlignment) RecordType(Decl); Decl->TypeForDecl = newType; Types.push_back(newType); - return QualType(newType, 0 + QualType Result = QualType(newType, 0); #if ENABLE_BSC - , Decl->isOwnedDecl() + if (Decl->isOwnedDecl()) + Result = getOwnedQualType(Result); #endif - ); + return Result; } #if ENABLE_BSC @@ -6226,9 +6279,13 @@ bool ASTContext::hasCvrSimilarType(QualType T1, QualType T2) { Qualifiers Quals1, Quals2; T1 = getUnqualifiedArrayType(T1, Quals1); T2 = getUnqualifiedArrayType(T2, Quals2); - +#if ENABLE_BSC + Quals1.removeCVROBQualifiers(); + Quals2.removeCVROBQualifiers(); +#else Quals1.removeCVRQualifiers(); Quals2.removeCVRQualifiers(); +#endif if (Quals1 != Quals2) return false; @@ -10446,13 +10503,6 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, RHS = RHS.getUnqualifiedType(); } -#if ENABLE_BSC - LHS.removeLocalOwned(); - RHS.removeLocalOwned(); - LHS.removeLocalBorrow(); - RHS.removeLocalBorrow(); -#endif - QualType LHSCan = getCanonicalType(LHS), RHSCan = getCanonicalType(RHS); @@ -10466,7 +10516,11 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, if (LQuals != RQuals) { // If any of these qualifiers are different, we have a type // mismatch. +#if ENABLE_BSC + if (LQuals.getCVROBQualifiers() != RQuals.getCVROBQualifiers() || +#else if (LQuals.getCVRQualifiers() != RQuals.getCVRQualifiers() || +#endif LQuals.getAddressSpace() != RQuals.getAddressSpace() || LQuals.getObjCLifetime() != RQuals.getObjCLifetime() || LQuals.hasUnaligned() != RQuals.hasUnaligned()) @@ -10883,7 +10937,11 @@ QualType ASTContext::mergeObjCGCQualifiers(QualType LHS, QualType RHS) { Qualifiers RQuals = RHSCan.getLocalQualifiers(); if (LQuals != RQuals) { // If any of these qualifiers are different, we have a type mismatch. +#if ENABLE_BSC + if (LQuals.getCVROBQualifiers() != RQuals.getCVROBQualifiers() || +#else if (LQuals.getCVRQualifiers() != RQuals.getCVRQualifiers() || +#endif LQuals.getAddressSpace() != RQuals.getAddressSpace()) return {}; diff --git a/clang/lib/AST/BSC/DeclBSC.cpp b/clang/lib/AST/BSC/DeclBSC.cpp index a18aed24fef242f15eff2a9df85189c37627d752..bf04c3c38b3589efbbe78911c0874f2dd3619d1c 100644 --- a/clang/lib/AST/BSC/DeclBSC.cpp +++ b/clang/lib/AST/BSC/DeclBSC.cpp @@ -108,7 +108,8 @@ void TraitDecl::completeDefinition() { void TraitDecl::MapInsert(QualType QT, VarDecl *VD) { ASTContext &Ctx = getASTContext(); - std::pair key = std::make_pair(this, QT); + QualType CanonicalQT = QT.getCanonicalType().getUnqualifiedType(); + std::pair key = std::make_pair(this, CanonicalQT); Ctx.TraitImplMap[key] = VD; } diff --git a/clang/lib/AST/BSC/TypeBSC.cpp b/clang/lib/AST/BSC/TypeBSC.cpp index a4802b3f3e15dec313f661c299ec734b2862ccc4..a1a0598ffb003624c7762d992eaa67f83bc5074f 100644 --- a/clang/lib/AST/BSC/TypeBSC.cpp +++ b/clang/lib/AST/BSC/TypeBSC.cpp @@ -322,7 +322,7 @@ bool QualType::hasBorrow() const { } bool QualType::isConstBorrow() const { - QualType QT = QualType(getTypePtr(), getLocalFastQualifiers()); + QualType QT = *this; if (QT.isBorrowQualified()) { while (QT->isPointerType()) { QT = QT->getPointeeType(); @@ -344,30 +344,34 @@ bool QualType::isConstPointee() const { } QualType QualType::addConstBorrow(const ASTContext &Context) { - SmallVector Qualifiers; + SmallVector QualifiersList; int PointerNum = 0; - QualType QT = QualType(getTypePtr(), getLocalFastQualifiers()); + QualType QT = *this; while (QT->isPointerType()) { - Qualifiers.push_back(QT.getLocalFastQualifiers()); + // Store all qualifiers (including owned/borrow from ExtQuals) + QualifiersList.push_back(QT.getLocalQualifiers()); QT = QT->getPointeeType(); PointerNum++; } QT.addConst(); while (PointerNum) { QT = Context.getPointerType(QT); - QT.setLocalFastQualifiers(Qualifiers[PointerNum - 1]); + // Restore all qualifiers (including owned/borrow) + QT = Context.getQualifiedType(QT, QualifiersList[PointerNum - 1]); PointerNum--; } - QT.addBorrow(); + // Replace with borrow-qualified type properly. + QT = Context.getBorrowQualType(QT); return QT; } QualType QualType::removeConstForBorrow(const ASTContext &Context) { - SmallVector Qualifiers; + SmallVector QualifiersList; int PointerNum = 0; - QualType QT = QualType(getTypePtr(), getLocalFastQualifiers()); + QualType QT = *this; while (QT->isPointerType()) { - Qualifiers.push_back(QT.getLocalFastQualifiers()); + // Store all qualifiers (including owned/borrow from ExtQuals) + QualifiersList.push_back(QT.getLocalQualifiers()); QT = QT->getPointeeType(); PointerNum++; } @@ -375,7 +379,8 @@ QualType QualType::removeConstForBorrow(const ASTContext &Context) { PointerNum--; while (PointerNum + 1) { QT = Context.getPointerType(QT); - QT.setLocalFastQualifiers(Qualifiers[PointerNum]); + // Restore all qualifiers (including owned/borrow) + QT = Context.getQualifiedType(QT, QualifiersList[PointerNum]); PointerNum--; } return QT; diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index c694f1b45838ba4be8f03c274dfc4c6411ee6bf6..bc2e3bf382c69acabaa7632dbaef548b966e69fc 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -4505,13 +4505,27 @@ struct IncDecSubobjectHandler { case APValue::Float: return found(Subobj.getFloat(), SubobjType); case APValue::ComplexInt: +#if ENABLE_BSC + return found(Subobj.getComplexIntReal(), + Info.Ctx.getCVROBQualifiedType( + SubobjType->castAs()->getElementType(), + SubobjType.getCVRQualifiers())); +#else return found(Subobj.getComplexIntReal(), SubobjType->castAs()->getElementType() .withCVRQualifiers(SubobjType.getCVRQualifiers())); +#endif case APValue::ComplexFloat: +#if ENABLE_BSC + return found(Subobj.getComplexFloatReal(), + Info.Ctx.getCVROBQualifiedType( + SubobjType->castAs()->getElementType(), + SubobjType.getCVRQualifiers())); +#else return found(Subobj.getComplexFloatReal(), SubobjType->castAs()->getElementType() .withCVRQualifiers(SubobjType.getCVRQualifiers())); +#endif case APValue::LValue: return foundPointer(Subobj, SubobjType); default: diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index 326d35ee0daf7ea3a8a5fdf3e6f3741f3372d6d5..4f556368521c64ab710228c952b6e5c2a8420307 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -6093,7 +6093,11 @@ bool CXXNameMangler::mangleSubstitution(NestedNameSpecifier *NNS) { /// substitutions. static bool hasMangledSubstitutionQualifiers(QualType T) { Qualifiers Qs = T.getQualifiers(); +#if ENABLE_BSC + return Qs.getCVROBQualifiers() || Qs.hasAddressSpace() || Qs.hasUnaligned(); +#else return Qs.getCVRQualifiers() || Qs.hasAddressSpace() || Qs.hasUnaligned(); +#endif } bool CXXNameMangler::mangleSubstitution(QualType T) { diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index 5a1f820f107c108f3122364fdd22f4d7b8314e6c..a4760f28432d4cb76347f39ef8db7f8098386d9e 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -61,7 +61,7 @@ using namespace clang; bool Qualifiers::isStrictSupersetOf(Qualifiers Other) const { return (*this != Other) && // CVR qualifiers superset - (((Mask & CVRMask) | (Other.Mask & CVRMask)) == (Mask & CVRMask)) && + (((Mask & CVROBMask) | (Other.Mask & CVROBMask)) == (Mask & CVROBMask)) && // ObjC GC qualifiers superset ((getObjCGCAttr() == Other.getObjCGCAttr()) || (hasObjCGCAttr() && !Other.hasObjCGCAttr())) && @@ -1509,8 +1509,8 @@ QualType QualType::stripObjCKindOfType(const ASTContext &constCtx) const { QualType QualType::getAtomicUnqualifiedType() const { if (const auto AT = getTypePtr()->getAs()) - return AT->getValueType().getUnqualifiedType(); - return getUnqualifiedType(); + return AT->getValueType().getOwnedAndBorrowQualifiedType(); + return getOwnedAndBorrowQualifiedType(); } Optional> Type::getObjCSubstitutions( @@ -3228,9 +3228,9 @@ QualType QualType::getNonLValueExprType(const ASTContext &Context) const { if (const AttributedType *AT = dyn_cast(this->getTypePtr())) return Context.getAttributedType( - AT->getAttrKind(), getUnqualifiedType(), getUnqualifiedType()); + AT->getAttrKind(), getOwnedAndBorrowQualifiedType(), getOwnedAndBorrowQualifiedType()); #endif - return getUnqualifiedType(); + return getOwnedAndBorrowQualifiedType(); } return *this; diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index fc5e9bfdf5bab8b73cda3a21a39a837d1d14a97f..13b1dcfe022379e09bdc01f8d3b3f467fed37fcc 100644 --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -2370,7 +2370,11 @@ std::string Qualifiers::getAsString(const PrintingPolicy &Policy) const { } bool Qualifiers::isEmptyWhenPrinted(const PrintingPolicy &Policy) const { +#if ENABLE_BSC + if (getCVROBQualifiers()) +#else if (getCVRQualifiers()) +#endif return false; if (getAddressSpace() != LangAS::Default) @@ -2432,8 +2436,11 @@ std::string Qualifiers::getAddrSpaceAsString(LangAS AS) { void Qualifiers::print(raw_ostream &OS, const PrintingPolicy& Policy, bool appendSpaceIfNonEmpty) const { bool addSpace = false; - +#if ENABLE_BSC + unsigned quals = getCVROBQualifiers(); +#else unsigned quals = getCVRQualifiers(); +#endif if (quals) { AppendTypeQualList(OS, quals, Policy.Restrict #if ENABLE_BSC diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 142b88d803e5425b0c2e6af1209cd9100df3aeb6..4ea0121f0e74fb8d6af6c56270a184bc846d7ad1 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -4212,7 +4212,11 @@ EmitExtVectorElementExpr(const ExtVectorElementExpr *E) { } QualType type = +#ifdef ENABLE_BSC + getContext().getCVROBQualifiedType(E->getType(), Base.getQuals().getCVROBQualifiers()); +#else E->getType().withCVRQualifiers(Base.getQuals().getCVRQualifiers()); +#endif // Encode the element access list into a vector of unsigned indices. SmallVector Indices; @@ -4386,8 +4390,12 @@ LValue CodeGenFunction::EmitLValueForField(LValue base, const bool UseVolatile = isAAPCS(CGM.getTarget()) && CGM.getCodeGenOpts().AAPCSBitfieldWidth && Info.VolatileStorageSize != 0 && - field->getType() - .withCVRQualifiers(base.getVRQualifiers()) + +#ifdef ENABLE_BSC + getContext().getCVROBQualifiedType(field->getType(), base.getVRQualifiers()) +#else + field->getType().withCVRQualifiers(base.getVRQualifiers()) +#endif .isVolatileQualified(); Address Addr = base.getAddress(*this); unsigned Idx = RL.getLLVMFieldNo(field); @@ -4419,7 +4427,11 @@ LValue CodeGenFunction::EmitLValueForField(LValue base, } QualType fieldType = +#ifdef ENABLE_BSC + getContext().getCVROBQualifiedType(field->getType(), base.getVRQualifiers()); +#else field->getType().withCVRQualifiers(base.getVRQualifiers()); +#endif // TODO: Support TBAA for bit fields. LValueBaseInfo FieldBaseInfo(BaseInfo.getAlignmentSource()); return LValue::MakeBitfield(Addr, Info, fieldType, FieldBaseInfo, diff --git a/clang/lib/CodeGen/CGObjCRuntime.cpp b/clang/lib/CodeGen/CGObjCRuntime.cpp index 550fd3d70bdccae05382d83c12b592fbae7e4f66..ba621944a27c4fb814d64999778759f100553cca 100644 --- a/clang/lib/CodeGen/CGObjCRuntime.cpp +++ b/clang/lib/CodeGen/CGObjCRuntime.cpp @@ -18,6 +18,7 @@ #include "CGRecordLayout.h" #include "CodeGenFunction.h" #include "CodeGenModule.h" +#include "clang/AST/ASTContext.h" #include "clang/AST/RecordLayout.h" #include "clang/AST/StmtObjC.h" #include "clang/CodeGen/CGFunctionInfo.h" @@ -61,7 +62,11 @@ LValue CGObjCRuntime::EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF, QualType ObjectPtrTy = CGF.CGM.getContext().getObjCObjectPointerType(InterfaceTy); QualType IvarTy = +#ifdef ENABLE_BSC + CGF.getContext().getCVROBQualifiedType(Ivar->getUsageType(ObjectPtrTy), CVRQualifiers); +#else Ivar->getUsageType(ObjectPtrTy).withCVRQualifiers(CVRQualifiers); +#endif llvm::Type *LTy = CGF.CGM.getTypes().ConvertTypeForMem(IvarTy); llvm::Value *V = CGF.Builder.CreateBitCast(BaseValue, CGF.Int8PtrTy); V = CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, V, Offset, "add.ptr"); diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 1f40bd902fc1a7fbe55aebc457af067f0f0a861b..215993ffa0063a13c4084f845b766f372abb7482 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -6806,8 +6806,12 @@ static QualType GeneralizeType(ASTContext &Ctx, QualType Ty) { return Ty; return Ctx.getPointerType( +#ifdef ENABLE_BSC + Ctx.getCVROBQualifiedType(Ctx.VoidTy, Ty->getPointeeType().getCVRQualifiers())); +#else QualType(Ctx.VoidTy).withCVRQualifiers( Ty->getPointeeType().getCVRQualifiers())); +#endif } // Apply type generalization to a FunctionType's return and argument types diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 2b00eeec46c9a1e741bc165832ad1f5c6d55a567..292d7c8dcda264ff0faad809a3a44bad37fb4130 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -6332,7 +6332,8 @@ void Parser::ParseDeclaratorInternal(Declarator &D, ExtendedTy = ICT->getInjectedSpecializationType(); } // add owned qualifiers for ExtendedTy. - ExtendedTy.addFastQualifiers(Qualifiers::Owned); + // Replace with owned-qualified type properly. + ExtendedTy = Actions.Context.getOwnedQualType(ExtendedTy); BSS.setExtendedType(ExtendedTy); if (Actions.Context.BSCDeclContextMap.find(BasedType) == Actions.Context.BSCDeclContextMap.end()) { diff --git a/clang/lib/Sema/BSC/SemaBSCDestructor.cpp b/clang/lib/Sema/BSC/SemaBSCDestructor.cpp index adae3e428015a0dd4baddb9f8cc5d5f5241b61f8..6aea78491d2c016d95d245ccd17b3f2cc0989fa2 100644 --- a/clang/lib/Sema/BSC/SemaBSCDestructor.cpp +++ b/clang/lib/Sema/BSC/SemaBSCDestructor.cpp @@ -62,7 +62,7 @@ BSCMethodDecl *Sema::getOrInsertBSCDestructor(RecordDecl *RD) { dyn_cast(ParamType)) { ParamType = ICT->getInjectedSpecializationType(); } - ParamType.addOwned(); + ParamType = getASTContext().getOwnedQualType(ParamType); SmallVector ParamTys; ParamTys.push_back(ParamType); QualType FuncType = @@ -157,7 +157,7 @@ void Sema::HandleBSCDestructorBody(RecordDecl *RD, BSCMethodDecl *Destructor, } ParmVarDecl *PVD = Destructor->getParamDecl(0); QualType ParamType = getASTContext().getRecordType(RD); - ParamType.addOwned(); + ParamType = getASTContext().getOwnedQualType(ParamType); Expr *DRE = BuildDeclRefExpr(PVD, ParamType, VK_LValue, CS->getRBracLoc()); diff --git a/clang/lib/Sema/BSC/SemaBSCOverload.cpp b/clang/lib/Sema/BSC/SemaBSCOverload.cpp index b459407b60a286964b81e8762c5d5afc0d7fd6e2..e038a03524d267b2fd999b3717bbad49a3e33753 100644 --- a/clang/lib/Sema/BSC/SemaBSCOverload.cpp +++ b/clang/lib/Sema/BSC/SemaBSCOverload.cpp @@ -41,7 +41,8 @@ Expr *Sema::DesugarOperatorFirstArg(FunctionDecl *FD, ArrayRef Args) { } QT = Context.getPointerType(QT); if (FirstParamTy.isBorrowQualified()) { - QT.addBorrow(); + // Replace with borrow-qualified type properly. + QT = Context.getBorrowQualType(QT); UO = (UO == UO_AddrConst ? UO_AddrConst : UO_AddrMut); } argExpr = UnaryOperator::Create(Context, Args[0], UO, QT, VK_PRValue, diff --git a/clang/lib/Sema/BSC/SemaBSCOwnership.cpp b/clang/lib/Sema/BSC/SemaBSCOwnership.cpp index c197a8c5ff22211b0c0296782f1f988c5302cdb5..1ba2fe0b430d685e8f3c5796e25dc42f4f66cba8 100644 --- a/clang/lib/Sema/BSC/SemaBSCOwnership.cpp +++ b/clang/lib/Sema/BSC/SemaBSCOwnership.cpp @@ -250,8 +250,8 @@ bool Sema::CheckBorrowQualTypeCStyleCast(QualType LHSType, QualType RHSType) { const auto *LHSPtrType = LHSType->getAs(); const auto *RHSPtrType = RHSType->getAs(); bool IsPointer = LHSPtrType && RHSPtrType; - QualType RHSRawType = RHSCanType.getUnqualifiedType(); - QualType LHSRawType = LHSCanType.getUnqualifiedType(); + QualType RHSRawType = RHSCanType.getOwnedAndBorrowQualifiedType(); + QualType LHSRawType = LHSCanType.getOwnedAndBorrowQualifiedType(); if (IsSameType) { return true; @@ -313,8 +313,8 @@ bool Sema::CheckBorrowQualTypeAssignment(QualType LHSType, QualType RHSType, Sou bool Sema::CheckBorrowQualTypeAssignment(QualType LHSType, Expr* RHSExpr) { QualType RHSCanType = - RHSExpr->getType().getCanonicalType().getUnqualifiedType(); - QualType LHSCanType = LHSType.getCanonicalType().getUnqualifiedType(); + RHSExpr->getType().getCanonicalType().getOwnedAndBorrowQualifiedType(); + QualType LHSCanType = LHSType.getCanonicalType().getOwnedAndBorrowQualifiedType(); SourceLocation ExprLoc = RHSExpr->getBeginLoc(); bool Res = true; @@ -322,7 +322,7 @@ bool Sema::CheckBorrowQualTypeAssignment(QualType LHSType, Expr* RHSExpr) { if (TraitDecl *TD = TryDesugarTrait(LHSCanType)) { if (RHSCanType->isPointerType()) { QualType ImplType = RHSCanType->getPointeeType().getUnqualifiedType().getCanonicalType(); - ImplType.removeLocalOwned(); + ImplType = Context.removeOwnedQualType(ImplType); if (TD->getTypeImpledVarDecl(ImplType)) return true; } diff --git a/clang/lib/Sema/BSC/SemaBSCSafeZone.cpp b/clang/lib/Sema/BSC/SemaBSCSafeZone.cpp index 1e53906233e062b08a626755ef01221bfff5c728..69e156042772a76154f2db1f3c6eb053bb07ff87 100644 --- a/clang/lib/Sema/BSC/SemaBSCSafeZone.cpp +++ b/clang/lib/Sema/BSC/SemaBSCSafeZone.cpp @@ -203,8 +203,8 @@ bool Sema::IsSafeFunctionPointerTypeCast(QualType DestType, Expr *SrcExpr) { return false; } - if (LSHFuncType->getReturnType().getUnqualifiedType() != - RSHFuncType->getReturnType().getUnqualifiedType()) { + if (LSHFuncType->getReturnType().getOwnedAndBorrowQualifiedType() != + RSHFuncType->getReturnType().getOwnedAndBorrowQualifiedType()) { Diag(SrcExpr->getBeginLoc(), diag::err_unsafe_fun_cast) << SrcExpr->getType() << DestType; return false; @@ -217,8 +217,8 @@ bool Sema::IsSafeFunctionPointerTypeCast(QualType DestType, Expr *SrcExpr) { } for (unsigned i = 0; i < LSHFuncType->getNumParams(); i++) { - if (LSHFuncType->getParamType(i).getUnqualifiedType() != - RSHFuncType->getParamType(i).getUnqualifiedType()) { + if (LSHFuncType->getParamType(i).getOwnedAndBorrowQualifiedType() != + RSHFuncType->getParamType(i).getOwnedAndBorrowQualifiedType()) { Diag(SrcExpr->getBeginLoc(), diag::err_unsafe_fun_cast) << SrcExpr->getType() << DestType; return false; diff --git a/clang/lib/Sema/BSC/SemaBSCTrait.cpp b/clang/lib/Sema/BSC/SemaBSCTrait.cpp index a09089a1d6aa4f0b41a5b7501fb806ac84af1311..76e57295399879a5e991a7a09ee394816ea818ef 100644 --- a/clang/lib/Sema/BSC/SemaBSCTrait.cpp +++ b/clang/lib/Sema/BSC/SemaBSCTrait.cpp @@ -179,9 +179,11 @@ RecordDecl *Sema::ActOnDesugarTraitRecord(TraitDecl *TD, std::string VtableName = "vtable"; QualType DataPT = Context.getPointerType(Context.VoidTy); if (addOwned) - DataPT.addOwned(); + // Replace with owned-qualified type properly. + DataPT = Context.getOwnedQualType(DataPT); if (addBorrow) - DataPT.addBorrow(); + // Replace with borrow-qualified type properly. + DataPT = Context.getBorrowQualType(DataPT); QualType RecordTy = Context.getRecordType(TraitVtableRD); ClassTemplateDecl *CTD = TraitVtableRD->getDescribedClassTemplate(); if (CTD) @@ -293,9 +295,11 @@ Expr *Sema::ConvertParmTraitToStructTrait(Expr *UO, QualType ProtoArgType, QualType VoidPT = Context.getPointerType(Context.VoidTy); if ((ProtoArgType.isOwnedQualified() || ProtoArgType->isMoveSemanticType()) && UO->getType().isOwnedQualified()) - VoidPT.addOwned(); + // Replace with owned-qualified type properly. + VoidPT = Context.getOwnedQualType(VoidPT); else if (ProtoArgType->hasBorrowFields() && UO->getType().isBorrowQualified()) - VoidPT.addBorrow(); + // Replace with borrow-qualified type properly. + VoidPT = Context.getBorrowQualType(VoidPT); QualType VtablePT = QualType(); RecordDecl *RD = ProtoArgType->getAsRecordDecl(); for (auto Field : RD->fields()) { @@ -831,9 +835,11 @@ VarDecl *Sema::ActOnDesugarTraitInstance(Decl *D) { } else { QualType VoidPT = Context.getPointerType(Context.VoidTy); if (VD->getType().isOwnedQualified()) - VoidPT.addOwned(); + // Replace with owned-qualified type properly. + VoidPT = Context.getOwnedQualType(VoidPT); if (VD->getType().isBorrowQualified()) - VoidPT.addBorrow(); + // Replace with borrow-qualified type properly. + VoidPT = Context.getBorrowQualType(VoidPT); ImplicitCastExpr *TraitData = ImplicitCastExpr::Create(Context, VoidPT, /* CastKind=*/CK_BitCast, @@ -1120,8 +1126,8 @@ ExprResult Sema::ActOnTraitReassign(Scope *S, SourceLocation TokLoc, RecordDecl *RD = dyn_cast(LTy.getCanonicalType())->getDecl(); QualType T = - RE->getType()->getPointeeType().getUnqualifiedType().getCanonicalType(); - T.removeLocalOwned(); + RE->getType()->getPointeeType().getOwnedAndBorrowQualifiedType().getCanonicalType(); + T = Context.removeOwnedQualType(T); for (RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end(); I != E; ++I) { Expr *NewLHSExpr = BuildMemberExpr( diff --git a/clang/lib/Sema/BSC/SemaDeclBSC.cpp b/clang/lib/Sema/BSC/SemaDeclBSC.cpp index c9991e6011754a4a20e424f0fed2a523803ad173..b65ee7d4c67689088f576930c4004223e1ef5945 100644 --- a/clang/lib/Sema/BSC/SemaDeclBSC.cpp +++ b/clang/lib/Sema/BSC/SemaDeclBSC.cpp @@ -101,8 +101,8 @@ bool Sema::HasDiffBorrowOrOwnedParamsTypeAtBothFunction(QualType LHS, return true; } for (unsigned i = 0; i < LSHFuncType->getNumParams(); i++) { - QualType LHSParType = LSHFuncType->getParamType(i).getUnqualifiedType(); - QualType RHSParType = RSHFuncType->getParamType(i).getUnqualifiedType(); + QualType LHSParType = LSHFuncType->getParamType(i).getOwnedAndBorrowQualifiedType(); + QualType RHSParType = RSHFuncType->getParamType(i).getOwnedAndBorrowQualifiedType(); if (HasDiffBorrorOrOwnedQualifiers(LHSParType, RHSParType)) { return true; } diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp index b174416b2a54141d7e60aecb9b218d61a37aebe5..b1d48b2fa54fbddd0ac554cf48c301967b7e6d56 100644 --- a/clang/lib/Sema/SemaCast.cpp +++ b/clang/lib/Sema/SemaCast.cpp @@ -67,7 +67,9 @@ namespace { // expression is adjusted to T prior to any further analysis. if (!S.Context.getLangOpts().ObjC && !DestType->isRecordType() && !DestType->isArrayType()) { - DestType = DestType.getUnqualifiedType(); +#if ENABLE_BSC + DestType = DestType.getOwnedAndBorrowQualifiedType(); +#endif } if (const BuiltinType *placeholder = @@ -622,7 +624,11 @@ unwrapCastAwayConstnessLevel(ASTContext &Context, QualType &T1, QualType &T2) { Kind = CastAwayConstnessKind::CACK_SimilarKind; T1 = Unwrap(T1); +#ifdef ENABLE_BSC + T2 = Context.getCVROBQualifiedType(Unwrap(T2), T2.getCVRQualifiers()); +#else T2 = Unwrap(T2).withCVRQualifiers(T2.getCVRQualifiers()); +#endif } return Kind; @@ -685,10 +691,17 @@ CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType, if (CheckCVR) { Qualifiers SrcCvrQuals = +#ifdef ENABLE_BSC + Qualifiers::fromCVROBMask(SrcQuals.getCVROBQualifiers()); +#else Qualifiers::fromCVRMask(SrcQuals.getCVRQualifiers()); +#endif Qualifiers DestCvrQuals = +#ifdef ENABLE_BSC + Qualifiers::fromCVROBMask(DestQuals.getCVROBQualifiers()); +#else Qualifiers::fromCVRMask(DestQuals.getCVRQualifiers()); - +#endif if (SrcCvrQuals != DestCvrQuals) { if (CastAwayQualifiers) *CastAwayQualifiers = SrcCvrQuals - DestCvrQuals; diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index c7bfeb708742410a78779ed7784f85b0ef63b584..0b881f37989c17392efbe977ad1cdbb3e1d43a92 100755 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -14785,7 +14785,7 @@ Decl *Sema::ActOnParamDeclarator(Scope *S, Declarator &D // check memberfunction type whether has cvr-qualifiers // cvr-qualified type is not allowed to define member functions Qualifiers ETQ = ExtendedType.getQualifiers(); - if (ETQ.hasCVRQualifiers() && + if (ETQ.hasCVROBQualifiers() && !((TypePtr->isOwnedStructureType() || TypePtr->isOwnedTemplateSpecializationType()) && ETQ.hasOnlyOwned())) { Diag(D.getBeginLoc(), diag::err_cvrqualified_member_type_unsupported) diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 71c4a74ea387f8d985b4bedf24a3c7db0ebcf461..08dbf05c841b5ae60dbb2a174acfcbf37ef66a2a 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -15758,9 +15758,14 @@ static CanQualType RemoveAddressSpaceFromPtr(Sema &SemaRef, auto &Ctx = SemaRef.Context; Qualifiers PtrQuals = PtrTy->getPointeeType().getQualifiers(); PtrQuals.removeAddressSpace(); - return Ctx.getPointerType(Ctx.getCanonicalType(Ctx.getQualifiedType( - PtrTy->getPointeeType().getUnqualifiedType(), PtrQuals))); -} +#if ENABLE_BSC + return Ctx.getPointerType(Ctx.getCanonicalType(Ctx.getQualifiedType( + PtrTy->getPointeeType().getOwnedAndBorrowQualifiedType(), PtrQuals))); +#else + return Ctx.getPointerType(Ctx.getCanonicalType(Ctx.getQualifiedType( + PtrTy->getPointeeType().getUnqualifiedType(), PtrQuals))); +#endif + } static inline bool CheckOperatorNewDeleteTypes(Sema &SemaRef, const FunctionDecl *FnDecl, diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 37def7ff1d965244fa7a4fe6ba29bcea7b6f55ac..ed5c9d71c75edde7035bc00618a29412a676eb00 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -695,8 +695,11 @@ ExprResult Sema::DefaultLvalueConversion(Expr *E) { // version of the type of the lvalue; otherwise, the value has the // type of the lvalue. if (T.hasQualifiers()) +#if ENABLE_BSC + T = T.getOwnedAndBorrowQualifiedType(); +#else T = T.getUnqualifiedType(); - +#endif // Under the MS ABI, lock down the inheritance model now. if (T->isMemberPointerType() && Context.getTargetInfo().getCXXABI().isMicrosoft()) @@ -745,7 +748,11 @@ ExprResult Sema::DefaultLvalueConversion(Expr *E) { // ... if the lvalue has atomic type, the value has the non-atomic version // of the type of the lvalue ... if (const AtomicType *Atomic = T->getAs()) { +#if ENABLE_BSC + T = Atomic->getValueType().getOwnedAndBorrowQualifiedType(); +#else T = Atomic->getValueType().getUnqualifiedType(); +#endif Res = ImplicitCastExpr::Create(Context, T, CK_AtomicToNonAtomic, Res.get(), nullptr, VK_PRValue, FPOptionsOverride()); } @@ -3528,7 +3535,11 @@ ExprResult Sema::BuildDeclarationNameExpr( // [...] The expression is an lvalue if the entity is a [...] template // parameter object. if (type->isRecordType()) { +#if ENABLE_BSC + type = type.getOwnedAndBorrowQualifiedType().withConst(); +#else type = type.getUnqualifiedType().withConst(); +#endif valueKind = VK_LValue; break; } @@ -3536,7 +3547,11 @@ ExprResult Sema::BuildDeclarationNameExpr( // For non-references, we need to strip qualifiers just in case // the template parameter was declared as 'const int' or whatever. valueKind = VK_PRValue; - type = type.getUnqualifiedType(); +#if ENABLE_BSC + type = type.getOwnedAndBorrowQualifiedType(); +#else + type = type.getUnqualifiedType()(); +#endif break; } @@ -7273,8 +7288,12 @@ ExprResult Sema::BuildCallExpr(Scope *Scope, Expr *Fn, SourceLocation LParenLoc, Qualifiers ArgPtQuals = ArgPtTy.getQualifiers(); ArgPtQuals.setAddressSpace(ParamAS); auto NewArgPtTy = +#if ENABLE_BSC + Context.getQualifiedType(ArgPtTy.getOwnedAndBorrowQualifiedType(), ArgPtQuals); +#else Context.getQualifiedType(ArgPtTy.getUnqualifiedType(), ArgPtQuals); - auto NewArgTy = +#endif + auto NewArgTy = Context.getQualifiedType(Context.getPointerType(NewArgPtTy), ArgTy.getQualifiers()); @@ -8733,12 +8752,19 @@ static QualType checkConditionalPointerCompatibility(Sema &S, ExprResult &LHS, << RHS.get()->getSourceRange(); return QualType(); } - +#if ENABLE_BSC + unsigned MergedCVRQual = lhQual.getCVROBQualifiers() | rhQual.getCVROBQualifiers(); +#else unsigned MergedCVRQual = lhQual.getCVRQualifiers() | rhQual.getCVRQualifiers(); +#endif auto LHSCastKind = CK_BitCast, RHSCastKind = CK_BitCast; - lhQual.removeCVRQualifiers(); - rhQual.removeCVRQualifiers(); - +#if ENABLE_BSC + lhQual.removeCVROBQualifiers(); + rhQual.removeCVROBQualifiers(); +#else + Quals1.removeCVRQualifiers(); + Quals2.removeCVRQualifiers(); +#endif // OpenCL v2.0 specification doesn't extend compatibility of type qualifiers // (C99 6.7.3) for address spaces. We assume that the check should behave in // the same manner as it's defined for CVR qualifiers, so for OpenCL two @@ -8755,10 +8781,13 @@ static QualType checkConditionalPointerCompatibility(Sema &S, ExprResult &LHS, RAddrSpace == ResultAddrSpace ? CK_BitCast : CK_AddressSpaceConversion; lhQual.removeAddressSpace(); rhQual.removeAddressSpace(); - +#if ENABLE_BSC + lhptee = S.Context.getQualifiedType(lhptee.getOwnedAndBorrowQualifiedType(), lhQual); + rhptee = S.Context.getQualifiedType(rhptee.getOwnedAndBorrowQualifiedType(), rhQual); +#else lhptee = S.Context.getQualifiedType(lhptee.getUnqualifiedType(), lhQual); rhptee = S.Context.getQualifiedType(rhptee.getUnqualifiedType(), rhQual); - +#endif QualType CompositeTy = S.Context.mergeTypes(lhptee, rhptee); if (CompositeTy.isNull()) { @@ -8794,10 +8823,18 @@ static QualType checkConditionalPointerCompatibility(Sema &S, ExprResult &LHS, Qualifiers CompositeQuals = CompositeTy.getQualifiers(); CompositeQuals.setAddressSpace(ResultAddrSpace); return S.Context +#if ENABLE_BSC + .getQualifiedType(CompositeTy.getOwnedAndBorrowQualifiedType(), CompositeQuals) +#else .getQualifiedType(CompositeTy.getUnqualifiedType(), CompositeQuals) +#endif .withCVRQualifiers(MergedCVRQual); } +#ifdef ENABLE_BSC + return S.Context.getCVROBQualifiedType(CompositeTy, MergedCVRQual); +#else return CompositeTy.withCVRQualifiers(MergedCVRQual); +#endif }(); if (IsBlockPointer) ResultTy = S.Context.getBlockPointerType(ResultTy); @@ -9209,7 +9246,11 @@ QualType Sema::CheckConditionalOperands(ExprResult &Cond, ExprResult &LHS, if (LHSRT->getDecl() == RHSRT->getDecl()) // "If both the operands have structure or union type, the result has // that type." This implies that CV qualifiers are dropped. +#if ENABLE_BSC + return LHSTy.getOwnedAndBorrowQualifiedType(); +#else return LHSTy.getUnqualifiedType(); +#endif // FIXME: Type of conditional expression must be complete in C mode. } @@ -10409,8 +10450,8 @@ static bool IsTraitEqualExpr(Sema &S, QualType DstType, QualType SrcType, SourceLocation Loc) { if (TraitDecl *TD = S.TryDesugarTrait(DstType)) { if (SrcType->isPointerType()) { - QualType T = SrcType->getPointeeType().getUnqualifiedType().getCanonicalType(); - T.removeLocalOwned(); + QualType T = SrcType->getPointeeType().getOwnedAndBorrowQualifiedType().getCanonicalType(); + T = S.Context.removeOwnedQualType(T); if (TD->getTypeImpledVarDecl(T)) return true; while (T->isPointerType()) @@ -10504,11 +10545,11 @@ Sema::CheckSingleAssignmentConstraints(QualType LHSType, ExprResult &CallerRHS, // cv-unqualified type of the left operand. QualType RHSType = RHS.get()->getType(); if (Diagnose) { - RHS = PerformImplicitConversion(RHS.get(), LHSType.getUnqualifiedType(), + RHS = PerformImplicitConversion(RHS.get(), LHSType.getOwnedAndBorrowQualifiedType(), AA_Assigning); } else { ImplicitConversionSequence ICS = - TryImplicitConversion(RHS.get(), LHSType.getUnqualifiedType(), + TryImplicitConversion(RHS.get(), LHSType.getOwnedAndBorrowQualifiedType(), /*SuppressUserConversions=*/false, AllowedExplicit::None, /*InOverloadResolution=*/false, @@ -10516,7 +10557,7 @@ Sema::CheckSingleAssignmentConstraints(QualType LHSType, ExprResult &CallerRHS, /*AllowObjCWritebackConversion=*/false); if (ICS.isFailure()) return Incompatible; - RHS = PerformImplicitConversion(RHS.get(), LHSType.getUnqualifiedType(), + RHS = PerformImplicitConversion(RHS.get(), LHSType.getOwnedAndBorrowQualifiedType(), ICS, AA_Assigning); } if (RHS.isInvalid()) @@ -14818,7 +14859,7 @@ static QualType CheckIncrementDecrementOperand(Sema &S, Expr *Op, return ResType; } else { VK = VK_PRValue; - return ResType.getUnqualifiedType(); + return ResType.getOwnedAndBorrowQualifiedType(); } } @@ -14946,10 +14987,12 @@ QualType Sema::GetBorrowAddressOperandQualType(QualType resultType, if (!resultType.isNull()) { if (resultType->isPointerType()) { resultType = resultType.getUnqualifiedType(); - resultType.removeLocalOwned(); - resultType.addBorrow(); + resultType = Context.removeOwnedQualType(resultType); + // Replace with borrow-qualified type properly. + resultType = Context.getBorrowQualType(resultType); } else { - resultType.addBorrow(); + // Replace with borrow-qualified type properly. + resultType = Context.getBorrowQualType(resultType); } } } else if (Opc == UO_AddrConst || Opc == UO_AddrConstDeref) { @@ -14963,10 +15006,11 @@ QualType Sema::GetBorrowAddressOperandQualType(QualType resultType, if (!resultType.isNull()) { if (resultType->isFunctionPointerType()) { resultType.addConst(); - resultType.addBorrow(); + // Replace with borrow-qualified type properly. + resultType = Context.getBorrowQualType(resultType); } else if (resultType->isPointerType()) { resultType = resultType.getUnqualifiedType(); - resultType.removeLocalOwned(); + resultType = Context.removeOwnedQualType(resultType); resultType = resultType.addConstBorrow(Context); } else { resultType = resultType.addConstBorrow(Context); @@ -19352,7 +19396,7 @@ static bool captureInCapturedRegion( // Using an LValue reference type is consistent with Lambdas (see below). if (S.isOpenMPCapturedDecl(Var)) { bool HasConst = DeclRefType.isConstQualified(); - DeclRefType = DeclRefType.getUnqualifiedType(); + DeclRefType = DeclRefType.getOwnedAndBorrowQualifiedType(); // Don't lose diagnostics about assignments to const. if (HasConst) DeclRefType.addConst(); @@ -19731,7 +19775,7 @@ bool Sema::tryCaptureVariable( (IsGlobal && !IsGlobalCap)) { Nested = !IsTargetCap; bool HasConst = DeclRefType.isConstQualified(); - DeclRefType = DeclRefType.getUnqualifiedType(); + DeclRefType = DeclRefType.getOwnedAndBorrowQualifiedType(); // Don't lose diagnostics about assignments to const. if (HasConst) DeclRefType.addConst(); diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 4a98035b77d9e0a12e317db23cf778fca9ccb106..c3858fe0c7571099ab87f9965a35ee6793538a30 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -1179,7 +1179,7 @@ static QualType adjustCVQualifiersForCXXThisWithinLambda( while (Closure && IsThisCaptured(Closure, IsByCopyCapture, IsConstCapture)) { if (IsByCopyCapture) { - ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask); + ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask); if (IsConstCapture) ClassType.addConst(); return ASTCtx.getPointerType(ClassType); diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index c605201445ff4ac62a3d2fcc0525be5f894d3f0c..4d36e54170559f2240d0da759f267b1cbaff2a77 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -4305,7 +4305,7 @@ ResolveOverloadedFunctionForReferenceBinding(Sema &S, Sequence.AddAddressOverloadResolutionStep(Fn, Found, HadMultipleCandidates); SourceType = Fn->getType(); - UnqualifiedSourceType = SourceType.getUnqualifiedType(); + UnqualifiedSourceType = SourceType.getOwnedAndBorrowQualifiedType(); } else if (!UnqualifiedTargetType->isRecordType()) { Sequence.SetFailed(InitializationSequence::FK_AddressOfOverloadFailed); return true; @@ -4649,9 +4649,9 @@ static OverloadingResult TryRefInitWithConversionFunction( InitializationSequence &Sequence) { QualType DestType = Entity.getType(); QualType cv1T1 = DestType->castAs()->getPointeeType(); - QualType T1 = cv1T1.getUnqualifiedType(); + QualType T1 = cv1T1.getOwnedAndBorrowQualifiedType(); QualType cv2T2 = Initializer->getType(); - QualType T2 = cv2T2.getUnqualifiedType(); + QualType T2 = cv2T2.getOwnedAndBorrowQualifiedType(); assert(!S.CompareReferenceRelationship(Initializer->getBeginLoc(), T1, T2) && "Must have incompatible references when binding via conversion"); @@ -5153,8 +5153,13 @@ static void TryReferenceInitializationCore(Sema &S, // [...] If T1 is reference-related to T2, cv1 must be the // same cv-qualification as, or greater cv-qualification // than, cv2; otherwise, the program is ill-formed. +#if ENABLE_BSC + unsigned T1CVRQuals = T1Quals.getCVROBQualifiers(); + unsigned T2CVRQuals = T2Quals.getCVROBQualifiers(); +#else unsigned T1CVRQuals = T1Quals.getCVRQualifiers(); unsigned T2CVRQuals = T2Quals.getCVRQualifiers(); +#endif if (RefRelationship == Sema::Ref_Related && ((T1CVRQuals | T2CVRQuals) != T1CVRQuals || !T1Quals.isAddressSpaceSupersetOf(T2Quals))) { @@ -5433,7 +5438,7 @@ static void TryUserDefinedConversion(Sema &S, // subsumed by the initialization. Per DR5, the created temporary is of the // cv-unqualified type of the destination. Sequence.AddUserConversionStep(Function, Best->FoundDecl, - DestType.getUnqualifiedType(), + DestType.getOwnedAndBorrowQualifiedType(), HadMultipleCandidates); // C++14 and before: @@ -9333,8 +9338,13 @@ bool InitializationSequence::Diagnose(Sema &S, else if (DroppedQualifiers.hasQualifiers()) S.Diag(Kind.getLocation(), diag::err_reference_bind_drops_quals) << NonRefType << SourceType << 0 /*cv quals*/ +#if ENABLE_BSC + << Qualifiers::fromCVROBMask(DroppedQualifiers.getCVROBQualifiers()) + << DroppedQualifiers.getCVROBQualifiers() << Args[0]->getSourceRange(); +#else << Qualifiers::fromCVRMask(DroppedQualifiers.getCVRQualifiers()) << DroppedQualifiers.getCVRQualifiers() << Args[0]->getSourceRange(); +#endif else // FIXME: Consider decomposing the type and explaining which qualifiers // were dropped where, or on which level a 'const' is missing, etc. diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index a1b1fc807c6be7c91e6ce0bb51c2bb1c84b90b3e..fa29d73eef2622c794b2311ac84dc0533ae70e2d 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -3284,7 +3284,11 @@ static bool isQualificationConversionStep(QualType FromType, QualType ToType, // -- if the cv 1,j and cv 2,j are different, then const is in // every cv for 0 < k < j. +#if ENABLE_BSC + if (!CStyle && FromQuals.getCVROBQualifiers() != ToQuals.getCVROBQualifiers() && +#else if (!CStyle && FromQuals.getCVRQualifiers() != ToQuals.getCVRQualifiers() && +#endif !PreviousToQualsIncludeConst) return false; @@ -5548,7 +5552,11 @@ Sema::PerformObjectArgumentInitialization(Expr *From, case BadConversionSequence::bad_qualifiers: { Qualifiers FromQs = FromRecordType.getQualifiers(); Qualifiers ToQs = DestType.getQualifiers(); +#if ENABLE_BSC + unsigned CVR = FromQs.getCVROBQualifiers() & ~ToQs.getCVROBQualifiers(); +#else unsigned CVR = FromQs.getCVRQualifiers() & ~ToQs.getCVRQualifiers(); +#endif if (CVR) { Diag(From->getBeginLoc(), diag::err_member_function_call_bad_cvr) << Method->getDeclName() << FromRecordType << (CVR - 1) @@ -8049,19 +8057,49 @@ BuiltinCandidateTypeSet::AddPointerWithMoreQualifiedTypeVariants(QualType Ty, #endif // Iterate through all strict supersets of BaseCVR. - for (unsigned CVR = BaseCVR+1; CVR <= Qualifiers::CVRMask; ++CVR) { +#if ENABLE_BSC + unsigned BaseCVROnly = BaseCVR & Qualifiers::CVRMask; + unsigned BaseOBOnly = BaseCVR & Qualifiers::OBMask; + for (unsigned CVR = BaseCVROnly; CVR <= Qualifiers::CVRMask; ++CVR) { + for (unsigned OB = BaseOBOnly; OB <= Qualifiers::OBMask; OB += 16) { + unsigned Mask = CVR | OB; + if (Mask <= BaseCVR || (Mask | BaseCVR) != Mask) continue; + // Skip over volatile if no volatile found anywhere in the types. + if ((Mask & Qualifiers::Volatile) && !hasVolatile) continue; + + // Skip over owned if no owned found anywhere in the types. + if ((Mask & Qualifiers::Owned) && !hasOwned) continue; + + // Skip over borrow if no borrow found anywhere in the types. + if ((Mask & Qualifiers::Borrow) && !hasBorrow) continue; + + // Skip over restrict if no restrict found anywhere in the types, or if + // the type cannot be restrict-qualified. + if ((Mask & Qualifiers::Restrict) && + (!hasRestrict || + (!(PointeeTy->isAnyPointerType() || PointeeTy->isReferenceType())))) + continue; + + // Build qualified pointee type. + QualType QPointeeTy = Context.getCVROBQualifiedType(PointeeTy, Mask); + + // Build qualified pointer type. + QualType QPointerTy; + if (!buildObjCPtr) + QPointerTy = Context.getPointerType(QPointeeTy); + else + QPointerTy = Context.getObjCObjectPointerType(QPointeeTy); + + // Insert qualified pointer type. + PointerTypes.insert(QPointerTy); + } + } +#else + for (unsigned CVR = BaseCVR+1; CVR <= Qualifiers::CVROBMask; ++CVR) { if ((CVR | BaseCVR) != CVR) continue; // Skip over volatile if no volatile found anywhere in the types. if ((CVR & Qualifiers::Volatile) && !hasVolatile) continue; - #if ENABLE_BSC - // Skip over owned if no owned found anywhere in the types. - if ((CVR & Qualifiers::Owned) && !hasOwned) continue; - - // Skip over borrow if no borrow found anywhere in the types. - if ((CVR & Qualifiers::Borrow) && !hasBorrow) continue; - #endif - // Skip over restrict if no restrict found anywhere in the types, or if // the type cannot be restrict-qualified. if ((CVR & Qualifiers::Restrict) && @@ -8082,6 +8120,7 @@ BuiltinCandidateTypeSet::AddPointerWithMoreQualifiedTypeVariants(QualType Ty, // Insert qualified pointer type. PointerTypes.insert(QPointerTy); } +#endif return true; } @@ -8117,13 +8156,28 @@ BuiltinCandidateTypeSet::AddMemberPointerWithMoreQualifiedTypeVariants( // Iterate through all strict supersets of the pointee type's CVR // qualifiers. unsigned BaseCVR = PointeeTy.getCVRQualifiers(); - for (unsigned CVR = BaseCVR+1; CVR <= Qualifiers::CVRMask; ++CVR) { +#if ENABLE_BSC + unsigned BaseCVROnly = BaseCVR & Qualifiers::CVRMask; + unsigned BaseOBOnly = BaseCVR & Qualifiers::OBMask; + for (unsigned CVR = BaseCVROnly; CVR <= Qualifiers::CVRMask; ++CVR) { + for (unsigned OB = BaseOBOnly; OB <= Qualifiers::OBMask; OB += 16) { + unsigned Mask = CVR | OB; + if (Mask <= BaseCVR || (Mask | BaseCVR) != Mask) continue; + + QualType QPointeeTy = Context.getCVROBQualifiedType(PointeeTy, Mask); + MemberPointerTypes.insert( + Context.getMemberPointerType(QPointeeTy, ClassTy)); + } + } +#else + for (unsigned CVR = BaseCVR+1; CVR <= Qualifiers::CVROBMask; ++CVR) { if ((CVR | BaseCVR) != CVR) continue; QualType QPointeeTy = Context.getCVRQualifiedType(PointeeTy, CVR); MemberPointerTypes.insert( Context.getMemberPointerType(QPointeeTy, ClassTy)); } +#endif return true; } @@ -10737,8 +10791,11 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand, MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); return; } - +#if ENABLE_BSC + unsigned CVR = FromQs.getCVROBQualifiers() & ~ToQs.getCVROBQualifiers(); +#else unsigned CVR = FromQs.getCVRQualifiers() & ~ToQs.getCVRQualifiers(); +#endif assert(CVR && "expected qualifiers mismatch"); if (isObjectArgument) { diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index df440a9335ef3fa715efda49f5de9f0912314329..747cd9aaa9b0fd31fb47d80bd4790854f24eea1a 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -412,7 +412,7 @@ static Sema::TemplateDeductionResult DeduceNonTypeTemplateArgument( ParamType = ParamType.getNonReferenceType(); else // Top-level cv-qualifiers are irrelevant for a non-reference type. - ValueType = ValueType.getUnqualifiedType(); + ValueType = ValueType.getOwnedAndBorrowQualifiedType(); return DeduceTemplateArgumentsByTypeMatch( S, TemplateParams, ParamType, ValueType, Info, Deduced, @@ -1034,8 +1034,8 @@ DeduceTemplateArguments(Sema &S, if (Sema::TemplateDeductionResult Result = DeduceTemplateArgumentsByTypeMatch( - S, TemplateParams, Params[ParamIdx].getUnqualifiedType(), - Args[ArgIdx].getUnqualifiedType(), Info, Deduced, TDF, + S, TemplateParams, Params[ParamIdx].getOwnedAndBorrowQualifiedType(), + Args[ArgIdx].getOwnedAndBorrowQualifiedType(), Info, Deduced, TDF, PartialOrdering, /*DeducedFromArrayBound=*/false)) return Result; @@ -1061,8 +1061,8 @@ DeduceTemplateArguments(Sema &S, // Deduce template arguments from the pattern. if (Sema::TemplateDeductionResult Result = DeduceTemplateArgumentsByTypeMatch( - S, TemplateParams, Pattern.getUnqualifiedType(), - Args[ArgIdx].getUnqualifiedType(), Info, Deduced, TDF, + S, TemplateParams, Pattern.getOwnedAndBorrowQualifiedType(), + Args[ArgIdx].getOwnedAndBorrowQualifiedType(), Info, Deduced, TDF, PartialOrdering, /*DeducedFromArrayBound=*/false)) return Result; @@ -1135,7 +1135,11 @@ static bool hasInconsistentOrSupersetQualifiersOf(QualType ParamType, return true; // CVR qualifiers inconsistent or a superset. +#if ENABLE_BSC + return (ParamQs.getCVROBQualifiers() & ~ArgQs.getCVROBQualifiers()) != 0; +#else return (ParamQs.getCVRQualifiers() & ~ArgQs.getCVRQualifiers()) != 0; +#endif } /// Compare types for equality with respect to possibly compatible @@ -1505,7 +1509,7 @@ static Sema::TemplateDeductionResult DeduceTemplateArgumentsByTypeMatch( DeducedQs.setObjCLifetime(Qualifiers::OCL_Strong); DeducedType = - S.Context.getQualifiedType(DeducedType.getUnqualifiedType(), DeducedQs); + S.Context.getQualifiedType(DeducedType.getOwnedAndBorrowQualifiedType(), DeducedQs); DeducedTemplateArgument NewDeduced(DeducedType, DeducedFromArrayBound); DeducedTemplateArgument Result = @@ -3353,7 +3357,7 @@ CheckOriginalCallArgDeduction(Sema &S, TemplateDeductionInfo &Info, // Qualifiers are compatible, so have the argument type adopt the // deduced argument type's qualifiers as if we had performed the // qualification conversion. - A = Context.getQualifiedType(A.getUnqualifiedType(), DeducedAQuals); + A = Context.getQualifiedType(A.getOwnedAndBorrowQualifiedType(), DeducedAQuals); } } @@ -3734,7 +3738,7 @@ static bool AdjustFunctionParmAndArgTypesForDeduction( // If P is a cv-qualified type, the top level cv-qualifiers of P's type // are ignored for type deduction. if (ParamType.hasQualifiers()) - ParamType = ParamType.getUnqualifiedType(); + ParamType = ParamType.getOwnedAndBorrowQualifiedType(); // [...] If P is a reference type, the type referred to by P is // used for type deduction. @@ -3784,7 +3788,7 @@ static bool AdjustFunctionParmAndArgTypesForDeduction( else { // - If A is a cv-qualified type, the top level cv-qualifiers of A's // type are ignored for type deduction. - ArgType = ArgType.getUnqualifiedType(); + ArgType = ArgType.getOwnedAndBorrowQualifiedType(); } } @@ -4329,8 +4333,8 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *ConversionTemplate, // removed from P and A in this case, unless P was a reference type. This // seems to mostly match what other compilers are doing. if (!FromType->getAs()) { - A = A.getUnqualifiedType(); - P = P.getUnqualifiedType(); + A = A.getOwnedAndBorrowQualifiedType(); + P = P.getOwnedAndBorrowQualifiedType(); } // C++ [temp.deduct.conv]p3: @@ -4352,13 +4356,13 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *ConversionTemplate, // - If P is a cv-qualified type, the top level cv-qualifiers of // P's type are ignored for type deduction. else - P = P.getUnqualifiedType(); + P = P.getOwnedAndBorrowQualifiedType(); // C++0x [temp.deduct.conv]p4: // If A is a cv-qualified type, the top level cv-qualifiers of A's // type are ignored for type deduction. If A is a reference type, the type // referred to by A is used for type deduction. - A = A.getUnqualifiedType(); + A = A.getOwnedAndBorrowQualifiedType(); } // Unevaluated SFINAE context. diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 39232992907b972bcff895a39dab2cdeca6ebdef..e2ebd38552cd4547b9b2aca3dd0b49c8317ef034 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -2092,11 +2092,18 @@ QualType Sema::BuildQualifiedType(QualType T, SourceLocation Loc, DS ? DS->getAtomicSpecLoc() : Loc); if (T.isNull()) return T; +#if ENABLE_BSC + Split.Quals.addCVROBQualifiers(CVR); +#else Split.Quals.addCVRQualifiers(CVR); +#endif return BuildQualifiedType(T, Loc, Split.Quals); } - +#if ENABLE_BSC + Qualifiers Q = Qualifiers::fromCVROBMask(CVR); +#else Qualifiers Q = Qualifiers::fromCVRMask(CVR); +#endif Q.setUnaligned(CVRAU & DeclSpec::TQ_unaligned); return BuildQualifiedType(T, Loc, Q, DS); } @@ -5882,7 +5889,11 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, // Strip the cv-qualifiers and ref-qualifiers from the type. FunctionProtoType::ExtProtoInfo EPI = FnTy->getExtProtoInfo(); +#if ENABLE_BSC + EPI.TypeQuals.removeCVROBQualifiers(); +#else EPI.TypeQuals.removeCVRQualifiers(); +#endif EPI.RefQualifier = RQ_None; T = Context.getFunctionType(FnTy->getReturnType(), FnTy->getParamTypes(),