Bug Summary

File:build-llvm/tools/clang/include/clang/AST/Attrs.inc
Warning:line 9612, 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-9/lib/clang/9.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-9~svn361465/build-llvm/tools/clang/lib/Sema -I /build/llvm-toolchain-snapshot-9~svn361465/tools/clang/lib/Sema -I /build/llvm-toolchain-snapshot-9~svn361465/tools/clang/include -I /build/llvm-toolchain-snapshot-9~svn361465/build-llvm/tools/clang/include -I /build/llvm-toolchain-snapshot-9~svn361465/build-llvm/include -I /build/llvm-toolchain-snapshot-9~svn361465/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/9.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-9/lib/clang/9.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-9~svn361465/build-llvm/tools/clang/lib/Sema -fdebug-prefix-map=/build/llvm-toolchain-snapshot-9~svn361465=. -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-2019-05-24-031927-21217-1 -x c++ /build/llvm-toolchain-snapshot-9~svn361465/tools/clang/lib/Sema/Sema.cpp -faddrsig

/build/llvm-toolchain-snapshot-9~svn361465/tools/clang/lib/Sema/Sema.cpp

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

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