diff options
author | Chris Lattner <sabre@nondot.org> | 2011-02-24 05:42:24 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-02-24 05:42:24 +0000 |
commit | 951bbb2a6d9641ea11a6fe81cba429152a055b7c (patch) | |
tree | 41ec89544f983bab6b872823c0bdcae566f5623e /lib/Sema/SemaDeclAttr.cpp | |
parent | f226d18f0f49394cec460699f4268e32bd0ce833 (diff) |
rework processing of unavailable and deprecated attributes to avoid
unneeded allocation of an empty StringLiteral when these don't have
a message.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126364 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclAttr.cpp')
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index cbc940f2f0..bef1bb451f 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -1014,54 +1014,48 @@ static void HandleDestructorAttr(Decl *d, const AttributeList &Attr, Sema &S) { } static void HandleDeprecatedAttr(Decl *d, const AttributeList &Attr, Sema &S) { - // check the attribute arguments. - int noArgs = Attr.getNumArgs(); - if (noArgs > 1) { + unsigned NumArgs = Attr.getNumArgs(); + if (NumArgs > 1) { S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << "0 or 1"; return; } + // Handle the case where deprecated attribute has a text message. - StringLiteral *SE; - if (noArgs == 1) { - Expr *ArgExpr = Attr.getArg(0); - SE = dyn_cast<StringLiteral>(ArgExpr); + llvm::StringRef Str; + if (NumArgs == 1) { + StringLiteral *SE = dyn_cast<StringLiteral>(Attr.getArg(0)); if (!SE) { - S.Diag(ArgExpr->getLocStart(), - diag::err_attribute_not_string) << "deprecated"; + S.Diag(Attr.getArg(0)->getLocStart(), diag::err_attribute_not_string) + << "deprecated"; return; } + Str = SE->getString(); } - else - SE = StringLiteral::CreateEmpty(S.Context, 1); - d->addAttr(::new (S.Context) DeprecatedAttr(Attr.getLoc(), S.Context, - SE->getString())); + d->addAttr(::new (S.Context) DeprecatedAttr(Attr.getLoc(), S.Context, Str)); } static void HandleUnavailableAttr(Decl *d, const AttributeList &Attr, Sema &S) { - // check the attribute arguments. - int noArgs = Attr.getNumArgs(); - if (noArgs > 1) { + unsigned NumArgs = Attr.getNumArgs(); + if (NumArgs > 1) { S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << "0 or 1"; return; } + // Handle the case where unavailable attribute has a text message. - StringLiteral *SE; - if (noArgs == 1) { - Expr *ArgExpr = Attr.getArg(0); - SE = dyn_cast<StringLiteral>(ArgExpr); + llvm::StringRef Str; + if (NumArgs == 1) { + StringLiteral *SE = dyn_cast<StringLiteral>(Attr.getArg(0)); if (!SE) { - S.Diag(ArgExpr->getLocStart(), + S.Diag(Attr.getArg(0)->getLocStart(), diag::err_attribute_not_string) << "unavailable"; return; } + Str = SE->getString(); } - else - SE = StringLiteral::CreateEmpty(S.Context, 1); - d->addAttr(::new (S.Context) UnavailableAttr(Attr.getLoc(), S.Context, - SE->getString())); + d->addAttr(::new (S.Context) UnavailableAttr(Attr.getLoc(), S.Context, Str)); } static void HandleVisibilityAttr(Decl *d, const AttributeList &Attr, Sema &S) { |