diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-01-28 22:42:45 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-01-28 22:42:45 +0000 |
commit | 3a2b7a18a4504f39e3ded0d2b5749c5c80b8b9b5 (patch) | |
tree | fc4e910b0c160814e3a27e3b19092b2a5bbc41f3 /lib/Sema/SemaDeclAttr.cpp | |
parent | 319d8fc2221fb41b3d332e091bd1e3e53ac05931 (diff) |
Finish semantic analysis for [[carries_dependency]] attribute.
This required plumbing through a new flag to determine whether a ParmVarDecl is
actually a parameter of a function declaration (as opposed to a function
typedef etc, where the attribute is prohibited). Weirdly, this attribute (just
like [[noreturn]]) cannot be applied to a function type, just to a function
declaration (and its parameters).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173726 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclAttr.cpp')
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index bb77adfd45..adeb8e690f 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -24,6 +24,7 @@ #include "clang/Sema/DeclSpec.h" #include "clang/Sema/DelayedDiagnostic.h" #include "clang/Sema/Lookup.h" +#include "clang/Sema/Scope.h" #include "llvm/ADT/StringExtras.h" using namespace clang; using namespace sema; @@ -1815,13 +1816,25 @@ static void handleVecReturnAttr(Sema &S, Decl *D, const AttributeList &Attr) { Attr.getAttributeSpellingListIndex())); } -static void handleDependencyAttr(Sema &S, Decl *D, const AttributeList &Attr) { - if (!isa<FunctionDecl>(D) && !isa<ParmVarDecl>(D)) { +static void handleDependencyAttr(Sema &S, Scope *Scope, Decl *D, + const AttributeList &Attr) { + if (isa<ParmVarDecl>(D)) { + // [[carries_dependency]] can only be applied to a parameter if it is a + // parameter of a function declaration or lambda. + if (!(Scope->getFlags() & clang::Scope::FunctionDeclarationScope)) { + S.Diag(Attr.getLoc(), + diag::err_carries_dependency_param_not_function_decl); + return; + } + } else if (!isa<FunctionDecl>(D)) { S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type) << Attr.getName() << ExpectedFunctionMethodOrParameter; return; } - // FIXME: Actually store the attribute on the declaration + + D->addAttr(::new (S.Context) CarriesDependencyAttr( + Attr.getRange(), S.Context, + Attr.getAttributeSpellingListIndex())); } static void handleUnusedAttr(Sema &S, Decl *D, const AttributeList &Attr) { @@ -4494,7 +4507,8 @@ static void ProcessInheritableDeclAttr(Sema &S, Scope *scope, Decl *D, case AttributeList::AT_Annotate: handleAnnotateAttr (S, D, Attr); break; case AttributeList::AT_Availability:handleAvailabilityAttr(S, D, Attr); break; case AttributeList::AT_CarriesDependency: - handleDependencyAttr (S, D, Attr); break; + handleDependencyAttr(S, scope, D, Attr); + break; case AttributeList::AT_Common: handleCommonAttr (S, D, Attr); break; case AttributeList::AT_CUDAConstant:handleConstantAttr (S, D, Attr); break; case AttributeList::AT_Constructor: handleConstructorAttr (S, D, Attr); break; |