File: | build-llvm/tools/clang/include/clang/AST/Attrs.inc |
Warning: | line 9616, column 5 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 | static bool isFunctionOrMethod(const Decl *D) { | |||
58 | return (D->getFunctionType() != nullptr) || isa<ObjCMethodDecl>(D); | |||
59 | } | |||
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 | static bool isFunctionOrMethodOrBlock(const Decl *D) { | |||
64 | return isFunctionOrMethod(D) || isa<BlockDecl>(D); | |||
65 | } | |||
66 | ||||
67 | /// Return true if the given decl has a declarator that should have | |||
68 | /// been processed by Sema::GetTypeForDeclarator. | |||
69 | static bool hasDeclarator(const Decl *D) { | |||
70 | // In some sense, TypedefDecl really *ought* to be a DeclaratorDecl. | |||
71 | return isa<DeclaratorDecl>(D) || isa<BlockDecl>(D) || isa<TypedefNameDecl>(D) || | |||
72 | isa<ObjCPropertyDecl>(D); | |||
73 | } | |||
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 | static bool hasFunctionProto(const Decl *D) { | |||
79 | if (const FunctionType *FnTy = D->getFunctionType()) | |||
80 | return isa<FunctionProtoType>(FnTy); | |||
81 | return isa<ObjCMethodDecl>(D) || isa<BlockDecl>(D); | |||
82 | } | |||
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 | static unsigned getFunctionOrMethodNumParams(const Decl *D) { | |||
88 | if (const FunctionType *FnTy = D->getFunctionType()) | |||
89 | return cast<FunctionProtoType>(FnTy)->getNumParams(); | |||
90 | if (const auto *BD = dyn_cast<BlockDecl>(D)) | |||
91 | return BD->getNumParams(); | |||
92 | return cast<ObjCMethodDecl>(D)->param_size(); | |||
93 | } | |||
94 | ||||
95 | static const ParmVarDecl *getFunctionOrMethodParam(const Decl *D, | |||
96 | unsigned Idx) { | |||
97 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) | |||
98 | return FD->getParamDecl(Idx); | |||
99 | if (const auto *MD = dyn_cast<ObjCMethodDecl>(D)) | |||
100 | return MD->getParamDecl(Idx); | |||
101 | if (const auto *BD = dyn_cast<BlockDecl>(D)) | |||
102 | return BD->getParamDecl(Idx); | |||
103 | return nullptr; | |||
104 | } | |||
105 | ||||
106 | static QualType getFunctionOrMethodParamType(const Decl *D, unsigned Idx) { | |||
107 | if (const FunctionType *FnTy = D->getFunctionType()) | |||
108 | return cast<FunctionProtoType>(FnTy)->getParamType(Idx); | |||
109 | if (const auto *BD = dyn_cast<BlockDecl>(D)) | |||
110 | return BD->getParamDecl(Idx)->getType(); | |||
111 | ||||
112 | return cast<ObjCMethodDecl>(D)->parameters()[Idx]->getType(); | |||
113 | } | |||
114 | ||||
115 | static SourceRange getFunctionOrMethodParamRange(const Decl *D, unsigned Idx) { | |||
116 | if (auto *PVD = getFunctionOrMethodParam(D, Idx)) | |||
117 | return PVD->getSourceRange(); | |||
118 | return SourceRange(); | |||
119 | } | |||
120 | ||||
121 | static QualType getFunctionOrMethodResultType(const Decl *D) { | |||
122 | if (const FunctionType *FnTy = D->getFunctionType()) | |||
123 | return FnTy->getReturnType(); | |||
124 | return cast<ObjCMethodDecl>(D)->getReturnType(); | |||
125 | } | |||
126 | ||||
127 | static SourceRange getFunctionOrMethodResultSourceRange(const Decl *D) { | |||
128 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) | |||
129 | return FD->getReturnTypeSourceRange(); | |||
130 | if (const auto *MD = dyn_cast<ObjCMethodDecl>(D)) | |||
131 | return MD->getReturnTypeSourceRange(); | |||
132 | return SourceRange(); | |||
133 | } | |||
134 | ||||
135 | static bool isFunctionOrMethodVariadic(const Decl *D) { | |||
136 | if (const FunctionType *FnTy = D->getFunctionType()) | |||
137 | return cast<FunctionProtoType>(FnTy)->isVariadic(); | |||
138 | if (const auto *BD = dyn_cast<BlockDecl>(D)) | |||
139 | return BD->isVariadic(); | |||
140 | return cast<ObjCMethodDecl>(D)->isVariadic(); | |||
141 | } | |||
142 | ||||
143 | static bool isInstanceMethod(const Decl *D) { | |||
144 | if (const auto *MethodDecl = dyn_cast<CXXMethodDecl>(D)) | |||
145 | return MethodDecl->isInstance(); | |||
146 | return false; | |||
147 | } | |||
148 | ||||
149 | static inline bool isNSStringType(QualType T, ASTContext &Ctx) { | |||
150 | const auto *PT = T->getAs<ObjCObjectPointerType>(); | |||
151 | if (!PT) | |||
152 | return false; | |||
153 | ||||
154 | ObjCInterfaceDecl *Cls = PT->getObjectType()->getInterface(); | |||
155 | if (!Cls) | |||
156 | return false; | |||
157 | ||||
158 | IdentifierInfo* ClsName = Cls->getIdentifier(); | |||
159 | ||||
160 | // FIXME: Should we walk the chain of classes? | |||
161 | return ClsName == &Ctx.Idents.get("NSString") || | |||
162 | ClsName == &Ctx.Idents.get("NSMutableString"); | |||
163 | } | |||
164 | ||||
165 | static inline bool isCFStringType(QualType T, ASTContext &Ctx) { | |||
166 | const auto *PT = T->getAs<PointerType>(); | |||
167 | if (!PT) | |||
168 | return false; | |||
169 | ||||
170 | const auto *RT = PT->getPointeeType()->getAs<RecordType>(); | |||
171 | if (!RT) | |||
172 | return false; | |||
173 | ||||
174 | const RecordDecl *RD = RT->getDecl(); | |||
175 | if (RD->getTagKind() != TTK_Struct) | |||
176 | return false; | |||
177 | ||||
178 | return RD->getIdentifier() == &Ctx.Idents.get("__CFString"); | |||
179 | } | |||
180 | ||||
181 | static unsigned getNumAttributeArgs(const ParsedAttr &AL) { | |||
182 | // FIXME: Include the type in the argument list. | |||
183 | return AL.getNumArgs() + AL.hasParsedType(); | |||
184 | } | |||
185 | ||||
186 | template <typename Compare> | |||
187 | static bool checkAttributeNumArgsImpl(Sema &S, const ParsedAttr &AL, | |||
188 | unsigned Num, unsigned Diag, | |||
189 | Compare Comp) { | |||
190 | if (Comp(getNumAttributeArgs(AL), Num)) { | |||
191 | S.Diag(AL.getLoc(), Diag) << AL << Num; | |||
192 | return false; | |||
193 | } | |||
194 | ||||
195 | return true; | |||
196 | } | |||
197 | ||||
198 | /// Check if the attribute has exactly as many args as Num. May | |||
199 | /// output an error. | |||
200 | static bool checkAttributeNumArgs(Sema &S, const ParsedAttr &AL, unsigned Num) { | |||
201 | return checkAttributeNumArgsImpl(S, AL, Num, | |||
202 | diag::err_attribute_wrong_number_arguments, | |||
203 | std::not_equal_to<unsigned>()); | |||
204 | } | |||
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 | unsigned Num) { | |||
210 | return checkAttributeNumArgsImpl(S, AL, Num, | |||
211 | diag::err_attribute_too_few_arguments, | |||
212 | std::less<unsigned>()); | |||
213 | } | |||
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 | unsigned Num) { | |||
219 | return checkAttributeNumArgsImpl(S, AL, Num, | |||
220 | diag::err_attribute_too_many_arguments, | |||
221 | std::greater<unsigned>()); | |||
222 | } | |||
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 | getAttrLoc(const AttrInfo &AL) { | |||
230 | return AL.getLocation(); | |||
231 | } | |||
232 | 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(2147483647 *2U +1U), | |||
242 | bool StrictlyUnsigned = false) { | |||
243 | llvm::APSInt I(32); | |||
244 | if (Expr->isTypeDependent() || Expr->isValueDependent() || | |||
245 | !Expr->isIntegerConstantExpr(I, S.Context)) { | |||
246 | if (Idx != UINT_MAX(2147483647 *2U +1U)) | |||
247 | S.Diag(getAttrLoc(AI), diag::err_attribute_argument_n_type) | |||
248 | << &AI << Idx << AANT_ArgumentIntegerConstant | |||
249 | << Expr->getSourceRange(); | |||
250 | else | |||
251 | S.Diag(getAttrLoc(AI), diag::err_attribute_argument_type) | |||
252 | << &AI << AANT_ArgumentIntegerConstant << Expr->getSourceRange(); | |||
253 | return false; | |||
254 | } | |||
255 | ||||
256 | if (!I.isIntN(32)) { | |||
257 | S.Diag(Expr->getExprLoc(), diag::err_ice_too_large) | |||
258 | << I.toString(10, false) << 32 << /* Unsigned */ 1; | |||
259 | return false; | |||
260 | } | |||
261 | ||||
262 | if (StrictlyUnsigned && I.isSigned() && I.isNegative()) { | |||
263 | S.Diag(getAttrLoc(AI), diag::err_attribute_requires_positive_integer) | |||
264 | << &AI << /*non-negative*/ 1; | |||
265 | return false; | |||
266 | } | |||
267 | ||||
268 | Val = (uint32_t)I.getZExtValue(); | |||
269 | return true; | |||
270 | } | |||
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 | int &Val, unsigned Idx = UINT_MAX(2147483647 *2U +1U)) { | |||
278 | uint32_t UVal; | |||
279 | if (!checkUInt32Argument(S, AI, Expr, UVal, Idx)) | |||
280 | return false; | |||
281 | ||||
282 | if (UVal > (uint32_t)std::numeric_limits<int>::max()) { | |||
283 | llvm::APSInt I(32); // for toString | |||
284 | I = UVal; | |||
285 | S.Diag(Expr->getExprLoc(), diag::err_ice_too_large) | |||
286 | << I.toString(10, false) << 32 << /* Unsigned */ 0; | |||
287 | return false; | |||
288 | } | |||
289 | ||||
290 | Val = UVal; | |||
291 | return true; | |||
292 | } | |||
293 | ||||
294 | /// Diagnose mutually exclusive attributes when present on a given | |||
295 | /// declaration. Returns true if diagnosed. | |||
296 | template <typename AttrTy> | |||
297 | static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
298 | if (const auto *A = D->getAttr<AttrTy>()) { | |||
299 | S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A; | |||
300 | S.Diag(A->getLocation(), diag::note_conflicting_attribute); | |||
301 | return true; | |||
302 | } | |||
303 | return false; | |||
304 | } | |||
305 | ||||
306 | template <typename AttrTy> | |||
307 | static bool checkAttrMutualExclusion(Sema &S, Decl *D, const Attr &AL) { | |||
308 | if (const auto *A = D->getAttr<AttrTy>()) { | |||
309 | S.Diag(AL.getLocation(), diag::err_attributes_are_not_compatible) << &AL | |||
310 | << A; | |||
311 | S.Diag(A->getLocation(), diag::note_conflicting_attribute); | |||
312 | return true; | |||
313 | } | |||
314 | return false; | |||
315 | } | |||
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 | const Expr *IdxExpr, ParamIdx &Idx, bool CanIndexImplicitThis = false) { | |||
325 | assert(isFunctionOrMethodOrBlock(D))((isFunctionOrMethodOrBlock(D)) ? static_cast<void> (0) : __assert_fail ("isFunctionOrMethodOrBlock(D)", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 325, __PRETTY_FUNCTION__)); | |||
326 | ||||
327 | // In C++ the implicit 'this' function parameter also counts. | |||
328 | // Parameters are counted from one. | |||
329 | bool HP = hasFunctionProto(D); | |||
330 | bool HasImplicitThisParam = isInstanceMethod(D); | |||
331 | bool IV = HP && isFunctionOrMethodVariadic(D); | |||
332 | unsigned NumParams = | |||
333 | (HP ? getFunctionOrMethodNumParams(D) : 0) + HasImplicitThisParam; | |||
334 | ||||
335 | llvm::APSInt IdxInt; | |||
336 | if (IdxExpr->isTypeDependent() || IdxExpr->isValueDependent() || | |||
337 | !IdxExpr->isIntegerConstantExpr(IdxInt, S.Context)) { | |||
338 | S.Diag(getAttrLoc(AI), diag::err_attribute_argument_n_type) | |||
339 | << &AI << AttrArgNum << AANT_ArgumentIntegerConstant | |||
340 | << IdxExpr->getSourceRange(); | |||
341 | return false; | |||
342 | } | |||
343 | ||||
344 | unsigned IdxSource = IdxInt.getLimitedValue(UINT_MAX(2147483647 *2U +1U)); | |||
345 | if (IdxSource < 1 || (!IV && IdxSource > NumParams)) { | |||
346 | S.Diag(getAttrLoc(AI), diag::err_attribute_argument_out_of_bounds) | |||
347 | << &AI << AttrArgNum << IdxExpr->getSourceRange(); | |||
348 | return false; | |||
349 | } | |||
350 | if (HasImplicitThisParam && !CanIndexImplicitThis) { | |||
351 | if (IdxSource == 1) { | |||
352 | S.Diag(getAttrLoc(AI), diag::err_attribute_invalid_implicit_this_argument) | |||
353 | << &AI << IdxExpr->getSourceRange(); | |||
354 | return false; | |||
355 | } | |||
356 | } | |||
357 | ||||
358 | Idx = ParamIdx(IdxSource, D); | |||
359 | return true; | |||
360 | } | |||
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 | SourceLocation *ArgLocation) { | |||
369 | // Look for identifiers. If we have one emit a hint to fix it to a literal. | |||
370 | if (AL.isArgIdent(ArgNum)) { | |||
371 | IdentifierLoc *Loc = AL.getArgAsIdent(ArgNum); | |||
372 | Diag(Loc->Loc, diag::err_attribute_argument_type) | |||
373 | << AL << AANT_ArgumentString | |||
374 | << FixItHint::CreateInsertion(Loc->Loc, "\"") | |||
375 | << FixItHint::CreateInsertion(getLocForEndOfToken(Loc->Loc), "\""); | |||
376 | Str = Loc->Ident->getName(); | |||
377 | if (ArgLocation) | |||
378 | *ArgLocation = Loc->Loc; | |||
379 | return true; | |||
380 | } | |||
381 | ||||
382 | // Now check for an actual string literal. | |||
383 | Expr *ArgExpr = AL.getArgAsExpr(ArgNum); | |||
384 | const auto *Literal = dyn_cast<StringLiteral>(ArgExpr->IgnoreParenCasts()); | |||
385 | if (ArgLocation) | |||
386 | *ArgLocation = ArgExpr->getBeginLoc(); | |||
387 | ||||
388 | if (!Literal || !Literal->isAscii()) { | |||
389 | Diag(ArgExpr->getBeginLoc(), diag::err_attribute_argument_type) | |||
390 | << AL << AANT_ArgumentString; | |||
391 | return false; | |||
392 | } | |||
393 | ||||
394 | Str = Literal->getString(); | |||
395 | return true; | |||
396 | } | |||
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 | unsigned SpellingIndex) { | |||
403 | D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex)); | |||
404 | } | |||
405 | ||||
406 | template <typename AttrType> | |||
407 | static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
408 | handleSimpleAttribute<AttrType>(S, D, AL.getRange(), | |||
409 | AL.getAttributeSpellingListIndex()); | |||
410 | } | |||
411 | ||||
412 | ||||
413 | template <typename... DiagnosticArgs> | |||
414 | static const Sema::SemaDiagnosticBuilder& | |||
415 | appendDiagnostics(const Sema::SemaDiagnosticBuilder &Bldr) { | |||
416 | return Bldr; | |||
417 | } | |||
418 | ||||
419 | template <typename T, typename... DiagnosticArgs> | |||
420 | static const Sema::SemaDiagnosticBuilder& | |||
421 | appendDiagnostics(const Sema::SemaDiagnosticBuilder &Bldr, T &&ExtraArg, | |||
422 | DiagnosticArgs &&... ExtraArgs) { | |||
423 | return appendDiagnostics(Bldr << std::forward<T>(ExtraArg), | |||
424 | std::forward<DiagnosticArgs>(ExtraArgs)...); | |||
425 | } | |||
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 | unsigned DiagID, DiagnosticArgs&&... ExtraArgs) { | |||
437 | if (!PassesCheck) { | |||
438 | Sema::SemaDiagnosticBuilder DB = S.Diag(D->getBeginLoc(), DiagID); | |||
439 | appendDiagnostics(DB, std::forward<DiagnosticArgs>(ExtraArgs)...); | |||
440 | return; | |||
441 | } | |||
442 | handleSimpleAttribute<AttrType>(S, D, SR, SpellingIndex); | |||
443 | } | |||
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 | DiagnosticArgs&&... ExtraArgs) { | |||
451 | return handleSimpleAttributeOrDiagnose<AttrType>( | |||
452 | S, D, AL.getRange(), AL.getAttributeSpellingListIndex(), PassesCheck, | |||
453 | DiagID, std::forward<DiagnosticArgs>(ExtraArgs)...); | |||
454 | } | |||
455 | ||||
456 | template <typename AttrType> | |||
457 | static void handleSimpleAttributeWithExclusions(Sema &S, Decl *D, | |||
458 | const ParsedAttr &AL) { | |||
459 | handleSimpleAttribute<AttrType>(S, D, AL); | |||
460 | } | |||
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 | const ParsedAttr &AL) { | |||
468 | if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL)) | |||
469 | return; | |||
470 | handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D, | |||
471 | AL); | |||
472 | } | |||
473 | ||||
474 | /// Check if the passed-in expression is of type int or bool. | |||
475 | static bool isIntOrBool(Expr *Exp) { | |||
476 | QualType QT = Exp->getType(); | |||
477 | return QT->isBooleanType() || QT->isIntegerType(); | |||
478 | } | |||
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 | static bool threadSafetyCheckIsSmartPointer(Sema &S, const RecordType* RT) { | |||
484 | auto IsOverloadedOperatorPresent = [&S](const RecordDecl *Record, | |||
485 | OverloadedOperatorKind Op) { | |||
486 | DeclContextLookupResult Result = | |||
487 | Record->lookup(S.Context.DeclarationNames.getCXXOperatorName(Op)); | |||
488 | return !Result.empty(); | |||
489 | }; | |||
490 | ||||
491 | const RecordDecl *Record = RT->getDecl(); | |||
492 | bool foundStarOperator = IsOverloadedOperatorPresent(Record, OO_Star); | |||
493 | bool foundArrowOperator = IsOverloadedOperatorPresent(Record, OO_Arrow); | |||
494 | if (foundStarOperator && foundArrowOperator) | |||
495 | return true; | |||
496 | ||||
497 | const CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(Record); | |||
498 | if (!CXXRecord) | |||
499 | return false; | |||
500 | ||||
501 | for (auto BaseSpecifier : CXXRecord->bases()) { | |||
502 | if (!foundStarOperator) | |||
503 | foundStarOperator = IsOverloadedOperatorPresent( | |||
504 | BaseSpecifier.getType()->getAsRecordDecl(), OO_Star); | |||
505 | if (!foundArrowOperator) | |||
506 | foundArrowOperator = IsOverloadedOperatorPresent( | |||
507 | BaseSpecifier.getType()->getAsRecordDecl(), OO_Arrow); | |||
508 | } | |||
509 | ||||
510 | if (foundStarOperator && foundArrowOperator) | |||
511 | return true; | |||
512 | ||||
513 | return false; | |||
514 | } | |||
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 | const ParsedAttr &AL) { | |||
521 | const auto *VD = cast<ValueDecl>(D); | |||
522 | QualType QT = VD->getType(); | |||
523 | if (QT->isAnyPointerType()) | |||
524 | return true; | |||
525 | ||||
526 | if (const auto *RT = QT->getAs<RecordType>()) { | |||
527 | // If it's an incomplete type, it could be a smart pointer; skip it. | |||
528 | // (We don't want to force template instantiation if we can avoid it, | |||
529 | // since that would alter the order in which templates are instantiated.) | |||
530 | if (RT->isIncompleteType()) | |||
531 | return true; | |||
532 | ||||
533 | if (threadSafetyCheckIsSmartPointer(S, RT)) | |||
534 | return true; | |||
535 | } | |||
536 | ||||
537 | S.Diag(AL.getLoc(), diag::warn_thread_attribute_decl_not_pointer) << AL << QT; | |||
538 | return false; | |||
539 | } | |||
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 | static const RecordType *getRecordType(QualType QT) { | |||
544 | if (const auto *RT = QT->getAs<RecordType>()) | |||
545 | return RT; | |||
546 | ||||
547 | // Now check if we point to record type. | |||
548 | if (const auto *PT = QT->getAs<PointerType>()) | |||
549 | return PT->getPointeeType()->getAs<RecordType>(); | |||
550 | ||||
551 | return nullptr; | |||
552 | } | |||
553 | ||||
554 | template <typename AttrType> | |||
555 | static bool checkRecordDeclForAttr(const RecordDecl *RD) { | |||
556 | // Check if the record itself has the attribute. | |||
557 | if (RD->hasAttr<AttrType>()) | |||
558 | return true; | |||
559 | ||||
560 | // Else check if any base classes have the attribute. | |||
561 | if (const auto *CRD = dyn_cast<CXXRecordDecl>(RD)) { | |||
562 | CXXBasePaths BPaths(false, false); | |||
563 | if (CRD->lookupInBases( | |||
564 | [](const CXXBaseSpecifier *BS, CXXBasePath &) { | |||
565 | const auto &Ty = *BS->getType(); | |||
566 | // If it's type-dependent, we assume it could have the attribute. | |||
567 | if (Ty.isDependentType()) | |||
568 | return true; | |||
569 | return Ty.getAs<RecordType>()->getDecl()->hasAttr<AttrType>(); | |||
570 | }, | |||
571 | BPaths, true)) | |||
572 | return true; | |||
573 | } | |||
574 | return false; | |||
575 | } | |||
576 | ||||
577 | static bool checkRecordTypeForCapability(Sema &S, QualType Ty) { | |||
578 | const RecordType *RT = getRecordType(Ty); | |||
579 | ||||
580 | if (!RT) | |||
581 | return false; | |||
582 | ||||
583 | // Don't check for the capability if the class hasn't been defined yet. | |||
584 | if (RT->isIncompleteType()) | |||
585 | return true; | |||
586 | ||||
587 | // Allow smart pointers to be used as capability objects. | |||
588 | // FIXME -- Check the type that the smart pointer points to. | |||
589 | if (threadSafetyCheckIsSmartPointer(S, RT)) | |||
590 | return true; | |||
591 | ||||
592 | return checkRecordDeclForAttr<CapabilityAttr>(RT->getDecl()); | |||
593 | } | |||
594 | ||||
595 | static bool checkTypedefTypeForCapability(QualType Ty) { | |||
596 | const auto *TD = Ty->getAs<TypedefType>(); | |||
597 | if (!TD) | |||
598 | return false; | |||
599 | ||||
600 | TypedefNameDecl *TN = TD->getDecl(); | |||
601 | if (!TN) | |||
602 | return false; | |||
603 | ||||
604 | return TN->hasAttr<CapabilityAttr>(); | |||
605 | } | |||
606 | ||||
607 | static bool typeHasCapability(Sema &S, QualType Ty) { | |||
608 | if (checkTypedefTypeForCapability(Ty)) | |||
609 | return true; | |||
610 | ||||
611 | if (checkRecordTypeForCapability(S, Ty)) | |||
612 | return true; | |||
613 | ||||
614 | return false; | |||
615 | } | |||
616 | ||||
617 | static bool isCapabilityExpr(Sema &S, const Expr *Ex) { | |||
618 | // Capability expressions are simple expressions involving the boolean logic | |||
619 | // operators &&, || or !, a simple DeclRefExpr, CastExpr or a ParenExpr. Once | |||
620 | // a DeclRefExpr is found, its type should be checked to determine whether it | |||
621 | // is a capability or not. | |||
622 | ||||
623 | if (const auto *E = dyn_cast<CastExpr>(Ex)) | |||
624 | return isCapabilityExpr(S, E->getSubExpr()); | |||
625 | else if (const auto *E = dyn_cast<ParenExpr>(Ex)) | |||
626 | return isCapabilityExpr(S, E->getSubExpr()); | |||
627 | else if (const auto *E = dyn_cast<UnaryOperator>(Ex)) { | |||
628 | if (E->getOpcode() == UO_LNot || E->getOpcode() == UO_AddrOf || | |||
629 | E->getOpcode() == UO_Deref) | |||
630 | return isCapabilityExpr(S, E->getSubExpr()); | |||
631 | return false; | |||
632 | } else if (const auto *E = dyn_cast<BinaryOperator>(Ex)) { | |||
633 | if (E->getOpcode() == BO_LAnd || E->getOpcode() == BO_LOr) | |||
634 | return isCapabilityExpr(S, E->getLHS()) && | |||
635 | isCapabilityExpr(S, E->getRHS()); | |||
636 | return false; | |||
637 | } | |||
638 | ||||
639 | return typeHasCapability(S, Ex->getType()); | |||
640 | } | |||
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 | bool ParamIdxOk = false) { | |||
652 | if (Sidx == AL.getNumArgs()) { | |||
653 | // If we don't have any capability arguments, the attribute implicitly | |||
654 | // refers to 'this'. So we need to make sure that 'this' exists, i.e. we're | |||
655 | // a non-static method, and that the class is a (scoped) capability. | |||
656 | const auto *MD = dyn_cast<const CXXMethodDecl>(D); | |||
657 | if (MD && !MD->isStatic()) { | |||
658 | const CXXRecordDecl *RD = MD->getParent(); | |||
659 | // FIXME -- need to check this again on template instantiation | |||
660 | if (!checkRecordDeclForAttr<CapabilityAttr>(RD) && | |||
661 | !checkRecordDeclForAttr<ScopedLockableAttr>(RD)) | |||
662 | S.Diag(AL.getLoc(), | |||
663 | diag::warn_thread_attribute_not_on_capability_member) | |||
664 | << AL << MD->getParent(); | |||
665 | } else { | |||
666 | S.Diag(AL.getLoc(), diag::warn_thread_attribute_not_on_non_static_member) | |||
667 | << AL; | |||
668 | } | |||
669 | } | |||
670 | ||||
671 | for (unsigned Idx = Sidx; Idx < AL.getNumArgs(); ++Idx) { | |||
672 | Expr *ArgExp = AL.getArgAsExpr(Idx); | |||
673 | ||||
674 | if (ArgExp->isTypeDependent()) { | |||
675 | // FIXME -- need to check this again on template instantiation | |||
676 | Args.push_back(ArgExp); | |||
677 | continue; | |||
678 | } | |||
679 | ||||
680 | if (const auto *StrLit = dyn_cast<StringLiteral>(ArgExp)) { | |||
681 | if (StrLit->getLength() == 0 || | |||
682 | (StrLit->isAscii() && StrLit->getString() == StringRef("*"))) { | |||
683 | // Pass empty strings to the analyzer without warnings. | |||
684 | // Treat "*" as the universal lock. | |||
685 | Args.push_back(ArgExp); | |||
686 | continue; | |||
687 | } | |||
688 | ||||
689 | // We allow constant strings to be used as a placeholder for expressions | |||
690 | // that are not valid C++ syntax, but warn that they are ignored. | |||
691 | S.Diag(AL.getLoc(), diag::warn_thread_attribute_ignored) << AL; | |||
692 | Args.push_back(ArgExp); | |||
693 | continue; | |||
694 | } | |||
695 | ||||
696 | QualType ArgTy = ArgExp->getType(); | |||
697 | ||||
698 | // A pointer to member expression of the form &MyClass::mu is treated | |||
699 | // specially -- we need to look at the type of the member. | |||
700 | if (const auto *UOp = dyn_cast<UnaryOperator>(ArgExp)) | |||
701 | if (UOp->getOpcode() == UO_AddrOf) | |||
702 | if (const auto *DRE = dyn_cast<DeclRefExpr>(UOp->getSubExpr())) | |||
703 | if (DRE->getDecl()->isCXXInstanceMember()) | |||
704 | ArgTy = DRE->getDecl()->getType(); | |||
705 | ||||
706 | // First see if we can just cast to record type, or pointer to record type. | |||
707 | const RecordType *RT = getRecordType(ArgTy); | |||
708 | ||||
709 | // Now check if we index into a record type function param. | |||
710 | if(!RT && ParamIdxOk) { | |||
711 | const auto *FD = dyn_cast<FunctionDecl>(D); | |||
712 | const auto *IL = dyn_cast<IntegerLiteral>(ArgExp); | |||
713 | if(FD && IL) { | |||
714 | unsigned int NumParams = FD->getNumParams(); | |||
715 | llvm::APInt ArgValue = IL->getValue(); | |||
716 | uint64_t ParamIdxFromOne = ArgValue.getZExtValue(); | |||
717 | uint64_t ParamIdxFromZero = ParamIdxFromOne - 1; | |||
718 | if (!ArgValue.isStrictlyPositive() || ParamIdxFromOne > NumParams) { | |||
719 | S.Diag(AL.getLoc(), | |||
720 | diag::err_attribute_argument_out_of_bounds_extra_info) | |||
721 | << AL << Idx + 1 << NumParams; | |||
722 | continue; | |||
723 | } | |||
724 | ArgTy = FD->getParamDecl(ParamIdxFromZero)->getType(); | |||
725 | } | |||
726 | } | |||
727 | ||||
728 | // If the type does not have a capability, see if the components of the | |||
729 | // expression have capabilities. This allows for writing C code where the | |||
730 | // capability may be on the type, and the expression is a capability | |||
731 | // boolean logic expression. Eg) requires_capability(A || B && !C) | |||
732 | if (!typeHasCapability(S, ArgTy) && !isCapabilityExpr(S, ArgExp)) | |||
733 | S.Diag(AL.getLoc(), diag::warn_thread_attribute_argument_not_lockable) | |||
734 | << AL << ArgTy; | |||
735 | ||||
736 | Args.push_back(ArgExp); | |||
737 | } | |||
738 | } | |||
739 | ||||
740 | //===----------------------------------------------------------------------===// | |||
741 | // Attribute Implementations | |||
742 | //===----------------------------------------------------------------------===// | |||
743 | ||||
744 | static void handlePtGuardedVarAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
745 | if (!threadSafetyCheckIsPointer(S, D, AL)) | |||
746 | return; | |||
747 | ||||
748 | D->addAttr(::new (S.Context) | |||
749 | PtGuardedVarAttr(AL.getRange(), S.Context, | |||
750 | AL.getAttributeSpellingListIndex())); | |||
751 | } | |||
752 | ||||
753 | static bool checkGuardedByAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL, | |||
754 | Expr *&Arg) { | |||
755 | SmallVector<Expr *, 1> Args; | |||
756 | // check that all arguments are lockable objects | |||
757 | checkAttrArgsAreCapabilityObjs(S, D, AL, Args); | |||
758 | unsigned Size = Args.size(); | |||
759 | if (Size != 1) | |||
760 | return false; | |||
761 | ||||
762 | Arg = Args[0]; | |||
763 | ||||
764 | return true; | |||
765 | } | |||
766 | ||||
767 | static void handleGuardedByAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
768 | Expr *Arg = nullptr; | |||
769 | if (!checkGuardedByAttrCommon(S, D, AL, Arg)) | |||
770 | return; | |||
771 | ||||
772 | D->addAttr(::new (S.Context) GuardedByAttr( | |||
773 | AL.getRange(), S.Context, Arg, AL.getAttributeSpellingListIndex())); | |||
774 | } | |||
775 | ||||
776 | static void handlePtGuardedByAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
777 | Expr *Arg = nullptr; | |||
778 | if (!checkGuardedByAttrCommon(S, D, AL, Arg)) | |||
779 | return; | |||
780 | ||||
781 | if (!threadSafetyCheckIsPointer(S, D, AL)) | |||
782 | return; | |||
783 | ||||
784 | D->addAttr(::new (S.Context) PtGuardedByAttr( | |||
785 | AL.getRange(), S.Context, Arg, AL.getAttributeSpellingListIndex())); | |||
786 | } | |||
787 | ||||
788 | static bool checkAcquireOrderAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL, | |||
789 | SmallVectorImpl<Expr *> &Args) { | |||
790 | if (!checkAttributeAtLeastNumArgs(S, AL, 1)) | |||
791 | return false; | |||
792 | ||||
793 | // Check that this attribute only applies to lockable types. | |||
794 | QualType QT = cast<ValueDecl>(D)->getType(); | |||
795 | if (!QT->isDependentType() && !typeHasCapability(S, QT)) { | |||
796 | S.Diag(AL.getLoc(), diag::warn_thread_attribute_decl_not_lockable) << AL; | |||
797 | return false; | |||
798 | } | |||
799 | ||||
800 | // Check that all arguments are lockable objects. | |||
801 | checkAttrArgsAreCapabilityObjs(S, D, AL, Args); | |||
802 | if (Args.empty()) | |||
803 | return false; | |||
804 | ||||
805 | return true; | |||
806 | } | |||
807 | ||||
808 | static void handleAcquiredAfterAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
809 | SmallVector<Expr *, 1> Args; | |||
810 | if (!checkAcquireOrderAttrCommon(S, D, AL, Args)) | |||
811 | return; | |||
812 | ||||
813 | Expr **StartArg = &Args[0]; | |||
814 | D->addAttr(::new (S.Context) AcquiredAfterAttr( | |||
815 | AL.getRange(), S.Context, StartArg, Args.size(), | |||
816 | AL.getAttributeSpellingListIndex())); | |||
817 | } | |||
818 | ||||
819 | static void handleAcquiredBeforeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
820 | SmallVector<Expr *, 1> Args; | |||
821 | if (!checkAcquireOrderAttrCommon(S, D, AL, Args)) | |||
822 | return; | |||
823 | ||||
824 | Expr **StartArg = &Args[0]; | |||
825 | D->addAttr(::new (S.Context) AcquiredBeforeAttr( | |||
826 | AL.getRange(), S.Context, StartArg, Args.size(), | |||
827 | AL.getAttributeSpellingListIndex())); | |||
828 | } | |||
829 | ||||
830 | static bool checkLockFunAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL, | |||
831 | SmallVectorImpl<Expr *> &Args) { | |||
832 | // zero or more arguments ok | |||
833 | // check that all arguments are lockable objects | |||
834 | checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 0, /*ParamIdxOk=*/true); | |||
835 | ||||
836 | return true; | |||
837 | } | |||
838 | ||||
839 | static void handleAssertSharedLockAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
840 | SmallVector<Expr *, 1> Args; | |||
841 | if (!checkLockFunAttrCommon(S, D, AL, Args)) | |||
842 | return; | |||
843 | ||||
844 | unsigned Size = Args.size(); | |||
845 | Expr **StartArg = Size == 0 ? nullptr : &Args[0]; | |||
846 | D->addAttr(::new (S.Context) | |||
847 | AssertSharedLockAttr(AL.getRange(), S.Context, StartArg, Size, | |||
848 | AL.getAttributeSpellingListIndex())); | |||
849 | } | |||
850 | ||||
851 | static void handleAssertExclusiveLockAttr(Sema &S, Decl *D, | |||
852 | const ParsedAttr &AL) { | |||
853 | SmallVector<Expr *, 1> Args; | |||
854 | if (!checkLockFunAttrCommon(S, D, AL, Args)) | |||
855 | return; | |||
856 | ||||
857 | unsigned Size = Args.size(); | |||
858 | Expr **StartArg = Size == 0 ? nullptr : &Args[0]; | |||
859 | D->addAttr(::new (S.Context) AssertExclusiveLockAttr( | |||
860 | AL.getRange(), S.Context, StartArg, Size, | |||
861 | AL.getAttributeSpellingListIndex())); | |||
862 | } | |||
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 | const AttrInfo &AI, unsigned AttrArgNo) { | |||
872 | assert(AI.isArgExpr(AttrArgNo) && "Expected expression argument")((AI.isArgExpr(AttrArgNo) && "Expected expression argument" ) ? static_cast<void> (0) : __assert_fail ("AI.isArgExpr(AttrArgNo) && \"Expected expression argument\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 872, __PRETTY_FUNCTION__)); | |||
873 | Expr *AttrArg = AI.getArgAsExpr(AttrArgNo); | |||
874 | ParamIdx Idx; | |||
875 | if (!checkFunctionOrMethodParameterIndex(S, FD, AI, AttrArgNo + 1, AttrArg, | |||
876 | Idx)) | |||
877 | return false; | |||
878 | ||||
879 | const ParmVarDecl *Param = FD->getParamDecl(Idx.getASTIndex()); | |||
880 | if (!Param->getType()->isIntegerType() && !Param->getType()->isCharType()) { | |||
881 | SourceLocation SrcLoc = AttrArg->getBeginLoc(); | |||
882 | S.Diag(SrcLoc, diag::err_attribute_integers_only) | |||
883 | << AI << Param->getSourceRange(); | |||
884 | return false; | |||
885 | } | |||
886 | return true; | |||
887 | } | |||
888 | ||||
889 | static void handleAllocSizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
890 | if (!checkAttributeAtLeastNumArgs(S, AL, 1) || | |||
891 | !checkAttributeAtMostNumArgs(S, AL, 2)) | |||
892 | return; | |||
893 | ||||
894 | const auto *FD = cast<FunctionDecl>(D); | |||
895 | if (!FD->getReturnType()->isPointerType()) { | |||
896 | S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only) << AL; | |||
897 | return; | |||
898 | } | |||
899 | ||||
900 | const Expr *SizeExpr = AL.getArgAsExpr(0); | |||
901 | int SizeArgNoVal; | |||
902 | // Parameter indices are 1-indexed, hence Index=1 | |||
903 | if (!checkPositiveIntArgument(S, AL, SizeExpr, SizeArgNoVal, /*Index=*/1)) | |||
904 | return; | |||
905 | if (!checkParamIsIntegerType(S, FD, AL, /*AttrArgNo=*/0)) | |||
906 | return; | |||
907 | ParamIdx SizeArgNo(SizeArgNoVal, D); | |||
908 | ||||
909 | ParamIdx NumberArgNo; | |||
910 | if (AL.getNumArgs() == 2) { | |||
911 | const Expr *NumberExpr = AL.getArgAsExpr(1); | |||
912 | int Val; | |||
913 | // Parameter indices are 1-based, hence Index=2 | |||
914 | if (!checkPositiveIntArgument(S, AL, NumberExpr, Val, /*Index=*/2)) | |||
915 | return; | |||
916 | if (!checkParamIsIntegerType(S, FD, AL, /*AttrArgNo=*/1)) | |||
917 | return; | |||
918 | NumberArgNo = ParamIdx(Val, D); | |||
919 | } | |||
920 | ||||
921 | D->addAttr(::new (S.Context) | |||
922 | AllocSizeAttr(AL.getRange(), S.Context, SizeArgNo, NumberArgNo, | |||
923 | AL.getAttributeSpellingListIndex())); | |||
924 | } | |||
925 | ||||
926 | static bool checkTryLockFunAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL, | |||
927 | SmallVectorImpl<Expr *> &Args) { | |||
928 | if (!checkAttributeAtLeastNumArgs(S, AL, 1)) | |||
929 | return false; | |||
930 | ||||
931 | if (!isIntOrBool(AL.getArgAsExpr(0))) { | |||
932 | S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) | |||
933 | << AL << 1 << AANT_ArgumentIntOrBool; | |||
934 | return false; | |||
935 | } | |||
936 | ||||
937 | // check that all arguments are lockable objects | |||
938 | checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 1); | |||
939 | ||||
940 | return true; | |||
941 | } | |||
942 | ||||
943 | static void handleSharedTrylockFunctionAttr(Sema &S, Decl *D, | |||
944 | const ParsedAttr &AL) { | |||
945 | SmallVector<Expr*, 2> Args; | |||
946 | if (!checkTryLockFunAttrCommon(S, D, AL, Args)) | |||
947 | return; | |||
948 | ||||
949 | D->addAttr(::new (S.Context) SharedTrylockFunctionAttr( | |||
950 | AL.getRange(), S.Context, AL.getArgAsExpr(0), Args.data(), Args.size(), | |||
951 | AL.getAttributeSpellingListIndex())); | |||
952 | } | |||
953 | ||||
954 | static void handleExclusiveTrylockFunctionAttr(Sema &S, Decl *D, | |||
955 | const ParsedAttr &AL) { | |||
956 | SmallVector<Expr*, 2> Args; | |||
957 | if (!checkTryLockFunAttrCommon(S, D, AL, Args)) | |||
958 | return; | |||
959 | ||||
960 | D->addAttr(::new (S.Context) ExclusiveTrylockFunctionAttr( | |||
961 | AL.getRange(), S.Context, AL.getArgAsExpr(0), Args.data(), | |||
962 | Args.size(), AL.getAttributeSpellingListIndex())); | |||
963 | } | |||
964 | ||||
965 | static void handleLockReturnedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
966 | // check that the argument is lockable object | |||
967 | SmallVector<Expr*, 1> Args; | |||
968 | checkAttrArgsAreCapabilityObjs(S, D, AL, Args); | |||
969 | unsigned Size = Args.size(); | |||
970 | if (Size == 0) | |||
971 | return; | |||
972 | ||||
973 | D->addAttr(::new (S.Context) | |||
974 | LockReturnedAttr(AL.getRange(), S.Context, Args[0], | |||
975 | AL.getAttributeSpellingListIndex())); | |||
976 | } | |||
977 | ||||
978 | static void handleLocksExcludedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
979 | if (!checkAttributeAtLeastNumArgs(S, AL, 1)) | |||
980 | return; | |||
981 | ||||
982 | // check that all arguments are lockable objects | |||
983 | SmallVector<Expr*, 1> Args; | |||
984 | checkAttrArgsAreCapabilityObjs(S, D, AL, Args); | |||
985 | unsigned Size = Args.size(); | |||
986 | if (Size == 0) | |||
987 | return; | |||
988 | Expr **StartArg = &Args[0]; | |||
989 | ||||
990 | D->addAttr(::new (S.Context) | |||
991 | LocksExcludedAttr(AL.getRange(), S.Context, StartArg, Size, | |||
992 | AL.getAttributeSpellingListIndex())); | |||
993 | } | |||
994 | ||||
995 | static bool checkFunctionConditionAttr(Sema &S, Decl *D, const ParsedAttr &AL, | |||
996 | Expr *&Cond, StringRef &Msg) { | |||
997 | Cond = AL.getArgAsExpr(0); | |||
998 | if (!Cond->isTypeDependent()) { | |||
999 | ExprResult Converted = S.PerformContextuallyConvertToBool(Cond); | |||
1000 | if (Converted.isInvalid()) | |||
1001 | return false; | |||
1002 | Cond = Converted.get(); | |||
1003 | } | |||
1004 | ||||
1005 | if (!S.checkStringLiteralArgumentAttr(AL, 1, Msg)) | |||
1006 | return false; | |||
1007 | ||||
1008 | if (Msg.empty()) | |||
1009 | Msg = "<no message provided>"; | |||
1010 | ||||
1011 | SmallVector<PartialDiagnosticAt, 8> Diags; | |||
1012 | if (isa<FunctionDecl>(D) && !Cond->isValueDependent() && | |||
1013 | !Expr::isPotentialConstantExprUnevaluated(Cond, cast<FunctionDecl>(D), | |||
1014 | Diags)) { | |||
1015 | S.Diag(AL.getLoc(), diag::err_attr_cond_never_constant_expr) << AL; | |||
1016 | for (const PartialDiagnosticAt &PDiag : Diags) | |||
1017 | S.Diag(PDiag.first, PDiag.second); | |||
1018 | return false; | |||
1019 | } | |||
1020 | return true; | |||
1021 | } | |||
1022 | ||||
1023 | static void handleEnableIfAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1024 | S.Diag(AL.getLoc(), diag::ext_clang_enable_if); | |||
1025 | ||||
1026 | Expr *Cond; | |||
1027 | StringRef Msg; | |||
1028 | if (checkFunctionConditionAttr(S, D, AL, Cond, Msg)) | |||
1029 | D->addAttr(::new (S.Context) | |||
1030 | EnableIfAttr(AL.getRange(), S.Context, Cond, Msg, | |||
1031 | AL.getAttributeSpellingListIndex())); | |||
1032 | } | |||
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 | 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 | } | |||
1055 | ||||
1056 | bool referencesArgs(Expr *E) { | |||
1057 | Result = false; | |||
1058 | TraverseStmt(E); | |||
1059 | return Result; | |||
1060 | } | |||
1061 | ||||
1062 | bool VisitCXXThisExpr(CXXThisExpr *E) { | |||
1063 | assert(E->getType()->getPointeeCXXRecordDecl() == ClassType &&((E->getType()->getPointeeCXXRecordDecl() == ClassType && "`this` doesn't refer to the enclosing class?") ? static_cast <void> (0) : __assert_fail ("E->getType()->getPointeeCXXRecordDecl() == ClassType && \"`this` doesn't refer to the enclosing class?\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 1064, __PRETTY_FUNCTION__)) | |||
1064 | "`this` doesn't refer to the enclosing class?")((E->getType()->getPointeeCXXRecordDecl() == ClassType && "`this` doesn't refer to the enclosing class?") ? static_cast <void> (0) : __assert_fail ("E->getType()->getPointeeCXXRecordDecl() == ClassType && \"`this` doesn't refer to the enclosing class?\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 1064, __PRETTY_FUNCTION__)); | |||
1065 | Result = true; | |||
1066 | return false; | |||
1067 | } | |||
1068 | ||||
1069 | bool VisitDeclRefExpr(DeclRefExpr *DRE) { | |||
1070 | if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) | |||
1071 | if (Parms.count(PVD)) { | |||
1072 | Result = true; | |||
1073 | return false; | |||
1074 | } | |||
1075 | return true; | |||
1076 | } | |||
1077 | }; | |||
1078 | } | |||
1079 | ||||
1080 | static void handleDiagnoseIfAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1081 | S.Diag(AL.getLoc(), diag::ext_clang_diagnose_if); | |||
1082 | ||||
1083 | Expr *Cond; | |||
1084 | StringRef Msg; | |||
1085 | if (!checkFunctionConditionAttr(S, D, AL, Cond, Msg)) | |||
1086 | return; | |||
1087 | ||||
1088 | StringRef DiagTypeStr; | |||
1089 | if (!S.checkStringLiteralArgumentAttr(AL, 2, DiagTypeStr)) | |||
1090 | return; | |||
1091 | ||||
1092 | DiagnoseIfAttr::DiagnosticType DiagType; | |||
1093 | if (!DiagnoseIfAttr::ConvertStrToDiagnosticType(DiagTypeStr, DiagType)) { | |||
1094 | S.Diag(AL.getArgAsExpr(2)->getBeginLoc(), | |||
1095 | diag::err_diagnose_if_invalid_diagnostic_type); | |||
1096 | return; | |||
1097 | } | |||
1098 | ||||
1099 | bool ArgDependent = false; | |||
1100 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) | |||
1101 | ArgDependent = ArgumentDependenceChecker(FD).referencesArgs(Cond); | |||
1102 | D->addAttr(::new (S.Context) DiagnoseIfAttr( | |||
1103 | AL.getRange(), S.Context, Cond, Msg, DiagType, ArgDependent, | |||
1104 | cast<NamedDecl>(D), AL.getAttributeSpellingListIndex())); | |||
1105 | } | |||
1106 | ||||
1107 | static void handlePassObjectSizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1108 | if (D->hasAttr<PassObjectSizeAttr>()) { | |||
1109 | S.Diag(D->getBeginLoc(), diag::err_attribute_only_once_per_parameter) << AL; | |||
1110 | return; | |||
1111 | } | |||
1112 | ||||
1113 | Expr *E = AL.getArgAsExpr(0); | |||
1114 | uint32_t Type; | |||
1115 | if (!checkUInt32Argument(S, AL, E, Type, /*Idx=*/1)) | |||
1116 | return; | |||
1117 | ||||
1118 | // pass_object_size's argument is passed in as the second argument of | |||
1119 | // __builtin_object_size. So, it has the same constraints as that second | |||
1120 | // argument; namely, it must be in the range [0, 3]. | |||
1121 | if (Type > 3) { | |||
1122 | S.Diag(E->getBeginLoc(), diag::err_attribute_argument_out_of_range) | |||
1123 | << AL << 0 << 3 << E->getSourceRange(); | |||
1124 | return; | |||
1125 | } | |||
1126 | ||||
1127 | // pass_object_size is only supported on constant pointer parameters; as a | |||
1128 | // kindness to users, we allow the parameter to be non-const for declarations. | |||
1129 | // At this point, we have no clue if `D` belongs to a function declaration or | |||
1130 | // definition, so we defer the constness check until later. | |||
1131 | if (!cast<ParmVarDecl>(D)->getType()->isPointerType()) { | |||
1132 | S.Diag(D->getBeginLoc(), diag::err_attribute_pointers_only) << AL << 1; | |||
1133 | return; | |||
1134 | } | |||
1135 | ||||
1136 | D->addAttr(::new (S.Context) PassObjectSizeAttr( | |||
1137 | AL.getRange(), S.Context, (int)Type, AL.getAttributeSpellingListIndex())); | |||
1138 | } | |||
1139 | ||||
1140 | static void handleConsumableAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1141 | ConsumableAttr::ConsumedState DefaultState; | |||
1142 | ||||
1143 | if (AL.isArgIdent(0)) { | |||
1144 | IdentifierLoc *IL = AL.getArgAsIdent(0); | |||
1145 | if (!ConsumableAttr::ConvertStrToConsumedState(IL->Ident->getName(), | |||
1146 | DefaultState)) { | |||
1147 | S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL | |||
1148 | << IL->Ident; | |||
1149 | return; | |||
1150 | } | |||
1151 | } else { | |||
1152 | S.Diag(AL.getLoc(), diag::err_attribute_argument_type) | |||
1153 | << AL << AANT_ArgumentIdentifier; | |||
1154 | return; | |||
1155 | } | |||
1156 | ||||
1157 | D->addAttr(::new (S.Context) | |||
1158 | ConsumableAttr(AL.getRange(), S.Context, DefaultState, | |||
1159 | AL.getAttributeSpellingListIndex())); | |||
1160 | } | |||
1161 | ||||
1162 | static bool checkForConsumableClass(Sema &S, const CXXMethodDecl *MD, | |||
1163 | const ParsedAttr &AL) { | |||
1164 | QualType ThisType = MD->getThisType()->getPointeeType(); | |||
1165 | ||||
1166 | if (const CXXRecordDecl *RD = ThisType->getAsCXXRecordDecl()) { | |||
1167 | if (!RD->hasAttr<ConsumableAttr>()) { | |||
1168 | S.Diag(AL.getLoc(), diag::warn_attr_on_unconsumable_class) << | |||
1169 | RD->getNameAsString(); | |||
1170 | ||||
1171 | return false; | |||
1172 | } | |||
1173 | } | |||
1174 | ||||
1175 | return true; | |||
1176 | } | |||
1177 | ||||
1178 | static void handleCallableWhenAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1179 | if (!checkAttributeAtLeastNumArgs(S, AL, 1)) | |||
1180 | return; | |||
1181 | ||||
1182 | if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), AL)) | |||
1183 | return; | |||
1184 | ||||
1185 | SmallVector<CallableWhenAttr::ConsumedState, 3> States; | |||
1186 | for (unsigned ArgIndex = 0; ArgIndex < AL.getNumArgs(); ++ArgIndex) { | |||
1187 | CallableWhenAttr::ConsumedState CallableState; | |||
1188 | ||||
1189 | StringRef StateString; | |||
1190 | SourceLocation Loc; | |||
1191 | if (AL.isArgIdent(ArgIndex)) { | |||
1192 | IdentifierLoc *Ident = AL.getArgAsIdent(ArgIndex); | |||
1193 | StateString = Ident->Ident->getName(); | |||
1194 | Loc = Ident->Loc; | |||
1195 | } else { | |||
1196 | if (!S.checkStringLiteralArgumentAttr(AL, ArgIndex, StateString, &Loc)) | |||
1197 | return; | |||
1198 | } | |||
1199 | ||||
1200 | if (!CallableWhenAttr::ConvertStrToConsumedState(StateString, | |||
1201 | CallableState)) { | |||
1202 | S.Diag(Loc, diag::warn_attribute_type_not_supported) << AL << StateString; | |||
1203 | return; | |||
1204 | } | |||
1205 | ||||
1206 | States.push_back(CallableState); | |||
1207 | } | |||
1208 | ||||
1209 | D->addAttr(::new (S.Context) | |||
1210 | CallableWhenAttr(AL.getRange(), S.Context, States.data(), | |||
1211 | States.size(), AL.getAttributeSpellingListIndex())); | |||
1212 | } | |||
1213 | ||||
1214 | static void handleParamTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1215 | ParamTypestateAttr::ConsumedState ParamState; | |||
1216 | ||||
1217 | if (AL.isArgIdent(0)) { | |||
1218 | IdentifierLoc *Ident = AL.getArgAsIdent(0); | |||
1219 | StringRef StateString = Ident->Ident->getName(); | |||
1220 | ||||
1221 | if (!ParamTypestateAttr::ConvertStrToConsumedState(StateString, | |||
1222 | ParamState)) { | |||
1223 | S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) | |||
1224 | << AL << StateString; | |||
1225 | return; | |||
1226 | } | |||
1227 | } else { | |||
1228 | S.Diag(AL.getLoc(), diag::err_attribute_argument_type) | |||
1229 | << AL << AANT_ArgumentIdentifier; | |||
1230 | return; | |||
1231 | } | |||
1232 | ||||
1233 | // FIXME: This check is currently being done in the analysis. It can be | |||
1234 | // enabled here only after the parser propagates attributes at | |||
1235 | // template specialization definition, not declaration. | |||
1236 | //QualType ReturnType = cast<ParmVarDecl>(D)->getType(); | |||
1237 | //const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl(); | |||
1238 | // | |||
1239 | //if (!RD || !RD->hasAttr<ConsumableAttr>()) { | |||
1240 | // S.Diag(AL.getLoc(), diag::warn_return_state_for_unconsumable_type) << | |||
1241 | // ReturnType.getAsString(); | |||
1242 | // return; | |||
1243 | //} | |||
1244 | ||||
1245 | D->addAttr(::new (S.Context) | |||
1246 | ParamTypestateAttr(AL.getRange(), S.Context, ParamState, | |||
1247 | AL.getAttributeSpellingListIndex())); | |||
1248 | } | |||
1249 | ||||
1250 | static void handleReturnTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1251 | ReturnTypestateAttr::ConsumedState ReturnState; | |||
1252 | ||||
1253 | if (AL.isArgIdent(0)) { | |||
1254 | IdentifierLoc *IL = AL.getArgAsIdent(0); | |||
1255 | if (!ReturnTypestateAttr::ConvertStrToConsumedState(IL->Ident->getName(), | |||
1256 | ReturnState)) { | |||
1257 | S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL | |||
1258 | << IL->Ident; | |||
1259 | return; | |||
1260 | } | |||
1261 | } else { | |||
1262 | S.Diag(AL.getLoc(), diag::err_attribute_argument_type) | |||
1263 | << AL << AANT_ArgumentIdentifier; | |||
1264 | return; | |||
1265 | } | |||
1266 | ||||
1267 | // FIXME: This check is currently being done in the analysis. It can be | |||
1268 | // enabled here only after the parser propagates attributes at | |||
1269 | // template specialization definition, not declaration. | |||
1270 | //QualType ReturnType; | |||
1271 | // | |||
1272 | //if (const ParmVarDecl *Param = dyn_cast<ParmVarDecl>(D)) { | |||
1273 | // ReturnType = Param->getType(); | |||
1274 | // | |||
1275 | //} else if (const CXXConstructorDecl *Constructor = | |||
1276 | // dyn_cast<CXXConstructorDecl>(D)) { | |||
1277 | // ReturnType = Constructor->getThisType()->getPointeeType(); | |||
1278 | // | |||
1279 | //} else { | |||
1280 | // | |||
1281 | // ReturnType = cast<FunctionDecl>(D)->getCallResultType(); | |||
1282 | //} | |||
1283 | // | |||
1284 | //const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl(); | |||
1285 | // | |||
1286 | //if (!RD || !RD->hasAttr<ConsumableAttr>()) { | |||
1287 | // S.Diag(Attr.getLoc(), diag::warn_return_state_for_unconsumable_type) << | |||
1288 | // ReturnType.getAsString(); | |||
1289 | // return; | |||
1290 | //} | |||
1291 | ||||
1292 | D->addAttr(::new (S.Context) | |||
1293 | ReturnTypestateAttr(AL.getRange(), S.Context, ReturnState, | |||
1294 | AL.getAttributeSpellingListIndex())); | |||
1295 | } | |||
1296 | ||||
1297 | static void handleSetTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1298 | if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), AL)) | |||
1299 | return; | |||
1300 | ||||
1301 | SetTypestateAttr::ConsumedState NewState; | |||
1302 | if (AL.isArgIdent(0)) { | |||
1303 | IdentifierLoc *Ident = AL.getArgAsIdent(0); | |||
1304 | StringRef Param = Ident->Ident->getName(); | |||
1305 | if (!SetTypestateAttr::ConvertStrToConsumedState(Param, NewState)) { | |||
1306 | S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL | |||
1307 | << Param; | |||
1308 | return; | |||
1309 | } | |||
1310 | } else { | |||
1311 | S.Diag(AL.getLoc(), diag::err_attribute_argument_type) | |||
1312 | << AL << AANT_ArgumentIdentifier; | |||
1313 | return; | |||
1314 | } | |||
1315 | ||||
1316 | D->addAttr(::new (S.Context) | |||
1317 | SetTypestateAttr(AL.getRange(), S.Context, NewState, | |||
1318 | AL.getAttributeSpellingListIndex())); | |||
1319 | } | |||
1320 | ||||
1321 | static void handleTestTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1322 | if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), AL)) | |||
1323 | return; | |||
1324 | ||||
1325 | TestTypestateAttr::ConsumedState TestState; | |||
1326 | if (AL.isArgIdent(0)) { | |||
1327 | IdentifierLoc *Ident = AL.getArgAsIdent(0); | |||
1328 | StringRef Param = Ident->Ident->getName(); | |||
1329 | if (!TestTypestateAttr::ConvertStrToConsumedState(Param, TestState)) { | |||
1330 | S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL | |||
1331 | << Param; | |||
1332 | return; | |||
1333 | } | |||
1334 | } else { | |||
1335 | S.Diag(AL.getLoc(), diag::err_attribute_argument_type) | |||
1336 | << AL << AANT_ArgumentIdentifier; | |||
1337 | return; | |||
1338 | } | |||
1339 | ||||
1340 | D->addAttr(::new (S.Context) | |||
1341 | TestTypestateAttr(AL.getRange(), S.Context, TestState, | |||
1342 | AL.getAttributeSpellingListIndex())); | |||
1343 | } | |||
1344 | ||||
1345 | static void handleExtVectorTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1346 | // Remember this typedef decl, we will need it later for diagnostics. | |||
1347 | S.ExtVectorDecls.push_back(cast<TypedefNameDecl>(D)); | |||
1348 | } | |||
1349 | ||||
1350 | static void handlePackedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1351 | if (auto *TD = dyn_cast<TagDecl>(D)) | |||
1352 | TD->addAttr(::new (S.Context) PackedAttr(AL.getRange(), S.Context, | |||
1353 | AL.getAttributeSpellingListIndex())); | |||
1354 | else if (auto *FD = dyn_cast<FieldDecl>(D)) { | |||
1355 | bool BitfieldByteAligned = (!FD->getType()->isDependentType() && | |||
1356 | !FD->getType()->isIncompleteType() && | |||
1357 | FD->isBitField() && | |||
1358 | S.Context.getTypeAlign(FD->getType()) <= 8); | |||
1359 | ||||
1360 | if (S.getASTContext().getTargetInfo().getTriple().isPS4()) { | |||
1361 | if (BitfieldByteAligned) | |||
1362 | // The PS4 target needs to maintain ABI backwards compatibility. | |||
1363 | S.Diag(AL.getLoc(), diag::warn_attribute_ignored_for_field_of_type) | |||
1364 | << AL << FD->getType(); | |||
1365 | else | |||
1366 | FD->addAttr(::new (S.Context) PackedAttr( | |||
1367 | AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); | |||
1368 | } else { | |||
1369 | // Report warning about changed offset in the newer compiler versions. | |||
1370 | if (BitfieldByteAligned) | |||
1371 | S.Diag(AL.getLoc(), diag::warn_attribute_packed_for_bitfield); | |||
1372 | ||||
1373 | FD->addAttr(::new (S.Context) PackedAttr( | |||
1374 | AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); | |||
1375 | } | |||
1376 | ||||
1377 | } else | |||
1378 | S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL; | |||
1379 | } | |||
1380 | ||||
1381 | static bool checkIBOutletCommon(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1382 | // The IBOutlet/IBOutletCollection attributes only apply to instance | |||
1383 | // variables or properties of Objective-C classes. The outlet must also | |||
1384 | // have an object reference type. | |||
1385 | if (const auto *VD = dyn_cast<ObjCIvarDecl>(D)) { | |||
1386 | if (!VD->getType()->getAs<ObjCObjectPointerType>()) { | |||
1387 | S.Diag(AL.getLoc(), diag::warn_iboutlet_object_type) | |||
1388 | << AL << VD->getType() << 0; | |||
1389 | return false; | |||
1390 | } | |||
1391 | } | |||
1392 | else if (const auto *PD = dyn_cast<ObjCPropertyDecl>(D)) { | |||
1393 | if (!PD->getType()->getAs<ObjCObjectPointerType>()) { | |||
1394 | S.Diag(AL.getLoc(), diag::warn_iboutlet_object_type) | |||
1395 | << AL << PD->getType() << 1; | |||
1396 | return false; | |||
1397 | } | |||
1398 | } | |||
1399 | else { | |||
1400 | S.Diag(AL.getLoc(), diag::warn_attribute_iboutlet) << AL; | |||
1401 | return false; | |||
1402 | } | |||
1403 | ||||
1404 | return true; | |||
1405 | } | |||
1406 | ||||
1407 | static void handleIBOutlet(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1408 | if (!checkIBOutletCommon(S, D, AL)) | |||
1409 | return; | |||
1410 | ||||
1411 | D->addAttr(::new (S.Context) | |||
1412 | IBOutletAttr(AL.getRange(), S.Context, | |||
1413 | AL.getAttributeSpellingListIndex())); | |||
1414 | } | |||
1415 | ||||
1416 | static void handleIBOutletCollection(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1417 | ||||
1418 | // The iboutletcollection attribute can have zero or one arguments. | |||
1419 | if (AL.getNumArgs() > 1) { | |||
1420 | S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; | |||
1421 | return; | |||
1422 | } | |||
1423 | ||||
1424 | if (!checkIBOutletCommon(S, D, AL)) | |||
1425 | return; | |||
1426 | ||||
1427 | ParsedType PT; | |||
1428 | ||||
1429 | if (AL.hasParsedType()) | |||
1430 | PT = AL.getTypeArg(); | |||
1431 | else { | |||
1432 | PT = S.getTypeName(S.Context.Idents.get("NSObject"), AL.getLoc(), | |||
1433 | S.getScopeForContext(D->getDeclContext()->getParent())); | |||
1434 | if (!PT) { | |||
1435 | S.Diag(AL.getLoc(), diag::err_iboutletcollection_type) << "NSObject"; | |||
1436 | return; | |||
1437 | } | |||
1438 | } | |||
1439 | ||||
1440 | TypeSourceInfo *QTLoc = nullptr; | |||
1441 | QualType QT = S.GetTypeFromParser(PT, &QTLoc); | |||
1442 | if (!QTLoc) | |||
1443 | QTLoc = S.Context.getTrivialTypeSourceInfo(QT, AL.getLoc()); | |||
1444 | ||||
1445 | // Diagnose use of non-object type in iboutletcollection attribute. | |||
1446 | // FIXME. Gnu attribute extension ignores use of builtin types in | |||
1447 | // attributes. So, __attribute__((iboutletcollection(char))) will be | |||
1448 | // treated as __attribute__((iboutletcollection())). | |||
1449 | if (!QT->isObjCIdType() && !QT->isObjCObjectType()) { | |||
1450 | S.Diag(AL.getLoc(), | |||
1451 | QT->isBuiltinType() ? diag::err_iboutletcollection_builtintype | |||
1452 | : diag::err_iboutletcollection_type) << QT; | |||
1453 | return; | |||
1454 | } | |||
1455 | ||||
1456 | D->addAttr(::new (S.Context) | |||
1457 | IBOutletCollectionAttr(AL.getRange(), S.Context, QTLoc, | |||
1458 | AL.getAttributeSpellingListIndex())); | |||
1459 | } | |||
1460 | ||||
1461 | bool Sema::isValidPointerAttrType(QualType T, bool RefOkay) { | |||
1462 | if (RefOkay) { | |||
1463 | if (T->isReferenceType()) | |||
1464 | return true; | |||
1465 | } else { | |||
1466 | T = T.getNonReferenceType(); | |||
1467 | } | |||
1468 | ||||
1469 | // The nonnull attribute, and other similar attributes, can be applied to a | |||
1470 | // transparent union that contains a pointer type. | |||
1471 | if (const RecordType *UT = T->getAsUnionType()) { | |||
1472 | if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) { | |||
1473 | RecordDecl *UD = UT->getDecl(); | |||
1474 | for (const auto *I : UD->fields()) { | |||
1475 | QualType QT = I->getType(); | |||
1476 | if (QT->isAnyPointerType() || QT->isBlockPointerType()) | |||
1477 | return true; | |||
1478 | } | |||
1479 | } | |||
1480 | } | |||
1481 | ||||
1482 | return T->isAnyPointerType() || T->isBlockPointerType(); | |||
1483 | } | |||
1484 | ||||
1485 | static bool attrNonNullArgCheck(Sema &S, QualType T, const ParsedAttr &AL, | |||
1486 | SourceRange AttrParmRange, | |||
1487 | SourceRange TypeRange, | |||
1488 | bool isReturnValue = false) { | |||
1489 | if (!S.isValidPointerAttrType(T)) { | |||
1490 | if (isReturnValue) | |||
1491 | S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only) | |||
1492 | << AL << AttrParmRange << TypeRange; | |||
1493 | else | |||
1494 | S.Diag(AL.getLoc(), diag::warn_attribute_pointers_only) | |||
1495 | << AL << AttrParmRange << TypeRange << 0; | |||
1496 | return false; | |||
1497 | } | |||
1498 | return true; | |||
1499 | } | |||
1500 | ||||
1501 | static void handleNonNullAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1502 | SmallVector<ParamIdx, 8> NonNullArgs; | |||
1503 | for (unsigned I = 0; I < AL.getNumArgs(); ++I) { | |||
1504 | Expr *Ex = AL.getArgAsExpr(I); | |||
1505 | ParamIdx Idx; | |||
1506 | if (!checkFunctionOrMethodParameterIndex(S, D, AL, I + 1, Ex, Idx)) | |||
1507 | return; | |||
1508 | ||||
1509 | // Is the function argument a pointer type? | |||
1510 | if (Idx.getASTIndex() < getFunctionOrMethodNumParams(D) && | |||
1511 | !attrNonNullArgCheck( | |||
1512 | S, getFunctionOrMethodParamType(D, Idx.getASTIndex()), AL, | |||
1513 | Ex->getSourceRange(), | |||
1514 | getFunctionOrMethodParamRange(D, Idx.getASTIndex()))) | |||
1515 | continue; | |||
1516 | ||||
1517 | NonNullArgs.push_back(Idx); | |||
1518 | } | |||
1519 | ||||
1520 | // If no arguments were specified to __attribute__((nonnull)) then all pointer | |||
1521 | // arguments have a nonnull attribute; warn if there aren't any. Skip this | |||
1522 | // check if the attribute came from a macro expansion or a template | |||
1523 | // instantiation. | |||
1524 | if (NonNullArgs.empty() && AL.getLoc().isFileID() && | |||
1525 | !S.inTemplateInstantiation()) { | |||
1526 | bool AnyPointers = isFunctionOrMethodVariadic(D); | |||
1527 | for (unsigned I = 0, E = getFunctionOrMethodNumParams(D); | |||
1528 | I != E && !AnyPointers; ++I) { | |||
1529 | QualType T = getFunctionOrMethodParamType(D, I); | |||
1530 | if (T->isDependentType() || S.isValidPointerAttrType(T)) | |||
1531 | AnyPointers = true; | |||
1532 | } | |||
1533 | ||||
1534 | if (!AnyPointers) | |||
1535 | S.Diag(AL.getLoc(), diag::warn_attribute_nonnull_no_pointers); | |||
1536 | } | |||
1537 | ||||
1538 | ParamIdx *Start = NonNullArgs.data(); | |||
1539 | unsigned Size = NonNullArgs.size(); | |||
1540 | llvm::array_pod_sort(Start, Start + Size); | |||
1541 | D->addAttr(::new (S.Context) | |||
1542 | NonNullAttr(AL.getRange(), S.Context, Start, Size, | |||
1543 | AL.getAttributeSpellingListIndex())); | |||
1544 | } | |||
1545 | ||||
1546 | static void handleNonNullAttrParameter(Sema &S, ParmVarDecl *D, | |||
1547 | const ParsedAttr &AL) { | |||
1548 | if (AL.getNumArgs() > 0) { | |||
1549 | if (D->getFunctionType()) { | |||
1550 | handleNonNullAttr(S, D, AL); | |||
1551 | } else { | |||
1552 | S.Diag(AL.getLoc(), diag::warn_attribute_nonnull_parm_no_args) | |||
1553 | << D->getSourceRange(); | |||
1554 | } | |||
1555 | return; | |||
1556 | } | |||
1557 | ||||
1558 | // Is the argument a pointer type? | |||
1559 | if (!attrNonNullArgCheck(S, D->getType(), AL, SourceRange(), | |||
1560 | D->getSourceRange())) | |||
1561 | return; | |||
1562 | ||||
1563 | D->addAttr(::new (S.Context) | |||
1564 | NonNullAttr(AL.getRange(), S.Context, nullptr, 0, | |||
1565 | AL.getAttributeSpellingListIndex())); | |||
1566 | } | |||
1567 | ||||
1568 | static void handleReturnsNonNullAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1569 | QualType ResultType = getFunctionOrMethodResultType(D); | |||
1570 | SourceRange SR = getFunctionOrMethodResultSourceRange(D); | |||
1571 | if (!attrNonNullArgCheck(S, ResultType, AL, SourceRange(), SR, | |||
1572 | /* isReturnValue */ true)) | |||
1573 | return; | |||
1574 | ||||
1575 | D->addAttr(::new (S.Context) | |||
1576 | ReturnsNonNullAttr(AL.getRange(), S.Context, | |||
1577 | AL.getAttributeSpellingListIndex())); | |||
1578 | } | |||
1579 | ||||
1580 | static void handleNoEscapeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1581 | if (D->isInvalidDecl()) | |||
1582 | return; | |||
1583 | ||||
1584 | // noescape only applies to pointer types. | |||
1585 | QualType T = cast<ParmVarDecl>(D)->getType(); | |||
1586 | if (!S.isValidPointerAttrType(T, /* RefOkay */ true)) { | |||
1587 | S.Diag(AL.getLoc(), diag::warn_attribute_pointers_only) | |||
1588 | << AL << AL.getRange() << 0; | |||
1589 | return; | |||
1590 | } | |||
1591 | ||||
1592 | D->addAttr(::new (S.Context) NoEscapeAttr( | |||
1593 | AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); | |||
1594 | } | |||
1595 | ||||
1596 | static void handleAssumeAlignedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1597 | Expr *E = AL.getArgAsExpr(0), | |||
1598 | *OE = AL.getNumArgs() > 1 ? AL.getArgAsExpr(1) : nullptr; | |||
1599 | S.AddAssumeAlignedAttr(AL.getRange(), D, E, OE, | |||
1600 | AL.getAttributeSpellingListIndex()); | |||
1601 | } | |||
1602 | ||||
1603 | static void handleAllocAlignAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1604 | S.AddAllocAlignAttr(AL.getRange(), D, AL.getArgAsExpr(0), | |||
1605 | AL.getAttributeSpellingListIndex()); | |||
1606 | } | |||
1607 | ||||
1608 | void Sema::AddAssumeAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, | |||
1609 | Expr *OE, unsigned SpellingListIndex) { | |||
1610 | QualType ResultType = getFunctionOrMethodResultType(D); | |||
1611 | SourceRange SR = getFunctionOrMethodResultSourceRange(D); | |||
1612 | ||||
1613 | AssumeAlignedAttr TmpAttr(AttrRange, Context, E, OE, SpellingListIndex); | |||
1614 | SourceLocation AttrLoc = AttrRange.getBegin(); | |||
1615 | ||||
1616 | if (!isValidPointerAttrType(ResultType, /* RefOkay */ true)) { | |||
1617 | Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only) | |||
1618 | << &TmpAttr << AttrRange << SR; | |||
1619 | return; | |||
1620 | } | |||
1621 | ||||
1622 | if (!E->isValueDependent()) { | |||
1623 | llvm::APSInt I(64); | |||
1624 | if (!E->isIntegerConstantExpr(I, Context)) { | |||
1625 | if (OE) | |||
1626 | Diag(AttrLoc, diag::err_attribute_argument_n_type) | |||
1627 | << &TmpAttr << 1 << AANT_ArgumentIntegerConstant | |||
1628 | << E->getSourceRange(); | |||
1629 | else | |||
1630 | Diag(AttrLoc, diag::err_attribute_argument_type) | |||
1631 | << &TmpAttr << AANT_ArgumentIntegerConstant | |||
1632 | << E->getSourceRange(); | |||
1633 | return; | |||
1634 | } | |||
1635 | ||||
1636 | if (!I.isPowerOf2()) { | |||
1637 | Diag(AttrLoc, diag::err_alignment_not_power_of_two) | |||
1638 | << E->getSourceRange(); | |||
1639 | return; | |||
1640 | } | |||
1641 | } | |||
1642 | ||||
1643 | if (OE) { | |||
1644 | if (!OE->isValueDependent()) { | |||
1645 | llvm::APSInt I(64); | |||
1646 | if (!OE->isIntegerConstantExpr(I, Context)) { | |||
1647 | Diag(AttrLoc, diag::err_attribute_argument_n_type) | |||
1648 | << &TmpAttr << 2 << AANT_ArgumentIntegerConstant | |||
1649 | << OE->getSourceRange(); | |||
1650 | return; | |||
1651 | } | |||
1652 | } | |||
1653 | } | |||
1654 | ||||
1655 | D->addAttr(::new (Context) | |||
1656 | AssumeAlignedAttr(AttrRange, Context, E, OE, SpellingListIndex)); | |||
1657 | } | |||
1658 | ||||
1659 | void Sema::AddAllocAlignAttr(SourceRange AttrRange, Decl *D, Expr *ParamExpr, | |||
1660 | unsigned SpellingListIndex) { | |||
1661 | QualType ResultType = getFunctionOrMethodResultType(D); | |||
1662 | ||||
1663 | AllocAlignAttr TmpAttr(AttrRange, Context, ParamIdx(), SpellingListIndex); | |||
1664 | SourceLocation AttrLoc = AttrRange.getBegin(); | |||
1665 | ||||
1666 | if (!ResultType->isDependentType() && | |||
1667 | !isValidPointerAttrType(ResultType, /* RefOkay */ true)) { | |||
1668 | Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only) | |||
1669 | << &TmpAttr << AttrRange << getFunctionOrMethodResultSourceRange(D); | |||
1670 | return; | |||
1671 | } | |||
1672 | ||||
1673 | ParamIdx Idx; | |||
1674 | const auto *FuncDecl = cast<FunctionDecl>(D); | |||
1675 | if (!checkFunctionOrMethodParameterIndex(*this, FuncDecl, TmpAttr, | |||
1676 | /*AttrArgNo=*/1, ParamExpr, Idx)) | |||
1677 | return; | |||
1678 | ||||
1679 | QualType Ty = getFunctionOrMethodParamType(D, Idx.getASTIndex()); | |||
1680 | if (!Ty->isDependentType() && !Ty->isIntegralType(Context)) { | |||
1681 | Diag(ParamExpr->getBeginLoc(), diag::err_attribute_integers_only) | |||
1682 | << &TmpAttr | |||
1683 | << FuncDecl->getParamDecl(Idx.getASTIndex())->getSourceRange(); | |||
1684 | return; | |||
1685 | } | |||
1686 | ||||
1687 | D->addAttr(::new (Context) | |||
1688 | AllocAlignAttr(AttrRange, Context, Idx, SpellingListIndex)); | |||
1689 | } | |||
1690 | ||||
1691 | /// Normalize the attribute, __foo__ becomes foo. | |||
1692 | /// Returns true if normalization was applied. | |||
1693 | static bool normalizeName(StringRef &AttrName) { | |||
1694 | if (AttrName.size() > 4 && AttrName.startswith("__") && | |||
1695 | AttrName.endswith("__")) { | |||
1696 | AttrName = AttrName.drop_front(2).drop_back(2); | |||
1697 | return true; | |||
1698 | } | |||
1699 | return false; | |||
1700 | } | |||
1701 | ||||
1702 | static void handleOwnershipAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1703 | // This attribute must be applied to a function declaration. The first | |||
1704 | // argument to the attribute must be an identifier, the name of the resource, | |||
1705 | // for example: malloc. The following arguments must be argument indexes, the | |||
1706 | // arguments must be of integer type for Returns, otherwise of pointer type. | |||
1707 | // The difference between Holds and Takes is that a pointer may still be used | |||
1708 | // after being held. free() should be __attribute((ownership_takes)), whereas | |||
1709 | // a list append function may well be __attribute((ownership_holds)). | |||
1710 | ||||
1711 | if (!AL.isArgIdent(0)) { | |||
1712 | S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) | |||
1713 | << AL << 1 << AANT_ArgumentIdentifier; | |||
1714 | return; | |||
1715 | } | |||
1716 | ||||
1717 | // Figure out our Kind. | |||
1718 | OwnershipAttr::OwnershipKind K = | |||
1719 | OwnershipAttr(AL.getLoc(), S.Context, nullptr, nullptr, 0, | |||
1720 | AL.getAttributeSpellingListIndex()).getOwnKind(); | |||
1721 | ||||
1722 | // Check arguments. | |||
1723 | switch (K) { | |||
1724 | case OwnershipAttr::Takes: | |||
1725 | case OwnershipAttr::Holds: | |||
1726 | if (AL.getNumArgs() < 2) { | |||
1727 | S.Diag(AL.getLoc(), diag::err_attribute_too_few_arguments) << AL << 2; | |||
1728 | return; | |||
1729 | } | |||
1730 | break; | |||
1731 | case OwnershipAttr::Returns: | |||
1732 | if (AL.getNumArgs() > 2) { | |||
1733 | S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 1; | |||
1734 | return; | |||
1735 | } | |||
1736 | break; | |||
1737 | } | |||
1738 | ||||
1739 | IdentifierInfo *Module = AL.getArgAsIdent(0)->Ident; | |||
1740 | ||||
1741 | StringRef ModuleName = Module->getName(); | |||
1742 | if (normalizeName(ModuleName)) { | |||
1743 | Module = &S.PP.getIdentifierTable().get(ModuleName); | |||
1744 | } | |||
1745 | ||||
1746 | SmallVector<ParamIdx, 8> OwnershipArgs; | |||
1747 | for (unsigned i = 1; i < AL.getNumArgs(); ++i) { | |||
1748 | Expr *Ex = AL.getArgAsExpr(i); | |||
1749 | ParamIdx Idx; | |||
1750 | if (!checkFunctionOrMethodParameterIndex(S, D, AL, i, Ex, Idx)) | |||
1751 | return; | |||
1752 | ||||
1753 | // Is the function argument a pointer type? | |||
1754 | QualType T = getFunctionOrMethodParamType(D, Idx.getASTIndex()); | |||
1755 | int Err = -1; // No error | |||
1756 | switch (K) { | |||
1757 | case OwnershipAttr::Takes: | |||
1758 | case OwnershipAttr::Holds: | |||
1759 | if (!T->isAnyPointerType() && !T->isBlockPointerType()) | |||
1760 | Err = 0; | |||
1761 | break; | |||
1762 | case OwnershipAttr::Returns: | |||
1763 | if (!T->isIntegerType()) | |||
1764 | Err = 1; | |||
1765 | break; | |||
1766 | } | |||
1767 | if (-1 != Err) { | |||
1768 | S.Diag(AL.getLoc(), diag::err_ownership_type) << AL << Err | |||
1769 | << Ex->getSourceRange(); | |||
1770 | return; | |||
1771 | } | |||
1772 | ||||
1773 | // Check we don't have a conflict with another ownership attribute. | |||
1774 | for (const auto *I : D->specific_attrs<OwnershipAttr>()) { | |||
1775 | // Cannot have two ownership attributes of different kinds for the same | |||
1776 | // index. | |||
1777 | if (I->getOwnKind() != K && I->args_end() != | |||
1778 | std::find(I->args_begin(), I->args_end(), Idx)) { | |||
1779 | S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << I; | |||
1780 | return; | |||
1781 | } else if (K == OwnershipAttr::Returns && | |||
1782 | I->getOwnKind() == OwnershipAttr::Returns) { | |||
1783 | // A returns attribute conflicts with any other returns attribute using | |||
1784 | // a different index. | |||
1785 | if (std::find(I->args_begin(), I->args_end(), Idx) == I->args_end()) { | |||
1786 | S.Diag(I->getLocation(), diag::err_ownership_returns_index_mismatch) | |||
1787 | << I->args_begin()->getSourceIndex(); | |||
1788 | if (I->args_size()) | |||
1789 | S.Diag(AL.getLoc(), diag::note_ownership_returns_index_mismatch) | |||
1790 | << Idx.getSourceIndex() << Ex->getSourceRange(); | |||
1791 | return; | |||
1792 | } | |||
1793 | } | |||
1794 | } | |||
1795 | OwnershipArgs.push_back(Idx); | |||
1796 | } | |||
1797 | ||||
1798 | ParamIdx *Start = OwnershipArgs.data(); | |||
1799 | unsigned Size = OwnershipArgs.size(); | |||
1800 | llvm::array_pod_sort(Start, Start + Size); | |||
1801 | D->addAttr(::new (S.Context) | |||
1802 | OwnershipAttr(AL.getLoc(), S.Context, Module, Start, Size, | |||
1803 | AL.getAttributeSpellingListIndex())); | |||
1804 | } | |||
1805 | ||||
1806 | static void handleWeakRefAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1807 | // Check the attribute arguments. | |||
1808 | if (AL.getNumArgs() > 1) { | |||
1809 | S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; | |||
1810 | return; | |||
1811 | } | |||
1812 | ||||
1813 | // gcc rejects | |||
1814 | // class c { | |||
1815 | // static int a __attribute__((weakref ("v2"))); | |||
1816 | // static int b() __attribute__((weakref ("f3"))); | |||
1817 | // }; | |||
1818 | // and ignores the attributes of | |||
1819 | // void f(void) { | |||
1820 | // static int a __attribute__((weakref ("v2"))); | |||
1821 | // } | |||
1822 | // we reject them | |||
1823 | const DeclContext *Ctx = D->getDeclContext()->getRedeclContext(); | |||
1824 | if (!Ctx->isFileContext()) { | |||
1825 | S.Diag(AL.getLoc(), diag::err_attribute_weakref_not_global_context) | |||
1826 | << cast<NamedDecl>(D); | |||
1827 | return; | |||
1828 | } | |||
1829 | ||||
1830 | // The GCC manual says | |||
1831 | // | |||
1832 | // At present, a declaration to which `weakref' is attached can only | |||
1833 | // be `static'. | |||
1834 | // | |||
1835 | // It also says | |||
1836 | // | |||
1837 | // Without a TARGET, | |||
1838 | // given as an argument to `weakref' or to `alias', `weakref' is | |||
1839 | // equivalent to `weak'. | |||
1840 | // | |||
1841 | // gcc 4.4.1 will accept | |||
1842 | // int a7 __attribute__((weakref)); | |||
1843 | // as | |||
1844 | // int a7 __attribute__((weak)); | |||
1845 | // This looks like a bug in gcc. We reject that for now. We should revisit | |||
1846 | // it if this behaviour is actually used. | |||
1847 | ||||
1848 | // GCC rejects | |||
1849 | // static ((alias ("y"), weakref)). | |||
1850 | // Should we? How to check that weakref is before or after alias? | |||
1851 | ||||
1852 | // FIXME: it would be good for us to keep the WeakRefAttr as-written instead | |||
1853 | // of transforming it into an AliasAttr. The WeakRefAttr never uses the | |||
1854 | // StringRef parameter it was given anyway. | |||
1855 | StringRef Str; | |||
1856 | if (AL.getNumArgs() && S.checkStringLiteralArgumentAttr(AL, 0, Str)) | |||
1857 | // GCC will accept anything as the argument of weakref. Should we | |||
1858 | // check for an existing decl? | |||
1859 | D->addAttr(::new (S.Context) AliasAttr(AL.getRange(), S.Context, Str, | |||
1860 | AL.getAttributeSpellingListIndex())); | |||
1861 | ||||
1862 | D->addAttr(::new (S.Context) | |||
1863 | WeakRefAttr(AL.getRange(), S.Context, | |||
1864 | AL.getAttributeSpellingListIndex())); | |||
1865 | } | |||
1866 | ||||
1867 | static void handleIFuncAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1868 | StringRef Str; | |||
1869 | if (!S.checkStringLiteralArgumentAttr(AL, 0, Str)) | |||
1870 | return; | |||
1871 | ||||
1872 | // Aliases should be on declarations, not definitions. | |||
1873 | const auto *FD = cast<FunctionDecl>(D); | |||
1874 | if (FD->isThisDeclarationADefinition()) { | |||
1875 | S.Diag(AL.getLoc(), diag::err_alias_is_definition) << FD << 1; | |||
1876 | return; | |||
1877 | } | |||
1878 | ||||
1879 | D->addAttr(::new (S.Context) IFuncAttr(AL.getRange(), S.Context, Str, | |||
1880 | AL.getAttributeSpellingListIndex())); | |||
1881 | } | |||
1882 | ||||
1883 | static void handleAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1884 | StringRef Str; | |||
1885 | if (!S.checkStringLiteralArgumentAttr(AL, 0, Str)) | |||
1886 | return; | |||
1887 | ||||
1888 | if (S.Context.getTargetInfo().getTriple().isOSDarwin()) { | |||
1889 | S.Diag(AL.getLoc(), diag::err_alias_not_supported_on_darwin); | |||
1890 | return; | |||
1891 | } | |||
1892 | if (S.Context.getTargetInfo().getTriple().isNVPTX()) { | |||
1893 | S.Diag(AL.getLoc(), diag::err_alias_not_supported_on_nvptx); | |||
1894 | } | |||
1895 | ||||
1896 | // Aliases should be on declarations, not definitions. | |||
1897 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) { | |||
1898 | if (FD->isThisDeclarationADefinition()) { | |||
1899 | S.Diag(AL.getLoc(), diag::err_alias_is_definition) << FD << 0; | |||
1900 | return; | |||
1901 | } | |||
1902 | } else { | |||
1903 | const auto *VD = cast<VarDecl>(D); | |||
1904 | if (VD->isThisDeclarationADefinition() && VD->isExternallyVisible()) { | |||
1905 | S.Diag(AL.getLoc(), diag::err_alias_is_definition) << VD << 0; | |||
1906 | return; | |||
1907 | } | |||
1908 | } | |||
1909 | ||||
1910 | // Mark target used to prevent unneeded-internal-declaration warnings. | |||
1911 | if (!S.LangOpts.CPlusPlus) { | |||
1912 | // FIXME: demangle Str for C++, as the attribute refers to the mangled | |||
1913 | // linkage name, not the pre-mangled identifier. | |||
1914 | const DeclarationNameInfo target(&S.Context.Idents.get(Str), AL.getLoc()); | |||
1915 | LookupResult LR(S, target, Sema::LookupOrdinaryName); | |||
1916 | if (S.LookupQualifiedName(LR, S.getCurLexicalContext())) | |||
1917 | for (NamedDecl *ND : LR) | |||
1918 | ND->markUsed(S.Context); | |||
1919 | } | |||
1920 | ||||
1921 | D->addAttr(::new (S.Context) AliasAttr(AL.getRange(), S.Context, Str, | |||
1922 | AL.getAttributeSpellingListIndex())); | |||
1923 | } | |||
1924 | ||||
1925 | static void handleTLSModelAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1926 | StringRef Model; | |||
1927 | SourceLocation LiteralLoc; | |||
1928 | // Check that it is a string. | |||
1929 | if (!S.checkStringLiteralArgumentAttr(AL, 0, Model, &LiteralLoc)) | |||
1930 | return; | |||
1931 | ||||
1932 | // Check that the value. | |||
1933 | if (Model != "global-dynamic" && Model != "local-dynamic" | |||
1934 | && Model != "initial-exec" && Model != "local-exec") { | |||
1935 | S.Diag(LiteralLoc, diag::err_attr_tlsmodel_arg); | |||
1936 | return; | |||
1937 | } | |||
1938 | ||||
1939 | D->addAttr(::new (S.Context) | |||
1940 | TLSModelAttr(AL.getRange(), S.Context, Model, | |||
1941 | AL.getAttributeSpellingListIndex())); | |||
1942 | } | |||
1943 | ||||
1944 | static void handleRestrictAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1945 | QualType ResultType = getFunctionOrMethodResultType(D); | |||
1946 | if (ResultType->isAnyPointerType() || ResultType->isBlockPointerType()) { | |||
1947 | D->addAttr(::new (S.Context) RestrictAttr( | |||
1948 | AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); | |||
1949 | return; | |||
1950 | } | |||
1951 | ||||
1952 | S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only) | |||
1953 | << AL << getFunctionOrMethodResultSourceRange(D); | |||
1954 | } | |||
1955 | ||||
1956 | static void handleCPUSpecificAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
1957 | FunctionDecl *FD = cast<FunctionDecl>(D); | |||
1958 | ||||
1959 | if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) { | |||
1960 | if (MD->getParent()->isLambda()) { | |||
1961 | S.Diag(AL.getLoc(), diag::err_attribute_dll_lambda) << AL; | |||
1962 | return; | |||
1963 | } | |||
1964 | } | |||
1965 | ||||
1966 | if (!checkAttributeAtLeastNumArgs(S, AL, 1)) | |||
1967 | return; | |||
1968 | ||||
1969 | SmallVector<IdentifierInfo *, 8> CPUs; | |||
1970 | for (unsigned ArgNo = 0; ArgNo < getNumAttributeArgs(AL); ++ArgNo) { | |||
1971 | if (!AL.isArgIdent(ArgNo)) { | |||
1972 | S.Diag(AL.getLoc(), diag::err_attribute_argument_type) | |||
1973 | << AL << AANT_ArgumentIdentifier; | |||
1974 | return; | |||
1975 | } | |||
1976 | ||||
1977 | IdentifierLoc *CPUArg = AL.getArgAsIdent(ArgNo); | |||
1978 | StringRef CPUName = CPUArg->Ident->getName().trim(); | |||
1979 | ||||
1980 | if (!S.Context.getTargetInfo().validateCPUSpecificCPUDispatch(CPUName)) { | |||
1981 | S.Diag(CPUArg->Loc, diag::err_invalid_cpu_specific_dispatch_value) | |||
1982 | << CPUName << (AL.getKind() == ParsedAttr::AT_CPUDispatch); | |||
1983 | return; | |||
1984 | } | |||
1985 | ||||
1986 | const TargetInfo &Target = S.Context.getTargetInfo(); | |||
1987 | if (llvm::any_of(CPUs, [CPUName, &Target](const IdentifierInfo *Cur) { | |||
1988 | return Target.CPUSpecificManglingCharacter(CPUName) == | |||
1989 | Target.CPUSpecificManglingCharacter(Cur->getName()); | |||
1990 | })) { | |||
1991 | S.Diag(AL.getLoc(), diag::warn_multiversion_duplicate_entries); | |||
1992 | return; | |||
1993 | } | |||
1994 | CPUs.push_back(CPUArg->Ident); | |||
1995 | } | |||
1996 | ||||
1997 | FD->setIsMultiVersion(true); | |||
1998 | if (AL.getKind() == ParsedAttr::AT_CPUSpecific) | |||
1999 | D->addAttr(::new (S.Context) CPUSpecificAttr( | |||
2000 | AL.getRange(), S.Context, CPUs.data(), CPUs.size(), | |||
2001 | AL.getAttributeSpellingListIndex())); | |||
2002 | else | |||
2003 | D->addAttr(::new (S.Context) CPUDispatchAttr( | |||
2004 | AL.getRange(), S.Context, CPUs.data(), CPUs.size(), | |||
2005 | AL.getAttributeSpellingListIndex())); | |||
2006 | } | |||
2007 | ||||
2008 | static void handleCommonAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2009 | if (S.LangOpts.CPlusPlus) { | |||
2010 | S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang) | |||
2011 | << AL << AttributeLangSupport::Cpp; | |||
2012 | return; | |||
2013 | } | |||
2014 | ||||
2015 | if (CommonAttr *CA = S.mergeCommonAttr(D, AL)) | |||
2016 | D->addAttr(CA); | |||
2017 | } | |||
2018 | ||||
2019 | static void handleNakedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2020 | if (checkAttrMutualExclusion<DisableTailCallsAttr>(S, D, AL)) | |||
2021 | return; | |||
2022 | ||||
2023 | if (AL.isDeclspecAttribute()) { | |||
2024 | const auto &Triple = S.getASTContext().getTargetInfo().getTriple(); | |||
2025 | const auto &Arch = Triple.getArch(); | |||
2026 | if (Arch != llvm::Triple::x86 && | |||
2027 | (Arch != llvm::Triple::arm && Arch != llvm::Triple::thumb)) { | |||
2028 | S.Diag(AL.getLoc(), diag::err_attribute_not_supported_on_arch) | |||
2029 | << AL << Triple.getArchName(); | |||
2030 | return; | |||
2031 | } | |||
2032 | } | |||
2033 | ||||
2034 | D->addAttr(::new (S.Context) NakedAttr(AL.getRange(), S.Context, | |||
2035 | AL.getAttributeSpellingListIndex())); | |||
2036 | } | |||
2037 | ||||
2038 | static void handleNoReturnAttr(Sema &S, Decl *D, const ParsedAttr &Attrs) { | |||
2039 | if (hasDeclarator(D)) return; | |||
2040 | ||||
2041 | if (!isa<ObjCMethodDecl>(D)) { | |||
2042 | S.Diag(Attrs.getLoc(), diag::warn_attribute_wrong_decl_type) | |||
2043 | << Attrs << ExpectedFunctionOrMethod; | |||
2044 | return; | |||
2045 | } | |||
2046 | ||||
2047 | D->addAttr(::new (S.Context) NoReturnAttr( | |||
2048 | Attrs.getRange(), S.Context, Attrs.getAttributeSpellingListIndex())); | |||
2049 | } | |||
2050 | ||||
2051 | static void handleNoCfCheckAttr(Sema &S, Decl *D, const ParsedAttr &Attrs) { | |||
2052 | if (!S.getLangOpts().CFProtectionBranch) | |||
2053 | S.Diag(Attrs.getLoc(), diag::warn_nocf_check_attribute_ignored); | |||
2054 | else | |||
2055 | handleSimpleAttribute<AnyX86NoCfCheckAttr>(S, D, Attrs); | |||
2056 | } | |||
2057 | ||||
2058 | bool Sema::CheckAttrNoArgs(const ParsedAttr &Attrs) { | |||
2059 | if (!checkAttributeNumArgs(*this, Attrs, 0)) { | |||
2060 | Attrs.setInvalid(); | |||
2061 | return true; | |||
2062 | } | |||
2063 | ||||
2064 | return false; | |||
2065 | } | |||
2066 | ||||
2067 | bool Sema::CheckAttrTarget(const ParsedAttr &AL) { | |||
2068 | // Check whether the attribute is valid on the current target. | |||
2069 | if (!AL.existsInTarget(Context.getTargetInfo())) { | |||
2070 | Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored) << AL; | |||
2071 | AL.setInvalid(); | |||
2072 | return true; | |||
2073 | } | |||
2074 | ||||
2075 | return false; | |||
2076 | } | |||
2077 | ||||
2078 | static void handleAnalyzerNoReturnAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2079 | ||||
2080 | // The checking path for 'noreturn' and 'analyzer_noreturn' are different | |||
2081 | // because 'analyzer_noreturn' does not impact the type. | |||
2082 | if (!isFunctionOrMethodOrBlock(D)) { | |||
2083 | ValueDecl *VD = dyn_cast<ValueDecl>(D); | |||
2084 | if (!VD || (!VD->getType()->isBlockPointerType() && | |||
2085 | !VD->getType()->isFunctionPointerType())) { | |||
2086 | S.Diag(AL.getLoc(), AL.isCXX11Attribute() | |||
2087 | ? diag::err_attribute_wrong_decl_type | |||
2088 | : diag::warn_attribute_wrong_decl_type) | |||
2089 | << AL << ExpectedFunctionMethodOrBlock; | |||
2090 | return; | |||
2091 | } | |||
2092 | } | |||
2093 | ||||
2094 | D->addAttr(::new (S.Context) | |||
2095 | AnalyzerNoReturnAttr(AL.getRange(), S.Context, | |||
2096 | AL.getAttributeSpellingListIndex())); | |||
2097 | } | |||
2098 | ||||
2099 | // PS3 PPU-specific. | |||
2100 | static void handleVecReturnAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2101 | /* | |||
2102 | Returning a Vector Class in Registers | |||
2103 | ||||
2104 | According to the PPU ABI specifications, a class with a single member of | |||
2105 | vector type is returned in memory when used as the return value of a | |||
2106 | function. | |||
2107 | This results in inefficient code when implementing vector classes. To return | |||
2108 | the value in a single vector register, add the vecreturn attribute to the | |||
2109 | class definition. This attribute is also applicable to struct types. | |||
2110 | ||||
2111 | Example: | |||
2112 | ||||
2113 | struct Vector | |||
2114 | { | |||
2115 | __vector float xyzw; | |||
2116 | } __attribute__((vecreturn)); | |||
2117 | ||||
2118 | Vector Add(Vector lhs, Vector rhs) | |||
2119 | { | |||
2120 | Vector result; | |||
2121 | result.xyzw = vec_add(lhs.xyzw, rhs.xyzw); | |||
2122 | return result; // This will be returned in a register | |||
2123 | } | |||
2124 | */ | |||
2125 | if (VecReturnAttr *A = D->getAttr<VecReturnAttr>()) { | |||
2126 | S.Diag(AL.getLoc(), diag::err_repeat_attribute) << A; | |||
2127 | return; | |||
2128 | } | |||
2129 | ||||
2130 | const auto *R = cast<RecordDecl>(D); | |||
2131 | int count = 0; | |||
2132 | ||||
2133 | if (!isa<CXXRecordDecl>(R)) { | |||
2134 | S.Diag(AL.getLoc(), diag::err_attribute_vecreturn_only_vector_member); | |||
2135 | return; | |||
2136 | } | |||
2137 | ||||
2138 | if (!cast<CXXRecordDecl>(R)->isPOD()) { | |||
2139 | S.Diag(AL.getLoc(), diag::err_attribute_vecreturn_only_pod_record); | |||
2140 | return; | |||
2141 | } | |||
2142 | ||||
2143 | for (const auto *I : R->fields()) { | |||
2144 | if ((count == 1) || !I->getType()->isVectorType()) { | |||
2145 | S.Diag(AL.getLoc(), diag::err_attribute_vecreturn_only_vector_member); | |||
2146 | return; | |||
2147 | } | |||
2148 | count++; | |||
2149 | } | |||
2150 | ||||
2151 | D->addAttr(::new (S.Context) VecReturnAttr( | |||
2152 | AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); | |||
2153 | } | |||
2154 | ||||
2155 | static void handleDependencyAttr(Sema &S, Scope *Scope, Decl *D, | |||
2156 | const ParsedAttr &AL) { | |||
2157 | if (isa<ParmVarDecl>(D)) { | |||
2158 | // [[carries_dependency]] can only be applied to a parameter if it is a | |||
2159 | // parameter of a function declaration or lambda. | |||
2160 | if (!(Scope->getFlags() & clang::Scope::FunctionDeclarationScope)) { | |||
2161 | S.Diag(AL.getLoc(), | |||
2162 | diag::err_carries_dependency_param_not_function_decl); | |||
2163 | return; | |||
2164 | } | |||
2165 | } | |||
2166 | ||||
2167 | D->addAttr(::new (S.Context) CarriesDependencyAttr( | |||
2168 | AL.getRange(), S.Context, | |||
2169 | AL.getAttributeSpellingListIndex())); | |||
2170 | } | |||
2171 | ||||
2172 | static void handleUnusedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2173 | bool IsCXX17Attr = AL.isCXX11Attribute() && !AL.getScopeName(); | |||
2174 | ||||
2175 | // If this is spelled as the standard C++17 attribute, but not in C++17, warn | |||
2176 | // about using it as an extension. | |||
2177 | if (!S.getLangOpts().CPlusPlus17 && IsCXX17Attr) | |||
2178 | S.Diag(AL.getLoc(), diag::ext_cxx17_attr) << AL; | |||
2179 | ||||
2180 | D->addAttr(::new (S.Context) UnusedAttr( | |||
2181 | AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); | |||
2182 | } | |||
2183 | ||||
2184 | static void handleConstructorAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2185 | uint32_t priority = ConstructorAttr::DefaultPriority; | |||
2186 | if (AL.getNumArgs() && | |||
2187 | !checkUInt32Argument(S, AL, AL.getArgAsExpr(0), priority)) | |||
2188 | return; | |||
2189 | ||||
2190 | D->addAttr(::new (S.Context) | |||
2191 | ConstructorAttr(AL.getRange(), S.Context, priority, | |||
2192 | AL.getAttributeSpellingListIndex())); | |||
2193 | } | |||
2194 | ||||
2195 | static void handleDestructorAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2196 | uint32_t priority = DestructorAttr::DefaultPriority; | |||
2197 | if (AL.getNumArgs() && | |||
2198 | !checkUInt32Argument(S, AL, AL.getArgAsExpr(0), priority)) | |||
2199 | return; | |||
2200 | ||||
2201 | D->addAttr(::new (S.Context) | |||
2202 | DestructorAttr(AL.getRange(), S.Context, priority, | |||
2203 | AL.getAttributeSpellingListIndex())); | |||
2204 | } | |||
2205 | ||||
2206 | template <typename AttrTy> | |||
2207 | static void handleAttrWithMessage(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2208 | // Handle the case where the attribute has a text message. | |||
2209 | StringRef Str; | |||
2210 | if (AL.getNumArgs() == 1 && !S.checkStringLiteralArgumentAttr(AL, 0, Str)) | |||
2211 | return; | |||
2212 | ||||
2213 | D->addAttr(::new (S.Context) AttrTy(AL.getRange(), S.Context, Str, | |||
2214 | AL.getAttributeSpellingListIndex())); | |||
2215 | } | |||
2216 | ||||
2217 | static void handleObjCSuppresProtocolAttr(Sema &S, Decl *D, | |||
2218 | const ParsedAttr &AL) { | |||
2219 | if (!cast<ObjCProtocolDecl>(D)->isThisDeclarationADefinition()) { | |||
2220 | S.Diag(AL.getLoc(), diag::err_objc_attr_protocol_requires_definition) | |||
2221 | << AL << AL.getRange(); | |||
2222 | return; | |||
2223 | } | |||
2224 | ||||
2225 | D->addAttr(::new (S.Context) | |||
2226 | ObjCExplicitProtocolImplAttr(AL.getRange(), S.Context, | |||
2227 | AL.getAttributeSpellingListIndex())); | |||
2228 | } | |||
2229 | ||||
2230 | static bool checkAvailabilityAttr(Sema &S, SourceRange Range, | |||
2231 | IdentifierInfo *Platform, | |||
2232 | VersionTuple Introduced, | |||
2233 | VersionTuple Deprecated, | |||
2234 | VersionTuple Obsoleted) { | |||
2235 | StringRef PlatformName | |||
2236 | = AvailabilityAttr::getPrettyPlatformName(Platform->getName()); | |||
2237 | if (PlatformName.empty()) | |||
2238 | PlatformName = Platform->getName(); | |||
2239 | ||||
2240 | // Ensure that Introduced <= Deprecated <= Obsoleted (although not all | |||
2241 | // of these steps are needed). | |||
2242 | if (!Introduced.empty() && !Deprecated.empty() && | |||
2243 | !(Introduced <= Deprecated)) { | |||
2244 | S.Diag(Range.getBegin(), diag::warn_availability_version_ordering) | |||
2245 | << 1 << PlatformName << Deprecated.getAsString() | |||
2246 | << 0 << Introduced.getAsString(); | |||
2247 | return true; | |||
2248 | } | |||
2249 | ||||
2250 | if (!Introduced.empty() && !Obsoleted.empty() && | |||
2251 | !(Introduced <= Obsoleted)) { | |||
2252 | S.Diag(Range.getBegin(), diag::warn_availability_version_ordering) | |||
2253 | << 2 << PlatformName << Obsoleted.getAsString() | |||
2254 | << 0 << Introduced.getAsString(); | |||
2255 | return true; | |||
2256 | } | |||
2257 | ||||
2258 | if (!Deprecated.empty() && !Obsoleted.empty() && | |||
2259 | !(Deprecated <= Obsoleted)) { | |||
2260 | S.Diag(Range.getBegin(), diag::warn_availability_version_ordering) | |||
2261 | << 2 << PlatformName << Obsoleted.getAsString() | |||
2262 | << 1 << Deprecated.getAsString(); | |||
2263 | return true; | |||
2264 | } | |||
2265 | ||||
2266 | return false; | |||
2267 | } | |||
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 | bool BeforeIsOkay) { | |||
2275 | if (X.empty() || Y.empty()) | |||
2276 | return true; | |||
2277 | ||||
2278 | if (X == Y) | |||
2279 | return true; | |||
2280 | ||||
2281 | if (BeforeIsOkay && X < Y) | |||
2282 | return true; | |||
2283 | ||||
2284 | return false; | |||
2285 | } | |||
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 | AvailabilityMergeKind AMK, int Priority, unsigned AttrSpellingListIndex) { | |||
2292 | VersionTuple MergedIntroduced = Introduced; | |||
2293 | VersionTuple MergedDeprecated = Deprecated; | |||
2294 | VersionTuple MergedObsoleted = Obsoleted; | |||
2295 | bool FoundAny = false; | |||
2296 | bool OverrideOrImpl = false; | |||
2297 | switch (AMK) { | |||
2298 | case AMK_None: | |||
2299 | case AMK_Redeclaration: | |||
2300 | OverrideOrImpl = false; | |||
2301 | break; | |||
2302 | ||||
2303 | case AMK_Override: | |||
2304 | case AMK_ProtocolImplementation: | |||
2305 | OverrideOrImpl = true; | |||
2306 | break; | |||
2307 | } | |||
2308 | ||||
2309 | if (D->hasAttrs()) { | |||
2310 | AttrVec &Attrs = D->getAttrs(); | |||
2311 | for (unsigned i = 0, e = Attrs.size(); i != e;) { | |||
2312 | const auto *OldAA = dyn_cast<AvailabilityAttr>(Attrs[i]); | |||
2313 | if (!OldAA) { | |||
2314 | ++i; | |||
2315 | continue; | |||
2316 | } | |||
2317 | ||||
2318 | IdentifierInfo *OldPlatform = OldAA->getPlatform(); | |||
2319 | if (OldPlatform != Platform) { | |||
2320 | ++i; | |||
2321 | continue; | |||
2322 | } | |||
2323 | ||||
2324 | // If there is an existing availability attribute for this platform that | |||
2325 | // has a lower priority use the existing one and discard the new | |||
2326 | // attribute. | |||
2327 | if (OldAA->getPriority() < Priority) | |||
2328 | return nullptr; | |||
2329 | ||||
2330 | // If there is an existing attribute for this platform that has a higher | |||
2331 | // priority than the new attribute then erase the old one and continue | |||
2332 | // processing the attributes. | |||
2333 | if (OldAA->getPriority() > Priority) { | |||
2334 | Attrs.erase(Attrs.begin() + i); | |||
2335 | --e; | |||
2336 | continue; | |||
2337 | } | |||
2338 | ||||
2339 | FoundAny = true; | |||
2340 | VersionTuple OldIntroduced = OldAA->getIntroduced(); | |||
2341 | VersionTuple OldDeprecated = OldAA->getDeprecated(); | |||
2342 | VersionTuple OldObsoleted = OldAA->getObsoleted(); | |||
2343 | bool OldIsUnavailable = OldAA->getUnavailable(); | |||
2344 | ||||
2345 | if (!versionsMatch(OldIntroduced, Introduced, OverrideOrImpl) || | |||
2346 | !versionsMatch(Deprecated, OldDeprecated, OverrideOrImpl) || | |||
2347 | !versionsMatch(Obsoleted, OldObsoleted, OverrideOrImpl) || | |||
2348 | !(OldIsUnavailable == IsUnavailable || | |||
2349 | (OverrideOrImpl && !OldIsUnavailable && IsUnavailable))) { | |||
2350 | if (OverrideOrImpl) { | |||
2351 | int Which = -1; | |||
2352 | VersionTuple FirstVersion; | |||
2353 | VersionTuple SecondVersion; | |||
2354 | if (!versionsMatch(OldIntroduced, Introduced, OverrideOrImpl)) { | |||
2355 | Which = 0; | |||
2356 | FirstVersion = OldIntroduced; | |||
2357 | SecondVersion = Introduced; | |||
2358 | } else if (!versionsMatch(Deprecated, OldDeprecated, OverrideOrImpl)) { | |||
2359 | Which = 1; | |||
2360 | FirstVersion = Deprecated; | |||
2361 | SecondVersion = OldDeprecated; | |||
2362 | } else if (!versionsMatch(Obsoleted, OldObsoleted, OverrideOrImpl)) { | |||
2363 | Which = 2; | |||
2364 | FirstVersion = Obsoleted; | |||
2365 | SecondVersion = OldObsoleted; | |||
2366 | } | |||
2367 | ||||
2368 | if (Which == -1) { | |||
2369 | Diag(OldAA->getLocation(), | |||
2370 | diag::warn_mismatched_availability_override_unavail) | |||
2371 | << AvailabilityAttr::getPrettyPlatformName(Platform->getName()) | |||
2372 | << (AMK == AMK_Override); | |||
2373 | } else { | |||
2374 | Diag(OldAA->getLocation(), | |||
2375 | diag::warn_mismatched_availability_override) | |||
2376 | << Which | |||
2377 | << AvailabilityAttr::getPrettyPlatformName(Platform->getName()) | |||
2378 | << FirstVersion.getAsString() << SecondVersion.getAsString() | |||
2379 | << (AMK == AMK_Override); | |||
2380 | } | |||
2381 | if (AMK == AMK_Override) | |||
2382 | Diag(Range.getBegin(), diag::note_overridden_method); | |||
2383 | else | |||
2384 | Diag(Range.getBegin(), diag::note_protocol_method); | |||
2385 | } else { | |||
2386 | Diag(OldAA->getLocation(), diag::warn_mismatched_availability); | |||
2387 | Diag(Range.getBegin(), diag::note_previous_attribute); | |||
2388 | } | |||
2389 | ||||
2390 | Attrs.erase(Attrs.begin() + i); | |||
2391 | --e; | |||
2392 | continue; | |||
2393 | } | |||
2394 | ||||
2395 | VersionTuple MergedIntroduced2 = MergedIntroduced; | |||
2396 | VersionTuple MergedDeprecated2 = MergedDeprecated; | |||
2397 | VersionTuple MergedObsoleted2 = MergedObsoleted; | |||
2398 | ||||
2399 | if (MergedIntroduced2.empty()) | |||
2400 | MergedIntroduced2 = OldIntroduced; | |||
2401 | if (MergedDeprecated2.empty()) | |||
2402 | MergedDeprecated2 = OldDeprecated; | |||
2403 | if (MergedObsoleted2.empty()) | |||
2404 | MergedObsoleted2 = OldObsoleted; | |||
2405 | ||||
2406 | if (checkAvailabilityAttr(*this, OldAA->getRange(), Platform, | |||
2407 | MergedIntroduced2, MergedDeprecated2, | |||
2408 | MergedObsoleted2)) { | |||
2409 | Attrs.erase(Attrs.begin() + i); | |||
2410 | --e; | |||
2411 | continue; | |||
2412 | } | |||
2413 | ||||
2414 | MergedIntroduced = MergedIntroduced2; | |||
2415 | MergedDeprecated = MergedDeprecated2; | |||
2416 | MergedObsoleted = MergedObsoleted2; | |||
2417 | ++i; | |||
2418 | } | |||
2419 | } | |||
2420 | ||||
2421 | if (FoundAny && | |||
2422 | MergedIntroduced == Introduced && | |||
2423 | MergedDeprecated == Deprecated && | |||
2424 | MergedObsoleted == Obsoleted) | |||
2425 | return nullptr; | |||
2426 | ||||
2427 | // Only create a new attribute if !OverrideOrImpl, but we want to do | |||
2428 | // the checking. | |||
2429 | if (!checkAvailabilityAttr(*this, Range, Platform, MergedIntroduced, | |||
2430 | MergedDeprecated, MergedObsoleted) && | |||
2431 | !OverrideOrImpl) { | |||
2432 | auto *Avail = ::new (Context) | |||
2433 | AvailabilityAttr(Range, Context, Platform, Introduced, Deprecated, | |||
2434 | Obsoleted, IsUnavailable, Message, IsStrict, | |||
2435 | Replacement, Priority, AttrSpellingListIndex); | |||
2436 | Avail->setImplicit(Implicit); | |||
2437 | return Avail; | |||
2438 | } | |||
2439 | return nullptr; | |||
2440 | } | |||
2441 | ||||
2442 | static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2443 | if (!checkAttributeNumArgs(S, AL, 1)) | |||
2444 | return; | |||
2445 | IdentifierLoc *Platform = AL.getArgAsIdent(0); | |||
2446 | unsigned Index = AL.getAttributeSpellingListIndex(); | |||
2447 | ||||
2448 | IdentifierInfo *II = Platform->Ident; | |||
2449 | if (AvailabilityAttr::getPrettyPlatformName(II->getName()).empty()) | |||
2450 | S.Diag(Platform->Loc, diag::warn_availability_unknown_platform) | |||
2451 | << Platform->Ident; | |||
2452 | ||||
2453 | auto *ND = dyn_cast<NamedDecl>(D); | |||
2454 | if (!ND) // We warned about this already, so just return. | |||
2455 | return; | |||
2456 | ||||
2457 | AvailabilityChange Introduced = AL.getAvailabilityIntroduced(); | |||
2458 | AvailabilityChange Deprecated = AL.getAvailabilityDeprecated(); | |||
2459 | AvailabilityChange Obsoleted = AL.getAvailabilityObsoleted(); | |||
2460 | bool IsUnavailable = AL.getUnavailableLoc().isValid(); | |||
2461 | bool IsStrict = AL.getStrictLoc().isValid(); | |||
2462 | StringRef Str; | |||
2463 | if (const auto *SE = dyn_cast_or_null<StringLiteral>(AL.getMessageExpr())) | |||
2464 | Str = SE->getString(); | |||
2465 | StringRef Replacement; | |||
2466 | if (const auto *SE = dyn_cast_or_null<StringLiteral>(AL.getReplacementExpr())) | |||
2467 | Replacement = SE->getString(); | |||
2468 | ||||
2469 | if (II->isStr("swift")) { | |||
2470 | if (Introduced.isValid() || Obsoleted.isValid() || | |||
2471 | (!IsUnavailable && !Deprecated.isValid())) { | |||
2472 | S.Diag(AL.getLoc(), | |||
2473 | diag::warn_availability_swift_unavailable_deprecated_only); | |||
2474 | return; | |||
2475 | } | |||
2476 | } | |||
2477 | ||||
2478 | int PriorityModifier = AL.isPragmaClangAttribute() | |||
2479 | ? Sema::AP_PragmaClangAttribute | |||
2480 | : Sema::AP_Explicit; | |||
2481 | AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr( | |||
2482 | ND, AL.getRange(), II, false /*Implicit*/, Introduced.Version, | |||
2483 | Deprecated.Version, Obsoleted.Version, IsUnavailable, Str, IsStrict, | |||
2484 | Replacement, Sema::AMK_None, PriorityModifier, Index); | |||
2485 | if (NewAttr) | |||
2486 | D->addAttr(NewAttr); | |||
2487 | ||||
2488 | // Transcribe "ios" to "watchos" (and add a new attribute) if the versioning | |||
2489 | // matches before the start of the watchOS platform. | |||
2490 | if (S.Context.getTargetInfo().getTriple().isWatchOS()) { | |||
2491 | IdentifierInfo *NewII = nullptr; | |||
2492 | if (II->getName() == "ios") | |||
2493 | NewII = &S.Context.Idents.get("watchos"); | |||
2494 | else if (II->getName() == "ios_app_extension") | |||
2495 | NewII = &S.Context.Idents.get("watchos_app_extension"); | |||
2496 | ||||
2497 | if (NewII) { | |||
2498 | auto adjustWatchOSVersion = [](VersionTuple Version) -> VersionTuple { | |||
2499 | if (Version.empty()) | |||
2500 | return Version; | |||
2501 | auto Major = Version.getMajor(); | |||
2502 | auto NewMajor = Major >= 9 ? Major - 7 : 0; | |||
2503 | if (NewMajor >= 2) { | |||
2504 | if (Version.getMinor().hasValue()) { | |||
2505 | if (Version.getSubminor().hasValue()) | |||
2506 | return VersionTuple(NewMajor, Version.getMinor().getValue(), | |||
2507 | Version.getSubminor().getValue()); | |||
2508 | else | |||
2509 | return VersionTuple(NewMajor, Version.getMinor().getValue()); | |||
2510 | } | |||
2511 | return VersionTuple(NewMajor); | |||
2512 | } | |||
2513 | ||||
2514 | return VersionTuple(2, 0); | |||
2515 | }; | |||
2516 | ||||
2517 | auto NewIntroduced = adjustWatchOSVersion(Introduced.Version); | |||
2518 | auto NewDeprecated = adjustWatchOSVersion(Deprecated.Version); | |||
2519 | auto NewObsoleted = adjustWatchOSVersion(Obsoleted.Version); | |||
2520 | ||||
2521 | AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr( | |||
2522 | ND, AL.getRange(), NewII, true /*Implicit*/, NewIntroduced, | |||
2523 | NewDeprecated, NewObsoleted, IsUnavailable, Str, IsStrict, | |||
2524 | Replacement, Sema::AMK_None, | |||
2525 | PriorityModifier + Sema::AP_InferredFromOtherPlatform, Index); | |||
2526 | if (NewAttr) | |||
2527 | D->addAttr(NewAttr); | |||
2528 | } | |||
2529 | } else if (S.Context.getTargetInfo().getTriple().isTvOS()) { | |||
2530 | // Transcribe "ios" to "tvos" (and add a new attribute) if the versioning | |||
2531 | // matches before the start of the tvOS platform. | |||
2532 | IdentifierInfo *NewII = nullptr; | |||
2533 | if (II->getName() == "ios") | |||
2534 | NewII = &S.Context.Idents.get("tvos"); | |||
2535 | else if (II->getName() == "ios_app_extension") | |||
2536 | NewII = &S.Context.Idents.get("tvos_app_extension"); | |||
2537 | ||||
2538 | if (NewII) { | |||
2539 | AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr( | |||
2540 | ND, AL.getRange(), NewII, true /*Implicit*/, Introduced.Version, | |||
2541 | Deprecated.Version, Obsoleted.Version, IsUnavailable, Str, IsStrict, | |||
2542 | Replacement, Sema::AMK_None, | |||
2543 | PriorityModifier + Sema::AP_InferredFromOtherPlatform, Index); | |||
2544 | if (NewAttr) | |||
2545 | D->addAttr(NewAttr); | |||
2546 | } | |||
2547 | } | |||
2548 | } | |||
2549 | ||||
2550 | static void handleExternalSourceSymbolAttr(Sema &S, Decl *D, | |||
2551 | const ParsedAttr &AL) { | |||
2552 | if (!checkAttributeAtLeastNumArgs(S, AL, 1)) | |||
2553 | return; | |||
2554 | assert(checkAttributeAtMostNumArgs(S, AL, 3) &&((checkAttributeAtMostNumArgs(S, AL, 3) && "Invalid number of arguments in an external_source_symbol attribute" ) ? static_cast<void> (0) : __assert_fail ("checkAttributeAtMostNumArgs(S, AL, 3) && \"Invalid number of arguments in an external_source_symbol attribute\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 2555, __PRETTY_FUNCTION__)) | |||
2555 | "Invalid number of arguments in an external_source_symbol attribute")((checkAttributeAtMostNumArgs(S, AL, 3) && "Invalid number of arguments in an external_source_symbol attribute" ) ? static_cast<void> (0) : __assert_fail ("checkAttributeAtMostNumArgs(S, AL, 3) && \"Invalid number of arguments in an external_source_symbol attribute\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 2555, __PRETTY_FUNCTION__)); | |||
2556 | ||||
2557 | StringRef Language; | |||
2558 | if (const auto *SE = dyn_cast_or_null<StringLiteral>(AL.getArgAsExpr(0))) | |||
2559 | Language = SE->getString(); | |||
2560 | StringRef DefinedIn; | |||
2561 | if (const auto *SE = dyn_cast_or_null<StringLiteral>(AL.getArgAsExpr(1))) | |||
2562 | DefinedIn = SE->getString(); | |||
2563 | bool IsGeneratedDeclaration = AL.getArgAsIdent(2) != nullptr; | |||
2564 | ||||
2565 | D->addAttr(::new (S.Context) ExternalSourceSymbolAttr( | |||
2566 | AL.getRange(), S.Context, Language, DefinedIn, IsGeneratedDeclaration, | |||
2567 | AL.getAttributeSpellingListIndex())); | |||
2568 | } | |||
2569 | ||||
2570 | template <class T> | |||
2571 | static T *mergeVisibilityAttr(Sema &S, Decl *D, SourceRange range, | |||
2572 | typename T::VisibilityType value, | |||
2573 | unsigned attrSpellingListIndex) { | |||
2574 | T *existingAttr = D->getAttr<T>(); | |||
2575 | if (existingAttr) { | |||
2576 | typename T::VisibilityType existingValue = existingAttr->getVisibility(); | |||
2577 | if (existingValue == value) | |||
2578 | return nullptr; | |||
2579 | S.Diag(existingAttr->getLocation(), diag::err_mismatched_visibility); | |||
2580 | S.Diag(range.getBegin(), diag::note_previous_attribute); | |||
2581 | D->dropAttr<T>(); | |||
2582 | } | |||
2583 | return ::new (S.Context) T(range, S.Context, value, attrSpellingListIndex); | |||
2584 | } | |||
2585 | ||||
2586 | VisibilityAttr *Sema::mergeVisibilityAttr(Decl *D, SourceRange Range, | |||
2587 | VisibilityAttr::VisibilityType Vis, | |||
2588 | unsigned AttrSpellingListIndex) { | |||
2589 | return ::mergeVisibilityAttr<VisibilityAttr>(*this, D, Range, Vis, | |||
2590 | AttrSpellingListIndex); | |||
2591 | } | |||
2592 | ||||
2593 | TypeVisibilityAttr *Sema::mergeTypeVisibilityAttr(Decl *D, SourceRange Range, | |||
2594 | TypeVisibilityAttr::VisibilityType Vis, | |||
2595 | unsigned AttrSpellingListIndex) { | |||
2596 | return ::mergeVisibilityAttr<TypeVisibilityAttr>(*this, D, Range, Vis, | |||
2597 | AttrSpellingListIndex); | |||
2598 | } | |||
2599 | ||||
2600 | static void handleVisibilityAttr(Sema &S, Decl *D, const ParsedAttr &AL, | |||
2601 | bool isTypeVisibility) { | |||
2602 | // Visibility attributes don't mean anything on a typedef. | |||
2603 | if (isa<TypedefNameDecl>(D)) { | |||
2604 | S.Diag(AL.getRange().getBegin(), diag::warn_attribute_ignored) << AL; | |||
2605 | return; | |||
2606 | } | |||
2607 | ||||
2608 | // 'type_visibility' can only go on a type or namespace. | |||
2609 | if (isTypeVisibility && | |||
2610 | !(isa<TagDecl>(D) || | |||
2611 | isa<ObjCInterfaceDecl>(D) || | |||
2612 | isa<NamespaceDecl>(D))) { | |||
2613 | S.Diag(AL.getRange().getBegin(), diag::err_attribute_wrong_decl_type) | |||
2614 | << AL << ExpectedTypeOrNamespace; | |||
2615 | return; | |||
2616 | } | |||
2617 | ||||
2618 | // Check that the argument is a string literal. | |||
2619 | StringRef TypeStr; | |||
2620 | SourceLocation LiteralLoc; | |||
2621 | if (!S.checkStringLiteralArgumentAttr(AL, 0, TypeStr, &LiteralLoc)) | |||
2622 | return; | |||
2623 | ||||
2624 | VisibilityAttr::VisibilityType type; | |||
2625 | if (!VisibilityAttr::ConvertStrToVisibilityType(TypeStr, type)) { | |||
2626 | S.Diag(LiteralLoc, diag::warn_attribute_type_not_supported) << AL | |||
2627 | << TypeStr; | |||
2628 | return; | |||
2629 | } | |||
2630 | ||||
2631 | // Complain about attempts to use protected visibility on targets | |||
2632 | // (like Darwin) that don't support it. | |||
2633 | if (type == VisibilityAttr::Protected && | |||
2634 | !S.Context.getTargetInfo().hasProtectedVisibility()) { | |||
2635 | S.Diag(AL.getLoc(), diag::warn_attribute_protected_visibility); | |||
2636 | type = VisibilityAttr::Default; | |||
2637 | } | |||
2638 | ||||
2639 | unsigned Index = AL.getAttributeSpellingListIndex(); | |||
2640 | Attr *newAttr; | |||
2641 | if (isTypeVisibility) { | |||
2642 | newAttr = S.mergeTypeVisibilityAttr(D, AL.getRange(), | |||
2643 | (TypeVisibilityAttr::VisibilityType) type, | |||
2644 | Index); | |||
2645 | } else { | |||
2646 | newAttr = S.mergeVisibilityAttr(D, AL.getRange(), type, Index); | |||
2647 | } | |||
2648 | if (newAttr) | |||
2649 | D->addAttr(newAttr); | |||
2650 | } | |||
2651 | ||||
2652 | static void handleObjCMethodFamilyAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2653 | const auto *M = cast<ObjCMethodDecl>(D); | |||
2654 | if (!AL.isArgIdent(0)) { | |||
2655 | S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) | |||
2656 | << AL << 1 << AANT_ArgumentIdentifier; | |||
2657 | return; | |||
2658 | } | |||
2659 | ||||
2660 | IdentifierLoc *IL = AL.getArgAsIdent(0); | |||
2661 | ObjCMethodFamilyAttr::FamilyKind F; | |||
2662 | if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind(IL->Ident->getName(), F)) { | |||
2663 | S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL << IL->Ident; | |||
2664 | return; | |||
2665 | } | |||
2666 | ||||
2667 | if (F == ObjCMethodFamilyAttr::OMF_init && | |||
2668 | !M->getReturnType()->isObjCObjectPointerType()) { | |||
2669 | S.Diag(M->getLocation(), diag::err_init_method_bad_return_type) | |||
2670 | << M->getReturnType(); | |||
2671 | // Ignore the attribute. | |||
2672 | return; | |||
2673 | } | |||
2674 | ||||
2675 | D->addAttr(new (S.Context) ObjCMethodFamilyAttr( | |||
2676 | AL.getRange(), S.Context, F, AL.getAttributeSpellingListIndex())); | |||
2677 | } | |||
2678 | ||||
2679 | static void handleObjCNSObject(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2680 | if (const auto *TD = dyn_cast<TypedefNameDecl>(D)) { | |||
2681 | QualType T = TD->getUnderlyingType(); | |||
2682 | if (!T->isCARCBridgableType()) { | |||
2683 | S.Diag(TD->getLocation(), diag::err_nsobject_attribute); | |||
2684 | return; | |||
2685 | } | |||
2686 | } | |||
2687 | else if (const auto *PD = dyn_cast<ObjCPropertyDecl>(D)) { | |||
2688 | QualType T = PD->getType(); | |||
2689 | if (!T->isCARCBridgableType()) { | |||
2690 | S.Diag(PD->getLocation(), diag::err_nsobject_attribute); | |||
2691 | return; | |||
2692 | } | |||
2693 | } | |||
2694 | else { | |||
2695 | // It is okay to include this attribute on properties, e.g.: | |||
2696 | // | |||
2697 | // @property (retain, nonatomic) struct Bork *Q __attribute__((NSObject)); | |||
2698 | // | |||
2699 | // In this case it follows tradition and suppresses an error in the above | |||
2700 | // case. | |||
2701 | S.Diag(D->getLocation(), diag::warn_nsobject_attribute); | |||
2702 | } | |||
2703 | D->addAttr(::new (S.Context) | |||
2704 | ObjCNSObjectAttr(AL.getRange(), S.Context, | |||
2705 | AL.getAttributeSpellingListIndex())); | |||
2706 | } | |||
2707 | ||||
2708 | static void handleObjCIndependentClass(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2709 | if (const auto *TD = dyn_cast<TypedefNameDecl>(D)) { | |||
2710 | QualType T = TD->getUnderlyingType(); | |||
2711 | if (!T->isObjCObjectPointerType()) { | |||
2712 | S.Diag(TD->getLocation(), diag::warn_ptr_independentclass_attribute); | |||
2713 | return; | |||
2714 | } | |||
2715 | } else { | |||
2716 | S.Diag(D->getLocation(), diag::warn_independentclass_attribute); | |||
2717 | return; | |||
2718 | } | |||
2719 | D->addAttr(::new (S.Context) | |||
2720 | ObjCIndependentClassAttr(AL.getRange(), S.Context, | |||
2721 | AL.getAttributeSpellingListIndex())); | |||
2722 | } | |||
2723 | ||||
2724 | static void handleBlocksAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2725 | if (!AL.isArgIdent(0)) { | |||
2726 | S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) | |||
2727 | << AL << 1 << AANT_ArgumentIdentifier; | |||
2728 | return; | |||
2729 | } | |||
2730 | ||||
2731 | IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; | |||
2732 | BlocksAttr::BlockType type; | |||
2733 | if (!BlocksAttr::ConvertStrToBlockType(II->getName(), type)) { | |||
2734 | S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II; | |||
2735 | return; | |||
2736 | } | |||
2737 | ||||
2738 | D->addAttr(::new (S.Context) | |||
2739 | BlocksAttr(AL.getRange(), S.Context, type, | |||
2740 | AL.getAttributeSpellingListIndex())); | |||
2741 | } | |||
2742 | ||||
2743 | static void handleSentinelAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2744 | unsigned sentinel = (unsigned)SentinelAttr::DefaultSentinel; | |||
2745 | if (AL.getNumArgs() > 0) { | |||
2746 | Expr *E = AL.getArgAsExpr(0); | |||
2747 | llvm::APSInt Idx(32); | |||
2748 | if (E->isTypeDependent() || E->isValueDependent() || | |||
2749 | !E->isIntegerConstantExpr(Idx, S.Context)) { | |||
2750 | S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) | |||
2751 | << AL << 1 << AANT_ArgumentIntegerConstant << E->getSourceRange(); | |||
2752 | return; | |||
2753 | } | |||
2754 | ||||
2755 | if (Idx.isSigned() && Idx.isNegative()) { | |||
2756 | S.Diag(AL.getLoc(), diag::err_attribute_sentinel_less_than_zero) | |||
2757 | << E->getSourceRange(); | |||
2758 | return; | |||
2759 | } | |||
2760 | ||||
2761 | sentinel = Idx.getZExtValue(); | |||
2762 | } | |||
2763 | ||||
2764 | unsigned nullPos = (unsigned)SentinelAttr::DefaultNullPos; | |||
2765 | if (AL.getNumArgs() > 1) { | |||
2766 | Expr *E = AL.getArgAsExpr(1); | |||
2767 | llvm::APSInt Idx(32); | |||
2768 | if (E->isTypeDependent() || E->isValueDependent() || | |||
2769 | !E->isIntegerConstantExpr(Idx, S.Context)) { | |||
2770 | S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) | |||
2771 | << AL << 2 << AANT_ArgumentIntegerConstant << E->getSourceRange(); | |||
2772 | return; | |||
2773 | } | |||
2774 | nullPos = Idx.getZExtValue(); | |||
2775 | ||||
2776 | if ((Idx.isSigned() && Idx.isNegative()) || nullPos > 1) { | |||
2777 | // FIXME: This error message could be improved, it would be nice | |||
2778 | // to say what the bounds actually are. | |||
2779 | S.Diag(AL.getLoc(), diag::err_attribute_sentinel_not_zero_or_one) | |||
2780 | << E->getSourceRange(); | |||
2781 | return; | |||
2782 | } | |||
2783 | } | |||
2784 | ||||
2785 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) { | |||
2786 | const FunctionType *FT = FD->getType()->castAs<FunctionType>(); | |||
2787 | if (isa<FunctionNoProtoType>(FT)) { | |||
2788 | S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_named_arguments); | |||
2789 | return; | |||
2790 | } | |||
2791 | ||||
2792 | if (!cast<FunctionProtoType>(FT)->isVariadic()) { | |||
2793 | S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0; | |||
2794 | return; | |||
2795 | } | |||
2796 | } else if (const auto *MD = dyn_cast<ObjCMethodDecl>(D)) { | |||
2797 | if (!MD->isVariadic()) { | |||
2798 | S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0; | |||
2799 | return; | |||
2800 | } | |||
2801 | } else if (const auto *BD = dyn_cast<BlockDecl>(D)) { | |||
2802 | if (!BD->isVariadic()) { | |||
2803 | S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 1; | |||
2804 | return; | |||
2805 | } | |||
2806 | } else if (const auto *V = dyn_cast<VarDecl>(D)) { | |||
2807 | QualType Ty = V->getType(); | |||
2808 | if (Ty->isBlockPointerType() || Ty->isFunctionPointerType()) { | |||
2809 | const FunctionType *FT = Ty->isFunctionPointerType() | |||
2810 | ? D->getFunctionType() | |||
2811 | : Ty->getAs<BlockPointerType>()->getPointeeType()->getAs<FunctionType>(); | |||
2812 | if (!cast<FunctionProtoType>(FT)->isVariadic()) { | |||
2813 | int m = Ty->isFunctionPointerType() ? 0 : 1; | |||
2814 | S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << m; | |||
2815 | return; | |||
2816 | } | |||
2817 | } else { | |||
2818 | S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type) | |||
2819 | << AL << ExpectedFunctionMethodOrBlock; | |||
2820 | return; | |||
2821 | } | |||
2822 | } else { | |||
2823 | S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type) | |||
2824 | << AL << ExpectedFunctionMethodOrBlock; | |||
2825 | return; | |||
2826 | } | |||
2827 | D->addAttr(::new (S.Context) | |||
2828 | SentinelAttr(AL.getRange(), S.Context, sentinel, nullPos, | |||
2829 | AL.getAttributeSpellingListIndex())); | |||
2830 | } | |||
2831 | ||||
2832 | static void handleWarnUnusedResult(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2833 | if (D->getFunctionType() && | |||
2834 | D->getFunctionType()->getReturnType()->isVoidType()) { | |||
2835 | S.Diag(AL.getLoc(), diag::warn_attribute_void_function_method) << AL << 0; | |||
2836 | return; | |||
2837 | } | |||
2838 | if (const auto *MD = dyn_cast<ObjCMethodDecl>(D)) | |||
2839 | if (MD->getReturnType()->isVoidType()) { | |||
2840 | S.Diag(AL.getLoc(), diag::warn_attribute_void_function_method) << AL << 1; | |||
2841 | return; | |||
2842 | } | |||
2843 | ||||
2844 | // If this is spelled as the standard C++17 attribute, but not in C++17, warn | |||
2845 | // about using it as an extension. | |||
2846 | if (!S.getLangOpts().CPlusPlus17 && AL.isCXX11Attribute() && | |||
2847 | !AL.getScopeName()) | |||
2848 | S.Diag(AL.getLoc(), diag::ext_cxx17_attr) << AL; | |||
2849 | ||||
2850 | D->addAttr(::new (S.Context) | |||
2851 | WarnUnusedResultAttr(AL.getRange(), S.Context, | |||
2852 | AL.getAttributeSpellingListIndex())); | |||
2853 | } | |||
2854 | ||||
2855 | static void handleWeakImportAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2856 | // weak_import only applies to variable & function declarations. | |||
2857 | bool isDef = false; | |||
2858 | if (!D->canBeWeakImported(isDef)) { | |||
2859 | if (isDef) | |||
2860 | S.Diag(AL.getLoc(), diag::warn_attribute_invalid_on_definition) | |||
2861 | << "weak_import"; | |||
2862 | else if (isa<ObjCPropertyDecl>(D) || isa<ObjCMethodDecl>(D) || | |||
2863 | (S.Context.getTargetInfo().getTriple().isOSDarwin() && | |||
2864 | (isa<ObjCInterfaceDecl>(D) || isa<EnumDecl>(D)))) { | |||
2865 | // Nothing to warn about here. | |||
2866 | } else | |||
2867 | S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type) | |||
2868 | << AL << ExpectedVariableOrFunction; | |||
2869 | ||||
2870 | return; | |||
2871 | } | |||
2872 | ||||
2873 | D->addAttr(::new (S.Context) | |||
2874 | WeakImportAttr(AL.getRange(), S.Context, | |||
2875 | AL.getAttributeSpellingListIndex())); | |||
2876 | } | |||
2877 | ||||
2878 | // Handles reqd_work_group_size and work_group_size_hint. | |||
2879 | template <typename WorkGroupAttr> | |||
2880 | static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2881 | uint32_t WGSize[3]; | |||
2882 | for (unsigned i = 0; i < 3; ++i) { | |||
2883 | const Expr *E = AL.getArgAsExpr(i); | |||
2884 | if (!checkUInt32Argument(S, AL, E, WGSize[i], i, | |||
2885 | /*StrictlyUnsigned=*/true)) | |||
2886 | return; | |||
2887 | if (WGSize[i] == 0) { | |||
2888 | S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero) | |||
2889 | << AL << E->getSourceRange(); | |||
2890 | return; | |||
2891 | } | |||
2892 | } | |||
2893 | ||||
2894 | WorkGroupAttr *Existing = D->getAttr<WorkGroupAttr>(); | |||
2895 | if (Existing && !(Existing->getXDim() == WGSize[0] && | |||
2896 | Existing->getYDim() == WGSize[1] && | |||
2897 | Existing->getZDim() == WGSize[2])) | |||
2898 | S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL; | |||
2899 | ||||
2900 | D->addAttr(::new (S.Context) WorkGroupAttr(AL.getRange(), S.Context, | |||
2901 | WGSize[0], WGSize[1], WGSize[2], | |||
2902 | AL.getAttributeSpellingListIndex())); | |||
2903 | } | |||
2904 | ||||
2905 | // Handles intel_reqd_sub_group_size. | |||
2906 | static void handleSubGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2907 | uint32_t SGSize; | |||
2908 | const Expr *E = AL.getArgAsExpr(0); | |||
2909 | if (!checkUInt32Argument(S, AL, E, SGSize)) | |||
2910 | return; | |||
2911 | if (SGSize == 0) { | |||
2912 | S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero) | |||
2913 | << AL << E->getSourceRange(); | |||
2914 | return; | |||
2915 | } | |||
2916 | ||||
2917 | OpenCLIntelReqdSubGroupSizeAttr *Existing = | |||
2918 | D->getAttr<OpenCLIntelReqdSubGroupSizeAttr>(); | |||
2919 | if (Existing && Existing->getSubGroupSize() != SGSize) | |||
2920 | S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL; | |||
2921 | ||||
2922 | D->addAttr(::new (S.Context) OpenCLIntelReqdSubGroupSizeAttr( | |||
2923 | AL.getRange(), S.Context, SGSize, | |||
2924 | AL.getAttributeSpellingListIndex())); | |||
2925 | } | |||
2926 | ||||
2927 | static void handleVecTypeHint(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2928 | if (!AL.hasParsedType()) { | |||
2929 | S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; | |||
2930 | return; | |||
2931 | } | |||
2932 | ||||
2933 | TypeSourceInfo *ParmTSI = nullptr; | |||
2934 | QualType ParmType = S.GetTypeFromParser(AL.getTypeArg(), &ParmTSI); | |||
2935 | assert(ParmTSI && "no type source info for attribute argument")((ParmTSI && "no type source info for attribute argument" ) ? static_cast<void> (0) : __assert_fail ("ParmTSI && \"no type source info for attribute argument\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 2935, __PRETTY_FUNCTION__)); | |||
2936 | ||||
2937 | if (!ParmType->isExtVectorType() && !ParmType->isFloatingType() && | |||
2938 | (ParmType->isBooleanType() || | |||
2939 | !ParmType->isIntegralType(S.getASTContext()))) { | |||
2940 | S.Diag(AL.getLoc(), diag::err_attribute_argument_vec_type_hint) | |||
2941 | << ParmType; | |||
2942 | return; | |||
2943 | } | |||
2944 | ||||
2945 | if (VecTypeHintAttr *A = D->getAttr<VecTypeHintAttr>()) { | |||
2946 | if (!S.Context.hasSameType(A->getTypeHint(), ParmType)) { | |||
2947 | S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL; | |||
2948 | return; | |||
2949 | } | |||
2950 | } | |||
2951 | ||||
2952 | D->addAttr(::new (S.Context) VecTypeHintAttr(AL.getLoc(), S.Context, | |||
2953 | ParmTSI, | |||
2954 | AL.getAttributeSpellingListIndex())); | |||
2955 | } | |||
2956 | ||||
2957 | SectionAttr *Sema::mergeSectionAttr(Decl *D, SourceRange Range, | |||
2958 | StringRef Name, | |||
2959 | unsigned AttrSpellingListIndex) { | |||
2960 | // Explicit or partial specializations do not inherit | |||
2961 | // the section attribute from the primary template. | |||
2962 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) { | |||
2963 | if (AttrSpellingListIndex == SectionAttr::Declspec_allocate && | |||
2964 | FD->isFunctionTemplateSpecialization()) | |||
2965 | return nullptr; | |||
2966 | } | |||
2967 | if (SectionAttr *ExistingAttr = D->getAttr<SectionAttr>()) { | |||
2968 | if (ExistingAttr->getName() == Name) | |||
2969 | return nullptr; | |||
2970 | Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section) | |||
2971 | << 1 /*section*/; | |||
2972 | Diag(Range.getBegin(), diag::note_previous_attribute); | |||
2973 | return nullptr; | |||
2974 | } | |||
2975 | return ::new (Context) SectionAttr(Range, Context, Name, | |||
2976 | AttrSpellingListIndex); | |||
2977 | } | |||
2978 | ||||
2979 | bool Sema::checkSectionName(SourceLocation LiteralLoc, StringRef SecName) { | |||
2980 | std::string Error = Context.getTargetInfo().isValidSectionSpecifier(SecName); | |||
2981 | if (!Error.empty()) { | |||
2982 | Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target) << Error | |||
2983 | << 1 /*'section'*/; | |||
2984 | return false; | |||
2985 | } | |||
2986 | return true; | |||
2987 | } | |||
2988 | ||||
2989 | static void handleSectionAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
2990 | // Make sure that there is a string literal as the sections's single | |||
2991 | // argument. | |||
2992 | StringRef Str; | |||
2993 | SourceLocation LiteralLoc; | |||
2994 | if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc)) | |||
2995 | return; | |||
2996 | ||||
2997 | if (!S.checkSectionName(LiteralLoc, Str)) | |||
2998 | return; | |||
2999 | ||||
3000 | // If the target wants to validate the section specifier, make it happen. | |||
3001 | std::string Error = S.Context.getTargetInfo().isValidSectionSpecifier(Str); | |||
3002 | if (!Error.empty()) { | |||
3003 | S.Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target) | |||
3004 | << Error; | |||
3005 | return; | |||
3006 | } | |||
3007 | ||||
3008 | unsigned Index = AL.getAttributeSpellingListIndex(); | |||
3009 | SectionAttr *NewAttr = S.mergeSectionAttr(D, AL.getRange(), Str, Index); | |||
3010 | if (NewAttr) | |||
3011 | D->addAttr(NewAttr); | |||
3012 | } | |||
3013 | ||||
3014 | static bool checkCodeSegName(Sema&S, SourceLocation LiteralLoc, StringRef CodeSegName) { | |||
3015 | std::string Error = S.Context.getTargetInfo().isValidSectionSpecifier(CodeSegName); | |||
3016 | if (!Error.empty()) { | |||
3017 | S.Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target) << Error | |||
3018 | << 0 /*'code-seg'*/; | |||
3019 | return false; | |||
3020 | } | |||
3021 | return true; | |||
3022 | } | |||
3023 | ||||
3024 | CodeSegAttr *Sema::mergeCodeSegAttr(Decl *D, SourceRange Range, | |||
3025 | StringRef Name, | |||
3026 | unsigned AttrSpellingListIndex) { | |||
3027 | // Explicit or partial specializations do not inherit | |||
3028 | // the code_seg attribute from the primary template. | |||
3029 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) { | |||
3030 | if (FD->isFunctionTemplateSpecialization()) | |||
3031 | return nullptr; | |||
3032 | } | |||
3033 | if (const auto *ExistingAttr = D->getAttr<CodeSegAttr>()) { | |||
3034 | if (ExistingAttr->getName() == Name) | |||
3035 | return nullptr; | |||
3036 | Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section) | |||
3037 | << 0 /*codeseg*/; | |||
3038 | Diag(Range.getBegin(), diag::note_previous_attribute); | |||
3039 | return nullptr; | |||
3040 | } | |||
3041 | return ::new (Context) CodeSegAttr(Range, Context, Name, | |||
3042 | AttrSpellingListIndex); | |||
3043 | } | |||
3044 | ||||
3045 | static void handleCodeSegAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
3046 | StringRef Str; | |||
3047 | SourceLocation LiteralLoc; | |||
3048 | if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc)) | |||
3049 | return; | |||
3050 | if (!checkCodeSegName(S, LiteralLoc, Str)) | |||
3051 | return; | |||
3052 | if (const auto *ExistingAttr = D->getAttr<CodeSegAttr>()) { | |||
3053 | if (!ExistingAttr->isImplicit()) { | |||
3054 | S.Diag(AL.getLoc(), | |||
3055 | ExistingAttr->getName() == Str | |||
3056 | ? diag::warn_duplicate_codeseg_attribute | |||
3057 | : diag::err_conflicting_codeseg_attribute); | |||
3058 | return; | |||
3059 | } | |||
3060 | D->dropAttr<CodeSegAttr>(); | |||
3061 | } | |||
3062 | if (CodeSegAttr *CSA = S.mergeCodeSegAttr(D, AL.getRange(), Str, | |||
3063 | AL.getAttributeSpellingListIndex())) | |||
3064 | D->addAttr(CSA); | |||
3065 | } | |||
3066 | ||||
3067 | // Check for things we'd like to warn about. Multiversioning issues are | |||
3068 | // handled later in the process, once we know how many exist. | |||
3069 | bool Sema::checkTargetAttr(SourceLocation LiteralLoc, StringRef AttrStr) { | |||
3070 | enum FirstParam { Unsupported, Duplicate }; | |||
3071 | enum SecondParam { None, Architecture }; | |||
3072 | for (auto Str : {"tune=", "fpmath="}) | |||
3073 | if (AttrStr.find(Str) != StringRef::npos) | |||
3074 | return Diag(LiteralLoc, diag::warn_unsupported_target_attribute) | |||
3075 | << Unsupported << None << Str; | |||
3076 | ||||
3077 | TargetAttr::ParsedTargetAttr ParsedAttrs = TargetAttr::parse(AttrStr); | |||
3078 | ||||
3079 | if (!ParsedAttrs.Architecture.empty() && | |||
3080 | !Context.getTargetInfo().isValidCPUName(ParsedAttrs.Architecture)) | |||
3081 | return Diag(LiteralLoc, diag::warn_unsupported_target_attribute) | |||
3082 | << Unsupported << Architecture << ParsedAttrs.Architecture; | |||
3083 | ||||
3084 | if (ParsedAttrs.DuplicateArchitecture) | |||
3085 | return Diag(LiteralLoc, diag::warn_unsupported_target_attribute) | |||
3086 | << Duplicate << None << "arch="; | |||
3087 | ||||
3088 | for (const auto &Feature : ParsedAttrs.Features) { | |||
3089 | auto CurFeature = StringRef(Feature).drop_front(); // remove + or -. | |||
3090 | if (!Context.getTargetInfo().isValidFeatureName(CurFeature)) | |||
3091 | return Diag(LiteralLoc, diag::warn_unsupported_target_attribute) | |||
3092 | << Unsupported << None << CurFeature; | |||
3093 | } | |||
3094 | ||||
3095 | return false; | |||
3096 | } | |||
3097 | ||||
3098 | static void handleTargetAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
3099 | StringRef Str; | |||
3100 | SourceLocation LiteralLoc; | |||
3101 | if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc) || | |||
3102 | S.checkTargetAttr(LiteralLoc, Str)) | |||
3103 | return; | |||
3104 | ||||
3105 | unsigned Index = AL.getAttributeSpellingListIndex(); | |||
3106 | TargetAttr *NewAttr = | |||
3107 | ::new (S.Context) TargetAttr(AL.getRange(), S.Context, Str, Index); | |||
3108 | D->addAttr(NewAttr); | |||
3109 | } | |||
3110 | ||||
3111 | static void handleMinVectorWidthAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
3112 | Expr *E = AL.getArgAsExpr(0); | |||
3113 | uint32_t VecWidth; | |||
3114 | if (!checkUInt32Argument(S, AL, E, VecWidth)) { | |||
3115 | AL.setInvalid(); | |||
3116 | return; | |||
3117 | } | |||
3118 | ||||
3119 | MinVectorWidthAttr *Existing = D->getAttr<MinVectorWidthAttr>(); | |||
3120 | if (Existing && Existing->getVectorWidth() != VecWidth) { | |||
3121 | S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL; | |||
3122 | return; | |||
3123 | } | |||
3124 | ||||
3125 | D->addAttr(::new (S.Context) | |||
3126 | MinVectorWidthAttr(AL.getRange(), S.Context, VecWidth, | |||
3127 | AL.getAttributeSpellingListIndex())); | |||
3128 | } | |||
3129 | ||||
3130 | static void handleCleanupAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
3131 | Expr *E = AL.getArgAsExpr(0); | |||
3132 | SourceLocation Loc = E->getExprLoc(); | |||
3133 | FunctionDecl *FD = nullptr; | |||
3134 | DeclarationNameInfo NI; | |||
3135 | ||||
3136 | // gcc only allows for simple identifiers. Since we support more than gcc, we | |||
3137 | // will warn the user. | |||
3138 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) { | |||
3139 | if (DRE->hasQualifier()) | |||
3140 | S.Diag(Loc, diag::warn_cleanup_ext); | |||
3141 | FD = dyn_cast<FunctionDecl>(DRE->getDecl()); | |||
3142 | NI = DRE->getNameInfo(); | |||
3143 | if (!FD) { | |||
3144 | S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 1 | |||
3145 | << NI.getName(); | |||
3146 | return; | |||
3147 | } | |||
3148 | } else if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(E)) { | |||
3149 | if (ULE->hasExplicitTemplateArgs()) | |||
3150 | S.Diag(Loc, diag::warn_cleanup_ext); | |||
3151 | FD = S.ResolveSingleFunctionTemplateSpecialization(ULE, true); | |||
3152 | NI = ULE->getNameInfo(); | |||
3153 | if (!FD) { | |||
3154 | S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 2 | |||
3155 | << NI.getName(); | |||
3156 | if (ULE->getType() == S.Context.OverloadTy) | |||
3157 | S.NoteAllOverloadCandidates(ULE); | |||
3158 | return; | |||
3159 | } | |||
3160 | } else { | |||
3161 | S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 0; | |||
3162 | return; | |||
3163 | } | |||
3164 | ||||
3165 | if (FD->getNumParams() != 1) { | |||
3166 | S.Diag(Loc, diag::err_attribute_cleanup_func_must_take_one_arg) | |||
3167 | << NI.getName(); | |||
3168 | return; | |||
3169 | } | |||
3170 | ||||
3171 | // We're currently more strict than GCC about what function types we accept. | |||
3172 | // If this ever proves to be a problem it should be easy to fix. | |||
3173 | QualType Ty = S.Context.getPointerType(cast<VarDecl>(D)->getType()); | |||
3174 | QualType ParamTy = FD->getParamDecl(0)->getType(); | |||
3175 | if (S.CheckAssignmentConstraints(FD->getParamDecl(0)->getLocation(), | |||
3176 | ParamTy, Ty) != Sema::Compatible) { | |||
3177 | S.Diag(Loc, diag::err_attribute_cleanup_func_arg_incompatible_type) | |||
3178 | << NI.getName() << ParamTy << Ty; | |||
3179 | return; | |||
3180 | } | |||
3181 | ||||
3182 | D->addAttr(::new (S.Context) | |||
3183 | CleanupAttr(AL.getRange(), S.Context, FD, | |||
3184 | AL.getAttributeSpellingListIndex())); | |||
3185 | } | |||
3186 | ||||
3187 | static void handleEnumExtensibilityAttr(Sema &S, Decl *D, | |||
3188 | const ParsedAttr &AL) { | |||
3189 | if (!AL.isArgIdent(0)) { | |||
3190 | S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) | |||
3191 | << AL << 0 << AANT_ArgumentIdentifier; | |||
3192 | return; | |||
3193 | } | |||
3194 | ||||
3195 | EnumExtensibilityAttr::Kind ExtensibilityKind; | |||
3196 | IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; | |||
3197 | if (!EnumExtensibilityAttr::ConvertStrToKind(II->getName(), | |||
3198 | ExtensibilityKind)) { | |||
3199 | S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II; | |||
3200 | return; | |||
3201 | } | |||
3202 | ||||
3203 | D->addAttr(::new (S.Context) EnumExtensibilityAttr( | |||
3204 | AL.getRange(), S.Context, ExtensibilityKind, | |||
3205 | AL.getAttributeSpellingListIndex())); | |||
3206 | } | |||
3207 | ||||
3208 | /// Handle __attribute__((format_arg((idx)))) attribute based on | |||
3209 | /// http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html | |||
3210 | static void handleFormatArgAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
3211 | Expr *IdxExpr = AL.getArgAsExpr(0); | |||
3212 | ParamIdx Idx; | |||
3213 | if (!checkFunctionOrMethodParameterIndex(S, D, AL, 1, IdxExpr, Idx)) | |||
3214 | return; | |||
3215 | ||||
3216 | // Make sure the format string is really a string. | |||
3217 | QualType Ty = getFunctionOrMethodParamType(D, Idx.getASTIndex()); | |||
3218 | ||||
3219 | bool NotNSStringTy = !isNSStringType(Ty, S.Context); | |||
3220 | if (NotNSStringTy && | |||
3221 | !isCFStringType(Ty, S.Context) && | |||
3222 | (!Ty->isPointerType() || | |||
3223 | !Ty->getAs<PointerType>()->getPointeeType()->isCharType())) { | |||
3224 | S.Diag(AL.getLoc(), diag::err_format_attribute_not) | |||
3225 | << "a string type" << IdxExpr->getSourceRange() | |||
3226 | << getFunctionOrMethodParamRange(D, 0); | |||
3227 | return; | |||
3228 | } | |||
3229 | Ty = getFunctionOrMethodResultType(D); | |||
3230 | if (!isNSStringType(Ty, S.Context) && | |||
3231 | !isCFStringType(Ty, S.Context) && | |||
3232 | (!Ty->isPointerType() || | |||
3233 | !Ty->getAs<PointerType>()->getPointeeType()->isCharType())) { | |||
3234 | S.Diag(AL.getLoc(), diag::err_format_attribute_result_not) | |||
3235 | << (NotNSStringTy ? "string type" : "NSString") | |||
3236 | << IdxExpr->getSourceRange() << getFunctionOrMethodParamRange(D, 0); | |||
3237 | return; | |||
3238 | } | |||
3239 | ||||
3240 | D->addAttr(::new (S.Context) FormatArgAttr( | |||
3241 | AL.getRange(), S.Context, Idx, AL.getAttributeSpellingListIndex())); | |||
3242 | } | |||
3243 | ||||
3244 | enum FormatAttrKind { | |||
3245 | CFStringFormat, | |||
3246 | NSStringFormat, | |||
3247 | StrftimeFormat, | |||
3248 | SupportedFormat, | |||
3249 | IgnoredFormat, | |||
3250 | InvalidFormat | |||
3251 | }; | |||
3252 | ||||
3253 | /// getFormatAttrKind - Map from format attribute names to supported format | |||
3254 | /// types. | |||
3255 | static FormatAttrKind getFormatAttrKind(StringRef Format) { | |||
3256 | return llvm::StringSwitch<FormatAttrKind>(Format) | |||
3257 | // Check for formats that get handled specially. | |||
3258 | .Case("NSString", NSStringFormat) | |||
3259 | .Case("CFString", CFStringFormat) | |||
3260 | .Case("strftime", StrftimeFormat) | |||
3261 | ||||
3262 | // Otherwise, check for supported formats. | |||
3263 | .Cases("scanf", "printf", "printf0", "strfmon", SupportedFormat) | |||
3264 | .Cases("cmn_err", "vcmn_err", "zcmn_err", SupportedFormat) | |||
3265 | .Case("kprintf", SupportedFormat) // OpenBSD. | |||
3266 | .Case("freebsd_kprintf", SupportedFormat) // FreeBSD. | |||
3267 | .Case("os_trace", SupportedFormat) | |||
3268 | .Case("os_log", SupportedFormat) | |||
3269 | ||||
3270 | .Cases("gcc_diag", "gcc_cdiag", "gcc_cxxdiag", "gcc_tdiag", IgnoredFormat) | |||
3271 | .Default(InvalidFormat); | |||
3272 | } | |||
3273 | ||||
3274 | /// Handle __attribute__((init_priority(priority))) attributes based on | |||
3275 | /// http://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html | |||
3276 | static void handleInitPriorityAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
3277 | if (!S.getLangOpts().CPlusPlus) { | |||
3278 | S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL; | |||
3279 | return; | |||
3280 | } | |||
3281 | ||||
3282 | if (S.getCurFunctionOrMethodDecl()) { | |||
3283 | S.Diag(AL.getLoc(), diag::err_init_priority_object_attr); | |||
3284 | AL.setInvalid(); | |||
3285 | return; | |||
3286 | } | |||
3287 | QualType T = cast<VarDecl>(D)->getType(); | |||
3288 | if (S.Context.getAsArrayType(T)) | |||
3289 | T = S.Context.getBaseElementType(T); | |||
3290 | if (!T->getAs<RecordType>()) { | |||
3291 | S.Diag(AL.getLoc(), diag::err_init_priority_object_attr); | |||
3292 | AL.setInvalid(); | |||
3293 | return; | |||
3294 | } | |||
3295 | ||||
3296 | Expr *E = AL.getArgAsExpr(0); | |||
3297 | uint32_t prioritynum; | |||
3298 | if (!checkUInt32Argument(S, AL, E, prioritynum)) { | |||
3299 | AL.setInvalid(); | |||
3300 | return; | |||
3301 | } | |||
3302 | ||||
3303 | if (prioritynum < 101 || prioritynum > 65535) { | |||
3304 | S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_range) | |||
3305 | << E->getSourceRange() << AL << 101 << 65535; | |||
3306 | AL.setInvalid(); | |||
3307 | return; | |||
3308 | } | |||
3309 | D->addAttr(::new (S.Context) | |||
3310 | InitPriorityAttr(AL.getRange(), S.Context, prioritynum, | |||
3311 | AL.getAttributeSpellingListIndex())); | |||
3312 | } | |||
3313 | ||||
3314 | FormatAttr *Sema::mergeFormatAttr(Decl *D, SourceRange Range, | |||
3315 | IdentifierInfo *Format, int FormatIdx, | |||
3316 | int FirstArg, | |||
3317 | unsigned AttrSpellingListIndex) { | |||
3318 | // Check whether we already have an equivalent format attribute. | |||
3319 | for (auto *F : D->specific_attrs<FormatAttr>()) { | |||
3320 | if (F->getType() == Format && | |||
3321 | F->getFormatIdx() == FormatIdx && | |||
3322 | F->getFirstArg() == FirstArg) { | |||
3323 | // If we don't have a valid location for this attribute, adopt the | |||
3324 | // location. | |||
3325 | if (F->getLocation().isInvalid()) | |||
3326 | F->setRange(Range); | |||
3327 | return nullptr; | |||
3328 | } | |||
3329 | } | |||
3330 | ||||
3331 | return ::new (Context) FormatAttr(Range, Context, Format, FormatIdx, | |||
3332 | FirstArg, AttrSpellingListIndex); | |||
3333 | } | |||
3334 | ||||
3335 | /// Handle __attribute__((format(type,idx,firstarg))) attributes based on | |||
3336 | /// http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html | |||
3337 | static void handleFormatAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
3338 | if (!AL.isArgIdent(0)) { | |||
3339 | S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) | |||
3340 | << AL << 1 << AANT_ArgumentIdentifier; | |||
3341 | return; | |||
3342 | } | |||
3343 | ||||
3344 | // In C++ the implicit 'this' function parameter also counts, and they are | |||
3345 | // counted from one. | |||
3346 | bool HasImplicitThisParam = isInstanceMethod(D); | |||
3347 | unsigned NumArgs = getFunctionOrMethodNumParams(D) + HasImplicitThisParam; | |||
3348 | ||||
3349 | IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; | |||
3350 | StringRef Format = II->getName(); | |||
3351 | ||||
3352 | if (normalizeName(Format)) { | |||
3353 | // If we've modified the string name, we need a new identifier for it. | |||
3354 | II = &S.Context.Idents.get(Format); | |||
3355 | } | |||
3356 | ||||
3357 | // Check for supported formats. | |||
3358 | FormatAttrKind Kind = getFormatAttrKind(Format); | |||
3359 | ||||
3360 | if (Kind == IgnoredFormat) | |||
3361 | return; | |||
3362 | ||||
3363 | if (Kind == InvalidFormat) { | |||
3364 | S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) | |||
3365 | << AL << II->getName(); | |||
3366 | return; | |||
3367 | } | |||
3368 | ||||
3369 | // checks for the 2nd argument | |||
3370 | Expr *IdxExpr = AL.getArgAsExpr(1); | |||
3371 | uint32_t Idx; | |||
3372 | if (!checkUInt32Argument(S, AL, IdxExpr, Idx, 2)) | |||
3373 | return; | |||
3374 | ||||
3375 | if (Idx < 1 || Idx > NumArgs) { | |||
3376 | S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds) | |||
3377 | << AL << 2 << IdxExpr->getSourceRange(); | |||
3378 | return; | |||
3379 | } | |||
3380 | ||||
3381 | // FIXME: Do we need to bounds check? | |||
3382 | unsigned ArgIdx = Idx - 1; | |||
3383 | ||||
3384 | if (HasImplicitThisParam) { | |||
3385 | if (ArgIdx == 0) { | |||
3386 | S.Diag(AL.getLoc(), | |||
3387 | diag::err_format_attribute_implicit_this_format_string) | |||
3388 | << IdxExpr->getSourceRange(); | |||
3389 | return; | |||
3390 | } | |||
3391 | ArgIdx--; | |||
3392 | } | |||
3393 | ||||
3394 | // make sure the format string is really a string | |||
3395 | QualType Ty = getFunctionOrMethodParamType(D, ArgIdx); | |||
3396 | ||||
3397 | if (Kind == CFStringFormat) { | |||
3398 | if (!isCFStringType(Ty, S.Context)) { | |||
3399 | S.Diag(AL.getLoc(), diag::err_format_attribute_not) | |||
3400 | << "a CFString" << IdxExpr->getSourceRange() | |||
3401 | << getFunctionOrMethodParamRange(D, ArgIdx); | |||
3402 | return; | |||
3403 | } | |||
3404 | } else if (Kind == NSStringFormat) { | |||
3405 | // FIXME: do we need to check if the type is NSString*? What are the | |||
3406 | // semantics? | |||
3407 | if (!isNSStringType(Ty, S.Context)) { | |||
3408 | S.Diag(AL.getLoc(), diag::err_format_attribute_not) | |||
3409 | << "an NSString" << IdxExpr->getSourceRange() | |||
3410 | << getFunctionOrMethodParamRange(D, ArgIdx); | |||
3411 | return; | |||
3412 | } | |||
3413 | } else if (!Ty->isPointerType() || | |||
3414 | !Ty->getAs<PointerType>()->getPointeeType()->isCharType()) { | |||
3415 | S.Diag(AL.getLoc(), diag::err_format_attribute_not) | |||
3416 | << "a string type" << IdxExpr->getSourceRange() | |||
3417 | << getFunctionOrMethodParamRange(D, ArgIdx); | |||
3418 | return; | |||
3419 | } | |||
3420 | ||||
3421 | // check the 3rd argument | |||
3422 | Expr *FirstArgExpr = AL.getArgAsExpr(2); | |||
3423 | uint32_t FirstArg; | |||
3424 | if (!checkUInt32Argument(S, AL, FirstArgExpr, FirstArg, 3)) | |||
3425 | return; | |||
3426 | ||||
3427 | // check if the function is variadic if the 3rd argument non-zero | |||
3428 | if (FirstArg != 0) { | |||
3429 | if (isFunctionOrMethodVariadic(D)) { | |||
3430 | ++NumArgs; // +1 for ... | |||
3431 | } else { | |||
3432 | S.Diag(D->getLocation(), diag::err_format_attribute_requires_variadic); | |||
3433 | return; | |||
3434 | } | |||
3435 | } | |||
3436 | ||||
3437 | // strftime requires FirstArg to be 0 because it doesn't read from any | |||
3438 | // variable the input is just the current time + the format string. | |||
3439 | if (Kind == StrftimeFormat) { | |||
3440 | if (FirstArg != 0) { | |||
3441 | S.Diag(AL.getLoc(), diag::err_format_strftime_third_parameter) | |||
3442 | << FirstArgExpr->getSourceRange(); | |||
3443 | return; | |||
3444 | } | |||
3445 | // if 0 it disables parameter checking (to use with e.g. va_list) | |||
3446 | } else if (FirstArg != 0 && FirstArg != NumArgs) { | |||
3447 | S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds) | |||
3448 | << AL << 3 << FirstArgExpr->getSourceRange(); | |||
3449 | return; | |||
3450 | } | |||
3451 | ||||
3452 | FormatAttr *NewAttr = S.mergeFormatAttr(D, AL.getRange(), II, | |||
3453 | Idx, FirstArg, | |||
3454 | AL.getAttributeSpellingListIndex()); | |||
3455 | if (NewAttr) | |||
3456 | D->addAttr(NewAttr); | |||
3457 | } | |||
3458 | ||||
3459 | /// Handle __attribute__((callback(CalleeIdx, PayloadIdx0, ...))) attributes. | |||
3460 | static void handleCallbackAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
3461 | // The index that identifies the callback callee is mandatory. | |||
3462 | if (AL.getNumArgs() == 0) { | |||
3463 | S.Diag(AL.getLoc(), diag::err_callback_attribute_no_callee) | |||
3464 | << AL.getRange(); | |||
3465 | return; | |||
3466 | } | |||
3467 | ||||
3468 | bool HasImplicitThisParam = isInstanceMethod(D); | |||
3469 | int32_t NumArgs = getFunctionOrMethodNumParams(D); | |||
3470 | ||||
3471 | FunctionDecl *FD = D->getAsFunction(); | |||
3472 | assert(FD && "Expected a function declaration!")((FD && "Expected a function declaration!") ? static_cast <void> (0) : __assert_fail ("FD && \"Expected a function declaration!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 3472, __PRETTY_FUNCTION__)); | |||
3473 | ||||
3474 | llvm::StringMap<int> NameIdxMapping; | |||
3475 | NameIdxMapping["__"] = -1; | |||
3476 | ||||
3477 | NameIdxMapping["this"] = 0; | |||
3478 | ||||
3479 | int Idx = 1; | |||
3480 | for (const ParmVarDecl *PVD : FD->parameters()) | |||
3481 | NameIdxMapping[PVD->getName()] = Idx++; | |||
3482 | ||||
3483 | auto UnknownName = NameIdxMapping.end(); | |||
3484 | ||||
3485 | SmallVector<int, 8> EncodingIndices; | |||
3486 | for (unsigned I = 0, E = AL.getNumArgs(); I < E; ++I) { | |||
3487 | SourceRange SR; | |||
3488 | int32_t ArgIdx; | |||
3489 | ||||
3490 | if (AL.isArgIdent(I)) { | |||
3491 | IdentifierLoc *IdLoc = AL.getArgAsIdent(I); | |||
3492 | auto It = NameIdxMapping.find(IdLoc->Ident->getName()); | |||
3493 | if (It == UnknownName) { | |||
3494 | S.Diag(AL.getLoc(), diag::err_callback_attribute_argument_unknown) | |||
3495 | << IdLoc->Ident << IdLoc->Loc; | |||
3496 | return; | |||
3497 | } | |||
3498 | ||||
3499 | SR = SourceRange(IdLoc->Loc); | |||
3500 | ArgIdx = It->second; | |||
3501 | } else if (AL.isArgExpr(I)) { | |||
3502 | Expr *IdxExpr = AL.getArgAsExpr(I); | |||
3503 | ||||
3504 | // If the expression is not parseable as an int32_t we have a problem. | |||
3505 | if (!checkUInt32Argument(S, AL, IdxExpr, (uint32_t &)ArgIdx, I + 1, | |||
3506 | false)) { | |||
3507 | S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds) | |||
3508 | << AL << (I + 1) << IdxExpr->getSourceRange(); | |||
3509 | return; | |||
3510 | } | |||
3511 | ||||
3512 | // Check oob, excluding the special values, 0 and -1. | |||
3513 | if (ArgIdx < -1 || ArgIdx > NumArgs) { | |||
3514 | S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds) | |||
3515 | << AL << (I + 1) << IdxExpr->getSourceRange(); | |||
3516 | return; | |||
3517 | } | |||
3518 | ||||
3519 | SR = IdxExpr->getSourceRange(); | |||
3520 | } else { | |||
3521 | llvm_unreachable("Unexpected ParsedAttr argument type!")::llvm::llvm_unreachable_internal("Unexpected ParsedAttr argument type!" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 3521); | |||
3522 | } | |||
3523 | ||||
3524 | if (ArgIdx == 0 && !HasImplicitThisParam) { | |||
3525 | S.Diag(AL.getLoc(), diag::err_callback_implicit_this_not_available) | |||
3526 | << (I + 1) << SR; | |||
3527 | return; | |||
3528 | } | |||
3529 | ||||
3530 | // Adjust for the case we do not have an implicit "this" parameter. In this | |||
3531 | // case we decrease all positive values by 1 to get LLVM argument indices. | |||
3532 | if (!HasImplicitThisParam && ArgIdx > 0) | |||
3533 | ArgIdx -= 1; | |||
3534 | ||||
3535 | EncodingIndices.push_back(ArgIdx); | |||
3536 | } | |||
3537 | ||||
3538 | int CalleeIdx = EncodingIndices.front(); | |||
3539 | // Check if the callee index is proper, thus not "this" and not "unknown". | |||
3540 | // This means the "CalleeIdx" has to be non-negative if "HasImplicitThisParam" | |||
3541 | // is false and positive if "HasImplicitThisParam" is true. | |||
3542 | if (CalleeIdx < (int)HasImplicitThisParam) { | |||
3543 | S.Diag(AL.getLoc(), diag::err_callback_attribute_invalid_callee) | |||
3544 | << AL.getRange(); | |||
3545 | return; | |||
3546 | } | |||
3547 | ||||
3548 | // Get the callee type, note the index adjustment as the AST doesn't contain | |||
3549 | // the this type (which the callee cannot reference anyway!). | |||
3550 | const Type *CalleeType = | |||
3551 | getFunctionOrMethodParamType(D, CalleeIdx - HasImplicitThisParam) | |||
3552 | .getTypePtr(); | |||
3553 | if (!CalleeType || !CalleeType->isFunctionPointerType()) { | |||
3554 | S.Diag(AL.getLoc(), diag::err_callback_callee_no_function_type) | |||
3555 | << AL.getRange(); | |||
3556 | return; | |||
3557 | } | |||
3558 | ||||
3559 | const Type *CalleeFnType = | |||
3560 | CalleeType->getPointeeType()->getUnqualifiedDesugaredType(); | |||
3561 | ||||
3562 | // TODO: Check the type of the callee arguments. | |||
3563 | ||||
3564 | const auto *CalleeFnProtoType = dyn_cast<FunctionProtoType>(CalleeFnType); | |||
3565 | if (!CalleeFnProtoType) { | |||
3566 | S.Diag(AL.getLoc(), diag::err_callback_callee_no_function_type) | |||
3567 | << AL.getRange(); | |||
3568 | return; | |||
3569 | } | |||
3570 | ||||
3571 | if (CalleeFnProtoType->getNumParams() > EncodingIndices.size() - 1) { | |||
3572 | S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) | |||
3573 | << AL << (unsigned)(EncodingIndices.size() - 1); | |||
3574 | return; | |||
3575 | } | |||
3576 | ||||
3577 | if (CalleeFnProtoType->getNumParams() < EncodingIndices.size() - 1) { | |||
3578 | S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) | |||
3579 | << AL << (unsigned)(EncodingIndices.size() - 1); | |||
3580 | return; | |||
3581 | } | |||
3582 | ||||
3583 | if (CalleeFnProtoType->isVariadic()) { | |||
3584 | S.Diag(AL.getLoc(), diag::err_callback_callee_is_variadic) << AL.getRange(); | |||
3585 | return; | |||
3586 | } | |||
3587 | ||||
3588 | // Do not allow multiple callback attributes. | |||
3589 | if (D->hasAttr<CallbackAttr>()) { | |||
3590 | S.Diag(AL.getLoc(), diag::err_callback_attribute_multiple) << AL.getRange(); | |||
3591 | return; | |||
3592 | } | |||
3593 | ||||
3594 | D->addAttr(::new (S.Context) CallbackAttr( | |||
3595 | AL.getRange(), S.Context, EncodingIndices.data(), EncodingIndices.size(), | |||
3596 | AL.getAttributeSpellingListIndex())); | |||
3597 | } | |||
3598 | ||||
3599 | static void handleTransparentUnionAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
3600 | // Try to find the underlying union declaration. | |||
3601 | RecordDecl *RD = nullptr; | |||
3602 | const auto *TD = dyn_cast<TypedefNameDecl>(D); | |||
3603 | if (TD && TD->getUnderlyingType()->isUnionType()) | |||
3604 | RD = TD->getUnderlyingType()->getAsUnionType()->getDecl(); | |||
3605 | else | |||
3606 | RD = dyn_cast<RecordDecl>(D); | |||
3607 | ||||
3608 | if (!RD || !RD->isUnion()) { | |||
3609 | S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type) << AL | |||
3610 | << ExpectedUnion; | |||
3611 | return; | |||
3612 | } | |||
3613 | ||||
3614 | if (!RD->isCompleteDefinition()) { | |||
3615 | if (!RD->isBeingDefined()) | |||
3616 | S.Diag(AL.getLoc(), | |||
3617 | diag::warn_transparent_union_attribute_not_definition); | |||
3618 | return; | |||
3619 | } | |||
3620 | ||||
3621 | RecordDecl::field_iterator Field = RD->field_begin(), | |||
3622 | FieldEnd = RD->field_end(); | |||
3623 | if (Field == FieldEnd) { | |||
3624 | S.Diag(AL.getLoc(), diag::warn_transparent_union_attribute_zero_fields); | |||
3625 | return; | |||
3626 | } | |||
3627 | ||||
3628 | FieldDecl *FirstField = *Field; | |||
3629 | QualType FirstType = FirstField->getType(); | |||
3630 | if (FirstType->hasFloatingRepresentation() || FirstType->isVectorType()) { | |||
3631 | S.Diag(FirstField->getLocation(), | |||
3632 | diag::warn_transparent_union_attribute_floating) | |||
3633 | << FirstType->isVectorType() << FirstType; | |||
3634 | return; | |||
3635 | } | |||
3636 | ||||
3637 | if (FirstType->isIncompleteType()) | |||
3638 | return; | |||
3639 | uint64_t FirstSize = S.Context.getTypeSize(FirstType); | |||
3640 | uint64_t FirstAlign = S.Context.getTypeAlign(FirstType); | |||
3641 | for (; Field != FieldEnd; ++Field) { | |||
3642 | QualType FieldType = Field->getType(); | |||
3643 | if (FieldType->isIncompleteType()) | |||
3644 | return; | |||
3645 | // FIXME: this isn't fully correct; we also need to test whether the | |||
3646 | // members of the union would all have the same calling convention as the | |||
3647 | // first member of the union. Checking just the size and alignment isn't | |||
3648 | // sufficient (consider structs passed on the stack instead of in registers | |||
3649 | // as an example). | |||
3650 | if (S.Context.getTypeSize(FieldType) != FirstSize || | |||
3651 | S.Context.getTypeAlign(FieldType) > FirstAlign) { | |||
3652 | // Warn if we drop the attribute. | |||
3653 | bool isSize = S.Context.getTypeSize(FieldType) != FirstSize; | |||
3654 | unsigned FieldBits = isSize? S.Context.getTypeSize(FieldType) | |||
3655 | : S.Context.getTypeAlign(FieldType); | |||
3656 | S.Diag(Field->getLocation(), | |||
3657 | diag::warn_transparent_union_attribute_field_size_align) | |||
3658 | << isSize << Field->getDeclName() << FieldBits; | |||
3659 | unsigned FirstBits = isSize? FirstSize : FirstAlign; | |||
3660 | S.Diag(FirstField->getLocation(), | |||
3661 | diag::note_transparent_union_first_field_size_align) | |||
3662 | << isSize << FirstBits; | |||
3663 | return; | |||
3664 | } | |||
3665 | } | |||
3666 | ||||
3667 | RD->addAttr(::new (S.Context) | |||
3668 | TransparentUnionAttr(AL.getRange(), S.Context, | |||
3669 | AL.getAttributeSpellingListIndex())); | |||
3670 | } | |||
3671 | ||||
3672 | static void handleAnnotateAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
3673 | // Make sure that there is a string literal as the annotation's single | |||
3674 | // argument. | |||
3675 | StringRef Str; | |||
3676 | if (!S.checkStringLiteralArgumentAttr(AL, 0, Str)) | |||
3677 | return; | |||
3678 | ||||
3679 | // Don't duplicate annotations that are already set. | |||
3680 | for (const auto *I : D->specific_attrs<AnnotateAttr>()) { | |||
3681 | if (I->getAnnotation() == Str) | |||
3682 | return; | |||
3683 | } | |||
3684 | ||||
3685 | D->addAttr(::new (S.Context) | |||
3686 | AnnotateAttr(AL.getRange(), S.Context, Str, | |||
3687 | AL.getAttributeSpellingListIndex())); | |||
3688 | } | |||
3689 | ||||
3690 | static void handleAlignValueAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
3691 | S.AddAlignValueAttr(AL.getRange(), D, AL.getArgAsExpr(0), | |||
3692 | AL.getAttributeSpellingListIndex()); | |||
3693 | } | |||
3694 | ||||
3695 | void Sema::AddAlignValueAttr(SourceRange AttrRange, Decl *D, Expr *E, | |||
3696 | unsigned SpellingListIndex) { | |||
3697 | AlignValueAttr TmpAttr(AttrRange, Context, E, SpellingListIndex); | |||
3698 | SourceLocation AttrLoc = AttrRange.getBegin(); | |||
3699 | ||||
3700 | QualType T; | |||
3701 | if (const auto *TD = dyn_cast<TypedefNameDecl>(D)) | |||
3702 | T = TD->getUnderlyingType(); | |||
3703 | else if (const auto *VD = dyn_cast<ValueDecl>(D)) | |||
3704 | T = VD->getType(); | |||
3705 | else | |||
3706 | llvm_unreachable("Unknown decl type for align_value")::llvm::llvm_unreachable_internal("Unknown decl type for align_value" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 3706); | |||
3707 | ||||
3708 | if (!T->isDependentType() && !T->isAnyPointerType() && | |||
3709 | !T->isReferenceType() && !T->isMemberPointerType()) { | |||
3710 | Diag(AttrLoc, diag::warn_attribute_pointer_or_reference_only) | |||
3711 | << &TmpAttr /*TmpAttr.getName()*/ << T << D->getSourceRange(); | |||
3712 | return; | |||
3713 | } | |||
3714 | ||||
3715 | if (!E->isValueDependent()) { | |||
3716 | llvm::APSInt Alignment; | |||
3717 | ExprResult ICE | |||
3718 | = VerifyIntegerConstantExpression(E, &Alignment, | |||
3719 | diag::err_align_value_attribute_argument_not_int, | |||
3720 | /*AllowFold*/ false); | |||
3721 | if (ICE.isInvalid()) | |||
3722 | return; | |||
3723 | ||||
3724 | if (!Alignment.isPowerOf2()) { | |||
3725 | Diag(AttrLoc, diag::err_alignment_not_power_of_two) | |||
3726 | << E->getSourceRange(); | |||
3727 | return; | |||
3728 | } | |||
3729 | ||||
3730 | D->addAttr(::new (Context) | |||
3731 | AlignValueAttr(AttrRange, Context, ICE.get(), | |||
3732 | SpellingListIndex)); | |||
3733 | return; | |||
3734 | } | |||
3735 | ||||
3736 | // Save dependent expressions in the AST to be instantiated. | |||
3737 | D->addAttr(::new (Context) AlignValueAttr(TmpAttr)); | |||
3738 | } | |||
3739 | ||||
3740 | static void handleAlignedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
3741 | // check the attribute arguments. | |||
3742 | if (AL.getNumArgs() > 1) { | |||
3743 | S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; | |||
3744 | return; | |||
3745 | } | |||
3746 | ||||
3747 | if (AL.getNumArgs() == 0) { | |||
3748 | D->addAttr(::new (S.Context) AlignedAttr(AL.getRange(), S.Context, | |||
3749 | true, nullptr, AL.getAttributeSpellingListIndex())); | |||
3750 | return; | |||
3751 | } | |||
3752 | ||||
3753 | Expr *E = AL.getArgAsExpr(0); | |||
3754 | if (AL.isPackExpansion() && !E->containsUnexpandedParameterPack()) { | |||
3755 | S.Diag(AL.getEllipsisLoc(), | |||
3756 | diag::err_pack_expansion_without_parameter_packs); | |||
3757 | return; | |||
3758 | } | |||
3759 | ||||
3760 | if (!AL.isPackExpansion() && S.DiagnoseUnexpandedParameterPack(E)) | |||
3761 | return; | |||
3762 | ||||
3763 | S.AddAlignedAttr(AL.getRange(), D, E, AL.getAttributeSpellingListIndex(), | |||
3764 | AL.isPackExpansion()); | |||
3765 | } | |||
3766 | ||||
3767 | void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, | |||
3768 | unsigned SpellingListIndex, bool IsPackExpansion) { | |||
3769 | AlignedAttr TmpAttr(AttrRange, Context, true, E, SpellingListIndex); | |||
3770 | SourceLocation AttrLoc = AttrRange.getBegin(); | |||
3771 | ||||
3772 | // C++11 alignas(...) and C11 _Alignas(...) have additional requirements. | |||
3773 | if (TmpAttr.isAlignas()) { | |||
3774 | // C++11 [dcl.align]p1: | |||
3775 | // An alignment-specifier may be applied to a variable or to a class | |||
3776 | // data member, but it shall not be applied to a bit-field, a function | |||
3777 | // parameter, the formal parameter of a catch clause, or a variable | |||
3778 | // declared with the register storage class specifier. An | |||
3779 | // alignment-specifier may also be applied to the declaration of a class | |||
3780 | // or enumeration type. | |||
3781 | // C11 6.7.5/2: | |||
3782 | // An alignment attribute shall not be specified in a declaration of | |||
3783 | // a typedef, or a bit-field, or a function, or a parameter, or an | |||
3784 | // object declared with the register storage-class specifier. | |||
3785 | int DiagKind = -1; | |||
3786 | if (isa<ParmVarDecl>(D)) { | |||
3787 | DiagKind = 0; | |||
3788 | } else if (const auto *VD = dyn_cast<VarDecl>(D)) { | |||
3789 | if (VD->getStorageClass() == SC_Register) | |||
3790 | DiagKind = 1; | |||
3791 | if (VD->isExceptionVariable()) | |||
3792 | DiagKind = 2; | |||
3793 | } else if (const auto *FD = dyn_cast<FieldDecl>(D)) { | |||
3794 | if (FD->isBitField()) | |||
3795 | DiagKind = 3; | |||
3796 | } else if (!isa<TagDecl>(D)) { | |||
3797 | Diag(AttrLoc, diag::err_attribute_wrong_decl_type) << &TmpAttr | |||
3798 | << (TmpAttr.isC11() ? ExpectedVariableOrField | |||
3799 | : ExpectedVariableFieldOrTag); | |||
3800 | return; | |||
3801 | } | |||
3802 | if (DiagKind != -1) { | |||
3803 | Diag(AttrLoc, diag::err_alignas_attribute_wrong_decl_type) | |||
3804 | << &TmpAttr << DiagKind; | |||
3805 | return; | |||
3806 | } | |||
3807 | } | |||
3808 | ||||
3809 | if (E->isValueDependent()) { | |||
3810 | // We can't support a dependent alignment on a non-dependent type, | |||
3811 | // because we have no way to model that a type is "alignment-dependent" | |||
3812 | // but not dependent in any other way. | |||
3813 | if (const auto *TND = dyn_cast<TypedefNameDecl>(D)) { | |||
3814 | if (!TND->getUnderlyingType()->isDependentType()) { | |||
3815 | Diag(AttrLoc, diag::err_alignment_dependent_typedef_name) | |||
3816 | << E->getSourceRange(); | |||
3817 | return; | |||
3818 | } | |||
3819 | } | |||
3820 | ||||
3821 | // Save dependent expressions in the AST to be instantiated. | |||
3822 | AlignedAttr *AA = ::new (Context) AlignedAttr(TmpAttr); | |||
3823 | AA->setPackExpansion(IsPackExpansion); | |||
3824 | D->addAttr(AA); | |||
3825 | return; | |||
3826 | } | |||
3827 | ||||
3828 | // FIXME: Cache the number on the AL object? | |||
3829 | llvm::APSInt Alignment; | |||
3830 | ExprResult ICE | |||
3831 | = VerifyIntegerConstantExpression(E, &Alignment, | |||
3832 | diag::err_aligned_attribute_argument_not_int, | |||
3833 | /*AllowFold*/ false); | |||
3834 | if (ICE.isInvalid()) | |||
3835 | return; | |||
3836 | ||||
3837 | uint64_t AlignVal = Alignment.getZExtValue(); | |||
3838 | ||||
3839 | // C++11 [dcl.align]p2: | |||
3840 | // -- if the constant expression evaluates to zero, the alignment | |||
3841 | // specifier shall have no effect | |||
3842 | // C11 6.7.5p6: | |||
3843 | // An alignment specification of zero has no effect. | |||
3844 | if (!(TmpAttr.isAlignas() && !Alignment)) { | |||
3845 | if (!llvm::isPowerOf2_64(AlignVal)) { | |||
3846 | Diag(AttrLoc, diag::err_alignment_not_power_of_two) | |||
3847 | << E->getSourceRange(); | |||
3848 | return; | |||
3849 | } | |||
3850 | } | |||
3851 | ||||
3852 | // Alignment calculations can wrap around if it's greater than 2**28. | |||
3853 | unsigned MaxValidAlignment = | |||
3854 | Context.getTargetInfo().getTriple().isOSBinFormatCOFF() ? 8192 | |||
3855 | : 268435456; | |||
3856 | if (AlignVal > MaxValidAlignment) { | |||
3857 | Diag(AttrLoc, diag::err_attribute_aligned_too_great) << MaxValidAlignment | |||
3858 | << E->getSourceRange(); | |||
3859 | return; | |||
3860 | } | |||
3861 | ||||
3862 | if (Context.getTargetInfo().isTLSSupported()) { | |||
3863 | unsigned MaxTLSAlign = | |||
3864 | Context.toCharUnitsFromBits(Context.getTargetInfo().getMaxTLSAlign()) | |||
3865 | .getQuantity(); | |||
3866 | const auto *VD = dyn_cast<VarDecl>(D); | |||
3867 | if (MaxTLSAlign && AlignVal > MaxTLSAlign && VD && | |||
3868 | VD->getTLSKind() != VarDecl::TLS_None) { | |||
3869 | Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum) | |||
3870 | << (unsigned)AlignVal << VD << MaxTLSAlign; | |||
3871 | return; | |||
3872 | } | |||
3873 | } | |||
3874 | ||||
3875 | AlignedAttr *AA = ::new (Context) AlignedAttr(AttrRange, Context, true, | |||
3876 | ICE.get(), SpellingListIndex); | |||
3877 | AA->setPackExpansion(IsPackExpansion); | |||
3878 | D->addAttr(AA); | |||
3879 | } | |||
3880 | ||||
3881 | void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *TS, | |||
3882 | unsigned SpellingListIndex, bool IsPackExpansion) { | |||
3883 | // FIXME: Cache the number on the AL object if non-dependent? | |||
3884 | // FIXME: Perform checking of type validity | |||
3885 | AlignedAttr *AA = ::new (Context) AlignedAttr(AttrRange, Context, false, TS, | |||
3886 | SpellingListIndex); | |||
3887 | AA->setPackExpansion(IsPackExpansion); | |||
3888 | D->addAttr(AA); | |||
3889 | } | |||
3890 | ||||
3891 | void Sema::CheckAlignasUnderalignment(Decl *D) { | |||
3892 | assert(D->hasAttrs() && "no attributes on decl")((D->hasAttrs() && "no attributes on decl") ? static_cast <void> (0) : __assert_fail ("D->hasAttrs() && \"no attributes on decl\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 3892, __PRETTY_FUNCTION__)); | |||
3893 | ||||
3894 | QualType UnderlyingTy, DiagTy; | |||
3895 | if (const auto *VD = dyn_cast<ValueDecl>(D)) { | |||
3896 | UnderlyingTy = DiagTy = VD->getType(); | |||
3897 | } else { | |||
3898 | UnderlyingTy = DiagTy = Context.getTagDeclType(cast<TagDecl>(D)); | |||
3899 | if (const auto *ED = dyn_cast<EnumDecl>(D)) | |||
3900 | UnderlyingTy = ED->getIntegerType(); | |||
3901 | } | |||
3902 | if (DiagTy->isDependentType() || DiagTy->isIncompleteType()) | |||
3903 | return; | |||
3904 | ||||
3905 | // C++11 [dcl.align]p5, C11 6.7.5/4: | |||
3906 | // The combined effect of all alignment attributes in a declaration shall | |||
3907 | // not specify an alignment that is less strict than the alignment that | |||
3908 | // would otherwise be required for the entity being declared. | |||
3909 | AlignedAttr *AlignasAttr = nullptr; | |||
3910 | unsigned Align = 0; | |||
3911 | for (auto *I : D->specific_attrs<AlignedAttr>()) { | |||
3912 | if (I->isAlignmentDependent()) | |||
3913 | return; | |||
3914 | if (I->isAlignas()) | |||
3915 | AlignasAttr = I; | |||
3916 | Align = std::max(Align, I->getAlignment(Context)); | |||
3917 | } | |||
3918 | ||||
3919 | if (AlignasAttr && Align) { | |||
3920 | CharUnits RequestedAlign = Context.toCharUnitsFromBits(Align); | |||
3921 | CharUnits NaturalAlign = Context.getTypeAlignInChars(UnderlyingTy); | |||
3922 | if (NaturalAlign > RequestedAlign) | |||
3923 | Diag(AlignasAttr->getLocation(), diag::err_alignas_underaligned) | |||
3924 | << DiagTy << (unsigned)NaturalAlign.getQuantity(); | |||
3925 | } | |||
3926 | } | |||
3927 | ||||
3928 | bool Sema::checkMSInheritanceAttrOnDefinition( | |||
3929 | CXXRecordDecl *RD, SourceRange Range, bool BestCase, | |||
3930 | MSInheritanceAttr::Spelling SemanticSpelling) { | |||
3931 | assert(RD->hasDefinition() && "RD has no definition!")((RD->hasDefinition() && "RD has no definition!") ? static_cast<void> (0) : __assert_fail ("RD->hasDefinition() && \"RD has no definition!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 3931, __PRETTY_FUNCTION__)); | |||
3932 | ||||
3933 | // We may not have seen base specifiers or any virtual methods yet. We will | |||
3934 | // have to wait until the record is defined to catch any mismatches. | |||
3935 | if (!RD->getDefinition()->isCompleteDefinition()) | |||
3936 | return false; | |||
3937 | ||||
3938 | // The unspecified model never matches what a definition could need. | |||
3939 | if (SemanticSpelling == MSInheritanceAttr::Keyword_unspecified_inheritance) | |||
3940 | return false; | |||
3941 | ||||
3942 | if (BestCase) { | |||
3943 | if (RD->calculateInheritanceModel() == SemanticSpelling) | |||
3944 | return false; | |||
3945 | } else { | |||
3946 | if (RD->calculateInheritanceModel() <= SemanticSpelling) | |||
3947 | return false; | |||
3948 | } | |||
3949 | ||||
3950 | Diag(Range.getBegin(), diag::err_mismatched_ms_inheritance) | |||
3951 | << 0 /*definition*/; | |||
3952 | Diag(RD->getDefinition()->getLocation(), diag::note_defined_here) | |||
3953 | << RD->getNameAsString(); | |||
3954 | return true; | |||
3955 | } | |||
3956 | ||||
3957 | /// parseModeAttrArg - Parses attribute mode string and returns parsed type | |||
3958 | /// attribute. | |||
3959 | static void parseModeAttrArg(Sema &S, StringRef Str, unsigned &DestWidth, | |||
3960 | bool &IntegerMode, bool &ComplexMode) { | |||
3961 | IntegerMode = true; | |||
3962 | ComplexMode = false; | |||
3963 | switch (Str.size()) { | |||
3964 | case 2: | |||
3965 | switch (Str[0]) { | |||
3966 | case 'Q': | |||
3967 | DestWidth = 8; | |||
3968 | break; | |||
3969 | case 'H': | |||
3970 | DestWidth = 16; | |||
3971 | break; | |||
3972 | case 'S': | |||
3973 | DestWidth = 32; | |||
3974 | break; | |||
3975 | case 'D': | |||
3976 | DestWidth = 64; | |||
3977 | break; | |||
3978 | case 'X': | |||
3979 | DestWidth = 96; | |||
3980 | break; | |||
3981 | case 'T': | |||
3982 | DestWidth = 128; | |||
3983 | break; | |||
3984 | } | |||
3985 | if (Str[1] == 'F') { | |||
3986 | IntegerMode = false; | |||
3987 | } else if (Str[1] == 'C') { | |||
3988 | IntegerMode = false; | |||
3989 | ComplexMode = true; | |||
3990 | } else if (Str[1] != 'I') { | |||
3991 | DestWidth = 0; | |||
3992 | } | |||
3993 | break; | |||
3994 | case 4: | |||
3995 | // FIXME: glibc uses 'word' to define register_t; this is narrower than a | |||
3996 | // pointer on PIC16 and other embedded platforms. | |||
3997 | if (Str == "word") | |||
3998 | DestWidth = S.Context.getTargetInfo().getRegisterWidth(); | |||
3999 | else if (Str == "byte") | |||
4000 | DestWidth = S.Context.getTargetInfo().getCharWidth(); | |||
4001 | break; | |||
4002 | case 7: | |||
4003 | if (Str == "pointer") | |||
4004 | DestWidth = S.Context.getTargetInfo().getPointerWidth(0); | |||
4005 | break; | |||
4006 | case 11: | |||
4007 | if (Str == "unwind_word") | |||
4008 | DestWidth = S.Context.getTargetInfo().getUnwindWordWidth(); | |||
4009 | break; | |||
4010 | } | |||
4011 | } | |||
4012 | ||||
4013 | /// handleModeAttr - This attribute modifies the width of a decl with primitive | |||
4014 | /// type. | |||
4015 | /// | |||
4016 | /// Despite what would be logical, the mode attribute is a decl attribute, not a | |||
4017 | /// type attribute: 'int ** __attribute((mode(HI))) *G;' tries to make 'G' be | |||
4018 | /// HImode, not an intermediate pointer. | |||
4019 | static void handleModeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
4020 | // This attribute isn't documented, but glibc uses it. It changes | |||
4021 | // the width of an int or unsigned int to the specified size. | |||
4022 | if (!AL.isArgIdent(0)) { | |||
4023 | S.Diag(AL.getLoc(), diag::err_attribute_argument_type) | |||
4024 | << AL << AANT_ArgumentIdentifier; | |||
4025 | return; | |||
4026 | } | |||
4027 | ||||
4028 | IdentifierInfo *Name = AL.getArgAsIdent(0)->Ident; | |||
4029 | ||||
4030 | S.AddModeAttr(AL.getRange(), D, Name, AL.getAttributeSpellingListIndex()); | |||
4031 | } | |||
4032 | ||||
4033 | void Sema::AddModeAttr(SourceRange AttrRange, Decl *D, IdentifierInfo *Name, | |||
4034 | unsigned SpellingListIndex, bool InInstantiation) { | |||
4035 | StringRef Str = Name->getName(); | |||
4036 | normalizeName(Str); | |||
4037 | SourceLocation AttrLoc = AttrRange.getBegin(); | |||
4038 | ||||
4039 | unsigned DestWidth = 0; | |||
4040 | bool IntegerMode = true; | |||
4041 | bool ComplexMode = false; | |||
4042 | llvm::APInt VectorSize(64, 0); | |||
4043 | if (Str.size() >= 4 && Str[0] == 'V') { | |||
4044 | // Minimal length of vector mode is 4: 'V' + NUMBER(>=1) + TYPE(>=2). | |||
4045 | size_t StrSize = Str.size(); | |||
4046 | size_t VectorStringLength = 0; | |||
4047 | while ((VectorStringLength + 1) < StrSize && | |||
4048 | isdigit(Str[VectorStringLength + 1])) | |||
4049 | ++VectorStringLength; | |||
4050 | if (VectorStringLength && | |||
4051 | !Str.substr(1, VectorStringLength).getAsInteger(10, VectorSize) && | |||
4052 | VectorSize.isPowerOf2()) { | |||
4053 | parseModeAttrArg(*this, Str.substr(VectorStringLength + 1), DestWidth, | |||
4054 | IntegerMode, ComplexMode); | |||
4055 | // Avoid duplicate warning from template instantiation. | |||
4056 | if (!InInstantiation) | |||
4057 | Diag(AttrLoc, diag::warn_vector_mode_deprecated); | |||
4058 | } else { | |||
4059 | VectorSize = 0; | |||
4060 | } | |||
4061 | } | |||
4062 | ||||
4063 | if (!VectorSize) | |||
4064 | parseModeAttrArg(*this, Str, DestWidth, IntegerMode, ComplexMode); | |||
4065 | ||||
4066 | // FIXME: Sync this with InitializePredefinedMacros; we need to match int8_t | |||
4067 | // and friends, at least with glibc. | |||
4068 | // FIXME: Make sure floating-point mappings are accurate | |||
4069 | // FIXME: Support XF and TF types | |||
4070 | if (!DestWidth) { | |||
4071 | Diag(AttrLoc, diag::err_machine_mode) << 0 /*Unknown*/ << Name; | |||
4072 | return; | |||
4073 | } | |||
4074 | ||||
4075 | QualType OldTy; | |||
4076 | if (const auto *TD = dyn_cast<TypedefNameDecl>(D)) | |||
4077 | OldTy = TD->getUnderlyingType(); | |||
4078 | else if (const auto *ED = dyn_cast<EnumDecl>(D)) { | |||
4079 | // Something like 'typedef enum { X } __attribute__((mode(XX))) T;'. | |||
4080 | // Try to get type from enum declaration, default to int. | |||
4081 | OldTy = ED->getIntegerType(); | |||
4082 | if (OldTy.isNull()) | |||
4083 | OldTy = Context.IntTy; | |||
4084 | } else | |||
4085 | OldTy = cast<ValueDecl>(D)->getType(); | |||
4086 | ||||
4087 | if (OldTy->isDependentType()) { | |||
4088 | D->addAttr(::new (Context) | |||
4089 | ModeAttr(AttrRange, Context, Name, SpellingListIndex)); | |||
4090 | return; | |||
4091 | } | |||
4092 | ||||
4093 | // Base type can also be a vector type (see PR17453). | |||
4094 | // Distinguish between base type and base element type. | |||
4095 | QualType OldElemTy = OldTy; | |||
4096 | if (const auto *VT = OldTy->getAs<VectorType>()) | |||
4097 | OldElemTy = VT->getElementType(); | |||
4098 | ||||
4099 | // GCC allows 'mode' attribute on enumeration types (even incomplete), except | |||
4100 | // for vector modes. So, 'enum X __attribute__((mode(QI)));' forms a complete | |||
4101 | // type, 'enum { A } __attribute__((mode(V4SI)))' is rejected. | |||
4102 | if ((isa<EnumDecl>(D) || OldElemTy->getAs<EnumType>()) && | |||
4103 | VectorSize.getBoolValue()) { | |||
4104 | Diag(AttrLoc, diag::err_enum_mode_vector_type) << Name << AttrRange; | |||
4105 | return; | |||
4106 | } | |||
4107 | bool IntegralOrAnyEnumType = | |||
4108 | OldElemTy->isIntegralOrEnumerationType() || OldElemTy->getAs<EnumType>(); | |||
4109 | ||||
4110 | if (!OldElemTy->getAs<BuiltinType>() && !OldElemTy->isComplexType() && | |||
4111 | !IntegralOrAnyEnumType) | |||
4112 | Diag(AttrLoc, diag::err_mode_not_primitive); | |||
4113 | else if (IntegerMode) { | |||
4114 | if (!IntegralOrAnyEnumType) | |||
4115 | Diag(AttrLoc, diag::err_mode_wrong_type); | |||
4116 | } else if (ComplexMode) { | |||
4117 | if (!OldElemTy->isComplexType()) | |||
4118 | Diag(AttrLoc, diag::err_mode_wrong_type); | |||
4119 | } else { | |||
4120 | if (!OldElemTy->isFloatingType()) | |||
4121 | Diag(AttrLoc, diag::err_mode_wrong_type); | |||
4122 | } | |||
4123 | ||||
4124 | QualType NewElemTy; | |||
4125 | ||||
4126 | if (IntegerMode) | |||
4127 | NewElemTy = Context.getIntTypeForBitwidth(DestWidth, | |||
4128 | OldElemTy->isSignedIntegerType()); | |||
4129 | else | |||
4130 | NewElemTy = Context.getRealTypeForBitwidth(DestWidth); | |||
4131 | ||||
4132 | if (NewElemTy.isNull()) { | |||
4133 | Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name; | |||
4134 | return; | |||
4135 | } | |||
4136 | ||||
4137 | if (ComplexMode) { | |||
4138 | NewElemTy = Context.getComplexType(NewElemTy); | |||
4139 | } | |||
4140 | ||||
4141 | QualType NewTy = NewElemTy; | |||
4142 | if (VectorSize.getBoolValue()) { | |||
4143 | NewTy = Context.getVectorType(NewTy, VectorSize.getZExtValue(), | |||
4144 | VectorType::GenericVector); | |||
4145 | } else if (const auto *OldVT = OldTy->getAs<VectorType>()) { | |||
4146 | // Complex machine mode does not support base vector types. | |||
4147 | if (ComplexMode) { | |||
4148 | Diag(AttrLoc, diag::err_complex_mode_vector_type); | |||
4149 | return; | |||
4150 | } | |||
4151 | unsigned NumElements = Context.getTypeSize(OldElemTy) * | |||
4152 | OldVT->getNumElements() / | |||
4153 | Context.getTypeSize(NewElemTy); | |||
4154 | NewTy = | |||
4155 | Context.getVectorType(NewElemTy, NumElements, OldVT->getVectorKind()); | |||
4156 | } | |||
4157 | ||||
4158 | if (NewTy.isNull()) { | |||
4159 | Diag(AttrLoc, diag::err_mode_wrong_type); | |||
4160 | return; | |||
4161 | } | |||
4162 | ||||
4163 | // Install the new type. | |||
4164 | if (auto *TD = dyn_cast<TypedefNameDecl>(D)) | |||
4165 | TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy); | |||
4166 | else if (auto *ED = dyn_cast<EnumDecl>(D)) | |||
4167 | ED->setIntegerType(NewTy); | |||
4168 | else | |||
4169 | cast<ValueDecl>(D)->setType(NewTy); | |||
4170 | ||||
4171 | D->addAttr(::new (Context) | |||
4172 | ModeAttr(AttrRange, Context, Name, SpellingListIndex)); | |||
4173 | } | |||
4174 | ||||
4175 | static void handleNoDebugAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
4176 | D->addAttr(::new (S.Context) | |||
4177 | NoDebugAttr(AL.getRange(), S.Context, | |||
4178 | AL.getAttributeSpellingListIndex())); | |||
4179 | } | |||
4180 | ||||
4181 | AlwaysInlineAttr *Sema::mergeAlwaysInlineAttr(Decl *D, SourceRange Range, | |||
4182 | IdentifierInfo *Ident, | |||
4183 | unsigned AttrSpellingListIndex) { | |||
4184 | if (OptimizeNoneAttr *Optnone = D->getAttr<OptimizeNoneAttr>()) { | |||
4185 | Diag(Range.getBegin(), diag::warn_attribute_ignored) << Ident; | |||
4186 | Diag(Optnone->getLocation(), diag::note_conflicting_attribute); | |||
4187 | return nullptr; | |||
4188 | } | |||
4189 | ||||
4190 | if (D->hasAttr<AlwaysInlineAttr>()) | |||
4191 | return nullptr; | |||
4192 | ||||
4193 | return ::new (Context) AlwaysInlineAttr(Range, Context, | |||
4194 | AttrSpellingListIndex); | |||
4195 | } | |||
4196 | ||||
4197 | CommonAttr *Sema::mergeCommonAttr(Decl *D, const ParsedAttr &AL) { | |||
4198 | if (checkAttrMutualExclusion<InternalLinkageAttr>(*this, D, AL)) | |||
4199 | return nullptr; | |||
4200 | ||||
4201 | return ::new (Context) | |||
4202 | CommonAttr(AL.getRange(), Context, AL.getAttributeSpellingListIndex()); | |||
4203 | } | |||
4204 | ||||
4205 | CommonAttr *Sema::mergeCommonAttr(Decl *D, const CommonAttr &AL) { | |||
4206 | if (checkAttrMutualExclusion<InternalLinkageAttr>(*this, D, AL)) | |||
4207 | return nullptr; | |||
4208 | ||||
4209 | return ::new (Context) | |||
4210 | CommonAttr(AL.getRange(), Context, AL.getSpellingListIndex()); | |||
4211 | } | |||
4212 | ||||
4213 | InternalLinkageAttr *Sema::mergeInternalLinkageAttr(Decl *D, | |||
4214 | const ParsedAttr &AL) { | |||
4215 | if (const auto *VD = dyn_cast<VarDecl>(D)) { | |||
4216 | // Attribute applies to Var but not any subclass of it (like ParmVar, | |||
4217 | // ImplicitParm or VarTemplateSpecialization). | |||
4218 | if (VD->getKind() != Decl::Var) { | |||
4219 | Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type) | |||
4220 | << AL << (getLangOpts().CPlusPlus ? ExpectedFunctionVariableOrClass | |||
4221 | : ExpectedVariableOrFunction); | |||
4222 | return nullptr; | |||
4223 | } | |||
4224 | // Attribute does not apply to non-static local variables. | |||
4225 | if (VD->hasLocalStorage()) { | |||
4226 | Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage); | |||
4227 | return nullptr; | |||
4228 | } | |||
4229 | } | |||
4230 | ||||
4231 | if (checkAttrMutualExclusion<CommonAttr>(*this, D, AL)) | |||
4232 | return nullptr; | |||
4233 | ||||
4234 | return ::new (Context) InternalLinkageAttr( | |||
4235 | AL.getRange(), Context, AL.getAttributeSpellingListIndex()); | |||
4236 | } | |||
4237 | InternalLinkageAttr * | |||
4238 | Sema::mergeInternalLinkageAttr(Decl *D, const InternalLinkageAttr &AL) { | |||
4239 | if (const auto *VD = dyn_cast<VarDecl>(D)) { | |||
4240 | // Attribute applies to Var but not any subclass of it (like ParmVar, | |||
4241 | // ImplicitParm or VarTemplateSpecialization). | |||
4242 | if (VD->getKind() != Decl::Var) { | |||
4243 | Diag(AL.getLocation(), diag::warn_attribute_wrong_decl_type) | |||
4244 | << &AL << (getLangOpts().CPlusPlus ? ExpectedFunctionVariableOrClass | |||
4245 | : ExpectedVariableOrFunction); | |||
4246 | return nullptr; | |||
4247 | } | |||
4248 | // Attribute does not apply to non-static local variables. | |||
4249 | if (VD->hasLocalStorage()) { | |||
4250 | Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage); | |||
4251 | return nullptr; | |||
4252 | } | |||
4253 | } | |||
4254 | ||||
4255 | if (checkAttrMutualExclusion<CommonAttr>(*this, D, AL)) | |||
4256 | return nullptr; | |||
4257 | ||||
4258 | return ::new (Context) | |||
4259 | InternalLinkageAttr(AL.getRange(), Context, AL.getSpellingListIndex()); | |||
4260 | } | |||
4261 | ||||
4262 | MinSizeAttr *Sema::mergeMinSizeAttr(Decl *D, SourceRange Range, | |||
4263 | unsigned AttrSpellingListIndex) { | |||
4264 | if (OptimizeNoneAttr *Optnone = D->getAttr<OptimizeNoneAttr>()) { | |||
4265 | Diag(Range.getBegin(), diag::warn_attribute_ignored) << "'minsize'"; | |||
4266 | Diag(Optnone->getLocation(), diag::note_conflicting_attribute); | |||
4267 | return nullptr; | |||
4268 | } | |||
4269 | ||||
4270 | if (D->hasAttr<MinSizeAttr>()) | |||
4271 | return nullptr; | |||
4272 | ||||
4273 | return ::new (Context) MinSizeAttr(Range, Context, AttrSpellingListIndex); | |||
4274 | } | |||
4275 | ||||
4276 | NoSpeculativeLoadHardeningAttr *Sema::mergeNoSpeculativeLoadHardeningAttr( | |||
4277 | Decl *D, const NoSpeculativeLoadHardeningAttr &AL) { | |||
4278 | if (checkAttrMutualExclusion<SpeculativeLoadHardeningAttr>(*this, D, AL)) | |||
4279 | return nullptr; | |||
4280 | ||||
4281 | return ::new (Context) NoSpeculativeLoadHardeningAttr( | |||
4282 | AL.getRange(), Context, AL.getSpellingListIndex()); | |||
4283 | } | |||
4284 | ||||
4285 | OptimizeNoneAttr *Sema::mergeOptimizeNoneAttr(Decl *D, SourceRange Range, | |||
4286 | unsigned AttrSpellingListIndex) { | |||
4287 | if (AlwaysInlineAttr *Inline = D->getAttr<AlwaysInlineAttr>()) { | |||
4288 | Diag(Inline->getLocation(), diag::warn_attribute_ignored) << Inline; | |||
4289 | Diag(Range.getBegin(), diag::note_conflicting_attribute); | |||
4290 | D->dropAttr<AlwaysInlineAttr>(); | |||
4291 | } | |||
4292 | if (MinSizeAttr *MinSize = D->getAttr<MinSizeAttr>()) { | |||
4293 | Diag(MinSize->getLocation(), diag::warn_attribute_ignored) << MinSize; | |||
4294 | Diag(Range.getBegin(), diag::note_conflicting_attribute); | |||
4295 | D->dropAttr<MinSizeAttr>(); | |||
4296 | } | |||
4297 | ||||
4298 | if (D->hasAttr<OptimizeNoneAttr>()) | |||
4299 | return nullptr; | |||
4300 | ||||
4301 | return ::new (Context) OptimizeNoneAttr(Range, Context, | |||
4302 | AttrSpellingListIndex); | |||
4303 | } | |||
4304 | ||||
4305 | SpeculativeLoadHardeningAttr *Sema::mergeSpeculativeLoadHardeningAttr( | |||
4306 | Decl *D, const SpeculativeLoadHardeningAttr &AL) { | |||
4307 | if (checkAttrMutualExclusion<NoSpeculativeLoadHardeningAttr>(*this, D, AL)) | |||
4308 | return nullptr; | |||
4309 | ||||
4310 | return ::new (Context) SpeculativeLoadHardeningAttr( | |||
4311 | AL.getRange(), Context, AL.getSpellingListIndex()); | |||
4312 | } | |||
4313 | ||||
4314 | static void handleAlwaysInlineAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
4315 | if (checkAttrMutualExclusion<NotTailCalledAttr>(S, D, AL)) | |||
4316 | return; | |||
4317 | ||||
4318 | if (AlwaysInlineAttr *Inline = S.mergeAlwaysInlineAttr( | |||
4319 | D, AL.getRange(), AL.getName(), | |||
4320 | AL.getAttributeSpellingListIndex())) | |||
4321 | D->addAttr(Inline); | |||
4322 | } | |||
4323 | ||||
4324 | static void handleMinSizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
4325 | if (MinSizeAttr *MinSize = S.mergeMinSizeAttr( | |||
4326 | D, AL.getRange(), AL.getAttributeSpellingListIndex())) | |||
4327 | D->addAttr(MinSize); | |||
4328 | } | |||
4329 | ||||
4330 | static void handleOptimizeNoneAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
4331 | if (OptimizeNoneAttr *Optnone = S.mergeOptimizeNoneAttr( | |||
4332 | D, AL.getRange(), AL.getAttributeSpellingListIndex())) | |||
4333 | D->addAttr(Optnone); | |||
4334 | } | |||
4335 | ||||
4336 | static void handleConstantAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
4337 | if (checkAttrMutualExclusion<CUDASharedAttr>(S, D, AL)) | |||
4338 | return; | |||
4339 | const auto *VD = cast<VarDecl>(D); | |||
4340 | if (!VD->hasGlobalStorage()) { | |||
4341 | S.Diag(AL.getLoc(), diag::err_cuda_nonglobal_constant); | |||
4342 | return; | |||
4343 | } | |||
4344 | D->addAttr(::new (S.Context) CUDAConstantAttr( | |||
4345 | AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); | |||
4346 | } | |||
4347 | ||||
4348 | static void handleSharedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
4349 | if (checkAttrMutualExclusion<CUDAConstantAttr>(S, D, AL)) | |||
4350 | return; | |||
4351 | const auto *VD = cast<VarDecl>(D); | |||
4352 | // extern __shared__ is only allowed on arrays with no length (e.g. | |||
4353 | // "int x[]"). | |||
4354 | if (!S.getLangOpts().GPURelocatableDeviceCode && VD->hasExternalStorage() && | |||
4355 | !isa<IncompleteArrayType>(VD->getType())) { | |||
4356 | S.Diag(AL.getLoc(), diag::err_cuda_extern_shared) << VD; | |||
4357 | return; | |||
4358 | } | |||
4359 | if (S.getLangOpts().CUDA && VD->hasLocalStorage() && | |||
4360 | S.CUDADiagIfHostCode(AL.getLoc(), diag::err_cuda_host_shared) | |||
4361 | << S.CurrentCUDATarget()) | |||
4362 | return; | |||
4363 | D->addAttr(::new (S.Context) CUDASharedAttr( | |||
4364 | AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); | |||
4365 | } | |||
4366 | ||||
4367 | static void handleGlobalAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
4368 | if (checkAttrMutualExclusion<CUDADeviceAttr>(S, D, AL) || | |||
4369 | checkAttrMutualExclusion<CUDAHostAttr>(S, D, AL)) { | |||
4370 | return; | |||
4371 | } | |||
4372 | const auto *FD = cast<FunctionDecl>(D); | |||
4373 | if (!FD->getReturnType()->isVoidType()) { | |||
4374 | SourceRange RTRange = FD->getReturnTypeSourceRange(); | |||
4375 | S.Diag(FD->getTypeSpecStartLoc(), diag::err_kern_type_not_void_return) | |||
4376 | << FD->getType() | |||
4377 | << (RTRange.isValid() ? FixItHint::CreateReplacement(RTRange, "void") | |||
4378 | : FixItHint()); | |||
4379 | return; | |||
4380 | } | |||
4381 | if (const auto *Method = dyn_cast<CXXMethodDecl>(FD)) { | |||
4382 | if (Method->isInstance()) { | |||
4383 | S.Diag(Method->getBeginLoc(), diag::err_kern_is_nonstatic_method) | |||
4384 | << Method; | |||
4385 | return; | |||
4386 | } | |||
4387 | S.Diag(Method->getBeginLoc(), diag::warn_kern_is_method) << Method; | |||
4388 | } | |||
4389 | // Only warn for "inline" when compiling for host, to cut down on noise. | |||
4390 | if (FD->isInlineSpecified() && !S.getLangOpts().CUDAIsDevice) | |||
4391 | S.Diag(FD->getBeginLoc(), diag::warn_kern_is_inline) << FD; | |||
4392 | ||||
4393 | D->addAttr(::new (S.Context) | |||
4394 | CUDAGlobalAttr(AL.getRange(), S.Context, | |||
4395 | AL.getAttributeSpellingListIndex())); | |||
4396 | } | |||
4397 | ||||
4398 | static void handleGNUInlineAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
4399 | const auto *Fn = cast<FunctionDecl>(D); | |||
4400 | if (!Fn->isInlineSpecified()) { | |||
4401 | S.Diag(AL.getLoc(), diag::warn_gnu_inline_attribute_requires_inline); | |||
4402 | return; | |||
4403 | } | |||
4404 | ||||
4405 | D->addAttr(::new (S.Context) | |||
4406 | GNUInlineAttr(AL.getRange(), S.Context, | |||
4407 | AL.getAttributeSpellingListIndex())); | |||
4408 | } | |||
4409 | ||||
4410 | static void handleCallConvAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
4411 | if (hasDeclarator(D)) return; | |||
4412 | ||||
4413 | // Diagnostic is emitted elsewhere: here we store the (valid) AL | |||
4414 | // in the Decl node for syntactic reasoning, e.g., pretty-printing. | |||
4415 | CallingConv CC; | |||
4416 | if (S.CheckCallingConvAttr(AL, CC, /*FD*/nullptr)) | |||
4417 | return; | |||
4418 | ||||
4419 | if (!isa<ObjCMethodDecl>(D)) { | |||
4420 | S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type) | |||
4421 | << AL << ExpectedFunctionOrMethod; | |||
4422 | return; | |||
4423 | } | |||
4424 | ||||
4425 | switch (AL.getKind()) { | |||
4426 | case ParsedAttr::AT_FastCall: | |||
4427 | D->addAttr(::new (S.Context) | |||
4428 | FastCallAttr(AL.getRange(), S.Context, | |||
4429 | AL.getAttributeSpellingListIndex())); | |||
4430 | return; | |||
4431 | case ParsedAttr::AT_StdCall: | |||
4432 | D->addAttr(::new (S.Context) | |||
4433 | StdCallAttr(AL.getRange(), S.Context, | |||
4434 | AL.getAttributeSpellingListIndex())); | |||
4435 | return; | |||
4436 | case ParsedAttr::AT_ThisCall: | |||
4437 | D->addAttr(::new (S.Context) | |||
4438 | ThisCallAttr(AL.getRange(), S.Context, | |||
4439 | AL.getAttributeSpellingListIndex())); | |||
4440 | return; | |||
4441 | case ParsedAttr::AT_CDecl: | |||
4442 | D->addAttr(::new (S.Context) | |||
4443 | CDeclAttr(AL.getRange(), S.Context, | |||
4444 | AL.getAttributeSpellingListIndex())); | |||
4445 | return; | |||
4446 | case ParsedAttr::AT_Pascal: | |||
4447 | D->addAttr(::new (S.Context) | |||
4448 | PascalAttr(AL.getRange(), S.Context, | |||
4449 | AL.getAttributeSpellingListIndex())); | |||
4450 | return; | |||
4451 | case ParsedAttr::AT_SwiftCall: | |||
4452 | D->addAttr(::new (S.Context) | |||
4453 | SwiftCallAttr(AL.getRange(), S.Context, | |||
4454 | AL.getAttributeSpellingListIndex())); | |||
4455 | return; | |||
4456 | case ParsedAttr::AT_VectorCall: | |||
4457 | D->addAttr(::new (S.Context) | |||
4458 | VectorCallAttr(AL.getRange(), S.Context, | |||
4459 | AL.getAttributeSpellingListIndex())); | |||
4460 | return; | |||
4461 | case ParsedAttr::AT_MSABI: | |||
4462 | D->addAttr(::new (S.Context) | |||
4463 | MSABIAttr(AL.getRange(), S.Context, | |||
4464 | AL.getAttributeSpellingListIndex())); | |||
4465 | return; | |||
4466 | case ParsedAttr::AT_SysVABI: | |||
4467 | D->addAttr(::new (S.Context) | |||
4468 | SysVABIAttr(AL.getRange(), S.Context, | |||
4469 | AL.getAttributeSpellingListIndex())); | |||
4470 | return; | |||
4471 | case ParsedAttr::AT_RegCall: | |||
4472 | D->addAttr(::new (S.Context) RegCallAttr( | |||
4473 | AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); | |||
4474 | return; | |||
4475 | case ParsedAttr::AT_Pcs: { | |||
4476 | PcsAttr::PCSType PCS; | |||
4477 | switch (CC) { | |||
4478 | case CC_AAPCS: | |||
4479 | PCS = PcsAttr::AAPCS; | |||
4480 | break; | |||
4481 | case CC_AAPCS_VFP: | |||
4482 | PCS = PcsAttr::AAPCS_VFP; | |||
4483 | break; | |||
4484 | default: | |||
4485 | llvm_unreachable("unexpected calling convention in pcs attribute")::llvm::llvm_unreachable_internal("unexpected calling convention in pcs attribute" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 4485); | |||
4486 | } | |||
4487 | ||||
4488 | D->addAttr(::new (S.Context) | |||
4489 | PcsAttr(AL.getRange(), S.Context, PCS, | |||
4490 | AL.getAttributeSpellingListIndex())); | |||
4491 | return; | |||
4492 | } | |||
4493 | case ParsedAttr::AT_AArch64VectorPcs: | |||
4494 | D->addAttr(::new(S.Context) | |||
4495 | AArch64VectorPcsAttr(AL.getRange(), S.Context, | |||
4496 | AL.getAttributeSpellingListIndex())); | |||
4497 | return; | |||
4498 | case ParsedAttr::AT_IntelOclBicc: | |||
4499 | D->addAttr(::new (S.Context) | |||
4500 | IntelOclBiccAttr(AL.getRange(), S.Context, | |||
4501 | AL.getAttributeSpellingListIndex())); | |||
4502 | return; | |||
4503 | case ParsedAttr::AT_PreserveMost: | |||
4504 | D->addAttr(::new (S.Context) PreserveMostAttr( | |||
4505 | AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); | |||
4506 | return; | |||
4507 | case ParsedAttr::AT_PreserveAll: | |||
4508 | D->addAttr(::new (S.Context) PreserveAllAttr( | |||
4509 | AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); | |||
4510 | return; | |||
4511 | default: | |||
4512 | llvm_unreachable("unexpected attribute kind")::llvm::llvm_unreachable_internal("unexpected attribute kind" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 4512); | |||
4513 | } | |||
4514 | } | |||
4515 | ||||
4516 | static void handleSuppressAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
4517 | if (!checkAttributeAtLeastNumArgs(S, AL, 1)) | |||
4518 | return; | |||
4519 | ||||
4520 | std::vector<StringRef> DiagnosticIdentifiers; | |||
4521 | for (unsigned I = 0, E = AL.getNumArgs(); I != E; ++I) { | |||
4522 | StringRef RuleName; | |||
4523 | ||||
4524 | if (!S.checkStringLiteralArgumentAttr(AL, I, RuleName, nullptr)) | |||
4525 | return; | |||
4526 | ||||
4527 | // FIXME: Warn if the rule name is unknown. This is tricky because only | |||
4528 | // clang-tidy knows about available rules. | |||
4529 | DiagnosticIdentifiers.push_back(RuleName); | |||
4530 | } | |||
4531 | D->addAttr(::new (S.Context) SuppressAttr( | |||
4532 | AL.getRange(), S.Context, DiagnosticIdentifiers.data(), | |||
4533 | DiagnosticIdentifiers.size(), AL.getAttributeSpellingListIndex())); | |||
4534 | } | |||
4535 | ||||
4536 | bool Sema::CheckCallingConvAttr(const ParsedAttr &Attrs, CallingConv &CC, | |||
4537 | const FunctionDecl *FD) { | |||
4538 | if (Attrs.isInvalid()) | |||
4539 | return true; | |||
4540 | ||||
4541 | if (Attrs.hasProcessingCache()) { | |||
4542 | CC = (CallingConv) Attrs.getProcessingCache(); | |||
4543 | return false; | |||
4544 | } | |||
4545 | ||||
4546 | unsigned ReqArgs = Attrs.getKind() == ParsedAttr::AT_Pcs ? 1 : 0; | |||
4547 | if (!checkAttributeNumArgs(*this, Attrs, ReqArgs)) { | |||
4548 | Attrs.setInvalid(); | |||
4549 | return true; | |||
4550 | } | |||
4551 | ||||
4552 | // TODO: diagnose uses of these conventions on the wrong target. | |||
4553 | switch (Attrs.getKind()) { | |||
4554 | case ParsedAttr::AT_CDecl: | |||
4555 | CC = CC_C; | |||
4556 | break; | |||
4557 | case ParsedAttr::AT_FastCall: | |||
4558 | CC = CC_X86FastCall; | |||
4559 | break; | |||
4560 | case ParsedAttr::AT_StdCall: | |||
4561 | CC = CC_X86StdCall; | |||
4562 | break; | |||
4563 | case ParsedAttr::AT_ThisCall: | |||
4564 | CC = CC_X86ThisCall; | |||
4565 | break; | |||
4566 | case ParsedAttr::AT_Pascal: | |||
4567 | CC = CC_X86Pascal; | |||
4568 | break; | |||
4569 | case ParsedAttr::AT_SwiftCall: | |||
4570 | CC = CC_Swift; | |||
4571 | break; | |||
4572 | case ParsedAttr::AT_VectorCall: | |||
4573 | CC = CC_X86VectorCall; | |||
4574 | break; | |||
4575 | case ParsedAttr::AT_AArch64VectorPcs: | |||
4576 | CC = CC_AArch64VectorCall; | |||
4577 | break; | |||
4578 | case ParsedAttr::AT_RegCall: | |||
4579 | CC = CC_X86RegCall; | |||
4580 | break; | |||
4581 | case ParsedAttr::AT_MSABI: | |||
4582 | CC = Context.getTargetInfo().getTriple().isOSWindows() ? CC_C : | |||
4583 | CC_Win64; | |||
4584 | break; | |||
4585 | case ParsedAttr::AT_SysVABI: | |||
4586 | CC = Context.getTargetInfo().getTriple().isOSWindows() ? CC_X86_64SysV : | |||
4587 | CC_C; | |||
4588 | break; | |||
4589 | case ParsedAttr::AT_Pcs: { | |||
4590 | StringRef StrRef; | |||
4591 | if (!checkStringLiteralArgumentAttr(Attrs, 0, StrRef)) { | |||
4592 | Attrs.setInvalid(); | |||
4593 | return true; | |||
4594 | } | |||
4595 | if (StrRef == "aapcs") { | |||
4596 | CC = CC_AAPCS; | |||
4597 | break; | |||
4598 | } else if (StrRef == "aapcs-vfp") { | |||
4599 | CC = CC_AAPCS_VFP; | |||
4600 | break; | |||
4601 | } | |||
4602 | ||||
4603 | Attrs.setInvalid(); | |||
4604 | Diag(Attrs.getLoc(), diag::err_invalid_pcs); | |||
4605 | return true; | |||
4606 | } | |||
4607 | case ParsedAttr::AT_IntelOclBicc: | |||
4608 | CC = CC_IntelOclBicc; | |||
4609 | break; | |||
4610 | case ParsedAttr::AT_PreserveMost: | |||
4611 | CC = CC_PreserveMost; | |||
4612 | break; | |||
4613 | case ParsedAttr::AT_PreserveAll: | |||
4614 | CC = CC_PreserveAll; | |||
4615 | break; | |||
4616 | default: llvm_unreachable("unexpected attribute kind")::llvm::llvm_unreachable_internal("unexpected attribute kind" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 4616); | |||
4617 | } | |||
4618 | ||||
4619 | TargetInfo::CallingConvCheckResult A = TargetInfo::CCCR_OK; | |||
4620 | const TargetInfo &TI = Context.getTargetInfo(); | |||
4621 | // CUDA functions may have host and/or device attributes which indicate | |||
4622 | // their targeted execution environment, therefore the calling convention | |||
4623 | // of functions in CUDA should be checked against the target deduced based | |||
4624 | // on their host/device attributes. | |||
4625 | if (LangOpts.CUDA) { | |||
4626 | auto *Aux = Context.getAuxTargetInfo(); | |||
4627 | auto CudaTarget = IdentifyCUDATarget(FD); | |||
4628 | bool CheckHost = false, CheckDevice = false; | |||
4629 | switch (CudaTarget) { | |||
4630 | case CFT_HostDevice: | |||
4631 | CheckHost = true; | |||
4632 | CheckDevice = true; | |||
4633 | break; | |||
4634 | case CFT_Host: | |||
4635 | CheckHost = true; | |||
4636 | break; | |||
4637 | case CFT_Device: | |||
4638 | case CFT_Global: | |||
4639 | CheckDevice = true; | |||
4640 | break; | |||
4641 | case CFT_InvalidTarget: | |||
4642 | llvm_unreachable("unexpected cuda target")::llvm::llvm_unreachable_internal("unexpected cuda target", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 4642); | |||
4643 | } | |||
4644 | auto *HostTI = LangOpts.CUDAIsDevice ? Aux : &TI; | |||
4645 | auto *DeviceTI = LangOpts.CUDAIsDevice ? &TI : Aux; | |||
4646 | if (CheckHost && HostTI) | |||
4647 | A = HostTI->checkCallingConvention(CC); | |||
4648 | if (A == TargetInfo::CCCR_OK && CheckDevice && DeviceTI) | |||
4649 | A = DeviceTI->checkCallingConvention(CC); | |||
4650 | } else { | |||
4651 | A = TI.checkCallingConvention(CC); | |||
4652 | } | |||
4653 | if (A != TargetInfo::CCCR_OK) { | |||
4654 | if (A == TargetInfo::CCCR_Warning) | |||
4655 | Diag(Attrs.getLoc(), diag::warn_cconv_ignored) | |||
4656 | << Attrs << (int)CallingConventionIgnoredReason::ForThisTarget; | |||
4657 | ||||
4658 | // This convention is not valid for the target. Use the default function or | |||
4659 | // method calling convention. | |||
4660 | bool IsCXXMethod = false, IsVariadic = false; | |||
4661 | if (FD) { | |||
4662 | IsCXXMethod = FD->isCXXInstanceMember(); | |||
4663 | IsVariadic = FD->isVariadic(); | |||
4664 | } | |||
4665 | CC = Context.getDefaultCallingConvention(IsVariadic, IsCXXMethod); | |||
4666 | } | |||
4667 | ||||
4668 | Attrs.setProcessingCache((unsigned) CC); | |||
4669 | return false; | |||
4670 | } | |||
4671 | ||||
4672 | /// Pointer-like types in the default address space. | |||
4673 | static bool isValidSwiftContextType(QualType Ty) { | |||
4674 | if (!Ty->hasPointerRepresentation()) | |||
4675 | return Ty->isDependentType(); | |||
4676 | return Ty->getPointeeType().getAddressSpace() == LangAS::Default; | |||
4677 | } | |||
4678 | ||||
4679 | /// Pointers and references in the default address space. | |||
4680 | static bool isValidSwiftIndirectResultType(QualType Ty) { | |||
4681 | if (const auto *PtrType = Ty->getAs<PointerType>()) { | |||
4682 | Ty = PtrType->getPointeeType(); | |||
4683 | } else if (const auto *RefType = Ty->getAs<ReferenceType>()) { | |||
4684 | Ty = RefType->getPointeeType(); | |||
4685 | } else { | |||
4686 | return Ty->isDependentType(); | |||
4687 | } | |||
4688 | return Ty.getAddressSpace() == LangAS::Default; | |||
4689 | } | |||
4690 | ||||
4691 | /// Pointers and references to pointers in the default address space. | |||
4692 | static bool isValidSwiftErrorResultType(QualType Ty) { | |||
4693 | if (const auto *PtrType = Ty->getAs<PointerType>()) { | |||
4694 | Ty = PtrType->getPointeeType(); | |||
4695 | } else if (const auto *RefType = Ty->getAs<ReferenceType>()) { | |||
4696 | Ty = RefType->getPointeeType(); | |||
4697 | } else { | |||
4698 | return Ty->isDependentType(); | |||
4699 | } | |||
4700 | if (!Ty.getQualifiers().empty()) | |||
4701 | return false; | |||
4702 | return isValidSwiftContextType(Ty); | |||
4703 | } | |||
4704 | ||||
4705 | static void handleParameterABIAttr(Sema &S, Decl *D, const ParsedAttr &Attrs, | |||
4706 | ParameterABI Abi) { | |||
4707 | S.AddParameterABIAttr(Attrs.getRange(), D, Abi, | |||
4708 | Attrs.getAttributeSpellingListIndex()); | |||
4709 | } | |||
4710 | ||||
4711 | void Sema::AddParameterABIAttr(SourceRange range, Decl *D, ParameterABI abi, | |||
4712 | unsigned spellingIndex) { | |||
4713 | ||||
4714 | QualType type = cast<ParmVarDecl>(D)->getType(); | |||
4715 | ||||
4716 | if (auto existingAttr = D->getAttr<ParameterABIAttr>()) { | |||
4717 | if (existingAttr->getABI() != abi) { | |||
4718 | Diag(range.getBegin(), diag::err_attributes_are_not_compatible) | |||
4719 | << getParameterABISpelling(abi) << existingAttr; | |||
4720 | Diag(existingAttr->getLocation(), diag::note_conflicting_attribute); | |||
4721 | return; | |||
4722 | } | |||
4723 | } | |||
4724 | ||||
4725 | switch (abi) { | |||
4726 | case ParameterABI::Ordinary: | |||
4727 | llvm_unreachable("explicit attribute for ordinary parameter ABI?")::llvm::llvm_unreachable_internal("explicit attribute for ordinary parameter ABI?" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 4727); | |||
4728 | ||||
4729 | case ParameterABI::SwiftContext: | |||
4730 | if (!isValidSwiftContextType(type)) { | |||
4731 | Diag(range.getBegin(), diag::err_swift_abi_parameter_wrong_type) | |||
4732 | << getParameterABISpelling(abi) | |||
4733 | << /*pointer to pointer */ 0 << type; | |||
4734 | } | |||
4735 | D->addAttr(::new (Context) | |||
4736 | SwiftContextAttr(range, Context, spellingIndex)); | |||
4737 | return; | |||
4738 | ||||
4739 | case ParameterABI::SwiftErrorResult: | |||
4740 | if (!isValidSwiftErrorResultType(type)) { | |||
4741 | Diag(range.getBegin(), diag::err_swift_abi_parameter_wrong_type) | |||
4742 | << getParameterABISpelling(abi) | |||
4743 | << /*pointer to pointer */ 1 << type; | |||
4744 | } | |||
4745 | D->addAttr(::new (Context) | |||
4746 | SwiftErrorResultAttr(range, Context, spellingIndex)); | |||
4747 | return; | |||
4748 | ||||
4749 | case ParameterABI::SwiftIndirectResult: | |||
4750 | if (!isValidSwiftIndirectResultType(type)) { | |||
4751 | Diag(range.getBegin(), diag::err_swift_abi_parameter_wrong_type) | |||
4752 | << getParameterABISpelling(abi) | |||
4753 | << /*pointer*/ 0 << type; | |||
4754 | } | |||
4755 | D->addAttr(::new (Context) | |||
4756 | SwiftIndirectResultAttr(range, Context, spellingIndex)); | |||
4757 | return; | |||
4758 | } | |||
4759 | llvm_unreachable("bad parameter ABI attribute")::llvm::llvm_unreachable_internal("bad parameter ABI attribute" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 4759); | |||
4760 | } | |||
4761 | ||||
4762 | /// Checks a regparm attribute, returning true if it is ill-formed and | |||
4763 | /// otherwise setting numParams to the appropriate value. | |||
4764 | bool Sema::CheckRegparmAttr(const ParsedAttr &AL, unsigned &numParams) { | |||
4765 | if (AL.isInvalid()) | |||
4766 | return true; | |||
4767 | ||||
4768 | if (!checkAttributeNumArgs(*this, AL, 1)) { | |||
4769 | AL.setInvalid(); | |||
4770 | return true; | |||
4771 | } | |||
4772 | ||||
4773 | uint32_t NP; | |||
4774 | Expr *NumParamsExpr = AL.getArgAsExpr(0); | |||
4775 | if (!checkUInt32Argument(*this, AL, NumParamsExpr, NP)) { | |||
4776 | AL.setInvalid(); | |||
4777 | return true; | |||
4778 | } | |||
4779 | ||||
4780 | if (Context.getTargetInfo().getRegParmMax() == 0) { | |||
4781 | Diag(AL.getLoc(), diag::err_attribute_regparm_wrong_platform) | |||
4782 | << NumParamsExpr->getSourceRange(); | |||
4783 | AL.setInvalid(); | |||
4784 | return true; | |||
4785 | } | |||
4786 | ||||
4787 | numParams = NP; | |||
4788 | if (numParams > Context.getTargetInfo().getRegParmMax()) { | |||
4789 | Diag(AL.getLoc(), diag::err_attribute_regparm_invalid_number) | |||
4790 | << Context.getTargetInfo().getRegParmMax() << NumParamsExpr->getSourceRange(); | |||
4791 | AL.setInvalid(); | |||
4792 | return true; | |||
4793 | } | |||
4794 | ||||
4795 | return false; | |||
4796 | } | |||
4797 | ||||
4798 | // Checks whether an argument of launch_bounds attribute is | |||
4799 | // acceptable, performs implicit conversion to Rvalue, and returns | |||
4800 | // non-nullptr Expr result on success. Otherwise, it returns nullptr | |||
4801 | // and may output an error. | |||
4802 | static Expr *makeLaunchBoundsArgExpr(Sema &S, Expr *E, | |||
4803 | const CUDALaunchBoundsAttr &AL, | |||
4804 | const unsigned Idx) { | |||
4805 | if (S.DiagnoseUnexpandedParameterPack(E)) | |||
4806 | return nullptr; | |||
4807 | ||||
4808 | // Accept template arguments for now as they depend on something else. | |||
4809 | // We'll get to check them when they eventually get instantiated. | |||
4810 | if (E->isValueDependent()) | |||
4811 | return E; | |||
4812 | ||||
4813 | llvm::APSInt I(64); | |||
4814 | if (!E->isIntegerConstantExpr(I, S.Context)) { | |||
4815 | S.Diag(E->getExprLoc(), diag::err_attribute_argument_n_type) | |||
4816 | << &AL << Idx << AANT_ArgumentIntegerConstant << E->getSourceRange(); | |||
4817 | return nullptr; | |||
4818 | } | |||
4819 | // Make sure we can fit it in 32 bits. | |||
4820 | if (!I.isIntN(32)) { | |||
4821 | S.Diag(E->getExprLoc(), diag::err_ice_too_large) << I.toString(10, false) | |||
4822 | << 32 << /* Unsigned */ 1; | |||
4823 | return nullptr; | |||
4824 | } | |||
4825 | if (I < 0) | |||
4826 | S.Diag(E->getExprLoc(), diag::warn_attribute_argument_n_negative) | |||
4827 | << &AL << Idx << E->getSourceRange(); | |||
4828 | ||||
4829 | // We may need to perform implicit conversion of the argument. | |||
4830 | InitializedEntity Entity = InitializedEntity::InitializeParameter( | |||
4831 | S.Context, S.Context.getConstType(S.Context.IntTy), /*consume*/ false); | |||
4832 | ExprResult ValArg = S.PerformCopyInitialization(Entity, SourceLocation(), E); | |||
4833 | assert(!ValArg.isInvalid() &&((!ValArg.isInvalid() && "Unexpected PerformCopyInitialization() failure." ) ? static_cast<void> (0) : __assert_fail ("!ValArg.isInvalid() && \"Unexpected PerformCopyInitialization() failure.\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 4834, __PRETTY_FUNCTION__)) | |||
4834 | "Unexpected PerformCopyInitialization() failure.")((!ValArg.isInvalid() && "Unexpected PerformCopyInitialization() failure." ) ? static_cast<void> (0) : __assert_fail ("!ValArg.isInvalid() && \"Unexpected PerformCopyInitialization() failure.\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 4834, __PRETTY_FUNCTION__)); | |||
4835 | ||||
4836 | return ValArg.getAs<Expr>(); | |||
4837 | } | |||
4838 | ||||
4839 | void Sema::AddLaunchBoundsAttr(SourceRange AttrRange, Decl *D, Expr *MaxThreads, | |||
4840 | Expr *MinBlocks, unsigned SpellingListIndex) { | |||
4841 | CUDALaunchBoundsAttr TmpAttr(AttrRange, Context, MaxThreads, MinBlocks, | |||
4842 | SpellingListIndex); | |||
4843 | MaxThreads = makeLaunchBoundsArgExpr(*this, MaxThreads, TmpAttr, 0); | |||
4844 | if (MaxThreads == nullptr) | |||
4845 | return; | |||
4846 | ||||
4847 | if (MinBlocks) { | |||
4848 | MinBlocks = makeLaunchBoundsArgExpr(*this, MinBlocks, TmpAttr, 1); | |||
4849 | if (MinBlocks == nullptr) | |||
4850 | return; | |||
4851 | } | |||
4852 | ||||
4853 | D->addAttr(::new (Context) CUDALaunchBoundsAttr( | |||
4854 | AttrRange, Context, MaxThreads, MinBlocks, SpellingListIndex)); | |||
4855 | } | |||
4856 | ||||
4857 | static void handleLaunchBoundsAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
4858 | if (!checkAttributeAtLeastNumArgs(S, AL, 1) || | |||
4859 | !checkAttributeAtMostNumArgs(S, AL, 2)) | |||
4860 | return; | |||
4861 | ||||
4862 | S.AddLaunchBoundsAttr(AL.getRange(), D, AL.getArgAsExpr(0), | |||
4863 | AL.getNumArgs() > 1 ? AL.getArgAsExpr(1) : nullptr, | |||
4864 | AL.getAttributeSpellingListIndex()); | |||
4865 | } | |||
4866 | ||||
4867 | static void handleArgumentWithTypeTagAttr(Sema &S, Decl *D, | |||
4868 | const ParsedAttr &AL) { | |||
4869 | if (!AL.isArgIdent(0)) { | |||
4870 | S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) | |||
4871 | << AL << /* arg num = */ 1 << AANT_ArgumentIdentifier; | |||
4872 | return; | |||
4873 | } | |||
4874 | ||||
4875 | ParamIdx ArgumentIdx; | |||
4876 | if (!checkFunctionOrMethodParameterIndex(S, D, AL, 2, AL.getArgAsExpr(1), | |||
4877 | ArgumentIdx)) | |||
4878 | return; | |||
4879 | ||||
4880 | ParamIdx TypeTagIdx; | |||
4881 | if (!checkFunctionOrMethodParameterIndex(S, D, AL, 3, AL.getArgAsExpr(2), | |||
4882 | TypeTagIdx)) | |||
4883 | return; | |||
4884 | ||||
4885 | bool IsPointer = AL.getName()->getName() == "pointer_with_type_tag"; | |||
4886 | if (IsPointer) { | |||
4887 | // Ensure that buffer has a pointer type. | |||
4888 | unsigned ArgumentIdxAST = ArgumentIdx.getASTIndex(); | |||
4889 | if (ArgumentIdxAST >= getFunctionOrMethodNumParams(D) || | |||
4890 | !getFunctionOrMethodParamType(D, ArgumentIdxAST)->isPointerType()) | |||
4891 | S.Diag(AL.getLoc(), diag::err_attribute_pointers_only) << AL << 0; | |||
4892 | } | |||
4893 | ||||
4894 | D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr( | |||
4895 | AL.getRange(), S.Context, AL.getArgAsIdent(0)->Ident, ArgumentIdx, | |||
4896 | TypeTagIdx, IsPointer, AL.getAttributeSpellingListIndex())); | |||
4897 | } | |||
4898 | ||||
4899 | static void handleTypeTagForDatatypeAttr(Sema &S, Decl *D, | |||
4900 | const ParsedAttr &AL) { | |||
4901 | if (!AL.isArgIdent(0)) { | |||
4902 | S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) | |||
4903 | << AL << 1 << AANT_ArgumentIdentifier; | |||
4904 | return; | |||
4905 | } | |||
4906 | ||||
4907 | if (!checkAttributeNumArgs(S, AL, 1)) | |||
4908 | return; | |||
4909 | ||||
4910 | if (!isa<VarDecl>(D)) { | |||
4911 | S.Diag(AL.getLoc(), diag::err_attribute_wrong_decl_type) | |||
4912 | << AL << ExpectedVariable; | |||
4913 | return; | |||
4914 | } | |||
4915 | ||||
4916 | IdentifierInfo *PointerKind = AL.getArgAsIdent(0)->Ident; | |||
4917 | TypeSourceInfo *MatchingCTypeLoc = nullptr; | |||
4918 | S.GetTypeFromParser(AL.getMatchingCType(), &MatchingCTypeLoc); | |||
4919 | assert(MatchingCTypeLoc && "no type source info for attribute argument")((MatchingCTypeLoc && "no type source info for attribute argument" ) ? static_cast<void> (0) : __assert_fail ("MatchingCTypeLoc && \"no type source info for attribute argument\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 4919, __PRETTY_FUNCTION__)); | |||
4920 | ||||
4921 | D->addAttr(::new (S.Context) | |||
4922 | TypeTagForDatatypeAttr(AL.getRange(), S.Context, PointerKind, | |||
4923 | MatchingCTypeLoc, | |||
4924 | AL.getLayoutCompatible(), | |||
4925 | AL.getMustBeNull(), | |||
4926 | AL.getAttributeSpellingListIndex())); | |||
4927 | } | |||
4928 | ||||
4929 | static void handleXRayLogArgsAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
4930 | ParamIdx ArgCount; | |||
4931 | ||||
4932 | if (!checkFunctionOrMethodParameterIndex(S, D, AL, 1, AL.getArgAsExpr(0), | |||
4933 | ArgCount, | |||
4934 | true /* CanIndexImplicitThis */)) | |||
4935 | return; | |||
4936 | ||||
4937 | // ArgCount isn't a parameter index [0;n), it's a count [1;n] | |||
4938 | D->addAttr(::new (S.Context) XRayLogArgsAttr( | |||
4939 | AL.getRange(), S.Context, ArgCount.getSourceIndex(), | |||
4940 | AL.getAttributeSpellingListIndex())); | |||
4941 | } | |||
4942 | ||||
4943 | //===----------------------------------------------------------------------===// | |||
4944 | // Checker-specific attribute handlers. | |||
4945 | //===----------------------------------------------------------------------===// | |||
4946 | static bool isValidSubjectOfNSReturnsRetainedAttribute(QualType QT) { | |||
4947 | return QT->isDependentType() || QT->isObjCRetainableType(); | |||
4948 | } | |||
4949 | ||||
4950 | static bool isValidSubjectOfNSAttribute(QualType QT) { | |||
4951 | return QT->isDependentType() || QT->isObjCObjectPointerType() || | |||
4952 | QT->isObjCNSObjectType(); | |||
4953 | } | |||
4954 | ||||
4955 | static bool isValidSubjectOfCFAttribute(QualType QT) { | |||
4956 | return QT->isDependentType() || QT->isPointerType() || | |||
4957 | isValidSubjectOfNSAttribute(QT); | |||
4958 | } | |||
4959 | ||||
4960 | static bool isValidSubjectOfOSAttribute(QualType QT) { | |||
4961 | if (QT->isDependentType()) | |||
4962 | return true; | |||
4963 | QualType PT = QT->getPointeeType(); | |||
4964 | return !PT.isNull() && PT->getAsCXXRecordDecl() != nullptr; | |||
4965 | } | |||
4966 | ||||
4967 | void Sema::AddXConsumedAttr(Decl *D, SourceRange SR, unsigned SpellingIndex, | |||
4968 | RetainOwnershipKind K, | |||
4969 | bool IsTemplateInstantiation) { | |||
4970 | ValueDecl *VD = cast<ValueDecl>(D); | |||
4971 | switch (K) { | |||
4972 | case RetainOwnershipKind::OS: | |||
4973 | handleSimpleAttributeOrDiagnose<OSConsumedAttr>( | |||
4974 | *this, VD, SR, SpellingIndex, isValidSubjectOfOSAttribute(VD->getType()), | |||
4975 | diag::warn_ns_attribute_wrong_parameter_type, | |||
4976 | /*ExtraArgs=*/SR, "os_consumed", /*pointers*/ 1); | |||
4977 | return; | |||
4978 | case RetainOwnershipKind::NS: | |||
4979 | handleSimpleAttributeOrDiagnose<NSConsumedAttr>( | |||
4980 | *this, VD, SR, SpellingIndex, isValidSubjectOfNSAttribute(VD->getType()), | |||
4981 | ||||
4982 | // These attributes are normally just advisory, but in ARC, ns_consumed | |||
4983 | // is significant. Allow non-dependent code to contain inappropriate | |||
4984 | // attributes even in ARC, but require template instantiations to be | |||
4985 | // set up correctly. | |||
4986 | ((IsTemplateInstantiation && getLangOpts().ObjCAutoRefCount) | |||
4987 | ? diag::err_ns_attribute_wrong_parameter_type | |||
4988 | : diag::warn_ns_attribute_wrong_parameter_type), | |||
4989 | /*ExtraArgs=*/SR, "ns_consumed", /*objc pointers*/ 0); | |||
4990 | return; | |||
4991 | case RetainOwnershipKind::CF: | |||
4992 | handleSimpleAttributeOrDiagnose<CFConsumedAttr>( | |||
4993 | *this, VD, SR, SpellingIndex, | |||
4994 | isValidSubjectOfCFAttribute(VD->getType()), | |||
4995 | diag::warn_ns_attribute_wrong_parameter_type, | |||
4996 | /*ExtraArgs=*/SR, "cf_consumed", /*pointers*/1); | |||
4997 | return; | |||
4998 | } | |||
4999 | } | |||
5000 | ||||
5001 | static Sema::RetainOwnershipKind | |||
5002 | parsedAttrToRetainOwnershipKind(const ParsedAttr &AL) { | |||
5003 | switch (AL.getKind()) { | |||
5004 | case ParsedAttr::AT_CFConsumed: | |||
5005 | case ParsedAttr::AT_CFReturnsRetained: | |||
5006 | case ParsedAttr::AT_CFReturnsNotRetained: | |||
5007 | return Sema::RetainOwnershipKind::CF; | |||
5008 | case ParsedAttr::AT_OSConsumesThis: | |||
5009 | case ParsedAttr::AT_OSConsumed: | |||
5010 | case ParsedAttr::AT_OSReturnsRetained: | |||
5011 | case ParsedAttr::AT_OSReturnsNotRetained: | |||
5012 | case ParsedAttr::AT_OSReturnsRetainedOnZero: | |||
5013 | case ParsedAttr::AT_OSReturnsRetainedOnNonZero: | |||
5014 | return Sema::RetainOwnershipKind::OS; | |||
5015 | case ParsedAttr::AT_NSConsumesSelf: | |||
5016 | case ParsedAttr::AT_NSConsumed: | |||
5017 | case ParsedAttr::AT_NSReturnsRetained: | |||
5018 | case ParsedAttr::AT_NSReturnsNotRetained: | |||
5019 | case ParsedAttr::AT_NSReturnsAutoreleased: | |||
5020 | return Sema::RetainOwnershipKind::NS; | |||
5021 | default: | |||
5022 | llvm_unreachable("Wrong argument supplied")::llvm::llvm_unreachable_internal("Wrong argument supplied", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 5022); | |||
5023 | } | |||
5024 | } | |||
5025 | ||||
5026 | bool Sema::checkNSReturnsRetainedReturnType(SourceLocation Loc, QualType QT) { | |||
5027 | if (isValidSubjectOfNSReturnsRetainedAttribute(QT)) | |||
5028 | return false; | |||
5029 | ||||
5030 | Diag(Loc, diag::warn_ns_attribute_wrong_return_type) | |||
5031 | << "'ns_returns_retained'" << 0 << 0; | |||
5032 | return true; | |||
5033 | } | |||
5034 | ||||
5035 | /// \return whether the parameter is a pointer to OSObject pointer. | |||
5036 | static bool isValidOSObjectOutParameter(const Decl *D) { | |||
5037 | const auto *PVD = dyn_cast<ParmVarDecl>(D); | |||
5038 | if (!PVD) | |||
5039 | return false; | |||
5040 | QualType QT = PVD->getType(); | |||
5041 | QualType PT = QT->getPointeeType(); | |||
5042 | return !PT.isNull() && isValidSubjectOfOSAttribute(PT); | |||
5043 | } | |||
5044 | ||||
5045 | static void handleXReturnsXRetainedAttr(Sema &S, Decl *D, | |||
5046 | const ParsedAttr &AL) { | |||
5047 | QualType ReturnType; | |||
5048 | Sema::RetainOwnershipKind K = parsedAttrToRetainOwnershipKind(AL); | |||
5049 | ||||
5050 | if (const auto *MD = dyn_cast<ObjCMethodDecl>(D)) { | |||
5051 | ReturnType = MD->getReturnType(); | |||
5052 | } else if (S.getLangOpts().ObjCAutoRefCount && hasDeclarator(D) && | |||
5053 | (AL.getKind() == ParsedAttr::AT_NSReturnsRetained)) { | |||
5054 | return; // ignore: was handled as a type attribute | |||
5055 | } else if (const auto *PD = dyn_cast<ObjCPropertyDecl>(D)) { | |||
5056 | ReturnType = PD->getType(); | |||
5057 | } else if (const auto *FD = dyn_cast<FunctionDecl>(D)) { | |||
5058 | ReturnType = FD->getReturnType(); | |||
5059 | } else if (const auto *Param = dyn_cast<ParmVarDecl>(D)) { | |||
5060 | // Attributes on parameters are used for out-parameters, | |||
5061 | // passed as pointers-to-pointers. | |||
5062 | unsigned DiagID = K == Sema::RetainOwnershipKind::CF | |||
5063 | ? /*pointer-to-CF-pointer*/2 | |||
5064 | : /*pointer-to-OSObject-pointer*/3; | |||
5065 | ReturnType = Param->getType()->getPointeeType(); | |||
5066 | if (ReturnType.isNull()) { | |||
5067 | S.Diag(D->getBeginLoc(), diag::warn_ns_attribute_wrong_parameter_type) | |||
5068 | << AL << DiagID << AL.getRange(); | |||
5069 | return; | |||
5070 | } | |||
5071 | } else if (AL.isUsedAsTypeAttr()) { | |||
5072 | return; | |||
5073 | } else { | |||
5074 | AttributeDeclKind ExpectedDeclKind; | |||
5075 | switch (AL.getKind()) { | |||
5076 | default: llvm_unreachable("invalid ownership attribute")::llvm::llvm_unreachable_internal("invalid ownership attribute" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 5076); | |||
5077 | case ParsedAttr::AT_NSReturnsRetained: | |||
5078 | case ParsedAttr::AT_NSReturnsAutoreleased: | |||
5079 | case ParsedAttr::AT_NSReturnsNotRetained: | |||
5080 | ExpectedDeclKind = ExpectedFunctionOrMethod; | |||
5081 | break; | |||
5082 | ||||
5083 | case ParsedAttr::AT_OSReturnsRetained: | |||
5084 | case ParsedAttr::AT_OSReturnsNotRetained: | |||
5085 | case ParsedAttr::AT_CFReturnsRetained: | |||
5086 | case ParsedAttr::AT_CFReturnsNotRetained: | |||
5087 | ExpectedDeclKind = ExpectedFunctionMethodOrParameter; | |||
5088 | break; | |||
5089 | } | |||
5090 | S.Diag(D->getBeginLoc(), diag::warn_attribute_wrong_decl_type) | |||
5091 | << AL.getRange() << AL << ExpectedDeclKind; | |||
5092 | return; | |||
5093 | } | |||
5094 | ||||
5095 | bool TypeOK; | |||
5096 | bool Cf; | |||
5097 | unsigned ParmDiagID = 2; // Pointer-to-CF-pointer | |||
5098 | switch (AL.getKind()) { | |||
5099 | default: llvm_unreachable("invalid ownership attribute")::llvm::llvm_unreachable_internal("invalid ownership attribute" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 5099); | |||
5100 | case ParsedAttr::AT_NSReturnsRetained: | |||
5101 | TypeOK = isValidSubjectOfNSReturnsRetainedAttribute(ReturnType); | |||
5102 | Cf = false; | |||
5103 | break; | |||
5104 | ||||
5105 | case ParsedAttr::AT_NSReturnsAutoreleased: | |||
5106 | case ParsedAttr::AT_NSReturnsNotRetained: | |||
5107 | TypeOK = isValidSubjectOfNSAttribute(ReturnType); | |||
5108 | Cf = false; | |||
5109 | break; | |||
5110 | ||||
5111 | case ParsedAttr::AT_CFReturnsRetained: | |||
5112 | case ParsedAttr::AT_CFReturnsNotRetained: | |||
5113 | TypeOK = isValidSubjectOfCFAttribute(ReturnType); | |||
5114 | Cf = true; | |||
5115 | break; | |||
5116 | ||||
5117 | case ParsedAttr::AT_OSReturnsRetained: | |||
5118 | case ParsedAttr::AT_OSReturnsNotRetained: | |||
5119 | TypeOK = isValidSubjectOfOSAttribute(ReturnType); | |||
5120 | Cf = true; | |||
5121 | ParmDiagID = 3; // Pointer-to-OSObject-pointer | |||
5122 | break; | |||
5123 | } | |||
5124 | ||||
5125 | if (!TypeOK) { | |||
5126 | if (AL.isUsedAsTypeAttr()) | |||
5127 | return; | |||
5128 | ||||
5129 | if (isa<ParmVarDecl>(D)) { | |||
5130 | S.Diag(D->getBeginLoc(), diag::warn_ns_attribute_wrong_parameter_type) | |||
5131 | << AL << ParmDiagID << AL.getRange(); | |||
5132 | } else { | |||
5133 | // Needs to be kept in sync with warn_ns_attribute_wrong_return_type. | |||
5134 | enum : unsigned { | |||
5135 | Function, | |||
5136 | Method, | |||
5137 | Property | |||
5138 | } SubjectKind = Function; | |||
5139 | if (isa<ObjCMethodDecl>(D)) | |||
5140 | SubjectKind = Method; | |||
5141 | else if (isa<ObjCPropertyDecl>(D)) | |||
5142 | SubjectKind = Property; | |||
5143 | S.Diag(D->getBeginLoc(), diag::warn_ns_attribute_wrong_return_type) | |||
5144 | << AL << SubjectKind << Cf << AL.getRange(); | |||
5145 | } | |||
5146 | return; | |||
5147 | } | |||
5148 | ||||
5149 | switch (AL.getKind()) { | |||
5150 | default: | |||
5151 | llvm_unreachable("invalid ownership attribute")::llvm::llvm_unreachable_internal("invalid ownership attribute" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 5151); | |||
5152 | case ParsedAttr::AT_NSReturnsAutoreleased: | |||
5153 | handleSimpleAttribute<NSReturnsAutoreleasedAttr>(S, D, AL); | |||
5154 | return; | |||
5155 | case ParsedAttr::AT_CFReturnsNotRetained: | |||
5156 | handleSimpleAttribute<CFReturnsNotRetainedAttr>(S, D, AL); | |||
5157 | return; | |||
5158 | case ParsedAttr::AT_NSReturnsNotRetained: | |||
5159 | handleSimpleAttribute<NSReturnsNotRetainedAttr>(S, D, AL); | |||
5160 | return; | |||
5161 | case ParsedAttr::AT_CFReturnsRetained: | |||
5162 | handleSimpleAttribute<CFReturnsRetainedAttr>(S, D, AL); | |||
5163 | return; | |||
5164 | case ParsedAttr::AT_NSReturnsRetained: | |||
5165 | handleSimpleAttribute<NSReturnsRetainedAttr>(S, D, AL); | |||
5166 | return; | |||
5167 | case ParsedAttr::AT_OSReturnsRetained: | |||
5168 | handleSimpleAttribute<OSReturnsRetainedAttr>(S, D, AL); | |||
5169 | return; | |||
5170 | case ParsedAttr::AT_OSReturnsNotRetained: | |||
5171 | handleSimpleAttribute<OSReturnsNotRetainedAttr>(S, D, AL); | |||
5172 | return; | |||
5173 | }; | |||
5174 | } | |||
5175 | ||||
5176 | static void handleObjCReturnsInnerPointerAttr(Sema &S, Decl *D, | |||
5177 | const ParsedAttr &Attrs) { | |||
5178 | const int EP_ObjCMethod = 1; | |||
5179 | const int EP_ObjCProperty = 2; | |||
5180 | ||||
5181 | SourceLocation loc = Attrs.getLoc(); | |||
5182 | QualType resultType; | |||
5183 | if (isa<ObjCMethodDecl>(D)) | |||
5184 | resultType = cast<ObjCMethodDecl>(D)->getReturnType(); | |||
5185 | else | |||
5186 | resultType = cast<ObjCPropertyDecl>(D)->getType(); | |||
5187 | ||||
5188 | if (!resultType->isReferenceType() && | |||
5189 | (!resultType->isPointerType() || resultType->isObjCRetainableType())) { | |||
5190 | S.Diag(D->getBeginLoc(), diag::warn_ns_attribute_wrong_return_type) | |||
5191 | << SourceRange(loc) << Attrs | |||
5192 | << (isa<ObjCMethodDecl>(D) ? EP_ObjCMethod : EP_ObjCProperty) | |||
5193 | << /*non-retainable pointer*/ 2; | |||
5194 | ||||
5195 | // Drop the attribute. | |||
5196 | return; | |||
5197 | } | |||
5198 | ||||
5199 | D->addAttr(::new (S.Context) ObjCReturnsInnerPointerAttr( | |||
5200 | Attrs.getRange(), S.Context, Attrs.getAttributeSpellingListIndex())); | |||
5201 | } | |||
5202 | ||||
5203 | static void handleObjCRequiresSuperAttr(Sema &S, Decl *D, | |||
5204 | const ParsedAttr &Attrs) { | |||
5205 | const auto *Method = cast<ObjCMethodDecl>(D); | |||
5206 | ||||
5207 | const DeclContext *DC = Method->getDeclContext(); | |||
5208 | if (const auto *PDecl = dyn_cast_or_null<ObjCProtocolDecl>(DC)) { | |||
5209 | S.Diag(D->getBeginLoc(), diag::warn_objc_requires_super_protocol) << Attrs | |||
5210 | << 0; | |||
5211 | S.Diag(PDecl->getLocation(), diag::note_protocol_decl); | |||
5212 | return; | |||
5213 | } | |||
5214 | if (Method->getMethodFamily() == OMF_dealloc) { | |||
5215 | S.Diag(D->getBeginLoc(), diag::warn_objc_requires_super_protocol) << Attrs | |||
5216 | << 1; | |||
5217 | return; | |||
5218 | } | |||
5219 | ||||
5220 | D->addAttr(::new (S.Context) ObjCRequiresSuperAttr( | |||
5221 | Attrs.getRange(), S.Context, Attrs.getAttributeSpellingListIndex())); | |||
5222 | } | |||
5223 | ||||
5224 | static void handleObjCBridgeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
5225 | IdentifierLoc *Parm = AL.isArgIdent(0) ? AL.getArgAsIdent(0) : nullptr; | |||
5226 | ||||
5227 | if (!Parm) { | |||
5228 | S.Diag(D->getBeginLoc(), diag::err_objc_attr_not_id) << AL << 0; | |||
5229 | return; | |||
5230 | } | |||
5231 | ||||
5232 | // Typedefs only allow objc_bridge(id) and have some additional checking. | |||
5233 | if (const auto *TD = dyn_cast<TypedefNameDecl>(D)) { | |||
5234 | if (!Parm->Ident->isStr("id")) { | |||
5235 | S.Diag(AL.getLoc(), diag::err_objc_attr_typedef_not_id) << AL; | |||
5236 | return; | |||
5237 | } | |||
5238 | ||||
5239 | // Only allow 'cv void *'. | |||
5240 | QualType T = TD->getUnderlyingType(); | |||
5241 | if (!T->isVoidPointerType()) { | |||
5242 | S.Diag(AL.getLoc(), diag::err_objc_attr_typedef_not_void_pointer); | |||
5243 | return; | |||
5244 | } | |||
5245 | } | |||
5246 | ||||
5247 | D->addAttr(::new (S.Context) | |||
5248 | ObjCBridgeAttr(AL.getRange(), S.Context, Parm->Ident, | |||
5249 | AL.getAttributeSpellingListIndex())); | |||
5250 | } | |||
5251 | ||||
5252 | static void handleObjCBridgeMutableAttr(Sema &S, Decl *D, | |||
5253 | const ParsedAttr &AL) { | |||
5254 | IdentifierLoc *Parm = AL.isArgIdent(0) ? AL.getArgAsIdent(0) : nullptr; | |||
5255 | ||||
5256 | if (!Parm) { | |||
5257 | S.Diag(D->getBeginLoc(), diag::err_objc_attr_not_id) << AL << 0; | |||
5258 | return; | |||
5259 | } | |||
5260 | ||||
5261 | D->addAttr(::new (S.Context) | |||
5262 | ObjCBridgeMutableAttr(AL.getRange(), S.Context, Parm->Ident, | |||
5263 | AL.getAttributeSpellingListIndex())); | |||
5264 | } | |||
5265 | ||||
5266 | static void handleObjCBridgeRelatedAttr(Sema &S, Decl *D, | |||
5267 | const ParsedAttr &AL) { | |||
5268 | IdentifierInfo *RelatedClass = | |||
5269 | AL.isArgIdent(0) ? AL.getArgAsIdent(0)->Ident : nullptr; | |||
5270 | if (!RelatedClass) { | |||
5271 | S.Diag(D->getBeginLoc(), diag::err_objc_attr_not_id) << AL << 0; | |||
5272 | return; | |||
5273 | } | |||
5274 | IdentifierInfo *ClassMethod = | |||
5275 | AL.getArgAsIdent(1) ? AL.getArgAsIdent(1)->Ident : nullptr; | |||
5276 | IdentifierInfo *InstanceMethod = | |||
5277 | AL.getArgAsIdent(2) ? AL.getArgAsIdent(2)->Ident : nullptr; | |||
5278 | D->addAttr(::new (S.Context) | |||
5279 | ObjCBridgeRelatedAttr(AL.getRange(), S.Context, RelatedClass, | |||
5280 | ClassMethod, InstanceMethod, | |||
5281 | AL.getAttributeSpellingListIndex())); | |||
5282 | } | |||
5283 | ||||
5284 | static void handleObjCDesignatedInitializer(Sema &S, Decl *D, | |||
5285 | const ParsedAttr &AL) { | |||
5286 | DeclContext *Ctx = D->getDeclContext(); | |||
5287 | ||||
5288 | // This attribute can only be applied to methods in interfaces or class | |||
5289 | // extensions. | |||
5290 | if (!isa<ObjCInterfaceDecl>(Ctx) && | |||
5291 | !(isa<ObjCCategoryDecl>(Ctx) && | |||
5292 | cast<ObjCCategoryDecl>(Ctx)->IsClassExtension())) { | |||
5293 | S.Diag(D->getLocation(), diag::err_designated_init_attr_non_init); | |||
5294 | return; | |||
5295 | } | |||
5296 | ||||
5297 | ObjCInterfaceDecl *IFace; | |||
5298 | if (auto *CatDecl = dyn_cast<ObjCCategoryDecl>(Ctx)) | |||
5299 | IFace = CatDecl->getClassInterface(); | |||
5300 | else | |||
5301 | IFace = cast<ObjCInterfaceDecl>(Ctx); | |||
5302 | ||||
5303 | if (!IFace) | |||
5304 | return; | |||
5305 | ||||
5306 | IFace->setHasDesignatedInitializers(); | |||
5307 | D->addAttr(::new (S.Context) | |||
5308 | ObjCDesignatedInitializerAttr(AL.getRange(), S.Context, | |||
5309 | AL.getAttributeSpellingListIndex())); | |||
5310 | } | |||
5311 | ||||
5312 | static void handleObjCRuntimeName(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
5313 | StringRef MetaDataName; | |||
5314 | if (!S.checkStringLiteralArgumentAttr(AL, 0, MetaDataName)) | |||
5315 | return; | |||
5316 | D->addAttr(::new (S.Context) | |||
5317 | ObjCRuntimeNameAttr(AL.getRange(), S.Context, | |||
5318 | MetaDataName, | |||
5319 | AL.getAttributeSpellingListIndex())); | |||
5320 | } | |||
5321 | ||||
5322 | // When a user wants to use objc_boxable with a union or struct | |||
5323 | // but they don't have access to the declaration (legacy/third-party code) | |||
5324 | // then they can 'enable' this feature with a typedef: | |||
5325 | // typedef struct __attribute((objc_boxable)) legacy_struct legacy_struct; | |||
5326 | static void handleObjCBoxable(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
5327 | bool notify = false; | |||
5328 | ||||
5329 | auto *RD = dyn_cast<RecordDecl>(D); | |||
5330 | if (RD && RD->getDefinition()) { | |||
5331 | RD = RD->getDefinition(); | |||
5332 | notify = true; | |||
5333 | } | |||
5334 | ||||
5335 | if (RD) { | |||
5336 | ObjCBoxableAttr *BoxableAttr = ::new (S.Context) | |||
5337 | ObjCBoxableAttr(AL.getRange(), S.Context, | |||
5338 | AL.getAttributeSpellingListIndex()); | |||
5339 | RD->addAttr(BoxableAttr); | |||
5340 | if (notify) { | |||
5341 | // we need to notify ASTReader/ASTWriter about | |||
5342 | // modification of existing declaration | |||
5343 | if (ASTMutationListener *L = S.getASTMutationListener()) | |||
5344 | L->AddedAttributeToRecord(BoxableAttr, RD); | |||
5345 | } | |||
5346 | } | |||
5347 | } | |||
5348 | ||||
5349 | static void handleObjCOwnershipAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
5350 | if (hasDeclarator(D)) return; | |||
5351 | ||||
5352 | S.Diag(D->getBeginLoc(), diag::err_attribute_wrong_decl_type) | |||
5353 | << AL.getRange() << AL << ExpectedVariable; | |||
5354 | } | |||
5355 | ||||
5356 | static void handleObjCPreciseLifetimeAttr(Sema &S, Decl *D, | |||
5357 | const ParsedAttr &AL) { | |||
5358 | const auto *VD = cast<ValueDecl>(D); | |||
5359 | QualType QT = VD->getType(); | |||
5360 | ||||
5361 | if (!QT->isDependentType() && | |||
5362 | !QT->isObjCLifetimeType()) { | |||
5363 | S.Diag(AL.getLoc(), diag::err_objc_precise_lifetime_bad_type) | |||
5364 | << QT; | |||
5365 | return; | |||
5366 | } | |||
5367 | ||||
5368 | Qualifiers::ObjCLifetime Lifetime = QT.getObjCLifetime(); | |||
5369 | ||||
5370 | // If we have no lifetime yet, check the lifetime we're presumably | |||
5371 | // going to infer. | |||
5372 | if (Lifetime == Qualifiers::OCL_None && !QT->isDependentType()) | |||
5373 | Lifetime = QT->getObjCARCImplicitLifetime(); | |||
5374 | ||||
5375 | switch (Lifetime) { | |||
5376 | case Qualifiers::OCL_None: | |||
5377 | assert(QT->isDependentType() &&((QT->isDependentType() && "didn't infer lifetime for non-dependent type?" ) ? static_cast<void> (0) : __assert_fail ("QT->isDependentType() && \"didn't infer lifetime for non-dependent type?\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 5378, __PRETTY_FUNCTION__)) | |||
5378 | "didn't infer lifetime for non-dependent type?")((QT->isDependentType() && "didn't infer lifetime for non-dependent type?" ) ? static_cast<void> (0) : __assert_fail ("QT->isDependentType() && \"didn't infer lifetime for non-dependent type?\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 5378, __PRETTY_FUNCTION__)); | |||
5379 | break; | |||
5380 | ||||
5381 | case Qualifiers::OCL_Weak: // meaningful | |||
5382 | case Qualifiers::OCL_Strong: // meaningful | |||
5383 | break; | |||
5384 | ||||
5385 | case Qualifiers::OCL_ExplicitNone: | |||
5386 | case Qualifiers::OCL_Autoreleasing: | |||
5387 | S.Diag(AL.getLoc(), diag::warn_objc_precise_lifetime_meaningless) | |||
5388 | << (Lifetime == Qualifiers::OCL_Autoreleasing); | |||
5389 | break; | |||
5390 | } | |||
5391 | ||||
5392 | D->addAttr(::new (S.Context) | |||
5393 | ObjCPreciseLifetimeAttr(AL.getRange(), S.Context, | |||
5394 | AL.getAttributeSpellingListIndex())); | |||
5395 | } | |||
5396 | ||||
5397 | //===----------------------------------------------------------------------===// | |||
5398 | // Microsoft specific attribute handlers. | |||
5399 | //===----------------------------------------------------------------------===// | |||
5400 | ||||
5401 | UuidAttr *Sema::mergeUuidAttr(Decl *D, SourceRange Range, | |||
5402 | unsigned AttrSpellingListIndex, StringRef Uuid) { | |||
5403 | if (const auto *UA = D->getAttr<UuidAttr>()) { | |||
5404 | if (UA->getGuid().equals_lower(Uuid)) | |||
5405 | return nullptr; | |||
5406 | Diag(UA->getLocation(), diag::err_mismatched_uuid); | |||
5407 | Diag(Range.getBegin(), diag::note_previous_uuid); | |||
5408 | D->dropAttr<UuidAttr>(); | |||
5409 | } | |||
5410 | ||||
5411 | return ::new (Context) UuidAttr(Range, Context, Uuid, AttrSpellingListIndex); | |||
5412 | } | |||
5413 | ||||
5414 | static void handleUuidAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
5415 | if (!S.LangOpts.CPlusPlus) { | |||
5416 | S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang) | |||
5417 | << AL << AttributeLangSupport::C; | |||
5418 | return; | |||
5419 | } | |||
5420 | ||||
5421 | StringRef StrRef; | |||
5422 | SourceLocation LiteralLoc; | |||
5423 | if (!S.checkStringLiteralArgumentAttr(AL, 0, StrRef, &LiteralLoc)) | |||
5424 | return; | |||
5425 | ||||
5426 | // GUID format is "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" or | |||
5427 | // "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}", normalize to the former. | |||
5428 | if (StrRef.size() == 38 && StrRef.front() == '{' && StrRef.back() == '}') | |||
5429 | StrRef = StrRef.drop_front().drop_back(); | |||
5430 | ||||
5431 | // Validate GUID length. | |||
5432 | if (StrRef.size() != 36) { | |||
5433 | S.Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid); | |||
5434 | return; | |||
5435 | } | |||
5436 | ||||
5437 | for (unsigned i = 0; i < 36; ++i) { | |||
5438 | if (i == 8 || i == 13 || i == 18 || i == 23) { | |||
5439 | if (StrRef[i] != '-') { | |||
5440 | S.Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid); | |||
5441 | return; | |||
5442 | } | |||
5443 | } else if (!isHexDigit(StrRef[i])) { | |||
5444 | S.Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid); | |||
5445 | return; | |||
5446 | } | |||
5447 | } | |||
5448 | ||||
5449 | // FIXME: It'd be nice to also emit a fixit removing uuid(...) (and, if it's | |||
5450 | // the only thing in the [] list, the [] too), and add an insertion of | |||
5451 | // __declspec(uuid(...)). But sadly, neither the SourceLocs of the commas | |||
5452 | // separating attributes nor of the [ and the ] are in the AST. | |||
5453 | // Cf "SourceLocations of attribute list delimiters - [[ ... , ... ]] etc" | |||
5454 | // on cfe-dev. | |||
5455 | if (AL.isMicrosoftAttribute()) // Check for [uuid(...)] spelling. | |||
5456 | S.Diag(AL.getLoc(), diag::warn_atl_uuid_deprecated); | |||
5457 | ||||
5458 | UuidAttr *UA = S.mergeUuidAttr(D, AL.getRange(), | |||
5459 | AL.getAttributeSpellingListIndex(), StrRef); | |||
5460 | if (UA) | |||
5461 | D->addAttr(UA); | |||
5462 | } | |||
5463 | ||||
5464 | static void handleMSInheritanceAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
5465 | if (!S.LangOpts.CPlusPlus) { | |||
5466 | S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang) | |||
5467 | << AL << AttributeLangSupport::C; | |||
5468 | return; | |||
5469 | } | |||
5470 | MSInheritanceAttr *IA = S.mergeMSInheritanceAttr( | |||
5471 | D, AL.getRange(), /*BestCase=*/true, | |||
5472 | AL.getAttributeSpellingListIndex(), | |||
5473 | (MSInheritanceAttr::Spelling)AL.getSemanticSpelling()); | |||
5474 | if (IA) { | |||
5475 | D->addAttr(IA); | |||
5476 | S.Consumer.AssignInheritanceModel(cast<CXXRecordDecl>(D)); | |||
5477 | } | |||
5478 | } | |||
5479 | ||||
5480 | static void handleDeclspecThreadAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
5481 | const auto *VD = cast<VarDecl>(D); | |||
5482 | if (!S.Context.getTargetInfo().isTLSSupported()) { | |||
5483 | S.Diag(AL.getLoc(), diag::err_thread_unsupported); | |||
5484 | return; | |||
5485 | } | |||
5486 | if (VD->getTSCSpec() != TSCS_unspecified) { | |||
5487 | S.Diag(AL.getLoc(), diag::err_declspec_thread_on_thread_variable); | |||
5488 | return; | |||
5489 | } | |||
5490 | if (VD->hasLocalStorage()) { | |||
5491 | S.Diag(AL.getLoc(), diag::err_thread_non_global) << "__declspec(thread)"; | |||
5492 | return; | |||
5493 | } | |||
5494 | D->addAttr(::new (S.Context) ThreadAttr(AL.getRange(), S.Context, | |||
5495 | AL.getAttributeSpellingListIndex())); | |||
5496 | } | |||
5497 | ||||
5498 | static void handleAbiTagAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
5499 | SmallVector<StringRef, 4> Tags; | |||
5500 | for (unsigned I = 0, E = AL.getNumArgs(); I != E; ++I) { | |||
5501 | StringRef Tag; | |||
5502 | if (!S.checkStringLiteralArgumentAttr(AL, I, Tag)) | |||
5503 | return; | |||
5504 | Tags.push_back(Tag); | |||
5505 | } | |||
5506 | ||||
5507 | if (const auto *NS = dyn_cast<NamespaceDecl>(D)) { | |||
5508 | if (!NS->isInline()) { | |||
5509 | S.Diag(AL.getLoc(), diag::warn_attr_abi_tag_namespace) << 0; | |||
5510 | return; | |||
5511 | } | |||
5512 | if (NS->isAnonymousNamespace()) { | |||
5513 | S.Diag(AL.getLoc(), diag::warn_attr_abi_tag_namespace) << 1; | |||
5514 | return; | |||
5515 | } | |||
5516 | if (AL.getNumArgs() == 0) | |||
5517 | Tags.push_back(NS->getName()); | |||
5518 | } else if (!checkAttributeAtLeastNumArgs(S, AL, 1)) | |||
5519 | return; | |||
5520 | ||||
5521 | // Store tags sorted and without duplicates. | |||
5522 | llvm::sort(Tags); | |||
5523 | Tags.erase(std::unique(Tags.begin(), Tags.end()), Tags.end()); | |||
5524 | ||||
5525 | D->addAttr(::new (S.Context) | |||
5526 | AbiTagAttr(AL.getRange(), S.Context, Tags.data(), Tags.size(), | |||
5527 | AL.getAttributeSpellingListIndex())); | |||
5528 | } | |||
5529 | ||||
5530 | static void handleARMInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
5531 | // Check the attribute arguments. | |||
5532 | if (AL.getNumArgs() > 1) { | |||
5533 | S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 1; | |||
5534 | return; | |||
5535 | } | |||
5536 | ||||
5537 | StringRef Str; | |||
5538 | SourceLocation ArgLoc; | |||
5539 | ||||
5540 | if (AL.getNumArgs() == 0) | |||
5541 | Str = ""; | |||
5542 | else if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &ArgLoc)) | |||
5543 | return; | |||
5544 | ||||
5545 | ARMInterruptAttr::InterruptType Kind; | |||
5546 | if (!ARMInterruptAttr::ConvertStrToInterruptType(Str, Kind)) { | |||
5547 | S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << Str | |||
5548 | << ArgLoc; | |||
5549 | return; | |||
5550 | } | |||
5551 | ||||
5552 | unsigned Index = AL.getAttributeSpellingListIndex(); | |||
5553 | D->addAttr(::new (S.Context) | |||
5554 | ARMInterruptAttr(AL.getLoc(), S.Context, Kind, Index)); | |||
5555 | } | |||
5556 | ||||
5557 | static void handleMSP430InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
5558 | // MSP430 'interrupt' attribute is applied to | |||
5559 | // a function with no parameters and void return type. | |||
5560 | if (!isFunctionOrMethod(D)) { | |||
5561 | S.Diag(D->getLocation(), diag::warn_attribute_wrong_decl_type) | |||
5562 | << "'interrupt'" << ExpectedFunctionOrMethod; | |||
5563 | return; | |||
5564 | } | |||
5565 | ||||
5566 | if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) { | |||
5567 | S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid) | |||
5568 | << /*MSP430*/ 1 << 0; | |||
5569 | return; | |||
5570 | } | |||
5571 | ||||
5572 | if (!getFunctionOrMethodResultType(D)->isVoidType()) { | |||
5573 | S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid) | |||
5574 | << /*MSP430*/ 1 << 1; | |||
5575 | return; | |||
5576 | } | |||
5577 | ||||
5578 | // The attribute takes one integer argument. | |||
5579 | if (!checkAttributeNumArgs(S, AL, 1)) | |||
5580 | return; | |||
5581 | ||||
5582 | if (!AL.isArgExpr(0)) { | |||
5583 | S.Diag(AL.getLoc(), diag::err_attribute_argument_type) | |||
5584 | << AL << AANT_ArgumentIntegerConstant; | |||
5585 | return; | |||
5586 | } | |||
5587 | ||||
5588 | Expr *NumParamsExpr = static_cast<Expr *>(AL.getArgAsExpr(0)); | |||
5589 | llvm::APSInt NumParams(32); | |||
5590 | if (!NumParamsExpr->isIntegerConstantExpr(NumParams, S.Context)) { | |||
5591 | S.Diag(AL.getLoc(), diag::err_attribute_argument_type) | |||
5592 | << AL << AANT_ArgumentIntegerConstant | |||
5593 | << NumParamsExpr->getSourceRange(); | |||
5594 | return; | |||
5595 | } | |||
5596 | // The argument should be in range 0..63. | |||
5597 | unsigned Num = NumParams.getLimitedValue(255); | |||
5598 | if (Num > 63) { | |||
5599 | S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds) | |||
5600 | << AL << (int)NumParams.getSExtValue() | |||
5601 | << NumParamsExpr->getSourceRange(); | |||
5602 | return; | |||
5603 | } | |||
5604 | ||||
5605 | D->addAttr(::new (S.Context) | |||
5606 | MSP430InterruptAttr(AL.getLoc(), S.Context, Num, | |||
5607 | AL.getAttributeSpellingListIndex())); | |||
5608 | D->addAttr(UsedAttr::CreateImplicit(S.Context)); | |||
5609 | } | |||
5610 | ||||
5611 | static void handleMipsInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
5612 | // Only one optional argument permitted. | |||
5613 | if (AL.getNumArgs() > 1) { | |||
5614 | S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 1; | |||
5615 | return; | |||
5616 | } | |||
5617 | ||||
5618 | StringRef Str; | |||
5619 | SourceLocation ArgLoc; | |||
5620 | ||||
5621 | if (AL.getNumArgs() == 0) | |||
5622 | Str = ""; | |||
5623 | else if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &ArgLoc)) | |||
5624 | return; | |||
5625 | ||||
5626 | // Semantic checks for a function with the 'interrupt' attribute for MIPS: | |||
5627 | // a) Must be a function. | |||
5628 | // b) Must have no parameters. | |||
5629 | // c) Must have the 'void' return type. | |||
5630 | // d) Cannot have the 'mips16' attribute, as that instruction set | |||
5631 | // lacks the 'eret' instruction. | |||
5632 | // e) The attribute itself must either have no argument or one of the | |||
5633 | // valid interrupt types, see [MipsInterruptDocs]. | |||
5634 | ||||
5635 | if (!isFunctionOrMethod(D)) { | |||
5636 | S.Diag(D->getLocation(), diag::warn_attribute_wrong_decl_type) | |||
5637 | << "'interrupt'" << ExpectedFunctionOrMethod; | |||
5638 | return; | |||
5639 | } | |||
5640 | ||||
5641 | if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) { | |||
5642 | S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid) | |||
5643 | << /*MIPS*/ 0 << 0; | |||
5644 | return; | |||
5645 | } | |||
5646 | ||||
5647 | if (!getFunctionOrMethodResultType(D)->isVoidType()) { | |||
5648 | S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid) | |||
5649 | << /*MIPS*/ 0 << 1; | |||
5650 | return; | |||
5651 | } | |||
5652 | ||||
5653 | if (checkAttrMutualExclusion<Mips16Attr>(S, D, AL)) | |||
5654 | return; | |||
5655 | ||||
5656 | MipsInterruptAttr::InterruptType Kind; | |||
5657 | if (!MipsInterruptAttr::ConvertStrToInterruptType(Str, Kind)) { | |||
5658 | S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) | |||
5659 | << AL << "'" + std::string(Str) + "'"; | |||
5660 | return; | |||
5661 | } | |||
5662 | ||||
5663 | D->addAttr(::new (S.Context) MipsInterruptAttr( | |||
5664 | AL.getLoc(), S.Context, Kind, AL.getAttributeSpellingListIndex())); | |||
5665 | } | |||
5666 | ||||
5667 | static void handleAnyX86InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
5668 | // Semantic checks for a function with the 'interrupt' attribute. | |||
5669 | // a) Must be a function. | |||
5670 | // b) Must have the 'void' return type. | |||
5671 | // c) Must take 1 or 2 arguments. | |||
5672 | // d) The 1st argument must be a pointer. | |||
5673 | // e) The 2nd argument (if any) must be an unsigned integer. | |||
5674 | if (!isFunctionOrMethod(D) || !hasFunctionProto(D) || isInstanceMethod(D) || | |||
5675 | CXXMethodDecl::isStaticOverloadedOperator( | |||
5676 | cast<NamedDecl>(D)->getDeclName().getCXXOverloadedOperator())) { | |||
5677 | S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type) | |||
5678 | << AL << ExpectedFunctionWithProtoType; | |||
5679 | return; | |||
5680 | } | |||
5681 | // Interrupt handler must have void return type. | |||
5682 | if (!getFunctionOrMethodResultType(D)->isVoidType()) { | |||
5683 | S.Diag(getFunctionOrMethodResultSourceRange(D).getBegin(), | |||
5684 | diag::err_anyx86_interrupt_attribute) | |||
5685 | << (S.Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86 | |||
5686 | ? 0 | |||
5687 | : 1) | |||
5688 | << 0; | |||
5689 | return; | |||
5690 | } | |||
5691 | // Interrupt handler must have 1 or 2 parameters. | |||
5692 | unsigned NumParams = getFunctionOrMethodNumParams(D); | |||
5693 | if (NumParams < 1 || NumParams > 2) { | |||
5694 | S.Diag(D->getBeginLoc(), diag::err_anyx86_interrupt_attribute) | |||
5695 | << (S.Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86 | |||
5696 | ? 0 | |||
5697 | : 1) | |||
5698 | << 1; | |||
5699 | return; | |||
5700 | } | |||
5701 | // The first argument must be a pointer. | |||
5702 | if (!getFunctionOrMethodParamType(D, 0)->isPointerType()) { | |||
5703 | S.Diag(getFunctionOrMethodParamRange(D, 0).getBegin(), | |||
5704 | diag::err_anyx86_interrupt_attribute) | |||
5705 | << (S.Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86 | |||
5706 | ? 0 | |||
5707 | : 1) | |||
5708 | << 2; | |||
5709 | return; | |||
5710 | } | |||
5711 | // The second argument, if present, must be an unsigned integer. | |||
5712 | unsigned TypeSize = | |||
5713 | S.Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86_64 | |||
5714 | ? 64 | |||
5715 | : 32; | |||
5716 | if (NumParams == 2 && | |||
5717 | (!getFunctionOrMethodParamType(D, 1)->isUnsignedIntegerType() || | |||
5718 | S.Context.getTypeSize(getFunctionOrMethodParamType(D, 1)) != TypeSize)) { | |||
5719 | S.Diag(getFunctionOrMethodParamRange(D, 1).getBegin(), | |||
5720 | diag::err_anyx86_interrupt_attribute) | |||
5721 | << (S.Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86 | |||
5722 | ? 0 | |||
5723 | : 1) | |||
5724 | << 3 << S.Context.getIntTypeForBitwidth(TypeSize, /*Signed=*/false); | |||
5725 | return; | |||
5726 | } | |||
5727 | D->addAttr(::new (S.Context) AnyX86InterruptAttr( | |||
5728 | AL.getLoc(), S.Context, AL.getAttributeSpellingListIndex())); | |||
5729 | D->addAttr(UsedAttr::CreateImplicit(S.Context)); | |||
5730 | } | |||
5731 | ||||
5732 | static void handleAVRInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
5733 | if (!isFunctionOrMethod(D)) { | |||
5734 | S.Diag(D->getLocation(), diag::warn_attribute_wrong_decl_type) | |||
5735 | << "'interrupt'" << ExpectedFunction; | |||
5736 | return; | |||
5737 | } | |||
5738 | ||||
5739 | if (!checkAttributeNumArgs(S, AL, 0)) | |||
5740 | return; | |||
5741 | ||||
5742 | handleSimpleAttribute<AVRInterruptAttr>(S, D, AL); | |||
5743 | } | |||
5744 | ||||
5745 | static void handleAVRSignalAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
5746 | if (!isFunctionOrMethod(D)) { | |||
5747 | S.Diag(D->getLocation(), diag::warn_attribute_wrong_decl_type) | |||
5748 | << "'signal'" << ExpectedFunction; | |||
5749 | return; | |||
5750 | } | |||
5751 | ||||
5752 | if (!checkAttributeNumArgs(S, AL, 0)) | |||
5753 | return; | |||
5754 | ||||
5755 | handleSimpleAttribute<AVRSignalAttr>(S, D, AL); | |||
5756 | } | |||
5757 | ||||
5758 | static void handleWebAssemblyImportModuleAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
5759 | if (!isFunctionOrMethod(D)) { | |||
5760 | S.Diag(D->getLocation(), diag::warn_attribute_wrong_decl_type) | |||
5761 | << "'import_module'" << ExpectedFunction; | |||
5762 | return; | |||
5763 | } | |||
5764 | ||||
5765 | auto *FD = cast<FunctionDecl>(D); | |||
5766 | if (FD->isThisDeclarationADefinition()) { | |||
5767 | S.Diag(D->getLocation(), diag::err_alias_is_definition) << FD << 0; | |||
5768 | return; | |||
5769 | } | |||
5770 | ||||
5771 | StringRef Str; | |||
5772 | SourceLocation ArgLoc; | |||
5773 | if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &ArgLoc)) | |||
5774 | return; | |||
5775 | ||||
5776 | FD->addAttr(::new (S.Context) WebAssemblyImportModuleAttr( | |||
5777 | AL.getRange(), S.Context, Str, | |||
5778 | AL.getAttributeSpellingListIndex())); | |||
5779 | } | |||
5780 | ||||
5781 | static void handleWebAssemblyImportNameAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
5782 | if (!isFunctionOrMethod(D)) { | |||
5783 | S.Diag(D->getLocation(), diag::warn_attribute_wrong_decl_type) | |||
5784 | << "'import_name'" << ExpectedFunction; | |||
5785 | return; | |||
5786 | } | |||
5787 | ||||
5788 | auto *FD = cast<FunctionDecl>(D); | |||
5789 | if (FD->isThisDeclarationADefinition()) { | |||
5790 | S.Diag(D->getLocation(), diag::err_alias_is_definition) << FD << 0; | |||
5791 | return; | |||
5792 | } | |||
5793 | ||||
5794 | StringRef Str; | |||
5795 | SourceLocation ArgLoc; | |||
5796 | if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &ArgLoc)) | |||
5797 | return; | |||
5798 | ||||
5799 | FD->addAttr(::new (S.Context) WebAssemblyImportNameAttr( | |||
5800 | AL.getRange(), S.Context, Str, | |||
5801 | AL.getAttributeSpellingListIndex())); | |||
5802 | } | |||
5803 | ||||
5804 | static void handleRISCVInterruptAttr(Sema &S, Decl *D, | |||
5805 | const ParsedAttr &AL) { | |||
5806 | // Warn about repeated attributes. | |||
5807 | if (const auto *A = D->getAttr<RISCVInterruptAttr>()) { | |||
5808 | S.Diag(AL.getRange().getBegin(), | |||
5809 | diag::warn_riscv_repeated_interrupt_attribute); | |||
5810 | S.Diag(A->getLocation(), diag::note_riscv_repeated_interrupt_attribute); | |||
5811 | return; | |||
5812 | } | |||
5813 | ||||
5814 | // Check the attribute argument. Argument is optional. | |||
5815 | if (!checkAttributeAtMostNumArgs(S, AL, 1)) | |||
5816 | return; | |||
5817 | ||||
5818 | StringRef Str; | |||
5819 | SourceLocation ArgLoc; | |||
5820 | ||||
5821 | // 'machine'is the default interrupt mode. | |||
5822 | if (AL.getNumArgs() == 0) | |||
5823 | Str = "machine"; | |||
5824 | else if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &ArgLoc)) | |||
5825 | return; | |||
5826 | ||||
5827 | // Semantic checks for a function with the 'interrupt' attribute: | |||
5828 | // - Must be a function. | |||
5829 | // - Must have no parameters. | |||
5830 | // - Must have the 'void' return type. | |||
5831 | // - The attribute itself must either have no argument or one of the | |||
5832 | // valid interrupt types, see [RISCVInterruptDocs]. | |||
5833 | ||||
5834 | if (D->getFunctionType() == nullptr) { | |||
5835 | S.Diag(D->getLocation(), diag::warn_attribute_wrong_decl_type) | |||
5836 | << "'interrupt'" << ExpectedFunction; | |||
5837 | return; | |||
5838 | } | |||
5839 | ||||
5840 | if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) { | |||
5841 | S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid) | |||
5842 | << /*RISC-V*/ 2 << 0; | |||
5843 | return; | |||
5844 | } | |||
5845 | ||||
5846 | if (!getFunctionOrMethodResultType(D)->isVoidType()) { | |||
5847 | S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid) | |||
5848 | << /*RISC-V*/ 2 << 1; | |||
5849 | return; | |||
5850 | } | |||
5851 | ||||
5852 | RISCVInterruptAttr::InterruptType Kind; | |||
5853 | if (!RISCVInterruptAttr::ConvertStrToInterruptType(Str, Kind)) { | |||
5854 | S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << Str | |||
5855 | << ArgLoc; | |||
5856 | return; | |||
5857 | } | |||
5858 | ||||
5859 | D->addAttr(::new (S.Context) RISCVInterruptAttr( | |||
5860 | AL.getLoc(), S.Context, Kind, AL.getAttributeSpellingListIndex())); | |||
5861 | } | |||
5862 | ||||
5863 | static void handleInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
5864 | // Dispatch the interrupt attribute based on the current target. | |||
5865 | switch (S.Context.getTargetInfo().getTriple().getArch()) { | |||
5866 | case llvm::Triple::msp430: | |||
5867 | handleMSP430InterruptAttr(S, D, AL); | |||
5868 | break; | |||
5869 | case llvm::Triple::mipsel: | |||
5870 | case llvm::Triple::mips: | |||
5871 | handleMipsInterruptAttr(S, D, AL); | |||
5872 | break; | |||
5873 | case llvm::Triple::x86: | |||
5874 | case llvm::Triple::x86_64: | |||
5875 | handleAnyX86InterruptAttr(S, D, AL); | |||
5876 | break; | |||
5877 | case llvm::Triple::avr: | |||
5878 | handleAVRInterruptAttr(S, D, AL); | |||
5879 | break; | |||
5880 | case llvm::Triple::riscv32: | |||
5881 | case llvm::Triple::riscv64: | |||
5882 | handleRISCVInterruptAttr(S, D, AL); | |||
5883 | break; | |||
5884 | default: | |||
5885 | handleARMInterruptAttr(S, D, AL); | |||
5886 | break; | |||
5887 | } | |||
5888 | } | |||
5889 | ||||
5890 | static bool | |||
5891 | checkAMDGPUFlatWorkGroupSizeArguments(Sema &S, Expr *MinExpr, Expr *MaxExpr, | |||
5892 | const AMDGPUFlatWorkGroupSizeAttr &Attr) { | |||
5893 | // Accept template arguments for now as they depend on something else. | |||
5894 | // We'll get to check them when they eventually get instantiated. | |||
5895 | if (MinExpr->isValueDependent() || MaxExpr->isValueDependent()) | |||
5896 | return false; | |||
5897 | ||||
5898 | uint32_t Min = 0; | |||
5899 | if (!checkUInt32Argument(S, Attr, MinExpr, Min, 0)) | |||
5900 | return true; | |||
5901 | ||||
5902 | uint32_t Max = 0; | |||
5903 | if (!checkUInt32Argument(S, Attr, MaxExpr, Max, 1)) | |||
5904 | return true; | |||
5905 | ||||
5906 | if (Min == 0 && Max != 0) { | |||
5907 | S.Diag(Attr.getLocation(), diag::err_attribute_argument_invalid) | |||
5908 | << &Attr << 0; | |||
5909 | return true; | |||
5910 | } | |||
5911 | if (Min > Max) { | |||
5912 | S.Diag(Attr.getLocation(), diag::err_attribute_argument_invalid) | |||
5913 | << &Attr << 1; | |||
5914 | return true; | |||
5915 | } | |||
5916 | ||||
5917 | return false; | |||
5918 | } | |||
5919 | ||||
5920 | void Sema::addAMDGPUFlatWorkGroupSizeAttr(SourceRange AttrRange, Decl *D, | |||
5921 | Expr *MinExpr, Expr *MaxExpr, | |||
5922 | unsigned SpellingListIndex) { | |||
5923 | AMDGPUFlatWorkGroupSizeAttr TmpAttr(AttrRange, Context, MinExpr, MaxExpr, | |||
5924 | SpellingListIndex); | |||
5925 | ||||
5926 | if (checkAMDGPUFlatWorkGroupSizeArguments(*this, MinExpr, MaxExpr, TmpAttr)) | |||
5927 | return; | |||
5928 | ||||
5929 | D->addAttr(::new (Context) AMDGPUFlatWorkGroupSizeAttr( | |||
5930 | AttrRange, Context, MinExpr, MaxExpr, SpellingListIndex)); | |||
5931 | } | |||
5932 | ||||
5933 | static void handleAMDGPUFlatWorkGroupSizeAttr(Sema &S, Decl *D, | |||
5934 | const ParsedAttr &AL) { | |||
5935 | Expr *MinExpr = AL.getArgAsExpr(0); | |||
5936 | Expr *MaxExpr = AL.getArgAsExpr(1); | |||
5937 | ||||
5938 | S.addAMDGPUFlatWorkGroupSizeAttr(AL.getRange(), D, MinExpr, MaxExpr, | |||
5939 | AL.getAttributeSpellingListIndex()); | |||
5940 | } | |||
5941 | ||||
5942 | static bool checkAMDGPUWavesPerEUArguments(Sema &S, Expr *MinExpr, | |||
5943 | Expr *MaxExpr, | |||
5944 | const AMDGPUWavesPerEUAttr &Attr) { | |||
5945 | if (S.DiagnoseUnexpandedParameterPack(MinExpr) || | |||
5946 | (MaxExpr && S.DiagnoseUnexpandedParameterPack(MaxExpr))) | |||
5947 | return true; | |||
5948 | ||||
5949 | // Accept template arguments for now as they depend on something else. | |||
5950 | // We'll get to check them when they eventually get instantiated. | |||
5951 | if (MinExpr->isValueDependent() || (MaxExpr && MaxExpr->isValueDependent())) | |||
5952 | return false; | |||
5953 | ||||
5954 | uint32_t Min = 0; | |||
5955 | if (!checkUInt32Argument(S, Attr, MinExpr, Min, 0)) | |||
5956 | return true; | |||
5957 | ||||
5958 | uint32_t Max = 0; | |||
5959 | if (MaxExpr && !checkUInt32Argument(S, Attr, MaxExpr, Max, 1)) | |||
5960 | return true; | |||
5961 | ||||
5962 | if (Min == 0 && Max != 0) { | |||
5963 | S.Diag(Attr.getLocation(), diag::err_attribute_argument_invalid) | |||
5964 | << &Attr << 0; | |||
5965 | return true; | |||
5966 | } | |||
5967 | if (Max != 0 && Min > Max) { | |||
5968 | S.Diag(Attr.getLocation(), diag::err_attribute_argument_invalid) | |||
5969 | << &Attr << 1; | |||
5970 | return true; | |||
5971 | } | |||
5972 | ||||
5973 | return false; | |||
5974 | } | |||
5975 | ||||
5976 | void Sema::addAMDGPUWavesPerEUAttr(SourceRange AttrRange, Decl *D, | |||
5977 | Expr *MinExpr, Expr *MaxExpr, | |||
5978 | unsigned SpellingListIndex) { | |||
5979 | AMDGPUWavesPerEUAttr TmpAttr(AttrRange, Context, MinExpr, MaxExpr, | |||
5980 | SpellingListIndex); | |||
5981 | ||||
5982 | if (checkAMDGPUWavesPerEUArguments(*this, MinExpr, MaxExpr, TmpAttr)) | |||
5983 | return; | |||
5984 | ||||
5985 | D->addAttr(::new (Context) AMDGPUWavesPerEUAttr(AttrRange, Context, MinExpr, | |||
5986 | MaxExpr, SpellingListIndex)); | |||
5987 | } | |||
5988 | ||||
5989 | static void handleAMDGPUWavesPerEUAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
5990 | if (!checkAttributeAtLeastNumArgs(S, AL, 1) || | |||
5991 | !checkAttributeAtMostNumArgs(S, AL, 2)) | |||
5992 | return; | |||
5993 | ||||
5994 | Expr *MinExpr = AL.getArgAsExpr(0); | |||
5995 | Expr *MaxExpr = (AL.getNumArgs() > 1) ? AL.getArgAsExpr(1) : nullptr; | |||
5996 | ||||
5997 | S.addAMDGPUWavesPerEUAttr(AL.getRange(), D, MinExpr, MaxExpr, | |||
5998 | AL.getAttributeSpellingListIndex()); | |||
5999 | } | |||
6000 | ||||
6001 | static void handleAMDGPUNumSGPRAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
6002 | uint32_t NumSGPR = 0; | |||
6003 | Expr *NumSGPRExpr = AL.getArgAsExpr(0); | |||
6004 | if (!checkUInt32Argument(S, AL, NumSGPRExpr, NumSGPR)) | |||
6005 | return; | |||
6006 | ||||
6007 | D->addAttr(::new (S.Context) | |||
6008 | AMDGPUNumSGPRAttr(AL.getLoc(), S.Context, NumSGPR, | |||
6009 | AL.getAttributeSpellingListIndex())); | |||
6010 | } | |||
6011 | ||||
6012 | static void handleAMDGPUNumVGPRAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
6013 | uint32_t NumVGPR = 0; | |||
6014 | Expr *NumVGPRExpr = AL.getArgAsExpr(0); | |||
6015 | if (!checkUInt32Argument(S, AL, NumVGPRExpr, NumVGPR)) | |||
6016 | return; | |||
6017 | ||||
6018 | D->addAttr(::new (S.Context) | |||
6019 | AMDGPUNumVGPRAttr(AL.getLoc(), S.Context, NumVGPR, | |||
6020 | AL.getAttributeSpellingListIndex())); | |||
6021 | } | |||
6022 | ||||
6023 | static void handleX86ForceAlignArgPointerAttr(Sema &S, Decl *D, | |||
6024 | const ParsedAttr &AL) { | |||
6025 | // If we try to apply it to a function pointer, don't warn, but don't | |||
6026 | // do anything, either. It doesn't matter anyway, because there's nothing | |||
6027 | // special about calling a force_align_arg_pointer function. | |||
6028 | const auto *VD = dyn_cast<ValueDecl>(D); | |||
6029 | if (VD && VD->getType()->isFunctionPointerType()) | |||
6030 | return; | |||
6031 | // Also don't warn on function pointer typedefs. | |||
6032 | const auto *TD = dyn_cast<TypedefNameDecl>(D); | |||
6033 | if (TD && (TD->getUnderlyingType()->isFunctionPointerType() || | |||
6034 | TD->getUnderlyingType()->isFunctionType())) | |||
6035 | return; | |||
6036 | // Attribute can only be applied to function types. | |||
6037 | if (!isa<FunctionDecl>(D)) { | |||
6038 | S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type) | |||
6039 | << AL << ExpectedFunction; | |||
6040 | return; | |||
6041 | } | |||
6042 | ||||
6043 | D->addAttr(::new (S.Context) | |||
6044 | X86ForceAlignArgPointerAttr(AL.getRange(), S.Context, | |||
6045 | AL.getAttributeSpellingListIndex())); | |||
6046 | } | |||
6047 | ||||
6048 | static void handleLayoutVersion(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
6049 | uint32_t Version; | |||
6050 | Expr *VersionExpr = static_cast<Expr *>(AL.getArgAsExpr(0)); | |||
6051 | if (!checkUInt32Argument(S, AL, AL.getArgAsExpr(0), Version)) | |||
6052 | return; | |||
6053 | ||||
6054 | // TODO: Investigate what happens with the next major version of MSVC. | |||
6055 | if (Version != LangOptions::MSVC2015 / 100) { | |||
6056 | S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds) | |||
6057 | << AL << Version << VersionExpr->getSourceRange(); | |||
6058 | return; | |||
6059 | } | |||
6060 | ||||
6061 | // The attribute expects a "major" version number like 19, but new versions of | |||
6062 | // MSVC have moved to updating the "minor", or less significant numbers, so we | |||
6063 | // have to multiply by 100 now. | |||
6064 | Version *= 100; | |||
6065 | ||||
6066 | D->addAttr(::new (S.Context) | |||
6067 | LayoutVersionAttr(AL.getRange(), S.Context, Version, | |||
6068 | AL.getAttributeSpellingListIndex())); | |||
6069 | } | |||
6070 | ||||
6071 | DLLImportAttr *Sema::mergeDLLImportAttr(Decl *D, SourceRange Range, | |||
6072 | unsigned AttrSpellingListIndex) { | |||
6073 | if (D->hasAttr<DLLExportAttr>()) { | |||
6074 | Diag(Range.getBegin(), diag::warn_attribute_ignored) << "'dllimport'"; | |||
6075 | return nullptr; | |||
6076 | } | |||
6077 | ||||
6078 | if (D->hasAttr<DLLImportAttr>()) | |||
6079 | return nullptr; | |||
6080 | ||||
6081 | return ::new (Context) DLLImportAttr(Range, Context, AttrSpellingListIndex); | |||
6082 | } | |||
6083 | ||||
6084 | DLLExportAttr *Sema::mergeDLLExportAttr(Decl *D, SourceRange Range, | |||
6085 | unsigned AttrSpellingListIndex) { | |||
6086 | if (DLLImportAttr *Import = D->getAttr<DLLImportAttr>()) { | |||
6087 | Diag(Import->getLocation(), diag::warn_attribute_ignored) << Import; | |||
6088 | D->dropAttr<DLLImportAttr>(); | |||
6089 | } | |||
6090 | ||||
6091 | if (D->hasAttr<DLLExportAttr>()) | |||
6092 | return nullptr; | |||
6093 | ||||
6094 | return ::new (Context) DLLExportAttr(Range, Context, AttrSpellingListIndex); | |||
6095 | } | |||
6096 | ||||
6097 | static void handleDLLAttr(Sema &S, Decl *D, const ParsedAttr &A) { | |||
6098 | if (isa<ClassTemplatePartialSpecializationDecl>(D) && | |||
6099 | S.Context.getTargetInfo().getCXXABI().isMicrosoft()) { | |||
6100 | S.Diag(A.getRange().getBegin(), diag::warn_attribute_ignored) << A; | |||
6101 | return; | |||
6102 | } | |||
6103 | ||||
6104 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) { | |||
6105 | if (FD->isInlined() && A.getKind() == ParsedAttr::AT_DLLImport && | |||
6106 | !S.Context.getTargetInfo().getCXXABI().isMicrosoft()) { | |||
6107 | // MinGW doesn't allow dllimport on inline functions. | |||
6108 | S.Diag(A.getRange().getBegin(), diag::warn_attribute_ignored_on_inline) | |||
6109 | << A; | |||
6110 | return; | |||
6111 | } | |||
6112 | } | |||
6113 | ||||
6114 | if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) { | |||
6115 | if (S.Context.getTargetInfo().getCXXABI().isMicrosoft() && | |||
6116 | MD->getParent()->isLambda()) { | |||
6117 | S.Diag(A.getRange().getBegin(), diag::err_attribute_dll_lambda) << A; | |||
6118 | return; | |||
6119 | } | |||
6120 | } | |||
6121 | ||||
6122 | unsigned Index = A.getAttributeSpellingListIndex(); | |||
6123 | Attr *NewAttr = A.getKind() == ParsedAttr::AT_DLLExport | |||
6124 | ? (Attr *)S.mergeDLLExportAttr(D, A.getRange(), Index) | |||
6125 | : (Attr *)S.mergeDLLImportAttr(D, A.getRange(), Index); | |||
6126 | if (NewAttr) | |||
6127 | D->addAttr(NewAttr); | |||
6128 | } | |||
6129 | ||||
6130 | MSInheritanceAttr * | |||
6131 | Sema::mergeMSInheritanceAttr(Decl *D, SourceRange Range, bool BestCase, | |||
6132 | unsigned AttrSpellingListIndex, | |||
6133 | MSInheritanceAttr::Spelling SemanticSpelling) { | |||
6134 | if (MSInheritanceAttr *IA = D->getAttr<MSInheritanceAttr>()) { | |||
6135 | if (IA->getSemanticSpelling() == SemanticSpelling) | |||
6136 | return nullptr; | |||
6137 | Diag(IA->getLocation(), diag::err_mismatched_ms_inheritance) | |||
6138 | << 1 /*previous declaration*/; | |||
6139 | Diag(Range.getBegin(), diag::note_previous_ms_inheritance); | |||
6140 | D->dropAttr<MSInheritanceAttr>(); | |||
6141 | } | |||
6142 | ||||
6143 | auto *RD = cast<CXXRecordDecl>(D); | |||
6144 | if (RD->hasDefinition()) { | |||
6145 | if (checkMSInheritanceAttrOnDefinition(RD, Range, BestCase, | |||
6146 | SemanticSpelling)) { | |||
6147 | return nullptr; | |||
6148 | } | |||
6149 | } else { | |||
6150 | if (isa<ClassTemplatePartialSpecializationDecl>(RD)) { | |||
6151 | Diag(Range.getBegin(), diag::warn_ignored_ms_inheritance) | |||
6152 | << 1 /*partial specialization*/; | |||
6153 | return nullptr; | |||
6154 | } | |||
6155 | if (RD->getDescribedClassTemplate()) { | |||
6156 | Diag(Range.getBegin(), diag::warn_ignored_ms_inheritance) | |||
6157 | << 0 /*primary template*/; | |||
6158 | return nullptr; | |||
6159 | } | |||
6160 | } | |||
6161 | ||||
6162 | return ::new (Context) | |||
6163 | MSInheritanceAttr(Range, Context, BestCase, AttrSpellingListIndex); | |||
6164 | } | |||
6165 | ||||
6166 | static void handleCapabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
6167 | // The capability attributes take a single string parameter for the name of | |||
6168 | // the capability they represent. The lockable attribute does not take any | |||
6169 | // parameters. However, semantically, both attributes represent the same | |||
6170 | // concept, and so they use the same semantic attribute. Eventually, the | |||
6171 | // lockable attribute will be removed. | |||
6172 | // | |||
6173 | // For backward compatibility, any capability which has no specified string | |||
6174 | // literal will be considered a "mutex." | |||
6175 | StringRef N("mutex"); | |||
6176 | SourceLocation LiteralLoc; | |||
6177 | if (AL.getKind() == ParsedAttr::AT_Capability && | |||
6178 | !S.checkStringLiteralArgumentAttr(AL, 0, N, &LiteralLoc)) | |||
6179 | return; | |||
6180 | ||||
6181 | // Currently, there are only two names allowed for a capability: role and | |||
6182 | // mutex (case insensitive). Diagnose other capability names. | |||
6183 | if (!N.equals_lower("mutex") && !N.equals_lower("role")) | |||
6184 | S.Diag(LiteralLoc, diag::warn_invalid_capability_name) << N; | |||
6185 | ||||
6186 | D->addAttr(::new (S.Context) CapabilityAttr(AL.getRange(), S.Context, N, | |||
6187 | AL.getAttributeSpellingListIndex())); | |||
6188 | } | |||
6189 | ||||
6190 | static void handleAssertCapabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
6191 | SmallVector<Expr*, 1> Args; | |||
6192 | if (!checkLockFunAttrCommon(S, D, AL, Args)) | |||
6193 | return; | |||
6194 | ||||
6195 | D->addAttr(::new (S.Context) AssertCapabilityAttr(AL.getRange(), S.Context, | |||
6196 | Args.data(), Args.size(), | |||
6197 | AL.getAttributeSpellingListIndex())); | |||
6198 | } | |||
6199 | ||||
6200 | static void handleAcquireCapabilityAttr(Sema &S, Decl *D, | |||
6201 | const ParsedAttr &AL) { | |||
6202 | SmallVector<Expr*, 1> Args; | |||
6203 | if (!checkLockFunAttrCommon(S, D, AL, Args)) | |||
6204 | return; | |||
6205 | ||||
6206 | D->addAttr(::new (S.Context) AcquireCapabilityAttr(AL.getRange(), | |||
6207 | S.Context, | |||
6208 | Args.data(), Args.size(), | |||
6209 | AL.getAttributeSpellingListIndex())); | |||
6210 | } | |||
6211 | ||||
6212 | static void handleTryAcquireCapabilityAttr(Sema &S, Decl *D, | |||
6213 | const ParsedAttr &AL) { | |||
6214 | SmallVector<Expr*, 2> Args; | |||
6215 | if (!checkTryLockFunAttrCommon(S, D, AL, Args)) | |||
6216 | return; | |||
6217 | ||||
6218 | D->addAttr(::new (S.Context) TryAcquireCapabilityAttr(AL.getRange(), | |||
6219 | S.Context, | |||
6220 | AL.getArgAsExpr(0), | |||
6221 | Args.data(), | |||
6222 | Args.size(), | |||
6223 | AL.getAttributeSpellingListIndex())); | |||
6224 | } | |||
6225 | ||||
6226 | static void handleReleaseCapabilityAttr(Sema &S, Decl *D, | |||
6227 | const ParsedAttr &AL) { | |||
6228 | // Check that all arguments are lockable objects. | |||
6229 | SmallVector<Expr *, 1> Args; | |||
6230 | checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 0, true); | |||
6231 | ||||
6232 | D->addAttr(::new (S.Context) ReleaseCapabilityAttr( | |||
6233 | AL.getRange(), S.Context, Args.data(), Args.size(), | |||
6234 | AL.getAttributeSpellingListIndex())); | |||
6235 | } | |||
6236 | ||||
6237 | static void handleRequiresCapabilityAttr(Sema &S, Decl *D, | |||
6238 | const ParsedAttr &AL) { | |||
6239 | if (!checkAttributeAtLeastNumArgs(S, AL, 1)) | |||
6240 | return; | |||
6241 | ||||
6242 | // check that all arguments are lockable objects | |||
6243 | SmallVector<Expr*, 1> Args; | |||
6244 | checkAttrArgsAreCapabilityObjs(S, D, AL, Args); | |||
6245 | if (Args.empty()) | |||
6246 | return; | |||
6247 | ||||
6248 | RequiresCapabilityAttr *RCA = ::new (S.Context) | |||
6249 | RequiresCapabilityAttr(AL.getRange(), S.Context, Args.data(), | |||
6250 | Args.size(), AL.getAttributeSpellingListIndex()); | |||
6251 | ||||
6252 | D->addAttr(RCA); | |||
6253 | } | |||
6254 | ||||
6255 | static void handleDeprecatedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
6256 | if (const auto *NSD = dyn_cast<NamespaceDecl>(D)) { | |||
6257 | if (NSD->isAnonymousNamespace()) { | |||
6258 | S.Diag(AL.getLoc(), diag::warn_deprecated_anonymous_namespace); | |||
6259 | // Do not want to attach the attribute to the namespace because that will | |||
6260 | // cause confusing diagnostic reports for uses of declarations within the | |||
6261 | // namespace. | |||
6262 | return; | |||
6263 | } | |||
6264 | } | |||
6265 | ||||
6266 | // Handle the cases where the attribute has a text message. | |||
6267 | StringRef Str, Replacement; | |||
6268 | if (AL.isArgExpr(0) && AL.getArgAsExpr(0) && | |||
6269 | !S.checkStringLiteralArgumentAttr(AL, 0, Str)) | |||
6270 | return; | |||
6271 | ||||
6272 | // Only support a single optional message for Declspec and CXX11. | |||
6273 | if (AL.isDeclspecAttribute() || AL.isCXX11Attribute()) | |||
6274 | checkAttributeAtMostNumArgs(S, AL, 1); | |||
6275 | else if (AL.isArgExpr(1) && AL.getArgAsExpr(1) && | |||
6276 | !S.checkStringLiteralArgumentAttr(AL, 1, Replacement)) | |||
6277 | return; | |||
6278 | ||||
6279 | if (!S.getLangOpts().CPlusPlus14 && AL.isCXX11Attribute() && !AL.isGNUScope()) | |||
6280 | S.Diag(AL.getLoc(), diag::ext_cxx14_attr) << AL; | |||
6281 | ||||
6282 | D->addAttr(::new (S.Context) | |||
6283 | DeprecatedAttr(AL.getRange(), S.Context, Str, Replacement, | |||
6284 | AL.getAttributeSpellingListIndex())); | |||
6285 | } | |||
6286 | ||||
6287 | static bool isGlobalVar(const Decl *D) { | |||
6288 | if (const auto *S = dyn_cast<VarDecl>(D)) | |||
6289 | return S->hasGlobalStorage(); | |||
6290 | return false; | |||
6291 | } | |||
6292 | ||||
6293 | static void handleNoSanitizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
6294 | if (!checkAttributeAtLeastNumArgs(S, AL, 1)) | |||
6295 | return; | |||
6296 | ||||
6297 | std::vector<StringRef> Sanitizers; | |||
6298 | ||||
6299 | for (unsigned I = 0, E = AL.getNumArgs(); I != E; ++I) { | |||
6300 | StringRef SanitizerName; | |||
6301 | SourceLocation LiteralLoc; | |||
6302 | ||||
6303 | if (!S.checkStringLiteralArgumentAttr(AL, I, SanitizerName, &LiteralLoc)) | |||
6304 | return; | |||
6305 | ||||
6306 | if (parseSanitizerValue(SanitizerName, /*AllowGroups=*/true) == | |||
6307 | SanitizerMask()) | |||
6308 | S.Diag(LiteralLoc, diag::warn_unknown_sanitizer_ignored) << SanitizerName; | |||
6309 | else if (isGlobalVar(D) && SanitizerName != "address") | |||
6310 | S.Diag(D->getLocation(), diag::err_attribute_wrong_decl_type) | |||
6311 | << AL << ExpectedFunctionOrMethod; | |||
6312 | Sanitizers.push_back(SanitizerName); | |||
6313 | } | |||
6314 | ||||
6315 | D->addAttr(::new (S.Context) NoSanitizeAttr( | |||
6316 | AL.getRange(), S.Context, Sanitizers.data(), Sanitizers.size(), | |||
6317 | AL.getAttributeSpellingListIndex())); | |||
6318 | } | |||
6319 | ||||
6320 | static void handleNoSanitizeSpecificAttr(Sema &S, Decl *D, | |||
6321 | const ParsedAttr &AL) { | |||
6322 | StringRef AttrName = AL.getName()->getName(); | |||
6323 | normalizeName(AttrName); | |||
6324 | StringRef SanitizerName = llvm::StringSwitch<StringRef>(AttrName) | |||
6325 | .Case("no_address_safety_analysis", "address") | |||
6326 | .Case("no_sanitize_address", "address") | |||
6327 | .Case("no_sanitize_thread", "thread") | |||
6328 | .Case("no_sanitize_memory", "memory"); | |||
6329 | if (isGlobalVar(D) && SanitizerName != "address") | |||
6330 | S.Diag(D->getLocation(), diag::err_attribute_wrong_decl_type) | |||
6331 | << AL << ExpectedFunction; | |||
6332 | ||||
6333 | // FIXME: Rather than create a NoSanitizeSpecificAttr, this creates a | |||
6334 | // NoSanitizeAttr object; but we need to calculate the correct spelling list | |||
6335 | // index rather than incorrectly assume the index for NoSanitizeSpecificAttr | |||
6336 | // has the same spellings as the index for NoSanitizeAttr. We don't have a | |||
6337 | // general way to "translate" between the two, so this hack attempts to work | |||
6338 | // around the issue with hard-coded indicies. This is critical for calling | |||
6339 | // getSpelling() or prettyPrint() on the resulting semantic attribute object | |||
6340 | // without failing assertions. | |||
6341 | unsigned TranslatedSpellingIndex = 0; | |||
6342 | if (AL.isC2xAttribute() || AL.isCXX11Attribute()) | |||
6343 | TranslatedSpellingIndex = 1; | |||
6344 | ||||
6345 | D->addAttr(::new (S.Context) NoSanitizeAttr( | |||
6346 | AL.getRange(), S.Context, &SanitizerName, 1, TranslatedSpellingIndex)); | |||
6347 | } | |||
6348 | ||||
6349 | static void handleInternalLinkageAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
6350 | if (InternalLinkageAttr *Internal = S.mergeInternalLinkageAttr(D, AL)) | |||
6351 | D->addAttr(Internal); | |||
6352 | } | |||
6353 | ||||
6354 | static void handleOpenCLNoSVMAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
6355 | if (S.LangOpts.OpenCLVersion != 200) | |||
6356 | S.Diag(AL.getLoc(), diag::err_attribute_requires_opencl_version) | |||
6357 | << AL << "2.0" << 0; | |||
6358 | else | |||
6359 | S.Diag(AL.getLoc(), diag::warn_opencl_attr_deprecated_ignored) << AL | |||
6360 | << "2.0"; | |||
6361 | } | |||
6362 | ||||
6363 | /// Handles semantic checking for features that are common to all attributes, | |||
6364 | /// such as checking whether a parameter was properly specified, or the correct | |||
6365 | /// number of arguments were passed, etc. | |||
6366 | static bool handleCommonAttributeFeatures(Sema &S, Decl *D, | |||
6367 | const ParsedAttr &AL) { | |||
6368 | // Several attributes carry different semantics than the parsing requires, so | |||
6369 | // those are opted out of the common argument checks. | |||
6370 | // | |||
6371 | // We also bail on unknown and ignored attributes because those are handled | |||
6372 | // as part of the target-specific handling logic. | |||
6373 | if (AL.getKind() == ParsedAttr::UnknownAttribute) | |||
6374 | return false; | |||
6375 | // Check whether the attribute requires specific language extensions to be | |||
6376 | // enabled. | |||
6377 | if (!AL.diagnoseLangOpts(S)) | |||
6378 | return true; | |||
6379 | // Check whether the attribute appertains to the given subject. | |||
6380 | if (!AL.diagnoseAppertainsTo(S, D)) | |||
6381 | return true; | |||
6382 | if (AL.hasCustomParsing()) | |||
6383 | return false; | |||
6384 | ||||
6385 | if (AL.getMinArgs() == AL.getMaxArgs()) { | |||
6386 | // If there are no optional arguments, then checking for the argument count | |||
6387 | // is trivial. | |||
6388 | if (!checkAttributeNumArgs(S, AL, AL.getMinArgs())) | |||
6389 | return true; | |||
6390 | } else { | |||
6391 | // There are optional arguments, so checking is slightly more involved. | |||
6392 | if (AL.getMinArgs() && | |||
6393 | !checkAttributeAtLeastNumArgs(S, AL, AL.getMinArgs())) | |||
6394 | return true; | |||
6395 | else if (!AL.hasVariadicArg() && AL.getMaxArgs() && | |||
6396 | !checkAttributeAtMostNumArgs(S, AL, AL.getMaxArgs())) | |||
6397 | return true; | |||
6398 | } | |||
6399 | ||||
6400 | if (S.CheckAttrTarget(AL)) | |||
6401 | return true; | |||
6402 | ||||
6403 | return false; | |||
6404 | } | |||
6405 | ||||
6406 | static void handleOpenCLAccessAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
6407 | if (D->isInvalidDecl()) | |||
6408 | return; | |||
6409 | ||||
6410 | // Check if there is only one access qualifier. | |||
6411 | if (D->hasAttr<OpenCLAccessAttr>()) { | |||
6412 | if (D->getAttr<OpenCLAccessAttr>()->getSemanticSpelling() == | |||
6413 | AL.getSemanticSpelling()) { | |||
6414 | S.Diag(AL.getLoc(), diag::warn_duplicate_declspec) | |||
6415 | << AL.getName()->getName() << AL.getRange(); | |||
6416 | } else { | |||
6417 | S.Diag(AL.getLoc(), diag::err_opencl_multiple_access_qualifiers) | |||
6418 | << D->getSourceRange(); | |||
6419 | D->setInvalidDecl(true); | |||
6420 | return; | |||
6421 | } | |||
6422 | } | |||
6423 | ||||
6424 | // OpenCL v2.0 s6.6 - read_write can be used for image types to specify that an | |||
6425 | // image object can be read and written. | |||
6426 | // OpenCL v2.0 s6.13.6 - A kernel cannot read from and write to the same pipe | |||
6427 | // object. Using the read_write (or __read_write) qualifier with the pipe | |||
6428 | // qualifier is a compilation error. | |||
6429 | if (const auto *PDecl = dyn_cast<ParmVarDecl>(D)) { | |||
6430 | const Type *DeclTy = PDecl->getType().getCanonicalType().getTypePtr(); | |||
6431 | if (AL.getName()->getName().find("read_write") != StringRef::npos) { | |||
6432 | if ((!S.getLangOpts().OpenCLCPlusPlus && | |||
6433 | S.getLangOpts().OpenCLVersion < 200) || | |||
6434 | DeclTy->isPipeType()) { | |||
6435 | S.Diag(AL.getLoc(), diag::err_opencl_invalid_read_write) | |||
6436 | << AL << PDecl->getType() << DeclTy->isImageType(); | |||
6437 | D->setInvalidDecl(true); | |||
6438 | return; | |||
6439 | } | |||
6440 | } | |||
6441 | } | |||
6442 | ||||
6443 | D->addAttr(::new (S.Context) OpenCLAccessAttr( | |||
6444 | AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); | |||
6445 | } | |||
6446 | ||||
6447 | static void handleDestroyAttr(Sema &S, Decl *D, const ParsedAttr &A) { | |||
6448 | if (!cast<VarDecl>(D)->hasGlobalStorage()) { | |||
6449 | S.Diag(D->getLocation(), diag::err_destroy_attr_on_non_static_var) | |||
6450 | << (A.getKind() == ParsedAttr::AT_AlwaysDestroy); | |||
6451 | return; | |||
6452 | } | |||
6453 | ||||
6454 | if (A.getKind() == ParsedAttr::AT_AlwaysDestroy) | |||
6455 | handleSimpleAttributeWithExclusions<AlwaysDestroyAttr, NoDestroyAttr>(S, D, A); | |||
6456 | else | |||
6457 | handleSimpleAttributeWithExclusions<NoDestroyAttr, AlwaysDestroyAttr>(S, D, A); | |||
6458 | } | |||
6459 | ||||
6460 | static void handleUninitializedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
6461 | assert(cast<VarDecl>(D)->getStorageDuration() == SD_Automatic &&((cast<VarDecl>(D)->getStorageDuration() == SD_Automatic && "uninitialized is only valid on automatic duration variables" ) ? static_cast<void> (0) : __assert_fail ("cast<VarDecl>(D)->getStorageDuration() == SD_Automatic && \"uninitialized is only valid on automatic duration variables\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 6462, __PRETTY_FUNCTION__)) | |||
6462 | "uninitialized is only valid on automatic duration variables")((cast<VarDecl>(D)->getStorageDuration() == SD_Automatic && "uninitialized is only valid on automatic duration variables" ) ? static_cast<void> (0) : __assert_fail ("cast<VarDecl>(D)->getStorageDuration() == SD_Automatic && \"uninitialized is only valid on automatic duration variables\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 6462, __PRETTY_FUNCTION__)); | |||
6463 | unsigned Index = AL.getAttributeSpellingListIndex(); | |||
6464 | D->addAttr(::new (S.Context) | |||
6465 | UninitializedAttr(AL.getLoc(), S.Context, Index)); | |||
6466 | } | |||
6467 | ||||
6468 | static bool tryMakeVariablePseudoStrong(Sema &S, VarDecl *VD, | |||
6469 | bool DiagnoseFailure) { | |||
6470 | QualType Ty = VD->getType(); | |||
6471 | if (!Ty->isObjCRetainableType()) { | |||
6472 | if (DiagnoseFailure) { | |||
6473 | S.Diag(VD->getBeginLoc(), diag::warn_ignored_objc_externally_retained) | |||
6474 | << 0; | |||
6475 | } | |||
6476 | return false; | |||
6477 | } | |||
6478 | ||||
6479 | Qualifiers::ObjCLifetime LifetimeQual = Ty.getQualifiers().getObjCLifetime(); | |||
6480 | ||||
6481 | // Sema::inferObjCARCLifetime must run after processing decl attributes | |||
6482 | // (because __block lowers to an attribute), so if the lifetime hasn't been | |||
6483 | // explicitly specified, infer it locally now. | |||
6484 | if (LifetimeQual == Qualifiers::OCL_None) | |||
6485 | LifetimeQual = Ty->getObjCARCImplicitLifetime(); | |||
6486 | ||||
6487 | // The attributes only really makes sense for __strong variables; ignore any | |||
6488 | // attempts to annotate a parameter with any other lifetime qualifier. | |||
6489 | if (LifetimeQual != Qualifiers::OCL_Strong) { | |||
6490 | if (DiagnoseFailure) { | |||
6491 | S.Diag(VD->getBeginLoc(), diag::warn_ignored_objc_externally_retained) | |||
6492 | << 1; | |||
6493 | } | |||
6494 | return false; | |||
6495 | } | |||
6496 | ||||
6497 | // Tampering with the type of a VarDecl here is a bit of a hack, but we need | |||
6498 | // to ensure that the variable is 'const' so that we can error on | |||
6499 | // modification, which can otherwise over-release. | |||
6500 | VD->setType(Ty.withConst()); | |||
6501 | VD->setARCPseudoStrong(true); | |||
6502 | return true; | |||
6503 | } | |||
6504 | ||||
6505 | static void handleObjCExternallyRetainedAttr(Sema &S, Decl *D, | |||
6506 | const ParsedAttr &AL) { | |||
6507 | if (auto *VD = dyn_cast<VarDecl>(D)) { | |||
6508 | assert(!isa<ParmVarDecl>(VD) && "should be diagnosed automatically")((!isa<ParmVarDecl>(VD) && "should be diagnosed automatically" ) ? static_cast<void> (0) : __assert_fail ("!isa<ParmVarDecl>(VD) && \"should be diagnosed automatically\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 6508, __PRETTY_FUNCTION__)); | |||
6509 | if (!VD->hasLocalStorage()) { | |||
6510 | S.Diag(D->getBeginLoc(), diag::warn_ignored_objc_externally_retained) | |||
6511 | << 0; | |||
6512 | return; | |||
6513 | } | |||
6514 | ||||
6515 | if (!tryMakeVariablePseudoStrong(S, VD, /*DiagnoseFailure=*/true)) | |||
6516 | return; | |||
6517 | ||||
6518 | handleSimpleAttribute<ObjCExternallyRetainedAttr>(S, D, AL); | |||
6519 | return; | |||
6520 | } | |||
6521 | ||||
6522 | // If D is a function-like declaration (method, block, or function), then we | |||
6523 | // make every parameter psuedo-strong. | |||
6524 | for (unsigned I = 0, E = getFunctionOrMethodNumParams(D); I != E; ++I) { | |||
6525 | auto *PVD = const_cast<ParmVarDecl *>(getFunctionOrMethodParam(D, I)); | |||
6526 | QualType Ty = PVD->getType(); | |||
6527 | ||||
6528 | // If a user wrote a parameter with __strong explicitly, then assume they | |||
6529 | // want "real" strong semantics for that parameter. This works because if | |||
6530 | // the parameter was written with __strong, then the strong qualifier will | |||
6531 | // be non-local. | |||
6532 | if (Ty.getLocalUnqualifiedType().getQualifiers().getObjCLifetime() == | |||
6533 | Qualifiers::OCL_Strong) | |||
6534 | continue; | |||
6535 | ||||
6536 | tryMakeVariablePseudoStrong(S, PVD, /*DiagnoseFailure=*/false); | |||
6537 | } | |||
6538 | handleSimpleAttribute<ObjCExternallyRetainedAttr>(S, D, AL); | |||
6539 | } | |||
6540 | ||||
6541 | static void handleMIGServerRoutineAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
6542 | // Check that the return type is a `typedef int kern_return_t` or a typedef | |||
6543 | // around it, because otherwise MIG convention checks make no sense. | |||
6544 | // BlockDecl doesn't store a return type, so it's annoying to check, | |||
6545 | // so let's skip it for now. | |||
6546 | if (!isa<BlockDecl>(D)) { | |||
6547 | QualType T = getFunctionOrMethodResultType(D); | |||
6548 | bool IsKernReturnT = false; | |||
6549 | while (const auto *TT = T->getAs<TypedefType>()) { | |||
6550 | IsKernReturnT = (TT->getDecl()->getName() == "kern_return_t"); | |||
6551 | T = TT->desugar(); | |||
6552 | } | |||
6553 | if (!IsKernReturnT || T.getCanonicalType() != S.getASTContext().IntTy) { | |||
6554 | S.Diag(D->getBeginLoc(), | |||
6555 | diag::warn_mig_server_routine_does_not_return_kern_return_t); | |||
6556 | return; | |||
6557 | } | |||
6558 | } | |||
6559 | ||||
6560 | handleSimpleAttribute<MIGServerRoutineAttr>(S, D, AL); | |||
6561 | } | |||
6562 | ||||
6563 | static void handleMSAllocatorAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |||
6564 | // Warn if the return type is not a pointer or reference type. | |||
6565 | if (auto *FD = dyn_cast<FunctionDecl>(D)) { | |||
6566 | QualType RetTy = FD->getReturnType(); | |||
6567 | if (!RetTy->isPointerType() && !RetTy->isReferenceType()) { | |||
6568 | S.Diag(AL.getLoc(), diag::warn_declspec_allocator_nonpointer) | |||
6569 | << AL.getRange() << RetTy; | |||
6570 | return; | |||
6571 | } | |||
6572 | } | |||
6573 | ||||
6574 | handleSimpleAttribute<MSAllocatorAttr>(S, D, AL); | |||
6575 | } | |||
6576 | ||||
6577 | //===----------------------------------------------------------------------===// | |||
6578 | // Top Level Sema Entry Points | |||
6579 | //===----------------------------------------------------------------------===// | |||
6580 | ||||
6581 | /// ProcessDeclAttribute - Apply the specific attribute to the specified decl if | |||
6582 | /// the attribute applies to decls. If the attribute is a type attribute, just | |||
6583 | /// silently ignore it if a GNU attribute. | |||
6584 | static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, | |||
6585 | const ParsedAttr &AL, | |||
6586 | bool IncludeCXX11Attributes) { | |||
6587 | if (AL.isInvalid() || AL.getKind() == ParsedAttr::IgnoredAttribute) | |||
6588 | return; | |||
6589 | ||||
6590 | // Ignore C++11 attributes on declarator chunks: they appertain to the type | |||
6591 | // instead. | |||
6592 | if (AL.isCXX11Attribute() && !IncludeCXX11Attributes) | |||
6593 | return; | |||
6594 | ||||
6595 | // Unknown attributes are automatically warned on. Target-specific attributes | |||
6596 | // which do not apply to the current target architecture are treated as | |||
6597 | // though they were unknown attributes. | |||
6598 | if (AL.getKind() == ParsedAttr::UnknownAttribute || | |||
6599 | !AL.existsInTarget(S.Context.getTargetInfo())) { | |||
6600 | S.Diag(AL.getLoc(), | |||
6601 | AL.isDeclspecAttribute() | |||
6602 | ? (unsigned)diag::warn_unhandled_ms_attribute_ignored | |||
6603 | : (unsigned)diag::warn_unknown_attribute_ignored) | |||
6604 | << AL; | |||
6605 | return; | |||
6606 | } | |||
6607 | ||||
6608 | if (handleCommonAttributeFeatures(S, D, AL)) | |||
6609 | return; | |||
6610 | ||||
6611 | switch (AL.getKind()) { | |||
6612 | default: | |||
6613 | if (!AL.isStmtAttr()) { | |||
6614 | // Type attributes are handled elsewhere; silently move on. | |||
6615 | assert(AL.isTypeAttr() && "Non-type attribute not handled")((AL.isTypeAttr() && "Non-type attribute not handled" ) ? static_cast<void> (0) : __assert_fail ("AL.isTypeAttr() && \"Non-type attribute not handled\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 6615, __PRETTY_FUNCTION__)); | |||
6616 | break; | |||
6617 | } | |||
6618 | S.Diag(AL.getLoc(), diag::err_stmt_attribute_invalid_on_decl) | |||
6619 | << AL << D->getLocation(); | |||
6620 | break; | |||
6621 | case ParsedAttr::AT_Interrupt: | |||
6622 | handleInterruptAttr(S, D, AL); | |||
6623 | break; | |||
6624 | case ParsedAttr::AT_X86ForceAlignArgPointer: | |||
6625 | handleX86ForceAlignArgPointerAttr(S, D, AL); | |||
6626 | break; | |||
6627 | case ParsedAttr::AT_DLLExport: | |||
6628 | case ParsedAttr::AT_DLLImport: | |||
6629 | handleDLLAttr(S, D, AL); | |||
6630 | break; | |||
6631 | case ParsedAttr::AT_Mips16: | |||
6632 | handleSimpleAttributeWithExclusions<Mips16Attr, MicroMipsAttr, | |||
6633 | MipsInterruptAttr>(S, D, AL); | |||
6634 | break; | |||
6635 | case ParsedAttr::AT_NoMips16: | |||
6636 | handleSimpleAttribute<NoMips16Attr>(S, D, AL); | |||
6637 | break; | |||
6638 | case ParsedAttr::AT_MicroMips: | |||
6639 | handleSimpleAttributeWithExclusions<MicroMipsAttr, Mips16Attr>(S, D, AL); | |||
6640 | break; | |||
6641 | case ParsedAttr::AT_NoMicroMips: | |||
6642 | handleSimpleAttribute<NoMicroMipsAttr>(S, D, AL); | |||
6643 | break; | |||
6644 | case ParsedAttr::AT_MipsLongCall: | |||
6645 | handleSimpleAttributeWithExclusions<MipsLongCallAttr, MipsShortCallAttr>( | |||
6646 | S, D, AL); | |||
6647 | break; | |||
6648 | case ParsedAttr::AT_MipsShortCall: | |||
6649 | handleSimpleAttributeWithExclusions<MipsShortCallAttr, MipsLongCallAttr>( | |||
6650 | S, D, AL); | |||
6651 | break; | |||
6652 | case ParsedAttr::AT_AMDGPUFlatWorkGroupSize: | |||
6653 | handleAMDGPUFlatWorkGroupSizeAttr(S, D, AL); | |||
6654 | break; | |||
6655 | case ParsedAttr::AT_AMDGPUWavesPerEU: | |||
6656 | handleAMDGPUWavesPerEUAttr(S, D, AL); | |||
6657 | break; | |||
6658 | case ParsedAttr::AT_AMDGPUNumSGPR: | |||
6659 | handleAMDGPUNumSGPRAttr(S, D, AL); | |||
6660 | break; | |||
6661 | case ParsedAttr::AT_AMDGPUNumVGPR: | |||
6662 | handleAMDGPUNumVGPRAttr(S, D, AL); | |||
6663 | break; | |||
6664 | case ParsedAttr::AT_AVRSignal: | |||
6665 | handleAVRSignalAttr(S, D, AL); | |||
6666 | break; | |||
6667 | case ParsedAttr::AT_WebAssemblyImportModule: | |||
6668 | handleWebAssemblyImportModuleAttr(S, D, AL); | |||
6669 | break; | |||
6670 | case ParsedAttr::AT_WebAssemblyImportName: | |||
6671 | handleWebAssemblyImportNameAttr(S, D, AL); | |||
6672 | break; | |||
6673 | case ParsedAttr::AT_IBAction: | |||
6674 | handleSimpleAttribute<IBActionAttr>(S, D, AL); | |||
6675 | break; | |||
6676 | case ParsedAttr::AT_IBOutlet: | |||
6677 | handleIBOutlet(S, D, AL); | |||
6678 | break; | |||
6679 | case ParsedAttr::AT_IBOutletCollection: | |||
6680 | handleIBOutletCollection(S, D, AL); | |||
6681 | break; | |||
6682 | case ParsedAttr::AT_IFunc: | |||
6683 | handleIFuncAttr(S, D, AL); | |||
6684 | break; | |||
6685 | case ParsedAttr::AT_Alias: | |||
6686 | handleAliasAttr(S, D, AL); | |||
6687 | break; | |||
6688 | case ParsedAttr::AT_Aligned: | |||
6689 | handleAlignedAttr(S, D, AL); | |||
6690 | break; | |||
6691 | case ParsedAttr::AT_AlignValue: | |||
6692 | handleAlignValueAttr(S, D, AL); | |||
6693 | break; | |||
6694 | case ParsedAttr::AT_AllocSize: | |||
6695 | handleAllocSizeAttr(S, D, AL); | |||
6696 | break; | |||
6697 | case ParsedAttr::AT_AlwaysInline: | |||
6698 | handleAlwaysInlineAttr(S, D, AL); | |||
6699 | break; | |||
6700 | case ParsedAttr::AT_Artificial: | |||
6701 | handleSimpleAttribute<ArtificialAttr>(S, D, AL); | |||
6702 | break; | |||
6703 | case ParsedAttr::AT_AnalyzerNoReturn: | |||
6704 | handleAnalyzerNoReturnAttr(S, D, AL); | |||
6705 | break; | |||
6706 | case ParsedAttr::AT_TLSModel: | |||
6707 | handleTLSModelAttr(S, D, AL); | |||
6708 | break; | |||
6709 | case ParsedAttr::AT_Annotate: | |||
6710 | handleAnnotateAttr(S, D, AL); | |||
6711 | break; | |||
6712 | case ParsedAttr::AT_Availability: | |||
6713 | handleAvailabilityAttr(S, D, AL); | |||
6714 | break; | |||
6715 | case ParsedAttr::AT_CarriesDependency: | |||
6716 | handleDependencyAttr(S, scope, D, AL); | |||
6717 | break; | |||
6718 | case ParsedAttr::AT_CPUDispatch: | |||
6719 | case ParsedAttr::AT_CPUSpecific: | |||
6720 | handleCPUSpecificAttr(S, D, AL); | |||
6721 | break; | |||
6722 | case ParsedAttr::AT_Common: | |||
6723 | handleCommonAttr(S, D, AL); | |||
6724 | break; | |||
6725 | case ParsedAttr::AT_CUDAConstant: | |||
6726 | handleConstantAttr(S, D, AL); | |||
6727 | break; | |||
6728 | case ParsedAttr::AT_PassObjectSize: | |||
6729 | handlePassObjectSizeAttr(S, D, AL); | |||
6730 | break; | |||
6731 | case ParsedAttr::AT_Constructor: | |||
6732 | handleConstructorAttr(S, D, AL); | |||
6733 | break; | |||
6734 | case ParsedAttr::AT_CXX11NoReturn: | |||
6735 | handleSimpleAttribute<CXX11NoReturnAttr>(S, D, AL); | |||
6736 | break; | |||
6737 | case ParsedAttr::AT_Deprecated: | |||
6738 | handleDeprecatedAttr(S, D, AL); | |||
6739 | break; | |||
6740 | case ParsedAttr::AT_Destructor: | |||
6741 | handleDestructorAttr(S, D, AL); | |||
6742 | break; | |||
6743 | case ParsedAttr::AT_EnableIf: | |||
6744 | handleEnableIfAttr(S, D, AL); | |||
6745 | break; | |||
6746 | case ParsedAttr::AT_DiagnoseIf: | |||
6747 | handleDiagnoseIfAttr(S, D, AL); | |||
6748 | break; | |||
6749 | case ParsedAttr::AT_ExtVectorType: | |||
6750 | handleExtVectorTypeAttr(S, D, AL); | |||
6751 | break; | |||
6752 | case ParsedAttr::AT_ExternalSourceSymbol: | |||
6753 | handleExternalSourceSymbolAttr(S, D, AL); | |||
6754 | break; | |||
6755 | case ParsedAttr::AT_MinSize: | |||
6756 | handleMinSizeAttr(S, D, AL); | |||
6757 | break; | |||
6758 | case ParsedAttr::AT_OptimizeNone: | |||
6759 | handleOptimizeNoneAttr(S, D, AL); | |||
6760 | break; | |||
6761 | case ParsedAttr::AT_FlagEnum: | |||
6762 | handleSimpleAttribute<FlagEnumAttr>(S, D, AL); | |||
6763 | break; | |||
6764 | case ParsedAttr::AT_EnumExtensibility: | |||
6765 | handleEnumExtensibilityAttr(S, D, AL); | |||
6766 | break; | |||
6767 | case ParsedAttr::AT_Flatten: | |||
6768 | handleSimpleAttribute<FlattenAttr>(S, D, AL); | |||
6769 | break; | |||
6770 | case ParsedAttr::AT_Format: | |||
6771 | handleFormatAttr(S, D, AL); | |||
6772 | break; | |||
6773 | case ParsedAttr::AT_FormatArg: | |||
6774 | handleFormatArgAttr(S, D, AL); | |||
6775 | break; | |||
6776 | case ParsedAttr::AT_Callback: | |||
6777 | handleCallbackAttr(S, D, AL); | |||
6778 | break; | |||
6779 | case ParsedAttr::AT_CUDAGlobal: | |||
6780 | handleGlobalAttr(S, D, AL); | |||
6781 | break; | |||
6782 | case ParsedAttr::AT_CUDADevice: | |||
6783 | handleSimpleAttributeWithExclusions<CUDADeviceAttr, CUDAGlobalAttr>(S, D, | |||
6784 | AL); | |||
6785 | break; | |||
6786 | case ParsedAttr::AT_CUDAHost: | |||
6787 | handleSimpleAttributeWithExclusions<CUDAHostAttr, CUDAGlobalAttr>(S, D, AL); | |||
6788 | break; | |||
6789 | case ParsedAttr::AT_GNUInline: | |||
6790 | handleGNUInlineAttr(S, D, AL); | |||
6791 | break; | |||
6792 | case ParsedAttr::AT_CUDALaunchBounds: | |||
6793 | handleLaunchBoundsAttr(S, D, AL); | |||
6794 | break; | |||
6795 | case ParsedAttr::AT_Restrict: | |||
6796 | handleRestrictAttr(S, D, AL); | |||
6797 | break; | |||
6798 | case ParsedAttr::AT_LifetimeBound: | |||
6799 | handleSimpleAttribute<LifetimeBoundAttr>(S, D, AL); | |||
6800 | break; | |||
6801 | case ParsedAttr::AT_MayAlias: | |||
6802 | handleSimpleAttribute<MayAliasAttr>(S, D, AL); | |||
6803 | break; | |||
6804 | case ParsedAttr::AT_Mode: | |||
6805 | handleModeAttr(S, D, AL); | |||
6806 | break; | |||
6807 | case ParsedAttr::AT_NoAlias: | |||
6808 | handleSimpleAttribute<NoAliasAttr>(S, D, AL); | |||
6809 | break; | |||
6810 | case ParsedAttr::AT_NoCommon: | |||
6811 | handleSimpleAttribute<NoCommonAttr>(S, D, AL); | |||
6812 | break; | |||
6813 | case ParsedAttr::AT_NoSplitStack: | |||
6814 | handleSimpleAttribute<NoSplitStackAttr>(S, D, AL); | |||
6815 | break; | |||
6816 | case ParsedAttr::AT_NonNull: | |||
6817 | if (auto *PVD = dyn_cast<ParmVarDecl>(D)) | |||
6818 | handleNonNullAttrParameter(S, PVD, AL); | |||
6819 | else | |||
6820 | handleNonNullAttr(S, D, AL); | |||
6821 | break; | |||
6822 | case ParsedAttr::AT_ReturnsNonNull: | |||
6823 | handleReturnsNonNullAttr(S, D, AL); | |||
6824 | break; | |||
6825 | case ParsedAttr::AT_NoEscape: | |||
6826 | handleNoEscapeAttr(S, D, AL); | |||
6827 | break; | |||
6828 | case ParsedAttr::AT_AssumeAligned: | |||
6829 | handleAssumeAlignedAttr(S, D, AL); | |||
6830 | break; | |||
6831 | case ParsedAttr::AT_AllocAlign: | |||
6832 | handleAllocAlignAttr(S, D, AL); | |||
6833 | break; | |||
6834 | case ParsedAttr::AT_Overloadable: | |||
6835 | handleSimpleAttribute<OverloadableAttr>(S, D, AL); | |||
6836 | break; | |||
6837 | case ParsedAttr::AT_Ownership: | |||
6838 | handleOwnershipAttr(S, D, AL); | |||
6839 | break; | |||
6840 | case ParsedAttr::AT_Cold: | |||
6841 | handleSimpleAttributeWithExclusions<ColdAttr, HotAttr>(S, D, AL); | |||
6842 | break; | |||
6843 | case ParsedAttr::AT_Hot: | |||
6844 | handleSimpleAttributeWithExclusions<HotAttr, ColdAttr>(S, D, AL); | |||
6845 | break; | |||
6846 | case ParsedAttr::AT_Naked: | |||
6847 | handleNakedAttr(S, D, AL); | |||
6848 | break; | |||
6849 | case ParsedAttr::AT_NoReturn: | |||
6850 | handleNoReturnAttr(S, D, AL); | |||
6851 | break; | |||
6852 | case ParsedAttr::AT_AnyX86NoCfCheck: | |||
6853 | handleNoCfCheckAttr(S, D, AL); | |||
6854 | break; | |||
6855 | case ParsedAttr::AT_NoThrow: | |||
6856 | if (!AL.isUsedAsTypeAttr()) | |||
6857 | handleSimpleAttribute<NoThrowAttr>(S, D, AL); | |||
6858 | break; | |||
6859 | case ParsedAttr::AT_CUDAShared: | |||
6860 | handleSharedAttr(S, D, AL); | |||
6861 | break; | |||
6862 | case ParsedAttr::AT_VecReturn: | |||
6863 | handleVecReturnAttr(S, D, AL); | |||
6864 | break; | |||
6865 | case ParsedAttr::AT_ObjCOwnership: | |||
6866 | handleObjCOwnershipAttr(S, D, AL); | |||
6867 | break; | |||
6868 | case ParsedAttr::AT_ObjCPreciseLifetime: | |||
6869 | handleObjCPreciseLifetimeAttr(S, D, AL); | |||
6870 | break; | |||
6871 | case ParsedAttr::AT_ObjCReturnsInnerPointer: | |||
6872 | handleObjCReturnsInnerPointerAttr(S, D, AL); | |||
6873 | break; | |||
6874 | case ParsedAttr::AT_ObjCRequiresSuper: | |||
6875 | handleObjCRequiresSuperAttr(S, D, AL); | |||
6876 | break; | |||
6877 | case ParsedAttr::AT_ObjCBridge: | |||
6878 | handleObjCBridgeAttr(S, D, AL); | |||
6879 | break; | |||
6880 | case ParsedAttr::AT_ObjCBridgeMutable: | |||
6881 | handleObjCBridgeMutableAttr(S, D, AL); | |||
6882 | break; | |||
6883 | case ParsedAttr::AT_ObjCBridgeRelated: | |||
6884 | handleObjCBridgeRelatedAttr(S, D, AL); | |||
6885 | break; | |||
6886 | case ParsedAttr::AT_ObjCDesignatedInitializer: | |||
6887 | handleObjCDesignatedInitializer(S, D, AL); | |||
6888 | break; | |||
6889 | case ParsedAttr::AT_ObjCRuntimeName: | |||
6890 | handleObjCRuntimeName(S, D, AL); | |||
6891 | break; | |||
6892 | case ParsedAttr::AT_ObjCRuntimeVisible: | |||
6893 | handleSimpleAttribute<ObjCRuntimeVisibleAttr>(S, D, AL); | |||
6894 | break; | |||
6895 | case ParsedAttr::AT_ObjCBoxable: | |||
6896 | handleObjCBoxable(S, D, AL); | |||
6897 | break; | |||
6898 | case ParsedAttr::AT_CFAuditedTransfer: | |||
6899 | handleSimpleAttributeWithExclusions<CFAuditedTransferAttr, | |||
6900 | CFUnknownTransferAttr>(S, D, AL); | |||
6901 | break; | |||
6902 | case ParsedAttr::AT_CFUnknownTransfer: | |||
6903 | handleSimpleAttributeWithExclusions<CFUnknownTransferAttr, | |||
6904 | CFAuditedTransferAttr>(S, D, AL); | |||
6905 | break; | |||
6906 | case ParsedAttr::AT_CFConsumed: | |||
6907 | case ParsedAttr::AT_NSConsumed: | |||
6908 | case ParsedAttr::AT_OSConsumed: | |||
6909 | S.AddXConsumedAttr(D, AL.getRange(), AL.getAttributeSpellingListIndex(), | |||
6910 | parsedAttrToRetainOwnershipKind(AL), | |||
6911 | /*IsTemplateInstantiation=*/false); | |||
6912 | break; | |||
6913 | case ParsedAttr::AT_NSConsumesSelf: | |||
6914 | handleSimpleAttribute<NSConsumesSelfAttr>(S, D, AL); | |||
6915 | break; | |||
6916 | case ParsedAttr::AT_OSConsumesThis: | |||
6917 | handleSimpleAttribute<OSConsumesThisAttr>(S, D, AL); | |||
6918 | break; | |||
6919 | case ParsedAttr::AT_OSReturnsRetainedOnZero: | |||
6920 | handleSimpleAttributeOrDiagnose<OSReturnsRetainedOnZeroAttr>( | |||
6921 | S, D, AL, isValidOSObjectOutParameter(D), | |||
6922 | diag::warn_ns_attribute_wrong_parameter_type, | |||
6923 | /*Extra Args=*/AL, /*pointer-to-OSObject-pointer*/ 3, AL.getRange()); | |||
6924 | break; | |||
6925 | case ParsedAttr::AT_OSReturnsRetainedOnNonZero: | |||
6926 | handleSimpleAttributeOrDiagnose<OSReturnsRetainedOnNonZeroAttr>( | |||
6927 | S, D, AL, isValidOSObjectOutParameter(D), | |||
6928 | diag::warn_ns_attribute_wrong_parameter_type, | |||
6929 | /*Extra Args=*/AL, /*pointer-to-OSObject-poointer*/ 3, AL.getRange()); | |||
6930 | break; | |||
6931 | case ParsedAttr::AT_NSReturnsAutoreleased: | |||
6932 | case ParsedAttr::AT_NSReturnsNotRetained: | |||
6933 | case ParsedAttr::AT_NSReturnsRetained: | |||
6934 | case ParsedAttr::AT_CFReturnsNotRetained: | |||
6935 | case ParsedAttr::AT_CFReturnsRetained: | |||
6936 | case ParsedAttr::AT_OSReturnsNotRetained: | |||
6937 | case ParsedAttr::AT_OSReturnsRetained: | |||
6938 | handleXReturnsXRetainedAttr(S, D, AL); | |||
6939 | break; | |||
6940 | case ParsedAttr::AT_WorkGroupSizeHint: | |||
6941 | handleWorkGroupSize<WorkGroupSizeHintAttr>(S, D, AL); | |||
6942 | break; | |||
6943 | case ParsedAttr::AT_ReqdWorkGroupSize: | |||
6944 | handleWorkGroupSize<ReqdWorkGroupSizeAttr>(S, D, AL); | |||
6945 | break; | |||
6946 | case ParsedAttr::AT_OpenCLIntelReqdSubGroupSize: | |||
6947 | handleSubGroupSize(S, D, AL); | |||
6948 | break; | |||
6949 | case ParsedAttr::AT_VecTypeHint: | |||
6950 | handleVecTypeHint(S, D, AL); | |||
6951 | break; | |||
6952 | case ParsedAttr::AT_RequireConstantInit: | |||
6953 | handleSimpleAttribute<RequireConstantInitAttr>(S, D, AL); | |||
6954 | break; | |||
6955 | case ParsedAttr::AT_InitPriority: | |||
6956 | handleInitPriorityAttr(S, D, AL); | |||
6957 | break; | |||
6958 | case ParsedAttr::AT_Packed: | |||
6959 | handlePackedAttr(S, D, AL); | |||
6960 | break; | |||
6961 | case ParsedAttr::AT_Section: | |||
6962 | handleSectionAttr(S, D, AL); | |||
6963 | break; | |||
6964 | case ParsedAttr::AT_SpeculativeLoadHardening: | |||
6965 | handleSimpleAttributeWithExclusions<SpeculativeLoadHardeningAttr, | |||
6966 | NoSpeculativeLoadHardeningAttr>(S, D, | |||
6967 | AL); | |||
6968 | break; | |||
6969 | case ParsedAttr::AT_NoSpeculativeLoadHardening: | |||
6970 | handleSimpleAttributeWithExclusions<NoSpeculativeLoadHardeningAttr, | |||
6971 | SpeculativeLoadHardeningAttr>(S, D, AL); | |||
6972 | break; | |||
6973 | case ParsedAttr::AT_CodeSeg: | |||
6974 | handleCodeSegAttr(S, D, AL); | |||
6975 | break; | |||
6976 | case ParsedAttr::AT_Target: | |||
6977 | handleTargetAttr(S, D, AL); | |||
6978 | break; | |||
6979 | case ParsedAttr::AT_MinVectorWidth: | |||
6980 | handleMinVectorWidthAttr(S, D, AL); | |||
6981 | break; | |||
6982 | case ParsedAttr::AT_Unavailable: | |||
6983 | handleAttrWithMessage<UnavailableAttr>(S, D, AL); | |||
6984 | break; | |||
6985 | case ParsedAttr::AT_ArcWeakrefUnavailable: | |||
6986 | handleSimpleAttribute<ArcWeakrefUnavailableAttr>(S, D, AL); | |||
6987 | break; | |||
6988 | case ParsedAttr::AT_ObjCRootClass: | |||
6989 | handleSimpleAttribute<ObjCRootClassAttr>(S, D, AL); | |||
6990 | break; | |||
6991 | case ParsedAttr::AT_ObjCNonLazyClass: | |||
6992 | handleSimpleAttribute<ObjCNonLazyClassAttr>(S, D, AL); | |||
6993 | break; | |||
6994 | case ParsedAttr::AT_ObjCSubclassingRestricted: | |||
6995 | handleSimpleAttribute<ObjCSubclassingRestrictedAttr>(S, D, AL); | |||
6996 | break; | |||
6997 | case ParsedAttr::AT_ObjCClassStub: | |||
6998 | handleSimpleAttribute<ObjCClassStubAttr>(S, D, AL); | |||
6999 | break; | |||
7000 | case ParsedAttr::AT_ObjCExplicitProtocolImpl: | |||
7001 | handleObjCSuppresProtocolAttr(S, D, AL); | |||
7002 | break; | |||
7003 | case ParsedAttr::AT_ObjCRequiresPropertyDefs: | |||
7004 | handleSimpleAttribute<ObjCRequiresPropertyDefsAttr>(S, D, AL); | |||
7005 | break; | |||
7006 | case ParsedAttr::AT_Unused: | |||
7007 | handleUnusedAttr(S, D, AL); | |||
7008 | break; | |||
7009 | case ParsedAttr::AT_ReturnsTwice: | |||
7010 | handleSimpleAttribute<ReturnsTwiceAttr>(S, D, AL); | |||
7011 | break; | |||
7012 | case ParsedAttr::AT_NotTailCalled: | |||
7013 | handleSimpleAttributeWithExclusions<NotTailCalledAttr, AlwaysInlineAttr>( | |||
7014 | S, D, AL); | |||
7015 | break; | |||
7016 | case ParsedAttr::AT_DisableTailCalls: | |||
7017 | handleSimpleAttributeWithExclusions<DisableTailCallsAttr, NakedAttr>(S, D, | |||
7018 | AL); | |||
7019 | break; | |||
7020 | case ParsedAttr::AT_Used: | |||
7021 | handleSimpleAttribute<UsedAttr>(S, D, AL); | |||
7022 | break; | |||
7023 | case ParsedAttr::AT_Visibility: | |||
7024 | handleVisibilityAttr(S, D, AL, false); | |||
7025 | break; | |||
7026 | case ParsedAttr::AT_TypeVisibility: | |||
7027 | handleVisibilityAttr(S, D, AL, true); | |||
7028 | break; | |||
7029 | case ParsedAttr::AT_WarnUnused: | |||
7030 | handleSimpleAttribute<WarnUnusedAttr>(S, D, AL); | |||
7031 | break; | |||
7032 | case ParsedAttr::AT_WarnUnusedResult: | |||
7033 | handleWarnUnusedResult(S, D, AL); | |||
7034 | break; | |||
7035 | case ParsedAttr::AT_Weak: | |||
7036 | handleSimpleAttribute<WeakAttr>(S, D, AL); | |||
7037 | break; | |||
7038 | case ParsedAttr::AT_WeakRef: | |||
7039 | handleWeakRefAttr(S, D, AL); | |||
7040 | break; | |||
7041 | case ParsedAttr::AT_WeakImport: | |||
7042 | handleWeakImportAttr(S, D, AL); | |||
7043 | break; | |||
7044 | case ParsedAttr::AT_TransparentUnion: | |||
7045 | handleTransparentUnionAttr(S, D, AL); | |||
7046 | break; | |||
7047 | case ParsedAttr::AT_ObjCException: | |||
7048 | handleSimpleAttribute<ObjCExceptionAttr>(S, D, AL); | |||
7049 | break; | |||
7050 | case ParsedAttr::AT_ObjCMethodFamily: | |||
7051 | handleObjCMethodFamilyAttr(S, D, AL); | |||
7052 | break; | |||
7053 | case ParsedAttr::AT_ObjCNSObject: | |||
7054 | handleObjCNSObject(S, D, AL); | |||
7055 | break; | |||
7056 | case ParsedAttr::AT_ObjCIndependentClass: | |||
7057 | handleObjCIndependentClass(S, D, AL); | |||
7058 | break; | |||
7059 | case ParsedAttr::AT_Blocks: | |||
7060 | handleBlocksAttr(S, D, AL); | |||
7061 | break; | |||
7062 | case ParsedAttr::AT_Sentinel: | |||
7063 | handleSentinelAttr(S, D, AL); | |||
7064 | break; | |||
7065 | case ParsedAttr::AT_Const: | |||
7066 | handleSimpleAttribute<ConstAttr>(S, D, AL); | |||
7067 | break; | |||
7068 | case ParsedAttr::AT_Pure: | |||
7069 | handleSimpleAttribute<PureAttr>(S, D, AL); | |||
7070 | break; | |||
7071 | case ParsedAttr::AT_Cleanup: | |||
7072 | handleCleanupAttr(S, D, AL); | |||
7073 | break; | |||
7074 | case ParsedAttr::AT_NoDebug: | |||
7075 | handleNoDebugAttr(S, D, AL); | |||
7076 | break; | |||
7077 | case ParsedAttr::AT_NoDuplicate: | |||
7078 | handleSimpleAttribute<NoDuplicateAttr>(S, D, AL); | |||
7079 | break; | |||
7080 | case ParsedAttr::AT_Convergent: | |||
7081 | handleSimpleAttribute<ConvergentAttr>(S, D, AL); | |||
7082 | break; | |||
7083 | case ParsedAttr::AT_NoInline: | |||
7084 | handleSimpleAttribute<NoInlineAttr>(S, D, AL); | |||
7085 | break; | |||
7086 | case ParsedAttr::AT_NoInstrumentFunction: // Interacts with -pg. | |||
7087 | handleSimpleAttribute<NoInstrumentFunctionAttr>(S, D, AL); | |||
7088 | break; | |||
7089 | case ParsedAttr::AT_NoStackProtector: | |||
7090 | // Interacts with -fstack-protector options. | |||
7091 | handleSimpleAttribute<NoStackProtectorAttr>(S, D, AL); | |||
7092 | break; | |||
7093 | case ParsedAttr::AT_StdCall: | |||
7094 | case ParsedAttr::AT_CDecl: | |||
7095 | case ParsedAttr::AT_FastCall: | |||
7096 | case ParsedAttr::AT_ThisCall: | |||
7097 | case ParsedAttr::AT_Pascal: | |||
7098 | case ParsedAttr::AT_RegCall: | |||
7099 | case ParsedAttr::AT_SwiftCall: | |||
7100 | case ParsedAttr::AT_VectorCall: | |||
7101 | case ParsedAttr::AT_MSABI: | |||
7102 | case ParsedAttr::AT_SysVABI: | |||
7103 | case ParsedAttr::AT_Pcs: | |||
7104 | case ParsedAttr::AT_IntelOclBicc: | |||
7105 | case ParsedAttr::AT_PreserveMost: | |||
7106 | case ParsedAttr::AT_PreserveAll: | |||
7107 | case ParsedAttr::AT_AArch64VectorPcs: | |||
7108 | handleCallConvAttr(S, D, AL); | |||
7109 | break; | |||
7110 | case ParsedAttr::AT_Suppress: | |||
7111 | handleSuppressAttr(S, D, AL); | |||
7112 | break; | |||
7113 | case ParsedAttr::AT_OpenCLKernel: | |||
7114 | handleSimpleAttribute<OpenCLKernelAttr>(S, D, AL); | |||
7115 | break; | |||
7116 | case ParsedAttr::AT_OpenCLAccess: | |||
7117 | handleOpenCLAccessAttr(S, D, AL); | |||
7118 | break; | |||
7119 | case ParsedAttr::AT_OpenCLNoSVM: | |||
7120 | handleOpenCLNoSVMAttr(S, D, AL); | |||
7121 | break; | |||
7122 | case ParsedAttr::AT_SwiftContext: | |||
7123 | handleParameterABIAttr(S, D, AL, ParameterABI::SwiftContext); | |||
7124 | break; | |||
7125 | case ParsedAttr::AT_SwiftErrorResult: | |||
7126 | handleParameterABIAttr(S, D, AL, ParameterABI::SwiftErrorResult); | |||
7127 | break; | |||
7128 | case ParsedAttr::AT_SwiftIndirectResult: | |||
7129 | handleParameterABIAttr(S, D, AL, ParameterABI::SwiftIndirectResult); | |||
7130 | break; | |||
7131 | case ParsedAttr::AT_InternalLinkage: | |||
7132 | handleInternalLinkageAttr(S, D, AL); | |||
7133 | break; | |||
7134 | case ParsedAttr::AT_ExcludeFromExplicitInstantiation: | |||
7135 | handleSimpleAttribute<ExcludeFromExplicitInstantiationAttr>(S, D, AL); | |||
7136 | break; | |||
7137 | case ParsedAttr::AT_LTOVisibilityPublic: | |||
7138 | handleSimpleAttribute<LTOVisibilityPublicAttr>(S, D, AL); | |||
7139 | break; | |||
7140 | ||||
7141 | // Microsoft attributes: | |||
7142 | case ParsedAttr::AT_EmptyBases: | |||
7143 | handleSimpleAttribute<EmptyBasesAttr>(S, D, AL); | |||
7144 | break; | |||
7145 | case ParsedAttr::AT_LayoutVersion: | |||
7146 | handleLayoutVersion(S, D, AL); | |||
7147 | break; | |||
7148 | case ParsedAttr::AT_TrivialABI: | |||
7149 | handleSimpleAttribute<TrivialABIAttr>(S, D, AL); | |||
7150 | break; | |||
7151 | case ParsedAttr::AT_MSNoVTable: | |||
7152 | handleSimpleAttribute<MSNoVTableAttr>(S, D, AL); | |||
7153 | break; | |||
7154 | case ParsedAttr::AT_MSStruct: | |||
7155 | handleSimpleAttribute<MSStructAttr>(S, D, AL); | |||
7156 | break; | |||
7157 | case ParsedAttr::AT_Uuid: | |||
7158 | handleUuidAttr(S, D, AL); | |||
7159 | break; | |||
7160 | case ParsedAttr::AT_MSInheritance: | |||
7161 | handleMSInheritanceAttr(S, D, AL); | |||
7162 | break; | |||
7163 | case ParsedAttr::AT_SelectAny: | |||
7164 | handleSimpleAttribute<SelectAnyAttr>(S, D, AL); | |||
7165 | break; | |||
7166 | case ParsedAttr::AT_Thread: | |||
7167 | handleDeclspecThreadAttr(S, D, AL); | |||
7168 | break; | |||
7169 | ||||
7170 | case ParsedAttr::AT_AbiTag: | |||
7171 | handleAbiTagAttr(S, D, AL); | |||
7172 | break; | |||
7173 | ||||
7174 | // Thread safety attributes: | |||
7175 | case ParsedAttr::AT_AssertExclusiveLock: | |||
7176 | handleAssertExclusiveLockAttr(S, D, AL); | |||
7177 | break; | |||
7178 | case ParsedAttr::AT_AssertSharedLock: | |||
7179 | handleAssertSharedLockAttr(S, D, AL); | |||
7180 | break; | |||
7181 | case ParsedAttr::AT_GuardedVar: | |||
7182 | handleSimpleAttribute<GuardedVarAttr>(S, D, AL); | |||
7183 | break; | |||
7184 | case ParsedAttr::AT_PtGuardedVar: | |||
7185 | handlePtGuardedVarAttr(S, D, AL); | |||
7186 | break; | |||
7187 | case ParsedAttr::AT_ScopedLockable: | |||
7188 | handleSimpleAttribute<ScopedLockableAttr>(S, D, AL); | |||
7189 | break; | |||
7190 | case ParsedAttr::AT_NoSanitize: | |||
7191 | handleNoSanitizeAttr(S, D, AL); | |||
7192 | break; | |||
7193 | case ParsedAttr::AT_NoSanitizeSpecific: | |||
7194 | handleNoSanitizeSpecificAttr(S, D, AL); | |||
7195 | break; | |||
7196 | case ParsedAttr::AT_NoThreadSafetyAnalysis: | |||
7197 | handleSimpleAttribute<NoThreadSafetyAnalysisAttr>(S, D, AL); | |||
7198 | break; | |||
7199 | case ParsedAttr::AT_GuardedBy: | |||
7200 | handleGuardedByAttr(S, D, AL); | |||
7201 | break; | |||
7202 | case ParsedAttr::AT_PtGuardedBy: | |||
7203 | handlePtGuardedByAttr(S, D, AL); | |||
7204 | break; | |||
7205 | case ParsedAttr::AT_ExclusiveTrylockFunction: | |||
7206 | handleExclusiveTrylockFunctionAttr(S, D, AL); | |||
7207 | break; | |||
7208 | case ParsedAttr::AT_LockReturned: | |||
7209 | handleLockReturnedAttr(S, D, AL); | |||
7210 | break; | |||
7211 | case ParsedAttr::AT_LocksExcluded: | |||
7212 | handleLocksExcludedAttr(S, D, AL); | |||
7213 | break; | |||
7214 | case ParsedAttr::AT_SharedTrylockFunction: | |||
7215 | handleSharedTrylockFunctionAttr(S, D, AL); | |||
7216 | break; | |||
7217 | case ParsedAttr::AT_AcquiredBefore: | |||
7218 | handleAcquiredBeforeAttr(S, D, AL); | |||
7219 | break; | |||
7220 | case ParsedAttr::AT_AcquiredAfter: | |||
7221 | handleAcquiredAfterAttr(S, D, AL); | |||
7222 | break; | |||
7223 | ||||
7224 | // Capability analysis attributes. | |||
7225 | case ParsedAttr::AT_Capability: | |||
7226 | case ParsedAttr::AT_Lockable: | |||
7227 | handleCapabilityAttr(S, D, AL); | |||
7228 | break; | |||
7229 | case ParsedAttr::AT_RequiresCapability: | |||
7230 | handleRequiresCapabilityAttr(S, D, AL); | |||
7231 | break; | |||
7232 | ||||
7233 | case ParsedAttr::AT_AssertCapability: | |||
7234 | handleAssertCapabilityAttr(S, D, AL); | |||
7235 | break; | |||
7236 | case ParsedAttr::AT_AcquireCapability: | |||
7237 | handleAcquireCapabilityAttr(S, D, AL); | |||
7238 | break; | |||
7239 | case ParsedAttr::AT_ReleaseCapability: | |||
7240 | handleReleaseCapabilityAttr(S, D, AL); | |||
7241 | break; | |||
7242 | case ParsedAttr::AT_TryAcquireCapability: | |||
7243 | handleTryAcquireCapabilityAttr(S, D, AL); | |||
7244 | break; | |||
7245 | ||||
7246 | // Consumed analysis attributes. | |||
7247 | case ParsedAttr::AT_Consumable: | |||
7248 | handleConsumableAttr(S, D, AL); | |||
7249 | break; | |||
7250 | case ParsedAttr::AT_ConsumableAutoCast: | |||
7251 | handleSimpleAttribute<ConsumableAutoCastAttr>(S, D, AL); | |||
7252 | break; | |||
7253 | case ParsedAttr::AT_ConsumableSetOnRead: | |||
7254 | handleSimpleAttribute<ConsumableSetOnReadAttr>(S, D, AL); | |||
7255 | break; | |||
7256 | case ParsedAttr::AT_CallableWhen: | |||
7257 | handleCallableWhenAttr(S, D, AL); | |||
7258 | break; | |||
7259 | case ParsedAttr::AT_ParamTypestate: | |||
7260 | handleParamTypestateAttr(S, D, AL); | |||
7261 | break; | |||
7262 | case ParsedAttr::AT_ReturnTypestate: | |||
7263 | handleReturnTypestateAttr(S, D, AL); | |||
7264 | break; | |||
7265 | case ParsedAttr::AT_SetTypestate: | |||
7266 | handleSetTypestateAttr(S, D, AL); | |||
7267 | break; | |||
7268 | case ParsedAttr::AT_TestTypestate: | |||
7269 | handleTestTypestateAttr(S, D, AL); | |||
7270 | break; | |||
7271 | ||||
7272 | // Type safety attributes. | |||
7273 | case ParsedAttr::AT_ArgumentWithTypeTag: | |||
7274 | handleArgumentWithTypeTagAttr(S, D, AL); | |||
7275 | break; | |||
7276 | case ParsedAttr::AT_TypeTagForDatatype: | |||
7277 | handleTypeTagForDatatypeAttr(S, D, AL); | |||
7278 | break; | |||
7279 | case ParsedAttr::AT_AnyX86NoCallerSavedRegisters: | |||
7280 | handleSimpleAttribute<AnyX86NoCallerSavedRegistersAttr>(S, D, AL); | |||
7281 | break; | |||
7282 | case ParsedAttr::AT_RenderScriptKernel: | |||
7283 | handleSimpleAttribute<RenderScriptKernelAttr>(S, D, AL); | |||
7284 | break; | |||
7285 | // XRay attributes. | |||
7286 | case ParsedAttr::AT_XRayInstrument: | |||
7287 | handleSimpleAttribute<XRayInstrumentAttr>(S, D, AL); | |||
7288 | break; | |||
7289 | case ParsedAttr::AT_XRayLogArgs: | |||
7290 | handleXRayLogArgsAttr(S, D, AL); | |||
7291 | break; | |||
7292 | ||||
7293 | // Move semantics attribute. | |||
7294 | case ParsedAttr::AT_Reinitializes: | |||
7295 | handleSimpleAttribute<ReinitializesAttr>(S, D, AL); | |||
7296 | break; | |||
7297 | ||||
7298 | case ParsedAttr::AT_AlwaysDestroy: | |||
7299 | case ParsedAttr::AT_NoDestroy: | |||
7300 | handleDestroyAttr(S, D, AL); | |||
7301 | break; | |||
7302 | ||||
7303 | case ParsedAttr::AT_Uninitialized: | |||
7304 | handleUninitializedAttr(S, D, AL); | |||
7305 | break; | |||
7306 | ||||
7307 | case ParsedAttr::AT_ObjCExternallyRetained: | |||
7308 | handleObjCExternallyRetainedAttr(S, D, AL); | |||
7309 | break; | |||
7310 | ||||
7311 | case ParsedAttr::AT_MIGServerRoutine: | |||
7312 | handleMIGServerRoutineAttr(S, D, AL); | |||
7313 | break; | |||
7314 | ||||
7315 | case ParsedAttr::AT_MSAllocator: | |||
7316 | handleMSAllocatorAttr(S, D, AL); | |||
7317 | break; | |||
7318 | } | |||
7319 | } | |||
7320 | ||||
7321 | /// ProcessDeclAttributeList - Apply all the decl attributes in the specified | |||
7322 | /// attribute list to the specified decl, ignoring any type attributes. | |||
7323 | void Sema::ProcessDeclAttributeList(Scope *S, Decl *D, | |||
7324 | const ParsedAttributesView &AttrList, | |||
7325 | bool IncludeCXX11Attributes) { | |||
7326 | if (AttrList.empty()) | |||
7327 | return; | |||
7328 | ||||
7329 | for (const ParsedAttr &AL : AttrList) | |||
7330 | ProcessDeclAttribute(*this, S, D, AL, IncludeCXX11Attributes); | |||
7331 | ||||
7332 | // FIXME: We should be able to handle these cases in TableGen. | |||
7333 | // GCC accepts | |||
7334 | // static int a9 __attribute__((weakref)); | |||
7335 | // but that looks really pointless. We reject it. | |||
7336 | if (D->hasAttr<WeakRefAttr>() && !D->hasAttr<AliasAttr>()) { | |||
7337 | Diag(AttrList.begin()->getLoc(), diag::err_attribute_weakref_without_alias) | |||
7338 | << cast<NamedDecl>(D); | |||
7339 | D->dropAttr<WeakRefAttr>(); | |||
7340 | return; | |||
7341 | } | |||
7342 | ||||
7343 | // FIXME: We should be able to handle this in TableGen as well. It would be | |||
7344 | // good to have a way to specify "these attributes must appear as a group", | |||
7345 | // for these. Additionally, it would be good to have a way to specify "these | |||
7346 | // attribute must never appear as a group" for attributes like cold and hot. | |||
7347 | if (!D->hasAttr<OpenCLKernelAttr>()) { | |||
7348 | // These attributes cannot be applied to a non-kernel function. | |||
7349 | if (const auto *A = D->getAttr<ReqdWorkGroupSizeAttr>()) { | |||
7350 | // FIXME: This emits a different error message than | |||
7351 | // diag::err_attribute_wrong_decl_type + ExpectedKernelFunction. | |||
7352 | Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A; | |||
7353 | D->setInvalidDecl(); | |||
7354 | } else if (const auto *A = D->getAttr<WorkGroupSizeHintAttr>()) { | |||
7355 | Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A; | |||
7356 | D->setInvalidDecl(); | |||
7357 | } else if (const auto *A = D->getAttr<VecTypeHintAttr>()) { | |||
7358 | Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A; | |||
7359 | D->setInvalidDecl(); | |||
7360 | } else if (const auto *A = D->getAttr<OpenCLIntelReqdSubGroupSizeAttr>()) { | |||
7361 | Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A; | |||
7362 | D->setInvalidDecl(); | |||
7363 | } else if (!D->hasAttr<CUDAGlobalAttr>()) { | |||
7364 | if (const auto *A = D->getAttr<AMDGPUFlatWorkGroupSizeAttr>()) { | |||
7365 | Diag(D->getLocation(), diag::err_attribute_wrong_decl_type) | |||
7366 | << A << ExpectedKernelFunction; | |||
7367 | D->setInvalidDecl(); | |||
7368 | } else if (const auto *A = D->getAttr<AMDGPUWavesPerEUAttr>()) { | |||
7369 | Diag(D->getLocation(), diag::err_attribute_wrong_decl_type) | |||
7370 | << A << ExpectedKernelFunction; | |||
7371 | D->setInvalidDecl(); | |||
7372 | } else if (const auto *A = D->getAttr<AMDGPUNumSGPRAttr>()) { | |||
7373 | Diag(D->getLocation(), diag::err_attribute_wrong_decl_type) | |||
7374 | << A << ExpectedKernelFunction; | |||
7375 | D->setInvalidDecl(); | |||
7376 | } else if (const auto *A = D->getAttr<AMDGPUNumVGPRAttr>()) { | |||
7377 | Diag(D->getLocation(), diag::err_attribute_wrong_decl_type) | |||
7378 | << A << ExpectedKernelFunction; | |||
7379 | D->setInvalidDecl(); | |||
7380 | } | |||
7381 | } | |||
7382 | } | |||
7383 | ||||
7384 | // Do this check after processing D's attributes because the attribute | |||
7385 | // objc_method_family can change whether the given method is in the init | |||
7386 | // family, and it can be applied after objc_designated_initializer. This is a | |||
7387 | // bit of a hack, but we need it to be compatible with versions of clang that | |||
7388 | // processed the attribute list in the wrong order. | |||
7389 | if (D->hasAttr<ObjCDesignatedInitializerAttr>() && | |||
7390 | cast<ObjCMethodDecl>(D)->getMethodFamily() != OMF_init) { | |||
7391 | Diag(D->getLocation(), diag::err_designated_init_attr_non_init); | |||
7392 | D->dropAttr<ObjCDesignatedInitializerAttr>(); | |||
7393 | } | |||
7394 | } | |||
7395 | ||||
7396 | // Helper for delayed processing TransparentUnion attribute. | |||
7397 | void Sema::ProcessDeclAttributeDelayed(Decl *D, | |||
7398 | const ParsedAttributesView &AttrList) { | |||
7399 | for (const ParsedAttr &AL : AttrList) | |||
7400 | if (AL.getKind() == ParsedAttr::AT_TransparentUnion) { | |||
7401 | handleTransparentUnionAttr(*this, D, AL); | |||
7402 | break; | |||
7403 | } | |||
7404 | } | |||
7405 | ||||
7406 | // Annotation attributes are the only attributes allowed after an access | |||
7407 | // specifier. | |||
7408 | bool Sema::ProcessAccessDeclAttributeList( | |||
7409 | AccessSpecDecl *ASDecl, const ParsedAttributesView &AttrList) { | |||
7410 | for (const ParsedAttr &AL : AttrList) { | |||
7411 | if (AL.getKind() == ParsedAttr::AT_Annotate) { | |||
7412 | ProcessDeclAttribute(*this, nullptr, ASDecl, AL, AL.isCXX11Attribute()); | |||
7413 | } else { | |||
7414 | Diag(AL.getLoc(), diag::err_only_annotate_after_access_spec); | |||
7415 | return true; | |||
7416 | } | |||
7417 | } | |||
7418 | return false; | |||
7419 | } | |||
7420 | ||||
7421 | /// checkUnusedDeclAttributes - Check a list of attributes to see if it | |||
7422 | /// contains any decl attributes that we should warn about. | |||
7423 | static void checkUnusedDeclAttributes(Sema &S, const ParsedAttributesView &A) { | |||
7424 | for (const ParsedAttr &AL : A) { | |||
7425 | // Only warn if the attribute is an unignored, non-type attribute. | |||
7426 | if (AL.isUsedAsTypeAttr() || AL.isInvalid()) | |||
7427 | continue; | |||
7428 | if (AL.getKind() == ParsedAttr::IgnoredAttribute) | |||
7429 | continue; | |||
7430 | ||||
7431 | if (AL.getKind() == ParsedAttr::UnknownAttribute) { | |||
7432 | S.Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored) | |||
7433 | << AL << AL.getRange(); | |||
7434 | } else { | |||
7435 | S.Diag(AL.getLoc(), diag::warn_attribute_not_on_decl) << AL | |||
7436 | << AL.getRange(); | |||
7437 | } | |||
7438 | } | |||
7439 | } | |||
7440 | ||||
7441 | /// checkUnusedDeclAttributes - Given a declarator which is not being | |||
7442 | /// used to build a declaration, complain about any decl attributes | |||
7443 | /// which might be lying around on it. | |||
7444 | void Sema::checkUnusedDeclAttributes(Declarator &D) { | |||
7445 | ::checkUnusedDeclAttributes(*this, D.getDeclSpec().getAttributes()); | |||
7446 | ::checkUnusedDeclAttributes(*this, D.getAttributes()); | |||
7447 | for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) | |||
7448 | ::checkUnusedDeclAttributes(*this, D.getTypeObject(i).getAttrs()); | |||
7449 | } | |||
7450 | ||||
7451 | /// DeclClonePragmaWeak - clone existing decl (maybe definition), | |||
7452 | /// \#pragma weak needs a non-definition decl and source may not have one. | |||
7453 | NamedDecl * Sema::DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II, | |||
7454 | SourceLocation Loc) { | |||
7455 | assert(isa<FunctionDecl>(ND) || isa<VarDecl>(ND))((isa<FunctionDecl>(ND) || isa<VarDecl>(ND)) ? static_cast <void> (0) : __assert_fail ("isa<FunctionDecl>(ND) || isa<VarDecl>(ND)" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 7455, __PRETTY_FUNCTION__)); | |||
7456 | NamedDecl *NewD = nullptr; | |||
7457 | if (auto *FD = dyn_cast<FunctionDecl>(ND)) { | |||
7458 | FunctionDecl *NewFD; | |||
7459 | // FIXME: Missing call to CheckFunctionDeclaration(). | |||
7460 | // FIXME: Mangling? | |||
7461 | // FIXME: Is the qualifier info correct? | |||
7462 | // FIXME: Is the DeclContext correct? | |||
7463 | NewFD = FunctionDecl::Create(FD->getASTContext(), FD->getDeclContext(), | |||
7464 | Loc, Loc, DeclarationName(II), | |||
7465 | FD->getType(), FD->getTypeSourceInfo(), | |||
7466 | SC_None, false/*isInlineSpecified*/, | |||
7467 | FD->hasPrototype(), | |||
7468 | false/*isConstexprSpecified*/); | |||
7469 | NewD = NewFD; | |||
7470 | ||||
7471 | if (FD->getQualifier()) | |||
7472 | NewFD->setQualifierInfo(FD->getQualifierLoc()); | |||
7473 | ||||
7474 | // Fake up parameter variables; they are declared as if this were | |||
7475 | // a typedef. | |||
7476 | QualType FDTy = FD->getType(); | |||
7477 | if (const auto *FT = FDTy->getAs<FunctionProtoType>()) { | |||
7478 | SmallVector<ParmVarDecl*, 16> Params; | |||
7479 | for (const auto &AI : FT->param_types()) { | |||
7480 | ParmVarDecl *Param = BuildParmVarDeclForTypedef(NewFD, Loc, AI); | |||
7481 | Param->setScopeInfo(0, Params.size()); | |||
7482 | Params.push_back(Param); | |||
7483 | } | |||
7484 | NewFD->setParams(Params); | |||
7485 | } | |||
7486 | } else if (auto *VD = dyn_cast<VarDecl>(ND)) { | |||
7487 | NewD = VarDecl::Create(VD->getASTContext(), VD->getDeclContext(), | |||
7488 | VD->getInnerLocStart(), VD->getLocation(), II, | |||
7489 | VD->getType(), VD->getTypeSourceInfo(), | |||
7490 | VD->getStorageClass()); | |||
7491 | if (VD->getQualifier()) | |||
7492 | cast<VarDecl>(NewD)->setQualifierInfo(VD->getQualifierLoc()); | |||
7493 | } | |||
7494 | return NewD; | |||
7495 | } | |||
7496 | ||||
7497 | /// DeclApplyPragmaWeak - A declaration (maybe definition) needs \#pragma weak | |||
7498 | /// applied to it, possibly with an alias. | |||
7499 | void Sema::DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W) { | |||
7500 | if (W.getUsed()) return; // only do this once | |||
7501 | W.setUsed(true); | |||
7502 | if (W.getAlias()) { // clone decl, impersonate __attribute(weak,alias(...)) | |||
7503 | IdentifierInfo *NDId = ND->getIdentifier(); | |||
7504 | NamedDecl *NewD = DeclClonePragmaWeak(ND, W.getAlias(), W.getLocation()); | |||
7505 | NewD->addAttr(AliasAttr::CreateImplicit(Context, NDId->getName(), | |||
7506 | W.getLocation())); | |||
7507 | NewD->addAttr(WeakAttr::CreateImplicit(Context, W.getLocation())); | |||
7508 | WeakTopLevelDecl.push_back(NewD); | |||
7509 | // FIXME: "hideous" code from Sema::LazilyCreateBuiltin | |||
7510 | // to insert Decl at TU scope, sorry. | |||
7511 | DeclContext *SavedContext = CurContext; | |||
7512 | CurContext = Context.getTranslationUnitDecl(); | |||
7513 | NewD->setDeclContext(CurContext); | |||
7514 | NewD->setLexicalDeclContext(CurContext); | |||
7515 | PushOnScopeChains(NewD, S); | |||
7516 | CurContext = SavedContext; | |||
7517 | } else { // just add weak to existing | |||
7518 | ND->addAttr(WeakAttr::CreateImplicit(Context, W.getLocation())); | |||
7519 | } | |||
7520 | } | |||
7521 | ||||
7522 | void Sema::ProcessPragmaWeak(Scope *S, Decl *D) { | |||
7523 | // It's valid to "forward-declare" #pragma weak, in which case we | |||
7524 | // have to do this. | |||
7525 | LoadExternalWeakUndeclaredIdentifiers(); | |||
7526 | if (!WeakUndeclaredIdentifiers.empty()) { | |||
7527 | NamedDecl *ND = nullptr; | |||
7528 | if (auto *VD = dyn_cast<VarDecl>(D)) | |||
7529 | if (VD->isExternC()) | |||
7530 | ND = VD; | |||
7531 | if (auto *FD = dyn_cast<FunctionDecl>(D)) | |||
7532 | if (FD->isExternC()) | |||
7533 | ND = FD; | |||
7534 | if (ND) { | |||
7535 | if (IdentifierInfo *Id = ND->getIdentifier()) { | |||
7536 | auto I = WeakUndeclaredIdentifiers.find(Id); | |||
7537 | if (I != WeakUndeclaredIdentifiers.end()) { | |||
7538 | WeakInfo W = I->second; | |||
7539 | DeclApplyPragmaWeak(S, ND, W); | |||
7540 | WeakUndeclaredIdentifiers[Id] = W; | |||
7541 | } | |||
7542 | } | |||
7543 | } | |||
7544 | } | |||
7545 | } | |||
7546 | ||||
7547 | /// ProcessDeclAttributes - Given a declarator (PD) with attributes indicated in | |||
7548 | /// it, apply them to D. This is a bit tricky because PD can have attributes | |||
7549 | /// specified in many different places, and we need to find and apply them all. | |||
7550 | void Sema::ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD) { | |||
7551 | // Apply decl attributes from the DeclSpec if present. | |||
7552 | if (!PD.getDeclSpec().getAttributes().empty()) | |||
7553 | ProcessDeclAttributeList(S, D, PD.getDeclSpec().getAttributes()); | |||
7554 | ||||
7555 | // Walk the declarator structure, applying decl attributes that were in a type | |||
7556 | // position to the decl itself. This handles cases like: | |||
7557 | // int *__attr__(x)** D; | |||
7558 | // when X is a decl attribute. | |||
7559 | for (unsigned i = 0, e = PD.getNumTypeObjects(); i != e; ++i) | |||
7560 | ProcessDeclAttributeList(S, D, PD.getTypeObject(i).getAttrs(), | |||
7561 | /*IncludeCXX11Attributes=*/false); | |||
7562 | ||||
7563 | // Finally, apply any attributes on the decl itself. | |||
7564 | ProcessDeclAttributeList(S, D, PD.getAttributes()); | |||
7565 | ||||
7566 | // Apply additional attributes specified by '#pragma clang attribute'. | |||
7567 | AddPragmaAttributes(S, D); | |||
7568 | } | |||
7569 | ||||
7570 | /// Is the given declaration allowed to use a forbidden type? | |||
7571 | /// If so, it'll still be annotated with an attribute that makes it | |||
7572 | /// illegal to actually use. | |||
7573 | static bool isForbiddenTypeAllowed(Sema &S, Decl *D, | |||
7574 | const DelayedDiagnostic &diag, | |||
7575 | UnavailableAttr::ImplicitReason &reason) { | |||
7576 | // Private ivars are always okay. Unfortunately, people don't | |||
7577 | // always properly make their ivars private, even in system headers. | |||
7578 | // Plus we need to make fields okay, too. | |||
7579 | if (!isa<FieldDecl>(D) && !isa<ObjCPropertyDecl>(D) && | |||
7580 | !isa<FunctionDecl>(D)) | |||
7581 | return false; | |||
7582 | ||||
7583 | // Silently accept unsupported uses of __weak in both user and system | |||
7584 | // declarations when it's been disabled, for ease of integration with | |||
7585 | // -fno-objc-arc files. We do have to take some care against attempts | |||
7586 | // to define such things; for now, we've only done that for ivars | |||
7587 | // and properties. | |||
7588 | if ((isa<ObjCIvarDecl>(D) || isa<ObjCPropertyDecl>(D))) { | |||
7589 | if (diag.getForbiddenTypeDiagnostic() == diag::err_arc_weak_disabled || | |||
7590 | diag.getForbiddenTypeDiagnostic() == diag::err_arc_weak_no_runtime) { | |||
7591 | reason = UnavailableAttr::IR_ForbiddenWeak; | |||
7592 | return true; | |||
7593 | } | |||
7594 | } | |||
7595 | ||||
7596 | // Allow all sorts of things in system headers. | |||
7597 | if (S.Context.getSourceManager().isInSystemHeader(D->getLocation())) { | |||
7598 | // Currently, all the failures dealt with this way are due to ARC | |||
7599 | // restrictions. | |||
7600 | reason = UnavailableAttr::IR_ARCForbiddenType; | |||
7601 | return true; | |||
7602 | } | |||
7603 | ||||
7604 | return false; | |||
7605 | } | |||
7606 | ||||
7607 | /// Handle a delayed forbidden-type diagnostic. | |||
7608 | static void handleDelayedForbiddenType(Sema &S, DelayedDiagnostic &DD, | |||
7609 | Decl *D) { | |||
7610 | auto Reason = UnavailableAttr::IR_None; | |||
7611 | if (D && isForbiddenTypeAllowed(S, D, DD, Reason)) { | |||
7612 | assert(Reason && "didn't set reason?")((Reason && "didn't set reason?") ? static_cast<void > (0) : __assert_fail ("Reason && \"didn't set reason?\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 7612, __PRETTY_FUNCTION__)); | |||
7613 | D->addAttr(UnavailableAttr::CreateImplicit(S.Context, "", Reason, DD.Loc)); | |||
7614 | return; | |||
7615 | } | |||
7616 | if (S.getLangOpts().ObjCAutoRefCount) | |||
7617 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) { | |||
7618 | // FIXME: we may want to suppress diagnostics for all | |||
7619 | // kind of forbidden type messages on unavailable functions. | |||
7620 | if (FD->hasAttr<UnavailableAttr>() && | |||
7621 | DD.getForbiddenTypeDiagnostic() == | |||
7622 | diag::err_arc_array_param_no_ownership) { | |||
7623 | DD.Triggered = true; | |||
7624 | return; | |||
7625 | } | |||
7626 | } | |||
7627 | ||||
7628 | S.Diag(DD.Loc, DD.getForbiddenTypeDiagnostic()) | |||
7629 | << DD.getForbiddenTypeOperand() << DD.getForbiddenTypeArgument(); | |||
7630 | DD.Triggered = true; | |||
7631 | } | |||
7632 | ||||
7633 | static const AvailabilityAttr *getAttrForPlatform(ASTContext &Context, | |||
7634 | const Decl *D) { | |||
7635 | // Check each AvailabilityAttr to find the one for this platform. | |||
7636 | for (const auto *A : D->attrs()) { | |||
7637 | if (const auto *Avail = dyn_cast<AvailabilityAttr>(A)) { | |||
7638 | // FIXME: this is copied from CheckAvailability. We should try to | |||
7639 | // de-duplicate. | |||
7640 | ||||
7641 | // Check if this is an App Extension "platform", and if so chop off | |||
7642 | // the suffix for matching with the actual platform. | |||
7643 | StringRef ActualPlatform = Avail->getPlatform()->getName(); | |||
7644 | StringRef RealizedPlatform = ActualPlatform; | |||
7645 | if (Context.getLangOpts().AppExt) { | |||
7646 | size_t suffix = RealizedPlatform.rfind("_app_extension"); | |||
7647 | if (suffix != StringRef::npos) | |||
7648 | RealizedPlatform = RealizedPlatform.slice(0, suffix); | |||
7649 | } | |||
7650 | ||||
7651 | StringRef TargetPlatform = Context.getTargetInfo().getPlatformName(); | |||
7652 | ||||
7653 | // Match the platform name. | |||
7654 | if (RealizedPlatform == TargetPlatform) | |||
7655 | return Avail; | |||
7656 | } | |||
7657 | } | |||
7658 | return nullptr; | |||
7659 | } | |||
7660 | ||||
7661 | /// The diagnostic we should emit for \c D, and the declaration that | |||
7662 | /// originated it, or \c AR_Available. | |||
7663 | /// | |||
7664 | /// \param D The declaration to check. | |||
7665 | /// \param Message If non-null, this will be populated with the message from | |||
7666 | /// the availability attribute that is selected. | |||
7667 | /// \param ClassReceiver If we're checking the the method of a class message | |||
7668 | /// send, the class. Otherwise nullptr. | |||
7669 | static std::pair<AvailabilityResult, const NamedDecl *> | |||
7670 | ShouldDiagnoseAvailabilityOfDecl(Sema &S, const NamedDecl *D, | |||
7671 | std::string *Message, | |||
7672 | ObjCInterfaceDecl *ClassReceiver) { | |||
7673 | AvailabilityResult Result = D->getAvailability(Message); | |||
7674 | ||||
7675 | // For typedefs, if the typedef declaration appears available look | |||
7676 | // to the underlying type to see if it is more restrictive. | |||
7677 | while (const auto *TD = dyn_cast<TypedefNameDecl>(D)) { | |||
7678 | if (Result == AR_Available) { | |||
7679 | if (const auto *TT = TD->getUnderlyingType()->getAs<TagType>()) { | |||
7680 | D = TT->getDecl(); | |||
7681 | Result = D->getAvailability(Message); | |||
7682 | continue; | |||
7683 | } | |||
7684 | } | |||
7685 | break; | |||
7686 | } | |||
7687 | ||||
7688 | // Forward class declarations get their attributes from their definition. | |||
7689 | if (const auto *IDecl = dyn_cast<ObjCInterfaceDecl>(D)) { | |||
7690 | if (IDecl->getDefinition()) { | |||
7691 | D = IDecl->getDefinition(); | |||
7692 | Result = D->getAvailability(Message); | |||
7693 | } | |||
7694 | } | |||
7695 | ||||
7696 | if (const auto *ECD = dyn_cast<EnumConstantDecl>(D)) | |||
7697 | if (Result == AR_Available) { | |||
7698 | const DeclContext *DC = ECD->getDeclContext(); | |||
7699 | if (const auto *TheEnumDecl = dyn_cast<EnumDecl>(DC)) { | |||
7700 | Result = TheEnumDecl->getAvailability(Message); | |||
7701 | D = TheEnumDecl; | |||
7702 | } | |||
7703 | } | |||
7704 | ||||
7705 | // For +new, infer availability from -init. | |||
7706 | if (const auto *MD = dyn_cast<ObjCMethodDecl>(D)) { | |||
7707 | if (S.NSAPIObj && ClassReceiver) { | |||
7708 | ObjCMethodDecl *Init = ClassReceiver->lookupInstanceMethod( | |||
7709 | S.NSAPIObj->getInitSelector()); | |||
7710 | if (Init && Result == AR_Available && MD->isClassMethod() && | |||
7711 | MD->getSelector() == S.NSAPIObj->getNewSelector() && | |||
7712 | MD->definedInNSObject(S.getASTContext())) { | |||
7713 | Result = Init->getAvailability(Message); | |||
7714 | D = Init; | |||
7715 | } | |||
7716 | } | |||
7717 | } | |||
7718 | ||||
7719 | return {Result, D}; | |||
7720 | } | |||
7721 | ||||
7722 | ||||
7723 | /// whether we should emit a diagnostic for \c K and \c DeclVersion in | |||
7724 | /// the context of \c Ctx. For example, we should emit an unavailable diagnostic | |||
7725 | /// in a deprecated context, but not the other way around. | |||
7726 | static bool | |||
7727 | ShouldDiagnoseAvailabilityInContext(Sema &S, AvailabilityResult K, | |||
7728 | VersionTuple DeclVersion, Decl *Ctx, | |||
7729 | const NamedDecl *OffendingDecl) { | |||
7730 | assert(K != AR_Available && "Expected an unavailable declaration here!")((K != AR_Available && "Expected an unavailable declaration here!" ) ? static_cast<void> (0) : __assert_fail ("K != AR_Available && \"Expected an unavailable declaration here!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 7730, __PRETTY_FUNCTION__)); | |||
7731 | ||||
7732 | // Checks if we should emit the availability diagnostic in the context of C. | |||
7733 | auto CheckContext = [&](const Decl *C) { | |||
7734 | if (K == AR_NotYetIntroduced) { | |||
7735 | if (const AvailabilityAttr *AA = getAttrForPlatform(S.Context, C)) | |||
7736 | if (AA->getIntroduced() >= DeclVersion) | |||
7737 | return true; | |||
7738 | } else if (K == AR_Deprecated) { | |||
7739 | if (C->isDeprecated()) | |||
7740 | return true; | |||
7741 | } else if (K == AR_Unavailable) { | |||
7742 | // It is perfectly fine to refer to an 'unavailable' Objective-C method | |||
7743 | // when it is referenced from within the @implementation itself. In this | |||
7744 | // context, we interpret unavailable as a form of access control. | |||
7745 | if (const auto *MD = dyn_cast<ObjCMethodDecl>(OffendingDecl)) { | |||
7746 | if (const auto *Impl = dyn_cast<ObjCImplDecl>(C)) { | |||
7747 | if (MD->getClassInterface() == Impl->getClassInterface()) | |||
7748 | return true; | |||
7749 | } | |||
7750 | } | |||
7751 | } | |||
7752 | ||||
7753 | if (C->isUnavailable()) | |||
7754 | return true; | |||
7755 | return false; | |||
7756 | }; | |||
7757 | ||||
7758 | do { | |||
7759 | if (CheckContext(Ctx)) | |||
7760 | return false; | |||
7761 | ||||
7762 | // An implementation implicitly has the availability of the interface. | |||
7763 | // Unless it is "+load" method. | |||
7764 | if (const auto *MethodD = dyn_cast<ObjCMethodDecl>(Ctx)) | |||
7765 | if (MethodD->isClassMethod() && | |||
7766 | MethodD->getSelector().getAsString() == "load") | |||
7767 | return true; | |||
7768 | ||||
7769 | if (const auto *CatOrImpl = dyn_cast<ObjCImplDecl>(Ctx)) { | |||
7770 | if (const ObjCInterfaceDecl *Interface = CatOrImpl->getClassInterface()) | |||
7771 | if (CheckContext(Interface)) | |||
7772 | return false; | |||
7773 | } | |||
7774 | // A category implicitly has the availability of the interface. | |||
7775 | else if (const auto *CatD = dyn_cast<ObjCCategoryDecl>(Ctx)) | |||
7776 | if (const ObjCInterfaceDecl *Interface = CatD->getClassInterface()) | |||
7777 | if (CheckContext(Interface)) | |||
7778 | return false; | |||
7779 | } while ((Ctx = cast_or_null<Decl>(Ctx->getDeclContext()))); | |||
7780 | ||||
7781 | return true; | |||
7782 | } | |||
7783 | ||||
7784 | static bool | |||
7785 | shouldDiagnoseAvailabilityByDefault(const ASTContext &Context, | |||
7786 | const VersionTuple &DeploymentVersion, | |||
7787 | const VersionTuple &DeclVersion) { | |||
7788 | const auto &Triple = Context.getTargetInfo().getTriple(); | |||
7789 | VersionTuple ForceAvailabilityFromVersion; | |||
7790 | switch (Triple.getOS()) { | |||
7791 | case llvm::Triple::IOS: | |||
7792 | case llvm::Triple::TvOS: | |||
7793 | ForceAvailabilityFromVersion = VersionTuple(/*Major=*/11); | |||
7794 | break; | |||
7795 | case llvm::Triple::WatchOS: | |||
7796 | ForceAvailabilityFromVersion = VersionTuple(/*Major=*/4); | |||
7797 | break; | |||
7798 | case llvm::Triple::Darwin: | |||
7799 | case llvm::Triple::MacOSX: | |||
7800 | ForceAvailabilityFromVersion = VersionTuple(/*Major=*/10, /*Minor=*/13); | |||
7801 | break; | |||
7802 | default: | |||
7803 | // New targets should always warn about availability. | |||
7804 | return Triple.getVendor() == llvm::Triple::Apple; | |||
7805 | } | |||
7806 | return DeploymentVersion >= ForceAvailabilityFromVersion || | |||
7807 | DeclVersion >= ForceAvailabilityFromVersion; | |||
7808 | } | |||
7809 | ||||
7810 | static NamedDecl *findEnclosingDeclToAnnotate(Decl *OrigCtx) { | |||
7811 | for (Decl *Ctx = OrigCtx; Ctx; | |||
7812 | Ctx = cast_or_null<Decl>(Ctx->getDeclContext())) { | |||
7813 | if (isa<TagDecl>(Ctx) || isa<FunctionDecl>(Ctx) || isa<ObjCMethodDecl>(Ctx)) | |||
7814 | return cast<NamedDecl>(Ctx); | |||
7815 | if (auto *CD = dyn_cast<ObjCContainerDecl>(Ctx)) { | |||
7816 | if (auto *Imp = dyn_cast<ObjCImplDecl>(Ctx)) | |||
7817 | return Imp->getClassInterface(); | |||
7818 | return CD; | |||
7819 | } | |||
7820 | } | |||
7821 | ||||
7822 | return dyn_cast<NamedDecl>(OrigCtx); | |||
7823 | } | |||
7824 | ||||
7825 | namespace { | |||
7826 | ||||
7827 | struct AttributeInsertion { | |||
7828 | StringRef Prefix; | |||
7829 | SourceLocation Loc; | |||
7830 | StringRef Suffix; | |||
7831 | ||||
7832 | static AttributeInsertion createInsertionAfter(const NamedDecl *D) { | |||
7833 | return {" ", D->getEndLoc(), ""}; | |||
7834 | } | |||
7835 | static AttributeInsertion createInsertionAfter(SourceLocation Loc) { | |||
7836 | return {" ", Loc, ""}; | |||
7837 | } | |||
7838 | static AttributeInsertion createInsertionBefore(const NamedDecl *D) { | |||
7839 | return {"", D->getBeginLoc(), "\n"}; | |||
7840 | } | |||
7841 | }; | |||
7842 | ||||
7843 | } // end anonymous namespace | |||
7844 | ||||
7845 | /// Tries to parse a string as ObjC method name. | |||
7846 | /// | |||
7847 | /// \param Name The string to parse. Expected to originate from availability | |||
7848 | /// attribute argument. | |||
7849 | /// \param SlotNames The vector that will be populated with slot names. In case | |||
7850 | /// of unsuccessful parsing can contain invalid data. | |||
7851 | /// \returns A number of method parameters if parsing was successful, None | |||
7852 | /// otherwise. | |||
7853 | static Optional<unsigned> | |||
7854 | tryParseObjCMethodName(StringRef Name, SmallVectorImpl<StringRef> &SlotNames, | |||
7855 | const LangOptions &LangOpts) { | |||
7856 | // Accept replacements starting with - or + as valid ObjC method names. | |||
7857 | if (!Name.empty() && (Name.front() == '-' || Name.front() == '+')) | |||
7858 | Name = Name.drop_front(1); | |||
7859 | if (Name.empty()) | |||
7860 | return None; | |||
7861 | Name.split(SlotNames, ':'); | |||
7862 | unsigned NumParams; | |||
7863 | if (Name.back() == ':') { | |||
7864 | // Remove an empty string at the end that doesn't represent any slot. | |||
7865 | SlotNames.pop_back(); | |||
7866 | NumParams = SlotNames.size(); | |||
7867 | } else { | |||
7868 | if (SlotNames.size() != 1) | |||
7869 | // Not a valid method name, just a colon-separated string. | |||
7870 | return None; | |||
7871 | NumParams = 0; | |||
7872 | } | |||
7873 | // Verify all slot names are valid. | |||
7874 | bool AllowDollar = LangOpts.DollarIdents; | |||
7875 | for (StringRef S : SlotNames) { | |||
7876 | if (S.empty()) | |||
7877 | continue; | |||
7878 | if (!isValidIdentifier(S, AllowDollar)) | |||
7879 | return None; | |||
7880 | } | |||
7881 | return NumParams; | |||
7882 | } | |||
7883 | ||||
7884 | /// Returns a source location in which it's appropriate to insert a new | |||
7885 | /// attribute for the given declaration \D. | |||
7886 | static Optional<AttributeInsertion> | |||
7887 | createAttributeInsertion(const NamedDecl *D, const SourceManager &SM, | |||
7888 | const LangOptions &LangOpts) { | |||
7889 | if (isa<ObjCPropertyDecl>(D)) | |||
7890 | return AttributeInsertion::createInsertionAfter(D); | |||
7891 | if (const auto *MD = dyn_cast<ObjCMethodDecl>(D)) { | |||
7892 | if (MD->hasBody()) | |||
7893 | return None; | |||
7894 | return AttributeInsertion::createInsertionAfter(D); | |||
7895 | } | |||
7896 | if (const auto *TD = dyn_cast<TagDecl>(D)) { | |||
7897 | SourceLocation Loc = | |||
7898 | Lexer::getLocForEndOfToken(TD->getInnerLocStart(), 0, SM, LangOpts); | |||
7899 | if (Loc.isInvalid()) | |||
7900 | return None; | |||
7901 | // Insert after the 'struct'/whatever keyword. | |||
7902 | return AttributeInsertion::createInsertionAfter(Loc); | |||
7903 | } | |||
7904 | return AttributeInsertion::createInsertionBefore(D); | |||
7905 | } | |||
7906 | ||||
7907 | /// Actually emit an availability diagnostic for a reference to an unavailable | |||
7908 | /// decl. | |||
7909 | /// | |||
7910 | /// \param Ctx The context that the reference occurred in | |||
7911 | /// \param ReferringDecl The exact declaration that was referenced. | |||
7912 | /// \param OffendingDecl A related decl to \c ReferringDecl that has an | |||
7913 | /// availability attribute corresponding to \c K attached to it. Note that this | |||
7914 | /// may not be the same as ReferringDecl, i.e. if an EnumDecl is annotated and | |||
7915 | /// we refer to a member EnumConstantDecl, ReferringDecl is the EnumConstantDecl | |||
7916 | /// and OffendingDecl is the EnumDecl. | |||
7917 | static void DoEmitAvailabilityWarning(Sema &S, AvailabilityResult K, | |||
7918 | Decl *Ctx, const NamedDecl *ReferringDecl, | |||
7919 | const NamedDecl *OffendingDecl, | |||
7920 | StringRef Message, | |||
7921 | ArrayRef<SourceLocation> Locs, | |||
7922 | const ObjCInterfaceDecl *UnknownObjCClass, | |||
7923 | const ObjCPropertyDecl *ObjCProperty, | |||
7924 | bool ObjCPropertyAccess) { | |||
7925 | // Diagnostics for deprecated or unavailable. | |||
7926 | unsigned diag, diag_message, diag_fwdclass_message; | |||
7927 | unsigned diag_available_here = diag::note_availability_specified_here; | |||
7928 | SourceLocation NoteLocation = OffendingDecl->getLocation(); | |||
7929 | ||||
7930 | // Matches 'diag::note_property_attribute' options. | |||
7931 | unsigned property_note_select; | |||
7932 | ||||
7933 | // Matches diag::note_availability_specified_here. | |||
7934 | unsigned available_here_select_kind; | |||
7935 | ||||
7936 | VersionTuple DeclVersion; | |||
7937 | if (const AvailabilityAttr *AA = getAttrForPlatform(S.Context, OffendingDecl)) | |||
7938 | DeclVersion = AA->getIntroduced(); | |||
7939 | ||||
7940 | if (!ShouldDiagnoseAvailabilityInContext(S, K, DeclVersion, Ctx, | |||
7941 | OffendingDecl)) | |||
7942 | return; | |||
7943 | ||||
7944 | SourceLocation Loc = Locs.front(); | |||
7945 | ||||
7946 | // The declaration can have multiple availability attributes, we are looking | |||
7947 | // at one of them. | |||
7948 | const AvailabilityAttr *A = getAttrForPlatform(S.Context, OffendingDecl); | |||
7949 | if (A && A->isInherited()) { | |||
7950 | for (const Decl *Redecl = OffendingDecl->getMostRecentDecl(); Redecl; | |||
7951 | Redecl = Redecl->getPreviousDecl()) { | |||
7952 | const AvailabilityAttr *AForRedecl = | |||
7953 | getAttrForPlatform(S.Context, Redecl); | |||
7954 | if (AForRedecl && !AForRedecl->isInherited()) { | |||
7955 | // If D is a declaration with inherited attributes, the note should | |||
7956 | // point to the declaration with actual attributes. | |||
7957 | NoteLocation = Redecl->getLocation(); | |||
7958 | break; | |||
7959 | } | |||
7960 | } | |||
7961 | } | |||
7962 | ||||
7963 | switch (K) { | |||
7964 | case AR_NotYetIntroduced: { | |||
7965 | // We would like to emit the diagnostic even if -Wunguarded-availability is | |||
7966 | // not specified for deployment targets >= to iOS 11 or equivalent or | |||
7967 | // for declarations that were introduced in iOS 11 (macOS 10.13, ...) or | |||
7968 | // later. | |||
7969 | const AvailabilityAttr *AA = | |||
7970 | getAttrForPlatform(S.getASTContext(), OffendingDecl); | |||
7971 | VersionTuple Introduced = AA->getIntroduced(); | |||
7972 | ||||
7973 | bool UseNewWarning = shouldDiagnoseAvailabilityByDefault( | |||
7974 | S.Context, S.Context.getTargetInfo().getPlatformMinVersion(), | |||
7975 | Introduced); | |||
7976 | unsigned Warning = UseNewWarning ? diag::warn_unguarded_availability_new | |||
7977 | : diag::warn_unguarded_availability; | |||
7978 | ||||
7979 | std::string PlatformName = AvailabilityAttr::getPrettyPlatformName( | |||
7980 | S.getASTContext().getTargetInfo().getPlatformName()); | |||
7981 | ||||
7982 | S.Diag(Loc, Warning) << OffendingDecl << PlatformName | |||
7983 | << Introduced.getAsString(); | |||
7984 | ||||
7985 | S.Diag(OffendingDecl->getLocation(), | |||
7986 | diag::note_partial_availability_specified_here) | |||
7987 | << OffendingDecl << PlatformName << Introduced.getAsString() | |||
7988 | << S.Context.getTargetInfo().getPlatformMinVersion().getAsString(); | |||
7989 | ||||
7990 | if (const auto *Enclosing = findEnclosingDeclToAnnotate(Ctx)) { | |||
7991 | if (const auto *TD = dyn_cast<TagDecl>(Enclosing)) | |||
7992 | if (TD->getDeclName().isEmpty()) { | |||
7993 | S.Diag(TD->getLocation(), | |||
7994 | diag::note_decl_unguarded_availability_silence) | |||
7995 | << /*Anonymous*/ 1 << TD->getKindName(); | |||
7996 | return; | |||
7997 | } | |||
7998 | auto FixitNoteDiag = | |||
7999 | S.Diag(Enclosing->getLocation(), | |||
8000 | diag::note_decl_unguarded_availability_silence) | |||
8001 | << /*Named*/ 0 << Enclosing; | |||
8002 | // Don't offer a fixit for declarations with availability attributes. | |||
8003 | if (Enclosing->hasAttr<AvailabilityAttr>()) | |||
8004 | return; | |||
8005 | if (!S.getPreprocessor().isMacroDefined("API_AVAILABLE")) | |||
8006 | return; | |||
8007 | Optional<AttributeInsertion> Insertion = createAttributeInsertion( | |||
8008 | Enclosing, S.getSourceManager(), S.getLangOpts()); | |||
8009 | if (!Insertion) | |||
8010 | return; | |||
8011 | std::string PlatformName = | |||
8012 | AvailabilityAttr::getPlatformNameSourceSpelling( | |||
8013 | S.getASTContext().getTargetInfo().getPlatformName()) | |||
8014 | .lower(); | |||
8015 | std::string Introduced = | |||
8016 | OffendingDecl->getVersionIntroduced().getAsString(); | |||
8017 | FixitNoteDiag << FixItHint::CreateInsertion( | |||
8018 | Insertion->Loc, | |||
8019 | (llvm::Twine(Insertion->Prefix) + "API_AVAILABLE(" + PlatformName + | |||
8020 | "(" + Introduced + "))" + Insertion->Suffix) | |||
8021 | .str()); | |||
8022 | } | |||
8023 | return; | |||
8024 | } | |||
8025 | case AR_Deprecated: | |||
8026 | diag = !ObjCPropertyAccess ? diag::warn_deprecated | |||
8027 | : diag::warn_property_method_deprecated; | |||
8028 | diag_message = diag::warn_deprecated_message; | |||
8029 | diag_fwdclass_message = diag::warn_deprecated_fwdclass_message; | |||
8030 | property_note_select = /* deprecated */ 0; | |||
8031 | available_here_select_kind = /* deprecated */ 2; | |||
8032 | if (const auto *AL = OffendingDecl->getAttr<DeprecatedAttr>()) | |||
8033 | NoteLocation = AL->getLocation(); | |||
8034 | break; | |||
8035 | ||||
8036 | case AR_Unavailable: | |||
8037 | diag = !ObjCPropertyAccess ? diag::err_unavailable | |||
8038 | : diag::err_property_method_unavailable; | |||
8039 | diag_message = diag::err_unavailable_message; | |||
8040 | diag_fwdclass_message = diag::warn_unavailable_fwdclass_message; | |||
8041 | property_note_select = /* unavailable */ 1; | |||
8042 | available_here_select_kind = /* unavailable */ 0; | |||
8043 | ||||
8044 | if (auto AL = OffendingDecl->getAttr<UnavailableAttr>()) { | |||
8045 | if (AL->isImplicit() && AL->getImplicitReason()) { | |||
8046 | // Most of these failures are due to extra restrictions in ARC; | |||
8047 | // reflect that in the primary diagnostic when applicable. | |||
8048 | auto flagARCError = [&] { | |||
8049 | if (S.getLangOpts().ObjCAutoRefCount && | |||
8050 | S.getSourceManager().isInSystemHeader( | |||
8051 | OffendingDecl->getLocation())) | |||
8052 | diag = diag::err_unavailable_in_arc; | |||
8053 | }; | |||
8054 | ||||
8055 | switch (AL->getImplicitReason()) { | |||
8056 | case UnavailableAttr::IR_None: break; | |||
8057 | ||||
8058 | case UnavailableAttr::IR_ARCForbiddenType: | |||
8059 | flagARCError(); | |||
8060 | diag_available_here = diag::note_arc_forbidden_type; | |||
8061 | break; | |||
8062 | ||||
8063 | case UnavailableAttr::IR_ForbiddenWeak: | |||
8064 | if (S.getLangOpts().ObjCWeakRuntime) | |||
8065 | diag_available_here = diag::note_arc_weak_disabled; | |||
8066 | else | |||
8067 | diag_available_here = diag::note_arc_weak_no_runtime; | |||
8068 | break; | |||
8069 | ||||
8070 | case UnavailableAttr::IR_ARCForbiddenConversion: | |||
8071 | flagARCError(); | |||
8072 | diag_available_here = diag::note_performs_forbidden_arc_conversion; | |||
8073 | break; | |||
8074 | ||||
8075 | case UnavailableAttr::IR_ARCInitReturnsUnrelated: | |||
8076 | flagARCError(); | |||
8077 | diag_available_here = diag::note_arc_init_returns_unrelated; | |||
8078 | break; | |||
8079 | ||||
8080 | case UnavailableAttr::IR_ARCFieldWithOwnership: | |||
8081 | flagARCError(); | |||
8082 | diag_available_here = diag::note_arc_field_with_ownership; | |||
8083 | break; | |||
8084 | } | |||
8085 | } | |||
8086 | } | |||
8087 | break; | |||
8088 | ||||
8089 | case AR_Available: | |||
8090 | llvm_unreachable("Warning for availability of available declaration?")::llvm::llvm_unreachable_internal("Warning for availability of available declaration?" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 8090); | |||
8091 | } | |||
8092 | ||||
8093 | SmallVector<FixItHint, 12> FixIts; | |||
8094 | if (K == AR_Deprecated) { | |||
8095 | StringRef Replacement; | |||
8096 | if (auto AL = OffendingDecl->getAttr<DeprecatedAttr>()) | |||
8097 | Replacement = AL->getReplacement(); | |||
8098 | if (auto AL = getAttrForPlatform(S.Context, OffendingDecl)) | |||
8099 | Replacement = AL->getReplacement(); | |||
8100 | ||||
8101 | CharSourceRange UseRange; | |||
8102 | if (!Replacement.empty()) | |||
8103 | UseRange = | |||
8104 | CharSourceRange::getCharRange(Loc, S.getLocForEndOfToken(Loc)); | |||
8105 | if (UseRange.isValid()) { | |||
8106 | if (const auto *MethodDecl = dyn_cast<ObjCMethodDecl>(ReferringDecl)) { | |||
8107 | Selector Sel = MethodDecl->getSelector(); | |||
8108 | SmallVector<StringRef, 12> SelectorSlotNames; | |||
8109 | Optional<unsigned> NumParams = tryParseObjCMethodName( | |||
8110 | Replacement, SelectorSlotNames, S.getLangOpts()); | |||
8111 | if (NumParams && NumParams.getValue() == Sel.getNumArgs()) { | |||
8112 | assert(SelectorSlotNames.size() == Locs.size())((SelectorSlotNames.size() == Locs.size()) ? static_cast<void > (0) : __assert_fail ("SelectorSlotNames.size() == Locs.size()" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 8112, __PRETTY_FUNCTION__)); | |||
8113 | for (unsigned I = 0; I < Locs.size(); ++I) { | |||
8114 | if (!Sel.getNameForSlot(I).empty()) { | |||
8115 | CharSourceRange NameRange = CharSourceRange::getCharRange( | |||
8116 | Locs[I], S.getLocForEndOfToken(Locs[I])); | |||
8117 | FixIts.push_back(FixItHint::CreateReplacement( | |||
8118 | NameRange, SelectorSlotNames[I])); | |||
8119 | } else | |||
8120 | FixIts.push_back( | |||
8121 | FixItHint::CreateInsertion(Locs[I], SelectorSlotNames[I])); | |||
8122 | } | |||
8123 | } else | |||
8124 | FixIts.push_back(FixItHint::CreateReplacement(UseRange, Replacement)); | |||
8125 | } else | |||
8126 | FixIts.push_back(FixItHint::CreateReplacement(UseRange, Replacement)); | |||
8127 | } | |||
8128 | } | |||
8129 | ||||
8130 | if (!Message.empty()) { | |||
8131 | S.Diag(Loc, diag_message) << ReferringDecl << Message << FixIts; | |||
8132 | if (ObjCProperty) | |||
8133 | S.Diag(ObjCProperty->getLocation(), diag::note_property_attribute) | |||
8134 | << ObjCProperty->getDeclName() << property_note_select; | |||
8135 | } else if (!UnknownObjCClass) { | |||
8136 | S.Diag(Loc, diag) << ReferringDecl << FixIts; | |||
8137 | if (ObjCProperty) | |||
8138 | S.Diag(ObjCProperty->getLocation(), diag::note_property_attribute) | |||
8139 | << ObjCProperty->getDeclName() << property_note_select; | |||
8140 | } else { | |||
8141 | S.Diag(Loc, diag_fwdclass_message) << ReferringDecl << FixIts; | |||
8142 | S.Diag(UnknownObjCClass->getLocation(), diag::note_forward_class); | |||
8143 | } | |||
8144 | ||||
8145 | S.Diag(NoteLocation, diag_available_here) | |||
8146 | << OffendingDecl << available_here_select_kind; | |||
8147 | } | |||
8148 | ||||
8149 | static void handleDelayedAvailabilityCheck(Sema &S, DelayedDiagnostic &DD, | |||
8150 | Decl *Ctx) { | |||
8151 | assert(DD.Kind == DelayedDiagnostic::Availability &&((DD.Kind == DelayedDiagnostic::Availability && "Expected an availability diagnostic here" ) ? static_cast<void> (0) : __assert_fail ("DD.Kind == DelayedDiagnostic::Availability && \"Expected an availability diagnostic here\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 8152, __PRETTY_FUNCTION__)) | |||
8152 | "Expected an availability diagnostic here")((DD.Kind == DelayedDiagnostic::Availability && "Expected an availability diagnostic here" ) ? static_cast<void> (0) : __assert_fail ("DD.Kind == DelayedDiagnostic::Availability && \"Expected an availability diagnostic here\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 8152, __PRETTY_FUNCTION__)); | |||
8153 | ||||
8154 | DD.Triggered = true; | |||
8155 | DoEmitAvailabilityWarning( | |||
8156 | S, DD.getAvailabilityResult(), Ctx, DD.getAvailabilityReferringDecl(), | |||
8157 | DD.getAvailabilityOffendingDecl(), DD.getAvailabilityMessage(), | |||
8158 | DD.getAvailabilitySelectorLocs(), DD.getUnknownObjCClass(), | |||
8159 | DD.getObjCProperty(), false); | |||
8160 | } | |||
8161 | ||||
8162 | void Sema::PopParsingDeclaration(ParsingDeclState state, Decl *decl) { | |||
8163 | assert(DelayedDiagnostics.getCurrentPool())((DelayedDiagnostics.getCurrentPool()) ? static_cast<void> (0) : __assert_fail ("DelayedDiagnostics.getCurrentPool()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 8163, __PRETTY_FUNCTION__)); | |||
| ||||
8164 | DelayedDiagnosticPool &poppedPool = *DelayedDiagnostics.getCurrentPool(); | |||
8165 | DelayedDiagnostics.popWithoutEmitting(state); | |||
8166 | ||||
8167 | // When delaying diagnostics to run in the context of a parsed | |||
8168 | // declaration, we only want to actually emit anything if parsing | |||
8169 | // succeeds. | |||
8170 | if (!decl) return; | |||
8171 | ||||
8172 | // We emit all the active diagnostics in this pool or any of its | |||
8173 | // parents. In general, we'll get one pool for the decl spec | |||
8174 | // and a child pool for each declarator; in a decl group like: | |||
8175 | // deprecated_typedef foo, *bar, baz(); | |||
8176 | // only the declarator pops will be passed decls. This is correct; | |||
8177 | // we really do need to consider delayed diagnostics from the decl spec | |||
8178 | // for each of the different declarations. | |||
8179 | const DelayedDiagnosticPool *pool = &poppedPool; | |||
8180 | do { | |||
8181 | bool AnyAccessFailures = false; | |||
8182 | for (DelayedDiagnosticPool::pool_iterator | |||
8183 | i = pool->pool_begin(), e = pool->pool_end(); i != e; ++i) { | |||
8184 | // This const_cast is a bit lame. Really, Triggered should be mutable. | |||
8185 | DelayedDiagnostic &diag = const_cast<DelayedDiagnostic&>(*i); | |||
8186 | if (diag.Triggered) | |||
8187 | continue; | |||
8188 | ||||
8189 | switch (diag.Kind) { | |||
8190 | case DelayedDiagnostic::Availability: | |||
8191 | // Don't bother giving deprecation/unavailable diagnostics if | |||
8192 | // the decl is invalid. | |||
8193 | if (!decl->isInvalidDecl()) | |||
8194 | handleDelayedAvailabilityCheck(*this, diag, decl); | |||
8195 | break; | |||
8196 | ||||
8197 | case DelayedDiagnostic::Access: | |||
8198 | // Only produce one access control diagnostic for a structured binding | |||
8199 | // declaration: we don't need to tell the user that all the fields are | |||
8200 | // inaccessible one at a time. | |||
8201 | if (AnyAccessFailures && isa<DecompositionDecl>(decl)) | |||
8202 | continue; | |||
8203 | HandleDelayedAccessCheck(diag, decl); | |||
8204 | if (diag.Triggered) | |||
8205 | AnyAccessFailures = true; | |||
8206 | break; | |||
8207 | ||||
8208 | case DelayedDiagnostic::ForbiddenType: | |||
8209 | handleDelayedForbiddenType(*this, diag, decl); | |||
8210 | break; | |||
8211 | } | |||
8212 | } | |||
8213 | } while ((pool = pool->getParent())); | |||
8214 | } | |||
8215 | ||||
8216 | /// Given a set of delayed diagnostics, re-emit them as if they had | |||
8217 | /// been delayed in the current context instead of in the given pool. | |||
8218 | /// Essentially, this just moves them to the current pool. | |||
8219 | void Sema::redelayDiagnostics(DelayedDiagnosticPool &pool) { | |||
8220 | DelayedDiagnosticPool *curPool = DelayedDiagnostics.getCurrentPool(); | |||
8221 | assert(curPool && "re-emitting in undelayed context not supported")((curPool && "re-emitting in undelayed context not supported" ) ? static_cast<void> (0) : __assert_fail ("curPool && \"re-emitting in undelayed context not supported\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 8221, __PRETTY_FUNCTION__)); | |||
8222 | curPool->steal(pool); | |||
8223 | } | |||
8224 | ||||
8225 | static void EmitAvailabilityWarning(Sema &S, AvailabilityResult AR, | |||
8226 | const NamedDecl *ReferringDecl, | |||
8227 | const NamedDecl *OffendingDecl, | |||
8228 | StringRef Message, | |||
8229 | ArrayRef<SourceLocation> Locs, | |||
8230 | const ObjCInterfaceDecl *UnknownObjCClass, | |||
8231 | const ObjCPropertyDecl *ObjCProperty, | |||
8232 | bool ObjCPropertyAccess) { | |||
8233 | // Delay if we're currently parsing a declaration. | |||
8234 | if (S.DelayedDiagnostics.shouldDelayDiagnostics()) { | |||
8235 | S.DelayedDiagnostics.add( | |||
8236 | DelayedDiagnostic::makeAvailability( | |||
8237 | AR, Locs, ReferringDecl, OffendingDecl, UnknownObjCClass, | |||
8238 | ObjCProperty, Message, ObjCPropertyAccess)); | |||
8239 | return; | |||
8240 | } | |||
8241 | ||||
8242 | Decl *Ctx = cast<Decl>(S.getCurLexicalContext()); | |||
8243 | DoEmitAvailabilityWarning(S, AR, Ctx, ReferringDecl, OffendingDecl, | |||
8244 | Message, Locs, UnknownObjCClass, ObjCProperty, | |||
8245 | ObjCPropertyAccess); | |||
8246 | } | |||
8247 | ||||
8248 | namespace { | |||
8249 | ||||
8250 | /// Returns true if the given statement can be a body-like child of \p Parent. | |||
8251 | bool isBodyLikeChildStmt(const Stmt *S, const Stmt *Parent) { | |||
8252 | switch (Parent->getStmtClass()) { | |||
8253 | case Stmt::IfStmtClass: | |||
8254 | return cast<IfStmt>(Parent)->getThen() == S || | |||
8255 | cast<IfStmt>(Parent)->getElse() == S; | |||
8256 | case Stmt::WhileStmtClass: | |||
8257 | return cast<WhileStmt>(Parent)->getBody() == S; | |||
8258 | case Stmt::DoStmtClass: | |||
8259 | return cast<DoStmt>(Parent)->getBody() == S; | |||
8260 | case Stmt::ForStmtClass: | |||
8261 | return cast<ForStmt>(Parent)->getBody() == S; | |||
8262 | case Stmt::CXXForRangeStmtClass: | |||
8263 | return cast<CXXForRangeStmt>(Parent)->getBody() == S; | |||
8264 | case Stmt::ObjCForCollectionStmtClass: | |||
8265 | return cast<ObjCForCollectionStmt>(Parent)->getBody() == S; | |||
8266 | case Stmt::CaseStmtClass: | |||
8267 | case Stmt::DefaultStmtClass: | |||
8268 | return cast<SwitchCase>(Parent)->getSubStmt() == S; | |||
8269 | default: | |||
8270 | return false; | |||
8271 | } | |||
8272 | } | |||
8273 | ||||
8274 | class StmtUSEFinder : public RecursiveASTVisitor<StmtUSEFinder> { | |||
8275 | const Stmt *Target; | |||
8276 | ||||
8277 | public: | |||
8278 | bool VisitStmt(Stmt *S) { return S != Target; } | |||
8279 | ||||
8280 | /// Returns true if the given statement is present in the given declaration. | |||
8281 | static bool isContained(const Stmt *Target, const Decl *D) { | |||
8282 | StmtUSEFinder Visitor; | |||
8283 | Visitor.Target = Target; | |||
8284 | return !Visitor.TraverseDecl(const_cast<Decl *>(D)); | |||
8285 | } | |||
8286 | }; | |||
8287 | ||||
8288 | /// Traverses the AST and finds the last statement that used a given | |||
8289 | /// declaration. | |||
8290 | class LastDeclUSEFinder : public RecursiveASTVisitor<LastDeclUSEFinder> { | |||
8291 | const Decl *D; | |||
8292 | ||||
8293 | public: | |||
8294 | bool VisitDeclRefExpr(DeclRefExpr *DRE) { | |||
8295 | if (DRE->getDecl() == D) | |||
8296 | return false; | |||
8297 | return true; | |||
8298 | } | |||
8299 | ||||
8300 | static const Stmt *findLastStmtThatUsesDecl(const Decl *D, | |||
8301 | const CompoundStmt *Scope) { | |||
8302 | LastDeclUSEFinder Visitor; | |||
8303 | Visitor.D = D; | |||
8304 | for (auto I = Scope->body_rbegin(), E = Scope->body_rend(); I != E; ++I) { | |||
8305 | const Stmt *S = *I; | |||
8306 | if (!Visitor.TraverseStmt(const_cast<Stmt *>(S))) | |||
8307 | return S; | |||
8308 | } | |||
8309 | return nullptr; | |||
8310 | } | |||
8311 | }; | |||
8312 | ||||
8313 | /// This class implements -Wunguarded-availability. | |||
8314 | /// | |||
8315 | /// This is done with a traversal of the AST of a function that makes reference | |||
8316 | /// to a partially available declaration. Whenever we encounter an \c if of the | |||
8317 | /// form: \c if(@available(...)), we use the version from the condition to visit | |||
8318 | /// the then statement. | |||
8319 | class DiagnoseUnguardedAvailability | |||
8320 | : public RecursiveASTVisitor<DiagnoseUnguardedAvailability> { | |||
8321 | typedef RecursiveASTVisitor<DiagnoseUnguardedAvailability> Base; | |||
8322 | ||||
8323 | Sema &SemaRef; | |||
8324 | Decl *Ctx; | |||
8325 | ||||
8326 | /// Stack of potentially nested 'if (@available(...))'s. | |||
8327 | SmallVector<VersionTuple, 8> AvailabilityStack; | |||
8328 | SmallVector<const Stmt *, 16> StmtStack; | |||
8329 | ||||
8330 | void DiagnoseDeclAvailability(NamedDecl *D, SourceRange Range, | |||
8331 | ObjCInterfaceDecl *ClassReceiver = nullptr); | |||
8332 | ||||
8333 | public: | |||
8334 | DiagnoseUnguardedAvailability(Sema &SemaRef, Decl *Ctx) | |||
8335 | : SemaRef(SemaRef), Ctx(Ctx) { | |||
8336 | AvailabilityStack.push_back( | |||
8337 | SemaRef.Context.getTargetInfo().getPlatformMinVersion()); | |||
8338 | } | |||
8339 | ||||
8340 | bool TraverseDecl(Decl *D) { | |||
8341 | // Avoid visiting nested functions to prevent duplicate warnings. | |||
8342 | if (!D || isa<FunctionDecl>(D)) | |||
8343 | return true; | |||
8344 | return Base::TraverseDecl(D); | |||
8345 | } | |||
8346 | ||||
8347 | bool TraverseStmt(Stmt *S) { | |||
8348 | if (!S) | |||
8349 | return true; | |||
8350 | StmtStack.push_back(S); | |||
8351 | bool Result = Base::TraverseStmt(S); | |||
8352 | StmtStack.pop_back(); | |||
8353 | return Result; | |||
8354 | } | |||
8355 | ||||
8356 | void IssueDiagnostics(Stmt *S) { TraverseStmt(S); } | |||
8357 | ||||
8358 | bool TraverseIfStmt(IfStmt *If); | |||
8359 | ||||
8360 | bool TraverseLambdaExpr(LambdaExpr *E) { return true; } | |||
8361 | ||||
8362 | // for 'case X:' statements, don't bother looking at the 'X'; it can't lead | |||
8363 | // to any useful diagnostics. | |||
8364 | bool TraverseCaseStmt(CaseStmt *CS) { return TraverseStmt(CS->getSubStmt()); } | |||
8365 | ||||
8366 | bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *PRE) { | |||
8367 | if (PRE->isClassReceiver()) | |||
8368 | DiagnoseDeclAvailability(PRE->getClassReceiver(), PRE->getReceiverLocation()); | |||
8369 | return true; | |||
8370 | } | |||
8371 | ||||
8372 | bool VisitObjCMessageExpr(ObjCMessageExpr *Msg) { | |||
8373 | if (ObjCMethodDecl *D = Msg->getMethodDecl()) { | |||
8374 | ObjCInterfaceDecl *ID = nullptr; | |||
8375 | QualType ReceiverTy = Msg->getClassReceiver(); | |||
8376 | if (!ReceiverTy.isNull() && ReceiverTy->getAsObjCInterfaceType()) | |||
8377 | ID = ReceiverTy->getAsObjCInterfaceType()->getInterface(); | |||
8378 | ||||
8379 | DiagnoseDeclAvailability( | |||
8380 | D, SourceRange(Msg->getSelectorStartLoc(), Msg->getEndLoc()), ID); | |||
8381 | } | |||
8382 | return true; | |||
8383 | } | |||
8384 | ||||
8385 | bool VisitDeclRefExpr(DeclRefExpr *DRE) { | |||
8386 | DiagnoseDeclAvailability(DRE->getDecl(), | |||
8387 | SourceRange(DRE->getBeginLoc(), DRE->getEndLoc())); | |||
8388 | return true; | |||
8389 | } | |||
8390 | ||||
8391 | bool VisitMemberExpr(MemberExpr *ME) { | |||
8392 | DiagnoseDeclAvailability(ME->getMemberDecl(), | |||
8393 | SourceRange(ME->getBeginLoc(), ME->getEndLoc())); | |||
8394 | return true; | |||
8395 | } | |||
8396 | ||||
8397 | bool VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) { | |||
8398 | SemaRef.Diag(E->getBeginLoc(), diag::warn_at_available_unchecked_use) | |||
8399 | << (!SemaRef.getLangOpts().ObjC); | |||
8400 | return true; | |||
8401 | } | |||
8402 | ||||
8403 | bool VisitTypeLoc(TypeLoc Ty); | |||
8404 | }; | |||
8405 | ||||
8406 | void DiagnoseUnguardedAvailability::DiagnoseDeclAvailability( | |||
8407 | NamedDecl *D, SourceRange Range, ObjCInterfaceDecl *ReceiverClass) { | |||
8408 | AvailabilityResult Result; | |||
8409 | const NamedDecl *OffendingDecl; | |||
8410 | std::tie(Result, OffendingDecl) = | |||
8411 | ShouldDiagnoseAvailabilityOfDecl(SemaRef, D, nullptr, ReceiverClass); | |||
8412 | if (Result != AR_Available) { | |||
8413 | // All other diagnostic kinds have already been handled in | |||
8414 | // DiagnoseAvailabilityOfDecl. | |||
8415 | if (Result != AR_NotYetIntroduced) | |||
8416 | return; | |||
8417 | ||||
8418 | const AvailabilityAttr *AA = | |||
8419 | getAttrForPlatform(SemaRef.getASTContext(), OffendingDecl); | |||
8420 | VersionTuple Introduced = AA->getIntroduced(); | |||
8421 | ||||
8422 | if (AvailabilityStack.back() >= Introduced) | |||
8423 | return; | |||
8424 | ||||
8425 | // If the context of this function is less available than D, we should not | |||
8426 | // emit a diagnostic. | |||
8427 | if (!ShouldDiagnoseAvailabilityInContext(SemaRef, Result, Introduced, Ctx, | |||
8428 | OffendingDecl)) | |||
8429 | return; | |||
8430 | ||||
8431 | // We would like to emit the diagnostic even if -Wunguarded-availability is | |||
8432 | // not specified for deployment targets >= to iOS 11 or equivalent or | |||
8433 | // for declarations that were introduced in iOS 11 (macOS 10.13, ...) or | |||
8434 | // later. | |||
8435 | unsigned DiagKind = | |||
8436 | shouldDiagnoseAvailabilityByDefault( | |||
8437 | SemaRef.Context, | |||
8438 | SemaRef.Context.getTargetInfo().getPlatformMinVersion(), Introduced) | |||
8439 | ? diag::warn_unguarded_availability_new | |||
8440 | : diag::warn_unguarded_availability; | |||
8441 | ||||
8442 | std::string PlatformName = AvailabilityAttr::getPrettyPlatformName( | |||
8443 | SemaRef.getASTContext().getTargetInfo().getPlatformName()); | |||
8444 | ||||
8445 | SemaRef.Diag(Range.getBegin(), DiagKind) | |||
8446 | << Range << D << PlatformName << Introduced.getAsString(); | |||
8447 | ||||
8448 | SemaRef.Diag(OffendingDecl->getLocation(), | |||
8449 | diag::note_partial_availability_specified_here) | |||
8450 | << OffendingDecl << PlatformName << Introduced.getAsString() | |||
8451 | << SemaRef.Context.getTargetInfo() | |||
8452 | .getPlatformMinVersion() | |||
8453 | .getAsString(); | |||
8454 | ||||
8455 | auto FixitDiag = | |||
8456 | SemaRef.Diag(Range.getBegin(), diag::note_unguarded_available_silence) | |||
8457 | << Range << D | |||
8458 | << (SemaRef.getLangOpts().ObjC ? /*@available*/ 0 | |||
8459 | : /*__builtin_available*/ 1); | |||
8460 | ||||
8461 | // Find the statement which should be enclosed in the if @available check. | |||
8462 | if (StmtStack.empty()) | |||
8463 | return; | |||
8464 | const Stmt *StmtOfUse = StmtStack.back(); | |||
8465 | const CompoundStmt *Scope = nullptr; | |||
8466 | for (const Stmt *S : llvm::reverse(StmtStack)) { | |||
8467 | if (const auto *CS = dyn_cast<CompoundStmt>(S)) { | |||
8468 | Scope = CS; | |||
8469 | break; | |||
8470 | } | |||
8471 | if (isBodyLikeChildStmt(StmtOfUse, S)) { | |||
8472 | // The declaration won't be seen outside of the statement, so we don't | |||
8473 | // have to wrap the uses of any declared variables in if (@available). | |||
8474 | // Therefore we can avoid setting Scope here. | |||
8475 | break; | |||
8476 | } | |||
8477 | StmtOfUse = S; | |||
8478 | } | |||
8479 | const Stmt *LastStmtOfUse = nullptr; | |||
8480 | if (isa<DeclStmt>(StmtOfUse) && Scope) { | |||
8481 | for (const Decl *D : cast<DeclStmt>(StmtOfUse)->decls()) { | |||
8482 | if (StmtUSEFinder::isContained(StmtStack.back(), D)) { | |||
8483 | LastStmtOfUse = LastDeclUSEFinder::findLastStmtThatUsesDecl(D, Scope); | |||
8484 | break; | |||
8485 | } | |||
8486 | } | |||
8487 | } | |||
8488 | ||||
8489 | const SourceManager &SM = SemaRef.getSourceManager(); | |||
8490 | SourceLocation IfInsertionLoc = | |||
8491 | SM.getExpansionLoc(StmtOfUse->getBeginLoc()); | |||
8492 | SourceLocation StmtEndLoc = | |||
8493 | SM.getExpansionRange( | |||
8494 | (LastStmtOfUse ? LastStmtOfUse : StmtOfUse)->getEndLoc()) | |||
8495 | .getEnd(); | |||
8496 | if (SM.getFileID(IfInsertionLoc) != SM.getFileID(StmtEndLoc)) | |||
8497 | return; | |||
8498 | ||||
8499 | StringRef Indentation = Lexer::getIndentationForLine(IfInsertionLoc, SM); | |||
8500 | const char *ExtraIndentation = " "; | |||
8501 | std::string FixItString; | |||
8502 | llvm::raw_string_ostream FixItOS(FixItString); | |||
8503 | FixItOS << "if (" << (SemaRef.getLangOpts().ObjC ? "@available" | |||
8504 | : "__builtin_available") | |||
8505 | << "(" | |||
8506 | << AvailabilityAttr::getPlatformNameSourceSpelling( | |||
8507 | SemaRef.getASTContext().getTargetInfo().getPlatformName()) | |||
8508 | << " " << Introduced.getAsString() << ", *)) {\n" | |||
8509 | << Indentation << ExtraIndentation; | |||
8510 | FixitDiag << FixItHint::CreateInsertion(IfInsertionLoc, FixItOS.str()); | |||
8511 | SourceLocation ElseInsertionLoc = Lexer::findLocationAfterToken( | |||
8512 | StmtEndLoc, tok::semi, SM, SemaRef.getLangOpts(), | |||
8513 | /*SkipTrailingWhitespaceAndNewLine=*/false); | |||
8514 | if (ElseInsertionLoc.isInvalid()) | |||
8515 | ElseInsertionLoc = | |||
8516 | Lexer::getLocForEndOfToken(StmtEndLoc, 0, SM, SemaRef.getLangOpts()); | |||
8517 | FixItOS.str().clear(); | |||
8518 | FixItOS << "\n" | |||
8519 | << Indentation << "} else {\n" | |||
8520 | << Indentation << ExtraIndentation | |||
8521 | << "// Fallback on earlier versions\n" | |||
8522 | << Indentation << "}"; | |||
8523 | FixitDiag << FixItHint::CreateInsertion(ElseInsertionLoc, FixItOS.str()); | |||
8524 | } | |||
8525 | } | |||
8526 | ||||
8527 | bool DiagnoseUnguardedAvailability::VisitTypeLoc(TypeLoc Ty) { | |||
8528 | const Type *TyPtr = Ty.getTypePtr(); | |||
8529 | SourceRange Range{Ty.getBeginLoc(), Ty.getEndLoc()}; | |||
8530 | ||||
8531 | if (Range.isInvalid()) | |||
8532 | return true; | |||
8533 | ||||
8534 | if (const auto *TT = dyn_cast<TagType>(TyPtr)) { | |||
8535 | TagDecl *TD = TT->getDecl(); | |||
8536 | DiagnoseDeclAvailability(TD, Range); | |||
8537 | ||||
8538 | } else if (const auto *TD = dyn_cast<TypedefType>(TyPtr)) { | |||
8539 | TypedefNameDecl *D = TD->getDecl(); | |||
8540 | DiagnoseDeclAvailability(D, Range); | |||
8541 | ||||
8542 | } else if (const auto *ObjCO = dyn_cast<ObjCObjectType>(TyPtr)) { | |||
8543 | if (NamedDecl *D = ObjCO->getInterface()) | |||
8544 | DiagnoseDeclAvailability(D, Range); | |||
8545 | } | |||
8546 | ||||
8547 | return true; | |||
8548 | } | |||
8549 | ||||
8550 | bool DiagnoseUnguardedAvailability::TraverseIfStmt(IfStmt *If) { | |||
8551 | VersionTuple CondVersion; | |||
8552 | if (auto *E = dyn_cast<ObjCAvailabilityCheckExpr>(If->getCond())) { | |||
8553 | CondVersion = E->getVersion(); | |||
8554 | ||||
8555 | // If we're using the '*' case here or if this check is redundant, then we | |||
8556 | // use the enclosing version to check both branches. | |||
8557 | if (CondVersion.empty() || CondVersion <= AvailabilityStack.back()) | |||
8558 | return TraverseStmt(If->getThen()) && TraverseStmt(If->getElse()); | |||
8559 | } else { | |||
8560 | // This isn't an availability checking 'if', we can just continue. | |||
8561 | return Base::TraverseIfStmt(If); | |||
8562 | } | |||
8563 | ||||
8564 | AvailabilityStack.push_back(CondVersion); | |||
8565 | bool ShouldContinue = TraverseStmt(If->getThen()); | |||
8566 | AvailabilityStack.pop_back(); | |||
8567 | ||||
8568 | return ShouldContinue && TraverseStmt(If->getElse()); | |||
8569 | } | |||
8570 | ||||
8571 | } // end anonymous namespace | |||
8572 | ||||
8573 | void Sema::DiagnoseUnguardedAvailabilityViolations(Decl *D) { | |||
8574 | Stmt *Body = nullptr; | |||
8575 | ||||
8576 | if (auto *FD = D->getAsFunction()) { | |||
8577 | // FIXME: We only examine the pattern decl for availability violations now, | |||
8578 | // but we should also examine instantiated templates. | |||
8579 | if (FD->isTemplateInstantiation()) | |||
8580 | return; | |||
8581 | ||||
8582 | Body = FD->getBody(); | |||
8583 | } else if (auto *MD = dyn_cast<ObjCMethodDecl>(D)) | |||
8584 | Body = MD->getBody(); | |||
8585 | else if (auto *BD = dyn_cast<BlockDecl>(D)) | |||
8586 | Body = BD->getBody(); | |||
8587 | ||||
8588 | assert(Body && "Need a body here!")((Body && "Need a body here!") ? static_cast<void> (0) : __assert_fail ("Body && \"Need a body here!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaDeclAttr.cpp" , 8588, __PRETTY_FUNCTION__)); | |||
8589 | ||||
8590 | DiagnoseUnguardedAvailability(*this, D).IssueDiagnostics(Body); | |||
8591 | } | |||
8592 | ||||
8593 | void Sema::DiagnoseAvailabilityOfDecl(NamedDecl *D, | |||
8594 | ArrayRef<SourceLocation> Locs, | |||
8595 | const ObjCInterfaceDecl *UnknownObjCClass, | |||
8596 | bool ObjCPropertyAccess, | |||
8597 | bool AvoidPartialAvailabilityChecks, | |||
8598 | ObjCInterfaceDecl *ClassReceiver) { | |||
8599 | std::string Message; | |||
8600 | AvailabilityResult Result; | |||
8601 | const NamedDecl* OffendingDecl; | |||
8602 | // See if this declaration is unavailable, deprecated, or partial. | |||
8603 | std::tie(Result, OffendingDecl) = | |||
8604 | ShouldDiagnoseAvailabilityOfDecl(*this, D, &Message, ClassReceiver); | |||
8605 | if (Result == AR_Available) | |||
8606 | return; | |||
8607 | ||||
8608 | if (Result == AR_NotYetIntroduced) { | |||
8609 | if (AvoidPartialAvailabilityChecks) | |||
8610 | return; | |||
8611 | ||||
8612 | // We need to know the @available context in the current function to | |||
8613 | // diagnose this use, let DiagnoseUnguardedAvailabilityViolations do that | |||
8614 | // when we're done parsing the current function. | |||
8615 | if (getCurFunctionOrMethodDecl()) { | |||
8616 | getEnclosingFunction()->HasPotentialAvailabilityViolations = true; | |||
8617 | return; | |||
8618 | } else if (getCurBlock() || getCurLambda()) { | |||
8619 | getCurFunction()->HasPotentialAvailabilityViolations = true; | |||
8620 | return; | |||
8621 | } | |||
8622 | } | |||
8623 | ||||
8624 | const ObjCPropertyDecl *ObjCPDecl = nullptr; | |||
8625 | if (const auto *MD = dyn_cast<ObjCMethodDecl>(D)) { | |||
8626 | if (const ObjCPropertyDecl *PD = MD->findPropertyDecl()) { | |||
8627 | AvailabilityResult PDeclResult = PD->getAvailability(nullptr); | |||
8628 | if (PDeclResult == Result) | |||
8629 | ObjCPDecl = PD; | |||
8630 | } | |||
8631 | } | |||
8632 | ||||
8633 | EmitAvailabilityWarning(*this, Result, D, OffendingDecl, Message, Locs, | |||
8634 | UnknownObjCClass, ObjCPDecl, ObjCPropertyAccess); | |||
8635 | } |
1 | /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ | |||
2 | |* *| | |||
3 | |* Attribute classes' definitions *| | |||
4 | |* *| | |||
5 | |* Automatically generated file, do not edit! *| | |||
6 | |* *| | |||
7 | \*===----------------------------------------------------------------------===*/ | |||
8 | ||||
9 | #ifndef LLVM_CLANG_ATTR_CLASSES_INC | |||
10 | #define LLVM_CLANG_ATTR_CLASSES_INC | |||
11 | ||||
12 | class AArch64VectorPcsAttr : public InheritableAttr { | |||
13 | public: | |||
14 | static AArch64VectorPcsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
15 | auto *A = new (Ctx) AArch64VectorPcsAttr(Loc, Ctx, 0); | |||
16 | A->setImplicit(true); | |||
17 | return A; | |||
18 | } | |||
19 | ||||
20 | AArch64VectorPcsAttr(SourceRange R, ASTContext &Ctx | |||
21 | , unsigned SI | |||
22 | ) | |||
23 | : InheritableAttr(attr::AArch64VectorPcs, R, SI, false, false) | |||
24 | { | |||
25 | } | |||
26 | ||||
27 | AArch64VectorPcsAttr *clone(ASTContext &C) const; | |||
28 | void printPretty(raw_ostream &OS, | |||
29 | const PrintingPolicy &Policy) const; | |||
30 | const char *getSpelling() const; | |||
31 | ||||
32 | ||||
33 | static bool classof(const Attr *A) { return A->getKind() == attr::AArch64VectorPcs; } | |||
34 | }; | |||
35 | ||||
36 | class AMDGPUFlatWorkGroupSizeAttr : public InheritableAttr { | |||
37 | Expr * min; | |||
38 | ||||
39 | Expr * max; | |||
40 | ||||
41 | public: | |||
42 | static AMDGPUFlatWorkGroupSizeAttr *CreateImplicit(ASTContext &Ctx, Expr * Min, Expr * Max, SourceRange Loc = SourceRange()) { | |||
43 | auto *A = new (Ctx) AMDGPUFlatWorkGroupSizeAttr(Loc, Ctx, Min, Max, 0); | |||
44 | A->setImplicit(true); | |||
45 | return A; | |||
46 | } | |||
47 | ||||
48 | AMDGPUFlatWorkGroupSizeAttr(SourceRange R, ASTContext &Ctx | |||
49 | , Expr * Min | |||
50 | , Expr * Max | |||
51 | , unsigned SI | |||
52 | ) | |||
53 | : InheritableAttr(attr::AMDGPUFlatWorkGroupSize, R, SI, false, false) | |||
54 | , min(Min) | |||
55 | , max(Max) | |||
56 | { | |||
57 | } | |||
58 | ||||
59 | AMDGPUFlatWorkGroupSizeAttr *clone(ASTContext &C) const; | |||
60 | void printPretty(raw_ostream &OS, | |||
61 | const PrintingPolicy &Policy) const; | |||
62 | const char *getSpelling() const; | |||
63 | Expr * getMin() const { | |||
64 | return min; | |||
65 | } | |||
66 | ||||
67 | Expr * getMax() const { | |||
68 | return max; | |||
69 | } | |||
70 | ||||
71 | ||||
72 | ||||
73 | static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUFlatWorkGroupSize; } | |||
74 | }; | |||
75 | ||||
76 | class AMDGPUNumSGPRAttr : public InheritableAttr { | |||
77 | unsigned numSGPR; | |||
78 | ||||
79 | public: | |||
80 | static AMDGPUNumSGPRAttr *CreateImplicit(ASTContext &Ctx, unsigned NumSGPR, SourceRange Loc = SourceRange()) { | |||
81 | auto *A = new (Ctx) AMDGPUNumSGPRAttr(Loc, Ctx, NumSGPR, 0); | |||
82 | A->setImplicit(true); | |||
83 | return A; | |||
84 | } | |||
85 | ||||
86 | AMDGPUNumSGPRAttr(SourceRange R, ASTContext &Ctx | |||
87 | , unsigned NumSGPR | |||
88 | , unsigned SI | |||
89 | ) | |||
90 | : InheritableAttr(attr::AMDGPUNumSGPR, R, SI, false, false) | |||
91 | , numSGPR(NumSGPR) | |||
92 | { | |||
93 | } | |||
94 | ||||
95 | AMDGPUNumSGPRAttr *clone(ASTContext &C) const; | |||
96 | void printPretty(raw_ostream &OS, | |||
97 | const PrintingPolicy &Policy) const; | |||
98 | const char *getSpelling() const; | |||
99 | unsigned getNumSGPR() const { | |||
100 | return numSGPR; | |||
101 | } | |||
102 | ||||
103 | ||||
104 | ||||
105 | static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUNumSGPR; } | |||
106 | }; | |||
107 | ||||
108 | class AMDGPUNumVGPRAttr : public InheritableAttr { | |||
109 | unsigned numVGPR; | |||
110 | ||||
111 | public: | |||
112 | static AMDGPUNumVGPRAttr *CreateImplicit(ASTContext &Ctx, unsigned NumVGPR, SourceRange Loc = SourceRange()) { | |||
113 | auto *A = new (Ctx) AMDGPUNumVGPRAttr(Loc, Ctx, NumVGPR, 0); | |||
114 | A->setImplicit(true); | |||
115 | return A; | |||
116 | } | |||
117 | ||||
118 | AMDGPUNumVGPRAttr(SourceRange R, ASTContext &Ctx | |||
119 | , unsigned NumVGPR | |||
120 | , unsigned SI | |||
121 | ) | |||
122 | : InheritableAttr(attr::AMDGPUNumVGPR, R, SI, false, false) | |||
123 | , numVGPR(NumVGPR) | |||
124 | { | |||
125 | } | |||
126 | ||||
127 | AMDGPUNumVGPRAttr *clone(ASTContext &C) const; | |||
128 | void printPretty(raw_ostream &OS, | |||
129 | const PrintingPolicy &Policy) const; | |||
130 | const char *getSpelling() const; | |||
131 | unsigned getNumVGPR() const { | |||
132 | return numVGPR; | |||
133 | } | |||
134 | ||||
135 | ||||
136 | ||||
137 | static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUNumVGPR; } | |||
138 | }; | |||
139 | ||||
140 | class AMDGPUWavesPerEUAttr : public InheritableAttr { | |||
141 | Expr * min; | |||
142 | ||||
143 | Expr * max; | |||
144 | ||||
145 | public: | |||
146 | static AMDGPUWavesPerEUAttr *CreateImplicit(ASTContext &Ctx, Expr * Min, Expr * Max, SourceRange Loc = SourceRange()) { | |||
147 | auto *A = new (Ctx) AMDGPUWavesPerEUAttr(Loc, Ctx, Min, Max, 0); | |||
148 | A->setImplicit(true); | |||
149 | return A; | |||
150 | } | |||
151 | ||||
152 | AMDGPUWavesPerEUAttr(SourceRange R, ASTContext &Ctx | |||
153 | , Expr * Min | |||
154 | , Expr * Max | |||
155 | , unsigned SI | |||
156 | ) | |||
157 | : InheritableAttr(attr::AMDGPUWavesPerEU, R, SI, false, false) | |||
158 | , min(Min) | |||
159 | , max(Max) | |||
160 | { | |||
161 | } | |||
162 | ||||
163 | AMDGPUWavesPerEUAttr(SourceRange R, ASTContext &Ctx | |||
164 | , Expr * Min | |||
165 | , unsigned SI | |||
166 | ) | |||
167 | : InheritableAttr(attr::AMDGPUWavesPerEU, R, SI, false, false) | |||
168 | , min(Min) | |||
169 | , max() | |||
170 | { | |||
171 | } | |||
172 | ||||
173 | AMDGPUWavesPerEUAttr *clone(ASTContext &C) const; | |||
174 | void printPretty(raw_ostream &OS, | |||
175 | const PrintingPolicy &Policy) const; | |||
176 | const char *getSpelling() const; | |||
177 | Expr * getMin() const { | |||
178 | return min; | |||
179 | } | |||
180 | ||||
181 | Expr * getMax() const { | |||
182 | return max; | |||
183 | } | |||
184 | ||||
185 | ||||
186 | ||||
187 | static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUWavesPerEU; } | |||
188 | }; | |||
189 | ||||
190 | class ARMInterruptAttr : public InheritableAttr { | |||
191 | public: | |||
192 | enum InterruptType { | |||
193 | IRQ, | |||
194 | FIQ, | |||
195 | SWI, | |||
196 | ABORT, | |||
197 | UNDEF, | |||
198 | Generic | |||
199 | }; | |||
200 | private: | |||
201 | InterruptType interrupt; | |||
202 | ||||
203 | public: | |||
204 | static ARMInterruptAttr *CreateImplicit(ASTContext &Ctx, InterruptType Interrupt, SourceRange Loc = SourceRange()) { | |||
205 | auto *A = new (Ctx) ARMInterruptAttr(Loc, Ctx, Interrupt, 0); | |||
206 | A->setImplicit(true); | |||
207 | return A; | |||
208 | } | |||
209 | ||||
210 | ARMInterruptAttr(SourceRange R, ASTContext &Ctx | |||
211 | , InterruptType Interrupt | |||
212 | , unsigned SI | |||
213 | ) | |||
214 | : InheritableAttr(attr::ARMInterrupt, R, SI, false, false) | |||
215 | , interrupt(Interrupt) | |||
216 | { | |||
217 | } | |||
218 | ||||
219 | ARMInterruptAttr(SourceRange R, ASTContext &Ctx | |||
220 | , unsigned SI | |||
221 | ) | |||
222 | : InheritableAttr(attr::ARMInterrupt, R, SI, false, false) | |||
223 | , interrupt(InterruptType(0)) | |||
224 | { | |||
225 | } | |||
226 | ||||
227 | ARMInterruptAttr *clone(ASTContext &C) const; | |||
228 | void printPretty(raw_ostream &OS, | |||
229 | const PrintingPolicy &Policy) const; | |||
230 | const char *getSpelling() const; | |||
231 | InterruptType getInterrupt() const { | |||
232 | return interrupt; | |||
233 | } | |||
234 | ||||
235 | static bool ConvertStrToInterruptType(StringRef Val, InterruptType &Out) { | |||
236 | Optional<InterruptType> R = llvm::StringSwitch<Optional<InterruptType>>(Val) | |||
237 | .Case("IRQ", ARMInterruptAttr::IRQ) | |||
238 | .Case("FIQ", ARMInterruptAttr::FIQ) | |||
239 | .Case("SWI", ARMInterruptAttr::SWI) | |||
240 | .Case("ABORT", ARMInterruptAttr::ABORT) | |||
241 | .Case("UNDEF", ARMInterruptAttr::UNDEF) | |||
242 | .Case("", ARMInterruptAttr::Generic) | |||
243 | .Default(Optional<InterruptType>()); | |||
244 | if (R) { | |||
245 | Out = *R; | |||
246 | return true; | |||
247 | } | |||
248 | return false; | |||
249 | } | |||
250 | ||||
251 | static const char *ConvertInterruptTypeToStr(InterruptType Val) { | |||
252 | switch(Val) { | |||
253 | case ARMInterruptAttr::IRQ: return "IRQ"; | |||
254 | case ARMInterruptAttr::FIQ: return "FIQ"; | |||
255 | case ARMInterruptAttr::SWI: return "SWI"; | |||
256 | case ARMInterruptAttr::ABORT: return "ABORT"; | |||
257 | case ARMInterruptAttr::UNDEF: return "UNDEF"; | |||
258 | case ARMInterruptAttr::Generic: return ""; | |||
259 | } | |||
260 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 260); | |||
261 | } | |||
262 | ||||
263 | ||||
264 | static bool classof(const Attr *A) { return A->getKind() == attr::ARMInterrupt; } | |||
265 | }; | |||
266 | ||||
267 | class AVRInterruptAttr : public InheritableAttr { | |||
268 | public: | |||
269 | static AVRInterruptAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
270 | auto *A = new (Ctx) AVRInterruptAttr(Loc, Ctx, 0); | |||
271 | A->setImplicit(true); | |||
272 | return A; | |||
273 | } | |||
274 | ||||
275 | AVRInterruptAttr(SourceRange R, ASTContext &Ctx | |||
276 | , unsigned SI | |||
277 | ) | |||
278 | : InheritableAttr(attr::AVRInterrupt, R, SI, false, false) | |||
279 | { | |||
280 | } | |||
281 | ||||
282 | AVRInterruptAttr *clone(ASTContext &C) const; | |||
283 | void printPretty(raw_ostream &OS, | |||
284 | const PrintingPolicy &Policy) const; | |||
285 | const char *getSpelling() const; | |||
286 | ||||
287 | ||||
288 | static bool classof(const Attr *A) { return A->getKind() == attr::AVRInterrupt; } | |||
289 | }; | |||
290 | ||||
291 | class AVRSignalAttr : public InheritableAttr { | |||
292 | public: | |||
293 | static AVRSignalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
294 | auto *A = new (Ctx) AVRSignalAttr(Loc, Ctx, 0); | |||
295 | A->setImplicit(true); | |||
296 | return A; | |||
297 | } | |||
298 | ||||
299 | AVRSignalAttr(SourceRange R, ASTContext &Ctx | |||
300 | , unsigned SI | |||
301 | ) | |||
302 | : InheritableAttr(attr::AVRSignal, R, SI, false, false) | |||
303 | { | |||
304 | } | |||
305 | ||||
306 | AVRSignalAttr *clone(ASTContext &C) const; | |||
307 | void printPretty(raw_ostream &OS, | |||
308 | const PrintingPolicy &Policy) const; | |||
309 | const char *getSpelling() const; | |||
310 | ||||
311 | ||||
312 | static bool classof(const Attr *A) { return A->getKind() == attr::AVRSignal; } | |||
313 | }; | |||
314 | ||||
315 | class AbiTagAttr : public Attr { | |||
316 | unsigned tags_Size; | |||
317 | StringRef *tags_; | |||
318 | ||||
319 | public: | |||
320 | static AbiTagAttr *CreateImplicit(ASTContext &Ctx, StringRef *Tags, unsigned TagsSize, SourceRange Loc = SourceRange()) { | |||
321 | auto *A = new (Ctx) AbiTagAttr(Loc, Ctx, Tags, TagsSize, 0); | |||
322 | A->setImplicit(true); | |||
323 | return A; | |||
324 | } | |||
325 | ||||
326 | AbiTagAttr(SourceRange R, ASTContext &Ctx | |||
327 | , StringRef *Tags, unsigned TagsSize | |||
328 | , unsigned SI | |||
329 | ) | |||
330 | : Attr(attr::AbiTag, R, SI, false) | |||
331 | , tags_Size(TagsSize), tags_(new (Ctx, 16) StringRef[tags_Size]) | |||
332 | { | |||
333 | for (size_t I = 0, E = tags_Size; I != E; | |||
334 | ++I) { | |||
335 | StringRef Ref = Tags[I]; | |||
336 | if (!Ref.empty()) { | |||
337 | char *Mem = new (Ctx, 1) char[Ref.size()]; | |||
338 | std::memcpy(Mem, Ref.data(), Ref.size()); | |||
339 | tags_[I] = StringRef(Mem, Ref.size()); | |||
340 | } | |||
341 | } | |||
342 | } | |||
343 | ||||
344 | AbiTagAttr(SourceRange R, ASTContext &Ctx | |||
345 | , unsigned SI | |||
346 | ) | |||
347 | : Attr(attr::AbiTag, R, SI, false) | |||
348 | , tags_Size(0), tags_(nullptr) | |||
349 | { | |||
350 | } | |||
351 | ||||
352 | AbiTagAttr *clone(ASTContext &C) const; | |||
353 | void printPretty(raw_ostream &OS, | |||
354 | const PrintingPolicy &Policy) const; | |||
355 | const char *getSpelling() const; | |||
356 | typedef StringRef* tags_iterator; | |||
357 | tags_iterator tags_begin() const { return tags_; } | |||
358 | tags_iterator tags_end() const { return tags_ + tags_Size; } | |||
359 | unsigned tags_size() const { return tags_Size; } | |||
360 | llvm::iterator_range<tags_iterator> tags() const { return llvm::make_range(tags_begin(), tags_end()); } | |||
361 | ||||
362 | ||||
363 | ||||
364 | ||||
365 | static bool classof(const Attr *A) { return A->getKind() == attr::AbiTag; } | |||
366 | }; | |||
367 | ||||
368 | class AcquireCapabilityAttr : public InheritableAttr { | |||
369 | unsigned args_Size; | |||
370 | Expr * *args_; | |||
371 | ||||
372 | public: | |||
373 | enum Spelling { | |||
374 | GNU_acquire_capability = 0, | |||
375 | CXX11_clang_acquire_capability = 1, | |||
376 | GNU_acquire_shared_capability = 2, | |||
377 | CXX11_clang_acquire_shared_capability = 3, | |||
378 | GNU_exclusive_lock_function = 4, | |||
379 | GNU_shared_lock_function = 5 | |||
380 | }; | |||
381 | ||||
382 | static AcquireCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
383 | auto *A = new (Ctx) AcquireCapabilityAttr(Loc, Ctx, Args, ArgsSize, S); | |||
384 | A->setImplicit(true); | |||
385 | return A; | |||
386 | } | |||
387 | ||||
388 | AcquireCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
389 | , Expr * *Args, unsigned ArgsSize | |||
390 | , unsigned SI | |||
391 | ) | |||
392 | : InheritableAttr(attr::AcquireCapability, R, SI, true, true) | |||
393 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
394 | { | |||
395 | std::copy(Args, Args + args_Size, args_); | |||
396 | } | |||
397 | ||||
398 | AcquireCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
399 | , unsigned SI | |||
400 | ) | |||
401 | : InheritableAttr(attr::AcquireCapability, R, SI, true, true) | |||
402 | , args_Size(0), args_(nullptr) | |||
403 | { | |||
404 | } | |||
405 | ||||
406 | AcquireCapabilityAttr *clone(ASTContext &C) const; | |||
407 | void printPretty(raw_ostream &OS, | |||
408 | const PrintingPolicy &Policy) const; | |||
409 | const char *getSpelling() const; | |||
410 | Spelling getSemanticSpelling() const { | |||
411 | switch (SpellingListIndex) { | |||
412 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 412); | |||
413 | case 0: return GNU_acquire_capability; | |||
414 | case 1: return CXX11_clang_acquire_capability; | |||
415 | case 2: return GNU_acquire_shared_capability; | |||
416 | case 3: return CXX11_clang_acquire_shared_capability; | |||
417 | case 4: return GNU_exclusive_lock_function; | |||
418 | case 5: return GNU_shared_lock_function; | |||
419 | } | |||
420 | } | |||
421 | bool isShared() const { return SpellingListIndex == 2 || | |||
422 | SpellingListIndex == 3 || | |||
423 | SpellingListIndex == 5; } | |||
424 | typedef Expr ** args_iterator; | |||
425 | args_iterator args_begin() const { return args_; } | |||
426 | args_iterator args_end() const { return args_ + args_Size; } | |||
427 | unsigned args_size() const { return args_Size; } | |||
428 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
429 | ||||
430 | ||||
431 | ||||
432 | ||||
433 | static bool classof(const Attr *A) { return A->getKind() == attr::AcquireCapability; } | |||
434 | }; | |||
435 | ||||
436 | class AcquiredAfterAttr : public InheritableAttr { | |||
437 | unsigned args_Size; | |||
438 | Expr * *args_; | |||
439 | ||||
440 | public: | |||
441 | static AcquiredAfterAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
442 | auto *A = new (Ctx) AcquiredAfterAttr(Loc, Ctx, Args, ArgsSize, 0); | |||
443 | A->setImplicit(true); | |||
444 | return A; | |||
445 | } | |||
446 | ||||
447 | AcquiredAfterAttr(SourceRange R, ASTContext &Ctx | |||
448 | , Expr * *Args, unsigned ArgsSize | |||
449 | , unsigned SI | |||
450 | ) | |||
451 | : InheritableAttr(attr::AcquiredAfter, R, SI, true, true) | |||
452 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
453 | { | |||
454 | std::copy(Args, Args + args_Size, args_); | |||
455 | } | |||
456 | ||||
457 | AcquiredAfterAttr(SourceRange R, ASTContext &Ctx | |||
458 | , unsigned SI | |||
459 | ) | |||
460 | : InheritableAttr(attr::AcquiredAfter, R, SI, true, true) | |||
461 | , args_Size(0), args_(nullptr) | |||
462 | { | |||
463 | } | |||
464 | ||||
465 | AcquiredAfterAttr *clone(ASTContext &C) const; | |||
466 | void printPretty(raw_ostream &OS, | |||
467 | const PrintingPolicy &Policy) const; | |||
468 | const char *getSpelling() const; | |||
469 | typedef Expr ** args_iterator; | |||
470 | args_iterator args_begin() const { return args_; } | |||
471 | args_iterator args_end() const { return args_ + args_Size; } | |||
472 | unsigned args_size() const { return args_Size; } | |||
473 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
474 | ||||
475 | ||||
476 | ||||
477 | ||||
478 | static bool classof(const Attr *A) { return A->getKind() == attr::AcquiredAfter; } | |||
479 | }; | |||
480 | ||||
481 | class AcquiredBeforeAttr : public InheritableAttr { | |||
482 | unsigned args_Size; | |||
483 | Expr * *args_; | |||
484 | ||||
485 | public: | |||
486 | static AcquiredBeforeAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
487 | auto *A = new (Ctx) AcquiredBeforeAttr(Loc, Ctx, Args, ArgsSize, 0); | |||
488 | A->setImplicit(true); | |||
489 | return A; | |||
490 | } | |||
491 | ||||
492 | AcquiredBeforeAttr(SourceRange R, ASTContext &Ctx | |||
493 | , Expr * *Args, unsigned ArgsSize | |||
494 | , unsigned SI | |||
495 | ) | |||
496 | : InheritableAttr(attr::AcquiredBefore, R, SI, true, true) | |||
497 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
498 | { | |||
499 | std::copy(Args, Args + args_Size, args_); | |||
500 | } | |||
501 | ||||
502 | AcquiredBeforeAttr(SourceRange R, ASTContext &Ctx | |||
503 | , unsigned SI | |||
504 | ) | |||
505 | : InheritableAttr(attr::AcquiredBefore, R, SI, true, true) | |||
506 | , args_Size(0), args_(nullptr) | |||
507 | { | |||
508 | } | |||
509 | ||||
510 | AcquiredBeforeAttr *clone(ASTContext &C) const; | |||
511 | void printPretty(raw_ostream &OS, | |||
512 | const PrintingPolicy &Policy) const; | |||
513 | const char *getSpelling() const; | |||
514 | typedef Expr ** args_iterator; | |||
515 | args_iterator args_begin() const { return args_; } | |||
516 | args_iterator args_end() const { return args_ + args_Size; } | |||
517 | unsigned args_size() const { return args_Size; } | |||
518 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
519 | ||||
520 | ||||
521 | ||||
522 | ||||
523 | static bool classof(const Attr *A) { return A->getKind() == attr::AcquiredBefore; } | |||
524 | }; | |||
525 | ||||
526 | class AddressSpaceAttr : public TypeAttr { | |||
527 | int addressSpace; | |||
528 | ||||
529 | public: | |||
530 | static AddressSpaceAttr *CreateImplicit(ASTContext &Ctx, int AddressSpace, SourceRange Loc = SourceRange()) { | |||
531 | auto *A = new (Ctx) AddressSpaceAttr(Loc, Ctx, AddressSpace, 0); | |||
532 | A->setImplicit(true); | |||
533 | return A; | |||
534 | } | |||
535 | ||||
536 | AddressSpaceAttr(SourceRange R, ASTContext &Ctx | |||
537 | , int AddressSpace | |||
538 | , unsigned SI | |||
539 | ) | |||
540 | : TypeAttr(attr::AddressSpace, R, SI, false) | |||
541 | , addressSpace(AddressSpace) | |||
542 | { | |||
543 | } | |||
544 | ||||
545 | AddressSpaceAttr *clone(ASTContext &C) const; | |||
546 | void printPretty(raw_ostream &OS, | |||
547 | const PrintingPolicy &Policy) const; | |||
548 | const char *getSpelling() const; | |||
549 | int getAddressSpace() const { | |||
550 | return addressSpace; | |||
551 | } | |||
552 | ||||
553 | ||||
554 | ||||
555 | static bool classof(const Attr *A) { return A->getKind() == attr::AddressSpace; } | |||
556 | }; | |||
557 | ||||
558 | class AliasAttr : public Attr { | |||
559 | unsigned aliaseeLength; | |||
560 | char *aliasee; | |||
561 | ||||
562 | public: | |||
563 | static AliasAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Aliasee, SourceRange Loc = SourceRange()) { | |||
564 | auto *A = new (Ctx) AliasAttr(Loc, Ctx, Aliasee, 0); | |||
565 | A->setImplicit(true); | |||
566 | return A; | |||
567 | } | |||
568 | ||||
569 | AliasAttr(SourceRange R, ASTContext &Ctx | |||
570 | , llvm::StringRef Aliasee | |||
571 | , unsigned SI | |||
572 | ) | |||
573 | : Attr(attr::Alias, R, SI, false) | |||
574 | , aliaseeLength(Aliasee.size()),aliasee(new (Ctx, 1) char[aliaseeLength]) | |||
575 | { | |||
576 | if (!Aliasee.empty()) | |||
577 | std::memcpy(aliasee, Aliasee.data(), aliaseeLength); | |||
578 | } | |||
579 | ||||
580 | AliasAttr *clone(ASTContext &C) const; | |||
581 | void printPretty(raw_ostream &OS, | |||
582 | const PrintingPolicy &Policy) const; | |||
583 | const char *getSpelling() const; | |||
584 | llvm::StringRef getAliasee() const { | |||
585 | return llvm::StringRef(aliasee, aliaseeLength); | |||
586 | } | |||
587 | unsigned getAliaseeLength() const { | |||
588 | return aliaseeLength; | |||
589 | } | |||
590 | void setAliasee(ASTContext &C, llvm::StringRef S) { | |||
591 | aliaseeLength = S.size(); | |||
592 | this->aliasee = new (C, 1) char [aliaseeLength]; | |||
593 | if (!S.empty()) | |||
594 | std::memcpy(this->aliasee, S.data(), aliaseeLength); | |||
595 | } | |||
596 | ||||
597 | ||||
598 | ||||
599 | static bool classof(const Attr *A) { return A->getKind() == attr::Alias; } | |||
600 | }; | |||
601 | ||||
602 | class AlignMac68kAttr : public InheritableAttr { | |||
603 | public: | |||
604 | static AlignMac68kAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
605 | auto *A = new (Ctx) AlignMac68kAttr(Loc, Ctx, 0); | |||
606 | A->setImplicit(true); | |||
607 | return A; | |||
608 | } | |||
609 | ||||
610 | AlignMac68kAttr(SourceRange R, ASTContext &Ctx | |||
611 | , unsigned SI | |||
612 | ) | |||
613 | : InheritableAttr(attr::AlignMac68k, R, SI, false, false) | |||
614 | { | |||
615 | } | |||
616 | ||||
617 | AlignMac68kAttr *clone(ASTContext &C) const; | |||
618 | void printPretty(raw_ostream &OS, | |||
619 | const PrintingPolicy &Policy) const; | |||
620 | const char *getSpelling() const; | |||
621 | ||||
622 | ||||
623 | static bool classof(const Attr *A) { return A->getKind() == attr::AlignMac68k; } | |||
624 | }; | |||
625 | ||||
626 | class AlignValueAttr : public Attr { | |||
627 | Expr * alignment; | |||
628 | ||||
629 | public: | |||
630 | static AlignValueAttr *CreateImplicit(ASTContext &Ctx, Expr * Alignment, SourceRange Loc = SourceRange()) { | |||
631 | auto *A = new (Ctx) AlignValueAttr(Loc, Ctx, Alignment, 0); | |||
632 | A->setImplicit(true); | |||
633 | return A; | |||
634 | } | |||
635 | ||||
636 | AlignValueAttr(SourceRange R, ASTContext &Ctx | |||
637 | , Expr * Alignment | |||
638 | , unsigned SI | |||
639 | ) | |||
640 | : Attr(attr::AlignValue, R, SI, false) | |||
641 | , alignment(Alignment) | |||
642 | { | |||
643 | } | |||
644 | ||||
645 | AlignValueAttr *clone(ASTContext &C) const; | |||
646 | void printPretty(raw_ostream &OS, | |||
647 | const PrintingPolicy &Policy) const; | |||
648 | const char *getSpelling() const; | |||
649 | Expr * getAlignment() const { | |||
650 | return alignment; | |||
651 | } | |||
652 | ||||
653 | ||||
654 | ||||
655 | static bool classof(const Attr *A) { return A->getKind() == attr::AlignValue; } | |||
656 | }; | |||
657 | ||||
658 | class AlignedAttr : public InheritableAttr { | |||
659 | bool isalignmentExpr; | |||
660 | union { | |||
661 | Expr *alignmentExpr; | |||
662 | TypeSourceInfo *alignmentType; | |||
663 | }; | |||
664 | ||||
665 | public: | |||
666 | enum Spelling { | |||
667 | GNU_aligned = 0, | |||
668 | CXX11_gnu_aligned = 1, | |||
669 | Declspec_align = 2, | |||
670 | Keyword_alignas = 3, | |||
671 | Keyword_Alignas = 4 | |||
672 | }; | |||
673 | ||||
674 | static AlignedAttr *CreateImplicit(ASTContext &Ctx, Spelling S, bool IsAlignmentExpr, void *Alignment, SourceRange Loc = SourceRange()) { | |||
675 | auto *A = new (Ctx) AlignedAttr(Loc, Ctx, IsAlignmentExpr, Alignment, S); | |||
676 | A->setImplicit(true); | |||
677 | return A; | |||
678 | } | |||
679 | ||||
680 | AlignedAttr(SourceRange R, ASTContext &Ctx | |||
681 | , bool IsAlignmentExpr, void *Alignment | |||
682 | , unsigned SI | |||
683 | ) | |||
684 | : InheritableAttr(attr::Aligned, R, SI, false, false) | |||
685 | , isalignmentExpr(IsAlignmentExpr) | |||
686 | { | |||
687 | if (isalignmentExpr) | |||
688 | alignmentExpr = reinterpret_cast<Expr *>(Alignment); | |||
689 | else | |||
690 | alignmentType = reinterpret_cast<TypeSourceInfo *>(Alignment); | |||
691 | } | |||
692 | ||||
693 | AlignedAttr(SourceRange R, ASTContext &Ctx | |||
694 | , unsigned SI | |||
695 | ) | |||
696 | : InheritableAttr(attr::Aligned, R, SI, false, false) | |||
697 | , isalignmentExpr(false) | |||
698 | { | |||
699 | } | |||
700 | ||||
701 | AlignedAttr *clone(ASTContext &C) const; | |||
702 | void printPretty(raw_ostream &OS, | |||
703 | const PrintingPolicy &Policy) const; | |||
704 | const char *getSpelling() const; | |||
705 | Spelling getSemanticSpelling() const { | |||
706 | switch (SpellingListIndex) { | |||
707 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 707); | |||
708 | case 0: return GNU_aligned; | |||
709 | case 1: return CXX11_gnu_aligned; | |||
710 | case 2: return Declspec_align; | |||
711 | case 3: return Keyword_alignas; | |||
712 | case 4: return Keyword_Alignas; | |||
713 | } | |||
714 | } | |||
715 | bool isGNU() const { return SpellingListIndex == 0 || | |||
716 | SpellingListIndex == 1; } | |||
717 | bool isC11() const { return SpellingListIndex == 4; } | |||
718 | bool isAlignas() const { return SpellingListIndex == 3 || | |||
719 | SpellingListIndex == 4; } | |||
720 | bool isDeclspec() const { return SpellingListIndex == 2; } | |||
721 | bool isAlignmentDependent() const; | |||
722 | unsigned getAlignment(ASTContext &Ctx) const; | |||
723 | bool isAlignmentExpr() const { | |||
724 | return isalignmentExpr; | |||
725 | } | |||
726 | Expr *getAlignmentExpr() const { | |||
727 | assert(isalignmentExpr)((isalignmentExpr) ? static_cast<void> (0) : __assert_fail ("isalignmentExpr", "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 727, __PRETTY_FUNCTION__)); | |||
728 | return alignmentExpr; | |||
729 | } | |||
730 | TypeSourceInfo *getAlignmentType() const { | |||
731 | assert(!isalignmentExpr)((!isalignmentExpr) ? static_cast<void> (0) : __assert_fail ("!isalignmentExpr", "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 731, __PRETTY_FUNCTION__)); | |||
732 | return alignmentType; | |||
733 | } | |||
734 | ||||
735 | ||||
736 | ||||
737 | static bool classof(const Attr *A) { return A->getKind() == attr::Aligned; } | |||
738 | }; | |||
739 | ||||
740 | class AllocAlignAttr : public InheritableAttr { | |||
741 | ParamIdx paramIndex; | |||
742 | ||||
743 | public: | |||
744 | static AllocAlignAttr *CreateImplicit(ASTContext &Ctx, ParamIdx ParamIndex, SourceRange Loc = SourceRange()) { | |||
745 | auto *A = new (Ctx) AllocAlignAttr(Loc, Ctx, ParamIndex, 0); | |||
746 | A->setImplicit(true); | |||
747 | return A; | |||
748 | } | |||
749 | ||||
750 | AllocAlignAttr(SourceRange R, ASTContext &Ctx | |||
751 | , ParamIdx ParamIndex | |||
752 | , unsigned SI | |||
753 | ) | |||
754 | : InheritableAttr(attr::AllocAlign, R, SI, false, false) | |||
755 | , paramIndex(ParamIndex) | |||
756 | { | |||
757 | } | |||
758 | ||||
759 | AllocAlignAttr *clone(ASTContext &C) const; | |||
760 | void printPretty(raw_ostream &OS, | |||
761 | const PrintingPolicy &Policy) const; | |||
762 | const char *getSpelling() const; | |||
763 | ParamIdx getParamIndex() const { | |||
764 | return paramIndex; | |||
765 | } | |||
766 | ||||
767 | ||||
768 | ||||
769 | static bool classof(const Attr *A) { return A->getKind() == attr::AllocAlign; } | |||
770 | }; | |||
771 | ||||
772 | class AllocSizeAttr : public InheritableAttr { | |||
773 | ParamIdx elemSizeParam; | |||
774 | ||||
775 | ParamIdx numElemsParam; | |||
776 | ||||
777 | public: | |||
778 | static AllocSizeAttr *CreateImplicit(ASTContext &Ctx, ParamIdx ElemSizeParam, ParamIdx NumElemsParam, SourceRange Loc = SourceRange()) { | |||
779 | auto *A = new (Ctx) AllocSizeAttr(Loc, Ctx, ElemSizeParam, NumElemsParam, 0); | |||
780 | A->setImplicit(true); | |||
781 | return A; | |||
782 | } | |||
783 | ||||
784 | AllocSizeAttr(SourceRange R, ASTContext &Ctx | |||
785 | , ParamIdx ElemSizeParam | |||
786 | , ParamIdx NumElemsParam | |||
787 | , unsigned SI | |||
788 | ) | |||
789 | : InheritableAttr(attr::AllocSize, R, SI, false, false) | |||
790 | , elemSizeParam(ElemSizeParam) | |||
791 | , numElemsParam(NumElemsParam) | |||
792 | { | |||
793 | } | |||
794 | ||||
795 | AllocSizeAttr(SourceRange R, ASTContext &Ctx | |||
796 | , ParamIdx ElemSizeParam | |||
797 | , unsigned SI | |||
798 | ) | |||
799 | : InheritableAttr(attr::AllocSize, R, SI, false, false) | |||
800 | , elemSizeParam(ElemSizeParam) | |||
801 | , numElemsParam() | |||
802 | { | |||
803 | } | |||
804 | ||||
805 | AllocSizeAttr *clone(ASTContext &C) const; | |||
806 | void printPretty(raw_ostream &OS, | |||
807 | const PrintingPolicy &Policy) const; | |||
808 | const char *getSpelling() const; | |||
809 | ParamIdx getElemSizeParam() const { | |||
810 | return elemSizeParam; | |||
811 | } | |||
812 | ||||
813 | ParamIdx getNumElemsParam() const { | |||
814 | return numElemsParam; | |||
815 | } | |||
816 | ||||
817 | ||||
818 | ||||
819 | static bool classof(const Attr *A) { return A->getKind() == attr::AllocSize; } | |||
820 | }; | |||
821 | ||||
822 | class AlwaysDestroyAttr : public InheritableAttr { | |||
823 | public: | |||
824 | static AlwaysDestroyAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
825 | auto *A = new (Ctx) AlwaysDestroyAttr(Loc, Ctx, 0); | |||
826 | A->setImplicit(true); | |||
827 | return A; | |||
828 | } | |||
829 | ||||
830 | AlwaysDestroyAttr(SourceRange R, ASTContext &Ctx | |||
831 | , unsigned SI | |||
832 | ) | |||
833 | : InheritableAttr(attr::AlwaysDestroy, R, SI, false, false) | |||
834 | { | |||
835 | } | |||
836 | ||||
837 | AlwaysDestroyAttr *clone(ASTContext &C) const; | |||
838 | void printPretty(raw_ostream &OS, | |||
839 | const PrintingPolicy &Policy) const; | |||
840 | const char *getSpelling() const; | |||
841 | ||||
842 | ||||
843 | static bool classof(const Attr *A) { return A->getKind() == attr::AlwaysDestroy; } | |||
844 | }; | |||
845 | ||||
846 | class AlwaysInlineAttr : public InheritableAttr { | |||
847 | public: | |||
848 | enum Spelling { | |||
849 | GNU_always_inline = 0, | |||
850 | CXX11_gnu_always_inline = 1, | |||
851 | Keyword_forceinline = 2 | |||
852 | }; | |||
853 | ||||
854 | static AlwaysInlineAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
855 | auto *A = new (Ctx) AlwaysInlineAttr(Loc, Ctx, S); | |||
856 | A->setImplicit(true); | |||
857 | return A; | |||
858 | } | |||
859 | ||||
860 | AlwaysInlineAttr(SourceRange R, ASTContext &Ctx | |||
861 | , unsigned SI | |||
862 | ) | |||
863 | : InheritableAttr(attr::AlwaysInline, R, SI, false, false) | |||
864 | { | |||
865 | } | |||
866 | ||||
867 | AlwaysInlineAttr *clone(ASTContext &C) const; | |||
868 | void printPretty(raw_ostream &OS, | |||
869 | const PrintingPolicy &Policy) const; | |||
870 | const char *getSpelling() const; | |||
871 | Spelling getSemanticSpelling() const { | |||
872 | switch (SpellingListIndex) { | |||
873 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 873); | |||
874 | case 0: return GNU_always_inline; | |||
875 | case 1: return CXX11_gnu_always_inline; | |||
876 | case 2: return Keyword_forceinline; | |||
877 | } | |||
878 | } | |||
879 | ||||
880 | ||||
881 | static bool classof(const Attr *A) { return A->getKind() == attr::AlwaysInline; } | |||
882 | }; | |||
883 | ||||
884 | class AnalyzerNoReturnAttr : public InheritableAttr { | |||
885 | public: | |||
886 | static AnalyzerNoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
887 | auto *A = new (Ctx) AnalyzerNoReturnAttr(Loc, Ctx, 0); | |||
888 | A->setImplicit(true); | |||
889 | return A; | |||
890 | } | |||
891 | ||||
892 | AnalyzerNoReturnAttr(SourceRange R, ASTContext &Ctx | |||
893 | , unsigned SI | |||
894 | ) | |||
895 | : InheritableAttr(attr::AnalyzerNoReturn, R, SI, false, false) | |||
896 | { | |||
897 | } | |||
898 | ||||
899 | AnalyzerNoReturnAttr *clone(ASTContext &C) const; | |||
900 | void printPretty(raw_ostream &OS, | |||
901 | const PrintingPolicy &Policy) const; | |||
902 | const char *getSpelling() const; | |||
903 | ||||
904 | ||||
905 | static bool classof(const Attr *A) { return A->getKind() == attr::AnalyzerNoReturn; } | |||
906 | }; | |||
907 | ||||
908 | class AnnotateAttr : public InheritableParamAttr { | |||
909 | unsigned annotationLength; | |||
910 | char *annotation; | |||
911 | ||||
912 | public: | |||
913 | static AnnotateAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Annotation, SourceRange Loc = SourceRange()) { | |||
914 | auto *A = new (Ctx) AnnotateAttr(Loc, Ctx, Annotation, 0); | |||
915 | A->setImplicit(true); | |||
916 | return A; | |||
917 | } | |||
918 | ||||
919 | AnnotateAttr(SourceRange R, ASTContext &Ctx | |||
920 | , llvm::StringRef Annotation | |||
921 | , unsigned SI | |||
922 | ) | |||
923 | : InheritableParamAttr(attr::Annotate, R, SI, false, false) | |||
924 | , annotationLength(Annotation.size()),annotation(new (Ctx, 1) char[annotationLength]) | |||
925 | { | |||
926 | if (!Annotation.empty()) | |||
927 | std::memcpy(annotation, Annotation.data(), annotationLength); | |||
928 | } | |||
929 | ||||
930 | AnnotateAttr *clone(ASTContext &C) const; | |||
931 | void printPretty(raw_ostream &OS, | |||
932 | const PrintingPolicy &Policy) const; | |||
933 | const char *getSpelling() const; | |||
934 | llvm::StringRef getAnnotation() const { | |||
935 | return llvm::StringRef(annotation, annotationLength); | |||
936 | } | |||
937 | unsigned getAnnotationLength() const { | |||
938 | return annotationLength; | |||
939 | } | |||
940 | void setAnnotation(ASTContext &C, llvm::StringRef S) { | |||
941 | annotationLength = S.size(); | |||
942 | this->annotation = new (C, 1) char [annotationLength]; | |||
943 | if (!S.empty()) | |||
944 | std::memcpy(this->annotation, S.data(), annotationLength); | |||
945 | } | |||
946 | ||||
947 | ||||
948 | ||||
949 | static bool classof(const Attr *A) { return A->getKind() == attr::Annotate; } | |||
950 | }; | |||
951 | ||||
952 | class AnyX86InterruptAttr : public InheritableAttr { | |||
953 | public: | |||
954 | static AnyX86InterruptAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
955 | auto *A = new (Ctx) AnyX86InterruptAttr(Loc, Ctx, 0); | |||
956 | A->setImplicit(true); | |||
957 | return A; | |||
958 | } | |||
959 | ||||
960 | AnyX86InterruptAttr(SourceRange R, ASTContext &Ctx | |||
961 | , unsigned SI | |||
962 | ) | |||
963 | : InheritableAttr(attr::AnyX86Interrupt, R, SI, false, false) | |||
964 | { | |||
965 | } | |||
966 | ||||
967 | AnyX86InterruptAttr *clone(ASTContext &C) const; | |||
968 | void printPretty(raw_ostream &OS, | |||
969 | const PrintingPolicy &Policy) const; | |||
970 | const char *getSpelling() const; | |||
971 | ||||
972 | ||||
973 | static bool classof(const Attr *A) { return A->getKind() == attr::AnyX86Interrupt; } | |||
974 | }; | |||
975 | ||||
976 | class AnyX86NoCallerSavedRegistersAttr : public InheritableAttr { | |||
977 | public: | |||
978 | static AnyX86NoCallerSavedRegistersAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
979 | auto *A = new (Ctx) AnyX86NoCallerSavedRegistersAttr(Loc, Ctx, 0); | |||
980 | A->setImplicit(true); | |||
981 | return A; | |||
982 | } | |||
983 | ||||
984 | AnyX86NoCallerSavedRegistersAttr(SourceRange R, ASTContext &Ctx | |||
985 | , unsigned SI | |||
986 | ) | |||
987 | : InheritableAttr(attr::AnyX86NoCallerSavedRegisters, R, SI, false, false) | |||
988 | { | |||
989 | } | |||
990 | ||||
991 | AnyX86NoCallerSavedRegistersAttr *clone(ASTContext &C) const; | |||
992 | void printPretty(raw_ostream &OS, | |||
993 | const PrintingPolicy &Policy) const; | |||
994 | const char *getSpelling() const; | |||
995 | ||||
996 | ||||
997 | static bool classof(const Attr *A) { return A->getKind() == attr::AnyX86NoCallerSavedRegisters; } | |||
998 | }; | |||
999 | ||||
1000 | class AnyX86NoCfCheckAttr : public InheritableAttr { | |||
1001 | public: | |||
1002 | static AnyX86NoCfCheckAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1003 | auto *A = new (Ctx) AnyX86NoCfCheckAttr(Loc, Ctx, 0); | |||
1004 | A->setImplicit(true); | |||
1005 | return A; | |||
1006 | } | |||
1007 | ||||
1008 | AnyX86NoCfCheckAttr(SourceRange R, ASTContext &Ctx | |||
1009 | , unsigned SI | |||
1010 | ) | |||
1011 | : InheritableAttr(attr::AnyX86NoCfCheck, R, SI, false, false) | |||
1012 | { | |||
1013 | } | |||
1014 | ||||
1015 | AnyX86NoCfCheckAttr *clone(ASTContext &C) const; | |||
1016 | void printPretty(raw_ostream &OS, | |||
1017 | const PrintingPolicy &Policy) const; | |||
1018 | const char *getSpelling() const; | |||
1019 | ||||
1020 | ||||
1021 | static bool classof(const Attr *A) { return A->getKind() == attr::AnyX86NoCfCheck; } | |||
1022 | }; | |||
1023 | ||||
1024 | class ArcWeakrefUnavailableAttr : public InheritableAttr { | |||
1025 | public: | |||
1026 | static ArcWeakrefUnavailableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1027 | auto *A = new (Ctx) ArcWeakrefUnavailableAttr(Loc, Ctx, 0); | |||
1028 | A->setImplicit(true); | |||
1029 | return A; | |||
1030 | } | |||
1031 | ||||
1032 | ArcWeakrefUnavailableAttr(SourceRange R, ASTContext &Ctx | |||
1033 | , unsigned SI | |||
1034 | ) | |||
1035 | : InheritableAttr(attr::ArcWeakrefUnavailable, R, SI, false, false) | |||
1036 | { | |||
1037 | } | |||
1038 | ||||
1039 | ArcWeakrefUnavailableAttr *clone(ASTContext &C) const; | |||
1040 | void printPretty(raw_ostream &OS, | |||
1041 | const PrintingPolicy &Policy) const; | |||
1042 | const char *getSpelling() const; | |||
1043 | ||||
1044 | ||||
1045 | static bool classof(const Attr *A) { return A->getKind() == attr::ArcWeakrefUnavailable; } | |||
1046 | }; | |||
1047 | ||||
1048 | class ArgumentWithTypeTagAttr : public InheritableAttr { | |||
1049 | IdentifierInfo * argumentKind; | |||
1050 | ||||
1051 | ParamIdx argumentIdx; | |||
1052 | ||||
1053 | ParamIdx typeTagIdx; | |||
1054 | ||||
1055 | bool isPointer; | |||
1056 | ||||
1057 | public: | |||
1058 | enum Spelling { | |||
1059 | GNU_argument_with_type_tag = 0, | |||
1060 | CXX11_clang_argument_with_type_tag = 1, | |||
1061 | C2x_clang_argument_with_type_tag = 2, | |||
1062 | GNU_pointer_with_type_tag = 3, | |||
1063 | CXX11_clang_pointer_with_type_tag = 4, | |||
1064 | C2x_clang_pointer_with_type_tag = 5 | |||
1065 | }; | |||
1066 | ||||
1067 | static ArgumentWithTypeTagAttr *CreateImplicit(ASTContext &Ctx, Spelling S, IdentifierInfo * ArgumentKind, ParamIdx ArgumentIdx, ParamIdx TypeTagIdx, bool IsPointer, SourceRange Loc = SourceRange()) { | |||
1068 | auto *A = new (Ctx) ArgumentWithTypeTagAttr(Loc, Ctx, ArgumentKind, ArgumentIdx, TypeTagIdx, IsPointer, S); | |||
1069 | A->setImplicit(true); | |||
1070 | return A; | |||
1071 | } | |||
1072 | ||||
1073 | static ArgumentWithTypeTagAttr *CreateImplicit(ASTContext &Ctx, Spelling S, IdentifierInfo * ArgumentKind, ParamIdx ArgumentIdx, ParamIdx TypeTagIdx, SourceRange Loc = SourceRange()) { | |||
1074 | auto *A = new (Ctx) ArgumentWithTypeTagAttr(Loc, Ctx, ArgumentKind, ArgumentIdx, TypeTagIdx, S); | |||
1075 | A->setImplicit(true); | |||
1076 | return A; | |||
1077 | } | |||
1078 | ||||
1079 | ArgumentWithTypeTagAttr(SourceRange R, ASTContext &Ctx | |||
1080 | , IdentifierInfo * ArgumentKind | |||
1081 | , ParamIdx ArgumentIdx | |||
1082 | , ParamIdx TypeTagIdx | |||
1083 | , bool IsPointer | |||
1084 | , unsigned SI | |||
1085 | ) | |||
1086 | : InheritableAttr(attr::ArgumentWithTypeTag, R, SI, false, false) | |||
1087 | , argumentKind(ArgumentKind) | |||
1088 | , argumentIdx(ArgumentIdx) | |||
1089 | , typeTagIdx(TypeTagIdx) | |||
1090 | , isPointer(IsPointer) | |||
1091 | { | |||
1092 | } | |||
1093 | ||||
1094 | ArgumentWithTypeTagAttr(SourceRange R, ASTContext &Ctx | |||
1095 | , IdentifierInfo * ArgumentKind | |||
1096 | , ParamIdx ArgumentIdx | |||
1097 | , ParamIdx TypeTagIdx | |||
1098 | , unsigned SI | |||
1099 | ) | |||
1100 | : InheritableAttr(attr::ArgumentWithTypeTag, R, SI, false, false) | |||
1101 | , argumentKind(ArgumentKind) | |||
1102 | , argumentIdx(ArgumentIdx) | |||
1103 | , typeTagIdx(TypeTagIdx) | |||
1104 | , isPointer() | |||
1105 | { | |||
1106 | } | |||
1107 | ||||
1108 | ArgumentWithTypeTagAttr *clone(ASTContext &C) const; | |||
1109 | void printPretty(raw_ostream &OS, | |||
1110 | const PrintingPolicy &Policy) const; | |||
1111 | const char *getSpelling() const; | |||
1112 | Spelling getSemanticSpelling() const { | |||
1113 | switch (SpellingListIndex) { | |||
1114 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 1114); | |||
1115 | case 0: return GNU_argument_with_type_tag; | |||
1116 | case 1: return CXX11_clang_argument_with_type_tag; | |||
1117 | case 2: return C2x_clang_argument_with_type_tag; | |||
1118 | case 3: return GNU_pointer_with_type_tag; | |||
1119 | case 4: return CXX11_clang_pointer_with_type_tag; | |||
1120 | case 5: return C2x_clang_pointer_with_type_tag; | |||
1121 | } | |||
1122 | } | |||
1123 | IdentifierInfo * getArgumentKind() const { | |||
1124 | return argumentKind; | |||
1125 | } | |||
1126 | ||||
1127 | ParamIdx getArgumentIdx() const { | |||
1128 | return argumentIdx; | |||
1129 | } | |||
1130 | ||||
1131 | ParamIdx getTypeTagIdx() const { | |||
1132 | return typeTagIdx; | |||
1133 | } | |||
1134 | ||||
1135 | bool getIsPointer() const { | |||
1136 | return isPointer; | |||
1137 | } | |||
1138 | ||||
1139 | ||||
1140 | ||||
1141 | static bool classof(const Attr *A) { return A->getKind() == attr::ArgumentWithTypeTag; } | |||
1142 | }; | |||
1143 | ||||
1144 | class ArtificialAttr : public InheritableAttr { | |||
1145 | public: | |||
1146 | static ArtificialAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1147 | auto *A = new (Ctx) ArtificialAttr(Loc, Ctx, 0); | |||
1148 | A->setImplicit(true); | |||
1149 | return A; | |||
1150 | } | |||
1151 | ||||
1152 | ArtificialAttr(SourceRange R, ASTContext &Ctx | |||
1153 | , unsigned SI | |||
1154 | ) | |||
1155 | : InheritableAttr(attr::Artificial, R, SI, false, false) | |||
1156 | { | |||
1157 | } | |||
1158 | ||||
1159 | ArtificialAttr *clone(ASTContext &C) const; | |||
1160 | void printPretty(raw_ostream &OS, | |||
1161 | const PrintingPolicy &Policy) const; | |||
1162 | const char *getSpelling() const; | |||
1163 | ||||
1164 | ||||
1165 | static bool classof(const Attr *A) { return A->getKind() == attr::Artificial; } | |||
1166 | }; | |||
1167 | ||||
1168 | class AsmLabelAttr : public InheritableAttr { | |||
1169 | unsigned labelLength; | |||
1170 | char *label; | |||
1171 | ||||
1172 | public: | |||
1173 | static AsmLabelAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Label, SourceRange Loc = SourceRange()) { | |||
1174 | auto *A = new (Ctx) AsmLabelAttr(Loc, Ctx, Label, 0); | |||
1175 | A->setImplicit(true); | |||
1176 | return A; | |||
1177 | } | |||
1178 | ||||
1179 | AsmLabelAttr(SourceRange R, ASTContext &Ctx | |||
1180 | , llvm::StringRef Label | |||
1181 | , unsigned SI | |||
1182 | ) | |||
1183 | : InheritableAttr(attr::AsmLabel, R, SI, false, false) | |||
1184 | , labelLength(Label.size()),label(new (Ctx, 1) char[labelLength]) | |||
1185 | { | |||
1186 | if (!Label.empty()) | |||
1187 | std::memcpy(label, Label.data(), labelLength); | |||
1188 | } | |||
1189 | ||||
1190 | AsmLabelAttr *clone(ASTContext &C) const; | |||
1191 | void printPretty(raw_ostream &OS, | |||
1192 | const PrintingPolicy &Policy) const; | |||
1193 | const char *getSpelling() const; | |||
1194 | llvm::StringRef getLabel() const { | |||
1195 | return llvm::StringRef(label, labelLength); | |||
1196 | } | |||
1197 | unsigned getLabelLength() const { | |||
1198 | return labelLength; | |||
1199 | } | |||
1200 | void setLabel(ASTContext &C, llvm::StringRef S) { | |||
1201 | labelLength = S.size(); | |||
1202 | this->label = new (C, 1) char [labelLength]; | |||
1203 | if (!S.empty()) | |||
1204 | std::memcpy(this->label, S.data(), labelLength); | |||
1205 | } | |||
1206 | ||||
1207 | ||||
1208 | ||||
1209 | static bool classof(const Attr *A) { return A->getKind() == attr::AsmLabel; } | |||
1210 | }; | |||
1211 | ||||
1212 | class AssertCapabilityAttr : public InheritableAttr { | |||
1213 | unsigned args_Size; | |||
1214 | Expr * *args_; | |||
1215 | ||||
1216 | public: | |||
1217 | enum Spelling { | |||
1218 | GNU_assert_capability = 0, | |||
1219 | CXX11_clang_assert_capability = 1, | |||
1220 | GNU_assert_shared_capability = 2, | |||
1221 | CXX11_clang_assert_shared_capability = 3 | |||
1222 | }; | |||
1223 | ||||
1224 | static AssertCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
1225 | auto *A = new (Ctx) AssertCapabilityAttr(Loc, Ctx, Args, ArgsSize, S); | |||
1226 | A->setImplicit(true); | |||
1227 | return A; | |||
1228 | } | |||
1229 | ||||
1230 | AssertCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
1231 | , Expr * *Args, unsigned ArgsSize | |||
1232 | , unsigned SI | |||
1233 | ) | |||
1234 | : InheritableAttr(attr::AssertCapability, R, SI, true, true) | |||
1235 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
1236 | { | |||
1237 | std::copy(Args, Args + args_Size, args_); | |||
1238 | } | |||
1239 | ||||
1240 | AssertCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
1241 | , unsigned SI | |||
1242 | ) | |||
1243 | : InheritableAttr(attr::AssertCapability, R, SI, true, true) | |||
1244 | , args_Size(0), args_(nullptr) | |||
1245 | { | |||
1246 | } | |||
1247 | ||||
1248 | AssertCapabilityAttr *clone(ASTContext &C) const; | |||
1249 | void printPretty(raw_ostream &OS, | |||
1250 | const PrintingPolicy &Policy) const; | |||
1251 | const char *getSpelling() const; | |||
1252 | Spelling getSemanticSpelling() const { | |||
1253 | switch (SpellingListIndex) { | |||
1254 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 1254); | |||
1255 | case 0: return GNU_assert_capability; | |||
1256 | case 1: return CXX11_clang_assert_capability; | |||
1257 | case 2: return GNU_assert_shared_capability; | |||
1258 | case 3: return CXX11_clang_assert_shared_capability; | |||
1259 | } | |||
1260 | } | |||
1261 | bool isShared() const { return SpellingListIndex == 2 || | |||
1262 | SpellingListIndex == 3; } | |||
1263 | typedef Expr ** args_iterator; | |||
1264 | args_iterator args_begin() const { return args_; } | |||
1265 | args_iterator args_end() const { return args_ + args_Size; } | |||
1266 | unsigned args_size() const { return args_Size; } | |||
1267 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
1268 | ||||
1269 | ||||
1270 | ||||
1271 | ||||
1272 | static bool classof(const Attr *A) { return A->getKind() == attr::AssertCapability; } | |||
1273 | }; | |||
1274 | ||||
1275 | class AssertExclusiveLockAttr : public InheritableAttr { | |||
1276 | unsigned args_Size; | |||
1277 | Expr * *args_; | |||
1278 | ||||
1279 | public: | |||
1280 | static AssertExclusiveLockAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
1281 | auto *A = new (Ctx) AssertExclusiveLockAttr(Loc, Ctx, Args, ArgsSize, 0); | |||
1282 | A->setImplicit(true); | |||
1283 | return A; | |||
1284 | } | |||
1285 | ||||
1286 | AssertExclusiveLockAttr(SourceRange R, ASTContext &Ctx | |||
1287 | , Expr * *Args, unsigned ArgsSize | |||
1288 | , unsigned SI | |||
1289 | ) | |||
1290 | : InheritableAttr(attr::AssertExclusiveLock, R, SI, true, true) | |||
1291 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
1292 | { | |||
1293 | std::copy(Args, Args + args_Size, args_); | |||
1294 | } | |||
1295 | ||||
1296 | AssertExclusiveLockAttr(SourceRange R, ASTContext &Ctx | |||
1297 | , unsigned SI | |||
1298 | ) | |||
1299 | : InheritableAttr(attr::AssertExclusiveLock, R, SI, true, true) | |||
1300 | , args_Size(0), args_(nullptr) | |||
1301 | { | |||
1302 | } | |||
1303 | ||||
1304 | AssertExclusiveLockAttr *clone(ASTContext &C) const; | |||
1305 | void printPretty(raw_ostream &OS, | |||
1306 | const PrintingPolicy &Policy) const; | |||
1307 | const char *getSpelling() const; | |||
1308 | typedef Expr ** args_iterator; | |||
1309 | args_iterator args_begin() const { return args_; } | |||
1310 | args_iterator args_end() const { return args_ + args_Size; } | |||
1311 | unsigned args_size() const { return args_Size; } | |||
1312 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
1313 | ||||
1314 | ||||
1315 | ||||
1316 | ||||
1317 | static bool classof(const Attr *A) { return A->getKind() == attr::AssertExclusiveLock; } | |||
1318 | }; | |||
1319 | ||||
1320 | class AssertSharedLockAttr : public InheritableAttr { | |||
1321 | unsigned args_Size; | |||
1322 | Expr * *args_; | |||
1323 | ||||
1324 | public: | |||
1325 | static AssertSharedLockAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
1326 | auto *A = new (Ctx) AssertSharedLockAttr(Loc, Ctx, Args, ArgsSize, 0); | |||
1327 | A->setImplicit(true); | |||
1328 | return A; | |||
1329 | } | |||
1330 | ||||
1331 | AssertSharedLockAttr(SourceRange R, ASTContext &Ctx | |||
1332 | , Expr * *Args, unsigned ArgsSize | |||
1333 | , unsigned SI | |||
1334 | ) | |||
1335 | : InheritableAttr(attr::AssertSharedLock, R, SI, true, true) | |||
1336 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
1337 | { | |||
1338 | std::copy(Args, Args + args_Size, args_); | |||
1339 | } | |||
1340 | ||||
1341 | AssertSharedLockAttr(SourceRange R, ASTContext &Ctx | |||
1342 | , unsigned SI | |||
1343 | ) | |||
1344 | : InheritableAttr(attr::AssertSharedLock, R, SI, true, true) | |||
1345 | , args_Size(0), args_(nullptr) | |||
1346 | { | |||
1347 | } | |||
1348 | ||||
1349 | AssertSharedLockAttr *clone(ASTContext &C) const; | |||
1350 | void printPretty(raw_ostream &OS, | |||
1351 | const PrintingPolicy &Policy) const; | |||
1352 | const char *getSpelling() const; | |||
1353 | typedef Expr ** args_iterator; | |||
1354 | args_iterator args_begin() const { return args_; } | |||
1355 | args_iterator args_end() const { return args_ + args_Size; } | |||
1356 | unsigned args_size() const { return args_Size; } | |||
1357 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
1358 | ||||
1359 | ||||
1360 | ||||
1361 | ||||
1362 | static bool classof(const Attr *A) { return A->getKind() == attr::AssertSharedLock; } | |||
1363 | }; | |||
1364 | ||||
1365 | class AssumeAlignedAttr : public InheritableAttr { | |||
1366 | Expr * alignment; | |||
1367 | ||||
1368 | Expr * offset; | |||
1369 | ||||
1370 | public: | |||
1371 | static AssumeAlignedAttr *CreateImplicit(ASTContext &Ctx, Expr * Alignment, Expr * Offset, SourceRange Loc = SourceRange()) { | |||
1372 | auto *A = new (Ctx) AssumeAlignedAttr(Loc, Ctx, Alignment, Offset, 0); | |||
1373 | A->setImplicit(true); | |||
1374 | return A; | |||
1375 | } | |||
1376 | ||||
1377 | AssumeAlignedAttr(SourceRange R, ASTContext &Ctx | |||
1378 | , Expr * Alignment | |||
1379 | , Expr * Offset | |||
1380 | , unsigned SI | |||
1381 | ) | |||
1382 | : InheritableAttr(attr::AssumeAligned, R, SI, false, false) | |||
1383 | , alignment(Alignment) | |||
1384 | , offset(Offset) | |||
1385 | { | |||
1386 | } | |||
1387 | ||||
1388 | AssumeAlignedAttr(SourceRange R, ASTContext &Ctx | |||
1389 | , Expr * Alignment | |||
1390 | , unsigned SI | |||
1391 | ) | |||
1392 | : InheritableAttr(attr::AssumeAligned, R, SI, false, false) | |||
1393 | , alignment(Alignment) | |||
1394 | , offset() | |||
1395 | { | |||
1396 | } | |||
1397 | ||||
1398 | AssumeAlignedAttr *clone(ASTContext &C) const; | |||
1399 | void printPretty(raw_ostream &OS, | |||
1400 | const PrintingPolicy &Policy) const; | |||
1401 | const char *getSpelling() const; | |||
1402 | Expr * getAlignment() const { | |||
1403 | return alignment; | |||
1404 | } | |||
1405 | ||||
1406 | Expr * getOffset() const { | |||
1407 | return offset; | |||
1408 | } | |||
1409 | ||||
1410 | ||||
1411 | ||||
1412 | static bool classof(const Attr *A) { return A->getKind() == attr::AssumeAligned; } | |||
1413 | }; | |||
1414 | ||||
1415 | class AvailabilityAttr : public InheritableAttr { | |||
1416 | IdentifierInfo * platform; | |||
1417 | ||||
1418 | VersionTuple introduced; | |||
1419 | ||||
1420 | ||||
1421 | VersionTuple deprecated; | |||
1422 | ||||
1423 | ||||
1424 | VersionTuple obsoleted; | |||
1425 | ||||
1426 | ||||
1427 | bool unavailable; | |||
1428 | ||||
1429 | unsigned messageLength; | |||
1430 | char *message; | |||
1431 | ||||
1432 | bool strict; | |||
1433 | ||||
1434 | unsigned replacementLength; | |||
1435 | char *replacement; | |||
1436 | ||||
1437 | int priority; | |||
1438 | ||||
1439 | public: | |||
1440 | static AvailabilityAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Platform, VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted, bool Unavailable, llvm::StringRef Message, bool Strict, llvm::StringRef Replacement, int Priority, SourceRange Loc = SourceRange()) { | |||
1441 | auto *A = new (Ctx) AvailabilityAttr(Loc, Ctx, Platform, Introduced, Deprecated, Obsoleted, Unavailable, Message, Strict, Replacement, Priority, 0); | |||
1442 | A->setImplicit(true); | |||
1443 | return A; | |||
1444 | } | |||
1445 | ||||
1446 | AvailabilityAttr(SourceRange R, ASTContext &Ctx | |||
1447 | , IdentifierInfo * Platform | |||
1448 | , VersionTuple Introduced | |||
1449 | , VersionTuple Deprecated | |||
1450 | , VersionTuple Obsoleted | |||
1451 | , bool Unavailable | |||
1452 | , llvm::StringRef Message | |||
1453 | , bool Strict | |||
1454 | , llvm::StringRef Replacement | |||
1455 | , int Priority | |||
1456 | , unsigned SI | |||
1457 | ) | |||
1458 | : InheritableAttr(attr::Availability, R, SI, false, true) | |||
1459 | , platform(Platform) | |||
1460 | , introduced(Introduced) | |||
1461 | , deprecated(Deprecated) | |||
1462 | , obsoleted(Obsoleted) | |||
1463 | , unavailable(Unavailable) | |||
1464 | , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength]) | |||
1465 | , strict(Strict) | |||
1466 | , replacementLength(Replacement.size()),replacement(new (Ctx, 1) char[replacementLength]) | |||
1467 | , priority(Priority) | |||
1468 | { | |||
1469 | if (!Message.empty()) | |||
1470 | std::memcpy(message, Message.data(), messageLength); | |||
1471 | if (!Replacement.empty()) | |||
1472 | std::memcpy(replacement, Replacement.data(), replacementLength); | |||
1473 | } | |||
1474 | ||||
1475 | AvailabilityAttr *clone(ASTContext &C) const; | |||
1476 | void printPretty(raw_ostream &OS, | |||
1477 | const PrintingPolicy &Policy) const; | |||
1478 | const char *getSpelling() const; | |||
1479 | IdentifierInfo * getPlatform() const { | |||
1480 | return platform; | |||
1481 | } | |||
1482 | ||||
1483 | VersionTuple getIntroduced() const { | |||
1484 | return introduced; | |||
1485 | } | |||
1486 | void setIntroduced(ASTContext &C, VersionTuple V) { | |||
1487 | introduced = V; | |||
1488 | } | |||
1489 | ||||
1490 | VersionTuple getDeprecated() const { | |||
1491 | return deprecated; | |||
1492 | } | |||
1493 | void setDeprecated(ASTContext &C, VersionTuple V) { | |||
1494 | deprecated = V; | |||
1495 | } | |||
1496 | ||||
1497 | VersionTuple getObsoleted() const { | |||
1498 | return obsoleted; | |||
1499 | } | |||
1500 | void setObsoleted(ASTContext &C, VersionTuple V) { | |||
1501 | obsoleted = V; | |||
1502 | } | |||
1503 | ||||
1504 | bool getUnavailable() const { | |||
1505 | return unavailable; | |||
1506 | } | |||
1507 | ||||
1508 | llvm::StringRef getMessage() const { | |||
1509 | return llvm::StringRef(message, messageLength); | |||
1510 | } | |||
1511 | unsigned getMessageLength() const { | |||
1512 | return messageLength; | |||
1513 | } | |||
1514 | void setMessage(ASTContext &C, llvm::StringRef S) { | |||
1515 | messageLength = S.size(); | |||
1516 | this->message = new (C, 1) char [messageLength]; | |||
1517 | if (!S.empty()) | |||
1518 | std::memcpy(this->message, S.data(), messageLength); | |||
1519 | } | |||
1520 | ||||
1521 | bool getStrict() const { | |||
1522 | return strict; | |||
1523 | } | |||
1524 | ||||
1525 | llvm::StringRef getReplacement() const { | |||
1526 | return llvm::StringRef(replacement, replacementLength); | |||
1527 | } | |||
1528 | unsigned getReplacementLength() const { | |||
1529 | return replacementLength; | |||
1530 | } | |||
1531 | void setReplacement(ASTContext &C, llvm::StringRef S) { | |||
1532 | replacementLength = S.size(); | |||
1533 | this->replacement = new (C, 1) char [replacementLength]; | |||
1534 | if (!S.empty()) | |||
1535 | std::memcpy(this->replacement, S.data(), replacementLength); | |||
1536 | } | |||
1537 | ||||
1538 | int getPriority() const { | |||
1539 | return priority; | |||
1540 | } | |||
1541 | ||||
1542 | static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) { | |||
1543 | return llvm::StringSwitch<llvm::StringRef>(Platform) | |||
1544 | .Case("android", "Android") | |||
1545 | .Case("ios", "iOS") | |||
1546 | .Case("macos", "macOS") | |||
1547 | .Case("tvos", "tvOS") | |||
1548 | .Case("watchos", "watchOS") | |||
1549 | .Case("ios_app_extension", "iOS (App Extension)") | |||
1550 | .Case("macos_app_extension", "macOS (App Extension)") | |||
1551 | .Case("tvos_app_extension", "tvOS (App Extension)") | |||
1552 | .Case("watchos_app_extension", "watchOS (App Extension)") | |||
1553 | .Case("swift", "Swift") | |||
1554 | .Default(llvm::StringRef()); | |||
1555 | } | |||
1556 | static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) { | |||
1557 | return llvm::StringSwitch<llvm::StringRef>(Platform) | |||
1558 | .Case("ios", "iOS") | |||
1559 | .Case("macos", "macOS") | |||
1560 | .Case("tvos", "tvOS") | |||
1561 | .Case("watchos", "watchOS") | |||
1562 | .Case("ios_app_extension", "iOSApplicationExtension") | |||
1563 | .Case("macos_app_extension", "macOSApplicationExtension") | |||
1564 | .Case("tvos_app_extension", "tvOSApplicationExtension") | |||
1565 | .Case("watchos_app_extension", "watchOSApplicationExtension") | |||
1566 | .Default(Platform); | |||
1567 | } | |||
1568 | static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) { | |||
1569 | return llvm::StringSwitch<llvm::StringRef>(Platform) | |||
1570 | .Case("iOS", "ios") | |||
1571 | .Case("macOS", "macos") | |||
1572 | .Case("tvOS", "tvos") | |||
1573 | .Case("watchOS", "watchos") | |||
1574 | .Case("iOSApplicationExtension", "ios_app_extension") | |||
1575 | .Case("macOSApplicationExtension", "macos_app_extension") | |||
1576 | .Case("tvOSApplicationExtension", "tvos_app_extension") | |||
1577 | .Case("watchOSApplicationExtension", "watchos_app_extension") | |||
1578 | .Default(Platform); | |||
1579 | } | |||
1580 | ||||
1581 | static bool classof(const Attr *A) { return A->getKind() == attr::Availability; } | |||
1582 | }; | |||
1583 | ||||
1584 | class BlocksAttr : public InheritableAttr { | |||
1585 | public: | |||
1586 | enum BlockType { | |||
1587 | ByRef | |||
1588 | }; | |||
1589 | private: | |||
1590 | BlockType type; | |||
1591 | ||||
1592 | public: | |||
1593 | static BlocksAttr *CreateImplicit(ASTContext &Ctx, BlockType Type, SourceRange Loc = SourceRange()) { | |||
1594 | auto *A = new (Ctx) BlocksAttr(Loc, Ctx, Type, 0); | |||
1595 | A->setImplicit(true); | |||
1596 | return A; | |||
1597 | } | |||
1598 | ||||
1599 | BlocksAttr(SourceRange R, ASTContext &Ctx | |||
1600 | , BlockType Type | |||
1601 | , unsigned SI | |||
1602 | ) | |||
1603 | : InheritableAttr(attr::Blocks, R, SI, false, false) | |||
1604 | , type(Type) | |||
1605 | { | |||
1606 | } | |||
1607 | ||||
1608 | BlocksAttr *clone(ASTContext &C) const; | |||
1609 | void printPretty(raw_ostream &OS, | |||
1610 | const PrintingPolicy &Policy) const; | |||
1611 | const char *getSpelling() const; | |||
1612 | BlockType getType() const { | |||
1613 | return type; | |||
1614 | } | |||
1615 | ||||
1616 | static bool ConvertStrToBlockType(StringRef Val, BlockType &Out) { | |||
1617 | Optional<BlockType> R = llvm::StringSwitch<Optional<BlockType>>(Val) | |||
1618 | .Case("byref", BlocksAttr::ByRef) | |||
1619 | .Default(Optional<BlockType>()); | |||
1620 | if (R) { | |||
1621 | Out = *R; | |||
1622 | return true; | |||
1623 | } | |||
1624 | return false; | |||
1625 | } | |||
1626 | ||||
1627 | static const char *ConvertBlockTypeToStr(BlockType Val) { | |||
1628 | switch(Val) { | |||
1629 | case BlocksAttr::ByRef: return "byref"; | |||
1630 | } | |||
1631 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 1631); | |||
1632 | } | |||
1633 | ||||
1634 | ||||
1635 | static bool classof(const Attr *A) { return A->getKind() == attr::Blocks; } | |||
1636 | }; | |||
1637 | ||||
1638 | class C11NoReturnAttr : public InheritableAttr { | |||
1639 | public: | |||
1640 | static C11NoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1641 | auto *A = new (Ctx) C11NoReturnAttr(Loc, Ctx, 0); | |||
1642 | A->setImplicit(true); | |||
1643 | return A; | |||
1644 | } | |||
1645 | ||||
1646 | C11NoReturnAttr(SourceRange R, ASTContext &Ctx | |||
1647 | , unsigned SI | |||
1648 | ) | |||
1649 | : InheritableAttr(attr::C11NoReturn, R, SI, false, false) | |||
1650 | { | |||
1651 | } | |||
1652 | ||||
1653 | C11NoReturnAttr *clone(ASTContext &C) const; | |||
1654 | void printPretty(raw_ostream &OS, | |||
1655 | const PrintingPolicy &Policy) const; | |||
1656 | const char *getSpelling() const; | |||
1657 | ||||
1658 | ||||
1659 | static bool classof(const Attr *A) { return A->getKind() == attr::C11NoReturn; } | |||
1660 | }; | |||
1661 | ||||
1662 | class CDeclAttr : public InheritableAttr { | |||
1663 | public: | |||
1664 | static CDeclAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1665 | auto *A = new (Ctx) CDeclAttr(Loc, Ctx, 0); | |||
1666 | A->setImplicit(true); | |||
1667 | return A; | |||
1668 | } | |||
1669 | ||||
1670 | CDeclAttr(SourceRange R, ASTContext &Ctx | |||
1671 | , unsigned SI | |||
1672 | ) | |||
1673 | : InheritableAttr(attr::CDecl, R, SI, false, false) | |||
1674 | { | |||
1675 | } | |||
1676 | ||||
1677 | CDeclAttr *clone(ASTContext &C) const; | |||
1678 | void printPretty(raw_ostream &OS, | |||
1679 | const PrintingPolicy &Policy) const; | |||
1680 | const char *getSpelling() const; | |||
1681 | ||||
1682 | ||||
1683 | static bool classof(const Attr *A) { return A->getKind() == attr::CDecl; } | |||
1684 | }; | |||
1685 | ||||
1686 | class CFAuditedTransferAttr : public InheritableAttr { | |||
1687 | public: | |||
1688 | static CFAuditedTransferAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1689 | auto *A = new (Ctx) CFAuditedTransferAttr(Loc, Ctx, 0); | |||
1690 | A->setImplicit(true); | |||
1691 | return A; | |||
1692 | } | |||
1693 | ||||
1694 | CFAuditedTransferAttr(SourceRange R, ASTContext &Ctx | |||
1695 | , unsigned SI | |||
1696 | ) | |||
1697 | : InheritableAttr(attr::CFAuditedTransfer, R, SI, false, false) | |||
1698 | { | |||
1699 | } | |||
1700 | ||||
1701 | CFAuditedTransferAttr *clone(ASTContext &C) const; | |||
1702 | void printPretty(raw_ostream &OS, | |||
1703 | const PrintingPolicy &Policy) const; | |||
1704 | const char *getSpelling() const; | |||
1705 | ||||
1706 | ||||
1707 | static bool classof(const Attr *A) { return A->getKind() == attr::CFAuditedTransfer; } | |||
1708 | }; | |||
1709 | ||||
1710 | class CFConsumedAttr : public InheritableParamAttr { | |||
1711 | public: | |||
1712 | static CFConsumedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1713 | auto *A = new (Ctx) CFConsumedAttr(Loc, Ctx, 0); | |||
1714 | A->setImplicit(true); | |||
1715 | return A; | |||
1716 | } | |||
1717 | ||||
1718 | CFConsumedAttr(SourceRange R, ASTContext &Ctx | |||
1719 | , unsigned SI | |||
1720 | ) | |||
1721 | : InheritableParamAttr(attr::CFConsumed, R, SI, false, false) | |||
1722 | { | |||
1723 | } | |||
1724 | ||||
1725 | CFConsumedAttr *clone(ASTContext &C) const; | |||
1726 | void printPretty(raw_ostream &OS, | |||
1727 | const PrintingPolicy &Policy) const; | |||
1728 | const char *getSpelling() const; | |||
1729 | ||||
1730 | ||||
1731 | static bool classof(const Attr *A) { return A->getKind() == attr::CFConsumed; } | |||
1732 | }; | |||
1733 | ||||
1734 | class CFReturnsNotRetainedAttr : public InheritableAttr { | |||
1735 | public: | |||
1736 | static CFReturnsNotRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1737 | auto *A = new (Ctx) CFReturnsNotRetainedAttr(Loc, Ctx, 0); | |||
1738 | A->setImplicit(true); | |||
1739 | return A; | |||
1740 | } | |||
1741 | ||||
1742 | CFReturnsNotRetainedAttr(SourceRange R, ASTContext &Ctx | |||
1743 | , unsigned SI | |||
1744 | ) | |||
1745 | : InheritableAttr(attr::CFReturnsNotRetained, R, SI, false, false) | |||
1746 | { | |||
1747 | } | |||
1748 | ||||
1749 | CFReturnsNotRetainedAttr *clone(ASTContext &C) const; | |||
1750 | void printPretty(raw_ostream &OS, | |||
1751 | const PrintingPolicy &Policy) const; | |||
1752 | const char *getSpelling() const; | |||
1753 | ||||
1754 | ||||
1755 | static bool classof(const Attr *A) { return A->getKind() == attr::CFReturnsNotRetained; } | |||
1756 | }; | |||
1757 | ||||
1758 | class CFReturnsRetainedAttr : public InheritableAttr { | |||
1759 | public: | |||
1760 | static CFReturnsRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1761 | auto *A = new (Ctx) CFReturnsRetainedAttr(Loc, Ctx, 0); | |||
1762 | A->setImplicit(true); | |||
1763 | return A; | |||
1764 | } | |||
1765 | ||||
1766 | CFReturnsRetainedAttr(SourceRange R, ASTContext &Ctx | |||
1767 | , unsigned SI | |||
1768 | ) | |||
1769 | : InheritableAttr(attr::CFReturnsRetained, R, SI, false, false) | |||
1770 | { | |||
1771 | } | |||
1772 | ||||
1773 | CFReturnsRetainedAttr *clone(ASTContext &C) const; | |||
1774 | void printPretty(raw_ostream &OS, | |||
1775 | const PrintingPolicy &Policy) const; | |||
1776 | const char *getSpelling() const; | |||
1777 | ||||
1778 | ||||
1779 | static bool classof(const Attr *A) { return A->getKind() == attr::CFReturnsRetained; } | |||
1780 | }; | |||
1781 | ||||
1782 | class CFUnknownTransferAttr : public InheritableAttr { | |||
1783 | public: | |||
1784 | static CFUnknownTransferAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1785 | auto *A = new (Ctx) CFUnknownTransferAttr(Loc, Ctx, 0); | |||
1786 | A->setImplicit(true); | |||
1787 | return A; | |||
1788 | } | |||
1789 | ||||
1790 | CFUnknownTransferAttr(SourceRange R, ASTContext &Ctx | |||
1791 | , unsigned SI | |||
1792 | ) | |||
1793 | : InheritableAttr(attr::CFUnknownTransfer, R, SI, false, false) | |||
1794 | { | |||
1795 | } | |||
1796 | ||||
1797 | CFUnknownTransferAttr *clone(ASTContext &C) const; | |||
1798 | void printPretty(raw_ostream &OS, | |||
1799 | const PrintingPolicy &Policy) const; | |||
1800 | const char *getSpelling() const; | |||
1801 | ||||
1802 | ||||
1803 | static bool classof(const Attr *A) { return A->getKind() == attr::CFUnknownTransfer; } | |||
1804 | }; | |||
1805 | ||||
1806 | class CPUDispatchAttr : public InheritableAttr { | |||
1807 | unsigned cpus_Size; | |||
1808 | IdentifierInfo * *cpus_; | |||
1809 | ||||
1810 | public: | |||
1811 | static CPUDispatchAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * *Cpus, unsigned CpusSize, SourceRange Loc = SourceRange()) { | |||
1812 | auto *A = new (Ctx) CPUDispatchAttr(Loc, Ctx, Cpus, CpusSize, 0); | |||
1813 | A->setImplicit(true); | |||
1814 | return A; | |||
1815 | } | |||
1816 | ||||
1817 | CPUDispatchAttr(SourceRange R, ASTContext &Ctx | |||
1818 | , IdentifierInfo * *Cpus, unsigned CpusSize | |||
1819 | , unsigned SI | |||
1820 | ) | |||
1821 | : InheritableAttr(attr::CPUDispatch, R, SI, false, false) | |||
1822 | , cpus_Size(CpusSize), cpus_(new (Ctx, 16) IdentifierInfo *[cpus_Size]) | |||
1823 | { | |||
1824 | std::copy(Cpus, Cpus + cpus_Size, cpus_); | |||
1825 | } | |||
1826 | ||||
1827 | CPUDispatchAttr(SourceRange R, ASTContext &Ctx | |||
1828 | , unsigned SI | |||
1829 | ) | |||
1830 | : InheritableAttr(attr::CPUDispatch, R, SI, false, false) | |||
1831 | , cpus_Size(0), cpus_(nullptr) | |||
1832 | { | |||
1833 | } | |||
1834 | ||||
1835 | CPUDispatchAttr *clone(ASTContext &C) const; | |||
1836 | void printPretty(raw_ostream &OS, | |||
1837 | const PrintingPolicy &Policy) const; | |||
1838 | const char *getSpelling() const; | |||
1839 | typedef IdentifierInfo ** cpus_iterator; | |||
1840 | cpus_iterator cpus_begin() const { return cpus_; } | |||
1841 | cpus_iterator cpus_end() const { return cpus_ + cpus_Size; } | |||
1842 | unsigned cpus_size() const { return cpus_Size; } | |||
1843 | llvm::iterator_range<cpus_iterator> cpus() const { return llvm::make_range(cpus_begin(), cpus_end()); } | |||
1844 | ||||
1845 | ||||
1846 | ||||
1847 | ||||
1848 | static bool classof(const Attr *A) { return A->getKind() == attr::CPUDispatch; } | |||
1849 | }; | |||
1850 | ||||
1851 | class CPUSpecificAttr : public InheritableAttr { | |||
1852 | unsigned cpus_Size; | |||
1853 | IdentifierInfo * *cpus_; | |||
1854 | ||||
1855 | public: | |||
1856 | static CPUSpecificAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * *Cpus, unsigned CpusSize, SourceRange Loc = SourceRange()) { | |||
1857 | auto *A = new (Ctx) CPUSpecificAttr(Loc, Ctx, Cpus, CpusSize, 0); | |||
1858 | A->setImplicit(true); | |||
1859 | return A; | |||
1860 | } | |||
1861 | ||||
1862 | CPUSpecificAttr(SourceRange R, ASTContext &Ctx | |||
1863 | , IdentifierInfo * *Cpus, unsigned CpusSize | |||
1864 | , unsigned SI | |||
1865 | ) | |||
1866 | : InheritableAttr(attr::CPUSpecific, R, SI, false, false) | |||
1867 | , cpus_Size(CpusSize), cpus_(new (Ctx, 16) IdentifierInfo *[cpus_Size]) | |||
1868 | { | |||
1869 | std::copy(Cpus, Cpus + cpus_Size, cpus_); | |||
1870 | } | |||
1871 | ||||
1872 | CPUSpecificAttr(SourceRange R, ASTContext &Ctx | |||
1873 | , unsigned SI | |||
1874 | ) | |||
1875 | : InheritableAttr(attr::CPUSpecific, R, SI, false, false) | |||
1876 | , cpus_Size(0), cpus_(nullptr) | |||
1877 | { | |||
1878 | } | |||
1879 | ||||
1880 | CPUSpecificAttr *clone(ASTContext &C) const; | |||
1881 | void printPretty(raw_ostream &OS, | |||
1882 | const PrintingPolicy &Policy) const; | |||
1883 | const char *getSpelling() const; | |||
1884 | typedef IdentifierInfo ** cpus_iterator; | |||
1885 | cpus_iterator cpus_begin() const { return cpus_; } | |||
1886 | cpus_iterator cpus_end() const { return cpus_ + cpus_Size; } | |||
1887 | unsigned cpus_size() const { return cpus_Size; } | |||
1888 | llvm::iterator_range<cpus_iterator> cpus() const { return llvm::make_range(cpus_begin(), cpus_end()); } | |||
1889 | ||||
1890 | ||||
1891 | ||||
1892 | IdentifierInfo *getCPUName(unsigned Index) const { | |||
1893 | return *(cpus_begin() + Index); | |||
1894 | } | |||
1895 | ||||
1896 | ||||
1897 | static bool classof(const Attr *A) { return A->getKind() == attr::CPUSpecific; } | |||
1898 | }; | |||
1899 | ||||
1900 | class CUDAConstantAttr : public InheritableAttr { | |||
1901 | public: | |||
1902 | static CUDAConstantAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1903 | auto *A = new (Ctx) CUDAConstantAttr(Loc, Ctx, 0); | |||
1904 | A->setImplicit(true); | |||
1905 | return A; | |||
1906 | } | |||
1907 | ||||
1908 | CUDAConstantAttr(SourceRange R, ASTContext &Ctx | |||
1909 | , unsigned SI | |||
1910 | ) | |||
1911 | : InheritableAttr(attr::CUDAConstant, R, SI, false, false) | |||
1912 | { | |||
1913 | } | |||
1914 | ||||
1915 | CUDAConstantAttr *clone(ASTContext &C) const; | |||
1916 | void printPretty(raw_ostream &OS, | |||
1917 | const PrintingPolicy &Policy) const; | |||
1918 | const char *getSpelling() const; | |||
1919 | ||||
1920 | ||||
1921 | static bool classof(const Attr *A) { return A->getKind() == attr::CUDAConstant; } | |||
1922 | }; | |||
1923 | ||||
1924 | class CUDADeviceAttr : public InheritableAttr { | |||
1925 | public: | |||
1926 | static CUDADeviceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1927 | auto *A = new (Ctx) CUDADeviceAttr(Loc, Ctx, 0); | |||
1928 | A->setImplicit(true); | |||
1929 | return A; | |||
1930 | } | |||
1931 | ||||
1932 | CUDADeviceAttr(SourceRange R, ASTContext &Ctx | |||
1933 | , unsigned SI | |||
1934 | ) | |||
1935 | : InheritableAttr(attr::CUDADevice, R, SI, false, false) | |||
1936 | { | |||
1937 | } | |||
1938 | ||||
1939 | CUDADeviceAttr *clone(ASTContext &C) const; | |||
1940 | void printPretty(raw_ostream &OS, | |||
1941 | const PrintingPolicy &Policy) const; | |||
1942 | const char *getSpelling() const; | |||
1943 | ||||
1944 | ||||
1945 | static bool classof(const Attr *A) { return A->getKind() == attr::CUDADevice; } | |||
1946 | }; | |||
1947 | ||||
1948 | class CUDAGlobalAttr : public InheritableAttr { | |||
1949 | public: | |||
1950 | static CUDAGlobalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1951 | auto *A = new (Ctx) CUDAGlobalAttr(Loc, Ctx, 0); | |||
1952 | A->setImplicit(true); | |||
1953 | return A; | |||
1954 | } | |||
1955 | ||||
1956 | CUDAGlobalAttr(SourceRange R, ASTContext &Ctx | |||
1957 | , unsigned SI | |||
1958 | ) | |||
1959 | : InheritableAttr(attr::CUDAGlobal, R, SI, false, false) | |||
1960 | { | |||
1961 | } | |||
1962 | ||||
1963 | CUDAGlobalAttr *clone(ASTContext &C) const; | |||
1964 | void printPretty(raw_ostream &OS, | |||
1965 | const PrintingPolicy &Policy) const; | |||
1966 | const char *getSpelling() const; | |||
1967 | ||||
1968 | ||||
1969 | static bool classof(const Attr *A) { return A->getKind() == attr::CUDAGlobal; } | |||
1970 | }; | |||
1971 | ||||
1972 | class CUDAHostAttr : public InheritableAttr { | |||
1973 | public: | |||
1974 | static CUDAHostAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1975 | auto *A = new (Ctx) CUDAHostAttr(Loc, Ctx, 0); | |||
1976 | A->setImplicit(true); | |||
1977 | return A; | |||
1978 | } | |||
1979 | ||||
1980 | CUDAHostAttr(SourceRange R, ASTContext &Ctx | |||
1981 | , unsigned SI | |||
1982 | ) | |||
1983 | : InheritableAttr(attr::CUDAHost, R, SI, false, false) | |||
1984 | { | |||
1985 | } | |||
1986 | ||||
1987 | CUDAHostAttr *clone(ASTContext &C) const; | |||
1988 | void printPretty(raw_ostream &OS, | |||
1989 | const PrintingPolicy &Policy) const; | |||
1990 | const char *getSpelling() const; | |||
1991 | ||||
1992 | ||||
1993 | static bool classof(const Attr *A) { return A->getKind() == attr::CUDAHost; } | |||
1994 | }; | |||
1995 | ||||
1996 | class CUDAInvalidTargetAttr : public InheritableAttr { | |||
1997 | public: | |||
1998 | static CUDAInvalidTargetAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1999 | auto *A = new (Ctx) CUDAInvalidTargetAttr(Loc, Ctx, 0); | |||
2000 | A->setImplicit(true); | |||
2001 | return A; | |||
2002 | } | |||
2003 | ||||
2004 | CUDAInvalidTargetAttr(SourceRange R, ASTContext &Ctx | |||
2005 | , unsigned SI | |||
2006 | ) | |||
2007 | : InheritableAttr(attr::CUDAInvalidTarget, R, SI, false, false) | |||
2008 | { | |||
2009 | } | |||
2010 | ||||
2011 | CUDAInvalidTargetAttr *clone(ASTContext &C) const; | |||
2012 | void printPretty(raw_ostream &OS, | |||
2013 | const PrintingPolicy &Policy) const; | |||
2014 | const char *getSpelling() const; | |||
2015 | ||||
2016 | ||||
2017 | static bool classof(const Attr *A) { return A->getKind() == attr::CUDAInvalidTarget; } | |||
2018 | }; | |||
2019 | ||||
2020 | class CUDALaunchBoundsAttr : public InheritableAttr { | |||
2021 | Expr * maxThreads; | |||
2022 | ||||
2023 | Expr * minBlocks; | |||
2024 | ||||
2025 | public: | |||
2026 | static CUDALaunchBoundsAttr *CreateImplicit(ASTContext &Ctx, Expr * MaxThreads, Expr * MinBlocks, SourceRange Loc = SourceRange()) { | |||
2027 | auto *A = new (Ctx) CUDALaunchBoundsAttr(Loc, Ctx, MaxThreads, MinBlocks, 0); | |||
2028 | A->setImplicit(true); | |||
2029 | return A; | |||
2030 | } | |||
2031 | ||||
2032 | CUDALaunchBoundsAttr(SourceRange R, ASTContext &Ctx | |||
2033 | , Expr * MaxThreads | |||
2034 | , Expr * MinBlocks | |||
2035 | , unsigned SI | |||
2036 | ) | |||
2037 | : InheritableAttr(attr::CUDALaunchBounds, R, SI, false, false) | |||
2038 | , maxThreads(MaxThreads) | |||
2039 | , minBlocks(MinBlocks) | |||
2040 | { | |||
2041 | } | |||
2042 | ||||
2043 | CUDALaunchBoundsAttr(SourceRange R, ASTContext &Ctx | |||
2044 | , Expr * MaxThreads | |||
2045 | , unsigned SI | |||
2046 | ) | |||
2047 | : InheritableAttr(attr::CUDALaunchBounds, R, SI, false, false) | |||
2048 | , maxThreads(MaxThreads) | |||
2049 | , minBlocks() | |||
2050 | { | |||
2051 | } | |||
2052 | ||||
2053 | CUDALaunchBoundsAttr *clone(ASTContext &C) const; | |||
2054 | void printPretty(raw_ostream &OS, | |||
2055 | const PrintingPolicy &Policy) const; | |||
2056 | const char *getSpelling() const; | |||
2057 | Expr * getMaxThreads() const { | |||
2058 | return maxThreads; | |||
2059 | } | |||
2060 | ||||
2061 | Expr * getMinBlocks() const { | |||
2062 | return minBlocks; | |||
2063 | } | |||
2064 | ||||
2065 | ||||
2066 | ||||
2067 | static bool classof(const Attr *A) { return A->getKind() == attr::CUDALaunchBounds; } | |||
2068 | }; | |||
2069 | ||||
2070 | class CUDASharedAttr : public InheritableAttr { | |||
2071 | public: | |||
2072 | static CUDASharedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2073 | auto *A = new (Ctx) CUDASharedAttr(Loc, Ctx, 0); | |||
2074 | A->setImplicit(true); | |||
2075 | return A; | |||
2076 | } | |||
2077 | ||||
2078 | CUDASharedAttr(SourceRange R, ASTContext &Ctx | |||
2079 | , unsigned SI | |||
2080 | ) | |||
2081 | : InheritableAttr(attr::CUDAShared, R, SI, false, false) | |||
2082 | { | |||
2083 | } | |||
2084 | ||||
2085 | CUDASharedAttr *clone(ASTContext &C) const; | |||
2086 | void printPretty(raw_ostream &OS, | |||
2087 | const PrintingPolicy &Policy) const; | |||
2088 | const char *getSpelling() const; | |||
2089 | ||||
2090 | ||||
2091 | static bool classof(const Attr *A) { return A->getKind() == attr::CUDAShared; } | |||
2092 | }; | |||
2093 | ||||
2094 | class CXX11NoReturnAttr : public InheritableAttr { | |||
2095 | public: | |||
2096 | static CXX11NoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2097 | auto *A = new (Ctx) CXX11NoReturnAttr(Loc, Ctx, 0); | |||
2098 | A->setImplicit(true); | |||
2099 | return A; | |||
2100 | } | |||
2101 | ||||
2102 | CXX11NoReturnAttr(SourceRange R, ASTContext &Ctx | |||
2103 | , unsigned SI | |||
2104 | ) | |||
2105 | : InheritableAttr(attr::CXX11NoReturn, R, SI, false, false) | |||
2106 | { | |||
2107 | } | |||
2108 | ||||
2109 | CXX11NoReturnAttr *clone(ASTContext &C) const; | |||
2110 | void printPretty(raw_ostream &OS, | |||
2111 | const PrintingPolicy &Policy) const; | |||
2112 | const char *getSpelling() const; | |||
2113 | ||||
2114 | ||||
2115 | static bool classof(const Attr *A) { return A->getKind() == attr::CXX11NoReturn; } | |||
2116 | }; | |||
2117 | ||||
2118 | class CallableWhenAttr : public InheritableAttr { | |||
2119 | public: | |||
2120 | enum ConsumedState { | |||
2121 | Unknown, | |||
2122 | Consumed, | |||
2123 | Unconsumed | |||
2124 | }; | |||
2125 | private: | |||
2126 | unsigned callableStates_Size; | |||
2127 | ConsumedState *callableStates_; | |||
2128 | ||||
2129 | public: | |||
2130 | static CallableWhenAttr *CreateImplicit(ASTContext &Ctx, ConsumedState *CallableStates, unsigned CallableStatesSize, SourceRange Loc = SourceRange()) { | |||
2131 | auto *A = new (Ctx) CallableWhenAttr(Loc, Ctx, CallableStates, CallableStatesSize, 0); | |||
2132 | A->setImplicit(true); | |||
2133 | return A; | |||
2134 | } | |||
2135 | ||||
2136 | CallableWhenAttr(SourceRange R, ASTContext &Ctx | |||
2137 | , ConsumedState *CallableStates, unsigned CallableStatesSize | |||
2138 | , unsigned SI | |||
2139 | ) | |||
2140 | : InheritableAttr(attr::CallableWhen, R, SI, false, false) | |||
2141 | , callableStates_Size(CallableStatesSize), callableStates_(new (Ctx, 16) ConsumedState[callableStates_Size]) | |||
2142 | { | |||
2143 | std::copy(CallableStates, CallableStates + callableStates_Size, callableStates_); | |||
2144 | } | |||
2145 | ||||
2146 | CallableWhenAttr(SourceRange R, ASTContext &Ctx | |||
2147 | , unsigned SI | |||
2148 | ) | |||
2149 | : InheritableAttr(attr::CallableWhen, R, SI, false, false) | |||
2150 | , callableStates_Size(0), callableStates_(nullptr) | |||
2151 | { | |||
2152 | } | |||
2153 | ||||
2154 | CallableWhenAttr *clone(ASTContext &C) const; | |||
2155 | void printPretty(raw_ostream &OS, | |||
2156 | const PrintingPolicy &Policy) const; | |||
2157 | const char *getSpelling() const; | |||
2158 | typedef ConsumedState* callableStates_iterator; | |||
2159 | callableStates_iterator callableStates_begin() const { return callableStates_; } | |||
2160 | callableStates_iterator callableStates_end() const { return callableStates_ + callableStates_Size; } | |||
2161 | unsigned callableStates_size() const { return callableStates_Size; } | |||
2162 | llvm::iterator_range<callableStates_iterator> callableStates() const { return llvm::make_range(callableStates_begin(), callableStates_end()); } | |||
2163 | ||||
2164 | ||||
2165 | static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) { | |||
2166 | Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val) | |||
2167 | .Case("unknown", CallableWhenAttr::Unknown) | |||
2168 | .Case("consumed", CallableWhenAttr::Consumed) | |||
2169 | .Case("unconsumed", CallableWhenAttr::Unconsumed) | |||
2170 | .Default(Optional<ConsumedState>()); | |||
2171 | if (R) { | |||
2172 | Out = *R; | |||
2173 | return true; | |||
2174 | } | |||
2175 | return false; | |||
2176 | } | |||
2177 | ||||
2178 | static const char *ConvertConsumedStateToStr(ConsumedState Val) { | |||
2179 | switch(Val) { | |||
2180 | case CallableWhenAttr::Unknown: return "unknown"; | |||
2181 | case CallableWhenAttr::Consumed: return "consumed"; | |||
2182 | case CallableWhenAttr::Unconsumed: return "unconsumed"; | |||
2183 | } | |||
2184 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 2184); | |||
2185 | } | |||
2186 | ||||
2187 | ||||
2188 | static bool classof(const Attr *A) { return A->getKind() == attr::CallableWhen; } | |||
2189 | }; | |||
2190 | ||||
2191 | class CallbackAttr : public InheritableAttr { | |||
2192 | unsigned encoding_Size; | |||
2193 | int *encoding_; | |||
2194 | ||||
2195 | public: | |||
2196 | static CallbackAttr *CreateImplicit(ASTContext &Ctx, int *Encoding, unsigned EncodingSize, SourceRange Loc = SourceRange()) { | |||
2197 | auto *A = new (Ctx) CallbackAttr(Loc, Ctx, Encoding, EncodingSize, 0); | |||
2198 | A->setImplicit(true); | |||
2199 | return A; | |||
2200 | } | |||
2201 | ||||
2202 | CallbackAttr(SourceRange R, ASTContext &Ctx | |||
2203 | , int *Encoding, unsigned EncodingSize | |||
2204 | , unsigned SI | |||
2205 | ) | |||
2206 | : InheritableAttr(attr::Callback, R, SI, false, false) | |||
2207 | , encoding_Size(EncodingSize), encoding_(new (Ctx, 16) int[encoding_Size]) | |||
2208 | { | |||
2209 | std::copy(Encoding, Encoding + encoding_Size, encoding_); | |||
2210 | } | |||
2211 | ||||
2212 | CallbackAttr(SourceRange R, ASTContext &Ctx | |||
2213 | , unsigned SI | |||
2214 | ) | |||
2215 | : InheritableAttr(attr::Callback, R, SI, false, false) | |||
2216 | , encoding_Size(0), encoding_(nullptr) | |||
2217 | { | |||
2218 | } | |||
2219 | ||||
2220 | CallbackAttr *clone(ASTContext &C) const; | |||
2221 | void printPretty(raw_ostream &OS, | |||
2222 | const PrintingPolicy &Policy) const; | |||
2223 | const char *getSpelling() const; | |||
2224 | typedef int* encoding_iterator; | |||
2225 | encoding_iterator encoding_begin() const { return encoding_; } | |||
2226 | encoding_iterator encoding_end() const { return encoding_ + encoding_Size; } | |||
2227 | unsigned encoding_size() const { return encoding_Size; } | |||
2228 | llvm::iterator_range<encoding_iterator> encoding() const { return llvm::make_range(encoding_begin(), encoding_end()); } | |||
2229 | ||||
2230 | ||||
2231 | ||||
2232 | ||||
2233 | static bool classof(const Attr *A) { return A->getKind() == attr::Callback; } | |||
2234 | }; | |||
2235 | ||||
2236 | class CapabilityAttr : public InheritableAttr { | |||
2237 | unsigned nameLength; | |||
2238 | char *name; | |||
2239 | ||||
2240 | public: | |||
2241 | enum Spelling { | |||
2242 | GNU_capability = 0, | |||
2243 | CXX11_clang_capability = 1, | |||
2244 | GNU_shared_capability = 2, | |||
2245 | CXX11_clang_shared_capability = 3 | |||
2246 | }; | |||
2247 | ||||
2248 | static CapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, llvm::StringRef Name, SourceRange Loc = SourceRange()) { | |||
2249 | auto *A = new (Ctx) CapabilityAttr(Loc, Ctx, Name, S); | |||
2250 | A->setImplicit(true); | |||
2251 | return A; | |||
2252 | } | |||
2253 | ||||
2254 | CapabilityAttr(SourceRange R, ASTContext &Ctx | |||
2255 | , llvm::StringRef Name | |||
2256 | , unsigned SI | |||
2257 | ) | |||
2258 | : InheritableAttr(attr::Capability, R, SI, false, false) | |||
2259 | , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength]) | |||
2260 | { | |||
2261 | if (!Name.empty()) | |||
2262 | std::memcpy(name, Name.data(), nameLength); | |||
2263 | } | |||
2264 | ||||
2265 | CapabilityAttr *clone(ASTContext &C) const; | |||
2266 | void printPretty(raw_ostream &OS, | |||
2267 | const PrintingPolicy &Policy) const; | |||
2268 | const char *getSpelling() const; | |||
2269 | Spelling getSemanticSpelling() const { | |||
2270 | switch (SpellingListIndex) { | |||
2271 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 2271); | |||
2272 | case 0: return GNU_capability; | |||
2273 | case 1: return CXX11_clang_capability; | |||
2274 | case 2: return GNU_shared_capability; | |||
2275 | case 3: return CXX11_clang_shared_capability; | |||
2276 | } | |||
2277 | } | |||
2278 | bool isShared() const { return SpellingListIndex == 2 || | |||
2279 | SpellingListIndex == 3; } | |||
2280 | llvm::StringRef getName() const { | |||
2281 | return llvm::StringRef(name, nameLength); | |||
2282 | } | |||
2283 | unsigned getNameLength() const { | |||
2284 | return nameLength; | |||
2285 | } | |||
2286 | void setName(ASTContext &C, llvm::StringRef S) { | |||
2287 | nameLength = S.size(); | |||
2288 | this->name = new (C, 1) char [nameLength]; | |||
2289 | if (!S.empty()) | |||
2290 | std::memcpy(this->name, S.data(), nameLength); | |||
2291 | } | |||
2292 | ||||
2293 | ||||
2294 | bool isMutex() const { return getName().equals_lower("mutex"); } | |||
2295 | bool isRole() const { return getName().equals_lower("role"); } | |||
2296 | ||||
2297 | ||||
2298 | static bool classof(const Attr *A) { return A->getKind() == attr::Capability; } | |||
2299 | }; | |||
2300 | ||||
2301 | class CapturedRecordAttr : public InheritableAttr { | |||
2302 | public: | |||
2303 | static CapturedRecordAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2304 | auto *A = new (Ctx) CapturedRecordAttr(Loc, Ctx, 0); | |||
2305 | A->setImplicit(true); | |||
2306 | return A; | |||
2307 | } | |||
2308 | ||||
2309 | CapturedRecordAttr(SourceRange R, ASTContext &Ctx | |||
2310 | , unsigned SI | |||
2311 | ) | |||
2312 | : InheritableAttr(attr::CapturedRecord, R, SI, false, false) | |||
2313 | { | |||
2314 | } | |||
2315 | ||||
2316 | CapturedRecordAttr *clone(ASTContext &C) const; | |||
2317 | void printPretty(raw_ostream &OS, | |||
2318 | const PrintingPolicy &Policy) const; | |||
2319 | const char *getSpelling() const; | |||
2320 | ||||
2321 | ||||
2322 | static bool classof(const Attr *A) { return A->getKind() == attr::CapturedRecord; } | |||
2323 | }; | |||
2324 | ||||
2325 | class CarriesDependencyAttr : public InheritableParamAttr { | |||
2326 | public: | |||
2327 | static CarriesDependencyAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2328 | auto *A = new (Ctx) CarriesDependencyAttr(Loc, Ctx, 0); | |||
2329 | A->setImplicit(true); | |||
2330 | return A; | |||
2331 | } | |||
2332 | ||||
2333 | CarriesDependencyAttr(SourceRange R, ASTContext &Ctx | |||
2334 | , unsigned SI | |||
2335 | ) | |||
2336 | : InheritableParamAttr(attr::CarriesDependency, R, SI, false, false) | |||
2337 | { | |||
2338 | } | |||
2339 | ||||
2340 | CarriesDependencyAttr *clone(ASTContext &C) const; | |||
2341 | void printPretty(raw_ostream &OS, | |||
2342 | const PrintingPolicy &Policy) const; | |||
2343 | const char *getSpelling() const; | |||
2344 | ||||
2345 | ||||
2346 | static bool classof(const Attr *A) { return A->getKind() == attr::CarriesDependency; } | |||
2347 | }; | |||
2348 | ||||
2349 | class CleanupAttr : public InheritableAttr { | |||
2350 | FunctionDecl * functionDecl; | |||
2351 | ||||
2352 | public: | |||
2353 | static CleanupAttr *CreateImplicit(ASTContext &Ctx, FunctionDecl * FunctionDecl, SourceRange Loc = SourceRange()) { | |||
2354 | auto *A = new (Ctx) CleanupAttr(Loc, Ctx, FunctionDecl, 0); | |||
2355 | A->setImplicit(true); | |||
2356 | return A; | |||
2357 | } | |||
2358 | ||||
2359 | CleanupAttr(SourceRange R, ASTContext &Ctx | |||
2360 | , FunctionDecl * FunctionDecl | |||
2361 | , unsigned SI | |||
2362 | ) | |||
2363 | : InheritableAttr(attr::Cleanup, R, SI, false, false) | |||
2364 | , functionDecl(FunctionDecl) | |||
2365 | { | |||
2366 | } | |||
2367 | ||||
2368 | CleanupAttr *clone(ASTContext &C) const; | |||
2369 | void printPretty(raw_ostream &OS, | |||
2370 | const PrintingPolicy &Policy) const; | |||
2371 | const char *getSpelling() const; | |||
2372 | FunctionDecl * getFunctionDecl() const { | |||
2373 | return functionDecl; | |||
2374 | } | |||
2375 | ||||
2376 | ||||
2377 | ||||
2378 | static bool classof(const Attr *A) { return A->getKind() == attr::Cleanup; } | |||
2379 | }; | |||
2380 | ||||
2381 | class CodeSegAttr : public InheritableAttr { | |||
2382 | unsigned nameLength; | |||
2383 | char *name; | |||
2384 | ||||
2385 | public: | |||
2386 | static CodeSegAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) { | |||
2387 | auto *A = new (Ctx) CodeSegAttr(Loc, Ctx, Name, 0); | |||
2388 | A->setImplicit(true); | |||
2389 | return A; | |||
2390 | } | |||
2391 | ||||
2392 | CodeSegAttr(SourceRange R, ASTContext &Ctx | |||
2393 | , llvm::StringRef Name | |||
2394 | , unsigned SI | |||
2395 | ) | |||
2396 | : InheritableAttr(attr::CodeSeg, R, SI, false, false) | |||
2397 | , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength]) | |||
2398 | { | |||
2399 | if (!Name.empty()) | |||
2400 | std::memcpy(name, Name.data(), nameLength); | |||
2401 | } | |||
2402 | ||||
2403 | CodeSegAttr *clone(ASTContext &C) const; | |||
2404 | void printPretty(raw_ostream &OS, | |||
2405 | const PrintingPolicy &Policy) const; | |||
2406 | const char *getSpelling() const; | |||
2407 | llvm::StringRef getName() const { | |||
2408 | return llvm::StringRef(name, nameLength); | |||
2409 | } | |||
2410 | unsigned getNameLength() const { | |||
2411 | return nameLength; | |||
2412 | } | |||
2413 | void setName(ASTContext &C, llvm::StringRef S) { | |||
2414 | nameLength = S.size(); | |||
2415 | this->name = new (C, 1) char [nameLength]; | |||
2416 | if (!S.empty()) | |||
2417 | std::memcpy(this->name, S.data(), nameLength); | |||
2418 | } | |||
2419 | ||||
2420 | ||||
2421 | ||||
2422 | static bool classof(const Attr *A) { return A->getKind() == attr::CodeSeg; } | |||
2423 | }; | |||
2424 | ||||
2425 | class ColdAttr : public InheritableAttr { | |||
2426 | public: | |||
2427 | static ColdAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2428 | auto *A = new (Ctx) ColdAttr(Loc, Ctx, 0); | |||
2429 | A->setImplicit(true); | |||
2430 | return A; | |||
2431 | } | |||
2432 | ||||
2433 | ColdAttr(SourceRange R, ASTContext &Ctx | |||
2434 | , unsigned SI | |||
2435 | ) | |||
2436 | : InheritableAttr(attr::Cold, R, SI, false, false) | |||
2437 | { | |||
2438 | } | |||
2439 | ||||
2440 | ColdAttr *clone(ASTContext &C) const; | |||
2441 | void printPretty(raw_ostream &OS, | |||
2442 | const PrintingPolicy &Policy) const; | |||
2443 | const char *getSpelling() const; | |||
2444 | ||||
2445 | ||||
2446 | static bool classof(const Attr *A) { return A->getKind() == attr::Cold; } | |||
2447 | }; | |||
2448 | ||||
2449 | class CommonAttr : public InheritableAttr { | |||
2450 | public: | |||
2451 | static CommonAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2452 | auto *A = new (Ctx) CommonAttr(Loc, Ctx, 0); | |||
2453 | A->setImplicit(true); | |||
2454 | return A; | |||
2455 | } | |||
2456 | ||||
2457 | CommonAttr(SourceRange R, ASTContext &Ctx | |||
2458 | , unsigned SI | |||
2459 | ) | |||
2460 | : InheritableAttr(attr::Common, R, SI, false, false) | |||
2461 | { | |||
2462 | } | |||
2463 | ||||
2464 | CommonAttr *clone(ASTContext &C) const; | |||
2465 | void printPretty(raw_ostream &OS, | |||
2466 | const PrintingPolicy &Policy) const; | |||
2467 | const char *getSpelling() const; | |||
2468 | ||||
2469 | ||||
2470 | static bool classof(const Attr *A) { return A->getKind() == attr::Common; } | |||
2471 | }; | |||
2472 | ||||
2473 | class ConstAttr : public InheritableAttr { | |||
2474 | public: | |||
2475 | static ConstAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2476 | auto *A = new (Ctx) ConstAttr(Loc, Ctx, 0); | |||
2477 | A->setImplicit(true); | |||
2478 | return A; | |||
2479 | } | |||
2480 | ||||
2481 | ConstAttr(SourceRange R, ASTContext &Ctx | |||
2482 | , unsigned SI | |||
2483 | ) | |||
2484 | : InheritableAttr(attr::Const, R, SI, false, false) | |||
2485 | { | |||
2486 | } | |||
2487 | ||||
2488 | ConstAttr *clone(ASTContext &C) const; | |||
2489 | void printPretty(raw_ostream &OS, | |||
2490 | const PrintingPolicy &Policy) const; | |||
2491 | const char *getSpelling() const; | |||
2492 | ||||
2493 | ||||
2494 | static bool classof(const Attr *A) { return A->getKind() == attr::Const; } | |||
2495 | }; | |||
2496 | ||||
2497 | class ConstructorAttr : public InheritableAttr { | |||
2498 | int priority; | |||
2499 | ||||
2500 | public: | |||
2501 | static ConstructorAttr *CreateImplicit(ASTContext &Ctx, int Priority, SourceRange Loc = SourceRange()) { | |||
2502 | auto *A = new (Ctx) ConstructorAttr(Loc, Ctx, Priority, 0); | |||
2503 | A->setImplicit(true); | |||
2504 | return A; | |||
2505 | } | |||
2506 | ||||
2507 | ConstructorAttr(SourceRange R, ASTContext &Ctx | |||
2508 | , int Priority | |||
2509 | , unsigned SI | |||
2510 | ) | |||
2511 | : InheritableAttr(attr::Constructor, R, SI, false, false) | |||
2512 | , priority(Priority) | |||
2513 | { | |||
2514 | } | |||
2515 | ||||
2516 | ConstructorAttr(SourceRange R, ASTContext &Ctx | |||
2517 | , unsigned SI | |||
2518 | ) | |||
2519 | : InheritableAttr(attr::Constructor, R, SI, false, false) | |||
2520 | , priority() | |||
2521 | { | |||
2522 | } | |||
2523 | ||||
2524 | ConstructorAttr *clone(ASTContext &C) const; | |||
2525 | void printPretty(raw_ostream &OS, | |||
2526 | const PrintingPolicy &Policy) const; | |||
2527 | const char *getSpelling() const; | |||
2528 | int getPriority() const { | |||
2529 | return priority; | |||
2530 | } | |||
2531 | ||||
2532 | static const int DefaultPriority = 65535; | |||
2533 | ||||
2534 | ||||
2535 | ||||
2536 | static bool classof(const Attr *A) { return A->getKind() == attr::Constructor; } | |||
2537 | }; | |||
2538 | ||||
2539 | class ConsumableAttr : public InheritableAttr { | |||
2540 | public: | |||
2541 | enum ConsumedState { | |||
2542 | Unknown, | |||
2543 | Consumed, | |||
2544 | Unconsumed | |||
2545 | }; | |||
2546 | private: | |||
2547 | ConsumedState defaultState; | |||
2548 | ||||
2549 | public: | |||
2550 | static ConsumableAttr *CreateImplicit(ASTContext &Ctx, ConsumedState DefaultState, SourceRange Loc = SourceRange()) { | |||
2551 | auto *A = new (Ctx) ConsumableAttr(Loc, Ctx, DefaultState, 0); | |||
2552 | A->setImplicit(true); | |||
2553 | return A; | |||
2554 | } | |||
2555 | ||||
2556 | ConsumableAttr(SourceRange R, ASTContext &Ctx | |||
2557 | , ConsumedState DefaultState | |||
2558 | , unsigned SI | |||
2559 | ) | |||
2560 | : InheritableAttr(attr::Consumable, R, SI, false, false) | |||
2561 | , defaultState(DefaultState) | |||
2562 | { | |||
2563 | } | |||
2564 | ||||
2565 | ConsumableAttr *clone(ASTContext &C) const; | |||
2566 | void printPretty(raw_ostream &OS, | |||
2567 | const PrintingPolicy &Policy) const; | |||
2568 | const char *getSpelling() const; | |||
2569 | ConsumedState getDefaultState() const { | |||
2570 | return defaultState; | |||
2571 | } | |||
2572 | ||||
2573 | static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) { | |||
2574 | Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val) | |||
2575 | .Case("unknown", ConsumableAttr::Unknown) | |||
2576 | .Case("consumed", ConsumableAttr::Consumed) | |||
2577 | .Case("unconsumed", ConsumableAttr::Unconsumed) | |||
2578 | .Default(Optional<ConsumedState>()); | |||
2579 | if (R) { | |||
2580 | Out = *R; | |||
2581 | return true; | |||
2582 | } | |||
2583 | return false; | |||
2584 | } | |||
2585 | ||||
2586 | static const char *ConvertConsumedStateToStr(ConsumedState Val) { | |||
2587 | switch(Val) { | |||
2588 | case ConsumableAttr::Unknown: return "unknown"; | |||
2589 | case ConsumableAttr::Consumed: return "consumed"; | |||
2590 | case ConsumableAttr::Unconsumed: return "unconsumed"; | |||
2591 | } | |||
2592 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 2592); | |||
2593 | } | |||
2594 | ||||
2595 | ||||
2596 | static bool classof(const Attr *A) { return A->getKind() == attr::Consumable; } | |||
2597 | }; | |||
2598 | ||||
2599 | class ConsumableAutoCastAttr : public InheritableAttr { | |||
2600 | public: | |||
2601 | static ConsumableAutoCastAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2602 | auto *A = new (Ctx) ConsumableAutoCastAttr(Loc, Ctx, 0); | |||
2603 | A->setImplicit(true); | |||
2604 | return A; | |||
2605 | } | |||
2606 | ||||
2607 | ConsumableAutoCastAttr(SourceRange R, ASTContext &Ctx | |||
2608 | , unsigned SI | |||
2609 | ) | |||
2610 | : InheritableAttr(attr::ConsumableAutoCast, R, SI, false, false) | |||
2611 | { | |||
2612 | } | |||
2613 | ||||
2614 | ConsumableAutoCastAttr *clone(ASTContext &C) const; | |||
2615 | void printPretty(raw_ostream &OS, | |||
2616 | const PrintingPolicy &Policy) const; | |||
2617 | const char *getSpelling() const; | |||
2618 | ||||
2619 | ||||
2620 | static bool classof(const Attr *A) { return A->getKind() == attr::ConsumableAutoCast; } | |||
2621 | }; | |||
2622 | ||||
2623 | class ConsumableSetOnReadAttr : public InheritableAttr { | |||
2624 | public: | |||
2625 | static ConsumableSetOnReadAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2626 | auto *A = new (Ctx) ConsumableSetOnReadAttr(Loc, Ctx, 0); | |||
2627 | A->setImplicit(true); | |||
2628 | return A; | |||
2629 | } | |||
2630 | ||||
2631 | ConsumableSetOnReadAttr(SourceRange R, ASTContext &Ctx | |||
2632 | , unsigned SI | |||
2633 | ) | |||
2634 | : InheritableAttr(attr::ConsumableSetOnRead, R, SI, false, false) | |||
2635 | { | |||
2636 | } | |||
2637 | ||||
2638 | ConsumableSetOnReadAttr *clone(ASTContext &C) const; | |||
2639 | void printPretty(raw_ostream &OS, | |||
2640 | const PrintingPolicy &Policy) const; | |||
2641 | const char *getSpelling() const; | |||
2642 | ||||
2643 | ||||
2644 | static bool classof(const Attr *A) { return A->getKind() == attr::ConsumableSetOnRead; } | |||
2645 | }; | |||
2646 | ||||
2647 | class ConvergentAttr : public InheritableAttr { | |||
2648 | public: | |||
2649 | static ConvergentAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2650 | auto *A = new (Ctx) ConvergentAttr(Loc, Ctx, 0); | |||
2651 | A->setImplicit(true); | |||
2652 | return A; | |||
2653 | } | |||
2654 | ||||
2655 | ConvergentAttr(SourceRange R, ASTContext &Ctx | |||
2656 | , unsigned SI | |||
2657 | ) | |||
2658 | : InheritableAttr(attr::Convergent, R, SI, false, false) | |||
2659 | { | |||
2660 | } | |||
2661 | ||||
2662 | ConvergentAttr *clone(ASTContext &C) const; | |||
2663 | void printPretty(raw_ostream &OS, | |||
2664 | const PrintingPolicy &Policy) const; | |||
2665 | const char *getSpelling() const; | |||
2666 | ||||
2667 | ||||
2668 | static bool classof(const Attr *A) { return A->getKind() == attr::Convergent; } | |||
2669 | }; | |||
2670 | ||||
2671 | class DLLExportAttr : public InheritableAttr { | |||
2672 | public: | |||
2673 | static DLLExportAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2674 | auto *A = new (Ctx) DLLExportAttr(Loc, Ctx, 0); | |||
2675 | A->setImplicit(true); | |||
2676 | return A; | |||
2677 | } | |||
2678 | ||||
2679 | DLLExportAttr(SourceRange R, ASTContext &Ctx | |||
2680 | , unsigned SI | |||
2681 | ) | |||
2682 | : InheritableAttr(attr::DLLExport, R, SI, false, false) | |||
2683 | { | |||
2684 | } | |||
2685 | ||||
2686 | DLLExportAttr *clone(ASTContext &C) const; | |||
2687 | void printPretty(raw_ostream &OS, | |||
2688 | const PrintingPolicy &Policy) const; | |||
2689 | const char *getSpelling() const; | |||
2690 | ||||
2691 | ||||
2692 | static bool classof(const Attr *A) { return A->getKind() == attr::DLLExport; } | |||
2693 | }; | |||
2694 | ||||
2695 | class DLLExportStaticLocalAttr : public InheritableAttr { | |||
2696 | public: | |||
2697 | static DLLExportStaticLocalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2698 | auto *A = new (Ctx) DLLExportStaticLocalAttr(Loc, Ctx, 0); | |||
2699 | A->setImplicit(true); | |||
2700 | return A; | |||
2701 | } | |||
2702 | ||||
2703 | DLLExportStaticLocalAttr(SourceRange R, ASTContext &Ctx | |||
2704 | , unsigned SI | |||
2705 | ) | |||
2706 | : InheritableAttr(attr::DLLExportStaticLocal, R, SI, false, false) | |||
2707 | { | |||
2708 | } | |||
2709 | ||||
2710 | DLLExportStaticLocalAttr *clone(ASTContext &C) const; | |||
2711 | void printPretty(raw_ostream &OS, | |||
2712 | const PrintingPolicy &Policy) const; | |||
2713 | const char *getSpelling() const; | |||
2714 | ||||
2715 | ||||
2716 | static bool classof(const Attr *A) { return A->getKind() == attr::DLLExportStaticLocal; } | |||
2717 | }; | |||
2718 | ||||
2719 | class DLLImportAttr : public InheritableAttr { | |||
2720 | public: | |||
2721 | static DLLImportAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2722 | auto *A = new (Ctx) DLLImportAttr(Loc, Ctx, 0); | |||
2723 | A->setImplicit(true); | |||
2724 | return A; | |||
2725 | } | |||
2726 | ||||
2727 | DLLImportAttr(SourceRange R, ASTContext &Ctx | |||
2728 | , unsigned SI | |||
2729 | ) | |||
2730 | : InheritableAttr(attr::DLLImport, R, SI, false, false) | |||
2731 | { | |||
2732 | } | |||
2733 | ||||
2734 | DLLImportAttr *clone(ASTContext &C) const; | |||
2735 | void printPretty(raw_ostream &OS, | |||
2736 | const PrintingPolicy &Policy) const; | |||
2737 | const char *getSpelling() const; | |||
2738 | ||||
2739 | private: | |||
2740 | bool PropagatedToBaseTemplate = false; | |||
2741 | ||||
2742 | public: | |||
2743 | void setPropagatedToBaseTemplate() { PropagatedToBaseTemplate = true; } | |||
2744 | bool wasPropagatedToBaseTemplate() { return PropagatedToBaseTemplate; } | |||
2745 | ||||
2746 | ||||
2747 | static bool classof(const Attr *A) { return A->getKind() == attr::DLLImport; } | |||
2748 | }; | |||
2749 | ||||
2750 | class DLLImportStaticLocalAttr : public InheritableAttr { | |||
2751 | public: | |||
2752 | static DLLImportStaticLocalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2753 | auto *A = new (Ctx) DLLImportStaticLocalAttr(Loc, Ctx, 0); | |||
2754 | A->setImplicit(true); | |||
2755 | return A; | |||
2756 | } | |||
2757 | ||||
2758 | DLLImportStaticLocalAttr(SourceRange R, ASTContext &Ctx | |||
2759 | , unsigned SI | |||
2760 | ) | |||
2761 | : InheritableAttr(attr::DLLImportStaticLocal, R, SI, false, false) | |||
2762 | { | |||
2763 | } | |||
2764 | ||||
2765 | DLLImportStaticLocalAttr *clone(ASTContext &C) const; | |||
2766 | void printPretty(raw_ostream &OS, | |||
2767 | const PrintingPolicy &Policy) const; | |||
2768 | const char *getSpelling() const; | |||
2769 | ||||
2770 | ||||
2771 | static bool classof(const Attr *A) { return A->getKind() == attr::DLLImportStaticLocal; } | |||
2772 | }; | |||
2773 | ||||
2774 | class DeprecatedAttr : public InheritableAttr { | |||
2775 | unsigned messageLength; | |||
2776 | char *message; | |||
2777 | ||||
2778 | unsigned replacementLength; | |||
2779 | char *replacement; | |||
2780 | ||||
2781 | public: | |||
2782 | static DeprecatedAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Message, llvm::StringRef Replacement, SourceRange Loc = SourceRange()) { | |||
2783 | auto *A = new (Ctx) DeprecatedAttr(Loc, Ctx, Message, Replacement, 0); | |||
2784 | A->setImplicit(true); | |||
2785 | return A; | |||
2786 | } | |||
2787 | ||||
2788 | DeprecatedAttr(SourceRange R, ASTContext &Ctx | |||
2789 | , llvm::StringRef Message | |||
2790 | , llvm::StringRef Replacement | |||
2791 | , unsigned SI | |||
2792 | ) | |||
2793 | : InheritableAttr(attr::Deprecated, R, SI, false, false) | |||
2794 | , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength]) | |||
2795 | , replacementLength(Replacement.size()),replacement(new (Ctx, 1) char[replacementLength]) | |||
2796 | { | |||
2797 | if (!Message.empty()) | |||
2798 | std::memcpy(message, Message.data(), messageLength); | |||
2799 | if (!Replacement.empty()) | |||
2800 | std::memcpy(replacement, Replacement.data(), replacementLength); | |||
2801 | } | |||
2802 | ||||
2803 | DeprecatedAttr(SourceRange R, ASTContext &Ctx | |||
2804 | , unsigned SI | |||
2805 | ) | |||
2806 | : InheritableAttr(attr::Deprecated, R, SI, false, false) | |||
2807 | , messageLength(0),message(nullptr) | |||
2808 | , replacementLength(0),replacement(nullptr) | |||
2809 | { | |||
2810 | } | |||
2811 | ||||
2812 | DeprecatedAttr *clone(ASTContext &C) const; | |||
2813 | void printPretty(raw_ostream &OS, | |||
2814 | const PrintingPolicy &Policy) const; | |||
2815 | const char *getSpelling() const; | |||
2816 | llvm::StringRef getMessage() const { | |||
2817 | return llvm::StringRef(message, messageLength); | |||
2818 | } | |||
2819 | unsigned getMessageLength() const { | |||
2820 | return messageLength; | |||
2821 | } | |||
2822 | void setMessage(ASTContext &C, llvm::StringRef S) { | |||
2823 | messageLength = S.size(); | |||
2824 | this->message = new (C, 1) char [messageLength]; | |||
2825 | if (!S.empty()) | |||
2826 | std::memcpy(this->message, S.data(), messageLength); | |||
2827 | } | |||
2828 | ||||
2829 | llvm::StringRef getReplacement() const { | |||
2830 | return llvm::StringRef(replacement, replacementLength); | |||
2831 | } | |||
2832 | unsigned getReplacementLength() const { | |||
2833 | return replacementLength; | |||
2834 | } | |||
2835 | void setReplacement(ASTContext &C, llvm::StringRef S) { | |||
2836 | replacementLength = S.size(); | |||
2837 | this->replacement = new (C, 1) char [replacementLength]; | |||
2838 | if (!S.empty()) | |||
2839 | std::memcpy(this->replacement, S.data(), replacementLength); | |||
2840 | } | |||
2841 | ||||
2842 | ||||
2843 | ||||
2844 | static bool classof(const Attr *A) { return A->getKind() == attr::Deprecated; } | |||
2845 | }; | |||
2846 | ||||
2847 | class DestructorAttr : public InheritableAttr { | |||
2848 | int priority; | |||
2849 | ||||
2850 | public: | |||
2851 | static DestructorAttr *CreateImplicit(ASTContext &Ctx, int Priority, SourceRange Loc = SourceRange()) { | |||
2852 | auto *A = new (Ctx) DestructorAttr(Loc, Ctx, Priority, 0); | |||
2853 | A->setImplicit(true); | |||
2854 | return A; | |||
2855 | } | |||
2856 | ||||
2857 | DestructorAttr(SourceRange R, ASTContext &Ctx | |||
2858 | , int Priority | |||
2859 | , unsigned SI | |||
2860 | ) | |||
2861 | : InheritableAttr(attr::Destructor, R, SI, false, false) | |||
2862 | , priority(Priority) | |||
2863 | { | |||
2864 | } | |||
2865 | ||||
2866 | DestructorAttr(SourceRange R, ASTContext &Ctx | |||
2867 | , unsigned SI | |||
2868 | ) | |||
2869 | : InheritableAttr(attr::Destructor, R, SI, false, false) | |||
2870 | , priority() | |||
2871 | { | |||
2872 | } | |||
2873 | ||||
2874 | DestructorAttr *clone(ASTContext &C) const; | |||
2875 | void printPretty(raw_ostream &OS, | |||
2876 | const PrintingPolicy &Policy) const; | |||
2877 | const char *getSpelling() const; | |||
2878 | int getPriority() const { | |||
2879 | return priority; | |||
2880 | } | |||
2881 | ||||
2882 | static const int DefaultPriority = 65535; | |||
2883 | ||||
2884 | ||||
2885 | ||||
2886 | static bool classof(const Attr *A) { return A->getKind() == attr::Destructor; } | |||
2887 | }; | |||
2888 | ||||
2889 | class DiagnoseIfAttr : public InheritableAttr { | |||
2890 | Expr * cond; | |||
2891 | ||||
2892 | unsigned messageLength; | |||
2893 | char *message; | |||
2894 | ||||
2895 | public: | |||
2896 | enum DiagnosticType { | |||
2897 | DT_Error, | |||
2898 | DT_Warning | |||
2899 | }; | |||
2900 | private: | |||
2901 | DiagnosticType diagnosticType; | |||
2902 | ||||
2903 | bool argDependent; | |||
2904 | ||||
2905 | NamedDecl * parent; | |||
2906 | ||||
2907 | public: | |||
2908 | static DiagnoseIfAttr *CreateImplicit(ASTContext &Ctx, Expr * Cond, llvm::StringRef Message, DiagnosticType DiagnosticType, bool ArgDependent, NamedDecl * Parent, SourceRange Loc = SourceRange()) { | |||
2909 | auto *A = new (Ctx) DiagnoseIfAttr(Loc, Ctx, Cond, Message, DiagnosticType, ArgDependent, Parent, 0); | |||
2910 | A->setImplicit(true); | |||
2911 | return A; | |||
2912 | } | |||
2913 | ||||
2914 | static DiagnoseIfAttr *CreateImplicit(ASTContext &Ctx, Expr * Cond, llvm::StringRef Message, DiagnosticType DiagnosticType, SourceRange Loc = SourceRange()) { | |||
2915 | auto *A = new (Ctx) DiagnoseIfAttr(Loc, Ctx, Cond, Message, DiagnosticType, 0); | |||
2916 | A->setImplicit(true); | |||
2917 | return A; | |||
2918 | } | |||
2919 | ||||
2920 | DiagnoseIfAttr(SourceRange R, ASTContext &Ctx | |||
2921 | , Expr * Cond | |||
2922 | , llvm::StringRef Message | |||
2923 | , DiagnosticType DiagnosticType | |||
2924 | , bool ArgDependent | |||
2925 | , NamedDecl * Parent | |||
2926 | , unsigned SI | |||
2927 | ) | |||
2928 | : InheritableAttr(attr::DiagnoseIf, R, SI, true, true) | |||
2929 | , cond(Cond) | |||
2930 | , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength]) | |||
2931 | , diagnosticType(DiagnosticType) | |||
2932 | , argDependent(ArgDependent) | |||
2933 | , parent(Parent) | |||
2934 | { | |||
2935 | if (!Message.empty()) | |||
2936 | std::memcpy(message, Message.data(), messageLength); | |||
2937 | } | |||
2938 | ||||
2939 | DiagnoseIfAttr(SourceRange R, ASTContext &Ctx | |||
2940 | , Expr * Cond | |||
2941 | , llvm::StringRef Message | |||
2942 | , DiagnosticType DiagnosticType | |||
2943 | , unsigned SI | |||
2944 | ) | |||
2945 | : InheritableAttr(attr::DiagnoseIf, R, SI, true, true) | |||
2946 | , cond(Cond) | |||
2947 | , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength]) | |||
2948 | , diagnosticType(DiagnosticType) | |||
2949 | , argDependent() | |||
2950 | , parent() | |||
2951 | { | |||
2952 | if (!Message.empty()) | |||
2953 | std::memcpy(message, Message.data(), messageLength); | |||
2954 | } | |||
2955 | ||||
2956 | DiagnoseIfAttr *clone(ASTContext &C) const; | |||
2957 | void printPretty(raw_ostream &OS, | |||
2958 | const PrintingPolicy &Policy) const; | |||
2959 | const char *getSpelling() const; | |||
2960 | Expr * getCond() const { | |||
2961 | return cond; | |||
2962 | } | |||
2963 | ||||
2964 | llvm::StringRef getMessage() const { | |||
2965 | return llvm::StringRef(message, messageLength); | |||
2966 | } | |||
2967 | unsigned getMessageLength() const { | |||
2968 | return messageLength; | |||
2969 | } | |||
2970 | void setMessage(ASTContext &C, llvm::StringRef S) { | |||
2971 | messageLength = S.size(); | |||
2972 | this->message = new (C, 1) char [messageLength]; | |||
2973 | if (!S.empty()) | |||
2974 | std::memcpy(this->message, S.data(), messageLength); | |||
2975 | } | |||
2976 | ||||
2977 | DiagnosticType getDiagnosticType() const { | |||
2978 | return diagnosticType; | |||
2979 | } | |||
2980 | ||||
2981 | static bool ConvertStrToDiagnosticType(StringRef Val, DiagnosticType &Out) { | |||
2982 | Optional<DiagnosticType> R = llvm::StringSwitch<Optional<DiagnosticType>>(Val) | |||
2983 | .Case("error", DiagnoseIfAttr::DT_Error) | |||
2984 | .Case("warning", DiagnoseIfAttr::DT_Warning) | |||
2985 | .Default(Optional<DiagnosticType>()); | |||
2986 | if (R) { | |||
2987 | Out = *R; | |||
2988 | return true; | |||
2989 | } | |||
2990 | return false; | |||
2991 | } | |||
2992 | ||||
2993 | static const char *ConvertDiagnosticTypeToStr(DiagnosticType Val) { | |||
2994 | switch(Val) { | |||
2995 | case DiagnoseIfAttr::DT_Error: return "error"; | |||
2996 | case DiagnoseIfAttr::DT_Warning: return "warning"; | |||
2997 | } | |||
2998 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 2998); | |||
2999 | } | |||
3000 | bool getArgDependent() const { | |||
3001 | return argDependent; | |||
3002 | } | |||
3003 | ||||
3004 | NamedDecl * getParent() const { | |||
3005 | return parent; | |||
3006 | } | |||
3007 | ||||
3008 | ||||
3009 | bool isError() const { return diagnosticType == DT_Error; } | |||
3010 | bool isWarning() const { return diagnosticType == DT_Warning; } | |||
3011 | ||||
3012 | ||||
3013 | static bool classof(const Attr *A) { return A->getKind() == attr::DiagnoseIf; } | |||
3014 | }; | |||
3015 | ||||
3016 | class DisableTailCallsAttr : public InheritableAttr { | |||
3017 | public: | |||
3018 | static DisableTailCallsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3019 | auto *A = new (Ctx) DisableTailCallsAttr(Loc, Ctx, 0); | |||
3020 | A->setImplicit(true); | |||
3021 | return A; | |||
3022 | } | |||
3023 | ||||
3024 | DisableTailCallsAttr(SourceRange R, ASTContext &Ctx | |||
3025 | , unsigned SI | |||
3026 | ) | |||
3027 | : InheritableAttr(attr::DisableTailCalls, R, SI, false, false) | |||
3028 | { | |||
3029 | } | |||
3030 | ||||
3031 | DisableTailCallsAttr *clone(ASTContext &C) const; | |||
3032 | void printPretty(raw_ostream &OS, | |||
3033 | const PrintingPolicy &Policy) const; | |||
3034 | const char *getSpelling() const; | |||
3035 | ||||
3036 | ||||
3037 | static bool classof(const Attr *A) { return A->getKind() == attr::DisableTailCalls; } | |||
3038 | }; | |||
3039 | ||||
3040 | class EmptyBasesAttr : public InheritableAttr { | |||
3041 | public: | |||
3042 | static EmptyBasesAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3043 | auto *A = new (Ctx) EmptyBasesAttr(Loc, Ctx, 0); | |||
3044 | A->setImplicit(true); | |||
3045 | return A; | |||
3046 | } | |||
3047 | ||||
3048 | EmptyBasesAttr(SourceRange R, ASTContext &Ctx | |||
3049 | , unsigned SI | |||
3050 | ) | |||
3051 | : InheritableAttr(attr::EmptyBases, R, SI, false, false) | |||
3052 | { | |||
3053 | } | |||
3054 | ||||
3055 | EmptyBasesAttr *clone(ASTContext &C) const; | |||
3056 | void printPretty(raw_ostream &OS, | |||
3057 | const PrintingPolicy &Policy) const; | |||
3058 | const char *getSpelling() const; | |||
3059 | ||||
3060 | ||||
3061 | static bool classof(const Attr *A) { return A->getKind() == attr::EmptyBases; } | |||
3062 | }; | |||
3063 | ||||
3064 | class EnableIfAttr : public InheritableAttr { | |||
3065 | Expr * cond; | |||
3066 | ||||
3067 | unsigned messageLength; | |||
3068 | char *message; | |||
3069 | ||||
3070 | public: | |||
3071 | static EnableIfAttr *CreateImplicit(ASTContext &Ctx, Expr * Cond, llvm::StringRef Message, SourceRange Loc = SourceRange()) { | |||
3072 | auto *A = new (Ctx) EnableIfAttr(Loc, Ctx, Cond, Message, 0); | |||
3073 | A->setImplicit(true); | |||
3074 | return A; | |||
3075 | } | |||
3076 | ||||
3077 | EnableIfAttr(SourceRange R, ASTContext &Ctx | |||
3078 | , Expr * Cond | |||
3079 | , llvm::StringRef Message | |||
3080 | , unsigned SI | |||
3081 | ) | |||
3082 | : InheritableAttr(attr::EnableIf, R, SI, false, false) | |||
3083 | , cond(Cond) | |||
3084 | , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength]) | |||
3085 | { | |||
3086 | if (!Message.empty()) | |||
3087 | std::memcpy(message, Message.data(), messageLength); | |||
3088 | } | |||
3089 | ||||
3090 | EnableIfAttr *clone(ASTContext &C) const; | |||
3091 | void printPretty(raw_ostream &OS, | |||
3092 | const PrintingPolicy &Policy) const; | |||
3093 | const char *getSpelling() const; | |||
3094 | Expr * getCond() const { | |||
3095 | return cond; | |||
3096 | } | |||
3097 | ||||
3098 | llvm::StringRef getMessage() const { | |||
3099 | return llvm::StringRef(message, messageLength); | |||
3100 | } | |||
3101 | unsigned getMessageLength() const { | |||
3102 | return messageLength; | |||
3103 | } | |||
3104 | void setMessage(ASTContext &C, llvm::StringRef S) { | |||
3105 | messageLength = S.size(); | |||
3106 | this->message = new (C, 1) char [messageLength]; | |||
3107 | if (!S.empty()) | |||
3108 | std::memcpy(this->message, S.data(), messageLength); | |||
3109 | } | |||
3110 | ||||
3111 | ||||
3112 | ||||
3113 | static bool classof(const Attr *A) { return A->getKind() == attr::EnableIf; } | |||
3114 | }; | |||
3115 | ||||
3116 | class EnumExtensibilityAttr : public InheritableAttr { | |||
3117 | public: | |||
3118 | enum Kind { | |||
3119 | Closed, | |||
3120 | Open | |||
3121 | }; | |||
3122 | private: | |||
3123 | Kind extensibility; | |||
3124 | ||||
3125 | public: | |||
3126 | static EnumExtensibilityAttr *CreateImplicit(ASTContext &Ctx, Kind Extensibility, SourceRange Loc = SourceRange()) { | |||
3127 | auto *A = new (Ctx) EnumExtensibilityAttr(Loc, Ctx, Extensibility, 0); | |||
3128 | A->setImplicit(true); | |||
3129 | return A; | |||
3130 | } | |||
3131 | ||||
3132 | EnumExtensibilityAttr(SourceRange R, ASTContext &Ctx | |||
3133 | , Kind Extensibility | |||
3134 | , unsigned SI | |||
3135 | ) | |||
3136 | : InheritableAttr(attr::EnumExtensibility, R, SI, false, false) | |||
3137 | , extensibility(Extensibility) | |||
3138 | { | |||
3139 | } | |||
3140 | ||||
3141 | EnumExtensibilityAttr *clone(ASTContext &C) const; | |||
3142 | void printPretty(raw_ostream &OS, | |||
3143 | const PrintingPolicy &Policy) const; | |||
3144 | const char *getSpelling() const; | |||
3145 | Kind getExtensibility() const { | |||
3146 | return extensibility; | |||
3147 | } | |||
3148 | ||||
3149 | static bool ConvertStrToKind(StringRef Val, Kind &Out) { | |||
3150 | Optional<Kind> R = llvm::StringSwitch<Optional<Kind>>(Val) | |||
3151 | .Case("closed", EnumExtensibilityAttr::Closed) | |||
3152 | .Case("open", EnumExtensibilityAttr::Open) | |||
3153 | .Default(Optional<Kind>()); | |||
3154 | if (R) { | |||
3155 | Out = *R; | |||
3156 | return true; | |||
3157 | } | |||
3158 | return false; | |||
3159 | } | |||
3160 | ||||
3161 | static const char *ConvertKindToStr(Kind Val) { | |||
3162 | switch(Val) { | |||
3163 | case EnumExtensibilityAttr::Closed: return "closed"; | |||
3164 | case EnumExtensibilityAttr::Open: return "open"; | |||
3165 | } | |||
3166 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 3166); | |||
3167 | } | |||
3168 | ||||
3169 | ||||
3170 | static bool classof(const Attr *A) { return A->getKind() == attr::EnumExtensibility; } | |||
3171 | }; | |||
3172 | ||||
3173 | class ExcludeFromExplicitInstantiationAttr : public InheritableAttr { | |||
3174 | public: | |||
3175 | static ExcludeFromExplicitInstantiationAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3176 | auto *A = new (Ctx) ExcludeFromExplicitInstantiationAttr(Loc, Ctx, 0); | |||
3177 | A->setImplicit(true); | |||
3178 | return A; | |||
3179 | } | |||
3180 | ||||
3181 | ExcludeFromExplicitInstantiationAttr(SourceRange R, ASTContext &Ctx | |||
3182 | , unsigned SI | |||
3183 | ) | |||
3184 | : InheritableAttr(attr::ExcludeFromExplicitInstantiation, R, SI, false, false) | |||
3185 | { | |||
3186 | } | |||
3187 | ||||
3188 | ExcludeFromExplicitInstantiationAttr *clone(ASTContext &C) const; | |||
3189 | void printPretty(raw_ostream &OS, | |||
3190 | const PrintingPolicy &Policy) const; | |||
3191 | const char *getSpelling() const; | |||
3192 | ||||
3193 | ||||
3194 | static bool classof(const Attr *A) { return A->getKind() == attr::ExcludeFromExplicitInstantiation; } | |||
3195 | }; | |||
3196 | ||||
3197 | class ExclusiveTrylockFunctionAttr : public InheritableAttr { | |||
3198 | Expr * successValue; | |||
3199 | ||||
3200 | unsigned args_Size; | |||
3201 | Expr * *args_; | |||
3202 | ||||
3203 | public: | |||
3204 | static ExclusiveTrylockFunctionAttr *CreateImplicit(ASTContext &Ctx, Expr * SuccessValue, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
3205 | auto *A = new (Ctx) ExclusiveTrylockFunctionAttr(Loc, Ctx, SuccessValue, Args, ArgsSize, 0); | |||
3206 | A->setImplicit(true); | |||
3207 | return A; | |||
3208 | } | |||
3209 | ||||
3210 | ExclusiveTrylockFunctionAttr(SourceRange R, ASTContext &Ctx | |||
3211 | , Expr * SuccessValue | |||
3212 | , Expr * *Args, unsigned ArgsSize | |||
3213 | , unsigned SI | |||
3214 | ) | |||
3215 | : InheritableAttr(attr::ExclusiveTrylockFunction, R, SI, true, true) | |||
3216 | , successValue(SuccessValue) | |||
3217 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
3218 | { | |||
3219 | std::copy(Args, Args + args_Size, args_); | |||
3220 | } | |||
3221 | ||||
3222 | ExclusiveTrylockFunctionAttr(SourceRange R, ASTContext &Ctx | |||
3223 | , Expr * SuccessValue | |||
3224 | , unsigned SI | |||
3225 | ) | |||
3226 | : InheritableAttr(attr::ExclusiveTrylockFunction, R, SI, true, true) | |||
3227 | , successValue(SuccessValue) | |||
3228 | , args_Size(0), args_(nullptr) | |||
3229 | { | |||
3230 | } | |||
3231 | ||||
3232 | ExclusiveTrylockFunctionAttr *clone(ASTContext &C) const; | |||
3233 | void printPretty(raw_ostream &OS, | |||
3234 | const PrintingPolicy &Policy) const; | |||
3235 | const char *getSpelling() const; | |||
3236 | Expr * getSuccessValue() const { | |||
3237 | return successValue; | |||
3238 | } | |||
3239 | ||||
3240 | typedef Expr ** args_iterator; | |||
3241 | args_iterator args_begin() const { return args_; } | |||
3242 | args_iterator args_end() const { return args_ + args_Size; } | |||
3243 | unsigned args_size() const { return args_Size; } | |||
3244 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
3245 | ||||
3246 | ||||
3247 | ||||
3248 | ||||
3249 | static bool classof(const Attr *A) { return A->getKind() == attr::ExclusiveTrylockFunction; } | |||
3250 | }; | |||
3251 | ||||
3252 | class ExternalSourceSymbolAttr : public InheritableAttr { | |||
3253 | unsigned languageLength; | |||
3254 | char *language; | |||
3255 | ||||
3256 | unsigned definedInLength; | |||
3257 | char *definedIn; | |||
3258 | ||||
3259 | bool generatedDeclaration; | |||
3260 | ||||
3261 | public: | |||
3262 | static ExternalSourceSymbolAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Language, llvm::StringRef DefinedIn, bool GeneratedDeclaration, SourceRange Loc = SourceRange()) { | |||
3263 | auto *A = new (Ctx) ExternalSourceSymbolAttr(Loc, Ctx, Language, DefinedIn, GeneratedDeclaration, 0); | |||
3264 | A->setImplicit(true); | |||
3265 | return A; | |||
3266 | } | |||
3267 | ||||
3268 | ExternalSourceSymbolAttr(SourceRange R, ASTContext &Ctx | |||
3269 | , llvm::StringRef Language | |||
3270 | , llvm::StringRef DefinedIn | |||
3271 | , bool GeneratedDeclaration | |||
3272 | , unsigned SI | |||
3273 | ) | |||
3274 | : InheritableAttr(attr::ExternalSourceSymbol, R, SI, false, false) | |||
3275 | , languageLength(Language.size()),language(new (Ctx, 1) char[languageLength]) | |||
3276 | , definedInLength(DefinedIn.size()),definedIn(new (Ctx, 1) char[definedInLength]) | |||
3277 | , generatedDeclaration(GeneratedDeclaration) | |||
3278 | { | |||
3279 | if (!Language.empty()) | |||
3280 | std::memcpy(language, Language.data(), languageLength); | |||
3281 | if (!DefinedIn.empty()) | |||
3282 | std::memcpy(definedIn, DefinedIn.data(), definedInLength); | |||
3283 | } | |||
3284 | ||||
3285 | ExternalSourceSymbolAttr(SourceRange R, ASTContext &Ctx | |||
3286 | , unsigned SI | |||
3287 | ) | |||
3288 | : InheritableAttr(attr::ExternalSourceSymbol, R, SI, false, false) | |||
3289 | , languageLength(0),language(nullptr) | |||
3290 | , definedInLength(0),definedIn(nullptr) | |||
3291 | , generatedDeclaration() | |||
3292 | { | |||
3293 | } | |||
3294 | ||||
3295 | ExternalSourceSymbolAttr *clone(ASTContext &C) const; | |||
3296 | void printPretty(raw_ostream &OS, | |||
3297 | const PrintingPolicy &Policy) const; | |||
3298 | const char *getSpelling() const; | |||
3299 | llvm::StringRef getLanguage() const { | |||
3300 | return llvm::StringRef(language, languageLength); | |||
3301 | } | |||
3302 | unsigned getLanguageLength() const { | |||
3303 | return languageLength; | |||
3304 | } | |||
3305 | void setLanguage(ASTContext &C, llvm::StringRef S) { | |||
3306 | languageLength = S.size(); | |||
3307 | this->language = new (C, 1) char [languageLength]; | |||
3308 | if (!S.empty()) | |||
3309 | std::memcpy(this->language, S.data(), languageLength); | |||
3310 | } | |||
3311 | ||||
3312 | llvm::StringRef getDefinedIn() const { | |||
3313 | return llvm::StringRef(definedIn, definedInLength); | |||
3314 | } | |||
3315 | unsigned getDefinedInLength() const { | |||
3316 | return definedInLength; | |||
3317 | } | |||
3318 | void setDefinedIn(ASTContext &C, llvm::StringRef S) { | |||
3319 | definedInLength = S.size(); | |||
3320 | this->definedIn = new (C, 1) char [definedInLength]; | |||
3321 | if (!S.empty()) | |||
3322 | std::memcpy(this->definedIn, S.data(), definedInLength); | |||
3323 | } | |||
3324 | ||||
3325 | bool getGeneratedDeclaration() const { | |||
3326 | return generatedDeclaration; | |||
3327 | } | |||
3328 | ||||
3329 | ||||
3330 | ||||
3331 | static bool classof(const Attr *A) { return A->getKind() == attr::ExternalSourceSymbol; } | |||
3332 | }; | |||
3333 | ||||
3334 | class FallThroughAttr : public StmtAttr { | |||
3335 | public: | |||
3336 | static FallThroughAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3337 | auto *A = new (Ctx) FallThroughAttr(Loc, Ctx, 0); | |||
3338 | A->setImplicit(true); | |||
3339 | return A; | |||
3340 | } | |||
3341 | ||||
3342 | FallThroughAttr(SourceRange R, ASTContext &Ctx | |||
3343 | , unsigned SI | |||
3344 | ) | |||
3345 | : StmtAttr(attr::FallThrough, R, SI, false) | |||
3346 | { | |||
3347 | } | |||
3348 | ||||
3349 | FallThroughAttr *clone(ASTContext &C) const; | |||
3350 | void printPretty(raw_ostream &OS, | |||
3351 | const PrintingPolicy &Policy) const; | |||
3352 | const char *getSpelling() const; | |||
3353 | ||||
3354 | ||||
3355 | static bool classof(const Attr *A) { return A->getKind() == attr::FallThrough; } | |||
3356 | }; | |||
3357 | ||||
3358 | class FastCallAttr : public InheritableAttr { | |||
3359 | public: | |||
3360 | static FastCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3361 | auto *A = new (Ctx) FastCallAttr(Loc, Ctx, 0); | |||
3362 | A->setImplicit(true); | |||
3363 | return A; | |||
3364 | } | |||
3365 | ||||
3366 | FastCallAttr(SourceRange R, ASTContext &Ctx | |||
3367 | , unsigned SI | |||
3368 | ) | |||
3369 | : InheritableAttr(attr::FastCall, R, SI, false, false) | |||
3370 | { | |||
3371 | } | |||
3372 | ||||
3373 | FastCallAttr *clone(ASTContext &C) const; | |||
3374 | void printPretty(raw_ostream &OS, | |||
3375 | const PrintingPolicy &Policy) const; | |||
3376 | const char *getSpelling() const; | |||
3377 | ||||
3378 | ||||
3379 | static bool classof(const Attr *A) { return A->getKind() == attr::FastCall; } | |||
3380 | }; | |||
3381 | ||||
3382 | class FinalAttr : public InheritableAttr { | |||
3383 | public: | |||
3384 | enum Spelling { | |||
3385 | Keyword_final = 0, | |||
3386 | Keyword_sealed = 1 | |||
3387 | }; | |||
3388 | ||||
3389 | static FinalAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
3390 | auto *A = new (Ctx) FinalAttr(Loc, Ctx, S); | |||
3391 | A->setImplicit(true); | |||
3392 | return A; | |||
3393 | } | |||
3394 | ||||
3395 | FinalAttr(SourceRange R, ASTContext &Ctx | |||
3396 | , unsigned SI | |||
3397 | ) | |||
3398 | : InheritableAttr(attr::Final, R, SI, false, false) | |||
3399 | { | |||
3400 | } | |||
3401 | ||||
3402 | FinalAttr *clone(ASTContext &C) const; | |||
3403 | void printPretty(raw_ostream &OS, | |||
3404 | const PrintingPolicy &Policy) const; | |||
3405 | const char *getSpelling() const; | |||
3406 | Spelling getSemanticSpelling() const { | |||
3407 | switch (SpellingListIndex) { | |||
3408 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 3408); | |||
3409 | case 0: return Keyword_final; | |||
3410 | case 1: return Keyword_sealed; | |||
3411 | } | |||
3412 | } | |||
3413 | bool isSpelledAsSealed() const { return SpellingListIndex == 1; } | |||
3414 | ||||
3415 | ||||
3416 | static bool classof(const Attr *A) { return A->getKind() == attr::Final; } | |||
3417 | }; | |||
3418 | ||||
3419 | class FlagEnumAttr : public InheritableAttr { | |||
3420 | public: | |||
3421 | static FlagEnumAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3422 | auto *A = new (Ctx) FlagEnumAttr(Loc, Ctx, 0); | |||
3423 | A->setImplicit(true); | |||
3424 | return A; | |||
3425 | } | |||
3426 | ||||
3427 | FlagEnumAttr(SourceRange R, ASTContext &Ctx | |||
3428 | , unsigned SI | |||
3429 | ) | |||
3430 | : InheritableAttr(attr::FlagEnum, R, SI, false, false) | |||
3431 | { | |||
3432 | } | |||
3433 | ||||
3434 | FlagEnumAttr *clone(ASTContext &C) const; | |||
3435 | void printPretty(raw_ostream &OS, | |||
3436 | const PrintingPolicy &Policy) const; | |||
3437 | const char *getSpelling() const; | |||
3438 | ||||
3439 | ||||
3440 | static bool classof(const Attr *A) { return A->getKind() == attr::FlagEnum; } | |||
3441 | }; | |||
3442 | ||||
3443 | class FlattenAttr : public InheritableAttr { | |||
3444 | public: | |||
3445 | static FlattenAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3446 | auto *A = new (Ctx) FlattenAttr(Loc, Ctx, 0); | |||
3447 | A->setImplicit(true); | |||
3448 | return A; | |||
3449 | } | |||
3450 | ||||
3451 | FlattenAttr(SourceRange R, ASTContext &Ctx | |||
3452 | , unsigned SI | |||
3453 | ) | |||
3454 | : InheritableAttr(attr::Flatten, R, SI, false, false) | |||
3455 | { | |||
3456 | } | |||
3457 | ||||
3458 | FlattenAttr *clone(ASTContext &C) const; | |||
3459 | void printPretty(raw_ostream &OS, | |||
3460 | const PrintingPolicy &Policy) const; | |||
3461 | const char *getSpelling() const; | |||
3462 | ||||
3463 | ||||
3464 | static bool classof(const Attr *A) { return A->getKind() == attr::Flatten; } | |||
3465 | }; | |||
3466 | ||||
3467 | class FormatAttr : public InheritableAttr { | |||
3468 | IdentifierInfo * type; | |||
3469 | ||||
3470 | int formatIdx; | |||
3471 | ||||
3472 | int firstArg; | |||
3473 | ||||
3474 | public: | |||
3475 | static FormatAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Type, int FormatIdx, int FirstArg, SourceRange Loc = SourceRange()) { | |||
3476 | auto *A = new (Ctx) FormatAttr(Loc, Ctx, Type, FormatIdx, FirstArg, 0); | |||
3477 | A->setImplicit(true); | |||
3478 | return A; | |||
3479 | } | |||
3480 | ||||
3481 | FormatAttr(SourceRange R, ASTContext &Ctx | |||
3482 | , IdentifierInfo * Type | |||
3483 | , int FormatIdx | |||
3484 | , int FirstArg | |||
3485 | , unsigned SI | |||
3486 | ) | |||
3487 | : InheritableAttr(attr::Format, R, SI, false, false) | |||
3488 | , type(Type) | |||
3489 | , formatIdx(FormatIdx) | |||
3490 | , firstArg(FirstArg) | |||
3491 | { | |||
3492 | } | |||
3493 | ||||
3494 | FormatAttr *clone(ASTContext &C) const; | |||
3495 | void printPretty(raw_ostream &OS, | |||
3496 | const PrintingPolicy &Policy) const; | |||
3497 | const char *getSpelling() const; | |||
3498 | IdentifierInfo * getType() const { | |||
3499 | return type; | |||
3500 | } | |||
3501 | ||||
3502 | int getFormatIdx() const { | |||
3503 | return formatIdx; | |||
3504 | } | |||
3505 | ||||
3506 | int getFirstArg() const { | |||
3507 | return firstArg; | |||
3508 | } | |||
3509 | ||||
3510 | ||||
3511 | ||||
3512 | static bool classof(const Attr *A) { return A->getKind() == attr::Format; } | |||
3513 | }; | |||
3514 | ||||
3515 | class FormatArgAttr : public InheritableAttr { | |||
3516 | ParamIdx formatIdx; | |||
3517 | ||||
3518 | public: | |||
3519 | static FormatArgAttr *CreateImplicit(ASTContext &Ctx, ParamIdx FormatIdx, SourceRange Loc = SourceRange()) { | |||
3520 | auto *A = new (Ctx) FormatArgAttr(Loc, Ctx, FormatIdx, 0); | |||
3521 | A->setImplicit(true); | |||
3522 | return A; | |||
3523 | } | |||
3524 | ||||
3525 | FormatArgAttr(SourceRange R, ASTContext &Ctx | |||
3526 | , ParamIdx FormatIdx | |||
3527 | , unsigned SI | |||
3528 | ) | |||
3529 | : InheritableAttr(attr::FormatArg, R, SI, false, false) | |||
3530 | , formatIdx(FormatIdx) | |||
3531 | { | |||
3532 | } | |||
3533 | ||||
3534 | FormatArgAttr *clone(ASTContext &C) const; | |||
3535 | void printPretty(raw_ostream &OS, | |||
3536 | const PrintingPolicy &Policy) const; | |||
3537 | const char *getSpelling() const; | |||
3538 | ParamIdx getFormatIdx() const { | |||
3539 | return formatIdx; | |||
3540 | } | |||
3541 | ||||
3542 | ||||
3543 | ||||
3544 | static bool classof(const Attr *A) { return A->getKind() == attr::FormatArg; } | |||
3545 | }; | |||
3546 | ||||
3547 | class GNUInlineAttr : public InheritableAttr { | |||
3548 | public: | |||
3549 | static GNUInlineAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3550 | auto *A = new (Ctx) GNUInlineAttr(Loc, Ctx, 0); | |||
3551 | A->setImplicit(true); | |||
3552 | return A; | |||
3553 | } | |||
3554 | ||||
3555 | GNUInlineAttr(SourceRange R, ASTContext &Ctx | |||
3556 | , unsigned SI | |||
3557 | ) | |||
3558 | : InheritableAttr(attr::GNUInline, R, SI, false, false) | |||
3559 | { | |||
3560 | } | |||
3561 | ||||
3562 | GNUInlineAttr *clone(ASTContext &C) const; | |||
3563 | void printPretty(raw_ostream &OS, | |||
3564 | const PrintingPolicy &Policy) const; | |||
3565 | const char *getSpelling() const; | |||
3566 | ||||
3567 | ||||
3568 | static bool classof(const Attr *A) { return A->getKind() == attr::GNUInline; } | |||
3569 | }; | |||
3570 | ||||
3571 | class GuardedByAttr : public InheritableAttr { | |||
3572 | Expr * arg; | |||
3573 | ||||
3574 | public: | |||
3575 | static GuardedByAttr *CreateImplicit(ASTContext &Ctx, Expr * Arg, SourceRange Loc = SourceRange()) { | |||
3576 | auto *A = new (Ctx) GuardedByAttr(Loc, Ctx, Arg, 0); | |||
3577 | A->setImplicit(true); | |||
3578 | return A; | |||
3579 | } | |||
3580 | ||||
3581 | GuardedByAttr(SourceRange R, ASTContext &Ctx | |||
3582 | , Expr * Arg | |||
3583 | , unsigned SI | |||
3584 | ) | |||
3585 | : InheritableAttr(attr::GuardedBy, R, SI, true, true) | |||
3586 | , arg(Arg) | |||
3587 | { | |||
3588 | } | |||
3589 | ||||
3590 | GuardedByAttr *clone(ASTContext &C) const; | |||
3591 | void printPretty(raw_ostream &OS, | |||
3592 | const PrintingPolicy &Policy) const; | |||
3593 | const char *getSpelling() const; | |||
3594 | Expr * getArg() const { | |||
3595 | return arg; | |||
3596 | } | |||
3597 | ||||
3598 | ||||
3599 | ||||
3600 | static bool classof(const Attr *A) { return A->getKind() == attr::GuardedBy; } | |||
3601 | }; | |||
3602 | ||||
3603 | class GuardedVarAttr : public InheritableAttr { | |||
3604 | public: | |||
3605 | static GuardedVarAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3606 | auto *A = new (Ctx) GuardedVarAttr(Loc, Ctx, 0); | |||
3607 | A->setImplicit(true); | |||
3608 | return A; | |||
3609 | } | |||
3610 | ||||
3611 | GuardedVarAttr(SourceRange R, ASTContext &Ctx | |||
3612 | , unsigned SI | |||
3613 | ) | |||
3614 | : InheritableAttr(attr::GuardedVar, R, SI, false, false) | |||
3615 | { | |||
3616 | } | |||
3617 | ||||
3618 | GuardedVarAttr *clone(ASTContext &C) const; | |||
3619 | void printPretty(raw_ostream &OS, | |||
3620 | const PrintingPolicy &Policy) const; | |||
3621 | const char *getSpelling() const; | |||
3622 | ||||
3623 | ||||
3624 | static bool classof(const Attr *A) { return A->getKind() == attr::GuardedVar; } | |||
3625 | }; | |||
3626 | ||||
3627 | class HotAttr : public InheritableAttr { | |||
3628 | public: | |||
3629 | static HotAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3630 | auto *A = new (Ctx) HotAttr(Loc, Ctx, 0); | |||
3631 | A->setImplicit(true); | |||
3632 | return A; | |||
3633 | } | |||
3634 | ||||
3635 | HotAttr(SourceRange R, ASTContext &Ctx | |||
3636 | , unsigned SI | |||
3637 | ) | |||
3638 | : InheritableAttr(attr::Hot, R, SI, false, false) | |||
3639 | { | |||
3640 | } | |||
3641 | ||||
3642 | HotAttr *clone(ASTContext &C) const; | |||
3643 | void printPretty(raw_ostream &OS, | |||
3644 | const PrintingPolicy &Policy) const; | |||
3645 | const char *getSpelling() const; | |||
3646 | ||||
3647 | ||||
3648 | static bool classof(const Attr *A) { return A->getKind() == attr::Hot; } | |||
3649 | }; | |||
3650 | ||||
3651 | class IBActionAttr : public InheritableAttr { | |||
3652 | public: | |||
3653 | static IBActionAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3654 | auto *A = new (Ctx) IBActionAttr(Loc, Ctx, 0); | |||
3655 | A->setImplicit(true); | |||
3656 | return A; | |||
3657 | } | |||
3658 | ||||
3659 | IBActionAttr(SourceRange R, ASTContext &Ctx | |||
3660 | , unsigned SI | |||
3661 | ) | |||
3662 | : InheritableAttr(attr::IBAction, R, SI, false, false) | |||
3663 | { | |||
3664 | } | |||
3665 | ||||
3666 | IBActionAttr *clone(ASTContext &C) const; | |||
3667 | void printPretty(raw_ostream &OS, | |||
3668 | const PrintingPolicy &Policy) const; | |||
3669 | const char *getSpelling() const; | |||
3670 | ||||
3671 | ||||
3672 | static bool classof(const Attr *A) { return A->getKind() == attr::IBAction; } | |||
3673 | }; | |||
3674 | ||||
3675 | class IBOutletAttr : public InheritableAttr { | |||
3676 | public: | |||
3677 | static IBOutletAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3678 | auto *A = new (Ctx) IBOutletAttr(Loc, Ctx, 0); | |||
3679 | A->setImplicit(true); | |||
3680 | return A; | |||
3681 | } | |||
3682 | ||||
3683 | IBOutletAttr(SourceRange R, ASTContext &Ctx | |||
3684 | , unsigned SI | |||
3685 | ) | |||
3686 | : InheritableAttr(attr::IBOutlet, R, SI, false, false) | |||
3687 | { | |||
3688 | } | |||
3689 | ||||
3690 | IBOutletAttr *clone(ASTContext &C) const; | |||
3691 | void printPretty(raw_ostream &OS, | |||
3692 | const PrintingPolicy &Policy) const; | |||
3693 | const char *getSpelling() const; | |||
3694 | ||||
3695 | ||||
3696 | static bool classof(const Attr *A) { return A->getKind() == attr::IBOutlet; } | |||
3697 | }; | |||
3698 | ||||
3699 | class IBOutletCollectionAttr : public InheritableAttr { | |||
3700 | TypeSourceInfo * interface_; | |||
3701 | ||||
3702 | public: | |||
3703 | static IBOutletCollectionAttr *CreateImplicit(ASTContext &Ctx, TypeSourceInfo * Interface, SourceRange Loc = SourceRange()) { | |||
3704 | auto *A = new (Ctx) IBOutletCollectionAttr(Loc, Ctx, Interface, 0); | |||
3705 | A->setImplicit(true); | |||
3706 | return A; | |||
3707 | } | |||
3708 | ||||
3709 | IBOutletCollectionAttr(SourceRange R, ASTContext &Ctx | |||
3710 | , TypeSourceInfo * Interface | |||
3711 | , unsigned SI | |||
3712 | ) | |||
3713 | : InheritableAttr(attr::IBOutletCollection, R, SI, false, false) | |||
3714 | , interface_(Interface) | |||
3715 | { | |||
3716 | } | |||
3717 | ||||
3718 | IBOutletCollectionAttr(SourceRange R, ASTContext &Ctx | |||
3719 | , unsigned SI | |||
3720 | ) | |||
3721 | : InheritableAttr(attr::IBOutletCollection, R, SI, false, false) | |||
3722 | , interface_() | |||
3723 | { | |||
3724 | } | |||
3725 | ||||
3726 | IBOutletCollectionAttr *clone(ASTContext &C) const; | |||
3727 | void printPretty(raw_ostream &OS, | |||
3728 | const PrintingPolicy &Policy) const; | |||
3729 | const char *getSpelling() const; | |||
3730 | QualType getInterface() const { | |||
3731 | return interface_->getType(); | |||
3732 | } TypeSourceInfo * getInterfaceLoc() const { | |||
3733 | return interface_; | |||
3734 | } | |||
3735 | ||||
3736 | ||||
3737 | ||||
3738 | static bool classof(const Attr *A) { return A->getKind() == attr::IBOutletCollection; } | |||
3739 | }; | |||
3740 | ||||
3741 | class IFuncAttr : public Attr { | |||
3742 | unsigned resolverLength; | |||
3743 | char *resolver; | |||
3744 | ||||
3745 | public: | |||
3746 | static IFuncAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Resolver, SourceRange Loc = SourceRange()) { | |||
3747 | auto *A = new (Ctx) IFuncAttr(Loc, Ctx, Resolver, 0); | |||
3748 | A->setImplicit(true); | |||
3749 | return A; | |||
3750 | } | |||
3751 | ||||
3752 | IFuncAttr(SourceRange R, ASTContext &Ctx | |||
3753 | , llvm::StringRef Resolver | |||
3754 | , unsigned SI | |||
3755 | ) | |||
3756 | : Attr(attr::IFunc, R, SI, false) | |||
3757 | , resolverLength(Resolver.size()),resolver(new (Ctx, 1) char[resolverLength]) | |||
3758 | { | |||
3759 | if (!Resolver.empty()) | |||
3760 | std::memcpy(resolver, Resolver.data(), resolverLength); | |||
3761 | } | |||
3762 | ||||
3763 | IFuncAttr *clone(ASTContext &C) const; | |||
3764 | void printPretty(raw_ostream &OS, | |||
3765 | const PrintingPolicy &Policy) const; | |||
3766 | const char *getSpelling() const; | |||
3767 | llvm::StringRef getResolver() const { | |||
3768 | return llvm::StringRef(resolver, resolverLength); | |||
3769 | } | |||
3770 | unsigned getResolverLength() const { | |||
3771 | return resolverLength; | |||
3772 | } | |||
3773 | void setResolver(ASTContext &C, llvm::StringRef S) { | |||
3774 | resolverLength = S.size(); | |||
3775 | this->resolver = new (C, 1) char [resolverLength]; | |||
3776 | if (!S.empty()) | |||
3777 | std::memcpy(this->resolver, S.data(), resolverLength); | |||
3778 | } | |||
3779 | ||||
3780 | ||||
3781 | ||||
3782 | static bool classof(const Attr *A) { return A->getKind() == attr::IFunc; } | |||
3783 | }; | |||
3784 | ||||
3785 | class InitPriorityAttr : public InheritableAttr { | |||
3786 | unsigned priority; | |||
3787 | ||||
3788 | public: | |||
3789 | static InitPriorityAttr *CreateImplicit(ASTContext &Ctx, unsigned Priority, SourceRange Loc = SourceRange()) { | |||
3790 | auto *A = new (Ctx) InitPriorityAttr(Loc, Ctx, Priority, 0); | |||
3791 | A->setImplicit(true); | |||
3792 | return A; | |||
3793 | } | |||
3794 | ||||
3795 | InitPriorityAttr(SourceRange R, ASTContext &Ctx | |||
3796 | , unsigned Priority | |||
3797 | , unsigned SI | |||
3798 | ) | |||
3799 | : InheritableAttr(attr::InitPriority, R, SI, false, false) | |||
3800 | , priority(Priority) | |||
3801 | { | |||
3802 | } | |||
3803 | ||||
3804 | InitPriorityAttr *clone(ASTContext &C) const; | |||
3805 | void printPretty(raw_ostream &OS, | |||
3806 | const PrintingPolicy &Policy) const; | |||
3807 | const char *getSpelling() const; | |||
3808 | unsigned getPriority() const { | |||
3809 | return priority; | |||
3810 | } | |||
3811 | ||||
3812 | ||||
3813 | ||||
3814 | static bool classof(const Attr *A) { return A->getKind() == attr::InitPriority; } | |||
3815 | }; | |||
3816 | ||||
3817 | class InitSegAttr : public Attr { | |||
3818 | unsigned sectionLength; | |||
3819 | char *section; | |||
3820 | ||||
3821 | public: | |||
3822 | static InitSegAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Section, SourceRange Loc = SourceRange()) { | |||
3823 | auto *A = new (Ctx) InitSegAttr(Loc, Ctx, Section, 0); | |||
3824 | A->setImplicit(true); | |||
3825 | return A; | |||
3826 | } | |||
3827 | ||||
3828 | InitSegAttr(SourceRange R, ASTContext &Ctx | |||
3829 | , llvm::StringRef Section | |||
3830 | , unsigned SI | |||
3831 | ) | |||
3832 | : Attr(attr::InitSeg, R, SI, false) | |||
3833 | , sectionLength(Section.size()),section(new (Ctx, 1) char[sectionLength]) | |||
3834 | { | |||
3835 | if (!Section.empty()) | |||
3836 | std::memcpy(section, Section.data(), sectionLength); | |||
3837 | } | |||
3838 | ||||
3839 | InitSegAttr *clone(ASTContext &C) const; | |||
3840 | void printPretty(raw_ostream &OS, | |||
3841 | const PrintingPolicy &Policy) const; | |||
3842 | const char *getSpelling() const; | |||
3843 | llvm::StringRef getSection() const { | |||
3844 | return llvm::StringRef(section, sectionLength); | |||
3845 | } | |||
3846 | unsigned getSectionLength() const { | |||
3847 | return sectionLength; | |||
3848 | } | |||
3849 | void setSection(ASTContext &C, llvm::StringRef S) { | |||
3850 | sectionLength = S.size(); | |||
3851 | this->section = new (C, 1) char [sectionLength]; | |||
3852 | if (!S.empty()) | |||
3853 | std::memcpy(this->section, S.data(), sectionLength); | |||
3854 | } | |||
3855 | ||||
3856 | ||||
3857 | void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const { | |||
3858 | OS << " (" << getSection() << ')'; | |||
3859 | } | |||
3860 | ||||
3861 | ||||
3862 | static bool classof(const Attr *A) { return A->getKind() == attr::InitSeg; } | |||
3863 | }; | |||
3864 | ||||
3865 | class IntelOclBiccAttr : public InheritableAttr { | |||
3866 | public: | |||
3867 | static IntelOclBiccAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3868 | auto *A = new (Ctx) IntelOclBiccAttr(Loc, Ctx, 0); | |||
3869 | A->setImplicit(true); | |||
3870 | return A; | |||
3871 | } | |||
3872 | ||||
3873 | IntelOclBiccAttr(SourceRange R, ASTContext &Ctx | |||
3874 | , unsigned SI | |||
3875 | ) | |||
3876 | : InheritableAttr(attr::IntelOclBicc, R, SI, false, false) | |||
3877 | { | |||
3878 | } | |||
3879 | ||||
3880 | IntelOclBiccAttr *clone(ASTContext &C) const; | |||
3881 | void printPretty(raw_ostream &OS, | |||
3882 | const PrintingPolicy &Policy) const; | |||
3883 | const char *getSpelling() const; | |||
3884 | ||||
3885 | ||||
3886 | static bool classof(const Attr *A) { return A->getKind() == attr::IntelOclBicc; } | |||
3887 | }; | |||
3888 | ||||
3889 | class InternalLinkageAttr : public InheritableAttr { | |||
3890 | public: | |||
3891 | static InternalLinkageAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3892 | auto *A = new (Ctx) InternalLinkageAttr(Loc, Ctx, 0); | |||
3893 | A->setImplicit(true); | |||
3894 | return A; | |||
3895 | } | |||
3896 | ||||
3897 | InternalLinkageAttr(SourceRange R, ASTContext &Ctx | |||
3898 | , unsigned SI | |||
3899 | ) | |||
3900 | : InheritableAttr(attr::InternalLinkage, R, SI, false, false) | |||
3901 | { | |||
3902 | } | |||
3903 | ||||
3904 | InternalLinkageAttr *clone(ASTContext &C) const; | |||
3905 | void printPretty(raw_ostream &OS, | |||
3906 | const PrintingPolicy &Policy) const; | |||
3907 | const char *getSpelling() const; | |||
3908 | ||||
3909 | ||||
3910 | static bool classof(const Attr *A) { return A->getKind() == attr::InternalLinkage; } | |||
3911 | }; | |||
3912 | ||||
3913 | class LTOVisibilityPublicAttr : public InheritableAttr { | |||
3914 | public: | |||
3915 | static LTOVisibilityPublicAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3916 | auto *A = new (Ctx) LTOVisibilityPublicAttr(Loc, Ctx, 0); | |||
3917 | A->setImplicit(true); | |||
3918 | return A; | |||
3919 | } | |||
3920 | ||||
3921 | LTOVisibilityPublicAttr(SourceRange R, ASTContext &Ctx | |||
3922 | , unsigned SI | |||
3923 | ) | |||
3924 | : InheritableAttr(attr::LTOVisibilityPublic, R, SI, false, false) | |||
3925 | { | |||
3926 | } | |||
3927 | ||||
3928 | LTOVisibilityPublicAttr *clone(ASTContext &C) const; | |||
3929 | void printPretty(raw_ostream &OS, | |||
3930 | const PrintingPolicy &Policy) const; | |||
3931 | const char *getSpelling() const; | |||
3932 | ||||
3933 | ||||
3934 | static bool classof(const Attr *A) { return A->getKind() == attr::LTOVisibilityPublic; } | |||
3935 | }; | |||
3936 | ||||
3937 | class LayoutVersionAttr : public InheritableAttr { | |||
3938 | unsigned version; | |||
3939 | ||||
3940 | public: | |||
3941 | static LayoutVersionAttr *CreateImplicit(ASTContext &Ctx, unsigned Version, SourceRange Loc = SourceRange()) { | |||
3942 | auto *A = new (Ctx) LayoutVersionAttr(Loc, Ctx, Version, 0); | |||
3943 | A->setImplicit(true); | |||
3944 | return A; | |||
3945 | } | |||
3946 | ||||
3947 | LayoutVersionAttr(SourceRange R, ASTContext &Ctx | |||
3948 | , unsigned Version | |||
3949 | , unsigned SI | |||
3950 | ) | |||
3951 | : InheritableAttr(attr::LayoutVersion, R, SI, false, false) | |||
3952 | , version(Version) | |||
3953 | { | |||
3954 | } | |||
3955 | ||||
3956 | LayoutVersionAttr *clone(ASTContext &C) const; | |||
3957 | void printPretty(raw_ostream &OS, | |||
3958 | const PrintingPolicy &Policy) const; | |||
3959 | const char *getSpelling() const; | |||
3960 | unsigned getVersion() const { | |||
3961 | return version; | |||
3962 | } | |||
3963 | ||||
3964 | ||||
3965 | ||||
3966 | static bool classof(const Attr *A) { return A->getKind() == attr::LayoutVersion; } | |||
3967 | }; | |||
3968 | ||||
3969 | class LifetimeBoundAttr : public InheritableAttr { | |||
3970 | public: | |||
3971 | static LifetimeBoundAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3972 | auto *A = new (Ctx) LifetimeBoundAttr(Loc, Ctx, 0); | |||
3973 | A->setImplicit(true); | |||
3974 | return A; | |||
3975 | } | |||
3976 | ||||
3977 | LifetimeBoundAttr(SourceRange R, ASTContext &Ctx | |||
3978 | , unsigned SI | |||
3979 | ) | |||
3980 | : InheritableAttr(attr::LifetimeBound, R, SI, false, false) | |||
3981 | { | |||
3982 | } | |||
3983 | ||||
3984 | LifetimeBoundAttr *clone(ASTContext &C) const; | |||
3985 | void printPretty(raw_ostream &OS, | |||
3986 | const PrintingPolicy &Policy) const; | |||
3987 | const char *getSpelling() const; | |||
3988 | ||||
3989 | ||||
3990 | static bool classof(const Attr *A) { return A->getKind() == attr::LifetimeBound; } | |||
3991 | }; | |||
3992 | ||||
3993 | class LockReturnedAttr : public InheritableAttr { | |||
3994 | Expr * arg; | |||
3995 | ||||
3996 | public: | |||
3997 | static LockReturnedAttr *CreateImplicit(ASTContext &Ctx, Expr * Arg, SourceRange Loc = SourceRange()) { | |||
3998 | auto *A = new (Ctx) LockReturnedAttr(Loc, Ctx, Arg, 0); | |||
3999 | A->setImplicit(true); | |||
4000 | return A; | |||
4001 | } | |||
4002 | ||||
4003 | LockReturnedAttr(SourceRange R, ASTContext &Ctx | |||
4004 | , Expr * Arg | |||
4005 | , unsigned SI | |||
4006 | ) | |||
4007 | : InheritableAttr(attr::LockReturned, R, SI, true, false) | |||
4008 | , arg(Arg) | |||
4009 | { | |||
4010 | } | |||
4011 | ||||
4012 | LockReturnedAttr *clone(ASTContext &C) const; | |||
4013 | void printPretty(raw_ostream &OS, | |||
4014 | const PrintingPolicy &Policy) const; | |||
4015 | const char *getSpelling() const; | |||
4016 | Expr * getArg() const { | |||
4017 | return arg; | |||
4018 | } | |||
4019 | ||||
4020 | ||||
4021 | ||||
4022 | static bool classof(const Attr *A) { return A->getKind() == attr::LockReturned; } | |||
4023 | }; | |||
4024 | ||||
4025 | class LocksExcludedAttr : public InheritableAttr { | |||
4026 | unsigned args_Size; | |||
4027 | Expr * *args_; | |||
4028 | ||||
4029 | public: | |||
4030 | static LocksExcludedAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
4031 | auto *A = new (Ctx) LocksExcludedAttr(Loc, Ctx, Args, ArgsSize, 0); | |||
4032 | A->setImplicit(true); | |||
4033 | return A; | |||
4034 | } | |||
4035 | ||||
4036 | LocksExcludedAttr(SourceRange R, ASTContext &Ctx | |||
4037 | , Expr * *Args, unsigned ArgsSize | |||
4038 | , unsigned SI | |||
4039 | ) | |||
4040 | : InheritableAttr(attr::LocksExcluded, R, SI, true, true) | |||
4041 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
4042 | { | |||
4043 | std::copy(Args, Args + args_Size, args_); | |||
4044 | } | |||
4045 | ||||
4046 | LocksExcludedAttr(SourceRange R, ASTContext &Ctx | |||
4047 | , unsigned SI | |||
4048 | ) | |||
4049 | : InheritableAttr(attr::LocksExcluded, R, SI, true, true) | |||
4050 | , args_Size(0), args_(nullptr) | |||
4051 | { | |||
4052 | } | |||
4053 | ||||
4054 | LocksExcludedAttr *clone(ASTContext &C) const; | |||
4055 | void printPretty(raw_ostream &OS, | |||
4056 | const PrintingPolicy &Policy) const; | |||
4057 | const char *getSpelling() const; | |||
4058 | typedef Expr ** args_iterator; | |||
4059 | args_iterator args_begin() const { return args_; } | |||
4060 | args_iterator args_end() const { return args_ + args_Size; } | |||
4061 | unsigned args_size() const { return args_Size; } | |||
4062 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
4063 | ||||
4064 | ||||
4065 | ||||
4066 | ||||
4067 | static bool classof(const Attr *A) { return A->getKind() == attr::LocksExcluded; } | |||
4068 | }; | |||
4069 | ||||
4070 | class LoopHintAttr : public Attr { | |||
4071 | public: | |||
4072 | enum OptionType { | |||
4073 | Vectorize, | |||
4074 | VectorizeWidth, | |||
4075 | Interleave, | |||
4076 | InterleaveCount, | |||
4077 | Unroll, | |||
4078 | UnrollCount, | |||
4079 | UnrollAndJam, | |||
4080 | UnrollAndJamCount, | |||
4081 | PipelineDisabled, | |||
4082 | PipelineInitiationInterval, | |||
4083 | Distribute | |||
4084 | }; | |||
4085 | private: | |||
4086 | OptionType option; | |||
4087 | ||||
4088 | public: | |||
4089 | enum LoopHintState { | |||
4090 | Enable, | |||
4091 | Disable, | |||
4092 | Numeric, | |||
4093 | AssumeSafety, | |||
4094 | Full | |||
4095 | }; | |||
4096 | private: | |||
4097 | LoopHintState state; | |||
4098 | ||||
4099 | Expr * value; | |||
4100 | ||||
4101 | public: | |||
4102 | enum Spelling { | |||
4103 | Pragma_clang_loop = 0, | |||
4104 | Pragma_unroll = 1, | |||
4105 | Pragma_nounroll = 2, | |||
4106 | Pragma_unroll_and_jam = 3, | |||
4107 | Pragma_nounroll_and_jam = 4 | |||
4108 | }; | |||
4109 | ||||
4110 | static LoopHintAttr *CreateImplicit(ASTContext &Ctx, Spelling S, OptionType Option, LoopHintState State, Expr * Value, SourceRange Loc = SourceRange()) { | |||
4111 | auto *A = new (Ctx) LoopHintAttr(Loc, Ctx, Option, State, Value, S); | |||
4112 | A->setImplicit(true); | |||
4113 | return A; | |||
4114 | } | |||
4115 | ||||
4116 | LoopHintAttr(SourceRange R, ASTContext &Ctx | |||
4117 | , OptionType Option | |||
4118 | , LoopHintState State | |||
4119 | , Expr * Value | |||
4120 | , unsigned SI | |||
4121 | ) | |||
4122 | : Attr(attr::LoopHint, R, SI, false) | |||
4123 | , option(Option) | |||
4124 | , state(State) | |||
4125 | , value(Value) | |||
4126 | { | |||
4127 | } | |||
4128 | ||||
4129 | LoopHintAttr *clone(ASTContext &C) const; | |||
4130 | void printPretty(raw_ostream &OS, | |||
4131 | const PrintingPolicy &Policy) const; | |||
4132 | const char *getSpelling() const; | |||
4133 | Spelling getSemanticSpelling() const { | |||
4134 | switch (SpellingListIndex) { | |||
4135 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4135); | |||
4136 | case 0: return Pragma_clang_loop; | |||
4137 | case 1: return Pragma_unroll; | |||
4138 | case 2: return Pragma_nounroll; | |||
4139 | case 3: return Pragma_unroll_and_jam; | |||
4140 | case 4: return Pragma_nounroll_and_jam; | |||
4141 | } | |||
4142 | } | |||
4143 | OptionType getOption() const { | |||
4144 | return option; | |||
4145 | } | |||
4146 | ||||
4147 | static bool ConvertStrToOptionType(StringRef Val, OptionType &Out) { | |||
4148 | Optional<OptionType> R = llvm::StringSwitch<Optional<OptionType>>(Val) | |||
4149 | .Case("vectorize", LoopHintAttr::Vectorize) | |||
4150 | .Case("vectorize_width", LoopHintAttr::VectorizeWidth) | |||
4151 | .Case("interleave", LoopHintAttr::Interleave) | |||
4152 | .Case("interleave_count", LoopHintAttr::InterleaveCount) | |||
4153 | .Case("unroll", LoopHintAttr::Unroll) | |||
4154 | .Case("unroll_count", LoopHintAttr::UnrollCount) | |||
4155 | .Case("unroll_and_jam", LoopHintAttr::UnrollAndJam) | |||
4156 | .Case("unroll_and_jam_count", LoopHintAttr::UnrollAndJamCount) | |||
4157 | .Case("pipeline", LoopHintAttr::PipelineDisabled) | |||
4158 | .Case("pipeline_initiation_interval", LoopHintAttr::PipelineInitiationInterval) | |||
4159 | .Case("distribute", LoopHintAttr::Distribute) | |||
4160 | .Default(Optional<OptionType>()); | |||
4161 | if (R) { | |||
4162 | Out = *R; | |||
4163 | return true; | |||
4164 | } | |||
4165 | return false; | |||
4166 | } | |||
4167 | ||||
4168 | static const char *ConvertOptionTypeToStr(OptionType Val) { | |||
4169 | switch(Val) { | |||
4170 | case LoopHintAttr::Vectorize: return "vectorize"; | |||
4171 | case LoopHintAttr::VectorizeWidth: return "vectorize_width"; | |||
4172 | case LoopHintAttr::Interleave: return "interleave"; | |||
4173 | case LoopHintAttr::InterleaveCount: return "interleave_count"; | |||
4174 | case LoopHintAttr::Unroll: return "unroll"; | |||
4175 | case LoopHintAttr::UnrollCount: return "unroll_count"; | |||
4176 | case LoopHintAttr::UnrollAndJam: return "unroll_and_jam"; | |||
4177 | case LoopHintAttr::UnrollAndJamCount: return "unroll_and_jam_count"; | |||
4178 | case LoopHintAttr::PipelineDisabled: return "pipeline"; | |||
4179 | case LoopHintAttr::PipelineInitiationInterval: return "pipeline_initiation_interval"; | |||
4180 | case LoopHintAttr::Distribute: return "distribute"; | |||
4181 | } | |||
4182 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4182); | |||
4183 | } | |||
4184 | LoopHintState getState() const { | |||
4185 | return state; | |||
4186 | } | |||
4187 | ||||
4188 | static bool ConvertStrToLoopHintState(StringRef Val, LoopHintState &Out) { | |||
4189 | Optional<LoopHintState> R = llvm::StringSwitch<Optional<LoopHintState>>(Val) | |||
4190 | .Case("enable", LoopHintAttr::Enable) | |||
4191 | .Case("disable", LoopHintAttr::Disable) | |||
4192 | .Case("numeric", LoopHintAttr::Numeric) | |||
4193 | .Case("assume_safety", LoopHintAttr::AssumeSafety) | |||
4194 | .Case("full", LoopHintAttr::Full) | |||
4195 | .Default(Optional<LoopHintState>()); | |||
4196 | if (R) { | |||
4197 | Out = *R; | |||
4198 | return true; | |||
4199 | } | |||
4200 | return false; | |||
4201 | } | |||
4202 | ||||
4203 | static const char *ConvertLoopHintStateToStr(LoopHintState Val) { | |||
4204 | switch(Val) { | |||
4205 | case LoopHintAttr::Enable: return "enable"; | |||
4206 | case LoopHintAttr::Disable: return "disable"; | |||
4207 | case LoopHintAttr::Numeric: return "numeric"; | |||
4208 | case LoopHintAttr::AssumeSafety: return "assume_safety"; | |||
4209 | case LoopHintAttr::Full: return "full"; | |||
4210 | } | |||
4211 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4211); | |||
4212 | } | |||
4213 | Expr * getValue() const { | |||
4214 | return value; | |||
4215 | } | |||
4216 | ||||
4217 | ||||
4218 | static const char *getOptionName(int Option) { | |||
4219 | switch(Option) { | |||
4220 | case Vectorize: return "vectorize"; | |||
4221 | case VectorizeWidth: return "vectorize_width"; | |||
4222 | case Interleave: return "interleave"; | |||
4223 | case InterleaveCount: return "interleave_count"; | |||
4224 | case Unroll: return "unroll"; | |||
4225 | case UnrollCount: return "unroll_count"; | |||
4226 | case UnrollAndJam: return "unroll_and_jam"; | |||
4227 | case UnrollAndJamCount: return "unroll_and_jam_count"; | |||
4228 | case PipelineDisabled: return "pipeline"; | |||
4229 | case PipelineInitiationInterval: return "pipeline_initiation_interval"; | |||
4230 | case Distribute: return "distribute"; | |||
4231 | } | |||
4232 | llvm_unreachable("Unhandled LoopHint option.")::llvm::llvm_unreachable_internal("Unhandled LoopHint option." , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4232); | |||
4233 | } | |||
4234 | ||||
4235 | void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const { | |||
4236 | unsigned SpellingIndex = getSpellingListIndex(); | |||
4237 | // For "#pragma unroll" and "#pragma nounroll" the string "unroll" or | |||
4238 | // "nounroll" is already emitted as the pragma name. | |||
4239 | if (SpellingIndex == Pragma_nounroll || SpellingIndex == Pragma_nounroll_and_jam) | |||
4240 | return; | |||
4241 | else if (SpellingIndex == Pragma_unroll || SpellingIndex == Pragma_unroll_and_jam) { | |||
4242 | OS << ' ' << getValueString(Policy); | |||
4243 | return; | |||
4244 | } | |||
4245 | ||||
4246 | assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling")((SpellingIndex == Pragma_clang_loop && "Unexpected spelling" ) ? static_cast<void> (0) : __assert_fail ("SpellingIndex == Pragma_clang_loop && \"Unexpected spelling\"" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4246, __PRETTY_FUNCTION__)); | |||
4247 | OS << ' ' << getOptionName(option) << getValueString(Policy); | |||
4248 | } | |||
4249 | ||||
4250 | // Return a string containing the loop hint argument including the | |||
4251 | // enclosing parentheses. | |||
4252 | std::string getValueString(const PrintingPolicy &Policy) const { | |||
4253 | std::string ValueName; | |||
4254 | llvm::raw_string_ostream OS(ValueName); | |||
4255 | OS << "("; | |||
4256 | if (state == Numeric) | |||
4257 | value->printPretty(OS, nullptr, Policy); | |||
4258 | else if (state == Enable) | |||
4259 | OS << "enable"; | |||
4260 | else if (state == Full) | |||
4261 | OS << "full"; | |||
4262 | else if (state == AssumeSafety) | |||
4263 | OS << "assume_safety"; | |||
4264 | else | |||
4265 | OS << "disable"; | |||
4266 | OS << ")"; | |||
4267 | return OS.str(); | |||
4268 | } | |||
4269 | ||||
4270 | // Return a string suitable for identifying this attribute in diagnostics. | |||
4271 | std::string getDiagnosticName(const PrintingPolicy &Policy) const { | |||
4272 | unsigned SpellingIndex = getSpellingListIndex(); | |||
4273 | if (SpellingIndex == Pragma_nounroll) | |||
4274 | return "#pragma nounroll"; | |||
4275 | else if (SpellingIndex == Pragma_unroll) | |||
4276 | return "#pragma unroll" + (option == UnrollCount ? getValueString(Policy) : ""); | |||
4277 | else if (SpellingIndex == Pragma_nounroll_and_jam) | |||
4278 | return "#pragma nounroll_and_jam"; | |||
4279 | else if (SpellingIndex == Pragma_unroll_and_jam) | |||
4280 | return "#pragma unroll_and_jam" + | |||
4281 | (option == UnrollAndJamCount ? getValueString(Policy) : ""); | |||
4282 | ||||
4283 | assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling")((SpellingIndex == Pragma_clang_loop && "Unexpected spelling" ) ? static_cast<void> (0) : __assert_fail ("SpellingIndex == Pragma_clang_loop && \"Unexpected spelling\"" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4283, __PRETTY_FUNCTION__)); | |||
4284 | return getOptionName(option) + getValueString(Policy); | |||
4285 | } | |||
4286 | ||||
4287 | ||||
4288 | static bool classof(const Attr *A) { return A->getKind() == attr::LoopHint; } | |||
4289 | }; | |||
4290 | ||||
4291 | class MIGServerRoutineAttr : public InheritableAttr { | |||
4292 | public: | |||
4293 | static MIGServerRoutineAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4294 | auto *A = new (Ctx) MIGServerRoutineAttr(Loc, Ctx, 0); | |||
4295 | A->setImplicit(true); | |||
4296 | return A; | |||
4297 | } | |||
4298 | ||||
4299 | MIGServerRoutineAttr(SourceRange R, ASTContext &Ctx | |||
4300 | , unsigned SI | |||
4301 | ) | |||
4302 | : InheritableAttr(attr::MIGServerRoutine, R, SI, false, false) | |||
4303 | { | |||
4304 | } | |||
4305 | ||||
4306 | MIGServerRoutineAttr *clone(ASTContext &C) const; | |||
4307 | void printPretty(raw_ostream &OS, | |||
4308 | const PrintingPolicy &Policy) const; | |||
4309 | const char *getSpelling() const; | |||
4310 | ||||
4311 | ||||
4312 | static bool classof(const Attr *A) { return A->getKind() == attr::MIGServerRoutine; } | |||
4313 | }; | |||
4314 | ||||
4315 | class MSABIAttr : public InheritableAttr { | |||
4316 | public: | |||
4317 | static MSABIAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4318 | auto *A = new (Ctx) MSABIAttr(Loc, Ctx, 0); | |||
4319 | A->setImplicit(true); | |||
4320 | return A; | |||
4321 | } | |||
4322 | ||||
4323 | MSABIAttr(SourceRange R, ASTContext &Ctx | |||
4324 | , unsigned SI | |||
4325 | ) | |||
4326 | : InheritableAttr(attr::MSABI, R, SI, false, false) | |||
4327 | { | |||
4328 | } | |||
4329 | ||||
4330 | MSABIAttr *clone(ASTContext &C) const; | |||
4331 | void printPretty(raw_ostream &OS, | |||
4332 | const PrintingPolicy &Policy) const; | |||
4333 | const char *getSpelling() const; | |||
4334 | ||||
4335 | ||||
4336 | static bool classof(const Attr *A) { return A->getKind() == attr::MSABI; } | |||
4337 | }; | |||
4338 | ||||
4339 | class MSAllocatorAttr : public InheritableAttr { | |||
4340 | public: | |||
4341 | static MSAllocatorAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4342 | auto *A = new (Ctx) MSAllocatorAttr(Loc, Ctx, 0); | |||
4343 | A->setImplicit(true); | |||
4344 | return A; | |||
4345 | } | |||
4346 | ||||
4347 | MSAllocatorAttr(SourceRange R, ASTContext &Ctx | |||
4348 | , unsigned SI | |||
4349 | ) | |||
4350 | : InheritableAttr(attr::MSAllocator, R, SI, false, false) | |||
4351 | { | |||
4352 | } | |||
4353 | ||||
4354 | MSAllocatorAttr *clone(ASTContext &C) const; | |||
4355 | void printPretty(raw_ostream &OS, | |||
4356 | const PrintingPolicy &Policy) const; | |||
4357 | const char *getSpelling() const; | |||
4358 | ||||
4359 | ||||
4360 | static bool classof(const Attr *A) { return A->getKind() == attr::MSAllocator; } | |||
4361 | }; | |||
4362 | ||||
4363 | class MSInheritanceAttr : public InheritableAttr { | |||
4364 | bool bestCase; | |||
4365 | ||||
4366 | public: | |||
4367 | enum Spelling { | |||
4368 | Keyword_single_inheritance = 0, | |||
4369 | Keyword_multiple_inheritance = 1, | |||
4370 | Keyword_virtual_inheritance = 2, | |||
4371 | Keyword_unspecified_inheritance = 3 | |||
4372 | }; | |||
4373 | ||||
4374 | static MSInheritanceAttr *CreateImplicit(ASTContext &Ctx, Spelling S, bool BestCase, SourceRange Loc = SourceRange()) { | |||
4375 | auto *A = new (Ctx) MSInheritanceAttr(Loc, Ctx, BestCase, S); | |||
4376 | A->setImplicit(true); | |||
4377 | return A; | |||
4378 | } | |||
4379 | ||||
4380 | static MSInheritanceAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
4381 | auto *A = new (Ctx) MSInheritanceAttr(Loc, Ctx, S); | |||
4382 | A->setImplicit(true); | |||
4383 | return A; | |||
4384 | } | |||
4385 | ||||
4386 | MSInheritanceAttr(SourceRange R, ASTContext &Ctx | |||
4387 | , bool BestCase | |||
4388 | , unsigned SI | |||
4389 | ) | |||
4390 | : InheritableAttr(attr::MSInheritance, R, SI, false, false) | |||
4391 | , bestCase(BestCase) | |||
4392 | { | |||
4393 | } | |||
4394 | ||||
4395 | MSInheritanceAttr(SourceRange R, ASTContext &Ctx | |||
4396 | , unsigned SI | |||
4397 | ) | |||
4398 | : InheritableAttr(attr::MSInheritance, R, SI, false, false) | |||
4399 | , bestCase() | |||
4400 | { | |||
4401 | } | |||
4402 | ||||
4403 | MSInheritanceAttr *clone(ASTContext &C) const; | |||
4404 | void printPretty(raw_ostream &OS, | |||
4405 | const PrintingPolicy &Policy) const; | |||
4406 | const char *getSpelling() const; | |||
4407 | Spelling getSemanticSpelling() const { | |||
4408 | switch (SpellingListIndex) { | |||
4409 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4409); | |||
4410 | case 0: return Keyword_single_inheritance; | |||
4411 | case 1: return Keyword_multiple_inheritance; | |||
4412 | case 2: return Keyword_virtual_inheritance; | |||
4413 | case 3: return Keyword_unspecified_inheritance; | |||
4414 | } | |||
4415 | } | |||
4416 | bool getBestCase() const { | |||
4417 | return bestCase; | |||
4418 | } | |||
4419 | ||||
4420 | static const bool DefaultBestCase = true; | |||
4421 | ||||
4422 | ||||
4423 | static bool hasVBPtrOffsetField(Spelling Inheritance) { | |||
4424 | return Inheritance == Keyword_unspecified_inheritance; | |||
4425 | } | |||
4426 | ||||
4427 | // Only member pointers to functions need a this adjustment, since it can be | |||
4428 | // combined with the field offset for data pointers. | |||
4429 | static bool hasNVOffsetField(bool IsMemberFunction, Spelling Inheritance) { | |||
4430 | return IsMemberFunction && Inheritance >= Keyword_multiple_inheritance; | |||
4431 | } | |||
4432 | ||||
4433 | static bool hasVBTableOffsetField(Spelling Inheritance) { | |||
4434 | return Inheritance >= Keyword_virtual_inheritance; | |||
4435 | } | |||
4436 | ||||
4437 | static bool hasOnlyOneField(bool IsMemberFunction, | |||
4438 | Spelling Inheritance) { | |||
4439 | if (IsMemberFunction) | |||
4440 | return Inheritance <= Keyword_single_inheritance; | |||
4441 | return Inheritance <= Keyword_multiple_inheritance; | |||
4442 | } | |||
4443 | ||||
4444 | ||||
4445 | static bool classof(const Attr *A) { return A->getKind() == attr::MSInheritance; } | |||
4446 | }; | |||
4447 | ||||
4448 | class MSNoVTableAttr : public InheritableAttr { | |||
4449 | public: | |||
4450 | static MSNoVTableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4451 | auto *A = new (Ctx) MSNoVTableAttr(Loc, Ctx, 0); | |||
4452 | A->setImplicit(true); | |||
4453 | return A; | |||
4454 | } | |||
4455 | ||||
4456 | MSNoVTableAttr(SourceRange R, ASTContext &Ctx | |||
4457 | , unsigned SI | |||
4458 | ) | |||
4459 | : InheritableAttr(attr::MSNoVTable, R, SI, false, false) | |||
4460 | { | |||
4461 | } | |||
4462 | ||||
4463 | MSNoVTableAttr *clone(ASTContext &C) const; | |||
4464 | void printPretty(raw_ostream &OS, | |||
4465 | const PrintingPolicy &Policy) const; | |||
4466 | const char *getSpelling() const; | |||
4467 | ||||
4468 | ||||
4469 | static bool classof(const Attr *A) { return A->getKind() == attr::MSNoVTable; } | |||
4470 | }; | |||
4471 | ||||
4472 | class MSP430InterruptAttr : public InheritableAttr { | |||
4473 | unsigned number; | |||
4474 | ||||
4475 | public: | |||
4476 | static MSP430InterruptAttr *CreateImplicit(ASTContext &Ctx, unsigned Number, SourceRange Loc = SourceRange()) { | |||
4477 | auto *A = new (Ctx) MSP430InterruptAttr(Loc, Ctx, Number, 0); | |||
4478 | A->setImplicit(true); | |||
4479 | return A; | |||
4480 | } | |||
4481 | ||||
4482 | MSP430InterruptAttr(SourceRange R, ASTContext &Ctx | |||
4483 | , unsigned Number | |||
4484 | , unsigned SI | |||
4485 | ) | |||
4486 | : InheritableAttr(attr::MSP430Interrupt, R, SI, false, false) | |||
4487 | , number(Number) | |||
4488 | { | |||
4489 | } | |||
4490 | ||||
4491 | MSP430InterruptAttr *clone(ASTContext &C) const; | |||
4492 | void printPretty(raw_ostream &OS, | |||
4493 | const PrintingPolicy &Policy) const; | |||
4494 | const char *getSpelling() const; | |||
4495 | unsigned getNumber() const { | |||
4496 | return number; | |||
4497 | } | |||
4498 | ||||
4499 | ||||
4500 | ||||
4501 | static bool classof(const Attr *A) { return A->getKind() == attr::MSP430Interrupt; } | |||
4502 | }; | |||
4503 | ||||
4504 | class MSStructAttr : public InheritableAttr { | |||
4505 | public: | |||
4506 | static MSStructAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4507 | auto *A = new (Ctx) MSStructAttr(Loc, Ctx, 0); | |||
4508 | A->setImplicit(true); | |||
4509 | return A; | |||
4510 | } | |||
4511 | ||||
4512 | MSStructAttr(SourceRange R, ASTContext &Ctx | |||
4513 | , unsigned SI | |||
4514 | ) | |||
4515 | : InheritableAttr(attr::MSStruct, R, SI, false, false) | |||
4516 | { | |||
4517 | } | |||
4518 | ||||
4519 | MSStructAttr *clone(ASTContext &C) const; | |||
4520 | void printPretty(raw_ostream &OS, | |||
4521 | const PrintingPolicy &Policy) const; | |||
4522 | const char *getSpelling() const; | |||
4523 | ||||
4524 | ||||
4525 | static bool classof(const Attr *A) { return A->getKind() == attr::MSStruct; } | |||
4526 | }; | |||
4527 | ||||
4528 | class MSVtorDispAttr : public InheritableAttr { | |||
4529 | unsigned vdm; | |||
4530 | ||||
4531 | public: | |||
4532 | static MSVtorDispAttr *CreateImplicit(ASTContext &Ctx, unsigned Vdm, SourceRange Loc = SourceRange()) { | |||
4533 | auto *A = new (Ctx) MSVtorDispAttr(Loc, Ctx, Vdm, 0); | |||
4534 | A->setImplicit(true); | |||
4535 | return A; | |||
4536 | } | |||
4537 | ||||
4538 | MSVtorDispAttr(SourceRange R, ASTContext &Ctx | |||
4539 | , unsigned Vdm | |||
4540 | , unsigned SI | |||
4541 | ) | |||
4542 | : InheritableAttr(attr::MSVtorDisp, R, SI, false, false) | |||
4543 | , vdm(Vdm) | |||
4544 | { | |||
4545 | } | |||
4546 | ||||
4547 | MSVtorDispAttr *clone(ASTContext &C) const; | |||
4548 | void printPretty(raw_ostream &OS, | |||
4549 | const PrintingPolicy &Policy) const; | |||
4550 | const char *getSpelling() const; | |||
4551 | unsigned getVdm() const { | |||
4552 | return vdm; | |||
4553 | } | |||
4554 | ||||
4555 | ||||
4556 | enum Mode { | |||
4557 | Never, | |||
4558 | ForVBaseOverride, | |||
4559 | ForVFTable | |||
4560 | }; | |||
4561 | ||||
4562 | Mode getVtorDispMode() const { return Mode(vdm); } | |||
4563 | ||||
4564 | ||||
4565 | static bool classof(const Attr *A) { return A->getKind() == attr::MSVtorDisp; } | |||
4566 | }; | |||
4567 | ||||
4568 | class MaxFieldAlignmentAttr : public InheritableAttr { | |||
4569 | unsigned alignment; | |||
4570 | ||||
4571 | public: | |||
4572 | static MaxFieldAlignmentAttr *CreateImplicit(ASTContext &Ctx, unsigned Alignment, SourceRange Loc = SourceRange()) { | |||
4573 | auto *A = new (Ctx) MaxFieldAlignmentAttr(Loc, Ctx, Alignment, 0); | |||
4574 | A->setImplicit(true); | |||
4575 | return A; | |||
4576 | } | |||
4577 | ||||
4578 | MaxFieldAlignmentAttr(SourceRange R, ASTContext &Ctx | |||
4579 | , unsigned Alignment | |||
4580 | , unsigned SI | |||
4581 | ) | |||
4582 | : InheritableAttr(attr::MaxFieldAlignment, R, SI, false, false) | |||
4583 | , alignment(Alignment) | |||
4584 | { | |||
4585 | } | |||
4586 | ||||
4587 | MaxFieldAlignmentAttr *clone(ASTContext &C) const; | |||
4588 | void printPretty(raw_ostream &OS, | |||
4589 | const PrintingPolicy &Policy) const; | |||
4590 | const char *getSpelling() const; | |||
4591 | unsigned getAlignment() const { | |||
4592 | return alignment; | |||
4593 | } | |||
4594 | ||||
4595 | ||||
4596 | ||||
4597 | static bool classof(const Attr *A) { return A->getKind() == attr::MaxFieldAlignment; } | |||
4598 | }; | |||
4599 | ||||
4600 | class MayAliasAttr : public InheritableAttr { | |||
4601 | public: | |||
4602 | static MayAliasAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4603 | auto *A = new (Ctx) MayAliasAttr(Loc, Ctx, 0); | |||
4604 | A->setImplicit(true); | |||
4605 | return A; | |||
4606 | } | |||
4607 | ||||
4608 | MayAliasAttr(SourceRange R, ASTContext &Ctx | |||
4609 | , unsigned SI | |||
4610 | ) | |||
4611 | : InheritableAttr(attr::MayAlias, R, SI, false, false) | |||
4612 | { | |||
4613 | } | |||
4614 | ||||
4615 | MayAliasAttr *clone(ASTContext &C) const; | |||
4616 | void printPretty(raw_ostream &OS, | |||
4617 | const PrintingPolicy &Policy) const; | |||
4618 | const char *getSpelling() const; | |||
4619 | ||||
4620 | ||||
4621 | static bool classof(const Attr *A) { return A->getKind() == attr::MayAlias; } | |||
4622 | }; | |||
4623 | ||||
4624 | class MicroMipsAttr : public InheritableAttr { | |||
4625 | public: | |||
4626 | static MicroMipsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4627 | auto *A = new (Ctx) MicroMipsAttr(Loc, Ctx, 0); | |||
4628 | A->setImplicit(true); | |||
4629 | return A; | |||
4630 | } | |||
4631 | ||||
4632 | MicroMipsAttr(SourceRange R, ASTContext &Ctx | |||
4633 | , unsigned SI | |||
4634 | ) | |||
4635 | : InheritableAttr(attr::MicroMips, R, SI, false, false) | |||
4636 | { | |||
4637 | } | |||
4638 | ||||
4639 | MicroMipsAttr *clone(ASTContext &C) const; | |||
4640 | void printPretty(raw_ostream &OS, | |||
4641 | const PrintingPolicy &Policy) const; | |||
4642 | const char *getSpelling() const; | |||
4643 | ||||
4644 | ||||
4645 | static bool classof(const Attr *A) { return A->getKind() == attr::MicroMips; } | |||
4646 | }; | |||
4647 | ||||
4648 | class MinSizeAttr : public InheritableAttr { | |||
4649 | public: | |||
4650 | static MinSizeAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4651 | auto *A = new (Ctx) MinSizeAttr(Loc, Ctx, 0); | |||
4652 | A->setImplicit(true); | |||
4653 | return A; | |||
4654 | } | |||
4655 | ||||
4656 | MinSizeAttr(SourceRange R, ASTContext &Ctx | |||
4657 | , unsigned SI | |||
4658 | ) | |||
4659 | : InheritableAttr(attr::MinSize, R, SI, false, false) | |||
4660 | { | |||
4661 | } | |||
4662 | ||||
4663 | MinSizeAttr *clone(ASTContext &C) const; | |||
4664 | void printPretty(raw_ostream &OS, | |||
4665 | const PrintingPolicy &Policy) const; | |||
4666 | const char *getSpelling() const; | |||
4667 | ||||
4668 | ||||
4669 | static bool classof(const Attr *A) { return A->getKind() == attr::MinSize; } | |||
4670 | }; | |||
4671 | ||||
4672 | class MinVectorWidthAttr : public InheritableAttr { | |||
4673 | unsigned vectorWidth; | |||
4674 | ||||
4675 | public: | |||
4676 | static MinVectorWidthAttr *CreateImplicit(ASTContext &Ctx, unsigned VectorWidth, SourceRange Loc = SourceRange()) { | |||
4677 | auto *A = new (Ctx) MinVectorWidthAttr(Loc, Ctx, VectorWidth, 0); | |||
4678 | A->setImplicit(true); | |||
4679 | return A; | |||
4680 | } | |||
4681 | ||||
4682 | MinVectorWidthAttr(SourceRange R, ASTContext &Ctx | |||
4683 | , unsigned VectorWidth | |||
4684 | , unsigned SI | |||
4685 | ) | |||
4686 | : InheritableAttr(attr::MinVectorWidth, R, SI, false, false) | |||
4687 | , vectorWidth(VectorWidth) | |||
4688 | { | |||
4689 | } | |||
4690 | ||||
4691 | MinVectorWidthAttr *clone(ASTContext &C) const; | |||
4692 | void printPretty(raw_ostream &OS, | |||
4693 | const PrintingPolicy &Policy) const; | |||
4694 | const char *getSpelling() const; | |||
4695 | unsigned getVectorWidth() const { | |||
4696 | return vectorWidth; | |||
4697 | } | |||
4698 | ||||
4699 | ||||
4700 | ||||
4701 | static bool classof(const Attr *A) { return A->getKind() == attr::MinVectorWidth; } | |||
4702 | }; | |||
4703 | ||||
4704 | class Mips16Attr : public InheritableAttr { | |||
4705 | public: | |||
4706 | static Mips16Attr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4707 | auto *A = new (Ctx) Mips16Attr(Loc, Ctx, 0); | |||
4708 | A->setImplicit(true); | |||
4709 | return A; | |||
4710 | } | |||
4711 | ||||
4712 | Mips16Attr(SourceRange R, ASTContext &Ctx | |||
4713 | , unsigned SI | |||
4714 | ) | |||
4715 | : InheritableAttr(attr::Mips16, R, SI, false, false) | |||
4716 | { | |||
4717 | } | |||
4718 | ||||
4719 | Mips16Attr *clone(ASTContext &C) const; | |||
4720 | void printPretty(raw_ostream &OS, | |||
4721 | const PrintingPolicy &Policy) const; | |||
4722 | const char *getSpelling() const; | |||
4723 | ||||
4724 | ||||
4725 | static bool classof(const Attr *A) { return A->getKind() == attr::Mips16; } | |||
4726 | }; | |||
4727 | ||||
4728 | class MipsInterruptAttr : public InheritableAttr { | |||
4729 | public: | |||
4730 | enum InterruptType { | |||
4731 | sw0, | |||
4732 | sw1, | |||
4733 | hw0, | |||
4734 | hw1, | |||
4735 | hw2, | |||
4736 | hw3, | |||
4737 | hw4, | |||
4738 | hw5, | |||
4739 | eic | |||
4740 | }; | |||
4741 | private: | |||
4742 | InterruptType interrupt; | |||
4743 | ||||
4744 | public: | |||
4745 | static MipsInterruptAttr *CreateImplicit(ASTContext &Ctx, InterruptType Interrupt, SourceRange Loc = SourceRange()) { | |||
4746 | auto *A = new (Ctx) MipsInterruptAttr(Loc, Ctx, Interrupt, 0); | |||
4747 | A->setImplicit(true); | |||
4748 | return A; | |||
4749 | } | |||
4750 | ||||
4751 | MipsInterruptAttr(SourceRange R, ASTContext &Ctx | |||
4752 | , InterruptType Interrupt | |||
4753 | , unsigned SI | |||
4754 | ) | |||
4755 | : InheritableAttr(attr::MipsInterrupt, R, SI, false, false) | |||
4756 | , interrupt(Interrupt) | |||
4757 | { | |||
4758 | } | |||
4759 | ||||
4760 | MipsInterruptAttr *clone(ASTContext &C) const; | |||
4761 | void printPretty(raw_ostream &OS, | |||
4762 | const PrintingPolicy &Policy) const; | |||
4763 | const char *getSpelling() const; | |||
4764 | InterruptType getInterrupt() const { | |||
4765 | return interrupt; | |||
4766 | } | |||
4767 | ||||
4768 | static bool ConvertStrToInterruptType(StringRef Val, InterruptType &Out) { | |||
4769 | Optional<InterruptType> R = llvm::StringSwitch<Optional<InterruptType>>(Val) | |||
4770 | .Case("vector=sw0", MipsInterruptAttr::sw0) | |||
4771 | .Case("vector=sw1", MipsInterruptAttr::sw1) | |||
4772 | .Case("vector=hw0", MipsInterruptAttr::hw0) | |||
4773 | .Case("vector=hw1", MipsInterruptAttr::hw1) | |||
4774 | .Case("vector=hw2", MipsInterruptAttr::hw2) | |||
4775 | .Case("vector=hw3", MipsInterruptAttr::hw3) | |||
4776 | .Case("vector=hw4", MipsInterruptAttr::hw4) | |||
4777 | .Case("vector=hw5", MipsInterruptAttr::hw5) | |||
4778 | .Case("eic", MipsInterruptAttr::eic) | |||
4779 | .Case("", MipsInterruptAttr::eic) | |||
4780 | .Default(Optional<InterruptType>()); | |||
4781 | if (R) { | |||
4782 | Out = *R; | |||
4783 | return true; | |||
4784 | } | |||
4785 | return false; | |||
4786 | } | |||
4787 | ||||
4788 | static const char *ConvertInterruptTypeToStr(InterruptType Val) { | |||
4789 | switch(Val) { | |||
4790 | case MipsInterruptAttr::sw0: return "vector=sw0"; | |||
4791 | case MipsInterruptAttr::sw1: return "vector=sw1"; | |||
4792 | case MipsInterruptAttr::hw0: return "vector=hw0"; | |||
4793 | case MipsInterruptAttr::hw1: return "vector=hw1"; | |||
4794 | case MipsInterruptAttr::hw2: return "vector=hw2"; | |||
4795 | case MipsInterruptAttr::hw3: return "vector=hw3"; | |||
4796 | case MipsInterruptAttr::hw4: return "vector=hw4"; | |||
4797 | case MipsInterruptAttr::hw5: return "vector=hw5"; | |||
4798 | case MipsInterruptAttr::eic: return "eic"; | |||
4799 | } | |||
4800 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4800); | |||
4801 | } | |||
4802 | ||||
4803 | ||||
4804 | static bool classof(const Attr *A) { return A->getKind() == attr::MipsInterrupt; } | |||
4805 | }; | |||
4806 | ||||
4807 | class MipsLongCallAttr : public InheritableAttr { | |||
4808 | public: | |||
4809 | enum Spelling { | |||
4810 | GNU_long_call = 0, | |||
4811 | CXX11_gnu_long_call = 1, | |||
4812 | GNU_far = 2, | |||
4813 | CXX11_gnu_far = 3 | |||
4814 | }; | |||
4815 | ||||
4816 | static MipsLongCallAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
4817 | auto *A = new (Ctx) MipsLongCallAttr(Loc, Ctx, S); | |||
4818 | A->setImplicit(true); | |||
4819 | return A; | |||
4820 | } | |||
4821 | ||||
4822 | MipsLongCallAttr(SourceRange R, ASTContext &Ctx | |||
4823 | , unsigned SI | |||
4824 | ) | |||
4825 | : InheritableAttr(attr::MipsLongCall, R, SI, false, false) | |||
4826 | { | |||
4827 | } | |||
4828 | ||||
4829 | MipsLongCallAttr *clone(ASTContext &C) const; | |||
4830 | void printPretty(raw_ostream &OS, | |||
4831 | const PrintingPolicy &Policy) const; | |||
4832 | const char *getSpelling() const; | |||
4833 | Spelling getSemanticSpelling() const { | |||
4834 | switch (SpellingListIndex) { | |||
4835 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4835); | |||
4836 | case 0: return GNU_long_call; | |||
4837 | case 1: return CXX11_gnu_long_call; | |||
4838 | case 2: return GNU_far; | |||
4839 | case 3: return CXX11_gnu_far; | |||
4840 | } | |||
4841 | } | |||
4842 | ||||
4843 | ||||
4844 | static bool classof(const Attr *A) { return A->getKind() == attr::MipsLongCall; } | |||
4845 | }; | |||
4846 | ||||
4847 | class MipsShortCallAttr : public InheritableAttr { | |||
4848 | public: | |||
4849 | enum Spelling { | |||
4850 | GNU_short_call = 0, | |||
4851 | CXX11_gnu_short_call = 1, | |||
4852 | GNU_near = 2, | |||
4853 | CXX11_gnu_near = 3 | |||
4854 | }; | |||
4855 | ||||
4856 | static MipsShortCallAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
4857 | auto *A = new (Ctx) MipsShortCallAttr(Loc, Ctx, S); | |||
4858 | A->setImplicit(true); | |||
4859 | return A; | |||
4860 | } | |||
4861 | ||||
4862 | MipsShortCallAttr(SourceRange R, ASTContext &Ctx | |||
4863 | , unsigned SI | |||
4864 | ) | |||
4865 | : InheritableAttr(attr::MipsShortCall, R, SI, false, false) | |||
4866 | { | |||
4867 | } | |||
4868 | ||||
4869 | MipsShortCallAttr *clone(ASTContext &C) const; | |||
4870 | void printPretty(raw_ostream &OS, | |||
4871 | const PrintingPolicy &Policy) const; | |||
4872 | const char *getSpelling() const; | |||
4873 | Spelling getSemanticSpelling() const { | |||
4874 | switch (SpellingListIndex) { | |||
4875 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4875); | |||
4876 | case 0: return GNU_short_call; | |||
4877 | case 1: return CXX11_gnu_short_call; | |||
4878 | case 2: return GNU_near; | |||
4879 | case 3: return CXX11_gnu_near; | |||
4880 | } | |||
4881 | } | |||
4882 | ||||
4883 | ||||
4884 | static bool classof(const Attr *A) { return A->getKind() == attr::MipsShortCall; } | |||
4885 | }; | |||
4886 | ||||
4887 | class ModeAttr : public Attr { | |||
4888 | IdentifierInfo * mode; | |||
4889 | ||||
4890 | public: | |||
4891 | static ModeAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Mode, SourceRange Loc = SourceRange()) { | |||
4892 | auto *A = new (Ctx) ModeAttr(Loc, Ctx, Mode, 0); | |||
4893 | A->setImplicit(true); | |||
4894 | return A; | |||
4895 | } | |||
4896 | ||||
4897 | ModeAttr(SourceRange R, ASTContext &Ctx | |||
4898 | , IdentifierInfo * Mode | |||
4899 | , unsigned SI | |||
4900 | ) | |||
4901 | : Attr(attr::Mode, R, SI, false) | |||
4902 | , mode(Mode) | |||
4903 | { | |||
4904 | } | |||
4905 | ||||
4906 | ModeAttr *clone(ASTContext &C) const; | |||
4907 | void printPretty(raw_ostream &OS, | |||
4908 | const PrintingPolicy &Policy) const; | |||
4909 | const char *getSpelling() const; | |||
4910 | IdentifierInfo * getMode() const { | |||
4911 | return mode; | |||
4912 | } | |||
4913 | ||||
4914 | ||||
4915 | ||||
4916 | static bool classof(const Attr *A) { return A->getKind() == attr::Mode; } | |||
4917 | }; | |||
4918 | ||||
4919 | class NSConsumedAttr : public InheritableParamAttr { | |||
4920 | public: | |||
4921 | static NSConsumedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4922 | auto *A = new (Ctx) NSConsumedAttr(Loc, Ctx, 0); | |||
4923 | A->setImplicit(true); | |||
4924 | return A; | |||
4925 | } | |||
4926 | ||||
4927 | NSConsumedAttr(SourceRange R, ASTContext &Ctx | |||
4928 | , unsigned SI | |||
4929 | ) | |||
4930 | : InheritableParamAttr(attr::NSConsumed, R, SI, false, false) | |||
4931 | { | |||
4932 | } | |||
4933 | ||||
4934 | NSConsumedAttr *clone(ASTContext &C) const; | |||
4935 | void printPretty(raw_ostream &OS, | |||
4936 | const PrintingPolicy &Policy) const; | |||
4937 | const char *getSpelling() const; | |||
4938 | ||||
4939 | ||||
4940 | static bool classof(const Attr *A) { return A->getKind() == attr::NSConsumed; } | |||
4941 | }; | |||
4942 | ||||
4943 | class NSConsumesSelfAttr : public InheritableAttr { | |||
4944 | public: | |||
4945 | static NSConsumesSelfAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4946 | auto *A = new (Ctx) NSConsumesSelfAttr(Loc, Ctx, 0); | |||
4947 | A->setImplicit(true); | |||
4948 | return A; | |||
4949 | } | |||
4950 | ||||
4951 | NSConsumesSelfAttr(SourceRange R, ASTContext &Ctx | |||
4952 | , unsigned SI | |||
4953 | ) | |||
4954 | : InheritableAttr(attr::NSConsumesSelf, R, SI, false, false) | |||
4955 | { | |||
4956 | } | |||
4957 | ||||
4958 | NSConsumesSelfAttr *clone(ASTContext &C) const; | |||
4959 | void printPretty(raw_ostream &OS, | |||
4960 | const PrintingPolicy &Policy) const; | |||
4961 | const char *getSpelling() const; | |||
4962 | ||||
4963 | ||||
4964 | static bool classof(const Attr *A) { return A->getKind() == attr::NSConsumesSelf; } | |||
4965 | }; | |||
4966 | ||||
4967 | class NSReturnsAutoreleasedAttr : public InheritableAttr { | |||
4968 | public: | |||
4969 | static NSReturnsAutoreleasedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4970 | auto *A = new (Ctx) NSReturnsAutoreleasedAttr(Loc, Ctx, 0); | |||
4971 | A->setImplicit(true); | |||
4972 | return A; | |||
4973 | } | |||
4974 | ||||
4975 | NSReturnsAutoreleasedAttr(SourceRange R, ASTContext &Ctx | |||
4976 | , unsigned SI | |||
4977 | ) | |||
4978 | : InheritableAttr(attr::NSReturnsAutoreleased, R, SI, false, false) | |||
4979 | { | |||
4980 | } | |||
4981 | ||||
4982 | NSReturnsAutoreleasedAttr *clone(ASTContext &C) const; | |||
4983 | void printPretty(raw_ostream &OS, | |||
4984 | const PrintingPolicy &Policy) const; | |||
4985 | const char *getSpelling() const; | |||
4986 | ||||
4987 | ||||
4988 | static bool classof(const Attr *A) { return A->getKind() == attr::NSReturnsAutoreleased; } | |||
4989 | }; | |||
4990 | ||||
4991 | class NSReturnsNotRetainedAttr : public InheritableAttr { | |||
4992 | public: | |||
4993 | static NSReturnsNotRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4994 | auto *A = new (Ctx) NSReturnsNotRetainedAttr(Loc, Ctx, 0); | |||
4995 | A->setImplicit(true); | |||
4996 | return A; | |||
4997 | } | |||
4998 | ||||
4999 | NSReturnsNotRetainedAttr(SourceRange R, ASTContext &Ctx | |||
5000 | , unsigned SI | |||
5001 | ) | |||
5002 | : InheritableAttr(attr::NSReturnsNotRetained, R, SI, false, false) | |||
5003 | { | |||
5004 | } | |||
5005 | ||||
5006 | NSReturnsNotRetainedAttr *clone(ASTContext &C) const; | |||
5007 | void printPretty(raw_ostream &OS, | |||
5008 | const PrintingPolicy &Policy) const; | |||
5009 | const char *getSpelling() const; | |||
5010 | ||||
5011 | ||||
5012 | static bool classof(const Attr *A) { return A->getKind() == attr::NSReturnsNotRetained; } | |||
5013 | }; | |||
5014 | ||||
5015 | class NSReturnsRetainedAttr : public InheritableAttr { | |||
5016 | public: | |||
5017 | static NSReturnsRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5018 | auto *A = new (Ctx) NSReturnsRetainedAttr(Loc, Ctx, 0); | |||
5019 | A->setImplicit(true); | |||
5020 | return A; | |||
5021 | } | |||
5022 | ||||
5023 | NSReturnsRetainedAttr(SourceRange R, ASTContext &Ctx | |||
5024 | , unsigned SI | |||
5025 | ) | |||
5026 | : InheritableAttr(attr::NSReturnsRetained, R, SI, false, false) | |||
5027 | { | |||
5028 | } | |||
5029 | ||||
5030 | NSReturnsRetainedAttr *clone(ASTContext &C) const; | |||
5031 | void printPretty(raw_ostream &OS, | |||
5032 | const PrintingPolicy &Policy) const; | |||
5033 | const char *getSpelling() const; | |||
5034 | ||||
5035 | ||||
5036 | static bool classof(const Attr *A) { return A->getKind() == attr::NSReturnsRetained; } | |||
5037 | }; | |||
5038 | ||||
5039 | class NakedAttr : public InheritableAttr { | |||
5040 | public: | |||
5041 | static NakedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5042 | auto *A = new (Ctx) NakedAttr(Loc, Ctx, 0); | |||
5043 | A->setImplicit(true); | |||
5044 | return A; | |||
5045 | } | |||
5046 | ||||
5047 | NakedAttr(SourceRange R, ASTContext &Ctx | |||
5048 | , unsigned SI | |||
5049 | ) | |||
5050 | : InheritableAttr(attr::Naked, R, SI, false, false) | |||
5051 | { | |||
5052 | } | |||
5053 | ||||
5054 | NakedAttr *clone(ASTContext &C) const; | |||
5055 | void printPretty(raw_ostream &OS, | |||
5056 | const PrintingPolicy &Policy) const; | |||
5057 | const char *getSpelling() const; | |||
5058 | ||||
5059 | ||||
5060 | static bool classof(const Attr *A) { return A->getKind() == attr::Naked; } | |||
5061 | }; | |||
5062 | ||||
5063 | class NoAliasAttr : public InheritableAttr { | |||
5064 | public: | |||
5065 | static NoAliasAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5066 | auto *A = new (Ctx) NoAliasAttr(Loc, Ctx, 0); | |||
5067 | A->setImplicit(true); | |||
5068 | return A; | |||
5069 | } | |||
5070 | ||||
5071 | NoAliasAttr(SourceRange R, ASTContext &Ctx | |||
5072 | , unsigned SI | |||
5073 | ) | |||
5074 | : InheritableAttr(attr::NoAlias, R, SI, false, false) | |||
5075 | { | |||
5076 | } | |||
5077 | ||||
5078 | NoAliasAttr *clone(ASTContext &C) const; | |||
5079 | void printPretty(raw_ostream &OS, | |||
5080 | const PrintingPolicy &Policy) const; | |||
5081 | const char *getSpelling() const; | |||
5082 | ||||
5083 | ||||
5084 | static bool classof(const Attr *A) { return A->getKind() == attr::NoAlias; } | |||
5085 | }; | |||
5086 | ||||
5087 | class NoCommonAttr : public InheritableAttr { | |||
5088 | public: | |||
5089 | static NoCommonAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5090 | auto *A = new (Ctx) NoCommonAttr(Loc, Ctx, 0); | |||
5091 | A->setImplicit(true); | |||
5092 | return A; | |||
5093 | } | |||
5094 | ||||
5095 | NoCommonAttr(SourceRange R, ASTContext &Ctx | |||
5096 | , unsigned SI | |||
5097 | ) | |||
5098 | : InheritableAttr(attr::NoCommon, R, SI, false, false) | |||
5099 | { | |||
5100 | } | |||
5101 | ||||
5102 | NoCommonAttr *clone(ASTContext &C) const; | |||
5103 | void printPretty(raw_ostream &OS, | |||
5104 | const PrintingPolicy &Policy) const; | |||
5105 | const char *getSpelling() const; | |||
5106 | ||||
5107 | ||||
5108 | static bool classof(const Attr *A) { return A->getKind() == attr::NoCommon; } | |||
5109 | }; | |||
5110 | ||||
5111 | class NoDebugAttr : public InheritableAttr { | |||
5112 | public: | |||
5113 | static NoDebugAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5114 | auto *A = new (Ctx) NoDebugAttr(Loc, Ctx, 0); | |||
5115 | A->setImplicit(true); | |||
5116 | return A; | |||
5117 | } | |||
5118 | ||||
5119 | NoDebugAttr(SourceRange R, ASTContext &Ctx | |||
5120 | , unsigned SI | |||
5121 | ) | |||
5122 | : InheritableAttr(attr::NoDebug, R, SI, false, false) | |||
5123 | { | |||
5124 | } | |||
5125 | ||||
5126 | NoDebugAttr *clone(ASTContext &C) const; | |||
5127 | void printPretty(raw_ostream &OS, | |||
5128 | const PrintingPolicy &Policy) const; | |||
5129 | const char *getSpelling() const; | |||
5130 | ||||
5131 | ||||
5132 | static bool classof(const Attr *A) { return A->getKind() == attr::NoDebug; } | |||
5133 | }; | |||
5134 | ||||
5135 | class NoDerefAttr : public TypeAttr { | |||
5136 | public: | |||
5137 | static NoDerefAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5138 | auto *A = new (Ctx) NoDerefAttr(Loc, Ctx, 0); | |||
5139 | A->setImplicit(true); | |||
5140 | return A; | |||
5141 | } | |||
5142 | ||||
5143 | NoDerefAttr(SourceRange R, ASTContext &Ctx | |||
5144 | , unsigned SI | |||
5145 | ) | |||
5146 | : TypeAttr(attr::NoDeref, R, SI, false) | |||
5147 | { | |||
5148 | } | |||
5149 | ||||
5150 | NoDerefAttr *clone(ASTContext &C) const; | |||
5151 | void printPretty(raw_ostream &OS, | |||
5152 | const PrintingPolicy &Policy) const; | |||
5153 | const char *getSpelling() const; | |||
5154 | ||||
5155 | ||||
5156 | static bool classof(const Attr *A) { return A->getKind() == attr::NoDeref; } | |||
5157 | }; | |||
5158 | ||||
5159 | class NoDestroyAttr : public InheritableAttr { | |||
5160 | public: | |||
5161 | static NoDestroyAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5162 | auto *A = new (Ctx) NoDestroyAttr(Loc, Ctx, 0); | |||
5163 | A->setImplicit(true); | |||
5164 | return A; | |||
5165 | } | |||
5166 | ||||
5167 | NoDestroyAttr(SourceRange R, ASTContext &Ctx | |||
5168 | , unsigned SI | |||
5169 | ) | |||
5170 | : InheritableAttr(attr::NoDestroy, R, SI, false, false) | |||
5171 | { | |||
5172 | } | |||
5173 | ||||
5174 | NoDestroyAttr *clone(ASTContext &C) const; | |||
5175 | void printPretty(raw_ostream &OS, | |||
5176 | const PrintingPolicy &Policy) const; | |||
5177 | const char *getSpelling() const; | |||
5178 | ||||
5179 | ||||
5180 | static bool classof(const Attr *A) { return A->getKind() == attr::NoDestroy; } | |||
5181 | }; | |||
5182 | ||||
5183 | class NoDuplicateAttr : public InheritableAttr { | |||
5184 | public: | |||
5185 | static NoDuplicateAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5186 | auto *A = new (Ctx) NoDuplicateAttr(Loc, Ctx, 0); | |||
5187 | A->setImplicit(true); | |||
5188 | return A; | |||
5189 | } | |||
5190 | ||||
5191 | NoDuplicateAttr(SourceRange R, ASTContext &Ctx | |||
5192 | , unsigned SI | |||
5193 | ) | |||
5194 | : InheritableAttr(attr::NoDuplicate, R, SI, false, false) | |||
5195 | { | |||
5196 | } | |||
5197 | ||||
5198 | NoDuplicateAttr *clone(ASTContext &C) const; | |||
5199 | void printPretty(raw_ostream &OS, | |||
5200 | const PrintingPolicy &Policy) const; | |||
5201 | const char *getSpelling() const; | |||
5202 | ||||
5203 | ||||
5204 | static bool classof(const Attr *A) { return A->getKind() == attr::NoDuplicate; } | |||
5205 | }; | |||
5206 | ||||
5207 | class NoEscapeAttr : public Attr { | |||
5208 | public: | |||
5209 | static NoEscapeAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5210 | auto *A = new (Ctx) NoEscapeAttr(Loc, Ctx, 0); | |||
5211 | A->setImplicit(true); | |||
5212 | return A; | |||
5213 | } | |||
5214 | ||||
5215 | NoEscapeAttr(SourceRange R, ASTContext &Ctx | |||
5216 | , unsigned SI | |||
5217 | ) | |||
5218 | : Attr(attr::NoEscape, R, SI, false) | |||
5219 | { | |||
5220 | } | |||
5221 | ||||
5222 | NoEscapeAttr *clone(ASTContext &C) const; | |||
5223 | void printPretty(raw_ostream &OS, | |||
5224 | const PrintingPolicy &Policy) const; | |||
5225 | const char *getSpelling() const; | |||
5226 | ||||
5227 | ||||
5228 | static bool classof(const Attr *A) { return A->getKind() == attr::NoEscape; } | |||
5229 | }; | |||
5230 | ||||
5231 | class NoInlineAttr : public InheritableAttr { | |||
5232 | public: | |||
5233 | static NoInlineAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5234 | auto *A = new (Ctx) NoInlineAttr(Loc, Ctx, 0); | |||
5235 | A->setImplicit(true); | |||
5236 | return A; | |||
5237 | } | |||
5238 | ||||
5239 | NoInlineAttr(SourceRange R, ASTContext &Ctx | |||
5240 | , unsigned SI | |||
5241 | ) | |||
5242 | : InheritableAttr(attr::NoInline, R, SI, false, false) | |||
5243 | { | |||
5244 | } | |||
5245 | ||||
5246 | NoInlineAttr *clone(ASTContext &C) const; | |||
5247 | void printPretty(raw_ostream &OS, | |||
5248 | const PrintingPolicy &Policy) const; | |||
5249 | const char *getSpelling() const; | |||
5250 | ||||
5251 | ||||
5252 | static bool classof(const Attr *A) { return A->getKind() == attr::NoInline; } | |||
5253 | }; | |||
5254 | ||||
5255 | class NoInstrumentFunctionAttr : public InheritableAttr { | |||
5256 | public: | |||
5257 | static NoInstrumentFunctionAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5258 | auto *A = new (Ctx) NoInstrumentFunctionAttr(Loc, Ctx, 0); | |||
5259 | A->setImplicit(true); | |||
5260 | return A; | |||
5261 | } | |||
5262 | ||||
5263 | NoInstrumentFunctionAttr(SourceRange R, ASTContext &Ctx | |||
5264 | , unsigned SI | |||
5265 | ) | |||
5266 | : InheritableAttr(attr::NoInstrumentFunction, R, SI, false, false) | |||
5267 | { | |||
5268 | } | |||
5269 | ||||
5270 | NoInstrumentFunctionAttr *clone(ASTContext &C) const; | |||
5271 | void printPretty(raw_ostream &OS, | |||
5272 | const PrintingPolicy &Policy) const; | |||
5273 | const char *getSpelling() const; | |||
5274 | ||||
5275 | ||||
5276 | static bool classof(const Attr *A) { return A->getKind() == attr::NoInstrumentFunction; } | |||
5277 | }; | |||
5278 | ||||
5279 | class NoMicroMipsAttr : public InheritableAttr { | |||
5280 | public: | |||
5281 | static NoMicroMipsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5282 | auto *A = new (Ctx) NoMicroMipsAttr(Loc, Ctx, 0); | |||
5283 | A->setImplicit(true); | |||
5284 | return A; | |||
5285 | } | |||
5286 | ||||
5287 | NoMicroMipsAttr(SourceRange R, ASTContext &Ctx | |||
5288 | , unsigned SI | |||
5289 | ) | |||
5290 | : InheritableAttr(attr::NoMicroMips, R, SI, false, false) | |||
5291 | { | |||
5292 | } | |||
5293 | ||||
5294 | NoMicroMipsAttr *clone(ASTContext &C) const; | |||
5295 | void printPretty(raw_ostream &OS, | |||
5296 | const PrintingPolicy &Policy) const; | |||
5297 | const char *getSpelling() const; | |||
5298 | ||||
5299 | ||||
5300 | static bool classof(const Attr *A) { return A->getKind() == attr::NoMicroMips; } | |||
5301 | }; | |||
5302 | ||||
5303 | class NoMips16Attr : public InheritableAttr { | |||
5304 | public: | |||
5305 | static NoMips16Attr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5306 | auto *A = new (Ctx) NoMips16Attr(Loc, Ctx, 0); | |||
5307 | A->setImplicit(true); | |||
5308 | return A; | |||
5309 | } | |||
5310 | ||||
5311 | NoMips16Attr(SourceRange R, ASTContext &Ctx | |||
5312 | , unsigned SI | |||
5313 | ) | |||
5314 | : InheritableAttr(attr::NoMips16, R, SI, false, false) | |||
5315 | { | |||
5316 | } | |||
5317 | ||||
5318 | NoMips16Attr *clone(ASTContext &C) const; | |||
5319 | void printPretty(raw_ostream &OS, | |||
5320 | const PrintingPolicy &Policy) const; | |||
5321 | const char *getSpelling() const; | |||
5322 | ||||
5323 | ||||
5324 | static bool classof(const Attr *A) { return A->getKind() == attr::NoMips16; } | |||
5325 | }; | |||
5326 | ||||
5327 | class NoReturnAttr : public InheritableAttr { | |||
5328 | public: | |||
5329 | static NoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5330 | auto *A = new (Ctx) NoReturnAttr(Loc, Ctx, 0); | |||
5331 | A->setImplicit(true); | |||
5332 | return A; | |||
5333 | } | |||
5334 | ||||
5335 | NoReturnAttr(SourceRange R, ASTContext &Ctx | |||
5336 | , unsigned SI | |||
5337 | ) | |||
5338 | : InheritableAttr(attr::NoReturn, R, SI, false, false) | |||
5339 | { | |||
5340 | } | |||
5341 | ||||
5342 | NoReturnAttr *clone(ASTContext &C) const; | |||
5343 | void printPretty(raw_ostream &OS, | |||
5344 | const PrintingPolicy &Policy) const; | |||
5345 | const char *getSpelling() const; | |||
5346 | ||||
5347 | ||||
5348 | static bool classof(const Attr *A) { return A->getKind() == attr::NoReturn; } | |||
5349 | }; | |||
5350 | ||||
5351 | class NoSanitizeAttr : public InheritableAttr { | |||
5352 | unsigned sanitizers_Size; | |||
5353 | StringRef *sanitizers_; | |||
5354 | ||||
5355 | public: | |||
5356 | static NoSanitizeAttr *CreateImplicit(ASTContext &Ctx, StringRef *Sanitizers, unsigned SanitizersSize, SourceRange Loc = SourceRange()) { | |||
5357 | auto *A = new (Ctx) NoSanitizeAttr(Loc, Ctx, Sanitizers, SanitizersSize, 0); | |||
5358 | A->setImplicit(true); | |||
5359 | return A; | |||
5360 | } | |||
5361 | ||||
5362 | NoSanitizeAttr(SourceRange R, ASTContext &Ctx | |||
5363 | , StringRef *Sanitizers, unsigned SanitizersSize | |||
5364 | , unsigned SI | |||
5365 | ) | |||
5366 | : InheritableAttr(attr::NoSanitize, R, SI, false, false) | |||
5367 | , sanitizers_Size(SanitizersSize), sanitizers_(new (Ctx, 16) StringRef[sanitizers_Size]) | |||
5368 | { | |||
5369 | for (size_t I = 0, E = sanitizers_Size; I != E; | |||
5370 | ++I) { | |||
5371 | StringRef Ref = Sanitizers[I]; | |||
5372 | if (!Ref.empty()) { | |||
5373 | char *Mem = new (Ctx, 1) char[Ref.size()]; | |||
5374 | std::memcpy(Mem, Ref.data(), Ref.size()); | |||
5375 | sanitizers_[I] = StringRef(Mem, Ref.size()); | |||
5376 | } | |||
5377 | } | |||
5378 | } | |||
5379 | ||||
5380 | NoSanitizeAttr(SourceRange R, ASTContext &Ctx | |||
5381 | , unsigned SI | |||
5382 | ) | |||
5383 | : InheritableAttr(attr::NoSanitize, R, SI, false, false) | |||
5384 | , sanitizers_Size(0), sanitizers_(nullptr) | |||
5385 | { | |||
5386 | } | |||
5387 | ||||
5388 | NoSanitizeAttr *clone(ASTContext &C) const; | |||
5389 | void printPretty(raw_ostream &OS, | |||
5390 | const PrintingPolicy &Policy) const; | |||
5391 | const char *getSpelling() const; | |||
5392 | typedef StringRef* sanitizers_iterator; | |||
5393 | sanitizers_iterator sanitizers_begin() const { return sanitizers_; } | |||
5394 | sanitizers_iterator sanitizers_end() const { return sanitizers_ + sanitizers_Size; } | |||
5395 | unsigned sanitizers_size() const { return sanitizers_Size; } | |||
5396 | llvm::iterator_range<sanitizers_iterator> sanitizers() const { return llvm::make_range(sanitizers_begin(), sanitizers_end()); } | |||
5397 | ||||
5398 | ||||
5399 | ||||
5400 | SanitizerMask getMask() const { | |||
5401 | SanitizerMask Mask; | |||
5402 | for (auto SanitizerName : sanitizers()) { | |||
5403 | SanitizerMask ParsedMask = | |||
5404 | parseSanitizerValue(SanitizerName, /*AllowGroups=*/true); | |||
5405 | Mask |= expandSanitizerGroups(ParsedMask); | |||
5406 | } | |||
5407 | return Mask; | |||
5408 | } | |||
5409 | ||||
5410 | ||||
5411 | static bool classof(const Attr *A) { return A->getKind() == attr::NoSanitize; } | |||
5412 | }; | |||
5413 | ||||
5414 | class NoSpeculativeLoadHardeningAttr : public InheritableAttr { | |||
5415 | public: | |||
5416 | static NoSpeculativeLoadHardeningAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5417 | auto *A = new (Ctx) NoSpeculativeLoadHardeningAttr(Loc, Ctx, 0); | |||
5418 | A->setImplicit(true); | |||
5419 | return A; | |||
5420 | } | |||
5421 | ||||
5422 | NoSpeculativeLoadHardeningAttr(SourceRange R, ASTContext &Ctx | |||
5423 | , unsigned SI | |||
5424 | ) | |||
5425 | : InheritableAttr(attr::NoSpeculativeLoadHardening, R, SI, false, false) | |||
5426 | { | |||
5427 | } | |||
5428 | ||||
5429 | NoSpeculativeLoadHardeningAttr *clone(ASTContext &C) const; | |||
5430 | void printPretty(raw_ostream &OS, | |||
5431 | const PrintingPolicy &Policy) const; | |||
5432 | const char *getSpelling() const; | |||
5433 | ||||
5434 | ||||
5435 | static bool classof(const Attr *A) { return A->getKind() == attr::NoSpeculativeLoadHardening; } | |||
5436 | }; | |||
5437 | ||||
5438 | class NoSplitStackAttr : public InheritableAttr { | |||
5439 | public: | |||
5440 | static NoSplitStackAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5441 | auto *A = new (Ctx) NoSplitStackAttr(Loc, Ctx, 0); | |||
5442 | A->setImplicit(true); | |||
5443 | return A; | |||
5444 | } | |||
5445 | ||||
5446 | NoSplitStackAttr(SourceRange R, ASTContext &Ctx | |||
5447 | , unsigned SI | |||
5448 | ) | |||
5449 | : InheritableAttr(attr::NoSplitStack, R, SI, false, false) | |||
5450 | { | |||
5451 | } | |||
5452 | ||||
5453 | NoSplitStackAttr *clone(ASTContext &C) const; | |||
5454 | void printPretty(raw_ostream &OS, | |||
5455 | const PrintingPolicy &Policy) const; | |||
5456 | const char *getSpelling() const; | |||
5457 | ||||
5458 | ||||
5459 | static bool classof(const Attr *A) { return A->getKind() == attr::NoSplitStack; } | |||
5460 | }; | |||
5461 | ||||
5462 | class NoStackProtectorAttr : public InheritableAttr { | |||
5463 | public: | |||
5464 | static NoStackProtectorAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5465 | auto *A = new (Ctx) NoStackProtectorAttr(Loc, Ctx, 0); | |||
5466 | A->setImplicit(true); | |||
5467 | return A; | |||
5468 | } | |||
5469 | ||||
5470 | NoStackProtectorAttr(SourceRange R, ASTContext &Ctx | |||
5471 | , unsigned SI | |||
5472 | ) | |||
5473 | : InheritableAttr(attr::NoStackProtector, R, SI, false, false) | |||
5474 | { | |||
5475 | } | |||
5476 | ||||
5477 | NoStackProtectorAttr *clone(ASTContext &C) const; | |||
5478 | void printPretty(raw_ostream &OS, | |||
5479 | const PrintingPolicy &Policy) const; | |||
5480 | const char *getSpelling() const; | |||
5481 | ||||
5482 | ||||
5483 | static bool classof(const Attr *A) { return A->getKind() == attr::NoStackProtector; } | |||
5484 | }; | |||
5485 | ||||
5486 | class NoThreadSafetyAnalysisAttr : public InheritableAttr { | |||
5487 | public: | |||
5488 | static NoThreadSafetyAnalysisAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5489 | auto *A = new (Ctx) NoThreadSafetyAnalysisAttr(Loc, Ctx, 0); | |||
5490 | A->setImplicit(true); | |||
5491 | return A; | |||
5492 | } | |||
5493 | ||||
5494 | NoThreadSafetyAnalysisAttr(SourceRange R, ASTContext &Ctx | |||
5495 | , unsigned SI | |||
5496 | ) | |||
5497 | : InheritableAttr(attr::NoThreadSafetyAnalysis, R, SI, false, false) | |||
5498 | { | |||
5499 | } | |||
5500 | ||||
5501 | NoThreadSafetyAnalysisAttr *clone(ASTContext &C) const; | |||
5502 | void printPretty(raw_ostream &OS, | |||
5503 | const PrintingPolicy &Policy) const; | |||
5504 | const char *getSpelling() const; | |||
5505 | ||||
5506 | ||||
5507 | static bool classof(const Attr *A) { return A->getKind() == attr::NoThreadSafetyAnalysis; } | |||
5508 | }; | |||
5509 | ||||
5510 | class NoThrowAttr : public InheritableAttr { | |||
5511 | public: | |||
5512 | static NoThrowAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5513 | auto *A = new (Ctx) NoThrowAttr(Loc, Ctx, 0); | |||
5514 | A->setImplicit(true); | |||
5515 | return A; | |||
5516 | } | |||
5517 | ||||
5518 | NoThrowAttr(SourceRange R, ASTContext &Ctx | |||
5519 | , unsigned SI | |||
5520 | ) | |||
5521 | : InheritableAttr(attr::NoThrow, R, SI, false, false) | |||
5522 | { | |||
5523 | } | |||
5524 | ||||
5525 | NoThrowAttr *clone(ASTContext &C) const; | |||
5526 | void printPretty(raw_ostream &OS, | |||
5527 | const PrintingPolicy &Policy) const; | |||
5528 | const char *getSpelling() const; | |||
5529 | ||||
5530 | ||||
5531 | static bool classof(const Attr *A) { return A->getKind() == attr::NoThrow; } | |||
5532 | }; | |||
5533 | ||||
5534 | class NonNullAttr : public InheritableParamAttr { | |||
5535 | unsigned args_Size; | |||
5536 | ParamIdx *args_; | |||
5537 | ||||
5538 | public: | |||
5539 | static NonNullAttr *CreateImplicit(ASTContext &Ctx, ParamIdx *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
5540 | auto *A = new (Ctx) NonNullAttr(Loc, Ctx, Args, ArgsSize, 0); | |||
5541 | A->setImplicit(true); | |||
5542 | return A; | |||
5543 | } | |||
5544 | ||||
5545 | NonNullAttr(SourceRange R, ASTContext &Ctx | |||
5546 | , ParamIdx *Args, unsigned ArgsSize | |||
5547 | , unsigned SI | |||
5548 | ) | |||
5549 | : InheritableParamAttr(attr::NonNull, R, SI, false, true) | |||
5550 | , args_Size(ArgsSize), args_(new (Ctx, 16) ParamIdx[args_Size]) | |||
5551 | { | |||
5552 | std::copy(Args, Args + args_Size, args_); | |||
5553 | } | |||
5554 | ||||
5555 | NonNullAttr(SourceRange R, ASTContext &Ctx | |||
5556 | , unsigned SI | |||
5557 | ) | |||
5558 | : InheritableParamAttr(attr::NonNull, R, SI, false, true) | |||
5559 | , args_Size(0), args_(nullptr) | |||
5560 | { | |||
5561 | } | |||
5562 | ||||
5563 | NonNullAttr *clone(ASTContext &C) const; | |||
5564 | void printPretty(raw_ostream &OS, | |||
5565 | const PrintingPolicy &Policy) const; | |||
5566 | const char *getSpelling() const; | |||
5567 | typedef ParamIdx* args_iterator; | |||
5568 | args_iterator args_begin() const { return args_; } | |||
5569 | args_iterator args_end() const { return args_ + args_Size; } | |||
5570 | unsigned args_size() const { return args_Size; } | |||
5571 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
5572 | ||||
5573 | ||||
5574 | ||||
5575 | bool isNonNull(unsigned IdxAST) const { | |||
5576 | if (!args_size()) | |||
5577 | return true; | |||
5578 | return args_end() != std::find_if( | |||
5579 | args_begin(), args_end(), | |||
5580 | [=](const ParamIdx &Idx) { return Idx.getASTIndex() == IdxAST; }); | |||
5581 | } | |||
5582 | ||||
5583 | ||||
5584 | static bool classof(const Attr *A) { return A->getKind() == attr::NonNull; } | |||
5585 | }; | |||
5586 | ||||
5587 | class NotTailCalledAttr : public InheritableAttr { | |||
5588 | public: | |||
5589 | static NotTailCalledAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5590 | auto *A = new (Ctx) NotTailCalledAttr(Loc, Ctx, 0); | |||
5591 | A->setImplicit(true); | |||
5592 | return A; | |||
5593 | } | |||
5594 | ||||
5595 | NotTailCalledAttr(SourceRange R, ASTContext &Ctx | |||
5596 | , unsigned SI | |||
5597 | ) | |||
5598 | : InheritableAttr(attr::NotTailCalled, R, SI, false, false) | |||
5599 | { | |||
5600 | } | |||
5601 | ||||
5602 | NotTailCalledAttr *clone(ASTContext &C) const; | |||
5603 | void printPretty(raw_ostream &OS, | |||
5604 | const PrintingPolicy &Policy) const; | |||
5605 | const char *getSpelling() const; | |||
5606 | ||||
5607 | ||||
5608 | static bool classof(const Attr *A) { return A->getKind() == attr::NotTailCalled; } | |||
5609 | }; | |||
5610 | ||||
5611 | class OMPAllocateDeclAttr : public InheritableAttr { | |||
5612 | public: | |||
5613 | enum AllocatorTypeTy { | |||
5614 | OMPDefaultMemAlloc, | |||
5615 | OMPLargeCapMemAlloc, | |||
5616 | OMPConstMemAlloc, | |||
5617 | OMPHighBWMemAlloc, | |||
5618 | OMPLowLatMemAlloc, | |||
5619 | OMPCGroupMemAlloc, | |||
5620 | OMPPTeamMemAlloc, | |||
5621 | OMPThreadMemAlloc, | |||
5622 | OMPUserDefinedMemAlloc | |||
5623 | }; | |||
5624 | private: | |||
5625 | AllocatorTypeTy allocatorType; | |||
5626 | ||||
5627 | Expr * allocator; | |||
5628 | ||||
5629 | public: | |||
5630 | static OMPAllocateDeclAttr *CreateImplicit(ASTContext &Ctx, AllocatorTypeTy AllocatorType, Expr * Allocator, SourceRange Loc = SourceRange()) { | |||
5631 | auto *A = new (Ctx) OMPAllocateDeclAttr(Loc, Ctx, AllocatorType, Allocator, 0); | |||
5632 | A->setImplicit(true); | |||
5633 | return A; | |||
5634 | } | |||
5635 | ||||
5636 | OMPAllocateDeclAttr(SourceRange R, ASTContext &Ctx | |||
5637 | , AllocatorTypeTy AllocatorType | |||
5638 | , Expr * Allocator | |||
5639 | , unsigned SI | |||
5640 | ) | |||
5641 | : InheritableAttr(attr::OMPAllocateDecl, R, SI, false, false) | |||
5642 | , allocatorType(AllocatorType) | |||
5643 | , allocator(Allocator) | |||
5644 | { | |||
5645 | } | |||
5646 | ||||
5647 | OMPAllocateDeclAttr *clone(ASTContext &C) const; | |||
5648 | void printPretty(raw_ostream &OS, | |||
5649 | const PrintingPolicy &Policy) const; | |||
5650 | const char *getSpelling() const; | |||
5651 | AllocatorTypeTy getAllocatorType() const { | |||
5652 | return allocatorType; | |||
5653 | } | |||
5654 | ||||
5655 | static bool ConvertStrToAllocatorTypeTy(StringRef Val, AllocatorTypeTy &Out) { | |||
5656 | Optional<AllocatorTypeTy> R = llvm::StringSwitch<Optional<AllocatorTypeTy>>(Val) | |||
5657 | .Case("omp_default_mem_alloc", OMPAllocateDeclAttr::OMPDefaultMemAlloc) | |||
5658 | .Case("omp_large_cap_mem_alloc", OMPAllocateDeclAttr::OMPLargeCapMemAlloc) | |||
5659 | .Case("omp_const_mem_alloc", OMPAllocateDeclAttr::OMPConstMemAlloc) | |||
5660 | .Case("omp_high_bw_mem_alloc", OMPAllocateDeclAttr::OMPHighBWMemAlloc) | |||
5661 | .Case("omp_low_lat_mem_alloc", OMPAllocateDeclAttr::OMPLowLatMemAlloc) | |||
5662 | .Case("omp_cgroup_mem_alloc", OMPAllocateDeclAttr::OMPCGroupMemAlloc) | |||
5663 | .Case("omp_pteam_mem_alloc", OMPAllocateDeclAttr::OMPPTeamMemAlloc) | |||
5664 | .Case("omp_thread_mem_alloc", OMPAllocateDeclAttr::OMPThreadMemAlloc) | |||
5665 | .Case("", OMPAllocateDeclAttr::OMPUserDefinedMemAlloc) | |||
5666 | .Default(Optional<AllocatorTypeTy>()); | |||
5667 | if (R) { | |||
5668 | Out = *R; | |||
5669 | return true; | |||
5670 | } | |||
5671 | return false; | |||
5672 | } | |||
5673 | ||||
5674 | static const char *ConvertAllocatorTypeTyToStr(AllocatorTypeTy Val) { | |||
5675 | switch(Val) { | |||
5676 | case OMPAllocateDeclAttr::OMPDefaultMemAlloc: return "omp_default_mem_alloc"; | |||
5677 | case OMPAllocateDeclAttr::OMPLargeCapMemAlloc: return "omp_large_cap_mem_alloc"; | |||
5678 | case OMPAllocateDeclAttr::OMPConstMemAlloc: return "omp_const_mem_alloc"; | |||
5679 | case OMPAllocateDeclAttr::OMPHighBWMemAlloc: return "omp_high_bw_mem_alloc"; | |||
5680 | case OMPAllocateDeclAttr::OMPLowLatMemAlloc: return "omp_low_lat_mem_alloc"; | |||
5681 | case OMPAllocateDeclAttr::OMPCGroupMemAlloc: return "omp_cgroup_mem_alloc"; | |||
5682 | case OMPAllocateDeclAttr::OMPPTeamMemAlloc: return "omp_pteam_mem_alloc"; | |||
5683 | case OMPAllocateDeclAttr::OMPThreadMemAlloc: return "omp_thread_mem_alloc"; | |||
5684 | case OMPAllocateDeclAttr::OMPUserDefinedMemAlloc: return ""; | |||
5685 | } | |||
5686 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 5686); | |||
5687 | } | |||
5688 | Expr * getAllocator() const { | |||
5689 | return allocator; | |||
5690 | } | |||
5691 | ||||
5692 | ||||
5693 | ||||
5694 | static bool classof(const Attr *A) { return A->getKind() == attr::OMPAllocateDecl; } | |||
5695 | }; | |||
5696 | ||||
5697 | class OMPCaptureKindAttr : public Attr { | |||
5698 | unsigned captureKind; | |||
5699 | ||||
5700 | public: | |||
5701 | static OMPCaptureKindAttr *CreateImplicit(ASTContext &Ctx, unsigned CaptureKind, SourceRange Loc = SourceRange()) { | |||
5702 | auto *A = new (Ctx) OMPCaptureKindAttr(Loc, Ctx, CaptureKind, 0); | |||
5703 | A->setImplicit(true); | |||
5704 | return A; | |||
5705 | } | |||
5706 | ||||
5707 | OMPCaptureKindAttr(SourceRange R, ASTContext &Ctx | |||
5708 | , unsigned CaptureKind | |||
5709 | , unsigned SI | |||
5710 | ) | |||
5711 | : Attr(attr::OMPCaptureKind, R, SI, false) | |||
5712 | , captureKind(CaptureKind) | |||
5713 | { | |||
5714 | } | |||
5715 | ||||
5716 | OMPCaptureKindAttr *clone(ASTContext &C) const; | |||
5717 | void printPretty(raw_ostream &OS, | |||
5718 | const PrintingPolicy &Policy) const; | |||
5719 | const char *getSpelling() const; | |||
5720 | unsigned getCaptureKind() const { | |||
5721 | return captureKind; | |||
5722 | } | |||
5723 | ||||
5724 | ||||
5725 | ||||
5726 | static bool classof(const Attr *A) { return A->getKind() == attr::OMPCaptureKind; } | |||
5727 | }; | |||
5728 | ||||
5729 | class OMPCaptureNoInitAttr : public InheritableAttr { | |||
5730 | public: | |||
5731 | static OMPCaptureNoInitAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5732 | auto *A = new (Ctx) OMPCaptureNoInitAttr(Loc, Ctx, 0); | |||
5733 | A->setImplicit(true); | |||
5734 | return A; | |||
5735 | } | |||
5736 | ||||
5737 | OMPCaptureNoInitAttr(SourceRange R, ASTContext &Ctx | |||
5738 | , unsigned SI | |||
5739 | ) | |||
5740 | : InheritableAttr(attr::OMPCaptureNoInit, R, SI, false, false) | |||
5741 | { | |||
5742 | } | |||
5743 | ||||
5744 | OMPCaptureNoInitAttr *clone(ASTContext &C) const; | |||
5745 | void printPretty(raw_ostream &OS, | |||
5746 | const PrintingPolicy &Policy) const; | |||
5747 | const char *getSpelling() const; | |||
5748 | ||||
5749 | ||||
5750 | static bool classof(const Attr *A) { return A->getKind() == attr::OMPCaptureNoInit; } | |||
5751 | }; | |||
5752 | ||||
5753 | class OMPDeclareSimdDeclAttr : public Attr { | |||
5754 | public: | |||
5755 | enum BranchStateTy { | |||
5756 | BS_Undefined, | |||
5757 | BS_Inbranch, | |||
5758 | BS_Notinbranch | |||
5759 | }; | |||
5760 | private: | |||
5761 | BranchStateTy branchState; | |||
5762 | ||||
5763 | Expr * simdlen; | |||
5764 | ||||
5765 | unsigned uniforms_Size; | |||
5766 | Expr * *uniforms_; | |||
5767 | ||||
5768 | unsigned aligneds_Size; | |||
5769 | Expr * *aligneds_; | |||
5770 | ||||
5771 | unsigned alignments_Size; | |||
5772 | Expr * *alignments_; | |||
5773 | ||||
5774 | unsigned linears_Size; | |||
5775 | Expr * *linears_; | |||
5776 | ||||
5777 | unsigned modifiers_Size; | |||
5778 | unsigned *modifiers_; | |||
5779 | ||||
5780 | unsigned steps_Size; | |||
5781 | Expr * *steps_; | |||
5782 | ||||
5783 | public: | |||
5784 | static OMPDeclareSimdDeclAttr *CreateImplicit(ASTContext &Ctx, BranchStateTy BranchState, Expr * Simdlen, Expr * *Uniforms, unsigned UniformsSize, Expr * *Aligneds, unsigned AlignedsSize, Expr * *Alignments, unsigned AlignmentsSize, Expr * *Linears, unsigned LinearsSize, unsigned *Modifiers, unsigned ModifiersSize, Expr * *Steps, unsigned StepsSize, SourceRange Loc = SourceRange()) { | |||
5785 | auto *A = new (Ctx) OMPDeclareSimdDeclAttr(Loc, Ctx, BranchState, Simdlen, Uniforms, UniformsSize, Aligneds, AlignedsSize, Alignments, AlignmentsSize, Linears, LinearsSize, Modifiers, ModifiersSize, Steps, StepsSize, 0); | |||
5786 | A->setImplicit(true); | |||
5787 | return A; | |||
5788 | } | |||
5789 | ||||
5790 | OMPDeclareSimdDeclAttr(SourceRange R, ASTContext &Ctx | |||
5791 | , BranchStateTy BranchState | |||
5792 | , Expr * Simdlen | |||
5793 | , Expr * *Uniforms, unsigned UniformsSize | |||
5794 | , Expr * *Aligneds, unsigned AlignedsSize | |||
5795 | , Expr * *Alignments, unsigned AlignmentsSize | |||
5796 | , Expr * *Linears, unsigned LinearsSize | |||
5797 | , unsigned *Modifiers, unsigned ModifiersSize | |||
5798 | , Expr * *Steps, unsigned StepsSize | |||
5799 | , unsigned SI | |||
5800 | ) | |||
5801 | : Attr(attr::OMPDeclareSimdDecl, R, SI, false) | |||
5802 | , branchState(BranchState) | |||
5803 | , simdlen(Simdlen) | |||
5804 | , uniforms_Size(UniformsSize), uniforms_(new (Ctx, 16) Expr *[uniforms_Size]) | |||
5805 | , aligneds_Size(AlignedsSize), aligneds_(new (Ctx, 16) Expr *[aligneds_Size]) | |||
5806 | , alignments_Size(AlignmentsSize), alignments_(new (Ctx, 16) Expr *[alignments_Size]) | |||
5807 | , linears_Size(LinearsSize), linears_(new (Ctx, 16) Expr *[linears_Size]) | |||
5808 | , modifiers_Size(ModifiersSize), modifiers_(new (Ctx, 16) unsigned[modifiers_Size]) | |||
5809 | , steps_Size(StepsSize), steps_(new (Ctx, 16) Expr *[steps_Size]) | |||
5810 | { | |||
5811 | std::copy(Uniforms, Uniforms + uniforms_Size, uniforms_); | |||
5812 | std::copy(Aligneds, Aligneds + aligneds_Size, aligneds_); | |||
5813 | std::copy(Alignments, Alignments + alignments_Size, alignments_); | |||
5814 | std::copy(Linears, Linears + linears_Size, linears_); | |||
5815 | std::copy(Modifiers, Modifiers + modifiers_Size, modifiers_); | |||
5816 | std::copy(Steps, Steps + steps_Size, steps_); | |||
5817 | } | |||
5818 | ||||
5819 | OMPDeclareSimdDeclAttr(SourceRange R, ASTContext &Ctx | |||
5820 | , BranchStateTy BranchState | |||
5821 | , Expr * Simdlen | |||
5822 | , unsigned SI | |||
5823 | ) | |||
5824 | : Attr(attr::OMPDeclareSimdDecl, R, SI, false) | |||
5825 | , branchState(BranchState) | |||
5826 | , simdlen(Simdlen) | |||
5827 | , uniforms_Size(0), uniforms_(nullptr) | |||
5828 | , aligneds_Size(0), aligneds_(nullptr) | |||
5829 | , alignments_Size(0), alignments_(nullptr) | |||
5830 | , linears_Size(0), linears_(nullptr) | |||
5831 | , modifiers_Size(0), modifiers_(nullptr) | |||
5832 | , steps_Size(0), steps_(nullptr) | |||
5833 | { | |||
5834 | } | |||
5835 | ||||
5836 | OMPDeclareSimdDeclAttr *clone(ASTContext &C) const; | |||
5837 | void printPretty(raw_ostream &OS, | |||
5838 | const PrintingPolicy &Policy) const; | |||
5839 | const char *getSpelling() const; | |||
5840 | BranchStateTy getBranchState() const { | |||
5841 | return branchState; | |||
5842 | } | |||
5843 | ||||
5844 | static bool ConvertStrToBranchStateTy(StringRef Val, BranchStateTy &Out) { | |||
5845 | Optional<BranchStateTy> R = llvm::StringSwitch<Optional<BranchStateTy>>(Val) | |||
5846 | .Case("", OMPDeclareSimdDeclAttr::BS_Undefined) | |||
5847 | .Case("inbranch", OMPDeclareSimdDeclAttr::BS_Inbranch) | |||
5848 | .Case("notinbranch", OMPDeclareSimdDeclAttr::BS_Notinbranch) | |||
5849 | .Default(Optional<BranchStateTy>()); | |||
5850 | if (R) { | |||
5851 | Out = *R; | |||
5852 | return true; | |||
5853 | } | |||
5854 | return false; | |||
5855 | } | |||
5856 | ||||
5857 | static const char *ConvertBranchStateTyToStr(BranchStateTy Val) { | |||
5858 | switch(Val) { | |||
5859 | case OMPDeclareSimdDeclAttr::BS_Undefined: return ""; | |||
5860 | case OMPDeclareSimdDeclAttr::BS_Inbranch: return "inbranch"; | |||
5861 | case OMPDeclareSimdDeclAttr::BS_Notinbranch: return "notinbranch"; | |||
5862 | } | |||
5863 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 5863); | |||
5864 | } | |||
5865 | Expr * getSimdlen() const { | |||
5866 | return simdlen; | |||
5867 | } | |||
5868 | ||||
5869 | typedef Expr ** uniforms_iterator; | |||
5870 | uniforms_iterator uniforms_begin() const { return uniforms_; } | |||
5871 | uniforms_iterator uniforms_end() const { return uniforms_ + uniforms_Size; } | |||
5872 | unsigned uniforms_size() const { return uniforms_Size; } | |||
5873 | llvm::iterator_range<uniforms_iterator> uniforms() const { return llvm::make_range(uniforms_begin(), uniforms_end()); } | |||
5874 | ||||
5875 | ||||
5876 | typedef Expr ** aligneds_iterator; | |||
5877 | aligneds_iterator aligneds_begin() const { return aligneds_; } | |||
5878 | aligneds_iterator aligneds_end() const { return aligneds_ + aligneds_Size; } | |||
5879 | unsigned aligneds_size() const { return aligneds_Size; } | |||
5880 | llvm::iterator_range<aligneds_iterator> aligneds() const { return llvm::make_range(aligneds_begin(), aligneds_end()); } | |||
5881 | ||||
5882 | ||||
5883 | typedef Expr ** alignments_iterator; | |||
5884 | alignments_iterator alignments_begin() const { return alignments_; } | |||
5885 | alignments_iterator alignments_end() const { return alignments_ + alignments_Size; } | |||
5886 | unsigned alignments_size() const { return alignments_Size; } | |||
5887 | llvm::iterator_range<alignments_iterator> alignments() const { return llvm::make_range(alignments_begin(), alignments_end()); } | |||
5888 | ||||
5889 | ||||
5890 | typedef Expr ** linears_iterator; | |||
5891 | linears_iterator linears_begin() const { return linears_; } | |||
5892 | linears_iterator linears_end() const { return linears_ + linears_Size; } | |||
5893 | unsigned linears_size() const { return linears_Size; } | |||
5894 | llvm::iterator_range<linears_iterator> linears() const { return llvm::make_range(linears_begin(), linears_end()); } | |||
5895 | ||||
5896 | ||||
5897 | typedef unsigned* modifiers_iterator; | |||
5898 | modifiers_iterator modifiers_begin() const { return modifiers_; } | |||
5899 | modifiers_iterator modifiers_end() const { return modifiers_ + modifiers_Size; } | |||
5900 | unsigned modifiers_size() const { return modifiers_Size; } | |||
5901 | llvm::iterator_range<modifiers_iterator> modifiers() const { return llvm::make_range(modifiers_begin(), modifiers_end()); } | |||
5902 | ||||
5903 | ||||
5904 | typedef Expr ** steps_iterator; | |||
5905 | steps_iterator steps_begin() const { return steps_; } | |||
5906 | steps_iterator steps_end() const { return steps_ + steps_Size; } | |||
5907 | unsigned steps_size() const { return steps_Size; } | |||
5908 | llvm::iterator_range<steps_iterator> steps() const { return llvm::make_range(steps_begin(), steps_end()); } | |||
5909 | ||||
5910 | ||||
5911 | ||||
5912 | void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy) | |||
5913 | const { | |||
5914 | if (getBranchState() != BS_Undefined) | |||
5915 | OS << ' ' << ConvertBranchStateTyToStr(getBranchState()); | |||
5916 | if (auto *E = getSimdlen()) { | |||
5917 | OS << " simdlen("; | |||
5918 | E->printPretty(OS, nullptr, Policy); | |||
5919 | OS << ")"; | |||
5920 | } | |||
5921 | if (uniforms_size() > 0) { | |||
5922 | OS << " uniform"; | |||
5923 | StringRef Sep = "("; | |||
5924 | for (auto *E : uniforms()) { | |||
5925 | OS << Sep; | |||
5926 | E->printPretty(OS, nullptr, Policy); | |||
5927 | Sep = ", "; | |||
5928 | } | |||
5929 | OS << ")"; | |||
5930 | } | |||
5931 | alignments_iterator NI = alignments_begin(); | |||
5932 | for (auto *E : aligneds()) { | |||
5933 | OS << " aligned("; | |||
5934 | E->printPretty(OS, nullptr, Policy); | |||
5935 | if (*NI) { | |||
5936 | OS << ": "; | |||
5937 | (*NI)->printPretty(OS, nullptr, Policy); | |||
5938 | } | |||
5939 | OS << ")"; | |||
5940 | ++NI; | |||
5941 | } | |||
5942 | steps_iterator I = steps_begin(); | |||
5943 | modifiers_iterator MI = modifiers_begin(); | |||
5944 | for (auto *E : linears()) { | |||
5945 | OS << " linear("; | |||
5946 | if (*MI != OMPC_LINEAR_unknown) | |||
5947 | OS << getOpenMPSimpleClauseTypeName(OMPC_linear, *MI) << "("; | |||
5948 | E->printPretty(OS, nullptr, Policy); | |||
5949 | if (*MI != OMPC_LINEAR_unknown) | |||
5950 | OS << ")"; | |||
5951 | if (*I) { | |||
5952 | OS << ": "; | |||
5953 | (*I)->printPretty(OS, nullptr, Policy); | |||
5954 | } | |||
5955 | OS << ")"; | |||
5956 | ++I; | |||
5957 | ++MI; | |||
5958 | } | |||
5959 | } | |||
5960 | ||||
5961 | ||||
5962 | static bool classof(const Attr *A) { return A->getKind() == attr::OMPDeclareSimdDecl; } | |||
5963 | }; | |||
5964 | ||||
5965 | class OMPDeclareTargetDeclAttr : public InheritableAttr { | |||
5966 | public: | |||
5967 | enum MapTypeTy { | |||
5968 | MT_To, | |||
5969 | MT_Link | |||
5970 | }; | |||
5971 | private: | |||
5972 | MapTypeTy mapType; | |||
5973 | ||||
5974 | public: | |||
5975 | static OMPDeclareTargetDeclAttr *CreateImplicit(ASTContext &Ctx, MapTypeTy MapType, SourceRange Loc = SourceRange()) { | |||
5976 | auto *A = new (Ctx) OMPDeclareTargetDeclAttr(Loc, Ctx, MapType, 0); | |||
5977 | A->setImplicit(true); | |||
5978 | return A; | |||
5979 | } | |||
5980 | ||||
5981 | OMPDeclareTargetDeclAttr(SourceRange R, ASTContext &Ctx | |||
5982 | , MapTypeTy MapType | |||
5983 | , unsigned SI | |||
5984 | ) | |||
5985 | : InheritableAttr(attr::OMPDeclareTargetDecl, R, SI, false, false) | |||
5986 | , mapType(MapType) | |||
5987 | { | |||
5988 | } | |||
5989 | ||||
5990 | OMPDeclareTargetDeclAttr *clone(ASTContext &C) const; | |||
5991 | void printPretty(raw_ostream &OS, | |||
5992 | const PrintingPolicy &Policy) const; | |||
5993 | const char *getSpelling() const; | |||
5994 | MapTypeTy getMapType() const { | |||
5995 | return mapType; | |||
5996 | } | |||
5997 | ||||
5998 | static bool ConvertStrToMapTypeTy(StringRef Val, MapTypeTy &Out) { | |||
5999 | Optional<MapTypeTy> R = llvm::StringSwitch<Optional<MapTypeTy>>(Val) | |||
6000 | .Case("to", OMPDeclareTargetDeclAttr::MT_To) | |||
6001 | .Case("link", OMPDeclareTargetDeclAttr::MT_Link) | |||
6002 | .Default(Optional<MapTypeTy>()); | |||
6003 | if (R) { | |||
6004 | Out = *R; | |||
6005 | return true; | |||
6006 | } | |||
6007 | return false; | |||
6008 | } | |||
6009 | ||||
6010 | static const char *ConvertMapTypeTyToStr(MapTypeTy Val) { | |||
6011 | switch(Val) { | |||
6012 | case OMPDeclareTargetDeclAttr::MT_To: return "to"; | |||
6013 | case OMPDeclareTargetDeclAttr::MT_Link: return "link"; | |||
6014 | } | |||
6015 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 6015); | |||
6016 | } | |||
6017 | ||||
6018 | void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const { | |||
6019 | // Use fake syntax because it is for testing and debugging purpose only. | |||
6020 | if (getMapType() != MT_To) | |||
6021 | OS << ' ' << ConvertMapTypeTyToStr(getMapType()); | |||
6022 | } | |||
6023 | static llvm::Optional<MapTypeTy> | |||
6024 | isDeclareTargetDeclaration(const ValueDecl *VD) { | |||
6025 | if (!VD->hasAttrs()) | |||
6026 | return llvm::None; | |||
6027 | if (const auto *Attr = VD->getAttr<OMPDeclareTargetDeclAttr>()) | |||
6028 | return Attr->getMapType(); | |||
6029 | ||||
6030 | return llvm::None; | |||
6031 | } | |||
6032 | ||||
6033 | ||||
6034 | static bool classof(const Attr *A) { return A->getKind() == attr::OMPDeclareTargetDecl; } | |||
6035 | }; | |||
6036 | ||||
6037 | class OMPReferencedVarAttr : public Attr { | |||
6038 | Expr * ref; | |||
6039 | ||||
6040 | public: | |||
6041 | static OMPReferencedVarAttr *CreateImplicit(ASTContext &Ctx, Expr * Ref, SourceRange Loc = SourceRange()) { | |||
6042 | auto *A = new (Ctx) OMPReferencedVarAttr(Loc, Ctx, Ref, 0); | |||
6043 | A->setImplicit(true); | |||
6044 | return A; | |||
6045 | } | |||
6046 | ||||
6047 | OMPReferencedVarAttr(SourceRange R, ASTContext &Ctx | |||
6048 | , Expr * Ref | |||
6049 | , unsigned SI | |||
6050 | ) | |||
6051 | : Attr(attr::OMPReferencedVar, R, SI, false) | |||
6052 | , ref(Ref) | |||
6053 | { | |||
6054 | } | |||
6055 | ||||
6056 | OMPReferencedVarAttr *clone(ASTContext &C) const; | |||
6057 | void printPretty(raw_ostream &OS, | |||
6058 | const PrintingPolicy &Policy) const; | |||
6059 | const char *getSpelling() const; | |||
6060 | Expr * getRef() const { | |||
6061 | return ref; | |||
6062 | } | |||
6063 | ||||
6064 | ||||
6065 | ||||
6066 | static bool classof(const Attr *A) { return A->getKind() == attr::OMPReferencedVar; } | |||
6067 | }; | |||
6068 | ||||
6069 | class OMPThreadPrivateDeclAttr : public InheritableAttr { | |||
6070 | public: | |||
6071 | static OMPThreadPrivateDeclAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6072 | auto *A = new (Ctx) OMPThreadPrivateDeclAttr(Loc, Ctx, 0); | |||
6073 | A->setImplicit(true); | |||
6074 | return A; | |||
6075 | } | |||
6076 | ||||
6077 | OMPThreadPrivateDeclAttr(SourceRange R, ASTContext &Ctx | |||
6078 | , unsigned SI | |||
6079 | ) | |||
6080 | : InheritableAttr(attr::OMPThreadPrivateDecl, R, SI, false, false) | |||
6081 | { | |||
6082 | } | |||
6083 | ||||
6084 | OMPThreadPrivateDeclAttr *clone(ASTContext &C) const; | |||
6085 | void printPretty(raw_ostream &OS, | |||
6086 | const PrintingPolicy &Policy) const; | |||
6087 | const char *getSpelling() const; | |||
6088 | ||||
6089 | ||||
6090 | static bool classof(const Attr *A) { return A->getKind() == attr::OMPThreadPrivateDecl; } | |||
6091 | }; | |||
6092 | ||||
6093 | class OSConsumedAttr : public InheritableParamAttr { | |||
6094 | public: | |||
6095 | static OSConsumedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6096 | auto *A = new (Ctx) OSConsumedAttr(Loc, Ctx, 0); | |||
6097 | A->setImplicit(true); | |||
6098 | return A; | |||
6099 | } | |||
6100 | ||||
6101 | OSConsumedAttr(SourceRange R, ASTContext &Ctx | |||
6102 | , unsigned SI | |||
6103 | ) | |||
6104 | : InheritableParamAttr(attr::OSConsumed, R, SI, false, false) | |||
6105 | { | |||
6106 | } | |||
6107 | ||||
6108 | OSConsumedAttr *clone(ASTContext &C) const; | |||
6109 | void printPretty(raw_ostream &OS, | |||
6110 | const PrintingPolicy &Policy) const; | |||
6111 | const char *getSpelling() const; | |||
6112 | ||||
6113 | ||||
6114 | static bool classof(const Attr *A) { return A->getKind() == attr::OSConsumed; } | |||
6115 | }; | |||
6116 | ||||
6117 | class OSConsumesThisAttr : public InheritableAttr { | |||
6118 | public: | |||
6119 | static OSConsumesThisAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6120 | auto *A = new (Ctx) OSConsumesThisAttr(Loc, Ctx, 0); | |||
6121 | A->setImplicit(true); | |||
6122 | return A; | |||
6123 | } | |||
6124 | ||||
6125 | OSConsumesThisAttr(SourceRange R, ASTContext &Ctx | |||
6126 | , unsigned SI | |||
6127 | ) | |||
6128 | : InheritableAttr(attr::OSConsumesThis, R, SI, false, false) | |||
6129 | { | |||
6130 | } | |||
6131 | ||||
6132 | OSConsumesThisAttr *clone(ASTContext &C) const; | |||
6133 | void printPretty(raw_ostream &OS, | |||
6134 | const PrintingPolicy &Policy) const; | |||
6135 | const char *getSpelling() const; | |||
6136 | ||||
6137 | ||||
6138 | static bool classof(const Attr *A) { return A->getKind() == attr::OSConsumesThis; } | |||
6139 | }; | |||
6140 | ||||
6141 | class OSReturnsNotRetainedAttr : public InheritableAttr { | |||
6142 | public: | |||
6143 | static OSReturnsNotRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6144 | auto *A = new (Ctx) OSReturnsNotRetainedAttr(Loc, Ctx, 0); | |||
6145 | A->setImplicit(true); | |||
6146 | return A; | |||
6147 | } | |||
6148 | ||||
6149 | OSReturnsNotRetainedAttr(SourceRange R, ASTContext &Ctx | |||
6150 | , unsigned SI | |||
6151 | ) | |||
6152 | : InheritableAttr(attr::OSReturnsNotRetained, R, SI, false, false) | |||
6153 | { | |||
6154 | } | |||
6155 | ||||
6156 | OSReturnsNotRetainedAttr *clone(ASTContext &C) const; | |||
6157 | void printPretty(raw_ostream &OS, | |||
6158 | const PrintingPolicy &Policy) const; | |||
6159 | const char *getSpelling() const; | |||
6160 | ||||
6161 | ||||
6162 | static bool classof(const Attr *A) { return A->getKind() == attr::OSReturnsNotRetained; } | |||
6163 | }; | |||
6164 | ||||
6165 | class OSReturnsRetainedAttr : public InheritableAttr { | |||
6166 | public: | |||
6167 | static OSReturnsRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6168 | auto *A = new (Ctx) OSReturnsRetainedAttr(Loc, Ctx, 0); | |||
6169 | A->setImplicit(true); | |||
6170 | return A; | |||
6171 | } | |||
6172 | ||||
6173 | OSReturnsRetainedAttr(SourceRange R, ASTContext &Ctx | |||
6174 | , unsigned SI | |||
6175 | ) | |||
6176 | : InheritableAttr(attr::OSReturnsRetained, R, SI, false, false) | |||
6177 | { | |||
6178 | } | |||
6179 | ||||
6180 | OSReturnsRetainedAttr *clone(ASTContext &C) const; | |||
6181 | void printPretty(raw_ostream &OS, | |||
6182 | const PrintingPolicy &Policy) const; | |||
6183 | const char *getSpelling() const; | |||
6184 | ||||
6185 | ||||
6186 | static bool classof(const Attr *A) { return A->getKind() == attr::OSReturnsRetained; } | |||
6187 | }; | |||
6188 | ||||
6189 | class OSReturnsRetainedOnNonZeroAttr : public InheritableAttr { | |||
6190 | public: | |||
6191 | static OSReturnsRetainedOnNonZeroAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6192 | auto *A = new (Ctx) OSReturnsRetainedOnNonZeroAttr(Loc, Ctx, 0); | |||
6193 | A->setImplicit(true); | |||
6194 | return A; | |||
6195 | } | |||
6196 | ||||
6197 | OSReturnsRetainedOnNonZeroAttr(SourceRange R, ASTContext &Ctx | |||
6198 | , unsigned SI | |||
6199 | ) | |||
6200 | : InheritableAttr(attr::OSReturnsRetainedOnNonZero, R, SI, false, false) | |||
6201 | { | |||
6202 | } | |||
6203 | ||||
6204 | OSReturnsRetainedOnNonZeroAttr *clone(ASTContext &C) const; | |||
6205 | void printPretty(raw_ostream &OS, | |||
6206 | const PrintingPolicy &Policy) const; | |||
6207 | const char *getSpelling() const; | |||
6208 | ||||
6209 | ||||
6210 | static bool classof(const Attr *A) { return A->getKind() == attr::OSReturnsRetainedOnNonZero; } | |||
6211 | }; | |||
6212 | ||||
6213 | class OSReturnsRetainedOnZeroAttr : public InheritableAttr { | |||
6214 | public: | |||
6215 | static OSReturnsRetainedOnZeroAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6216 | auto *A = new (Ctx) OSReturnsRetainedOnZeroAttr(Loc, Ctx, 0); | |||
6217 | A->setImplicit(true); | |||
6218 | return A; | |||
6219 | } | |||
6220 | ||||
6221 | OSReturnsRetainedOnZeroAttr(SourceRange R, ASTContext &Ctx | |||
6222 | , unsigned SI | |||
6223 | ) | |||
6224 | : InheritableAttr(attr::OSReturnsRetainedOnZero, R, SI, false, false) | |||
6225 | { | |||
6226 | } | |||
6227 | ||||
6228 | OSReturnsRetainedOnZeroAttr *clone(ASTContext &C) const; | |||
6229 | void printPretty(raw_ostream &OS, | |||
6230 | const PrintingPolicy &Policy) const; | |||
6231 | const char *getSpelling() const; | |||
6232 | ||||
6233 | ||||
6234 | static bool classof(const Attr *A) { return A->getKind() == attr::OSReturnsRetainedOnZero; } | |||
6235 | }; | |||
6236 | ||||
6237 | class ObjCBoxableAttr : public Attr { | |||
6238 | public: | |||
6239 | static ObjCBoxableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6240 | auto *A = new (Ctx) ObjCBoxableAttr(Loc, Ctx, 0); | |||
6241 | A->setImplicit(true); | |||
6242 | return A; | |||
6243 | } | |||
6244 | ||||
6245 | ObjCBoxableAttr(SourceRange R, ASTContext &Ctx | |||
6246 | , unsigned SI | |||
6247 | ) | |||
6248 | : Attr(attr::ObjCBoxable, R, SI, false) | |||
6249 | { | |||
6250 | } | |||
6251 | ||||
6252 | ObjCBoxableAttr *clone(ASTContext &C) const; | |||
6253 | void printPretty(raw_ostream &OS, | |||
6254 | const PrintingPolicy &Policy) const; | |||
6255 | const char *getSpelling() const; | |||
6256 | ||||
6257 | ||||
6258 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCBoxable; } | |||
6259 | }; | |||
6260 | ||||
6261 | class ObjCBridgeAttr : public InheritableAttr { | |||
6262 | IdentifierInfo * bridgedType; | |||
6263 | ||||
6264 | public: | |||
6265 | static ObjCBridgeAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * BridgedType, SourceRange Loc = SourceRange()) { | |||
6266 | auto *A = new (Ctx) ObjCBridgeAttr(Loc, Ctx, BridgedType, 0); | |||
6267 | A->setImplicit(true); | |||
6268 | return A; | |||
6269 | } | |||
6270 | ||||
6271 | ObjCBridgeAttr(SourceRange R, ASTContext &Ctx | |||
6272 | , IdentifierInfo * BridgedType | |||
6273 | , unsigned SI | |||
6274 | ) | |||
6275 | : InheritableAttr(attr::ObjCBridge, R, SI, false, false) | |||
6276 | , bridgedType(BridgedType) | |||
6277 | { | |||
6278 | } | |||
6279 | ||||
6280 | ObjCBridgeAttr *clone(ASTContext &C) const; | |||
6281 | void printPretty(raw_ostream &OS, | |||
6282 | const PrintingPolicy &Policy) const; | |||
6283 | const char *getSpelling() const; | |||
6284 | IdentifierInfo * getBridgedType() const { | |||
6285 | return bridgedType; | |||
6286 | } | |||
6287 | ||||
6288 | ||||
6289 | ||||
6290 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCBridge; } | |||
6291 | }; | |||
6292 | ||||
6293 | class ObjCBridgeMutableAttr : public InheritableAttr { | |||
6294 | IdentifierInfo * bridgedType; | |||
6295 | ||||
6296 | public: | |||
6297 | static ObjCBridgeMutableAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * BridgedType, SourceRange Loc = SourceRange()) { | |||
6298 | auto *A = new (Ctx) ObjCBridgeMutableAttr(Loc, Ctx, BridgedType, 0); | |||
6299 | A->setImplicit(true); | |||
6300 | return A; | |||
6301 | } | |||
6302 | ||||
6303 | ObjCBridgeMutableAttr(SourceRange R, ASTContext &Ctx | |||
6304 | , IdentifierInfo * BridgedType | |||
6305 | , unsigned SI | |||
6306 | ) | |||
6307 | : InheritableAttr(attr::ObjCBridgeMutable, R, SI, false, false) | |||
6308 | , bridgedType(BridgedType) | |||
6309 | { | |||
6310 | } | |||
6311 | ||||
6312 | ObjCBridgeMutableAttr *clone(ASTContext &C) const; | |||
6313 | void printPretty(raw_ostream &OS, | |||
6314 | const PrintingPolicy &Policy) const; | |||
6315 | const char *getSpelling() const; | |||
6316 | IdentifierInfo * getBridgedType() const { | |||
6317 | return bridgedType; | |||
6318 | } | |||
6319 | ||||
6320 | ||||
6321 | ||||
6322 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCBridgeMutable; } | |||
6323 | }; | |||
6324 | ||||
6325 | class ObjCBridgeRelatedAttr : public InheritableAttr { | |||
6326 | IdentifierInfo * relatedClass; | |||
6327 | ||||
6328 | IdentifierInfo * classMethod; | |||
6329 | ||||
6330 | IdentifierInfo * instanceMethod; | |||
6331 | ||||
6332 | public: | |||
6333 | static ObjCBridgeRelatedAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * RelatedClass, IdentifierInfo * ClassMethod, IdentifierInfo * InstanceMethod, SourceRange Loc = SourceRange()) { | |||
6334 | auto *A = new (Ctx) ObjCBridgeRelatedAttr(Loc, Ctx, RelatedClass, ClassMethod, InstanceMethod, 0); | |||
6335 | A->setImplicit(true); | |||
6336 | return A; | |||
6337 | } | |||
6338 | ||||
6339 | ObjCBridgeRelatedAttr(SourceRange R, ASTContext &Ctx | |||
6340 | , IdentifierInfo * RelatedClass | |||
6341 | , IdentifierInfo * ClassMethod | |||
6342 | , IdentifierInfo * InstanceMethod | |||
6343 | , unsigned SI | |||
6344 | ) | |||
6345 | : InheritableAttr(attr::ObjCBridgeRelated, R, SI, false, false) | |||
6346 | , relatedClass(RelatedClass) | |||
6347 | , classMethod(ClassMethod) | |||
6348 | , instanceMethod(InstanceMethod) | |||
6349 | { | |||
6350 | } | |||
6351 | ||||
6352 | ObjCBridgeRelatedAttr *clone(ASTContext &C) const; | |||
6353 | void printPretty(raw_ostream &OS, | |||
6354 | const PrintingPolicy &Policy) const; | |||
6355 | const char *getSpelling() const; | |||
6356 | IdentifierInfo * getRelatedClass() const { | |||
6357 | return relatedClass; | |||
6358 | } | |||
6359 | ||||
6360 | IdentifierInfo * getClassMethod() const { | |||
6361 | return classMethod; | |||
6362 | } | |||
6363 | ||||
6364 | IdentifierInfo * getInstanceMethod() const { | |||
6365 | return instanceMethod; | |||
6366 | } | |||
6367 | ||||
6368 | ||||
6369 | ||||
6370 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCBridgeRelated; } | |||
6371 | }; | |||
6372 | ||||
6373 | class ObjCClassStubAttr : public Attr { | |||
6374 | public: | |||
6375 | static ObjCClassStubAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6376 | auto *A = new (Ctx) ObjCClassStubAttr(Loc, Ctx, 0); | |||
6377 | A->setImplicit(true); | |||
6378 | return A; | |||
6379 | } | |||
6380 | ||||
6381 | ObjCClassStubAttr(SourceRange R, ASTContext &Ctx | |||
6382 | , unsigned SI | |||
6383 | ) | |||
6384 | : Attr(attr::ObjCClassStub, R, SI, false) | |||
6385 | { | |||
6386 | } | |||
6387 | ||||
6388 | ObjCClassStubAttr *clone(ASTContext &C) const; | |||
6389 | void printPretty(raw_ostream &OS, | |||
6390 | const PrintingPolicy &Policy) const; | |||
6391 | const char *getSpelling() const; | |||
6392 | ||||
6393 | ||||
6394 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCClassStub; } | |||
6395 | }; | |||
6396 | ||||
6397 | class ObjCDesignatedInitializerAttr : public Attr { | |||
6398 | public: | |||
6399 | static ObjCDesignatedInitializerAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6400 | auto *A = new (Ctx) ObjCDesignatedInitializerAttr(Loc, Ctx, 0); | |||
6401 | A->setImplicit(true); | |||
6402 | return A; | |||
6403 | } | |||
6404 | ||||
6405 | ObjCDesignatedInitializerAttr(SourceRange R, ASTContext &Ctx | |||
6406 | , unsigned SI | |||
6407 | ) | |||
6408 | : Attr(attr::ObjCDesignatedInitializer, R, SI, false) | |||
6409 | { | |||
6410 | } | |||
6411 | ||||
6412 | ObjCDesignatedInitializerAttr *clone(ASTContext &C) const; | |||
6413 | void printPretty(raw_ostream &OS, | |||
6414 | const PrintingPolicy &Policy) const; | |||
6415 | const char *getSpelling() const; | |||
6416 | ||||
6417 | ||||
6418 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCDesignatedInitializer; } | |||
6419 | }; | |||
6420 | ||||
6421 | class ObjCExceptionAttr : public InheritableAttr { | |||
6422 | public: | |||
6423 | static ObjCExceptionAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6424 | auto *A = new (Ctx) ObjCExceptionAttr(Loc, Ctx, 0); | |||
6425 | A->setImplicit(true); | |||
6426 | return A; | |||
6427 | } | |||
6428 | ||||
6429 | ObjCExceptionAttr(SourceRange R, ASTContext &Ctx | |||
6430 | , unsigned SI | |||
6431 | ) | |||
6432 | : InheritableAttr(attr::ObjCException, R, SI, false, false) | |||
6433 | { | |||
6434 | } | |||
6435 | ||||
6436 | ObjCExceptionAttr *clone(ASTContext &C) const; | |||
6437 | void printPretty(raw_ostream &OS, | |||
6438 | const PrintingPolicy &Policy) const; | |||
6439 | const char *getSpelling() const; | |||
6440 | ||||
6441 | ||||
6442 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCException; } | |||
6443 | }; | |||
6444 | ||||
6445 | class ObjCExplicitProtocolImplAttr : public InheritableAttr { | |||
6446 | public: | |||
6447 | static ObjCExplicitProtocolImplAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6448 | auto *A = new (Ctx) ObjCExplicitProtocolImplAttr(Loc, Ctx, 0); | |||
6449 | A->setImplicit(true); | |||
6450 | return A; | |||
6451 | } | |||
6452 | ||||
6453 | ObjCExplicitProtocolImplAttr(SourceRange R, ASTContext &Ctx | |||
6454 | , unsigned SI | |||
6455 | ) | |||
6456 | : InheritableAttr(attr::ObjCExplicitProtocolImpl, R, SI, false, false) | |||
6457 | { | |||
6458 | } | |||
6459 | ||||
6460 | ObjCExplicitProtocolImplAttr *clone(ASTContext &C) const; | |||
6461 | void printPretty(raw_ostream &OS, | |||
6462 | const PrintingPolicy &Policy) const; | |||
6463 | const char *getSpelling() const; | |||
6464 | ||||
6465 | ||||
6466 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCExplicitProtocolImpl; } | |||
6467 | }; | |||
6468 | ||||
6469 | class ObjCExternallyRetainedAttr : public InheritableAttr { | |||
6470 | public: | |||
6471 | static ObjCExternallyRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6472 | auto *A = new (Ctx) ObjCExternallyRetainedAttr(Loc, Ctx, 0); | |||
6473 | A->setImplicit(true); | |||
6474 | return A; | |||
6475 | } | |||
6476 | ||||
6477 | ObjCExternallyRetainedAttr(SourceRange R, ASTContext &Ctx | |||
6478 | , unsigned SI | |||
6479 | ) | |||
6480 | : InheritableAttr(attr::ObjCExternallyRetained, R, SI, false, false) | |||
6481 | { | |||
6482 | } | |||
6483 | ||||
6484 | ObjCExternallyRetainedAttr *clone(ASTContext &C) const; | |||
6485 | void printPretty(raw_ostream &OS, | |||
6486 | const PrintingPolicy &Policy) const; | |||
6487 | const char *getSpelling() const; | |||
6488 | ||||
6489 | ||||
6490 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCExternallyRetained; } | |||
6491 | }; | |||
6492 | ||||
6493 | class ObjCGCAttr : public TypeAttr { | |||
6494 | IdentifierInfo * kind; | |||
6495 | ||||
6496 | public: | |||
6497 | static ObjCGCAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Kind, SourceRange Loc = SourceRange()) { | |||
6498 | auto *A = new (Ctx) ObjCGCAttr(Loc, Ctx, Kind, 0); | |||
6499 | A->setImplicit(true); | |||
6500 | return A; | |||
6501 | } | |||
6502 | ||||
6503 | ObjCGCAttr(SourceRange R, ASTContext &Ctx | |||
6504 | , IdentifierInfo * Kind | |||
6505 | , unsigned SI | |||
6506 | ) | |||
6507 | : TypeAttr(attr::ObjCGC, R, SI, false) | |||
6508 | , kind(Kind) | |||
6509 | { | |||
6510 | } | |||
6511 | ||||
6512 | ObjCGCAttr *clone(ASTContext &C) const; | |||
6513 | void printPretty(raw_ostream &OS, | |||
6514 | const PrintingPolicy &Policy) const; | |||
6515 | const char *getSpelling() const; | |||
6516 | IdentifierInfo * getKind() const { | |||
6517 | return kind; | |||
6518 | } | |||
6519 | ||||
6520 | ||||
6521 | ||||
6522 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCGC; } | |||
6523 | }; | |||
6524 | ||||
6525 | class ObjCIndependentClassAttr : public InheritableAttr { | |||
6526 | public: | |||
6527 | static ObjCIndependentClassAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6528 | auto *A = new (Ctx) ObjCIndependentClassAttr(Loc, Ctx, 0); | |||
6529 | A->setImplicit(true); | |||
6530 | return A; | |||
6531 | } | |||
6532 | ||||
6533 | ObjCIndependentClassAttr(SourceRange R, ASTContext &Ctx | |||
6534 | , unsigned SI | |||
6535 | ) | |||
6536 | : InheritableAttr(attr::ObjCIndependentClass, R, SI, false, false) | |||
6537 | { | |||
6538 | } | |||
6539 | ||||
6540 | ObjCIndependentClassAttr *clone(ASTContext &C) const; | |||
6541 | void printPretty(raw_ostream &OS, | |||
6542 | const PrintingPolicy &Policy) const; | |||
6543 | const char *getSpelling() const; | |||
6544 | ||||
6545 | ||||
6546 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCIndependentClass; } | |||
6547 | }; | |||
6548 | ||||
6549 | class ObjCInertUnsafeUnretainedAttr : public TypeAttr { | |||
6550 | public: | |||
6551 | static ObjCInertUnsafeUnretainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6552 | auto *A = new (Ctx) ObjCInertUnsafeUnretainedAttr(Loc, Ctx, 0); | |||
6553 | A->setImplicit(true); | |||
6554 | return A; | |||
6555 | } | |||
6556 | ||||
6557 | ObjCInertUnsafeUnretainedAttr(SourceRange R, ASTContext &Ctx | |||
6558 | , unsigned SI | |||
6559 | ) | |||
6560 | : TypeAttr(attr::ObjCInertUnsafeUnretained, R, SI, false) | |||
6561 | { | |||
6562 | } | |||
6563 | ||||
6564 | ObjCInertUnsafeUnretainedAttr *clone(ASTContext &C) const; | |||
6565 | void printPretty(raw_ostream &OS, | |||
6566 | const PrintingPolicy &Policy) const; | |||
6567 | const char *getSpelling() const; | |||
6568 | ||||
6569 | ||||
6570 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCInertUnsafeUnretained; } | |||
6571 | }; | |||
6572 | ||||
6573 | class ObjCKindOfAttr : public TypeAttr { | |||
6574 | public: | |||
6575 | static ObjCKindOfAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6576 | auto *A = new (Ctx) ObjCKindOfAttr(Loc, Ctx, 0); | |||
6577 | A->setImplicit(true); | |||
6578 | return A; | |||
6579 | } | |||
6580 | ||||
6581 | ObjCKindOfAttr(SourceRange R, ASTContext &Ctx | |||
6582 | , unsigned SI | |||
6583 | ) | |||
6584 | : TypeAttr(attr::ObjCKindOf, R, SI, false) | |||
6585 | { | |||
6586 | } | |||
6587 | ||||
6588 | ObjCKindOfAttr *clone(ASTContext &C) const; | |||
6589 | void printPretty(raw_ostream &OS, | |||
6590 | const PrintingPolicy &Policy) const; | |||
6591 | const char *getSpelling() const; | |||
6592 | ||||
6593 | ||||
6594 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCKindOf; } | |||
6595 | }; | |||
6596 | ||||
6597 | class ObjCMethodFamilyAttr : public InheritableAttr { | |||
6598 | public: | |||
6599 | enum FamilyKind { | |||
6600 | OMF_None, | |||
6601 | OMF_alloc, | |||
6602 | OMF_copy, | |||
6603 | OMF_init, | |||
6604 | OMF_mutableCopy, | |||
6605 | OMF_new | |||
6606 | }; | |||
6607 | private: | |||
6608 | FamilyKind family; | |||
6609 | ||||
6610 | public: | |||
6611 | static ObjCMethodFamilyAttr *CreateImplicit(ASTContext &Ctx, FamilyKind Family, SourceRange Loc = SourceRange()) { | |||
6612 | auto *A = new (Ctx) ObjCMethodFamilyAttr(Loc, Ctx, Family, 0); | |||
6613 | A->setImplicit(true); | |||
6614 | return A; | |||
6615 | } | |||
6616 | ||||
6617 | ObjCMethodFamilyAttr(SourceRange R, ASTContext &Ctx | |||
6618 | , FamilyKind Family | |||
6619 | , unsigned SI | |||
6620 | ) | |||
6621 | : InheritableAttr(attr::ObjCMethodFamily, R, SI, false, false) | |||
6622 | , family(Family) | |||
6623 | { | |||
6624 | } | |||
6625 | ||||
6626 | ObjCMethodFamilyAttr *clone(ASTContext &C) const; | |||
6627 | void printPretty(raw_ostream &OS, | |||
6628 | const PrintingPolicy &Policy) const; | |||
6629 | const char *getSpelling() const; | |||
6630 | FamilyKind getFamily() const { | |||
6631 | return family; | |||
6632 | } | |||
6633 | ||||
6634 | static bool ConvertStrToFamilyKind(StringRef Val, FamilyKind &Out) { | |||
6635 | Optional<FamilyKind> R = llvm::StringSwitch<Optional<FamilyKind>>(Val) | |||
6636 | .Case("none", ObjCMethodFamilyAttr::OMF_None) | |||
6637 | .Case("alloc", ObjCMethodFamilyAttr::OMF_alloc) | |||
6638 | .Case("copy", ObjCMethodFamilyAttr::OMF_copy) | |||
6639 | .Case("init", ObjCMethodFamilyAttr::OMF_init) | |||
6640 | .Case("mutableCopy", ObjCMethodFamilyAttr::OMF_mutableCopy) | |||
6641 | .Case("new", ObjCMethodFamilyAttr::OMF_new) | |||
6642 | .Default(Optional<FamilyKind>()); | |||
6643 | if (R) { | |||
6644 | Out = *R; | |||
6645 | return true; | |||
6646 | } | |||
6647 | return false; | |||
6648 | } | |||
6649 | ||||
6650 | static const char *ConvertFamilyKindToStr(FamilyKind Val) { | |||
6651 | switch(Val) { | |||
6652 | case ObjCMethodFamilyAttr::OMF_None: return "none"; | |||
6653 | case ObjCMethodFamilyAttr::OMF_alloc: return "alloc"; | |||
6654 | case ObjCMethodFamilyAttr::OMF_copy: return "copy"; | |||
6655 | case ObjCMethodFamilyAttr::OMF_init: return "init"; | |||
6656 | case ObjCMethodFamilyAttr::OMF_mutableCopy: return "mutableCopy"; | |||
6657 | case ObjCMethodFamilyAttr::OMF_new: return "new"; | |||
6658 | } | |||
6659 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 6659); | |||
6660 | } | |||
6661 | ||||
6662 | ||||
6663 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCMethodFamily; } | |||
6664 | }; | |||
6665 | ||||
6666 | class ObjCNSObjectAttr : public InheritableAttr { | |||
6667 | public: | |||
6668 | static ObjCNSObjectAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6669 | auto *A = new (Ctx) ObjCNSObjectAttr(Loc, Ctx, 0); | |||
6670 | A->setImplicit(true); | |||
6671 | return A; | |||
6672 | } | |||
6673 | ||||
6674 | ObjCNSObjectAttr(SourceRange R, ASTContext &Ctx | |||
6675 | , unsigned SI | |||
6676 | ) | |||
6677 | : InheritableAttr(attr::ObjCNSObject, R, SI, false, false) | |||
6678 | { | |||
6679 | } | |||
6680 | ||||
6681 | ObjCNSObjectAttr *clone(ASTContext &C) const; | |||
6682 | void printPretty(raw_ostream &OS, | |||
6683 | const PrintingPolicy &Policy) const; | |||
6684 | const char *getSpelling() const; | |||
6685 | ||||
6686 | ||||
6687 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCNSObject; } | |||
6688 | }; | |||
6689 | ||||
6690 | class ObjCNonLazyClassAttr : public Attr { | |||
6691 | public: | |||
6692 | static ObjCNonLazyClassAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6693 | auto *A = new (Ctx) ObjCNonLazyClassAttr(Loc, Ctx, 0); | |||
6694 | A->setImplicit(true); | |||
6695 | return A; | |||
6696 | } | |||
6697 | ||||
6698 | ObjCNonLazyClassAttr(SourceRange R, ASTContext &Ctx | |||
6699 | , unsigned SI | |||
6700 | ) | |||
6701 | : Attr(attr::ObjCNonLazyClass, R, SI, false) | |||
6702 | { | |||
6703 | } | |||
6704 | ||||
6705 | ObjCNonLazyClassAttr *clone(ASTContext &C) const; | |||
6706 | void printPretty(raw_ostream &OS, | |||
6707 | const PrintingPolicy &Policy) const; | |||
6708 | const char *getSpelling() const; | |||
6709 | ||||
6710 | ||||
6711 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCNonLazyClass; } | |||
6712 | }; | |||
6713 | ||||
6714 | class ObjCOwnershipAttr : public InheritableAttr { | |||
6715 | IdentifierInfo * kind; | |||
6716 | ||||
6717 | public: | |||
6718 | static ObjCOwnershipAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Kind, SourceRange Loc = SourceRange()) { | |||
6719 | auto *A = new (Ctx) ObjCOwnershipAttr(Loc, Ctx, Kind, 0); | |||
6720 | A->setImplicit(true); | |||
6721 | return A; | |||
6722 | } | |||
6723 | ||||
6724 | ObjCOwnershipAttr(SourceRange R, ASTContext &Ctx | |||
6725 | , IdentifierInfo * Kind | |||
6726 | , unsigned SI | |||
6727 | ) | |||
6728 | : InheritableAttr(attr::ObjCOwnership, R, SI, false, false) | |||
6729 | , kind(Kind) | |||
6730 | { | |||
6731 | } | |||
6732 | ||||
6733 | ObjCOwnershipAttr *clone(ASTContext &C) const; | |||
6734 | void printPretty(raw_ostream &OS, | |||
6735 | const PrintingPolicy &Policy) const; | |||
6736 | const char *getSpelling() const; | |||
6737 | IdentifierInfo * getKind() const { | |||
6738 | return kind; | |||
6739 | } | |||
6740 | ||||
6741 | ||||
6742 | ||||
6743 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCOwnership; } | |||
6744 | }; | |||
6745 | ||||
6746 | class ObjCPreciseLifetimeAttr : public InheritableAttr { | |||
6747 | public: | |||
6748 | static ObjCPreciseLifetimeAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6749 | auto *A = new (Ctx) ObjCPreciseLifetimeAttr(Loc, Ctx, 0); | |||
6750 | A->setImplicit(true); | |||
6751 | return A; | |||
6752 | } | |||
6753 | ||||
6754 | ObjCPreciseLifetimeAttr(SourceRange R, ASTContext &Ctx | |||
6755 | , unsigned SI | |||
6756 | ) | |||
6757 | : InheritableAttr(attr::ObjCPreciseLifetime, R, SI, false, false) | |||
6758 | { | |||
6759 | } | |||
6760 | ||||
6761 | ObjCPreciseLifetimeAttr *clone(ASTContext &C) const; | |||
6762 | void printPretty(raw_ostream &OS, | |||
6763 | const PrintingPolicy &Policy) const; | |||
6764 | const char *getSpelling() const; | |||
6765 | ||||
6766 | ||||
6767 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCPreciseLifetime; } | |||
6768 | }; | |||
6769 | ||||
6770 | class ObjCRequiresPropertyDefsAttr : public InheritableAttr { | |||
6771 | public: | |||
6772 | static ObjCRequiresPropertyDefsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6773 | auto *A = new (Ctx) ObjCRequiresPropertyDefsAttr(Loc, Ctx, 0); | |||
6774 | A->setImplicit(true); | |||
6775 | return A; | |||
6776 | } | |||
6777 | ||||
6778 | ObjCRequiresPropertyDefsAttr(SourceRange R, ASTContext &Ctx | |||
6779 | , unsigned SI | |||
6780 | ) | |||
6781 | : InheritableAttr(attr::ObjCRequiresPropertyDefs, R, SI, false, false) | |||
6782 | { | |||
6783 | } | |||
6784 | ||||
6785 | ObjCRequiresPropertyDefsAttr *clone(ASTContext &C) const; | |||
6786 | void printPretty(raw_ostream &OS, | |||
6787 | const PrintingPolicy &Policy) const; | |||
6788 | const char *getSpelling() const; | |||
6789 | ||||
6790 | ||||
6791 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRequiresPropertyDefs; } | |||
6792 | }; | |||
6793 | ||||
6794 | class ObjCRequiresSuperAttr : public InheritableAttr { | |||
6795 | public: | |||
6796 | static ObjCRequiresSuperAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6797 | auto *A = new (Ctx) ObjCRequiresSuperAttr(Loc, Ctx, 0); | |||
6798 | A->setImplicit(true); | |||
6799 | return A; | |||
6800 | } | |||
6801 | ||||
6802 | ObjCRequiresSuperAttr(SourceRange R, ASTContext &Ctx | |||
6803 | , unsigned SI | |||
6804 | ) | |||
6805 | : InheritableAttr(attr::ObjCRequiresSuper, R, SI, false, false) | |||
6806 | { | |||
6807 | } | |||
6808 | ||||
6809 | ObjCRequiresSuperAttr *clone(ASTContext &C) const; | |||
6810 | void printPretty(raw_ostream &OS, | |||
6811 | const PrintingPolicy &Policy) const; | |||
6812 | const char *getSpelling() const; | |||
6813 | ||||
6814 | ||||
6815 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRequiresSuper; } | |||
6816 | }; | |||
6817 | ||||
6818 | class ObjCReturnsInnerPointerAttr : public InheritableAttr { | |||
6819 | public: | |||
6820 | static ObjCReturnsInnerPointerAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6821 | auto *A = new (Ctx) ObjCReturnsInnerPointerAttr(Loc, Ctx, 0); | |||
6822 | A->setImplicit(true); | |||
6823 | return A; | |||
6824 | } | |||
6825 | ||||
6826 | ObjCReturnsInnerPointerAttr(SourceRange R, ASTContext &Ctx | |||
6827 | , unsigned SI | |||
6828 | ) | |||
6829 | : InheritableAttr(attr::ObjCReturnsInnerPointer, R, SI, false, false) | |||
6830 | { | |||
6831 | } | |||
6832 | ||||
6833 | ObjCReturnsInnerPointerAttr *clone(ASTContext &C) const; | |||
6834 | void printPretty(raw_ostream &OS, | |||
6835 | const PrintingPolicy &Policy) const; | |||
6836 | const char *getSpelling() const; | |||
6837 | ||||
6838 | ||||
6839 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCReturnsInnerPointer; } | |||
6840 | }; | |||
6841 | ||||
6842 | class ObjCRootClassAttr : public InheritableAttr { | |||
6843 | public: | |||
6844 | static ObjCRootClassAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6845 | auto *A = new (Ctx) ObjCRootClassAttr(Loc, Ctx, 0); | |||
6846 | A->setImplicit(true); | |||
6847 | return A; | |||
6848 | } | |||
6849 | ||||
6850 | ObjCRootClassAttr(SourceRange R, ASTContext &Ctx | |||
6851 | , unsigned SI | |||
6852 | ) | |||
6853 | : InheritableAttr(attr::ObjCRootClass, R, SI, false, false) | |||
6854 | { | |||
6855 | } | |||
6856 | ||||
6857 | ObjCRootClassAttr *clone(ASTContext &C) const; | |||
6858 | void printPretty(raw_ostream &OS, | |||
6859 | const PrintingPolicy &Policy) const; | |||
6860 | const char *getSpelling() const; | |||
6861 | ||||
6862 | ||||
6863 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRootClass; } | |||
6864 | }; | |||
6865 | ||||
6866 | class ObjCRuntimeNameAttr : public Attr { | |||
6867 | unsigned metadataNameLength; | |||
6868 | char *metadataName; | |||
6869 | ||||
6870 | public: | |||
6871 | static ObjCRuntimeNameAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef MetadataName, SourceRange Loc = SourceRange()) { | |||
6872 | auto *A = new (Ctx) ObjCRuntimeNameAttr(Loc, Ctx, MetadataName, 0); | |||
6873 | A->setImplicit(true); | |||
6874 | return A; | |||
6875 | } | |||
6876 | ||||
6877 | ObjCRuntimeNameAttr(SourceRange R, ASTContext &Ctx | |||
6878 | , llvm::StringRef MetadataName | |||
6879 | , unsigned SI | |||
6880 | ) | |||
6881 | : Attr(attr::ObjCRuntimeName, R, SI, false) | |||
6882 | , metadataNameLength(MetadataName.size()),metadataName(new (Ctx, 1) char[metadataNameLength]) | |||
6883 | { | |||
6884 | if (!MetadataName.empty()) | |||
6885 | std::memcpy(metadataName, MetadataName.data(), metadataNameLength); | |||
6886 | } | |||
6887 | ||||
6888 | ObjCRuntimeNameAttr *clone(ASTContext &C) const; | |||
6889 | void printPretty(raw_ostream &OS, | |||
6890 | const PrintingPolicy &Policy) const; | |||
6891 | const char *getSpelling() const; | |||
6892 | llvm::StringRef getMetadataName() const { | |||
6893 | return llvm::StringRef(metadataName, metadataNameLength); | |||
6894 | } | |||
6895 | unsigned getMetadataNameLength() const { | |||
6896 | return metadataNameLength; | |||
6897 | } | |||
6898 | void setMetadataName(ASTContext &C, llvm::StringRef S) { | |||
6899 | metadataNameLength = S.size(); | |||
6900 | this->metadataName = new (C, 1) char [metadataNameLength]; | |||
6901 | if (!S.empty()) | |||
6902 | std::memcpy(this->metadataName, S.data(), metadataNameLength); | |||
6903 | } | |||
6904 | ||||
6905 | ||||
6906 | ||||
6907 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRuntimeName; } | |||
6908 | }; | |||
6909 | ||||
6910 | class ObjCRuntimeVisibleAttr : public Attr { | |||
6911 | public: | |||
6912 | static ObjCRuntimeVisibleAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6913 | auto *A = new (Ctx) ObjCRuntimeVisibleAttr(Loc, Ctx, 0); | |||
6914 | A->setImplicit(true); | |||
6915 | return A; | |||
6916 | } | |||
6917 | ||||
6918 | ObjCRuntimeVisibleAttr(SourceRange R, ASTContext &Ctx | |||
6919 | , unsigned SI | |||
6920 | ) | |||
6921 | : Attr(attr::ObjCRuntimeVisible, R, SI, false) | |||
6922 | { | |||
6923 | } | |||
6924 | ||||
6925 | ObjCRuntimeVisibleAttr *clone(ASTContext &C) const; | |||
6926 | void printPretty(raw_ostream &OS, | |||
6927 | const PrintingPolicy &Policy) const; | |||
6928 | const char *getSpelling() const; | |||
6929 | ||||
6930 | ||||
6931 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRuntimeVisible; } | |||
6932 | }; | |||
6933 | ||||
6934 | class ObjCSubclassingRestrictedAttr : public InheritableAttr { | |||
6935 | public: | |||
6936 | static ObjCSubclassingRestrictedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6937 | auto *A = new (Ctx) ObjCSubclassingRestrictedAttr(Loc, Ctx, 0); | |||
6938 | A->setImplicit(true); | |||
6939 | return A; | |||
6940 | } | |||
6941 | ||||
6942 | ObjCSubclassingRestrictedAttr(SourceRange R, ASTContext &Ctx | |||
6943 | , unsigned SI | |||
6944 | ) | |||
6945 | : InheritableAttr(attr::ObjCSubclassingRestricted, R, SI, false, false) | |||
6946 | { | |||
6947 | } | |||
6948 | ||||
6949 | ObjCSubclassingRestrictedAttr *clone(ASTContext &C) const; | |||
6950 | void printPretty(raw_ostream &OS, | |||
6951 | const PrintingPolicy &Policy) const; | |||
6952 | const char *getSpelling() const; | |||
6953 | ||||
6954 | ||||
6955 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCSubclassingRestricted; } | |||
6956 | }; | |||
6957 | ||||
6958 | class OpenCLAccessAttr : public Attr { | |||
6959 | public: | |||
6960 | enum Spelling { | |||
6961 | Keyword_read_only = 0, | |||
6962 | Keyword_write_only = 2, | |||
6963 | Keyword_read_write = 4 | |||
6964 | }; | |||
6965 | ||||
6966 | static OpenCLAccessAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
6967 | auto *A = new (Ctx) OpenCLAccessAttr(Loc, Ctx, S); | |||
6968 | A->setImplicit(true); | |||
6969 | return A; | |||
6970 | } | |||
6971 | ||||
6972 | OpenCLAccessAttr(SourceRange R, ASTContext &Ctx | |||
6973 | , unsigned SI | |||
6974 | ) | |||
6975 | : Attr(attr::OpenCLAccess, R, SI, false) | |||
6976 | { | |||
6977 | } | |||
6978 | ||||
6979 | OpenCLAccessAttr *clone(ASTContext &C) const; | |||
6980 | void printPretty(raw_ostream &OS, | |||
6981 | const PrintingPolicy &Policy) const; | |||
6982 | const char *getSpelling() const; | |||
6983 | Spelling getSemanticSpelling() const { | |||
6984 | switch (SpellingListIndex) { | |||
6985 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 6985); | |||
6986 | case 0: return Keyword_read_only; | |||
6987 | case 1: return Keyword_read_only; | |||
6988 | case 2: return Keyword_write_only; | |||
6989 | case 3: return Keyword_write_only; | |||
6990 | case 4: return Keyword_read_write; | |||
6991 | case 5: return Keyword_read_write; | |||
6992 | } | |||
6993 | } | |||
6994 | bool isReadOnly() const { return SpellingListIndex == 0 || | |||
6995 | SpellingListIndex == 1; } | |||
6996 | bool isReadWrite() const { return SpellingListIndex == 4 || | |||
6997 | SpellingListIndex == 5; } | |||
6998 | bool isWriteOnly() const { return SpellingListIndex == 2 || | |||
6999 | SpellingListIndex == 3; } | |||
7000 | ||||
7001 | ||||
7002 | static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLAccess; } | |||
7003 | }; | |||
7004 | ||||
7005 | class OpenCLConstantAddressSpaceAttr : public TypeAttr { | |||
7006 | public: | |||
7007 | static OpenCLConstantAddressSpaceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7008 | auto *A = new (Ctx) OpenCLConstantAddressSpaceAttr(Loc, Ctx, 0); | |||
7009 | A->setImplicit(true); | |||
7010 | return A; | |||
7011 | } | |||
7012 | ||||
7013 | OpenCLConstantAddressSpaceAttr(SourceRange R, ASTContext &Ctx | |||
7014 | , unsigned SI | |||
7015 | ) | |||
7016 | : TypeAttr(attr::OpenCLConstantAddressSpace, R, SI, false) | |||
7017 | { | |||
7018 | } | |||
7019 | ||||
7020 | OpenCLConstantAddressSpaceAttr *clone(ASTContext &C) const; | |||
7021 | void printPretty(raw_ostream &OS, | |||
7022 | const PrintingPolicy &Policy) const; | |||
7023 | const char *getSpelling() const; | |||
7024 | ||||
7025 | ||||
7026 | static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLConstantAddressSpace; } | |||
7027 | }; | |||
7028 | ||||
7029 | class OpenCLGenericAddressSpaceAttr : public TypeAttr { | |||
7030 | public: | |||
7031 | static OpenCLGenericAddressSpaceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7032 | auto *A = new (Ctx) OpenCLGenericAddressSpaceAttr(Loc, Ctx, 0); | |||
7033 | A->setImplicit(true); | |||
7034 | return A; | |||
7035 | } | |||
7036 | ||||
7037 | OpenCLGenericAddressSpaceAttr(SourceRange R, ASTContext &Ctx | |||
7038 | , unsigned SI | |||
7039 | ) | |||
7040 | : TypeAttr(attr::OpenCLGenericAddressSpace, R, SI, false) | |||
7041 | { | |||
7042 | } | |||
7043 | ||||
7044 | OpenCLGenericAddressSpaceAttr *clone(ASTContext &C) const; | |||
7045 | void printPretty(raw_ostream &OS, | |||
7046 | const PrintingPolicy &Policy) const; | |||
7047 | const char *getSpelling() const; | |||
7048 | ||||
7049 | ||||
7050 | static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLGenericAddressSpace; } | |||
7051 | }; | |||
7052 | ||||
7053 | class OpenCLGlobalAddressSpaceAttr : public TypeAttr { | |||
7054 | public: | |||
7055 | static OpenCLGlobalAddressSpaceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7056 | auto *A = new (Ctx) OpenCLGlobalAddressSpaceAttr(Loc, Ctx, 0); | |||
7057 | A->setImplicit(true); | |||
7058 | return A; | |||
7059 | } | |||
7060 | ||||
7061 | OpenCLGlobalAddressSpaceAttr(SourceRange R, ASTContext &Ctx | |||
7062 | , unsigned SI | |||
7063 | ) | |||
7064 | : TypeAttr(attr::OpenCLGlobalAddressSpace, R, SI, false) | |||
7065 | { | |||
7066 | } | |||
7067 | ||||
7068 | OpenCLGlobalAddressSpaceAttr *clone(ASTContext &C) const; | |||
7069 | void printPretty(raw_ostream &OS, | |||
7070 | const PrintingPolicy &Policy) const; | |||
7071 | const char *getSpelling() const; | |||
7072 | ||||
7073 | ||||
7074 | static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLGlobalAddressSpace; } | |||
7075 | }; | |||
7076 | ||||
7077 | class OpenCLIntelReqdSubGroupSizeAttr : public InheritableAttr { | |||
7078 | unsigned subGroupSize; | |||
7079 | ||||
7080 | public: | |||
7081 | static OpenCLIntelReqdSubGroupSizeAttr *CreateImplicit(ASTContext &Ctx, unsigned SubGroupSize, SourceRange Loc = SourceRange()) { | |||
7082 | auto *A = new (Ctx) OpenCLIntelReqdSubGroupSizeAttr(Loc, Ctx, SubGroupSize, 0); | |||
7083 | A->setImplicit(true); | |||
7084 | return A; | |||
7085 | } | |||
7086 | ||||
7087 | OpenCLIntelReqdSubGroupSizeAttr(SourceRange R, ASTContext &Ctx | |||
7088 | , unsigned SubGroupSize | |||
7089 | , unsigned SI | |||
7090 | ) | |||
7091 | : InheritableAttr(attr::OpenCLIntelReqdSubGroupSize, R, SI, false, false) | |||
7092 | , subGroupSize(SubGroupSize) | |||
7093 | { | |||
7094 | } | |||
7095 | ||||
7096 | OpenCLIntelReqdSubGroupSizeAttr *clone(ASTContext &C) const; | |||
7097 | void printPretty(raw_ostream &OS, | |||
7098 | const PrintingPolicy &Policy) const; | |||
7099 | const char *getSpelling() const; | |||
7100 | unsigned getSubGroupSize() const { | |||
7101 | return subGroupSize; | |||
7102 | } | |||
7103 | ||||
7104 | ||||
7105 | ||||
7106 | static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLIntelReqdSubGroupSize; } | |||
7107 | }; | |||
7108 | ||||
7109 | class OpenCLKernelAttr : public InheritableAttr { | |||
7110 | public: | |||
7111 | static OpenCLKernelAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7112 | auto *A = new (Ctx) OpenCLKernelAttr(Loc, Ctx, 0); | |||
7113 | A->setImplicit(true); | |||
7114 | return A; | |||
7115 | } | |||
7116 | ||||
7117 | OpenCLKernelAttr(SourceRange R, ASTContext &Ctx | |||
7118 | , unsigned SI | |||
7119 | ) | |||
7120 | : InheritableAttr(attr::OpenCLKernel, R, SI, false, false) | |||
7121 | { | |||
7122 | } | |||
7123 | ||||
7124 | OpenCLKernelAttr *clone(ASTContext &C) const; | |||
7125 | void printPretty(raw_ostream &OS, | |||
7126 | const PrintingPolicy &Policy) const; | |||
7127 | const char *getSpelling() const; | |||
7128 | ||||
7129 | ||||
7130 | static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLKernel; } | |||
7131 | }; | |||
7132 | ||||
7133 | class OpenCLLocalAddressSpaceAttr : public TypeAttr { | |||
7134 | public: | |||
7135 | static OpenCLLocalAddressSpaceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7136 | auto *A = new (Ctx) OpenCLLocalAddressSpaceAttr(Loc, Ctx, 0); | |||
7137 | A->setImplicit(true); | |||
7138 | return A; | |||
7139 | } | |||
7140 | ||||
7141 | OpenCLLocalAddressSpaceAttr(SourceRange R, ASTContext &Ctx | |||
7142 | , unsigned SI | |||
7143 | ) | |||
7144 | : TypeAttr(attr::OpenCLLocalAddressSpace, R, SI, false) | |||
7145 | { | |||
7146 | } | |||
7147 | ||||
7148 | OpenCLLocalAddressSpaceAttr *clone(ASTContext &C) const; | |||
7149 | void printPretty(raw_ostream &OS, | |||
7150 | const PrintingPolicy &Policy) const; | |||
7151 | const char *getSpelling() const; | |||
7152 | ||||
7153 | ||||
7154 | static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLLocalAddressSpace; } | |||
7155 | }; | |||
7156 | ||||
7157 | class OpenCLPrivateAddressSpaceAttr : public TypeAttr { | |||
7158 | public: | |||
7159 | static OpenCLPrivateAddressSpaceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7160 | auto *A = new (Ctx) OpenCLPrivateAddressSpaceAttr(Loc, Ctx, 0); | |||
7161 | A->setImplicit(true); | |||
7162 | return A; | |||
7163 | } | |||
7164 | ||||
7165 | OpenCLPrivateAddressSpaceAttr(SourceRange R, ASTContext &Ctx | |||
7166 | , unsigned SI | |||
7167 | ) | |||
7168 | : TypeAttr(attr::OpenCLPrivateAddressSpace, R, SI, false) | |||
7169 | { | |||
7170 | } | |||
7171 | ||||
7172 | OpenCLPrivateAddressSpaceAttr *clone(ASTContext &C) const; | |||
7173 | void printPretty(raw_ostream &OS, | |||
7174 | const PrintingPolicy &Policy) const; | |||
7175 | const char *getSpelling() const; | |||
7176 | ||||
7177 | ||||
7178 | static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLPrivateAddressSpace; } | |||
7179 | }; | |||
7180 | ||||
7181 | class OpenCLUnrollHintAttr : public InheritableAttr { | |||
7182 | unsigned unrollHint; | |||
7183 | ||||
7184 | public: | |||
7185 | static OpenCLUnrollHintAttr *CreateImplicit(ASTContext &Ctx, unsigned UnrollHint, SourceRange Loc = SourceRange()) { | |||
7186 | auto *A = new (Ctx) OpenCLUnrollHintAttr(Loc, Ctx, UnrollHint, 0); | |||
7187 | A->setImplicit(true); | |||
7188 | return A; | |||
7189 | } | |||
7190 | ||||
7191 | OpenCLUnrollHintAttr(SourceRange R, ASTContext &Ctx | |||
7192 | , unsigned UnrollHint | |||
7193 | , unsigned SI | |||
7194 | ) | |||
7195 | : InheritableAttr(attr::OpenCLUnrollHint, R, SI, false, false) | |||
7196 | , unrollHint(UnrollHint) | |||
7197 | { | |||
7198 | } | |||
7199 | ||||
7200 | OpenCLUnrollHintAttr *clone(ASTContext &C) const; | |||
7201 | void printPretty(raw_ostream &OS, | |||
7202 | const PrintingPolicy &Policy) const; | |||
7203 | const char *getSpelling() const; | |||
7204 | unsigned getUnrollHint() const { | |||
7205 | return unrollHint; | |||
7206 | } | |||
7207 | ||||
7208 | ||||
7209 | ||||
7210 | static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLUnrollHint; } | |||
7211 | }; | |||
7212 | ||||
7213 | class OptimizeNoneAttr : public InheritableAttr { | |||
7214 | public: | |||
7215 | static OptimizeNoneAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7216 | auto *A = new (Ctx) OptimizeNoneAttr(Loc, Ctx, 0); | |||
7217 | A->setImplicit(true); | |||
7218 | return A; | |||
7219 | } | |||
7220 | ||||
7221 | OptimizeNoneAttr(SourceRange R, ASTContext &Ctx | |||
7222 | , unsigned SI | |||
7223 | ) | |||
7224 | : InheritableAttr(attr::OptimizeNone, R, SI, false, false) | |||
7225 | { | |||
7226 | } | |||
7227 | ||||
7228 | OptimizeNoneAttr *clone(ASTContext &C) const; | |||
7229 | void printPretty(raw_ostream &OS, | |||
7230 | const PrintingPolicy &Policy) const; | |||
7231 | const char *getSpelling() const; | |||
7232 | ||||
7233 | ||||
7234 | static bool classof(const Attr *A) { return A->getKind() == attr::OptimizeNone; } | |||
7235 | }; | |||
7236 | ||||
7237 | class OverloadableAttr : public Attr { | |||
7238 | public: | |||
7239 | static OverloadableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7240 | auto *A = new (Ctx) OverloadableAttr(Loc, Ctx, 0); | |||
7241 | A->setImplicit(true); | |||
7242 | return A; | |||
7243 | } | |||
7244 | ||||
7245 | OverloadableAttr(SourceRange R, ASTContext &Ctx | |||
7246 | , unsigned SI | |||
7247 | ) | |||
7248 | : Attr(attr::Overloadable, R, SI, false) | |||
7249 | { | |||
7250 | } | |||
7251 | ||||
7252 | OverloadableAttr *clone(ASTContext &C) const; | |||
7253 | void printPretty(raw_ostream &OS, | |||
7254 | const PrintingPolicy &Policy) const; | |||
7255 | const char *getSpelling() const; | |||
7256 | ||||
7257 | ||||
7258 | static bool classof(const Attr *A) { return A->getKind() == attr::Overloadable; } | |||
7259 | }; | |||
7260 | ||||
7261 | class OverrideAttr : public InheritableAttr { | |||
7262 | public: | |||
7263 | static OverrideAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7264 | auto *A = new (Ctx) OverrideAttr(Loc, Ctx, 0); | |||
7265 | A->setImplicit(true); | |||
7266 | return A; | |||
7267 | } | |||
7268 | ||||
7269 | OverrideAttr(SourceRange R, ASTContext &Ctx | |||
7270 | , unsigned SI | |||
7271 | ) | |||
7272 | : InheritableAttr(attr::Override, R, SI, false, false) | |||
7273 | { | |||
7274 | } | |||
7275 | ||||
7276 | OverrideAttr *clone(ASTContext &C) const; | |||
7277 | void printPretty(raw_ostream &OS, | |||
7278 | const PrintingPolicy &Policy) const; | |||
7279 | const char *getSpelling() const; | |||
7280 | ||||
7281 | ||||
7282 | static bool classof(const Attr *A) { return A->getKind() == attr::Override; } | |||
7283 | }; | |||
7284 | ||||
7285 | class OwnershipAttr : public InheritableAttr { | |||
7286 | IdentifierInfo * module; | |||
7287 | ||||
7288 | unsigned args_Size; | |||
7289 | ParamIdx *args_; | |||
7290 | ||||
7291 | public: | |||
7292 | enum Spelling { | |||
7293 | GNU_ownership_holds = 0, | |||
7294 | CXX11_clang_ownership_holds = 1, | |||
7295 | C2x_clang_ownership_holds = 2, | |||
7296 | GNU_ownership_returns = 3, | |||
7297 | CXX11_clang_ownership_returns = 4, | |||
7298 | C2x_clang_ownership_returns = 5, | |||
7299 | GNU_ownership_takes = 6, | |||
7300 | CXX11_clang_ownership_takes = 7, | |||
7301 | C2x_clang_ownership_takes = 8 | |||
7302 | }; | |||
7303 | ||||
7304 | static OwnershipAttr *CreateImplicit(ASTContext &Ctx, Spelling S, IdentifierInfo * Module, ParamIdx *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
7305 | auto *A = new (Ctx) OwnershipAttr(Loc, Ctx, Module, Args, ArgsSize, S); | |||
7306 | A->setImplicit(true); | |||
7307 | return A; | |||
7308 | } | |||
7309 | ||||
7310 | OwnershipAttr(SourceRange R, ASTContext &Ctx | |||
7311 | , IdentifierInfo * Module | |||
7312 | , ParamIdx *Args, unsigned ArgsSize | |||
7313 | , unsigned SI | |||
7314 | ) | |||
7315 | : InheritableAttr(attr::Ownership, R, SI, false, false) | |||
7316 | , module(Module) | |||
7317 | , args_Size(ArgsSize), args_(new (Ctx, 16) ParamIdx[args_Size]) | |||
7318 | { | |||
7319 | std::copy(Args, Args + args_Size, args_); | |||
7320 | } | |||
7321 | ||||
7322 | OwnershipAttr(SourceRange R, ASTContext &Ctx | |||
7323 | , IdentifierInfo * Module | |||
7324 | , unsigned SI | |||
7325 | ) | |||
7326 | : InheritableAttr(attr::Ownership, R, SI, false, false) | |||
7327 | , module(Module) | |||
7328 | , args_Size(0), args_(nullptr) | |||
7329 | { | |||
7330 | } | |||
7331 | ||||
7332 | OwnershipAttr *clone(ASTContext &C) const; | |||
7333 | void printPretty(raw_ostream &OS, | |||
7334 | const PrintingPolicy &Policy) const; | |||
7335 | const char *getSpelling() const; | |||
7336 | Spelling getSemanticSpelling() const { | |||
7337 | switch (SpellingListIndex) { | |||
7338 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 7338); | |||
7339 | case 0: return GNU_ownership_holds; | |||
7340 | case 1: return CXX11_clang_ownership_holds; | |||
7341 | case 2: return C2x_clang_ownership_holds; | |||
7342 | case 3: return GNU_ownership_returns; | |||
7343 | case 4: return CXX11_clang_ownership_returns; | |||
7344 | case 5: return C2x_clang_ownership_returns; | |||
7345 | case 6: return GNU_ownership_takes; | |||
7346 | case 7: return CXX11_clang_ownership_takes; | |||
7347 | case 8: return C2x_clang_ownership_takes; | |||
7348 | } | |||
7349 | } | |||
7350 | bool isHolds() const { return SpellingListIndex == 0 || | |||
7351 | SpellingListIndex == 1 || | |||
7352 | SpellingListIndex == 2; } | |||
7353 | bool isReturns() const { return SpellingListIndex == 3 || | |||
7354 | SpellingListIndex == 4 || | |||
7355 | SpellingListIndex == 5; } | |||
7356 | bool isTakes() const { return SpellingListIndex == 6 || | |||
7357 | SpellingListIndex == 7 || | |||
7358 | SpellingListIndex == 8; } | |||
7359 | IdentifierInfo * getModule() const { | |||
7360 | return module; | |||
7361 | } | |||
7362 | ||||
7363 | typedef ParamIdx* args_iterator; | |||
7364 | args_iterator args_begin() const { return args_; } | |||
7365 | args_iterator args_end() const { return args_ + args_Size; } | |||
7366 | unsigned args_size() const { return args_Size; } | |||
7367 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
7368 | ||||
7369 | ||||
7370 | ||||
7371 | enum OwnershipKind { Holds, Returns, Takes }; | |||
7372 | OwnershipKind getOwnKind() const { | |||
7373 | return isHolds() ? Holds : | |||
7374 | isTakes() ? Takes : | |||
7375 | Returns; | |||
7376 | } | |||
7377 | ||||
7378 | ||||
7379 | static bool classof(const Attr *A) { return A->getKind() == attr::Ownership; } | |||
7380 | }; | |||
7381 | ||||
7382 | class PackedAttr : public InheritableAttr { | |||
7383 | public: | |||
7384 | static PackedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7385 | auto *A = new (Ctx) PackedAttr(Loc, Ctx, 0); | |||
7386 | A->setImplicit(true); | |||
7387 | return A; | |||
7388 | } | |||
7389 | ||||
7390 | PackedAttr(SourceRange R, ASTContext &Ctx | |||
7391 | , unsigned SI | |||
7392 | ) | |||
7393 | : InheritableAttr(attr::Packed, R, SI, false, false) | |||
7394 | { | |||
7395 | } | |||
7396 | ||||
7397 | PackedAttr *clone(ASTContext &C) const; | |||
7398 | void printPretty(raw_ostream &OS, | |||
7399 | const PrintingPolicy &Policy) const; | |||
7400 | const char *getSpelling() const; | |||
7401 | ||||
7402 | ||||
7403 | static bool classof(const Attr *A) { return A->getKind() == attr::Packed; } | |||
7404 | }; | |||
7405 | ||||
7406 | class ParamTypestateAttr : public InheritableAttr { | |||
7407 | public: | |||
7408 | enum ConsumedState { | |||
7409 | Unknown, | |||
7410 | Consumed, | |||
7411 | Unconsumed | |||
7412 | }; | |||
7413 | private: | |||
7414 | ConsumedState paramState; | |||
7415 | ||||
7416 | public: | |||
7417 | static ParamTypestateAttr *CreateImplicit(ASTContext &Ctx, ConsumedState ParamState, SourceRange Loc = SourceRange()) { | |||
7418 | auto *A = new (Ctx) ParamTypestateAttr(Loc, Ctx, ParamState, 0); | |||
7419 | A->setImplicit(true); | |||
7420 | return A; | |||
7421 | } | |||
7422 | ||||
7423 | ParamTypestateAttr(SourceRange R, ASTContext &Ctx | |||
7424 | , ConsumedState ParamState | |||
7425 | , unsigned SI | |||
7426 | ) | |||
7427 | : InheritableAttr(attr::ParamTypestate, R, SI, false, false) | |||
7428 | , paramState(ParamState) | |||
7429 | { | |||
7430 | } | |||
7431 | ||||
7432 | ParamTypestateAttr *clone(ASTContext &C) const; | |||
7433 | void printPretty(raw_ostream &OS, | |||
7434 | const PrintingPolicy &Policy) const; | |||
7435 | const char *getSpelling() const; | |||
7436 | ConsumedState getParamState() const { | |||
7437 | return paramState; | |||
7438 | } | |||
7439 | ||||
7440 | static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) { | |||
7441 | Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val) | |||
7442 | .Case("unknown", ParamTypestateAttr::Unknown) | |||
7443 | .Case("consumed", ParamTypestateAttr::Consumed) | |||
7444 | .Case("unconsumed", ParamTypestateAttr::Unconsumed) | |||
7445 | .Default(Optional<ConsumedState>()); | |||
7446 | if (R) { | |||
7447 | Out = *R; | |||
7448 | return true; | |||
7449 | } | |||
7450 | return false; | |||
7451 | } | |||
7452 | ||||
7453 | static const char *ConvertConsumedStateToStr(ConsumedState Val) { | |||
7454 | switch(Val) { | |||
7455 | case ParamTypestateAttr::Unknown: return "unknown"; | |||
7456 | case ParamTypestateAttr::Consumed: return "consumed"; | |||
7457 | case ParamTypestateAttr::Unconsumed: return "unconsumed"; | |||
7458 | } | |||
7459 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 7459); | |||
7460 | } | |||
7461 | ||||
7462 | ||||
7463 | static bool classof(const Attr *A) { return A->getKind() == attr::ParamTypestate; } | |||
7464 | }; | |||
7465 | ||||
7466 | class PascalAttr : public InheritableAttr { | |||
7467 | public: | |||
7468 | static PascalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7469 | auto *A = new (Ctx) PascalAttr(Loc, Ctx, 0); | |||
7470 | A->setImplicit(true); | |||
7471 | return A; | |||
7472 | } | |||
7473 | ||||
7474 | PascalAttr(SourceRange R, ASTContext &Ctx | |||
7475 | , unsigned SI | |||
7476 | ) | |||
7477 | : InheritableAttr(attr::Pascal, R, SI, false, false) | |||
7478 | { | |||
7479 | } | |||
7480 | ||||
7481 | PascalAttr *clone(ASTContext &C) const; | |||
7482 | void printPretty(raw_ostream &OS, | |||
7483 | const PrintingPolicy &Policy) const; | |||
7484 | const char *getSpelling() const; | |||
7485 | ||||
7486 | ||||
7487 | static bool classof(const Attr *A) { return A->getKind() == attr::Pascal; } | |||
7488 | }; | |||
7489 | ||||
7490 | class PassObjectSizeAttr : public InheritableParamAttr { | |||
7491 | int type; | |||
7492 | ||||
7493 | public: | |||
7494 | enum Spelling { | |||
7495 | GNU_pass_object_size = 0, | |||
7496 | CXX11_clang_pass_object_size = 1, | |||
7497 | C2x_clang_pass_object_size = 2, | |||
7498 | GNU_pass_dynamic_object_size = 3, | |||
7499 | CXX11_clang_pass_dynamic_object_size = 4, | |||
7500 | C2x_clang_pass_dynamic_object_size = 5 | |||
7501 | }; | |||
7502 | ||||
7503 | static PassObjectSizeAttr *CreateImplicit(ASTContext &Ctx, Spelling S, int Type, SourceRange Loc = SourceRange()) { | |||
7504 | auto *A = new (Ctx) PassObjectSizeAttr(Loc, Ctx, Type, S); | |||
7505 | A->setImplicit(true); | |||
7506 | return A; | |||
7507 | } | |||
7508 | ||||
7509 | PassObjectSizeAttr(SourceRange R, ASTContext &Ctx | |||
7510 | , int Type | |||
7511 | , unsigned SI | |||
7512 | ) | |||
7513 | : InheritableParamAttr(attr::PassObjectSize, R, SI, false, false) | |||
7514 | , type(Type) | |||
7515 | { | |||
7516 | } | |||
7517 | ||||
7518 | PassObjectSizeAttr *clone(ASTContext &C) const; | |||
7519 | void printPretty(raw_ostream &OS, | |||
7520 | const PrintingPolicy &Policy) const; | |||
7521 | const char *getSpelling() const; | |||
7522 | Spelling getSemanticSpelling() const { | |||
7523 | switch (SpellingListIndex) { | |||
7524 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 7524); | |||
7525 | case 0: return GNU_pass_object_size; | |||
7526 | case 1: return CXX11_clang_pass_object_size; | |||
7527 | case 2: return C2x_clang_pass_object_size; | |||
7528 | case 3: return GNU_pass_dynamic_object_size; | |||
7529 | case 4: return CXX11_clang_pass_dynamic_object_size; | |||
7530 | case 5: return C2x_clang_pass_dynamic_object_size; | |||
7531 | } | |||
7532 | } | |||
7533 | bool isDynamic() const { return SpellingListIndex == 3 || | |||
7534 | SpellingListIndex == 4 || | |||
7535 | SpellingListIndex == 5; } | |||
7536 | int getType() const { | |||
7537 | return type; | |||
7538 | } | |||
7539 | ||||
7540 | ||||
7541 | ||||
7542 | static bool classof(const Attr *A) { return A->getKind() == attr::PassObjectSize; } | |||
7543 | }; | |||
7544 | ||||
7545 | class PcsAttr : public InheritableAttr { | |||
7546 | public: | |||
7547 | enum PCSType { | |||
7548 | AAPCS, | |||
7549 | AAPCS_VFP | |||
7550 | }; | |||
7551 | private: | |||
7552 | PCSType pCS; | |||
7553 | ||||
7554 | public: | |||
7555 | static PcsAttr *CreateImplicit(ASTContext &Ctx, PCSType PCS, SourceRange Loc = SourceRange()) { | |||
7556 | auto *A = new (Ctx) PcsAttr(Loc, Ctx, PCS, 0); | |||
7557 | A->setImplicit(true); | |||
7558 | return A; | |||
7559 | } | |||
7560 | ||||
7561 | PcsAttr(SourceRange R, ASTContext &Ctx | |||
7562 | , PCSType PCS | |||
7563 | , unsigned SI | |||
7564 | ) | |||
7565 | : InheritableAttr(attr::Pcs, R, SI, false, false) | |||
7566 | , pCS(PCS) | |||
7567 | { | |||
7568 | } | |||
7569 | ||||
7570 | PcsAttr *clone(ASTContext &C) const; | |||
7571 | void printPretty(raw_ostream &OS, | |||
7572 | const PrintingPolicy &Policy) const; | |||
7573 | const char *getSpelling() const; | |||
7574 | PCSType getPCS() const { | |||
7575 | return pCS; | |||
7576 | } | |||
7577 | ||||
7578 | static bool ConvertStrToPCSType(StringRef Val, PCSType &Out) { | |||
7579 | Optional<PCSType> R = llvm::StringSwitch<Optional<PCSType>>(Val) | |||
7580 | .Case("aapcs", PcsAttr::AAPCS) | |||
7581 | .Case("aapcs-vfp", PcsAttr::AAPCS_VFP) | |||
7582 | .Default(Optional<PCSType>()); | |||
7583 | if (R) { | |||
7584 | Out = *R; | |||
7585 | return true; | |||
7586 | } | |||
7587 | return false; | |||
7588 | } | |||
7589 | ||||
7590 | static const char *ConvertPCSTypeToStr(PCSType Val) { | |||
7591 | switch(Val) { | |||
7592 | case PcsAttr::AAPCS: return "aapcs"; | |||
7593 | case PcsAttr::AAPCS_VFP: return "aapcs-vfp"; | |||
7594 | } | |||
7595 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 7595); | |||
7596 | } | |||
7597 | ||||
7598 | ||||
7599 | static bool classof(const Attr *A) { return A->getKind() == attr::Pcs; } | |||
7600 | }; | |||
7601 | ||||
7602 | class PragmaClangBSSSectionAttr : public InheritableAttr { | |||
7603 | unsigned nameLength; | |||
7604 | char *name; | |||
7605 | ||||
7606 | public: | |||
7607 | static PragmaClangBSSSectionAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) { | |||
7608 | auto *A = new (Ctx) PragmaClangBSSSectionAttr(Loc, Ctx, Name, 0); | |||
7609 | A->setImplicit(true); | |||
7610 | return A; | |||
7611 | } | |||
7612 | ||||
7613 | PragmaClangBSSSectionAttr(SourceRange R, ASTContext &Ctx | |||
7614 | , llvm::StringRef Name | |||
7615 | , unsigned SI | |||
7616 | ) | |||
7617 | : InheritableAttr(attr::PragmaClangBSSSection, R, SI, false, false) | |||
7618 | , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength]) | |||
7619 | { | |||
7620 | if (!Name.empty()) | |||
7621 | std::memcpy(name, Name.data(), nameLength); | |||
7622 | } | |||
7623 | ||||
7624 | PragmaClangBSSSectionAttr *clone(ASTContext &C) const; | |||
7625 | void printPretty(raw_ostream &OS, | |||
7626 | const PrintingPolicy &Policy) const; | |||
7627 | const char *getSpelling() const; | |||
7628 | llvm::StringRef getName() const { | |||
7629 | return llvm::StringRef(name, nameLength); | |||
7630 | } | |||
7631 | unsigned getNameLength() const { | |||
7632 | return nameLength; | |||
7633 | } | |||
7634 | void setName(ASTContext &C, llvm::StringRef S) { | |||
7635 | nameLength = S.size(); | |||
7636 | this->name = new (C, 1) char [nameLength]; | |||
7637 | if (!S.empty()) | |||
7638 | std::memcpy(this->name, S.data(), nameLength); | |||
7639 | } | |||
7640 | ||||
7641 | ||||
7642 | ||||
7643 | static bool classof(const Attr *A) { return A->getKind() == attr::PragmaClangBSSSection; } | |||
7644 | }; | |||
7645 | ||||
7646 | class PragmaClangDataSectionAttr : public InheritableAttr { | |||
7647 | unsigned nameLength; | |||
7648 | char *name; | |||
7649 | ||||
7650 | public: | |||
7651 | static PragmaClangDataSectionAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) { | |||
7652 | auto *A = new (Ctx) PragmaClangDataSectionAttr(Loc, Ctx, Name, 0); | |||
7653 | A->setImplicit(true); | |||
7654 | return A; | |||
7655 | } | |||
7656 | ||||
7657 | PragmaClangDataSectionAttr(SourceRange R, ASTContext &Ctx | |||
7658 | , llvm::StringRef Name | |||
7659 | , unsigned SI | |||
7660 | ) | |||
7661 | : InheritableAttr(attr::PragmaClangDataSection, R, SI, false, false) | |||
7662 | , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength]) | |||
7663 | { | |||
7664 | if (!Name.empty()) | |||
7665 | std::memcpy(name, Name.data(), nameLength); | |||
7666 | } | |||
7667 | ||||
7668 | PragmaClangDataSectionAttr *clone(ASTContext &C) const; | |||
7669 | void printPretty(raw_ostream &OS, | |||
7670 | const PrintingPolicy &Policy) const; | |||
7671 | const char *getSpelling() const; | |||
7672 | llvm::StringRef getName() const { | |||
7673 | return llvm::StringRef(name, nameLength); | |||
7674 | } | |||
7675 | unsigned getNameLength() const { | |||
7676 | return nameLength; | |||
7677 | } | |||
7678 | void setName(ASTContext &C, llvm::StringRef S) { | |||
7679 | nameLength = S.size(); | |||
7680 | this->name = new (C, 1) char [nameLength]; | |||
7681 | if (!S.empty()) | |||
7682 | std::memcpy(this->name, S.data(), nameLength); | |||
7683 | } | |||
7684 | ||||
7685 | ||||
7686 | ||||
7687 | static bool classof(const Attr *A) { return A->getKind() == attr::PragmaClangDataSection; } | |||
7688 | }; | |||
7689 | ||||
7690 | class PragmaClangRodataSectionAttr : public InheritableAttr { | |||
7691 | unsigned nameLength; | |||
7692 | char *name; | |||
7693 | ||||
7694 | public: | |||
7695 | static PragmaClangRodataSectionAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) { | |||
7696 | auto *A = new (Ctx) PragmaClangRodataSectionAttr(Loc, Ctx, Name, 0); | |||
7697 | A->setImplicit(true); | |||
7698 | return A; | |||
7699 | } | |||
7700 | ||||
7701 | PragmaClangRodataSectionAttr(SourceRange R, ASTContext &Ctx | |||
7702 | , llvm::StringRef Name | |||
7703 | , unsigned SI | |||
7704 | ) | |||
7705 | : InheritableAttr(attr::PragmaClangRodataSection, R, SI, false, false) | |||
7706 | , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength]) | |||
7707 | { | |||
7708 | if (!Name.empty()) | |||
7709 | std::memcpy(name, Name.data(), nameLength); | |||
7710 | } | |||
7711 | ||||
7712 | PragmaClangRodataSectionAttr *clone(ASTContext &C) const; | |||
7713 | void printPretty(raw_ostream &OS, | |||
7714 | const PrintingPolicy &Policy) const; | |||
7715 | const char *getSpelling() const; | |||
7716 | llvm::StringRef getName() const { | |||
7717 | return llvm::StringRef(name, nameLength); | |||
7718 | } | |||
7719 | unsigned getNameLength() const { | |||
7720 | return nameLength; | |||
7721 | } | |||
7722 | void setName(ASTContext &C, llvm::StringRef S) { | |||
7723 | nameLength = S.size(); | |||
7724 | this->name = new (C, 1) char [nameLength]; | |||
7725 | if (!S.empty()) | |||
7726 | std::memcpy(this->name, S.data(), nameLength); | |||
7727 | } | |||
7728 | ||||
7729 | ||||
7730 | ||||
7731 | static bool classof(const Attr *A) { return A->getKind() == attr::PragmaClangRodataSection; } | |||
7732 | }; | |||
7733 | ||||
7734 | class PragmaClangTextSectionAttr : public InheritableAttr { | |||
7735 | unsigned nameLength; | |||
7736 | char *name; | |||
7737 | ||||
7738 | public: | |||
7739 | static PragmaClangTextSectionAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) { | |||
7740 | auto *A = new (Ctx) PragmaClangTextSectionAttr(Loc, Ctx, Name, 0); | |||
7741 | A->setImplicit(true); | |||
7742 | return A; | |||
7743 | } | |||
7744 | ||||
7745 | PragmaClangTextSectionAttr(SourceRange R, ASTContext &Ctx | |||
7746 | , llvm::StringRef Name | |||
7747 | , unsigned SI | |||
7748 | ) | |||
7749 | : InheritableAttr(attr::PragmaClangTextSection, R, SI, false, false) | |||
7750 | , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength]) | |||
7751 | { | |||
7752 | if (!Name.empty()) | |||
7753 | std::memcpy(name, Name.data(), nameLength); | |||
7754 | } | |||
7755 | ||||
7756 | PragmaClangTextSectionAttr *clone(ASTContext &C) const; | |||
7757 | void printPretty(raw_ostream &OS, | |||
7758 | const PrintingPolicy &Policy) const; | |||
7759 | const char *getSpelling() const; | |||
7760 | llvm::StringRef getName() const { | |||
7761 | return llvm::StringRef(name, nameLength); | |||
7762 | } | |||
7763 | unsigned getNameLength() const { | |||
7764 | return nameLength; | |||
7765 | } | |||
7766 | void setName(ASTContext &C, llvm::StringRef S) { | |||
7767 | nameLength = S.size(); | |||
7768 | this->name = new (C, 1) char [nameLength]; | |||
7769 | if (!S.empty()) | |||
7770 | std::memcpy(this->name, S.data(), nameLength); | |||
7771 | } | |||
7772 | ||||
7773 | ||||
7774 | ||||
7775 | static bool classof(const Attr *A) { return A->getKind() == attr::PragmaClangTextSection; } | |||
7776 | }; | |||
7777 | ||||
7778 | class PreserveAllAttr : public InheritableAttr { | |||
7779 | public: | |||
7780 | static PreserveAllAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7781 | auto *A = new (Ctx) PreserveAllAttr(Loc, Ctx, 0); | |||
7782 | A->setImplicit(true); | |||
7783 | return A; | |||
7784 | } | |||
7785 | ||||
7786 | PreserveAllAttr(SourceRange R, ASTContext &Ctx | |||
7787 | , unsigned SI | |||
7788 | ) | |||
7789 | : InheritableAttr(attr::PreserveAll, R, SI, false, false) | |||
7790 | { | |||
7791 | } | |||
7792 | ||||
7793 | PreserveAllAttr *clone(ASTContext &C) const; | |||
7794 | void printPretty(raw_ostream &OS, | |||
7795 | const PrintingPolicy &Policy) const; | |||
7796 | const char *getSpelling() const; | |||
7797 | ||||
7798 | ||||
7799 | static bool classof(const Attr *A) { return A->getKind() == attr::PreserveAll; } | |||
7800 | }; | |||
7801 | ||||
7802 | class PreserveMostAttr : public InheritableAttr { | |||
7803 | public: | |||
7804 | static PreserveMostAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7805 | auto *A = new (Ctx) PreserveMostAttr(Loc, Ctx, 0); | |||
7806 | A->setImplicit(true); | |||
7807 | return A; | |||
7808 | } | |||
7809 | ||||
7810 | PreserveMostAttr(SourceRange R, ASTContext &Ctx | |||
7811 | , unsigned SI | |||
7812 | ) | |||
7813 | : InheritableAttr(attr::PreserveMost, R, SI, false, false) | |||
7814 | { | |||
7815 | } | |||
7816 | ||||
7817 | PreserveMostAttr *clone(ASTContext &C) const; | |||
7818 | void printPretty(raw_ostream &OS, | |||
7819 | const PrintingPolicy &Policy) const; | |||
7820 | const char *getSpelling() const; | |||
7821 | ||||
7822 | ||||
7823 | static bool classof(const Attr *A) { return A->getKind() == attr::PreserveMost; } | |||
7824 | }; | |||
7825 | ||||
7826 | class PtGuardedByAttr : public InheritableAttr { | |||
7827 | Expr * arg; | |||
7828 | ||||
7829 | public: | |||
7830 | static PtGuardedByAttr *CreateImplicit(ASTContext &Ctx, Expr * Arg, SourceRange Loc = SourceRange()) { | |||
7831 | auto *A = new (Ctx) PtGuardedByAttr(Loc, Ctx, Arg, 0); | |||
7832 | A->setImplicit(true); | |||
7833 | return A; | |||
7834 | } | |||
7835 | ||||
7836 | PtGuardedByAttr(SourceRange R, ASTContext &Ctx | |||
7837 | , Expr * Arg | |||
7838 | , unsigned SI | |||
7839 | ) | |||
7840 | : InheritableAttr(attr::PtGuardedBy, R, SI, true, true) | |||
7841 | , arg(Arg) | |||
7842 | { | |||
7843 | } | |||
7844 | ||||
7845 | PtGuardedByAttr *clone(ASTContext &C) const; | |||
7846 | void printPretty(raw_ostream &OS, | |||
7847 | const PrintingPolicy &Policy) const; | |||
7848 | const char *getSpelling() const; | |||
7849 | Expr * getArg() const { | |||
7850 | return arg; | |||
7851 | } | |||
7852 | ||||
7853 | ||||
7854 | ||||
7855 | static bool classof(const Attr *A) { return A->getKind() == attr::PtGuardedBy; } | |||
7856 | }; | |||
7857 | ||||
7858 | class PtGuardedVarAttr : public InheritableAttr { | |||
7859 | public: | |||
7860 | static PtGuardedVarAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7861 | auto *A = new (Ctx) PtGuardedVarAttr(Loc, Ctx, 0); | |||
7862 | A->setImplicit(true); | |||
7863 | return A; | |||
7864 | } | |||
7865 | ||||
7866 | PtGuardedVarAttr(SourceRange R, ASTContext &Ctx | |||
7867 | , unsigned SI | |||
7868 | ) | |||
7869 | : InheritableAttr(attr::PtGuardedVar, R, SI, false, false) | |||
7870 | { | |||
7871 | } | |||
7872 | ||||
7873 | PtGuardedVarAttr *clone(ASTContext &C) const; | |||
7874 | void printPretty(raw_ostream &OS, | |||
7875 | const PrintingPolicy &Policy) const; | |||
7876 | const char *getSpelling() const; | |||
7877 | ||||
7878 | ||||
7879 | static bool classof(const Attr *A) { return A->getKind() == attr::PtGuardedVar; } | |||
7880 | }; | |||
7881 | ||||
7882 | class Ptr32Attr : public TypeAttr { | |||
7883 | public: | |||
7884 | static Ptr32Attr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7885 | auto *A = new (Ctx) Ptr32Attr(Loc, Ctx, 0); | |||
7886 | A->setImplicit(true); | |||
7887 | return A; | |||
7888 | } | |||
7889 | ||||
7890 | Ptr32Attr(SourceRange R, ASTContext &Ctx | |||
7891 | , unsigned SI | |||
7892 | ) | |||
7893 | : TypeAttr(attr::Ptr32, R, SI, false) | |||
7894 | { | |||
7895 | } | |||
7896 | ||||
7897 | Ptr32Attr *clone(ASTContext &C) const; | |||
7898 | void printPretty(raw_ostream &OS, | |||
7899 | const PrintingPolicy &Policy) const; | |||
7900 | const char *getSpelling() const; | |||
7901 | ||||
7902 | ||||
7903 | static bool classof(const Attr *A) { return A->getKind() == attr::Ptr32; } | |||
7904 | }; | |||
7905 | ||||
7906 | class Ptr64Attr : public TypeAttr { | |||
7907 | public: | |||
7908 | static Ptr64Attr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7909 | auto *A = new (Ctx) Ptr64Attr(Loc, Ctx, 0); | |||
7910 | A->setImplicit(true); | |||
7911 | return A; | |||
7912 | } | |||
7913 | ||||
7914 | Ptr64Attr(SourceRange R, ASTContext &Ctx | |||
7915 | , unsigned SI | |||
7916 | ) | |||
7917 | : TypeAttr(attr::Ptr64, R, SI, false) | |||
7918 | { | |||
7919 | } | |||
7920 | ||||
7921 | Ptr64Attr *clone(ASTContext &C) const; | |||
7922 | void printPretty(raw_ostream &OS, | |||
7923 | const PrintingPolicy &Policy) const; | |||
7924 | const char *getSpelling() const; | |||
7925 | ||||
7926 | ||||
7927 | static bool classof(const Attr *A) { return A->getKind() == attr::Ptr64; } | |||
7928 | }; | |||
7929 | ||||
7930 | class PureAttr : public InheritableAttr { | |||
7931 | public: | |||
7932 | static PureAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7933 | auto *A = new (Ctx) PureAttr(Loc, Ctx, 0); | |||
7934 | A->setImplicit(true); | |||
7935 | return A; | |||
7936 | } | |||
7937 | ||||
7938 | PureAttr(SourceRange R, ASTContext &Ctx | |||
7939 | , unsigned SI | |||
7940 | ) | |||
7941 | : InheritableAttr(attr::Pure, R, SI, false, false) | |||
7942 | { | |||
7943 | } | |||
7944 | ||||
7945 | PureAttr *clone(ASTContext &C) const; | |||
7946 | void printPretty(raw_ostream &OS, | |||
7947 | const PrintingPolicy &Policy) const; | |||
7948 | const char *getSpelling() const; | |||
7949 | ||||
7950 | ||||
7951 | static bool classof(const Attr *A) { return A->getKind() == attr::Pure; } | |||
7952 | }; | |||
7953 | ||||
7954 | class RISCVInterruptAttr : public InheritableAttr { | |||
7955 | public: | |||
7956 | enum InterruptType { | |||
7957 | user, | |||
7958 | supervisor, | |||
7959 | machine | |||
7960 | }; | |||
7961 | private: | |||
7962 | InterruptType interrupt; | |||
7963 | ||||
7964 | public: | |||
7965 | static RISCVInterruptAttr *CreateImplicit(ASTContext &Ctx, InterruptType Interrupt, SourceRange Loc = SourceRange()) { | |||
7966 | auto *A = new (Ctx) RISCVInterruptAttr(Loc, Ctx, Interrupt, 0); | |||
7967 | A->setImplicit(true); | |||
7968 | return A; | |||
7969 | } | |||
7970 | ||||
7971 | RISCVInterruptAttr(SourceRange R, ASTContext &Ctx | |||
7972 | , InterruptType Interrupt | |||
7973 | , unsigned SI | |||
7974 | ) | |||
7975 | : InheritableAttr(attr::RISCVInterrupt, R, SI, false, false) | |||
7976 | , interrupt(Interrupt) | |||
7977 | { | |||
7978 | } | |||
7979 | ||||
7980 | RISCVInterruptAttr(SourceRange R, ASTContext &Ctx | |||
7981 | , unsigned SI | |||
7982 | ) | |||
7983 | : InheritableAttr(attr::RISCVInterrupt, R, SI, false, false) | |||
7984 | , interrupt(InterruptType(0)) | |||
7985 | { | |||
7986 | } | |||
7987 | ||||
7988 | RISCVInterruptAttr *clone(ASTContext &C) const; | |||
7989 | void printPretty(raw_ostream &OS, | |||
7990 | const PrintingPolicy &Policy) const; | |||
7991 | const char *getSpelling() const; | |||
7992 | InterruptType getInterrupt() const { | |||
7993 | return interrupt; | |||
7994 | } | |||
7995 | ||||
7996 | static bool ConvertStrToInterruptType(StringRef Val, InterruptType &Out) { | |||
7997 | Optional<InterruptType> R = llvm::StringSwitch<Optional<InterruptType>>(Val) | |||
7998 | .Case("user", RISCVInterruptAttr::user) | |||
7999 | .Case("supervisor", RISCVInterruptAttr::supervisor) | |||
8000 | .Case("machine", RISCVInterruptAttr::machine) | |||
8001 | .Default(Optional<InterruptType>()); | |||
8002 | if (R) { | |||
8003 | Out = *R; | |||
8004 | return true; | |||
8005 | } | |||
8006 | return false; | |||
8007 | } | |||
8008 | ||||
8009 | static const char *ConvertInterruptTypeToStr(InterruptType Val) { | |||
8010 | switch(Val) { | |||
8011 | case RISCVInterruptAttr::user: return "user"; | |||
8012 | case RISCVInterruptAttr::supervisor: return "supervisor"; | |||
8013 | case RISCVInterruptAttr::machine: return "machine"; | |||
8014 | } | |||
8015 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 8015); | |||
8016 | } | |||
8017 | ||||
8018 | ||||
8019 | static bool classof(const Attr *A) { return A->getKind() == attr::RISCVInterrupt; } | |||
8020 | }; | |||
8021 | ||||
8022 | class RegCallAttr : public InheritableAttr { | |||
8023 | public: | |||
8024 | static RegCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8025 | auto *A = new (Ctx) RegCallAttr(Loc, Ctx, 0); | |||
8026 | A->setImplicit(true); | |||
8027 | return A; | |||
8028 | } | |||
8029 | ||||
8030 | RegCallAttr(SourceRange R, ASTContext &Ctx | |||
8031 | , unsigned SI | |||
8032 | ) | |||
8033 | : InheritableAttr(attr::RegCall, R, SI, false, false) | |||
8034 | { | |||
8035 | } | |||
8036 | ||||
8037 | RegCallAttr *clone(ASTContext &C) const; | |||
8038 | void printPretty(raw_ostream &OS, | |||
8039 | const PrintingPolicy &Policy) const; | |||
8040 | const char *getSpelling() const; | |||
8041 | ||||
8042 | ||||
8043 | static bool classof(const Attr *A) { return A->getKind() == attr::RegCall; } | |||
8044 | }; | |||
8045 | ||||
8046 | class ReinitializesAttr : public InheritableAttr { | |||
8047 | public: | |||
8048 | static ReinitializesAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8049 | auto *A = new (Ctx) ReinitializesAttr(Loc, Ctx, 0); | |||
8050 | A->setImplicit(true); | |||
8051 | return A; | |||
8052 | } | |||
8053 | ||||
8054 | ReinitializesAttr(SourceRange R, ASTContext &Ctx | |||
8055 | , unsigned SI | |||
8056 | ) | |||
8057 | : InheritableAttr(attr::Reinitializes, R, SI, false, false) | |||
8058 | { | |||
8059 | } | |||
8060 | ||||
8061 | ReinitializesAttr *clone(ASTContext &C) const; | |||
8062 | void printPretty(raw_ostream &OS, | |||
8063 | const PrintingPolicy &Policy) const; | |||
8064 | const char *getSpelling() const; | |||
8065 | ||||
8066 | ||||
8067 | static bool classof(const Attr *A) { return A->getKind() == attr::Reinitializes; } | |||
8068 | }; | |||
8069 | ||||
8070 | class ReleaseCapabilityAttr : public InheritableAttr { | |||
8071 | unsigned args_Size; | |||
8072 | Expr * *args_; | |||
8073 | ||||
8074 | public: | |||
8075 | enum Spelling { | |||
8076 | GNU_release_capability = 0, | |||
8077 | CXX11_clang_release_capability = 1, | |||
8078 | GNU_release_shared_capability = 2, | |||
8079 | CXX11_clang_release_shared_capability = 3, | |||
8080 | GNU_release_generic_capability = 4, | |||
8081 | CXX11_clang_release_generic_capability = 5, | |||
8082 | GNU_unlock_function = 6, | |||
8083 | CXX11_clang_unlock_function = 7 | |||
8084 | }; | |||
8085 | ||||
8086 | static ReleaseCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
8087 | auto *A = new (Ctx) ReleaseCapabilityAttr(Loc, Ctx, Args, ArgsSize, S); | |||
8088 | A->setImplicit(true); | |||
8089 | return A; | |||
8090 | } | |||
8091 | ||||
8092 | ReleaseCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
8093 | , Expr * *Args, unsigned ArgsSize | |||
8094 | , unsigned SI | |||
8095 | ) | |||
8096 | : InheritableAttr(attr::ReleaseCapability, R, SI, true, true) | |||
8097 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
8098 | { | |||
8099 | std::copy(Args, Args + args_Size, args_); | |||
8100 | } | |||
8101 | ||||
8102 | ReleaseCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
8103 | , unsigned SI | |||
8104 | ) | |||
8105 | : InheritableAttr(attr::ReleaseCapability, R, SI, true, true) | |||
8106 | , args_Size(0), args_(nullptr) | |||
8107 | { | |||
8108 | } | |||
8109 | ||||
8110 | ReleaseCapabilityAttr *clone(ASTContext &C) const; | |||
8111 | void printPretty(raw_ostream &OS, | |||
8112 | const PrintingPolicy &Policy) const; | |||
8113 | const char *getSpelling() const; | |||
8114 | Spelling getSemanticSpelling() const { | |||
8115 | switch (SpellingListIndex) { | |||
8116 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 8116); | |||
8117 | case 0: return GNU_release_capability; | |||
8118 | case 1: return CXX11_clang_release_capability; | |||
8119 | case 2: return GNU_release_shared_capability; | |||
8120 | case 3: return CXX11_clang_release_shared_capability; | |||
8121 | case 4: return GNU_release_generic_capability; | |||
8122 | case 5: return CXX11_clang_release_generic_capability; | |||
8123 | case 6: return GNU_unlock_function; | |||
8124 | case 7: return CXX11_clang_unlock_function; | |||
8125 | } | |||
8126 | } | |||
8127 | bool isShared() const { return SpellingListIndex == 2 || | |||
8128 | SpellingListIndex == 3; } | |||
8129 | bool isGeneric() const { return SpellingListIndex == 4 || | |||
8130 | SpellingListIndex == 5 || | |||
8131 | SpellingListIndex == 6 || | |||
8132 | SpellingListIndex == 7; } | |||
8133 | typedef Expr ** args_iterator; | |||
8134 | args_iterator args_begin() const { return args_; } | |||
8135 | args_iterator args_end() const { return args_ + args_Size; } | |||
8136 | unsigned args_size() const { return args_Size; } | |||
8137 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
8138 | ||||
8139 | ||||
8140 | ||||
8141 | ||||
8142 | static bool classof(const Attr *A) { return A->getKind() == attr::ReleaseCapability; } | |||
8143 | }; | |||
8144 | ||||
8145 | class RenderScriptKernelAttr : public Attr { | |||
8146 | public: | |||
8147 | static RenderScriptKernelAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8148 | auto *A = new (Ctx) RenderScriptKernelAttr(Loc, Ctx, 0); | |||
8149 | A->setImplicit(true); | |||
8150 | return A; | |||
8151 | } | |||
8152 | ||||
8153 | RenderScriptKernelAttr(SourceRange R, ASTContext &Ctx | |||
8154 | , unsigned SI | |||
8155 | ) | |||
8156 | : Attr(attr::RenderScriptKernel, R, SI, false) | |||
8157 | { | |||
8158 | } | |||
8159 | ||||
8160 | RenderScriptKernelAttr *clone(ASTContext &C) const; | |||
8161 | void printPretty(raw_ostream &OS, | |||
8162 | const PrintingPolicy &Policy) const; | |||
8163 | const char *getSpelling() const; | |||
8164 | ||||
8165 | ||||
8166 | static bool classof(const Attr *A) { return A->getKind() == attr::RenderScriptKernel; } | |||
8167 | }; | |||
8168 | ||||
8169 | class ReqdWorkGroupSizeAttr : public InheritableAttr { | |||
8170 | unsigned xDim; | |||
8171 | ||||
8172 | unsigned yDim; | |||
8173 | ||||
8174 | unsigned zDim; | |||
8175 | ||||
8176 | public: | |||
8177 | static ReqdWorkGroupSizeAttr *CreateImplicit(ASTContext &Ctx, unsigned XDim, unsigned YDim, unsigned ZDim, SourceRange Loc = SourceRange()) { | |||
8178 | auto *A = new (Ctx) ReqdWorkGroupSizeAttr(Loc, Ctx, XDim, YDim, ZDim, 0); | |||
8179 | A->setImplicit(true); | |||
8180 | return A; | |||
8181 | } | |||
8182 | ||||
8183 | ReqdWorkGroupSizeAttr(SourceRange R, ASTContext &Ctx | |||
8184 | , unsigned XDim | |||
8185 | , unsigned YDim | |||
8186 | , unsigned ZDim | |||
8187 | , unsigned SI | |||
8188 | ) | |||
8189 | : InheritableAttr(attr::ReqdWorkGroupSize, R, SI, false, false) | |||
8190 | , xDim(XDim) | |||
8191 | , yDim(YDim) | |||
8192 | , zDim(ZDim) | |||
8193 | { | |||
8194 | } | |||
8195 | ||||
8196 | ReqdWorkGroupSizeAttr *clone(ASTContext &C) const; | |||
8197 | void printPretty(raw_ostream &OS, | |||
8198 | const PrintingPolicy &Policy) const; | |||
8199 | const char *getSpelling() const; | |||
8200 | unsigned getXDim() const { | |||
8201 | return xDim; | |||
8202 | } | |||
8203 | ||||
8204 | unsigned getYDim() const { | |||
8205 | return yDim; | |||
8206 | } | |||
8207 | ||||
8208 | unsigned getZDim() const { | |||
8209 | return zDim; | |||
8210 | } | |||
8211 | ||||
8212 | ||||
8213 | ||||
8214 | static bool classof(const Attr *A) { return A->getKind() == attr::ReqdWorkGroupSize; } | |||
8215 | }; | |||
8216 | ||||
8217 | class RequireConstantInitAttr : public InheritableAttr { | |||
8218 | public: | |||
8219 | static RequireConstantInitAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8220 | auto *A = new (Ctx) RequireConstantInitAttr(Loc, Ctx, 0); | |||
8221 | A->setImplicit(true); | |||
8222 | return A; | |||
8223 | } | |||
8224 | ||||
8225 | RequireConstantInitAttr(SourceRange R, ASTContext &Ctx | |||
8226 | , unsigned SI | |||
8227 | ) | |||
8228 | : InheritableAttr(attr::RequireConstantInit, R, SI, false, false) | |||
8229 | { | |||
8230 | } | |||
8231 | ||||
8232 | RequireConstantInitAttr *clone(ASTContext &C) const; | |||
8233 | void printPretty(raw_ostream &OS, | |||
8234 | const PrintingPolicy &Policy) const; | |||
8235 | const char *getSpelling() const; | |||
8236 | ||||
8237 | ||||
8238 | static bool classof(const Attr *A) { return A->getKind() == attr::RequireConstantInit; } | |||
8239 | }; | |||
8240 | ||||
8241 | class RequiresCapabilityAttr : public InheritableAttr { | |||
8242 | unsigned args_Size; | |||
8243 | Expr * *args_; | |||
8244 | ||||
8245 | public: | |||
8246 | enum Spelling { | |||
8247 | GNU_requires_capability = 0, | |||
8248 | CXX11_clang_requires_capability = 1, | |||
8249 | GNU_exclusive_locks_required = 2, | |||
8250 | CXX11_clang_exclusive_locks_required = 3, | |||
8251 | GNU_requires_shared_capability = 4, | |||
8252 | CXX11_clang_requires_shared_capability = 5, | |||
8253 | GNU_shared_locks_required = 6, | |||
8254 | CXX11_clang_shared_locks_required = 7 | |||
8255 | }; | |||
8256 | ||||
8257 | static RequiresCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
8258 | auto *A = new (Ctx) RequiresCapabilityAttr(Loc, Ctx, Args, ArgsSize, S); | |||
8259 | A->setImplicit(true); | |||
8260 | return A; | |||
8261 | } | |||
8262 | ||||
8263 | RequiresCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
8264 | , Expr * *Args, unsigned ArgsSize | |||
8265 | , unsigned SI | |||
8266 | ) | |||
8267 | : InheritableAttr(attr::RequiresCapability, R, SI, true, true) | |||
8268 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
8269 | { | |||
8270 | std::copy(Args, Args + args_Size, args_); | |||
8271 | } | |||
8272 | ||||
8273 | RequiresCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
8274 | , unsigned SI | |||
8275 | ) | |||
8276 | : InheritableAttr(attr::RequiresCapability, R, SI, true, true) | |||
8277 | , args_Size(0), args_(nullptr) | |||
8278 | { | |||
8279 | } | |||
8280 | ||||
8281 | RequiresCapabilityAttr *clone(ASTContext &C) const; | |||
8282 | void printPretty(raw_ostream &OS, | |||
8283 | const PrintingPolicy &Policy) const; | |||
8284 | const char *getSpelling() const; | |||
8285 | Spelling getSemanticSpelling() const { | |||
8286 | switch (SpellingListIndex) { | |||
8287 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 8287); | |||
8288 | case 0: return GNU_requires_capability; | |||
8289 | case 1: return CXX11_clang_requires_capability; | |||
8290 | case 2: return GNU_exclusive_locks_required; | |||
8291 | case 3: return CXX11_clang_exclusive_locks_required; | |||
8292 | case 4: return GNU_requires_shared_capability; | |||
8293 | case 5: return CXX11_clang_requires_shared_capability; | |||
8294 | case 6: return GNU_shared_locks_required; | |||
8295 | case 7: return CXX11_clang_shared_locks_required; | |||
8296 | } | |||
8297 | } | |||
8298 | bool isShared() const { return SpellingListIndex == 4 || | |||
8299 | SpellingListIndex == 5 || | |||
8300 | SpellingListIndex == 6 || | |||
8301 | SpellingListIndex == 7; } | |||
8302 | typedef Expr ** args_iterator; | |||
8303 | args_iterator args_begin() const { return args_; } | |||
8304 | args_iterator args_end() const { return args_ + args_Size; } | |||
8305 | unsigned args_size() const { return args_Size; } | |||
8306 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
8307 | ||||
8308 | ||||
8309 | ||||
8310 | ||||
8311 | static bool classof(const Attr *A) { return A->getKind() == attr::RequiresCapability; } | |||
8312 | }; | |||
8313 | ||||
8314 | class RestrictAttr : public InheritableAttr { | |||
8315 | public: | |||
8316 | enum Spelling { | |||
8317 | Declspec_restrict = 0, | |||
8318 | GNU_malloc = 1, | |||
8319 | CXX11_gnu_malloc = 2 | |||
8320 | }; | |||
8321 | ||||
8322 | static RestrictAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
8323 | auto *A = new (Ctx) RestrictAttr(Loc, Ctx, S); | |||
8324 | A->setImplicit(true); | |||
8325 | return A; | |||
8326 | } | |||
8327 | ||||
8328 | RestrictAttr(SourceRange R, ASTContext &Ctx | |||
8329 | , unsigned SI | |||
8330 | ) | |||
8331 | : InheritableAttr(attr::Restrict, R, SI, false, false) | |||
8332 | { | |||
8333 | } | |||
8334 | ||||
8335 | RestrictAttr *clone(ASTContext &C) const; | |||
8336 | void printPretty(raw_ostream &OS, | |||
8337 | const PrintingPolicy &Policy) const; | |||
8338 | const char *getSpelling() const; | |||
8339 | Spelling getSemanticSpelling() const { | |||
8340 | switch (SpellingListIndex) { | |||
8341 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 8341); | |||
8342 | case 0: return Declspec_restrict; | |||
8343 | case 1: return GNU_malloc; | |||
8344 | case 2: return CXX11_gnu_malloc; | |||
8345 | } | |||
8346 | } | |||
8347 | ||||
8348 | ||||
8349 | static bool classof(const Attr *A) { return A->getKind() == attr::Restrict; } | |||
8350 | }; | |||
8351 | ||||
8352 | class ReturnTypestateAttr : public InheritableAttr { | |||
8353 | public: | |||
8354 | enum ConsumedState { | |||
8355 | Unknown, | |||
8356 | Consumed, | |||
8357 | Unconsumed | |||
8358 | }; | |||
8359 | private: | |||
8360 | ConsumedState state; | |||
8361 | ||||
8362 | public: | |||
8363 | static ReturnTypestateAttr *CreateImplicit(ASTContext &Ctx, ConsumedState State, SourceRange Loc = SourceRange()) { | |||
8364 | auto *A = new (Ctx) ReturnTypestateAttr(Loc, Ctx, State, 0); | |||
8365 | A->setImplicit(true); | |||
8366 | return A; | |||
8367 | } | |||
8368 | ||||
8369 | ReturnTypestateAttr(SourceRange R, ASTContext &Ctx | |||
8370 | , ConsumedState State | |||
8371 | , unsigned SI | |||
8372 | ) | |||
8373 | : InheritableAttr(attr::ReturnTypestate, R, SI, false, false) | |||
8374 | , state(State) | |||
8375 | { | |||
8376 | } | |||
8377 | ||||
8378 | ReturnTypestateAttr *clone(ASTContext &C) const; | |||
8379 | void printPretty(raw_ostream &OS, | |||
8380 | const PrintingPolicy &Policy) const; | |||
8381 | const char *getSpelling() const; | |||
8382 | ConsumedState getState() const { | |||
8383 | return state; | |||
8384 | } | |||
8385 | ||||
8386 | static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) { | |||
8387 | Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val) | |||
8388 | .Case("unknown", ReturnTypestateAttr::Unknown) | |||
8389 | .Case("consumed", ReturnTypestateAttr::Consumed) | |||
8390 | .Case("unconsumed", ReturnTypestateAttr::Unconsumed) | |||
8391 | .Default(Optional<ConsumedState>()); | |||
8392 | if (R) { | |||
8393 | Out = *R; | |||
8394 | return true; | |||
8395 | } | |||
8396 | return false; | |||
8397 | } | |||
8398 | ||||
8399 | static const char *ConvertConsumedStateToStr(ConsumedState Val) { | |||
8400 | switch(Val) { | |||
8401 | case ReturnTypestateAttr::Unknown: return "unknown"; | |||
8402 | case ReturnTypestateAttr::Consumed: return "consumed"; | |||
8403 | case ReturnTypestateAttr::Unconsumed: return "unconsumed"; | |||
8404 | } | |||
8405 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 8405); | |||
8406 | } | |||
8407 | ||||
8408 | ||||
8409 | static bool classof(const Attr *A) { return A->getKind() == attr::ReturnTypestate; } | |||
8410 | }; | |||
8411 | ||||
8412 | class ReturnsNonNullAttr : public InheritableAttr { | |||
8413 | public: | |||
8414 | static ReturnsNonNullAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8415 | auto *A = new (Ctx) ReturnsNonNullAttr(Loc, Ctx, 0); | |||
8416 | A->setImplicit(true); | |||
8417 | return A; | |||
8418 | } | |||
8419 | ||||
8420 | ReturnsNonNullAttr(SourceRange R, ASTContext &Ctx | |||
8421 | , unsigned SI | |||
8422 | ) | |||
8423 | : InheritableAttr(attr::ReturnsNonNull, R, SI, false, false) | |||
8424 | { | |||
8425 | } | |||
8426 | ||||
8427 | ReturnsNonNullAttr *clone(ASTContext &C) const; | |||
8428 | void printPretty(raw_ostream &OS, | |||
8429 | const PrintingPolicy &Policy) const; | |||
8430 | const char *getSpelling() const; | |||
8431 | ||||
8432 | ||||
8433 | static bool classof(const Attr *A) { return A->getKind() == attr::ReturnsNonNull; } | |||
8434 | }; | |||
8435 | ||||
8436 | class ReturnsTwiceAttr : public InheritableAttr { | |||
8437 | public: | |||
8438 | static ReturnsTwiceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8439 | auto *A = new (Ctx) ReturnsTwiceAttr(Loc, Ctx, 0); | |||
8440 | A->setImplicit(true); | |||
8441 | return A; | |||
8442 | } | |||
8443 | ||||
8444 | ReturnsTwiceAttr(SourceRange R, ASTContext &Ctx | |||
8445 | , unsigned SI | |||
8446 | ) | |||
8447 | : InheritableAttr(attr::ReturnsTwice, R, SI, false, false) | |||
8448 | { | |||
8449 | } | |||
8450 | ||||
8451 | ReturnsTwiceAttr *clone(ASTContext &C) const; | |||
8452 | void printPretty(raw_ostream &OS, | |||
8453 | const PrintingPolicy &Policy) const; | |||
8454 | const char *getSpelling() const; | |||
8455 | ||||
8456 | ||||
8457 | static bool classof(const Attr *A) { return A->getKind() == attr::ReturnsTwice; } | |||
8458 | }; | |||
8459 | ||||
8460 | class SPtrAttr : public TypeAttr { | |||
8461 | public: | |||
8462 | static SPtrAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8463 | auto *A = new (Ctx) SPtrAttr(Loc, Ctx, 0); | |||
8464 | A->setImplicit(true); | |||
8465 | return A; | |||
8466 | } | |||
8467 | ||||
8468 | SPtrAttr(SourceRange R, ASTContext &Ctx | |||
8469 | , unsigned SI | |||
8470 | ) | |||
8471 | : TypeAttr(attr::SPtr, R, SI, false) | |||
8472 | { | |||
8473 | } | |||
8474 | ||||
8475 | SPtrAttr *clone(ASTContext &C) const; | |||
8476 | void printPretty(raw_ostream &OS, | |||
8477 | const PrintingPolicy &Policy) const; | |||
8478 | const char *getSpelling() const; | |||
8479 | ||||
8480 | ||||
8481 | static bool classof(const Attr *A) { return A->getKind() == attr::SPtr; } | |||
8482 | }; | |||
8483 | ||||
8484 | class ScopedLockableAttr : public InheritableAttr { | |||
8485 | public: | |||
8486 | static ScopedLockableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8487 | auto *A = new (Ctx) ScopedLockableAttr(Loc, Ctx, 0); | |||
8488 | A->setImplicit(true); | |||
8489 | return A; | |||
8490 | } | |||
8491 | ||||
8492 | ScopedLockableAttr(SourceRange R, ASTContext &Ctx | |||
8493 | , unsigned SI | |||
8494 | ) | |||
8495 | : InheritableAttr(attr::ScopedLockable, R, SI, false, false) | |||
8496 | { | |||
8497 | } | |||
8498 | ||||
8499 | ScopedLockableAttr *clone(ASTContext &C) const; | |||
8500 | void printPretty(raw_ostream &OS, | |||
8501 | const PrintingPolicy &Policy) const; | |||
8502 | const char *getSpelling() const; | |||
8503 | ||||
8504 | ||||
8505 | static bool classof(const Attr *A) { return A->getKind() == attr::ScopedLockable; } | |||
8506 | }; | |||
8507 | ||||
8508 | class SectionAttr : public InheritableAttr { | |||
8509 | unsigned nameLength; | |||
8510 | char *name; | |||
8511 | ||||
8512 | public: | |||
8513 | enum Spelling { | |||
8514 | GNU_section = 0, | |||
8515 | CXX11_gnu_section = 1, | |||
8516 | Declspec_allocate = 2 | |||
8517 | }; | |||
8518 | ||||
8519 | static SectionAttr *CreateImplicit(ASTContext &Ctx, Spelling S, llvm::StringRef Name, SourceRange Loc = SourceRange()) { | |||
8520 | auto *A = new (Ctx) SectionAttr(Loc, Ctx, Name, S); | |||
8521 | A->setImplicit(true); | |||
8522 | return A; | |||
8523 | } | |||
8524 | ||||
8525 | SectionAttr(SourceRange R, ASTContext &Ctx | |||
8526 | , llvm::StringRef Name | |||
8527 | , unsigned SI | |||
8528 | ) | |||
8529 | : InheritableAttr(attr::Section, R, SI, false, false) | |||
8530 | , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength]) | |||
8531 | { | |||
8532 | if (!Name.empty()) | |||
8533 | std::memcpy(name, Name.data(), nameLength); | |||
8534 | } | |||
8535 | ||||
8536 | SectionAttr *clone(ASTContext &C) const; | |||
8537 | void printPretty(raw_ostream &OS, | |||
8538 | const PrintingPolicy &Policy) const; | |||
8539 | const char *getSpelling() const; | |||
8540 | Spelling getSemanticSpelling() const { | |||
8541 | switch (SpellingListIndex) { | |||
8542 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 8542); | |||
8543 | case 0: return GNU_section; | |||
8544 | case 1: return CXX11_gnu_section; | |||
8545 | case 2: return Declspec_allocate; | |||
8546 | } | |||
8547 | } | |||
8548 | llvm::StringRef getName() const { | |||
8549 | return llvm::StringRef(name, nameLength); | |||
8550 | } | |||
8551 | unsigned getNameLength() const { | |||
8552 | return nameLength; | |||
8553 | } | |||
8554 | void setName(ASTContext &C, llvm::StringRef S) { | |||
8555 | nameLength = S.size(); | |||
8556 | this->name = new (C, 1) char [nameLength]; | |||
8557 | if (!S.empty()) | |||
8558 | std::memcpy(this->name, S.data(), nameLength); | |||
8559 | } | |||
8560 | ||||
8561 | ||||
8562 | ||||
8563 | static bool classof(const Attr *A) { return A->getKind() == attr::Section; } | |||
8564 | }; | |||
8565 | ||||
8566 | class SelectAnyAttr : public InheritableAttr { | |||
8567 | public: | |||
8568 | static SelectAnyAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8569 | auto *A = new (Ctx) SelectAnyAttr(Loc, Ctx, 0); | |||
8570 | A->setImplicit(true); | |||
8571 | return A; | |||
8572 | } | |||
8573 | ||||
8574 | SelectAnyAttr(SourceRange R, ASTContext &Ctx | |||
8575 | , unsigned SI | |||
8576 | ) | |||
8577 | : InheritableAttr(attr::SelectAny, R, SI, false, false) | |||
8578 | { | |||
8579 | } | |||
8580 | ||||
8581 | SelectAnyAttr *clone(ASTContext &C) const; | |||
8582 | void printPretty(raw_ostream &OS, | |||
8583 | const PrintingPolicy &Policy) const; | |||
8584 | const char *getSpelling() const; | |||
8585 | ||||
8586 | ||||
8587 | static bool classof(const Attr *A) { return A->getKind() == attr::SelectAny; } | |||
8588 | }; | |||
8589 | ||||
8590 | class SentinelAttr : public InheritableAttr { | |||
8591 | int sentinel; | |||
8592 | ||||
8593 | int nullPos; | |||
8594 | ||||
8595 | public: | |||
8596 | static SentinelAttr *CreateImplicit(ASTContext &Ctx, int Sentinel, int NullPos, SourceRange Loc = SourceRange()) { | |||
8597 | auto *A = new (Ctx) SentinelAttr(Loc, Ctx, Sentinel, NullPos, 0); | |||
8598 | A->setImplicit(true); | |||
8599 | return A; | |||
8600 | } | |||
8601 | ||||
8602 | SentinelAttr(SourceRange R, ASTContext &Ctx | |||
8603 | , int Sentinel | |||
8604 | , int NullPos | |||
8605 | , unsigned SI | |||
8606 | ) | |||
8607 | : InheritableAttr(attr::Sentinel, R, SI, false, false) | |||
8608 | , sentinel(Sentinel) | |||
8609 | , nullPos(NullPos) | |||
8610 | { | |||
8611 | } | |||
8612 | ||||
8613 | SentinelAttr(SourceRange R, ASTContext &Ctx | |||
8614 | , unsigned SI | |||
8615 | ) | |||
8616 | : InheritableAttr(attr::Sentinel, R, SI, false, false) | |||
8617 | , sentinel() | |||
8618 | , nullPos() | |||
8619 | { | |||
8620 | } | |||
8621 | ||||
8622 | SentinelAttr *clone(ASTContext &C) const; | |||
8623 | void printPretty(raw_ostream &OS, | |||
8624 | const PrintingPolicy &Policy) const; | |||
8625 | const char *getSpelling() const; | |||
8626 | int getSentinel() const { | |||
8627 | return sentinel; | |||
8628 | } | |||
8629 | ||||
8630 | static const int DefaultSentinel = 0; | |||
8631 | ||||
8632 | int getNullPos() const { | |||
8633 | return nullPos; | |||
8634 | } | |||
8635 | ||||
8636 | static const int DefaultNullPos = 0; | |||
8637 | ||||
8638 | ||||
8639 | ||||
8640 | static bool classof(const Attr *A) { return A->getKind() == attr::Sentinel; } | |||
8641 | }; | |||
8642 | ||||
8643 | class SetTypestateAttr : public InheritableAttr { | |||
8644 | public: | |||
8645 | enum ConsumedState { | |||
8646 | Unknown, | |||
8647 | Consumed, | |||
8648 | Unconsumed | |||
8649 | }; | |||
8650 | private: | |||
8651 | ConsumedState newState; | |||
8652 | ||||
8653 | public: | |||
8654 | static SetTypestateAttr *CreateImplicit(ASTContext &Ctx, ConsumedState NewState, SourceRange Loc = SourceRange()) { | |||
8655 | auto *A = new (Ctx) SetTypestateAttr(Loc, Ctx, NewState, 0); | |||
8656 | A->setImplicit(true); | |||
8657 | return A; | |||
8658 | } | |||
8659 | ||||
8660 | SetTypestateAttr(SourceRange R, ASTContext &Ctx | |||
8661 | , ConsumedState NewState | |||
8662 | , unsigned SI | |||
8663 | ) | |||
8664 | : InheritableAttr(attr::SetTypestate, R, SI, false, false) | |||
8665 | , newState(NewState) | |||
8666 | { | |||
8667 | } | |||
8668 | ||||
8669 | SetTypestateAttr *clone(ASTContext &C) const; | |||
8670 | void printPretty(raw_ostream &OS, | |||
8671 | const PrintingPolicy &Policy) const; | |||
8672 | const char *getSpelling() const; | |||
8673 | ConsumedState getNewState() const { | |||
8674 | return newState; | |||
8675 | } | |||
8676 | ||||
8677 | static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) { | |||
8678 | Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val) | |||
8679 | .Case("unknown", SetTypestateAttr::Unknown) | |||
8680 | .Case("consumed", SetTypestateAttr::Consumed) | |||
8681 | .Case("unconsumed", SetTypestateAttr::Unconsumed) | |||
8682 | .Default(Optional<ConsumedState>()); | |||
8683 | if (R) { | |||
8684 | Out = *R; | |||
8685 | return true; | |||
8686 | } | |||
8687 | return false; | |||
8688 | } | |||
8689 | ||||
8690 | static const char *ConvertConsumedStateToStr(ConsumedState Val) { | |||
8691 | switch(Val) { | |||
8692 | case SetTypestateAttr::Unknown: return "unknown"; | |||
8693 | case SetTypestateAttr::Consumed: return "consumed"; | |||
8694 | case SetTypestateAttr::Unconsumed: return "unconsumed"; | |||
8695 | } | |||
8696 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 8696); | |||
8697 | } | |||
8698 | ||||
8699 | ||||
8700 | static bool classof(const Attr *A) { return A->getKind() == attr::SetTypestate; } | |||
8701 | }; | |||
8702 | ||||
8703 | class SharedTrylockFunctionAttr : public InheritableAttr { | |||
8704 | Expr * successValue; | |||
8705 | ||||
8706 | unsigned args_Size; | |||
8707 | Expr * *args_; | |||
8708 | ||||
8709 | public: | |||
8710 | static SharedTrylockFunctionAttr *CreateImplicit(ASTContext &Ctx, Expr * SuccessValue, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
8711 | auto *A = new (Ctx) SharedTrylockFunctionAttr(Loc, Ctx, SuccessValue, Args, ArgsSize, 0); | |||
8712 | A->setImplicit(true); | |||
8713 | return A; | |||
8714 | } | |||
8715 | ||||
8716 | SharedTrylockFunctionAttr(SourceRange R, ASTContext &Ctx | |||
8717 | , Expr * SuccessValue | |||
8718 | , Expr * *Args, unsigned ArgsSize | |||
8719 | , unsigned SI | |||
8720 | ) | |||
8721 | : InheritableAttr(attr::SharedTrylockFunction, R, SI, true, true) | |||
8722 | , successValue(SuccessValue) | |||
8723 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
8724 | { | |||
8725 | std::copy(Args, Args + args_Size, args_); | |||
8726 | } | |||
8727 | ||||
8728 | SharedTrylockFunctionAttr(SourceRange R, ASTContext &Ctx | |||
8729 | , Expr * SuccessValue | |||
8730 | , unsigned SI | |||
8731 | ) | |||
8732 | : InheritableAttr(attr::SharedTrylockFunction, R, SI, true, true) | |||
8733 | , successValue(SuccessValue) | |||
8734 | , args_Size(0), args_(nullptr) | |||
8735 | { | |||
8736 | } | |||
8737 | ||||
8738 | SharedTrylockFunctionAttr *clone(ASTContext &C) const; | |||
8739 | void printPretty(raw_ostream &OS, | |||
8740 | const PrintingPolicy &Policy) const; | |||
8741 | const char *getSpelling() const; | |||
8742 | Expr * getSuccessValue() const { | |||
8743 | return successValue; | |||
8744 | } | |||
8745 | ||||
8746 | typedef Expr ** args_iterator; | |||
8747 | args_iterator args_begin() const { return args_; } | |||
8748 | args_iterator args_end() const { return args_ + args_Size; } | |||
8749 | unsigned args_size() const { return args_Size; } | |||
8750 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
8751 | ||||
8752 | ||||
8753 | ||||
8754 | ||||
8755 | static bool classof(const Attr *A) { return A->getKind() == attr::SharedTrylockFunction; } | |||
8756 | }; | |||
8757 | ||||
8758 | class SpeculativeLoadHardeningAttr : public InheritableAttr { | |||
8759 | public: | |||
8760 | static SpeculativeLoadHardeningAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8761 | auto *A = new (Ctx) SpeculativeLoadHardeningAttr(Loc, Ctx, 0); | |||
8762 | A->setImplicit(true); | |||
8763 | return A; | |||
8764 | } | |||
8765 | ||||
8766 | SpeculativeLoadHardeningAttr(SourceRange R, ASTContext &Ctx | |||
8767 | , unsigned SI | |||
8768 | ) | |||
8769 | : InheritableAttr(attr::SpeculativeLoadHardening, R, SI, false, false) | |||
8770 | { | |||
8771 | } | |||
8772 | ||||
8773 | SpeculativeLoadHardeningAttr *clone(ASTContext &C) const; | |||
8774 | void printPretty(raw_ostream &OS, | |||
8775 | const PrintingPolicy &Policy) const; | |||
8776 | const char *getSpelling() const; | |||
8777 | ||||
8778 | ||||
8779 | static bool classof(const Attr *A) { return A->getKind() == attr::SpeculativeLoadHardening; } | |||
8780 | }; | |||
8781 | ||||
8782 | class StdCallAttr : public InheritableAttr { | |||
8783 | public: | |||
8784 | static StdCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8785 | auto *A = new (Ctx) StdCallAttr(Loc, Ctx, 0); | |||
8786 | A->setImplicit(true); | |||
8787 | return A; | |||
8788 | } | |||
8789 | ||||
8790 | StdCallAttr(SourceRange R, ASTContext &Ctx | |||
8791 | , unsigned SI | |||
8792 | ) | |||
8793 | : InheritableAttr(attr::StdCall, R, SI, false, false) | |||
8794 | { | |||
8795 | } | |||
8796 | ||||
8797 | StdCallAttr *clone(ASTContext &C) const; | |||
8798 | void printPretty(raw_ostream &OS, | |||
8799 | const PrintingPolicy &Policy) const; | |||
8800 | const char *getSpelling() const; | |||
8801 | ||||
8802 | ||||
8803 | static bool classof(const Attr *A) { return A->getKind() == attr::StdCall; } | |||
8804 | }; | |||
8805 | ||||
8806 | class SuppressAttr : public StmtAttr { | |||
8807 | unsigned diagnosticIdentifiers_Size; | |||
8808 | StringRef *diagnosticIdentifiers_; | |||
8809 | ||||
8810 | public: | |||
8811 | static SuppressAttr *CreateImplicit(ASTContext &Ctx, StringRef *DiagnosticIdentifiers, unsigned DiagnosticIdentifiersSize, SourceRange Loc = SourceRange()) { | |||
8812 | auto *A = new (Ctx) SuppressAttr(Loc, Ctx, DiagnosticIdentifiers, DiagnosticIdentifiersSize, 0); | |||
8813 | A->setImplicit(true); | |||
8814 | return A; | |||
8815 | } | |||
8816 | ||||
8817 | SuppressAttr(SourceRange R, ASTContext &Ctx | |||
8818 | , StringRef *DiagnosticIdentifiers, unsigned DiagnosticIdentifiersSize | |||
8819 | , unsigned SI | |||
8820 | ) | |||
8821 | : StmtAttr(attr::Suppress, R, SI, false) | |||
8822 | , diagnosticIdentifiers_Size(DiagnosticIdentifiersSize), diagnosticIdentifiers_(new (Ctx, 16) StringRef[diagnosticIdentifiers_Size]) | |||
8823 | { | |||
8824 | for (size_t I = 0, E = diagnosticIdentifiers_Size; I != E; | |||
8825 | ++I) { | |||
8826 | StringRef Ref = DiagnosticIdentifiers[I]; | |||
8827 | if (!Ref.empty()) { | |||
8828 | char *Mem = new (Ctx, 1) char[Ref.size()]; | |||
8829 | std::memcpy(Mem, Ref.data(), Ref.size()); | |||
8830 | diagnosticIdentifiers_[I] = StringRef(Mem, Ref.size()); | |||
8831 | } | |||
8832 | } | |||
8833 | } | |||
8834 | ||||
8835 | SuppressAttr(SourceRange R, ASTContext &Ctx | |||
8836 | , unsigned SI | |||
8837 | ) | |||
8838 | : StmtAttr(attr::Suppress, R, SI, false) | |||
8839 | , diagnosticIdentifiers_Size(0), diagnosticIdentifiers_(nullptr) | |||
8840 | { | |||
8841 | } | |||
8842 | ||||
8843 | SuppressAttr *clone(ASTContext &C) const; | |||
8844 | void printPretty(raw_ostream &OS, | |||
8845 | const PrintingPolicy &Policy) const; | |||
8846 | const char *getSpelling() const; | |||
8847 | typedef StringRef* diagnosticIdentifiers_iterator; | |||
8848 | diagnosticIdentifiers_iterator diagnosticIdentifiers_begin() const { return diagnosticIdentifiers_; } | |||
8849 | diagnosticIdentifiers_iterator diagnosticIdentifiers_end() const { return diagnosticIdentifiers_ + diagnosticIdentifiers_Size; } | |||
8850 | unsigned diagnosticIdentifiers_size() const { return diagnosticIdentifiers_Size; } | |||
8851 | llvm::iterator_range<diagnosticIdentifiers_iterator> diagnosticIdentifiers() const { return llvm::make_range(diagnosticIdentifiers_begin(), diagnosticIdentifiers_end()); } | |||
8852 | ||||
8853 | ||||
8854 | ||||
8855 | ||||
8856 | static bool classof(const Attr *A) { return A->getKind() == attr::Suppress; } | |||
8857 | }; | |||
8858 | ||||
8859 | class SwiftCallAttr : public InheritableAttr { | |||
8860 | public: | |||
8861 | static SwiftCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8862 | auto *A = new (Ctx) SwiftCallAttr(Loc, Ctx, 0); | |||
8863 | A->setImplicit(true); | |||
8864 | return A; | |||
8865 | } | |||
8866 | ||||
8867 | SwiftCallAttr(SourceRange R, ASTContext &Ctx | |||
8868 | , unsigned SI | |||
8869 | ) | |||
8870 | : InheritableAttr(attr::SwiftCall, R, SI, false, false) | |||
8871 | { | |||
8872 | } | |||
8873 | ||||
8874 | SwiftCallAttr *clone(ASTContext &C) const; | |||
8875 | void printPretty(raw_ostream &OS, | |||
8876 | const PrintingPolicy &Policy) const; | |||
8877 | const char *getSpelling() const; | |||
8878 | ||||
8879 | ||||
8880 | static bool classof(const Attr *A) { return A->getKind() == attr::SwiftCall; } | |||
8881 | }; | |||
8882 | ||||
8883 | class SwiftContextAttr : public ParameterABIAttr { | |||
8884 | public: | |||
8885 | static SwiftContextAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8886 | auto *A = new (Ctx) SwiftContextAttr(Loc, Ctx, 0); | |||
8887 | A->setImplicit(true); | |||
8888 | return A; | |||
8889 | } | |||
8890 | ||||
8891 | SwiftContextAttr(SourceRange R, ASTContext &Ctx | |||
8892 | , unsigned SI | |||
8893 | ) | |||
8894 | : ParameterABIAttr(attr::SwiftContext, R, SI, false, false) | |||
8895 | { | |||
8896 | } | |||
8897 | ||||
8898 | SwiftContextAttr *clone(ASTContext &C) const; | |||
8899 | void printPretty(raw_ostream &OS, | |||
8900 | const PrintingPolicy &Policy) const; | |||
8901 | const char *getSpelling() const; | |||
8902 | ||||
8903 | ||||
8904 | static bool classof(const Attr *A) { return A->getKind() == attr::SwiftContext; } | |||
8905 | }; | |||
8906 | ||||
8907 | class SwiftErrorResultAttr : public ParameterABIAttr { | |||
8908 | public: | |||
8909 | static SwiftErrorResultAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8910 | auto *A = new (Ctx) SwiftErrorResultAttr(Loc, Ctx, 0); | |||
8911 | A->setImplicit(true); | |||
8912 | return A; | |||
8913 | } | |||
8914 | ||||
8915 | SwiftErrorResultAttr(SourceRange R, ASTContext &Ctx | |||
8916 | , unsigned SI | |||
8917 | ) | |||
8918 | : ParameterABIAttr(attr::SwiftErrorResult, R, SI, false, false) | |||
8919 | { | |||
8920 | } | |||
8921 | ||||
8922 | SwiftErrorResultAttr *clone(ASTContext &C) const; | |||
8923 | void printPretty(raw_ostream &OS, | |||
8924 | const PrintingPolicy &Policy) const; | |||
8925 | const char *getSpelling() const; | |||
8926 | ||||
8927 | ||||
8928 | static bool classof(const Attr *A) { return A->getKind() == attr::SwiftErrorResult; } | |||
8929 | }; | |||
8930 | ||||
8931 | class SwiftIndirectResultAttr : public ParameterABIAttr { | |||
8932 | public: | |||
8933 | static SwiftIndirectResultAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8934 | auto *A = new (Ctx) SwiftIndirectResultAttr(Loc, Ctx, 0); | |||
8935 | A->setImplicit(true); | |||
8936 | return A; | |||
8937 | } | |||
8938 | ||||
8939 | SwiftIndirectResultAttr(SourceRange R, ASTContext &Ctx | |||
8940 | , unsigned SI | |||
8941 | ) | |||
8942 | : ParameterABIAttr(attr::SwiftIndirectResult, R, SI, false, false) | |||
8943 | { | |||
8944 | } | |||
8945 | ||||
8946 | SwiftIndirectResultAttr *clone(ASTContext &C) const; | |||
8947 | void printPretty(raw_ostream &OS, | |||
8948 | const PrintingPolicy &Policy) const; | |||
8949 | const char *getSpelling() const; | |||
8950 | ||||
8951 | ||||
8952 | static bool classof(const Attr *A) { return A->getKind() == attr::SwiftIndirectResult; } | |||
8953 | }; | |||
8954 | ||||
8955 | class SysVABIAttr : public InheritableAttr { | |||
8956 | public: | |||
8957 | static SysVABIAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8958 | auto *A = new (Ctx) SysVABIAttr(Loc, Ctx, 0); | |||
8959 | A->setImplicit(true); | |||
8960 | return A; | |||
8961 | } | |||
8962 | ||||
8963 | SysVABIAttr(SourceRange R, ASTContext &Ctx | |||
8964 | , unsigned SI | |||
8965 | ) | |||
8966 | : InheritableAttr(attr::SysVABI, R, SI, false, false) | |||
8967 | { | |||
8968 | } | |||
8969 | ||||
8970 | SysVABIAttr *clone(ASTContext &C) const; | |||
8971 | void printPretty(raw_ostream &OS, | |||
8972 | const PrintingPolicy &Policy) const; | |||
8973 | const char *getSpelling() const; | |||
8974 | ||||
8975 | ||||
8976 | static bool classof(const Attr *A) { return A->getKind() == attr::SysVABI; } | |||
8977 | }; | |||
8978 | ||||
8979 | class TLSModelAttr : public InheritableAttr { | |||
8980 | unsigned modelLength; | |||
8981 | char *model; | |||
8982 | ||||
8983 | public: | |||
8984 | static TLSModelAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Model, SourceRange Loc = SourceRange()) { | |||
8985 | auto *A = new (Ctx) TLSModelAttr(Loc, Ctx, Model, 0); | |||
8986 | A->setImplicit(true); | |||
8987 | return A; | |||
8988 | } | |||
8989 | ||||
8990 | TLSModelAttr(SourceRange R, ASTContext &Ctx | |||
8991 | , llvm::StringRef Model | |||
8992 | , unsigned SI | |||
8993 | ) | |||
8994 | : InheritableAttr(attr::TLSModel, R, SI, false, false) | |||
8995 | , modelLength(Model.size()),model(new (Ctx, 1) char[modelLength]) | |||
8996 | { | |||
8997 | if (!Model.empty()) | |||
8998 | std::memcpy(model, Model.data(), modelLength); | |||
8999 | } | |||
9000 | ||||
9001 | TLSModelAttr *clone(ASTContext &C) const; | |||
9002 | void printPretty(raw_ostream &OS, | |||
9003 | const PrintingPolicy &Policy) const; | |||
9004 | const char *getSpelling() const; | |||
9005 | llvm::StringRef getModel() const { | |||
9006 | return llvm::StringRef(model, modelLength); | |||
9007 | } | |||
9008 | unsigned getModelLength() const { | |||
9009 | return modelLength; | |||
9010 | } | |||
9011 | void setModel(ASTContext &C, llvm::StringRef S) { | |||
9012 | modelLength = S.size(); | |||
9013 | this->model = new (C, 1) char [modelLength]; | |||
9014 | if (!S.empty()) | |||
9015 | std::memcpy(this->model, S.data(), modelLength); | |||
9016 | } | |||
9017 | ||||
9018 | ||||
9019 | ||||
9020 | static bool classof(const Attr *A) { return A->getKind() == attr::TLSModel; } | |||
9021 | }; | |||
9022 | ||||
9023 | class TargetAttr : public InheritableAttr { | |||
9024 | unsigned featuresStrLength; | |||
9025 | char *featuresStr; | |||
9026 | ||||
9027 | public: | |||
9028 | static TargetAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef FeaturesStr, SourceRange Loc = SourceRange()) { | |||
9029 | auto *A = new (Ctx) TargetAttr(Loc, Ctx, FeaturesStr, 0); | |||
9030 | A->setImplicit(true); | |||
9031 | return A; | |||
9032 | } | |||
9033 | ||||
9034 | TargetAttr(SourceRange R, ASTContext &Ctx | |||
9035 | , llvm::StringRef FeaturesStr | |||
9036 | , unsigned SI | |||
9037 | ) | |||
9038 | : InheritableAttr(attr::Target, R, SI, false, false) | |||
9039 | , featuresStrLength(FeaturesStr.size()),featuresStr(new (Ctx, 1) char[featuresStrLength]) | |||
9040 | { | |||
9041 | if (!FeaturesStr.empty()) | |||
9042 | std::memcpy(featuresStr, FeaturesStr.data(), featuresStrLength); | |||
9043 | } | |||
9044 | ||||
9045 | TargetAttr *clone(ASTContext &C) const; | |||
9046 | void printPretty(raw_ostream &OS, | |||
9047 | const PrintingPolicy &Policy) const; | |||
9048 | const char *getSpelling() const; | |||
9049 | llvm::StringRef getFeaturesStr() const { | |||
9050 | return llvm::StringRef(featuresStr, featuresStrLength); | |||
9051 | } | |||
9052 | unsigned getFeaturesStrLength() const { | |||
9053 | return featuresStrLength; | |||
9054 | } | |||
9055 | void setFeaturesStr(ASTContext &C, llvm::StringRef S) { | |||
9056 | featuresStrLength = S.size(); | |||
9057 | this->featuresStr = new (C, 1) char [featuresStrLength]; | |||
9058 | if (!S.empty()) | |||
9059 | std::memcpy(this->featuresStr, S.data(), featuresStrLength); | |||
9060 | } | |||
9061 | ||||
9062 | ||||
9063 | struct ParsedTargetAttr { | |||
9064 | std::vector<std::string> Features; | |||
9065 | StringRef Architecture; | |||
9066 | bool DuplicateArchitecture = false; | |||
9067 | bool operator ==(const ParsedTargetAttr &Other) const { | |||
9068 | return DuplicateArchitecture == Other.DuplicateArchitecture && | |||
9069 | Architecture == Other.Architecture && Features == Other.Features; | |||
9070 | } | |||
9071 | }; | |||
9072 | ParsedTargetAttr parse() const { | |||
9073 | return parse(getFeaturesStr()); | |||
9074 | } | |||
9075 | ||||
9076 | StringRef getArchitecture() const { | |||
9077 | StringRef Features = getFeaturesStr(); | |||
9078 | if (Features == "default") return {}; | |||
9079 | ||||
9080 | SmallVector<StringRef, 1> AttrFeatures; | |||
9081 | Features.split(AttrFeatures, ","); | |||
9082 | ||||
9083 | for (auto &Feature : AttrFeatures) { | |||
9084 | Feature = Feature.trim(); | |||
9085 | if (Feature.startswith("arch=")) | |||
9086 | return Feature.drop_front(sizeof("arch=") - 1); | |||
9087 | } | |||
9088 | return ""; | |||
9089 | } | |||
9090 | ||||
9091 | // Gets the list of features as simple string-refs with no +/- or 'no-'. | |||
9092 | // Only adds the items to 'Out' that are additions. | |||
9093 | void getAddedFeatures(llvm::SmallVectorImpl<StringRef> &Out) const { | |||
9094 | StringRef Features = getFeaturesStr(); | |||
9095 | if (Features == "default") return; | |||
9096 | ||||
9097 | SmallVector<StringRef, 1> AttrFeatures; | |||
9098 | Features.split(AttrFeatures, ","); | |||
9099 | ||||
9100 | for (auto &Feature : AttrFeatures) { | |||
9101 | Feature = Feature.trim(); | |||
9102 | ||||
9103 | if (!Feature.startswith("no-") && !Feature.startswith("arch=") && | |||
9104 | !Feature.startswith("fpmath=") && !Feature.startswith("tune=")) | |||
9105 | Out.push_back(Feature); | |||
9106 | } | |||
9107 | } | |||
9108 | ||||
9109 | template<class Compare> | |||
9110 | ParsedTargetAttr parse(Compare cmp) const { | |||
9111 | ParsedTargetAttr Attrs = parse(); | |||
9112 | llvm::sort(std::begin(Attrs.Features), std::end(Attrs.Features), cmp); | |||
9113 | return Attrs; | |||
9114 | } | |||
9115 | ||||
9116 | bool isDefaultVersion() const { return getFeaturesStr() == "default"; } | |||
9117 | ||||
9118 | static ParsedTargetAttr parse(StringRef Features) { | |||
9119 | ParsedTargetAttr Ret; | |||
9120 | if (Features == "default") return Ret; | |||
9121 | SmallVector<StringRef, 1> AttrFeatures; | |||
9122 | Features.split(AttrFeatures, ","); | |||
9123 | ||||
9124 | // Grab the various features and prepend a "+" to turn on the feature to | |||
9125 | // the backend and add them to our existing set of features. | |||
9126 | for (auto &Feature : AttrFeatures) { | |||
9127 | // Go ahead and trim whitespace rather than either erroring or | |||
9128 | // accepting it weirdly. | |||
9129 | Feature = Feature.trim(); | |||
9130 | ||||
9131 | // We don't support cpu tuning this way currently. | |||
9132 | // TODO: Support the fpmath option. It will require checking | |||
9133 | // overall feature validity for the function with the rest of the | |||
9134 | // attributes on the function. | |||
9135 | if (Feature.startswith("fpmath=") || Feature.startswith("tune=")) | |||
9136 | continue; | |||
9137 | ||||
9138 | // While we're here iterating check for a different target cpu. | |||
9139 | if (Feature.startswith("arch=")) { | |||
9140 | if (!Ret.Architecture.empty()) | |||
9141 | Ret.DuplicateArchitecture = true; | |||
9142 | else | |||
9143 | Ret.Architecture = Feature.split("=").second.trim(); | |||
9144 | } else if (Feature.startswith("no-")) | |||
9145 | Ret.Features.push_back("-" + Feature.split("-").second.str()); | |||
9146 | else | |||
9147 | Ret.Features.push_back("+" + Feature.str()); | |||
9148 | } | |||
9149 | return Ret; | |||
9150 | } | |||
9151 | ||||
9152 | ||||
9153 | static bool classof(const Attr *A) { return A->getKind() == attr::Target; } | |||
9154 | }; | |||
9155 | ||||
9156 | class TestTypestateAttr : public InheritableAttr { | |||
9157 | public: | |||
9158 | enum ConsumedState { | |||
9159 | Consumed, | |||
9160 | Unconsumed | |||
9161 | }; | |||
9162 | private: | |||
9163 | ConsumedState testState; | |||
9164 | ||||
9165 | public: | |||
9166 | static TestTypestateAttr *CreateImplicit(ASTContext &Ctx, ConsumedState TestState, SourceRange Loc = SourceRange()) { | |||
9167 | auto *A = new (Ctx) TestTypestateAttr(Loc, Ctx, TestState, 0); | |||
9168 | A->setImplicit(true); | |||
9169 | return A; | |||
9170 | } | |||
9171 | ||||
9172 | TestTypestateAttr(SourceRange R, ASTContext &Ctx | |||
9173 | , ConsumedState TestState | |||
9174 | , unsigned SI | |||
9175 | ) | |||
9176 | : InheritableAttr(attr::TestTypestate, R, SI, false, false) | |||
9177 | , testState(TestState) | |||
9178 | { | |||
9179 | } | |||
9180 | ||||
9181 | TestTypestateAttr *clone(ASTContext &C) const; | |||
9182 | void printPretty(raw_ostream &OS, | |||
9183 | const PrintingPolicy &Policy) const; | |||
9184 | const char *getSpelling() const; | |||
9185 | ConsumedState getTestState() const { | |||
9186 | return testState; | |||
9187 | } | |||
9188 | ||||
9189 | static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) { | |||
9190 | Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val) | |||
9191 | .Case("consumed", TestTypestateAttr::Consumed) | |||
9192 | .Case("unconsumed", TestTypestateAttr::Unconsumed) | |||
9193 | .Default(Optional<ConsumedState>()); | |||
9194 | if (R) { | |||
9195 | Out = *R; | |||
9196 | return true; | |||
9197 | } | |||
9198 | return false; | |||
9199 | } | |||
9200 | ||||
9201 | static const char *ConvertConsumedStateToStr(ConsumedState Val) { | |||
9202 | switch(Val) { | |||
9203 | case TestTypestateAttr::Consumed: return "consumed"; | |||
9204 | case TestTypestateAttr::Unconsumed: return "unconsumed"; | |||
9205 | } | |||
9206 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 9206); | |||
9207 | } | |||
9208 | ||||
9209 | ||||
9210 | static bool classof(const Attr *A) { return A->getKind() == attr::TestTypestate; } | |||
9211 | }; | |||
9212 | ||||
9213 | class ThisCallAttr : public InheritableAttr { | |||
9214 | public: | |||
9215 | static ThisCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9216 | auto *A = new (Ctx) ThisCallAttr(Loc, Ctx, 0); | |||
9217 | A->setImplicit(true); | |||
9218 | return A; | |||
9219 | } | |||
9220 | ||||
9221 | ThisCallAttr(SourceRange R, ASTContext &Ctx | |||
9222 | , unsigned SI | |||
9223 | ) | |||
9224 | : InheritableAttr(attr::ThisCall, R, SI, false, false) | |||
9225 | { | |||
9226 | } | |||
9227 | ||||
9228 | ThisCallAttr *clone(ASTContext &C) const; | |||
9229 | void printPretty(raw_ostream &OS, | |||
9230 | const PrintingPolicy &Policy) const; | |||
9231 | const char *getSpelling() const; | |||
9232 | ||||
9233 | ||||
9234 | static bool classof(const Attr *A) { return A->getKind() == attr::ThisCall; } | |||
9235 | }; | |||
9236 | ||||
9237 | class ThreadAttr : public Attr { | |||
9238 | public: | |||
9239 | static ThreadAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9240 | auto *A = new (Ctx) ThreadAttr(Loc, Ctx, 0); | |||
9241 | A->setImplicit(true); | |||
9242 | return A; | |||
9243 | } | |||
9244 | ||||
9245 | ThreadAttr(SourceRange R, ASTContext &Ctx | |||
9246 | , unsigned SI | |||
9247 | ) | |||
9248 | : Attr(attr::Thread, R, SI, false) | |||
9249 | { | |||
9250 | } | |||
9251 | ||||
9252 | ThreadAttr *clone(ASTContext &C) const; | |||
9253 | void printPretty(raw_ostream &OS, | |||
9254 | const PrintingPolicy &Policy) const; | |||
9255 | const char *getSpelling() const; | |||
9256 | ||||
9257 | ||||
9258 | static bool classof(const Attr *A) { return A->getKind() == attr::Thread; } | |||
9259 | }; | |||
9260 | ||||
9261 | class TransparentUnionAttr : public InheritableAttr { | |||
9262 | public: | |||
9263 | static TransparentUnionAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9264 | auto *A = new (Ctx) TransparentUnionAttr(Loc, Ctx, 0); | |||
9265 | A->setImplicit(true); | |||
9266 | return A; | |||
9267 | } | |||
9268 | ||||
9269 | TransparentUnionAttr(SourceRange R, ASTContext &Ctx | |||
9270 | , unsigned SI | |||
9271 | ) | |||
9272 | : InheritableAttr(attr::TransparentUnion, R, SI, false, false) | |||
9273 | { | |||
9274 | } | |||
9275 | ||||
9276 | TransparentUnionAttr *clone(ASTContext &C) const; | |||
9277 | void printPretty(raw_ostream &OS, | |||
9278 | const PrintingPolicy &Policy) const; | |||
9279 | const char *getSpelling() const; | |||
9280 | ||||
9281 | ||||
9282 | static bool classof(const Attr *A) { return A->getKind() == attr::TransparentUnion; } | |||
9283 | }; | |||
9284 | ||||
9285 | class TrivialABIAttr : public InheritableAttr { | |||
9286 | public: | |||
9287 | static TrivialABIAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9288 | auto *A = new (Ctx) TrivialABIAttr(Loc, Ctx, 0); | |||
9289 | A->setImplicit(true); | |||
9290 | return A; | |||
9291 | } | |||
9292 | ||||
9293 | TrivialABIAttr(SourceRange R, ASTContext &Ctx | |||
9294 | , unsigned SI | |||
9295 | ) | |||
9296 | : InheritableAttr(attr::TrivialABI, R, SI, false, false) | |||
9297 | { | |||
9298 | } | |||
9299 | ||||
9300 | TrivialABIAttr *clone(ASTContext &C) const; | |||
9301 | void printPretty(raw_ostream &OS, | |||
9302 | const PrintingPolicy &Policy) const; | |||
9303 | const char *getSpelling() const; | |||
9304 | ||||
9305 | ||||
9306 | static bool classof(const Attr *A) { return A->getKind() == attr::TrivialABI; } | |||
9307 | }; | |||
9308 | ||||
9309 | class TryAcquireCapabilityAttr : public InheritableAttr { | |||
9310 | Expr * successValue; | |||
9311 | ||||
9312 | unsigned args_Size; | |||
9313 | Expr * *args_; | |||
9314 | ||||
9315 | public: | |||
9316 | enum Spelling { | |||
9317 | GNU_try_acquire_capability = 0, | |||
9318 | CXX11_clang_try_acquire_capability = 1, | |||
9319 | GNU_try_acquire_shared_capability = 2, | |||
9320 | CXX11_clang_try_acquire_shared_capability = 3 | |||
9321 | }; | |||
9322 | ||||
9323 | static TryAcquireCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * SuccessValue, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
9324 | auto *A = new (Ctx) TryAcquireCapabilityAttr(Loc, Ctx, SuccessValue, Args, ArgsSize, S); | |||
9325 | A->setImplicit(true); | |||
9326 | return A; | |||
9327 | } | |||
9328 | ||||
9329 | TryAcquireCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
9330 | , Expr * SuccessValue | |||
9331 | , Expr * *Args, unsigned ArgsSize | |||
9332 | , unsigned SI | |||
9333 | ) | |||
9334 | : InheritableAttr(attr::TryAcquireCapability, R, SI, true, true) | |||
9335 | , successValue(SuccessValue) | |||
9336 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
9337 | { | |||
9338 | std::copy(Args, Args + args_Size, args_); | |||
9339 | } | |||
9340 | ||||
9341 | TryAcquireCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
9342 | , Expr * SuccessValue | |||
9343 | , unsigned SI | |||
9344 | ) | |||
9345 | : InheritableAttr(attr::TryAcquireCapability, R, SI, true, true) | |||
9346 | , successValue(SuccessValue) | |||
9347 | , args_Size(0), args_(nullptr) | |||
9348 | { | |||
9349 | } | |||
9350 | ||||
9351 | TryAcquireCapabilityAttr *clone(ASTContext &C) const; | |||
9352 | void printPretty(raw_ostream &OS, | |||
9353 | const PrintingPolicy &Policy) const; | |||
9354 | const char *getSpelling() const; | |||
9355 | Spelling getSemanticSpelling() const { | |||
9356 | switch (SpellingListIndex) { | |||
9357 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 9357); | |||
9358 | case 0: return GNU_try_acquire_capability; | |||
9359 | case 1: return CXX11_clang_try_acquire_capability; | |||
9360 | case 2: return GNU_try_acquire_shared_capability; | |||
9361 | case 3: return CXX11_clang_try_acquire_shared_capability; | |||
9362 | } | |||
9363 | } | |||
9364 | bool isShared() const { return SpellingListIndex == 2 || | |||
9365 | SpellingListIndex == 3; } | |||
9366 | Expr * getSuccessValue() const { | |||
9367 | return successValue; | |||
9368 | } | |||
9369 | ||||
9370 | typedef Expr ** args_iterator; | |||
9371 | args_iterator args_begin() const { return args_; } | |||
9372 | args_iterator args_end() const { return args_ + args_Size; } | |||
9373 | unsigned args_size() const { return args_Size; } | |||
9374 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
9375 | ||||
9376 | ||||
9377 | ||||
9378 | ||||
9379 | static bool classof(const Attr *A) { return A->getKind() == attr::TryAcquireCapability; } | |||
9380 | }; | |||
9381 | ||||
9382 | class TypeNonNullAttr : public TypeAttr { | |||
9383 | public: | |||
9384 | static TypeNonNullAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9385 | auto *A = new (Ctx) TypeNonNullAttr(Loc, Ctx, 0); | |||
9386 | A->setImplicit(true); | |||
9387 | return A; | |||
9388 | } | |||
9389 | ||||
9390 | TypeNonNullAttr(SourceRange R, ASTContext &Ctx | |||
9391 | , unsigned SI | |||
9392 | ) | |||
9393 | : TypeAttr(attr::TypeNonNull, R, SI, false) | |||
9394 | { | |||
9395 | } | |||
9396 | ||||
9397 | TypeNonNullAttr *clone(ASTContext &C) const; | |||
9398 | void printPretty(raw_ostream &OS, | |||
9399 | const PrintingPolicy &Policy) const; | |||
9400 | const char *getSpelling() const; | |||
9401 | ||||
9402 | ||||
9403 | static bool classof(const Attr *A) { return A->getKind() == attr::TypeNonNull; } | |||
9404 | }; | |||
9405 | ||||
9406 | class TypeNullUnspecifiedAttr : public TypeAttr { | |||
9407 | public: | |||
9408 | static TypeNullUnspecifiedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9409 | auto *A = new (Ctx) TypeNullUnspecifiedAttr(Loc, Ctx, 0); | |||
9410 | A->setImplicit(true); | |||
9411 | return A; | |||
9412 | } | |||
9413 | ||||
9414 | TypeNullUnspecifiedAttr(SourceRange R, ASTContext &Ctx | |||
9415 | , unsigned SI | |||
9416 | ) | |||
9417 | : TypeAttr(attr::TypeNullUnspecified, R, SI, false) | |||
9418 | { | |||
9419 | } | |||
9420 | ||||
9421 | TypeNullUnspecifiedAttr *clone(ASTContext &C) const; | |||
9422 | void printPretty(raw_ostream &OS, | |||
9423 | const PrintingPolicy &Policy) const; | |||
9424 | const char *getSpelling() const; | |||
9425 | ||||
9426 | ||||
9427 | static bool classof(const Attr *A) { return A->getKind() == attr::TypeNullUnspecified; } | |||
9428 | }; | |||
9429 | ||||
9430 | class TypeNullableAttr : public TypeAttr { | |||
9431 | public: | |||
9432 | static TypeNullableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9433 | auto *A = new (Ctx) TypeNullableAttr(Loc, Ctx, 0); | |||
9434 | A->setImplicit(true); | |||
9435 | return A; | |||
9436 | } | |||
9437 | ||||
9438 | TypeNullableAttr(SourceRange R, ASTContext &Ctx | |||
9439 | , unsigned SI | |||
9440 | ) | |||
9441 | : TypeAttr(attr::TypeNullable, R, SI, false) | |||
9442 | { | |||
9443 | } | |||
9444 | ||||
9445 | TypeNullableAttr *clone(ASTContext &C) const; | |||
9446 | void printPretty(raw_ostream &OS, | |||
9447 | const PrintingPolicy &Policy) const; | |||
9448 | const char *getSpelling() const; | |||
9449 | ||||
9450 | ||||
9451 | static bool classof(const Attr *A) { return A->getKind() == attr::TypeNullable; } | |||
9452 | }; | |||
9453 | ||||
9454 | class TypeTagForDatatypeAttr : public InheritableAttr { | |||
9455 | IdentifierInfo * argumentKind; | |||
9456 | ||||
9457 | TypeSourceInfo * matchingCType; | |||
9458 | ||||
9459 | bool layoutCompatible; | |||
9460 | ||||
9461 | bool mustBeNull; | |||
9462 | ||||
9463 | public: | |||
9464 | static TypeTagForDatatypeAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * ArgumentKind, TypeSourceInfo * MatchingCType, bool LayoutCompatible, bool MustBeNull, SourceRange Loc = SourceRange()) { | |||
9465 | auto *A = new (Ctx) TypeTagForDatatypeAttr(Loc, Ctx, ArgumentKind, MatchingCType, LayoutCompatible, MustBeNull, 0); | |||
9466 | A->setImplicit(true); | |||
9467 | return A; | |||
9468 | } | |||
9469 | ||||
9470 | TypeTagForDatatypeAttr(SourceRange R, ASTContext &Ctx | |||
9471 | , IdentifierInfo * ArgumentKind | |||
9472 | , TypeSourceInfo * MatchingCType | |||
9473 | , bool LayoutCompatible | |||
9474 | , bool MustBeNull | |||
9475 | , unsigned SI | |||
9476 | ) | |||
9477 | : InheritableAttr(attr::TypeTagForDatatype, R, SI, false, false) | |||
9478 | , argumentKind(ArgumentKind) | |||
9479 | , matchingCType(MatchingCType) | |||
9480 | , layoutCompatible(LayoutCompatible) | |||
9481 | , mustBeNull(MustBeNull) | |||
9482 | { | |||
9483 | } | |||
9484 | ||||
9485 | TypeTagForDatatypeAttr *clone(ASTContext &C) const; | |||
9486 | void printPretty(raw_ostream &OS, | |||
9487 | const PrintingPolicy &Policy) const; | |||
9488 | const char *getSpelling() const; | |||
9489 | IdentifierInfo * getArgumentKind() const { | |||
9490 | return argumentKind; | |||
9491 | } | |||
9492 | ||||
9493 | QualType getMatchingCType() const { | |||
9494 | return matchingCType->getType(); | |||
9495 | } TypeSourceInfo * getMatchingCTypeLoc() const { | |||
9496 | return matchingCType; | |||
9497 | } | |||
9498 | ||||
9499 | bool getLayoutCompatible() const { | |||
9500 | return layoutCompatible; | |||
9501 | } | |||
9502 | ||||
9503 | bool getMustBeNull() const { | |||
9504 | return mustBeNull; | |||
9505 | } | |||
9506 | ||||
9507 | ||||
9508 | ||||
9509 | static bool classof(const Attr *A) { return A->getKind() == attr::TypeTagForDatatype; } | |||
9510 | }; | |||
9511 | ||||
9512 | class TypeVisibilityAttr : public InheritableAttr { | |||
9513 | public: | |||
9514 | enum VisibilityType { | |||
9515 | Default, | |||
9516 | Hidden, | |||
9517 | Protected | |||
9518 | }; | |||
9519 | private: | |||
9520 | VisibilityType visibility; | |||
9521 | ||||
9522 | public: | |||
9523 | static TypeVisibilityAttr *CreateImplicit(ASTContext &Ctx, VisibilityType Visibility, SourceRange Loc = SourceRange()) { | |||
9524 | auto *A = new (Ctx) TypeVisibilityAttr(Loc, Ctx, Visibility, 0); | |||
9525 | A->setImplicit(true); | |||
9526 | return A; | |||
9527 | } | |||
9528 | ||||
9529 | TypeVisibilityAttr(SourceRange R, ASTContext &Ctx | |||
9530 | , VisibilityType Visibility | |||
9531 | , unsigned SI | |||
9532 | ) | |||
9533 | : InheritableAttr(attr::TypeVisibility, R, SI, false, false) | |||
9534 | , visibility(Visibility) | |||
9535 | { | |||
9536 | } | |||
9537 | ||||
9538 | TypeVisibilityAttr *clone(ASTContext &C) const; | |||
9539 | void printPretty(raw_ostream &OS, | |||
9540 | const PrintingPolicy &Policy) const; | |||
9541 | const char *getSpelling() const; | |||
9542 | VisibilityType getVisibility() const { | |||
9543 | return visibility; | |||
9544 | } | |||
9545 | ||||
9546 | static bool ConvertStrToVisibilityType(StringRef Val, VisibilityType &Out) { | |||
9547 | Optional<VisibilityType> R = llvm::StringSwitch<Optional<VisibilityType>>(Val) | |||
9548 | .Case("default", TypeVisibilityAttr::Default) | |||
9549 | .Case("hidden", TypeVisibilityAttr::Hidden) | |||
9550 | .Case("internal", TypeVisibilityAttr::Hidden) | |||
9551 | .Case("protected", TypeVisibilityAttr::Protected) | |||
9552 | .Default(Optional<VisibilityType>()); | |||
9553 | if (R) { | |||
9554 | Out = *R; | |||
9555 | return true; | |||
9556 | } | |||
9557 | return false; | |||
9558 | } | |||
9559 | ||||
9560 | static const char *ConvertVisibilityTypeToStr(VisibilityType Val) { | |||
9561 | switch(Val) { | |||
9562 | case TypeVisibilityAttr::Default: return "default"; | |||
9563 | case TypeVisibilityAttr::Hidden: return "hidden"; | |||
9564 | case TypeVisibilityAttr::Protected: return "protected"; | |||
9565 | } | |||
9566 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 9566); | |||
9567 | } | |||
9568 | ||||
9569 | ||||
9570 | static bool classof(const Attr *A) { return A->getKind() == attr::TypeVisibility; } | |||
9571 | }; | |||
9572 | ||||
9573 | class UPtrAttr : public TypeAttr { | |||
9574 | public: | |||
9575 | static UPtrAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9576 | auto *A = new (Ctx) UPtrAttr(Loc, Ctx, 0); | |||
9577 | A->setImplicit(true); | |||
9578 | return A; | |||
9579 | } | |||
9580 | ||||
9581 | UPtrAttr(SourceRange R, ASTContext &Ctx | |||
9582 | , unsigned SI | |||
9583 | ) | |||
9584 | : TypeAttr(attr::UPtr, R, SI, false) | |||
9585 | { | |||
9586 | } | |||
9587 | ||||
9588 | UPtrAttr *clone(ASTContext &C) const; | |||
9589 | void printPretty(raw_ostream &OS, | |||
9590 | const PrintingPolicy &Policy) const; | |||
9591 | const char *getSpelling() const; | |||
9592 | ||||
9593 | ||||
9594 | static bool classof(const Attr *A) { return A->getKind() == attr::UPtr; } | |||
9595 | }; | |||
9596 | ||||
9597 | class UnavailableAttr : public InheritableAttr { | |||
9598 | unsigned messageLength; | |||
9599 | char *message; | |||
9600 | ||||
9601 | public: | |||
9602 | enum ImplicitReason { | |||
9603 | IR_None, | |||
9604 | IR_ARCForbiddenType, | |||
9605 | IR_ForbiddenWeak, | |||
9606 | IR_ARCForbiddenConversion, | |||
9607 | IR_ARCInitReturnsUnrelated, | |||
9608 | IR_ARCFieldWithOwnership | |||
9609 | }; | |||
9610 | private: | |||
9611 | ImplicitReason implicitReason; | |||
9612 | ||||
9613 | public: | |||
9614 | static UnavailableAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Message, ImplicitReason ImplicitReason, SourceRange Loc = SourceRange()) { | |||
9615 | auto *A = new (Ctx) UnavailableAttr(Loc, Ctx, Message, ImplicitReason, 0); | |||
9616 | A->setImplicit(true); | |||
| ||||
9617 | return A; | |||
9618 | } | |||
9619 | ||||
9620 | static UnavailableAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Message, SourceRange Loc = SourceRange()) { | |||
9621 | auto *A = new (Ctx) UnavailableAttr(Loc, Ctx, Message, 0); | |||
9622 | A->setImplicit(true); | |||
9623 | return A; | |||
9624 | } | |||
9625 | ||||
9626 | UnavailableAttr(SourceRange R, ASTContext &Ctx | |||
9627 | , llvm::StringRef Message | |||
9628 | , ImplicitReason ImplicitReason | |||
9629 | , unsigned SI | |||
9630 | ) | |||
9631 | : InheritableAttr(attr::Unavailable, R, SI, false, false) | |||
9632 | , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength]) | |||
9633 | , implicitReason(ImplicitReason) | |||
9634 | { | |||
9635 | if (!Message.empty()) | |||
9636 | std::memcpy(message, Message.data(), messageLength); | |||
9637 | } | |||
9638 | ||||
9639 | UnavailableAttr(SourceRange R, ASTContext &Ctx | |||
9640 | , llvm::StringRef Message | |||
9641 | , unsigned SI | |||
9642 | ) | |||
9643 | : InheritableAttr(attr::Unavailable, R, SI, false, false) | |||
9644 | , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength]) | |||
9645 | , implicitReason(ImplicitReason(0)) | |||
9646 | { | |||
9647 | if (!Message.empty()) | |||
9648 | std::memcpy(message, Message.data(), messageLength); | |||
9649 | } | |||
9650 | ||||
9651 | UnavailableAttr(SourceRange R, ASTContext &Ctx | |||
9652 | , unsigned SI | |||
9653 | ) | |||
9654 | : InheritableAttr(attr::Unavailable, R, SI, false, false) | |||
9655 | , messageLength(0),message(nullptr) | |||
9656 | , implicitReason(ImplicitReason(0)) | |||
9657 | { | |||
9658 | } | |||
9659 | ||||
9660 | UnavailableAttr *clone(ASTContext &C) const; | |||
9661 | void printPretty(raw_ostream &OS, | |||
9662 | const PrintingPolicy &Policy) const; | |||
9663 | const char *getSpelling() const; | |||
9664 | llvm::StringRef getMessage() const { | |||
9665 | return llvm::StringRef(message, messageLength); | |||
9666 | } | |||
9667 | unsigned getMessageLength() const { | |||
9668 | return messageLength; | |||
9669 | } | |||
9670 | void setMessage(ASTContext &C, llvm::StringRef S) { | |||
9671 | messageLength = S.size(); | |||
9672 | this->message = new (C, 1) char [messageLength]; | |||
9673 | if (!S.empty()) | |||
9674 | std::memcpy(this->message, S.data(), messageLength); | |||
9675 | } | |||
9676 | ||||
9677 | ImplicitReason getImplicitReason() const { | |||
9678 | return implicitReason; | |||
9679 | } | |||
9680 | ||||
9681 | ||||
9682 | ||||
9683 | static bool classof(const Attr *A) { return A->getKind() == attr::Unavailable; } | |||
9684 | }; | |||
9685 | ||||
9686 | class UninitializedAttr : public InheritableAttr { | |||
9687 | public: | |||
9688 | static UninitializedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9689 | auto *A = new (Ctx) UninitializedAttr(Loc, Ctx, 0); | |||
9690 | A->setImplicit(true); | |||
9691 | return A; | |||
9692 | } | |||
9693 | ||||
9694 | UninitializedAttr(SourceRange R, ASTContext &Ctx | |||
9695 | , unsigned SI | |||
9696 | ) | |||
9697 | : InheritableAttr(attr::Uninitialized, R, SI, false, false) | |||
9698 | { | |||
9699 | } | |||
9700 | ||||
9701 | UninitializedAttr *clone(ASTContext &C) const; | |||
9702 | void printPretty(raw_ostream &OS, | |||
9703 | const PrintingPolicy &Policy) const; | |||
9704 | const char *getSpelling() const; | |||
9705 | ||||
9706 | ||||
9707 | static bool classof(const Attr *A) { return A->getKind() == attr::Uninitialized; } | |||
9708 | }; | |||
9709 | ||||
9710 | class UnusedAttr : public InheritableAttr { | |||
9711 | public: | |||
9712 | enum Spelling { | |||
9713 | CXX11_maybe_unused = 0, | |||
9714 | GNU_unused = 1, | |||
9715 | CXX11_gnu_unused = 2, | |||
9716 | C2x_maybe_unused = 3 | |||
9717 | }; | |||
9718 | ||||
9719 | static UnusedAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
9720 | auto *A = new (Ctx) UnusedAttr(Loc, Ctx, S); | |||
9721 | A->setImplicit(true); | |||
9722 | return A; | |||
9723 | } | |||
9724 | ||||
9725 | UnusedAttr(SourceRange R, ASTContext &Ctx | |||
9726 | , unsigned SI | |||
9727 | ) | |||
9728 | : InheritableAttr(attr::Unused, R, SI, false, false) | |||
9729 | { | |||
9730 | } | |||
9731 | ||||
9732 | UnusedAttr *clone(ASTContext &C) const; | |||
9733 | void printPretty(raw_ostream &OS, | |||
9734 | const PrintingPolicy &Policy) const; | |||
9735 | const char *getSpelling() const; | |||
9736 | Spelling getSemanticSpelling() const { | |||
9737 | switch (SpellingListIndex) { | |||
9738 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 9738); | |||
9739 | case 0: return CXX11_maybe_unused; | |||
9740 | case 1: return GNU_unused; | |||
9741 | case 2: return CXX11_gnu_unused; | |||
9742 | case 3: return C2x_maybe_unused; | |||
9743 | } | |||
9744 | } | |||
9745 | ||||
9746 | ||||
9747 | static bool classof(const Attr *A) { return A->getKind() == attr::Unused; } | |||
9748 | }; | |||
9749 | ||||
9750 | class UsedAttr : public InheritableAttr { | |||
9751 | public: | |||
9752 | static UsedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9753 | auto *A = new (Ctx) UsedAttr(Loc, Ctx, 0); | |||
9754 | A->setImplicit(true); | |||
9755 | return A; | |||
9756 | } | |||
9757 | ||||
9758 | UsedAttr(SourceRange R, ASTContext &Ctx | |||
9759 | , unsigned SI | |||
9760 | ) | |||
9761 | : InheritableAttr(attr::Used, R, SI, false, false) | |||
9762 | { | |||
9763 | } | |||
9764 | ||||
9765 | UsedAttr *clone(ASTContext &C) const; | |||
9766 | void printPretty(raw_ostream &OS, | |||
9767 | const PrintingPolicy &Policy) const; | |||
9768 | const char *getSpelling() const; | |||
9769 | ||||
9770 | ||||
9771 | static bool classof(const Attr *A) { return A->getKind() == attr::Used; } | |||
9772 | }; | |||
9773 | ||||
9774 | class UuidAttr : public InheritableAttr { | |||
9775 | unsigned guidLength; | |||
9776 | char *guid; | |||
9777 | ||||
9778 | public: | |||
9779 | static UuidAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Guid, SourceRange Loc = SourceRange()) { | |||
9780 | auto *A = new (Ctx) UuidAttr(Loc, Ctx, Guid, 0); | |||
9781 | A->setImplicit(true); | |||
9782 | return A; | |||
9783 | } | |||
9784 | ||||
9785 | UuidAttr(SourceRange R, ASTContext &Ctx | |||
9786 | , llvm::StringRef Guid | |||
9787 | , unsigned SI | |||
9788 | ) | |||
9789 | : InheritableAttr(attr::Uuid, R, SI, false, false) | |||
9790 | , guidLength(Guid.size()),guid(new (Ctx, 1) char[guidLength]) | |||
9791 | { | |||
9792 | if (!Guid.empty()) | |||
9793 | std::memcpy(guid, Guid.data(), guidLength); | |||
9794 | } | |||
9795 | ||||
9796 | UuidAttr *clone(ASTContext &C) const; | |||
9797 | void printPretty(raw_ostream &OS, | |||
9798 | const PrintingPolicy &Policy) const; | |||
9799 | const char *getSpelling() const; | |||
9800 | llvm::StringRef getGuid() const { | |||
9801 | return llvm::StringRef(guid, guidLength); | |||
9802 | } | |||
9803 | unsigned getGuidLength() const { | |||
9804 | return guidLength; | |||
9805 | } | |||
9806 | void setGuid(ASTContext &C, llvm::StringRef S) { | |||
9807 | guidLength = S.size(); | |||
9808 | this->guid = new (C, 1) char [guidLength]; | |||
9809 | if (!S.empty()) | |||
9810 | std::memcpy(this->guid, S.data(), guidLength); | |||
9811 | } | |||
9812 | ||||
9813 | ||||
9814 | ||||
9815 | static bool classof(const Attr *A) { return A->getKind() == attr::Uuid; } | |||
9816 | }; | |||
9817 | ||||
9818 | class VecReturnAttr : public InheritableAttr { | |||
9819 | public: | |||
9820 | static VecReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9821 | auto *A = new (Ctx) VecReturnAttr(Loc, Ctx, 0); | |||
9822 | A->setImplicit(true); | |||
9823 | return A; | |||
9824 | } | |||
9825 | ||||
9826 | VecReturnAttr(SourceRange R, ASTContext &Ctx | |||
9827 | , unsigned SI | |||
9828 | ) | |||
9829 | : InheritableAttr(attr::VecReturn, R, SI, false, false) | |||
9830 | { | |||
9831 | } | |||
9832 | ||||
9833 | VecReturnAttr *clone(ASTContext &C) const; | |||
9834 | void printPretty(raw_ostream &OS, | |||
9835 | const PrintingPolicy &Policy) const; | |||
9836 | const char *getSpelling() const; | |||
9837 | ||||
9838 | ||||
9839 | static bool classof(const Attr *A) { return A->getKind() == attr::VecReturn; } | |||
9840 | }; | |||
9841 | ||||
9842 | class VecTypeHintAttr : public InheritableAttr { | |||
9843 | TypeSourceInfo * typeHint; | |||
9844 | ||||
9845 | public: | |||
9846 | static VecTypeHintAttr *CreateImplicit(ASTContext &Ctx, TypeSourceInfo * TypeHint, SourceRange Loc = SourceRange()) { | |||
9847 | auto *A = new (Ctx) VecTypeHintAttr(Loc, Ctx, TypeHint, 0); | |||
9848 | A->setImplicit(true); | |||
9849 | return A; | |||
9850 | } | |||
9851 | ||||
9852 | VecTypeHintAttr(SourceRange R, ASTContext &Ctx | |||
9853 | , TypeSourceInfo * TypeHint | |||
9854 | , unsigned SI | |||
9855 | ) | |||
9856 | : InheritableAttr(attr::VecTypeHint, R, SI, false, false) | |||
9857 | , typeHint(TypeHint) | |||
9858 | { | |||
9859 | } | |||
9860 | ||||
9861 | VecTypeHintAttr *clone(ASTContext &C) const; | |||
9862 | void printPretty(raw_ostream &OS, | |||
9863 | const PrintingPolicy &Policy) const; | |||
9864 | const char *getSpelling() const; | |||
9865 | QualType getTypeHint() const { | |||
9866 | return typeHint->getType(); | |||
9867 | } TypeSourceInfo * getTypeHintLoc() const { | |||
9868 | return typeHint; | |||
9869 | } | |||
9870 | ||||
9871 | ||||
9872 | ||||
9873 | static bool classof(const Attr *A) { return A->getKind() == attr::VecTypeHint; } | |||
9874 | }; | |||
9875 | ||||
9876 | class VectorCallAttr : public InheritableAttr { | |||
9877 | public: | |||
9878 | static VectorCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9879 | auto *A = new (Ctx) VectorCallAttr(Loc, Ctx, 0); | |||
9880 | A->setImplicit(true); | |||
9881 | return A; | |||
9882 | } | |||
9883 | ||||
9884 | VectorCallAttr(SourceRange R, ASTContext &Ctx | |||
9885 | , unsigned SI | |||
9886 | ) | |||
9887 | : InheritableAttr(attr::VectorCall, R, SI, false, false) | |||
9888 | { | |||
9889 | } | |||
9890 | ||||
9891 | VectorCallAttr *clone(ASTContext &C) const; | |||
9892 | void printPretty(raw_ostream &OS, | |||
9893 | const PrintingPolicy &Policy) const; | |||
9894 | const char *getSpelling() const; | |||
9895 | ||||
9896 | ||||
9897 | static bool classof(const Attr *A) { return A->getKind() == attr::VectorCall; } | |||
9898 | }; | |||
9899 | ||||
9900 | class VisibilityAttr : public InheritableAttr { | |||
9901 | public: | |||
9902 | enum VisibilityType { | |||
9903 | Default, | |||
9904 | Hidden, | |||
9905 | Protected | |||
9906 | }; | |||
9907 | private: | |||
9908 | VisibilityType visibility; | |||
9909 | ||||
9910 | public: | |||
9911 | static VisibilityAttr *CreateImplicit(ASTContext &Ctx, VisibilityType Visibility, SourceRange Loc = SourceRange()) { | |||
9912 | auto *A = new (Ctx) VisibilityAttr(Loc, Ctx, Visibility, 0); | |||
9913 | A->setImplicit(true); | |||
9914 | return A; | |||
9915 | } | |||
9916 | ||||
9917 | VisibilityAttr(SourceRange R, ASTContext &Ctx | |||
9918 | , VisibilityType Visibility | |||
9919 | , unsigned SI | |||
9920 | ) | |||
9921 | : InheritableAttr(attr::Visibility, R, SI, false, false) | |||
9922 | , visibility(Visibility) | |||
9923 | { | |||
9924 | } | |||
9925 | ||||
9926 | VisibilityAttr *clone(ASTContext &C) const; | |||
9927 | void printPretty(raw_ostream &OS, | |||
9928 | const PrintingPolicy &Policy) const; | |||
9929 | const char *getSpelling() const; | |||
9930 | VisibilityType getVisibility() const { | |||
9931 | return visibility; | |||
9932 | } | |||
9933 | ||||
9934 | static bool ConvertStrToVisibilityType(StringRef Val, VisibilityType &Out) { | |||
9935 | Optional<VisibilityType> R = llvm::StringSwitch<Optional<VisibilityType>>(Val) | |||
9936 | .Case("default", VisibilityAttr::Default) | |||
9937 | .Case("hidden", VisibilityAttr::Hidden) | |||
9938 | .Case("internal", VisibilityAttr::Hidden) | |||
9939 | .Case("protected", VisibilityAttr::Protected) | |||
9940 | .Default(Optional<VisibilityType>()); | |||
9941 | if (R) { | |||
9942 | Out = *R; | |||
9943 | return true; | |||
9944 | } | |||
9945 | return false; | |||
9946 | } | |||
9947 | ||||
9948 | static const char *ConvertVisibilityTypeToStr(VisibilityType Val) { | |||
9949 | switch(Val) { | |||
9950 | case VisibilityAttr::Default: return "default"; | |||
9951 | case VisibilityAttr::Hidden: return "hidden"; | |||
9952 | case VisibilityAttr::Protected: return "protected"; | |||
9953 | } | |||
9954 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 9954); | |||
9955 | } | |||
9956 | ||||
9957 | ||||
9958 | static bool classof(const Attr *A) { return A->getKind() == attr::Visibility; } | |||
9959 | }; | |||
9960 | ||||
9961 | class WarnUnusedAttr : public InheritableAttr { | |||
9962 | public: | |||
9963 | static WarnUnusedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9964 | auto *A = new (Ctx) WarnUnusedAttr(Loc, Ctx, 0); | |||
9965 | A->setImplicit(true); | |||
9966 | return A; | |||
9967 | } | |||
9968 | ||||
9969 | WarnUnusedAttr(SourceRange R, ASTContext &Ctx | |||
9970 | , unsigned SI | |||
9971 | ) | |||
9972 | : InheritableAttr(attr::WarnUnused, R, SI, false, false) | |||
9973 | { | |||
9974 | } | |||
9975 | ||||
9976 | WarnUnusedAttr *clone(ASTContext &C) const; | |||
9977 | void printPretty(raw_ostream &OS, | |||
9978 | const PrintingPolicy &Policy) const; | |||
9979 | const char *getSpelling() const; | |||
9980 | ||||
9981 | ||||
9982 | static bool classof(const Attr *A) { return A->getKind() == attr::WarnUnused; } | |||
9983 | }; | |||
9984 | ||||
9985 | class WarnUnusedResultAttr : public InheritableAttr { | |||
9986 | public: | |||
9987 | enum Spelling { | |||
9988 | CXX11_nodiscard = 0, | |||
9989 | C2x_nodiscard = 1, | |||
9990 | CXX11_clang_warn_unused_result = 2, | |||
9991 | GNU_warn_unused_result = 3, | |||
9992 | CXX11_gnu_warn_unused_result = 4 | |||
9993 | }; | |||
9994 | ||||
9995 | static WarnUnusedResultAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
9996 | auto *A = new (Ctx) WarnUnusedResultAttr(Loc, Ctx, S); | |||
9997 | A->setImplicit(true); | |||
9998 | return A; | |||
9999 | } | |||
10000 | ||||
10001 | WarnUnusedResultAttr(SourceRange R, ASTContext &Ctx | |||
10002 | , unsigned SI | |||
10003 | ) | |||
10004 | : InheritableAttr(attr::WarnUnusedResult, R, SI, false, false) | |||
10005 | { | |||
10006 | } | |||
10007 | ||||
10008 | WarnUnusedResultAttr *clone(ASTContext &C) const; | |||
10009 | void printPretty(raw_ostream &OS, | |||
10010 | const PrintingPolicy &Policy) const; | |||
10011 | const char *getSpelling() const; | |||
10012 | Spelling getSemanticSpelling() const { | |||
10013 | switch (SpellingListIndex) { | |||
10014 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 10014); | |||
10015 | case 0: return CXX11_nodiscard; | |||
10016 | case 1: return C2x_nodiscard; | |||
10017 | case 2: return CXX11_clang_warn_unused_result; | |||
10018 | case 3: return GNU_warn_unused_result; | |||
10019 | case 4: return CXX11_gnu_warn_unused_result; | |||
10020 | } | |||
10021 | } | |||
10022 | ||||
10023 | ||||
10024 | static bool classof(const Attr *A) { return A->getKind() == attr::WarnUnusedResult; } | |||
10025 | }; | |||
10026 | ||||
10027 | class WeakAttr : public InheritableAttr { | |||
10028 | public: | |||
10029 | static WeakAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
10030 | auto *A = new (Ctx) WeakAttr(Loc, Ctx, 0); | |||
10031 | A->setImplicit(true); | |||
10032 | return A; | |||
10033 | } | |||
10034 | ||||
10035 | WeakAttr(SourceRange R, ASTContext &Ctx | |||
10036 | , unsigned SI | |||
10037 | ) | |||
10038 | : InheritableAttr(attr::Weak, R, SI, false, false) | |||
10039 | { | |||
10040 | } | |||
10041 | ||||
10042 | WeakAttr *clone(ASTContext &C) const; | |||
10043 | void printPretty(raw_ostream &OS, | |||
10044 | const PrintingPolicy &Policy) const; | |||
10045 | const char *getSpelling() const; | |||
10046 | ||||
10047 | ||||
10048 | static bool classof(const Attr *A) { return A->getKind() == attr::Weak; } | |||
10049 | }; | |||
10050 | ||||
10051 | class WeakImportAttr : public InheritableAttr { | |||
10052 | public: | |||
10053 | static WeakImportAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
10054 | auto *A = new (Ctx) WeakImportAttr(Loc, Ctx, 0); | |||
10055 | A->setImplicit(true); | |||
10056 | return A; | |||
10057 | } | |||
10058 | ||||
10059 | WeakImportAttr(SourceRange R, ASTContext &Ctx | |||
10060 | , unsigned SI | |||
10061 | ) | |||
10062 | : InheritableAttr(attr::WeakImport, R, SI, false, false) | |||
10063 | { | |||
10064 | } | |||
10065 | ||||
10066 | WeakImportAttr *clone(ASTContext &C) const; | |||
10067 | void printPretty(raw_ostream &OS, | |||
10068 | const PrintingPolicy &Policy) const; | |||
10069 | const char *getSpelling() const; | |||
10070 | ||||
10071 | ||||
10072 | static bool classof(const Attr *A) { return A->getKind() == attr::WeakImport; } | |||
10073 | }; | |||
10074 | ||||
10075 | class WeakRefAttr : public InheritableAttr { | |||
10076 | unsigned aliaseeLength; | |||
10077 | char *aliasee; | |||
10078 | ||||
10079 | public: | |||
10080 | static WeakRefAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Aliasee, SourceRange Loc = SourceRange()) { | |||
10081 | auto *A = new (Ctx) WeakRefAttr(Loc, Ctx, Aliasee, 0); | |||
10082 | A->setImplicit(true); | |||
10083 | return A; | |||
10084 | } | |||
10085 | ||||
10086 | WeakRefAttr(SourceRange R, ASTContext &Ctx | |||
10087 | , llvm::StringRef Aliasee | |||
10088 | , unsigned SI | |||
10089 | ) | |||
10090 | : InheritableAttr(attr::WeakRef, R, SI, false, false) | |||
10091 | , aliaseeLength(Aliasee.size()),aliasee(new (Ctx, 1) char[aliaseeLength]) | |||
10092 | { | |||
10093 | if (!Aliasee.empty()) | |||
10094 | std::memcpy(aliasee, Aliasee.data(), aliaseeLength); | |||
10095 | } | |||
10096 | ||||
10097 | WeakRefAttr(SourceRange R, ASTContext &Ctx | |||
10098 | , unsigned SI | |||
10099 | ) | |||
10100 | : InheritableAttr(attr::WeakRef, R, SI, false, false) | |||
10101 | , aliaseeLength(0),aliasee(nullptr) | |||
10102 | { | |||
10103 | } | |||
10104 | ||||
10105 | WeakRefAttr *clone(ASTContext &C) const; | |||
10106 | void printPretty(raw_ostream &OS, | |||
10107 | const PrintingPolicy &Policy) const; | |||
10108 | const char *getSpelling() const; | |||
10109 | llvm::StringRef getAliasee() const { | |||
10110 | return llvm::StringRef(aliasee, aliaseeLength); | |||
10111 | } | |||
10112 | unsigned getAliaseeLength() const { | |||
10113 | return aliaseeLength; | |||
10114 | } | |||
10115 | void setAliasee(ASTContext &C, llvm::StringRef S) { | |||
10116 | aliaseeLength = S.size(); | |||
10117 | this->aliasee = new (C, 1) char [aliaseeLength]; | |||
10118 | if (!S.empty()) | |||
10119 | std::memcpy(this->aliasee, S.data(), aliaseeLength); | |||
10120 | } | |||
10121 | ||||
10122 | ||||
10123 | ||||
10124 | static bool classof(const Attr *A) { return A->getKind() == attr::WeakRef; } | |||
10125 | }; | |||
10126 | ||||
10127 | class WebAssemblyImportModuleAttr : public InheritableAttr { | |||
10128 | unsigned importModuleLength; | |||
10129 | char *importModule; | |||
10130 | ||||
10131 | public: | |||
10132 | static WebAssemblyImportModuleAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef ImportModule, SourceRange Loc = SourceRange()) { | |||
10133 | auto *A = new (Ctx) WebAssemblyImportModuleAttr(Loc, Ctx, ImportModule, 0); | |||
10134 | A->setImplicit(true); | |||
10135 | return A; | |||
10136 | } | |||
10137 | ||||
10138 | WebAssemblyImportModuleAttr(SourceRange R, ASTContext &Ctx | |||
10139 | , llvm::StringRef ImportModule | |||
10140 | , unsigned SI | |||
10141 | ) | |||
10142 | : InheritableAttr(attr::WebAssemblyImportModule, R, SI, false, false) | |||
10143 | , importModuleLength(ImportModule.size()),importModule(new (Ctx, 1) char[importModuleLength]) | |||
10144 | { | |||
10145 | if (!ImportModule.empty()) | |||
10146 | std::memcpy(importModule, ImportModule.data(), importModuleLength); | |||
10147 | } | |||
10148 | ||||
10149 | WebAssemblyImportModuleAttr *clone(ASTContext &C) const; | |||
10150 | void printPretty(raw_ostream &OS, | |||
10151 | const PrintingPolicy &Policy) const; | |||
10152 | const char *getSpelling() const; | |||
10153 | llvm::StringRef getImportModule() const { | |||
10154 | return llvm::StringRef(importModule, importModuleLength); | |||
10155 | } | |||
10156 | unsigned getImportModuleLength() const { | |||
10157 | return importModuleLength; | |||
10158 | } | |||
10159 | void setImportModule(ASTContext &C, llvm::StringRef S) { | |||
10160 | importModuleLength = S.size(); | |||
10161 | this->importModule = new (C, 1) char [importModuleLength]; | |||
10162 | if (!S.empty()) | |||
10163 | std::memcpy(this->importModule, S.data(), importModuleLength); | |||
10164 | } | |||
10165 | ||||
10166 | ||||
10167 | ||||
10168 | static bool classof(const Attr *A) { return A->getKind() == attr::WebAssemblyImportModule; } | |||
10169 | }; | |||
10170 | ||||
10171 | class WebAssemblyImportNameAttr : public InheritableAttr { | |||
10172 | unsigned importNameLength; | |||
10173 | char *importName; | |||
10174 | ||||
10175 | public: | |||
10176 | static WebAssemblyImportNameAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef ImportName, SourceRange Loc = SourceRange()) { | |||
10177 | auto *A = new (Ctx) WebAssemblyImportNameAttr(Loc, Ctx, ImportName, 0); | |||
10178 | A->setImplicit(true); | |||
10179 | return A; | |||
10180 | } | |||
10181 | ||||
10182 | WebAssemblyImportNameAttr(SourceRange R, ASTContext &Ctx | |||
10183 | , llvm::StringRef ImportName | |||
10184 | , unsigned SI | |||
10185 | ) | |||
10186 | : InheritableAttr(attr::WebAssemblyImportName, R, SI, false, false) | |||
10187 | , importNameLength(ImportName.size()),importName(new (Ctx, 1) char[importNameLength]) | |||
10188 | { | |||
10189 | if (!ImportName.empty()) | |||
10190 | std::memcpy(importName, ImportName.data(), importNameLength); | |||
10191 | } | |||
10192 | ||||
10193 | WebAssemblyImportNameAttr *clone(ASTContext &C) const; | |||
10194 | void printPretty(raw_ostream &OS, | |||
10195 | const PrintingPolicy &Policy) const; | |||
10196 | const char *getSpelling() const; | |||
10197 | llvm::StringRef getImportName() const { | |||
10198 | return llvm::StringRef(importName, importNameLength); | |||
10199 | } | |||
10200 | unsigned getImportNameLength() const { | |||
10201 | return importNameLength; | |||
10202 | } | |||
10203 | void setImportName(ASTContext &C, llvm::StringRef S) { | |||
10204 | importNameLength = S.size(); | |||
10205 | this->importName = new (C, 1) char [importNameLength]; | |||
10206 | if (!S.empty()) | |||
10207 | std::memcpy(this->importName, S.data(), importNameLength); | |||
10208 | } | |||
10209 | ||||
10210 | ||||
10211 | ||||
10212 | static bool classof(const Attr *A) { return A->getKind() == attr::WebAssemblyImportName; } | |||
10213 | }; | |||
10214 | ||||
10215 | class WorkGroupSizeHintAttr : public InheritableAttr { | |||
10216 | unsigned xDim; | |||
10217 | ||||
10218 | unsigned yDim; | |||
10219 | ||||
10220 | unsigned zDim; | |||
10221 | ||||
10222 | public: | |||
10223 | static WorkGroupSizeHintAttr *CreateImplicit(ASTContext &Ctx, unsigned XDim, unsigned YDim, unsigned ZDim, SourceRange Loc = SourceRange()) { | |||
10224 | auto *A = new (Ctx) WorkGroupSizeHintAttr(Loc, Ctx, XDim, YDim, ZDim, 0); | |||
10225 | A->setImplicit(true); | |||
10226 | return A; | |||
10227 | } | |||
10228 | ||||
10229 | WorkGroupSizeHintAttr(SourceRange R, ASTContext &Ctx | |||
10230 | , unsigned XDim | |||
10231 | , unsigned YDim | |||
10232 | , unsigned ZDim | |||
10233 | , unsigned SI | |||
10234 | ) | |||
10235 | : InheritableAttr(attr::WorkGroupSizeHint, R, SI, false, false) | |||
10236 | , xDim(XDim) | |||
10237 | , yDim(YDim) | |||
10238 | , zDim(ZDim) | |||
10239 | { | |||
10240 | } | |||
10241 | ||||
10242 | WorkGroupSizeHintAttr *clone(ASTContext &C) const; | |||
10243 | void printPretty(raw_ostream &OS, | |||
10244 | const PrintingPolicy &Policy) const; | |||
10245 | const char *getSpelling() const; | |||
10246 | unsigned getXDim() const { | |||
10247 | return xDim; | |||
10248 | } | |||
10249 | ||||
10250 | unsigned getYDim() const { | |||
10251 | return yDim; | |||
10252 | } | |||
10253 | ||||
10254 | unsigned getZDim() const { | |||
10255 | return zDim; | |||
10256 | } | |||
10257 | ||||
10258 | ||||
10259 | ||||
10260 | static bool classof(const Attr *A) { return A->getKind() == attr::WorkGroupSizeHint; } | |||
10261 | }; | |||
10262 | ||||
10263 | class X86ForceAlignArgPointerAttr : public InheritableAttr { | |||
10264 | public: | |||
10265 | static X86ForceAlignArgPointerAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
10266 | auto *A = new (Ctx) X86ForceAlignArgPointerAttr(Loc, Ctx, 0); | |||
10267 | A->setImplicit(true); | |||
10268 | return A; | |||
10269 | } | |||
10270 | ||||
10271 | X86ForceAlignArgPointerAttr(SourceRange R, ASTContext &Ctx | |||
10272 | , unsigned SI | |||
10273 | ) | |||
10274 | : InheritableAttr(attr::X86ForceAlignArgPointer, R, SI, false, false) | |||
10275 | { | |||
10276 | } | |||
10277 | ||||
10278 | X86ForceAlignArgPointerAttr *clone(ASTContext &C) const; | |||
10279 | void printPretty(raw_ostream &OS, | |||
10280 | const PrintingPolicy &Policy) const; | |||
10281 | const char *getSpelling() const; | |||
10282 | ||||
10283 | ||||
10284 | static bool classof(const Attr *A) { return A->getKind() == attr::X86ForceAlignArgPointer; } | |||
10285 | }; | |||
10286 | ||||
10287 | class XRayInstrumentAttr : public InheritableAttr { | |||
10288 | public: | |||
10289 | enum Spelling { | |||
10290 | GNU_xray_always_instrument = 0, | |||
10291 | CXX11_clang_xray_always_instrument = 1, | |||
10292 | C2x_clang_xray_always_instrument = 2, | |||
10293 | GNU_xray_never_instrument = 3, | |||
10294 | CXX11_clang_xray_never_instrument = 4, | |||
10295 | C2x_clang_xray_never_instrument = 5 | |||
10296 | }; | |||
10297 | ||||
10298 | static XRayInstrumentAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
10299 | auto *A = new (Ctx) XRayInstrumentAttr(Loc, Ctx, S); | |||
10300 | A->setImplicit(true); | |||
10301 | return A; | |||
10302 | } | |||
10303 | ||||
10304 | XRayInstrumentAttr(SourceRange R, ASTContext &Ctx | |||
10305 | , unsigned SI | |||
10306 | ) | |||
10307 | : InheritableAttr(attr::XRayInstrument, R, SI, false, false) | |||
10308 | { | |||
10309 | } | |||
10310 | ||||
10311 | XRayInstrumentAttr *clone(ASTContext &C) const; | |||
10312 | void printPretty(raw_ostream &OS, | |||
10313 | const PrintingPolicy &Policy) const; | |||
10314 | const char *getSpelling() const; | |||
10315 | Spelling getSemanticSpelling() const { | |||
10316 | switch (SpellingListIndex) { | |||
10317 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 10317); | |||
10318 | case 0: return GNU_xray_always_instrument; | |||
10319 | case 1: return CXX11_clang_xray_always_instrument; | |||
10320 | case 2: return C2x_clang_xray_always_instrument; | |||
10321 | case 3: return GNU_xray_never_instrument; | |||
10322 | case 4: return CXX11_clang_xray_never_instrument; | |||
10323 | case 5: return C2x_clang_xray_never_instrument; | |||
10324 | } | |||
10325 | } | |||
10326 | bool alwaysXRayInstrument() const { return SpellingListIndex == 0 || | |||
10327 | SpellingListIndex == 1 || | |||
10328 | SpellingListIndex == 2; } | |||
10329 | bool neverXRayInstrument() const { return SpellingListIndex == 3 || | |||
10330 | SpellingListIndex == 4 || | |||
10331 | SpellingListIndex == 5; } | |||
10332 | ||||
10333 | ||||
10334 | static bool classof(const Attr *A) { return A->getKind() == attr::XRayInstrument; } | |||
10335 | }; | |||
10336 | ||||
10337 | class XRayLogArgsAttr : public InheritableAttr { | |||
10338 | unsigned argumentCount; | |||
10339 | ||||
10340 | public: | |||
10341 | static XRayLogArgsAttr *CreateImplicit(ASTContext &Ctx, unsigned ArgumentCount, SourceRange Loc = SourceRange()) { | |||
10342 | auto *A = new (Ctx) XRayLogArgsAttr(Loc, Ctx, ArgumentCount, 0); | |||
10343 | A->setImplicit(true); | |||
10344 | return A; | |||
10345 | } | |||
10346 | ||||
10347 | XRayLogArgsAttr(SourceRange R, ASTContext &Ctx | |||
10348 | , unsigned ArgumentCount | |||
10349 | , unsigned SI | |||
10350 | ) | |||
10351 | : InheritableAttr(attr::XRayLogArgs, R, SI, false, false) | |||
10352 | , argumentCount(ArgumentCount) | |||
10353 | { | |||
10354 | } | |||
10355 | ||||
10356 | XRayLogArgsAttr *clone(ASTContext &C) const; | |||
10357 | void printPretty(raw_ostream &OS, | |||
10358 | const PrintingPolicy &Policy) const; | |||
10359 | const char *getSpelling() const; | |||
10360 | unsigned getArgumentCount() const { | |||
10361 | return argumentCount; | |||
10362 | } | |||
10363 | ||||
10364 | ||||
10365 | ||||
10366 | static bool classof(const Attr *A) { return A->getKind() == attr::XRayLogArgs; } | |||
10367 | }; | |||
10368 | ||||
10369 | #endif // LLVM_CLANG_ATTR_CLASSES_INC |