From: Aaron Ballman Date: Fri, 13 Sep 2013 17:48:25 +0000 (+0000) Subject: Updated the PCS calling convention to use the new checkStringLiteralArgument helper... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fbf6f5c8ac0a3feb9a5add5f9221a21f68ca487a;p=clang Updated the PCS calling convention to use the new checkStringLiteralArgument helper function. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190710 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 8530c8bd15..ceb4a3649b 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -3869,18 +3869,11 @@ bool Sema::CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC, CC_C; break; case AttributeList::AT_Pcs: { - StringLiteral *Str = 0; - if (attr.isArgExpr(0)) - Str = dyn_cast(attr.getArgAsExpr(0)); - - if (!Str || !Str->isAscii()) { - Diag(attr.getLoc(), diag::err_attribute_argument_type) << attr.getName() - << AANT_ArgumentString; + StringRef StrRef; + if (!checkStringLiteralArgument(*this, StrRef, attr, 0)) { attr.setInvalid(); return true; } - - StringRef StrRef = Str->getString(); if (StrRef == "aapcs") { CC = CC_AAPCS; break; diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 7abc36afb4..d0da7b752a 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -4371,9 +4371,15 @@ static AttributedType::Kind getCCTypeAttrKind(AttributeList &Attr) { case AttributeList::AT_Pascal: return AttributedType::attr_pascal; case AttributeList::AT_Pcs: { - // We know attr is valid so it can only have one of two strings args. - StringLiteral *Str = cast(Attr.getArgAsExpr(0)); - return llvm::StringSwitch(Str->getString()) + // The attribute may have had a fixit applied where we treated an + // identifier as a string literal. The contents of the string are valid, + // but the form may not be. + StringRef Str; + if (Attr.isArgExpr(0)) + Str = cast(Attr.getArgAsExpr(0))->getString(); + else + Str = Attr.getArgAsIdent(0)->Ident->getName(); + return llvm::StringSwitch(Str) .Case("aapcs", AttributedType::attr_pcs) .Case("aapcs-vfp", AttributedType::attr_pcs_vfp); } diff --git a/test/Sema/callingconv.c b/test/Sema/callingconv.c index 3234609d68..5badc14a01 100644 --- a/test/Sema/callingconv.c +++ b/test/Sema/callingconv.c @@ -38,7 +38,8 @@ Handler H = foo; int __attribute__((pcs("aapcs", "aapcs"))) pcs1(void); // expected-error {{'pcs' attribute takes one argument}} int __attribute__((pcs())) pcs2(void); // expected-error {{'pcs' attribute takes one argument}} -int __attribute__((pcs(pcs1))) pcs3(void); // expected-error {{'pcs' attribute requires a string}} +int __attribute__((pcs(pcs1))) pcs3(void); // expected-error {{'pcs' attribute requires a string}} \ + // expected-error {{invalid PCS type}} int __attribute__((pcs(0))) pcs4(void); // expected-error {{'pcs' attribute requires a string}} /* These are ignored because the target is i386 and not ARM */ int __attribute__((pcs("aapcs"))) pcs5(void); // expected-warning {{calling convention 'pcs' ignored for this target}}