@@ -1220,35 +1220,11 @@ static void handlePreferredName(Sema &S, Decl *D, const ParsedAttr &AL) {
12201220 << TT->getDecl ();
12211221}
12221222
1223- bool Sema::isValidPointerAttrType (QualType T, bool RefOkay) {
1224- if (RefOkay) {
1225- if (T->isReferenceType ())
1226- return true ;
1227- } else {
1228- T = T.getNonReferenceType ();
1229- }
1230-
1231- // The nonnull attribute, and other similar attributes, can be applied to a
1232- // transparent union that contains a pointer type.
1233- if (const RecordType *UT = T->getAsUnionType ()) {
1234- if (UT && UT->getDecl ()->hasAttr <TransparentUnionAttr>()) {
1235- RecordDecl *UD = UT->getDecl ();
1236- for (const auto *I : UD->fields ()) {
1237- QualType QT = I->getType ();
1238- if (QT->isAnyPointerType () || QT->isBlockPointerType ())
1239- return true ;
1240- }
1241- }
1242- }
1243-
1244- return T->isAnyPointerType () || T->isBlockPointerType ();
1245- }
1246-
12471223static bool attrNonNullArgCheck (Sema &S, QualType T, const ParsedAttr &AL,
12481224 SourceRange AttrParmRange,
12491225 SourceRange TypeRange,
12501226 bool isReturnValue = false ) {
1251- if (!S. isValidPointerAttrType (T)) {
1227+ if (!isValidPointerAttrType (T)) {
12521228 if (isReturnValue)
12531229 S.Diag (AL.getLoc (), diag::warn_attribute_return_pointers_only)
12541230 << AL << AttrParmRange << TypeRange;
@@ -1296,7 +1272,7 @@ static void handleNonNullAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
12961272 for (unsigned I = 0 , E = getFunctionOrMethodNumParams (D);
12971273 I != E && !AnyPointers; ++I) {
12981274 QualType T = getFunctionOrMethodParamType (D, I);
1299- if (T->isDependentType () || S. isValidPointerAttrType (T)) {
1275+ if (T->isDependentType () || isValidPointerAttrType (T)) {
13001276 AnyPointers = true ;
13011277 /* TO_UPSTREAM(BoundsSafety) ON*/
13021278 if (auto DCPTy = T->getAs <CountAttributedType>()) {
@@ -1355,10 +1331,11 @@ static void handleNoEscapeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
13551331 if (D->isInvalidDecl ())
13561332 return ;
13571333
1358- // noescape only applies to pointer types.
1334+ // noescape only applies to pointer and record types.
13591335 QualType T = cast<ParmVarDecl>(D)->getType ();
1360- if (!S.isValidPointerAttrType (T, /* RefOkay */ true )) {
1361- S.Diag (AL.getLoc (), diag::warn_attribute_pointers_only)
1336+ if (!isValidPointerAttrType (T, /* RefOkay */ true ) && !T->isRecordType ()) {
1337+ S.Diag (AL.getLoc (),
1338+ diag::warn_attribute_pointer_or_reference_or_record_only)
13621339 << AL << AL.getRange () << 0 ;
13631340 return ;
13641341 }
0 commit comments