From c77fbd026ece7e944df22f7243cc26f619b174db Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Fri, 19 Dec 2014 16:42:04 +0000 Subject: [PATCH] Attributes accepting an EnumArgument are allowed to pass a string literal, or an identifier. VariadicEnumArguments now behave consistently instead of only accepting a string literal. This change affects the only attribute accepting a variadic enumeration: callable_when. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224582 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclAttr.cpp | 10 ++++++++-- test/SemaCXX/warn-consumed-parsing.cpp | 1 + utils/TableGen/ClangAttrEmitter.cpp | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 6248f6c78b..f1f369401c 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -863,8 +863,14 @@ static void handleCallableWhenAttr(Sema &S, Decl *D, StringRef StateString; SourceLocation Loc; - if (!S.checkStringLiteralArgumentAttr(Attr, ArgIndex, StateString, &Loc)) - return; + if (Attr.isArgIdent(ArgIndex)) { + IdentifierLoc *Ident = Attr.getArgAsIdent(ArgIndex); + StateString = Ident->Ident->getName(); + Loc = Ident->Loc; + } else { + if (!S.checkStringLiteralArgumentAttr(Attr, ArgIndex, StateString, &Loc)) + return; + } if (!CallableWhenAttr::ConvertStrToConsumedState(StateString, CallableState)) { diff --git a/test/SemaCXX/warn-consumed-parsing.cpp b/test/SemaCXX/warn-consumed-parsing.cpp index 5c0a04fffe..179604141b 100644 --- a/test/SemaCXX/warn-consumed-parsing.cpp +++ b/test/SemaCXX/warn-consumed-parsing.cpp @@ -37,6 +37,7 @@ class CONSUMABLE(unknown) AttrTester1 { void callableWhen0() CALLABLE_WHEN("unconsumed"); void callableWhen1() CALLABLE_WHEN(42); // expected-error {{'callable_when' attribute requires a string}} void callableWhen2() CALLABLE_WHEN("foo"); // expected-warning {{'callable_when' attribute argument not supported: foo}} + void callableWhen3() CALLABLE_WHEN(unconsumed); void consumes() SET_TYPESTATE(consumed); bool testUnconsumed() TEST_TYPESTATE(consumed); }; diff --git a/utils/TableGen/ClangAttrEmitter.cpp b/utils/TableGen/ClangAttrEmitter.cpp index 67f9452ba6..4103a39e70 100644 --- a/utils/TableGen/ClangAttrEmitter.cpp +++ b/utils/TableGen/ClangAttrEmitter.cpp @@ -1387,6 +1387,7 @@ static bool isIdentifierArgument(Record *Arg) { llvm::StringSwitch(Arg->getSuperClasses().back()->getName()) .Case("IdentifierArgument", true) .Case("EnumArgument", true) + .Case("VariadicEnumArgument", true) .Default(false); } -- 2.40.0