From 6a6b63b464e55ff2bd124fca468a8a800b6cd8cd Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Tue, 1 Oct 2013 14:34:18 +0000 Subject: [PATCH] Move checkStringLiteralArgument into Sema class It's a useful function to have around for target-specific attributes. llvm-svn: 191768 --- clang/include/clang/Sema/Sema.h | 4 ++++ clang/lib/Sema/SemaDeclAttr.cpp | 31 +++++++++++++++---------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index d9af5b6d78c0..a7df4365b5ba 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -2543,6 +2543,10 @@ public: bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC, const FunctionDecl *FD = 0); bool CheckNoReturnAttr(const AttributeList &attr); + bool checkStringLiteralArgumentAttr(const AttributeList &Attr, + unsigned ArgNum, StringRef &Str, + SourceLocation *ArgLocation = 0); + void CheckAlignasUnderalignment(Decl *D); /// Adjust the calling convention of a method to be the ABI default if it diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 3d46f87faa5c..950c8df268cf 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -287,17 +287,16 @@ static bool checkFunctionOrMethodArgumentIndex(Sema &S, const Decl *D, /// If not emit an error and return false. If the argument is an identifier it /// will emit an error with a fixit hint and treat it as if it was a string /// literal. -static bool checkStringLiteralArgument(Sema &S, StringRef &Str, - const AttributeList &Attr, - unsigned ArgNum, - SourceLocation *ArgLocation = 0) { +bool Sema::checkStringLiteralArgumentAttr(const AttributeList &Attr, + unsigned ArgNum, StringRef &Str, + SourceLocation *ArgLocation = 0) { // Look for identifiers. If we have one emit a hint to fix it to a literal. if (Attr.isArgIdent(ArgNum)) { IdentifierLoc *Loc = Attr.getArgAsIdent(ArgNum); - S.Diag(Loc->Loc, diag::err_attribute_argument_type) + Diag(Loc->Loc, diag::err_attribute_argument_type) << Attr.getName() << AANT_ArgumentString << FixItHint::CreateInsertion(Loc->Loc, "\"") - << FixItHint::CreateInsertion(S.PP.getLocForEndOfToken(Loc->Loc), "\""); + << FixItHint::CreateInsertion(PP.getLocForEndOfToken(Loc->Loc), "\""); Str = Loc->Ident->getName(); if (ArgLocation) *ArgLocation = Loc->Loc; @@ -311,7 +310,7 @@ static bool checkStringLiteralArgument(Sema &S, StringRef &Str, *ArgLocation = ArgExpr->getLocStart(); if (!Literal || !Literal->isAscii()) { - S.Diag(ArgExpr->getLocStart(), diag::err_attribute_argument_type) + Diag(ArgExpr->getLocStart(), diag::err_attribute_argument_type) << Attr.getName() << AANT_ArgumentString; return false; } @@ -1564,7 +1563,7 @@ static void handleWeakRefAttr(Sema &S, Decl *D, const AttributeList &Attr) { // of transforming it into an AliasAttr. The WeakRefAttr never uses the // StringRef parameter it was given anyway. StringRef Str; - if (Attr.getNumArgs() && checkStringLiteralArgument(S, Str, Attr, 0)) + if (Attr.getNumArgs() && S.checkStringLiteralArgumentAttr(Attr, 0, Str)) // GCC will accept anything as the argument of weakref. Should we // check for an existing decl? D->addAttr(::new (S.Context) AliasAttr(Attr.getRange(), S.Context, Str, @@ -1577,7 +1576,7 @@ static void handleWeakRefAttr(Sema &S, Decl *D, const AttributeList &Attr) { static void handleAliasAttr(Sema &S, Decl *D, const AttributeList &Attr) { StringRef Str; - if (!checkStringLiteralArgument(S, Str, Attr, 0)) + if (!S.checkStringLiteralArgumentAttr(Attr, 0, Str)) return; if (S.Context.getTargetInfo().getTriple().isOSDarwin()) { @@ -1667,7 +1666,7 @@ static void handleTLSModelAttr(Sema &S, Decl *D, StringRef Model; SourceLocation LiteralLoc; // Check that it is a string. - if (!checkStringLiteralArgument(S, Model, Attr, 0, &LiteralLoc)) + if (!S.checkStringLiteralArgumentAttr(Attr, 0, Model, &LiteralLoc)) return; if (!isa(D) || !cast(D)->getTLSKind()) { @@ -1999,7 +1998,7 @@ static void handleAttrWithMessage(Sema &S, Decl *D, // Handle the case where the attribute has a text message. StringRef Str; - if (NumArgs == 1 && !checkStringLiteralArgument(S, Str, Attr, 0)) + if (NumArgs == 1 && !S.checkStringLiteralArgumentAttr(Attr, 0, Str)) return; D->addAttr(::new (S.Context) AttrTy(Attr.getRange(), S.Context, Str, @@ -2310,7 +2309,7 @@ static void handleVisibilityAttr(Sema &S, Decl *D, const AttributeList &Attr, // Check that the argument is a string literal. StringRef TypeStr; SourceLocation LiteralLoc; - if (!checkStringLiteralArgument(S, TypeStr, Attr, 0, &LiteralLoc)) + if (!S.checkStringLiteralArgumentAttr(Attr, 0, TypeStr, &LiteralLoc)) return; VisibilityAttr::VisibilityType type; @@ -2724,7 +2723,7 @@ static void handleSectionAttr(Sema &S, Decl *D, const AttributeList &Attr) { // argument. StringRef Str; SourceLocation LiteralLoc; - if (!checkStringLiteralArgument(S, Str, Attr, 0, &LiteralLoc)) + if (!S.checkStringLiteralArgumentAttr(Attr, 0, Str, &LiteralLoc)) return; // If the target wants to validate the section specifier, make it happen. @@ -3195,7 +3194,7 @@ static void handleAnnotateAttr(Sema &S, Decl *D, const AttributeList &Attr) { // Make sure that there is a string literal as the annotation's single // argument. StringRef Str; - if (!checkStringLiteralArgument(S, Str, Attr, 0)) + if (!S.checkStringLiteralArgumentAttr(Attr, 0, Str)) return; // Don't duplicate annotations that are already set. @@ -3793,7 +3792,7 @@ bool Sema::CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC, break; case AttributeList::AT_Pcs: { StringRef StrRef; - if (!checkStringLiteralArgument(*this, StrRef, attr, 0)) { + if (!checkStringLiteralArgumentAttr(attr, 0, StrRef)) { attr.setInvalid(); return true; } @@ -4353,7 +4352,7 @@ static void handleUuidAttr(Sema &S, Decl *D, const AttributeList &Attr) { StringRef StrRef; SourceLocation LiteralLoc; - if (!checkStringLiteralArgument(S, StrRef, Attr, 0, &LiteralLoc)) + if (!S.checkStringLiteralArgumentAttr(Attr, 0, StrRef, &LiteralLoc)) return; // GUID format is "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" or