From 36ea1dd4fc5e193d0eb7f6bf69f15d3779b6da24 Mon Sep 17 00:00:00 2001 From: DeLesley Hutchins Date: Thu, 17 Oct 2013 22:53:04 +0000 Subject: Consumed Analysis: Allow parameters that are passed by non-const reference to be treated as return values, and marked with the "returned_typestate" attribute. Patch by chris.wailes@gmail.com; reviewed by delesley@google.com. llvm-svn: 192932 --- clang/lib/Sema/SemaDeclAttr.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'clang/lib/Sema/SemaDeclAttr.cpp') diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index c08767574ce..c3e6bc4cc34 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -1068,6 +1068,14 @@ static void handleCallableWhenAttr(Sema &S, Decl *D, static void handleReturnTypestateAttr(Sema &S, Decl *D, const AttributeList &Attr) { + if (!checkAttributeNumArgs(S, Attr, 1)) return; + + if (!(isa(D) || isa(D))) { + S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) << + Attr.getName() << ExpectedFunctionMethodOrParameter; + return; + } + ReturnTypestateAttr::ConsumedState ReturnState; if (Attr.isArgIdent(0)) { @@ -1084,18 +1092,16 @@ static void handleReturnTypestateAttr(Sema &S, Decl *D, return; } - if (!isa(D)) { - S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) << - Attr.getName() << ExpectedFunction; - return; - } - // FIXME: This check is currently being done in the analysis. It can be // enabled here only after the parser propagates attributes at // template specialization definition, not declaration. //QualType ReturnType; // - //if (const CXXConstructorDecl *Constructor = dyn_cast(D)) { + //if (const ParmVarDecl *Param = dyn_cast(D)) { + // ReturnType = Param->getType(); + // + //} else if (const CXXConstructorDecl *Constructor = + // dyn_cast(D)) { // ReturnType = Constructor->getThisType(S.getASTContext())->getPointeeType(); // //} else { -- cgit v1.2.3