Bug Summary

File:build-llvm/tools/clang/include/clang/AST/Attrs.inc
Warning:line 9274, column 9
Null pointer passed as an argument to a 'nonnull' parameter

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name Sema.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mthread-model posix -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-8/lib/clang/8.0.0 -D CLANG_VENDOR="Debian " -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/tools/clang/lib/Sema -I /build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema -I /build/llvm-toolchain-snapshot-8~svn350071/tools/clang/include -I /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/tools/clang/include -I /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/include -I /build/llvm-toolchain-snapshot-8~svn350071/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/include/clang/8.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-8/lib/clang/8.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/tools/clang/lib/Sema -fdebug-prefix-map=/build/llvm-toolchain-snapshot-8~svn350071=. -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -stack-protector 2 -fobjc-runtime=gcc -fno-common -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-12-27-042839-1215-1 -x c++ /build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp -faddrsig

/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp

1//===--- Sema.cpp - AST Builder and Semantic Analysis Implementation ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the actions class which performs semantic analysis and
11// builds an AST out of a parse stream.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang/AST/ASTContext.h"
16#include "clang/AST/ASTDiagnostic.h"
17#include "clang/AST/DeclCXX.h"
18#include "clang/AST/DeclFriend.h"
19#include "clang/AST/DeclObjC.h"
20#include "clang/AST/Expr.h"
21#include "clang/AST/ExprCXX.h"
22#include "clang/AST/PrettyDeclStackTrace.h"
23#include "clang/AST/StmtCXX.h"
24#include "clang/Basic/DiagnosticOptions.h"
25#include "clang/Basic/PartialDiagnostic.h"
26#include "clang/Basic/TargetInfo.h"
27#include "clang/Lex/HeaderSearch.h"
28#include "clang/Lex/Preprocessor.h"
29#include "clang/Sema/CXXFieldCollector.h"
30#include "clang/Sema/DelayedDiagnostic.h"
31#include "clang/Sema/ExternalSemaSource.h"
32#include "clang/Sema/Initialization.h"
33#include "clang/Sema/MultiplexExternalSemaSource.h"
34#include "clang/Sema/ObjCMethodList.h"
35#include "clang/Sema/Scope.h"
36#include "clang/Sema/ScopeInfo.h"
37#include "clang/Sema/SemaConsumer.h"
38#include "clang/Sema/SemaInternal.h"
39#include "clang/Sema/TemplateDeduction.h"
40#include "clang/Sema/TemplateInstCallback.h"
41#include "llvm/ADT/DenseMap.h"
42#include "llvm/ADT/SmallSet.h"
43using namespace clang;
44using namespace sema;
45
46SourceLocation Sema::getLocForEndOfToken(SourceLocation Loc, unsigned Offset) {
47 return Lexer::getLocForEndOfToken(Loc, Offset, SourceMgr, LangOpts);
48}
49
50ModuleLoader &Sema::getModuleLoader() const { return PP.getModuleLoader(); }
51
52PrintingPolicy Sema::getPrintingPolicy(const ASTContext &Context,
53 const Preprocessor &PP) {
54 PrintingPolicy Policy = Context.getPrintingPolicy();
55 // In diagnostics, we print _Bool as bool if the latter is defined as the
56 // former.
57 Policy.Bool = Context.getLangOpts().Bool;
58 if (!Policy.Bool) {
59 if (const MacroInfo *BoolMacro = PP.getMacroInfo(Context.getBoolName())) {
60 Policy.Bool = BoolMacro->isObjectLike() &&
61 BoolMacro->getNumTokens() == 1 &&
62 BoolMacro->getReplacementToken(0).is(tok::kw__Bool);
63 }
64 }
65
66 return Policy;
67}
68
69void Sema::ActOnTranslationUnitScope(Scope *S) {
70 TUScope = S;
71 PushDeclContext(S, Context.getTranslationUnitDecl());
72}
73
74namespace clang {
75namespace sema {
76
77class SemaPPCallbacks : public PPCallbacks {
78 Sema *S = nullptr;
79 llvm::SmallVector<SourceLocation, 8> IncludeStack;
80
81public:
82 void set(Sema &S) { this->S = &S; }
83
84 void reset() { S = nullptr; }
85
86 virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,
87 SrcMgr::CharacteristicKind FileType,
88 FileID PrevFID) override {
89 if (!S)
90 return;
91 switch (Reason) {
92 case EnterFile: {
93 SourceManager &SM = S->getSourceManager();
94 SourceLocation IncludeLoc = SM.getIncludeLoc(SM.getFileID(Loc));
95 if (IncludeLoc.isValid()) {
96 IncludeStack.push_back(IncludeLoc);
97 S->DiagnoseNonDefaultPragmaPack(
98 Sema::PragmaPackDiagnoseKind::NonDefaultStateAtInclude, IncludeLoc);
99 }
100 break;
101 }
102 case ExitFile:
103 if (!IncludeStack.empty())
104 S->DiagnoseNonDefaultPragmaPack(
105 Sema::PragmaPackDiagnoseKind::ChangedStateAtExit,
106 IncludeStack.pop_back_val());
107 break;
108 default:
109 break;
110 }
111 }
112};
113
114} // end namespace sema
115} // end namespace clang
116
117Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
118 TranslationUnitKind TUKind, CodeCompleteConsumer *CodeCompleter)
119 : ExternalSource(nullptr), isMultiplexExternalSource(false),
120 FPFeatures(pp.getLangOpts()), LangOpts(pp.getLangOpts()), PP(pp),
121 Context(ctxt), Consumer(consumer), Diags(PP.getDiagnostics()),
122 SourceMgr(PP.getSourceManager()), CollectStats(false),
123 CodeCompleter(CodeCompleter), CurContext(nullptr),
124 OriginalLexicalContext(nullptr), MSStructPragmaOn(false),
125 MSPointerToMemberRepresentationMethod(
126 LangOpts.getMSPointerToMemberRepresentationMethod()),
127 VtorDispStack(MSVtorDispAttr::Mode(LangOpts.VtorDispMode)), PackStack(0),
128 DataSegStack(nullptr), BSSSegStack(nullptr), ConstSegStack(nullptr),
129 CodeSegStack(nullptr), CurInitSeg(nullptr), VisContext(nullptr),
130 PragmaAttributeCurrentTargetDecl(nullptr),
131 IsBuildingRecoveryCallExpr(false), Cleanup{}, LateTemplateParser(nullptr),
132 LateTemplateParserCleanup(nullptr), OpaqueParser(nullptr), IdResolver(pp),
133 StdExperimentalNamespaceCache(nullptr), StdInitializerList(nullptr),
134 StdCoroutineTraitsCache(nullptr), CXXTypeInfoDecl(nullptr),
135 MSVCGuidDecl(nullptr), NSNumberDecl(nullptr), NSValueDecl(nullptr),
136 NSStringDecl(nullptr), StringWithUTF8StringMethod(nullptr),
137 ValueWithBytesObjCTypeMethod(nullptr), NSArrayDecl(nullptr),
138 ArrayWithObjectsMethod(nullptr), NSDictionaryDecl(nullptr),
139 DictionaryWithObjectsMethod(nullptr), GlobalNewDeleteDeclared(false),
140 TUKind(TUKind), NumSFINAEErrors(0),
141 FullyCheckedComparisonCategories(
142 static_cast<unsigned>(ComparisonCategoryType::Last) + 1),
143 AccessCheckingSFINAE(false), InNonInstantiationSFINAEContext(false),
144 NonInstantiationEntries(0), ArgumentPackSubstitutionIndex(-1),
145 CurrentInstantiationScope(nullptr), DisableTypoCorrection(false),
146 TyposCorrected(0), AnalysisWarnings(*this),
147 ThreadSafetyDeclCache(nullptr), VarDataSharingAttributesStack(nullptr),
148 CurScope(nullptr), Ident_super(nullptr), Ident___float128(nullptr) {
149 TUScope = nullptr;
150
151 LoadedExternalKnownNamespaces = false;
152 for (unsigned I = 0; I != NSAPI::NumNSNumberLiteralMethods; ++I)
153 NSNumberLiteralMethods[I] = nullptr;
154
155 if (getLangOpts().ObjC)
156 NSAPIObj.reset(new NSAPI(Context));
157
158 if (getLangOpts().CPlusPlus)
159 FieldCollector.reset(new CXXFieldCollector());
160
161 // Tell diagnostics how to render things from the AST library.
162 Diags.SetArgToStringFn(&FormatASTNodeDiagnosticArgument, &Context);
163
164 ExprEvalContexts.emplace_back(
165 ExpressionEvaluationContext::PotentiallyEvaluated, 0, CleanupInfo{},
166 nullptr, ExpressionEvaluationContextRecord::EK_Other);
167
168 PreallocatedFunctionScope.reset(new FunctionScopeInfo(Diags));
169
170 // Initialization of data sharing attributes stack for OpenMP
171 InitDataSharingAttributesStack();
172
173 std::unique_ptr<sema::SemaPPCallbacks> Callbacks =
174 llvm::make_unique<sema::SemaPPCallbacks>();
175 SemaPPCallbackHandler = Callbacks.get();
176 PP.addPPCallbacks(std::move(Callbacks));
177 SemaPPCallbackHandler->set(*this);
178}
179
180void Sema::addImplicitTypedef(StringRef Name, QualType T) {
181 DeclarationName DN = &Context.Idents.get(Name);
182 if (IdResolver.begin(DN) == IdResolver.end())
183 PushOnScopeChains(Context.buildImplicitTypedef(T, Name), TUScope);
184}
185
186void Sema::Initialize() {
187 if (SemaConsumer *SC = dyn_cast<SemaConsumer>(&Consumer))
188 SC->InitializeSema(*this);
189
190 // Tell the external Sema source about this Sema object.
191 if (ExternalSemaSource *ExternalSema
192 = dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource()))
193 ExternalSema->InitializeSema(*this);
194
195 // This needs to happen after ExternalSemaSource::InitializeSema(this) or we
196 // will not be able to merge any duplicate __va_list_tag decls correctly.
197 VAListTagName = PP.getIdentifierInfo("__va_list_tag");
198
199 if (!TUScope)
200 return;
201
202 // Initialize predefined 128-bit integer types, if needed.
203 if (Context.getTargetInfo().hasInt128Type()) {
204 // If either of the 128-bit integer types are unavailable to name lookup,
205 // define them now.
206 DeclarationName Int128 = &Context.Idents.get("__int128_t");
207 if (IdResolver.begin(Int128) == IdResolver.end())
208 PushOnScopeChains(Context.getInt128Decl(), TUScope);
209
210 DeclarationName UInt128 = &Context.Idents.get("__uint128_t");
211 if (IdResolver.begin(UInt128) == IdResolver.end())
212 PushOnScopeChains(Context.getUInt128Decl(), TUScope);
213 }
214
215
216 // Initialize predefined Objective-C types:
217 if (getLangOpts().ObjC) {
218 // If 'SEL' does not yet refer to any declarations, make it refer to the
219 // predefined 'SEL'.
220 DeclarationName SEL = &Context.Idents.get("SEL");
221 if (IdResolver.begin(SEL) == IdResolver.end())
222 PushOnScopeChains(Context.getObjCSelDecl(), TUScope);
223
224 // If 'id' does not yet refer to any declarations, make it refer to the
225 // predefined 'id'.
226 DeclarationName Id = &Context.Idents.get("id");
227 if (IdResolver.begin(Id) == IdResolver.end())
228 PushOnScopeChains(Context.getObjCIdDecl(), TUScope);
229
230 // Create the built-in typedef for 'Class'.
231 DeclarationName Class = &Context.Idents.get("Class");
232 if (IdResolver.begin(Class) == IdResolver.end())
233 PushOnScopeChains(Context.getObjCClassDecl(), TUScope);
234
235 // Create the built-in forward declaratino for 'Protocol'.
236 DeclarationName Protocol = &Context.Idents.get("Protocol");
237 if (IdResolver.begin(Protocol) == IdResolver.end())
238 PushOnScopeChains(Context.getObjCProtocolDecl(), TUScope);
239 }
240
241 // Create the internal type for the *StringMakeConstantString builtins.
242 DeclarationName ConstantString = &Context.Idents.get("__NSConstantString");
243 if (IdResolver.begin(ConstantString) == IdResolver.end())
244 PushOnScopeChains(Context.getCFConstantStringDecl(), TUScope);
245
246 // Initialize Microsoft "predefined C++ types".
247 if (getLangOpts().MSVCCompat) {
248 if (getLangOpts().CPlusPlus &&
249 IdResolver.begin(&Context.Idents.get("type_info")) == IdResolver.end())
250 PushOnScopeChains(Context.buildImplicitRecord("type_info", TTK_Class),
251 TUScope);
252
253 addImplicitTypedef("size_t", Context.getSizeType());
254 }
255
256 // Initialize predefined OpenCL types and supported extensions and (optional)
257 // core features.
258 if (getLangOpts().OpenCL) {
259 getOpenCLOptions().addSupport(Context.getTargetInfo().getSupportedOpenCLOpts());
260 getOpenCLOptions().enableSupportedCore(getLangOpts().OpenCLVersion);
261 addImplicitTypedef("sampler_t", Context.OCLSamplerTy);
262 addImplicitTypedef("event_t", Context.OCLEventTy);
263 if (getLangOpts().OpenCLVersion >= 200) {
264 addImplicitTypedef("clk_event_t", Context.OCLClkEventTy);
265 addImplicitTypedef("queue_t", Context.OCLQueueTy);
266 addImplicitTypedef("reserve_id_t", Context.OCLReserveIDTy);
267 addImplicitTypedef("atomic_int", Context.getAtomicType(Context.IntTy));
268 addImplicitTypedef("atomic_uint",
269 Context.getAtomicType(Context.UnsignedIntTy));
270 auto AtomicLongT = Context.getAtomicType(Context.LongTy);
271 addImplicitTypedef("atomic_long", AtomicLongT);
272 auto AtomicULongT = Context.getAtomicType(Context.UnsignedLongTy);
273 addImplicitTypedef("atomic_ulong", AtomicULongT);
274 addImplicitTypedef("atomic_float",
275 Context.getAtomicType(Context.FloatTy));
276 auto AtomicDoubleT = Context.getAtomicType(Context.DoubleTy);
277 addImplicitTypedef("atomic_double", AtomicDoubleT);
278 // OpenCLC v2.0, s6.13.11.6 requires that atomic_flag is implemented as
279 // 32-bit integer and OpenCLC v2.0, s6.1.1 int is always 32-bit wide.
280 addImplicitTypedef("atomic_flag", Context.getAtomicType(Context.IntTy));
281 auto AtomicIntPtrT = Context.getAtomicType(Context.getIntPtrType());
282 addImplicitTypedef("atomic_intptr_t", AtomicIntPtrT);
283 auto AtomicUIntPtrT = Context.getAtomicType(Context.getUIntPtrType());
284 addImplicitTypedef("atomic_uintptr_t", AtomicUIntPtrT);
285 auto AtomicSizeT = Context.getAtomicType(Context.getSizeType());
286 addImplicitTypedef("atomic_size_t", AtomicSizeT);
287 auto AtomicPtrDiffT = Context.getAtomicType(Context.getPointerDiffType());
288 addImplicitTypedef("atomic_ptrdiff_t", AtomicPtrDiffT);
289
290 // OpenCL v2.0 s6.13.11.6:
291 // - The atomic_long and atomic_ulong types are supported if the
292 // cl_khr_int64_base_atomics and cl_khr_int64_extended_atomics
293 // extensions are supported.
294 // - The atomic_double type is only supported if double precision
295 // is supported and the cl_khr_int64_base_atomics and
296 // cl_khr_int64_extended_atomics extensions are supported.
297 // - If the device address space is 64-bits, the data types
298 // atomic_intptr_t, atomic_uintptr_t, atomic_size_t and
299 // atomic_ptrdiff_t are supported if the cl_khr_int64_base_atomics and
300 // cl_khr_int64_extended_atomics extensions are supported.
301 std::vector<QualType> Atomic64BitTypes;
302 Atomic64BitTypes.push_back(AtomicLongT);
303 Atomic64BitTypes.push_back(AtomicULongT);
304 Atomic64BitTypes.push_back(AtomicDoubleT);
305 if (Context.getTypeSize(AtomicSizeT) == 64) {
306 Atomic64BitTypes.push_back(AtomicSizeT);
307 Atomic64BitTypes.push_back(AtomicIntPtrT);
308 Atomic64BitTypes.push_back(AtomicUIntPtrT);
309 Atomic64BitTypes.push_back(AtomicPtrDiffT);
310 }
311 for (auto &I : Atomic64BitTypes)
312 setOpenCLExtensionForType(I,
313 "cl_khr_int64_base_atomics cl_khr_int64_extended_atomics");
314
315 setOpenCLExtensionForType(AtomicDoubleT, "cl_khr_fp64");
316 }
317
318 setOpenCLExtensionForType(Context.DoubleTy, "cl_khr_fp64");
319
320#define GENERIC_IMAGE_TYPE_EXT(Type, Id, Ext)setOpenCLExtensionForType(Context.Id, Ext); \
321 setOpenCLExtensionForType(Context.Id, Ext);
322#include "clang/Basic/OpenCLImageTypes.def"
323#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
324 addImplicitTypedef(#ExtType, Context.Id##Ty); \
325 setOpenCLExtensionForType(Context.Id##Ty, #Ext);
326#include "clang/Basic/OpenCLExtensionTypes.def"
327 };
328
329 if (Context.getTargetInfo().hasBuiltinMSVaList()) {
330 DeclarationName MSVaList = &Context.Idents.get("__builtin_ms_va_list");
331 if (IdResolver.begin(MSVaList) == IdResolver.end())
332 PushOnScopeChains(Context.getBuiltinMSVaListDecl(), TUScope);
333 }
334
335 DeclarationName BuiltinVaList = &Context.Idents.get("__builtin_va_list");
336 if (IdResolver.begin(BuiltinVaList) == IdResolver.end())
337 PushOnScopeChains(Context.getBuiltinVaListDecl(), TUScope);
338}
339
340Sema::~Sema() {
341 if (VisContext) FreeVisContext();
342
343 // Kill all the active scopes.
344 for (sema::FunctionScopeInfo *FSI : FunctionScopes)
345 if (FSI != PreallocatedFunctionScope.get())
346 delete FSI;
347
348 // Tell the SemaConsumer to forget about us; we're going out of scope.
349 if (SemaConsumer *SC = dyn_cast<SemaConsumer>(&Consumer))
350 SC->ForgetSema();
351
352 // Detach from the external Sema source.
353 if (ExternalSemaSource *ExternalSema
354 = dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource()))
355 ExternalSema->ForgetSema();
356
357 // If Sema's ExternalSource is the multiplexer - we own it.
358 if (isMultiplexExternalSource)
359 delete ExternalSource;
360
361 threadSafety::threadSafetyCleanup(ThreadSafetyDeclCache);
362
363 // Destroys data sharing attributes stack for OpenMP
364 DestroyDataSharingAttributesStack();
365
366 // Detach from the PP callback handler which outlives Sema since it's owned
367 // by the preprocessor.
368 SemaPPCallbackHandler->reset();
369
370 assert(DelayedTypos.empty() && "Uncorrected typos!")((DelayedTypos.empty() && "Uncorrected typos!") ? static_cast
<void> (0) : __assert_fail ("DelayedTypos.empty() && \"Uncorrected typos!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 370, __PRETTY_FUNCTION__))
;
371}
372
373/// makeUnavailableInSystemHeader - There is an error in the current
374/// context. If we're still in a system header, and we can plausibly
375/// make the relevant declaration unavailable instead of erroring, do
376/// so and return true.
377bool Sema::makeUnavailableInSystemHeader(SourceLocation loc,
378 UnavailableAttr::ImplicitReason reason) {
379 // If we're not in a function, it's an error.
380 FunctionDecl *fn = dyn_cast<FunctionDecl>(CurContext);
381 if (!fn) return false;
1
Taking false branch
382
383 // If we're in template instantiation, it's an error.
384 if (inTemplateInstantiation())
2
Taking false branch
385 return false;
386
387 // If that function's not in a system header, it's an error.
388 if (!Context.getSourceManager().isInSystemHeader(loc))
3
Taking false branch
389 return false;
390
391 // If the function is already unavailable, it's not an error.
392 if (fn->hasAttr<UnavailableAttr>()) return true;
4
Taking false branch
393
394 fn->addAttr(UnavailableAttr::CreateImplicit(Context, "", reason, loc));
5
Calling 'UnavailableAttr::CreateImplicit'
395 return true;
396}
397
398ASTMutationListener *Sema::getASTMutationListener() const {
399 return getASTConsumer().GetASTMutationListener();
400}
401
402///Registers an external source. If an external source already exists,
403/// creates a multiplex external source and appends to it.
404///
405///\param[in] E - A non-null external sema source.
406///
407void Sema::addExternalSource(ExternalSemaSource *E) {
408 assert(E && "Cannot use with NULL ptr")((E && "Cannot use with NULL ptr") ? static_cast<void
> (0) : __assert_fail ("E && \"Cannot use with NULL ptr\""
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 408, __PRETTY_FUNCTION__))
;
409
410 if (!ExternalSource) {
411 ExternalSource = E;
412 return;
413 }
414
415 if (isMultiplexExternalSource)
416 static_cast<MultiplexExternalSemaSource*>(ExternalSource)->addSource(*E);
417 else {
418 ExternalSource = new MultiplexExternalSemaSource(*ExternalSource, *E);
419 isMultiplexExternalSource = true;
420 }
421}
422
423/// Print out statistics about the semantic analysis.
424void Sema::PrintStats() const {
425 llvm::errs() << "\n*** Semantic Analysis Stats:\n";
426 llvm::errs() << NumSFINAEErrors << " SFINAE diagnostics trapped.\n";
427
428 BumpAlloc.PrintStats();
429 AnalysisWarnings.PrintStats();
430}
431
432void Sema::diagnoseNullableToNonnullConversion(QualType DstType,
433 QualType SrcType,
434 SourceLocation Loc) {
435 Optional<NullabilityKind> ExprNullability = SrcType->getNullability(Context);
436 if (!ExprNullability || *ExprNullability != NullabilityKind::Nullable)
437 return;
438
439 Optional<NullabilityKind> TypeNullability = DstType->getNullability(Context);
440 if (!TypeNullability || *TypeNullability != NullabilityKind::NonNull)
441 return;
442
443 Diag(Loc, diag::warn_nullability_lost) << SrcType << DstType;
444}
445
446void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr* E) {
447 if (Diags.isIgnored(diag::warn_zero_as_null_pointer_constant,
448 E->getBeginLoc()))
449 return;
450 // nullptr only exists from C++11 on, so don't warn on its absence earlier.
451 if (!getLangOpts().CPlusPlus11)
452 return;
453
454 if (Kind != CK_NullToPointer && Kind != CK_NullToMemberPointer)
455 return;
456 if (E->IgnoreParenImpCasts()->getType()->isNullPtrType())
457 return;
458
459 // If it is a macro from system header, and if the macro name is not "NULL",
460 // do not warn.
461 SourceLocation MaybeMacroLoc = E->getBeginLoc();
462 if (Diags.getSuppressSystemWarnings() &&
463 SourceMgr.isInSystemMacro(MaybeMacroLoc) &&
464 !findMacroSpelling(MaybeMacroLoc, "NULL"))
465 return;
466
467 Diag(E->getBeginLoc(), diag::warn_zero_as_null_pointer_constant)
468 << FixItHint::CreateReplacement(E->getSourceRange(), "nullptr");
469}
470
471/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
472/// If there is already an implicit cast, merge into the existing one.
473/// The result is of the given category.
474ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty,
475 CastKind Kind, ExprValueKind VK,
476 const CXXCastPath *BasePath,
477 CheckedConversionKind CCK) {
478#ifndef NDEBUG
479 if (VK == VK_RValue && !E->isRValue()) {
480 switch (Kind) {
481 default:
482 llvm_unreachable("can't implicitly cast lvalue to rvalue with this cast "::llvm::llvm_unreachable_internal("can't implicitly cast lvalue to rvalue with this cast "
"kind", "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 483)
483 "kind")::llvm::llvm_unreachable_internal("can't implicitly cast lvalue to rvalue with this cast "
"kind", "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 483)
;
484 case CK_LValueToRValue:
485 case CK_ArrayToPointerDecay:
486 case CK_FunctionToPointerDecay:
487 case CK_ToVoid:
488 case CK_NonAtomicToAtomic:
489 break;
490 }
491 }
492 assert((VK == VK_RValue || !E->isRValue()) && "can't cast rvalue to lvalue")(((VK == VK_RValue || !E->isRValue()) && "can't cast rvalue to lvalue"
) ? static_cast<void> (0) : __assert_fail ("(VK == VK_RValue || !E->isRValue()) && \"can't cast rvalue to lvalue\""
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 492, __PRETTY_FUNCTION__))
;
493#endif
494
495 diagnoseNullableToNonnullConversion(Ty, E->getType(), E->getBeginLoc());
496 diagnoseZeroToNullptrConversion(Kind, E);
497
498 QualType ExprTy = Context.getCanonicalType(E->getType());
499 QualType TypeTy = Context.getCanonicalType(Ty);
500
501 if (ExprTy == TypeTy)
502 return E;
503
504 // C++1z [conv.array]: The temporary materialization conversion is applied.
505 // We also use this to fuel C++ DR1213, which applies to C++11 onwards.
506 if (Kind == CK_ArrayToPointerDecay && getLangOpts().CPlusPlus &&
507 E->getValueKind() == VK_RValue) {
508 // The temporary is an lvalue in C++98 and an xvalue otherwise.
509 ExprResult Materialized = CreateMaterializeTemporaryExpr(
510 E->getType(), E, !getLangOpts().CPlusPlus11);
511 if (Materialized.isInvalid())
512 return ExprError();
513 E = Materialized.get();
514 }
515
516 if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(E)) {
517 if (ImpCast->getCastKind() == Kind && (!BasePath || BasePath->empty())) {
518 ImpCast->setType(Ty);
519 ImpCast->setValueKind(VK);
520 return E;
521 }
522 }
523
524 return ImplicitCastExpr::Create(Context, Ty, Kind, E, BasePath, VK);
525}
526
527/// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding
528/// to the conversion from scalar type ScalarTy to the Boolean type.
529CastKind Sema::ScalarTypeToBooleanCastKind(QualType ScalarTy) {
530 switch (ScalarTy->getScalarTypeKind()) {
531 case Type::STK_Bool: return CK_NoOp;
532 case Type::STK_CPointer: return CK_PointerToBoolean;
533 case Type::STK_BlockPointer: return CK_PointerToBoolean;
534 case Type::STK_ObjCObjectPointer: return CK_PointerToBoolean;
535 case Type::STK_MemberPointer: return CK_MemberPointerToBoolean;
536 case Type::STK_Integral: return CK_IntegralToBoolean;
537 case Type::STK_Floating: return CK_FloatingToBoolean;
538 case Type::STK_IntegralComplex: return CK_IntegralComplexToBoolean;
539 case Type::STK_FloatingComplex: return CK_FloatingComplexToBoolean;
540 case Type::STK_FixedPoint: return CK_FixedPointToBoolean;
541 }
542 llvm_unreachable("unknown scalar type kind")::llvm::llvm_unreachable_internal("unknown scalar type kind",
"/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 542)
;
543}
544
545/// Used to prune the decls of Sema's UnusedFileScopedDecls vector.
546static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D) {
547 if (D->getMostRecentDecl()->isUsed())
548 return true;
549
550 if (D->isExternallyVisible())
551 return true;
552
553 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
554 // If this is a function template and none of its specializations is used,
555 // we should warn.
556 if (FunctionTemplateDecl *Template = FD->getDescribedFunctionTemplate())
557 for (const auto *Spec : Template->specializations())
558 if (ShouldRemoveFromUnused(SemaRef, Spec))
559 return true;
560
561 // UnusedFileScopedDecls stores the first declaration.
562 // The declaration may have become definition so check again.
563 const FunctionDecl *DeclToCheck;
564 if (FD->hasBody(DeclToCheck))
565 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck);
566
567 // Later redecls may add new information resulting in not having to warn,
568 // so check again.
569 DeclToCheck = FD->getMostRecentDecl();
570 if (DeclToCheck != FD)
571 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck);
572 }
573
574 if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
575 // If a variable usable in constant expressions is referenced,
576 // don't warn if it isn't used: if the value of a variable is required
577 // for the computation of a constant expression, it doesn't make sense to
578 // warn even if the variable isn't odr-used. (isReferenced doesn't
579 // precisely reflect that, but it's a decent approximation.)
580 if (VD->isReferenced() &&
581 VD->isUsableInConstantExpressions(SemaRef->Context))
582 return true;
583
584 if (VarTemplateDecl *Template = VD->getDescribedVarTemplate())
585 // If this is a variable template and none of its specializations is used,
586 // we should warn.
587 for (const auto *Spec : Template->specializations())
588 if (ShouldRemoveFromUnused(SemaRef, Spec))
589 return true;
590
591 // UnusedFileScopedDecls stores the first declaration.
592 // The declaration may have become definition so check again.
593 const VarDecl *DeclToCheck = VD->getDefinition();
594 if (DeclToCheck)
595 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck);
596
597 // Later redecls may add new information resulting in not having to warn,
598 // so check again.
599 DeclToCheck = VD->getMostRecentDecl();
600 if (DeclToCheck != VD)
601 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck);
602 }
603
604 return false;
605}
606
607static bool isFunctionOrVarDeclExternC(NamedDecl *ND) {
608 if (auto *FD = dyn_cast<FunctionDecl>(ND))
609 return FD->isExternC();
610 return cast<VarDecl>(ND)->isExternC();
611}
612
613/// Determine whether ND is an external-linkage function or variable whose
614/// type has no linkage.
615bool Sema::isExternalWithNoLinkageType(ValueDecl *VD) {
616 // Note: it's not quite enough to check whether VD has UniqueExternalLinkage,
617 // because we also want to catch the case where its type has VisibleNoLinkage,
618 // which does not affect the linkage of VD.
619 return getLangOpts().CPlusPlus && VD->hasExternalFormalLinkage() &&
620 !isExternalFormalLinkage(VD->getType()->getLinkage()) &&
621 !isFunctionOrVarDeclExternC(VD);
622}
623
624/// Obtains a sorted list of functions and variables that are undefined but
625/// ODR-used.
626void Sema::getUndefinedButUsed(
627 SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined) {
628 for (const auto &UndefinedUse : UndefinedButUsed) {
629 NamedDecl *ND = UndefinedUse.first;
630
631 // Ignore attributes that have become invalid.
632 if (ND->isInvalidDecl()) continue;
633
634 // __attribute__((weakref)) is basically a definition.
635 if (ND->hasAttr<WeakRefAttr>()) continue;
636
637 if (isa<CXXDeductionGuideDecl>(ND))
638 continue;
639
640 if (ND->hasAttr<DLLImportAttr>() || ND->hasAttr<DLLExportAttr>()) {
641 // An exported function will always be emitted when defined, so even if
642 // the function is inline, it doesn't have to be emitted in this TU. An
643 // imported function implies that it has been exported somewhere else.
644 continue;
645 }
646
647 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
648 if (FD->isDefined())
649 continue;
650 if (FD->isExternallyVisible() &&
651 !isExternalWithNoLinkageType(FD) &&
652 !FD->getMostRecentDecl()->isInlined() &&
653 !FD->hasAttr<ExcludeFromExplicitInstantiationAttr>())
654 continue;
655 if (FD->getBuiltinID())
656 continue;
657 } else {
658 auto *VD = cast<VarDecl>(ND);
659 if (VD->hasDefinition() != VarDecl::DeclarationOnly)
660 continue;
661 if (VD->isExternallyVisible() &&
662 !isExternalWithNoLinkageType(VD) &&
663 !VD->getMostRecentDecl()->isInline() &&
664 !VD->hasAttr<ExcludeFromExplicitInstantiationAttr>())
665 continue;
666
667 // Skip VarDecls that lack formal definitions but which we know are in
668 // fact defined somewhere.
669 if (VD->isKnownToBeDefined())
670 continue;
671 }
672
673 Undefined.push_back(std::make_pair(ND, UndefinedUse.second));
674 }
675}
676
677/// checkUndefinedButUsed - Check for undefined objects with internal linkage
678/// or that are inline.
679static void checkUndefinedButUsed(Sema &S) {
680 if (S.UndefinedButUsed.empty()) return;
681
682 // Collect all the still-undefined entities with internal linkage.
683 SmallVector<std::pair<NamedDecl *, SourceLocation>, 16> Undefined;
684 S.getUndefinedButUsed(Undefined);
685 if (Undefined.empty()) return;
686
687 for (auto Undef : Undefined) {
688 ValueDecl *VD = cast<ValueDecl>(Undef.first);
689 SourceLocation UseLoc = Undef.second;
690
691 if (S.isExternalWithNoLinkageType(VD)) {
692 // C++ [basic.link]p8:
693 // A type without linkage shall not be used as the type of a variable
694 // or function with external linkage unless
695 // -- the entity has C language linkage
696 // -- the entity is not odr-used or is defined in the same TU
697 //
698 // As an extension, accept this in cases where the type is externally
699 // visible, since the function or variable actually can be defined in
700 // another translation unit in that case.
701 S.Diag(VD->getLocation(), isExternallyVisible(VD->getType()->getLinkage())
702 ? diag::ext_undefined_internal_type
703 : diag::err_undefined_internal_type)
704 << isa<VarDecl>(VD) << VD;
705 } else if (!VD->isExternallyVisible()) {
706 // FIXME: We can promote this to an error. The function or variable can't
707 // be defined anywhere else, so the program must necessarily violate the
708 // one definition rule.
709 S.Diag(VD->getLocation(), diag::warn_undefined_internal)
710 << isa<VarDecl>(VD) << VD;
711 } else if (auto *FD = dyn_cast<FunctionDecl>(VD)) {
712 (void)FD;
713 assert(FD->getMostRecentDecl()->isInlined() &&((FD->getMostRecentDecl()->isInlined() && "used object requires definition but isn't inline or internal?"
) ? static_cast<void> (0) : __assert_fail ("FD->getMostRecentDecl()->isInlined() && \"used object requires definition but isn't inline or internal?\""
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 714, __PRETTY_FUNCTION__))
714 "used object requires definition but isn't inline or internal?")((FD->getMostRecentDecl()->isInlined() && "used object requires definition but isn't inline or internal?"
) ? static_cast<void> (0) : __assert_fail ("FD->getMostRecentDecl()->isInlined() && \"used object requires definition but isn't inline or internal?\""
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 714, __PRETTY_FUNCTION__))
;
715 // FIXME: This is ill-formed; we should reject.
716 S.Diag(VD->getLocation(), diag::warn_undefined_inline) << VD;
717 } else {
718 assert(cast<VarDecl>(VD)->getMostRecentDecl()->isInline() &&((cast<VarDecl>(VD)->getMostRecentDecl()->isInline
() && "used var requires definition but isn't inline or internal?"
) ? static_cast<void> (0) : __assert_fail ("cast<VarDecl>(VD)->getMostRecentDecl()->isInline() && \"used var requires definition but isn't inline or internal?\""
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 719, __PRETTY_FUNCTION__))
719 "used var requires definition but isn't inline or internal?")((cast<VarDecl>(VD)->getMostRecentDecl()->isInline
() && "used var requires definition but isn't inline or internal?"
) ? static_cast<void> (0) : __assert_fail ("cast<VarDecl>(VD)->getMostRecentDecl()->isInline() && \"used var requires definition but isn't inline or internal?\""
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 719, __PRETTY_FUNCTION__))
;
720 S.Diag(VD->getLocation(), diag::err_undefined_inline_var) << VD;
721 }
722 if (UseLoc.isValid())
723 S.Diag(UseLoc, diag::note_used_here);
724 }
725
726 S.UndefinedButUsed.clear();
727}
728
729void Sema::LoadExternalWeakUndeclaredIdentifiers() {
730 if (!ExternalSource)
731 return;
732
733 SmallVector<std::pair<IdentifierInfo *, WeakInfo>, 4> WeakIDs;
734 ExternalSource->ReadWeakUndeclaredIdentifiers(WeakIDs);
735 for (auto &WeakID : WeakIDs)
736 WeakUndeclaredIdentifiers.insert(WeakID);
737}
738
739
740typedef llvm::DenseMap<const CXXRecordDecl*, bool> RecordCompleteMap;
741
742/// Returns true, if all methods and nested classes of the given
743/// CXXRecordDecl are defined in this translation unit.
744///
745/// Should only be called from ActOnEndOfTranslationUnit so that all
746/// definitions are actually read.
747static bool MethodsAndNestedClassesComplete(const CXXRecordDecl *RD,
748 RecordCompleteMap &MNCComplete) {
749 RecordCompleteMap::iterator Cache = MNCComplete.find(RD);
750 if (Cache != MNCComplete.end())
751 return Cache->second;
752 if (!RD->isCompleteDefinition())
753 return false;
754 bool Complete = true;
755 for (DeclContext::decl_iterator I = RD->decls_begin(),
756 E = RD->decls_end();
757 I != E && Complete; ++I) {
758 if (const CXXMethodDecl *M = dyn_cast<CXXMethodDecl>(*I))
759 Complete = M->isDefined() || M->isDefaulted() ||
760 (M->isPure() && !isa<CXXDestructorDecl>(M));
761 else if (const FunctionTemplateDecl *F = dyn_cast<FunctionTemplateDecl>(*I))
762 // If the template function is marked as late template parsed at this
763 // point, it has not been instantiated and therefore we have not
764 // performed semantic analysis on it yet, so we cannot know if the type
765 // can be considered complete.
766 Complete = !F->getTemplatedDecl()->isLateTemplateParsed() &&
767 F->getTemplatedDecl()->isDefined();
768 else if (const CXXRecordDecl *R = dyn_cast<CXXRecordDecl>(*I)) {
769 if (R->isInjectedClassName())
770 continue;
771 if (R->hasDefinition())
772 Complete = MethodsAndNestedClassesComplete(R->getDefinition(),
773 MNCComplete);
774 else
775 Complete = false;
776 }
777 }
778 MNCComplete[RD] = Complete;
779 return Complete;
780}
781
782/// Returns true, if the given CXXRecordDecl is fully defined in this
783/// translation unit, i.e. all methods are defined or pure virtual and all
784/// friends, friend functions and nested classes are fully defined in this
785/// translation unit.
786///
787/// Should only be called from ActOnEndOfTranslationUnit so that all
788/// definitions are actually read.
789static bool IsRecordFullyDefined(const CXXRecordDecl *RD,
790 RecordCompleteMap &RecordsComplete,
791 RecordCompleteMap &MNCComplete) {
792 RecordCompleteMap::iterator Cache = RecordsComplete.find(RD);
793 if (Cache != RecordsComplete.end())
794 return Cache->second;
795 bool Complete = MethodsAndNestedClassesComplete(RD, MNCComplete);
796 for (CXXRecordDecl::friend_iterator I = RD->friend_begin(),
797 E = RD->friend_end();
798 I != E && Complete; ++I) {
799 // Check if friend classes and methods are complete.
800 if (TypeSourceInfo *TSI = (*I)->getFriendType()) {
801 // Friend classes are available as the TypeSourceInfo of the FriendDecl.
802 if (CXXRecordDecl *FriendD = TSI->getType()->getAsCXXRecordDecl())
803 Complete = MethodsAndNestedClassesComplete(FriendD, MNCComplete);
804 else
805 Complete = false;
806 } else {
807 // Friend functions are available through the NamedDecl of FriendDecl.
808 if (const FunctionDecl *FD =
809 dyn_cast<FunctionDecl>((*I)->getFriendDecl()))
810 Complete = FD->isDefined();
811 else
812 // This is a template friend, give up.
813 Complete = false;
814 }
815 }
816 RecordsComplete[RD] = Complete;
817 return Complete;
818}
819
820void Sema::emitAndClearUnusedLocalTypedefWarnings() {
821 if (ExternalSource)
822 ExternalSource->ReadUnusedLocalTypedefNameCandidates(
823 UnusedLocalTypedefNameCandidates);
824 for (const TypedefNameDecl *TD : UnusedLocalTypedefNameCandidates) {
825 if (TD->isReferenced())
826 continue;
827 Diag(TD->getLocation(), diag::warn_unused_local_typedef)
828 << isa<TypeAliasDecl>(TD) << TD->getDeclName();
829 }
830 UnusedLocalTypedefNameCandidates.clear();
831}
832
833/// This is called before the very first declaration in the translation unit
834/// is parsed. Note that the ASTContext may have already injected some
835/// declarations.
836void Sema::ActOnStartOfTranslationUnit() {
837 if (getLangOpts().ModulesTS &&
838 (getLangOpts().getCompilingModule() == LangOptions::CMK_ModuleInterface ||
839 getLangOpts().getCompilingModule() == LangOptions::CMK_None)) {
840 SourceLocation StartOfTU =
841 SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
842
843 // We start in the global module; all those declarations are implicitly
844 // module-private (though they do not have module linkage).
845 auto &Map = PP.getHeaderSearchInfo().getModuleMap();
846 auto *GlobalModule = Map.createGlobalModuleForInterfaceUnit(StartOfTU);
847 assert(GlobalModule && "module creation should not fail")((GlobalModule && "module creation should not fail") ?
static_cast<void> (0) : __assert_fail ("GlobalModule && \"module creation should not fail\""
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 847, __PRETTY_FUNCTION__))
;
848
849 // Enter the scope of the global module.
850 ModuleScopes.push_back({});
851 ModuleScopes.back().Module = GlobalModule;
852 VisibleModules.setVisible(GlobalModule, StartOfTU);
853
854 // All declarations created from now on are owned by the global module.
855 auto *TU = Context.getTranslationUnitDecl();
856 TU->setModuleOwnershipKind(Decl::ModuleOwnershipKind::Visible);
857 TU->setLocalOwningModule(GlobalModule);
858 }
859}
860
861/// ActOnEndOfTranslationUnit - This is called at the very end of the
862/// translation unit when EOF is reached and all but the top-level scope is
863/// popped.
864void Sema::ActOnEndOfTranslationUnit() {
865 assert(DelayedDiagnostics.getCurrentPool() == nullptr((DelayedDiagnostics.getCurrentPool() == nullptr && "reached end of translation unit with a pool attached?"
) ? static_cast<void> (0) : __assert_fail ("DelayedDiagnostics.getCurrentPool() == nullptr && \"reached end of translation unit with a pool attached?\""
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 866, __PRETTY_FUNCTION__))
866 && "reached end of translation unit with a pool attached?")((DelayedDiagnostics.getCurrentPool() == nullptr && "reached end of translation unit with a pool attached?"
) ? static_cast<void> (0) : __assert_fail ("DelayedDiagnostics.getCurrentPool() == nullptr && \"reached end of translation unit with a pool attached?\""
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 866, __PRETTY_FUNCTION__))
;
867
868 // If code completion is enabled, don't perform any end-of-translation-unit
869 // work.
870 if (PP.isCodeCompletionEnabled())
871 return;
872
873 // Transfer late parsed template instantiations over to the pending template
874 // instantiation list. During normal compliation, the late template parser
875 // will be installed and instantiating these templates will succeed.
876 //
877 // If we are building a TU prefix for serialization, it is also safe to
878 // transfer these over, even though they are not parsed. The end of the TU
879 // should be outside of any eager template instantiation scope, so when this
880 // AST is deserialized, these templates will not be parsed until the end of
881 // the combined TU.
882 PendingInstantiations.insert(PendingInstantiations.end(),
883 LateParsedInstantiations.begin(),
884 LateParsedInstantiations.end());
885 LateParsedInstantiations.clear();
886
887 // Complete translation units and modules define vtables and perform implicit
888 // instantiations. PCH files do not.
889 if (TUKind != TU_Prefix) {
890 DiagnoseUseOfUnimplementedSelectors();
891
892 // If DefinedUsedVTables ends up marking any virtual member functions it
893 // might lead to more pending template instantiations, which we then need
894 // to instantiate.
895 DefineUsedVTables();
896
897 // C++: Perform implicit template instantiations.
898 //
899 // FIXME: When we perform these implicit instantiations, we do not
900 // carefully keep track of the point of instantiation (C++ [temp.point]).
901 // This means that name lookup that occurs within the template
902 // instantiation will always happen at the end of the translation unit,
903 // so it will find some names that are not required to be found. This is
904 // valid, but we could do better by diagnosing if an instantiation uses a
905 // name that was not visible at its first point of instantiation.
906 if (ExternalSource) {
907 // Load pending instantiations from the external source.
908 SmallVector<PendingImplicitInstantiation, 4> Pending;
909 ExternalSource->ReadPendingInstantiations(Pending);
910 for (auto PII : Pending)
911 if (auto Func = dyn_cast<FunctionDecl>(PII.first))
912 Func->setInstantiationIsPending(true);
913 PendingInstantiations.insert(PendingInstantiations.begin(),
914 Pending.begin(), Pending.end());
915 }
916
917 PerformPendingInstantiations();
918
919 assert(LateParsedInstantiations.empty() &&((LateParsedInstantiations.empty() && "end of TU template instantiation should not create more "
"late-parsed templates") ? static_cast<void> (0) : __assert_fail
("LateParsedInstantiations.empty() && \"end of TU template instantiation should not create more \" \"late-parsed templates\""
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 921, __PRETTY_FUNCTION__))
920 "end of TU template instantiation should not create more "((LateParsedInstantiations.empty() && "end of TU template instantiation should not create more "
"late-parsed templates") ? static_cast<void> (0) : __assert_fail
("LateParsedInstantiations.empty() && \"end of TU template instantiation should not create more \" \"late-parsed templates\""
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 921, __PRETTY_FUNCTION__))
921 "late-parsed templates")((LateParsedInstantiations.empty() && "end of TU template instantiation should not create more "
"late-parsed templates") ? static_cast<void> (0) : __assert_fail
("LateParsedInstantiations.empty() && \"end of TU template instantiation should not create more \" \"late-parsed templates\""
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 921, __PRETTY_FUNCTION__))
;
922
923 if (LateTemplateParserCleanup)
924 LateTemplateParserCleanup(OpaqueParser);
925
926 CheckDelayedMemberExceptionSpecs();
927 }
928
929 DiagnoseUnterminatedPragmaPack();
930 DiagnoseUnterminatedPragmaAttribute();
931
932 // All delayed member exception specs should be checked or we end up accepting
933 // incompatible declarations.
934 assert(DelayedOverridingExceptionSpecChecks.empty())((DelayedOverridingExceptionSpecChecks.empty()) ? static_cast
<void> (0) : __assert_fail ("DelayedOverridingExceptionSpecChecks.empty()"
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 934, __PRETTY_FUNCTION__))
;
935 assert(DelayedEquivalentExceptionSpecChecks.empty())((DelayedEquivalentExceptionSpecChecks.empty()) ? static_cast
<void> (0) : __assert_fail ("DelayedEquivalentExceptionSpecChecks.empty()"
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 935, __PRETTY_FUNCTION__))
;
936 assert(DelayedDefaultedMemberExceptionSpecs.empty())((DelayedDefaultedMemberExceptionSpecs.empty()) ? static_cast
<void> (0) : __assert_fail ("DelayedDefaultedMemberExceptionSpecs.empty()"
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 936, __PRETTY_FUNCTION__))
;
937
938 // All dllexport classes should have been processed already.
939 assert(DelayedDllExportClasses.empty())((DelayedDllExportClasses.empty()) ? static_cast<void> (
0) : __assert_fail ("DelayedDllExportClasses.empty()", "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 939, __PRETTY_FUNCTION__))
;
940
941 // Remove file scoped decls that turned out to be used.
942 UnusedFileScopedDecls.erase(
943 std::remove_if(UnusedFileScopedDecls.begin(nullptr, true),
944 UnusedFileScopedDecls.end(),
945 [this](const DeclaratorDecl *DD) {
946 return ShouldRemoveFromUnused(this, DD);
947 }),
948 UnusedFileScopedDecls.end());
949
950 if (TUKind == TU_Prefix) {
951 // Translation unit prefixes don't need any of the checking below.
952 if (!PP.isIncrementalProcessingEnabled())
953 TUScope = nullptr;
954 return;
955 }
956
957 // Check for #pragma weak identifiers that were never declared
958 LoadExternalWeakUndeclaredIdentifiers();
959 for (auto WeakID : WeakUndeclaredIdentifiers) {
960 if (WeakID.second.getUsed())
961 continue;
962
963 Decl *PrevDecl = LookupSingleName(TUScope, WeakID.first, SourceLocation(),
964 LookupOrdinaryName);
965 if (PrevDecl != nullptr &&
966 !(isa<FunctionDecl>(PrevDecl) || isa<VarDecl>(PrevDecl)))
967 Diag(WeakID.second.getLocation(), diag::warn_attribute_wrong_decl_type)
968 << "'weak'" << ExpectedVariableOrFunction;
969 else
970 Diag(WeakID.second.getLocation(), diag::warn_weak_identifier_undeclared)
971 << WeakID.first;
972 }
973
974 if (LangOpts.CPlusPlus11 &&
975 !Diags.isIgnored(diag::warn_delegating_ctor_cycle, SourceLocation()))
976 CheckDelegatingCtorCycles();
977
978 if (!Diags.hasErrorOccurred()) {
979 if (ExternalSource)
980 ExternalSource->ReadUndefinedButUsed(UndefinedButUsed);
981 checkUndefinedButUsed(*this);
982 }
983
984 if (TUKind == TU_Module) {
985 // If we are building a module interface unit, we need to have seen the
986 // module declaration by now.
987 if (getLangOpts().getCompilingModule() ==
988 LangOptions::CMK_ModuleInterface &&
989 (ModuleScopes.empty() ||
990 ModuleScopes.back().Module->Kind != Module::ModuleInterfaceUnit)) {
991 // FIXME: Make a better guess as to where to put the module declaration.
992 Diag(getSourceManager().getLocForStartOfFile(
993 getSourceManager().getMainFileID()),
994 diag::err_module_declaration_missing);
995 }
996
997 // If we are building a module, resolve all of the exported declarations
998 // now.
999 if (Module *CurrentModule = PP.getCurrentModule()) {
1000 ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap();
1001
1002 SmallVector<Module *, 2> Stack;
1003 Stack.push_back(CurrentModule);
1004 while (!Stack.empty()) {
1005 Module *Mod = Stack.pop_back_val();
1006
1007 // Resolve the exported declarations and conflicts.
1008 // FIXME: Actually complain, once we figure out how to teach the
1009 // diagnostic client to deal with complaints in the module map at this
1010 // point.
1011 ModMap.resolveExports(Mod, /*Complain=*/false);
1012 ModMap.resolveUses(Mod, /*Complain=*/false);
1013 ModMap.resolveConflicts(Mod, /*Complain=*/false);
1014
1015 // Queue the submodules, so their exports will also be resolved.
1016 Stack.append(Mod->submodule_begin(), Mod->submodule_end());
1017 }
1018 }
1019
1020 // Warnings emitted in ActOnEndOfTranslationUnit() should be emitted for
1021 // modules when they are built, not every time they are used.
1022 emitAndClearUnusedLocalTypedefWarnings();
1023 }
1024
1025 // C99 6.9.2p2:
1026 // A declaration of an identifier for an object that has file
1027 // scope without an initializer, and without a storage-class
1028 // specifier or with the storage-class specifier static,
1029 // constitutes a tentative definition. If a translation unit
1030 // contains one or more tentative definitions for an identifier,
1031 // and the translation unit contains no external definition for
1032 // that identifier, then the behavior is exactly as if the
1033 // translation unit contains a file scope declaration of that
1034 // identifier, with the composite type as of the end of the
1035 // translation unit, with an initializer equal to 0.
1036 llvm::SmallSet<VarDecl *, 32> Seen;
1037 for (TentativeDefinitionsType::iterator
1038 T = TentativeDefinitions.begin(ExternalSource),
1039 TEnd = TentativeDefinitions.end();
1040 T != TEnd; ++T) {
1041 VarDecl *VD = (*T)->getActingDefinition();
1042
1043 // If the tentative definition was completed, getActingDefinition() returns
1044 // null. If we've already seen this variable before, insert()'s second
1045 // return value is false.
1046 if (!VD || VD->isInvalidDecl() || !Seen.insert(VD).second)
1047 continue;
1048
1049 if (const IncompleteArrayType *ArrayT
1050 = Context.getAsIncompleteArrayType(VD->getType())) {
1051 // Set the length of the array to 1 (C99 6.9.2p5).
1052 Diag(VD->getLocation(), diag::warn_tentative_incomplete_array);
1053 llvm::APInt One(Context.getTypeSize(Context.getSizeType()), true);
1054 QualType T = Context.getConstantArrayType(ArrayT->getElementType(),
1055 One, ArrayType::Normal, 0);
1056 VD->setType(T);
1057 } else if (RequireCompleteType(VD->getLocation(), VD->getType(),
1058 diag::err_tentative_def_incomplete_type))
1059 VD->setInvalidDecl();
1060
1061 // No initialization is performed for a tentative definition.
1062 CheckCompleteVariableDeclaration(VD);
1063
1064 // Notify the consumer that we've completed a tentative definition.
1065 if (!VD->isInvalidDecl())
1066 Consumer.CompleteTentativeDefinition(VD);
1067 }
1068
1069 // If there were errors, disable 'unused' warnings since they will mostly be
1070 // noise. Don't warn for a use from a module: either we should warn on all
1071 // file-scope declarations in modules or not at all, but whether the
1072 // declaration is used is immaterial.
1073 if (!Diags.hasErrorOccurred() && TUKind != TU_Module) {
1074 // Output warning for unused file scoped decls.
1075 for (UnusedFileScopedDeclsType::iterator
1076 I = UnusedFileScopedDecls.begin(ExternalSource),
1077 E = UnusedFileScopedDecls.end(); I != E; ++I) {
1078 if (ShouldRemoveFromUnused(this, *I))
1079 continue;
1080
1081 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) {
1082 const FunctionDecl *DiagD;
1083 if (!FD->hasBody(DiagD))
1084 DiagD = FD;
1085 if (DiagD->isDeleted())
1086 continue; // Deleted functions are supposed to be unused.
1087 if (DiagD->isReferenced()) {
1088 if (isa<CXXMethodDecl>(DiagD))
1089 Diag(DiagD->getLocation(), diag::warn_unneeded_member_function)
1090 << DiagD->getDeclName();
1091 else {
1092 if (FD->getStorageClass() == SC_Static &&
1093 !FD->isInlineSpecified() &&
1094 !SourceMgr.isInMainFile(
1095 SourceMgr.getExpansionLoc(FD->getLocation())))
1096 Diag(DiagD->getLocation(),
1097 diag::warn_unneeded_static_internal_decl)
1098 << DiagD->getDeclName();
1099 else
1100 Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
1101 << /*function*/0 << DiagD->getDeclName();
1102 }
1103 } else {
1104 if (FD->getDescribedFunctionTemplate())
1105 Diag(DiagD->getLocation(), diag::warn_unused_template)
1106 << /*function*/0 << DiagD->getDeclName();
1107 else
1108 Diag(DiagD->getLocation(),
1109 isa<CXXMethodDecl>(DiagD) ? diag::warn_unused_member_function
1110 : diag::warn_unused_function)
1111 << DiagD->getDeclName();
1112 }
1113 } else {
1114 const VarDecl *DiagD = cast<VarDecl>(*I)->getDefinition();
1115 if (!DiagD)
1116 DiagD = cast<VarDecl>(*I);
1117 if (DiagD->isReferenced()) {
1118 Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
1119 << /*variable*/1 << DiagD->getDeclName();
1120 } else if (DiagD->getType().isConstQualified()) {
1121 const SourceManager &SM = SourceMgr;
1122 if (SM.getMainFileID() != SM.getFileID(DiagD->getLocation()) ||
1123 !PP.getLangOpts().IsHeaderFile)
1124 Diag(DiagD->getLocation(), diag::warn_unused_const_variable)
1125 << DiagD->getDeclName();
1126 } else {
1127 if (DiagD->getDescribedVarTemplate())
1128 Diag(DiagD->getLocation(), diag::warn_unused_template)
1129 << /*variable*/1 << DiagD->getDeclName();
1130 else
1131 Diag(DiagD->getLocation(), diag::warn_unused_variable)
1132 << DiagD->getDeclName();
1133 }
1134 }
1135 }
1136
1137 emitAndClearUnusedLocalTypedefWarnings();
1138 }
1139
1140 if (!Diags.isIgnored(diag::warn_unused_private_field, SourceLocation())) {
1141 // FIXME: Load additional unused private field candidates from the external
1142 // source.
1143 RecordCompleteMap RecordsComplete;
1144 RecordCompleteMap MNCComplete;
1145 for (NamedDeclSetType::iterator I = UnusedPrivateFields.begin(),
1146 E = UnusedPrivateFields.end(); I != E; ++I) {
1147 const NamedDecl *D = *I;
1148 const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D->getDeclContext());
1149 if (RD && !RD->isUnion() &&
1150 IsRecordFullyDefined(RD, RecordsComplete, MNCComplete)) {
1151 Diag(D->getLocation(), diag::warn_unused_private_field)
1152 << D->getDeclName();
1153 }
1154 }
1155 }
1156
1157 if (!Diags.isIgnored(diag::warn_mismatched_delete_new, SourceLocation())) {
1158 if (ExternalSource)
1159 ExternalSource->ReadMismatchingDeleteExpressions(DeleteExprs);
1160 for (const auto &DeletedFieldInfo : DeleteExprs) {
1161 for (const auto &DeleteExprLoc : DeletedFieldInfo.second) {
1162 AnalyzeDeleteExprMismatch(DeletedFieldInfo.first, DeleteExprLoc.first,
1163 DeleteExprLoc.second);
1164 }
1165 }
1166 }
1167
1168 // Check we've noticed that we're no longer parsing the initializer for every
1169 // variable. If we miss cases, then at best we have a performance issue and
1170 // at worst a rejects-valid bug.
1171 assert(ParsingInitForAutoVars.empty() &&((ParsingInitForAutoVars.empty() && "Didn't unmark var as having its initializer parsed"
) ? static_cast<void> (0) : __assert_fail ("ParsingInitForAutoVars.empty() && \"Didn't unmark var as having its initializer parsed\""
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 1172, __PRETTY_FUNCTION__))
1172 "Didn't unmark var as having its initializer parsed")((ParsingInitForAutoVars.empty() && "Didn't unmark var as having its initializer parsed"
) ? static_cast<void> (0) : __assert_fail ("ParsingInitForAutoVars.empty() && \"Didn't unmark var as having its initializer parsed\""
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 1172, __PRETTY_FUNCTION__))
;
1173
1174 if (!PP.isIncrementalProcessingEnabled())
1175 TUScope = nullptr;
1176}
1177
1178
1179//===----------------------------------------------------------------------===//
1180// Helper functions.
1181//===----------------------------------------------------------------------===//
1182
1183DeclContext *Sema::getFunctionLevelDeclContext() {
1184 DeclContext *DC = CurContext;
1185
1186 while (true) {
1187 if (isa<BlockDecl>(DC) || isa<EnumDecl>(DC) || isa<CapturedDecl>(DC)) {
1188 DC = DC->getParent();
1189 } else if (isa<CXXMethodDecl>(DC) &&
1190 cast<CXXMethodDecl>(DC)->getOverloadedOperator() == OO_Call &&
1191 cast<CXXRecordDecl>(DC->getParent())->isLambda()) {
1192 DC = DC->getParent()->getParent();
1193 }
1194 else break;
1195 }
1196
1197 return DC;
1198}
1199
1200/// getCurFunctionDecl - If inside of a function body, this returns a pointer
1201/// to the function decl for the function being parsed. If we're currently
1202/// in a 'block', this returns the containing context.
1203FunctionDecl *Sema::getCurFunctionDecl() {
1204 DeclContext *DC = getFunctionLevelDeclContext();
1205 return dyn_cast<FunctionDecl>(DC);
1206}
1207
1208ObjCMethodDecl *Sema::getCurMethodDecl() {
1209 DeclContext *DC = getFunctionLevelDeclContext();
1210 while (isa<RecordDecl>(DC))
1211 DC = DC->getParent();
1212 return dyn_cast<ObjCMethodDecl>(DC);
1213}
1214
1215NamedDecl *Sema::getCurFunctionOrMethodDecl() {
1216 DeclContext *DC = getFunctionLevelDeclContext();
1217 if (isa<ObjCMethodDecl>(DC) || isa<FunctionDecl>(DC))
1218 return cast<NamedDecl>(DC);
1219 return nullptr;
1220}
1221
1222void Sema::EmitCurrentDiagnostic(unsigned DiagID) {
1223 // FIXME: It doesn't make sense to me that DiagID is an incoming argument here
1224 // and yet we also use the current diag ID on the DiagnosticsEngine. This has
1225 // been made more painfully obvious by the refactor that introduced this
1226 // function, but it is possible that the incoming argument can be
1227 // eliminated. If it truly cannot be (for example, there is some reentrancy
1228 // issue I am not seeing yet), then there should at least be a clarifying
1229 // comment somewhere.
1230 if (Optional<TemplateDeductionInfo*> Info = isSFINAEContext()) {
1231 switch (DiagnosticIDs::getDiagnosticSFINAEResponse(
1232 Diags.getCurrentDiagID())) {
1233 case DiagnosticIDs::SFINAE_Report:
1234 // We'll report the diagnostic below.
1235 break;
1236
1237 case DiagnosticIDs::SFINAE_SubstitutionFailure:
1238 // Count this failure so that we know that template argument deduction
1239 // has failed.
1240 ++NumSFINAEErrors;
1241
1242 // Make a copy of this suppressed diagnostic and store it with the
1243 // template-deduction information.
1244 if (*Info && !(*Info)->hasSFINAEDiagnostic()) {
1245 Diagnostic DiagInfo(&Diags);
1246 (*Info)->addSFINAEDiagnostic(DiagInfo.getLocation(),
1247 PartialDiagnostic(DiagInfo, Context.getDiagAllocator()));
1248 }
1249
1250 Diags.setLastDiagnosticIgnored();
1251 Diags.Clear();
1252 return;
1253
1254 case DiagnosticIDs::SFINAE_AccessControl: {
1255 // Per C++ Core Issue 1170, access control is part of SFINAE.
1256 // Additionally, the AccessCheckingSFINAE flag can be used to temporarily
1257 // make access control a part of SFINAE for the purposes of checking
1258 // type traits.
1259 if (!AccessCheckingSFINAE && !getLangOpts().CPlusPlus11)
1260 break;
1261
1262 SourceLocation Loc = Diags.getCurrentDiagLoc();
1263
1264 // Suppress this diagnostic.
1265 ++NumSFINAEErrors;
1266
1267 // Make a copy of this suppressed diagnostic and store it with the
1268 // template-deduction information.
1269 if (*Info && !(*Info)->hasSFINAEDiagnostic()) {
1270 Diagnostic DiagInfo(&Diags);
1271 (*Info)->addSFINAEDiagnostic(DiagInfo.getLocation(),
1272 PartialDiagnostic(DiagInfo, Context.getDiagAllocator()));
1273 }
1274
1275 Diags.setLastDiagnosticIgnored();
1276 Diags.Clear();
1277
1278 // Now the diagnostic state is clear, produce a C++98 compatibility
1279 // warning.
1280 Diag(Loc, diag::warn_cxx98_compat_sfinae_access_control);
1281
1282 // The last diagnostic which Sema produced was ignored. Suppress any
1283 // notes attached to it.
1284 Diags.setLastDiagnosticIgnored();
1285 return;
1286 }
1287
1288 case DiagnosticIDs::SFINAE_Suppress:
1289 // Make a copy of this suppressed diagnostic and store it with the
1290 // template-deduction information;
1291 if (*Info) {
1292 Diagnostic DiagInfo(&Diags);
1293 (*Info)->addSuppressedDiagnostic(DiagInfo.getLocation(),
1294 PartialDiagnostic(DiagInfo, Context.getDiagAllocator()));
1295 }
1296
1297 // Suppress this diagnostic.
1298 Diags.setLastDiagnosticIgnored();
1299 Diags.Clear();
1300 return;
1301 }
1302 }
1303
1304 // Copy the diagnostic printing policy over the ASTContext printing policy.
1305 // TODO: Stop doing that. See: https://reviews.llvm.org/D45093#1090292
1306 Context.setPrintingPolicy(getPrintingPolicy());
1307
1308 // Emit the diagnostic.
1309 if (!Diags.EmitCurrentDiagnostic())
1310 return;
1311
1312 // If this is not a note, and we're in a template instantiation
1313 // that is different from the last template instantiation where
1314 // we emitted an error, print a template instantiation
1315 // backtrace.
1316 if (!DiagnosticIDs::isBuiltinNote(DiagID))
1317 PrintContextStack();
1318}
1319
1320Sema::SemaDiagnosticBuilder
1321Sema::Diag(SourceLocation Loc, const PartialDiagnostic& PD) {
1322 SemaDiagnosticBuilder Builder(Diag(Loc, PD.getDiagID()));
1323 PD.Emit(Builder);
1324
1325 return Builder;
1326}
1327
1328/// Looks through the macro-expansion chain for the given
1329/// location, looking for a macro expansion with the given name.
1330/// If one is found, returns true and sets the location to that
1331/// expansion loc.
1332bool Sema::findMacroSpelling(SourceLocation &locref, StringRef name) {
1333 SourceLocation loc = locref;
1334 if (!loc.isMacroID()) return false;
1335
1336 // There's no good way right now to look at the intermediate
1337 // expansions, so just jump to the expansion location.
1338 loc = getSourceManager().getExpansionLoc(loc);
1339
1340 // If that's written with the name, stop here.
1341 SmallVector<char, 16> buffer;
1342 if (getPreprocessor().getSpelling(loc, buffer) == name) {
1343 locref = loc;
1344 return true;
1345 }
1346 return false;
1347}
1348
1349/// Determines the active Scope associated with the given declaration
1350/// context.
1351///
1352/// This routine maps a declaration context to the active Scope object that
1353/// represents that declaration context in the parser. It is typically used
1354/// from "scope-less" code (e.g., template instantiation, lazy creation of
1355/// declarations) that injects a name for name-lookup purposes and, therefore,
1356/// must update the Scope.
1357///
1358/// \returns The scope corresponding to the given declaraion context, or NULL
1359/// if no such scope is open.
1360Scope *Sema::getScopeForContext(DeclContext *Ctx) {
1361
1362 if (!Ctx)
1363 return nullptr;
1364
1365 Ctx = Ctx->getPrimaryContext();
1366 for (Scope *S = getCurScope(); S; S = S->getParent()) {
1367 // Ignore scopes that cannot have declarations. This is important for
1368 // out-of-line definitions of static class members.
1369 if (S->getFlags() & (Scope::DeclScope | Scope::TemplateParamScope))
1370 if (DeclContext *Entity = S->getEntity())
1371 if (Ctx == Entity->getPrimaryContext())
1372 return S;
1373 }
1374
1375 return nullptr;
1376}
1377
1378/// Enter a new function scope
1379void Sema::PushFunctionScope() {
1380 if (FunctionScopes.empty()) {
1381 // Use PreallocatedFunctionScope to avoid allocating memory when possible.
1382 PreallocatedFunctionScope->Clear();
1383 FunctionScopes.push_back(PreallocatedFunctionScope.get());
1384 } else {
1385 FunctionScopes.push_back(new FunctionScopeInfo(getDiagnostics()));
1386 }
1387 if (LangOpts.OpenMP)
1388 pushOpenMPFunctionRegion();
1389}
1390
1391void Sema::PushBlockScope(Scope *BlockScope, BlockDecl *Block) {
1392 FunctionScopes.push_back(new BlockScopeInfo(getDiagnostics(),
1393 BlockScope, Block));
1394}
1395
1396LambdaScopeInfo *Sema::PushLambdaScope() {
1397 LambdaScopeInfo *const LSI = new LambdaScopeInfo(getDiagnostics());
1398 FunctionScopes.push_back(LSI);
1399 return LSI;
1400}
1401
1402void Sema::RecordParsingTemplateParameterDepth(unsigned Depth) {
1403 if (LambdaScopeInfo *const LSI = getCurLambda()) {
1404 LSI->AutoTemplateParameterDepth = Depth;
1405 return;
1406 }
1407 llvm_unreachable(::llvm::llvm_unreachable_internal("Remove assertion if intentionally called in a non-lambda context."
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 1408)
1408 "Remove assertion if intentionally called in a non-lambda context.")::llvm::llvm_unreachable_internal("Remove assertion if intentionally called in a non-lambda context."
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 1408)
;
1409}
1410
1411// Check that the type of the VarDecl has an accessible copy constructor and
1412// resolve its destructor's exception spefication.
1413static void checkEscapingByref(VarDecl *VD, Sema &S) {
1414 QualType T = VD->getType();
1415 EnterExpressionEvaluationContext scope(
1416 S, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
1417 SourceLocation Loc = VD->getLocation();
1418 Expr *VarRef =
1419 new (S.Context) DeclRefExpr(S.Context, VD, false, T, VK_LValue, Loc);
1420 ExprResult Result = S.PerformMoveOrCopyInitialization(
1421 InitializedEntity::InitializeBlock(Loc, T, false), VD, VD->getType(),
1422 VarRef, /*AllowNRVO=*/true);
1423 if (!Result.isInvalid()) {
1424 Result = S.MaybeCreateExprWithCleanups(Result);
1425 Expr *Init = Result.getAs<Expr>();
1426 S.Context.setBlockVarCopyInit(VD, Init, S.canThrow(Init));
1427 }
1428
1429 // The destructor's exception spefication is needed when IRGen generates
1430 // block copy/destroy functions. Resolve it here.
1431 if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl())
1432 if (CXXDestructorDecl *DD = RD->getDestructor()) {
1433 auto *FPT = DD->getType()->getAs<FunctionProtoType>();
1434 S.ResolveExceptionSpec(Loc, FPT);
1435 }
1436}
1437
1438static void markEscapingByrefs(const FunctionScopeInfo &FSI, Sema &S) {
1439 // Set the EscapingByref flag of __block variables captured by
1440 // escaping blocks.
1441 for (const BlockDecl *BD : FSI.Blocks) {
1442 if (BD->doesNotEscape())
1443 continue;
1444 for (const BlockDecl::Capture &BC : BD->captures()) {
1445 VarDecl *VD = BC.getVariable();
1446 if (VD->hasAttr<BlocksAttr>())
1447 VD->setEscapingByref();
1448 }
1449 }
1450
1451 for (VarDecl *VD : FSI.ByrefBlockVars) {
1452 // __block variables might require us to capture a copy-initializer.
1453 if (!VD->isEscapingByref())
1454 continue;
1455 // It's currently invalid to ever have a __block variable with an
1456 // array type; should we diagnose that here?
1457 // Regardless, we don't want to ignore array nesting when
1458 // constructing this copy.
1459 if (VD->getType()->isStructureOrClassType())
1460 checkEscapingByref(VD, S);
1461 }
1462}
1463
1464void Sema::PopFunctionScopeInfo(const AnalysisBasedWarnings::Policy *WP,
1465 const Decl *D, const BlockExpr *blkExpr) {
1466 assert(!FunctionScopes.empty() && "mismatched push/pop!")((!FunctionScopes.empty() && "mismatched push/pop!") ?
static_cast<void> (0) : __assert_fail ("!FunctionScopes.empty() && \"mismatched push/pop!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 1466, __PRETTY_FUNCTION__))
;
1467
1468 // This function shouldn't be called after popping the current function scope.
1469 // markEscapingByrefs calls PerformMoveOrCopyInitialization, which can call
1470 // PushFunctionScope, which can cause clearing out PreallocatedFunctionScope
1471 // when FunctionScopes is empty.
1472 markEscapingByrefs(*FunctionScopes.back(), *this);
1473
1474 FunctionScopeInfo *Scope = FunctionScopes.pop_back_val();
1475
1476 if (LangOpts.OpenMP)
1477 popOpenMPFunctionRegion(Scope);
1478
1479 // Issue any analysis-based warnings.
1480 if (WP && D)
1481 AnalysisWarnings.IssueWarnings(*WP, Scope, D, blkExpr);
1482 else
1483 for (const auto &PUD : Scope->PossiblyUnreachableDiags)
1484 Diag(PUD.Loc, PUD.PD);
1485
1486 // Delete the scope unless its our preallocated scope.
1487 if (Scope != PreallocatedFunctionScope.get())
1488 delete Scope;
1489}
1490
1491void Sema::PushCompoundScope(bool IsStmtExpr) {
1492 getCurFunction()->CompoundScopes.push_back(CompoundScopeInfo(IsStmtExpr));
1493}
1494
1495void Sema::PopCompoundScope() {
1496 FunctionScopeInfo *CurFunction = getCurFunction();
1497 assert(!CurFunction->CompoundScopes.empty() && "mismatched push/pop")((!CurFunction->CompoundScopes.empty() && "mismatched push/pop"
) ? static_cast<void> (0) : __assert_fail ("!CurFunction->CompoundScopes.empty() && \"mismatched push/pop\""
, "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 1497, __PRETTY_FUNCTION__))
;
1498
1499 CurFunction->CompoundScopes.pop_back();
1500}
1501
1502/// Determine whether any errors occurred within this function/method/
1503/// block.
1504bool Sema::hasAnyUnrecoverableErrorsInThisFunction() const {
1505 return getCurFunction()->ErrorTrap.hasUnrecoverableErrorOccurred();
1506}
1507
1508void Sema::setFunctionHasBranchIntoScope() {
1509 if (!FunctionScopes.empty())
1510 FunctionScopes.back()->setHasBranchIntoScope();
1511}
1512
1513void Sema::setFunctionHasBranchProtectedScope() {
1514 if (!FunctionScopes.empty())
1515 FunctionScopes.back()->setHasBranchProtectedScope();
1516}
1517
1518void Sema::setFunctionHasIndirectGoto() {
1519 if (!FunctionScopes.empty())
1520 FunctionScopes.back()->setHasIndirectGoto();
1521}
1522
1523BlockScopeInfo *Sema::getCurBlock() {
1524 if (FunctionScopes.empty())
1525 return nullptr;
1526
1527 auto CurBSI = dyn_cast<BlockScopeInfo>(FunctionScopes.back());
1528 if (CurBSI && CurBSI->TheDecl &&
1529 !CurBSI->TheDecl->Encloses(CurContext)) {
1530 // We have switched contexts due to template instantiation.
1531 assert(!CodeSynthesisContexts.empty())((!CodeSynthesisContexts.empty()) ? static_cast<void> (
0) : __assert_fail ("!CodeSynthesisContexts.empty()", "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 1531, __PRETTY_FUNCTION__))
;
1532 return nullptr;
1533 }
1534
1535 return CurBSI;
1536}
1537
1538FunctionScopeInfo *Sema::getEnclosingFunction() const {
1539 if (FunctionScopes.empty())
1540 return nullptr;
1541
1542 for (int e = FunctionScopes.size() - 1; e >= 0; --e) {
1543 if (isa<sema::BlockScopeInfo>(FunctionScopes[e]))
1544 continue;
1545 return FunctionScopes[e];
1546 }
1547 return nullptr;
1548}
1549
1550LambdaScopeInfo *Sema::getCurLambda(bool IgnoreNonLambdaCapturingScope) {
1551 if (FunctionScopes.empty())
1552 return nullptr;
1553
1554 auto I = FunctionScopes.rbegin();
1555 if (IgnoreNonLambdaCapturingScope) {
1556 auto E = FunctionScopes.rend();
1557 while (I != E && isa<CapturingScopeInfo>(*I) && !isa<LambdaScopeInfo>(*I))
1558 ++I;
1559 if (I == E)
1560 return nullptr;
1561 }
1562 auto *CurLSI = dyn_cast<LambdaScopeInfo>(*I);
1563 if (CurLSI && CurLSI->Lambda &&
1564 !CurLSI->Lambda->Encloses(CurContext)) {
1565 // We have switched contexts due to template instantiation.
1566 assert(!CodeSynthesisContexts.empty())((!CodeSynthesisContexts.empty()) ? static_cast<void> (
0) : __assert_fail ("!CodeSynthesisContexts.empty()", "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 1566, __PRETTY_FUNCTION__))
;
1567 return nullptr;
1568 }
1569
1570 return CurLSI;
1571}
1572// We have a generic lambda if we parsed auto parameters, or we have
1573// an associated template parameter list.
1574LambdaScopeInfo *Sema::getCurGenericLambda() {
1575 if (LambdaScopeInfo *LSI = getCurLambda()) {
1576 return (LSI->AutoTemplateParams.size() ||
1577 LSI->GLTemplateParameterList) ? LSI : nullptr;
1578 }
1579 return nullptr;
1580}
1581
1582
1583void Sema::ActOnComment(SourceRange Comment) {
1584 if (!LangOpts.RetainCommentsFromSystemHeaders &&
1585 SourceMgr.isInSystemHeader(Comment.getBegin()))
1586 return;
1587 RawComment RC(SourceMgr, Comment, LangOpts.CommentOpts, false);
1588 if (RC.isAlmostTrailingComment()) {
1589 SourceRange MagicMarkerRange(Comment.getBegin(),
1590 Comment.getBegin().getLocWithOffset(3));
1591 StringRef MagicMarkerText;
1592 switch (RC.getKind()) {
1593 case RawComment::RCK_OrdinaryBCPL:
1594 MagicMarkerText = "///<";
1595 break;
1596 case RawComment::RCK_OrdinaryC:
1597 MagicMarkerText = "/**<";
1598 break;
1599 default:
1600 llvm_unreachable("if this is an almost Doxygen comment, "::llvm::llvm_unreachable_internal("if this is an almost Doxygen comment, "
"it should be ordinary", "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 1601)
1601 "it should be ordinary")::llvm::llvm_unreachable_internal("if this is an almost Doxygen comment, "
"it should be ordinary", "/build/llvm-toolchain-snapshot-8~svn350071/tools/clang/lib/Sema/Sema.cpp"
, 1601)
;
1602 }
1603 Diag(Comment.getBegin(), diag::warn_not_a_doxygen_trailing_member_comment) <<
1604 FixItHint::CreateReplacement(MagicMarkerRange, MagicMarkerText);
1605 }
1606 Context.addComment(RC);
1607}
1608
1609// Pin this vtable to this file.
1610ExternalSemaSource::~ExternalSemaSource() {}
1611
1612void ExternalSemaSource::ReadMethodPool(Selector Sel) { }
1613void ExternalSemaSource::updateOutOfDateSelector(Selector Sel) { }
1614
1615void ExternalSemaSource::ReadKnownNamespaces(
1616 SmallVectorImpl<NamespaceDecl *> &Namespaces) {
1617}
1618
1619void ExternalSemaSource::ReadUndefinedButUsed(
1620 llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) {}
1621
1622void ExternalSemaSource::ReadMismatchingDeleteExpressions(llvm::MapVector<
1623 FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &) {}
1624
1625/// Figure out if an expression could be turned into a call.
1626///
1627/// Use this when trying to recover from an error where the programmer may have
1628/// written just the name of a function instead of actually calling it.
1629///
1630/// \param E - The expression to examine.
1631/// \param ZeroArgCallReturnTy - If the expression can be turned into a call
1632/// with no arguments, this parameter is set to the type returned by such a
1633/// call; otherwise, it is set to an empty QualType.
1634/// \param OverloadSet - If the expression is an overloaded function
1635/// name, this parameter is populated with the decls of the various overloads.
1636bool Sema::tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy,
1637 UnresolvedSetImpl &OverloadSet) {
1638 ZeroArgCallReturnTy = QualType();
1639 OverloadSet.clear();
1640
1641 const OverloadExpr *Overloads = nullptr;
1642 bool IsMemExpr = false;
1643 if (E.getType() == Context.OverloadTy) {
1644 OverloadExpr::FindResult FR = OverloadExpr::find(const_cast<Expr*>(&E));
1645
1646 // Ignore overloads that are pointer-to-member constants.
1647 if (FR.HasFormOfMemberPointer)
1648 return false;
1649
1650 Overloads = FR.Expression;
1651 } else if (E.getType() == Context.BoundMemberTy) {
1652 Overloads = dyn_cast<UnresolvedMemberExpr>(E.IgnoreParens());
1653 IsMemExpr = true;
1654 }
1655
1656 bool Ambiguous = false;
1657 bool IsMV = false;
1658
1659 if (Overloads) {
1660 for (OverloadExpr::decls_iterator it = Overloads->decls_begin(),
1661 DeclsEnd = Overloads->decls_end(); it != DeclsEnd; ++it) {
1662 OverloadSet.addDecl(*it);
1663
1664 // Check whether the function is a non-template, non-member which takes no
1665 // arguments.
1666 if (IsMemExpr)
1667 continue;
1668 if (const FunctionDecl *OverloadDecl
1669 = dyn_cast<FunctionDecl>((*it)->getUnderlyingDecl())) {
1670 if (OverloadDecl->getMinRequiredArguments() == 0) {
1671 if (!ZeroArgCallReturnTy.isNull() && !Ambiguous &&
1672 (!IsMV || !(OverloadDecl->isCPUDispatchMultiVersion() ||
1673 OverloadDecl->isCPUSpecificMultiVersion()))) {
1674 ZeroArgCallReturnTy = QualType();
1675 Ambiguous = true;
1676 } else {
1677 ZeroArgCallReturnTy = OverloadDecl->getReturnType();
1678 IsMV = OverloadDecl->isCPUDispatchMultiVersion() ||
1679 OverloadDecl->isCPUSpecificMultiVersion();
1680 }
1681 }
1682 }
1683 }
1684
1685 // If it's not a member, use better machinery to try to resolve the call
1686 if (!IsMemExpr)
1687 return !ZeroArgCallReturnTy.isNull();
1688 }
1689
1690 // Attempt to call the member with no arguments - this will correctly handle
1691 // member templates with defaults/deduction of template arguments, overloads
1692 // with default arguments, etc.
1693 if (IsMemExpr && !E.isTypeDependent()) {
1694 bool Suppress = getDiagnostics().getSuppressAllDiagnostics();
1695 getDiagnostics().setSuppressAllDiagnostics(true);
1696 ExprResult R = BuildCallToMemberFunction(nullptr, &E, SourceLocation(),
1697 None, SourceLocation());
1698 getDiagnostics().setSuppressAllDiagnostics(Suppress);
1699 if (R.isUsable()) {
1700 ZeroArgCallReturnTy = R.get()->getType();
1701 return true;
1702 }
1703 return false;
1704 }
1705
1706 if (const DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E.IgnoreParens())) {
1707 if (const FunctionDecl *Fun = dyn_cast<FunctionDecl>(DeclRef->getDecl())) {
1708 if (Fun->getMinRequiredArguments() == 0)
1709 ZeroArgCallReturnTy = Fun->getReturnType();
1710 return true;
1711 }
1712 }
1713
1714 // We don't have an expression that's convenient to get a FunctionDecl from,
1715 // but we can at least check if the type is "function of 0 arguments".
1716 QualType ExprTy = E.getType();
1717 const FunctionType *FunTy = nullptr;
1718 QualType PointeeTy = ExprTy->getPointeeType();
1719 if (!PointeeTy.isNull())
1720 FunTy = PointeeTy->getAs<FunctionType>();
1721 if (!FunTy)
1722 FunTy = ExprTy->getAs<FunctionType>();
1723
1724 if (const FunctionProtoType *FPT =
1725 dyn_cast_or_null<FunctionProtoType>(FunTy)) {
1726 if (FPT->getNumParams() == 0)
1727 ZeroArgCallReturnTy = FunTy->getReturnType();
1728 return true;
1729 }
1730 return false;
1731}
1732
1733/// Give notes for a set of overloads.
1734///
1735/// A companion to tryExprAsCall. In cases when the name that the programmer
1736/// wrote was an overloaded function, we may be able to make some guesses about
1737/// plausible overloads based on their return types; such guesses can be handed
1738/// off to this method to be emitted as notes.
1739///
1740/// \param Overloads - The overloads to note.
1741/// \param FinalNoteLoc - If we've suppressed printing some overloads due to
1742/// -fshow-overloads=best, this is the location to attach to the note about too
1743/// many candidates. Typically this will be the location of the original
1744/// ill-formed expression.
1745static void noteOverloads(Sema &S, const UnresolvedSetImpl &Overloads,
1746 const SourceLocation FinalNoteLoc) {
1747 int ShownOverloads = 0;
1748 int SuppressedOverloads = 0;
1749 for (UnresolvedSetImpl::iterator It = Overloads.begin(),
1750 DeclsEnd = Overloads.end(); It != DeclsEnd; ++It) {
1751 // FIXME: Magic number for max shown overloads stolen from
1752 // OverloadCandidateSet::NoteCandidates.
1753 if (ShownOverloads >= 4 && S.Diags.getShowOverloads() == Ovl_Best) {
1754 ++SuppressedOverloads;
1755 continue;
1756 }
1757
1758 NamedDecl *Fn = (*It)->getUnderlyingDecl();
1759 // Don't print overloads for non-default multiversioned functions.
1760 if (const auto *FD = Fn->getAsFunction()) {
1761 if (FD->isMultiVersion() && FD->hasAttr<TargetAttr>() &&
1762 !FD->getAttr<TargetAttr>()->isDefaultVersion())
1763 continue;
1764 }
1765 S.Diag(Fn->getLocation(), diag::note_possible_target_of_call);
1766 ++ShownOverloads;
1767 }
1768
1769 if (SuppressedOverloads)
1770 S.Diag(FinalNoteLoc, diag::note_ovl_too_many_candidates)
1771 << SuppressedOverloads;
1772}
1773
1774static void notePlausibleOverloads(Sema &S, SourceLocation Loc,
1775 const UnresolvedSetImpl &Overloads,
1776 bool (*IsPlausibleResult)(QualType)) {
1777 if (!IsPlausibleResult)
1778 return noteOverloads(S, Overloads, Loc);
1779
1780 UnresolvedSet<2> PlausibleOverloads;
1781 for (OverloadExpr::decls_iterator It = Overloads.begin(),
1782 DeclsEnd = Overloads.end(); It != DeclsEnd; ++It) {
1783 const FunctionDecl *OverloadDecl = cast<FunctionDecl>(*It);
1784 QualType OverloadResultTy = OverloadDecl->getReturnType();
1785 if (IsPlausibleResult(OverloadResultTy))
1786 PlausibleOverloads.addDecl(It.getDecl());
1787 }
1788 noteOverloads(S, PlausibleOverloads, Loc);
1789}
1790
1791/// Determine whether the given expression can be called by just
1792/// putting parentheses after it. Notably, expressions with unary
1793/// operators can't be because the unary operator will start parsing
1794/// outside the call.
1795static bool IsCallableWithAppend(Expr *E) {
1796 E = E->IgnoreImplicit();
1797 return (!isa<CStyleCastExpr>(E) &&
1798 !isa<UnaryOperator>(E) &&
1799 !isa<BinaryOperator>(E) &&
1800 !isa<CXXOperatorCallExpr>(E));
1801}
1802
1803static bool IsCPUDispatchCPUSpecificMultiVersion(const Expr *E) {
1804 if (const auto *UO = dyn_cast<UnaryOperator>(E))
1805 E = UO->getSubExpr();
1806
1807 if (const auto *ULE = dyn_cast<UnresolvedLookupExpr>(E)) {
1808 if (ULE->getNumDecls() == 0)
1809 return false;
1810
1811 const NamedDecl *ND = *ULE->decls_begin();
1812 if (const auto *FD = dyn_cast<FunctionDecl>(ND))
1813 return FD->isCPUDispatchMultiVersion() || FD->isCPUSpecificMultiVersion();
1814 }
1815 return false;
1816}
1817
1818bool Sema::tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD,
1819 bool ForceComplain,
1820 bool (*IsPlausibleResult)(QualType)) {
1821 SourceLocation Loc = E.get()->getExprLoc();
1822 SourceRange Range = E.get()->getSourceRange();
1823
1824 QualType ZeroArgCallTy;
1825 UnresolvedSet<4> Overloads;
1826 if (tryExprAsCall(*E.get(), ZeroArgCallTy, Overloads) &&
1827 !ZeroArgCallTy.isNull() &&
1828 (!IsPlausibleResult || IsPlausibleResult(ZeroArgCallTy))) {
1829 // At this point, we know E is potentially callable with 0
1830 // arguments and that it returns something of a reasonable type,
1831 // so we can emit a fixit and carry on pretending that E was
1832 // actually a CallExpr.
1833 SourceLocation ParenInsertionLoc = getLocForEndOfToken(Range.getEnd());
1834 bool IsMV = IsCPUDispatchCPUSpecificMultiVersion(E.get());
1835 Diag(Loc, PD) << /*zero-arg*/ 1 << IsMV << Range
1836 << (IsCallableWithAppend(E.get())
1837 ? FixItHint::CreateInsertion(ParenInsertionLoc, "()")
1838 : FixItHint());
1839 if (!IsMV)
1840 notePlausibleOverloads(*this, Loc, Overloads, IsPlausibleResult);
1841
1842 // FIXME: Try this before emitting the fixit, and suppress diagnostics
1843 // while doing so.
1844 E = ActOnCallExpr(nullptr, E.get(), Range.getEnd(), None,
1845 Range.getEnd().getLocWithOffset(1));
1846 return true;
1847 }
1848
1849 if (!ForceComplain) return false;
1850
1851 bool IsMV = IsCPUDispatchCPUSpecificMultiVersion(E.get());
1852 Diag(Loc, PD) << /*not zero-arg*/ 0 << IsMV << Range;
1853 if (!IsMV)
1854 notePlausibleOverloads(*this, Loc, Overloads, IsPlausibleResult);
1855 E = ExprError();
1856 return true;
1857}
1858
1859IdentifierInfo *Sema::getSuperIdentifier() const {
1860 if (!Ident_super)
1861 Ident_super = &Context.Idents.get("super");
1862 return Ident_super;
1863}
1864
1865IdentifierInfo *Sema::getFloat128Identifier() const {
1866 if (!Ident___float128)
1867 Ident___float128 = &Context.Idents.get("__float128");
1868 return Ident___float128;
1869}
1870
1871void Sema::PushCapturedRegionScope(Scope *S, CapturedDecl *CD, RecordDecl *RD,
1872 CapturedRegionKind K) {
1873 CapturingScopeInfo *CSI = new CapturedRegionScopeInfo(
1874 getDiagnostics(), S, CD, RD, CD->getContextParam(), K,
1875 (getLangOpts().OpenMP && K == CR_OpenMP) ? getOpenMPNestingLevel() : 0);
1876 CSI->ReturnType = Context.VoidTy;
1877 FunctionScopes.push_back(CSI);
1878}
1879
1880CapturedRegionScopeInfo *Sema::getCurCapturedRegion() {
1881 if (FunctionScopes.empty())
1882 return nullptr;
1883
1884 return dyn_cast<CapturedRegionScopeInfo>(FunctionScopes.back());
1885}
1886
1887const llvm::MapVector<FieldDecl *, Sema::DeleteLocs> &
1888Sema::getMismatchingDeleteExpressions() const {
1889 return DeleteExprs;
1890}
1891
1892void Sema::setOpenCLExtensionForType(QualType T, llvm::StringRef ExtStr) {
1893 if (ExtStr.empty())
1894 return;
1895 llvm::SmallVector<StringRef, 1> Exts;
1896 ExtStr.split(Exts, " ", /* limit */ -1, /* keep empty */ false);
1897 auto CanT = T.getCanonicalType().getTypePtr();
1898 for (auto &I : Exts)
1899 OpenCLTypeExtMap[CanT].insert(I.str());
1900}
1901
1902void Sema::setOpenCLExtensionForDecl(Decl *FD, StringRef ExtStr) {
1903 llvm::SmallVector<StringRef, 1> Exts;
1904 ExtStr.split(Exts, " ", /* limit */ -1, /* keep empty */ false);
1905 if (Exts.empty())
1906 return;
1907 for (auto &I : Exts)
1908 OpenCLDeclExtMap[FD].insert(I.str());
1909}
1910
1911void Sema::setCurrentOpenCLExtensionForType(QualType T) {
1912 if (CurrOpenCLExtension.empty())
1913 return;
1914 setOpenCLExtensionForType(T, CurrOpenCLExtension);
1915}
1916
1917void Sema::setCurrentOpenCLExtensionForDecl(Decl *D) {
1918 if (CurrOpenCLExtension.empty())
1919 return;
1920 setOpenCLExtensionForDecl(D, CurrOpenCLExtension);
1921}
1922
1923std::string Sema::getOpenCLExtensionsFromDeclExtMap(FunctionDecl *FD) {
1924 if (!OpenCLDeclExtMap.empty())
1925 return getOpenCLExtensionsFromExtMap(FD, OpenCLDeclExtMap);
1926
1927 return "";
1928}
1929
1930std::string Sema::getOpenCLExtensionsFromTypeExtMap(FunctionType *FT) {
1931 if (!OpenCLTypeExtMap.empty())
1932 return getOpenCLExtensionsFromExtMap(FT, OpenCLTypeExtMap);
1933
1934 return "";
1935}
1936
1937template <typename T, typename MapT>
1938std::string Sema::getOpenCLExtensionsFromExtMap(T *FDT, MapT &Map) {
1939 std::string ExtensionNames = "";
1940 auto Loc = Map.find(FDT);
1941
1942 for (auto const& I : Loc->second) {
1943 ExtensionNames += I;
1944 ExtensionNames += " ";
1945 }
1946 ExtensionNames.pop_back();
1947
1948 return ExtensionNames;
1949}
1950
1951bool Sema::isOpenCLDisabledDecl(Decl *FD) {
1952 auto Loc = OpenCLDeclExtMap.find(FD);
1953 if (Loc == OpenCLDeclExtMap.end())
1954 return false;
1955 for (auto &I : Loc->second) {
1956 if (!getOpenCLOptions().isEnabled(I))
1957 return true;
1958 }
1959 return false;
1960}
1961
1962template <typename T, typename DiagLocT, typename DiagInfoT, typename MapT>
1963bool Sema::checkOpenCLDisabledTypeOrDecl(T D, DiagLocT DiagLoc,
1964 DiagInfoT DiagInfo, MapT &Map,
1965 unsigned Selector,
1966 SourceRange SrcRange) {
1967 auto Loc = Map.find(D);
1968 if (Loc == Map.end())
1969 return false;
1970 bool Disabled = false;
1971 for (auto &I : Loc->second) {
1972 if (I != CurrOpenCLExtension && !getOpenCLOptions().isEnabled(I)) {
1973 Diag(DiagLoc, diag::err_opencl_requires_extension) << Selector << DiagInfo
1974 << I << SrcRange;
1975 Disabled = true;
1976 }
1977 }
1978 return Disabled;
1979}
1980
1981bool Sema::checkOpenCLDisabledTypeDeclSpec(const DeclSpec &DS, QualType QT) {
1982 // Check extensions for declared types.
1983 Decl *Decl = nullptr;
1984 if (auto TypedefT = dyn_cast<TypedefType>(QT.getTypePtr()))
1985 Decl = TypedefT->getDecl();
1986 if (auto TagT = dyn_cast<TagType>(QT.getCanonicalType().getTypePtr()))
1987 Decl = TagT->getDecl();
1988 auto Loc = DS.getTypeSpecTypeLoc();
1989
1990 // Check extensions for vector types.
1991 // e.g. double4 is not allowed when cl_khr_fp64 is absent.
1992 if (QT->isExtVectorType()) {
1993 auto TypePtr = QT->castAs<ExtVectorType>()->getElementType().getTypePtr();
1994 return checkOpenCLDisabledTypeOrDecl(TypePtr, Loc, QT, OpenCLTypeExtMap);
1995 }
1996
1997 if (checkOpenCLDisabledTypeOrDecl(Decl, Loc, QT, OpenCLDeclExtMap))
1998 return true;
1999
2000 // Check extensions for builtin types.
2001 return checkOpenCLDisabledTypeOrDecl(QT.getCanonicalType().getTypePtr(), Loc,
2002 QT, OpenCLTypeExtMap);
2003}
2004
2005bool Sema::checkOpenCLDisabledDecl(const NamedDecl &D, const Expr &E) {
2006 IdentifierInfo *FnName = D.getIdentifier();
2007 return checkOpenCLDisabledTypeOrDecl(&D, E.getBeginLoc(), FnName,
2008 OpenCLDeclExtMap, 1, D.getSourceRange());
2009}

/build/llvm-toolchain-snapshot-8~svn350071/build-llvm/tools/clang/include/clang/AST/Attrs.inc

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
12class AArch64VectorPcsAttr : public InheritableAttr {
13public:
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
36class AMDGPUFlatWorkGroupSizeAttr : public InheritableAttr {
37unsigned min;
38
39unsigned max;
40
41public:
42 static AMDGPUFlatWorkGroupSizeAttr *CreateImplicit(ASTContext &Ctx, unsigned Min, unsigned 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 , unsigned Min
50 , unsigned 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 unsigned getMin() const {
64 return min;
65 }
66
67 unsigned getMax() const {
68 return max;
69 }
70
71
72
73 static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUFlatWorkGroupSize; }
74};
75
76class AMDGPUNumSGPRAttr : public InheritableAttr {
77unsigned numSGPR;
78
79public:
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
108class AMDGPUNumVGPRAttr : public InheritableAttr {
109unsigned numVGPR;
110
111public:
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
140class AMDGPUWavesPerEUAttr : public InheritableAttr {
141unsigned min;
142
143unsigned max;
144
145public:
146 static AMDGPUWavesPerEUAttr *CreateImplicit(ASTContext &Ctx, unsigned Min, unsigned 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 , unsigned Min
154 , unsigned 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 , unsigned 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 unsigned getMin() const {
178 return min;
179 }
180
181 unsigned getMax() const {
182 return max;
183 }
184
185
186
187 static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUWavesPerEU; }
188};
189
190class ARMInterruptAttr : public InheritableAttr {
191public:
192 enum InterruptType {
193 IRQ,
194 FIQ,
195 SWI,
196 ABORT,
197 UNDEF,
198 Generic
199 };
200private:
201 InterruptType interrupt;
202
203public:
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-8~svn350071/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
267class AVRInterruptAttr : public InheritableAttr {
268public:
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
291class AVRSignalAttr : public InheritableAttr {
292public:
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
315class AbiTagAttr : public Attr {
316 unsigned tags_Size;
317 StringRef *tags_;
318
319public:
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
368class AcquireCapabilityAttr : public InheritableAttr {
369 unsigned args_Size;
370 Expr * *args_;
371
372public:
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-8~svn350071/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
436class AcquiredAfterAttr : public InheritableAttr {
437 unsigned args_Size;
438 Expr * *args_;
439
440public:
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
481class AcquiredBeforeAttr : public InheritableAttr {
482 unsigned args_Size;
483 Expr * *args_;
484
485public:
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
526class AddressSpaceAttr : public TypeAttr {
527int addressSpace;
528
529public:
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
558class AliasAttr : public Attr {
559unsigned aliaseeLength;
560char *aliasee;
561
562public:
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
602class AlignMac68kAttr : public InheritableAttr {
603public:
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
626class AlignValueAttr : public Attr {
627Expr * alignment;
628
629public:
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
658class AlignedAttr : public InheritableAttr {
659bool isalignmentExpr;
660union {
661Expr *alignmentExpr;
662TypeSourceInfo *alignmentType;
663};
664
665public:
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-8~svn350071/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-8~svn350071/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-8~svn350071/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
740class AllocAlignAttr : public InheritableAttr {
741ParamIdx paramIndex;
742
743public:
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
772class AllocSizeAttr : public InheritableAttr {
773ParamIdx elemSizeParam;
774
775ParamIdx numElemsParam;
776
777public:
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
822class AlwaysDestroyAttr : public InheritableAttr {
823public:
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
846class AlwaysInlineAttr : public InheritableAttr {
847public:
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-8~svn350071/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
884class AnalyzerNoReturnAttr : public InheritableAttr {
885public:
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
908class AnnotateAttr : public InheritableParamAttr {
909unsigned annotationLength;
910char *annotation;
911
912public:
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
952class AnyX86InterruptAttr : public InheritableAttr {
953public:
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
976class AnyX86NoCallerSavedRegistersAttr : public InheritableAttr {
977public:
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
1000class AnyX86NoCfCheckAttr : public InheritableAttr {
1001public:
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
1024class ArcWeakrefUnavailableAttr : public InheritableAttr {
1025public:
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
1048class ArgumentWithTypeTagAttr : public InheritableAttr {
1049IdentifierInfo * argumentKind;
1050
1051ParamIdx argumentIdx;
1052
1053ParamIdx typeTagIdx;
1054
1055bool isPointer;
1056
1057public:
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-8~svn350071/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
1144class ArtificialAttr : public InheritableAttr {
1145public:
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
1168class AsmLabelAttr : public InheritableAttr {
1169unsigned labelLength;
1170char *label;
1171
1172public:
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
1212class AssertCapabilityAttr : public InheritableAttr {
1213 unsigned args_Size;
1214 Expr * *args_;
1215
1216public:
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-8~svn350071/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
1275class AssertExclusiveLockAttr : public InheritableAttr {
1276 unsigned args_Size;
1277 Expr * *args_;
1278
1279public:
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
1320class AssertSharedLockAttr : public InheritableAttr {
1321 unsigned args_Size;
1322 Expr * *args_;
1323
1324public:
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
1365class AssumeAlignedAttr : public InheritableAttr {
1366Expr * alignment;
1367
1368Expr * offset;
1369
1370public:
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
1415class AvailabilityAttr : public InheritableAttr {
1416IdentifierInfo * platform;
1417
1418VersionTuple introduced;
1419
1420
1421VersionTuple deprecated;
1422
1423
1424VersionTuple obsoleted;
1425
1426
1427bool unavailable;
1428
1429unsigned messageLength;
1430char *message;
1431
1432bool strict;
1433
1434unsigned replacementLength;
1435char *replacement;
1436
1437public:
1438 static AvailabilityAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Platform, VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted, bool Unavailable, llvm::StringRef Message, bool Strict, llvm::StringRef Replacement, SourceRange Loc = SourceRange()) {
1439 auto *A = new (Ctx) AvailabilityAttr(Loc, Ctx, Platform, Introduced, Deprecated, Obsoleted, Unavailable, Message, Strict, Replacement, 0);
1440 A->setImplicit(true);
1441 return A;
1442 }
1443
1444 AvailabilityAttr(SourceRange R, ASTContext &Ctx
1445 , IdentifierInfo * Platform
1446 , VersionTuple Introduced
1447 , VersionTuple Deprecated
1448 , VersionTuple Obsoleted
1449 , bool Unavailable
1450 , llvm::StringRef Message
1451 , bool Strict
1452 , llvm::StringRef Replacement
1453 , unsigned SI
1454 )
1455 : InheritableAttr(attr::Availability, R, SI, false, true)
1456 , platform(Platform)
1457 , introduced(Introduced)
1458 , deprecated(Deprecated)
1459 , obsoleted(Obsoleted)
1460 , unavailable(Unavailable)
1461 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
1462 , strict(Strict)
1463 , replacementLength(Replacement.size()),replacement(new (Ctx, 1) char[replacementLength])
1464 {
1465 if (!Message.empty())
1466 std::memcpy(message, Message.data(), messageLength);
1467 if (!Replacement.empty())
1468 std::memcpy(replacement, Replacement.data(), replacementLength);
1469 }
1470
1471 AvailabilityAttr *clone(ASTContext &C) const;
1472 void printPretty(raw_ostream &OS,
1473 const PrintingPolicy &Policy) const;
1474 const char *getSpelling() const;
1475 IdentifierInfo * getPlatform() const {
1476 return platform;
1477 }
1478
1479 VersionTuple getIntroduced() const {
1480 return introduced;
1481 }
1482 void setIntroduced(ASTContext &C, VersionTuple V) {
1483 introduced = V;
1484 }
1485
1486 VersionTuple getDeprecated() const {
1487 return deprecated;
1488 }
1489 void setDeprecated(ASTContext &C, VersionTuple V) {
1490 deprecated = V;
1491 }
1492
1493 VersionTuple getObsoleted() const {
1494 return obsoleted;
1495 }
1496 void setObsoleted(ASTContext &C, VersionTuple V) {
1497 obsoleted = V;
1498 }
1499
1500 bool getUnavailable() const {
1501 return unavailable;
1502 }
1503
1504 llvm::StringRef getMessage() const {
1505 return llvm::StringRef(message, messageLength);
1506 }
1507 unsigned getMessageLength() const {
1508 return messageLength;
1509 }
1510 void setMessage(ASTContext &C, llvm::StringRef S) {
1511 messageLength = S.size();
1512 this->message = new (C, 1) char [messageLength];
1513 if (!S.empty())
1514 std::memcpy(this->message, S.data(), messageLength);
1515 }
1516
1517 bool getStrict() const {
1518 return strict;
1519 }
1520
1521 llvm::StringRef getReplacement() const {
1522 return llvm::StringRef(replacement, replacementLength);
1523 }
1524 unsigned getReplacementLength() const {
1525 return replacementLength;
1526 }
1527 void setReplacement(ASTContext &C, llvm::StringRef S) {
1528 replacementLength = S.size();
1529 this->replacement = new (C, 1) char [replacementLength];
1530 if (!S.empty())
1531 std::memcpy(this->replacement, S.data(), replacementLength);
1532 }
1533
1534static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
1535 return llvm::StringSwitch<llvm::StringRef>(Platform)
1536 .Case("android", "Android")
1537 .Case("ios", "iOS")
1538 .Case("macos", "macOS")
1539 .Case("tvos", "tvOS")
1540 .Case("watchos", "watchOS")
1541 .Case("ios_app_extension", "iOS (App Extension)")
1542 .Case("macos_app_extension", "macOS (App Extension)")
1543 .Case("tvos_app_extension", "tvOS (App Extension)")
1544 .Case("watchos_app_extension", "watchOS (App Extension)")
1545 .Case("swift", "Swift")
1546 .Default(llvm::StringRef());
1547}
1548static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) {
1549 return llvm::StringSwitch<llvm::StringRef>(Platform)
1550 .Case("ios", "iOS")
1551 .Case("macos", "macOS")
1552 .Case("tvos", "tvOS")
1553 .Case("watchos", "watchOS")
1554 .Case("ios_app_extension", "iOSApplicationExtension")
1555 .Case("macos_app_extension", "macOSApplicationExtension")
1556 .Case("tvos_app_extension", "tvOSApplicationExtension")
1557 .Case("watchos_app_extension", "watchOSApplicationExtension")
1558 .Default(Platform);
1559}
1560static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) {
1561 return llvm::StringSwitch<llvm::StringRef>(Platform)
1562 .Case("iOS", "ios")
1563 .Case("macOS", "macos")
1564 .Case("tvOS", "tvos")
1565 .Case("watchOS", "watchos")
1566 .Case("iOSApplicationExtension", "ios_app_extension")
1567 .Case("macOSApplicationExtension", "macos_app_extension")
1568 .Case("tvOSApplicationExtension", "tvos_app_extension")
1569 .Case("watchOSApplicationExtension", "watchos_app_extension")
1570 .Default(Platform);
1571}
1572
1573 static bool classof(const Attr *A) { return A->getKind() == attr::Availability; }
1574};
1575
1576class BlocksAttr : public InheritableAttr {
1577public:
1578 enum BlockType {
1579 ByRef
1580 };
1581private:
1582 BlockType type;
1583
1584public:
1585 static BlocksAttr *CreateImplicit(ASTContext &Ctx, BlockType Type, SourceRange Loc = SourceRange()) {
1586 auto *A = new (Ctx) BlocksAttr(Loc, Ctx, Type, 0);
1587 A->setImplicit(true);
1588 return A;
1589 }
1590
1591 BlocksAttr(SourceRange R, ASTContext &Ctx
1592 , BlockType Type
1593 , unsigned SI
1594 )
1595 : InheritableAttr(attr::Blocks, R, SI, false, false)
1596 , type(Type)
1597 {
1598 }
1599
1600 BlocksAttr *clone(ASTContext &C) const;
1601 void printPretty(raw_ostream &OS,
1602 const PrintingPolicy &Policy) const;
1603 const char *getSpelling() const;
1604 BlockType getType() const {
1605 return type;
1606 }
1607
1608 static bool ConvertStrToBlockType(StringRef Val, BlockType &Out) {
1609 Optional<BlockType> R = llvm::StringSwitch<Optional<BlockType>>(Val)
1610 .Case("byref", BlocksAttr::ByRef)
1611 .Default(Optional<BlockType>());
1612 if (R) {
1613 Out = *R;
1614 return true;
1615 }
1616 return false;
1617 }
1618
1619 static const char *ConvertBlockTypeToStr(BlockType Val) {
1620 switch(Val) {
1621 case BlocksAttr::ByRef: return "byref";
1622 }
1623 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-8~svn350071/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 1623)
;
1624 }
1625
1626
1627 static bool classof(const Attr *A) { return A->getKind() == attr::Blocks; }
1628};
1629
1630class C11NoReturnAttr : public InheritableAttr {
1631public:
1632 static C11NoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1633 auto *A = new (Ctx) C11NoReturnAttr(Loc, Ctx, 0);
1634 A->setImplicit(true);
1635 return A;
1636 }
1637
1638 C11NoReturnAttr(SourceRange R, ASTContext &Ctx
1639 , unsigned SI
1640 )
1641 : InheritableAttr(attr::C11NoReturn, R, SI, false, false)
1642 {
1643 }
1644
1645 C11NoReturnAttr *clone(ASTContext &C) const;
1646 void printPretty(raw_ostream &OS,
1647 const PrintingPolicy &Policy) const;
1648 const char *getSpelling() const;
1649
1650
1651 static bool classof(const Attr *A) { return A->getKind() == attr::C11NoReturn; }
1652};
1653
1654class CDeclAttr : public InheritableAttr {
1655public:
1656 static CDeclAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1657 auto *A = new (Ctx) CDeclAttr(Loc, Ctx, 0);
1658 A->setImplicit(true);
1659 return A;
1660 }
1661
1662 CDeclAttr(SourceRange R, ASTContext &Ctx
1663 , unsigned SI
1664 )
1665 : InheritableAttr(attr::CDecl, R, SI, false, false)
1666 {
1667 }
1668
1669 CDeclAttr *clone(ASTContext &C) const;
1670 void printPretty(raw_ostream &OS,
1671 const PrintingPolicy &Policy) const;
1672 const char *getSpelling() const;
1673
1674
1675 static bool classof(const Attr *A) { return A->getKind() == attr::CDecl; }
1676};
1677
1678class CFAuditedTransferAttr : public InheritableAttr {
1679public:
1680 static CFAuditedTransferAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1681 auto *A = new (Ctx) CFAuditedTransferAttr(Loc, Ctx, 0);
1682 A->setImplicit(true);
1683 return A;
1684 }
1685
1686 CFAuditedTransferAttr(SourceRange R, ASTContext &Ctx
1687 , unsigned SI
1688 )
1689 : InheritableAttr(attr::CFAuditedTransfer, R, SI, false, false)
1690 {
1691 }
1692
1693 CFAuditedTransferAttr *clone(ASTContext &C) const;
1694 void printPretty(raw_ostream &OS,
1695 const PrintingPolicy &Policy) const;
1696 const char *getSpelling() const;
1697
1698
1699 static bool classof(const Attr *A) { return A->getKind() == attr::CFAuditedTransfer; }
1700};
1701
1702class CFConsumedAttr : public InheritableParamAttr {
1703public:
1704 static CFConsumedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1705 auto *A = new (Ctx) CFConsumedAttr(Loc, Ctx, 0);
1706 A->setImplicit(true);
1707 return A;
1708 }
1709
1710 CFConsumedAttr(SourceRange R, ASTContext &Ctx
1711 , unsigned SI
1712 )
1713 : InheritableParamAttr(attr::CFConsumed, R, SI, false, false)
1714 {
1715 }
1716
1717 CFConsumedAttr *clone(ASTContext &C) const;
1718 void printPretty(raw_ostream &OS,
1719 const PrintingPolicy &Policy) const;
1720 const char *getSpelling() const;
1721
1722
1723 static bool classof(const Attr *A) { return A->getKind() == attr::CFConsumed; }
1724};
1725
1726class CFReturnsNotRetainedAttr : public InheritableAttr {
1727public:
1728 static CFReturnsNotRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1729 auto *A = new (Ctx) CFReturnsNotRetainedAttr(Loc, Ctx, 0);
1730 A->setImplicit(true);
1731 return A;
1732 }
1733
1734 CFReturnsNotRetainedAttr(SourceRange R, ASTContext &Ctx
1735 , unsigned SI
1736 )
1737 : InheritableAttr(attr::CFReturnsNotRetained, R, SI, false, false)
1738 {
1739 }
1740
1741 CFReturnsNotRetainedAttr *clone(ASTContext &C) const;
1742 void printPretty(raw_ostream &OS,
1743 const PrintingPolicy &Policy) const;
1744 const char *getSpelling() const;
1745
1746
1747 static bool classof(const Attr *A) { return A->getKind() == attr::CFReturnsNotRetained; }
1748};
1749
1750class CFReturnsRetainedAttr : public InheritableAttr {
1751public:
1752 static CFReturnsRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1753 auto *A = new (Ctx) CFReturnsRetainedAttr(Loc, Ctx, 0);
1754 A->setImplicit(true);
1755 return A;
1756 }
1757
1758 CFReturnsRetainedAttr(SourceRange R, ASTContext &Ctx
1759 , unsigned SI
1760 )
1761 : InheritableAttr(attr::CFReturnsRetained, R, SI, false, false)
1762 {
1763 }
1764
1765 CFReturnsRetainedAttr *clone(ASTContext &C) const;
1766 void printPretty(raw_ostream &OS,
1767 const PrintingPolicy &Policy) const;
1768 const char *getSpelling() const;
1769
1770
1771 static bool classof(const Attr *A) { return A->getKind() == attr::CFReturnsRetained; }
1772};
1773
1774class CFUnknownTransferAttr : public InheritableAttr {
1775public:
1776 static CFUnknownTransferAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1777 auto *A = new (Ctx) CFUnknownTransferAttr(Loc, Ctx, 0);
1778 A->setImplicit(true);
1779 return A;
1780 }
1781
1782 CFUnknownTransferAttr(SourceRange R, ASTContext &Ctx
1783 , unsigned SI
1784 )
1785 : InheritableAttr(attr::CFUnknownTransfer, R, SI, false, false)
1786 {
1787 }
1788
1789 CFUnknownTransferAttr *clone(ASTContext &C) const;
1790 void printPretty(raw_ostream &OS,
1791 const PrintingPolicy &Policy) const;
1792 const char *getSpelling() const;
1793
1794
1795 static bool classof(const Attr *A) { return A->getKind() == attr::CFUnknownTransfer; }
1796};
1797
1798class CPUDispatchAttr : public InheritableAttr {
1799 unsigned cpus_Size;
1800 IdentifierInfo * *cpus_;
1801
1802public:
1803 static CPUDispatchAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * *Cpus, unsigned CpusSize, SourceRange Loc = SourceRange()) {
1804 auto *A = new (Ctx) CPUDispatchAttr(Loc, Ctx, Cpus, CpusSize, 0);
1805 A->setImplicit(true);
1806 return A;
1807 }
1808
1809 CPUDispatchAttr(SourceRange R, ASTContext &Ctx
1810 , IdentifierInfo * *Cpus, unsigned CpusSize
1811 , unsigned SI
1812 )
1813 : InheritableAttr(attr::CPUDispatch, R, SI, false, false)
1814 , cpus_Size(CpusSize), cpus_(new (Ctx, 16) IdentifierInfo *[cpus_Size])
1815 {
1816 std::copy(Cpus, Cpus + cpus_Size, cpus_);
1817 }
1818
1819 CPUDispatchAttr(SourceRange R, ASTContext &Ctx
1820 , unsigned SI
1821 )
1822 : InheritableAttr(attr::CPUDispatch, R, SI, false, false)
1823 , cpus_Size(0), cpus_(nullptr)
1824 {
1825 }
1826
1827 CPUDispatchAttr *clone(ASTContext &C) const;
1828 void printPretty(raw_ostream &OS,
1829 const PrintingPolicy &Policy) const;
1830 const char *getSpelling() const;
1831 typedef IdentifierInfo ** cpus_iterator;
1832 cpus_iterator cpus_begin() const { return cpus_; }
1833 cpus_iterator cpus_end() const { return cpus_ + cpus_Size; }
1834 unsigned cpus_size() const { return cpus_Size; }
1835 llvm::iterator_range<cpus_iterator> cpus() const { return llvm::make_range(cpus_begin(), cpus_end()); }
1836
1837
1838
1839
1840 static bool classof(const Attr *A) { return A->getKind() == attr::CPUDispatch; }
1841};
1842
1843class CPUSpecificAttr : public InheritableAttr {
1844 unsigned cpus_Size;
1845 IdentifierInfo * *cpus_;
1846
1847public:
1848 static CPUSpecificAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * *Cpus, unsigned CpusSize, SourceRange Loc = SourceRange()) {
1849 auto *A = new (Ctx) CPUSpecificAttr(Loc, Ctx, Cpus, CpusSize, 0);
1850 A->setImplicit(true);
1851 return A;
1852 }
1853
1854 CPUSpecificAttr(SourceRange R, ASTContext &Ctx
1855 , IdentifierInfo * *Cpus, unsigned CpusSize
1856 , unsigned SI
1857 )
1858 : InheritableAttr(attr::CPUSpecific, R, SI, false, false)
1859 , cpus_Size(CpusSize), cpus_(new (Ctx, 16) IdentifierInfo *[cpus_Size])
1860 {
1861 std::copy(Cpus, Cpus + cpus_Size, cpus_);
1862 }
1863
1864 CPUSpecificAttr(SourceRange R, ASTContext &Ctx
1865 , unsigned SI
1866 )
1867 : InheritableAttr(attr::CPUSpecific, R, SI, false, false)
1868 , cpus_Size(0), cpus_(nullptr)
1869 {
1870 }
1871
1872 CPUSpecificAttr *clone(ASTContext &C) const;
1873 void printPretty(raw_ostream &OS,
1874 const PrintingPolicy &Policy) const;
1875 const char *getSpelling() const;
1876 typedef IdentifierInfo ** cpus_iterator;
1877 cpus_iterator cpus_begin() const { return cpus_; }
1878 cpus_iterator cpus_end() const { return cpus_ + cpus_Size; }
1879 unsigned cpus_size() const { return cpus_Size; }
1880 llvm::iterator_range<cpus_iterator> cpus() const { return llvm::make_range(cpus_begin(), cpus_end()); }
1881
1882
1883
1884 IdentifierInfo *getCPUName(unsigned Index) const {
1885 return *(cpus_begin() + Index);
1886 }
1887
1888
1889 static bool classof(const Attr *A) { return A->getKind() == attr::CPUSpecific; }
1890};
1891
1892class CUDAConstantAttr : public InheritableAttr {
1893public:
1894 static CUDAConstantAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1895 auto *A = new (Ctx) CUDAConstantAttr(Loc, Ctx, 0);
1896 A->setImplicit(true);
1897 return A;
1898 }
1899
1900 CUDAConstantAttr(SourceRange R, ASTContext &Ctx
1901 , unsigned SI
1902 )
1903 : InheritableAttr(attr::CUDAConstant, R, SI, false, false)
1904 {
1905 }
1906
1907 CUDAConstantAttr *clone(ASTContext &C) const;
1908 void printPretty(raw_ostream &OS,
1909 const PrintingPolicy &Policy) const;
1910 const char *getSpelling() const;
1911
1912
1913 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAConstant; }
1914};
1915
1916class CUDADeviceAttr : public InheritableAttr {
1917public:
1918 static CUDADeviceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1919 auto *A = new (Ctx) CUDADeviceAttr(Loc, Ctx, 0);
1920 A->setImplicit(true);
1921 return A;
1922 }
1923
1924 CUDADeviceAttr(SourceRange R, ASTContext &Ctx
1925 , unsigned SI
1926 )
1927 : InheritableAttr(attr::CUDADevice, R, SI, false, false)
1928 {
1929 }
1930
1931 CUDADeviceAttr *clone(ASTContext &C) const;
1932 void printPretty(raw_ostream &OS,
1933 const PrintingPolicy &Policy) const;
1934 const char *getSpelling() const;
1935
1936
1937 static bool classof(const Attr *A) { return A->getKind() == attr::CUDADevice; }
1938};
1939
1940class CUDAGlobalAttr : public InheritableAttr {
1941public:
1942 static CUDAGlobalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1943 auto *A = new (Ctx) CUDAGlobalAttr(Loc, Ctx, 0);
1944 A->setImplicit(true);
1945 return A;
1946 }
1947
1948 CUDAGlobalAttr(SourceRange R, ASTContext &Ctx
1949 , unsigned SI
1950 )
1951 : InheritableAttr(attr::CUDAGlobal, R, SI, false, false)
1952 {
1953 }
1954
1955 CUDAGlobalAttr *clone(ASTContext &C) const;
1956 void printPretty(raw_ostream &OS,
1957 const PrintingPolicy &Policy) const;
1958 const char *getSpelling() const;
1959
1960
1961 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAGlobal; }
1962};
1963
1964class CUDAHostAttr : public InheritableAttr {
1965public:
1966 static CUDAHostAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1967 auto *A = new (Ctx) CUDAHostAttr(Loc, Ctx, 0);
1968 A->setImplicit(true);
1969 return A;
1970 }
1971
1972 CUDAHostAttr(SourceRange R, ASTContext &Ctx
1973 , unsigned SI
1974 )
1975 : InheritableAttr(attr::CUDAHost, R, SI, false, false)
1976 {
1977 }
1978
1979 CUDAHostAttr *clone(ASTContext &C) const;
1980 void printPretty(raw_ostream &OS,
1981 const PrintingPolicy &Policy) const;
1982 const char *getSpelling() const;
1983
1984
1985 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAHost; }
1986};
1987
1988class CUDAInvalidTargetAttr : public InheritableAttr {
1989public:
1990 static CUDAInvalidTargetAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1991 auto *A = new (Ctx) CUDAInvalidTargetAttr(Loc, Ctx, 0);
1992 A->setImplicit(true);
1993 return A;
1994 }
1995
1996 CUDAInvalidTargetAttr(SourceRange R, ASTContext &Ctx
1997 , unsigned SI
1998 )
1999 : InheritableAttr(attr::CUDAInvalidTarget, R, SI, false, false)
2000 {
2001 }
2002
2003 CUDAInvalidTargetAttr *clone(ASTContext &C) const;
2004 void printPretty(raw_ostream &OS,
2005 const PrintingPolicy &Policy) const;
2006 const char *getSpelling() const;
2007
2008
2009 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAInvalidTarget; }
2010};
2011
2012class CUDALaunchBoundsAttr : public InheritableAttr {
2013Expr * maxThreads;
2014
2015Expr * minBlocks;
2016
2017public:
2018 static CUDALaunchBoundsAttr *CreateImplicit(ASTContext &Ctx, Expr * MaxThreads, Expr * MinBlocks, SourceRange Loc = SourceRange()) {
2019 auto *A = new (Ctx) CUDALaunchBoundsAttr(Loc, Ctx, MaxThreads, MinBlocks, 0);
2020 A->setImplicit(true);
2021 return A;
2022 }
2023
2024 CUDALaunchBoundsAttr(SourceRange R, ASTContext &Ctx
2025 , Expr * MaxThreads
2026 , Expr * MinBlocks
2027 , unsigned SI
2028 )
2029 : InheritableAttr(attr::CUDALaunchBounds, R, SI, false, false)
2030 , maxThreads(MaxThreads)
2031 , minBlocks(MinBlocks)
2032 {
2033 }
2034
2035 CUDALaunchBoundsAttr(SourceRange R, ASTContext &Ctx
2036 , Expr * MaxThreads
2037 , unsigned SI
2038 )
2039 : InheritableAttr(attr::CUDALaunchBounds, R, SI, false, false)
2040 , maxThreads(MaxThreads)
2041 , minBlocks()
2042 {
2043 }
2044
2045 CUDALaunchBoundsAttr *clone(ASTContext &C) const;
2046 void printPretty(raw_ostream &OS,
2047 const PrintingPolicy &Policy) const;
2048 const char *getSpelling() const;
2049 Expr * getMaxThreads() const {
2050 return maxThreads;
2051 }
2052
2053 Expr * getMinBlocks() const {
2054 return minBlocks;
2055 }
2056
2057
2058
2059 static bool classof(const Attr *A) { return A->getKind() == attr::CUDALaunchBounds; }
2060};
2061
2062class CUDASharedAttr : public InheritableAttr {
2063public:
2064 static CUDASharedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2065 auto *A = new (Ctx) CUDASharedAttr(Loc, Ctx, 0);
2066 A->setImplicit(true);
2067 return A;
2068 }
2069
2070 CUDASharedAttr(SourceRange R, ASTContext &Ctx
2071 , unsigned SI
2072 )
2073 : InheritableAttr(attr::CUDAShared, R, SI, false, false)
2074 {
2075 }
2076
2077 CUDASharedAttr *clone(ASTContext &C) const;
2078 void printPretty(raw_ostream &OS,
2079 const PrintingPolicy &Policy) const;
2080 const char *getSpelling() const;
2081
2082
2083 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAShared; }
2084};
2085
2086class CXX11NoReturnAttr : public InheritableAttr {
2087public:
2088 static CXX11NoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2089 auto *A = new (Ctx) CXX11NoReturnAttr(Loc, Ctx, 0);
2090 A->setImplicit(true);
2091 return A;
2092 }
2093
2094 CXX11NoReturnAttr(SourceRange R, ASTContext &Ctx
2095 , unsigned SI
2096 )
2097 : InheritableAttr(attr::CXX11NoReturn, R, SI, false, false)
2098 {
2099 }
2100
2101 CXX11NoReturnAttr *clone(ASTContext &C) const;
2102 void printPretty(raw_ostream &OS,
2103 const PrintingPolicy &Policy) const;
2104 const char *getSpelling() const;
2105
2106
2107 static bool classof(const Attr *A) { return A->getKind() == attr::CXX11NoReturn; }
2108};
2109
2110class CallableWhenAttr : public InheritableAttr {
2111public:
2112 enum ConsumedState {
2113 Unknown,
2114 Consumed,
2115 Unconsumed
2116 };
2117private:
2118 unsigned callableStates_Size;
2119 ConsumedState *callableStates_;
2120
2121public:
2122 static CallableWhenAttr *CreateImplicit(ASTContext &Ctx, ConsumedState *CallableStates, unsigned CallableStatesSize, SourceRange Loc = SourceRange()) {
2123 auto *A = new (Ctx) CallableWhenAttr(Loc, Ctx, CallableStates, CallableStatesSize, 0);
2124 A->setImplicit(true);
2125 return A;
2126 }
2127
2128 CallableWhenAttr(SourceRange R, ASTContext &Ctx
2129 , ConsumedState *CallableStates, unsigned CallableStatesSize
2130 , unsigned SI
2131 )
2132 : InheritableAttr(attr::CallableWhen, R, SI, false, false)
2133 , callableStates_Size(CallableStatesSize), callableStates_(new (Ctx, 16) ConsumedState[callableStates_Size])
2134 {
2135 std::copy(CallableStates, CallableStates + callableStates_Size, callableStates_);
2136 }
2137
2138 CallableWhenAttr(SourceRange R, ASTContext &Ctx
2139 , unsigned SI
2140 )
2141 : InheritableAttr(attr::CallableWhen, R, SI, false, false)
2142 , callableStates_Size(0), callableStates_(nullptr)
2143 {
2144 }
2145
2146 CallableWhenAttr *clone(ASTContext &C) const;
2147 void printPretty(raw_ostream &OS,
2148 const PrintingPolicy &Policy) const;
2149 const char *getSpelling() const;
2150 typedef ConsumedState* callableStates_iterator;
2151 callableStates_iterator callableStates_begin() const { return callableStates_; }
2152 callableStates_iterator callableStates_end() const { return callableStates_ + callableStates_Size; }
2153 unsigned callableStates_size() const { return callableStates_Size; }
2154 llvm::iterator_range<callableStates_iterator> callableStates() const { return llvm::make_range(callableStates_begin(), callableStates_end()); }
2155
2156
2157 static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) {
2158 Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val)
2159 .Case("unknown", CallableWhenAttr::Unknown)
2160 .Case("consumed", CallableWhenAttr::Consumed)
2161 .Case("unconsumed", CallableWhenAttr::Unconsumed)
2162 .Default(Optional<ConsumedState>());
2163 if (R) {
2164 Out = *R;
2165 return true;
2166 }
2167 return false;
2168 }
2169
2170 static const char *ConvertConsumedStateToStr(ConsumedState Val) {
2171 switch(Val) {
2172 case CallableWhenAttr::Unknown: return "unknown";
2173 case CallableWhenAttr::Consumed: return "consumed";
2174 case CallableWhenAttr::Unconsumed: return "unconsumed";
2175 }
2176 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-8~svn350071/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 2176)
;
2177 }
2178
2179
2180 static bool classof(const Attr *A) { return A->getKind() == attr::CallableWhen; }
2181};
2182
2183class CapabilityAttr : public InheritableAttr {
2184unsigned nameLength;
2185char *name;
2186
2187public:
2188 enum Spelling {
2189 GNU_capability = 0,
2190 CXX11_clang_capability = 1,
2191 GNU_shared_capability = 2,
2192 CXX11_clang_shared_capability = 3
2193 };
2194
2195 static CapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, llvm::StringRef Name, SourceRange Loc = SourceRange()) {
2196 auto *A = new (Ctx) CapabilityAttr(Loc, Ctx, Name, S);
2197 A->setImplicit(true);
2198 return A;
2199 }
2200
2201 CapabilityAttr(SourceRange R, ASTContext &Ctx
2202 , llvm::StringRef Name
2203 , unsigned SI
2204 )
2205 : InheritableAttr(attr::Capability, R, SI, false, false)
2206 , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength])
2207 {
2208 if (!Name.empty())
2209 std::memcpy(name, Name.data(), nameLength);
2210 }
2211
2212 CapabilityAttr *clone(ASTContext &C) const;
2213 void printPretty(raw_ostream &OS,
2214 const PrintingPolicy &Policy) const;
2215 const char *getSpelling() const;
2216 Spelling getSemanticSpelling() const {
2217 switch (SpellingListIndex) {
2218 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-8~svn350071/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 2218)
;
2219 case 0: return GNU_capability;
2220 case 1: return CXX11_clang_capability;
2221 case 2: return GNU_shared_capability;
2222 case 3: return CXX11_clang_shared_capability;
2223 }
2224 }
2225 bool isShared() const { return SpellingListIndex == 2 ||
2226 SpellingListIndex == 3; }
2227 llvm::StringRef getName() const {
2228 return llvm::StringRef(name, nameLength);
2229 }
2230 unsigned getNameLength() const {
2231 return nameLength;
2232 }
2233 void setName(ASTContext &C, llvm::StringRef S) {
2234 nameLength = S.size();
2235 this->name = new (C, 1) char [nameLength];
2236 if (!S.empty())
2237 std::memcpy(this->name, S.data(), nameLength);
2238 }
2239
2240
2241 bool isMutex() const { return getName().equals_lower("mutex"); }
2242 bool isRole() const { return getName().equals_lower("role"); }
2243
2244
2245 static bool classof(const Attr *A) { return A->getKind() == attr::Capability; }
2246};
2247
2248class CapturedRecordAttr : public InheritableAttr {
2249public:
2250 static CapturedRecordAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2251 auto *A = new (Ctx) CapturedRecordAttr(Loc, Ctx, 0);
2252 A->setImplicit(true);
2253 return A;
2254 }
2255
2256 CapturedRecordAttr(SourceRange R, ASTContext &Ctx
2257 , unsigned SI
2258 )
2259 : InheritableAttr(attr::CapturedRecord, R, SI, false, false)
2260 {
2261 }
2262
2263 CapturedRecordAttr *clone(ASTContext &C) const;
2264 void printPretty(raw_ostream &OS,
2265 const PrintingPolicy &Policy) const;
2266 const char *getSpelling() const;
2267
2268
2269 static bool classof(const Attr *A) { return A->getKind() == attr::CapturedRecord; }
2270};
2271
2272class CarriesDependencyAttr : public InheritableParamAttr {
2273public:
2274 static CarriesDependencyAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2275 auto *A = new (Ctx) CarriesDependencyAttr(Loc, Ctx, 0);
2276 A->setImplicit(true);
2277 return A;
2278 }
2279
2280 CarriesDependencyAttr(SourceRange R, ASTContext &Ctx
2281 , unsigned SI
2282 )
2283 : InheritableParamAttr(attr::CarriesDependency, R, SI, false, false)
2284 {
2285 }
2286
2287 CarriesDependencyAttr *clone(ASTContext &C) const;
2288 void printPretty(raw_ostream &OS,
2289 const PrintingPolicy &Policy) const;
2290 const char *getSpelling() const;
2291
2292
2293 static bool classof(const Attr *A) { return A->getKind() == attr::CarriesDependency; }
2294};
2295
2296class CleanupAttr : public InheritableAttr {
2297FunctionDecl * functionDecl;
2298
2299public:
2300 static CleanupAttr *CreateImplicit(ASTContext &Ctx, FunctionDecl * FunctionDecl, SourceRange Loc = SourceRange()) {
2301 auto *A = new (Ctx) CleanupAttr(Loc, Ctx, FunctionDecl, 0);
2302 A->setImplicit(true);
2303 return A;
2304 }
2305
2306 CleanupAttr(SourceRange R, ASTContext &Ctx
2307 , FunctionDecl * FunctionDecl
2308 , unsigned SI
2309 )
2310 : InheritableAttr(attr::Cleanup, R, SI, false, false)
2311 , functionDecl(FunctionDecl)
2312 {
2313 }
2314
2315 CleanupAttr *clone(ASTContext &C) const;
2316 void printPretty(raw_ostream &OS,
2317 const PrintingPolicy &Policy) const;
2318 const char *getSpelling() const;
2319 FunctionDecl * getFunctionDecl() const {
2320 return functionDecl;
2321 }
2322
2323
2324
2325 static bool classof(const Attr *A) { return A->getKind() == attr::Cleanup; }
2326};
2327
2328class CodeSegAttr : public InheritableAttr {
2329unsigned nameLength;
2330char *name;
2331
2332public:
2333 static CodeSegAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) {
2334 auto *A = new (Ctx) CodeSegAttr(Loc, Ctx, Name, 0);
2335 A->setImplicit(true);
2336 return A;
2337 }
2338
2339 CodeSegAttr(SourceRange R, ASTContext &Ctx
2340 , llvm::StringRef Name
2341 , unsigned SI
2342 )
2343 : InheritableAttr(attr::CodeSeg, R, SI, false, false)
2344 , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength])
2345 {
2346 if (!Name.empty())
2347 std::memcpy(name, Name.data(), nameLength);
2348 }
2349
2350 CodeSegAttr *clone(ASTContext &C) const;
2351 void printPretty(raw_ostream &OS,
2352 const PrintingPolicy &Policy) const;
2353 const char *getSpelling() const;
2354 llvm::StringRef getName() const {
2355 return llvm::StringRef(name, nameLength);
2356 }
2357 unsigned getNameLength() const {
2358 return nameLength;
2359 }
2360 void setName(ASTContext &C, llvm::StringRef S) {
2361 nameLength = S.size();
2362 this->name = new (C, 1) char [nameLength];
2363 if (!S.empty())
2364 std::memcpy(this->name, S.data(), nameLength);
2365 }
2366
2367
2368
2369 static bool classof(const Attr *A) { return A->getKind() == attr::CodeSeg; }
2370};
2371
2372class ColdAttr : public InheritableAttr {
2373public:
2374 static ColdAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2375 auto *A = new (Ctx) ColdAttr(Loc, Ctx, 0);
2376 A->setImplicit(true);
2377 return A;
2378 }
2379
2380 ColdAttr(SourceRange R, ASTContext &Ctx
2381 , unsigned SI
2382 )
2383 : InheritableAttr(attr::Cold, R, SI, false, false)
2384 {
2385 }
2386
2387 ColdAttr *clone(ASTContext &C) const;
2388 void printPretty(raw_ostream &OS,
2389 const PrintingPolicy &Policy) const;
2390 const char *getSpelling() const;
2391
2392
2393 static bool classof(const Attr *A) { return A->getKind() == attr::Cold; }
2394};
2395
2396class CommonAttr : public InheritableAttr {
2397public:
2398 static CommonAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2399 auto *A = new (Ctx) CommonAttr(Loc, Ctx, 0);
2400 A->setImplicit(true);
2401 return A;
2402 }
2403
2404 CommonAttr(SourceRange R, ASTContext &Ctx
2405 , unsigned SI
2406 )
2407 : InheritableAttr(attr::Common, R, SI, false, false)
2408 {
2409 }
2410
2411 CommonAttr *clone(ASTContext &C) const;
2412 void printPretty(raw_ostream &OS,
2413 const PrintingPolicy &Policy) const;
2414 const char *getSpelling() const;
2415
2416
2417 static bool classof(const Attr *A) { return A->getKind() == attr::Common; }
2418};
2419
2420class ConstAttr : public InheritableAttr {
2421public:
2422 static ConstAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2423 auto *A = new (Ctx) ConstAttr(Loc, Ctx, 0);
2424 A->setImplicit(true);
2425 return A;
2426 }
2427
2428 ConstAttr(SourceRange R, ASTContext &Ctx
2429 , unsigned SI
2430 )
2431 : InheritableAttr(attr::Const, R, SI, false, false)
2432 {
2433 }
2434
2435 ConstAttr *clone(ASTContext &C) const;
2436 void printPretty(raw_ostream &OS,
2437 const PrintingPolicy &Policy) const;
2438 const char *getSpelling() const;
2439
2440
2441 static bool classof(const Attr *A) { return A->getKind() == attr::Const; }
2442};
2443
2444class ConstructorAttr : public InheritableAttr {
2445int priority;
2446
2447public:
2448 static ConstructorAttr *CreateImplicit(ASTContext &Ctx, int Priority, SourceRange Loc = SourceRange()) {
2449 auto *A = new (Ctx) ConstructorAttr(Loc, Ctx, Priority, 0);
2450 A->setImplicit(true);
2451 return A;
2452 }
2453
2454 ConstructorAttr(SourceRange R, ASTContext &Ctx
2455 , int Priority
2456 , unsigned SI
2457 )
2458 : InheritableAttr(attr::Constructor, R, SI, false, false)
2459 , priority(Priority)
2460 {
2461 }
2462
2463 ConstructorAttr(SourceRange R, ASTContext &Ctx
2464 , unsigned SI
2465 )
2466 : InheritableAttr(attr::Constructor, R, SI, false, false)
2467 , priority()
2468 {
2469 }
2470
2471 ConstructorAttr *clone(ASTContext &C) const;
2472 void printPretty(raw_ostream &OS,
2473 const PrintingPolicy &Policy) const;
2474 const char *getSpelling() const;
2475 int getPriority() const {
2476 return priority;
2477 }
2478
2479 static const int DefaultPriority = 65535;
2480
2481
2482
2483 static bool classof(const Attr *A) { return A->getKind() == attr::Constructor; }
2484};
2485
2486class ConsumableAttr : public InheritableAttr {
2487public:
2488 enum ConsumedState {
2489 Unknown,
2490 Consumed,
2491 Unconsumed
2492 };
2493private:
2494 ConsumedState defaultState;
2495
2496public:
2497 static ConsumableAttr *CreateImplicit(ASTContext &Ctx, ConsumedState DefaultState, SourceRange Loc = SourceRange()) {
2498 auto *A = new (Ctx) ConsumableAttr(Loc, Ctx, DefaultState, 0);
2499 A->setImplicit(true);
2500 return A;
2501 }
2502
2503 ConsumableAttr(SourceRange R, ASTContext &Ctx
2504 , ConsumedState DefaultState
2505 , unsigned SI
2506 )
2507 : InheritableAttr(attr::Consumable, R, SI, false, false)
2508 , defaultState(DefaultState)
2509 {
2510 }
2511
2512 ConsumableAttr *clone(ASTContext &C) const;
2513 void printPretty(raw_ostream &OS,
2514 const PrintingPolicy &Policy) const;
2515 const char *getSpelling() const;
2516 ConsumedState getDefaultState() const {
2517 return defaultState;
2518 }
2519
2520 static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) {
2521 Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val)
2522 .Case("unknown", ConsumableAttr::Unknown)
2523 .Case("consumed", ConsumableAttr::Consumed)
2524 .Case("unconsumed", ConsumableAttr::Unconsumed)
2525 .Default(Optional<ConsumedState>());
2526 if (R) {
2527 Out = *R;
2528 return true;
2529 }
2530 return false;
2531 }
2532
2533 static const char *ConvertConsumedStateToStr(ConsumedState Val) {
2534 switch(Val) {
2535 case ConsumableAttr::Unknown: return "unknown";
2536 case ConsumableAttr::Consumed: return "consumed";
2537 case ConsumableAttr::Unconsumed: return "unconsumed";
2538 }
2539 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-8~svn350071/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 2539)
;
2540 }
2541
2542
2543 static bool classof(const Attr *A) { return A->getKind() == attr::Consumable; }
2544};
2545
2546class ConsumableAutoCastAttr : public InheritableAttr {
2547public:
2548 static ConsumableAutoCastAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2549 auto *A = new (Ctx) ConsumableAutoCastAttr(Loc, Ctx, 0);
2550 A->setImplicit(true);
2551 return A;
2552 }
2553
2554 ConsumableAutoCastAttr(SourceRange R, ASTContext &Ctx
2555 , unsigned SI
2556 )
2557 : InheritableAttr(attr::ConsumableAutoCast, R, SI, false, false)
2558 {
2559 }
2560
2561 ConsumableAutoCastAttr *clone(ASTContext &C) const;
2562 void printPretty(raw_ostream &OS,
2563 const PrintingPolicy &Policy) const;
2564 const char *getSpelling() const;
2565
2566
2567 static bool classof(const Attr *A) { return A->getKind() == attr::ConsumableAutoCast; }
2568};
2569
2570class ConsumableSetOnReadAttr : public InheritableAttr {
2571public:
2572 static ConsumableSetOnReadAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2573 auto *A = new (Ctx) ConsumableSetOnReadAttr(Loc, Ctx, 0);
2574 A->setImplicit(true);
2575 return A;
2576 }
2577
2578 ConsumableSetOnReadAttr(SourceRange R, ASTContext &Ctx
2579 , unsigned SI
2580 )
2581 : InheritableAttr(attr::ConsumableSetOnRead, R, SI, false, false)
2582 {
2583 }
2584
2585 ConsumableSetOnReadAttr *clone(ASTContext &C) const;
2586 void printPretty(raw_ostream &OS,
2587 const PrintingPolicy &Policy) const;
2588 const char *getSpelling() const;
2589
2590
2591 static bool classof(const Attr *A) { return A->getKind() == attr::ConsumableSetOnRead; }
2592};
2593
2594class ConvergentAttr : public InheritableAttr {
2595public:
2596 static ConvergentAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2597 auto *A = new (Ctx) ConvergentAttr(Loc, Ctx, 0);
2598 A->setImplicit(true);
2599 return A;
2600 }
2601
2602 ConvergentAttr(SourceRange R, ASTContext &Ctx
2603 , unsigned SI
2604 )
2605 : InheritableAttr(attr::Convergent, R, SI, false, false)
2606 {
2607 }
2608
2609 ConvergentAttr *clone(ASTContext &C) const;
2610 void printPretty(raw_ostream &OS,
2611 const PrintingPolicy &Policy) const;
2612 const char *getSpelling() const;
2613
2614
2615 static bool classof(const Attr *A) { return A->getKind() == attr::Convergent; }
2616};
2617
2618class DLLExportAttr : public InheritableAttr {
2619public:
2620 static DLLExportAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2621 auto *A = new (Ctx) DLLExportAttr(Loc, Ctx, 0);
2622 A->setImplicit(true);
2623 return A;
2624 }
2625
2626 DLLExportAttr(SourceRange R, ASTContext &Ctx
2627 , unsigned SI
2628 )
2629 : InheritableAttr(attr::DLLExport, R, SI, false, false)
2630 {
2631 }
2632
2633 DLLExportAttr *clone(ASTContext &C) const;
2634 void printPretty(raw_ostream &OS,
2635 const PrintingPolicy &Policy) const;
2636 const char *getSpelling() const;
2637
2638
2639 static bool classof(const Attr *A) { return A->getKind() == attr::DLLExport; }
2640};
2641
2642class DLLExportStaticLocalAttr : public InheritableAttr {
2643public:
2644 static DLLExportStaticLocalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2645 auto *A = new (Ctx) DLLExportStaticLocalAttr(Loc, Ctx, 0);
2646 A->setImplicit(true);
2647 return A;
2648 }
2649
2650 DLLExportStaticLocalAttr(SourceRange R, ASTContext &Ctx
2651 , unsigned SI
2652 )
2653 : InheritableAttr(attr::DLLExportStaticLocal, R, SI, false, false)
2654 {
2655 }
2656
2657 DLLExportStaticLocalAttr *clone(ASTContext &C) const;
2658 void printPretty(raw_ostream &OS,
2659 const PrintingPolicy &Policy) const;
2660 const char *getSpelling() const;
2661
2662
2663 static bool classof(const Attr *A) { return A->getKind() == attr::DLLExportStaticLocal; }
2664};
2665
2666class DLLImportAttr : public InheritableAttr {
2667public:
2668 static DLLImportAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2669 auto *A = new (Ctx) DLLImportAttr(Loc, Ctx, 0);
2670 A->setImplicit(true);
2671 return A;
2672 }
2673
2674 DLLImportAttr(SourceRange R, ASTContext &Ctx
2675 , unsigned SI
2676 )
2677 : InheritableAttr(attr::DLLImport, R, SI, false, false)
2678 {
2679 }
2680
2681 DLLImportAttr *clone(ASTContext &C) const;
2682 void printPretty(raw_ostream &OS,
2683 const PrintingPolicy &Policy) const;
2684 const char *getSpelling() const;
2685
2686private:
2687 bool PropagatedToBaseTemplate = false;
2688
2689public:
2690 void setPropagatedToBaseTemplate() { PropagatedToBaseTemplate = true; }
2691 bool wasPropagatedToBaseTemplate() { return PropagatedToBaseTemplate; }
2692
2693
2694 static bool classof(const Attr *A) { return A->getKind() == attr::DLLImport; }
2695};
2696
2697class DLLImportStaticLocalAttr : public InheritableAttr {
2698public:
2699 static DLLImportStaticLocalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2700 auto *A = new (Ctx) DLLImportStaticLocalAttr(Loc, Ctx, 0);
2701 A->setImplicit(true);
2702 return A;
2703 }
2704
2705 DLLImportStaticLocalAttr(SourceRange R, ASTContext &Ctx
2706 , unsigned SI
2707 )
2708 : InheritableAttr(attr::DLLImportStaticLocal, R, SI, false, false)
2709 {
2710 }
2711
2712 DLLImportStaticLocalAttr *clone(ASTContext &C) const;
2713 void printPretty(raw_ostream &OS,
2714 const PrintingPolicy &Policy) const;
2715 const char *getSpelling() const;
2716
2717
2718 static bool classof(const Attr *A) { return A->getKind() == attr::DLLImportStaticLocal; }
2719};
2720
2721class DeprecatedAttr : public InheritableAttr {
2722unsigned messageLength;
2723char *message;
2724
2725unsigned replacementLength;
2726char *replacement;
2727
2728public:
2729 static DeprecatedAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Message, llvm::StringRef Replacement, SourceRange Loc = SourceRange()) {
2730 auto *A = new (Ctx) DeprecatedAttr(Loc, Ctx, Message, Replacement, 0);
2731 A->setImplicit(true);
2732 return A;
2733 }
2734
2735 DeprecatedAttr(SourceRange R, ASTContext &Ctx
2736 , llvm::StringRef Message
2737 , llvm::StringRef Replacement
2738 , unsigned SI
2739 )
2740 : InheritableAttr(attr::Deprecated, R, SI, false, false)
2741 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
2742 , replacementLength(Replacement.size()),replacement(new (Ctx, 1) char[replacementLength])
2743 {
2744 if (!Message.empty())
2745 std::memcpy(message, Message.data(), messageLength);
2746 if (!Replacement.empty())
2747 std::memcpy(replacement, Replacement.data(), replacementLength);
2748 }
2749
2750 DeprecatedAttr(SourceRange R, ASTContext &Ctx
2751 , unsigned SI
2752 )
2753 : InheritableAttr(attr::Deprecated, R, SI, false, false)
2754 , messageLength(0),message(nullptr)
2755 , replacementLength(0),replacement(nullptr)
2756 {
2757 }
2758
2759 DeprecatedAttr *clone(ASTContext &C) const;
2760 void printPretty(raw_ostream &OS,
2761 const PrintingPolicy &Policy) const;
2762 const char *getSpelling() const;
2763 llvm::StringRef getMessage() const {
2764 return llvm::StringRef(message, messageLength);
2765 }
2766 unsigned getMessageLength() const {
2767 return messageLength;
2768 }
2769 void setMessage(ASTContext &C, llvm::StringRef S) {
2770 messageLength = S.size();
2771 this->message = new (C, 1) char [messageLength];
2772 if (!S.empty())
2773 std::memcpy(this->message, S.data(), messageLength);
2774 }
2775
2776 llvm::StringRef getReplacement() const {
2777 return llvm::StringRef(replacement, replacementLength);
2778 }
2779 unsigned getReplacementLength() const {
2780 return replacementLength;
2781 }
2782 void setReplacement(ASTContext &C, llvm::StringRef S) {
2783 replacementLength = S.size();
2784 this->replacement = new (C, 1) char [replacementLength];
2785 if (!S.empty())
2786 std::memcpy(this->replacement, S.data(), replacementLength);
2787 }
2788
2789
2790
2791 static bool classof(const Attr *A) { return A->getKind() == attr::Deprecated; }
2792};
2793
2794class DestructorAttr : public InheritableAttr {
2795int priority;
2796
2797public:
2798 static DestructorAttr *CreateImplicit(ASTContext &Ctx, int Priority, SourceRange Loc = SourceRange()) {
2799 auto *A = new (Ctx) DestructorAttr(Loc, Ctx, Priority, 0);
2800 A->setImplicit(true);
2801 return A;
2802 }
2803
2804 DestructorAttr(SourceRange R, ASTContext &Ctx
2805 , int Priority
2806 , unsigned SI
2807 )
2808 : InheritableAttr(attr::Destructor, R, SI, false, false)
2809 , priority(Priority)
2810 {
2811 }
2812
2813 DestructorAttr(SourceRange R, ASTContext &Ctx
2814 , unsigned SI
2815 )
2816 : InheritableAttr(attr::Destructor, R, SI, false, false)
2817 , priority()
2818 {
2819 }
2820
2821 DestructorAttr *clone(ASTContext &C) const;
2822 void printPretty(raw_ostream &OS,
2823 const PrintingPolicy &Policy) const;
2824 const char *getSpelling() const;
2825 int getPriority() const {
2826 return priority;
2827 }
2828
2829 static const int DefaultPriority = 65535;
2830
2831
2832
2833 static bool classof(const Attr *A) { return A->getKind() == attr::Destructor; }
2834};
2835
2836class DiagnoseIfAttr : public InheritableAttr {
2837Expr * cond;
2838
2839unsigned messageLength;
2840char *message;
2841
2842public:
2843 enum DiagnosticType {
2844 DT_Error,
2845 DT_Warning
2846 };
2847private:
2848 DiagnosticType diagnosticType;
2849
2850bool argDependent;
2851
2852NamedDecl * parent;
2853
2854public:
2855 static DiagnoseIfAttr *CreateImplicit(ASTContext &Ctx, Expr * Cond, llvm::StringRef Message, DiagnosticType DiagnosticType, bool ArgDependent, NamedDecl * Parent, SourceRange Loc = SourceRange()) {
2856 auto *A = new (Ctx) DiagnoseIfAttr(Loc, Ctx, Cond, Message, DiagnosticType, ArgDependent, Parent, 0);
2857 A->setImplicit(true);
2858 return A;
2859 }
2860
2861 static DiagnoseIfAttr *CreateImplicit(ASTContext &Ctx, Expr * Cond, llvm::StringRef Message, DiagnosticType DiagnosticType, SourceRange Loc = SourceRange()) {
2862 auto *A = new (Ctx) DiagnoseIfAttr(Loc, Ctx, Cond, Message, DiagnosticType, 0);
2863 A->setImplicit(true);
2864 return A;
2865 }
2866
2867 DiagnoseIfAttr(SourceRange R, ASTContext &Ctx
2868 , Expr * Cond
2869 , llvm::StringRef Message
2870 , DiagnosticType DiagnosticType
2871 , bool ArgDependent
2872 , NamedDecl * Parent
2873 , unsigned SI
2874 )
2875 : InheritableAttr(attr::DiagnoseIf, R, SI, true, true)
2876 , cond(Cond)
2877 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
2878 , diagnosticType(DiagnosticType)
2879 , argDependent(ArgDependent)
2880 , parent(Parent)
2881 {
2882 if (!Message.empty())
2883 std::memcpy(message, Message.data(), messageLength);
2884 }
2885
2886 DiagnoseIfAttr(SourceRange R, ASTContext &Ctx
2887 , Expr * Cond
2888 , llvm::StringRef Message
2889 , DiagnosticType DiagnosticType
2890 , unsigned SI
2891 )
2892 : InheritableAttr(attr::DiagnoseIf, R, SI, true, true)
2893 , cond(Cond)
2894 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
2895 , diagnosticType(DiagnosticType)
2896 , argDependent()
2897 , parent()
2898 {
2899 if (!Message.empty())
2900 std::memcpy(message, Message.data(), messageLength);
2901 }
2902
2903 DiagnoseIfAttr *clone(ASTContext &C) const;
2904 void printPretty(raw_ostream &OS,
2905 const PrintingPolicy &Policy) const;
2906 const char *getSpelling() const;
2907 Expr * getCond() const {
2908 return cond;
2909 }
2910
2911 llvm::StringRef getMessage() const {
2912 return llvm::StringRef(message, messageLength);
2913 }
2914 unsigned getMessageLength() const {
2915 return messageLength;
2916 }
2917 void setMessage(ASTContext &C, llvm::StringRef S) {
2918 messageLength = S.size();
2919 this->message = new (C, 1) char [messageLength];
2920 if (!S.empty())
2921 std::memcpy(this->message, S.data(), messageLength);
2922 }
2923
2924 DiagnosticType getDiagnosticType() const {
2925 return diagnosticType;
2926 }
2927
2928 static bool ConvertStrToDiagnosticType(StringRef Val, DiagnosticType &Out) {
2929 Optional<DiagnosticType> R = llvm::StringSwitch<Optional<DiagnosticType>>(Val)
2930 .Case("error", DiagnoseIfAttr::DT_Error)
2931 .Case("warning", DiagnoseIfAttr::DT_Warning)
2932 .Default(Optional<DiagnosticType>());
2933 if (R) {
2934 Out = *R;
2935 return true;
2936 }
2937 return false;
2938 }
2939
2940 static const char *ConvertDiagnosticTypeToStr(DiagnosticType Val) {
2941 switch(Val) {
2942 case DiagnoseIfAttr::DT_Error: return "error";
2943 case DiagnoseIfAttr::DT_Warning: return "warning";
2944 }
2945 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-8~svn350071/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 2945)
;
2946 }
2947 bool getArgDependent() const {
2948 return argDependent;
2949 }
2950
2951 NamedDecl * getParent() const {
2952 return parent;
2953 }
2954
2955
2956 bool isError() const { return diagnosticType == DT_Error; }
2957 bool isWarning() const { return diagnosticType == DT_Warning; }
2958
2959
2960 static bool classof(const Attr *A) { return A->getKind() == attr::DiagnoseIf; }
2961};
2962
2963class DisableTailCallsAttr : public InheritableAttr {
2964public:
2965 static DisableTailCallsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2966 auto *A = new (Ctx) DisableTailCallsAttr(Loc, Ctx, 0);
2967 A->setImplicit(true);
2968 return A;
2969 }
2970
2971 DisableTailCallsAttr(SourceRange R, ASTContext &Ctx
2972 , unsigned SI
2973 )
2974 : InheritableAttr(attr::DisableTailCalls, R, SI, false, false)
2975 {
2976 }
2977
2978 DisableTailCallsAttr *clone(ASTContext &C) const;
2979 void printPretty(raw_ostream &OS,
2980 const PrintingPolicy &Policy) const;
2981 const char *getSpelling() const;
2982
2983
2984 static bool classof(const Attr *A) { return A->getKind() == attr::DisableTailCalls; }
2985};
2986
2987class EmptyBasesAttr : public InheritableAttr {
2988public:
2989 static EmptyBasesAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2990 auto *A = new (Ctx) EmptyBasesAttr(Loc, Ctx, 0);
2991 A->setImplicit(true);
2992 return A;
2993 }
2994
2995 EmptyBasesAttr(SourceRange R, ASTContext &Ctx
2996 , unsigned SI
2997 )
2998 : InheritableAttr(attr::EmptyBases, R, SI, false, false)
2999 {
3000 }
3001
3002 EmptyBasesAttr *clone(ASTContext &C) const;
3003 void printPretty(raw_ostream &OS,
3004 const PrintingPolicy &Policy) const;
3005 const char *getSpelling() const;
3006
3007
3008 static bool classof(const Attr *A) { return A->getKind() == attr::EmptyBases; }
3009};
3010
3011class EnableIfAttr : public InheritableAttr {
3012Expr * cond;
3013
3014unsigned messageLength;
3015char *message;
3016
3017public:
3018 static EnableIfAttr *CreateImplicit(ASTContext &Ctx, Expr * Cond, llvm::StringRef Message, SourceRange Loc = SourceRange()) {
3019 auto *A = new (Ctx) EnableIfAttr(Loc, Ctx, Cond, Message, 0);
3020 A->setImplicit(true);
3021 return A;
3022 }
3023
3024 EnableIfAttr(SourceRange R, ASTContext &Ctx
3025 , Expr * Cond
3026 , llvm::StringRef Message
3027 , unsigned SI
3028 )
3029 : InheritableAttr(attr::EnableIf, R, SI, false, false)
3030 , cond(Cond)
3031 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
3032 {
3033 if (!Message.empty())
3034 std::memcpy(message, Message.data(), messageLength);
3035 }
3036
3037 EnableIfAttr *clone(ASTContext &C) const;
3038 void printPretty(raw_ostream &OS,
3039 const PrintingPolicy &Policy) const;
3040 const char *getSpelling() const;
3041 Expr * getCond() const {
3042 return cond;
3043 }
3044
3045 llvm::StringRef getMessage() const {
3046 return llvm::StringRef(message, messageLength);
3047 }
3048 unsigned getMessageLength() const {
3049 return messageLength;
3050 }
3051 void setMessage(ASTContext &C, llvm::StringRef S) {
3052 messageLength = S.size();
3053 this->message = new (C, 1) char [messageLength];
3054 if (!S.empty())
3055 std::memcpy(this->message, S.data(), messageLength);
3056 }
3057
3058
3059
3060 static bool classof(const Attr *A) { return A->getKind() == attr::EnableIf; }
3061};
3062
3063class EnumExtensibilityAttr : public InheritableAttr {
3064public:
3065 enum Kind {
3066 Closed,
3067 Open
3068 };
3069private:
3070 Kind extensibility;
3071
3072public:
3073 static EnumExtensibilityAttr *CreateImplicit(ASTContext &Ctx, Kind Extensibility, SourceRange Loc = SourceRange()) {
3074 auto *A = new (Ctx) EnumExtensibilityAttr(Loc, Ctx, Extensibility, 0);
3075 A->setImplicit(true);
3076 return A;
3077 }
3078
3079 EnumExtensibilityAttr(SourceRange R, ASTContext &Ctx
3080 , Kind Extensibility
3081 , unsigned SI
3082 )
3083 : InheritableAttr(attr::EnumExtensibility, R, SI, false, false)
3084 , extensibility(Extensibility)
3085 {
3086 }
3087
3088 EnumExtensibilityAttr *clone(ASTContext &C) const;
3089 void printPretty(raw_ostream &OS,
3090 const PrintingPolicy &Policy) const;
3091 const char *getSpelling() const;
3092 Kind getExtensibility() const {
3093 return extensibility;
3094 }
3095
3096 static bool ConvertStrToKind(StringRef Val, Kind &Out) {
3097 Optional<Kind> R = llvm::StringSwitch<Optional<Kind>>(Val)
3098 .Case("closed", EnumExtensibilityAttr::Closed)
3099 .Case("open", EnumExtensibilityAttr::Open)
3100 .Default(Optional<Kind>());
3101 if (R) {
3102 Out = *R;
3103 return true;
3104 }
3105 return false;
3106 }
3107
3108 static const char *ConvertKindToStr(Kind Val) {
3109 switch(Val) {
3110 case EnumExtensibilityAttr::Closed: return "closed";
3111 case EnumExtensibilityAttr::Open: return "open";
3112 }
3113 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-8~svn350071/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 3113)
;
3114 }
3115
3116
3117 static bool classof(const Attr *A) { return A->getKind() == attr::EnumExtensibility; }
3118};
3119
3120class ExcludeFromExplicitInstantiationAttr : public InheritableAttr {
3121public:
3122 static ExcludeFromExplicitInstantiationAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3123 auto *A = new (Ctx) ExcludeFromExplicitInstantiationAttr(Loc, Ctx, 0);
3124 A->setImplicit(true);
3125 return A;
3126 }
3127
3128 ExcludeFromExplicitInstantiationAttr(SourceRange R, ASTContext &Ctx
3129 , unsigned SI
3130 )
3131 : InheritableAttr(attr::ExcludeFromExplicitInstantiation, R, SI, false, false)
3132 {
3133 }
3134
3135 ExcludeFromExplicitInstantiationAttr *clone(ASTContext &C) const;
3136 void printPretty(raw_ostream &OS,
3137 const PrintingPolicy &Policy) const;
3138 const char *getSpelling() const;
3139
3140
3141 static bool classof(const Attr *A) { return A->getKind() == attr::ExcludeFromExplicitInstantiation; }
3142};
3143
3144class ExclusiveTrylockFunctionAttr : public InheritableAttr {
3145Expr * successValue;
3146
3147 unsigned args_Size;
3148 Expr * *args_;
3149
3150public:
3151 static ExclusiveTrylockFunctionAttr *CreateImplicit(ASTContext &Ctx, Expr * SuccessValue, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
3152 auto *A = new (Ctx) ExclusiveTrylockFunctionAttr(Loc, Ctx, SuccessValue, Args, ArgsSize, 0);
3153 A->setImplicit(true);
3154 return A;
3155 }
3156
3157 ExclusiveTrylockFunctionAttr(SourceRange R, ASTContext &Ctx
3158 , Expr * SuccessValue
3159 , Expr * *Args, unsigned ArgsSize
3160 , unsigned SI
3161 )
3162 : InheritableAttr(attr::ExclusiveTrylockFunction, R, SI, true, true)
3163 , successValue(SuccessValue)
3164 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
3165 {
3166 std::copy(Args, Args + args_Size, args_);
3167 }
3168
3169 ExclusiveTrylockFunctionAttr(SourceRange R, ASTContext &Ctx
3170 , Expr * SuccessValue
3171 , unsigned SI
3172 )
3173 : InheritableAttr(attr::ExclusiveTrylockFunction, R, SI, true, true)
3174 , successValue(SuccessValue)
3175 , args_Size(0), args_(nullptr)
3176 {
3177 }
3178
3179 ExclusiveTrylockFunctionAttr *clone(ASTContext &C) const;
3180 void printPretty(raw_ostream &OS,
3181 const PrintingPolicy &Policy) const;
3182 const char *getSpelling() const;
3183 Expr * getSuccessValue() const {
3184 return successValue;
3185 }
3186
3187 typedef Expr ** args_iterator;
3188 args_iterator args_begin() const { return args_; }
3189 args_iterator args_end() const { return args_ + args_Size; }
3190 unsigned args_size() const { return args_Size; }
3191 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
3192
3193
3194
3195
3196 static bool classof(const Attr *A) { return A->getKind() == attr::ExclusiveTrylockFunction; }
3197};
3198
3199class ExternalSourceSymbolAttr : public InheritableAttr {
3200unsigned languageLength;
3201char *language;
3202
3203unsigned definedInLength;
3204char *definedIn;
3205
3206bool generatedDeclaration;
3207
3208public:
3209 static ExternalSourceSymbolAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Language, llvm::StringRef DefinedIn, bool GeneratedDeclaration, SourceRange Loc = SourceRange()) {
3210 auto *A = new (Ctx) ExternalSourceSymbolAttr(Loc, Ctx, Language, DefinedIn, GeneratedDeclaration, 0);
3211 A->setImplicit(true);
3212 return A;
3213 }
3214
3215 ExternalSourceSymbolAttr(SourceRange R, ASTContext &Ctx
3216 , llvm::StringRef Language
3217 , llvm::StringRef DefinedIn
3218 , bool GeneratedDeclaration
3219 , unsigned SI
3220 )
3221 : InheritableAttr(attr::ExternalSourceSymbol, R, SI, false, false)
3222 , languageLength(Language.size()),language(new (Ctx, 1) char[languageLength])
3223 , definedInLength(DefinedIn.size()),definedIn(new (Ctx, 1) char[definedInLength])
3224 , generatedDeclaration(GeneratedDeclaration)
3225 {
3226 if (!Language.empty())
3227 std::memcpy(language, Language.data(), languageLength);
3228 if (!DefinedIn.empty())
3229 std::memcpy(definedIn, DefinedIn.data(), definedInLength);
3230 }
3231
3232 ExternalSourceSymbolAttr(SourceRange R, ASTContext &Ctx
3233 , unsigned SI
3234 )
3235 : InheritableAttr(attr::ExternalSourceSymbol, R, SI, false, false)
3236 , languageLength(0),language(nullptr)
3237 , definedInLength(0),definedIn(nullptr)
3238 , generatedDeclaration()
3239 {
3240 }
3241
3242 ExternalSourceSymbolAttr *clone(ASTContext &C) const;
3243 void printPretty(raw_ostream &OS,
3244 const PrintingPolicy &Policy) const;
3245 const char *getSpelling() const;
3246 llvm::StringRef getLanguage() const {
3247 return llvm::StringRef(language, languageLength);
3248 }
3249 unsigned getLanguageLength() const {
3250 return languageLength;
3251 }
3252 void setLanguage(ASTContext &C, llvm::StringRef S) {
3253 languageLength = S.size();
3254 this->language = new (C, 1) char [languageLength];
3255 if (!S.empty())
3256 std::memcpy(this->language, S.data(), languageLength);
3257 }
3258
3259 llvm::StringRef getDefinedIn() const {
3260 return llvm::StringRef(definedIn, definedInLength);
3261 }
3262 unsigned getDefinedInLength() const {
3263 return definedInLength;
3264 }
3265 void setDefinedIn(ASTContext &C, llvm::StringRef S) {
3266 definedInLength = S.size();
3267 this->definedIn = new (C, 1) char [definedInLength];
3268 if (!S.empty())
3269 std::memcpy(this->definedIn, S.data(), definedInLength);
3270 }
3271
3272 bool getGeneratedDeclaration() const {
3273 return generatedDeclaration;
3274 }
3275
3276
3277
3278 static bool classof(const Attr *A) { return A->getKind() == attr::ExternalSourceSymbol; }
3279};
3280
3281class FallThroughAttr : public StmtAttr {
3282public:
3283 static FallThroughAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3284 auto *A = new (Ctx) FallThroughAttr(Loc, Ctx, 0);
3285 A->setImplicit(true);
3286 return A;
3287 }
3288
3289 FallThroughAttr(SourceRange R, ASTContext &Ctx
3290 , unsigned SI
3291 )
3292 : StmtAttr(attr::FallThrough, R, SI, false)
3293 {
3294 }
3295
3296 FallThroughAttr *clone(ASTContext &C) const;
3297 void printPretty(raw_ostream &OS,
3298 const PrintingPolicy &Policy) const;
3299 const char *getSpelling() const;
3300
3301
3302 static bool classof(const Attr *A) { return A->getKind() == attr::FallThrough; }
3303};
3304
3305class FastCallAttr : public InheritableAttr {
3306public:
3307 static FastCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3308 auto *A = new (Ctx) FastCallAttr(Loc, Ctx, 0);
3309 A->setImplicit(true);
3310 return A;
3311 }
3312
3313 FastCallAttr(SourceRange R, ASTContext &Ctx
3314 , unsigned SI
3315 )
3316 : InheritableAttr(attr::FastCall, R, SI, false, false)
3317 {
3318 }
3319
3320 FastCallAttr *clone(ASTContext &C) const;
3321 void printPretty(raw_ostream &OS,
3322 const PrintingPolicy &Policy) const;
3323 const char *getSpelling() const;
3324
3325
3326 static bool classof(const Attr *A) { return A->getKind() == attr::FastCall; }
3327};
3328
3329class FinalAttr : public InheritableAttr {
3330public:
3331 enum Spelling {
3332 Keyword_final = 0,
3333 Keyword_sealed = 1
3334 };
3335
3336 static FinalAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
3337 auto *A = new (Ctx) FinalAttr(Loc, Ctx, S);
3338 A->setImplicit(true);
3339 return A;
3340 }
3341
3342 FinalAttr(SourceRange R, ASTContext &Ctx
3343 , unsigned SI
3344 )
3345 : InheritableAttr(attr::Final, R, SI, false, false)
3346 {
3347 }
3348
3349 FinalAttr *clone(ASTContext &C) const;
3350 void printPretty(raw_ostream &OS,
3351 const PrintingPolicy &Policy) const;
3352 const char *getSpelling() const;
3353 Spelling getSemanticSpelling() const {
3354 switch (SpellingListIndex) {
3355 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-8~svn350071/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 3355)
;
3356 case 0: return Keyword_final;
3357 case 1: return Keyword_sealed;
3358 }
3359 }
3360 bool isSpelledAsSealed() const { return SpellingListIndex == 1; }
3361
3362
3363 static bool classof(const Attr *A) { return A->getKind() == attr::Final; }
3364};
3365
3366class FlagEnumAttr : public InheritableAttr {
3367public:
3368 static FlagEnumAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3369 auto *A = new (Ctx) FlagEnumAttr(Loc, Ctx, 0);
3370 A->setImplicit(true);
3371 return A;
3372 }
3373
3374 FlagEnumAttr(SourceRange R, ASTContext &Ctx
3375 , unsigned SI
3376 )
3377 : InheritableAttr(attr::FlagEnum, R, SI, false, false)
3378 {
3379 }
3380
3381 FlagEnumAttr *clone(ASTContext &C) const;
3382 void printPretty(raw_ostream &OS,
3383 const PrintingPolicy &Policy) const;
3384 const char *getSpelling() const;
3385
3386
3387 static bool classof(const Attr *A) { return A->getKind() == attr::FlagEnum; }
3388};
3389
3390class FlattenAttr : public InheritableAttr {
3391public:
3392 static FlattenAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3393 auto *A = new (Ctx) FlattenAttr(Loc, Ctx, 0);
3394 A->setImplicit(true);
3395 return A;
3396 }
3397
3398 FlattenAttr(SourceRange R, ASTContext &Ctx
3399 , unsigned SI
3400 )
3401 : InheritableAttr(attr::Flatten, R, SI, false, false)
3402 {
3403 }
3404
3405 FlattenAttr *clone(ASTContext &C) const;
3406 void printPretty(raw_ostream &OS,
3407 const PrintingPolicy &Policy) const;
3408 const char *getSpelling() const;
3409
3410
3411 static bool classof(const Attr *A) { return A->getKind() == attr::Flatten; }
3412};
3413
3414class FormatAttr : public InheritableAttr {
3415IdentifierInfo * type;
3416
3417int formatIdx;
3418
3419int firstArg;
3420
3421public:
3422 static FormatAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Type, int FormatIdx, int FirstArg, SourceRange Loc = SourceRange()) {
3423 auto *A = new (Ctx) FormatAttr(Loc, Ctx, Type, FormatIdx, FirstArg, 0);
3424 A->setImplicit(true);
3425 return A;
3426 }
3427
3428 FormatAttr(SourceRange R, ASTContext &Ctx
3429 , IdentifierInfo * Type
3430 , int FormatIdx
3431 , int FirstArg
3432 , unsigned SI
3433 )
3434 : InheritableAttr(attr::Format, R, SI, false, false)
3435 , type(Type)
3436 , formatIdx(FormatIdx)
3437 , firstArg(FirstArg)
3438 {
3439 }
3440
3441 FormatAttr *clone(ASTContext &C) const;
3442 void printPretty(raw_ostream &OS,
3443 const PrintingPolicy &Policy) const;
3444 const char *getSpelling() const;
3445 IdentifierInfo * getType() const {
3446 return type;
3447 }
3448
3449 int getFormatIdx() const {
3450 return formatIdx;
3451 }
3452
3453 int getFirstArg() const {
3454 return firstArg;
3455 }
3456
3457
3458
3459 static bool classof(const Attr *A) { return A->getKind() == attr::Format; }
3460};
3461
3462class FormatArgAttr : public InheritableAttr {
3463ParamIdx formatIdx;
3464
3465public:
3466 static FormatArgAttr *CreateImplicit(ASTContext &Ctx, ParamIdx FormatIdx, SourceRange Loc = SourceRange()) {
3467 auto *A = new (Ctx) FormatArgAttr(Loc, Ctx, FormatIdx, 0);
3468 A->setImplicit(true);
3469 return A;
3470 }
3471
3472 FormatArgAttr(SourceRange R, ASTContext &Ctx
3473 , ParamIdx FormatIdx
3474 , unsigned SI
3475 )
3476 : InheritableAttr(attr::FormatArg, R, SI, false, false)
3477 , formatIdx(FormatIdx)
3478 {
3479 }
3480
3481 FormatArgAttr *clone(ASTContext &C) const;
3482 void printPretty(raw_ostream &OS,
3483 const PrintingPolicy &Policy) const;
3484 const char *getSpelling() const;
3485 ParamIdx getFormatIdx() const {
3486 return formatIdx;
3487 }
3488
3489
3490
3491 static bool classof(const Attr *A) { return A->getKind() == attr::FormatArg; }
3492};
3493
3494class GNUInlineAttr : public InheritableAttr {
3495public:
3496 static GNUInlineAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3497 auto *A = new (Ctx) GNUInlineAttr(Loc, Ctx, 0);
3498 A->setImplicit(true);
3499 return A;
3500 }
3501
3502 GNUInlineAttr(SourceRange R, ASTContext &Ctx
3503 , unsigned SI
3504 )
3505 : InheritableAttr(attr::GNUInline, R, SI, false, false)
3506 {
3507 }
3508
3509 GNUInlineAttr *clone(ASTContext &C) const;
3510 void printPretty(raw_ostream &OS,
3511 const PrintingPolicy &Policy) const;
3512 const char *getSpelling() const;
3513
3514
3515 static bool classof(const Attr *A) { return A->getKind() == attr::GNUInline; }
3516};
3517
3518class GuardedByAttr : public InheritableAttr {
3519Expr * arg;
3520
3521public:
3522 static GuardedByAttr *CreateImplicit(ASTContext &Ctx, Expr * Arg, SourceRange Loc = SourceRange()) {
3523 auto *A = new (Ctx) GuardedByAttr(Loc, Ctx, Arg, 0);
3524 A->setImplicit(true);
3525 return A;
3526 }
3527
3528 GuardedByAttr(SourceRange R, ASTContext &Ctx
3529 , Expr * Arg
3530 , unsigned SI
3531 )
3532 : InheritableAttr(attr::GuardedBy, R, SI, true, true)
3533 , arg(Arg)
3534 {
3535 }
3536
3537 GuardedByAttr *clone(ASTContext &C) const;
3538 void printPretty(raw_ostream &OS,
3539 const PrintingPolicy &Policy) const;
3540 const char *getSpelling() const;
3541 Expr * getArg() const {
3542 return arg;
3543 }
3544
3545
3546
3547 static bool classof(const Attr *A) { return A->getKind() == attr::GuardedBy; }
3548};
3549
3550class GuardedVarAttr : public InheritableAttr {
3551public:
3552 static GuardedVarAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3553 auto *A = new (Ctx) GuardedVarAttr(Loc, Ctx, 0);
3554 A->setImplicit(true);
3555 return A;
3556 }
3557
3558 GuardedVarAttr(SourceRange R, ASTContext &Ctx
3559 , unsigned SI
3560 )
3561 : InheritableAttr(attr::GuardedVar, R, SI, false, false)
3562 {
3563 }
3564
3565 GuardedVarAttr *clone(ASTContext &C) const;
3566 void printPretty(raw_ostream &OS,
3567 const PrintingPolicy &Policy) const;
3568 const char *getSpelling() const;
3569
3570
3571 static bool classof(const Attr *A) { return A->getKind() == attr::GuardedVar; }
3572};
3573
3574class HotAttr : public InheritableAttr {
3575public:
3576 static HotAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3577 auto *A = new (Ctx) HotAttr(Loc, Ctx, 0);
3578 A->setImplicit(true);
3579 return A;
3580 }
3581
3582 HotAttr(SourceRange R, ASTContext &Ctx
3583 , unsigned SI
3584 )
3585 : InheritableAttr(attr::Hot, R, SI, false, false)
3586 {
3587 }
3588
3589 HotAttr *clone(ASTContext &C) const;
3590 void printPretty(raw_ostream &OS,
3591 const PrintingPolicy &Policy) const;
3592 const char *getSpelling() const;
3593
3594
3595 static bool classof(const Attr *A) { return A->getKind() == attr::Hot; }
3596};
3597
3598class IBActionAttr : public InheritableAttr {
3599public:
3600 static IBActionAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3601 auto *A = new (Ctx) IBActionAttr(Loc, Ctx, 0);
3602 A->setImplicit(true);
3603 return A;
3604 }
3605
3606 IBActionAttr(SourceRange R, ASTContext &Ctx
3607 , unsigned SI
3608 )
3609 : InheritableAttr(attr::IBAction, R, SI, false, false)
3610 {
3611 }
3612
3613 IBActionAttr *clone(ASTContext &C) const;
3614 void printPretty(raw_ostream &OS,
3615 const PrintingPolicy &Policy) const;
3616 const char *getSpelling() const;
3617
3618
3619 static bool classof(const Attr *A) { return A->getKind() == attr::IBAction; }
3620};
3621
3622class IBOutletAttr : public InheritableAttr {
3623public:
3624 static IBOutletAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3625 auto *A = new (Ctx) IBOutletAttr(Loc, Ctx, 0);
3626 A->setImplicit(true);
3627 return A;
3628 }
3629
3630 IBOutletAttr(SourceRange R, ASTContext &Ctx
3631 , unsigned SI
3632 )
3633 : InheritableAttr(attr::IBOutlet, R, SI, false, false)
3634 {
3635 }
3636
3637 IBOutletAttr *clone(ASTContext &C) const;
3638 void printPretty(raw_ostream &OS,
3639 const PrintingPolicy &Policy) const;
3640 const char *getSpelling() const;
3641
3642
3643 static bool classof(const Attr *A) { return A->getKind() == attr::IBOutlet; }
3644};
3645
3646class IBOutletCollectionAttr : public InheritableAttr {
3647TypeSourceInfo * interface_;
3648
3649public:
3650 static IBOutletCollectionAttr *CreateImplicit(ASTContext &Ctx, TypeSourceInfo * Interface, SourceRange Loc = SourceRange()) {
3651 auto *A = new (Ctx) IBOutletCollectionAttr(Loc, Ctx, Interface, 0);
3652 A->setImplicit(true);
3653 return A;
3654 }
3655
3656 IBOutletCollectionAttr(SourceRange R, ASTContext &Ctx
3657 , TypeSourceInfo * Interface
3658 , unsigned SI
3659 )
3660 : InheritableAttr(attr::IBOutletCollection, R, SI, false, false)
3661 , interface_(Interface)
3662 {
3663 }
3664
3665 IBOutletCollectionAttr(SourceRange R, ASTContext &Ctx
3666 , unsigned SI
3667 )
3668 : InheritableAttr(attr::IBOutletCollection, R, SI, false, false)
3669 , interface_()
3670 {
3671 }
3672
3673 IBOutletCollectionAttr *clone(ASTContext &C) const;
3674 void printPretty(raw_ostream &OS,
3675 const PrintingPolicy &Policy) const;
3676 const char *getSpelling() const;
3677 QualType getInterface() const {
3678 return interface_->getType();
3679 } TypeSourceInfo * getInterfaceLoc() const {
3680 return interface_;
3681 }
3682
3683
3684
3685 static bool classof(const Attr *A) { return A->getKind() == attr::IBOutletCollection; }
3686};
3687
3688class IFuncAttr : public Attr {
3689unsigned resolverLength;
3690char *resolver;
3691
3692public:
3693 static IFuncAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Resolver, SourceRange Loc = SourceRange()) {
3694 auto *A = new (Ctx) IFuncAttr(Loc, Ctx, Resolver, 0);
3695 A->setImplicit(true);
3696 return A;
3697 }
3698
3699 IFuncAttr(SourceRange R, ASTContext &Ctx
3700 , llvm::StringRef Resolver
3701 , unsigned SI
3702 )
3703 : Attr(attr::IFunc, R, SI, false)
3704 , resolverLength(Resolver.size()),resolver(new (Ctx, 1) char[resolverLength])
3705 {
3706 if (!Resolver.empty())
3707 std::memcpy(resolver, Resolver.data(), resolverLength);
3708 }
3709
3710 IFuncAttr *clone(ASTContext &C) const;
3711 void printPretty(raw_ostream &OS,
3712 const PrintingPolicy &Policy) const;
3713 const char *getSpelling() const;
3714 llvm::StringRef getResolver() const {
3715 return llvm::StringRef(resolver, resolverLength);
3716 }
3717 unsigned getResolverLength() const {
3718 return resolverLength;
3719 }
3720 void setResolver(ASTContext &C, llvm::StringRef S) {
3721 resolverLength = S.size();
3722 this->resolver = new (C, 1) char [resolverLength];
3723 if (!S.empty())
3724 std::memcpy(this->resolver, S.data(), resolverLength);
3725 }
3726
3727
3728
3729 static bool classof(const Attr *A) { return A->getKind() == attr::IFunc; }
3730};
3731
3732class InitPriorityAttr : public InheritableAttr {
3733unsigned priority;
3734
3735public:
3736 static InitPriorityAttr *CreateImplicit(ASTContext &Ctx, unsigned Priority, SourceRange Loc = SourceRange()) {
3737 auto *A = new (Ctx) InitPriorityAttr(Loc, Ctx, Priority, 0);
3738 A->setImplicit(true);
3739 return A;
3740 }
3741
3742 InitPriorityAttr(SourceRange R, ASTContext &Ctx
3743 , unsigned Priority
3744 , unsigned SI
3745 )
3746 : InheritableAttr(attr::InitPriority, R, SI, false, false)
3747 , priority(Priority)
3748 {
3749 }
3750
3751 InitPriorityAttr *clone(ASTContext &C) const;
3752 void printPretty(raw_ostream &OS,
3753 const PrintingPolicy &Policy) const;
3754 const char *getSpelling() const;
3755 unsigned getPriority() const {
3756 return priority;
3757 }
3758
3759
3760
3761 static bool classof(const Attr *A) { return A->getKind() == attr::InitPriority; }
3762};
3763
3764class InitSegAttr : public Attr {
3765unsigned sectionLength;
3766char *section;
3767
3768public:
3769 static InitSegAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Section, SourceRange Loc = SourceRange()) {
3770 auto *A = new (Ctx) InitSegAttr(Loc, Ctx, Section, 0);
3771 A->setImplicit(true);
3772 return A;
3773 }
3774
3775 InitSegAttr(SourceRange R, ASTContext &Ctx
3776 , llvm::StringRef Section
3777 , unsigned SI
3778 )
3779 : Attr(attr::InitSeg, R, SI, false)
3780 , sectionLength(Section.size()),section(new (Ctx, 1) char[sectionLength])
3781 {
3782 if (!Section.empty())
3783 std::memcpy(section, Section.data(), sectionLength);
3784 }
3785
3786 InitSegAttr *clone(ASTContext &C) const;
3787 void printPretty(raw_ostream &OS,
3788 const PrintingPolicy &Policy) const;
3789 const char *getSpelling() const;
3790 llvm::StringRef getSection() const {
3791 return llvm::StringRef(section, sectionLength);
3792 }
3793 unsigned getSectionLength() const {
3794 return sectionLength;
3795 }
3796 void setSection(ASTContext &C, llvm::StringRef S) {
3797 sectionLength = S.size();
3798 this->section = new (C, 1) char [sectionLength];
3799 if (!S.empty())
3800 std::memcpy(this->section, S.data(), sectionLength);
3801 }
3802
3803
3804 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
3805 OS << " (" << getSection() << ')';
3806 }
3807
3808
3809 static bool classof(const Attr *A) { return A->getKind() == attr::InitSeg; }
3810};
3811
3812class IntelOclBiccAttr : public InheritableAttr {
3813public:
3814 static IntelOclBiccAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3815 auto *A = new (Ctx) IntelOclBiccAttr(Loc, Ctx, 0);
3816 A->setImplicit(true);
3817 return A;
3818 }
3819
3820 IntelOclBiccAttr(SourceRange R, ASTContext &Ctx
3821 , unsigned SI
3822 )
3823 : InheritableAttr(attr::IntelOclBicc, R, SI, false, false)
3824 {
3825 }
3826
3827 IntelOclBiccAttr *clone(ASTContext &C) const;
3828 void printPretty(raw_ostream &OS,
3829 const PrintingPolicy &Policy) const;
3830 const char *getSpelling() const;
3831
3832
3833 static bool classof(const Attr *A) { return A->getKind() == attr::IntelOclBicc; }
3834};
3835
3836class InternalLinkageAttr : public InheritableAttr {
3837public:
3838 static InternalLinkageAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3839 auto *A = new (Ctx) InternalLinkageAttr(Loc, Ctx, 0);
3840 A->setImplicit(true);
3841 return A;
3842 }
3843
3844 InternalLinkageAttr(SourceRange R, ASTContext &Ctx
3845 , unsigned SI
3846 )
3847 : InheritableAttr(attr::InternalLinkage, R, SI, false, false)
3848 {
3849 }
3850
3851 InternalLinkageAttr *clone(ASTContext &C) const;
3852 void printPretty(raw_ostream &OS,
3853 const PrintingPolicy &Policy) const;
3854 const char *getSpelling() const;
3855
3856
3857 static bool classof(const Attr *A) { return A->getKind() == attr::InternalLinkage; }
3858};
3859
3860class LTOVisibilityPublicAttr : public InheritableAttr {
3861public:
3862 static LTOVisibilityPublicAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3863 auto *A = new (Ctx) LTOVisibilityPublicAttr(Loc, Ctx, 0);
3864 A->setImplicit(true);
3865 return A;
3866 }
3867
3868 LTOVisibilityPublicAttr(SourceRange R, ASTContext &Ctx
3869 , unsigned SI
3870 )
3871 : InheritableAttr(attr::LTOVisibilityPublic, R, SI, false, false)
3872 {
3873 }
3874
3875 LTOVisibilityPublicAttr *clone(ASTContext &C) const;
3876 void printPretty(raw_ostream &OS,
3877 const PrintingPolicy &Policy) const;
3878 const char *getSpelling() const;
3879
3880
3881 static bool classof(const Attr *A) { return A->getKind() == attr::LTOVisibilityPublic; }
3882};
3883
3884class LayoutVersionAttr : public InheritableAttr {
3885unsigned version;
3886
3887public:
3888 static LayoutVersionAttr *CreateImplicit(ASTContext &Ctx, unsigned Version, SourceRange Loc = SourceRange()) {
3889 auto *A = new (Ctx) LayoutVersionAttr(Loc, Ctx, Version, 0);
3890 A->setImplicit(true);
3891 return A;
3892 }
3893
3894 LayoutVersionAttr(SourceRange R, ASTContext &Ctx
3895 , unsigned Version
3896 , unsigned SI
3897 )
3898 : InheritableAttr(attr::LayoutVersion, R, SI, false, false)
3899 , version(Version)
3900 {
3901 }
3902
3903 LayoutVersionAttr *clone(ASTContext &C) const;
3904 void printPretty(raw_ostream &OS,
3905 const PrintingPolicy &Policy) const;
3906 const char *getSpelling() const;
3907 unsigned getVersion() const {
3908 return version;
3909 }
3910
3911
3912
3913 static bool classof(const Attr *A) { return A->getKind() == attr::LayoutVersion; }
3914};
3915
3916class LifetimeBoundAttr : public InheritableAttr {
3917public:
3918 static LifetimeBoundAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3919 auto *A = new (Ctx) LifetimeBoundAttr(Loc, Ctx, 0);
3920 A->setImplicit(true);
3921 return A;
3922 }
3923
3924 LifetimeBoundAttr(SourceRange R, ASTContext &Ctx
3925 , unsigned SI
3926 )
3927 : InheritableAttr(attr::LifetimeBound, R, SI, false, false)
3928 {
3929 }
3930
3931 LifetimeBoundAttr *clone(ASTContext &C) const;
3932 void printPretty(raw_ostream &OS,
3933 const PrintingPolicy &Policy) const;
3934 const char *getSpelling() const;
3935
3936
3937 static bool classof(const Attr *A) { return A->getKind() == attr::LifetimeBound; }
3938};
3939
3940class LockReturnedAttr : public InheritableAttr {
3941Expr * arg;
3942
3943public:
3944 static LockReturnedAttr *CreateImplicit(ASTContext &Ctx, Expr * Arg, SourceRange Loc = SourceRange()) {
3945 auto *A = new (Ctx) LockReturnedAttr(Loc, Ctx, Arg, 0);
3946 A->setImplicit(true);
3947 return A;
3948 }
3949
3950 LockReturnedAttr(SourceRange R, ASTContext &Ctx
3951 , Expr * Arg
3952 , unsigned SI
3953 )
3954 : InheritableAttr(attr::LockReturned, R, SI, true, false)
3955 , arg(Arg)
3956 {
3957 }
3958
3959 LockReturnedAttr *clone(ASTContext &C) const;
3960 void printPretty(raw_ostream &OS,
3961 const PrintingPolicy &Policy) const;
3962 const char *getSpelling() const;
3963 Expr * getArg() const {
3964 return arg;
3965 }
3966
3967
3968
3969 static bool classof(const Attr *A) { return A->getKind() == attr::LockReturned; }
3970};
3971
3972class LocksExcludedAttr : public InheritableAttr {
3973 unsigned args_Size;
3974 Expr * *args_;
3975
3976public:
3977 static LocksExcludedAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
3978 auto *A = new (Ctx) LocksExcludedAttr(Loc, Ctx, Args, ArgsSize, 0);
3979 A->setImplicit(true);
3980 return A;
3981 }
3982
3983 LocksExcludedAttr(SourceRange R, ASTContext &Ctx
3984 , Expr * *Args, unsigned ArgsSize
3985 , unsigned SI
3986 )
3987 : InheritableAttr(attr::LocksExcluded, R, SI, true, true)
3988 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
3989 {
3990 std::copy(Args, Args + args_Size, args_);
3991 }
3992
3993 LocksExcludedAttr(SourceRange R, ASTContext &Ctx
3994 , unsigned SI
3995 )
3996 : InheritableAttr(attr::LocksExcluded, R, SI, true, true)
3997 , args_Size(0), args_(nullptr)
3998 {
3999 }
4000
4001 LocksExcludedAttr *clone(ASTContext &C) const;
4002 void printPretty(raw_ostream &OS,
4003 const PrintingPolicy &Policy) const;
4004 const char *getSpelling() const;
4005 typedef Expr ** args_iterator;
4006 args_iterator args_begin() const { return args_; }
4007 args_iterator args_end() const { return args_ + args_Size; }
4008 unsigned args_size() const { return args_Size; }
4009 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
4010
4011
4012
4013
4014 static bool classof(const Attr *A) { return A->getKind() == attr::LocksExcluded; }
4015};
4016
4017class LoopHintAttr : public Attr {
4018public:
4019 enum OptionType {
4020 Vectorize,
4021 VectorizeWidth,
4022 Interleave,
4023 InterleaveCount,
4024 Unroll,
4025 UnrollCount,
4026 UnrollAndJam,
4027 UnrollAndJamCount,
4028 Distribute
4029 };
4030private:
4031 OptionType option;
4032
4033public:
4034 enum LoopHintState {
4035 Enable,
4036 Disable,
4037 Numeric,
4038 AssumeSafety,
4039 Full
4040 };
4041private:
4042 LoopHintState state;
4043
4044Expr * value;
4045
4046public:
4047 enum Spelling {
4048 Pragma_clang_loop = 0,
4049 Pragma_unroll = 1,
4050 Pragma_nounroll = 2,
4051 Pragma_unroll_and_jam = 3,
4052 Pragma_nounroll_and_jam = 4
4053 };
4054
4055 static LoopHintAttr *CreateImplicit(ASTContext &Ctx, Spelling S, OptionType Option, LoopHintState State, Expr * Value, SourceRange Loc = SourceRange()) {
4056 auto *A = new (Ctx) LoopHintAttr(Loc, Ctx, Option, State, Value, S);
4057 A->setImplicit(true);
4058 return A;
4059 }
4060
4061 LoopHintAttr(SourceRange R, ASTContext &Ctx
4062 , OptionType Option
4063 , LoopHintState State
4064 , Expr * Value
4065 , unsigned SI
4066 )
4067 : Attr(attr::LoopHint, R, SI, false)
4068 , option(Option)
4069 , state(State)
4070 , value(Value)
4071 {
4072 }
4073
4074 LoopHintAttr *clone(ASTContext &C) const;
4075 void printPretty(raw_ostream &OS,
4076 const PrintingPolicy &Policy) const;
4077 const char *getSpelling() const;
4078 Spelling getSemanticSpelling() const {
4079 switch (SpellingListIndex) {
4080 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-8~svn350071/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 4080)
;
4081 case 0: return Pragma_clang_loop;
4082 case 1: return Pragma_unroll;
4083 case 2: return Pragma_nounroll;
4084 case 3: return Pragma_unroll_and_jam;
4085 case 4: return Pragma_nounroll_and_jam;
4086 }
4087 }
4088 OptionType getOption() const {
4089 return option;
4090 }
4091
4092 static bool ConvertStrToOptionType(StringRef Val, OptionType &Out) {
4093 Optional<OptionType> R = llvm::StringSwitch<Optional<OptionType>>(Val)
4094 .Case("vectorize", LoopHintAttr::Vectorize)
4095 .Case("vectorize_width", LoopHintAttr::VectorizeWidth)
4096 .Case("interleave", LoopHintAttr::Interleave)
4097 .Case("interleave_count", LoopHintAttr::InterleaveCount)
4098 .Case("unroll", LoopHintAttr::Unroll)
4099 .Case("unroll_count", LoopHintAttr::UnrollCount)
4100 .Case("unroll_and_jam", LoopHintAttr::UnrollAndJam)
4101 .Case("unroll_and_jam_count", LoopHintAttr::UnrollAndJamCount)
4102 .Case("distribute", LoopHintAttr::Distribute)
4103 .Default(Optional<OptionType>());
4104 if (R) {
4105 Out = *R;
4106 return true;
4107 }
4108 return false;
4109 }
4110
4111 static const char *ConvertOptionTypeToStr(OptionType Val) {
4112 switch(Val) {
4113 case LoopHintAttr::Vectorize: return "vectorize";
4114 case LoopHintAttr::VectorizeWidth: return "vectorize_width";
4115 case LoopHintAttr::Interleave: return "interleave";
4116 case LoopHintAttr::InterleaveCount: return "interleave_count";
4117 case LoopHintAttr::Unroll: return "unroll";
4118 case LoopHintAttr::UnrollCount: return "unroll_count";
4119 case LoopHintAttr::UnrollAndJam: return "unroll_and_jam";
4120 case LoopHintAttr::UnrollAndJamCount: return "unroll_and_jam_count";
4121 case LoopHintAttr::Distribute: return "distribute";
4122 }
4123 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-8~svn350071/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 4123)
;
4124 }
4125 LoopHintState getState() const {
4126 return state;
4127 }
4128
4129 static bool ConvertStrToLoopHintState(StringRef Val, LoopHintState &Out) {
4130 Optional<LoopHintState> R = llvm::StringSwitch<Optional<LoopHintState>>(Val)
4131 .Case("enable", LoopHintAttr::Enable)
4132 .Case("disable", LoopHintAttr::Disable)
4133 .Case("numeric", LoopHintAttr::Numeric)
4134 .Case("assume_safety", LoopHintAttr::AssumeSafety)
4135 .Case("full", LoopHintAttr::Full)
4136 .Default(Optional<LoopHintState>());
4137 if (R) {
4138 Out = *R;
4139 return true;
4140 }
4141 return false;
4142 }
4143
4144 static const char *ConvertLoopHintStateToStr(LoopHintState Val) {
4145 switch(Val) {
4146 case LoopHintAttr::Enable: return "enable";
4147 case LoopHintAttr::Disable: return "disable";
4148 case LoopHintAttr::Numeric: return "numeric";
4149 case LoopHintAttr::AssumeSafety: return "assume_safety";
4150 case LoopHintAttr::Full: return "full";
4151 }
4152 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-8~svn350071/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 4152)
;
4153 }
4154 Expr * getValue() const {
4155 return value;
4156 }
4157
4158
4159 static const char *getOptionName(int Option) {
4160 switch(Option) {
4161 case Vectorize: return "vectorize";
4162 case VectorizeWidth: return "vectorize_width";
4163 case Interleave: return "interleave";
4164 case InterleaveCount: return "interleave_count";
4165 case Unroll: return "unroll";
4166 case UnrollCount: return "unroll_count";
4167 case UnrollAndJam: return "unroll_and_jam";
4168 case UnrollAndJamCount: return "unroll_and_jam_count";
4169 case Distribute: return "distribute";
4170 }
4171 llvm_unreachable("Unhandled LoopHint option.")::llvm::llvm_unreachable_internal("Unhandled LoopHint option."
, "/build/llvm-toolchain-snapshot-8~svn350071/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 4171)
;
4172 }
4173
4174 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
4175 unsigned SpellingIndex = getSpellingListIndex();
4176 // For "#pragma unroll" and "#pragma nounroll" the string "unroll" or
4177 // "nounroll" is already emitted as the pragma name.
4178 if (SpellingIndex == Pragma_nounroll || SpellingIndex == Pragma_nounroll_and_jam)
4179 return;
4180 else if (SpellingIndex == Pragma_unroll || SpellingIndex == Pragma_unroll_and_jam) {
4181 OS << ' ' << getValueString(Policy);
4182 return;
4183 }
4184
4185 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-8~svn350071/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 4185, __PRETTY_FUNCTION__))
;
4186 OS << ' ' << getOptionName(option) << getValueString(Policy);
4187 }
4188
4189 // Return a string containing the loop hint argument including the
4190 // enclosing parentheses.
4191 std::string getValueString(const PrintingPolicy &Policy) const {
4192 std::string ValueName;
4193 llvm::raw_string_ostream OS(ValueName);
4194 OS << "(";
4195 if (state == Numeric)
4196 value->printPretty(OS, nullptr, Policy);
4197 else if (state == Enable)
4198 OS << "enable";