[cfe-commits] r126364 - /cfe/trunk/lib/Sema/SemaDeclAttr.cpp
Chris Lattner
sabre at nondot.org
Wed Feb 23 21:42:24 PST 2011
Author: lattner
Date: Wed Feb 23 23:42:24 2011
New Revision: 126364
URL: http://llvm.org/viewvc/llvm-project?rev=126364&view=rev
Log:
rework processing of unavailable and deprecated attributes to avoid
unneeded allocation of an empty StringLiteral when these don't have
a message.
Modified:
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=126364&r1=126363&r2=126364&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Feb 23 23:42:24 2011
@@ -1014,54 +1014,48 @@
}
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) {
More information about the cfe-commits
mailing list