Switching the CallableWhen attribute over to using the string literal helper function instead of custom logic.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192050 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 41cc3fd..1985de4 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -1059,25 +1059,19 @@
for (unsigned ArgIndex = 0; ArgIndex < Attr.getNumArgs(); ++ArgIndex) {
CallableWhenAttr::ConsumedState CallableState;
- if (Attr.isArgExpr(ArgIndex) &&
- isa<StringLiteral>(Attr.getArgAsExpr(ArgIndex))) {
-
- Expr *Arg = Attr.getArgAsExpr(ArgIndex);
- StringRef StateString = cast<StringLiteral>(Arg)->getString();
-
- if (!CallableWhenAttr::ConvertStrToConsumedState(StateString,
- CallableState)) {
- S.Diag(Arg->getExprLoc(), diag::warn_attribute_type_not_supported)
- << Attr.getName() << StateString;
- return;
- }
-
- States.push_back(CallableState);
- } else {
- S.Diag(Attr.getLoc(), diag::err_attribute_argument_type) << Attr.getName()
- << AANT_ArgumentString;
+ StringRef StateString;
+ SourceLocation Loc;
+ if (!S.checkStringLiteralArgumentAttr(Attr, ArgIndex, StateString, &Loc))
+ return;
+
+ if (!CallableWhenAttr::ConvertStrToConsumedState(StateString,
+ CallableState)) {
+ S.Diag(Loc, diag::warn_attribute_type_not_supported)
+ << Attr.getName() << StateString;
return;
}
+
+ States.push_back(CallableState);
}
D->addAttr(::new (S.Context)