r339344 - Implement diagnostic stream operator for ParsedAttr.
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 9 06:21:32 PDT 2018
Author: erichkeane
Date: Thu Aug 9 06:21:32 2018
New Revision: 339344
URL: http://llvm.org/viewvc/llvm-project?rev=339344&view=rev
Log:
Implement diagnostic stream operator for ParsedAttr.
As a part of attempting to clean up the way attributes are
printed, this patch adds an operator << to the diagnostics/
partialdiagnostics so that ParsedAttr can be sent directly.
This patch also rewrites a large amount* of the times when
ParsedAttr was printed using its IdentifierInfo object instead
of being printed itself.
*"a large amount" == "All I could find".
Modified:
cfe/trunk/include/clang/Sema/ParsedAttr.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaStmtAttr.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
Modified: cfe/trunk/include/clang/Sema/ParsedAttr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ParsedAttr.h?rev=339344&r1=339343&r2=339344&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/ParsedAttr.h (original)
+++ cfe/trunk/include/clang/Sema/ParsedAttr.h Thu Aug 9 06:21:32 2018
@@ -16,6 +16,7 @@
#define LLVM_CLANG_SEMA_ATTRIBUTELIST_H
#include "clang/Basic/AttrSubjectMatchRules.h"
+#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Sema/Ownership.h"
@@ -939,6 +940,34 @@ enum AttributeDeclKind {
ExpectedFunctionWithProtoType,
};
+inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
+ const ParsedAttr &At) {
+ DB.AddTaggedVal(reinterpret_cast<intptr_t>(At.getName()),
+ DiagnosticsEngine::ak_identifierinfo);
+ return DB;
+}
+
+inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
+ const ParsedAttr &At) {
+ PD.AddTaggedVal(reinterpret_cast<intptr_t>(At.getName()),
+ DiagnosticsEngine::ak_identifierinfo);
+ return PD;
+}
+
+inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
+ const ParsedAttr *At) {
+ DB.AddTaggedVal(reinterpret_cast<intptr_t>(At->getName()),
+ DiagnosticsEngine::ak_identifierinfo);
+ return DB;
+}
+
+inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
+ const ParsedAttr *At) {
+ PD.AddTaggedVal(reinterpret_cast<intptr_t>(At->getName()),
+ DiagnosticsEngine::ak_identifierinfo);
+ return PD;
+}
+
} // namespace clang
#endif // LLVM_CLANG_SEMA_ATTRIBUTELIST_H
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=339344&r1=339343&r2=339344&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Aug 9 06:21:32 2018
@@ -2456,11 +2456,11 @@ public:
unsigned AttrSpellingListIndex);
OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, SourceRange Range,
unsigned AttrSpellingListIndex);
- InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, SourceRange Range,
- IdentifierInfo *Ident,
- unsigned AttrSpellingListIndex);
- CommonAttr *mergeCommonAttr(Decl *D, SourceRange Range, IdentifierInfo *Ident,
- unsigned AttrSpellingListIndex);
+ InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, const ParsedAttr &AL);
+ InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D,
+ const InternalLinkageAttr &AL);
+ CommonAttr *mergeCommonAttr(Decl *D, const ParsedAttr &AL);
+ CommonAttr *mergeCommonAttr(Decl *D, const CommonAttr &AL);
void mergeDeclAttributes(NamedDecl *New, Decl *Old,
AvailabilityMergeKind AMK = AMK_Redeclaration);
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=339344&r1=339343&r2=339344&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Aug 9 06:21:32 2018
@@ -2474,14 +2474,9 @@ static bool mergeDeclAttribute(Sema &S,
else if (const auto *OA = dyn_cast<OptimizeNoneAttr>(Attr))
NewAttr = S.mergeOptimizeNoneAttr(D, OA->getRange(), AttrSpellingListIndex);
else if (const auto *InternalLinkageA = dyn_cast<InternalLinkageAttr>(Attr))
- NewAttr = S.mergeInternalLinkageAttr(
- D, InternalLinkageA->getRange(),
- &S.Context.Idents.get(InternalLinkageA->getSpelling()),
- AttrSpellingListIndex);
+ NewAttr = S.mergeInternalLinkageAttr(D, *InternalLinkageA);
else if (const auto *CommonA = dyn_cast<CommonAttr>(Attr))
- NewAttr = S.mergeCommonAttr(D, CommonA->getRange(),
- &S.Context.Idents.get(CommonA->getSpelling()),
- AttrSpellingListIndex);
+ NewAttr = S.mergeCommonAttr(D, *CommonA);
else if (isa<AlignedAttr>(Attr))
// AlignedAttrs are handled separately, because we need to handle all
// such attributes on a declaration at the same time.
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=339344&r1=339343&r2=339344&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Aug 9 06:21:32 2018
@@ -182,7 +182,7 @@ static bool checkAttributeNumArgsImpl(Se
unsigned Num, unsigned Diag,
Compare Comp) {
if (Comp(getNumAttributeArgs(AL), Num)) {
- S.Diag(AL.getLoc(), Diag) << AL.getName() << Num;
+ S.Diag(AL.getLoc(), Diag) << AL << Num;
return false;
}
@@ -225,18 +225,6 @@ getAttrLoc(const AttrInfo &AL) {
}
static SourceLocation getAttrLoc(const ParsedAttr &AL) { return AL.getLoc(); }
-/// A helper function to provide Attribute Name for the Attr types
-/// AND the ParsedAttr.
-template <typename AttrInfo>
-static typename std::enable_if<std::is_base_of<Attr, AttrInfo>::value,
- const AttrInfo *>::type
-getAttrName(const AttrInfo &AL) {
- return &AL;
-}
-static const IdentifierInfo *getAttrName(const ParsedAttr &AL) {
- return AL.getName();
-}
-
/// If Expr is a valid integer constant, get the value of the integer
/// expression and return success or failure. May output an error.
template <typename AttrInfo>
@@ -247,12 +235,11 @@ static bool checkUInt32Argument(Sema &S,
!Expr->isIntegerConstantExpr(I, S.Context)) {
if (Idx != UINT_MAX)
S.Diag(getAttrLoc(AI), diag::err_attribute_argument_n_type)
- << getAttrName(AI) << Idx << AANT_ArgumentIntegerConstant
- << Expr->getSourceRange();
+ << AI << Idx << AANT_ArgumentIntegerConstant
+ << Expr->getSourceRange();
else
S.Diag(getAttrLoc(AI), diag::err_attribute_argument_type)
- << getAttrName(AI) << AANT_ArgumentIntegerConstant
- << Expr->getSourceRange();
+ << AI << AANT_ArgumentIntegerConstant << Expr->getSourceRange();
return false;
}
@@ -291,10 +278,19 @@ static bool checkPositiveIntArgument(Sem
/// Diagnose mutually exclusive attributes when present on a given
/// declaration. Returns true if diagnosed.
template <typename AttrTy>
-static bool checkAttrMutualExclusion(Sema &S, Decl *D, SourceRange Range,
- IdentifierInfo *Ident) {
+static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
+ if (const auto *A = D->getAttr<AttrTy>()) {
+ S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
+ S.Diag(A->getLocation(), diag::note_conflicting_attribute);
+ return true;
+ }
+ return false;
+}
+
+template <typename AttrTy>
+static bool checkAttrMutualExclusion(Sema &S, Decl *D, const Attr &AL) {
if (const auto *A = D->getAttr<AttrTy>()) {
- S.Diag(Range.getBegin(), diag::err_attributes_are_not_compatible) << Ident
+ S.Diag(AL.getLocation(), diag::err_attributes_are_not_compatible) << &AL
<< A;
S.Diag(A->getLocation(), diag::note_conflicting_attribute);
return true;
@@ -324,22 +320,21 @@ static bool checkFunctionOrMethodParamet
if (IdxExpr->isTypeDependent() || IdxExpr->isValueDependent() ||
!IdxExpr->isIntegerConstantExpr(IdxInt, S.Context)) {
S.Diag(getAttrLoc(AI), diag::err_attribute_argument_n_type)
- << getAttrName(AI) << AttrArgNum << AANT_ArgumentIntegerConstant
- << IdxExpr->getSourceRange();
+ << &AI << AttrArgNum << AANT_ArgumentIntegerConstant
+ << IdxExpr->getSourceRange();
return false;
}
unsigned IdxSource = IdxInt.getLimitedValue(UINT_MAX);
if (IdxSource < 1 || (!IV && IdxSource > NumParams)) {
S.Diag(getAttrLoc(AI), diag::err_attribute_argument_out_of_bounds)
- << getAttrName(AI) << AttrArgNum << IdxExpr->getSourceRange();
+ << &AI << AttrArgNum << IdxExpr->getSourceRange();
return false;
}
if (HasImplicitThisParam && !CanIndexImplicitThis) {
if (IdxSource == 1) {
- S.Diag(getAttrLoc(AI),
- diag::err_attribute_invalid_implicit_this_argument)
- << getAttrName(AI) << IdxExpr->getSourceRange();
+ S.Diag(getAttrLoc(AI), diag::err_attribute_invalid_implicit_this_argument)
+ << &AI << IdxExpr->getSourceRange();
return false;
}
}
@@ -359,7 +354,7 @@ bool Sema::checkStringLiteralArgumentAtt
if (AL.isArgIdent(ArgNum)) {
IdentifierLoc *Loc = AL.getArgAsIdent(ArgNum);
Diag(Loc->Loc, diag::err_attribute_argument_type)
- << AL.getName() << AANT_ArgumentString
+ << AL << AANT_ArgumentString
<< FixItHint::CreateInsertion(Loc->Loc, "\"")
<< FixItHint::CreateInsertion(getLocForEndOfToken(Loc->Loc), "\"");
Str = Loc->Ident->getName();
@@ -376,7 +371,7 @@ bool Sema::checkStringLiteralArgumentAtt
if (!Literal || !Literal->isAscii()) {
Diag(ArgExpr->getLocStart(), diag::err_attribute_argument_type)
- << AL.getName() << AANT_ArgumentString;
+ << AL << AANT_ArgumentString;
return false;
}
@@ -404,8 +399,7 @@ template <typename AttrType, typename In
typename... IncompatibleAttrTypes>
static void handleSimpleAttributeWithExclusions(Sema &S, Decl *D,
const ParsedAttr &AL) {
- if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL.getRange(),
- AL.getName()))
+ if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
return;
handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
AL);
@@ -455,8 +449,7 @@ static bool threadSafetyCheckIsPointer(S
return true;
}
- S.Diag(AL.getLoc(), diag::warn_thread_attribute_decl_not_pointer)
- << AL.getName() << QT;
+ S.Diag(AL.getLoc(), diag::warn_thread_attribute_decl_not_pointer) << AL << QT;
return false;
}
@@ -582,7 +575,7 @@ static void checkAttrArgsAreCapabilityOb
// We allow constant strings to be used as a placeholder for expressions
// that are not valid C++ syntax, but warn that they are ignored.
- S.Diag(AL.getLoc(), diag::warn_thread_attribute_ignored) << AL.getName();
+ S.Diag(AL.getLoc(), diag::warn_thread_attribute_ignored) << AL;
Args.push_back(ArgExp);
continue;
}
@@ -611,7 +604,7 @@ static void checkAttrArgsAreCapabilityOb
uint64_t ParamIdxFromZero = ParamIdxFromOne - 1;
if (!ArgValue.isStrictlyPositive() || ParamIdxFromOne > NumParams) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_range)
- << AL.getName() << Idx + 1 << NumParams;
+ << AL << Idx + 1 << NumParams;
continue;
}
ArgTy = FD->getParamDecl(ParamIdxFromZero)->getType();
@@ -624,7 +617,7 @@ static void checkAttrArgsAreCapabilityOb
// boolean logic expression. Eg) requires_capability(A || B && !C)
if (!typeHasCapability(S, ArgTy) && !isCapabilityExpr(S, ArgExp))
S.Diag(AL.getLoc(), diag::warn_thread_attribute_argument_not_lockable)
- << AL.getName() << ArgTy;
+ << AL << ArgTy;
Args.push_back(ArgExp);
}
@@ -686,8 +679,7 @@ static bool checkAcquireOrderAttrCommon(
// Check that this attribute only applies to lockable types.
QualType QT = cast<ValueDecl>(D)->getType();
if (!QT->isDependentType() && !typeHasCapability(S, QT)) {
- S.Diag(AL.getLoc(), diag::warn_thread_attribute_decl_not_lockable)
- << AL.getName();
+ S.Diag(AL.getLoc(), diag::warn_thread_attribute_decl_not_lockable) << AL;
return false;
}
@@ -774,7 +766,7 @@ static bool checkParamIsIntegerType(Sema
if (!Param->getType()->isIntegerType() && !Param->getType()->isCharType()) {
SourceLocation SrcLoc = AttrArg->getLocStart();
S.Diag(SrcLoc, diag::err_attribute_integers_only)
- << getAttrName(AI) << Param->getSourceRange();
+ << AI << Param->getSourceRange();
return false;
}
return true;
@@ -787,8 +779,7 @@ static void handleAllocSizeAttr(Sema &S,
const auto *FD = cast<FunctionDecl>(D);
if (!FD->getReturnType()->isPointerType()) {
- S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only)
- << AL.getName();
+ S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only) << AL;
return;
}
@@ -825,7 +816,7 @@ static bool checkTryLockFunAttrCommon(Se
if (!isIntOrBool(AL.getArgAsExpr(0))) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
- << AL.getName() << 1 << AANT_ArgumentIntOrBool;
+ << AL << 1 << AANT_ArgumentIntOrBool;
return false;
}
@@ -907,8 +898,7 @@ static bool checkFunctionConditionAttr(S
if (isa<FunctionDecl>(D) && !Cond->isValueDependent() &&
!Expr::isPotentialConstantExprUnevaluated(Cond, cast<FunctionDecl>(D),
Diags)) {
- S.Diag(AL.getLoc(), diag::err_attr_cond_never_constant_expr)
- << AL.getName();
+ S.Diag(AL.getLoc(), diag::err_attr_cond_never_constant_expr) << AL;
for (const PartialDiagnosticAt &PDiag : Diags)
S.Diag(PDiag.first, PDiag.second);
return false;
@@ -1002,8 +992,7 @@ static void handleDiagnoseIfAttr(Sema &S
static void handlePassObjectSizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
if (D->hasAttr<PassObjectSizeAttr>()) {
- S.Diag(D->getLocStart(), diag::err_attribute_only_once_per_parameter)
- << AL.getName();
+ S.Diag(D->getLocStart(), diag::err_attribute_only_once_per_parameter) << AL;
return;
}
@@ -1017,7 +1006,7 @@ static void handlePassObjectSizeAttr(Sem
// argument; namely, it must be in the range [0, 3].
if (Type > 3) {
S.Diag(E->getLocStart(), diag::err_attribute_argument_outof_range)
- << AL.getName() << 0 << 3 << E->getSourceRange();
+ << AL << 0 << 3 << E->getSourceRange();
return;
}
@@ -1026,8 +1015,7 @@ static void handlePassObjectSizeAttr(Sem
// At this point, we have no clue if `D` belongs to a function declaration or
// definition, so we defer the constness check until later.
if (!cast<ParmVarDecl>(D)->getType()->isPointerType()) {
- S.Diag(D->getLocStart(), diag::err_attribute_pointers_only)
- << AL.getName() << 1;
+ S.Diag(D->getLocStart(), diag::err_attribute_pointers_only) << AL << 1;
return;
}
@@ -1042,13 +1030,13 @@ static void handleConsumableAttr(Sema &S
IdentifierLoc *IL = AL.getArgAsIdent(0);
if (!ConsumableAttr::ConvertStrToConsumedState(IL->Ident->getName(),
DefaultState)) {
- S.Diag(IL->Loc, diag::warn_attribute_type_not_supported)
- << AL.getName() << IL->Ident;
+ S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL
+ << IL->Ident;
return;
}
} else {
S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
- << AL.getName() << AANT_ArgumentIdentifier;
+ << AL << AANT_ArgumentIdentifier;
return;
}
@@ -1098,8 +1086,7 @@ static void handleCallableWhenAttr(Sema
if (!CallableWhenAttr::ConvertStrToConsumedState(StateString,
CallableState)) {
- S.Diag(Loc, diag::warn_attribute_type_not_supported)
- << AL.getName() << StateString;
+ S.Diag(Loc, diag::warn_attribute_type_not_supported) << AL << StateString;
return;
}
@@ -1121,12 +1108,12 @@ static void handleParamTypestateAttr(Sem
if (!ParamTypestateAttr::ConvertStrToConsumedState(StateString,
ParamState)) {
S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported)
- << AL.getName() << StateString;
+ << AL << StateString;
return;
}
} else {
- S.Diag(AL.getLoc(), diag::err_attribute_argument_type) <<
- AL.getName() << AANT_ArgumentIdentifier;
+ S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+ << AL << AANT_ArgumentIdentifier;
return;
}
@@ -1154,13 +1141,13 @@ static void handleReturnTypestateAttr(Se
IdentifierLoc *IL = AL.getArgAsIdent(0);
if (!ReturnTypestateAttr::ConvertStrToConsumedState(IL->Ident->getName(),
ReturnState)) {
- S.Diag(IL->Loc, diag::warn_attribute_type_not_supported)
- << AL.getName() << IL->Ident;
+ S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL
+ << IL->Ident;
return;
}
} else {
- S.Diag(AL.getLoc(), diag::err_attribute_argument_type) <<
- AL.getName() << AANT_ArgumentIdentifier;
+ S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+ << AL << AANT_ArgumentIdentifier;
return;
}
@@ -1203,13 +1190,13 @@ static void handleSetTypestateAttr(Sema
IdentifierLoc *Ident = AL.getArgAsIdent(0);
StringRef Param = Ident->Ident->getName();
if (!SetTypestateAttr::ConvertStrToConsumedState(Param, NewState)) {
- S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported)
- << AL.getName() << Param;
+ S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL
+ << Param;
return;
}
} else {
- S.Diag(AL.getLoc(), diag::err_attribute_argument_type) <<
- AL.getName() << AANT_ArgumentIdentifier;
+ S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+ << AL << AANT_ArgumentIdentifier;
return;
}
@@ -1227,13 +1214,13 @@ static void handleTestTypestateAttr(Sema
IdentifierLoc *Ident = AL.getArgAsIdent(0);
StringRef Param = Ident->Ident->getName();
if (!TestTypestateAttr::ConvertStrToConsumedState(Param, TestState)) {
- S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported)
- << AL.getName() << Param;
+ S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL
+ << Param;
return;
}
} else {
- S.Diag(AL.getLoc(), diag::err_attribute_argument_type) <<
- AL.getName() << AANT_ArgumentIdentifier;
+ S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+ << AL << AANT_ArgumentIdentifier;
return;
}
@@ -1261,7 +1248,7 @@ static void handlePackedAttr(Sema &S, De
if (BitfieldByteAligned)
// The PS4 target needs to maintain ABI backwards compatibility.
S.Diag(AL.getLoc(), diag::warn_attribute_ignored_for_field_of_type)
- << AL.getName() << FD->getType();
+ << AL << FD->getType();
else
FD->addAttr(::new (S.Context) PackedAttr(
AL.getRange(), S.Context, AL.getAttributeSpellingListIndex()));
@@ -1275,7 +1262,7 @@ static void handlePackedAttr(Sema &S, De
}
} else
- S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL.getName();
+ S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL;
}
static bool checkIBOutletCommon(Sema &S, Decl *D, const ParsedAttr &AL) {
@@ -1285,19 +1272,19 @@ static bool checkIBOutletCommon(Sema &S,
if (const auto *VD = dyn_cast<ObjCIvarDecl>(D)) {
if (!VD->getType()->getAs<ObjCObjectPointerType>()) {
S.Diag(AL.getLoc(), diag::warn_iboutlet_object_type)
- << AL.getName() << VD->getType() << 0;
+ << AL << VD->getType() << 0;
return false;
}
}
else if (const auto *PD = dyn_cast<ObjCPropertyDecl>(D)) {
if (!PD->getType()->getAs<ObjCObjectPointerType>()) {
S.Diag(AL.getLoc(), diag::warn_iboutlet_object_type)
- << AL.getName() << PD->getType() << 1;
+ << AL << PD->getType() << 1;
return false;
}
}
else {
- S.Diag(AL.getLoc(), diag::warn_attribute_iboutlet) << AL.getName();
+ S.Diag(AL.getLoc(), diag::warn_attribute_iboutlet) << AL;
return false;
}
@@ -1317,8 +1304,7 @@ static void handleIBOutletCollection(Sem
// The iboutletcollection attribute can have zero or one arguments.
if (AL.getNumArgs() > 1) {
- S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments)
- << AL.getName() << 1;
+ S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
return;
}
@@ -1390,10 +1376,10 @@ static bool attrNonNullArgCheck(Sema &S,
if (!S.isValidPointerAttrType(T)) {
if (isReturnValue)
S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only)
- << AL.getName() << AttrParmRange << TypeRange;
+ << AL << AttrParmRange << TypeRange;
else
S.Diag(AL.getLoc(), diag::warn_attribute_pointers_only)
- << AL.getName() << AttrParmRange << TypeRange << 0;
+ << AL << AttrParmRange << TypeRange << 0;
return false;
}
return true;
@@ -1486,7 +1472,7 @@ static void handleNoEscapeAttr(Sema &S,
QualType T = cast<ParmVarDecl>(D)->getType();
if (!S.isValidPointerAttrType(T, /* RefOkay */ true)) {
S.Diag(AL.getLoc(), diag::warn_attribute_pointers_only)
- << AL.getName() << AL.getRange() << 0;
+ << AL << AL.getRange() << 0;
return;
}
@@ -1611,7 +1597,7 @@ static void handleOwnershipAttr(Sema &S,
if (!AL.isArgIdent(0)) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
- << AL.getName() << 1 << AANT_ArgumentIdentifier;
+ << AL << 1 << AANT_ArgumentIdentifier;
return;
}
@@ -1625,15 +1611,13 @@ static void handleOwnershipAttr(Sema &S,
case OwnershipAttr::Takes:
case OwnershipAttr::Holds:
if (AL.getNumArgs() < 2) {
- S.Diag(AL.getLoc(), diag::err_attribute_too_few_arguments)
- << AL.getName() << 2;
+ S.Diag(AL.getLoc(), diag::err_attribute_too_few_arguments) << AL << 2;
return;
}
break;
case OwnershipAttr::Returns:
if (AL.getNumArgs() > 2) {
- S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments)
- << AL.getName() << 1;
+ S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
return;
}
break;
@@ -1668,8 +1652,8 @@ static void handleOwnershipAttr(Sema &S,
break;
}
if (-1 != Err) {
- S.Diag(AL.getLoc(), diag::err_ownership_type) << AL.getName() << Err
- << Ex->getSourceRange();
+ S.Diag(AL.getLoc(), diag::err_ownership_type) << AL << Err
+ << Ex->getSourceRange();
return;
}
@@ -1679,8 +1663,7 @@ static void handleOwnershipAttr(Sema &S,
// index.
if (I->getOwnKind() != K && I->args_end() !=
std::find(I->args_begin(), I->args_end(), Idx)) {
- S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible)
- << AL.getName() << I;
+ S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << I;
return;
} else if (K == OwnershipAttr::Returns &&
I->getOwnKind() == OwnershipAttr::Returns) {
@@ -1710,8 +1693,7 @@ static void handleOwnershipAttr(Sema &S,
static void handleWeakRefAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
// Check the attribute arguments.
if (AL.getNumArgs() > 1) {
- S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments)
- << AL.getName() << 1;
+ S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
return;
}
@@ -1846,7 +1828,7 @@ static void handleRestrictAttr(Sema &S,
}
S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only)
- << AL.getName() << getFunctionOrMethodResultSourceRange(D);
+ << AL << getFunctionOrMethodResultSourceRange(D);
}
static void handleCPUSpecificAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
@@ -1858,7 +1840,7 @@ static void handleCPUSpecificAttr(Sema &
for (unsigned ArgNo = 0; ArgNo < getNumAttributeArgs(AL); ++ArgNo) {
if (!AL.isArgIdent(ArgNo)) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
- << AL.getName() << AANT_ArgumentIdentifier;
+ << AL << AANT_ArgumentIdentifier;
return;
}
@@ -1896,18 +1878,16 @@ static void handleCPUSpecificAttr(Sema &
static void handleCommonAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
if (S.LangOpts.CPlusPlus) {
S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang)
- << AL.getName() << AttributeLangSupport::Cpp;
+ << AL << AttributeLangSupport::Cpp;
return;
}
- if (CommonAttr *CA = S.mergeCommonAttr(D, AL.getRange(), AL.getName(),
- AL.getAttributeSpellingListIndex()))
+ if (CommonAttr *CA = S.mergeCommonAttr(D, AL))
D->addAttr(CA);
}
static void handleNakedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
- if (checkAttrMutualExclusion<DisableTailCallsAttr>(S, D, AL.getRange(),
- AL.getName()))
+ if (checkAttrMutualExclusion<DisableTailCallsAttr>(S, D, AL))
return;
if (AL.isDeclspecAttribute()) {
@@ -1916,7 +1896,7 @@ static void handleNakedAttr(Sema &S, Dec
if (Arch != llvm::Triple::x86 &&
(Arch != llvm::Triple::arm && Arch != llvm::Triple::thumb)) {
S.Diag(AL.getLoc(), diag::err_attribute_not_supported_on_arch)
- << AL.getName() << Triple.getArchName();
+ << AL << Triple.getArchName();
return;
}
}
@@ -1930,7 +1910,7 @@ static void handleNoReturnAttr(Sema &S,
if (!isa<ObjCMethodDecl>(D)) {
S.Diag(Attrs.getLoc(), diag::warn_attribute_wrong_decl_type)
- << Attrs.getName() << ExpectedFunctionOrMethod;
+ << Attrs << ExpectedFunctionOrMethod;
return;
}
@@ -1957,7 +1937,7 @@ bool Sema::CheckAttrNoArgs(const ParsedA
bool Sema::CheckAttrTarget(const ParsedAttr &AL) {
// Check whether the attribute is valid on the current target.
if (!AL.existsInTarget(Context.getTargetInfo())) {
- Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored) << AL.getName();
+ Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored) << AL;
AL.setInvalid();
return true;
}
@@ -1973,10 +1953,10 @@ static void handleAnalyzerNoReturnAttr(S
ValueDecl *VD = dyn_cast<ValueDecl>(D);
if (!VD || (!VD->getType()->isBlockPointerType() &&
!VD->getType()->isFunctionPointerType())) {
- S.Diag(AL.getLoc(),
- AL.isCXX11Attribute() ? diag::err_attribute_wrong_decl_type
- : diag::warn_attribute_wrong_decl_type)
- << AL.getName() << ExpectedFunctionMethodOrBlock;
+ S.Diag(AL.getLoc(), AL.isCXX11Attribute()
+ ? diag::err_attribute_wrong_decl_type
+ : diag::warn_attribute_wrong_decl_type)
+ << AL << ExpectedFunctionMethodOrBlock;
return;
}
}
@@ -2065,7 +2045,7 @@ static void handleUnusedAttr(Sema &S, De
// If this is spelled as the standard C++17 attribute, but not in C++17, warn
// about using it as an extension.
if (!S.getLangOpts().CPlusPlus17 && IsCXX17Attr)
- S.Diag(AL.getLoc(), diag::ext_cxx17_attr) << AL.getName();
+ S.Diag(AL.getLoc(), diag::ext_cxx17_attr) << AL;
D->addAttr(::new (S.Context) UnusedAttr(
AL.getRange(), S.Context, AL.getAttributeSpellingListIndex()));
@@ -2108,7 +2088,7 @@ static void handleObjCSuppresProtocolAtt
const ParsedAttr &AL) {
if (!cast<ObjCProtocolDecl>(D)->isThisDeclarationADefinition()) {
S.Diag(AL.getLoc(), diag::err_objc_attr_protocol_requires_definition)
- << AL.getName() << AL.getRange();
+ << AL << AL.getRange();
return;
}
@@ -2506,8 +2486,7 @@ static void handleVisibilityAttr(Sema &S
bool isTypeVisibility) {
// Visibility attributes don't mean anything on a typedef.
if (isa<TypedefNameDecl>(D)) {
- S.Diag(AL.getRange().getBegin(), diag::warn_attribute_ignored)
- << AL.getName();
+ S.Diag(AL.getRange().getBegin(), diag::warn_attribute_ignored) << AL;
return;
}
@@ -2517,7 +2496,7 @@ static void handleVisibilityAttr(Sema &S
isa<ObjCInterfaceDecl>(D) ||
isa<NamespaceDecl>(D))) {
S.Diag(AL.getRange().getBegin(), diag::err_attribute_wrong_decl_type)
- << AL.getName() << ExpectedTypeOrNamespace;
+ << AL << ExpectedTypeOrNamespace;
return;
}
@@ -2529,8 +2508,8 @@ static void handleVisibilityAttr(Sema &S
VisibilityAttr::VisibilityType type;
if (!VisibilityAttr::ConvertStrToVisibilityType(TypeStr, type)) {
- S.Diag(LiteralLoc, diag::warn_attribute_type_not_supported)
- << AL.getName() << TypeStr;
+ S.Diag(LiteralLoc, diag::warn_attribute_type_not_supported) << AL
+ << TypeStr;
return;
}
@@ -2559,15 +2538,14 @@ static void handleObjCMethodFamilyAttr(S
const auto *M = cast<ObjCMethodDecl>(D);
if (!AL.isArgIdent(0)) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
- << AL.getName() << 1 << AANT_ArgumentIdentifier;
+ << AL << 1 << AANT_ArgumentIdentifier;
return;
}
IdentifierLoc *IL = AL.getArgAsIdent(0);
ObjCMethodFamilyAttr::FamilyKind F;
if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind(IL->Ident->getName(), F)) {
- S.Diag(IL->Loc, diag::warn_attribute_type_not_supported)
- << AL.getName() << IL->Ident;
+ S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL << IL->Ident;
return;
}
@@ -2631,15 +2609,14 @@ static void handleObjCIndependentClass(S
static void handleBlocksAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
if (!AL.isArgIdent(0)) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
- << AL.getName() << 1 << AANT_ArgumentIdentifier;
+ << AL << 1 << AANT_ArgumentIdentifier;
return;
}
IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
BlocksAttr::BlockType type;
if (!BlocksAttr::ConvertStrToBlockType(II->getName(), type)) {
- S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported)
- << AL.getName() << II;
+ S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
return;
}
@@ -2656,8 +2633,7 @@ static void handleSentinelAttr(Sema &S,
if (E->isTypeDependent() || E->isValueDependent() ||
!E->isIntegerConstantExpr(Idx, S.Context)) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
- << AL.getName() << 1 << AANT_ArgumentIntegerConstant
- << E->getSourceRange();
+ << AL << 1 << AANT_ArgumentIntegerConstant << E->getSourceRange();
return;
}
@@ -2677,8 +2653,7 @@ static void handleSentinelAttr(Sema &S,
if (E->isTypeDependent() || E->isValueDependent() ||
!E->isIntegerConstantExpr(Idx, S.Context)) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
- << AL.getName() << 2 << AANT_ArgumentIntegerConstant
- << E->getSourceRange();
+ << AL << 2 << AANT_ArgumentIntegerConstant << E->getSourceRange();
return;
}
nullPos = Idx.getZExtValue();
@@ -2726,12 +2701,12 @@ static void handleSentinelAttr(Sema &S,
}
} else {
S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
- << AL.getName() << ExpectedFunctionMethodOrBlock;
+ << AL << ExpectedFunctionMethodOrBlock;
return;
}
} else {
S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
- << AL.getName() << ExpectedFunctionMethodOrBlock;
+ << AL << ExpectedFunctionMethodOrBlock;
return;
}
D->addAttr(::new (S.Context)
@@ -2742,14 +2717,12 @@ static void handleSentinelAttr(Sema &S,
static void handleWarnUnusedResult(Sema &S, Decl *D, const ParsedAttr &AL) {
if (D->getFunctionType() &&
D->getFunctionType()->getReturnType()->isVoidType()) {
- S.Diag(AL.getLoc(), diag::warn_attribute_void_function_method)
- << AL.getName() << 0;
+ S.Diag(AL.getLoc(), diag::warn_attribute_void_function_method) << AL << 0;
return;
}
if (const auto *MD = dyn_cast<ObjCMethodDecl>(D))
if (MD->getReturnType()->isVoidType()) {
- S.Diag(AL.getLoc(), diag::warn_attribute_void_function_method)
- << AL.getName() << 1;
+ S.Diag(AL.getLoc(), diag::warn_attribute_void_function_method) << AL << 1;
return;
}
@@ -2757,7 +2730,7 @@ static void handleWarnUnusedResult(Sema
// about using it as an extension.
if (!S.getLangOpts().CPlusPlus17 && AL.isCXX11Attribute() &&
!AL.getScopeName())
- S.Diag(AL.getLoc(), diag::ext_cxx17_attr) << AL.getName();
+ S.Diag(AL.getLoc(), diag::ext_cxx17_attr) << AL;
D->addAttr(::new (S.Context)
WarnUnusedResultAttr(AL.getRange(), S.Context,
@@ -2777,7 +2750,7 @@ static void handleWeakImportAttr(Sema &S
// Nothing to warn about here.
} else
S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
- << AL.getName() << ExpectedVariableOrFunction;
+ << AL << ExpectedVariableOrFunction;
return;
}
@@ -2797,7 +2770,7 @@ static void handleWorkGroupSize(Sema &S,
return;
if (WGSize[i] == 0) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero)
- << AL.getName() << E->getSourceRange();
+ << AL << E->getSourceRange();
return;
}
}
@@ -2806,7 +2779,7 @@ static void handleWorkGroupSize(Sema &S,
if (Existing && !(Existing->getXDim() == WGSize[0] &&
Existing->getYDim() == WGSize[1] &&
Existing->getZDim() == WGSize[2]))
- S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL.getName();
+ S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
D->addAttr(::new (S.Context) WorkGroupAttr(AL.getRange(), S.Context,
WGSize[0], WGSize[1], WGSize[2],
@@ -2821,14 +2794,14 @@ static void handleSubGroupSize(Sema &S,
return;
if (SGSize == 0) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero)
- << AL.getName() << E->getSourceRange();
+ << AL << E->getSourceRange();
return;
}
OpenCLIntelReqdSubGroupSizeAttr *Existing =
D->getAttr<OpenCLIntelReqdSubGroupSizeAttr>();
if (Existing && Existing->getSubGroupSize() != SGSize)
- S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL.getName();
+ S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
D->addAttr(::new (S.Context) OpenCLIntelReqdSubGroupSizeAttr(
AL.getRange(), S.Context, SGSize,
@@ -2837,8 +2810,7 @@ static void handleSubGroupSize(Sema &S,
static void handleVecTypeHint(Sema &S, Decl *D, const ParsedAttr &AL) {
if (!AL.hasParsedType()) {
- S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments)
- << AL.getName() << 1;
+ S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
return;
}
@@ -2856,7 +2828,7 @@ static void handleVecTypeHint(Sema &S, D
if (VecTypeHintAttr *A = D->getAttr<VecTypeHintAttr>()) {
if (!S.Context.hasSameType(A->getTypeHint(), ParmType)) {
- S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL.getName();
+ S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
return;
}
}
@@ -3030,7 +3002,7 @@ static void handleMinVectorWidthAttr(Sem
MinVectorWidthAttr *Existing = D->getAttr<MinVectorWidthAttr>();
if (Existing && Existing->getVectorWidth() != VecWidth) {
- S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL.getName();
+ S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
return;
}
@@ -3100,7 +3072,7 @@ static void handleEnumExtensibilityAttr(
const ParsedAttr &AL) {
if (!AL.isArgIdent(0)) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
- << AL.getName() << 0 << AANT_ArgumentIdentifier;
+ << AL << 0 << AANT_ArgumentIdentifier;
return;
}
@@ -3108,8 +3080,7 @@ static void handleEnumExtensibilityAttr(
IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
if (!EnumExtensibilityAttr::ConvertStrToKind(II->getName(),
ExtensibilityKind)) {
- S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported)
- << AL.getName() << II;
+ S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
return;
}
@@ -3188,7 +3159,7 @@ static FormatAttrKind getFormatAttrKind(
/// http://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html
static void handleInitPriorityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
if (!S.getLangOpts().CPlusPlus) {
- S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL.getName();
+ S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL;
return;
}
@@ -3215,7 +3186,7 @@ static void handleInitPriorityAttr(Sema
if (prioritynum < 101 || prioritynum > 65535) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_outof_range)
- << E->getSourceRange() << AL.getName() << 101 << 65535;
+ << E->getSourceRange() << AL << 101 << 65535;
AL.setInvalid();
return;
}
@@ -3250,7 +3221,7 @@ FormatAttr *Sema::mergeFormatAttr(Decl *
static void handleFormatAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
if (!AL.isArgIdent(0)) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
- << AL.getName() << 1 << AANT_ArgumentIdentifier;
+ << AL << 1 << AANT_ArgumentIdentifier;
return;
}
@@ -3275,7 +3246,7 @@ static void handleFormatAttr(Sema &S, De
if (Kind == InvalidFormat) {
S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported)
- << AL.getName() << II->getName();
+ << AL << II->getName();
return;
}
@@ -3287,7 +3258,7 @@ static void handleFormatAttr(Sema &S, De
if (Idx < 1 || Idx > NumArgs) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
- << AL.getName() << 2 << IdxExpr->getSourceRange();
+ << AL << 2 << IdxExpr->getSourceRange();
return;
}
@@ -3358,7 +3329,7 @@ static void handleFormatAttr(Sema &S, De
// if 0 it disables parameter checking (to use with e.g. va_list)
} else if (FirstArg != 0 && FirstArg != NumArgs) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
- << AL.getName() << 3 << FirstArgExpr->getSourceRange();
+ << AL << 3 << FirstArgExpr->getSourceRange();
return;
}
@@ -3379,8 +3350,8 @@ static void handleTransparentUnionAttr(S
RD = dyn_cast<RecordDecl>(D);
if (!RD || !RD->isUnion()) {
- S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
- << AL.getName() << ExpectedUnion;
+ S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type) << AL
+ << ExpectedUnion;
return;
}
@@ -3513,8 +3484,7 @@ void Sema::AddAlignValueAttr(SourceRange
static void handleAlignedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
// check the attribute arguments.
if (AL.getNumArgs() > 1) {
- S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments)
- << AL.getName() << 1;
+ S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
return;
}
@@ -3794,8 +3764,8 @@ static void handleModeAttr(Sema &S, Decl
// This attribute isn't documented, but glibc uses it. It changes
// the width of an int or unsigned int to the specified size.
if (!AL.isArgIdent(0)) {
- S.Diag(AL.getLoc(), diag::err_attribute_argument_type) << AL.getName()
- << AANT_ArgumentIdentifier;
+ S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+ << AL << AANT_ArgumentIdentifier;
return;
}
@@ -3968,26 +3938,55 @@ AlwaysInlineAttr *Sema::mergeAlwaysInlin
AttrSpellingListIndex);
}
-CommonAttr *Sema::mergeCommonAttr(Decl *D, SourceRange Range,
- IdentifierInfo *Ident,
- unsigned AttrSpellingListIndex) {
- if (checkAttrMutualExclusion<InternalLinkageAttr>(*this, D, Range, Ident))
+CommonAttr *Sema::mergeCommonAttr(Decl *D, const ParsedAttr &AL) {
+ if (checkAttrMutualExclusion<InternalLinkageAttr>(*this, D, AL))
return nullptr;
- return ::new (Context) CommonAttr(Range, Context, AttrSpellingListIndex);
+ return ::new (Context)
+ CommonAttr(AL.getRange(), Context, AL.getAttributeSpellingListIndex());
+}
+
+CommonAttr *Sema::mergeCommonAttr(Decl *D, const CommonAttr &AL) {
+ if (checkAttrMutualExclusion<InternalLinkageAttr>(*this, D, AL))
+ return nullptr;
+
+ return ::new (Context)
+ CommonAttr(AL.getRange(), Context, AL.getSpellingListIndex());
}
+InternalLinkageAttr *Sema::mergeInternalLinkageAttr(Decl *D,
+ const ParsedAttr &AL) {
+ if (const auto *VD = dyn_cast<VarDecl>(D)) {
+ // Attribute applies to Var but not any subclass of it (like ParmVar,
+ // ImplicitParm or VarTemplateSpecialization).
+ if (VD->getKind() != Decl::Var) {
+ Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
+ << AL << (getLangOpts().CPlusPlus ? ExpectedFunctionVariableOrClass
+ : ExpectedVariableOrFunction);
+ return nullptr;
+ }
+ // Attribute does not apply to non-static local variables.
+ if (VD->hasLocalStorage()) {
+ Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage);
+ return nullptr;
+ }
+ }
+
+ if (checkAttrMutualExclusion<CommonAttr>(*this, D, AL))
+ return nullptr;
+
+ return ::new (Context) InternalLinkageAttr(
+ AL.getRange(), Context, AL.getAttributeSpellingListIndex());
+}
InternalLinkageAttr *
-Sema::mergeInternalLinkageAttr(Decl *D, SourceRange Range,
- IdentifierInfo *Ident,
- unsigned AttrSpellingListIndex) {
+Sema::mergeInternalLinkageAttr(Decl *D, const InternalLinkageAttr &AL) {
if (const auto *VD = dyn_cast<VarDecl>(D)) {
// Attribute applies to Var but not any subclass of it (like ParmVar,
// ImplicitParm or VarTemplateSpecialization).
if (VD->getKind() != Decl::Var) {
- Diag(Range.getBegin(), diag::warn_attribute_wrong_decl_type)
- << Ident << (getLangOpts().CPlusPlus ? ExpectedFunctionVariableOrClass
- : ExpectedVariableOrFunction);
+ Diag(AL.getLocation(), diag::warn_attribute_wrong_decl_type)
+ << &AL << (getLangOpts().CPlusPlus ? ExpectedFunctionVariableOrClass
+ : ExpectedVariableOrFunction);
return nullptr;
}
// Attribute does not apply to non-static local variables.
@@ -3997,11 +3996,11 @@ Sema::mergeInternalLinkageAttr(Decl *D,
}
}
- if (checkAttrMutualExclusion<CommonAttr>(*this, D, Range, Ident))
+ if (checkAttrMutualExclusion<CommonAttr>(*this, D, AL))
return nullptr;
return ::new (Context)
- InternalLinkageAttr(Range, Context, AttrSpellingListIndex);
+ InternalLinkageAttr(AL.getRange(), Context, AL.getSpellingListIndex());
}
MinSizeAttr *Sema::mergeMinSizeAttr(Decl *D, SourceRange Range,
@@ -4039,8 +4038,7 @@ OptimizeNoneAttr *Sema::mergeOptimizeNon
}
static void handleAlwaysInlineAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
- if (checkAttrMutualExclusion<NotTailCalledAttr>(S, D, AL.getRange(),
- AL.getName()))
+ if (checkAttrMutualExclusion<NotTailCalledAttr>(S, D, AL))
return;
if (AlwaysInlineAttr *Inline = S.mergeAlwaysInlineAttr(
@@ -4062,8 +4060,7 @@ static void handleOptimizeNoneAttr(Sema
}
static void handleConstantAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
- if (checkAttrMutualExclusion<CUDASharedAttr>(S, D, AL.getRange(),
- AL.getName()))
+ if (checkAttrMutualExclusion<CUDASharedAttr>(S, D, AL))
return;
const auto *VD = cast<VarDecl>(D);
if (!VD->hasGlobalStorage()) {
@@ -4075,8 +4072,7 @@ static void handleConstantAttr(Sema &S,
}
static void handleSharedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
- if (checkAttrMutualExclusion<CUDAConstantAttr>(S, D, AL.getRange(),
- AL.getName()))
+ if (checkAttrMutualExclusion<CUDAConstantAttr>(S, D, AL))
return;
const auto *VD = cast<VarDecl>(D);
// extern __shared__ is only allowed on arrays with no length (e.g.
@@ -4095,10 +4091,8 @@ static void handleSharedAttr(Sema &S, De
}
static void handleGlobalAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
- if (checkAttrMutualExclusion<CUDADeviceAttr>(S, D, AL.getRange(),
- AL.getName()) ||
- checkAttrMutualExclusion<CUDAHostAttr>(S, D, AL.getRange(),
- AL.getName())) {
+ if (checkAttrMutualExclusion<CUDADeviceAttr>(S, D, AL) ||
+ checkAttrMutualExclusion<CUDAHostAttr>(S, D, AL)) {
return;
}
const auto *FD = cast<FunctionDecl>(D);
@@ -4150,7 +4144,7 @@ static void handleCallConvAttr(Sema &S,
if (!isa<ObjCMethodDecl>(D)) {
S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
- << AL.getName() << ExpectedFunctionOrMethod;
+ << AL << ExpectedFunctionOrMethod;
return;
}
@@ -4344,7 +4338,7 @@ bool Sema::CheckCallingConvAttr(const Pa
TargetInfo::CallingConvCheckResult A = TI.checkCallingConvention(CC);
if (A != TargetInfo::CCCR_OK) {
if (A == TargetInfo::CCCR_Warning)
- Diag(Attrs.getLoc(), diag::warn_cconv_ignored) << Attrs.getName();
+ Diag(Attrs.getLoc(), diag::warn_cconv_ignored) << Attrs;
// This convention is not valid for the target. Use the default function or
// method calling convention.
@@ -4559,7 +4553,7 @@ static void handleArgumentWithTypeTagAtt
const ParsedAttr &AL) {
if (!AL.isArgIdent(0)) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
- << AL.getName() << /* arg num = */ 1 << AANT_ArgumentIdentifier;
+ << AL << /* arg num = */ 1 << AANT_ArgumentIdentifier;
return;
}
@@ -4579,8 +4573,7 @@ static void handleArgumentWithTypeTagAtt
unsigned ArgumentIdxAST = ArgumentIdx.getASTIndex();
if (ArgumentIdxAST >= getFunctionOrMethodNumParams(D) ||
!getFunctionOrMethodParamType(D, ArgumentIdxAST)->isPointerType())
- S.Diag(AL.getLoc(), diag::err_attribute_pointers_only)
- << AL.getName() << 0;
+ S.Diag(AL.getLoc(), diag::err_attribute_pointers_only) << AL << 0;
}
D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr(
@@ -4592,7 +4585,7 @@ static void handleTypeTagForDatatypeAttr
const ParsedAttr &AL) {
if (!AL.isArgIdent(0)) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
- << AL.getName() << 1 << AANT_ArgumentIdentifier;
+ << AL << 1 << AANT_ArgumentIdentifier;
return;
}
@@ -4601,7 +4594,7 @@ static void handleTypeTagForDatatypeAttr
if (!isa<VarDecl>(D)) {
S.Diag(AL.getLoc(), diag::err_attribute_wrong_decl_type)
- << AL.getName() << ExpectedVariable;
+ << AL << ExpectedVariable;
return;
}
@@ -4715,8 +4708,7 @@ static void handleNSReturnsRetainedAttr(
ReturnType = Param->getType()->getPointeeType();
if (ReturnType.isNull()) {
S.Diag(D->getLocStart(), diag::warn_ns_attribute_wrong_parameter_type)
- << AL.getName() << /*pointer-to-CF*/2
- << AL.getRange();
+ << AL << /*pointer-to-CF*/ 2 << AL.getRange();
return;
}
} else if (AL.isUsedAsTypeAttr()) {
@@ -4737,7 +4729,7 @@ static void handleNSReturnsRetainedAttr(
break;
}
S.Diag(D->getLocStart(), diag::warn_attribute_wrong_decl_type)
- << AL.getRange() << AL.getName() << ExpectedDeclKind;
+ << AL.getRange() << AL << ExpectedDeclKind;
return;
}
@@ -4769,8 +4761,7 @@ static void handleNSReturnsRetainedAttr(
if (isa<ParmVarDecl>(D)) {
S.Diag(D->getLocStart(), diag::warn_ns_attribute_wrong_parameter_type)
- << AL.getName() << /*pointer-to-CF*/2
- << AL.getRange();
+ << AL << /*pointer-to-CF*/ 2 << AL.getRange();
} else {
// Needs to be kept in sync with warn_ns_attribute_wrong_return_type.
enum : unsigned {
@@ -4783,8 +4774,7 @@ static void handleNSReturnsRetainedAttr(
else if (isa<ObjCPropertyDecl>(D))
SubjectKind = Property;
S.Diag(D->getLocStart(), diag::warn_ns_attribute_wrong_return_type)
- << AL.getName() << SubjectKind << Cf
- << AL.getRange();
+ << AL << SubjectKind << Cf << AL.getRange();
}
return;
}
@@ -4830,10 +4820,9 @@ static void handleObjCReturnsInnerPointe
if (!resultType->isReferenceType() &&
(!resultType->isPointerType() || resultType->isObjCRetainableType())) {
S.Diag(D->getLocStart(), diag::warn_ns_attribute_wrong_return_type)
- << SourceRange(loc)
- << Attrs.getName()
- << (isa<ObjCMethodDecl>(D) ? EP_ObjCMethod : EP_ObjCProperty)
- << /*non-retainable pointer*/ 2;
+ << SourceRange(loc) << Attrs
+ << (isa<ObjCMethodDecl>(D) ? EP_ObjCMethod : EP_ObjCProperty)
+ << /*non-retainable pointer*/ 2;
// Drop the attribute.
return;
@@ -4849,14 +4838,14 @@ static void handleObjCRequiresSuperAttr(
const DeclContext *DC = Method->getDeclContext();
if (const auto *PDecl = dyn_cast_or_null<ObjCProtocolDecl>(DC)) {
- S.Diag(D->getLocStart(), diag::warn_objc_requires_super_protocol)
- << Attrs.getName() << 0;
+ S.Diag(D->getLocStart(), diag::warn_objc_requires_super_protocol) << Attrs
+ << 0;
S.Diag(PDecl->getLocation(), diag::note_protocol_decl);
return;
}
if (Method->getMethodFamily() == OMF_dealloc) {
- S.Diag(D->getLocStart(), diag::warn_objc_requires_super_protocol)
- << Attrs.getName() << 1;
+ S.Diag(D->getLocStart(), diag::warn_objc_requires_super_protocol) << Attrs
+ << 1;
return;
}
@@ -4868,15 +4857,14 @@ static void handleObjCBridgeAttr(Sema &S
IdentifierLoc *Parm = AL.isArgIdent(0) ? AL.getArgAsIdent(0) : nullptr;
if (!Parm) {
- S.Diag(D->getLocStart(), diag::err_objc_attr_not_id) << AL.getName() << 0;
+ S.Diag(D->getLocStart(), diag::err_objc_attr_not_id) << AL << 0;
return;
}
// Typedefs only allow objc_bridge(id) and have some additional checking.
if (const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
if (!Parm->Ident->isStr("id")) {
- S.Diag(AL.getLoc(), diag::err_objc_attr_typedef_not_id)
- << AL.getName();
+ S.Diag(AL.getLoc(), diag::err_objc_attr_typedef_not_id) << AL;
return;
}
@@ -4898,7 +4886,7 @@ static void handleObjCBridgeMutableAttr(
IdentifierLoc *Parm = AL.isArgIdent(0) ? AL.getArgAsIdent(0) : nullptr;
if (!Parm) {
- S.Diag(D->getLocStart(), diag::err_objc_attr_not_id) << AL.getName() << 0;
+ S.Diag(D->getLocStart(), diag::err_objc_attr_not_id) << AL << 0;
return;
}
@@ -4912,7 +4900,7 @@ static void handleObjCBridgeRelatedAttr(
IdentifierInfo *RelatedClass =
AL.isArgIdent(0) ? AL.getArgAsIdent(0)->Ident : nullptr;
if (!RelatedClass) {
- S.Diag(D->getLocStart(), diag::err_objc_attr_not_id) << AL.getName() << 0;
+ S.Diag(D->getLocStart(), diag::err_objc_attr_not_id) << AL << 0;
return;
}
IdentifierInfo *ClassMethod =
@@ -4983,7 +4971,7 @@ static void handleObjCOwnershipAttr(Sema
if (hasDeclarator(D)) return;
S.Diag(D->getLocStart(), diag::err_attribute_wrong_decl_type)
- << AL.getRange() << AL.getName() << ExpectedVariable;
+ << AL.getRange() << AL << ExpectedVariable;
}
static void handleObjCPreciseLifetimeAttr(Sema &S, Decl *D,
@@ -5047,7 +5035,7 @@ UuidAttr *Sema::mergeUuidAttr(Decl *D, S
static void handleUuidAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
if (!S.LangOpts.CPlusPlus) {
S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang)
- << AL.getName() << AttributeLangSupport::C;
+ << AL << AttributeLangSupport::C;
return;
}
@@ -5097,7 +5085,7 @@ static void handleUuidAttr(Sema &S, Decl
static void handleMSInheritanceAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
if (!S.LangOpts.CPlusPlus) {
S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang)
- << AL.getName() << AttributeLangSupport::C;
+ << AL << AttributeLangSupport::C;
return;
}
MSInheritanceAttr *IA = S.mergeMSInheritanceAttr(
@@ -5163,8 +5151,7 @@ static void handleAbiTagAttr(Sema &S, De
static void handleARMInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
// Check the attribute arguments.
if (AL.getNumArgs() > 1) {
- S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments)
- << AL.getName() << 1;
+ S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
return;
}
@@ -5178,8 +5165,8 @@ static void handleARMInterruptAttr(Sema
ARMInterruptAttr::InterruptType Kind;
if (!ARMInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
- S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported)
- << AL.getName() << Str << ArgLoc;
+ S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << Str
+ << ArgLoc;
return;
}
@@ -5193,8 +5180,8 @@ static void handleMSP430InterruptAttr(Se
return;
if (!AL.isArgExpr(0)) {
- S.Diag(AL.getLoc(), diag::err_attribute_argument_type) << AL.getName()
- << AANT_ArgumentIntegerConstant;
+ S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+ << AL << AANT_ArgumentIntegerConstant;
return;
}
@@ -5204,16 +5191,16 @@ static void handleMSP430InterruptAttr(Se
llvm::APSInt NumParams(32);
if (!NumParamsExpr->isIntegerConstantExpr(NumParams, S.Context)) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
- << AL.getName() << AANT_ArgumentIntegerConstant
- << NumParamsExpr->getSourceRange();
+ << AL << AANT_ArgumentIntegerConstant
+ << NumParamsExpr->getSourceRange();
return;
}
unsigned Num = NumParams.getLimitedValue(255);
if ((Num & 1) || Num > 30) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
- << AL.getName() << (int)NumParams.getSExtValue()
- << NumParamsExpr->getSourceRange();
+ << AL << (int)NumParams.getSExtValue()
+ << NumParamsExpr->getSourceRange();
return;
}
@@ -5226,8 +5213,7 @@ static void handleMSP430InterruptAttr(Se
static void handleMipsInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
// Only one optional argument permitted.
if (AL.getNumArgs() > 1) {
- S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments)
- << AL.getName() << 1;
+ S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
return;
}
@@ -5266,14 +5252,13 @@ static void handleMipsInterruptAttr(Sema
return;
}
- if (checkAttrMutualExclusion<Mips16Attr>(S, D, AL.getRange(),
- AL.getName()))
+ if (checkAttrMutualExclusion<Mips16Attr>(S, D, AL))
return;
MipsInterruptAttr::InterruptType Kind;
if (!MipsInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported)
- << AL.getName() << "'" + std::string(Str) + "'";
+ << AL << "'" + std::string(Str) + "'";
return;
}
@@ -5292,7 +5277,7 @@ static void handleAnyX86InterruptAttr(Se
CXXMethodDecl::isStaticOverloadedOperator(
cast<NamedDecl>(D)->getDeclName().getCXXOverloadedOperator())) {
S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
- << AL.getName() << ExpectedFunctionWithProtoType;
+ << AL << ExpectedFunctionWithProtoType;
return;
}
// Interrupt handler must have void return type.
@@ -5421,8 +5406,8 @@ static void handleRISCVInterruptAttr(Sem
RISCVInterruptAttr::InterruptType Kind;
if (!RISCVInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
- S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported)
- << AL.getName() << Str << ArgLoc;
+ S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << Str
+ << ArgLoc;
return;
}
@@ -5470,13 +5455,11 @@ static void handleAMDGPUFlatWorkGroupSiz
return;
if (Min == 0 && Max != 0) {
- S.Diag(AL.getLoc(), diag::err_attribute_argument_invalid)
- << AL.getName() << 0;
+ S.Diag(AL.getLoc(), diag::err_attribute_argument_invalid) << AL << 0;
return;
}
if (Min > Max) {
- S.Diag(AL.getLoc(), diag::err_attribute_argument_invalid)
- << AL.getName() << 1;
+ S.Diag(AL.getLoc(), diag::err_attribute_argument_invalid) << AL << 1;
return;
}
@@ -5499,13 +5482,11 @@ static void handleAMDGPUWavesPerEUAttr(S
}
if (Min == 0 && Max != 0) {
- S.Diag(AL.getLoc(), diag::err_attribute_argument_invalid)
- << AL.getName() << 0;
+ S.Diag(AL.getLoc(), diag::err_attribute_argument_invalid) << AL << 0;
return;
}
if (Max != 0 && Min > Max) {
- S.Diag(AL.getLoc(), diag::err_attribute_argument_invalid)
- << AL.getName() << 1;
+ S.Diag(AL.getLoc(), diag::err_attribute_argument_invalid) << AL << 1;
return;
}
@@ -5552,7 +5533,7 @@ static void handleX86ForceAlignArgPointe
// Attribute can only be applied to function types.
if (!isa<FunctionDecl>(D)) {
S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
- << AL.getName() << ExpectedFunction;
+ << AL << ExpectedFunction;
return;
}
@@ -5570,7 +5551,7 @@ static void handleLayoutVersion(Sema &S,
// TODO: Investigate what happens with the next major version of MSVC.
if (Version != LangOptions::MSVC2015) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
- << AL.getName() << Version << VersionExpr->getSourceRange();
+ << AL << Version << VersionExpr->getSourceRange();
return;
}
@@ -5608,8 +5589,7 @@ DLLExportAttr *Sema::mergeDLLExportAttr(
static void handleDLLAttr(Sema &S, Decl *D, const ParsedAttr &A) {
if (isa<ClassTemplatePartialSpecializationDecl>(D) &&
S.Context.getTargetInfo().getCXXABI().isMicrosoft()) {
- S.Diag(A.getRange().getBegin(), diag::warn_attribute_ignored)
- << A.getName();
+ S.Diag(A.getRange().getBegin(), diag::warn_attribute_ignored) << A;
return;
}
@@ -5618,7 +5598,7 @@ static void handleDLLAttr(Sema &S, Decl
!S.Context.getTargetInfo().getCXXABI().isMicrosoft()) {
// MinGW doesn't allow dllimport on inline functions.
S.Diag(A.getRange().getBegin(), diag::warn_attribute_ignored_on_inline)
- << A.getName();
+ << A;
return;
}
}
@@ -5626,7 +5606,7 @@ static void handleDLLAttr(Sema &S, Decl
if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
if (S.Context.getTargetInfo().getCXXABI().isMicrosoft() &&
MD->getParent()->isLambda()) {
- S.Diag(A.getRange().getBegin(), diag::err_attribute_dll_lambda) << A.getName();
+ S.Diag(A.getRange().getBegin(), diag::err_attribute_dll_lambda) << A;
return;
}
}
@@ -5791,7 +5771,7 @@ static void handleDeprecatedAttr(Sema &S
if (!S.getLangOpts().CPlusPlus14)
if (AL.isCXX11Attribute() &&
!(AL.hasScope() && AL.getScopeName()->isStr("gnu")))
- S.Diag(AL.getLoc(), diag::ext_cxx14_attr) << AL.getName();
+ S.Diag(AL.getLoc(), diag::ext_cxx14_attr) << AL;
D->addAttr(::new (S.Context)
DeprecatedAttr(AL.getRange(), S.Context, Str, Replacement,
@@ -5821,7 +5801,7 @@ static void handleNoSanitizeAttr(Sema &S
S.Diag(LiteralLoc, diag::warn_unknown_sanitizer_ignored) << SanitizerName;
else if (isGlobalVar(D) && SanitizerName != "address")
S.Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)
- << AL.getName() << ExpectedFunctionOrMethod;
+ << AL << ExpectedFunctionOrMethod;
Sanitizers.push_back(SanitizerName);
}
@@ -5841,26 +5821,24 @@ static void handleNoSanitizeSpecificAttr
.Case("no_sanitize_memory", "memory");
if (isGlobalVar(D) && SanitizerName != "address")
S.Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)
- << AL.getName() << ExpectedFunction;
+ << AL << ExpectedFunction;
D->addAttr(::new (S.Context)
NoSanitizeAttr(AL.getRange(), S.Context, &SanitizerName, 1,
AL.getAttributeSpellingListIndex()));
}
static void handleInternalLinkageAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
- if (InternalLinkageAttr *Internal =
- S.mergeInternalLinkageAttr(D, AL.getRange(), AL.getName(),
- AL.getAttributeSpellingListIndex()))
+ if (InternalLinkageAttr *Internal = S.mergeInternalLinkageAttr(D, AL))
D->addAttr(Internal);
}
static void handleOpenCLNoSVMAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
if (S.LangOpts.OpenCLVersion != 200)
S.Diag(AL.getLoc(), diag::err_attribute_requires_opencl_version)
- << AL.getName() << "2.0" << 0;
+ << AL << "2.0" << 0;
else
- S.Diag(AL.getLoc(), diag::warn_opencl_attr_deprecated_ignored)
- << AL.getName() << "2.0";
+ S.Diag(AL.getLoc(), diag::warn_opencl_attr_deprecated_ignored) << AL
+ << "2.0";
}
/// Handles semantic checking for features that are common to all attributes,
@@ -5928,7 +5906,7 @@ static void handleOpenCLAccessAttr(Sema
if (AL.getName()->getName().find("read_write") != StringRef::npos) {
if (S.getLangOpts().OpenCLVersion < 200 || DeclTy->isPipeType()) {
S.Diag(AL.getLoc(), diag::err_opencl_invalid_read_write)
- << AL.getName() << PDecl->getType() << DeclTy->isImageType();
+ << AL << PDecl->getType() << DeclTy->isImageType();
D->setInvalidDecl(true);
return;
}
@@ -5965,7 +5943,7 @@ static void ProcessDeclAttribute(Sema &S
S.Diag(AL.getLoc(), AL.isDeclspecAttribute()
? diag::warn_unhandled_ms_attribute_ignored
: diag::warn_unknown_attribute_ignored)
- << AL.getName();
+ << AL;
return;
}
@@ -5980,7 +5958,7 @@ static void ProcessDeclAttribute(Sema &S
break;
}
S.Diag(AL.getLoc(), diag::err_stmt_attribute_invalid_on_decl)
- << AL.getName() << D->getLocation();
+ << AL << D->getLocation();
break;
case ParsedAttr::AT_Interrupt:
handleInterruptAttr(S, D, AL);
@@ -6708,10 +6686,10 @@ static void checkUnusedDeclAttributes(Se
if (AL.getKind() == ParsedAttr::UnknownAttribute) {
S.Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
- << AL.getName() << AL.getRange();
+ << AL << AL.getRange();
} else {
- S.Diag(AL.getLoc(), diag::warn_attribute_not_on_decl)
- << AL.getName() << AL.getRange();
+ S.Diag(AL.getLoc(), diag::warn_attribute_not_on_decl) << AL
+ << AL.getRange();
}
}
}
Modified: cfe/trunk/lib/Sema/SemaStmtAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAttr.cpp?rev=339344&r1=339343&r2=339344&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmtAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmtAttr.cpp Thu Aug 9 06:21:32 2018
@@ -56,8 +56,7 @@ static Attr *handleFallThroughAttr(Sema
static Attr *handleSuppressAttr(Sema &S, Stmt *St, const ParsedAttr &A,
SourceRange Range) {
if (A.getNumArgs() < 1) {
- S.Diag(A.getLoc(), diag::err_attribute_too_few_arguments)
- << A.getName() << 1;
+ S.Diag(A.getLoc(), diag::err_attribute_too_few_arguments) << A << 1;
return nullptr;
}
@@ -284,8 +283,7 @@ static Attr *handleOpenCLUnrollHint(Sema
unsigned NumArgs = A.getNumArgs();
if (NumArgs > 1) {
- S.Diag(A.getLoc(), diag::err_attribute_too_many_arguments) << A.getName()
- << 1;
+ S.Diag(A.getLoc(), diag::err_attribute_too_many_arguments) << A << 1;
return nullptr;
}
@@ -297,7 +295,7 @@ static Attr *handleOpenCLUnrollHint(Sema
if (!E->isIntegerConstantExpr(ArgVal, S.Context)) {
S.Diag(A.getLoc(), diag::err_attribute_argument_type)
- << A.getName() << AANT_ArgumentIntegerConstant << E->getSourceRange();
+ << A << AANT_ArgumentIntegerConstant << E->getSourceRange();
return nullptr;
}
@@ -306,7 +304,7 @@ static Attr *handleOpenCLUnrollHint(Sema
if (Val <= 0) {
S.Diag(A.getRange().getBegin(),
diag::err_attribute_requires_positive_integer)
- << A.getName();
+ << A;
return nullptr;
}
UnrollFactor = Val;
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=339344&r1=339343&r2=339344&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Aug 9 06:21:32 2018
@@ -5815,8 +5815,8 @@ static void HandleAddressSpaceTypeAttrib
// Check the attribute arguments.
if (Attr.getNumArgs() != 1) {
- S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
- << Attr.getName() << 1;
+ S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << Attr
+ << 1;
Attr.setInvalid();
return;
}
@@ -5951,8 +5951,8 @@ static bool handleObjCOwnershipTypeAttr(
S.getSourceManager().getImmediateExpansionRange(AttrLoc).getBegin();
if (!attr.isArgIdent(0)) {
- S.Diag(AttrLoc, diag::err_attribute_argument_type)
- << attr.getName() << AANT_ArgumentString;
+ S.Diag(AttrLoc, diag::err_attribute_argument_type) << attr
+ << AANT_ArgumentString;
attr.setInvalid();
return true;
}
@@ -6122,14 +6122,14 @@ static bool handleObjCGCTypeAttr(TypePro
// Check the attribute arguments.
if (!attr.isArgIdent(0)) {
S.Diag(attr.getLoc(), diag::err_attribute_argument_type)
- << attr.getName() << AANT_ArgumentString;
+ << attr << AANT_ArgumentString;
attr.setInvalid();
return true;
}
Qualifiers::GC GCAttr;
if (attr.getNumArgs() > 1) {
- S.Diag(attr.getLoc(), diag::err_attribute_wrong_number_arguments)
- << attr.getName() << 1;
+ S.Diag(attr.getLoc(), diag::err_attribute_wrong_number_arguments) << attr
+ << 1;
attr.setInvalid();
return true;
}
@@ -6338,11 +6338,9 @@ static bool handleMSPointerTypeQualifier
// pointer-to-member types.
if (!isa<PointerType>(Desugared)) {
if (Type->isMemberPointerType())
- S.Diag(Attr.getLoc(), diag::err_attribute_no_member_pointers)
- << Attr.getName();
+ S.Diag(Attr.getLoc(), diag::err_attribute_no_member_pointers) << Attr;
else
- S.Diag(Attr.getLoc(), diag::err_attribute_pointers_only)
- << Attr.getName() << 0;
+ S.Diag(Attr.getLoc(), diag::err_attribute_pointers_only) << Attr << 0;
return true;
}
@@ -6906,8 +6904,8 @@ static void HandleVectorSizeAttr(QualTyp
Sema &S) {
// Check the attribute arguments.
if (Attr.getNumArgs() != 1) {
- S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
- << Attr.getName() << 1;
+ S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << Attr
+ << 1;
Attr.setInvalid();
return;
}
@@ -6943,8 +6941,8 @@ static void HandleExtVectorTypeAttr(Qual
Sema &S) {
// check the attribute arguments.
if (Attr.getNumArgs() != 1) {
- S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
- << Attr.getName() << 1;
+ S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << Attr
+ << 1;
return;
}
@@ -7032,14 +7030,14 @@ static void HandleNeonVectorTypeAttr(Qua
Sema &S, VectorType::VectorKind VecKind) {
// Target must have NEON
if (!S.Context.getTargetInfo().hasFeature("neon")) {
- S.Diag(Attr.getLoc(), diag::err_attribute_unsupported) << Attr.getName();
+ S.Diag(Attr.getLoc(), diag::err_attribute_unsupported) << Attr;
Attr.setInvalid();
return;
}
// Check the attribute arguments.
if (Attr.getNumArgs() != 1) {
- S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
- << Attr.getName() << 1;
+ S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << Attr
+ << 1;
Attr.setInvalid();
return;
}
@@ -7049,8 +7047,8 @@ static void HandleNeonVectorTypeAttr(Qua
if (numEltsExpr->isTypeDependent() || numEltsExpr->isValueDependent() ||
!numEltsExpr->isIntegerConstantExpr(numEltsInt, S.Context)) {
S.Diag(Attr.getLoc(), diag::err_attribute_argument_type)
- << Attr.getName() << AANT_ArgumentIntegerConstant
- << numEltsExpr->getSourceRange();
+ << Attr << AANT_ArgumentIntegerConstant
+ << numEltsExpr->getSourceRange();
Attr.setInvalid();
return;
}
@@ -7256,7 +7254,7 @@ static void processTypeAttrs(TypeProcess
// A C++11 attribute on a declarator chunk must appertain to a type.
if (attr.isCXX11Attribute() && TAL == TAL_DeclChunk) {
state.getSema().Diag(attr.getLoc(), diag::err_attribute_not_type_attr)
- << attr.getName();
+ << attr;
attr.setUsedAsTypeAttr();
}
break;
Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=339344&r1=339343&r2=339344&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Thu Aug 9 06:21:32 2018
@@ -3335,7 +3335,7 @@ static std::string GenerateAppertainsTo(
SS << (Warn ? "warn_attribute_wrong_decl_type_str" :
"err_attribute_wrong_decl_type_str");
SS << ")\n";
- SS << " << Attr.getName() << ";
+ SS << " << Attr << ";
SS << CalculateDiagnostic(*SubjectObj) << ";\n";
SS << " return false;\n";
SS << " }\n";
More information about the cfe-commits
mailing list