Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Sema/SemaDeclAttr.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- SemaDeclAttr.cpp - Declaration Attribute Handling ----------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
//  This file implements decl-related attribute processing.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/AST/ASTConsumer.h"
14
#include "clang/AST/ASTContext.h"
15
#include "clang/AST/ASTMutationListener.h"
16
#include "clang/AST/CXXInheritance.h"
17
#include "clang/AST/DeclCXX.h"
18
#include "clang/AST/DeclObjC.h"
19
#include "clang/AST/DeclTemplate.h"
20
#include "clang/AST/Expr.h"
21
#include "clang/AST/ExprCXX.h"
22
#include "clang/AST/Mangle.h"
23
#include "clang/AST/RecursiveASTVisitor.h"
24
#include "clang/Basic/CharInfo.h"
25
#include "clang/Basic/SourceManager.h"
26
#include "clang/Basic/TargetInfo.h"
27
#include "clang/Lex/Preprocessor.h"
28
#include "clang/Sema/DeclSpec.h"
29
#include "clang/Sema/DelayedDiagnostic.h"
30
#include "clang/Sema/Initialization.h"
31
#include "clang/Sema/Lookup.h"
32
#include "clang/Sema/Scope.h"
33
#include "clang/Sema/ScopeInfo.h"
34
#include "clang/Sema/SemaInternal.h"
35
#include "llvm/ADT/STLExtras.h"
36
#include "llvm/ADT/StringExtras.h"
37
#include "llvm/Support/MathExtras.h"
38
39
using namespace clang;
40
using namespace sema;
41
42
namespace AttributeLangSupport {
43
  enum LANG {
44
    C,
45
    Cpp,
46
    ObjC
47
  };
48
} // end namespace AttributeLangSupport
49
50
//===----------------------------------------------------------------------===//
51
//  Helper functions
52
//===----------------------------------------------------------------------===//
53
54
/// isFunctionOrMethod - Return true if the given decl has function
55
/// type (function or function-typed variable) or an Objective-C
56
/// method.
57
186
static bool isFunctionOrMethod(const Decl *D) {
58
186
  return (D->getFunctionType() != nullptr) || 
isa<ObjCMethodDecl>(D)16
;
59
186
}
60
61
/// Return true if the given decl has function type (function or
62
/// function-typed variable) or an Objective-C method or a block.
63
7
static bool isFunctionOrMethodOrBlock(const Decl *D) {
64
7
  return isFunctionOrMethod(D) || 
isa<BlockDecl>(D)0
;
65
7
}
66
67
/// Return true if the given decl has a declarator that should have
68
/// been processed by Sema::GetTypeForDeclarator.
69
43.7k
static bool hasDeclarator(const Decl *D) {
70
43.7k
  // In some sense, TypedefDecl really *ought* to be a DeclaratorDecl.
71
43.7k
  return isa<DeclaratorDecl>(D) || 
isa<BlockDecl>(D)350
||
isa<TypedefNameDecl>(D)341
||
72
43.7k
         
isa<ObjCPropertyDecl>(D)203
;
73
43.7k
}
74
75
/// hasFunctionProto - Return true if the given decl has a argument
76
/// information. This decl should have already passed
77
/// isFunctionOrMethod or isFunctionOrMethodOrBlock.
78
17.7k
static bool hasFunctionProto(const Decl *D) {
79
17.7k
  if (const FunctionType *FnTy = D->getFunctionType())
80
17.7k
    return isa<FunctionProtoType>(FnTy);
81
23
  return isa<ObjCMethodDecl>(D) || 
isa<BlockDecl>(D)1
;
82
23
}
83
84
/// getFunctionOrMethodNumParams - Return number of function or method
85
/// parameters. It is an error to call this on a K&R function (use
86
/// hasFunctionProto first).
87
73.6k
static unsigned getFunctionOrMethodNumParams(const Decl *D) {
88
73.6k
  if (const FunctionType *FnTy = D->getFunctionType())
89
73.3k
    return cast<FunctionProtoType>(FnTy)->getNumParams();
90
278
  if (const auto *BD = dyn_cast<BlockDecl>(D))
91
17
    return BD->getNumParams();
92
261
  return cast<ObjCMethodDecl>(D)->param_size();
93
261
}
94
95
static const ParmVarDecl *getFunctionOrMethodParam(const Decl *D,
96
4.24k
                                                   unsigned Idx) {
97
4.24k
  if (const auto *FD = dyn_cast<FunctionDecl>(D))
98
4.18k
    return FD->getParamDecl(Idx);
99
55
  if (const auto *MD = dyn_cast<ObjCMethodDecl>(D))
100
23
    return MD->getParamDecl(Idx);
101
32
  if (const auto *BD = dyn_cast<BlockDecl>(D))
102
16
    return BD->getParamDecl(Idx);
103
16
  return nullptr;
104
16
}
105
106
56.4k
static QualType getFunctionOrMethodParamType(const Decl *D, unsigned Idx) {
107
56.4k
  if (const FunctionType *FnTy = D->getFunctionType())
108
56.1k
    return cast<FunctionProtoType>(FnTy)->getParamType(Idx);
109
252
  if (const auto *BD = dyn_cast<BlockDecl>(D))
110
8
    return BD->getParamDecl(Idx)->getType();
111
244
112
244
  return cast<ObjCMethodDecl>(D)->parameters()[Idx]->getType();
113
244
}
114
115
4.17k
static SourceRange getFunctionOrMethodParamRange(const Decl *D, unsigned Idx) {
116
4.17k
  if (auto *PVD = getFunctionOrMethodParam(D, Idx))
117
4.16k
    return PVD->getSourceRange();
118
16
  return SourceRange();
119
16
}
120
121
2.85k
static QualType getFunctionOrMethodResultType(const Decl *D) {
122
2.85k
  if (const FunctionType *FnTy = D->getFunctionType())
123
2.82k
    return FnTy->getReturnType();
124
25
  return cast<ObjCMethodDecl>(D)->getReturnType();
125
25
}
126
127
76
static SourceRange getFunctionOrMethodResultSourceRange(const Decl *D) {
128
76
  if (const auto *FD = dyn_cast<FunctionDecl>(D))
129
72
    return FD->getReturnTypeSourceRange();
130
4
  if (const auto *MD = dyn_cast<ObjCMethodDecl>(D))
131
4
    return MD->getReturnTypeSourceRange();
132
0
  return SourceRange();
133
0
}
134
135
42.3k
static bool isFunctionOrMethodVariadic(const Decl *D) {
136
42.3k
  if (const FunctionType *FnTy = D->getFunctionType())
137
42.1k
    return cast<FunctionProtoType>(FnTy)->isVariadic();
138
200
  if (const auto *BD = dyn_cast<BlockDecl>(D))
139
6
    return BD->isVariadic();
140
194
  return cast<ObjCMethodDecl>(D)->isVariadic();
141
194
}
142
143
69.3k
static bool isInstanceMethod(const Decl *D) {
144
69.3k
  if (const auto *MethodDecl = dyn_cast<CXXMethodDecl>(D))
145
222
    return MethodDecl->isInstance();
146
69.1k
  return false;
147
69.1k
}
148
149
983
static inline bool isNSStringType(QualType T, ASTContext &Ctx) {
150
983
  const auto *PT = T->getAs<ObjCObjectPointerType>();
151
983
  if (!PT)
152
626
    return false;
153
357
154
357
  ObjCInterfaceDecl *Cls = PT->getObjectType()->getInterface();
155
357
  if (!Cls)
156
0
    return false;
157
357
158
357
  IdentifierInfo* ClsName = Cls->getIdentifier();
159
357
160
357
  // FIXME: Should we walk the chain of classes?
161
357
  return ClsName == &Ctx.Idents.get("NSString") ||
162
357
         
ClsName == &Ctx.Idents.get("NSMutableString")0
;
163
357
}
164
165
693
static inline bool isCFStringType(QualType T, ASTContext &Ctx) {
166
693
  const auto *PT = T->getAs<PointerType>();
167
693
  if (!PT)
168
3
    return false;
169
690
170
690
  const auto *RT = PT->getPointeeType()->getAs<RecordType>();
171
690
  if (!RT)
172
578
    return false;
173
112
174
112
  const RecordDecl *RD = RT->getDecl();
175
112
  if (RD->getTagKind() != TTK_Struct)
176
0
    return false;
177
112
178
112
  return RD->getIdentifier() == &Ctx.Idents.get("__CFString");
179
112
}
180
181
8.19M
static unsigned getNumAttributeArgs(const ParsedAttr &AL) {
182
8.19M
  // FIXME: Include the type in the argument list.
183
8.19M
  return AL.getNumArgs() + AL.hasParsedType();
184
8.19M
}
185
186
template <typename Compare>
187
static bool checkAttributeNumArgsImpl(Sema &S, const ParsedAttr &AL,
188
                                      unsigned Num, unsigned Diag,
189
8.19M
                                      Compare Comp) {
190
8.19M
  if (Comp(getNumAttributeArgs(AL), Num)) {
191
307
    S.Diag(AL.getLoc(), Diag) << AL << Num;
192
307
    return false;
193
307
  }
194
8.19M
195
8.19M
  return true;
196
8.19M
}
SemaDeclAttr.cpp:bool checkAttributeNumArgsImpl<std::__1::not_equal_to<unsigned int> >(clang::Sema&, clang::ParsedAttr const&, unsigned int, unsigned int, std::__1::not_equal_to<unsigned int>)
Line
Count
Source
189
8.07M
                                      Compare Comp) {
190
8.07M
  if (Comp(getNumAttributeArgs(AL), Num)) {
191
242
    S.Diag(AL.getLoc(), Diag) << AL << Num;
192
242
    return false;
193
242
  }
194
8.07M
195
8.07M
  return true;
196
8.07M
}
SemaDeclAttr.cpp:bool checkAttributeNumArgsImpl<std::__1::less<unsigned int> >(clang::Sema&, clang::ParsedAttr const&, unsigned int, unsigned int, std::__1::less<unsigned int>)
Line
Count
Source
189
28.5k
                                      Compare Comp) {
190
28.5k
  if (Comp(getNumAttributeArgs(AL), Num)) {
191
47
    S.Diag(AL.getLoc(), Diag) << AL << Num;
192
47
    return false;
193
47
  }
194
28.5k
195
28.5k
  return true;
196
28.5k
}
SemaDeclAttr.cpp:bool checkAttributeNumArgsImpl<std::__1::greater<unsigned int> >(clang::Sema&, clang::ParsedAttr const&, unsigned int, unsigned int, std::__1::greater<unsigned int>)
Line
Count
Source
189
92.3k
                                      Compare Comp) {
190
92.3k
  if (Comp(getNumAttributeArgs(AL), Num)) {
191
18
    S.Diag(AL.getLoc(), Diag) << AL << Num;
192
18
    return false;
193
18
  }
194
92.3k
195
92.3k
  return true;
196
92.3k
}
197
198
/// Check if the attribute has exactly as many args as Num. May
199
/// output an error.
200
8.07M
static bool checkAttributeNumArgs(Sema &S, const ParsedAttr &AL, unsigned Num) {
201
8.07M
  return checkAttributeNumArgsImpl(S, AL, Num,
202
8.07M
                                   diag::err_attribute_wrong_number_arguments,
203
8.07M
                                   std::not_equal_to<unsigned>());
204
8.07M
}
205
206
/// Check if the attribute has at least as many args as Num. May
207
/// output an error.
208
static bool checkAttributeAtLeastNumArgs(Sema &S, const ParsedAttr &AL,
209
28.5k
                                         unsigned Num) {
210
28.5k
  return checkAttributeNumArgsImpl(S, AL, Num,
211
28.5k
                                   diag::err_attribute_too_few_arguments,
212
28.5k
                                   std::less<unsigned>());
213
28.5k
}
214
215
/// Check if the attribute has at most as many args as Num. May
216
/// output an error.
217
static bool checkAttributeAtMostNumArgs(Sema &S, const ParsedAttr &AL,
218
92.3k
                                        unsigned Num) {
219
92.3k
  return checkAttributeNumArgsImpl(S, AL, Num,
220
92.3k
                                   diag::err_attribute_too_many_arguments,
221
92.3k
                                   std::greater<unsigned>());
222
92.3k
}
223
224
/// A helper function to provide Attribute Location for the Attr types
225
/// AND the ParsedAttr.
226
template <typename AttrInfo>
227
static typename std::enable_if<std::is_base_of<Attr, AttrInfo>::value,
228
                               SourceLocation>::type
229
23
getAttrLoc(const AttrInfo &AL) {
230
23
  return AL.getLocation();
231
23
}
SemaDeclAttr.cpp:std::__1::enable_if<std::is_base_of<clang::Attr, clang::AMDGPUFlatWorkGroupSizeAttr>::value, clang::SourceLocation>::type getAttrLoc<clang::AMDGPUFlatWorkGroupSizeAttr>(clang::AMDGPUFlatWorkGroupSizeAttr const&)
Line
Count
Source
229
9
getAttrLoc(const AttrInfo &AL) {
230
9
  return AL.getLocation();
231
9
}
SemaDeclAttr.cpp:std::__1::enable_if<std::is_base_of<clang::Attr, clang::AMDGPUWavesPerEUAttr>::value, clang::SourceLocation>::type getAttrLoc<clang::AMDGPUWavesPerEUAttr>(clang::AMDGPUWavesPerEUAttr const&)
Line
Count
Source
229
9
getAttrLoc(const AttrInfo &AL) {
230
9
  return AL.getLocation();
231
9
}
SemaDeclAttr.cpp:std::__1::enable_if<std::is_base_of<clang::Attr, clang::AllocAlignAttr>::value, clang::SourceLocation>::type getAttrLoc<clang::AllocAlignAttr>(clang::AllocAlignAttr const&)
Line
Count
Source
229
5
getAttrLoc(const AttrInfo &AL) {
230
5
  return AL.getLocation();
231
5
}
232
69
static SourceLocation getAttrLoc(const ParsedAttr &AL) { return AL.getLoc(); }
233
234
/// If Expr is a valid integer constant, get the value of the integer
235
/// expression and return success or failure. May output an error.
236
///
237
/// Negative argument is implicitly converted to unsigned, unless
238
/// \p StrictlyUnsigned is true.
239
template <typename AttrInfo>
240
static bool checkUInt32Argument(Sema &S, const AttrInfo &AI, const Expr *Expr,
241
                                uint32_t &Val, unsigned Idx = UINT_MAX,
242
819k
                                bool StrictlyUnsigned = false) {
243
819k
  llvm::APSInt I(32);
244
819k
  if (Expr->isTypeDependent() || Expr->isValueDependent() ||
245
819k
      !Expr->isIntegerConstantExpr(I, S.Context)) {
246
30
    if (Idx != UINT_MAX)
247
30
      S.Diag(getAttrLoc(AI), diag::err_attribute_argument_n_type)
248
21
          << &AI << Idx << AANT_ArgumentIntegerConstant
249
21
          << Expr->getSourceRange();
250
9
    else
251
9
      S.Diag(getAttrLoc(AI), diag::err_attribute_argument_type)
252
9
          << &AI << AANT_ArgumentIntegerConstant << Expr->getSourceRange();
253
30
    return false;
254
30
  }
255
819k
256
819k
  if (!I.isIntN(32)) {
257
10
    S.Diag(Expr->getExprLoc(), diag::err_ice_too_large)
258
10
        << I.toString(10, false) << 32 << /* Unsigned */ 1;
259
10
    return false;
260
10
  }
261
819k
262
819k
  if (StrictlyUnsigned && 
I.isSigned()56
&&
I.isNegative()56
) {
263
2
    S.Diag(getAttrLoc(AI), diag::err_attribute_requires_positive_integer)
264
2
        << &AI << /*non-negative*/ 1;
265
2
    return false;
266
2
  }
267
819k
268
819k
  Val = (uint32_t)I.getZExtValue();
269
819k
  return true;
270
819k
}
SemaDeclAttr.cpp:bool checkUInt32Argument<clang::AMDGPUFlatWorkGroupSizeAttr>(clang::Sema&, clang::AMDGPUFlatWorkGroupSizeAttr const&, clang::Expr const*, unsigned int&, unsigned int, bool)
Line
Count
Source
242
203
                                bool StrictlyUnsigned = false) {
243
203
  llvm::APSInt I(32);
244
203
  if (Expr->isTypeDependent() || Expr->isValueDependent() ||
245
203
      !Expr->isIntegerConstantExpr(I, S.Context)) {
246
9
    if (Idx != UINT_MAX)
247
9
      S.Diag(getAttrLoc(AI), diag::err_attribute_argument_n_type)
248
9
          << &AI << Idx << AANT_ArgumentIntegerConstant
249
9
          << Expr->getSourceRange();
250
0
    else
251
0
      S.Diag(getAttrLoc(AI), diag::err_attribute_argument_type)
252
0
          << &AI << AANT_ArgumentIntegerConstant << Expr->getSourceRange();
253
9
    return false;
254
9
  }
255
194
256
194
  if (!I.isIntN(32)) {
257
3
    S.Diag(Expr->getExprLoc(), diag::err_ice_too_large)
258
3
        << I.toString(10, false) << 32 << /* Unsigned */ 1;
259
3
    return false;
260
3
  }
261
191
262
191
  if (StrictlyUnsigned && 
I.isSigned()0
&&
I.isNegative()0
) {
263
0
    S.Diag(getAttrLoc(AI), diag::err_attribute_requires_positive_integer)
264
0
        << &AI << /*non-negative*/ 1;
265
0
    return false;
266
0
  }
267
191
268
191
  Val = (uint32_t)I.getZExtValue();
269
191
  return true;
270
191
}
SemaDeclAttr.cpp:bool checkUInt32Argument<clang::AMDGPUWavesPerEUAttr>(clang::Sema&, clang::AMDGPUWavesPerEUAttr const&, clang::Expr const*, unsigned int&, unsigned int, bool)
Line
Count
Source
242
191
                                bool StrictlyUnsigned = false) {
243
191
  llvm::APSInt I(32);
244
191
  if (Expr->isTypeDependent() || Expr->isValueDependent() ||
245
191
      !Expr->isIntegerConstantExpr(I, S.Context)) {
246
9
    if (Idx != UINT_MAX)
247
9
      S.Diag(getAttrLoc(AI), diag::err_attribute_argument_n_type)
248
9
          << &AI << Idx << AANT_ArgumentIntegerConstant
249
9
          << Expr->getSourceRange();
250
0
    else
251
0
      S.Diag(getAttrLoc(AI), diag::err_attribute_argument_type)
252
0
          << &AI << AANT_ArgumentIntegerConstant << Expr->getSourceRange();
253
9
    return false;
254
9
  }
255
182
256
182
  if (!I.isIntN(32)) {
257
3
    S.Diag(Expr->getExprLoc(), diag::err_ice_too_large)
258
3
        << I.toString(10, false) << 32 << /* Unsigned */ 1;
259
3
    return false;
260
3
  }
261
179
262
179
  if (StrictlyUnsigned && 
I.isSigned()0
&&
I.isNegative()0
) {
263
0
    S.Diag(getAttrLoc(AI), diag::err_attribute_requires_positive_integer)
264
0
        << &AI << /*non-negative*/ 1;
265
0
    return false;
266
0
  }
267
179
268
179
  Val = (uint32_t)I.getZExtValue();
269
179
  return true;
270
179
}
SemaDeclAttr.cpp:bool checkUInt32Argument<clang::ParsedAttr>(clang::Sema&, clang::ParsedAttr const&, clang::Expr const*, unsigned int&, unsigned int, bool)
Line
Count
Source
242
818k
                                bool StrictlyUnsigned = false) {
243
818k
  llvm::APSInt I(32);
244
818k
  if (Expr->isTypeDependent() || Expr->isValueDependent() ||
245
818k
      !Expr->isIntegerConstantExpr(I, S.Context)) {
246
12
    if (Idx != UINT_MAX)
247
12
      S.Diag(getAttrLoc(AI), diag::err_attribute_argument_n_type)
248
3
          << &AI << Idx << AANT_ArgumentIntegerConstant
249
3
          << Expr->getSourceRange();
250
9
    else
251
9
      S.Diag(getAttrLoc(AI), diag::err_attribute_argument_type)
252
9
          << &AI << AANT_ArgumentIntegerConstant << Expr->getSourceRange();
253
12
    return false;
254
12
  }
255
818k
256
818k
  if (!I.isIntN(32)) {
257
4
    S.Diag(Expr->getExprLoc(), diag::err_ice_too_large)
258
4
        << I.toString(10, false) << 32 << /* Unsigned */ 1;
259
4
    return false;
260
4
  }
261
818k
262
818k
  if (StrictlyUnsigned && 
I.isSigned()56
&&
I.isNegative()56
) {
263
2
    S.Diag(getAttrLoc(AI), diag::err_attribute_requires_positive_integer)
264
2
        << &AI << /*non-negative*/ 1;
265
2
    return false;
266
2
  }
267
818k
268
818k
  Val = (uint32_t)I.getZExtValue();
269
818k
  return true;
270
818k
}
271
272
/// Wrapper around checkUInt32Argument, with an extra check to be sure
273
/// that the result will fit into a regular (signed) int. All args have the same
274
/// purpose as they do in checkUInt32Argument.
275
template <typename AttrInfo>
276
static bool checkPositiveIntArgument(Sema &S, const AttrInfo &AI, const Expr *Expr,
277
12.7k
                                     int &Val, unsigned Idx = UINT_MAX) {
278
12.7k
  uint32_t UVal;
279
12.7k
  if (!checkUInt32Argument(S, AI, Expr, UVal, Idx))
280
2
    return false;
281
12.7k
282
12.7k
  if (UVal > (uint32_t)std::numeric_limits<int>::max()) {
283
1
    llvm::APSInt I(32); // for toString
284
1
    I = UVal;
285
1
    S.Diag(Expr->getExprLoc(), diag::err_ice_too_large)
286
1
        << I.toString(10, false) << 32 << /* Unsigned */ 0;
287
1
    return false;
288
1
  }
289
12.7k
290
12.7k
  Val = UVal;
291
12.7k
  return true;
292
12.7k
}
293
294
/// Diagnose mutually exclusive attributes when present on a given
295
/// declaration. Returns true if diagnosed.
296
template <typename AttrTy>
297
1.16M
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
1.16M
  if (const auto *A = D->getAttr<AttrTy>()) {
299
51
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
51
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
51
    return true;
302
51
  }
303
1.16M
  return false;
304
1.16M
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::Mips16Attr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
28
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
28
  if (const auto *A = D->getAttr<AttrTy>()) {
299
4
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
4
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
4
    return true;
302
4
  }
303
24
  return false;
304
24
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::MicroMipsAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
11
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
11
  if (const auto *A = D->getAttr<AttrTy>()) {
299
1
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
1
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
1
    return true;
302
1
  }
303
10
  return false;
304
10
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::MipsInterruptAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
10
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
10
  if (const auto *A = D->getAttr<AttrTy>()) {
299
2
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
2
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
2
    return true;
302
2
  }
303
8
  return false;
304
8
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::MipsShortCallAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
16
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
16
  if (const auto *A = D->getAttr<AttrTy>()) {
299
2
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
2
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
2
    return true;
302
2
  }
303
14
  return false;
304
14
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::MipsLongCallAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
16
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
16
  if (const auto *A = D->getAttr<AttrTy>()) {
299
2
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
2
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
2
    return true;
302
2
  }
303
14
  return false;
304
14
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::NotTailCalledAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
1.15M
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
1.15M
  if (const auto *A = D->getAttr<AttrTy>()) {
299
1
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
1
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
1
    return true;
302
1
  }
303
1.15M
  return false;
304
1.15M
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::CUDASharedAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
155
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
155
  if (const auto *A = D->getAttr<AttrTy>()) {
299
2
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
2
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
2
    return true;
302
2
  }
303
153
  return false;
304
153
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::CUDADeviceAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
213
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
213
  if (const auto *A = D->getAttr<AttrTy>()) {
299
4
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
4
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
4
    return true;
302
4
  }
303
209
  return false;
304
209
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::CUDAHostAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
201
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
201
  if (const auto *A = D->getAttr<AttrTy>()) {
299
2
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
2
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
2
    return true;
302
2
  }
303
199
  return false;
304
199
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::CUDAGlobalAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
2.14k
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
2.14k
  if (const auto *A = D->getAttr<AttrTy>()) {
299
4
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
4
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
4
    return true;
302
4
  }
303
2.13k
  return false;
304
2.13k
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::CUDAConstantAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
232
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
232
  if (const auto *A = D->getAttr<AttrTy>()) {
299
6
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
6
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
6
    return true;
302
6
  }
303
226
  return false;
304
226
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::HotAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
26
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
26
  if (const auto *A = D->getAttr<AttrTy>()) {
299
1
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
1
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
1
    return true;
302
1
  }
303
25
  return false;
304
25
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::ColdAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
3
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
3
  if (const auto *A = D->getAttr<AttrTy>()) {
299
1
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
1
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
1
    return true;
302
1
  }
303
2
  return false;
304
2
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::DisableTailCallsAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
31
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
31
  if (const auto *A = D->getAttr<AttrTy>()) {
299
1
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
1
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
1
    return true;
302
1
  }
303
30
  return false;
304
30
}
Unexecuted instantiation: SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::CFUnknownTransferAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::CFAuditedTransferAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
1
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
1
  if (const auto *A = D->getAttr<AttrTy>()) {
299
0
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
0
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
0
    return true;
302
0
  }
303
1
  return false;
304
1
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::NoSpeculativeLoadHardeningAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
27
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
27
  if (const auto *A = D->getAttr<AttrTy>()) {
299
2
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
2
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
2
    return true;
302
2
  }
303
25
  return false;
304
25
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::SpeculativeLoadHardeningAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
27
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
27
  if (const auto *A = D->getAttr<AttrTy>()) {
299
2
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
2
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
2
    return true;
302
2
  }
303
25
  return false;
304
25
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::AlwaysInlineAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
206
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
206
  if (const auto *A = D->getAttr<AttrTy>()) {
299
1
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
1
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
1
    return true;
302
1
  }
303
205
  return false;
304
205
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::NakedAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
56
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
56
  if (const auto *A = D->getAttr<AttrTy>()) {
299
1
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
1
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
1
    return true;
302
1
  }
303
55
  return false;
304
55
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::NoDestroyAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
28
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
28
  if (const auto *A = D->getAttr<AttrTy>()) {
299
4
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
4
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
4
    return true;
302
4
  }
303
24
  return false;
304
24
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::AlwaysDestroyAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
42
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
42
  if (const auto *A = D->getAttr<AttrTy>()) {
299
4
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
4
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
4
    return true;
302
4
  }
303
38
  return false;
304
38
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::InternalLinkageAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
8
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
8
  if (const auto *A = D->getAttr<AttrTy>()) {
299
1
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
1
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
1
    return true;
302
1
  }
303
7
  return false;
304
7
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::CommonAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
297
156
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) {
298
156
  if (const auto *A = D->getAttr<AttrTy>()) {
299
3
    S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300
3
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
301
3
    return true;
302
3
  }
303
153
  return false;
304
153
}
305
306
template <typename AttrTy>
307
11
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const Attr &AL) {
308
11
  if (const auto *A = D->getAttr<AttrTy>()) {
309
4
    S.Diag(AL.getLocation(), diag::err_attributes_are_not_compatible) << &AL
310
4
                                                                      << A;
311
4
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
312
4
    return true;
313
4
  }
314
7
  return false;
315
7
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::InternalLinkageAttr>(clang::Sema&, clang::Decl*, clang::Attr const&)
Line
Count
Source
307
1
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const Attr &AL) {
308
1
  if (const auto *A = D->getAttr<AttrTy>()) {
309
1
    S.Diag(AL.getLocation(), diag::err_attributes_are_not_compatible) << &AL
310
1
                                                                      << A;
311
1
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
312
1
    return true;
313
1
  }
314
0
  return false;
315
0
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::CommonAttr>(clang::Sema&, clang::Decl*, clang::Attr const&)
Line
Count
Source
307
8
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const Attr &AL) {
308
8
  if (const auto *A = D->getAttr<AttrTy>()) {
309
1
    S.Diag(AL.getLocation(), diag::err_attributes_are_not_compatible) << &AL
310
1
                                                                      << A;
311
1
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
312
1
    return true;
313
1
  }
314
7
  return false;
315
7
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::SpeculativeLoadHardeningAttr>(clang::Sema&, clang::Decl*, clang::Attr const&)
Line
Count
Source
307
1
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const Attr &AL) {
308
1
  if (const auto *A = D->getAttr<AttrTy>()) {
309
1
    S.Diag(AL.getLocation(), diag::err_attributes_are_not_compatible) << &AL
310
1
                                                                      << A;
311
1
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
312
1
    return true;
313
1
  }
314
0
  return false;
315
0
}
SemaDeclAttr.cpp:bool checkAttrMutualExclusion<clang::NoSpeculativeLoadHardeningAttr>(clang::Sema&, clang::Decl*, clang::Attr const&)
Line
Count
Source
307
1
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const Attr &AL) {
308
1
  if (const auto *A = D->getAttr<AttrTy>()) {
309
1
    S.Diag(AL.getLocation(), diag::err_attributes_are_not_compatible) << &AL
310
1
                                                                      << A;
311
1
    S.Diag(A->getLocation(), diag::note_conflicting_attribute);
312
1
    return true;
313
1
  }
314
0
  return false;
315
0
}
316
317
/// Check if IdxExpr is a valid parameter index for a function or
318
/// instance method D.  May output an error.
319
///
320
/// \returns true if IdxExpr is a valid index.
321
template <typename AttrInfo>
322
static bool checkFunctionOrMethodParameterIndex(
323
    Sema &S, const Decl *D, const AttrInfo &AI, unsigned AttrArgNum,
324
17.5k
    const Expr *IdxExpr, ParamIdx &Idx, bool CanIndexImplicitThis = false) {
325
17.5k
  assert(isFunctionOrMethodOrBlock(D));
326
17.5k
327
17.5k
  // In C++ the implicit 'this' function parameter also counts.
328
17.5k
  // Parameters are counted from one.
329
17.5k
  bool HP = hasFunctionProto(D);
330
17.5k
  bool HasImplicitThisParam = isInstanceMethod(D);
331
17.5k
  bool IV = HP && 
isFunctionOrMethodVariadic(D)17.5k
;
332
17.5k
  unsigned NumParams =
333
17.5k
      (HP ? 
getFunctionOrMethodNumParams(D)17.5k
:
03
) + HasImplicitThisParam;
334
17.5k
335
17.5k
  llvm::APSInt IdxInt;
336
17.5k
  if (IdxExpr->isTypeDependent() || IdxExpr->isValueDependent() ||
337
17.5k
      
!IdxExpr->isIntegerConstantExpr(IdxInt, S.Context)17.5k
) {
338
13
    S.Diag(getAttrLoc(AI), diag::err_attribute_argument_n_type)
339
13
        << &AI << AttrArgNum << AANT_ArgumentIntegerConstant
340
13
        << IdxExpr->getSourceRange();
341
13
    return false;
342
13
  }
343
17.5k
344
17.5k
  unsigned IdxSource = IdxInt.getLimitedValue(UINT_MAX);
345
17.5k
  if (IdxSource < 1 || 
(17.5k
!IV17.5k
&&
IdxSource > NumParams17.4k
)) {
346
42
    S.Diag(getAttrLoc(AI), diag::err_attribute_argument_out_of_bounds)
347
42
        << &AI << AttrArgNum << IdxExpr->getSourceRange();
348
42
    return false;
349
42
  }
350
17.4k
  if (HasImplicitThisParam && 
!CanIndexImplicitThis70
) {
351
67
    if (IdxSource == 1) {
352
5
      S.Diag(getAttrLoc(AI), diag::err_attribute_invalid_implicit_this_argument)
353
5
          << &AI << IdxExpr->getSourceRange();
354
5
      return false;
355
5
    }
356
17.4k
  }
357
17.4k
358
17.4k
  Idx = ParamIdx(IdxSource, D);
359
17.4k
  return true;
360
17.4k
}
SemaDeclAttr.cpp:bool checkFunctionOrMethodParameterIndex<clang::ParsedAttr>(clang::Sema&, clang::Decl const*, clang::ParsedAttr const&, unsigned int, clang::Expr const*, clang::ParamIdx&, bool)
Line
Count
Source
324
17.4k
    const Expr *IdxExpr, ParamIdx &Idx, bool CanIndexImplicitThis = false) {
325
17.4k
  assert(isFunctionOrMethodOrBlock(D));
326
17.4k
327
17.4k
  // In C++ the implicit 'this' function parameter also counts.
328
17.4k
  // Parameters are counted from one.
329
17.4k
  bool HP = hasFunctionProto(D);
330
17.4k
  bool HasImplicitThisParam = isInstanceMethod(D);
331
17.4k
  bool IV = HP && 
isFunctionOrMethodVariadic(D)17.4k
;
332
17.4k
  unsigned NumParams =
333
17.4k
      (HP ? 
getFunctionOrMethodNumParams(D)17.4k
:
03
) + HasImplicitThisParam;
334
17.4k
335
17.4k
  llvm::APSInt IdxInt;
336
17.4k
  if (IdxExpr->isTypeDependent() || IdxExpr->isValueDependent() ||
337
17.4k
      
!IdxExpr->isIntegerConstantExpr(IdxInt, S.Context)17.4k
) {
338
11
    S.Diag(getAttrLoc(AI), diag::err_attribute_argument_n_type)
339
11
        << &AI << AttrArgNum << AANT_ArgumentIntegerConstant
340
11
        << IdxExpr->getSourceRange();
341
11
    return false;
342
11
  }
343
17.4k
344
17.4k
  unsigned IdxSource = IdxInt.getLimitedValue(UINT_MAX);
345
17.4k
  if (IdxSource < 1 || 
(17.4k
!IV17.4k
&&
IdxSource > NumParams17.3k
)) {
346
40
    S.Diag(getAttrLoc(AI), diag::err_attribute_argument_out_of_bounds)
347
40
        << &AI << AttrArgNum << IdxExpr->getSourceRange();
348
40
    return false;
349
40
  }
350
17.4k
  if (HasImplicitThisParam && 
!CanIndexImplicitThis59
) {
351
56
    if (IdxSource == 1) {
352
4
      S.Diag(getAttrLoc(AI), diag::err_attribute_invalid_implicit_this_argument)
353
4
          << &AI << IdxExpr->getSourceRange();
354
4
      return false;
355
4
    }
356
17.4k
  }
357
17.4k
358
17.4k
  Idx = ParamIdx(IdxSource, D);
359
17.4k
  return true;
360
17.4k
}
SemaDeclAttr.cpp:bool checkFunctionOrMethodParameterIndex<clang::AllocAlignAttr>(clang::Sema&, clang::Decl const*, clang::AllocAlignAttr const&, unsigned int, clang::Expr const*, clang::ParamIdx&, bool)
Line
Count
Source
324
34
    const Expr *IdxExpr, ParamIdx &Idx, bool CanIndexImplicitThis = false) {
325
34
  assert(isFunctionOrMethodOrBlock(D));
326
34
327
34
  // In C++ the implicit 'this' function parameter also counts.
328
34
  // Parameters are counted from one.
329
34
  bool HP = hasFunctionProto(D);
330
34
  bool HasImplicitThisParam = isInstanceMethod(D);
331
34
  bool IV = HP && isFunctionOrMethodVariadic(D);
332
34
  unsigned NumParams =
333
34
      (HP ? getFunctionOrMethodNumParams(D) : 
00
) + HasImplicitThisParam;
334
34
335
34
  llvm::APSInt IdxInt;
336
34
  if (IdxExpr->isTypeDependent() || IdxExpr->isValueDependent() ||
337
34
      
!IdxExpr->isIntegerConstantExpr(IdxInt, S.Context)33
) {
338
2
    S.Diag(getAttrLoc(AI), diag::err_attribute_argument_n_type)
339
2
        << &AI << AttrArgNum << AANT_ArgumentIntegerConstant
340
2
        << IdxExpr->getSourceRange();
341
2
    return false;
342
2
  }
343
32
344
32
  unsigned IdxSource = IdxInt.getLimitedValue(UINT_MAX);
345
32
  if (IdxSource < 1 || 
(31
!IV31
&&
IdxSource > NumParams31
)) {
346
2
    S.Diag(getAttrLoc(AI), diag::err_attribute_argument_out_of_bounds)
347
2
        << &AI << AttrArgNum << IdxExpr->getSourceRange();
348
2
    return false;
349
2
  }
350
30
  if (HasImplicitThisParam && 
!CanIndexImplicitThis11
) {
351
11
    if (IdxSource == 1) {
352
1
      S.Diag(getAttrLoc(AI), diag::err_attribute_invalid_implicit_this_argument)
353
1
          << &AI << IdxExpr->getSourceRange();
354
1
      return false;
355
1
    }
356
29
  }
357
29
358
29
  Idx = ParamIdx(IdxSource, D);
359
29
  return true;
360
29
}
361
362
/// Check if the argument \p ArgNum of \p Attr is a ASCII string literal.
363
/// If not emit an error and return false. If the argument is an identifier it
364
/// will emit an error with a fixit hint and treat it as if it was a string
365
/// literal.
366
bool Sema::checkStringLiteralArgumentAttr(const ParsedAttr &AL, unsigned ArgNum,
367
                                          StringRef &Str,
368
2.19M
                                          SourceLocation *ArgLocation) {
369
2.19M
  // Look for identifiers. If we have one emit a hint to fix it to a literal.
370
2.19M
  if (AL.isArgIdent(ArgNum)) {
371
11
    IdentifierLoc *Loc = AL.getArgAsIdent(ArgNum);
372
11
    Diag(Loc->Loc, diag::err_attribute_argument_type)
373
11
        << AL << AANT_ArgumentString
374
11
        << FixItHint::CreateInsertion(Loc->Loc, "\"")
375
11
        << FixItHint::CreateInsertion(getLocForEndOfToken(Loc->Loc), "\"");
376
11
    Str = Loc->Ident->getName();
377
11
    if (ArgLocation)
378
8
      *ArgLocation = Loc->Loc;
379
11
    return true;
380
11
  }
381
2.19M
382
2.19M
  // Now check for an actual string literal.
383
2.19M
  Expr *ArgExpr = AL.getArgAsExpr(ArgNum);
384
2.19M
  const auto *Literal = dyn_cast<StringLiteral>(ArgExpr->IgnoreParenCasts());
385
2.19M
  if (ArgLocation)
386
2.16M
    *ArgLocation = ArgExpr->getBeginLoc();
387
2.19M
388
2.19M
  if (!Literal || 
!Literal->isAscii()2.19M
) {
389
24
    Diag(ArgExpr->getBeginLoc(), diag::err_attribute_argument_type)
390
24
        << AL << AANT_ArgumentString;
391
24
    return false;
392
24
  }
393
2.19M
394
2.19M
  Str = Literal->getString();
395
2.19M
  return true;
396
2.19M
}
397
398
/// Applies the given attribute to the Decl without performing any
399
/// additional semantic checking.
400
template <typename AttrType>
401
static void handleSimpleAttribute(Sema &S, Decl *D, SourceRange SR,
402
1.71M
                                  unsigned SpellingIndex) {
403
1.71M
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
1.71M
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::AVRInterruptAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
2
                                  unsigned SpellingIndex) {
403
2
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
2
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::Mips16Attr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
8
                                  unsigned SpellingIndex) {
403
8
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
8
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoMips16Attr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
4
                                  unsigned SpellingIndex) {
403
4
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
4
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::MicroMipsAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
3
                                  unsigned SpellingIndex) {
403
3
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
3
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoMicroMipsAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
2
                                  unsigned SpellingIndex) {
403
2
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
2
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::MipsLongCallAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
14
                                  unsigned SpellingIndex) {
403
14
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
14
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::MipsShortCallAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
14
                                  unsigned SpellingIndex) {
403
14
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
14
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::AVRSignalAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
2
                                  unsigned SpellingIndex) {
403
2
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
2
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::IBActionAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
55
                                  unsigned SpellingIndex) {
403
55
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
55
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ArtificialAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
4.50k
                                  unsigned SpellingIndex) {
403
4.50k
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
4.50k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::CXX11NoReturnAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
7.79k
                                  unsigned SpellingIndex) {
403
7.79k
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
7.79k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::FlagEnumAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
1.06k
                                  unsigned SpellingIndex) {
403
1.06k
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
1.06k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::FlattenAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
10
                                  unsigned SpellingIndex) {
403
10
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
10
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::CUDADeviceAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
1.48k
                                  unsigned SpellingIndex) {
403
1.48k
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
1.48k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::CUDAHostAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
658
                                  unsigned SpellingIndex) {
403
658
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
658
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::HIPPinnedShadowAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
6
                                  unsigned SpellingIndex) {
403
6
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
6
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::LifetimeBoundAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
11
                                  unsigned SpellingIndex) {
403
11
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
11
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::MayAliasAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
14.0k
                                  unsigned SpellingIndex) {
403
14.0k
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
14.0k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoAliasAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
2
                                  unsigned SpellingIndex) {
403
2
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
2
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoCommonAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
4
                                  unsigned SpellingIndex) {
403
4
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
4
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoSplitStackAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
14
                                  unsigned SpellingIndex) {
403
14
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
14
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoUniqueAddressAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
61
                                  unsigned SpellingIndex) {
403
61
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
61
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::OverloadableAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
361k
                                  unsigned SpellingIndex) {
403
361k
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
361k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ColdAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
25
                                  unsigned SpellingIndex) {
403
25
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
25
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::HotAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
2
                                  unsigned SpellingIndex) {
403
2
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
2
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::AnyX86NoCfCheckAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
10
                                  unsigned SpellingIndex) {
403
10
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
10
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoThrowAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
2.60k
                                  unsigned SpellingIndex) {
403
2.60k
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
2.60k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ObjCRuntimeVisibleAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
4
                                  unsigned SpellingIndex) {
403
4
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
4
}
Unexecuted instantiation: SemaDeclAttr.cpp:void handleSimpleAttribute<clang::CFAuditedTransferAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::CFUnknownTransferAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
1
                                  unsigned SpellingIndex) {
403
1
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
1
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NSConsumesSelfAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
44
                                  unsigned SpellingIndex) {
403
44
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
44
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::OSConsumesThisAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
3
                                  unsigned SpellingIndex) {
403
3
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
3
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::OSReturnsRetainedOnZeroAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
3
                                  unsigned SpellingIndex) {
403
3
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
3
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::OSReturnsRetainedOnNonZeroAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
2
                                  unsigned SpellingIndex) {
403
2
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
2
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NSReturnsAutoreleasedAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
6
                                  unsigned SpellingIndex) {
403
6
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
6
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::CFReturnsNotRetainedAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
76
                                  unsigned SpellingIndex) {
403
76
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
76
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NSReturnsNotRetainedAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
111
                                  unsigned SpellingIndex) {
403
111
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
111
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::CFReturnsRetainedAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
500
                                  unsigned SpellingIndex) {
403
500
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
500
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NSReturnsRetainedAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
974
                                  unsigned SpellingIndex) {
403
974
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
974
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::OSReturnsRetainedAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
18
                                  unsigned SpellingIndex) {
403
18
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
18
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::OSReturnsNotRetainedAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
11
                                  unsigned SpellingIndex) {
403
11
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
11
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::RequireConstantInitAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
157
                                  unsigned SpellingIndex) {
403
157
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
157
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::SpeculativeLoadHardeningAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
25
                                  unsigned SpellingIndex) {
403
25
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
25
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoSpeculativeLoadHardeningAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
25
                                  unsigned SpellingIndex) {
403
25
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
25
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ArcWeakrefUnavailableAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
63
                                  unsigned SpellingIndex) {
403
63
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
63
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ObjCRootClassAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
208
                                  unsigned SpellingIndex) {
403
208
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
208
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ObjCNonLazyClassAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
7
                                  unsigned SpellingIndex) {
403
7
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
7
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ObjCSubclassingRestrictedAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
21
                                  unsigned SpellingIndex) {
403
21
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
21
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ObjCClassStubAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
6
                                  unsigned SpellingIndex) {
403
6
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
6
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ObjCRequiresPropertyDefsAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
4
                                  unsigned SpellingIndex) {
403
4
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
4
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ReturnsTwiceAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
17
                                  unsigned SpellingIndex) {
403
17
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
17
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NotTailCalledAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
205
                                  unsigned SpellingIndex) {
403
205
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
205
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::DisableTailCallsAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
55
                                  unsigned SpellingIndex) {
403
55
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
55
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::UsedAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
7.25k
                                  unsigned SpellingIndex) {
403
7.25k
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
7.25k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::WarnUnusedAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
7
                                  unsigned SpellingIndex) {
403
7
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
7
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::WeakAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
30.1k
                                  unsigned SpellingIndex) {
403
30.1k
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
30.1k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ObjCExceptionAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
44
                                  unsigned SpellingIndex) {
403
44
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
44
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ConstAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
214k
                                  unsigned SpellingIndex) {
403
214k
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
214k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::PureAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
3.24k
                                  unsigned SpellingIndex) {
403
3.24k
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
3.24k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoDuplicateAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
6
                                  unsigned SpellingIndex) {
403
6
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
6
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ConvergentAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
4.68k
                                  unsigned SpellingIndex) {
403
4.68k
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
4.68k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoInlineAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
13.0k
                                  unsigned SpellingIndex) {
403
13.0k
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
13.0k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoInstrumentFunctionAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
27
                                  unsigned SpellingIndex) {
403
27
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
27
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoStackProtectorAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
10
                                  unsigned SpellingIndex) {
403
10
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
10
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::OpenCLKernelAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
733
                                  unsigned SpellingIndex) {
403
733
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
733
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ExcludeFromExplicitInstantiationAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
1.04M
                                  unsigned SpellingIndex) {
403
1.04M
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
1.04M
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::LTOVisibilityPublicAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
5
                                  unsigned SpellingIndex) {
403
5
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
5
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::EmptyBasesAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
9
                                  unsigned SpellingIndex) {
403
9
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
9
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::TrivialABIAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
32
                                  unsigned SpellingIndex) {
403
32
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
32
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::MSNoVTableAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
6
                                  unsigned SpellingIndex) {
403
6
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
6
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::MSStructAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
73
                                  unsigned SpellingIndex) {
403
73
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
73
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::SelectAnyAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
65
                                  unsigned SpellingIndex) {
403
65
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
65
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::GuardedVarAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
13
                                  unsigned SpellingIndex) {
403
13
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
13
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ScopedLockableAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
67
                                  unsigned SpellingIndex) {
403
67
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
67
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoThreadSafetyAnalysisAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
43
                                  unsigned SpellingIndex) {
403
43
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
43
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ConsumableAutoCastAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
2
                                  unsigned SpellingIndex) {
403
2
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
2
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ConsumableSetOnReadAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
2
                                  unsigned SpellingIndex) {
403
2
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
2
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::AnyX86NoCallerSavedRegistersAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
27
                                  unsigned SpellingIndex) {
403
27
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
27
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::RenderScriptKernelAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
1
                                  unsigned SpellingIndex) {
403
1
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
1
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::XRayInstrumentAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
697
                                  unsigned SpellingIndex) {
403
697
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
697
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ReinitializesAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
11
                                  unsigned SpellingIndex) {
403
11
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
11
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::AlwaysDestroyAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
24
                                  unsigned SpellingIndex) {
403
24
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
24
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoDestroyAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
38
                                  unsigned SpellingIndex) {
403
38
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
38
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ObjCExternallyRetainedAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
47
                                  unsigned SpellingIndex) {
403
47
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
47
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::MIGServerRoutineAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
26
                                  unsigned SpellingIndex) {
403
26
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
26
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::MSAllocatorAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
4
                                  unsigned SpellingIndex) {
403
4
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
4
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::OSConsumedAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
9
                                  unsigned SpellingIndex) {
403
9
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
9
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NSConsumedAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
218
                                  unsigned SpellingIndex) {
403
218
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
218
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::CFConsumedAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int)
Line
Count
Source
402
419
                                  unsigned SpellingIndex) {
403
419
  D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex));
404
419
}
405
406
template <typename AttrType>
407
1.71M
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
1.71M
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
1.71M
                                  AL.getAttributeSpellingListIndex());
410
1.71M
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::AVRInterruptAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
2
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
2
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
2
                                  AL.getAttributeSpellingListIndex());
410
2
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::Mips16Attr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
8
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
8
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
8
                                  AL.getAttributeSpellingListIndex());
410
8
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoMips16Attr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
4
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
4
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
4
                                  AL.getAttributeSpellingListIndex());
410
4
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::MicroMipsAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
3
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
3
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
3
                                  AL.getAttributeSpellingListIndex());
410
3
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoMicroMipsAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
2
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
2
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
2
                                  AL.getAttributeSpellingListIndex());
410
2
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::MipsLongCallAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
14
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
14
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
14
                                  AL.getAttributeSpellingListIndex());
410
14
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::MipsShortCallAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
14
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
14
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
14
                                  AL.getAttributeSpellingListIndex());
410
14
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::AVRSignalAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
2
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
2
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
2
                                  AL.getAttributeSpellingListIndex());
410
2
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::IBActionAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
55
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
55
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
55
                                  AL.getAttributeSpellingListIndex());
410
55
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ArtificialAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
4.50k
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
4.50k
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
4.50k
                                  AL.getAttributeSpellingListIndex());
410
4.50k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::CXX11NoReturnAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
7.79k
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
7.79k
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
7.79k
                                  AL.getAttributeSpellingListIndex());
410
7.79k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::FlagEnumAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
1.06k
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
1.06k
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
1.06k
                                  AL.getAttributeSpellingListIndex());
410
1.06k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::FlattenAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
10
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
10
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
10
                                  AL.getAttributeSpellingListIndex());
410
10
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::CUDADeviceAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
1.48k
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
1.48k
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
1.48k
                                  AL.getAttributeSpellingListIndex());
410
1.48k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::CUDAHostAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
658
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
658
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
658
                                  AL.getAttributeSpellingListIndex());
410
658
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::HIPPinnedShadowAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
6
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
6
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
6
                                  AL.getAttributeSpellingListIndex());
410
6
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::LifetimeBoundAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
11
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
11
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
11
                                  AL.getAttributeSpellingListIndex());
410
11
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::MayAliasAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
14.0k
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
14.0k
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
14.0k
                                  AL.getAttributeSpellingListIndex());
410
14.0k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoAliasAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
2
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
2
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
2
                                  AL.getAttributeSpellingListIndex());
410
2
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoCommonAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
4
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
4
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
4
                                  AL.getAttributeSpellingListIndex());
410
4
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoSplitStackAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
14
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
14
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
14
                                  AL.getAttributeSpellingListIndex());
410
14
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoUniqueAddressAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
61
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
61
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
61
                                  AL.getAttributeSpellingListIndex());
410
61
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::OverloadableAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
361k
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
361k
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
361k
                                  AL.getAttributeSpellingListIndex());
410
361k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ColdAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
25
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
25
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
25
                                  AL.getAttributeSpellingListIndex());
410
25
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::HotAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
2
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
2
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
2
                                  AL.getAttributeSpellingListIndex());
410
2
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::AnyX86NoCfCheckAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
10
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
10
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
10
                                  AL.getAttributeSpellingListIndex());
410
10
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoThrowAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
2.60k
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
2.60k
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
2.60k
                                  AL.getAttributeSpellingListIndex());
410
2.60k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ObjCRuntimeVisibleAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
4
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
4
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
4
                                  AL.getAttributeSpellingListIndex());
410
4
}
Unexecuted instantiation: SemaDeclAttr.cpp:void handleSimpleAttribute<clang::CFAuditedTransferAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::CFUnknownTransferAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
1
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
1
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
1
                                  AL.getAttributeSpellingListIndex());
410
1
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NSConsumesSelfAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
44
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
44
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
44
                                  AL.getAttributeSpellingListIndex());
410
44
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::OSConsumesThisAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
3
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
3
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
3
                                  AL.getAttributeSpellingListIndex());
410
3
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NSReturnsAutoreleasedAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
6
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
6
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
6
                                  AL.getAttributeSpellingListIndex());
410
6
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::CFReturnsNotRetainedAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
76
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
76
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
76
                                  AL.getAttributeSpellingListIndex());
410
76
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NSReturnsNotRetainedAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
111
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
111
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
111
                                  AL.getAttributeSpellingListIndex());
410
111
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::CFReturnsRetainedAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
500
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
500
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
500
                                  AL.getAttributeSpellingListIndex());
410
500
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NSReturnsRetainedAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
974
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
974
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
974
                                  AL.getAttributeSpellingListIndex());
410
974
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::OSReturnsRetainedAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
18
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
18
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
18
                                  AL.getAttributeSpellingListIndex());
410
18
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::OSReturnsNotRetainedAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
11
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
11
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
11
                                  AL.getAttributeSpellingListIndex());
410
11
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::RequireConstantInitAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
157
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
157
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
157
                                  AL.getAttributeSpellingListIndex());
410
157
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::SpeculativeLoadHardeningAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
25
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
25
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
25
                                  AL.getAttributeSpellingListIndex());
410
25
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoSpeculativeLoadHardeningAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
25
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
25
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
25
                                  AL.getAttributeSpellingListIndex());
410
25
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ArcWeakrefUnavailableAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
63
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
63
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
63
                                  AL.getAttributeSpellingListIndex());
410
63
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ObjCRootClassAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
208
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
208
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
208
                                  AL.getAttributeSpellingListIndex());
410
208
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ObjCNonLazyClassAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
7
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
7
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
7
                                  AL.getAttributeSpellingListIndex());
410
7
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ObjCSubclassingRestrictedAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
21
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
21
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
21
                                  AL.getAttributeSpellingListIndex());
410
21
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ObjCClassStubAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
6
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
6
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
6
                                  AL.getAttributeSpellingListIndex());
410
6
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ObjCRequiresPropertyDefsAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
4
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
4
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
4
                                  AL.getAttributeSpellingListIndex());
410
4
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ReturnsTwiceAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
17
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
17
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
17
                                  AL.getAttributeSpellingListIndex());
410
17
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NotTailCalledAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
205
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
205
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
205
                                  AL.getAttributeSpellingListIndex());
410
205
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::DisableTailCallsAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
55
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
55
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
55
                                  AL.getAttributeSpellingListIndex());
410
55
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::UsedAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
7.25k
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
7.25k
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
7.25k
                                  AL.getAttributeSpellingListIndex());
410
7.25k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::WarnUnusedAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
7
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
7
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
7
                                  AL.getAttributeSpellingListIndex());
410
7
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::WeakAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
30.1k
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
30.1k
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
30.1k
                                  AL.getAttributeSpellingListIndex());
410
30.1k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ObjCExceptionAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
44
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
44
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
44
                                  AL.getAttributeSpellingListIndex());
410
44
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ConstAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
214k
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
214k
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
214k
                                  AL.getAttributeSpellingListIndex());
410
214k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::PureAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
3.24k
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
3.24k
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
3.24k
                                  AL.getAttributeSpellingListIndex());
410
3.24k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoDuplicateAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
6
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
6
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
6
                                  AL.getAttributeSpellingListIndex());
410
6
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ConvergentAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
4.68k
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
4.68k
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
4.68k
                                  AL.getAttributeSpellingListIndex());
410
4.68k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoInlineAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
13.0k
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
13.0k
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
13.0k
                                  AL.getAttributeSpellingListIndex());
410
13.0k
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoInstrumentFunctionAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
27
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
27
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
27
                                  AL.getAttributeSpellingListIndex());
410
27
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoStackProtectorAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
10
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
10
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
10
                                  AL.getAttributeSpellingListIndex());
410
10
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::OpenCLKernelAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
733
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
733
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
733
                                  AL.getAttributeSpellingListIndex());
410
733
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ExcludeFromExplicitInstantiationAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
1.04M
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
1.04M
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
1.04M
                                  AL.getAttributeSpellingListIndex());
410
1.04M
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::LTOVisibilityPublicAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
5
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
5
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
5
                                  AL.getAttributeSpellingListIndex());
410
5
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::EmptyBasesAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
9
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
9
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
9
                                  AL.getAttributeSpellingListIndex());
410
9
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::TrivialABIAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
32
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
32
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
32
                                  AL.getAttributeSpellingListIndex());
410
32
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::MSNoVTableAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
6
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
6
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
6
                                  AL.getAttributeSpellingListIndex());
410
6
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::MSStructAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
73
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
73
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
73
                                  AL.getAttributeSpellingListIndex());
410
73
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::SelectAnyAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
65
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
65
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
65
                                  AL.getAttributeSpellingListIndex());
410
65
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::GuardedVarAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
13
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
13
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
13
                                  AL.getAttributeSpellingListIndex());
410
13
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ScopedLockableAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
67
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
67
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
67
                                  AL.getAttributeSpellingListIndex());
410
67
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoThreadSafetyAnalysisAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
43
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
43
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
43
                                  AL.getAttributeSpellingListIndex());
410
43
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ConsumableAutoCastAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
2
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
2
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
2
                                  AL.getAttributeSpellingListIndex());
410
2
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ConsumableSetOnReadAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
2
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
2
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
2
                                  AL.getAttributeSpellingListIndex());
410
2
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::AnyX86NoCallerSavedRegistersAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
27
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
27
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
27
                                  AL.getAttributeSpellingListIndex());
410
27
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::RenderScriptKernelAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
1
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
1
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
1
                                  AL.getAttributeSpellingListIndex());
410
1
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::XRayInstrumentAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
697
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
697
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
697
                                  AL.getAttributeSpellingListIndex());
410
697
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ReinitializesAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
11
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
11
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
11
                                  AL.getAttributeSpellingListIndex());
410
11
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::AlwaysDestroyAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
24
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
24
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
24
                                  AL.getAttributeSpellingListIndex());
410
24
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::NoDestroyAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
38
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
38
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
38
                                  AL.getAttributeSpellingListIndex());
410
38
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::ObjCExternallyRetainedAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
47
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
47
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
47
                                  AL.getAttributeSpellingListIndex());
410
47
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::MIGServerRoutineAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
26
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
26
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
26
                                  AL.getAttributeSpellingListIndex());
410
26
}
SemaDeclAttr.cpp:void handleSimpleAttribute<clang::MSAllocatorAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
407
4
static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) {
408
4
  handleSimpleAttribute<AttrType>(S, D, AL.getRange(),
409
4
                                  AL.getAttributeSpellingListIndex());
410
4
}
411
412
413
template <typename... DiagnosticArgs>
414
static const Sema::SemaDiagnosticBuilder&
415
4
appendDiagnostics(const Sema::SemaDiagnosticBuilder &Bldr) {
416
4
  return Bldr;
417
4
}
418
419
template <typename T, typename... DiagnosticArgs>
420
static const Sema::SemaDiagnosticBuilder&
421
appendDiagnostics(const Sema::SemaDiagnosticBuilder &Bldr, T &&ExtraArg,
422
12
                  DiagnosticArgs &&... ExtraArgs) {
423
12
  return appendDiagnostics(Bldr << std::forward<T>(ExtraArg),
424
12
                           std::forward<DiagnosticArgs>(ExtraArgs)...);
425
12
}
SemaDeclAttr.cpp:clang::Sema::SemaDiagnosticBuilder const& appendDiagnostics<clang::ParsedAttr const&, int, clang::SourceRange>(clang::Sema::SemaDiagnosticBuilder const&, clang::ParsedAttr const&&&, int&&, clang::SourceRange&&)
Line
Count
Source
422
2
                  DiagnosticArgs &&... ExtraArgs) {
423
2
  return appendDiagnostics(Bldr << std::forward<T>(ExtraArg),
424
2
                           std::forward<DiagnosticArgs>(ExtraArgs)...);
425
2
}
SemaDeclAttr.cpp:clang::Sema::SemaDiagnosticBuilder const& appendDiagnostics<int, clang::SourceRange>(clang::Sema::SemaDiagnosticBuilder const&, int&&, clang::SourceRange&&)
Line
Count
Source
422
2
                  DiagnosticArgs &&... ExtraArgs) {
423
2
  return appendDiagnostics(Bldr << std::forward<T>(ExtraArg),
424
2
                           std::forward<DiagnosticArgs>(ExtraArgs)...);
425
2
}
SemaDeclAttr.cpp:clang::Sema::SemaDiagnosticBuilder const& appendDiagnostics<clang::SourceRange>(clang::Sema::SemaDiagnosticBuilder const&, clang::SourceRange&&)
Line
Count
Source
422
2
                  DiagnosticArgs &&... ExtraArgs) {
423
2
  return appendDiagnostics(Bldr << std::forward<T>(ExtraArg),
424
2
                           std::forward<DiagnosticArgs>(ExtraArgs)...);
425
2
}
SemaDeclAttr.cpp:clang::Sema::SemaDiagnosticBuilder const& appendDiagnostics<clang::SourceRange&, char const (&) [12], int>(clang::Sema::SemaDiagnosticBuilder const&, clang::SourceRange&&&, char const (&&&) [12], int&&)
Line
Count
Source
422
2
                  DiagnosticArgs &&... ExtraArgs) {
423
2
  return appendDiagnostics(Bldr << std::forward<T>(ExtraArg),
424
2
                           std::forward<DiagnosticArgs>(ExtraArgs)...);
425
2
}
SemaDeclAttr.cpp:clang::Sema::SemaDiagnosticBuilder const& appendDiagnostics<char const (&) [12], int>(clang::Sema::SemaDiagnosticBuilder const&, char const (&&&) [12], int&&)
Line
Count
Source
422
2
                  DiagnosticArgs &&... ExtraArgs) {
423
2
  return appendDiagnostics(Bldr << std::forward<T>(ExtraArg),
424
2
                           std::forward<DiagnosticArgs>(ExtraArgs)...);
425
2
}
SemaDeclAttr.cpp:clang::Sema::SemaDiagnosticBuilder const& appendDiagnostics<int>(clang::Sema::SemaDiagnosticBuilder const&, int&&)
Line
Count
Source
422
2
                  DiagnosticArgs &&... ExtraArgs) {
423
2
  return appendDiagnostics(Bldr << std::forward<T>(ExtraArg),
424
2
                           std::forward<DiagnosticArgs>(ExtraArgs)...);
425
2
}
426
427
/// Add an attribute {@code AttrType} to declaration {@code D}, provided that
428
/// {@code PassesCheck} is true.
429
/// Otherwise, emit diagnostic {@code DiagID}, passing in all parameters
430
/// specified in {@code ExtraArgs}.
431
template <typename AttrType, typename... DiagnosticArgs>
432
static void
433
handleSimpleAttributeOrDiagnose(Sema &S, Decl *D, SourceRange SR,
434
                               unsigned SpellingIndex,
435
                               bool PassesCheck,
436
655
                               unsigned DiagID, DiagnosticArgs&&... ExtraArgs) {
437
655
  if (!PassesCheck) {
438
4
    Sema::SemaDiagnosticBuilder DB = S.Diag(D->getBeginLoc(), DiagID);
439
4
    appendDiagnostics(DB, std::forward<DiagnosticArgs>(ExtraArgs)...);
440
4
    return;
441
4
  }
442
651
  handleSimpleAttribute<AttrType>(S, D, SR, SpellingIndex);
443
651
}
SemaDeclAttr.cpp:void handleSimpleAttributeOrDiagnose<clang::OSReturnsRetainedOnZeroAttr, clang::ParsedAttr const&, int, clang::SourceRange>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int, bool, unsigned int, clang::ParsedAttr const&&&, int&&, clang::SourceRange&&)
Line
Count
Source
436
4
                               unsigned DiagID, DiagnosticArgs&&... ExtraArgs) {
437
4
  if (!PassesCheck) {
438
1
    Sema::SemaDiagnosticBuilder DB = S.Diag(D->getBeginLoc(), DiagID);
439
1
    appendDiagnostics(DB, std::forward<DiagnosticArgs>(ExtraArgs)...);
440
1
    return;
441
1
  }
442
3
  handleSimpleAttribute<AttrType>(S, D, SR, SpellingIndex);
443
3
}
SemaDeclAttr.cpp:void handleSimpleAttributeOrDiagnose<clang::OSReturnsRetainedOnNonZeroAttr, clang::ParsedAttr const&, int, clang::SourceRange>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int, bool, unsigned int, clang::ParsedAttr const&&&, int&&, clang::SourceRange&&)
Line
Count
Source
436
3
                               unsigned DiagID, DiagnosticArgs&&... ExtraArgs) {
437
3
  if (!PassesCheck) {
438
1
    Sema::SemaDiagnosticBuilder DB = S.Diag(D->getBeginLoc(), DiagID);
439
1
    appendDiagnostics(DB, std::forward<DiagnosticArgs>(ExtraArgs)...);
440
1
    return;
441
1
  }
442
2
  handleSimpleAttribute<AttrType>(S, D, SR, SpellingIndex);
443
2
}
SemaDeclAttr.cpp:void handleSimpleAttributeOrDiagnose<clang::OSConsumedAttr, clang::SourceRange&, char const (&) [12], int>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int, bool, unsigned int, clang::SourceRange&&&, char const (&&&) [12], int&&)
Line
Count
Source
436
10
                               unsigned DiagID, DiagnosticArgs&&... ExtraArgs) {
437
10
  if (!PassesCheck) {
438
1
    Sema::SemaDiagnosticBuilder DB = S.Diag(D->getBeginLoc(), DiagID);
439
1
    appendDiagnostics(DB, std::forward<DiagnosticArgs>(ExtraArgs)...);
440
1
    return;
441
1
  }
442
9
  handleSimpleAttribute<AttrType>(S, D, SR, SpellingIndex);
443
9
}
SemaDeclAttr.cpp:void handleSimpleAttributeOrDiagnose<clang::NSConsumedAttr, clang::SourceRange&, char const (&) [12], int>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int, bool, unsigned int, clang::SourceRange&&&, char const (&&&) [12], int&&)
Line
Count
Source
436
219
                               unsigned DiagID, DiagnosticArgs&&... ExtraArgs) {
437
219
  if (!PassesCheck) {
438
1
    Sema::SemaDiagnosticBuilder DB = S.Diag(D->getBeginLoc(), DiagID);
439
1
    appendDiagnostics(DB, std::forward<DiagnosticArgs>(ExtraArgs)...);
440
1
    return;
441
1
  }
442
218
  handleSimpleAttribute<AttrType>(S, D, SR, SpellingIndex);
443
218
}
SemaDeclAttr.cpp:void handleSimpleAttributeOrDiagnose<clang::CFConsumedAttr, clang::SourceRange&, char const (&) [12], int>(clang::Sema&, clang::Decl*, clang::SourceRange, unsigned int, bool, unsigned int, clang::SourceRange&&&, char const (&&&) [12], int&&)
Line
Count
Source
436
419
                               unsigned DiagID, DiagnosticArgs&&... ExtraArgs) {
437
419
  if (!PassesCheck) {
438
0
    Sema::SemaDiagnosticBuilder DB = S.Diag(D->getBeginLoc(), DiagID);
439
0
    appendDiagnostics(DB, std::forward<DiagnosticArgs>(ExtraArgs)...);
440
0
    return;
441
0
  }
442
419
  handleSimpleAttribute<AttrType>(S, D, SR, SpellingIndex);
443
419
}
444
445
template <typename AttrType, typename... DiagnosticArgs>
446
static void
447
handleSimpleAttributeOrDiagnose(Sema &S, Decl *D, const ParsedAttr &AL,
448
                               bool PassesCheck,
449
                               unsigned DiagID,
450
7
                               DiagnosticArgs&&... ExtraArgs) {
451
7
  return handleSimpleAttributeOrDiagnose<AttrType>(
452
7
      S, D, AL.getRange(), AL.getAttributeSpellingListIndex(), PassesCheck,
453
7
      DiagID, std::forward<DiagnosticArgs>(ExtraArgs)...);
454
7
}
SemaDeclAttr.cpp:void handleSimpleAttributeOrDiagnose<clang::OSReturnsRetainedOnZeroAttr, clang::ParsedAttr const&, int, clang::SourceRange>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&, bool, unsigned int, clang::ParsedAttr const&&&, int&&, clang::SourceRange&&)
Line
Count
Source
450
4
                               DiagnosticArgs&&... ExtraArgs) {
451
4
  return handleSimpleAttributeOrDiagnose<AttrType>(
452
4
      S, D, AL.getRange(), AL.getAttributeSpellingListIndex(), PassesCheck,
453
4
      DiagID, std::forward<DiagnosticArgs>(ExtraArgs)...);
454
4
}
SemaDeclAttr.cpp:void handleSimpleAttributeOrDiagnose<clang::OSReturnsRetainedOnNonZeroAttr, clang::ParsedAttr const&, int, clang::SourceRange>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&, bool, unsigned int, clang::ParsedAttr const&&&, int&&, clang::SourceRange&&)
Line
Count
Source
450
3
                               DiagnosticArgs&&... ExtraArgs) {
451
3
  return handleSimpleAttributeOrDiagnose<AttrType>(
452
3
      S, D, AL.getRange(), AL.getAttributeSpellingListIndex(), PassesCheck,
453
3
      DiagID, std::forward<DiagnosticArgs>(ExtraArgs)...);
454
3
}
455
456
template <typename AttrType>
457
static void handleSimpleAttributeWithExclusions(Sema &S, Decl *D,
458
2.58k
                                                const ParsedAttr &AL) {
459
2.58k
  handleSimpleAttribute<AttrType>(S, D, AL);
460
2.58k
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::Mips16Attr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
458
8
                                                const ParsedAttr &AL) {
459
8
  handleSimpleAttribute<AttrType>(S, D, AL);
460
8
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::MicroMipsAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
458
3
                                                const ParsedAttr &AL) {
459
3
  handleSimpleAttribute<AttrType>(S, D, AL);
460
3
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::MipsLongCallAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
458
14
                                                const ParsedAttr &AL) {
459
14
  handleSimpleAttribute<AttrType>(S, D, AL);
460
14
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::MipsShortCallAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
458
14
                                                const ParsedAttr &AL) {
459
14
  handleSimpleAttribute<AttrType>(S, D, AL);
460
14
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::CUDADeviceAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
458
1.48k
                                                const ParsedAttr &AL) {
459
1.48k
  handleSimpleAttribute<AttrType>(S, D, AL);
460
1.48k
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::CUDAHostAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
458
658
                                                const ParsedAttr &AL) {
459
658
  handleSimpleAttribute<AttrType>(S, D, AL);
460
658
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::HIPPinnedShadowAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
458
6
                                                const ParsedAttr &AL) {
459
6
  handleSimpleAttribute<AttrType>(S, D, AL);
460
6
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::ColdAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
458
25
                                                const ParsedAttr &AL) {
459
25
  handleSimpleAttribute<AttrType>(S, D, AL);
460
25
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::HotAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
458
2
                                                const ParsedAttr &AL) {
459
2
  handleSimpleAttribute<AttrType>(S, D, AL);
460
2
}
Unexecuted instantiation: SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::CFAuditedTransferAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::CFUnknownTransferAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
458
1
                                                const ParsedAttr &AL) {
459
1
  handleSimpleAttribute<AttrType>(S, D, AL);
460
1
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::SpeculativeLoadHardeningAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
458
25
                                                const ParsedAttr &AL) {
459
25
  handleSimpleAttribute<AttrType>(S, D, AL);
460
25
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::NoSpeculativeLoadHardeningAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
458
25
                                                const ParsedAttr &AL) {
459
25
  handleSimpleAttribute<AttrType>(S, D, AL);
460
25
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::NotTailCalledAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
458
205
                                                const ParsedAttr &AL) {
459
205
  handleSimpleAttribute<AttrType>(S, D, AL);
460
205
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::DisableTailCallsAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
458
55
                                                const ParsedAttr &AL) {
459
55
  handleSimpleAttribute<AttrType>(S, D, AL);
460
55
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::AlwaysDestroyAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
458
24
                                                const ParsedAttr &AL) {
459
24
  handleSimpleAttribute<AttrType>(S, D, AL);
460
24
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::NoDestroyAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
458
38
                                                const ParsedAttr &AL) {
459
38
  handleSimpleAttribute<AttrType>(S, D, AL);
460
38
}
461
462
/// Applies the given attribute to the Decl so long as the Decl doesn't
463
/// already have one of the given incompatible attributes.
464
template <typename AttrType, typename IncompatibleAttrType,
465
          typename... IncompatibleAttrTypes>
466
static void handleSimpleAttributeWithExclusions(Sema &S, Decl *D,
467
2.63k
                                                const ParsedAttr &AL) {
468
2.63k
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
33
    return;
470
2.60k
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
2.60k
                                                                          AL);
472
2.60k
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::Mips16Attr, clang::MicroMipsAttr, clang::MipsInterruptAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
467
11
                                                const ParsedAttr &AL) {
468
11
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
1
    return;
470
10
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
10
                                                                          AL);
472
10
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::Mips16Attr, clang::MipsInterruptAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
467
10
                                                const ParsedAttr &AL) {
468
10
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
2
    return;
470
8
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
8
                                                                          AL);
472
8
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::MicroMipsAttr, clang::Mips16Attr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
467
5
                                                const ParsedAttr &AL) {
468
5
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
2
    return;
470
3
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
3
                                                                          AL);
472
3
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::MipsLongCallAttr, clang::MipsShortCallAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
467
16
                                                const ParsedAttr &AL) {
468
16
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
2
    return;
470
14
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
14
                                                                          AL);
472
14
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::MipsShortCallAttr, clang::MipsLongCallAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
467
16
                                                const ParsedAttr &AL) {
468
16
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
2
    return;
470
14
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
14
                                                                          AL);
472
14
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::CUDADeviceAttr, clang::CUDAGlobalAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
467
1.48k
                                                const ParsedAttr &AL) {
468
1.48k
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
2
    return;
470
1.48k
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
1.48k
                                                                          AL);
472
1.48k
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::CUDAHostAttr, clang::CUDAGlobalAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
467
660
                                                const ParsedAttr &AL) {
468
660
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
2
    return;
470
658
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
658
                                                                          AL);
472
658
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::HIPPinnedShadowAttr, clang::CUDADeviceAttr, clang::CUDAConstantAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
467
10
                                                const ParsedAttr &AL) {
468
10
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
2
    return;
470
8
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
8
                                                                          AL);
472
8
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::HIPPinnedShadowAttr, clang::CUDAConstantAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
467
8
                                                const ParsedAttr &AL) {
468
8
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
2
    return;
470
6
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
6
                                                                          AL);
472
6
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::ColdAttr, clang::HotAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
467
26
                                                const ParsedAttr &AL) {
468
26
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
1
    return;
470
25
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
25
                                                                          AL);
472
25
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::HotAttr, clang::ColdAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
467
3
                                                const ParsedAttr &AL) {
468
3
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
1
    return;
470
2
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
2
                                                                          AL);
472
2
}
Unexecuted instantiation: SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::CFAuditedTransferAttr, clang::CFUnknownTransferAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::CFUnknownTransferAttr, clang::CFAuditedTransferAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
467
1
                                                const ParsedAttr &AL) {
468
1
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
0
    return;
470
1
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
1
                                                                          AL);
472
1
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::SpeculativeLoadHardeningAttr, clang::NoSpeculativeLoadHardeningAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
467
27
                                                const ParsedAttr &AL) {
468
27
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
2
    return;
470
25
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
25
                                                                          AL);
472
25
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::NoSpeculativeLoadHardeningAttr, clang::SpeculativeLoadHardeningAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
467
27
                                                const ParsedAttr &AL) {
468
27
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
2
    return;
470
25
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
25
                                                                          AL);
472
25
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::NotTailCalledAttr, clang::AlwaysInlineAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
467
206
                                                const ParsedAttr &AL) {
468
206
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
1
    return;
470
205
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
205
                                                                          AL);
472
205
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::DisableTailCallsAttr, clang::NakedAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
467
56
                                                const ParsedAttr &AL) {
468
56
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
1
    return;
470
55
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
55
                                                                          AL);
472
55
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::AlwaysDestroyAttr, clang::NoDestroyAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
467
28
                                                const ParsedAttr &AL) {
468
28
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
4
    return;
470
24
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
24
                                                                          AL);
472
24
}
SemaDeclAttr.cpp:void handleSimpleAttributeWithExclusions<clang::NoDestroyAttr, clang::AlwaysDestroyAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
467
42
                                                const ParsedAttr &AL) {
468
42
  if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
469
4
    return;
470
38
  handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
471
38
                                                                          AL);
472
38
}
473
474
/// Check if the passed-in expression is of type int or bool.
475
176
static bool isIntOrBool(Expr *Exp) {
476
176
  QualType QT = Exp->getType();
477
176
  return QT->isBooleanType() || 
QT->isIntegerType()120
;
478
176
}
479
480
481
// Check to see if the type is a smart pointer of some kind.  We assume
482
// it's a smart pointer if it defines both operator-> and operator*.
483
2.69k
static bool threadSafetyCheckIsSmartPointer(Sema &S, const RecordType* RT) {
484
2.69k
  auto IsOverloadedOperatorPresent = [&S](const RecordDecl *Record,
485
5.48k
                                          OverloadedOperatorKind Op) {
486
5.48k
    DeclContextLookupResult Result =
487
5.48k
        Record->lookup(S.Context.DeclarationNames.getCXXOperatorName(Op));
488
5.48k
    return !Result.empty();
489
5.48k
  };
490
2.69k
491
2.69k
  const RecordDecl *Record = RT->getDecl();
492
2.69k
  bool foundStarOperator = IsOverloadedOperatorPresent(Record, OO_Star);
493
2.69k
  bool foundArrowOperator = IsOverloadedOperatorPresent(Record, OO_Arrow);
494
2.69k
  if (foundStarOperator && 
foundArrowOperator46
)
495
46
    return true;
496
2.65k
497
2.65k
  const CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(Record);
498
2.65k
  if (!CXXRecord)
499
21
    return false;
500
2.63k
501
2.63k
  for (auto BaseSpecifier : CXXRecord->bases()) {
502
44
    if (!foundStarOperator)
503
44
      foundStarOperator = IsOverloadedOperatorPresent(
504
44
          BaseSpecifier.getType()->getAsRecordDecl(), OO_Star);
505
44
    if (!foundArrowOperator)
506
44
      foundArrowOperator = IsOverloadedOperatorPresent(
507
44
          BaseSpecifier.getType()->getAsRecordDecl(), OO_Arrow);
508
44
  }
509
2.63k
510
2.63k
  if (foundStarOperator && 
foundArrowOperator16
)
511
16
    return true;
512
2.61k
513
2.61k
  return false;
514
2.61k
}
515
516
/// Check if passed in Decl is a pointer type.
517
/// Note that this function may produce an error message.
518
/// \return true if the Decl is a pointer type; false otherwise
519
static bool threadSafetyCheckIsPointer(Sema &S, const Decl *D,
520
153
                                       const ParsedAttr &AL) {
521
153
  const auto *VD = cast<ValueDecl>(D);
522
153
  QualType QT = VD->getType();
523
153
  if (QT->isAnyPointerType())
524
114
    return true;
525
39
526
39
  if (const auto *RT = QT->getAs<RecordType>()) {
527
22
    // If it's an incomplete type, it could be a smart pointer; skip it.
528
22
    // (We don't want to force template instantiation if we can avoid it,
529
22
    // since that would alter the order in which templates are instantiated.)
530
22
    if (RT->isIncompleteType())
531
3
      return true;
532
19
533
19
    if (threadSafetyCheckIsSmartPointer(S, RT))
534
19
      return true;
535
17
  }
536
17
537
17
  S.Diag(AL.getLoc(), diag::warn_thread_attribute_decl_not_pointer) << AL << QT;
538
17
  return false;
539
17
}
540
541
/// Checks that the passed in QualType either is of RecordType or points
542
/// to RecordType. Returns the relevant RecordType, null if it does not exit.
543
5.38k
static const RecordType *getRecordType(QualType QT) {
544
5.38k
  if (const auto *RT = QT->getAs<RecordType>())
545
4.37k
    return RT;
546
1.00k
547
1.00k
  // Now check if we point to record type.
548
1.00k
  if (const auto *PT = QT->getAs<PointerType>())
549
780
    return PT->getPointeeType()->getAs<RecordType>();
550
229
551
229
  return nullptr;
552
229
}
553
554
template <typename AttrType>
555
3.17k
static bool checkRecordDeclForAttr(const RecordDecl *RD) {
556
3.17k
  // Check if the record itself has the attribute.
557
3.17k
  if (RD->hasAttr<AttrType>())
558
2.85k
    return true;
559
324
560
324
  // Else check if any base classes have the attribute.
561
324
  if (const auto *CRD = dyn_cast<CXXRecordDecl>(RD)) {
562
322
    CXXBasePaths BPaths(false, false);
563
322
    if (CRD->lookupInBases(
564
322
            [](const CXXBaseSpecifier *BS, CXXBasePath &) {
565
49
              const auto &Ty = *BS->getType();
566
49
              // If it's type-dependent, we assume it could have the attribute.
567
49
              if (Ty.isDependentType())
568
3
                return true;
569
46
              return Ty.getAs<RecordType>()->getDecl()->hasAttr<AttrType>();
570
46
            },
SemaDeclAttr.cpp:bool checkRecordDeclForAttr<clang::CapabilityAttr>(clang::RecordDecl const*)::'lambda'(clang::CXXBaseSpecifier const*, clang::CXXBasePath&)::operator()(clang::CXXBaseSpecifier const*, clang::CXXBasePath&) const
Line
Count
Source
564
43
            [](const CXXBaseSpecifier *BS, CXXBasePath &) {
565
43
              const auto &Ty = *BS->getType();
566
43
              // If it's type-dependent, we assume it could have the attribute.
567
43
              if (Ty.isDependentType())
568
3
                return true;
569
40
              return Ty.getAs<RecordType>()->getDecl()->hasAttr<AttrType>();
570
40
            },
SemaDeclAttr.cpp:bool checkRecordDeclForAttr<clang::ScopedLockableAttr>(clang::RecordDecl const*)::'lambda'(clang::CXXBaseSpecifier const*, clang::CXXBasePath&)::operator()(clang::CXXBaseSpecifier const*, clang::CXXBasePath&) const
Line
Count
Source
564
6
            [](const CXXBaseSpecifier *BS, CXXBasePath &) {
565
6
              const auto &Ty = *BS->getType();
566
6
              // If it's type-dependent, we assume it could have the attribute.
567
6
              if (Ty.isDependentType())
568
0
                return true;
569
6
              return Ty.getAs<RecordType>()->getDecl()->hasAttr<AttrType>();
570
6
            },
571
322
            BPaths, true))
572
22
      return true;
573
302
  }
574
302
  return false;
575
302
}
SemaDeclAttr.cpp:bool checkRecordDeclForAttr<clang::CapabilityAttr>(clang::RecordDecl const*)
Line
Count
Source
555
3.01k
static bool checkRecordDeclForAttr(const RecordDecl *RD) {
556
3.01k
  // Check if the record itself has the attribute.
557
3.01k
  if (RD->hasAttr<AttrType>())
558
2.71k
    return true;
559
296
560
296
  // Else check if any base classes have the attribute.
561
296
  if (const auto *CRD = dyn_cast<CXXRecordDecl>(RD)) {
562
294
    CXXBasePaths BPaths(false, false);
563
294
    if (CRD->lookupInBases(
564
294
            [](const CXXBaseSpecifier *BS, CXXBasePath &) {
565
294
              const auto &Ty = *BS->getType();
566
294
              // If it's type-dependent, we assume it could have the attribute.
567
294
              if (Ty.isDependentType())
568
294
                return true;
569
294
              return Ty.getAs<RecordType>()->getDecl()->hasAttr<AttrType>();
570
294
            },
571
294
            BPaths, true))
572
19
      return true;
573
277
  }
574
277
  return false;
575
277
}
SemaDeclAttr.cpp:bool checkRecordDeclForAttr<clang::ScopedLockableAttr>(clang::RecordDecl const*)
Line
Count
Source
555
166
static bool checkRecordDeclForAttr(const RecordDecl *RD) {
556
166
  // Check if the record itself has the attribute.
557
166
  if (RD->hasAttr<AttrType>())
558
138
    return true;
559
28
560
28
  // Else check if any base classes have the attribute.
561
28
  if (const auto *CRD = dyn_cast<CXXRecordDecl>(RD)) {
562
28
    CXXBasePaths BPaths(false, false);
563
28
    if (CRD->lookupInBases(
564
28
            [](const CXXBaseSpecifier *BS, CXXBasePath &) {
565
28
              const auto &Ty = *BS->getType();
566
28
              // If it's type-dependent, we assume it could have the attribute.
567
28
              if (Ty.isDependentType())
568
28
                return true;
569
28
              return Ty.getAs<RecordType>()->getDecl()->hasAttr<AttrType>();
570
28
            },
571
28
            BPaths, true))
572
3
      return true;
573
25
  }
574
25
  return false;
575
25
}
576
577
2.84k
static bool checkRecordTypeForCapability(Sema &S, QualType Ty) {
578
2.84k
  const RecordType *RT = getRecordType(Ty);
579
2.84k
580
2.84k
  if (!RT)
581
160
    return false;
582
2.68k
583
2.68k
  // Don't check for the capability if the class hasn't been defined yet.
584
2.68k
  if (RT->isIncompleteType())
585
0
    return true;
586
2.68k
587
2.68k
  // Allow smart pointers to be used as capability objects.
588
2.68k
  // FIXME -- Check the type that the smart pointer points to.
589
2.68k
  if (threadSafetyCheckIsSmartPointer(S, RT))
590
43
    return true;
591
2.63k
592
2.63k
  return checkRecordDeclForAttr<CapabilityAttr>(RT->getDecl());
593
2.63k
}
594
595
2.88k
static bool checkTypedefTypeForCapability(QualType Ty) {
596
2.88k
  const auto *TD = Ty->getAs<TypedefType>();
597
2.88k
  if (!TD)
598
2.84k
    return false;
599
48
600
48
  TypedefNameDecl *TN = TD->getDecl();
601
48
  if (!TN)
602
0
    return false;
603
48
604
48
  return TN->hasAttr<CapabilityAttr>();
605
48
}
606
607
2.88k
static bool typeHasCapability(Sema &S, QualType Ty) {
608
2.88k
  if (checkTypedefTypeForCapability(Ty))
609
48
    return true;
610
2.84k
611
2.84k
  if (checkRecordTypeForCapability(S, Ty))
612
2.56k
    return true;
613
271
614
271
  return false;
615
271
}
616
617
203
static bool isCapabilityExpr(Sema &S, const Expr *Ex) {
618
203
  // Capability expressions are simple expressions involving the boolean logic
619
203
  // operators &&, || or !, a simple DeclRefExpr, CastExpr or a ParenExpr. Once
620
203
  // a DeclRefExpr is found, its type should be checked to determine whether it
621
203
  // is a capability or not.
622
203
623
203
  if (const auto *E = dyn_cast<CastExpr>(Ex))
624
26
    return isCapabilityExpr(S, E->getSubExpr());
625
177
  else if (const auto *E = dyn_cast<ParenExpr>(Ex))
626
1
    return isCapabilityExpr(S, E->getSubExpr());
627
176
  else if (const auto *E = dyn_cast<UnaryOperator>(Ex)) {
628
26
    if (E->getOpcode() == UO_LNot || 
E->getOpcode() == UO_AddrOf12
||
629
26
        
E->getOpcode() == UO_Deref3
)
630
26
      return isCapabilityExpr(S, E->getSubExpr());
631
0
    return false;
632
150
  } else if (const auto *E = dyn_cast<BinaryOperator>(Ex)) {
633
5
    if (E->getOpcode() == BO_LAnd || 
E->getOpcode() == BO_LOr2
)
634
5
      return isCapabilityExpr(S, E->getLHS()) &&
635
5
             isCapabilityExpr(S, E->getRHS());
636
0
    return false;
637
0
  }
638
145
639
145
  return typeHasCapability(S, Ex->getType());
640
145
}
641
642
/// Checks that all attribute arguments, starting from Sidx, resolve to
643
/// a capability object.
644
/// \param Sidx The attribute argument index to start checking with.
645
/// \param ParamIdxOk Whether an argument can be indexing into a function
646
/// parameter list.
647
static void checkAttrArgsAreCapabilityObjs(Sema &S, Decl *D,
648
                                           const ParsedAttr &AL,
649
                                           SmallVectorImpl<Expr *> &Args,
650
                                           unsigned Sidx = 0,
651
2.97k
                                           bool ParamIdxOk = false) {
652
2.97k
  if (Sidx == AL.getNumArgs()) {
653
419
    // If we don't have any capability arguments, the attribute implicitly
654
419
    // refers to 'this'. So we need to make sure that 'this' exists, i.e. we're
655
419
    // a non-static method, and that the class is a (scoped) capability.
656
419
    const auto *MD = dyn_cast<const CXXMethodDecl>(D);
657
419
    if (MD && 
!MD->isStatic()374
) {
658
374
      const CXXRecordDecl *RD = MD->getParent();
659
374
      // FIXME -- need to check this again on template instantiation
660
374
      if (!checkRecordDeclForAttr<CapabilityAttr>(RD) &&
661
374
          
!checkRecordDeclForAttr<ScopedLockableAttr>(RD)166
)
662
25
        S.Diag(AL.getLoc(),
663
25
               diag::warn_thread_attribute_not_on_capability_member)
664
25
            << AL << MD->getParent();
665
374
    } else {
666
45
      S.Diag(AL.getLoc(), diag::warn_thread_attribute_not_on_non_static_member)
667
45
          << AL;
668
45
    }
669
419
  }
670
2.97k
671
5.72k
  for (unsigned Idx = Sidx; Idx < AL.getNumArgs(); 
++Idx2.75k
) {
672
2.75k
    Expr *ArgExp = AL.getArgAsExpr(Idx);
673
2.75k
674
2.75k
    if (ArgExp->isTypeDependent()) {
675
101
      // FIXME -- need to check this again on template instantiation
676
101
      Args.push_back(ArgExp);
677
101
      continue;
678
101
    }
679
2.65k
680
2.65k
    if (const auto *StrLit = dyn_cast<StringLiteral>(ArgExp)) {
681
104
      if (StrLit->getLength() == 0 ||
682
104
          
(70
StrLit->isAscii()70
&&
StrLit->getString() == StringRef("*")67
)) {
683
62
        // Pass empty strings to the analyzer without warnings.
684
62
        // Treat "*" as the universal lock.
685
62
        Args.push_back(ArgExp);
686
62
        continue;
687
62
      }
688
42
689
42
      // We allow constant strings to be used as a placeholder for expressions
690
42
      // that are not valid C++ syntax, but warn that they are ignored.
691
42
      S.Diag(AL.getLoc(), diag::warn_thread_attribute_ignored) << AL;
692
42
      Args.push_back(ArgExp);
693
42
      continue;
694
42
    }
695
2.54k
696
2.54k
    QualType ArgTy = ArgExp->getType();
697
2.54k
698
2.54k
    // A pointer to member expression of the form  &MyClass::mu is treated
699
2.54k
    // specially -- we need to look at the type of the member.
700
2.54k
    if (const auto *UOp = dyn_cast<UnaryOperator>(ArgExp))
701
128
      if (UOp->getOpcode() == UO_AddrOf)
702
76
        if (const auto *DRE = dyn_cast<DeclRefExpr>(UOp->getSubExpr()))
703
76
          if (DRE->getDecl()->isCXXInstanceMember())
704
37
            ArgTy = DRE->getDecl()->getType();
705
2.54k
706
2.54k
    // First see if we can just cast to record type, or pointer to record type.
707
2.54k
    const RecordType *RT = getRecordType(ArgTy);
708
2.54k
709
2.54k
    // Now check if we index into a record type function param.
710
2.54k
    if(!RT && 
ParamIdxOk186
) {
711
89
      const auto *FD = dyn_cast<FunctionDecl>(D);
712
89
      const auto *IL = dyn_cast<IntegerLiteral>(ArgExp);
713
89
      if(FD && IL) {
714
63
        unsigned int NumParams = FD->getNumParams();
715
63
        llvm::APInt ArgValue = IL->getValue();
716
63
        uint64_t ParamIdxFromOne = ArgValue.getZExtValue();
717
63
        uint64_t ParamIdxFromZero = ParamIdxFromOne - 1;
718
63
        if (!ArgValue.isStrictlyPositive() || 
ParamIdxFromOne > NumParams36
) {
719
36
          S.Diag(AL.getLoc(),
720
36
                 diag::err_attribute_argument_out_of_bounds_extra_info)
721
36
              << AL << Idx + 1 << NumParams;
722
36
          continue;
723
36
        }
724
27
        ArgTy = FD->getParamDecl(ParamIdxFromZero)->getType();
725
27
      }
726
89
    }
727
2.54k
728
2.54k
    // If the type does not have a capability, see if the components of the
729
2.54k
    // expression have capabilities. This allows for writing C code where the
730
2.54k
    // capability may be on the type, and the expression is a capability
731
2.54k
    // boolean logic expression. Eg) requires_capability(A || B && !C)
732
2.54k
    
if (2.51k
!typeHasCapability(S, ArgTy)2.51k
&&
!isCapabilityExpr(S, ArgExp)140
)
733
125
      S.Diag(AL.getLoc(), diag::warn_thread_attribute_argument_not_lockable)
734
125
          << AL << ArgTy;
735
2.51k
736
2.51k
    Args.push_back(ArgExp);
737
2.51k
  }
738
2.97k
}
739
740
//===----------------------------------------------------------------------===//
741
// Attribute Implementations
742
//===----------------------------------------------------------------------===//
743
744
21
static void handlePtGuardedVarAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
745
21
  if (!threadSafetyCheckIsPointer(S, D, AL))
746
10
    return;
747
11
748
11
  D->addAttr(::new (S.Context)
749
11
             PtGuardedVarAttr(AL.getRange(), S.Context,
750
11
                              AL.getAttributeSpellingListIndex()));
751
11
}
752
753
static bool checkGuardedByAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
754
681
                                     Expr *&Arg) {
755
681
  SmallVector<Expr *, 1> Args;
756
681
  // check that all arguments are lockable objects
757
681
  checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
758
681
  unsigned Size = Args.size();
759
681
  if (Size != 1)
760
0
    return false;
761
681
762
681
  Arg = Args[0];
763
681
764
681
  return true;
765
681
}
766
767
549
static void handleGuardedByAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
768
549
  Expr *Arg = nullptr;
769
549
  if (!checkGuardedByAttrCommon(S, D, AL, Arg))
770
0
    return;
771
549
772
549
  D->addAttr(::new (S.Context) GuardedByAttr(
773
549
      AL.getRange(), S.Context, Arg, AL.getAttributeSpellingListIndex()));
774
549
}
775
776
132
static void handlePtGuardedByAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
777
132
  Expr *Arg = nullptr;
778
132
  if (!checkGuardedByAttrCommon(S, D, AL, Arg))
779
0
    return;
780
132
781
132
  if (!threadSafetyCheckIsPointer(S, D, AL))
782
7
    return;
783
125
784
125
  D->addAttr(::new (S.Context) PtGuardedByAttr(
785
125
      AL.getRange(), S.Context, Arg, AL.getAttributeSpellingListIndex()));
786
125
}
787
788
static bool checkAcquireOrderAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
789
245
                                        SmallVectorImpl<Expr *> &Args) {
790
245
  if (!checkAttributeAtLeastNumArgs(S, AL, 1))
791
12
    return false;
792
233
793
233
  // Check that this attribute only applies to lockable types.
794
233
  QualType QT = cast<ValueDecl>(D)->getType();
795
233
  if (!QT->isDependentType() && !typeHasCapability(S, QT)) {
796
6
    S.Diag(AL.getLoc(), diag::warn_thread_attribute_decl_not_lockable) << AL;
797
6
    return false;
798
6
  }
799
227
800
227
  // Check that all arguments are lockable objects.
801
227
  checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
802
227
  if (Args.empty())
803
0
    return false;
804
227
805
227
  return true;
806
227
}
807
808
142
static void handleAcquiredAfterAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
809
142
  SmallVector<Expr *, 1> Args;
810
142
  if (!checkAcquireOrderAttrCommon(S, D, AL, Args))
811
9
    return;
812
133
813
133
  Expr **StartArg = &Args[0];
814
133
  D->addAttr(::new (S.Context) AcquiredAfterAttr(
815
133
      AL.getRange(), S.Context, StartArg, Args.size(),
816
133
      AL.getAttributeSpellingListIndex()));
817
133
}
818
819
103
static void handleAcquiredBeforeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
820
103
  SmallVector<Expr *, 1> Args;
821
103
  if (!checkAcquireOrderAttrCommon(S, D, AL, Args))
822
9
    return;
823
94
824
94
  Expr **StartArg = &Args[0];
825
94
  D->addAttr(::new (S.Context) AcquiredBeforeAttr(
826
94
      AL.getRange(), S.Context, StartArg, Args.size(),
827
94
      AL.getAttributeSpellingListIndex()));
828
94
}
829
830
static bool checkLockFunAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
831
551
                                   SmallVectorImpl<Expr *> &Args) {
832
551
  // zero or more arguments ok
833
551
  // check that all arguments are lockable objects
834
551
  checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 0, /*ParamIdxOk=*/true);
835
551
836
551
  return true;
837
551
}
838
839
13
static void handleAssertSharedLockAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
840
13
  SmallVector<Expr *, 1> Args;
841
13
  if (!checkLockFunAttrCommon(S, D, AL, Args))
842
0
    return;
843
13
844
13
  unsigned Size = Args.size();
845
13
  Expr **StartArg = Size == 0 ? 
nullptr7
:
&Args[0]6
;
846
13
  D->addAttr(::new (S.Context)
847
13
                 AssertSharedLockAttr(AL.getRange(), S.Context, StartArg, Size,
848
13
                                      AL.getAttributeSpellingListIndex()));
849
13
}
850
851
static void handleAssertExclusiveLockAttr(Sema &S, Decl *D,
852
15
                                          const ParsedAttr &AL) {
853
15
  SmallVector<Expr *, 1> Args;
854
15
  if (!checkLockFunAttrCommon(S, D, AL, Args))
855
0
    return;
856
15
857
15
  unsigned Size = Args.size();
858
15
  Expr **StartArg = Size == 0 ? 
nullptr7
:
&Args[0]8
;
859
15
  D->addAttr(::new (S.Context) AssertExclusiveLockAttr(
860
15
      AL.getRange(), S.Context, StartArg, Size,
861
15
      AL.getAttributeSpellingListIndex()));
862
15
}
863
864
/// Checks to be sure that the given parameter number is in bounds, and
865
/// is an integral type. Will emit appropriate diagnostics if this returns
866
/// false.
867
///
868
/// AttrArgNo is used to actually retrieve the argument, so it's base-0.
869
template <typename AttrInfo>
870
static bool checkParamIsIntegerType(Sema &S, const FunctionDecl *FD,
871
12.7k
                                    const AttrInfo &AI, unsigned AttrArgNo) {
872
12.7k
  assert(AI.isArgExpr(AttrArgNo) && "Expected expression argument");
873
12.7k
  Expr *AttrArg = AI.getArgAsExpr(AttrArgNo);
874
12.7k
  ParamIdx Idx;
875
12.7k
  if (!checkFunctionOrMethodParameterIndex(S, FD, AI, AttrArgNo + 1, AttrArg,
876
12.7k
                                           Idx))
877
6
    return false;
878
12.7k
879
12.7k
  const ParmVarDecl *Param = FD->getParamDecl(Idx.getASTIndex());
880
12.7k
  if (!Param->getType()->isIntegerType() && 
!Param->getType()->isCharType()1
) {
881
1
    SourceLocation SrcLoc = AttrArg->getBeginLoc();
882
1
    S.Diag(SrcLoc, diag::err_attribute_integers_only)
883
1
        << AI << Param->getSourceRange();
884
1
    return false;
885
1
  }
886
12.7k
  return true;
887
12.7k
}
888
889
10.6k
static void handleAllocSizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
890
10.6k
  if (!checkAttributeAtLeastNumArgs(S, AL, 1) ||
891
10.6k
      !checkAttributeAtMostNumArgs(S, AL, 2))
892
0
    return;
893
10.6k
894
10.6k
  const auto *FD = cast<FunctionDecl>(D);
895
10.6k
  if (!FD->getReturnType()->isPointerType()) {
896
1
    S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only) << AL;
897
1
    return;
898
1
  }
899
10.6k
900
10.6k
  const Expr *SizeExpr = AL.getArgAsExpr(0);
901
10.6k
  int SizeArgNoVal;
902
10.6k
  // Parameter indices are 1-indexed, hence Index=1
903
10.6k
  if (!checkPositiveIntArgument(S, AL, SizeExpr, SizeArgNoVal, /*Idx=*/1))
904
2
    return;
905
10.6k
  if (!checkParamIsIntegerType(S, FD, AL, /*AttrArgNo=*/0))
906
5
    return;
907
10.6k
  ParamIdx SizeArgNo(SizeArgNoVal, D);
908
10.6k
909
10.6k
  ParamIdx NumberArgNo;
910
10.6k
  if (AL.getNumArgs() == 2) {
911
2.16k
    const Expr *NumberExpr = AL.getArgAsExpr(1);
912
2.16k
    int Val;
913
2.16k
    // Parameter indices are 1-based, hence Index=2
914
2.16k
    if (!checkPositiveIntArgument(S, AL, NumberExpr, Val, /*Idx=*/2))
915
1
      return;
916
2.16k
    if (!checkParamIsIntegerType(S, FD, AL, /*AttrArgNo=*/1))
917
2
      return;
918
2.16k
    NumberArgNo = ParamIdx(Val, D);
919
2.16k
  }
920
10.6k
921
10.6k
  D->addAttr(::new (S.Context)
922
10.5k
                 AllocSizeAttr(AL.getRange(), S.Context, SizeArgNo, NumberArgNo,
923
10.5k
                               AL.getAttributeSpellingListIndex()));
924
10.5k
}
925
926
static bool checkTryLockFunAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
927
176
                                      SmallVectorImpl<Expr *> &Args) {
928
176
  if (!checkAttributeAtLeastNumArgs(S, AL, 1))
929
0
    return false;
930
176
931
176
  if (!isIntOrBool(AL.getArgAsExpr(0))) {
932
18
    S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
933
18
        << AL << 1 << AANT_ArgumentIntOrBool;
934
18
    return false;
935
18
  }
936
158
937
158
  // check that all arguments are lockable objects
938
158
  checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 1);
939
158
940
158
  return true;
941
158
}
942
943
static void handleSharedTrylockFunctionAttr(Sema &S, Decl *D,
944
70
                                            const ParsedAttr &AL) {
945
70
  SmallVector<Expr*, 2> Args;
946
70
  if (!checkTryLockFunAttrCommon(S, D, AL, Args))
947
9
    return;
948
61
949
61
  D->addAttr(::new (S.Context) SharedTrylockFunctionAttr(
950
61
      AL.getRange(), S.Context, AL.getArgAsExpr(0), Args.data(), Args.size(),
951
61
      AL.getAttributeSpellingListIndex()));
952
61
}
953
954
static void handleExclusiveTrylockFunctionAttr(Sema &S, Decl *D,
955
78
                                               const ParsedAttr &AL) {
956
78
  SmallVector<Expr*, 2> Args;
957
78
  if (!checkTryLockFunAttrCommon(S, D, AL, Args))
958
9
    return;
959
69
960
69
  D->addAttr(::new (S.Context) ExclusiveTrylockFunctionAttr(
961
69
      AL.getRange(), S.Context, AL.getArgAsExpr(0), Args.data(),
962
69
      Args.size(), AL.getAttributeSpellingListIndex()));
963
69
}
964
965
80
static void handleLockReturnedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
966
80
  // check that the argument is lockable object
967
80
  SmallVector<Expr*, 1> Args;
968
80
  checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
969
80
  unsigned Size = Args.size();
970
80
  if (Size == 0)
971
0
    return;
972
80
973
80
  D->addAttr(::new (S.Context)
974
80
             LockReturnedAttr(AL.getRange(), S.Context, Args[0],
975
80
                              AL.getAttributeSpellingListIndex()));
976
80
}
977
978
136
static void handleLocksExcludedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
979
136
  if (!checkAttributeAtLeastNumArgs(S, AL, 1))
980
3
    return;
981
133
982
133
  // check that all arguments are lockable objects
983
133
  SmallVector<Expr*, 1> Args;
984
133
  checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
985
133
  unsigned Size = Args.size();
986
133
  if (Size == 0)
987
0
    return;
988
133
  Expr **StartArg = &Args[0];
989
133
990
133
  D->addAttr(::new (S.Context)
991
133
             LocksExcludedAttr(AL.getRange(), S.Context, StartArg, Size,
992
133
                               AL.getAttributeSpellingListIndex()));
993
133
}
994
995
static bool checkFunctionConditionAttr(Sema &S, Decl *D, const ParsedAttr &AL,
996
19.2k
                                       Expr *&Cond, StringRef &Msg) {
997
19.2k
  Cond = AL.getArgAsExpr(0);
998
19.2k
  if (!Cond->isTypeDependent()) {
999
18.9k
    ExprResult Converted = S.PerformContextuallyConvertToBool(Cond);
1000
18.9k
    if (Converted.isInvalid())
1001
0
      return false;
1002
18.9k
    Cond = Converted.get();
1003
18.9k
  }
1004
19.2k
1005
19.2k
  if (!S.checkStringLiteralArgumentAttr(AL, 1, Msg))
1006
2
    return false;
1007
19.2k
1008
19.2k
  if (Msg.empty())
1009
13.1k
    Msg = "<no message provided>";
1010
19.2k
1011
19.2k
  SmallVector<PartialDiagnosticAt, 8> Diags;
1012
19.2k
  if (isa<FunctionDecl>(D) && 
!Cond->isValueDependent()19.2k
&&
1013
19.2k
      !Expr::isPotentialConstantExprUnevaluated(Cond, cast<FunctionDecl>(D),
1014
18.9k
                                                Diags)) {
1015
3
    S.Diag(AL.getLoc(), diag::err_attr_cond_never_constant_expr) << AL;
1016
3
    for (const PartialDiagnosticAt &PDiag : Diags)
1017
3
      S.Diag(PDiag.first, PDiag.second);
1018
3
    return false;
1019
3
  }
1020
19.2k
  return true;
1021
19.2k
}
1022
1023
14.0k
static void handleEnableIfAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1024
14.0k
  S.Diag(AL.getLoc(), diag::ext_clang_enable_if);
1025
14.0k
1026
14.0k
  Expr *Cond;
1027
14.0k
  StringRef Msg;
1028
14.0k
  if (checkFunctionConditionAttr(S, D, AL, Cond, Msg))
1029
14.0k
    D->addAttr(::new (S.Context)
1030
14.0k
                   EnableIfAttr(AL.getRange(), S.Context, Cond, Msg,
1031
14.0k
                                AL.getAttributeSpellingListIndex()));
1032
14.0k
}
1033
1034
namespace {
1035
/// Determines if a given Expr references any of the given function's
1036
/// ParmVarDecls, or the function's implicit `this` parameter (if applicable).
1037
class ArgumentDependenceChecker
1038
    : public RecursiveASTVisitor<ArgumentDependenceChecker> {
1039
#ifndef NDEBUG
1040
  const CXXRecordDecl *ClassType;
1041
#endif
1042
  llvm::SmallPtrSet<const ParmVarDecl *, 16> Parms;
1043
  bool Result;
1044
1045
public:
1046
5.14k
  ArgumentDependenceChecker(const FunctionDecl *FD) {
1047
#ifndef NDEBUG
1048
    if (const auto *MD = dyn_cast<CXXMethodDecl>(FD))
1049
      ClassType = MD->getParent();
1050
    else
1051
      ClassType = nullptr;
1052
#endif
1053
    Parms.insert(FD->param_begin(), FD->param_end());
1054
5.14k
  }
1055
1056
5.14k
  bool referencesArgs(Expr *E) {
1057
5.14k
    Result = false;
1058
5.14k
    TraverseStmt(E);
1059
5.14k
    return Result;
1060
5.14k
  }
1061
1062
27
  bool VisitCXXThisExpr(CXXThisExpr *E) {
1063
27
    assert(E->getType()->getPointeeCXXRecordDecl() == ClassType &&
1064
27
           "`this` doesn't refer to the enclosing class?");
1065
27
    Result = true;
1066
27
    return false;
1067
27
  }
1068
1069
4.82k
  bool VisitDeclRefExpr(DeclRefExpr *DRE) {
1070
4.82k
    if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl()))
1071
4.81k
      if (Parms.count(PVD)) {
1072
4.81k
        Result = true;
1073
4.81k
        return false;
1074
4.81k
      }
1075
12
    return true;
1076
12
  }
1077
};
1078
}
1079
1080
5.15k
static void handleDiagnoseIfAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1081
5.15k
  S.Diag(AL.getLoc(), diag::ext_clang_diagnose_if);
1082
5.15k
1083
5.15k
  Expr *Cond;
1084
5.15k
  StringRef Msg;
1085
5.15k
  if (!checkFunctionConditionAttr(S, D, AL, Cond, Msg))
1086
3
    return;
1087
5.14k
1088
5.14k
  StringRef DiagTypeStr;
1089
5.14k
  if (!S.checkStringLiteralArgumentAttr(AL, 2, DiagTypeStr))
1090
0
    return;
1091
5.14k
1092
5.14k
  DiagnoseIfAttr::DiagnosticType DiagType;
1093
5.14k
  if (!DiagnoseIfAttr::ConvertStrToDiagnosticType(DiagTypeStr, DiagType)) {
1094
3
    S.Diag(AL.getArgAsExpr(2)->getBeginLoc(),
1095
3
           diag::err_diagnose_if_invalid_diagnostic_type);
1096
3
    return;
1097
3
  }
1098
5.14k
1099
5.14k
  bool ArgDependent = false;
1100
5.14k
  if (const auto *FD = dyn_cast<FunctionDecl>(D))
1101
5.14k
    ArgDependent = ArgumentDependenceChecker(FD).referencesArgs(Cond);
1102
5.14k
  D->addAttr(::new (S.Context) DiagnoseIfAttr(
1103
5.14k
      AL.getRange(), S.Context, Cond, Msg, DiagType, ArgDependent,
1104
5.14k
      cast<NamedDecl>(D), AL.getAttributeSpellingListIndex()));
1105
5.14k
}
1106
1107
138
static void handlePassObjectSizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1108
138
  if (D->hasAttr<PassObjectSizeAttr>()) {
1109
1
    S.Diag(D->getBeginLoc(), diag::err_attribute_only_once_per_parameter) << AL;
1110
1
    return;
1111
1
  }
1112
137
1113
137
  Expr *E = AL.getArgAsExpr(0);
1114
137
  uint32_t Type;
1115
137
  if (!checkUInt32Argument(S, AL, E, Type, /*Idx=*/1))
1116
2
    return;
1117
135
1118
135
  // pass_object_size's argument is passed in as the second argument of
1119
135
  // __builtin_object_size. So, it has the same constraints as that second
1120
135
  // argument; namely, it must be in the range [0, 3].
1121
135
  if (Type > 3) {
1122
2
    S.Diag(E->getBeginLoc(), diag::err_attribute_argument_out_of_range)
1123
2
        << AL << 0 << 3 << E->getSourceRange();
1124
2
    return;
1125
2
  }
1126
133
1127
133
  // pass_object_size is only supported on constant pointer parameters; as a
1128
133
  // kindness to users, we allow the parameter to be non-const for declarations.
1129
133
  // At this point, we have no clue if `D` belongs to a function declaration or
1130
133
  // definition, so we defer the constness check until later.
1131
133
  if (!cast<ParmVarDecl>(D)->getType()->isPointerType()) {
1132
3
    S.Diag(D->getBeginLoc(), diag::err_attribute_pointers_only) << AL << 1;
1133
3
    return;
1134
3
  }
1135
130
1136
130
  D->addAttr(::new (S.Context) PassObjectSizeAttr(
1137
130
      AL.getRange(), S.Context, (int)Type, AL.getAttributeSpellingListIndex()));
1138
130
}
1139
1140
7
static void handleConsumableAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1141
7
  ConsumableAttr::ConsumedState DefaultState;
1142
7
1143
7
  if (AL.isArgIdent(0)) {
1144
6
    IdentifierLoc *IL = AL.getArgAsIdent(0);
1145
6
    if (!ConsumableAttr::ConvertStrToConsumedState(IL->Ident->getName(),
1146
6
                                                   DefaultState)) {
1147
0
      S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL
1148
0
                                                               << IL->Ident;
1149
0
      return;
1150
0
    }
1151
1
  } else {
1152
1
    S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1153
1
        << AL << AANT_ArgumentIdentifier;
1154
1
    return;
1155
1
  }
1156
6
1157
6
  D->addAttr(::new (S.Context)
1158
6
             ConsumableAttr(AL.getRange(), S.Context, DefaultState,
1159
6
                            AL.getAttributeSpellingListIndex()));
1160
6
}
1161
1162
static bool checkForConsumableClass(Sema &S, const CXXMethodDecl *MD,
1163
31
                                    const ParsedAttr &AL) {
1164
31
  QualType ThisType = MD->getThisType()->getPointeeType();
1165
31
1166
31
  if (const CXXRecordDecl *RD = ThisType->getAsCXXRecordDecl()) {
1167
31
    if (!RD->hasAttr<ConsumableAttr>()) {
1168
3
      S.Diag(AL.getLoc(), diag::warn_attr_on_unconsumable_class) <<
1169
3
        RD->getNameAsString();
1170
3
1171
3
      return false;
1172
3
    }
1173
28
  }
1174
28
1175
28
  return true;
1176
28
}
1177
1178
16
static void handleCallableWhenAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1179
16
  if (!checkAttributeAtLeastNumArgs(S, AL, 1))
1180
1
    return;
1181
15
1182
15
  if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), AL))
1183
1
    return;
1184
14
1185
14
  SmallVector<CallableWhenAttr::ConsumedState, 3> States;
1186
32
  for (unsigned ArgIndex = 0; ArgIndex < AL.getNumArgs(); 
++ArgIndex18
) {
1187
20
    CallableWhenAttr::ConsumedState CallableState;
1188
20
1189
20
    StringRef StateString;
1190
20
    SourceLocation Loc;
1191
20
    if (AL.isArgIdent(ArgIndex)) {
1192
1
      IdentifierLoc *Ident = AL.getArgAsIdent(ArgIndex);
1193
1
      StateString = Ident->Ident->getName();
1194
1
      Loc = Ident->Loc;
1195
19
    } else {
1196
19
      if (!S.checkStringLiteralArgumentAttr(AL, ArgIndex, StateString, &Loc))
1197
1
        return;
1198
19
    }
1199
19
1200
19
    if (!CallableWhenAttr::ConvertStrToConsumedState(StateString,
1201
19
                                                     CallableState)) {
1202
1
      S.Diag(Loc, diag::warn_attribute_type_not_supported) << AL << StateString;
1203
1
      return;
1204
1
    }
1205
18
1206
18
    States.push_back(CallableState);
1207
18
  }
1208
14
1209
14
  D->addAttr(::new (S.Context)
1210
12
             CallableWhenAttr(AL.getRange(), S.Context, States.data(),
1211
12
               States.size(), AL.getAttributeSpellingListIndex()));
1212
12
}
1213
1214
7
static void handleParamTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1215
7
  ParamTypestateAttr::ConsumedState ParamState;
1216
7
1217
7
  if (AL.isArgIdent(0)) {
1218
7
    IdentifierLoc *Ident = AL.getArgAsIdent(0);
1219
7
    StringRef StateString = Ident->Ident->getName();
1220
7
1221
7
    if (!ParamTypestateAttr::ConvertStrToConsumedState(StateString,
1222
7
                                                       ParamState)) {
1223
0
      S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported)
1224
0
          << AL << StateString;
1225
0
      return;
1226
0
    }
1227
0
  } else {
1228
0
    S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1229
0
        << AL << AANT_ArgumentIdentifier;
1230
0
    return;
1231
0
  }
1232
7
1233
7
  // FIXME: This check is currently being done in the analysis.  It can be
1234
7
  //        enabled here only after the parser propagates attributes at
1235
7
  //        template specialization definition, not declaration.
1236
7
  //QualType ReturnType = cast<ParmVarDecl>(D)->getType();
1237
7
  //const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
1238
7
  //
1239
7
  //if (!RD || !RD->hasAttr<ConsumableAttr>()) {
1240
7
  //    S.Diag(AL.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
1241
7
  //      ReturnType.getAsString();
1242
7
  //    return;
1243
7
  //}
1244
7
1245
7
  D->addAttr(::new (S.Context)
1246
7
             ParamTypestateAttr(AL.getRange(), S.Context, ParamState,
1247
7
                                AL.getAttributeSpellingListIndex()));
1248
7
}
1249
1250
12
static void handleReturnTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1251
12
  ReturnTypestateAttr::ConsumedState ReturnState;
1252
12
1253
12
  if (AL.isArgIdent(0)) {
1254
11
    IdentifierLoc *IL = AL.getArgAsIdent(0);
1255
11
    if (!ReturnTypestateAttr::ConvertStrToConsumedState(IL->Ident->getName(),
1256
11
                                                        ReturnState)) {
1257
1
      S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL
1258
1
                                                               << IL->Ident;
1259
1
      return;
1260
1
    }
1261
1
  } else {
1262
1
    S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1263
1
        << AL << AANT_ArgumentIdentifier;
1264
1
    return;
1265
1
  }
1266
10
1267
10
  // FIXME: This check is currently being done in the analysis.  It can be
1268
10
  //        enabled here only after the parser propagates attributes at
1269
10
  //        template specialization definition, not declaration.
1270
10
  //QualType ReturnType;
1271
10
  //
1272
10
  //if (const ParmVarDecl *Param = dyn_cast<ParmVarDecl>(D)) {
1273
10
  //  ReturnType = Param->getType();
1274
10
  //
1275
10
  //} else if (const CXXConstructorDecl *Constructor =
1276
10
  //             dyn_cast<CXXConstructorDecl>(D)) {
1277
10
  //  ReturnType = Constructor->getThisType()->getPointeeType();
1278
10
  //
1279
10
  //} else {
1280
10
  //
1281
10
  //  ReturnType = cast<FunctionDecl>(D)->getCallResultType();
1282
10
  //}
1283
10
  //
1284
10
  //const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
1285
10
  //
1286
10
  //if (!RD || !RD->hasAttr<ConsumableAttr>()) {
1287
10
  //    S.Diag(Attr.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
1288
10
  //      ReturnType.getAsString();
1289
10
  //    return;
1290
10
  //}
1291
10
1292
10
  D->addAttr(::new (S.Context)
1293
10
                 ReturnTypestateAttr(AL.getRange(), S.Context, ReturnState,
1294
10
                                     AL.getAttributeSpellingListIndex()));
1295
10
}
1296
1297
10
static void handleSetTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1298
10
  if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), AL))
1299
1
    return;
1300
9
1301
9
  SetTypestateAttr::ConsumedState NewState;
1302
9
  if (AL.isArgIdent(0)) {
1303
9
    IdentifierLoc *Ident = AL.getArgAsIdent(0);
1304
9
    StringRef Param = Ident->Ident->getName();
1305
9
    if (!SetTypestateAttr::ConvertStrToConsumedState(Param, NewState)) {
1306
0
      S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL
1307
0
                                                                  << Param;
1308
0
      return;
1309
0
    }
1310
0
  } else {
1311
0
    S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1312
0
        << AL << AANT_ArgumentIdentifier;
1313
0
    return;
1314
0
  }
1315
9
1316
9
  D->addAttr(::new (S.Context)
1317
9
             SetTypestateAttr(AL.getRange(), S.Context, NewState,
1318
9
                              AL.getAttributeSpellingListIndex()));
1319
9
}
1320
1321
6
static void handleTestTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1322
6
  if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), AL))
1323
1
    return;
1324
5
1325
5
  TestTypestateAttr::ConsumedState TestState;
1326
5
  if (AL.isArgIdent(0)) {
1327
5
    IdentifierLoc *Ident = AL.getArgAsIdent(0);
1328
5
    StringRef Param = Ident->Ident->getName();
1329
5
    if (!TestTypestateAttr::ConvertStrToConsumedState(Param, TestState)) {
1330
0
      S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL
1331
0
                                                                  << Param;
1332
0
      return;
1333
0
    }
1334
0
  } else {
1335
0
    S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1336
0
        << AL << AANT_ArgumentIdentifier;
1337
0
    return;
1338
0
  }
1339
5
1340
5
  D->addAttr(::new (S.Context)
1341
5
             TestTypestateAttr(AL.getRange(), S.Context, TestState,
1342
5
                                AL.getAttributeSpellingListIndex()));
1343
5
}
1344
1345
2.00k
static void handleExtVectorTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1346
2.00k
  // Remember this typedef decl, we will need it later for diagnostics.
1347
2.00k
  S.ExtVectorDecls.push_back(cast<TypedefNameDecl>(D));
1348
2.00k
}
1349
1350
15.6k
static void handlePackedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1351
15.6k
  if (auto *TD = dyn_cast<TagDecl>(D))
1352
15.3k
    TD->addAttr(::new (S.Context) PackedAttr(AL.getRange(), S.Context,
1353
15.3k
                                        AL.getAttributeSpellingListIndex()));
1354
211
  else if (auto *FD = dyn_cast<FieldDecl>(D)) {
1355
201
    bool BitfieldByteAligned = (!FD->getType()->isDependentType() &&
1356
201
                                
!FD->getType()->isIncompleteType()200
&&
1357
201
                                
FD->isBitField()197
&&
1358
201
                                
S.Context.getTypeAlign(FD->getType()) <= 830
);
1359
201
1360
201
    if (S.getASTContext().getTargetInfo().getTriple().isPS4()) {
1361
6
      if (BitfieldByteAligned)
1362
1
        // The PS4 target needs to maintain ABI backwards compatibility.
1363
1
        S.Diag(AL.getLoc(), diag::warn_attribute_ignored_for_field_of_type)
1364
1
            << AL << FD->getType();
1365
5
      else
1366
5
        FD->addAttr(::new (S.Context) PackedAttr(
1367
5
                    AL.getRange(), S.Context, AL.getAttributeSpellingListIndex()));
1368
195
    } else {
1369
195
      // Report warning about changed offset in the newer compiler versions.
1370
195
      if (BitfieldByteAligned)
1371
2
        S.Diag(AL.getLoc(), diag::warn_attribute_packed_for_bitfield);
1372
195
1373
195
      FD->addAttr(::new (S.Context) PackedAttr(
1374
195
                  AL.getRange(), S.Context, AL.getAttributeSpellingListIndex()));
1375
195
    }
1376
201
1377
201
  } else
1378
10
    S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL;
1379
15.6k
}
1380
1381
84
static bool checkIBOutletCommon(Sema &S, Decl *D, const ParsedAttr &AL) {
1382
84
  // The IBOutlet/IBOutletCollection attributes only apply to instance
1383
84
  // variables or properties of Objective-C classes.  The outlet must also
1384
84
  // have an object reference type.
1385
84
  if (const auto *VD = dyn_cast<ObjCIvarDecl>(D)) {
1386
38
    if (!VD->getType()->getAs<ObjCObjectPointerType>()) {
1387
10
      S.Diag(AL.getLoc(), diag::warn_iboutlet_object_type)
1388
10
          << AL << VD->getType() << 0;
1389
10
      return false;
1390
10
    }
1391
46
  }
1392
46
  else if (const auto *PD = dyn_cast<ObjCPropertyDecl>(D)) {
1393
46
    if (!PD->getType()->getAs<ObjCObjectPointerType>()) {
1394
8
      S.Diag(AL.getLoc(), diag::warn_iboutlet_object_type)
1395
8
          << AL << PD->getType() << 1;
1396
8
      return false;
1397
8
    }
1398
0
  }
1399
0
  else {
1400
0
    S.Diag(AL.getLoc(), diag::warn_attribute_iboutlet) << AL;
1401
0
    return false;
1402
0
  }
1403
66
1404
66
  return true;
1405
66
}
1406
1407
49
static void handleIBOutlet(Sema &S, Decl *D, const ParsedAttr &AL) {
1408
49
  if (!checkIBOutletCommon(S, D, AL))
1409
14
    return;
1410
35
1411
35
  D->addAttr(::new (S.Context)
1412
35
             IBOutletAttr(AL.getRange(), S.Context,
1413
35
                          AL.getAttributeSpellingListIndex()));
1414
35
}
1415
1416
35
static void handleIBOutletCollection(Sema &S, Decl *D, const ParsedAttr &AL) {
1417
35
1418
35
  // The iboutletcollection attribute can have zero or one arguments.
1419
35
  if (AL.getNumArgs() > 1) {
1420
0
    S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
1421
0
    return;
1422
0
  }
1423
35
1424
35
  if (!checkIBOutletCommon(S, D, AL))
1425
4
    return;
1426
31
1427
31
  ParsedType PT;
1428
31
1429
31
  if (AL.hasParsedType())
1430
23
    PT = AL.getTypeArg();
1431
8
  else {
1432
8
    PT = S.getTypeName(S.Context.Idents.get("NSObject"), AL.getLoc(),
1433
8
                       S.getScopeForContext(D->getDeclContext()->getParent()));
1434
8
    if (!PT) {
1435
0
      S.Diag(AL.getLoc(), diag::err_iboutletcollection_type) << "NSObject";
1436
0
      return;
1437
0
    }
1438
31
  }
1439
31
1440
31
  TypeSourceInfo *QTLoc = nullptr;
1441
31
  QualType QT = S.GetTypeFromParser(PT, &QTLoc);
1442
31
  if (!QTLoc)
1443
8
    QTLoc = S.Context.getTrivialTypeSourceInfo(QT, AL.getLoc());
1444
31
1445
31
  // Diagnose use of non-object type in iboutletcollection attribute.
1446
31
  // FIXME. Gnu attribute extension ignores use of builtin types in
1447
31
  // attributes. So, __attribute__((iboutletcollection(char))) will be
1448
31
  // treated as __attribute__((iboutletcollection())).
1449
31
  if (!QT->isObjCIdType() && 
!QT->isObjCObjectType()26
) {
1450
4
    S.Diag(AL.getLoc(),
1451
4
           QT->isBuiltinType() ? 
diag::err_iboutletcollection_builtintype2
1452
4
                               : 
diag::err_iboutletcollection_type2
) << QT;
1453
4
    return;
1454
4
  }
1455
27
1456
27
  D->addAttr(::new (S.Context)
1457
27
             IBOutletCollectionAttr(AL.getRange(), S.Context, QTLoc,
1458
27
                                    AL.getAttributeSpellingListIndex()));
1459
27
}
1460
1461
6.19k
bool Sema::isValidPointerAttrType(QualType T, bool RefOkay) {
1462
6.19k
  if (RefOkay) {
1463
1.70k
    if (T->isReferenceType())
1464
2
      return true;
1465
4.48k
  } else {
1466
4.48k
    T = T.getNonReferenceType();
1467
4.48k
  }
1468
6.19k
1469
6.19k
  // The nonnull attribute, and other similar attributes, can be applied to a
1470
6.19k
  // transparent union that contains a pointer type.
1471
6.19k
  
if (const RecordType *6.19k
UT6.19k
= T->getAsUnionType()) {
1472
18
    if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) {
1473
18
      RecordDecl *UD = UT->getDecl();
1474
23
      for (const auto *I : UD->fields()) {
1475
23
        QualType QT = I->getType();
1476
23
        if (QT->isAnyPointerType() || 
QT->isBlockPointerType()5
)
1477
18
          return true;
1478
23
      }
1479
18
    }
1480
18
  }
1481
6.19k
1482
6.19k
  
return 6.17k
T->isAnyPointerType()6.17k
||
T->isBlockPointerType()2.01k
;
1483
6.19k
}
1484
1485
static bool attrNonNullArgCheck(Sema &S, QualType T, const ParsedAttr &AL,
1486
                                SourceRange AttrParmRange,
1487
                                SourceRange TypeRange,
1488
4.18k
                                bool isReturnValue = false) {
1489
4.18k
  if (!S.isValidPointerAttrType(T)) {
1490
17
    if (isReturnValue)
1491
6
      S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only)
1492
6
          << AL << AttrParmRange << TypeRange;
1493
11
    else
1494
11
      S.Diag(AL.getLoc(), diag::warn_attribute_pointers_only)
1495
11
          << AL << AttrParmRange << TypeRange << 0;
1496
17
    return false;
1497
17
  }
1498
4.16k
  return true;
1499
4.16k
}
1500
1501
5.93k
static void handleNonNullAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1502
5.93k
  SmallVector<ParamIdx, 8> NonNullArgs;
1503
10.0k
  for (unsigned I = 0; I < AL.getNumArgs(); 
++I4.13k
) {
1504
4.14k
    Expr *Ex = AL.getArgAsExpr(I);
1505
4.14k
    ParamIdx Idx;
1506
4.14k
    if (!checkFunctionOrMethodParameterIndex(S, D, AL, I + 1, Ex, Idx))
1507
5
      return;
1508
4.13k
1509
4.13k
    // Is the function argument a pointer type?
1510
4.13k
    if (Idx.getASTIndex() < getFunctionOrMethodNumParams(D) &&
1511
4.13k
        !attrNonNullArgCheck(
1512
4.12k
            S, getFunctionOrMethodParamType(D, Idx.getASTIndex()), AL,
1513
4.12k
            Ex->getSourceRange(),
1514
4.12k
            getFunctionOrMethodParamRange(D, Idx.getASTIndex())))
1515
7
      continue;
1516
4.12k
1517
4.12k
    NonNullArgs.push_back(Idx);
1518
4.12k
  }
1519
5.93k
1520
5.93k
  // If no arguments were specified to __attribute__((nonnull)) then all pointer
1521
5.93k
  // arguments have a nonnull attribute; warn if there aren't any. Skip this
1522
5.93k
  // check if the attribute came from a macro expansion or a template
1523
5.93k
  // instantiation.
1524
5.93k
  
if (5.93k
NonNullArgs.empty()5.93k
&&
AL.getLoc().isFileID()1.83k
&&
1525
5.93k
      
!S.inTemplateInstantiation()57
) {
1526
57
    bool AnyPointers = isFunctionOrMethodVariadic(D);
1527
57
    for (unsigned I = 0, E = getFunctionOrMethodNumParams(D);
1528
103
         I != E && 
!AnyPointers73
;
++I46
) {
1529
46
      QualType T = getFunctionOrMethodParamType(D, I);
1530
46
      if (T->isDependentType() || 
S.isValidPointerAttrType(T)45
)
1531
39
        AnyPointers = true;
1532
46
    }
1533
57
1534
57
    if (!AnyPointers)
1535
6
      S.Diag(AL.getLoc(), diag::warn_attribute_nonnull_no_pointers);
1536
57
  }
1537
5.93k
1538
5.93k
  ParamIdx *Start = NonNullArgs.data();
1539
5.93k
  unsigned Size = NonNullArgs.size();
1540
5.93k
  llvm::array_pod_sort(Start, Start + Size);
1541
5.93k
  D->addAttr(::new (S.Context)
1542
5.93k
                 NonNullAttr(AL.getRange(), S.Context, Start, Size,
1543
5.93k
                             AL.getAttributeSpellingListIndex()));
1544
5.93k
}
1545
1546
static void handleNonNullAttrParameter(Sema &S, ParmVarDecl *D,
1547
31
                                       const ParsedAttr &AL) {
1548
31
  if (AL.getNumArgs() > 0) {
1549
6
    if (D->getFunctionType()) {
1550
3
      handleNonNullAttr(S, D, AL);
1551
3
    } else {
1552
3
      S.Diag(AL.getLoc(), diag::warn_attribute_nonnull_parm_no_args)
1553
3
        << D->getSourceRange();
1554
3
    }
1555
6
    return;
1556
6
  }
1557
25
1558
25
  // Is the argument a pointer type?
1559
25
  if (!attrNonNullArgCheck(S, D->getType(), AL, SourceRange(),
1560
25
                           D->getSourceRange()))
1561
4
    return;
1562
21
1563
21
  D->addAttr(::new (S.Context)
1564
21
                 NonNullAttr(AL.getRange(), S.Context, nullptr, 0,
1565
21
                             AL.getAttributeSpellingListIndex()));
1566
21
}
1567
1568
27
static void handleReturnsNonNullAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1569
27
  QualType ResultType = getFunctionOrMethodResultType(D);
1570
27
  SourceRange SR = getFunctionOrMethodResultSourceRange(D);
1571
27
  if (!attrNonNullArgCheck(S, ResultType, AL, SourceRange(), SR,
1572
27
                           /* isReturnValue */ true))
1573
6
    return;
1574
21
1575
21
  D->addAttr(::new (S.Context)
1576
21
            ReturnsNonNullAttr(AL.getRange(), S.Context,
1577
21
                               AL.getAttributeSpellingListIndex()));
1578
21
}
1579
1580
1.63k
static void handleNoEscapeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1581
1.63k
  if (D->isInvalidDecl())
1582
0
    return;
1583
1.63k
1584
1.63k
  // noescape only applies to pointer types.
1585
1.63k
  QualType T = cast<ParmVarDecl>(D)->getType();
1586
1.63k
  if (!S.isValidPointerAttrType(T, /* RefOkay */ true)) {
1587
6
    S.Diag(AL.getLoc(), diag::warn_attribute_pointers_only)
1588
6
        << AL << AL.getRange() << 0;
1589
6
    return;
1590
6
  }
1591
1.63k
1592
1.63k
  D->addAttr(::new (S.Context) NoEscapeAttr(
1593
1.63k
      AL.getRange(), S.Context, AL.getAttributeSpellingListIndex()));
1594
1.63k
}
1595
1596
25
static void handleAssumeAlignedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1597
25
  Expr *E = AL.getArgAsExpr(0),
1598
25
       *OE = AL.getNumArgs() > 1 ? 
AL.getArgAsExpr(1)9
:
nullptr16
;
1599
25
  S.AddAssumeAlignedAttr(AL.getRange(), D, E, OE,
1600
25
                         AL.getAttributeSpellingListIndex());
1601
25
}
1602
1603
28
static void handleAllocAlignAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1604
28
  S.AddAllocAlignAttr(AL.getRange(), D, AL.getArgAsExpr(0),
1605
28
                      AL.getAttributeSpellingListIndex());
1606
28
}
1607
1608
void Sema::AddAssumeAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E,
1609
33
                                Expr *OE, unsigned SpellingListIndex) {
1610
33
  QualType ResultType = getFunctionOrMethodResultType(D);
1611
33
  SourceRange SR = getFunctionOrMethodResultSourceRange(D);
1612
33
1613
33
  AssumeAlignedAttr TmpAttr(AttrRange, Context, E, OE, SpellingListIndex);
1614
33
  SourceLocation AttrLoc = AttrRange.getBegin();
1615
33
1616
33
  if (!isValidPointerAttrType(ResultType, /* RefOkay */ true)) {
1617
3
    Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only)
1618
3
      << &TmpAttr << AttrRange << SR;
1619
3
    return;
1620
3
  }
1621
30
1622
30
  if (!E->isValueDependent()) {
1623
26
    llvm::APSInt I(64);
1624
26
    if (!E->isIntegerConstantExpr(I, Context)) {
1625
0
      if (OE)
1626
0
        Diag(AttrLoc, diag::err_attribute_argument_n_type)
1627
0
          << &TmpAttr << 1 << AANT_ArgumentIntegerConstant
1628
0
          << E->getSourceRange();
1629
0
      else
1630
0
        Diag(AttrLoc, diag::err_attribute_argument_type)
1631
0
          << &TmpAttr << AANT_ArgumentIntegerConstant
1632
0
          << E->getSourceRange();
1633
0
      return;
1634
0
    }
1635
26
1636
26
    if (!I.isPowerOf2()) {
1637
5
      Diag(AttrLoc, diag::err_alignment_not_power_of_two)
1638
5
        << E->getSourceRange();
1639
5
      return;
1640
5
    }
1641
25
  }
1642
25
1643
25
  if (OE) {
1644
10
    if (!OE->isValueDependent()) {
1645
8
      llvm::APSInt I(64);
1646
8
      if (!OE->isIntegerConstantExpr(I, Context)) {
1647
0
        Diag(AttrLoc, diag::err_attribute_argument_n_type)
1648
0
          << &TmpAttr << 2 << AANT_ArgumentIntegerConstant
1649
0
          << OE->getSourceRange();
1650
0
        return;
1651
0
      }
1652
25
    }
1653
10
  }
1654
25
1655
25
  D->addAttr(::new (Context)
1656
25
            AssumeAlignedAttr(AttrRange, Context, E, OE, SpellingListIndex));
1657
25
}
1658
1659
void Sema::AddAllocAlignAttr(SourceRange AttrRange, Decl *D, Expr *ParamExpr,
1660
36
                             unsigned SpellingListIndex) {
1661
36
  QualType ResultType = getFunctionOrMethodResultType(D);
1662
36
1663
36
  AllocAlignAttr TmpAttr(AttrRange, Context, ParamIdx(), SpellingListIndex);
1664
36
  SourceLocation AttrLoc = AttrRange.getBegin();
1665
36
1666
36
  if (!ResultType->isDependentType() &&
1667
36
      
!isValidPointerAttrType(ResultType, /* RefOkay */ true)34
) {
1668
2
    Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only)
1669
2
        << &TmpAttr << AttrRange << getFunctionOrMethodResultSourceRange(D);
1670
2
    return;
1671
2
  }
1672
34
1673
34
  ParamIdx Idx;
1674
34
  const auto *FuncDecl = cast<FunctionDecl>(D);
1675
34
  if (!checkFunctionOrMethodParameterIndex(*this, FuncDecl, TmpAttr,
1676
34
                                           /*AttrArgNum=*/1, ParamExpr, Idx))
1677
5
    return;
1678
29
1679
29
  QualType Ty = getFunctionOrMethodParamType(D, Idx.getASTIndex());
1680
29
  if (!Ty->isDependentType() && 
!Ty->isIntegralType(Context)27
) {
1681
3
    Diag(ParamExpr->getBeginLoc(), diag::err_attribute_integers_only)
1682
3
        << &TmpAttr
1683
3
        << FuncDecl->getParamDecl(Idx.getASTIndex())->getSourceRange();
1684
3
    return;
1685
3
  }
1686
26
1687
26
  D->addAttr(::new (Context)
1688
26
                 AllocAlignAttr(AttrRange, Context, Idx, SpellingListIndex));
1689
26
}
1690
1691
/// Normalize the attribute, __foo__ becomes foo.
1692
/// Returns true if normalization was applied.
1693
54.3k
static bool normalizeName(StringRef &AttrName) {
1694
54.3k
  if (AttrName.size() > 4 && 
AttrName.startswith("__")51.7k
&&
1695
54.3k
      
AttrName.endswith("__")50.9k
) {
1696
50.9k
    AttrName = AttrName.drop_front(2).drop_back(2);
1697
50.9k
    return true;
1698
50.9k
  }
1699
3.40k
  return false;
1700
3.40k
}
1701
1702
47
static void handleOwnershipAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1703
47
  // This attribute must be applied to a function declaration. The first
1704
47
  // argument to the attribute must be an identifier, the name of the resource,
1705
47
  // for example: malloc. The following arguments must be argument indexes, the
1706
47
  // arguments must be of integer type for Returns, otherwise of pointer type.
1707
47
  // The difference between Holds and Takes is that a pointer may still be used
1708
47
  // after being held. free() should be __attribute((ownership_takes)), whereas
1709
47
  // a list append function may well be __attribute((ownership_holds)).
1710
47
1711
47
  if (!AL.isArgIdent(0)) {
1712
1
    S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
1713
1
        << AL << 1 << AANT_ArgumentIdentifier;
1714
1
    return;
1715
1
  }
1716
46
1717
46
  // Figure out our Kind.
1718
46
  OwnershipAttr::OwnershipKind K =
1719
46
      OwnershipAttr(AL.getLoc(), S.Context, nullptr, nullptr, 0,
1720
46
                    AL.getAttributeSpellingListIndex()).getOwnKind();
1721
46
1722
46
  // Check arguments.
1723
46
  switch (K) {
1724
46
  case OwnershipAttr::Takes:
1725
29
  case OwnershipAttr::Holds:
1726
29
    if (AL.getNumArgs() < 2) {
1727
2
      S.Diag(AL.getLoc(), diag::err_attribute_too_few_arguments) << AL << 2;
1728
2
      return;
1729
2
    }
1730
27
    break;
1731
27
  case OwnershipAttr::Returns:
1732
17
    if (AL.getNumArgs() > 2) {
1733
1
      S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
1734
1
      return;
1735
1
    }
1736
16
    break;
1737
43
  }
1738
43
1739
43
  IdentifierInfo *Module = AL.getArgAsIdent(0)->Ident;
1740
43
1741
43
  StringRef ModuleName = Module->getName();
1742
43
  if (normalizeName(ModuleName)) {
1743
0
    Module = &S.PP.getIdentifierTable().get(ModuleName);
1744
0
  }
1745
43
1746
43
  SmallVector<ParamIdx, 8> OwnershipArgs;
1747
83
  for (unsigned i = 1; i < AL.getNumArgs(); 
++i40
) {
1748
49
    Expr *Ex = AL.getArgAsExpr(i);
1749
49
    ParamIdx Idx;
1750
49
    if (!checkFunctionOrMethodParameterIndex(S, D, AL, i, Ex, Idx))
1751
3
      return;
1752
46
1753
46
    // Is the function argument a pointer type?
1754
46
    QualType T = getFunctionOrMethodParamType(D, Idx.getASTIndex());
1755
46
    int Err = -1;  // No error
1756
46
    switch (K) {
1757
46
      case OwnershipAttr::Takes:
1758
35
      case OwnershipAttr::Holds:
1759
35
        if (!T->isAnyPointerType() && 
!T->isBlockPointerType()1
)
1760
1
          Err = 0;
1761
35
        break;
1762
35
      case OwnershipAttr::Returns:
1763
11
        if (!T->isIntegerType())
1764
2
          Err = 1;
1765
11
        break;
1766
46
    }
1767
46
    if (-1 != Err) {
1768
3
      S.Diag(AL.getLoc(), diag::err_ownership_type) << AL << Err
1769
3
                                                    << Ex->getSourceRange();
1770
3
      return;
1771
3
    }
1772
43
1773
43
    // Check we don't have a conflict with another ownership attribute.
1774
43
    for (const auto *I : D->specific_attrs<OwnershipAttr>()) {
1775
8
      // Cannot have two ownership attributes of different kinds for the same
1776
8
      // index.
1777
8
      if (I->getOwnKind() != K && I->args_end() !=
1778
2
          std::find(I->args_begin(), I->args_end(), Idx)) {
1779
1
        S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << I;
1780
1
        return;
1781
7
      } else if (K == OwnershipAttr::Returns &&
1782
7
                 
I->getOwnKind() == OwnershipAttr::Returns2
) {
1783
2
        // A returns attribute conflicts with any other returns attribute using
1784
2
        // a different index.
1785
2
        if (std::find(I->args_begin(), I->args_end(), Idx) == I->args_end()) {
1786
2
          S.Diag(I->getLocation(), diag::err_ownership_returns_index_mismatch)
1787
2
              << I->args_begin()->getSourceIndex();
1788
2
          if (I->args_size())
1789
2
            S.Diag(AL.getLoc(), diag::note_ownership_returns_index_mismatch)
1790
2
                << Idx.getSourceIndex() << Ex->getSourceRange();
1791
2
          return;
1792
2
        }
1793
2
      }
1794
8
    }
1795
43
    OwnershipArgs.push_back(Idx);
1796
40
  }
1797
43
1798
43
  ParamIdx *Start = OwnershipArgs.data();
1799
34
  unsigned Size = OwnershipArgs.size();
1800
34
  llvm::array_pod_sort(Start, Start + Size);
1801
34
  D->addAttr(::new (S.Context)
1802
34
                 OwnershipAttr(AL.getLoc(), S.Context, Module, Start, Size,
1803
34
                               AL.getAttributeSpellingListIndex()));
1804
34
}
1805
1806
40
static void handleWeakRefAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1807
40
  // Check the attribute arguments.
1808
40
  if (AL.getNumArgs() > 1) {
1809
0
    S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
1810
0
    return;
1811
0
  }
1812
40
1813
40
  // gcc rejects
1814
40
  // class c {
1815
40
  //   static int a __attribute__((weakref ("v2")));
1816
40
  //   static int b() __attribute__((weakref ("f3")));
1817
40
  // };
1818
40
  // and ignores the attributes of
1819
40
  // void f(void) {
1820
40
  //   static int a __attribute__((weakref ("v2")));
1821
40
  // }
1822
40
  // we reject them
1823
40
  const DeclContext *Ctx = D->getDeclContext()->getRedeclContext();
1824
40
  if (!Ctx->isFileContext()) {
1825
3
    S.Diag(AL.getLoc(), diag::err_attribute_weakref_not_global_context)
1826
3
        << cast<NamedDecl>(D);
1827
3
    return;
1828
3
  }
1829
37
1830
37
  // The GCC manual says
1831
37
  //
1832
37
  // At present, a declaration to which `weakref' is attached can only
1833
37
  // be `static'.
1834
37
  //
1835
37
  // It also says
1836
37
  //
1837
37
  // Without a TARGET,
1838
37
  // given as an argument to `weakref' or to `alias', `weakref' is
1839
37
  // equivalent to `weak'.
1840
37
  //
1841
37
  // gcc 4.4.1 will accept
1842
37
  // int a7 __attribute__((weakref));
1843
37
  // as
1844
37
  // int a7 __attribute__((weak));
1845
37
  // This looks like a bug in gcc. We reject that for now. We should revisit
1846
37
  // it if this behaviour is actually used.
1847
37
1848
37
  // GCC rejects
1849
37
  // static ((alias ("y"), weakref)).
1850
37
  // Should we? How to check that weakref is before or after alias?
1851
37
1852
37
  // FIXME: it would be good for us to keep the WeakRefAttr as-written instead
1853
37
  // of transforming it into an AliasAttr.  The WeakRefAttr never uses the
1854
37
  // StringRef parameter it was given anyway.
1855
37
  StringRef Str;
1856
37
  if (AL.getNumArgs() && 
S.checkStringLiteralArgumentAttr(AL, 0, Str)29
)
1857
28
    // GCC will accept anything as the argument of weakref. Should we
1858
28
    // check for an existing decl?
1859
28
    D->addAttr(::new (S.Context) AliasAttr(AL.getRange(), S.Context, Str,
1860
28
                                        AL.getAttributeSpellingListIndex()));
1861
37
1862
37
  D->addAttr(::new (S.Context)
1863
37
             WeakRefAttr(AL.getRange(), S.Context,
1864
37
                         AL.getAttributeSpellingListIndex()));
1865
37
}
1866
1867
12
static void handleIFuncAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1868
12
  StringRef Str;
1869
12
  if (!S.checkStringLiteralArgumentAttr(AL, 0, Str))
1870
0
    return;
1871
12
1872
12
  // Aliases should be on declarations, not definitions.
1873
12
  const auto *FD = cast<FunctionDecl>(D);
1874
12
  if (FD->isThisDeclarationADefinition()) {
1875
0
    S.Diag(AL.getLoc(), diag::err_alias_is_definition) << FD << 1;
1876
0
    return;
1877
0
  }
1878
12
1879
12
  D->addAttr(::new (S.Context) IFuncAttr(AL.getRange(), S.Context, Str,
1880
12
                                         AL.getAttributeSpellingListIndex()));
1881
12
}
1882
1883
99
static void handleAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1884
99
  StringRef Str;
1885
99
  if (!S.checkStringLiteralArgumentAttr(AL, 0, Str))
1886
0
    return;
1887
99
1888
99
  if (S.Context.getTargetInfo().getTriple().isOSDarwin()) {
1889
1
    S.Diag(AL.getLoc(), diag::err_alias_not_supported_on_darwin);
1890
1
    return;
1891
1
  }
1892
98
  if (S.Context.getTargetInfo().getTriple().isNVPTX()) {
1893
1
    S.Diag(AL.getLoc(), diag::err_alias_not_supported_on_nvptx);
1894
1
  }
1895
98
1896
98
  // Aliases should be on declarations, not definitions.
1897
98
  if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
1898
74
    if (FD->isThisDeclarationADefinition()) {
1899
0
      S.Diag(AL.getLoc(), diag::err_alias_is_definition) << FD << 0;
1900
0
      return;
1901
0
    }
1902
24
  } else {
1903
24
    const auto *VD = cast<VarDecl>(D);
1904
24
    if (VD->isThisDeclarationADefinition() && 
VD->isExternallyVisible()6
) {
1905
1
      S.Diag(AL.getLoc(), diag::err_alias_is_definition) << VD << 0;
1906
1
      return;
1907
1
    }
1908
97
  }
1909
97
1910
97
  // Mark target used to prevent unneeded-internal-declaration warnings.
1911
97
  if (!S.LangOpts.CPlusPlus) {
1912
85
    // FIXME: demangle Str for C++, as the attribute refers to the mangled
1913
85
    // linkage name, not the pre-mangled identifier.
1914
85
    const DeclarationNameInfo target(&S.Context.Idents.get(Str), AL.getLoc());
1915
85
    LookupResult LR(S, target, Sema::LookupOrdinaryName);
1916
85
    if (S.LookupQualifiedName(LR, S.getCurLexicalContext()))
1917
64
      for (NamedDecl *ND : LR)
1918
64
        ND->markUsed(S.Context);
1919
85
  }
1920
97
1921
97
  D->addAttr(::new (S.Context) AliasAttr(AL.getRange(), S.Context, Str,
1922
97
                                         AL.getAttributeSpellingListIndex()));
1923
97
}
1924
1925
29
static void handleTLSModelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1926
29
  StringRef Model;
1927
29
  SourceLocation LiteralLoc;
1928
29
  // Check that it is a string.
1929
29
  if (!S.checkStringLiteralArgumentAttr(AL, 0, Model, &LiteralLoc))
1930
1
    return;
1931
28
1932
28
  // Check that the value.
1933
28
  if (Model != "global-dynamic" && 
Model != "local-dynamic"24
1934
28
      && 
Model != "initial-exec"21
&&
Model != "local-exec"5
) {
1935
1
    S.Diag(LiteralLoc, diag::err_attr_tlsmodel_arg);
1936
1
    return;
1937
1
  }
1938
27
1939
27
  D->addAttr(::new (S.Context)
1940
27
             TLSModelAttr(AL.getRange(), S.Context, Model,
1941
27
                          AL.getAttributeSpellingListIndex()));
1942
27
}
1943
1944
2.19k
static void handleRestrictAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1945
2.19k
  QualType ResultType = getFunctionOrMethodResultType(D);
1946
2.19k
  if (ResultType->isAnyPointerType() || 
ResultType->isBlockPointerType()5
) {
1947
2.18k
    D->addAttr(::new (S.Context) RestrictAttr(
1948
2.18k
        AL.getRange(), S.Context, AL.getAttributeSpellingListIndex()));
1949
2.18k
    return;
1950
2.18k
  }
1951
4
1952
4
  S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only)
1953
4
      << AL << getFunctionOrMethodResultSourceRange(D);
1954
4
}
1955
1956
109
static void handleCPUSpecificAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1957
109
  FunctionDecl *FD = cast<FunctionDecl>(D);
1958
109
1959
109
  if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
1960
18
    if (MD->getParent()->isLambda()) {
1961
1
      S.Diag(AL.getLoc(), diag::err_attribute_dll_lambda) << AL;
1962
1
      return;
1963
1
    }
1964
108
  }
1965
108
1966
108
  if (!checkAttributeAtLeastNumArgs(S, AL, 1))
1967
2
    return;
1968
106
1969
106
  SmallVector<IdentifierInfo *, 8> CPUs;
1970
264
  for (unsigned ArgNo = 0; ArgNo < getNumAttributeArgs(AL); 
++ArgNo158
) {
1971
162
    if (!AL.isArgIdent(ArgNo)) {
1972
0
      S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1973
0
          << AL << AANT_ArgumentIdentifier;
1974
0
      return;
1975
0
    }
1976
162
1977
162
    IdentifierLoc *CPUArg = AL.getArgAsIdent(ArgNo);
1978
162
    StringRef CPUName = CPUArg->Ident->getName().trim();
1979
162
1980
162
    if (!S.Context.getTargetInfo().validateCPUSpecificCPUDispatch(CPUName)) {
1981
2
      S.Diag(CPUArg->Loc, diag::err_invalid_cpu_specific_dispatch_value)
1982
2
          << CPUName << (AL.getKind() == ParsedAttr::AT_CPUDispatch);
1983
2
      return;
1984
2
    }
1985
160
1986
160
    const TargetInfo &Target = S.Context.getTargetInfo();
1987
160
    if (llvm::any_of(CPUs, [CPUName, &Target](const IdentifierInfo *Cur) {
1988
83
          return Target.CPUSpecificManglingCharacter(CPUName) ==
1989
83
                 Target.CPUSpecificManglingCharacter(Cur->getName());
1990
83
        })) {
1991
2
      S.Diag(AL.getLoc(), diag::warn_multiversion_duplicate_entries);
1992
2
      return;
1993
2
    }
1994
158
    CPUs.push_back(CPUArg->Ident);
1995
158
  }
1996
106
1997
106
  FD->setIsMultiVersion(true);
1998
102
  if (AL.getKind() == ParsedAttr::AT_CPUSpecific)
1999
69
    D->addAttr(::new (S.Context) CPUSpecificAttr(
2000
69
        AL.getRange(), S.Context, CPUs.data(), CPUs.size(),
2001
69
        AL.getAttributeSpellingListIndex()));
2002
33
  else
2003
33
    D->addAttr(::new (S.Context) CPUDispatchAttr(
2004
33
        AL.getRange(), S.Context, CPUs.data(), CPUs.size(),
2005
33
        AL.getAttributeSpellingListIndex()));
2006
102
}
2007
2008
9
static void handleCommonAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2009
9
  if (S.LangOpts.CPlusPlus) {
2010
1
    S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang)
2011
1
        << AL << AttributeLangSupport::Cpp;
2012
1
    return;
2013
1
  }
2014
8
2015
8
  if (CommonAttr *CA = S.mergeCommonAttr(D, AL))
2016
7
    D->addAttr(CA);
2017
8
}
2018
2019
31
static void handleNakedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2020
31
  if (checkAttrMutualExclusion<DisableTailCallsAttr>(S, D, AL))
2021
1
    return;
2022
30
2023
30
  if (AL.isDeclspecAttribute()) {
2024
9
    const auto &Triple = S.getASTContext().getTargetInfo().getTriple();
2025
9
    const auto &Arch = Triple.getArch();
2026
9
    if (Arch != llvm::Triple::x86 &&
2027
9
        
(2
Arch != llvm::Triple::arm2
&&
Arch != llvm::Triple::thumb2
)) {
2028
1
      S.Diag(AL.getLoc(), diag::err_attribute_not_supported_on_arch)
2029
1
          << AL << Triple.getArchName();
2030
1
      return;
2031
1
    }
2032
29
  }
2033
29
2034
29
  D->addAttr(::new (S.Context) NakedAttr(AL.getRange(), S.Context,
2035
29
                                         AL.getAttributeSpellingListIndex()));
2036
29
}
2037
2038
36.6k
static void handleNoReturnAttr(Sema &S, Decl *D, const ParsedAttr &Attrs) {
2039
36.6k
  if (hasDeclarator(D)) 
return36.6k
;
2040
18
2041
18
  if (!isa<ObjCMethodDecl>(D)) {
2042
4
    S.Diag(Attrs.getLoc(), diag::warn_attribute_wrong_decl_type)
2043
4
        << Attrs << ExpectedFunctionOrMethod;
2044
4
    return;
2045
4
  }
2046
14
2047
14
  D->addAttr(::new (S.Context) NoReturnAttr(
2048
14
      Attrs.getRange(), S.Context, Attrs.getAttributeSpellingListIndex()));
2049
14
}
2050
2051
10
static void handleNoCfCheckAttr(Sema &S, Decl *D, const ParsedAttr &Attrs) {
2052
10
  if (!S.getLangOpts().CFProtectionBranch)
2053
0
    S.Diag(Attrs.getLoc(), diag::warn_nocf_check_attribute_ignored);
2054
10
  else
2055
10
    handleSimpleAttribute<AnyX86NoCfCheckAttr>(S, D, Attrs);
2056
10
}
2057
2058
24.1k
bool Sema::CheckAttrNoArgs(const ParsedAttr &Attrs) {
2059
24.1k
  if (!checkAttributeNumArgs(*this, Attrs, 0)) {
2060
6
    Attrs.setInvalid();
2061
6
    return true;
2062
6
  }
2063
24.1k
2064
24.1k
  return false;
2065
24.1k
}
2066
2067
7.31M
bool Sema::CheckAttrTarget(const ParsedAttr &AL) {
2068
7.31M
  // Check whether the attribute is valid on the current target.
2069
7.31M
  if (!AL.existsInTarget(Context.getTargetInfo())) {
2070
11
    Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored) << AL;
2071
11
    AL.setInvalid();
2072
11
    return true;
2073
11
  }
2074
7.31M
2075
7.31M
  return false;
2076
7.31M
}
2077
2078
7
static void handleAnalyzerNoReturnAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2079
7
2080
7
  // The checking path for 'noreturn' and 'analyzer_noreturn' are different
2081
7
  // because 'analyzer_noreturn' does not impact the type.
2082
7
  if (!isFunctionOrMethodOrBlock(D)) {
2083
0
    ValueDecl *VD = dyn_cast<ValueDecl>(D);
2084
0
    if (!VD || (!VD->getType()->isBlockPointerType() &&
2085
0
                !VD->getType()->isFunctionPointerType())) {
2086
0
      S.Diag(AL.getLoc(), AL.isCXX11Attribute()
2087
0
                              ? diag::err_attribute_wrong_decl_type
2088
0
                              : diag::warn_attribute_wrong_decl_type)
2089
0
          << AL << ExpectedFunctionMethodOrBlock;
2090
0
      return;
2091
0
    }
2092
7
  }
2093
7
2094
7
  D->addAttr(::new (S.Context)
2095
7
             AnalyzerNoReturnAttr(AL.getRange(), S.Context,
2096
7
                                  AL.getAttributeSpellingListIndex()));
2097
7
}
2098
2099
// PS3 PPU-specific.
2100
11
static void handleVecReturnAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2101
11
  /*
2102
11
    Returning a Vector Class in Registers
2103
11
2104
11
    According to the PPU ABI specifications, a class with a single member of
2105
11
    vector type is returned in memory when used as the return value of a
2106
11
    function.
2107
11
    This results in inefficient code when implementing vector classes. To return
2108
11
    the value in a single vector register, add the vecreturn attribute to the
2109
11
    class definition. This attribute is also applicable to struct types.
2110
11
2111
11
    Example:
2112
11
2113
11
    struct Vector
2114
11
    {
2115
11
      __vector float xyzw;
2116
11
    } __attribute__((vecreturn));
2117
11
2118
11
    Vector Add(Vector lhs, Vector rhs)
2119
11
    {
2120
11
      Vector result;
2121
11
      result.xyzw = vec_add(lhs.xyzw, rhs.xyzw);
2122
11
      return result; // This will be returned in a register
2123
11
    }
2124
11
  */
2125
11
  if (VecReturnAttr *A = D->getAttr<VecReturnAttr>()) {
2126
1
    S.Diag(AL.getLoc(), diag::err_repeat_attribute) << A;
2127
1
    return;
2128
1
  }
2129
10
2130
10
  const auto *R = cast<RecordDecl>(D);
2131
10
  int count = 0;
2132
10
2133
10
  if (!isa<CXXRecordDecl>(R)) {
2134
0
    S.Diag(AL.getLoc(), diag::err_attribute_vecreturn_only_vector_member);
2135
0
    return;
2136
0
  }
2137
10
2138
10
  if (!cast<CXXRecordDecl>(R)->isPOD()) {
2139
3
    S.Diag(AL.getLoc(), diag::err_attribute_vecreturn_only_pod_record);
2140
3
    return;
2141
3
  }
2142
7
2143
10
  
for (const auto *I : R->fields())7
{
2144
10
    if ((count == 1) || 
!I->getType()->isVectorType()7
) {
2145
3
      S.Diag(AL.getLoc(), diag::err_attribute_vecreturn_only_vector_member);
2146
3
      return;
2147
3
    }
2148
7
    count++;
2149
7
  }
2150
7
2151
7
  D->addAttr(::new (S.Context) VecReturnAttr(
2152
4
      AL.getRange(), S.Context, AL.getAttributeSpellingListIndex()));
2153
4
}
2154
2155
static void handleDependencyAttr(Sema &S, Scope *Scope, Decl *D,
2156
26
                                 const ParsedAttr &AL) {
2157
26
  if (isa<ParmVarDecl>(D)) {
2158
14
    // [[carries_dependency]] can only be applied to a parameter if it is a
2159
14
    // parameter of a function declaration or lambda.
2160
14
    if (!(Scope->getFlags() & clang::Scope::FunctionDeclarationScope)) {
2161
6
      S.Diag(AL.getLoc(),
2162
6
             diag::err_carries_dependency_param_not_function_decl);
2163
6
      return;
2164
6
    }
2165
20
  }
2166
20
2167
20
  D->addAttr(::new (S.Context) CarriesDependencyAttr(
2168
20
                                   AL.getRange(), S.Context,
2169
20
                                   AL.getAttributeSpellingListIndex()));
2170
20
}
2171
2172
36.3k
static void handleUnusedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2173
36.3k
  bool IsCXX17Attr = AL.isCXX11Attribute() && 
!AL.getScopeName()23
;
2174
36.3k
2175
36.3k
  // If this is spelled as the standard C++17 attribute, but not in C++17, warn
2176
36.3k
  // about using it as an extension.
2177
36.3k
  if (!S.getLangOpts().CPlusPlus17 && 
IsCXX17Attr36.3k
)
2178
4
    S.Diag(AL.getLoc(), diag::ext_cxx17_attr) << AL;
2179
36.3k
2180
36.3k
  D->addAttr(::new (S.Context) UnusedAttr(
2181
36.3k
      AL.getRange(), S.Context, AL.getAttributeSpellingListIndex()));
2182
36.3k
}
2183
2184
38
static void handleConstructorAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2185
38
  uint32_t priority = ConstructorAttr::DefaultPriority;
2186
38
  if (AL.getNumArgs() &&
2187
38
      
!checkUInt32Argument(S, AL, AL.getArgAsExpr(0), priority)8
)
2188
4
    return;
2189
34
2190
34
  D->addAttr(::new (S.Context)
2191
34
             ConstructorAttr(AL.getRange(), S.Context, priority,
2192
34
                             AL.getAttributeSpellingListIndex()));
2193
34
}
2194
2195
24
static void handleDestructorAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2196
24
  uint32_t priority = DestructorAttr::DefaultPriority;
2197
24
  if (AL.getNumArgs() &&
2198
24
      
!checkUInt32Argument(S, AL, AL.getArgAsExpr(0), priority)11
)
2199
1
    return;
2200
23
2201
23
  D->addAttr(::new (S.Context)
2202
23
             DestructorAttr(AL.getRange(), S.Context, priority,
2203
23
                            AL.getAttributeSpellingListIndex()));
2204
23
}
2205
2206
template <typename AttrTy>
2207
1.55k
static void handleAttrWithMessage(Sema &S, Decl *D, const ParsedAttr &AL) {
2208
1.55k
  // Handle the case where the attribute has a text message.
2209
1.55k
  StringRef Str;
2210
1.55k
  if (AL.getNumArgs() == 1 && 
!S.checkStringLiteralArgumentAttr(AL, 0, Str)799
)
2211
1
    return;
2212
1.55k
2213
1.55k
  D->addAttr(::new (S.Context) AttrTy(AL.getRange(), S.Context, Str,
2214
1.55k
                                      AL.getAttributeSpellingListIndex()));
2215
1.55k
}
2216
2217
static void handleObjCSuppresProtocolAttr(Sema &S, Decl *D,
2218
11
                                          const ParsedAttr &AL) {
2219
11
  if (!cast<ObjCProtocolDecl>(D)->isThisDeclarationADefinition()) {
2220
1
    S.Diag(AL.getLoc(), diag::err_objc_attr_protocol_requires_definition)
2221
1
        << AL << AL.getRange();
2222
1
    return;
2223
1
  }
2224
10
2225
10
  D->addAttr(::new (S.Context)
2226
10
          ObjCExplicitProtocolImplAttr(AL.getRange(), S.Context,
2227
10
                                       AL.getAttributeSpellingListIndex()));
2228
10
}
2229
2230
static bool checkAvailabilityAttr(Sema &S, SourceRange Range,
2231
                                  IdentifierInfo *Platform,
2232
                                  VersionTuple Introduced,
2233
                                  VersionTuple Deprecated,
2234
845k
                                  VersionTuple Obsoleted) {
2235
845k
  StringRef PlatformName
2236
845k
    = AvailabilityAttr::getPrettyPlatformName(Platform->getName());
2237
845k
  if (PlatformName.empty())
2238
3
    PlatformName = Platform->getName();
2239
845k
2240
845k
  // Ensure that Introduced <= Deprecated <= Obsoleted (although not all
2241
845k
  // of these steps are needed).
2242
845k
  if (!Introduced.empty() && 
!Deprecated.empty()695k
&&
2243
845k
      
!(Introduced <= Deprecated)54.1k
) {
2244
7
    S.Diag(Range.getBegin(), diag::warn_availability_version_ordering)
2245
7
      << 1 << PlatformName << Deprecated.getAsString()
2246
7
      << 0 << Introduced.getAsString();
2247
7
    return true;
2248
7
  }
2249
845k
2250
845k
  if (!Introduced.empty() && 
!Obsoleted.empty()694k
&&
2251
845k
      
!(Introduced <= Obsoleted)31
) {
2252
0
    S.Diag(Range.getBegin(), diag::warn_availability_version_ordering)
2253
0
      << 2 << PlatformName << Obsoleted.getAsString()
2254
0
      << 0 << Introduced.getAsString();
2255
0
    return true;
2256
0
  }
2257
845k
2258
845k
  if (!Deprecated.empty() && 
!Obsoleted.empty()63.2k
&&
2259
845k
      
!(Deprecated <= Obsoleted)28
) {
2260
3
    S.Diag(Range.getBegin(), diag::warn_availability_version_ordering)
2261
3
      << 2 << PlatformName << Obsoleted.getAsString()
2262
3
      << 1 << Deprecated.getAsString();
2263
3
    return true;
2264
3
  }
2265
845k
2266
845k
  return false;
2267
845k
}
2268
2269
/// Check whether the two versions match.
2270
///
2271
/// If either version tuple is empty, then they are assumed to match. If
2272
/// \p BeforeIsOkay is true, then \p X can be less than or equal to \p Y.
2273
static bool versionsMatch(const VersionTuple &X, const VersionTuple &Y,
2274
61.5k
                          bool BeforeIsOkay) {
2275
61.5k
  if (X.empty() || 
Y.empty()29.0k
)
2276
53.1k
    return true;
2277
8.36k
2278
8.36k
  if (X == Y)
2279
8.32k
    return true;
2280
46
2281
46
  if (BeforeIsOkay && 
X < Y38
)
2282
10
    return true;
2283
36
2284
36
  return false;
2285
36
}
2286
2287
AvailabilityAttr *Sema::mergeAvailabilityAttr(
2288
    NamedDecl *D, SourceRange Range, IdentifierInfo *Platform, bool Implicit,
2289
    VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted,
2290
    bool IsUnavailable, StringRef Message, bool IsStrict, StringRef Replacement,
2291
833k
    AvailabilityMergeKind AMK, int Priority, unsigned AttrSpellingListIndex) {
2292
833k
  VersionTuple MergedIntroduced = Introduced;
2293
833k
  VersionTuple MergedDeprecated = Deprecated;
2294
833k
  VersionTuple MergedObsoleted = Obsoleted;
2295
833k
  bool FoundAny = false;
2296
833k
  bool OverrideOrImpl = false;
2297
833k
  switch (AMK) {
2298
833k
  case AMK_None:
2299
826k
  case AMK_Redeclaration:
2300
826k
    OverrideOrImpl = false;
2301
826k
    break;
2302
826k
2303
826k
  case AMK_Override:
2304
6.61k
  case AMK_ProtocolImplementation:
2305
6.61k
    OverrideOrImpl = true;
2306
6.61k
    break;
2307
833k
  }
2308
833k
2309
833k
  if (D->hasAttrs()) {
2310
540k
    AttrVec &Attrs = D->getAttrs();
2311
1.68M
    for (unsigned i = 0, e = Attrs.size(); i != e;) {
2312
1.14M
      const auto *OldAA = dyn_cast<AvailabilityAttr>(Attrs[i]);
2313
1.14M
      if (!OldAA) {
2314
234k
        ++i;
2315
234k
        continue;
2316
234k
      }
2317
913k
2318
913k
      IdentifierInfo *OldPlatform = OldAA->getPlatform();
2319
913k
      if (OldPlatform != Platform) {
2320
893k
        ++i;
2321
893k
        continue;
2322
893k
      }
2323
20.5k
2324
20.5k
      // If there is an existing availability attribute for this platform that
2325
20.5k
      // has a lower priority use the existing one and discard the new
2326
20.5k
      // attribute.
2327
20.5k
      if (OldAA->getPriority() < Priority)
2328
8
        return nullptr;
2329
20.5k
2330
20.5k
      // If there is an existing attribute for this platform that has a higher
2331
20.5k
      // priority than the new attribute then erase the old one and continue
2332
20.5k
      // processing the attributes.
2333
20.5k
      if (OldAA->getPriority() > Priority) {
2334
4
        Attrs.erase(Attrs.begin() + i);
2335
4
        --e;
2336
4
        continue;
2337
4
      }
2338
20.5k
2339
20.5k
      FoundAny = true;
2340
20.5k
      VersionTuple OldIntroduced = OldAA->getIntroduced();
2341
20.5k
      VersionTuple OldDeprecated = OldAA->getDeprecated();
2342
20.5k
      VersionTuple OldObsoleted = OldAA->getObsoleted();
2343
20.5k
      bool OldIsUnavailable = OldAA->getUnavailable();
2344
20.5k
2345
20.5k
      if (!versionsMatch(OldIntroduced, Introduced, OverrideOrImpl) ||
2346
20.5k
          
!versionsMatch(Deprecated, OldDeprecated, OverrideOrImpl)20.5k
||
2347
20.5k
          
!versionsMatch(Obsoleted, OldObsoleted, OverrideOrImpl)20.4k
||
2348
20.5k
          
!(20.4k
OldIsUnavailable == IsUnavailable20.4k
||
2349
20.4k
            
(10
OverrideOrImpl10
&&
!OldIsUnavailable10
&&
IsUnavailable5
))) {
2350
27
        if (OverrideOrImpl) {
2351
19
          int Which = -1;
2352
19
          VersionTuple FirstVersion;
2353
19
          VersionTuple SecondVersion;
2354
19
          if (!versionsMatch(OldIntroduced, Introduced, OverrideOrImpl)) {
2355
9
            Which = 0;
2356
9
            FirstVersion = OldIntroduced;
2357
9
            SecondVersion = Introduced;
2358
10
          } else if (!versionsMatch(Deprecated, OldDeprecated, OverrideOrImpl)) {
2359
5
            Which = 1;
2360
5
            FirstVersion = Deprecated;
2361
5
            SecondVersion = OldDeprecated;
2362
5
          } else if (!versionsMatch(Obsoleted, OldObsoleted, OverrideOrImpl)) {
2363
0
            Which = 2;
2364
0
            FirstVersion = Obsoleted;
2365
0
            SecondVersion = OldObsoleted;
2366
0
          }
2367
19
2368
19
          if (Which == -1) {
2369
5
            Diag(OldAA->getLocation(),
2370
5
                 diag::warn_mismatched_availability_override_unavail)
2371
5
              << AvailabilityAttr::getPrettyPlatformName(Platform->getName())
2372
5
              << (AMK == AMK_Override);
2373
14
          } else {
2374
14
            Diag(OldAA->getLocation(),
2375
14
                 diag::warn_mismatched_availability_override)
2376
14
              << Which
2377
14
              << AvailabilityAttr::getPrettyPlatformName(Platform->getName())
2378
14
              << FirstVersion.getAsString() << SecondVersion.getAsString()
2379
14
              << (AMK == AMK_Override);
2380
14
          }
2381
19
          if (AMK == AMK_Override)
2382
15
            Diag(Range.getBegin(), diag::note_overridden_method);
2383
4
          else
2384
4
            Diag(Range.getBegin(), diag::note_protocol_method);
2385
19
        } else {
2386
8
          Diag(OldAA->getLocation(), diag::warn_mismatched_availability);
2387
8
          Diag(Range.getBegin(), diag::note_previous_attribute);
2388
8
        }
2389
27
2390
27
        Attrs.erase(Attrs.begin() + i);
2391
27
        --e;
2392
27
        continue;
2393
27
      }
2394
20.4k
2395
20.4k
      VersionTuple MergedIntroduced2 = MergedIntroduced;
2396
20.4k
      VersionTuple MergedDeprecated2 = MergedDeprecated;
2397
20.4k
      VersionTuple MergedObsoleted2 = MergedObsoleted;
2398
20.4k
2399
20.4k
      if (MergedIntroduced2.empty())
2400
10.5k
        MergedIntroduced2 = OldIntroduced;
2401
20.4k
      if (MergedDeprecated2.empty())
2402
9.91k
        MergedDeprecated2 = OldDeprecated;
2403
20.4k
      if (MergedObsoleted2.empty())
2404
20.4k
        MergedObsoleted2 = OldObsoleted;
2405
20.4k
2406
20.4k
      if (checkAvailabilityAttr(*this, OldAA->getRange(), Platform,
2407
20.4k
                                MergedIntroduced2, MergedDeprecated2,
2408
20.4k
                                MergedObsoleted2)) {
2409
4
        Attrs.erase(Attrs.begin() + i);
2410
4
        --e;
2411
4
        continue;
2412
4
      }
2413
20.4k
2414
20.4k
      MergedIntroduced = MergedIntroduced2;
2415
20.4k
      MergedDeprecated = MergedDeprecated2;
2416
20.4k
      MergedObsoleted = MergedObsoleted2;
2417
20.4k
      ++i;
2418
20.4k
    }
2419
540k
  }
2420
833k
2421
833k
  
if (833k
FoundAny833k
&&
2422
833k
      
MergedIntroduced == Introduced20.5k
&&
2423
833k
      
MergedDeprecated == Deprecated10.1k
&&
2424
833k
      
MergedObsoleted == Obsoleted8.30k
)
2425
8.30k
    return nullptr;
2426
825k
2427
825k
  // Only create a new attribute if !OverrideOrImpl, but we want to do
2428
825k
  // the checking.
2429
825k
  if (!checkAvailabilityAttr(*this, Range, Platform, MergedIntroduced,
2430
825k
                             MergedDeprecated, MergedObsoleted) &&
2431
825k
      
!OverrideOrImpl825k
) {
2432
825k
    auto *Avail = ::new (Context)
2433
825k
        AvailabilityAttr(Range, Context, Platform, Introduced, Deprecated,
2434
825k
                         Obsoleted, IsUnavailable, Message, IsStrict,
2435
825k
                         Replacement, Priority, AttrSpellingListIndex);
2436
825k
    Avail->setImplicit(Implicit);
2437
825k
    return Avail;
2438
825k
  }
2439
79
  return nullptr;
2440
79
}
2441
2442
822k
static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2443
822k
  if (!checkAttributeNumArgs(S, AL, 1))
2444
0
    return;
2445
822k
  IdentifierLoc *Platform = AL.getArgAsIdent(0);
2446
822k
  unsigned Index = AL.getAttributeSpellingListIndex();
2447
822k
2448
822k
  IdentifierInfo *II = Platform->Ident;
2449
822k
  if (AvailabilityAttr::getPrettyPlatformName(II->getName()).empty())
2450
3
    S.Diag(Platform->Loc, diag::warn_availability_unknown_platform)
2451
3
      << Platform->Ident;
2452
822k
2453
822k
  auto *ND = dyn_cast<NamedDecl>(D);
2454
822k
  if (!ND) // We warned about this already, so just return.
2455
0
    return;
2456
822k
2457
822k
  AvailabilityChange Introduced = AL.getAvailabilityIntroduced();
2458
822k
  AvailabilityChange Deprecated = AL.getAvailabilityDeprecated();
2459
822k
  AvailabilityChange Obsoleted = AL.getAvailabilityObsoleted();
2460
822k
  bool IsUnavailable = AL.getUnavailableLoc().isValid();
2461
822k
  bool IsStrict = AL.getStrictLoc().isValid();
2462
822k
  StringRef Str;
2463
822k
  if (const auto *SE = dyn_cast_or_null<StringLiteral>(AL.getMessageExpr()))
2464
76.3k
    Str = SE->getString();
2465
822k
  StringRef Replacement;
2466
822k
  if (const auto *SE = dyn_cast_or_null<StringLiteral>(AL.getReplacementExpr()))
2467
5.72k
    Replacement = SE->getString();
2468
822k
2469
822k
  if (II->isStr("swift")) {
2470
35.4k
    if (Introduced.isValid() || 
Obsoleted.isValid()35.4k
||
2471
35.4k
        
(35.4k
!IsUnavailable35.4k
&&
!Deprecated.isValid()3
)) {
2472
2
      S.Diag(AL.getLoc(),
2473
2
             diag::warn_availability_swift_unavailable_deprecated_only);
2474
2
      return;
2475
2
    }
2476
822k
  }
2477
822k
2478
822k
  int PriorityModifier = AL.isPragmaClangAttribute()
2479
822k
                             ? 
Sema::AP_PragmaClangAttribute111k
2480
822k
                             : 
Sema::AP_Explicit711k
;
2481
822k
  AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(
2482
822k
      ND, AL.getRange(), II, false /*Implicit*/, Introduced.Version,
2483
822k
      Deprecated.Version, Obsoleted.Version, IsUnavailable, Str, IsStrict,
2484
822k
      Replacement, Sema::AMK_None, PriorityModifier, Index);
2485
822k
  if (NewAttr)
2486
822k
    D->addAttr(NewAttr);
2487
822k
2488
822k
  // Transcribe "ios" to "watchos" (and add a new attribute) if the versioning
2489
822k
  // matches before the start of the watchOS platform.
2490
822k
  if (S.Context.getTargetInfo().getTriple().isWatchOS()) {
2491
53
    IdentifierInfo *NewII = nullptr;
2492
53
    if (II->getName() == "ios")
2493
17
      NewII = &S.Context.Idents.get("watchos");
2494
36
    else if (II->getName() == "ios_app_extension")
2495
0
      NewII = &S.Context.Idents.get("watchos_app_extension");
2496
53
2497
53
    if (NewII) {
2498
51
        auto adjustWatchOSVersion = [](VersionTuple Version) -> VersionTuple {
2499
51
          if (Version.empty())
2500
28
            return Version;
2501
23
          auto Major = Version.getMajor();
2502
23
          auto NewMajor = Major >= 9 ? 
Major - 75
:
018
;
2503
23
          if (NewMajor >= 2) {
2504
5
            if (Version.getMinor().hasValue()) {
2505
4
              if (Version.getSubminor().hasValue())
2506
0
                return VersionTuple(NewMajor, Version.getMinor().getValue(),
2507
0
                                    Version.getSubminor().getValue());
2508
4
              else
2509
4
                return VersionTuple(NewMajor, Version.getMinor().getValue());
2510
1
            }
2511
1
            return VersionTuple(NewMajor);
2512
1
          }
2513
18
2514
18
          return VersionTuple(2, 0);
2515
18
        };
2516
17
2517
17
        auto NewIntroduced = adjustWatchOSVersion(Introduced.Version);
2518
17
        auto NewDeprecated = adjustWatchOSVersion(Deprecated.Version);
2519
17
        auto NewObsoleted = adjustWatchOSVersion(Obsoleted.Version);
2520
17
2521
17
        AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(
2522
17
            ND, AL.getRange(), NewII, true /*Implicit*/, NewIntroduced,
2523
17
            NewDeprecated, NewObsoleted, IsUnavailable, Str, IsStrict,
2524
17
            Replacement, Sema::AMK_None,
2525
17
            PriorityModifier + Sema::AP_InferredFromOtherPlatform, Index);
2526
17
        if (NewAttr)
2527
16
          D->addAttr(NewAttr);
2528
17
      }
2529
822k
  } else if (S.Context.getTargetInfo().getTriple().isTvOS()) {
2530
86
    // Transcribe "ios" to "tvos" (and add a new attribute) if the versioning
2531
86
    // matches before the start of the tvOS platform.
2532
86
    IdentifierInfo *NewII = nullptr;
2533
86
    if (II->getName() == "ios")
2534
20
      NewII = &S.Context.Idents.get("tvos");
2535
66
    else if (II->getName() == "ios_app_extension")
2536
3
      NewII = &S.Context.Idents.get("tvos_app_extension");
2537
86
2538
86
    if (NewII) {
2539
23
      AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(
2540
23
          ND, AL.getRange(), NewII, true /*Implicit*/, Introduced.Version,
2541
23
          Deprecated.Version, Obsoleted.Version, IsUnavailable, Str, IsStrict,
2542
23
          Replacement, Sema::AMK_None,
2543
23
          PriorityModifier + Sema::AP_InferredFromOtherPlatform, Index);
2544
23
      if (NewAttr)
2545
17
        D->addAttr(NewAttr);
2546
23
      }
2547
86
  }
2548
822k
}
2549
2550
static void handleExternalSourceSymbolAttr(Sema &S, Decl *D,
2551
63
                                           const ParsedAttr &AL) {
2552
63
  if (!checkAttributeAtLeastNumArgs(S, AL, 1))
2553
3
    return;
2554
60
  assert(checkAttributeAtMostNumArgs(S, AL, 3) &&
2555
60
         "Invalid number of arguments in an external_source_symbol attribute");
2556
60
2557
60
  StringRef Language;
2558
60
  if (const auto *SE = dyn_cast_or_null<StringLiteral>(AL.getArgAsExpr(0)))
2559
49
    Language = SE->getString();
2560
60
  StringRef DefinedIn;
2561
60
  if (const auto *SE = dyn_cast_or_null<StringLiteral>(AL.getArgAsExpr(1)))
2562
47
    DefinedIn = SE->getString();
2563
60
  bool IsGeneratedDeclaration = AL.getArgAsIdent(2) != nullptr;
2564
60
2565
60
  D->addAttr(::new (S.Context) ExternalSourceSymbolAttr(
2566
60
      AL.getRange(), S.Context, Language, DefinedIn, IsGeneratedDeclaration,
2567
60
      AL.getAttributeSpellingListIndex()));
2568
60
}
2569
2570
template <class T>
2571
static T *mergeVisibilityAttr(Sema &S, Decl *D, SourceRange range,
2572
                              typename T::VisibilityType value,
2573
1.54M
                              unsigned attrSpellingListIndex) {
2574
1.54M
  T *existingAttr = D->getAttr<T>();
2575
1.54M
  if (existingAttr) {
2576
42.9k
    typename T::VisibilityType existingValue = existingAttr->getVisibility();
2577
42.9k
    if (existingValue == value)
2578
42.9k
      return nullptr;
2579
6
    S.Diag(existingAttr->getLocation(), diag::err_mismatched_visibility);
2580
6
    S.Diag(range.getBegin(), diag::note_previous_attribute);
2581
6
    D->dropAttr<T>();
2582
6
  }
2583
1.54M
  
return ::new (S.Context) T(range, S.Context, value, attrSpellingListIndex)1.49M
;
2584
1.54M
}
SemaDeclAttr.cpp:clang::VisibilityAttr* mergeVisibilityAttr<clang::VisibilityAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, clang::VisibilityAttr::VisibilityType, unsigned int)
Line
Count
Source
2573
1.33M
                              unsigned attrSpellingListIndex) {
2574
1.33M
  T *existingAttr = D->getAttr<T>();
2575
1.33M
  if (existingAttr) {
2576
31.5k
    typename T::VisibilityType existingValue = existingAttr->getVisibility();
2577
31.5k
    if (existingValue == value)
2578
31.5k
      return nullptr;
2579
6
    S.Diag(existingAttr->getLocation(), diag::err_mismatched_visibility);
2580
6
    S.Diag(range.getBegin(), diag::note_previous_attribute);
2581
6
    D->dropAttr<T>();
2582
6
  }
2583
1.33M
  
return ::new (S.Context) T(range, S.Context, value, attrSpellingListIndex)1.30M
;
2584
1.33M
}
SemaDeclAttr.cpp:clang::TypeVisibilityAttr* mergeVisibilityAttr<clang::TypeVisibilityAttr>(clang::Sema&, clang::Decl*, clang::SourceRange, clang::TypeVisibilityAttr::VisibilityType, unsigned int)
Line
Count
Source
2573
203k
                              unsigned attrSpellingListIndex) {
2574
203k
  T *existingAttr = D->getAttr<T>();
2575
203k
  if (existingAttr) {
2576
11.4k
    typename T::VisibilityType existingValue = existingAttr->getVisibility();
2577
11.4k
    if (existingValue == value)
2578
11.4k
      return nullptr;
2579
0
    S.Diag(existingAttr->getLocation(), diag::err_mismatched_visibility);
2580
0
    S.Diag(range.getBegin(), diag::note_previous_attribute);
2581
0
    D->dropAttr<T>();
2582
0
  }
2583
203k
  
return ::new (S.Context) T(range, S.Context, value, attrSpellingListIndex)192k
;
2584
203k
}
2585
2586
VisibilityAttr *Sema::mergeVisibilityAttr(Decl *D, SourceRange Range,
2587
                                          VisibilityAttr::VisibilityType Vis,
2588
1.33M
                                          unsigned AttrSpellingListIndex) {
2589
1.33M
  return ::mergeVisibilityAttr<VisibilityAttr>(*this, D, Range, Vis,
2590
1.33M
                                               AttrSpellingListIndex);
2591
1.33M
}
2592
2593
TypeVisibilityAttr *Sema::mergeTypeVisibilityAttr(Decl *D, SourceRange Range,
2594
                                      TypeVisibilityAttr::VisibilityType Vis,
2595
203k
                                      unsigned AttrSpellingListIndex) {
2596
203k
  return ::mergeVisibilityAttr<TypeVisibilityAttr>(*this, D, Range, Vis,
2597
203k
                                                   AttrSpellingListIndex);
2598
203k
}
2599
2600
static void handleVisibilityAttr(Sema &S, Decl *D, const ParsedAttr &AL,
2601
1.41M
                                 bool isTypeVisibility) {
2602
1.41M
  // Visibility attributes don't mean anything on a typedef.
2603
1.41M
  if (isa<TypedefNameDecl>(D)) {
2604
1
    S.Diag(AL.getRange().getBegin(), diag::warn_attribute_ignored) << AL;
2605
1
    return;
2606
1
  }
2607
1.41M
2608
1.41M
  // 'type_visibility' can only go on a type or namespace.
2609
1.41M
  if (isTypeVisibility &&
2610
1.41M
      
!(191k
isa<TagDecl>(D)191k
||
2611
191k
        
isa<ObjCInterfaceDecl>(D)1
||
2612
191k
        
isa<NamespaceDecl>(D)1
)) {
2613
1
    S.Diag(AL.getRange().getBegin(), diag::err_attribute_wrong_decl_type)
2614
1
        << AL << ExpectedTypeOrNamespace;
2615
1
    return;
2616
1
  }
2617
1.41M
2618
1.41M
  // Check that the argument is a string literal.
2619
1.41M
  StringRef TypeStr;
2620
1.41M
  SourceLocation LiteralLoc;
2621
1.41M
  if (!S.checkStringLiteralArgumentAttr(AL, 0, TypeStr, &LiteralLoc))
2622
0
    return;
2623
1.41M
2624
1.41M
  VisibilityAttr::VisibilityType type;
2625
1.41M
  if (!VisibilityAttr::ConvertStrToVisibilityType(TypeStr, type)) {
2626
0
    S.Diag(LiteralLoc, diag::warn_attribute_type_not_supported) << AL
2627
0
                                                                << TypeStr;
2628
0
    return;
2629
0
  }
2630
1.41M
2631
1.41M
  // Complain about attempts to use protected visibility on targets
2632
1.41M
  // (like Darwin) that don't support it.
2633
1.41M
  if (type == VisibilityAttr::Protected &&
2634
1.41M
      
!S.Context.getTargetInfo().hasProtectedVisibility()32
) {
2635
3
    S.Diag(AL.getLoc(), diag::warn_attribute_protected_visibility);
2636
3
    type = VisibilityAttr::Default;
2637
3
  }
2638
1.41M
2639
1.41M
  unsigned Index = AL.getAttributeSpellingListIndex();
2640
1.41M
  Attr *newAttr;
2641
1.41M
  if (isTypeVisibility) {
2642
191k
    newAttr = S.mergeTypeVisibilityAttr(D, AL.getRange(),
2643
191k
                                    (TypeVisibilityAttr::VisibilityType) type,
2644
191k
                                        Index);
2645
1.22M
  } else {
2646
1.22M
    newAttr = S.mergeVisibilityAttr(D, AL.getRange(), type, Index);
2647
1.22M
  }
2648
1.41M
  if (newAttr)
2649
1.41M
    D->addAttr(newAttr);
2650
1.41M
}
2651
2652
18
static void handleObjCMethodFamilyAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2653
18
  const auto *M = cast<ObjCMethodDecl>(D);
2654
18
  if (!AL.isArgIdent(0)) {
2655
2
    S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
2656
2
        << AL << 1 << AANT_ArgumentIdentifier;
2657
2
    return;
2658
2
  }
2659
16
2660
16
  IdentifierLoc *IL = AL.getArgAsIdent(0);
2661
16
  ObjCMethodFamilyAttr::FamilyKind F;
2662
16
  if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind(IL->Ident->getName(), F)) {
2663
0
    S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL << IL->Ident;
2664
0
    return;
2665
0
  }
2666
16
2667
16
  if (F == ObjCMethodFamilyAttr::OMF_init &&
2668
16
      
!M->getReturnType()->isObjCObjectPointerType()14
) {
2669
0
    S.Diag(M->getLocation(), diag::err_init_method_bad_return_type)
2670
0
        << M->getReturnType();
2671
0
    // Ignore the attribute.
2672
0
    return;
2673
0
  }
2674
16
2675
16
  D->addAttr(new (S.Context) ObjCMethodFamilyAttr(
2676
16
      AL.getRange(), S.Context, F, AL.getAttributeSpellingListIndex()));
2677
16
}
2678
2679
15
static void handleObjCNSObject(Sema &S, Decl *D, const ParsedAttr &AL) {
2680
15
  if (const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
2681
9
    QualType T = TD->getUnderlyingType();
2682
9
    if (!T->isCARCBridgableType()) {
2683
1
      S.Diag(TD->getLocation(), diag::err_nsobject_attribute);
2684
1
      return;
2685
1
    }
2686
6
  }
2687
6
  else if (const auto *PD = dyn_cast<ObjCPropertyDecl>(D)) {
2688
4
    QualType T = PD->getType();
2689
4
    if (!T->isCARCBridgableType()) {
2690
1
      S.Diag(PD->getLocation(), diag::err_nsobject_attribute);
2691
1
      return;
2692
1
    }
2693
2
  }
2694
2
  else {
2695
2
    // It is okay to include this attribute on properties, e.g.:
2696
2
    //
2697
2
    //  @property (retain, nonatomic) struct Bork *Q __attribute__((NSObject));
2698
2
    //
2699
2
    // In this case it follows tradition and suppresses an error in the above
2700
2
    // case.
2701
2
    S.Diag(D->getLocation(), diag::warn_nsobject_attribute);
2702
2
  }
2703
15
  D->addAttr(::new (S.Context)
2704
13
             ObjCNSObjectAttr(AL.getRange(), S.Context,
2705
13
                              AL.getAttributeSpellingListIndex()));
2706
13
}
2707
2708
279
static void handleObjCIndependentClass(Sema &S, Decl *D, const ParsedAttr &AL) {
2709
279
  if (const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
2710
275
    QualType T = TD->getUnderlyingType();
2711
275
    if (!T->isObjCObjectPointerType()) {
2712
1
      S.Diag(TD->getLocation(), diag::warn_ptr_independentclass_attribute);
2713
1
      return;
2714
1
    }
2715
4
  } else {
2716
4
    S.Diag(D->getLocation(), diag::warn_independentclass_attribute);
2717
4
    return;
2718
4
  }
2719
274
  D->addAttr(::new (S.Context)
2720
274
             ObjCIndependentClassAttr(AL.getRange(), S.Context,
2721
274
                              AL.getAttributeSpellingListIndex()));
2722
274
}
2723
2724
551
static void handleBlocksAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2725
551
  if (!AL.isArgIdent(0)) {
2726
0
    S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
2727
0
        << AL << 1 << AANT_ArgumentIdentifier;
2728
0
    return;
2729
0
  }
2730
551
2731
551
  IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
2732
551
  BlocksAttr::BlockType type;
2733
551
  if (!BlocksAttr::ConvertStrToBlockType(II->getName(), type)) {
2734
0
    S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
2735
0
    return;
2736
0
  }
2737
551
2738
551
  D->addAttr(::new (S.Context)
2739
551
             BlocksAttr(AL.getRange(), S.Context, type,
2740
551
                        AL.getAttributeSpellingListIndex()));
2741
551
}
2742
2743
344
static void handleSentinelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2744
344
  unsigned sentinel = (unsigned)SentinelAttr::DefaultSentinel;
2745
344
  if (AL.getNumArgs() > 0) {
2746
307
    Expr *E = AL.getArgAsExpr(0);
2747
307
    llvm::APSInt Idx(32);
2748
307
    if (E->isTypeDependent() || E->isValueDependent() ||
2749
307
        !E->isIntegerConstantExpr(Idx, S.Context)) {
2750
4
      S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
2751
4
          << AL << 1 << AANT_ArgumentIntegerConstant << E->getSourceRange();
2752
4
      return;
2753
4
    }
2754
303
2755
303
    if (Idx.isSigned() && Idx.isNegative()) {
2756
4
      S.Diag(AL.getLoc(), diag::err_attribute_sentinel_less_than_zero)
2757
4
        << E->getSourceRange();
2758
4
      return;
2759
4
    }
2760
299
2761
299
    sentinel = Idx.getZExtValue();
2762
299
  }
2763
344
2764
344
  unsigned nullPos = (unsigned)SentinelAttr::DefaultNullPos;
2765
336
  if (AL.getNumArgs() > 1) {
2766
253
    Expr *E = AL.getArgAsExpr(1);
2767
253
    llvm::APSInt Idx(32);
2768
253
    if (E->isTypeDependent() || E->isValueDependent() ||
2769
253
        !E->isIntegerConstantExpr(Idx, S.Context)) {
2770
0
      S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
2771
0
          << AL << 2 << AANT_ArgumentIntegerConstant << E->getSourceRange();
2772
0
      return;
2773
0
    }
2774
253
    nullPos = Idx.getZExtValue();
2775
253
2776
253
    if ((Idx.isSigned() && Idx.isNegative()) || nullPos > 1) {
2777
3
      // FIXME: This error message could be improved, it would be nice
2778
3
      // to say what the bounds actually are.
2779
3
      S.Diag(AL.getLoc(), diag::err_attribute_sentinel_not_zero_or_one)
2780
3
        << E->getSourceRange();
2781
3
      return;
2782
3
    }
2783
333
  }
2784
333
2785
333
  if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
2786
61
    const FunctionType *FT = FD->getType()->castAs<FunctionType>();
2787
61
    if (isa<FunctionNoProtoType>(FT)) {
2788
2
      S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_named_arguments);
2789
2
      return;
2790
2
    }
2791
59
2792
59
    if (!cast<FunctionProtoType>(FT)->isVariadic()) {
2793
4
      S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
2794
4
      return;
2795
4
    }
2796
272
  } else if (const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
2797
256
    if (!MD->isVariadic()) {
2798
1
      S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
2799
1
      return;
2800
1
    }
2801
16
  } else if (const auto *BD = dyn_cast<BlockDecl>(D)) {
2802
4
    if (!BD->isVariadic()) {
2803
1
      S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 1;
2804
1
      return;
2805
1
    }
2806
12
  } else if (const auto *V = dyn_cast<VarDecl>(D)) {
2807
12
    QualType Ty = V->getType();
2808
12
    if (Ty->isBlockPointerType() || 
Ty->isFunctionPointerType()7
) {
2809
9
      const FunctionType *FT = Ty->isFunctionPointerType()
2810
9
       ? 
D->getFunctionType()4
2811
9
       : 
Ty->getAs<BlockPointerType>()->getPointeeType()->getAs<FunctionType>()5
;
2812
9
      if (!cast<FunctionProtoType>(FT)->isVariadic()) {
2813
1
        int m = Ty->isFunctionPointerType() ? 
00
: 1;
2814
1
        S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << m;
2815
1
        return;
2816
1
      }
2817
3
    } else {
2818
3
      S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
2819
3
          << AL << ExpectedFunctionMethodOrBlock;
2820
3
      return;
2821
3
    }
2822
0
  } else {
2823
0
    S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
2824
0
        << AL << ExpectedFunctionMethodOrBlock;
2825
0
    return;
2826
0
  }
2827
321
  D->addAttr(::new (S.Context)
2828
321
             SentinelAttr(AL.getRange(), S.Context, sentinel, nullPos,
2829
321
                          AL.getAttributeSpellingListIndex()));
2830
321
}
2831
2832
10.1k
static void handleWarnUnusedResult(Sema &S, Decl *D, const ParsedAttr &AL) {
2833
10.1k
  if (D->getFunctionType() &&
2834
10.1k
      
D->getFunctionType()->getReturnType()->isVoidType()10.1k
) {
2835
1
    S.Diag(AL.getLoc(), diag::warn_attribute_void_function_method) << AL << 0;
2836
1
    return;
2837
1
  }
2838
10.1k
  if (const auto *MD = dyn_cast<ObjCMethodDecl>(D))
2839
4
    if (MD->getReturnType()->isVoidType()) {
2840
1
      S.Diag(AL.getLoc(), diag::warn_attribute_void_function_method) << AL << 1;
2841
1
      return;
2842
1
    }
2843
10.1k
2844
10.1k
  StringRef Str;
2845
10.1k
  if ((AL.isCXX11Attribute() || 
AL.isC2xAttribute()10.0k
) &&
!AL.getScopeName()59
) {
2846
50
    // If this is spelled as the standard C++17 attribute, but not in C++17,
2847
50
    // warn about using it as an extension. If there are attribute arguments,
2848
50
    // then claim it's a C++2a extension instead.
2849
50
    // FIXME: If WG14 does not seem likely to adopt the same feature, add an
2850
50
    // extension warning for C2x mode.
2851
50
    const LangOptions &LO = S.getLangOpts();
2852
50
    if (AL.getNumArgs() == 1) {
2853
17
      if (LO.CPlusPlus && 
!LO.CPlusPlus2a16
)
2854
10
        S.Diag(AL.getLoc(), diag::ext_cxx2a_attr) << AL;
2855
17
2856
17
      // Since this this is spelled [[nodiscard]], get the optional string
2857
17
      // literal. If in C++ mode, but not in C++2a mode, diagnose as an
2858
17
      // extension.
2859
17
      // FIXME: C2x should support this feature as well, even as an extension.
2860
17
      if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, nullptr))
2861
0
        return;
2862
33
    } else if (LO.CPlusPlus && 
!LO.CPlusPlus1724
)
2863
7
      S.Diag(AL.getLoc(), diag::ext_cxx17_attr) << AL;
2864
50
  }
2865
10.1k
2866
10.1k
  D->addAttr(::new (S.Context)
2867
10.1k
             WarnUnusedResultAttr(AL.getRange(), S.Context, Str,
2868
10.1k
                                  AL.getAttributeSpellingListIndex()));
2869
10.1k
}
2870
2871
137
static void handleWeakImportAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2872
137
  // weak_import only applies to variable & function declarations.
2873
137
  bool isDef = false;
2874
137
  if (!D->canBeWeakImported(isDef)) {
2875
9
    if (isDef)
2876
3
      S.Diag(AL.getLoc(), diag::warn_attribute_invalid_on_definition)
2877
3
        << "weak_import";
2878
6
    else if (isa<ObjCPropertyDecl>(D) || 
isa<ObjCMethodDecl>(D)5
||
2879
6
             
(3
S.Context.getTargetInfo().getTriple().isOSDarwin()3
&&
2880
5
              
(3
isa<ObjCInterfaceDecl>(D)3
||
isa<EnumDecl>(D)3
))) {
2881
5
      // Nothing to warn about here.
2882
5
    } else
2883
1
      S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
2884
1
          << AL << ExpectedVariableOrFunction;
2885
9
2886
9
    return;
2887
9
  }
2888
128
2889
128
  D->addAttr(::new (S.Context)
2890
128
             WeakImportAttr(AL.getRange(), S.Context,
2891
128
                            AL.getAttributeSpellingListIndex()));
2892
128
}
2893
2894
// Handles reqd_work_group_size and work_group_size_hint.
2895
template <typename WorkGroupAttr>
2896
20
static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
2897
20
  uint32_t WGSize[3];
2898
71
  for (unsigned i = 0; i < 3; 
++i51
) {
2899
56
    const Expr *E = AL.getArgAsExpr(i);
2900
56
    if (!checkUInt32Argument(S, AL, E, WGSize[i], i,
2901
56
                             /*StrictlyUnsigned=*/true))
2902
2
      return;
2903
54
    if (WGSize[i] == 0) {
2904
3
      S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero)
2905
3
          << AL << E->getSourceRange();
2906
3
      return;
2907
3
    }
2908
54
  }
2909
20
2910
20
  WorkGroupAttr *Existing = D->getAttr<WorkGroupAttr>();
2911
15
  if (Existing && 
!(1
Existing->getXDim() == WGSize[0]1
&&
2912
1
                    
Existing->getYDim() == WGSize[1]0
&&
2913
1
                    
Existing->getZDim() == WGSize[2]0
))
2914
1
    S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
2915
15
2916
15
  D->addAttr(::new (S.Context) WorkGroupAttr(AL.getRange(), S.Context,
2917
15
                                             WGSize[0], WGSize[1], WGSize[2],
2918
15
                                       AL.getAttributeSpellingListIndex()));
2919
15
}
SemaDeclAttr.cpp:void handleWorkGroupSize<clang::WorkGroupSizeHintAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
2896
6
static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
2897
6
  uint32_t WGSize[3];
2898
22
  for (unsigned i = 0; i < 3; 
++i16
) {
2899
17
    const Expr *E = AL.getArgAsExpr(i);
2900
17
    if (!checkUInt32Argument(S, AL, E, WGSize[i], i,
2901
17
                             /*StrictlyUnsigned=*/true))
2902
1
      return;
2903
16
    if (WGSize[i] == 0) {
2904
0
      S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero)
2905
0
          << AL << E->getSourceRange();
2906
0
      return;
2907
0
    }
2908
16
  }
2909
6
2910
6
  WorkGroupAttr *Existing = D->getAttr<WorkGroupAttr>();
2911
5
  if (Existing && 
!(1
Existing->getXDim() == WGSize[0]1
&&
2912
1
                    
Existing->getYDim() == WGSize[1]0
&&
2913
1
                    
Existing->getZDim() == WGSize[2]0
))
2914
1
    S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
2915
5
2916
5
  D->addAttr(::new (S.Context) WorkGroupAttr(AL.getRange(), S.Context,
2917
5
                                             WGSize[0], WGSize[1], WGSize[2],
2918
5
                                       AL.getAttributeSpellingListIndex()));
2919
5
}
SemaDeclAttr.cpp:void handleWorkGroupSize<clang::ReqdWorkGroupSizeAttr>(clang::Sema&, clang::Decl*, clang::ParsedAttr const&)
Line
Count
Source
2896
14
static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
2897
14
  uint32_t WGSize[3];
2898
49
  for (unsigned i = 0; i < 3; 
++i35
) {
2899
39
    const Expr *E = AL.getArgAsExpr(i);
2900
39
    if (!checkUInt32Argument(S, AL, E, WGSize[i], i,
2901
39
                             /*StrictlyUnsigned=*/true))
2902
1
      return;
2903
38
    if (WGSize[i] == 0) {
2904
3
      S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero)
2905
3
          << AL << E->getSourceRange();
2906
3
      return;
2907
3
    }
2908
38
  }
2909
14
2910
14
  WorkGroupAttr *Existing = D->getAttr<WorkGroupAttr>();
2911
10
  if (Existing && 
!(0
Existing->getXDim() == WGSize[0]0
&&
2912
0
                    Existing->getYDim() == WGSize[1] &&
2913
0
                    Existing->getZDim() == WGSize[2]))
2914
0
    S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
2915
10
2916
10
  D->addAttr(::new (S.Context) WorkGroupAttr(AL.getRange(), S.Context,
2917
10
                                             WGSize[0], WGSize[1], WGSize[2],
2918
10
                                       AL.getAttributeSpellingListIndex()));
2919
10
}
2920
2921
// Handles intel_reqd_sub_group_size.
2922
6
static void handleSubGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
2923
6
  uint32_t SGSize;
2924
6
  const Expr *E = AL.getArgAsExpr(0);
2925
6
  if (!checkUInt32Argument(S, AL, E, SGSize))
2926
0
    return;
2927
6
  if (SGSize == 0) {
2928
1
    S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero)
2929
1
        << AL << E->getSourceRange();
2930
1
    return;
2931
1
  }
2932
5
2933
5
  OpenCLIntelReqdSubGroupSizeAttr *Existing =
2934
5
      D->getAttr<OpenCLIntelReqdSubGroupSizeAttr>();
2935
5
  if (Existing && 
Existing->getSubGroupSize() != SGSize1
)
2936
1
    S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
2937
5
2938
5
  D->addAttr(::new (S.Context) OpenCLIntelReqdSubGroupSizeAttr(
2939
5
      AL.getRange(), S.Context, SGSize,
2940
5
      AL.getAttributeSpellingListIndex()));
2941
5
}
2942
2943
8
static void handleVecTypeHint(Sema &S, Decl *D, const ParsedAttr &AL) {
2944
8
  if (!AL.hasParsedType()) {
2945
0
    S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
2946
0
    return;
2947
0
  }
2948
8
2949
8
  TypeSourceInfo *ParmTSI = nullptr;
2950
8
  QualType ParmType = S.GetTypeFromParser(AL.getTypeArg(), &ParmTSI);
2951
8
  assert(ParmTSI && "no type source info for attribute argument");
2952
8
2953
8
  if (!ParmType->isExtVectorType() && 
!ParmType->isFloatingType()7
&&
2954
8
      
(6
ParmType->isBooleanType()6
||
2955
6
       
!ParmType->isIntegralType(S.getASTContext())5
)) {
2956
2
    S.Diag(AL.getLoc(), diag::err_attribute_argument_vec_type_hint)
2957
2
        << ParmType;
2958
2
    return;
2959
2
  }
2960
6
2961
6
  if (VecTypeHintAttr *A = D->getAttr<VecTypeHintAttr>()) {
2962
1
    if (!S.Context.hasSameType(A->getTypeHint(), ParmType)) {
2963
1
      S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
2964
1
      return;
2965
1
    }
2966
5
  }
2967
5
2968
5
  D->addAttr(::new (S.Context) VecTypeHintAttr(AL.getLoc(), S.Context,
2969
5
                                               ParmTSI,
2970
5
                                        AL.getAttributeSpellingListIndex()));
2971
5
}
2972
2973
SectionAttr *Sema::mergeSectionAttr(Decl *D, SourceRange Range,
2974
                                    StringRef Name,
2975
5.90k
                                    unsigned AttrSpellingListIndex) {
2976
5.90k
  // Explicit or partial specializations do not inherit
2977
5.90k
  // the section attribute from the primary template.
2978
5.90k
  if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
2979
38
    if (AttrSpellingListIndex == SectionAttr::Declspec_allocate &&
2980
38
        
FD->isFunctionTemplateSpecialization()3
)
2981
3
      return nullptr;
2982
5.89k
  }
2983
5.89k
  if (SectionAttr *ExistingAttr = D->getAttr<SectionAttr>()) {
2984
4
    if (ExistingAttr->getName() == Name)
2985
0
      return nullptr;
2986
4
    Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section)
2987
4
         << 1 /*section*/;
2988
4
    Diag(Range.getBegin(), diag::note_previous_attribute);
2989
4
    return nullptr;
2990
4
  }
2991
5.89k
  return ::new (Context) SectionAttr(Range, Context, Name,
2992
5.89k
                                     AttrSpellingListIndex);
2993
5.89k
}
2994
2995
5.92k
bool Sema::checkSectionName(SourceLocation LiteralLoc, StringRef SecName) {
2996
5.92k
  std::string Error = Context.getTargetInfo().isValidSectionSpecifier(SecName);
2997
5.92k
  if (!Error.empty()) {
2998
2
    Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target) << Error
2999
2
         << 1 /*'section'*/;
3000
2
    return false;
3001
2
  }
3002
5.92k
  return true;
3003
5.92k
}
3004
3005
5.88k
static void handleSectionAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3006
5.88k
  // Make sure that there is a string literal as the sections's single
3007
5.88k
  // argument.
3008
5.88k
  StringRef Str;
3009
5.88k
  SourceLocation LiteralLoc;
3010
5.88k
  if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc))
3011
2
    return;
3012
5.88k
3013
5.88k
  if (!S.checkSectionName(LiteralLoc, Str))
3014
1
    return;
3015
5.88k
3016
5.88k
  // If the target wants to validate the section specifier, make it happen.
3017
5.88k
  std::string Error = S.Context.getTargetInfo().isValidSectionSpecifier(Str);
3018
5.88k
  if (!Error.empty()) {
3019
0
    S.Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
3020
0
    << Error;
3021
0
    return;
3022
0
  }
3023
5.88k
3024
5.88k
  unsigned Index = AL.getAttributeSpellingListIndex();
3025
5.88k
  SectionAttr *NewAttr = S.mergeSectionAttr(D, AL.getRange(), Str, Index);
3026
5.88k
  if (NewAttr)
3027
5.88k
    D->addAttr(NewAttr);
3028
5.88k
}
3029
3030
// This is used for `__declspec(code_seg("segname"))` on a decl.
3031
// `#pragma code_seg("segname")` uses checkSectionName() instead.
3032
static bool checkCodeSegName(Sema &S, SourceLocation LiteralLoc,
3033
82
                             StringRef CodeSegName) {
3034
82
  std::string Error =
3035
82
      S.Context.getTargetInfo().isValidSectionSpecifier(CodeSegName);
3036
82
  if (!Error.empty()) {
3037
0
    S.Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
3038
0
        << Error << 0 /*'code-seg'*/;
3039
0
    return false;
3040
0
  }
3041
82
3042
82
  return true;
3043
82
}
3044
3045
CodeSegAttr *Sema::mergeCodeSegAttr(Decl *D, SourceRange Range,
3046
                                    StringRef Name,
3047
93
                                    unsigned AttrSpellingListIndex) {
3048
93
  // Explicit or partial specializations do not inherit
3049
93
  // the code_seg attribute from the primary template.
3050
93
  if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
3051
46
    if (FD->isFunctionTemplateSpecialization())
3052
3
      return nullptr;
3053
90
  }
3054
90
  if (const auto *ExistingAttr = D->getAttr<CodeSegAttr>()) {
3055
14
    if (ExistingAttr->getName() == Name)
3056
12
      return nullptr;
3057
2
    Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section)
3058
2
         << 0 /*codeseg*/;
3059
2
    Diag(Range.getBegin(), diag::note_previous_attribute);
3060
2
    return nullptr;
3061
2
  }
3062
76
  return ::new (Context) CodeSegAttr(Range, Context, Name,
3063
76
                                     AttrSpellingListIndex);
3064
76
}
3065
3066
82
static void handleCodeSegAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3067
82
  StringRef Str;
3068
82
  SourceLocation LiteralLoc;
3069
82
  if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc))
3070
0
    return;
3071
82
  if (!checkCodeSegName(S, LiteralLoc, Str))
3072
0
    return;
3073
82
  if (const auto *ExistingAttr = D->getAttr<CodeSegAttr>()) {
3074
14
    if (!ExistingAttr->isImplicit()) {
3075
6
      S.Diag(AL.getLoc(),
3076
6
             ExistingAttr->getName() == Str
3077
6
             ? 
diag::warn_duplicate_codeseg_attribute3
3078
6
             : 
diag::err_conflicting_codeseg_attribute3
);
3079
6
      return;
3080
6
    }
3081
8
    D->dropAttr<CodeSegAttr>();
3082
8
  }
3083
82
  
if (CodeSegAttr *76
CSA76
= S.mergeCodeSegAttr(D, AL.getRange(), Str,
3084
76
                                            AL.getAttributeSpellingListIndex()))
3085
76
    D->addAttr(CSA);
3086
76
}
3087
3088
// Check for things we'd like to warn about. Multiversioning issues are
3089
// handled later in the process, once we know how many exist.
3090
738k
bool Sema::checkTargetAttr(SourceLocation LiteralLoc, StringRef AttrStr) {
3091
738k
  enum FirstParam { Unsupported, Duplicate };
3092
738k
  enum SecondParam { None, Architecture };
3093
738k
  for (auto Str : {"tune=", "fpmath="})
3094
1.47M
    if (AttrStr.find(Str) != StringRef::npos)
3095
4
      return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3096
4
             << Unsupported << None << Str;
3097
738k
3098
738k
  TargetAttr::ParsedTargetAttr ParsedAttrs = TargetAttr::parse(AttrStr);
3099
738k
3100
738k
  if (!ParsedAttrs.Architecture.empty() &&
3101
738k
      
!Context.getTargetInfo().isValidCPUName(ParsedAttrs.Architecture)135
)
3102
3
    return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3103
3
           << Unsupported << Architecture << ParsedAttrs.Architecture;
3104
738k
3105
738k
  if (ParsedAttrs.DuplicateArchitecture)
3106
1
    return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3107
1
           << Duplicate << None << "arch=";
3108
738k
3109
872k
  
for (const auto &Feature : ParsedAttrs.Features)738k
{
3110
872k
    auto CurFeature = StringRef(Feature).drop_front(); // remove + or -.
3111
872k
    if (!Context.getTargetInfo().isValidFeatureName(CurFeature))
3112
4
      return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3113
4
             << Unsupported << None << CurFeature;
3114
872k
  }
3115
738k
3116
738k
  
return false738k
;
3117
738k
}
3118
3119
738k
static void handleTargetAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3120
738k
  StringRef Str;
3121
738k
  SourceLocation LiteralLoc;
3122
738k
  if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc) ||
3123
738k
      S.checkTargetAttr(LiteralLoc, Str))
3124
12
    return;
3125
738k
3126
738k
  unsigned Index = AL.getAttributeSpellingListIndex();
3127
738k
  TargetAttr *NewAttr =
3128
738k
      ::new (S.Context) TargetAttr(AL.getRange(), S.Context, Str, Index);
3129
738k
  D->addAttr(NewAttr);
3130
738k
}
3131
3132
701k
static void handleMinVectorWidthAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3133
701k
  Expr *E = AL.getArgAsExpr(0);
3134
701k
  uint32_t VecWidth;
3135
701k
  if (!checkUInt32Argument(S, AL, E, VecWidth)) {
3136
1
    AL.setInvalid();
3137
1
    return;
3138
1
  }
3139
701k
3140
701k
  MinVectorWidthAttr *Existing = D->getAttr<MinVectorWidthAttr>();
3141
701k
  if (Existing && 
Existing->getVectorWidth() != VecWidth1
) {
3142
1
    S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
3143
1
    return;
3144
1
  }
3145
701k
3146
701k
  D->addAttr(::new (S.Context)
3147
701k
             MinVectorWidthAttr(AL.getRange(), S.Context, VecWidth,
3148
701k
                                AL.getAttributeSpellingListIndex()));
3149
701k
}
3150
3151
37
static void handleCleanupAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3152
37
  Expr *E = AL.getArgAsExpr(0);
3153
37
  SourceLocation Loc = E->getExprLoc();
3154
37
  FunctionDecl *FD = nullptr;
3155
37
  DeclarationNameInfo NI;
3156
37
3157
37
  // gcc only allows for simple identifiers. Since we support more than gcc, we
3158
37
  // will warn the user.
3159
37
  if (auto *DRE = dyn_cast<DeclRefExpr>(E)) {
3160
34
    if (DRE->hasQualifier())
3161
4
      S.Diag(Loc, diag::warn_cleanup_ext);
3162
34
    FD = dyn_cast<FunctionDecl>(DRE->getDecl());
3163
34
    NI = DRE->getNameInfo();
3164
34
    if (!FD) {
3165
1
      S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 1
3166
1
        << NI.getName();
3167
1
      return;
3168
1
    }
3169
3
  } else if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(E)) {
3170
2
    if (ULE->hasExplicitTemplateArgs())
3171
1
      S.Diag(Loc, diag::warn_cleanup_ext);
3172
2
    FD = S.ResolveSingleFunctionTemplateSpecialization(ULE, true);
3173
2
    NI = ULE->getNameInfo();
3174
2
    if (!FD) {
3175
1
      S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 2
3176
1
        << NI.getName();
3177
1
      if (ULE->getType() == S.Context.OverloadTy)
3178
1
        S.NoteAllOverloadCandidates(ULE);
3179
1
      return;
3180
1
    }
3181
1
  } else {
3182
1
    S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 0;
3183
1
    return;
3184
1
  }
3185
34
3186
34
  if (FD->getNumParams() != 1) {
3187
1
    S.Diag(Loc, diag::err_attribute_cleanup_func_must_take_one_arg)
3188
1
      << NI.getName();
3189
1
    return;
3190
1
  }
3191
33
3192
33
  // We're currently more strict than GCC about what function types we accept.
3193
33
  // If this ever proves to be a problem it should be easy to fix.
3194
33
  QualType Ty = S.Context.getPointerType(cast<VarDecl>(D)->getType());
3195
33
  QualType ParamTy = FD->getParamDecl(0)->getType();
3196
33
  if (S.CheckAssignmentConstraints(FD->getParamDecl(0)->getLocation(),
3197
33
                                   ParamTy, Ty) != Sema::Compatible) {
3198
1
    S.Diag(Loc, diag::err_attribute_cleanup_func_arg_incompatible_type)
3199
1
      << NI.getName() << ParamTy << Ty;
3200
1
    return;
3201
1
  }
3202
32
3203
32
  D->addAttr(::new (S.Context)
3204
32
             CleanupAttr(AL.getRange(), S.Context, FD,
3205
32
                         AL.getAttributeSpellingListIndex()));
3206
32
}
3207
3208
static void handleEnumExtensibilityAttr(Sema &S, Decl *D,
3209
2.75k
                                        const ParsedAttr &AL) {
3210
2.75k
  if (!AL.isArgIdent(0)) {
3211
0
    S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
3212
0
        << AL << 0 << AANT_ArgumentIdentifier;
3213
0
    return;
3214
0
  }
3215
2.75k
3216
2.75k
  EnumExtensibilityAttr::Kind ExtensibilityKind;
3217
2.75k
  IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
3218
2.75k
  if (!EnumExtensibilityAttr::ConvertStrToKind(II->getName(),
3219
2.75k
                                               ExtensibilityKind)) {
3220
1
    S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
3221
1
    return;
3222
1
  }
3223
2.75k
3224
2.75k
  D->addAttr(::new (S.Context) EnumExtensibilityAttr(
3225
2.75k
      AL.getRange(), S.Context, ExtensibilityKind,
3226
2.75k
      AL.getAttributeSpellingListIndex()));
3227
2.75k
}
3228
3229
/// Handle __attribute__((format_arg((idx)))) attribute based on
3230
/// http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
3231
339
static void handleFormatArgAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3232
339
  Expr *IdxExpr = AL.getArgAsExpr(0);
3233
339
  ParamIdx Idx;
3234
339
  if (!checkFunctionOrMethodParameterIndex(S, D, AL, 1, IdxExpr, Idx))
3235
2
    return;
3236
337
3237
337
  // Make sure the format string is really a string.
3238
337
  QualType Ty = getFunctionOrMethodParamType(D, Idx.getASTIndex());
3239
337
3240
337
  bool NotNSStringTy = !isNSStringType(Ty, S.Context);
3241
337
  if (NotNSStringTy &&
3242
337
      
!isCFStringType(Ty, S.Context)313
&&
3243
337
      
(298
!Ty->isPointerType()298
||
3244
298
       
!Ty->getAs<PointerType>()->getPointeeType()->isCharType()296
)) {
3245
2
    S.Diag(AL.getLoc(), diag::err_format_attribute_not)
3246
2
        << "a string type" << IdxExpr->getSourceRange()
3247
2
        << getFunctionOrMethodParamRange(D, 0);
3248
2
    return;
3249
2
  }
3250
335
  Ty = getFunctionOrMethodResultType(D);
3251
335
  if (!isNSStringType(Ty, S.Context) &&
3252
335
      
!isCFStringType(Ty, S.Context)312
&&
3253
335
      
(282
!Ty->isPointerType()282
||
3254
282
       
!Ty->getAs<PointerType>()->getPointeeType()->isCharType()281
)) {
3255
1
    S.Diag(AL.getLoc(), diag::err_format_attribute_result_not)
3256
1
        << (NotNSStringTy ? 
"string type"0
: "NSString")
3257
1
        << IdxExpr->getSourceRange() << getFunctionOrMethodParamRange(D, 0);
3258
1
    return;
3259
1
  }
3260
334
3261
334
  D->addAttr(::new (S.Context) FormatArgAttr(
3262
334
      AL.getRange(), S.Context, Idx, AL.getAttributeSpellingListIndex()));
3263
334
}
3264
3265
enum FormatAttrKind {
3266
  CFStringFormat,
3267
  NSStringFormat,
3268
  StrftimeFormat,
3269
  SupportedFormat,
3270
  IgnoredFormat,
3271
  InvalidFormat
3272
};
3273
3274
/// getFormatAttrKind - Map from format attribute names to supported format
3275
/// types.
3276
51.5k
static FormatAttrKind getFormatAttrKind(StringRef Format) {