From b71368d28532908ae1c2dc23f91761781205b3d0 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Sat, 9 May 2009 02:44:38 +0000 Subject: [PATCH] Add back Parse/Sema support for attributes cf_returns_retained and ns_returns_retained, but do not include the other ownership attributes we previously had. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71308 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Attr.h | 6 ++++ include/clang/Parse/AttributeList.h | 2 ++ lib/Frontend/PCHReaderDecl.cpp | 2 ++ lib/Frontend/PCHWriter.cpp | 2 ++ lib/Sema/SemaDeclAttr.cpp | 44 +++++++++++++++++++++++++++++ 5 files changed, 56 insertions(+) diff --git a/include/clang/AST/Attr.h b/include/clang/AST/Attr.h index 63705e3d68..287d80f93f 100644 --- a/include/clang/AST/Attr.h +++ b/include/clang/AST/Attr.h @@ -59,6 +59,8 @@ public: NonNull, ObjCException, ObjCNSObject, + CFReturnsRetained, // Clang/Checker-specific. + NSReturnsRetained, // Clang/Checker-specific. Overloadable, // Clang-specific Packed, Pure, @@ -459,6 +461,10 @@ public: static bool classof(const RegparmAttr *A) { return true; } }; +// Checker-specific attributes. +DEF_SIMPLE_ATTR(CFReturnsRetained); +DEF_SIMPLE_ATTR(NSReturnsRetained); + #undef DEF_SIMPLE_ATTR } // end namespace clang diff --git a/include/clang/Parse/AttributeList.h b/include/clang/Parse/AttributeList.h index 8f7c8f5f44..7f67213ae9 100644 --- a/include/clang/Parse/AttributeList.h +++ b/include/clang/Parse/AttributeList.h @@ -76,6 +76,8 @@ public: AT_nothrow, AT_nsobject, AT_objc_exception, + AT_cf_returns_retained, // Clang-specific. + AT_ns_returns_retained, // Clang-specific. AT_objc_gc, AT_overloadable, // Clang-specific. AT_packed, diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp index d47a008f1f..e623b6f1d7 100644 --- a/lib/Frontend/PCHReaderDecl.cpp +++ b/lib/Frontend/PCHReaderDecl.cpp @@ -475,6 +475,8 @@ Attr *PCHReader::ReadAttributes() { SIMPLE_ATTR(ObjCException); SIMPLE_ATTR(ObjCNSObject); + SIMPLE_ATTR(CFReturnsRetained); + SIMPLE_ATTR(NSReturnsRetained); SIMPLE_ATTR(Overloadable); UNSIGNED_ATTR(Packed); SIMPLE_ATTR(Pure); diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index 688cedc524..4b9ca5c41a 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/lib/Frontend/PCHWriter.cpp @@ -1544,6 +1544,8 @@ void PCHWriter::WriteAttributeRecord(const Attr *Attr) { case Attr::ObjCException: case Attr::ObjCNSObject: + case Attr::CFReturnsRetained: + case Attr::NSReturnsRetained: case Attr::Overloadable: break; diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index a5365fc654..919f28ffec 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -1543,6 +1543,44 @@ static void HandleRegparmAttr(Decl *d, const AttributeList &Attr, Sema &S) { d->addAttr(::new (S.Context) RegparmAttr(NumParams.getZExtValue())); } +//===----------------------------------------------------------------------===// +// Checker-specific attribute handlers. +//===----------------------------------------------------------------------===// + +static void HandleNSReturnsRetainedAttr(Decl *d, const AttributeList &Attr, + Sema &S) { + + if (!isa(d) && !isa(d)) { + const char *name; + + switch (Attr.getKind()) { + default: + assert(0 && "invalid ownership attribute"); + return; + case AttributeList::AT_cf_returns_retained: + name = "cf_returns_retained"; break; + case AttributeList::AT_ns_returns_retained: + name = "ns_returns_retained"; break; + }; + + S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) << + name << 3 /* function or method */; + return; + } + + switch (Attr.getKind()) { + default: + assert(0 && "invalid ownership attribute"); + return; + case AttributeList::AT_cf_returns_retained: + d->addAttr(::new (S.Context) CFReturnsRetainedAttr()); + return; + case AttributeList::AT_ns_returns_retained: + d->addAttr(::new (S.Context) NSReturnsRetainedAttr()); + return; + }; +} + //===----------------------------------------------------------------------===// // Top Level Sema Entry Points //===----------------------------------------------------------------------===// @@ -1579,6 +1617,12 @@ static void ProcessDeclAttribute(Decl *D, const AttributeList &Attr, Sema &S) { case AttributeList::AT_nonnull: HandleNonNullAttr (D, Attr, S); break; case AttributeList::AT_noreturn: HandleNoReturnAttr (D, Attr, S); break; case AttributeList::AT_nothrow: HandleNothrowAttr (D, Attr, S); break; + + // Checker-specific. + case AttributeList::AT_ns_returns_retained: + case AttributeList::AT_cf_returns_retained: + HandleNSReturnsRetainedAttr(D, Attr, S); break; + case AttributeList::AT_packed: HandlePackedAttr (D, Attr, S); break; case AttributeList::AT_section: HandleSectionAttr (D, Attr, S); break; case AttributeList::AT_stdcall: HandleStdCallAttr (D, Attr, S); break; -- 2.40.0