diff options
Diffstat (limited to 'clang/lib/Sema/SemaDeclAttr.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index a05856ed7d3..2f92d3dbb2d 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -1548,18 +1548,16 @@ static void handleTLSModelAttr(Sema &S, Decl *D, Attr.getAttributeSpellingListIndex())); } -static void handleMallocAttr(Sema &S, Decl *D, const AttributeList &Attr) { - if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { - QualType RetTy = FD->getReturnType(); - if (RetTy->isAnyPointerType() || RetTy->isBlockPointerType()) { - D->addAttr(::new (S.Context) - MallocAttr(Attr.getRange(), S.Context, - Attr.getAttributeSpellingListIndex())); - return; - } +static void handleRestrictAttr(Sema &S, Decl *D, const AttributeList &Attr) { + QualType ResultType = getFunctionOrMethodResultType(D); + if (ResultType->isAnyPointerType() || ResultType->isBlockPointerType()) { + D->addAttr(::new (S.Context) RestrictAttr( + Attr.getRange(), S.Context, Attr.getAttributeSpellingListIndex())); + return; } - S.Diag(Attr.getLoc(), diag::warn_attribute_malloc_pointer_only); + S.Diag(Attr.getLoc(), diag::warn_attribute_return_pointers_only) + << Attr.getName() << getFunctionOrMethodResultSourceRange(D); } static void handleCommonAttr(Sema &S, Decl *D, const AttributeList &Attr) { @@ -4453,8 +4451,8 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, case AttributeList::AT_CUDALaunchBounds: handleLaunchBoundsAttr(S, D, Attr); break; - case AttributeList::AT_Malloc: - handleMallocAttr(S, D, Attr); + case AttributeList::AT_Restrict: + handleRestrictAttr(S, D, Attr); break; case AttributeList::AT_MayAlias: handleSimpleAttribute<MayAliasAttr>(S, D, Attr); |