forked from OSchip/llvm-project
Move checkStringLiteralArgument into Sema class
It's a useful function to have around for target-specific attributes. llvm-svn: 191768
This commit is contained in:
parent
2896d044bd
commit
6a6b63b464
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
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<VarDecl>(D) || !cast<VarDecl>(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
|
||||
|
|
Loading…
Reference in New Issue