Bug Summary

File:tools/clang/lib/Sema/SemaExprCXX.cpp
Warning:line 8424, column 5
Called C++ object pointer is null

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 SemaExprCXX.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -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 -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-7/lib/clang/7.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/lib/Sema -I /build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema -I /build/llvm-toolchain-snapshot-7~svn329677/tools/clang/include -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn329677/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.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-7~svn329677/build-llvm/tools/clang/lib/Sema -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fno-common -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-04-11-031539-24776-1 -x c++ /build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp

/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp

1//===--- SemaExprCXX.cpp - Semantic Analysis for Expressions --------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief Implements semantic analysis for C++ expressions.
12///
13//===----------------------------------------------------------------------===//
14
15#include "clang/Sema/SemaInternal.h"
16#include "TreeTransform.h"
17#include "TypeLocBuilder.h"
18#include "clang/AST/ASTContext.h"
19#include "clang/AST/ASTLambda.h"
20#include "clang/AST/CXXInheritance.h"
21#include "clang/AST/CharUnits.h"
22#include "clang/AST/DeclObjC.h"
23#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
25#include "clang/AST/RecursiveASTVisitor.h"
26#include "clang/AST/TypeLoc.h"
27#include "clang/Basic/AlignedAllocation.h"
28#include "clang/Basic/PartialDiagnostic.h"
29#include "clang/Basic/TargetInfo.h"
30#include "clang/Lex/Preprocessor.h"
31#include "clang/Sema/DeclSpec.h"
32#include "clang/Sema/Initialization.h"
33#include "clang/Sema/Lookup.h"
34#include "clang/Sema/ParsedTemplate.h"
35#include "clang/Sema/Scope.h"
36#include "clang/Sema/ScopeInfo.h"
37#include "clang/Sema/SemaLambda.h"
38#include "clang/Sema/TemplateDeduction.h"
39#include "llvm/ADT/APInt.h"
40#include "llvm/ADT/STLExtras.h"
41#include "llvm/Support/ErrorHandling.h"
42using namespace clang;
43using namespace sema;
44
45/// \brief Handle the result of the special case name lookup for inheriting
46/// constructor declarations. 'NS::X::X' and 'NS::X<...>::X' are treated as
47/// constructor names in member using declarations, even if 'X' is not the
48/// name of the corresponding type.
49ParsedType Sema::getInheritingConstructorName(CXXScopeSpec &SS,
50 SourceLocation NameLoc,
51 IdentifierInfo &Name) {
52 NestedNameSpecifier *NNS = SS.getScopeRep();
53
54 // Convert the nested-name-specifier into a type.
55 QualType Type;
56 switch (NNS->getKind()) {
57 case NestedNameSpecifier::TypeSpec:
58 case NestedNameSpecifier::TypeSpecWithTemplate:
59 Type = QualType(NNS->getAsType(), 0);
60 break;
61
62 case NestedNameSpecifier::Identifier:
63 // Strip off the last layer of the nested-name-specifier and build a
64 // typename type for it.
65 assert(NNS->getAsIdentifier() == &Name && "not a constructor name")(static_cast <bool> (NNS->getAsIdentifier() == &
Name && "not a constructor name") ? void (0) : __assert_fail
("NNS->getAsIdentifier() == &Name && \"not a constructor name\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 65, __extension__ __PRETTY_FUNCTION__))
;
66 Type = Context.getDependentNameType(ETK_None, NNS->getPrefix(),
67 NNS->getAsIdentifier());
68 break;
69
70 case NestedNameSpecifier::Global:
71 case NestedNameSpecifier::Super:
72 case NestedNameSpecifier::Namespace:
73 case NestedNameSpecifier::NamespaceAlias:
74 llvm_unreachable("Nested name specifier is not a type for inheriting ctor")::llvm::llvm_unreachable_internal("Nested name specifier is not a type for inheriting ctor"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 74)
;
75 }
76
77 // This reference to the type is located entirely at the location of the
78 // final identifier in the qualified-id.
79 return CreateParsedType(Type,
80 Context.getTrivialTypeSourceInfo(Type, NameLoc));
81}
82
83ParsedType Sema::getDestructorName(SourceLocation TildeLoc,
84 IdentifierInfo &II,
85 SourceLocation NameLoc,
86 Scope *S, CXXScopeSpec &SS,
87 ParsedType ObjectTypePtr,
88 bool EnteringContext) {
89 // Determine where to perform name lookup.
90
91 // FIXME: This area of the standard is very messy, and the current
92 // wording is rather unclear about which scopes we search for the
93 // destructor name; see core issues 399 and 555. Issue 399 in
94 // particular shows where the current description of destructor name
95 // lookup is completely out of line with existing practice, e.g.,
96 // this appears to be ill-formed:
97 //
98 // namespace N {
99 // template <typename T> struct S {
100 // ~S();
101 // };
102 // }
103 //
104 // void f(N::S<int>* s) {
105 // s->N::S<int>::~S();
106 // }
107 //
108 // See also PR6358 and PR6359.
109 // For this reason, we're currently only doing the C++03 version of this
110 // code; the C++0x version has to wait until we get a proper spec.
111 QualType SearchType;
112 DeclContext *LookupCtx = nullptr;
113 bool isDependent = false;
114 bool LookInScope = false;
115
116 if (SS.isInvalid())
117 return nullptr;
118
119 // If we have an object type, it's because we are in a
120 // pseudo-destructor-expression or a member access expression, and
121 // we know what type we're looking for.
122 if (ObjectTypePtr)
123 SearchType = GetTypeFromParser(ObjectTypePtr);
124
125 if (SS.isSet()) {
126 NestedNameSpecifier *NNS = SS.getScopeRep();
127
128 bool AlreadySearched = false;
129 bool LookAtPrefix = true;
130 // C++11 [basic.lookup.qual]p6:
131 // If a pseudo-destructor-name (5.2.4) contains a nested-name-specifier,
132 // the type-names are looked up as types in the scope designated by the
133 // nested-name-specifier. Similarly, in a qualified-id of the form:
134 //
135 // nested-name-specifier[opt] class-name :: ~ class-name
136 //
137 // the second class-name is looked up in the same scope as the first.
138 //
139 // Here, we determine whether the code below is permitted to look at the
140 // prefix of the nested-name-specifier.
141 DeclContext *DC = computeDeclContext(SS, EnteringContext);
142 if (DC && DC->isFileContext()) {
143 AlreadySearched = true;
144 LookupCtx = DC;
145 isDependent = false;
146 } else if (DC && isa<CXXRecordDecl>(DC)) {
147 LookAtPrefix = false;
148 LookInScope = true;
149 }
150
151 // The second case from the C++03 rules quoted further above.
152 NestedNameSpecifier *Prefix = nullptr;
153 if (AlreadySearched) {
154 // Nothing left to do.
155 } else if (LookAtPrefix && (Prefix = NNS->getPrefix())) {
156 CXXScopeSpec PrefixSS;
157 PrefixSS.Adopt(NestedNameSpecifierLoc(Prefix, SS.location_data()));
158 LookupCtx = computeDeclContext(PrefixSS, EnteringContext);
159 isDependent = isDependentScopeSpecifier(PrefixSS);
160 } else if (ObjectTypePtr) {
161 LookupCtx = computeDeclContext(SearchType);
162 isDependent = SearchType->isDependentType();
163 } else {
164 LookupCtx = computeDeclContext(SS, EnteringContext);
165 isDependent = LookupCtx && LookupCtx->isDependentContext();
166 }
167 } else if (ObjectTypePtr) {
168 // C++ [basic.lookup.classref]p3:
169 // If the unqualified-id is ~type-name, the type-name is looked up
170 // in the context of the entire postfix-expression. If the type T
171 // of the object expression is of a class type C, the type-name is
172 // also looked up in the scope of class C. At least one of the
173 // lookups shall find a name that refers to (possibly
174 // cv-qualified) T.
175 LookupCtx = computeDeclContext(SearchType);
176 isDependent = SearchType->isDependentType();
177 assert((isDependent || !SearchType->isIncompleteType()) &&(static_cast <bool> ((isDependent || !SearchType->isIncompleteType
()) && "Caller should have completed object type") ? void
(0) : __assert_fail ("(isDependent || !SearchType->isIncompleteType()) && \"Caller should have completed object type\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 178, __extension__ __PRETTY_FUNCTION__))
178 "Caller should have completed object type")(static_cast <bool> ((isDependent || !SearchType->isIncompleteType
()) && "Caller should have completed object type") ? void
(0) : __assert_fail ("(isDependent || !SearchType->isIncompleteType()) && \"Caller should have completed object type\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 178, __extension__ __PRETTY_FUNCTION__))
;
179
180 LookInScope = true;
181 } else {
182 // Perform lookup into the current scope (only).
183 LookInScope = true;
184 }
185
186 TypeDecl *NonMatchingTypeDecl = nullptr;
187 LookupResult Found(*this, &II, NameLoc, LookupOrdinaryName);
188 for (unsigned Step = 0; Step != 2; ++Step) {
189 // Look for the name first in the computed lookup context (if we
190 // have one) and, if that fails to find a match, in the scope (if
191 // we're allowed to look there).
192 Found.clear();
193 if (Step == 0 && LookupCtx) {
194 if (RequireCompleteDeclContext(SS, LookupCtx))
195 return nullptr;
196 LookupQualifiedName(Found, LookupCtx);
197 } else if (Step == 1 && LookInScope && S) {
198 LookupName(Found, S);
199 } else {
200 continue;
201 }
202
203 // FIXME: Should we be suppressing ambiguities here?
204 if (Found.isAmbiguous())
205 return nullptr;
206
207 if (TypeDecl *Type = Found.getAsSingle<TypeDecl>()) {
208 QualType T = Context.getTypeDeclType(Type);
209 MarkAnyDeclReferenced(Type->getLocation(), Type, /*OdrUse=*/false);
210
211 if (SearchType.isNull() || SearchType->isDependentType() ||
212 Context.hasSameUnqualifiedType(T, SearchType)) {
213 // We found our type!
214
215 return CreateParsedType(T,
216 Context.getTrivialTypeSourceInfo(T, NameLoc));
217 }
218
219 if (!SearchType.isNull())
220 NonMatchingTypeDecl = Type;
221 }
222
223 // If the name that we found is a class template name, and it is
224 // the same name as the template name in the last part of the
225 // nested-name-specifier (if present) or the object type, then
226 // this is the destructor for that class.
227 // FIXME: This is a workaround until we get real drafting for core
228 // issue 399, for which there isn't even an obvious direction.
229 if (ClassTemplateDecl *Template = Found.getAsSingle<ClassTemplateDecl>()) {
230 QualType MemberOfType;
231 if (SS.isSet()) {
232 if (DeclContext *Ctx = computeDeclContext(SS, EnteringContext)) {
233 // Figure out the type of the context, if it has one.
234 if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Ctx))
235 MemberOfType = Context.getTypeDeclType(Record);
236 }
237 }
238 if (MemberOfType.isNull())
239 MemberOfType = SearchType;
240
241 if (MemberOfType.isNull())
242 continue;
243
244 // We're referring into a class template specialization. If the
245 // class template we found is the same as the template being
246 // specialized, we found what we are looking for.
247 if (const RecordType *Record = MemberOfType->getAs<RecordType>()) {
248 if (ClassTemplateSpecializationDecl *Spec
249 = dyn_cast<ClassTemplateSpecializationDecl>(Record->getDecl())) {
250 if (Spec->getSpecializedTemplate()->getCanonicalDecl() ==
251 Template->getCanonicalDecl())
252 return CreateParsedType(
253 MemberOfType,
254 Context.getTrivialTypeSourceInfo(MemberOfType, NameLoc));
255 }
256
257 continue;
258 }
259
260 // We're referring to an unresolved class template
261 // specialization. Determine whether we class template we found
262 // is the same as the template being specialized or, if we don't
263 // know which template is being specialized, that it at least
264 // has the same name.
265 if (const TemplateSpecializationType *SpecType
266 = MemberOfType->getAs<TemplateSpecializationType>()) {
267 TemplateName SpecName = SpecType->getTemplateName();
268
269 // The class template we found is the same template being
270 // specialized.
271 if (TemplateDecl *SpecTemplate = SpecName.getAsTemplateDecl()) {
272 if (SpecTemplate->getCanonicalDecl() == Template->getCanonicalDecl())
273 return CreateParsedType(
274 MemberOfType,
275 Context.getTrivialTypeSourceInfo(MemberOfType, NameLoc));
276
277 continue;
278 }
279
280 // The class template we found has the same name as the
281 // (dependent) template name being specialized.
282 if (DependentTemplateName *DepTemplate
283 = SpecName.getAsDependentTemplateName()) {
284 if (DepTemplate->isIdentifier() &&
285 DepTemplate->getIdentifier() == Template->getIdentifier())
286 return CreateParsedType(
287 MemberOfType,
288 Context.getTrivialTypeSourceInfo(MemberOfType, NameLoc));
289
290 continue;
291 }
292 }
293 }
294 }
295
296 if (isDependent) {
297 // We didn't find our type, but that's okay: it's dependent
298 // anyway.
299
300 // FIXME: What if we have no nested-name-specifier?
301 QualType T = CheckTypenameType(ETK_None, SourceLocation(),
302 SS.getWithLocInContext(Context),
303 II, NameLoc);
304 return ParsedType::make(T);
305 }
306
307 if (NonMatchingTypeDecl) {
308 QualType T = Context.getTypeDeclType(NonMatchingTypeDecl);
309 Diag(NameLoc, diag::err_destructor_expr_type_mismatch)
310 << T << SearchType;
311 Diag(NonMatchingTypeDecl->getLocation(), diag::note_destructor_type_here)
312 << T;
313 } else if (ObjectTypePtr)
314 Diag(NameLoc, diag::err_ident_in_dtor_not_a_type)
315 << &II;
316 else {
317 SemaDiagnosticBuilder DtorDiag = Diag(NameLoc,
318 diag::err_destructor_class_name);
319 if (S) {
320 const DeclContext *Ctx = S->getEntity();
321 if (const CXXRecordDecl *Class = dyn_cast_or_null<CXXRecordDecl>(Ctx))
322 DtorDiag << FixItHint::CreateReplacement(SourceRange(NameLoc),
323 Class->getNameAsString());
324 }
325 }
326
327 return nullptr;
328}
329
330ParsedType Sema::getDestructorTypeForDecltype(const DeclSpec &DS,
331 ParsedType ObjectType) {
332 if (DS.getTypeSpecType() == DeclSpec::TST_error)
333 return nullptr;
334
335 if (DS.getTypeSpecType() == DeclSpec::TST_decltype_auto) {
336 Diag(DS.getTypeSpecTypeLoc(), diag::err_decltype_auto_invalid);
337 return nullptr;
338 }
339
340 assert(DS.getTypeSpecType() == DeclSpec::TST_decltype &&(static_cast <bool> (DS.getTypeSpecType() == DeclSpec::
TST_decltype && "unexpected type in getDestructorType"
) ? void (0) : __assert_fail ("DS.getTypeSpecType() == DeclSpec::TST_decltype && \"unexpected type in getDestructorType\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 341, __extension__ __PRETTY_FUNCTION__))
341 "unexpected type in getDestructorType")(static_cast <bool> (DS.getTypeSpecType() == DeclSpec::
TST_decltype && "unexpected type in getDestructorType"
) ? void (0) : __assert_fail ("DS.getTypeSpecType() == DeclSpec::TST_decltype && \"unexpected type in getDestructorType\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 341, __extension__ __PRETTY_FUNCTION__))
;
342 QualType T = BuildDecltypeType(DS.getRepAsExpr(), DS.getTypeSpecTypeLoc());
343
344 // If we know the type of the object, check that the correct destructor
345 // type was named now; we can give better diagnostics this way.
346 QualType SearchType = GetTypeFromParser(ObjectType);
347 if (!SearchType.isNull() && !SearchType->isDependentType() &&
348 !Context.hasSameUnqualifiedType(T, SearchType)) {
349 Diag(DS.getTypeSpecTypeLoc(), diag::err_destructor_expr_type_mismatch)
350 << T << SearchType;
351 return nullptr;
352 }
353
354 return ParsedType::make(T);
355}
356
357bool Sema::checkLiteralOperatorId(const CXXScopeSpec &SS,
358 const UnqualifiedId &Name) {
359 assert(Name.getKind() == UnqualifiedIdKind::IK_LiteralOperatorId)(static_cast <bool> (Name.getKind() == UnqualifiedIdKind
::IK_LiteralOperatorId) ? void (0) : __assert_fail ("Name.getKind() == UnqualifiedIdKind::IK_LiteralOperatorId"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 359, __extension__ __PRETTY_FUNCTION__))
;
360
361 if (!SS.isValid())
362 return false;
363
364 switch (SS.getScopeRep()->getKind()) {
365 case NestedNameSpecifier::Identifier:
366 case NestedNameSpecifier::TypeSpec:
367 case NestedNameSpecifier::TypeSpecWithTemplate:
368 // Per C++11 [over.literal]p2, literal operators can only be declared at
369 // namespace scope. Therefore, this unqualified-id cannot name anything.
370 // Reject it early, because we have no AST representation for this in the
371 // case where the scope is dependent.
372 Diag(Name.getLocStart(), diag::err_literal_operator_id_outside_namespace)
373 << SS.getScopeRep();
374 return true;
375
376 case NestedNameSpecifier::Global:
377 case NestedNameSpecifier::Super:
378 case NestedNameSpecifier::Namespace:
379 case NestedNameSpecifier::NamespaceAlias:
380 return false;
381 }
382
383 llvm_unreachable("unknown nested name specifier kind")::llvm::llvm_unreachable_internal("unknown nested name specifier kind"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 383)
;
384}
385
386/// \brief Build a C++ typeid expression with a type operand.
387ExprResult Sema::BuildCXXTypeId(QualType TypeInfoType,
388 SourceLocation TypeidLoc,
389 TypeSourceInfo *Operand,
390 SourceLocation RParenLoc) {
391 // C++ [expr.typeid]p4:
392 // The top-level cv-qualifiers of the lvalue expression or the type-id
393 // that is the operand of typeid are always ignored.
394 // If the type of the type-id is a class type or a reference to a class
395 // type, the class shall be completely-defined.
396 Qualifiers Quals;
397 QualType T
398 = Context.getUnqualifiedArrayType(Operand->getType().getNonReferenceType(),
399 Quals);
400 if (T->getAs<RecordType>() &&
401 RequireCompleteType(TypeidLoc, T, diag::err_incomplete_typeid))
402 return ExprError();
403
404 if (T->isVariablyModifiedType())
405 return ExprError(Diag(TypeidLoc, diag::err_variably_modified_typeid) << T);
406
407 return new (Context) CXXTypeidExpr(TypeInfoType.withConst(), Operand,
408 SourceRange(TypeidLoc, RParenLoc));
409}
410
411/// \brief Build a C++ typeid expression with an expression operand.
412ExprResult Sema::BuildCXXTypeId(QualType TypeInfoType,
413 SourceLocation TypeidLoc,
414 Expr *E,
415 SourceLocation RParenLoc) {
416 bool WasEvaluated = false;
417 if (E && !E->isTypeDependent()) {
418 if (E->getType()->isPlaceholderType()) {
419 ExprResult result = CheckPlaceholderExpr(E);
420 if (result.isInvalid()) return ExprError();
421 E = result.get();
422 }
423
424 QualType T = E->getType();
425 if (const RecordType *RecordT = T->getAs<RecordType>()) {
426 CXXRecordDecl *RecordD = cast<CXXRecordDecl>(RecordT->getDecl());
427 // C++ [expr.typeid]p3:
428 // [...] If the type of the expression is a class type, the class
429 // shall be completely-defined.
430 if (RequireCompleteType(TypeidLoc, T, diag::err_incomplete_typeid))
431 return ExprError();
432
433 // C++ [expr.typeid]p3:
434 // When typeid is applied to an expression other than an glvalue of a
435 // polymorphic class type [...] [the] expression is an unevaluated
436 // operand. [...]
437 if (RecordD->isPolymorphic() && E->isGLValue()) {
438 // The subexpression is potentially evaluated; switch the context
439 // and recheck the subexpression.
440 ExprResult Result = TransformToPotentiallyEvaluated(E);
441 if (Result.isInvalid()) return ExprError();
442 E = Result.get();
443
444 // We require a vtable to query the type at run time.
445 MarkVTableUsed(TypeidLoc, RecordD);
446 WasEvaluated = true;
447 }
448 }
449
450 // C++ [expr.typeid]p4:
451 // [...] If the type of the type-id is a reference to a possibly
452 // cv-qualified type, the result of the typeid expression refers to a
453 // std::type_info object representing the cv-unqualified referenced
454 // type.
455 Qualifiers Quals;
456 QualType UnqualT = Context.getUnqualifiedArrayType(T, Quals);
457 if (!Context.hasSameType(T, UnqualT)) {
458 T = UnqualT;
459 E = ImpCastExprToType(E, UnqualT, CK_NoOp, E->getValueKind()).get();
460 }
461 }
462
463 if (E->getType()->isVariablyModifiedType())
464 return ExprError(Diag(TypeidLoc, diag::err_variably_modified_typeid)
465 << E->getType());
466 else if (!inTemplateInstantiation() &&
467 E->HasSideEffects(Context, WasEvaluated)) {
468 // The expression operand for typeid is in an unevaluated expression
469 // context, so side effects could result in unintended consequences.
470 Diag(E->getExprLoc(), WasEvaluated
471 ? diag::warn_side_effects_typeid
472 : diag::warn_side_effects_unevaluated_context);
473 }
474
475 return new (Context) CXXTypeidExpr(TypeInfoType.withConst(), E,
476 SourceRange(TypeidLoc, RParenLoc));
477}
478
479/// ActOnCXXTypeidOfType - Parse typeid( type-id ) or typeid (expression);
480ExprResult
481Sema::ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation LParenLoc,
482 bool isType, void *TyOrExpr, SourceLocation RParenLoc) {
483 // Find the std::type_info type.
484 if (!getStdNamespace())
485 return ExprError(Diag(OpLoc, diag::err_need_header_before_typeid));
486
487 if (!CXXTypeInfoDecl) {
488 IdentifierInfo *TypeInfoII = &PP.getIdentifierTable().get("type_info");
489 LookupResult R(*this, TypeInfoII, SourceLocation(), LookupTagName);
490 LookupQualifiedName(R, getStdNamespace());
491 CXXTypeInfoDecl = R.getAsSingle<RecordDecl>();
492 // Microsoft's typeinfo doesn't have type_info in std but in the global
493 // namespace if _HAS_EXCEPTIONS is defined to 0. See PR13153.
494 if (!CXXTypeInfoDecl && LangOpts.MSVCCompat) {
495 LookupQualifiedName(R, Context.getTranslationUnitDecl());
496 CXXTypeInfoDecl = R.getAsSingle<RecordDecl>();
497 }
498 if (!CXXTypeInfoDecl)
499 return ExprError(Diag(OpLoc, diag::err_need_header_before_typeid));
500 }
501
502 if (!getLangOpts().RTTI) {
503 return ExprError(Diag(OpLoc, diag::err_no_typeid_with_fno_rtti));
504 }
505
506 QualType TypeInfoType = Context.getTypeDeclType(CXXTypeInfoDecl);
507
508 if (isType) {
509 // The operand is a type; handle it as such.
510 TypeSourceInfo *TInfo = nullptr;
511 QualType T = GetTypeFromParser(ParsedType::getFromOpaquePtr(TyOrExpr),
512 &TInfo);
513 if (T.isNull())
514 return ExprError();
515
516 if (!TInfo)
517 TInfo = Context.getTrivialTypeSourceInfo(T, OpLoc);
518
519 return BuildCXXTypeId(TypeInfoType, OpLoc, TInfo, RParenLoc);
520 }
521
522 // The operand is an expression.
523 return BuildCXXTypeId(TypeInfoType, OpLoc, (Expr*)TyOrExpr, RParenLoc);
524}
525
526/// Grabs __declspec(uuid()) off a type, or returns 0 if we cannot resolve to
527/// a single GUID.
528static void
529getUuidAttrOfType(Sema &SemaRef, QualType QT,
530 llvm::SmallSetVector<const UuidAttr *, 1> &UuidAttrs) {
531 // Optionally remove one level of pointer, reference or array indirection.
532 const Type *Ty = QT.getTypePtr();
533 if (QT->isPointerType() || QT->isReferenceType())
534 Ty = QT->getPointeeType().getTypePtr();
535 else if (QT->isArrayType())
536 Ty = Ty->getBaseElementTypeUnsafe();
537
538 const auto *TD = Ty->getAsTagDecl();
539 if (!TD)
540 return;
541
542 if (const auto *Uuid = TD->getMostRecentDecl()->getAttr<UuidAttr>()) {
543 UuidAttrs.insert(Uuid);
544 return;
545 }
546
547 // __uuidof can grab UUIDs from template arguments.
548 if (const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(TD)) {
549 const TemplateArgumentList &TAL = CTSD->getTemplateArgs();
550 for (const TemplateArgument &TA : TAL.asArray()) {
551 const UuidAttr *UuidForTA = nullptr;
552 if (TA.getKind() == TemplateArgument::Type)
553 getUuidAttrOfType(SemaRef, TA.getAsType(), UuidAttrs);
554 else if (TA.getKind() == TemplateArgument::Declaration)
555 getUuidAttrOfType(SemaRef, TA.getAsDecl()->getType(), UuidAttrs);
556
557 if (UuidForTA)
558 UuidAttrs.insert(UuidForTA);
559 }
560 }
561}
562
563/// \brief Build a Microsoft __uuidof expression with a type operand.
564ExprResult Sema::BuildCXXUuidof(QualType TypeInfoType,
565 SourceLocation TypeidLoc,
566 TypeSourceInfo *Operand,
567 SourceLocation RParenLoc) {
568 StringRef UuidStr;
569 if (!Operand->getType()->isDependentType()) {
570 llvm::SmallSetVector<const UuidAttr *, 1> UuidAttrs;
571 getUuidAttrOfType(*this, Operand->getType(), UuidAttrs);
572 if (UuidAttrs.empty())
573 return ExprError(Diag(TypeidLoc, diag::err_uuidof_without_guid));
574 if (UuidAttrs.size() > 1)
575 return ExprError(Diag(TypeidLoc, diag::err_uuidof_with_multiple_guids));
576 UuidStr = UuidAttrs.back()->getGuid();
577 }
578
579 return new (Context) CXXUuidofExpr(TypeInfoType.withConst(), Operand, UuidStr,
580 SourceRange(TypeidLoc, RParenLoc));
581}
582
583/// \brief Build a Microsoft __uuidof expression with an expression operand.
584ExprResult Sema::BuildCXXUuidof(QualType TypeInfoType,
585 SourceLocation TypeidLoc,
586 Expr *E,
587 SourceLocation RParenLoc) {
588 StringRef UuidStr;
589 if (!E->getType()->isDependentType()) {
590 if (E->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNull)) {
591 UuidStr = "00000000-0000-0000-0000-000000000000";
592 } else {
593 llvm::SmallSetVector<const UuidAttr *, 1> UuidAttrs;
594 getUuidAttrOfType(*this, E->getType(), UuidAttrs);
595 if (UuidAttrs.empty())
596 return ExprError(Diag(TypeidLoc, diag::err_uuidof_without_guid));
597 if (UuidAttrs.size() > 1)
598 return ExprError(Diag(TypeidLoc, diag::err_uuidof_with_multiple_guids));
599 UuidStr = UuidAttrs.back()->getGuid();
600 }
601 }
602
603 return new (Context) CXXUuidofExpr(TypeInfoType.withConst(), E, UuidStr,
604 SourceRange(TypeidLoc, RParenLoc));
605}
606
607/// ActOnCXXUuidof - Parse __uuidof( type-id ) or __uuidof (expression);
608ExprResult
609Sema::ActOnCXXUuidof(SourceLocation OpLoc, SourceLocation LParenLoc,
610 bool isType, void *TyOrExpr, SourceLocation RParenLoc) {
611 // If MSVCGuidDecl has not been cached, do the lookup.
612 if (!MSVCGuidDecl) {
613 IdentifierInfo *GuidII = &PP.getIdentifierTable().get("_GUID");
614 LookupResult R(*this, GuidII, SourceLocation(), LookupTagName);
615 LookupQualifiedName(R, Context.getTranslationUnitDecl());
616 MSVCGuidDecl = R.getAsSingle<RecordDecl>();
617 if (!MSVCGuidDecl)
618 return ExprError(Diag(OpLoc, diag::err_need_header_before_ms_uuidof));
619 }
620
621 QualType GuidType = Context.getTypeDeclType(MSVCGuidDecl);
622
623 if (isType) {
624 // The operand is a type; handle it as such.
625 TypeSourceInfo *TInfo = nullptr;
626 QualType T = GetTypeFromParser(ParsedType::getFromOpaquePtr(TyOrExpr),
627 &TInfo);
628 if (T.isNull())
629 return ExprError();
630
631 if (!TInfo)
632 TInfo = Context.getTrivialTypeSourceInfo(T, OpLoc);
633
634 return BuildCXXUuidof(GuidType, OpLoc, TInfo, RParenLoc);
635 }
636
637 // The operand is an expression.
638 return BuildCXXUuidof(GuidType, OpLoc, (Expr*)TyOrExpr, RParenLoc);
639}
640
641/// ActOnCXXBoolLiteral - Parse {true,false} literals.
642ExprResult
643Sema::ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind) {
644 assert((Kind == tok::kw_true || Kind == tok::kw_false) &&(static_cast <bool> ((Kind == tok::kw_true || Kind == tok
::kw_false) && "Unknown C++ Boolean value!") ? void (
0) : __assert_fail ("(Kind == tok::kw_true || Kind == tok::kw_false) && \"Unknown C++ Boolean value!\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 645, __extension__ __PRETTY_FUNCTION__))
645 "Unknown C++ Boolean value!")(static_cast <bool> ((Kind == tok::kw_true || Kind == tok
::kw_false) && "Unknown C++ Boolean value!") ? void (
0) : __assert_fail ("(Kind == tok::kw_true || Kind == tok::kw_false) && \"Unknown C++ Boolean value!\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 645, __extension__ __PRETTY_FUNCTION__))
;
646 return new (Context)
647 CXXBoolLiteralExpr(Kind == tok::kw_true, Context.BoolTy, OpLoc);
648}
649
650/// ActOnCXXNullPtrLiteral - Parse 'nullptr'.
651ExprResult
652Sema::ActOnCXXNullPtrLiteral(SourceLocation Loc) {
653 return new (Context) CXXNullPtrLiteralExpr(Context.NullPtrTy, Loc);
654}
655
656/// ActOnCXXThrow - Parse throw expressions.
657ExprResult
658Sema::ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *Ex) {
659 bool IsThrownVarInScope = false;
660 if (Ex) {
661 // C++0x [class.copymove]p31:
662 // When certain criteria are met, an implementation is allowed to omit the
663 // copy/move construction of a class object [...]
664 //
665 // - in a throw-expression, when the operand is the name of a
666 // non-volatile automatic object (other than a function or catch-
667 // clause parameter) whose scope does not extend beyond the end of the
668 // innermost enclosing try-block (if there is one), the copy/move
669 // operation from the operand to the exception object (15.1) can be
670 // omitted by constructing the automatic object directly into the
671 // exception object
672 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Ex->IgnoreParens()))
673 if (VarDecl *Var = dyn_cast<VarDecl>(DRE->getDecl())) {
674 if (Var->hasLocalStorage() && !Var->getType().isVolatileQualified()) {
675 for( ; S; S = S->getParent()) {
676 if (S->isDeclScope(Var)) {
677 IsThrownVarInScope = true;
678 break;
679 }
680
681 if (S->getFlags() &
682 (Scope::FnScope | Scope::ClassScope | Scope::BlockScope |
683 Scope::FunctionPrototypeScope | Scope::ObjCMethodScope |
684 Scope::TryScope))
685 break;
686 }
687 }
688 }
689 }
690
691 return BuildCXXThrow(OpLoc, Ex, IsThrownVarInScope);
692}
693
694ExprResult Sema::BuildCXXThrow(SourceLocation OpLoc, Expr *Ex,
695 bool IsThrownVarInScope) {
696 // Don't report an error if 'throw' is used in system headers.
697 if (!getLangOpts().CXXExceptions &&
698 !getSourceManager().isInSystemHeader(OpLoc))
699 Diag(OpLoc, diag::err_exceptions_disabled) << "throw";
700
701 // Exceptions aren't allowed in CUDA device code.
702 if (getLangOpts().CUDA)
703 CUDADiagIfDeviceCode(OpLoc, diag::err_cuda_device_exceptions)
704 << "throw" << CurrentCUDATarget();
705
706 if (getCurScope() && getCurScope()->isOpenMPSimdDirectiveScope())
707 Diag(OpLoc, diag::err_omp_simd_region_cannot_use_stmt) << "throw";
708
709 if (Ex && !Ex->isTypeDependent()) {
710 QualType ExceptionObjectTy = Context.getExceptionObjectType(Ex->getType());
711 if (CheckCXXThrowOperand(OpLoc, ExceptionObjectTy, Ex))
712 return ExprError();
713
714 // Initialize the exception result. This implicitly weeds out
715 // abstract types or types with inaccessible copy constructors.
716
717 // C++0x [class.copymove]p31:
718 // When certain criteria are met, an implementation is allowed to omit the
719 // copy/move construction of a class object [...]
720 //
721 // - in a throw-expression, when the operand is the name of a
722 // non-volatile automatic object (other than a function or
723 // catch-clause
724 // parameter) whose scope does not extend beyond the end of the
725 // innermost enclosing try-block (if there is one), the copy/move
726 // operation from the operand to the exception object (15.1) can be
727 // omitted by constructing the automatic object directly into the
728 // exception object
729 const VarDecl *NRVOVariable = nullptr;
730 if (IsThrownVarInScope)
731 NRVOVariable = getCopyElisionCandidate(QualType(), Ex, CES_Strict);
732
733 InitializedEntity Entity = InitializedEntity::InitializeException(
734 OpLoc, ExceptionObjectTy,
735 /*NRVO=*/NRVOVariable != nullptr);
736 ExprResult Res = PerformMoveOrCopyInitialization(
737 Entity, NRVOVariable, QualType(), Ex, IsThrownVarInScope);
738 if (Res.isInvalid())
739 return ExprError();
740 Ex = Res.get();
741 }
742
743 return new (Context)
744 CXXThrowExpr(Ex, Context.VoidTy, OpLoc, IsThrownVarInScope);
745}
746
747static void
748collectPublicBases(CXXRecordDecl *RD,
749 llvm::DenseMap<CXXRecordDecl *, unsigned> &SubobjectsSeen,
750 llvm::SmallPtrSetImpl<CXXRecordDecl *> &VBases,
751 llvm::SetVector<CXXRecordDecl *> &PublicSubobjectsSeen,
752 bool ParentIsPublic) {
753 for (const CXXBaseSpecifier &BS : RD->bases()) {
754 CXXRecordDecl *BaseDecl = BS.getType()->getAsCXXRecordDecl();
755 bool NewSubobject;
756 // Virtual bases constitute the same subobject. Non-virtual bases are
757 // always distinct subobjects.
758 if (BS.isVirtual())
759 NewSubobject = VBases.insert(BaseDecl).second;
760 else
761 NewSubobject = true;
762
763 if (NewSubobject)
764 ++SubobjectsSeen[BaseDecl];
765
766 // Only add subobjects which have public access throughout the entire chain.
767 bool PublicPath = ParentIsPublic && BS.getAccessSpecifier() == AS_public;
768 if (PublicPath)
769 PublicSubobjectsSeen.insert(BaseDecl);
770
771 // Recurse on to each base subobject.
772 collectPublicBases(BaseDecl, SubobjectsSeen, VBases, PublicSubobjectsSeen,
773 PublicPath);
774 }
775}
776
777static void getUnambiguousPublicSubobjects(
778 CXXRecordDecl *RD, llvm::SmallVectorImpl<CXXRecordDecl *> &Objects) {
779 llvm::DenseMap<CXXRecordDecl *, unsigned> SubobjectsSeen;
780 llvm::SmallSet<CXXRecordDecl *, 2> VBases;
781 llvm::SetVector<CXXRecordDecl *> PublicSubobjectsSeen;
782 SubobjectsSeen[RD] = 1;
783 PublicSubobjectsSeen.insert(RD);
784 collectPublicBases(RD, SubobjectsSeen, VBases, PublicSubobjectsSeen,
785 /*ParentIsPublic=*/true);
786
787 for (CXXRecordDecl *PublicSubobject : PublicSubobjectsSeen) {
788 // Skip ambiguous objects.
789 if (SubobjectsSeen[PublicSubobject] > 1)
790 continue;
791
792 Objects.push_back(PublicSubobject);
793 }
794}
795
796/// CheckCXXThrowOperand - Validate the operand of a throw.
797bool Sema::CheckCXXThrowOperand(SourceLocation ThrowLoc,
798 QualType ExceptionObjectTy, Expr *E) {
799 // If the type of the exception would be an incomplete type or a pointer
800 // to an incomplete type other than (cv) void the program is ill-formed.
801 QualType Ty = ExceptionObjectTy;
802 bool isPointer = false;
803 if (const PointerType* Ptr = Ty->getAs<PointerType>()) {
804 Ty = Ptr->getPointeeType();
805 isPointer = true;
806 }
807 if (!isPointer || !Ty->isVoidType()) {
808 if (RequireCompleteType(ThrowLoc, Ty,
809 isPointer ? diag::err_throw_incomplete_ptr
810 : diag::err_throw_incomplete,
811 E->getSourceRange()))
812 return true;
813
814 if (RequireNonAbstractType(ThrowLoc, ExceptionObjectTy,
815 diag::err_throw_abstract_type, E))
816 return true;
817 }
818
819 // If the exception has class type, we need additional handling.
820 CXXRecordDecl *RD = Ty->getAsCXXRecordDecl();
821 if (!RD)
822 return false;
823
824 // If we are throwing a polymorphic class type or pointer thereof,
825 // exception handling will make use of the vtable.
826 MarkVTableUsed(ThrowLoc, RD);
827
828 // If a pointer is thrown, the referenced object will not be destroyed.
829 if (isPointer)
830 return false;
831
832 // If the class has a destructor, we must be able to call it.
833 if (!RD->hasIrrelevantDestructor()) {
834 if (CXXDestructorDecl *Destructor = LookupDestructor(RD)) {
835 MarkFunctionReferenced(E->getExprLoc(), Destructor);
836 CheckDestructorAccess(E->getExprLoc(), Destructor,
837 PDiag(diag::err_access_dtor_exception) << Ty);
838 if (DiagnoseUseOfDecl(Destructor, E->getExprLoc()))
839 return true;
840 }
841 }
842
843 // The MSVC ABI creates a list of all types which can catch the exception
844 // object. This list also references the appropriate copy constructor to call
845 // if the object is caught by value and has a non-trivial copy constructor.
846 if (Context.getTargetInfo().getCXXABI().isMicrosoft()) {
847 // We are only interested in the public, unambiguous bases contained within
848 // the exception object. Bases which are ambiguous or otherwise
849 // inaccessible are not catchable types.
850 llvm::SmallVector<CXXRecordDecl *, 2> UnambiguousPublicSubobjects;
851 getUnambiguousPublicSubobjects(RD, UnambiguousPublicSubobjects);
852
853 for (CXXRecordDecl *Subobject : UnambiguousPublicSubobjects) {
854 // Attempt to lookup the copy constructor. Various pieces of machinery
855 // will spring into action, like template instantiation, which means this
856 // cannot be a simple walk of the class's decls. Instead, we must perform
857 // lookup and overload resolution.
858 CXXConstructorDecl *CD = LookupCopyingConstructor(Subobject, 0);
859 if (!CD)
860 continue;
861
862 // Mark the constructor referenced as it is used by this throw expression.
863 MarkFunctionReferenced(E->getExprLoc(), CD);
864
865 // Skip this copy constructor if it is trivial, we don't need to record it
866 // in the catchable type data.
867 if (CD->isTrivial())
868 continue;
869
870 // The copy constructor is non-trivial, create a mapping from this class
871 // type to this constructor.
872 // N.B. The selection of copy constructor is not sensitive to this
873 // particular throw-site. Lookup will be performed at the catch-site to
874 // ensure that the copy constructor is, in fact, accessible (via
875 // friendship or any other means).
876 Context.addCopyConstructorForExceptionObject(Subobject, CD);
877
878 // We don't keep the instantiated default argument expressions around so
879 // we must rebuild them here.
880 for (unsigned I = 1, E = CD->getNumParams(); I != E; ++I) {
881 if (CheckCXXDefaultArgExpr(ThrowLoc, CD, CD->getParamDecl(I)))
882 return true;
883 }
884 }
885 }
886
887 return false;
888}
889
890static QualType adjustCVQualifiersForCXXThisWithinLambda(
891 ArrayRef<FunctionScopeInfo *> FunctionScopes, QualType ThisTy,
892 DeclContext *CurSemaContext, ASTContext &ASTCtx) {
893
894 QualType ClassType = ThisTy->getPointeeType();
895 LambdaScopeInfo *CurLSI = nullptr;
896 DeclContext *CurDC = CurSemaContext;
897
898 // Iterate through the stack of lambdas starting from the innermost lambda to
899 // the outermost lambda, checking if '*this' is ever captured by copy - since
900 // that could change the cv-qualifiers of the '*this' object.
901 // The object referred to by '*this' starts out with the cv-qualifiers of its
902 // member function. We then start with the innermost lambda and iterate
903 // outward checking to see if any lambda performs a by-copy capture of '*this'
904 // - and if so, any nested lambda must respect the 'constness' of that
905 // capturing lamdbda's call operator.
906 //
907
908 // Since the FunctionScopeInfo stack is representative of the lexical
909 // nesting of the lambda expressions during initial parsing (and is the best
910 // place for querying information about captures about lambdas that are
911 // partially processed) and perhaps during instantiation of function templates
912 // that contain lambda expressions that need to be transformed BUT not
913 // necessarily during instantiation of a nested generic lambda's function call
914 // operator (which might even be instantiated at the end of the TU) - at which
915 // time the DeclContext tree is mature enough to query capture information
916 // reliably - we use a two pronged approach to walk through all the lexically
917 // enclosing lambda expressions:
918 //
919 // 1) Climb down the FunctionScopeInfo stack as long as each item represents
920 // a Lambda (i.e. LambdaScopeInfo) AND each LSI's 'closure-type' is lexically
921 // enclosed by the call-operator of the LSI below it on the stack (while
922 // tracking the enclosing DC for step 2 if needed). Note the topmost LSI on
923 // the stack represents the innermost lambda.
924 //
925 // 2) If we run out of enclosing LSI's, check if the enclosing DeclContext
926 // represents a lambda's call operator. If it does, we must be instantiating
927 // a generic lambda's call operator (represented by the Current LSI, and
928 // should be the only scenario where an inconsistency between the LSI and the
929 // DeclContext should occur), so climb out the DeclContexts if they
930 // represent lambdas, while querying the corresponding closure types
931 // regarding capture information.
932
933 // 1) Climb down the function scope info stack.
934 for (int I = FunctionScopes.size();
935 I-- && isa<LambdaScopeInfo>(FunctionScopes[I]) &&
936 (!CurLSI || !CurLSI->Lambda || CurLSI->Lambda->getDeclContext() ==
937 cast<LambdaScopeInfo>(FunctionScopes[I])->CallOperator);
938 CurDC = getLambdaAwareParentOfDeclContext(CurDC)) {
939 CurLSI = cast<LambdaScopeInfo>(FunctionScopes[I]);
940
941 if (!CurLSI->isCXXThisCaptured())
942 continue;
943
944 auto C = CurLSI->getCXXThisCapture();
945
946 if (C.isCopyCapture()) {
947 ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
948 if (CurLSI->CallOperator->isConst())
949 ClassType.addConst();
950 return ASTCtx.getPointerType(ClassType);
951 }
952 }
953
954 // 2) We've run out of ScopeInfos but check if CurDC is a lambda (which can
955 // happen during instantiation of its nested generic lambda call operator)
956 if (isLambdaCallOperator(CurDC)) {
957 assert(CurLSI && "While computing 'this' capture-type for a generic "(static_cast <bool> (CurLSI && "While computing 'this' capture-type for a generic "
"lambda, we must have a corresponding LambdaScopeInfo") ? void
(0) : __assert_fail ("CurLSI && \"While computing 'this' capture-type for a generic \" \"lambda, we must have a corresponding LambdaScopeInfo\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 958, __extension__ __PRETTY_FUNCTION__))
958 "lambda, we must have a corresponding LambdaScopeInfo")(static_cast <bool> (CurLSI && "While computing 'this' capture-type for a generic "
"lambda, we must have a corresponding LambdaScopeInfo") ? void
(0) : __assert_fail ("CurLSI && \"While computing 'this' capture-type for a generic \" \"lambda, we must have a corresponding LambdaScopeInfo\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 958, __extension__ __PRETTY_FUNCTION__))
;
959 assert(isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator) &&(static_cast <bool> (isGenericLambdaCallOperatorSpecialization
(CurLSI->CallOperator) && "While computing 'this' capture-type for a generic lambda, when we "
"run out of enclosing LSI's, yet the enclosing DC is a " "lambda-call-operator we must be (i.e. Current LSI) in a generic "
"lambda call oeprator") ? void (0) : __assert_fail ("isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator) && \"While computing 'this' capture-type for a generic lambda, when we \" \"run out of enclosing LSI's, yet the enclosing DC is a \" \"lambda-call-operator we must be (i.e. Current LSI) in a generic \" \"lambda call oeprator\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 963, __extension__ __PRETTY_FUNCTION__))
960 "While computing 'this' capture-type for a generic lambda, when we "(static_cast <bool> (isGenericLambdaCallOperatorSpecialization
(CurLSI->CallOperator) && "While computing 'this' capture-type for a generic lambda, when we "
"run out of enclosing LSI's, yet the enclosing DC is a " "lambda-call-operator we must be (i.e. Current LSI) in a generic "
"lambda call oeprator") ? void (0) : __assert_fail ("isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator) && \"While computing 'this' capture-type for a generic lambda, when we \" \"run out of enclosing LSI's, yet the enclosing DC is a \" \"lambda-call-operator we must be (i.e. Current LSI) in a generic \" \"lambda call oeprator\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 963, __extension__ __PRETTY_FUNCTION__))
961 "run out of enclosing LSI's, yet the enclosing DC is a "(static_cast <bool> (isGenericLambdaCallOperatorSpecialization
(CurLSI->CallOperator) && "While computing 'this' capture-type for a generic lambda, when we "
"run out of enclosing LSI's, yet the enclosing DC is a " "lambda-call-operator we must be (i.e. Current LSI) in a generic "
"lambda call oeprator") ? void (0) : __assert_fail ("isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator) && \"While computing 'this' capture-type for a generic lambda, when we \" \"run out of enclosing LSI's, yet the enclosing DC is a \" \"lambda-call-operator we must be (i.e. Current LSI) in a generic \" \"lambda call oeprator\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 963, __extension__ __PRETTY_FUNCTION__))
962 "lambda-call-operator we must be (i.e. Current LSI) in a generic "(static_cast <bool> (isGenericLambdaCallOperatorSpecialization
(CurLSI->CallOperator) && "While computing 'this' capture-type for a generic lambda, when we "
"run out of enclosing LSI's, yet the enclosing DC is a " "lambda-call-operator we must be (i.e. Current LSI) in a generic "
"lambda call oeprator") ? void (0) : __assert_fail ("isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator) && \"While computing 'this' capture-type for a generic lambda, when we \" \"run out of enclosing LSI's, yet the enclosing DC is a \" \"lambda-call-operator we must be (i.e. Current LSI) in a generic \" \"lambda call oeprator\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 963, __extension__ __PRETTY_FUNCTION__))
963 "lambda call oeprator")(static_cast <bool> (isGenericLambdaCallOperatorSpecialization
(CurLSI->CallOperator) && "While computing 'this' capture-type for a generic lambda, when we "
"run out of enclosing LSI's, yet the enclosing DC is a " "lambda-call-operator we must be (i.e. Current LSI) in a generic "
"lambda call oeprator") ? void (0) : __assert_fail ("isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator) && \"While computing 'this' capture-type for a generic lambda, when we \" \"run out of enclosing LSI's, yet the enclosing DC is a \" \"lambda-call-operator we must be (i.e. Current LSI) in a generic \" \"lambda call oeprator\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 963, __extension__ __PRETTY_FUNCTION__))
;
964 assert(CurDC == getLambdaAwareParentOfDeclContext(CurLSI->CallOperator))(static_cast <bool> (CurDC == getLambdaAwareParentOfDeclContext
(CurLSI->CallOperator)) ? void (0) : __assert_fail ("CurDC == getLambdaAwareParentOfDeclContext(CurLSI->CallOperator)"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 964, __extension__ __PRETTY_FUNCTION__))
;
965
966 auto IsThisCaptured =
967 [](CXXRecordDecl *Closure, bool &IsByCopy, bool &IsConst) {
968 IsConst = false;
969 IsByCopy = false;
970 for (auto &&C : Closure->captures()) {
971 if (C.capturesThis()) {
972 if (C.getCaptureKind() == LCK_StarThis)
973 IsByCopy = true;
974 if (Closure->getLambdaCallOperator()->isConst())
975 IsConst = true;
976 return true;
977 }
978 }
979 return false;
980 };
981
982 bool IsByCopyCapture = false;
983 bool IsConstCapture = false;
984 CXXRecordDecl *Closure = cast<CXXRecordDecl>(CurDC->getParent());
985 while (Closure &&
986 IsThisCaptured(Closure, IsByCopyCapture, IsConstCapture)) {
987 if (IsByCopyCapture) {
988 ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
989 if (IsConstCapture)
990 ClassType.addConst();
991 return ASTCtx.getPointerType(ClassType);
992 }
993 Closure = isLambdaCallOperator(Closure->getParent())
994 ? cast<CXXRecordDecl>(Closure->getParent()->getParent())
995 : nullptr;
996 }
997 }
998 return ASTCtx.getPointerType(ClassType);
999}
1000
1001QualType Sema::getCurrentThisType() {
1002 DeclContext *DC = getFunctionLevelDeclContext();
1003 QualType ThisTy = CXXThisTypeOverride;
1004
1005 if (CXXMethodDecl *method = dyn_cast<CXXMethodDecl>(DC)) {
1006 if (method && method->isInstance())
1007 ThisTy = method->getThisType(Context);
1008 }
1009
1010 if (ThisTy.isNull() && isLambdaCallOperator(CurContext) &&
1011 inTemplateInstantiation()) {
1012
1013 assert(isa<CXXRecordDecl>(DC) &&(static_cast <bool> (isa<CXXRecordDecl>(DC) &&
"Trying to get 'this' type from static method?") ? void (0) :
__assert_fail ("isa<CXXRecordDecl>(DC) && \"Trying to get 'this' type from static method?\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1014, __extension__ __PRETTY_FUNCTION__))
1014 "Trying to get 'this' type from static method?")(static_cast <bool> (isa<CXXRecordDecl>(DC) &&
"Trying to get 'this' type from static method?") ? void (0) :
__assert_fail ("isa<CXXRecordDecl>(DC) && \"Trying to get 'this' type from static method?\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1014, __extension__ __PRETTY_FUNCTION__))
;
1015
1016 // This is a lambda call operator that is being instantiated as a default
1017 // initializer. DC must point to the enclosing class type, so we can recover
1018 // the 'this' type from it.
1019
1020 QualType ClassTy = Context.getTypeDeclType(cast<CXXRecordDecl>(DC));
1021 // There are no cv-qualifiers for 'this' within default initializers,
1022 // per [expr.prim.general]p4.
1023 ThisTy = Context.getPointerType(ClassTy);
1024 }
1025
1026 // If we are within a lambda's call operator, the cv-qualifiers of 'this'
1027 // might need to be adjusted if the lambda or any of its enclosing lambda's
1028 // captures '*this' by copy.
1029 if (!ThisTy.isNull() && isLambdaCallOperator(CurContext))
1030 return adjustCVQualifiersForCXXThisWithinLambda(FunctionScopes, ThisTy,
1031 CurContext, Context);
1032 return ThisTy;
1033}
1034
1035Sema::CXXThisScopeRAII::CXXThisScopeRAII(Sema &S,
1036 Decl *ContextDecl,
1037 unsigned CXXThisTypeQuals,
1038 bool Enabled)
1039 : S(S), OldCXXThisTypeOverride(S.CXXThisTypeOverride), Enabled(false)
1040{
1041 if (!Enabled || !ContextDecl)
1042 return;
1043
1044 CXXRecordDecl *Record = nullptr;
1045 if (ClassTemplateDecl *Template = dyn_cast<ClassTemplateDecl>(ContextDecl))
1046 Record = Template->getTemplatedDecl();
1047 else
1048 Record = cast<CXXRecordDecl>(ContextDecl);
1049
1050 // We care only for CVR qualifiers here, so cut everything else.
1051 CXXThisTypeQuals &= Qualifiers::FastMask;
1052 S.CXXThisTypeOverride
1053 = S.Context.getPointerType(
1054 S.Context.getRecordType(Record).withCVRQualifiers(CXXThisTypeQuals));
1055
1056 this->Enabled = true;
1057}
1058
1059
1060Sema::CXXThisScopeRAII::~CXXThisScopeRAII() {
1061 if (Enabled) {
1062 S.CXXThisTypeOverride = OldCXXThisTypeOverride;
1063 }
1064}
1065
1066static Expr *captureThis(Sema &S, ASTContext &Context, RecordDecl *RD,
1067 QualType ThisTy, SourceLocation Loc,
1068 const bool ByCopy) {
1069
1070 QualType AdjustedThisTy = ThisTy;
1071 // The type of the corresponding data member (not a 'this' pointer if 'by
1072 // copy').
1073 QualType CaptureThisFieldTy = ThisTy;
1074 if (ByCopy) {
1075 // If we are capturing the object referred to by '*this' by copy, ignore any
1076 // cv qualifiers inherited from the type of the member function for the type
1077 // of the closure-type's corresponding data member and any use of 'this'.
1078 CaptureThisFieldTy = ThisTy->getPointeeType();
1079 CaptureThisFieldTy.removeLocalCVRQualifiers(Qualifiers::CVRMask);
1080 AdjustedThisTy = Context.getPointerType(CaptureThisFieldTy);
1081 }
1082
1083 FieldDecl *Field = FieldDecl::Create(
1084 Context, RD, Loc, Loc, nullptr, CaptureThisFieldTy,
1085 Context.getTrivialTypeSourceInfo(CaptureThisFieldTy, Loc), nullptr, false,
1086 ICIS_NoInit);
1087
1088 Field->setImplicit(true);
1089 Field->setAccess(AS_private);
1090 RD->addDecl(Field);
1091 Expr *This =
1092 new (Context) CXXThisExpr(Loc, ThisTy, /*isImplicit*/ true);
1093 if (ByCopy) {
1094 Expr *StarThis = S.CreateBuiltinUnaryOp(Loc,
1095 UO_Deref,
1096 This).get();
1097 InitializedEntity Entity = InitializedEntity::InitializeLambdaCapture(
1098 nullptr, CaptureThisFieldTy, Loc);
1099 InitializationKind InitKind = InitializationKind::CreateDirect(Loc, Loc, Loc);
1100 InitializationSequence Init(S, Entity, InitKind, StarThis);
1101 ExprResult ER = Init.Perform(S, Entity, InitKind, StarThis);
1102 if (ER.isInvalid()) return nullptr;
1103 return ER.get();
1104 }
1105 return This;
1106}
1107
1108bool Sema::CheckCXXThisCapture(SourceLocation Loc, const bool Explicit,
1109 bool BuildAndDiagnose, const unsigned *const FunctionScopeIndexToStopAt,
1110 const bool ByCopy) {
1111 // We don't need to capture this in an unevaluated context.
1112 if (isUnevaluatedContext() && !Explicit)
1113 return true;
1114
1115 assert((!ByCopy || Explicit) && "cannot implicitly capture *this by value")(static_cast <bool> ((!ByCopy || Explicit) && "cannot implicitly capture *this by value"
) ? void (0) : __assert_fail ("(!ByCopy || Explicit) && \"cannot implicitly capture *this by value\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1115, __extension__ __PRETTY_FUNCTION__))
;
1116
1117 const int MaxFunctionScopesIndex = FunctionScopeIndexToStopAt
1118 ? *FunctionScopeIndexToStopAt
1119 : FunctionScopes.size() - 1;
1120
1121 // Check that we can capture the *enclosing object* (referred to by '*this')
1122 // by the capturing-entity/closure (lambda/block/etc) at
1123 // MaxFunctionScopesIndex-deep on the FunctionScopes stack.
1124
1125 // Note: The *enclosing object* can only be captured by-value by a
1126 // closure that is a lambda, using the explicit notation:
1127 // [*this] { ... }.
1128 // Every other capture of the *enclosing object* results in its by-reference
1129 // capture.
1130
1131 // For a closure 'L' (at MaxFunctionScopesIndex in the FunctionScopes
1132 // stack), we can capture the *enclosing object* only if:
1133 // - 'L' has an explicit byref or byval capture of the *enclosing object*
1134 // - or, 'L' has an implicit capture.
1135 // AND
1136 // -- there is no enclosing closure
1137 // -- or, there is some enclosing closure 'E' that has already captured the
1138 // *enclosing object*, and every intervening closure (if any) between 'E'
1139 // and 'L' can implicitly capture the *enclosing object*.
1140 // -- or, every enclosing closure can implicitly capture the
1141 // *enclosing object*
1142
1143
1144 unsigned NumCapturingClosures = 0;
1145 for (int idx = MaxFunctionScopesIndex; idx >= 0; idx--) {
1146 if (CapturingScopeInfo *CSI =
1147 dyn_cast<CapturingScopeInfo>(FunctionScopes[idx])) {
1148 if (CSI->CXXThisCaptureIndex != 0) {
1149 // 'this' is already being captured; there isn't anything more to do.
1150 CSI->Captures[CSI->CXXThisCaptureIndex - 1].markUsed(BuildAndDiagnose);
1151 break;
1152 }
1153 LambdaScopeInfo *LSI = dyn_cast<LambdaScopeInfo>(CSI);
1154 if (LSI && isGenericLambdaCallOperatorSpecialization(LSI->CallOperator)) {
1155 // This context can't implicitly capture 'this'; fail out.
1156 if (BuildAndDiagnose)
1157 Diag(Loc, diag::err_this_capture)
1158 << (Explicit && idx == MaxFunctionScopesIndex);
1159 return true;
1160 }
1161 if (CSI->ImpCaptureStyle == CapturingScopeInfo::ImpCap_LambdaByref ||
1162 CSI->ImpCaptureStyle == CapturingScopeInfo::ImpCap_LambdaByval ||
1163 CSI->ImpCaptureStyle == CapturingScopeInfo::ImpCap_Block ||
1164 CSI->ImpCaptureStyle == CapturingScopeInfo::ImpCap_CapturedRegion ||
1165 (Explicit && idx == MaxFunctionScopesIndex)) {
1166 // Regarding (Explicit && idx == MaxFunctionScopesIndex): only the first
1167 // iteration through can be an explicit capture, all enclosing closures,
1168 // if any, must perform implicit captures.
1169
1170 // This closure can capture 'this'; continue looking upwards.
1171 NumCapturingClosures++;
1172 continue;
1173 }
1174 // This context can't implicitly capture 'this'; fail out.
1175 if (BuildAndDiagnose)
1176 Diag(Loc, diag::err_this_capture)
1177 << (Explicit && idx == MaxFunctionScopesIndex);
1178 return true;
1179 }
1180 break;
1181 }
1182 if (!BuildAndDiagnose) return false;
1183
1184 // If we got here, then the closure at MaxFunctionScopesIndex on the
1185 // FunctionScopes stack, can capture the *enclosing object*, so capture it
1186 // (including implicit by-reference captures in any enclosing closures).
1187
1188 // In the loop below, respect the ByCopy flag only for the closure requesting
1189 // the capture (i.e. first iteration through the loop below). Ignore it for
1190 // all enclosing closure's up to NumCapturingClosures (since they must be
1191 // implicitly capturing the *enclosing object* by reference (see loop
1192 // above)).
1193 assert((!ByCopy ||(static_cast <bool> ((!ByCopy || dyn_cast<LambdaScopeInfo
>(FunctionScopes[MaxFunctionScopesIndex])) && "Only a lambda can capture the enclosing object (referred to by "
"*this) by copy") ? void (0) : __assert_fail ("(!ByCopy || dyn_cast<LambdaScopeInfo>(FunctionScopes[MaxFunctionScopesIndex])) && \"Only a lambda can capture the enclosing object (referred to by \" \"*this) by copy\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1196, __extension__ __PRETTY_FUNCTION__))
1194 dyn_cast<LambdaScopeInfo>(FunctionScopes[MaxFunctionScopesIndex])) &&(static_cast <bool> ((!ByCopy || dyn_cast<LambdaScopeInfo
>(FunctionScopes[MaxFunctionScopesIndex])) && "Only a lambda can capture the enclosing object (referred to by "
"*this) by copy") ? void (0) : __assert_fail ("(!ByCopy || dyn_cast<LambdaScopeInfo>(FunctionScopes[MaxFunctionScopesIndex])) && \"Only a lambda can capture the enclosing object (referred to by \" \"*this) by copy\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1196, __extension__ __PRETTY_FUNCTION__))
1195 "Only a lambda can capture the enclosing object (referred to by "(static_cast <bool> ((!ByCopy || dyn_cast<LambdaScopeInfo
>(FunctionScopes[MaxFunctionScopesIndex])) && "Only a lambda can capture the enclosing object (referred to by "
"*this) by copy") ? void (0) : __assert_fail ("(!ByCopy || dyn_cast<LambdaScopeInfo>(FunctionScopes[MaxFunctionScopesIndex])) && \"Only a lambda can capture the enclosing object (referred to by \" \"*this) by copy\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1196, __extension__ __PRETTY_FUNCTION__))
1196 "*this) by copy")(static_cast <bool> ((!ByCopy || dyn_cast<LambdaScopeInfo
>(FunctionScopes[MaxFunctionScopesIndex])) && "Only a lambda can capture the enclosing object (referred to by "
"*this) by copy") ? void (0) : __assert_fail ("(!ByCopy || dyn_cast<LambdaScopeInfo>(FunctionScopes[MaxFunctionScopesIndex])) && \"Only a lambda can capture the enclosing object (referred to by \" \"*this) by copy\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1196, __extension__ __PRETTY_FUNCTION__))
;
1197 // FIXME: We need to delay this marking in PotentiallyPotentiallyEvaluated
1198 // contexts.
1199 QualType ThisTy = getCurrentThisType();
1200 for (int idx = MaxFunctionScopesIndex; NumCapturingClosures;
1201 --idx, --NumCapturingClosures) {
1202 CapturingScopeInfo *CSI = cast<CapturingScopeInfo>(FunctionScopes[idx]);
1203 Expr *ThisExpr = nullptr;
1204
1205 if (LambdaScopeInfo *LSI = dyn_cast<LambdaScopeInfo>(CSI)) {
1206 // For lambda expressions, build a field and an initializing expression,
1207 // and capture the *enclosing object* by copy only if this is the first
1208 // iteration.
1209 ThisExpr = captureThis(*this, Context, LSI->Lambda, ThisTy, Loc,
1210 ByCopy && idx == MaxFunctionScopesIndex);
1211
1212 } else if (CapturedRegionScopeInfo *RSI
1213 = dyn_cast<CapturedRegionScopeInfo>(FunctionScopes[idx]))
1214 ThisExpr =
1215 captureThis(*this, Context, RSI->TheRecordDecl, ThisTy, Loc,
1216 false/*ByCopy*/);
1217
1218 bool isNested = NumCapturingClosures > 1;
1219 CSI->addThisCapture(isNested, Loc, ThisExpr, ByCopy);
1220 }
1221 return false;
1222}
1223
1224ExprResult Sema::ActOnCXXThis(SourceLocation Loc) {
1225 /// C++ 9.3.2: In the body of a non-static member function, the keyword this
1226 /// is a non-lvalue expression whose value is the address of the object for
1227 /// which the function is called.
1228
1229 QualType ThisTy = getCurrentThisType();
1230 if (ThisTy.isNull()) return Diag(Loc, diag::err_invalid_this_use);
1231
1232 CheckCXXThisCapture(Loc);
1233 return new (Context) CXXThisExpr(Loc, ThisTy, /*isImplicit=*/false);
1234}
1235
1236bool Sema::isThisOutsideMemberFunctionBody(QualType BaseType) {
1237 // If we're outside the body of a member function, then we'll have a specified
1238 // type for 'this'.
1239 if (CXXThisTypeOverride.isNull())
1240 return false;
1241
1242 // Determine whether we're looking into a class that's currently being
1243 // defined.
1244 CXXRecordDecl *Class = BaseType->getAsCXXRecordDecl();
1245 return Class && Class->isBeingDefined();
1246}
1247
1248/// Parse construction of a specified type.
1249/// Can be interpreted either as function-style casting ("int(x)")
1250/// or class type construction ("ClassType(x,y,z)")
1251/// or creation of a value-initialized type ("int()").
1252ExprResult
1253Sema::ActOnCXXTypeConstructExpr(ParsedType TypeRep,
1254 SourceLocation LParenOrBraceLoc,
1255 MultiExprArg exprs,
1256 SourceLocation RParenOrBraceLoc,
1257 bool ListInitialization) {
1258 if (!TypeRep)
1259 return ExprError();
1260
1261 TypeSourceInfo *TInfo;
1262 QualType Ty = GetTypeFromParser(TypeRep, &TInfo);
1263 if (!TInfo)
1264 TInfo = Context.getTrivialTypeSourceInfo(Ty, SourceLocation());
1265
1266 auto Result = BuildCXXTypeConstructExpr(TInfo, LParenOrBraceLoc, exprs,
1267 RParenOrBraceLoc, ListInitialization);
1268 // Avoid creating a non-type-dependent expression that contains typos.
1269 // Non-type-dependent expressions are liable to be discarded without
1270 // checking for embedded typos.
1271 if (!Result.isInvalid() && Result.get()->isInstantiationDependent() &&
1272 !Result.get()->isTypeDependent())
1273 Result = CorrectDelayedTyposInExpr(Result.get());
1274 return Result;
1275}
1276
1277ExprResult
1278Sema::BuildCXXTypeConstructExpr(TypeSourceInfo *TInfo,
1279 SourceLocation LParenOrBraceLoc,
1280 MultiExprArg Exprs,
1281 SourceLocation RParenOrBraceLoc,
1282 bool ListInitialization) {
1283 QualType Ty = TInfo->getType();
1284 SourceLocation TyBeginLoc = TInfo->getTypeLoc().getBeginLoc();
1285
1286 if (Ty->isDependentType() || CallExpr::hasAnyTypeDependentArguments(Exprs)) {
1287 // FIXME: CXXUnresolvedConstructExpr does not model list-initialization
1288 // directly. We work around this by dropping the locations of the braces.
1289 SourceRange Locs = ListInitialization
1290 ? SourceRange()
1291 : SourceRange(LParenOrBraceLoc, RParenOrBraceLoc);
1292 return CXXUnresolvedConstructExpr::Create(Context, TInfo, Locs.getBegin(),
1293 Exprs, Locs.getEnd());
1294 }
1295
1296 assert((!ListInitialization ||(static_cast <bool> ((!ListInitialization || (Exprs.size
() == 1 && isa<InitListExpr>(Exprs[0]))) &&
"List initialization must have initializer list as expression."
) ? void (0) : __assert_fail ("(!ListInitialization || (Exprs.size() == 1 && isa<InitListExpr>(Exprs[0]))) && \"List initialization must have initializer list as expression.\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1298, __extension__ __PRETTY_FUNCTION__))
1297 (Exprs.size() == 1 && isa<InitListExpr>(Exprs[0]))) &&(static_cast <bool> ((!ListInitialization || (Exprs.size
() == 1 && isa<InitListExpr>(Exprs[0]))) &&
"List initialization must have initializer list as expression."
) ? void (0) : __assert_fail ("(!ListInitialization || (Exprs.size() == 1 && isa<InitListExpr>(Exprs[0]))) && \"List initialization must have initializer list as expression.\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1298, __extension__ __PRETTY_FUNCTION__))
1298 "List initialization must have initializer list as expression.")(static_cast <bool> ((!ListInitialization || (Exprs.size
() == 1 && isa<InitListExpr>(Exprs[0]))) &&
"List initialization must have initializer list as expression."
) ? void (0) : __assert_fail ("(!ListInitialization || (Exprs.size() == 1 && isa<InitListExpr>(Exprs[0]))) && \"List initialization must have initializer list as expression.\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1298, __extension__ __PRETTY_FUNCTION__))
;
1299 SourceRange FullRange = SourceRange(TyBeginLoc, RParenOrBraceLoc);
1300
1301 InitializedEntity Entity = InitializedEntity::InitializeTemporary(TInfo);
1302 InitializationKind Kind =
1303 Exprs.size()
1304 ? ListInitialization
1305 ? InitializationKind::CreateDirectList(
1306 TyBeginLoc, LParenOrBraceLoc, RParenOrBraceLoc)
1307 : InitializationKind::CreateDirect(TyBeginLoc, LParenOrBraceLoc,
1308 RParenOrBraceLoc)
1309 : InitializationKind::CreateValue(TyBeginLoc, LParenOrBraceLoc,
1310 RParenOrBraceLoc);
1311
1312 // C++1z [expr.type.conv]p1:
1313 // If the type is a placeholder for a deduced class type, [...perform class
1314 // template argument deduction...]
1315 DeducedType *Deduced = Ty->getContainedDeducedType();
1316 if (Deduced && isa<DeducedTemplateSpecializationType>(Deduced)) {
1317 Ty = DeduceTemplateSpecializationFromInitializer(TInfo, Entity,
1318 Kind, Exprs);
1319 if (Ty.isNull())
1320 return ExprError();
1321 Entity = InitializedEntity::InitializeTemporary(TInfo, Ty);
1322 }
1323
1324 // C++ [expr.type.conv]p1:
1325 // If the expression list is a parenthesized single expression, the type
1326 // conversion expression is equivalent (in definedness, and if defined in
1327 // meaning) to the corresponding cast expression.
1328 if (Exprs.size() == 1 && !ListInitialization &&
1329 !isa<InitListExpr>(Exprs[0])) {
1330 Expr *Arg = Exprs[0];
1331 return BuildCXXFunctionalCastExpr(TInfo, Ty, LParenOrBraceLoc, Arg,
1332 RParenOrBraceLoc);
1333 }
1334
1335 // For an expression of the form T(), T shall not be an array type.
1336 QualType ElemTy = Ty;
1337 if (Ty->isArrayType()) {
1338 if (!ListInitialization)
1339 return ExprError(Diag(TyBeginLoc, diag::err_value_init_for_array_type)
1340 << FullRange);
1341 ElemTy = Context.getBaseElementType(Ty);
1342 }
1343
1344 // There doesn't seem to be an explicit rule against this but sanity demands
1345 // we only construct objects with object types.
1346 if (Ty->isFunctionType())
1347 return ExprError(Diag(TyBeginLoc, diag::err_init_for_function_type)
1348 << Ty << FullRange);
1349
1350 // C++17 [expr.type.conv]p2:
1351 // If the type is cv void and the initializer is (), the expression is a
1352 // prvalue of the specified type that performs no initialization.
1353 if (!Ty->isVoidType() &&
1354 RequireCompleteType(TyBeginLoc, ElemTy,
1355 diag::err_invalid_incomplete_type_use, FullRange))
1356 return ExprError();
1357
1358 // Otherwise, the expression is a prvalue of the specified type whose
1359 // result object is direct-initialized (11.6) with the initializer.
1360 InitializationSequence InitSeq(*this, Entity, Kind, Exprs);
1361 ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Exprs);
1362
1363 if (Result.isInvalid())
1364 return Result;
1365
1366 Expr *Inner = Result.get();
1367 if (CXXBindTemporaryExpr *BTE = dyn_cast_or_null<CXXBindTemporaryExpr>(Inner))
1368 Inner = BTE->getSubExpr();
1369 if (!isa<CXXTemporaryObjectExpr>(Inner) &&
1370 !isa<CXXScalarValueInitExpr>(Inner)) {
1371 // If we created a CXXTemporaryObjectExpr, that node also represents the
1372 // functional cast. Otherwise, create an explicit cast to represent
1373 // the syntactic form of a functional-style cast that was used here.
1374 //
1375 // FIXME: Creating a CXXFunctionalCastExpr around a CXXConstructExpr
1376 // would give a more consistent AST representation than using a
1377 // CXXTemporaryObjectExpr. It's also weird that the functional cast
1378 // is sometimes handled by initialization and sometimes not.
1379 QualType ResultType = Result.get()->getType();
1380 SourceRange Locs = ListInitialization
1381 ? SourceRange()
1382 : SourceRange(LParenOrBraceLoc, RParenOrBraceLoc);
1383 Result = CXXFunctionalCastExpr::Create(
1384 Context, ResultType, Expr::getValueKindForType(Ty), TInfo, CK_NoOp,
1385 Result.get(), /*Path=*/nullptr, Locs.getBegin(), Locs.getEnd());
1386 }
1387
1388 return Result;
1389}
1390
1391/// \brief Determine whether the given function is a non-placement
1392/// deallocation function.
1393static bool isNonPlacementDeallocationFunction(Sema &S, FunctionDecl *FD) {
1394 if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FD))
1395 return Method->isUsualDeallocationFunction();
1396
1397 if (FD->getOverloadedOperator() != OO_Delete &&
1398 FD->getOverloadedOperator() != OO_Array_Delete)
1399 return false;
1400
1401 unsigned UsualParams = 1;
1402
1403 if (S.getLangOpts().SizedDeallocation && UsualParams < FD->getNumParams() &&
1404 S.Context.hasSameUnqualifiedType(
1405 FD->getParamDecl(UsualParams)->getType(),
1406 S.Context.getSizeType()))
1407 ++UsualParams;
1408
1409 if (S.getLangOpts().AlignedAllocation && UsualParams < FD->getNumParams() &&
1410 S.Context.hasSameUnqualifiedType(
1411 FD->getParamDecl(UsualParams)->getType(),
1412 S.Context.getTypeDeclType(S.getStdAlignValT())))
1413 ++UsualParams;
1414
1415 return UsualParams == FD->getNumParams();
1416}
1417
1418namespace {
1419 struct UsualDeallocFnInfo {
1420 UsualDeallocFnInfo() : Found(), FD(nullptr) {}
1421 UsualDeallocFnInfo(Sema &S, DeclAccessPair Found)
1422 : Found(Found), FD(dyn_cast<FunctionDecl>(Found->getUnderlyingDecl())),
1423 Destroying(false), HasSizeT(false), HasAlignValT(false),
1424 CUDAPref(Sema::CFP_Native) {
1425 // A function template declaration is never a usual deallocation function.
1426 if (!FD)
1427 return;
1428 unsigned NumBaseParams = 1;
1429 if (FD->isDestroyingOperatorDelete()) {
1430 Destroying = true;
1431 ++NumBaseParams;
1432 }
1433 if (FD->getNumParams() == NumBaseParams + 2)
1434 HasAlignValT = HasSizeT = true;
1435 else if (FD->getNumParams() == NumBaseParams + 1) {
1436 HasSizeT = FD->getParamDecl(NumBaseParams)->getType()->isIntegerType();
1437 HasAlignValT = !HasSizeT;
1438 }
1439
1440 // In CUDA, determine how much we'd like / dislike to call this.
1441 if (S.getLangOpts().CUDA)
1442 if (auto *Caller = dyn_cast<FunctionDecl>(S.CurContext))
1443 CUDAPref = S.IdentifyCUDAPreference(Caller, FD);
1444 }
1445
1446 explicit operator bool() const { return FD; }
1447
1448 bool isBetterThan(const UsualDeallocFnInfo &Other, bool WantSize,
1449 bool WantAlign) const {
1450 // C++ P0722:
1451 // A destroying operator delete is preferred over a non-destroying
1452 // operator delete.
1453 if (Destroying != Other.Destroying)
1454 return Destroying;
1455
1456 // C++17 [expr.delete]p10:
1457 // If the type has new-extended alignment, a function with a parameter
1458 // of type std::align_val_t is preferred; otherwise a function without
1459 // such a parameter is preferred
1460 if (HasAlignValT != Other.HasAlignValT)
1461 return HasAlignValT == WantAlign;
1462
1463 if (HasSizeT != Other.HasSizeT)
1464 return HasSizeT == WantSize;
1465
1466 // Use CUDA call preference as a tiebreaker.
1467 return CUDAPref > Other.CUDAPref;
1468 }
1469
1470 DeclAccessPair Found;
1471 FunctionDecl *FD;
1472 bool Destroying, HasSizeT, HasAlignValT;
1473 Sema::CUDAFunctionPreference CUDAPref;
1474 };
1475}
1476
1477/// Determine whether a type has new-extended alignment. This may be called when
1478/// the type is incomplete (for a delete-expression with an incomplete pointee
1479/// type), in which case it will conservatively return false if the alignment is
1480/// not known.
1481static bool hasNewExtendedAlignment(Sema &S, QualType AllocType) {
1482 return S.getLangOpts().AlignedAllocation &&
1483 S.getASTContext().getTypeAlignIfKnown(AllocType) >
1484 S.getASTContext().getTargetInfo().getNewAlign();
1485}
1486
1487/// Select the correct "usual" deallocation function to use from a selection of
1488/// deallocation functions (either global or class-scope).
1489static UsualDeallocFnInfo resolveDeallocationOverload(
1490 Sema &S, LookupResult &R, bool WantSize, bool WantAlign,
1491 llvm::SmallVectorImpl<UsualDeallocFnInfo> *BestFns = nullptr) {
1492 UsualDeallocFnInfo Best;
1493
1494 for (auto I = R.begin(), E = R.end(); I != E; ++I) {
1495 UsualDeallocFnInfo Info(S, I.getPair());
1496 if (!Info || !isNonPlacementDeallocationFunction(S, Info.FD) ||
1497 Info.CUDAPref == Sema::CFP_Never)
1498 continue;
1499
1500 if (!Best) {
1501 Best = Info;
1502 if (BestFns)
1503 BestFns->push_back(Info);
1504 continue;
1505 }
1506
1507 if (Best.isBetterThan(Info, WantSize, WantAlign))
1508 continue;
1509
1510 // If more than one preferred function is found, all non-preferred
1511 // functions are eliminated from further consideration.
1512 if (BestFns && Info.isBetterThan(Best, WantSize, WantAlign))
1513 BestFns->clear();
1514
1515 Best = Info;
1516 if (BestFns)
1517 BestFns->push_back(Info);
1518 }
1519
1520 return Best;
1521}
1522
1523/// Determine whether a given type is a class for which 'delete[]' would call
1524/// a member 'operator delete[]' with a 'size_t' parameter. This implies that
1525/// we need to store the array size (even if the type is
1526/// trivially-destructible).
1527static bool doesUsualArrayDeleteWantSize(Sema &S, SourceLocation loc,
1528 QualType allocType) {
1529 const RecordType *record =
1530 allocType->getBaseElementTypeUnsafe()->getAs<RecordType>();
1531 if (!record) return false;
1532
1533 // Try to find an operator delete[] in class scope.
1534
1535 DeclarationName deleteName =
1536 S.Context.DeclarationNames.getCXXOperatorName(OO_Array_Delete);
1537 LookupResult ops(S, deleteName, loc, Sema::LookupOrdinaryName);
1538 S.LookupQualifiedName(ops, record->getDecl());
1539
1540 // We're just doing this for information.
1541 ops.suppressDiagnostics();
1542
1543 // Very likely: there's no operator delete[].
1544 if (ops.empty()) return false;
1545
1546 // If it's ambiguous, it should be illegal to call operator delete[]
1547 // on this thing, so it doesn't matter if we allocate extra space or not.
1548 if (ops.isAmbiguous()) return false;
1549
1550 // C++17 [expr.delete]p10:
1551 // If the deallocation functions have class scope, the one without a
1552 // parameter of type std::size_t is selected.
1553 auto Best = resolveDeallocationOverload(
1554 S, ops, /*WantSize*/false,
1555 /*WantAlign*/hasNewExtendedAlignment(S, allocType));
1556 return Best && Best.HasSizeT;
1557}
1558
1559/// \brief Parsed a C++ 'new' expression (C++ 5.3.4).
1560///
1561/// E.g.:
1562/// @code new (memory) int[size][4] @endcode
1563/// or
1564/// @code ::new Foo(23, "hello") @endcode
1565///
1566/// \param StartLoc The first location of the expression.
1567/// \param UseGlobal True if 'new' was prefixed with '::'.
1568/// \param PlacementLParen Opening paren of the placement arguments.
1569/// \param PlacementArgs Placement new arguments.
1570/// \param PlacementRParen Closing paren of the placement arguments.
1571/// \param TypeIdParens If the type is in parens, the source range.
1572/// \param D The type to be allocated, as well as array dimensions.
1573/// \param Initializer The initializing expression or initializer-list, or null
1574/// if there is none.
1575ExprResult
1576Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
1577 SourceLocation PlacementLParen, MultiExprArg PlacementArgs,
1578 SourceLocation PlacementRParen, SourceRange TypeIdParens,
1579 Declarator &D, Expr *Initializer) {
1580 Expr *ArraySize = nullptr;
1581 // If the specified type is an array, unwrap it and save the expression.
1582 if (D.getNumTypeObjects() > 0 &&
1583 D.getTypeObject(0).Kind == DeclaratorChunk::Array) {
1584 DeclaratorChunk &Chunk = D.getTypeObject(0);
1585 if (D.getDeclSpec().hasAutoTypeSpec())
1586 return ExprError(Diag(Chunk.Loc, diag::err_new_array_of_auto)
1587 << D.getSourceRange());
1588 if (Chunk.Arr.hasStatic)
1589 return ExprError(Diag(Chunk.Loc, diag::err_static_illegal_in_new)
1590 << D.getSourceRange());
1591 if (!Chunk.Arr.NumElts)
1592 return ExprError(Diag(Chunk.Loc, diag::err_array_new_needs_size)
1593 << D.getSourceRange());
1594
1595 ArraySize = static_cast<Expr*>(Chunk.Arr.NumElts);
1596 D.DropFirstTypeObject();
1597 }
1598
1599 // Every dimension shall be of constant size.
1600 if (ArraySize) {
1601 for (unsigned I = 0, N = D.getNumTypeObjects(); I < N; ++I) {
1602 if (D.getTypeObject(I).Kind != DeclaratorChunk::Array)
1603 break;
1604
1605 DeclaratorChunk::ArrayTypeInfo &Array = D.getTypeObject(I).Arr;
1606 if (Expr *NumElts = (Expr *)Array.NumElts) {
1607 if (!NumElts->isTypeDependent() && !NumElts->isValueDependent()) {
1608 if (getLangOpts().CPlusPlus14) {
1609 // C++1y [expr.new]p6: Every constant-expression in a noptr-new-declarator
1610 // shall be a converted constant expression (5.19) of type std::size_t
1611 // and shall evaluate to a strictly positive value.
1612 unsigned IntWidth = Context.getTargetInfo().getIntWidth();
1613 assert(IntWidth && "Builtin type of size 0?")(static_cast <bool> (IntWidth && "Builtin type of size 0?"
) ? void (0) : __assert_fail ("IntWidth && \"Builtin type of size 0?\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1613, __extension__ __PRETTY_FUNCTION__))
;
1614 llvm::APSInt Value(IntWidth);
1615 Array.NumElts
1616 = CheckConvertedConstantExpression(NumElts, Context.getSizeType(), Value,
1617 CCEK_NewExpr)
1618 .get();
1619 } else {
1620 Array.NumElts
1621 = VerifyIntegerConstantExpression(NumElts, nullptr,
1622 diag::err_new_array_nonconst)
1623 .get();
1624 }
1625 if (!Array.NumElts)
1626 return ExprError();
1627 }
1628 }
1629 }
1630 }
1631
1632 TypeSourceInfo *TInfo = GetTypeForDeclarator(D, /*Scope=*/nullptr);
1633 QualType AllocType = TInfo->getType();
1634 if (D.isInvalidType())
1635 return ExprError();
1636
1637 SourceRange DirectInitRange;
1638 if (ParenListExpr *List = dyn_cast_or_null<ParenListExpr>(Initializer))
1639 DirectInitRange = List->getSourceRange();
1640
1641 return BuildCXXNew(SourceRange(StartLoc, D.getLocEnd()), UseGlobal,
1642 PlacementLParen,
1643 PlacementArgs,
1644 PlacementRParen,
1645 TypeIdParens,
1646 AllocType,
1647 TInfo,
1648 ArraySize,
1649 DirectInitRange,
1650 Initializer);
1651}
1652
1653static bool isLegalArrayNewInitializer(CXXNewExpr::InitializationStyle Style,
1654 Expr *Init) {
1655 if (!Init)
1656 return true;
1657 if (ParenListExpr *PLE = dyn_cast<ParenListExpr>(Init))
1658 return PLE->getNumExprs() == 0;
1659 if (isa<ImplicitValueInitExpr>(Init))
1660 return true;
1661 else if (CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(Init))
1662 return !CCE->isListInitialization() &&
1663 CCE->getConstructor()->isDefaultConstructor();
1664 else if (Style == CXXNewExpr::ListInit) {
1665 assert(isa<InitListExpr>(Init) &&(static_cast <bool> (isa<InitListExpr>(Init) &&
"Shouldn't create list CXXConstructExprs for arrays.") ? void
(0) : __assert_fail ("isa<InitListExpr>(Init) && \"Shouldn't create list CXXConstructExprs for arrays.\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1666, __extension__ __PRETTY_FUNCTION__))
1666 "Shouldn't create list CXXConstructExprs for arrays.")(static_cast <bool> (isa<InitListExpr>(Init) &&
"Shouldn't create list CXXConstructExprs for arrays.") ? void
(0) : __assert_fail ("isa<InitListExpr>(Init) && \"Shouldn't create list CXXConstructExprs for arrays.\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1666, __extension__ __PRETTY_FUNCTION__))
;
1667 return true;
1668 }
1669 return false;
1670}
1671
1672// Emit a diagnostic if an aligned allocation/deallocation function that is not
1673// implemented in the standard library is selected.
1674static void diagnoseUnavailableAlignedAllocation(const FunctionDecl &FD,
1675 SourceLocation Loc, bool IsDelete,
1676 Sema &S) {
1677 if (!S.getLangOpts().AlignedAllocationUnavailable)
1678 return;
1679
1680 // Return if there is a definition.
1681 if (FD.isDefined())
1682 return;
1683
1684 bool IsAligned = false;
1685 if (FD.isReplaceableGlobalAllocationFunction(&IsAligned) && IsAligned) {
1686 const llvm::Triple &T = S.getASTContext().getTargetInfo().getTriple();
1687 StringRef OSName = AvailabilityAttr::getPlatformNameSourceSpelling(
1688 S.getASTContext().getTargetInfo().getPlatformName());
1689
1690 S.Diag(Loc, diag::warn_aligned_allocation_unavailable)
1691 << IsDelete << FD.getType().getAsString() << OSName
1692 << alignedAllocMinVersion(T.getOS()).getAsString();
1693 S.Diag(Loc, diag::note_silence_unligned_allocation_unavailable);
1694 }
1695}
1696
1697ExprResult
1698Sema::BuildCXXNew(SourceRange Range, bool UseGlobal,
1699 SourceLocation PlacementLParen,
1700 MultiExprArg PlacementArgs,
1701 SourceLocation PlacementRParen,
1702 SourceRange TypeIdParens,
1703 QualType AllocType,
1704 TypeSourceInfo *AllocTypeInfo,
1705 Expr *ArraySize,
1706 SourceRange DirectInitRange,
1707 Expr *Initializer) {
1708 SourceRange TypeRange = AllocTypeInfo->getTypeLoc().getSourceRange();
1709 SourceLocation StartLoc = Range.getBegin();
1710
1711 CXXNewExpr::InitializationStyle initStyle;
1712 if (DirectInitRange.isValid()) {
1713 assert(Initializer && "Have parens but no initializer.")(static_cast <bool> (Initializer && "Have parens but no initializer."
) ? void (0) : __assert_fail ("Initializer && \"Have parens but no initializer.\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1713, __extension__ __PRETTY_FUNCTION__))
;
1714 initStyle = CXXNewExpr::CallInit;
1715 } else if (Initializer && isa<InitListExpr>(Initializer))
1716 initStyle = CXXNewExpr::ListInit;
1717 else {
1718 assert((!Initializer || isa<ImplicitValueInitExpr>(Initializer) ||(static_cast <bool> ((!Initializer || isa<ImplicitValueInitExpr
>(Initializer) || isa<CXXConstructExpr>(Initializer)
) && "Initializer expression that cannot have been implicitly created."
) ? void (0) : __assert_fail ("(!Initializer || isa<ImplicitValueInitExpr>(Initializer) || isa<CXXConstructExpr>(Initializer)) && \"Initializer expression that cannot have been implicitly created.\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1720, __extension__ __PRETTY_FUNCTION__))
1719 isa<CXXConstructExpr>(Initializer)) &&(static_cast <bool> ((!Initializer || isa<ImplicitValueInitExpr
>(Initializer) || isa<CXXConstructExpr>(Initializer)
) && "Initializer expression that cannot have been implicitly created."
) ? void (0) : __assert_fail ("(!Initializer || isa<ImplicitValueInitExpr>(Initializer) || isa<CXXConstructExpr>(Initializer)) && \"Initializer expression that cannot have been implicitly created.\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1720, __extension__ __PRETTY_FUNCTION__))
1720 "Initializer expression that cannot have been implicitly created.")(static_cast <bool> ((!Initializer || isa<ImplicitValueInitExpr
>(Initializer) || isa<CXXConstructExpr>(Initializer)
) && "Initializer expression that cannot have been implicitly created."
) ? void (0) : __assert_fail ("(!Initializer || isa<ImplicitValueInitExpr>(Initializer) || isa<CXXConstructExpr>(Initializer)) && \"Initializer expression that cannot have been implicitly created.\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1720, __extension__ __PRETTY_FUNCTION__))
;
1721 initStyle = CXXNewExpr::NoInit;
1722 }
1723
1724 Expr **Inits = &Initializer;
1725 unsigned NumInits = Initializer ? 1 : 0;
1726 if (ParenListExpr *List = dyn_cast_or_null<ParenListExpr>(Initializer)) {
1727 assert(initStyle == CXXNewExpr::CallInit && "paren init for non-call init")(static_cast <bool> (initStyle == CXXNewExpr::CallInit &&
"paren init for non-call init") ? void (0) : __assert_fail (
"initStyle == CXXNewExpr::CallInit && \"paren init for non-call init\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1727, __extension__ __PRETTY_FUNCTION__))
;
1728 Inits = List->getExprs();
1729 NumInits = List->getNumExprs();
1730 }
1731
1732 // C++11 [expr.new]p15:
1733 // A new-expression that creates an object of type T initializes that
1734 // object as follows:
1735 InitializationKind Kind
1736 // - If the new-initializer is omitted, the object is default-
1737 // initialized (8.5); if no initialization is performed,
1738 // the object has indeterminate value
1739 = initStyle == CXXNewExpr::NoInit
1740 ? InitializationKind::CreateDefault(TypeRange.getBegin())
1741 // - Otherwise, the new-initializer is interpreted according to the
1742 // initialization rules of 8.5 for direct-initialization.
1743 : initStyle == CXXNewExpr::ListInit
1744 ? InitializationKind::CreateDirectList(TypeRange.getBegin(),
1745 Initializer->getLocStart(),
1746 Initializer->getLocEnd())
1747 : InitializationKind::CreateDirect(TypeRange.getBegin(),
1748 DirectInitRange.getBegin(),
1749 DirectInitRange.getEnd());
1750
1751 // C++11 [dcl.spec.auto]p6. Deduce the type which 'auto' stands in for.
1752 auto *Deduced = AllocType->getContainedDeducedType();
1753 if (Deduced && isa<DeducedTemplateSpecializationType>(Deduced)) {
1754 if (ArraySize)
1755 return ExprError(Diag(ArraySize->getExprLoc(),
1756 diag::err_deduced_class_template_compound_type)
1757 << /*array*/ 2 << ArraySize->getSourceRange());
1758
1759 InitializedEntity Entity
1760 = InitializedEntity::InitializeNew(StartLoc, AllocType);
1761 AllocType = DeduceTemplateSpecializationFromInitializer(
1762 AllocTypeInfo, Entity, Kind, MultiExprArg(Inits, NumInits));
1763 if (AllocType.isNull())
1764 return ExprError();
1765 } else if (Deduced) {
1766 bool Braced = (initStyle == CXXNewExpr::ListInit);
1767 if (NumInits == 1) {
1768 if (auto p = dyn_cast_or_null<InitListExpr>(Inits[0])) {
1769 Inits = p->getInits();
1770 NumInits = p->getNumInits();
1771 Braced = true;
1772 }
1773 }
1774
1775 if (initStyle == CXXNewExpr::NoInit || NumInits == 0)
1776 return ExprError(Diag(StartLoc, diag::err_auto_new_requires_ctor_arg)
1777 << AllocType << TypeRange);
1778 if (NumInits > 1) {
1779 Expr *FirstBad = Inits[1];
1780 return ExprError(Diag(FirstBad->getLocStart(),
1781 diag::err_auto_new_ctor_multiple_expressions)
1782 << AllocType << TypeRange);
1783 }
1784 if (Braced && !getLangOpts().CPlusPlus17)
1785 Diag(Initializer->getLocStart(), diag::ext_auto_new_list_init)
1786 << AllocType << TypeRange;
1787 Expr *Deduce = Inits[0];
1788 QualType DeducedType;
1789 if (DeduceAutoType(AllocTypeInfo, Deduce, DeducedType) == DAR_Failed)
1790 return ExprError(Diag(StartLoc, diag::err_auto_new_deduction_failure)
1791 << AllocType << Deduce->getType()
1792 << TypeRange << Deduce->getSourceRange());
1793 if (DeducedType.isNull())
1794 return ExprError();
1795 AllocType = DeducedType;
1796 }
1797
1798 // Per C++0x [expr.new]p5, the type being constructed may be a
1799 // typedef of an array type.
1800 if (!ArraySize) {
1801 if (const ConstantArrayType *Array
1802 = Context.getAsConstantArrayType(AllocType)) {
1803 ArraySize = IntegerLiteral::Create(Context, Array->getSize(),
1804 Context.getSizeType(),
1805 TypeRange.getEnd());
1806 AllocType = Array->getElementType();
1807 }
1808 }
1809
1810 if (CheckAllocatedType(AllocType, TypeRange.getBegin(), TypeRange))
1811 return ExprError();
1812
1813 if (initStyle == CXXNewExpr::ListInit &&
1814 isStdInitializerList(AllocType, nullptr)) {
1815 Diag(AllocTypeInfo->getTypeLoc().getBeginLoc(),
1816 diag::warn_dangling_std_initializer_list)
1817 << /*at end of FE*/0 << Inits[0]->getSourceRange();
1818 }
1819
1820 // In ARC, infer 'retaining' for the allocated
1821 if (getLangOpts().ObjCAutoRefCount &&
1822 AllocType.getObjCLifetime() == Qualifiers::OCL_None &&
1823 AllocType->isObjCLifetimeType()) {
1824 AllocType = Context.getLifetimeQualifiedType(AllocType,
1825 AllocType->getObjCARCImplicitLifetime());
1826 }
1827
1828 QualType ResultType = Context.getPointerType(AllocType);
1829
1830 if (ArraySize && ArraySize->getType()->isNonOverloadPlaceholderType()) {
1831 ExprResult result = CheckPlaceholderExpr(ArraySize);
1832 if (result.isInvalid()) return ExprError();
1833 ArraySize = result.get();
1834 }
1835 // C++98 5.3.4p6: "The expression in a direct-new-declarator shall have
1836 // integral or enumeration type with a non-negative value."
1837 // C++11 [expr.new]p6: The expression [...] shall be of integral or unscoped
1838 // enumeration type, or a class type for which a single non-explicit
1839 // conversion function to integral or unscoped enumeration type exists.
1840 // C++1y [expr.new]p6: The expression [...] is implicitly converted to
1841 // std::size_t.
1842 llvm::Optional<uint64_t> KnownArraySize;
1843 if (ArraySize && !ArraySize->isTypeDependent()) {
1844 ExprResult ConvertedSize;
1845 if (getLangOpts().CPlusPlus14) {
1846 assert(Context.getTargetInfo().getIntWidth() && "Builtin type of size 0?")(static_cast <bool> (Context.getTargetInfo().getIntWidth
() && "Builtin type of size 0?") ? void (0) : __assert_fail
("Context.getTargetInfo().getIntWidth() && \"Builtin type of size 0?\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 1846, __extension__ __PRETTY_FUNCTION__))
;
1847
1848 ConvertedSize = PerformImplicitConversion(ArraySize, Context.getSizeType(),
1849 AA_Converting);
1850
1851 if (!ConvertedSize.isInvalid() &&
1852 ArraySize->getType()->getAs<RecordType>())
1853 // Diagnose the compatibility of this conversion.
1854 Diag(StartLoc, diag::warn_cxx98_compat_array_size_conversion)
1855 << ArraySize->getType() << 0 << "'size_t'";
1856 } else {
1857 class SizeConvertDiagnoser : public ICEConvertDiagnoser {
1858 protected:
1859 Expr *ArraySize;
1860
1861 public:
1862 SizeConvertDiagnoser(Expr *ArraySize)
1863 : ICEConvertDiagnoser(/*AllowScopedEnumerations*/false, false, false),
1864 ArraySize(ArraySize) {}
1865
1866 SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc,
1867 QualType T) override {
1868 return S.Diag(Loc, diag::err_array_size_not_integral)
1869 << S.getLangOpts().CPlusPlus11 << T;
1870 }
1871
1872 SemaDiagnosticBuilder diagnoseIncomplete(
1873 Sema &S, SourceLocation Loc, QualType T) override {
1874 return S.Diag(Loc, diag::err_array_size_incomplete_type)
1875 << T << ArraySize->getSourceRange();
1876 }
1877
1878 SemaDiagnosticBuilder diagnoseExplicitConv(
1879 Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) override {
1880 return S.Diag(Loc, diag::err_array_size_explicit_conversion) << T << ConvTy;
1881 }
1882
1883 SemaDiagnosticBuilder noteExplicitConv(
1884 Sema &S, CXXConversionDecl *Conv, QualType ConvTy) override {
1885 return S.Diag(Conv->getLocation(), diag::note_array_size_conversion)
1886 << ConvTy->isEnumeralType() << ConvTy;
1887 }
1888
1889 SemaDiagnosticBuilder diagnoseAmbiguous(
1890 Sema &S, SourceLocation Loc, QualType T) override {
1891 return S.Diag(Loc, diag::err_array_size_ambiguous_conversion) << T;
1892 }
1893
1894 SemaDiagnosticBuilder noteAmbiguous(
1895 Sema &S, CXXConversionDecl *Conv, QualType ConvTy) override {
1896 return S.Diag(Conv->getLocation(), diag::note_array_size_conversion)
1897 << ConvTy->isEnumeralType() << ConvTy;
1898 }
1899
1900 SemaDiagnosticBuilder diagnoseConversion(Sema &S, SourceLocation Loc,
1901 QualType T,
1902 QualType ConvTy) override {
1903 return S.Diag(Loc,
1904 S.getLangOpts().CPlusPlus11
1905 ? diag::warn_cxx98_compat_array_size_conversion
1906 : diag::ext_array_size_conversion)
1907 << T << ConvTy->isEnumeralType() << ConvTy;
1908 }
1909 } SizeDiagnoser(ArraySize);
1910
1911 ConvertedSize = PerformContextualImplicitConversion(StartLoc, ArraySize,
1912 SizeDiagnoser);
1913 }
1914 if (ConvertedSize.isInvalid())
1915 return ExprError();
1916
1917 ArraySize = ConvertedSize.get();
1918 QualType SizeType = ArraySize->getType();
1919
1920 if (!SizeType->isIntegralOrUnscopedEnumerationType())
1921 return ExprError();
1922
1923 // C++98 [expr.new]p7:
1924 // The expression in a direct-new-declarator shall have integral type
1925 // with a non-negative value.
1926 //
1927 // Let's see if this is a constant < 0. If so, we reject it out of hand,
1928 // per CWG1464. Otherwise, if it's not a constant, we must have an
1929 // unparenthesized array type.
1930 if (!ArraySize->isValueDependent()) {
1931 llvm::APSInt Value;
1932 // We've already performed any required implicit conversion to integer or
1933 // unscoped enumeration type.
1934 // FIXME: Per CWG1464, we are required to check the value prior to
1935 // converting to size_t. This will never find a negative array size in
1936 // C++14 onwards, because Value is always unsigned here!
1937 if (ArraySize->isIntegerConstantExpr(Value, Context)) {
1938 if (Value.isSigned() && Value.isNegative()) {
1939 return ExprError(Diag(ArraySize->getLocStart(),
1940 diag::err_typecheck_negative_array_size)
1941 << ArraySize->getSourceRange());
1942 }
1943
1944 if (!AllocType->isDependentType()) {
1945 unsigned ActiveSizeBits =
1946 ConstantArrayType::getNumAddressingBits(Context, AllocType, Value);
1947 if (ActiveSizeBits > ConstantArrayType::getMaxSizeBits(Context))
1948 return ExprError(Diag(ArraySize->getLocStart(),
1949 diag::err_array_too_large)
1950 << Value.toString(10)
1951 << ArraySize->getSourceRange());
1952 }
1953
1954 KnownArraySize = Value.getZExtValue();
1955 } else if (TypeIdParens.isValid()) {
1956 // Can't have dynamic array size when the type-id is in parentheses.
1957 Diag(ArraySize->getLocStart(), diag::ext_new_paren_array_nonconst)
1958 << ArraySize->getSourceRange()
1959 << FixItHint::CreateRemoval(TypeIdParens.getBegin())
1960 << FixItHint::CreateRemoval(TypeIdParens.getEnd());
1961
1962 TypeIdParens = SourceRange();
1963 }
1964 }
1965
1966 // Note that we do *not* convert the argument in any way. It can
1967 // be signed, larger than size_t, whatever.
1968 }
1969
1970 FunctionDecl *OperatorNew = nullptr;
1971 FunctionDecl *OperatorDelete = nullptr;
1972 unsigned Alignment =
1973 AllocType->isDependentType() ? 0 : Context.getTypeAlign(AllocType);
1974 unsigned NewAlignment = Context.getTargetInfo().getNewAlign();
1975 bool PassAlignment = getLangOpts().AlignedAllocation &&
1976 Alignment > NewAlignment;
1977
1978 AllocationFunctionScope Scope = UseGlobal ? AFS_Global : AFS_Both;
1979 if (!AllocType->isDependentType() &&
1980 !Expr::hasAnyTypeDependentArguments(PlacementArgs) &&
1981 FindAllocationFunctions(StartLoc,
1982 SourceRange(PlacementLParen, PlacementRParen),
1983 Scope, Scope, AllocType, ArraySize, PassAlignment,
1984 PlacementArgs, OperatorNew, OperatorDelete))
1985 return ExprError();
1986
1987 // If this is an array allocation, compute whether the usual array
1988 // deallocation function for the type has a size_t parameter.
1989 bool UsualArrayDeleteWantsSize = false;
1990 if (ArraySize && !AllocType->isDependentType())
1991 UsualArrayDeleteWantsSize =
1992 doesUsualArrayDeleteWantSize(*this, StartLoc, AllocType);
1993
1994 SmallVector<Expr *, 8> AllPlaceArgs;
1995 if (OperatorNew) {
1996 const FunctionProtoType *Proto =
1997 OperatorNew->getType()->getAs<FunctionProtoType>();
1998 VariadicCallType CallType = Proto->isVariadic() ? VariadicFunction
1999 : VariadicDoesNotApply;
2000
2001 // We've already converted the placement args, just fill in any default
2002 // arguments. Skip the first parameter because we don't have a corresponding
2003 // argument. Skip the second parameter too if we're passing in the
2004 // alignment; we've already filled it in.
2005 if (GatherArgumentsForCall(PlacementLParen, OperatorNew, Proto,
2006 PassAlignment ? 2 : 1, PlacementArgs,
2007 AllPlaceArgs, CallType))
2008 return ExprError();
2009
2010 if (!AllPlaceArgs.empty())
2011 PlacementArgs = AllPlaceArgs;
2012
2013 // FIXME: This is wrong: PlacementArgs misses out the first (size) argument.
2014 DiagnoseSentinelCalls(OperatorNew, PlacementLParen, PlacementArgs);
2015
2016 // FIXME: Missing call to CheckFunctionCall or equivalent
2017
2018 // Warn if the type is over-aligned and is being allocated by (unaligned)
2019 // global operator new.
2020 if (PlacementArgs.empty() && !PassAlignment &&
2021 (OperatorNew->isImplicit() ||
2022 (OperatorNew->getLocStart().isValid() &&
2023 getSourceManager().isInSystemHeader(OperatorNew->getLocStart())))) {
2024 if (Alignment > NewAlignment)
2025 Diag(StartLoc, diag::warn_overaligned_type)
2026 << AllocType
2027 << unsigned(Alignment / Context.getCharWidth())
2028 << unsigned(NewAlignment / Context.getCharWidth());
2029 }
2030 }
2031
2032 // Array 'new' can't have any initializers except empty parentheses.
2033 // Initializer lists are also allowed, in C++11. Rely on the parser for the
2034 // dialect distinction.
2035 if (ArraySize && !isLegalArrayNewInitializer(initStyle, Initializer)) {
2036 SourceRange InitRange(Inits[0]->getLocStart(),
2037 Inits[NumInits - 1]->getLocEnd());
2038 Diag(StartLoc, diag::err_new_array_init_args) << InitRange;
2039 return ExprError();
2040 }
2041
2042 // If we can perform the initialization, and we've not already done so,
2043 // do it now.
2044 if (!AllocType->isDependentType() &&
2045 !Expr::hasAnyTypeDependentArguments(
2046 llvm::makeArrayRef(Inits, NumInits))) {
2047 // The type we initialize is the complete type, including the array bound.
2048 QualType InitType;
2049 if (KnownArraySize)
2050 InitType = Context.getConstantArrayType(
2051 AllocType, llvm::APInt(Context.getTypeSize(Context.getSizeType()),
2052 *KnownArraySize),
2053 ArrayType::Normal, 0);
2054 else if (ArraySize)
2055 InitType =
2056 Context.getIncompleteArrayType(AllocType, ArrayType::Normal, 0);
2057 else
2058 InitType = AllocType;
2059
2060 InitializedEntity Entity
2061 = InitializedEntity::InitializeNew(StartLoc, InitType);
2062 InitializationSequence InitSeq(*this, Entity, Kind,
2063 MultiExprArg(Inits, NumInits));
2064 ExprResult FullInit = InitSeq.Perform(*this, Entity, Kind,
2065 MultiExprArg(Inits, NumInits));
2066 if (FullInit.isInvalid())
2067 return ExprError();
2068
2069 // FullInit is our initializer; strip off CXXBindTemporaryExprs, because
2070 // we don't want the initialized object to be destructed.
2071 // FIXME: We should not create these in the first place.
2072 if (CXXBindTemporaryExpr *Binder =
2073 dyn_cast_or_null<CXXBindTemporaryExpr>(FullInit.get()))
2074 FullInit = Binder->getSubExpr();
2075
2076 Initializer = FullInit.get();
2077 }
2078
2079 // Mark the new and delete operators as referenced.
2080 if (OperatorNew) {
2081 if (DiagnoseUseOfDecl(OperatorNew, StartLoc))
2082 return ExprError();
2083 MarkFunctionReferenced(StartLoc, OperatorNew);
2084 diagnoseUnavailableAlignedAllocation(*OperatorNew, StartLoc, false, *this);
2085 }
2086 if (OperatorDelete) {
2087 if (DiagnoseUseOfDecl(OperatorDelete, StartLoc))
2088 return ExprError();
2089 MarkFunctionReferenced(StartLoc, OperatorDelete);
2090 diagnoseUnavailableAlignedAllocation(*OperatorDelete, StartLoc, true, *this);
2091 }
2092
2093 // C++0x [expr.new]p17:
2094 // If the new expression creates an array of objects of class type,
2095 // access and ambiguity control are done for the destructor.
2096 QualType BaseAllocType = Context.getBaseElementType(AllocType);
2097 if (ArraySize && !BaseAllocType->isDependentType()) {
2098 if (const RecordType *BaseRecordType = BaseAllocType->getAs<RecordType>()) {
2099 if (CXXDestructorDecl *dtor = LookupDestructor(
2100 cast<CXXRecordDecl>(BaseRecordType->getDecl()))) {
2101 MarkFunctionReferenced(StartLoc, dtor);
2102 CheckDestructorAccess(StartLoc, dtor,
2103 PDiag(diag::err_access_dtor)
2104 << BaseAllocType);
2105 if (DiagnoseUseOfDecl(dtor, StartLoc))
2106 return ExprError();
2107 }
2108 }
2109 }
2110
2111 return new (Context)
2112 CXXNewExpr(Context, UseGlobal, OperatorNew, OperatorDelete, PassAlignment,
2113 UsualArrayDeleteWantsSize, PlacementArgs, TypeIdParens,
2114 ArraySize, initStyle, Initializer, ResultType, AllocTypeInfo,
2115 Range, DirectInitRange);
2116}
2117
2118/// \brief Checks that a type is suitable as the allocated type
2119/// in a new-expression.
2120bool Sema::CheckAllocatedType(QualType AllocType, SourceLocation Loc,
2121 SourceRange R) {
2122 // C++ 5.3.4p1: "[The] type shall be a complete object type, but not an
2123 // abstract class type or array thereof.
2124 if (AllocType->isFunctionType())
2125 return Diag(Loc, diag::err_bad_new_type)
2126 << AllocType << 0 << R;
2127 else if (AllocType->isReferenceType())
2128 return Diag(Loc, diag::err_bad_new_type)
2129 << AllocType << 1 << R;
2130 else if (!AllocType->isDependentType() &&
2131 RequireCompleteType(Loc, AllocType, diag::err_new_incomplete_type,R))
2132 return true;
2133 else if (RequireNonAbstractType(Loc, AllocType,
2134 diag::err_allocation_of_abstract_type))
2135 return true;
2136 else if (AllocType->isVariablyModifiedType())
2137 return Diag(Loc, diag::err_variably_modified_new_type)
2138 << AllocType;
2139 else if (AllocType.getAddressSpace() != LangAS::Default)
2140 return Diag(Loc, diag::err_address_space_qualified_new)
2141 << AllocType.getUnqualifiedType()
2142 << AllocType.getQualifiers().getAddressSpaceAttributePrintValue();
2143 else if (getLangOpts().ObjCAutoRefCount) {
2144 if (const ArrayType *AT = Context.getAsArrayType(AllocType)) {
2145 QualType BaseAllocType = Context.getBaseElementType(AT);
2146 if (BaseAllocType.getObjCLifetime() == Qualifiers::OCL_None &&
2147 BaseAllocType->isObjCLifetimeType())
2148 return Diag(Loc, diag::err_arc_new_array_without_ownership)
2149 << BaseAllocType;
2150 }
2151 }
2152
2153 return false;
2154}
2155
2156static bool resolveAllocationOverload(
2157 Sema &S, LookupResult &R, SourceRange Range, SmallVectorImpl<Expr *> &Args,
2158 bool &PassAlignment, FunctionDecl *&Operator,
2159 OverloadCandidateSet *AlignedCandidates, Expr *AlignArg, bool Diagnose) {
2160 OverloadCandidateSet Candidates(R.getNameLoc(),
2161 OverloadCandidateSet::CSK_Normal);
2162 for (LookupResult::iterator Alloc = R.begin(), AllocEnd = R.end();
2163 Alloc != AllocEnd; ++Alloc) {
2164 // Even member operator new/delete are implicitly treated as
2165 // static, so don't use AddMemberCandidate.
2166 NamedDecl *D = (*Alloc)->getUnderlyingDecl();
2167
2168 if (FunctionTemplateDecl *FnTemplate = dyn_cast<FunctionTemplateDecl>(D)) {
2169 S.AddTemplateOverloadCandidate(FnTemplate, Alloc.getPair(),
2170 /*ExplicitTemplateArgs=*/nullptr, Args,
2171 Candidates,
2172 /*SuppressUserConversions=*/false);
2173 continue;
2174 }
2175
2176 FunctionDecl *Fn = cast<FunctionDecl>(D);
2177 S.AddOverloadCandidate(Fn, Alloc.getPair(), Args, Candidates,
2178 /*SuppressUserConversions=*/false);
2179 }
2180
2181 // Do the resolution.
2182 OverloadCandidateSet::iterator Best;
2183 switch (Candidates.BestViableFunction(S, R.getNameLoc(), Best)) {
2184 case OR_Success: {
2185 // Got one!
2186 FunctionDecl *FnDecl = Best->Function;
2187 if (S.CheckAllocationAccess(R.getNameLoc(), Range, R.getNamingClass(),
2188 Best->FoundDecl) == Sema::AR_inaccessible)
2189 return true;
2190
2191 Operator = FnDecl;
2192 return false;
2193 }
2194
2195 case OR_No_Viable_Function:
2196 // C++17 [expr.new]p13:
2197 // If no matching function is found and the allocated object type has
2198 // new-extended alignment, the alignment argument is removed from the
2199 // argument list, and overload resolution is performed again.
2200 if (PassAlignment) {
2201 PassAlignment = false;
2202 AlignArg = Args[1];
2203 Args.erase(Args.begin() + 1);
2204 return resolveAllocationOverload(S, R, Range, Args, PassAlignment,
2205 Operator, &Candidates, AlignArg,
2206 Diagnose);
2207 }
2208
2209 // MSVC will fall back on trying to find a matching global operator new
2210 // if operator new[] cannot be found. Also, MSVC will leak by not
2211 // generating a call to operator delete or operator delete[], but we
2212 // will not replicate that bug.
2213 // FIXME: Find out how this interacts with the std::align_val_t fallback
2214 // once MSVC implements it.
2215 if (R.getLookupName().getCXXOverloadedOperator() == OO_Array_New &&
2216 S.Context.getLangOpts().MSVCCompat) {
2217 R.clear();
2218 R.setLookupName(S.Context.DeclarationNames.getCXXOperatorName(OO_New));
2219 S.LookupQualifiedName(R, S.Context.getTranslationUnitDecl());
2220 // FIXME: This will give bad diagnostics pointing at the wrong functions.
2221 return resolveAllocationOverload(S, R, Range, Args, PassAlignment,
2222 Operator, /*Candidates=*/nullptr,
2223 /*AlignArg=*/nullptr, Diagnose);
2224 }
2225
2226 if (Diagnose) {
2227 S.Diag(R.getNameLoc(), diag::err_ovl_no_viable_function_in_call)
2228 << R.getLookupName() << Range;
2229
2230 // If we have aligned candidates, only note the align_val_t candidates
2231 // from AlignedCandidates and the non-align_val_t candidates from
2232 // Candidates.
2233 if (AlignedCandidates) {
2234 auto IsAligned = [](OverloadCandidate &C) {
2235 return C.Function->getNumParams() > 1 &&
2236 C.Function->getParamDecl(1)->getType()->isAlignValT();
2237 };
2238 auto IsUnaligned = [&](OverloadCandidate &C) { return !IsAligned(C); };
2239
2240 // This was an overaligned allocation, so list the aligned candidates
2241 // first.
2242 Args.insert(Args.begin() + 1, AlignArg);
2243 AlignedCandidates->NoteCandidates(S, OCD_AllCandidates, Args, "",
2244 R.getNameLoc(), IsAligned);
2245 Args.erase(Args.begin() + 1);
2246 Candidates.NoteCandidates(S, OCD_AllCandidates, Args, "", R.getNameLoc(),
2247 IsUnaligned);
2248 } else {
2249 Candidates.NoteCandidates(S, OCD_AllCandidates, Args);
2250 }
2251 }
2252 return true;
2253
2254 case OR_Ambiguous:
2255 if (Diagnose) {
2256 S.Diag(R.getNameLoc(), diag::err_ovl_ambiguous_call)
2257 << R.getLookupName() << Range;
2258 Candidates.NoteCandidates(S, OCD_ViableCandidates, Args);
2259 }
2260 return true;
2261
2262 case OR_Deleted: {
2263 if (Diagnose) {
2264 S.Diag(R.getNameLoc(), diag::err_ovl_deleted_call)
2265 << Best->Function->isDeleted() << R.getLookupName()
2266 << S.getDeletedOrUnavailableSuffix(Best->Function) << Range;
2267 Candidates.NoteCandidates(S, OCD_AllCandidates, Args);
2268 }
2269 return true;
2270 }
2271 }
2272 llvm_unreachable("Unreachable, bad result from BestViableFunction")::llvm::llvm_unreachable_internal("Unreachable, bad result from BestViableFunction"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 2272)
;
2273}
2274
2275bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
2276 AllocationFunctionScope NewScope,
2277 AllocationFunctionScope DeleteScope,
2278 QualType AllocType, bool IsArray,
2279 bool &PassAlignment, MultiExprArg PlaceArgs,
2280 FunctionDecl *&OperatorNew,
2281 FunctionDecl *&OperatorDelete,
2282 bool Diagnose) {
2283 // --- Choosing an allocation function ---
2284 // C++ 5.3.4p8 - 14 & 18
2285 // 1) If looking in AFS_Global scope for allocation functions, only look in
2286 // the global scope. Else, if AFS_Class, only look in the scope of the
2287 // allocated class. If AFS_Both, look in both.
2288 // 2) If an array size is given, look for operator new[], else look for
2289 // operator new.
2290 // 3) The first argument is always size_t. Append the arguments from the
2291 // placement form.
2292
2293 SmallVector<Expr*, 8> AllocArgs;
2294 AllocArgs.reserve((PassAlignment ? 2 : 1) + PlaceArgs.size());
2295
2296 // We don't care about the actual value of these arguments.
2297 // FIXME: Should the Sema create the expression and embed it in the syntax
2298 // tree? Or should the consumer just recalculate the value?
2299 // FIXME: Using a dummy value will interact poorly with attribute enable_if.
2300 IntegerLiteral Size(Context, llvm::APInt::getNullValue(
2301 Context.getTargetInfo().getPointerWidth(0)),
2302 Context.getSizeType(),
2303 SourceLocation());
2304 AllocArgs.push_back(&Size);
2305
2306 QualType AlignValT = Context.VoidTy;
2307 if (PassAlignment) {
2308 DeclareGlobalNewDelete();
2309 AlignValT = Context.getTypeDeclType(getStdAlignValT());
2310 }
2311 CXXScalarValueInitExpr Align(AlignValT, nullptr, SourceLocation());
2312 if (PassAlignment)
2313 AllocArgs.push_back(&Align);
2314
2315 AllocArgs.insert(AllocArgs.end(), PlaceArgs.begin(), PlaceArgs.end());
2316
2317 // C++ [expr.new]p8:
2318 // If the allocated type is a non-array type, the allocation
2319 // function's name is operator new and the deallocation function's
2320 // name is operator delete. If the allocated type is an array
2321 // type, the allocation function's name is operator new[] and the
2322 // deallocation function's name is operator delete[].
2323 DeclarationName NewName = Context.DeclarationNames.getCXXOperatorName(
2324 IsArray ? OO_Array_New : OO_New);
2325
2326 QualType AllocElemType = Context.getBaseElementType(AllocType);
2327
2328 // Find the allocation function.
2329 {
2330 LookupResult R(*this, NewName, StartLoc, LookupOrdinaryName);
2331
2332 // C++1z [expr.new]p9:
2333 // If the new-expression begins with a unary :: operator, the allocation
2334 // function's name is looked up in the global scope. Otherwise, if the
2335 // allocated type is a class type T or array thereof, the allocation
2336 // function's name is looked up in the scope of T.
2337 if (AllocElemType->isRecordType() && NewScope != AFS_Global)
2338 LookupQualifiedName(R, AllocElemType->getAsCXXRecordDecl());
2339
2340 // We can see ambiguity here if the allocation function is found in
2341 // multiple base classes.
2342 if (R.isAmbiguous())
2343 return true;
2344
2345 // If this lookup fails to find the name, or if the allocated type is not
2346 // a class type, the allocation function's name is looked up in the
2347 // global scope.
2348 if (R.empty()) {
2349 if (NewScope == AFS_Class)
2350 return true;
2351
2352 LookupQualifiedName(R, Context.getTranslationUnitDecl());
2353 }
2354
2355 assert(!R.empty() && "implicitly declared allocation functions not found")(static_cast <bool> (!R.empty() && "implicitly declared allocation functions not found"
) ? void (0) : __assert_fail ("!R.empty() && \"implicitly declared allocation functions not found\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 2355, __extension__ __PRETTY_FUNCTION__))
;
2356 assert(!R.isAmbiguous() && "global allocation functions are ambiguous")(static_cast <bool> (!R.isAmbiguous() && "global allocation functions are ambiguous"
) ? void (0) : __assert_fail ("!R.isAmbiguous() && \"global allocation functions are ambiguous\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 2356, __extension__ __PRETTY_FUNCTION__))
;
2357
2358 // We do our own custom access checks below.
2359 R.suppressDiagnostics();
2360
2361 if (resolveAllocationOverload(*this, R, Range, AllocArgs, PassAlignment,
2362 OperatorNew, /*Candidates=*/nullptr,
2363 /*AlignArg=*/nullptr, Diagnose))
2364 return true;
2365 }
2366
2367 // We don't need an operator delete if we're running under -fno-exceptions.
2368 if (!getLangOpts().Exceptions) {
2369 OperatorDelete = nullptr;
2370 return false;
2371 }
2372
2373 // Note, the name of OperatorNew might have been changed from array to
2374 // non-array by resolveAllocationOverload.
2375 DeclarationName DeleteName = Context.DeclarationNames.getCXXOperatorName(
2376 OperatorNew->getDeclName().getCXXOverloadedOperator() == OO_Array_New
2377 ? OO_Array_Delete
2378 : OO_Delete);
2379
2380 // C++ [expr.new]p19:
2381 //
2382 // If the new-expression begins with a unary :: operator, the
2383 // deallocation function's name is looked up in the global
2384 // scope. Otherwise, if the allocated type is a class type T or an
2385 // array thereof, the deallocation function's name is looked up in
2386 // the scope of T. If this lookup fails to find the name, or if
2387 // the allocated type is not a class type or array thereof, the
2388 // deallocation function's name is looked up in the global scope.
2389 LookupResult FoundDelete(*this, DeleteName, StartLoc, LookupOrdinaryName);
2390 if (AllocElemType->isRecordType() && DeleteScope != AFS_Global) {
2391 CXXRecordDecl *RD
2392 = cast<CXXRecordDecl>(AllocElemType->getAs<RecordType>()->getDecl());
2393 LookupQualifiedName(FoundDelete, RD);
2394 }
2395 if (FoundDelete.isAmbiguous())
2396 return true; // FIXME: clean up expressions?
2397
2398 bool FoundGlobalDelete = FoundDelete.empty();
2399 if (FoundDelete.empty()) {
2400 if (DeleteScope == AFS_Class)
2401 return true;
2402
2403 DeclareGlobalNewDelete();
2404 LookupQualifiedName(FoundDelete, Context.getTranslationUnitDecl());
2405 }
2406
2407 FoundDelete.suppressDiagnostics();
2408
2409 SmallVector<std::pair<DeclAccessPair,FunctionDecl*>, 2> Matches;
2410
2411 // Whether we're looking for a placement operator delete is dictated
2412 // by whether we selected a placement operator new, not by whether
2413 // we had explicit placement arguments. This matters for things like
2414 // struct A { void *operator new(size_t, int = 0); ... };
2415 // A *a = new A()
2416 //
2417 // We don't have any definition for what a "placement allocation function"
2418 // is, but we assume it's any allocation function whose
2419 // parameter-declaration-clause is anything other than (size_t).
2420 //
2421 // FIXME: Should (size_t, std::align_val_t) also be considered non-placement?
2422 // This affects whether an exception from the constructor of an overaligned
2423 // type uses the sized or non-sized form of aligned operator delete.
2424 bool isPlacementNew = !PlaceArgs.empty() || OperatorNew->param_size() != 1 ||
2425 OperatorNew->isVariadic();
2426
2427 if (isPlacementNew) {
2428 // C++ [expr.new]p20:
2429 // A declaration of a placement deallocation function matches the
2430 // declaration of a placement allocation function if it has the
2431 // same number of parameters and, after parameter transformations
2432 // (8.3.5), all parameter types except the first are
2433 // identical. [...]
2434 //
2435 // To perform this comparison, we compute the function type that
2436 // the deallocation function should have, and use that type both
2437 // for template argument deduction and for comparison purposes.
2438 QualType ExpectedFunctionType;
2439 {
2440 const FunctionProtoType *Proto
2441 = OperatorNew->getType()->getAs<FunctionProtoType>();
2442
2443 SmallVector<QualType, 4> ArgTypes;
2444 ArgTypes.push_back(Context.VoidPtrTy);
2445 for (unsigned I = 1, N = Proto->getNumParams(); I < N; ++I)
2446 ArgTypes.push_back(Proto->getParamType(I));
2447
2448 FunctionProtoType::ExtProtoInfo EPI;
2449 // FIXME: This is not part of the standard's rule.
2450 EPI.Variadic = Proto->isVariadic();
2451
2452 ExpectedFunctionType
2453 = Context.getFunctionType(Context.VoidTy, ArgTypes, EPI);
2454 }
2455
2456 for (LookupResult::iterator D = FoundDelete.begin(),
2457 DEnd = FoundDelete.end();
2458 D != DEnd; ++D) {
2459 FunctionDecl *Fn = nullptr;
2460 if (FunctionTemplateDecl *FnTmpl =
2461 dyn_cast<FunctionTemplateDecl>((*D)->getUnderlyingDecl())) {
2462 // Perform template argument deduction to try to match the
2463 // expected function type.
2464 TemplateDeductionInfo Info(StartLoc);
2465 if (DeduceTemplateArguments(FnTmpl, nullptr, ExpectedFunctionType, Fn,
2466 Info))
2467 continue;
2468 } else
2469 Fn = cast<FunctionDecl>((*D)->getUnderlyingDecl());
2470
2471 if (Context.hasSameType(adjustCCAndNoReturn(Fn->getType(),
2472 ExpectedFunctionType,
2473 /*AdjustExcpetionSpec*/true),
2474 ExpectedFunctionType))
2475 Matches.push_back(std::make_pair(D.getPair(), Fn));
2476 }
2477
2478 if (getLangOpts().CUDA)
2479 EraseUnwantedCUDAMatches(dyn_cast<FunctionDecl>(CurContext), Matches);
2480 } else {
2481 // C++1y [expr.new]p22:
2482 // For a non-placement allocation function, the normal deallocation
2483 // function lookup is used
2484 //
2485 // Per [expr.delete]p10, this lookup prefers a member operator delete
2486 // without a size_t argument, but prefers a non-member operator delete
2487 // with a size_t where possible (which it always is in this case).
2488 llvm::SmallVector<UsualDeallocFnInfo, 4> BestDeallocFns;
2489 UsualDeallocFnInfo Selected = resolveDeallocationOverload(
2490 *this, FoundDelete, /*WantSize*/ FoundGlobalDelete,
2491 /*WantAlign*/ hasNewExtendedAlignment(*this, AllocElemType),
2492 &BestDeallocFns);
2493 if (Selected)
2494 Matches.push_back(std::make_pair(Selected.Found, Selected.FD));
2495 else {
2496 // If we failed to select an operator, all remaining functions are viable
2497 // but ambiguous.
2498 for (auto Fn : BestDeallocFns)
2499 Matches.push_back(std::make_pair(Fn.Found, Fn.FD));
2500 }
2501 }
2502
2503 // C++ [expr.new]p20:
2504 // [...] If the lookup finds a single matching deallocation
2505 // function, that function will be called; otherwise, no
2506 // deallocation function will be called.
2507 if (Matches.size() == 1) {
2508 OperatorDelete = Matches[0].second;
2509
2510 // C++1z [expr.new]p23:
2511 // If the lookup finds a usual deallocation function (3.7.4.2)
2512 // with a parameter of type std::size_t and that function, considered
2513 // as a placement deallocation function, would have been
2514 // selected as a match for the allocation function, the program
2515 // is ill-formed.
2516 if (getLangOpts().CPlusPlus11 && isPlacementNew &&
2517 isNonPlacementDeallocationFunction(*this, OperatorDelete)) {
2518 UsualDeallocFnInfo Info(*this,
2519 DeclAccessPair::make(OperatorDelete, AS_public));
2520 // Core issue, per mail to core reflector, 2016-10-09:
2521 // If this is a member operator delete, and there is a corresponding
2522 // non-sized member operator delete, this isn't /really/ a sized
2523 // deallocation function, it just happens to have a size_t parameter.
2524 bool IsSizedDelete = Info.HasSizeT;
2525 if (IsSizedDelete && !FoundGlobalDelete) {
2526 auto NonSizedDelete =
2527 resolveDeallocationOverload(*this, FoundDelete, /*WantSize*/false,
2528 /*WantAlign*/Info.HasAlignValT);
2529 if (NonSizedDelete && !NonSizedDelete.HasSizeT &&
2530 NonSizedDelete.HasAlignValT == Info.HasAlignValT)
2531 IsSizedDelete = false;
2532 }
2533
2534 if (IsSizedDelete) {
2535 SourceRange R = PlaceArgs.empty()
2536 ? SourceRange()
2537 : SourceRange(PlaceArgs.front()->getLocStart(),
2538 PlaceArgs.back()->getLocEnd());
2539 Diag(StartLoc, diag::err_placement_new_non_placement_delete) << R;
2540 if (!OperatorDelete->isImplicit())
2541 Diag(OperatorDelete->getLocation(), diag::note_previous_decl)
2542 << DeleteName;
2543 }
2544 }
2545
2546 CheckAllocationAccess(StartLoc, Range, FoundDelete.getNamingClass(),
2547 Matches[0].first);
2548 } else if (!Matches.empty()) {
2549 // We found multiple suitable operators. Per [expr.new]p20, that means we
2550 // call no 'operator delete' function, but we should at least warn the user.
2551 // FIXME: Suppress this warning if the construction cannot throw.
2552 Diag(StartLoc, diag::warn_ambiguous_suitable_delete_function_found)
2553 << DeleteName << AllocElemType;
2554
2555 for (auto &Match : Matches)
2556 Diag(Match.second->getLocation(),
2557 diag::note_member_declared_here) << DeleteName;
2558 }
2559
2560 return false;
2561}
2562
2563/// DeclareGlobalNewDelete - Declare the global forms of operator new and
2564/// delete. These are:
2565/// @code
2566/// // C++03:
2567/// void* operator new(std::size_t) throw(std::bad_alloc);
2568/// void* operator new[](std::size_t) throw(std::bad_alloc);
2569/// void operator delete(void *) throw();
2570/// void operator delete[](void *) throw();
2571/// // C++11:
2572/// void* operator new(std::size_t);
2573/// void* operator new[](std::size_t);
2574/// void operator delete(void *) noexcept;
2575/// void operator delete[](void *) noexcept;
2576/// // C++1y:
2577/// void* operator new(std::size_t);
2578/// void* operator new[](std::size_t);
2579/// void operator delete(void *) noexcept;
2580/// void operator delete[](void *) noexcept;
2581/// void operator delete(void *, std::size_t) noexcept;
2582/// void operator delete[](void *, std::size_t) noexcept;
2583/// @endcode
2584/// Note that the placement and nothrow forms of new are *not* implicitly
2585/// declared. Their use requires including \<new\>.
2586void Sema::DeclareGlobalNewDelete() {
2587 if (GlobalNewDeleteDeclared)
2588 return;
2589
2590 // C++ [basic.std.dynamic]p2:
2591 // [...] The following allocation and deallocation functions (18.4) are
2592 // implicitly declared in global scope in each translation unit of a
2593 // program
2594 //
2595 // C++03:
2596 // void* operator new(std::size_t) throw(std::bad_alloc);
2597 // void* operator new[](std::size_t) throw(std::bad_alloc);
2598 // void operator delete(void*) throw();
2599 // void operator delete[](void*) throw();
2600 // C++11:
2601 // void* operator new(std::size_t);
2602 // void* operator new[](std::size_t);
2603 // void operator delete(void*) noexcept;
2604 // void operator delete[](void*) noexcept;
2605 // C++1y:
2606 // void* operator new(std::size_t);
2607 // void* operator new[](std::size_t);
2608 // void operator delete(void*) noexcept;
2609 // void operator delete[](void*) noexcept;
2610 // void operator delete(void*, std::size_t) noexcept;
2611 // void operator delete[](void*, std::size_t) noexcept;
2612 //
2613 // These implicit declarations introduce only the function names operator
2614 // new, operator new[], operator delete, operator delete[].
2615 //
2616 // Here, we need to refer to std::bad_alloc, so we will implicitly declare
2617 // "std" or "bad_alloc" as necessary to form the exception specification.
2618 // However, we do not make these implicit declarations visible to name
2619 // lookup.
2620 if (!StdBadAlloc && !getLangOpts().CPlusPlus11) {
2621 // The "std::bad_alloc" class has not yet been declared, so build it
2622 // implicitly.
2623 StdBadAlloc = CXXRecordDecl::Create(Context, TTK_Class,
2624 getOrCreateStdNamespace(),
2625 SourceLocation(), SourceLocation(),
2626 &PP.getIdentifierTable().get("bad_alloc"),
2627 nullptr);
2628 getStdBadAlloc()->setImplicit(true);
2629 }
2630 if (!StdAlignValT && getLangOpts().AlignedAllocation) {
2631 // The "std::align_val_t" enum class has not yet been declared, so build it
2632 // implicitly.
2633 auto *AlignValT = EnumDecl::Create(
2634 Context, getOrCreateStdNamespace(), SourceLocation(), SourceLocation(),
2635 &PP.getIdentifierTable().get("align_val_t"), nullptr, true, true, true);
2636 AlignValT->setIntegerType(Context.getSizeType());
2637 AlignValT->setPromotionType(Context.getSizeType());
2638 AlignValT->setImplicit(true);
2639 StdAlignValT = AlignValT;
2640 }
2641
2642 GlobalNewDeleteDeclared = true;
2643
2644 QualType VoidPtr = Context.getPointerType(Context.VoidTy);
2645 QualType SizeT = Context.getSizeType();
2646
2647 auto DeclareGlobalAllocationFunctions = [&](OverloadedOperatorKind Kind,
2648 QualType Return, QualType Param) {
2649 llvm::SmallVector<QualType, 3> Params;
2650 Params.push_back(Param);
2651
2652 // Create up to four variants of the function (sized/aligned).
2653 bool HasSizedVariant = getLangOpts().SizedDeallocation &&
2654 (Kind == OO_Delete || Kind == OO_Array_Delete);
2655 bool HasAlignedVariant = getLangOpts().AlignedAllocation;
2656
2657 int NumSizeVariants = (HasSizedVariant ? 2 : 1);
2658 int NumAlignVariants = (HasAlignedVariant ? 2 : 1);
2659 for (int Sized = 0; Sized < NumSizeVariants; ++Sized) {
2660 if (Sized)
2661 Params.push_back(SizeT);
2662
2663 for (int Aligned = 0; Aligned < NumAlignVariants; ++Aligned) {
2664 if (Aligned)
2665 Params.push_back(Context.getTypeDeclType(getStdAlignValT()));
2666
2667 DeclareGlobalAllocationFunction(
2668 Context.DeclarationNames.getCXXOperatorName(Kind), Return, Params);
2669
2670 if (Aligned)
2671 Params.pop_back();
2672 }
2673 }
2674 };
2675
2676 DeclareGlobalAllocationFunctions(OO_New, VoidPtr, SizeT);
2677 DeclareGlobalAllocationFunctions(OO_Array_New, VoidPtr, SizeT);
2678 DeclareGlobalAllocationFunctions(OO_Delete, Context.VoidTy, VoidPtr);
2679 DeclareGlobalAllocationFunctions(OO_Array_Delete, Context.VoidTy, VoidPtr);
2680}
2681
2682/// DeclareGlobalAllocationFunction - Declares a single implicit global
2683/// allocation function if it doesn't already exist.
2684void Sema::DeclareGlobalAllocationFunction(DeclarationName Name,
2685 QualType Return,
2686 ArrayRef<QualType> Params) {
2687 DeclContext *GlobalCtx = Context.getTranslationUnitDecl();
2688
2689 // Check if this function is already declared.
2690 DeclContext::lookup_result R = GlobalCtx->lookup(Name);
2691 for (DeclContext::lookup_iterator Alloc = R.begin(), AllocEnd = R.end();
2692 Alloc != AllocEnd; ++Alloc) {
2693 // Only look at non-template functions, as it is the predefined,
2694 // non-templated allocation function we are trying to declare here.
2695 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(*Alloc)) {
2696 if (Func->getNumParams() == Params.size()) {
2697 llvm::SmallVector<QualType, 3> FuncParams;
2698 for (auto *P : Func->parameters())
2699 FuncParams.push_back(
2700 Context.getCanonicalType(P->getType().getUnqualifiedType()));
2701 if (llvm::makeArrayRef(FuncParams) == Params) {
2702 // Make the function visible to name lookup, even if we found it in
2703 // an unimported module. It either is an implicitly-declared global
2704 // allocation function, or is suppressing that function.
2705 Func->setVisibleDespiteOwningModule();
2706 return;
2707 }
2708 }
2709 }
2710 }
2711
2712 FunctionProtoType::ExtProtoInfo EPI;
2713
2714 QualType BadAllocType;
2715 bool HasBadAllocExceptionSpec
2716 = (Name.getCXXOverloadedOperator() == OO_New ||
2717 Name.getCXXOverloadedOperator() == OO_Array_New);
2718 if (HasBadAllocExceptionSpec) {
2719 if (!getLangOpts().CPlusPlus11) {
2720 BadAllocType = Context.getTypeDeclType(getStdBadAlloc());
2721 assert(StdBadAlloc && "Must have std::bad_alloc declared")(static_cast <bool> (StdBadAlloc && "Must have std::bad_alloc declared"
) ? void (0) : __assert_fail ("StdBadAlloc && \"Must have std::bad_alloc declared\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 2721, __extension__ __PRETTY_FUNCTION__))
;
2722 EPI.ExceptionSpec.Type = EST_Dynamic;
2723 EPI.ExceptionSpec.Exceptions = llvm::makeArrayRef(BadAllocType);
2724 }
2725 } else {
2726 EPI.ExceptionSpec =
2727 getLangOpts().CPlusPlus11 ? EST_BasicNoexcept : EST_DynamicNone;
2728 }
2729
2730 auto CreateAllocationFunctionDecl = [&](Attr *ExtraAttr) {
2731 QualType FnType = Context.getFunctionType(Return, Params, EPI);
2732 FunctionDecl *Alloc = FunctionDecl::Create(
2733 Context, GlobalCtx, SourceLocation(), SourceLocation(), Name,
2734 FnType, /*TInfo=*/nullptr, SC_None, false, true);
2735 Alloc->setImplicit();
2736 // Global allocation functions should always be visible.
2737 Alloc->setVisibleDespiteOwningModule();
2738
2739 // Implicit sized deallocation functions always have default visibility.
2740 Alloc->addAttr(
2741 VisibilityAttr::CreateImplicit(Context, VisibilityAttr::Default));
1
Calling 'VisibilityAttr::CreateImplicit'
2742
2743 llvm::SmallVector<ParmVarDecl *, 3> ParamDecls;
2744 for (QualType T : Params) {
2745 ParamDecls.push_back(ParmVarDecl::Create(
2746 Context, Alloc, SourceLocation(), SourceLocation(), nullptr, T,
2747 /*TInfo=*/nullptr, SC_None, nullptr));
2748 ParamDecls.back()->setImplicit();
2749 }
2750 Alloc->setParams(ParamDecls);
2751 if (ExtraAttr)
2752 Alloc->addAttr(ExtraAttr);
2753 Context.getTranslationUnitDecl()->addDecl(Alloc);
2754 IdResolver.tryAddTopLevelDecl(Alloc, Name);
2755 };
2756
2757 if (!LangOpts.CUDA)
2758 CreateAllocationFunctionDecl(nullptr);
2759 else {
2760 // Host and device get their own declaration so each can be
2761 // defined or re-declared independently.
2762 CreateAllocationFunctionDecl(CUDAHostAttr::CreateImplicit(Context));
2763 CreateAllocationFunctionDecl(CUDADeviceAttr::CreateImplicit(Context));
2764 }
2765}
2766
2767FunctionDecl *Sema::FindUsualDeallocationFunction(SourceLocation StartLoc,
2768 bool CanProvideSize,
2769 bool Overaligned,
2770 DeclarationName Name) {
2771 DeclareGlobalNewDelete();
2772
2773 LookupResult FoundDelete(*this, Name, StartLoc, LookupOrdinaryName);
2774 LookupQualifiedName(FoundDelete, Context.getTranslationUnitDecl());
2775
2776 // FIXME: It's possible for this to result in ambiguity, through a
2777 // user-declared variadic operator delete or the enable_if attribute. We
2778 // should probably not consider those cases to be usual deallocation
2779 // functions. But for now we just make an arbitrary choice in that case.
2780 auto Result = resolveDeallocationOverload(*this, FoundDelete, CanProvideSize,
2781 Overaligned);
2782 assert(Result.FD && "operator delete missing from global scope?")(static_cast <bool> (Result.FD && "operator delete missing from global scope?"
) ? void (0) : __assert_fail ("Result.FD && \"operator delete missing from global scope?\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 2782, __extension__ __PRETTY_FUNCTION__))
;
2783 return Result.FD;
2784}
2785
2786FunctionDecl *Sema::FindDeallocationFunctionForDestructor(SourceLocation Loc,
2787 CXXRecordDecl *RD) {
2788 DeclarationName Name = Context.DeclarationNames.getCXXOperatorName(OO_Delete);
2789
2790 FunctionDecl *OperatorDelete = nullptr;
2791 if (FindDeallocationFunction(Loc, RD, Name, OperatorDelete))
2792 return nullptr;
2793 if (OperatorDelete)
2794 return OperatorDelete;
2795
2796 // If there's no class-specific operator delete, look up the global
2797 // non-array delete.
2798 return FindUsualDeallocationFunction(
2799 Loc, true, hasNewExtendedAlignment(*this, Context.getRecordType(RD)),
2800 Name);
2801}
2802
2803bool Sema::FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD,
2804 DeclarationName Name,
2805 FunctionDecl *&Operator, bool Diagnose) {
2806 LookupResult Found(*this, Name, StartLoc, LookupOrdinaryName);
2807 // Try to find operator delete/operator delete[] in class scope.
2808 LookupQualifiedName(Found, RD);
2809
2810 if (Found.isAmbiguous())
2811 return true;
2812
2813 Found.suppressDiagnostics();
2814
2815 bool Overaligned = hasNewExtendedAlignment(*this, Context.getRecordType(RD));
2816
2817 // C++17 [expr.delete]p10:
2818 // If the deallocation functions have class scope, the one without a
2819 // parameter of type std::size_t is selected.
2820 llvm::SmallVector<UsualDeallocFnInfo, 4> Matches;
2821 resolveDeallocationOverload(*this, Found, /*WantSize*/ false,
2822 /*WantAlign*/ Overaligned, &Matches);
2823
2824 // If we could find an overload, use it.
2825 if (Matches.size() == 1) {
2826 Operator = cast<CXXMethodDecl>(Matches[0].FD);
2827
2828 // FIXME: DiagnoseUseOfDecl?
2829 if (Operator->isDeleted()) {
2830 if (Diagnose) {
2831 Diag(StartLoc, diag::err_deleted_function_use);
2832 NoteDeletedFunction(Operator);
2833 }
2834 return true;
2835 }
2836
2837 if (CheckAllocationAccess(StartLoc, SourceRange(), Found.getNamingClass(),
2838 Matches[0].Found, Diagnose) == AR_inaccessible)
2839 return true;
2840
2841 return false;
2842 }
2843
2844 // We found multiple suitable operators; complain about the ambiguity.
2845 // FIXME: The standard doesn't say to do this; it appears that the intent
2846 // is that this should never happen.
2847 if (!Matches.empty()) {
2848 if (Diagnose) {
2849 Diag(StartLoc, diag::err_ambiguous_suitable_delete_member_function_found)
2850 << Name << RD;
2851 for (auto &Match : Matches)
2852 Diag(Match.FD->getLocation(), diag::note_member_declared_here) << Name;
2853 }
2854 return true;
2855 }
2856
2857 // We did find operator delete/operator delete[] declarations, but
2858 // none of them were suitable.
2859 if (!Found.empty()) {
2860 if (Diagnose) {
2861 Diag(StartLoc, diag::err_no_suitable_delete_member_function_found)
2862 << Name << RD;
2863
2864 for (NamedDecl *D : Found)
2865 Diag(D->getUnderlyingDecl()->getLocation(),
2866 diag::note_member_declared_here) << Name;
2867 }
2868 return true;
2869 }
2870
2871 Operator = nullptr;
2872 return false;
2873}
2874
2875namespace {
2876/// \brief Checks whether delete-expression, and new-expression used for
2877/// initializing deletee have the same array form.
2878class MismatchingNewDeleteDetector {
2879public:
2880 enum MismatchResult {
2881 /// Indicates that there is no mismatch or a mismatch cannot be proven.
2882 NoMismatch,
2883 /// Indicates that variable is initialized with mismatching form of \a new.
2884 VarInitMismatches,
2885 /// Indicates that member is initialized with mismatching form of \a new.
2886 MemberInitMismatches,
2887 /// Indicates that 1 or more constructors' definitions could not been
2888 /// analyzed, and they will be checked again at the end of translation unit.
2889 AnalyzeLater
2890 };
2891
2892 /// \param EndOfTU True, if this is the final analysis at the end of
2893 /// translation unit. False, if this is the initial analysis at the point
2894 /// delete-expression was encountered.
2895 explicit MismatchingNewDeleteDetector(bool EndOfTU)
2896 : Field(nullptr), IsArrayForm(false), EndOfTU(EndOfTU),
2897 HasUndefinedConstructors(false) {}
2898
2899 /// \brief Checks whether pointee of a delete-expression is initialized with
2900 /// matching form of new-expression.
2901 ///
2902 /// If return value is \c VarInitMismatches or \c MemberInitMismatches at the
2903 /// point where delete-expression is encountered, then a warning will be
2904 /// issued immediately. If return value is \c AnalyzeLater at the point where
2905 /// delete-expression is seen, then member will be analyzed at the end of
2906 /// translation unit. \c AnalyzeLater is returned iff at least one constructor
2907 /// couldn't be analyzed. If at least one constructor initializes the member
2908 /// with matching type of new, the return value is \c NoMismatch.
2909 MismatchResult analyzeDeleteExpr(const CXXDeleteExpr *DE);
2910 /// \brief Analyzes a class member.
2911 /// \param Field Class member to analyze.
2912 /// \param DeleteWasArrayForm Array form-ness of the delete-expression used
2913 /// for deleting the \p Field.
2914 MismatchResult analyzeField(FieldDecl *Field, bool DeleteWasArrayForm);
2915 FieldDecl *Field;
2916 /// List of mismatching new-expressions used for initialization of the pointee
2917 llvm::SmallVector<const CXXNewExpr *, 4> NewExprs;
2918 /// Indicates whether delete-expression was in array form.
2919 bool IsArrayForm;
2920
2921private:
2922 const bool EndOfTU;
2923 /// \brief Indicates that there is at least one constructor without body.
2924 bool HasUndefinedConstructors;
2925 /// \brief Returns \c CXXNewExpr from given initialization expression.
2926 /// \param E Expression used for initializing pointee in delete-expression.
2927 /// E can be a single-element \c InitListExpr consisting of new-expression.
2928 const CXXNewExpr *getNewExprFromInitListOrExpr(const Expr *E);
2929 /// \brief Returns whether member is initialized with mismatching form of
2930 /// \c new either by the member initializer or in-class initialization.
2931 ///
2932 /// If bodies of all constructors are not visible at the end of translation
2933 /// unit or at least one constructor initializes member with the matching
2934 /// form of \c new, mismatch cannot be proven, and this function will return
2935 /// \c NoMismatch.
2936 MismatchResult analyzeMemberExpr(const MemberExpr *ME);
2937 /// \brief Returns whether variable is initialized with mismatching form of
2938 /// \c new.
2939 ///
2940 /// If variable is initialized with matching form of \c new or variable is not
2941 /// initialized with a \c new expression, this function will return true.
2942 /// If variable is initialized with mismatching form of \c new, returns false.
2943 /// \param D Variable to analyze.
2944 bool hasMatchingVarInit(const DeclRefExpr *D);
2945 /// \brief Checks whether the constructor initializes pointee with mismatching
2946 /// form of \c new.
2947 ///
2948 /// Returns true, if member is initialized with matching form of \c new in
2949 /// member initializer list. Returns false, if member is initialized with the
2950 /// matching form of \c new in this constructor's initializer or given
2951 /// constructor isn't defined at the point where delete-expression is seen, or
2952 /// member isn't initialized by the constructor.
2953 bool hasMatchingNewInCtor(const CXXConstructorDecl *CD);
2954 /// \brief Checks whether member is initialized with matching form of
2955 /// \c new in member initializer list.
2956 bool hasMatchingNewInCtorInit(const CXXCtorInitializer *CI);
2957 /// Checks whether member is initialized with mismatching form of \c new by
2958 /// in-class initializer.
2959 MismatchResult analyzeInClassInitializer();
2960};
2961}
2962
2963MismatchingNewDeleteDetector::MismatchResult
2964MismatchingNewDeleteDetector::analyzeDeleteExpr(const CXXDeleteExpr *DE) {
2965 NewExprs.clear();
2966 assert(DE && "Expected delete-expression")(static_cast <bool> (DE && "Expected delete-expression"
) ? void (0) : __assert_fail ("DE && \"Expected delete-expression\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 2966, __extension__ __PRETTY_FUNCTION__))
;
2967 IsArrayForm = DE->isArrayForm();
2968 const Expr *E = DE->getArgument()->IgnoreParenImpCasts();
2969 if (const MemberExpr *ME = dyn_cast<const MemberExpr>(E)) {
2970 return analyzeMemberExpr(ME);
2971 } else if (const DeclRefExpr *D = dyn_cast<const DeclRefExpr>(E)) {
2972 if (!hasMatchingVarInit(D))
2973 return VarInitMismatches;
2974 }
2975 return NoMismatch;
2976}
2977
2978const CXXNewExpr *
2979MismatchingNewDeleteDetector::getNewExprFromInitListOrExpr(const Expr *E) {
2980 assert(E != nullptr && "Expected a valid initializer expression")(static_cast <bool> (E != nullptr && "Expected a valid initializer expression"
) ? void (0) : __assert_fail ("E != nullptr && \"Expected a valid initializer expression\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 2980, __extension__ __PRETTY_FUNCTION__))
;
2981 E = E->IgnoreParenImpCasts();
2982 if (const InitListExpr *ILE = dyn_cast<const InitListExpr>(E)) {
2983 if (ILE->getNumInits() == 1)
2984 E = dyn_cast<const CXXNewExpr>(ILE->getInit(0)->IgnoreParenImpCasts());
2985 }
2986
2987 return dyn_cast_or_null<const CXXNewExpr>(E);
2988}
2989
2990bool MismatchingNewDeleteDetector::hasMatchingNewInCtorInit(
2991 const CXXCtorInitializer *CI) {
2992 const CXXNewExpr *NE = nullptr;
2993 if (Field == CI->getMember() &&
2994 (NE = getNewExprFromInitListOrExpr(CI->getInit()))) {
2995 if (NE->isArray() == IsArrayForm)
2996 return true;
2997 else
2998 NewExprs.push_back(NE);
2999 }
3000 return false;
3001}
3002
3003bool MismatchingNewDeleteDetector::hasMatchingNewInCtor(
3004 const CXXConstructorDecl *CD) {
3005 if (CD->isImplicit())
3006 return false;
3007 const FunctionDecl *Definition = CD;
3008 if (!CD->isThisDeclarationADefinition() && !CD->isDefined(Definition)) {
3009 HasUndefinedConstructors = true;
3010 return EndOfTU;
3011 }
3012 for (const auto *CI : cast<const CXXConstructorDecl>(Definition)->inits()) {
3013 if (hasMatchingNewInCtorInit(CI))
3014 return true;
3015 }
3016 return false;
3017}
3018
3019MismatchingNewDeleteDetector::MismatchResult
3020MismatchingNewDeleteDetector::analyzeInClassInitializer() {
3021 assert(Field != nullptr && "This should be called only for members")(static_cast <bool> (Field != nullptr && "This should be called only for members"
) ? void (0) : __assert_fail ("Field != nullptr && \"This should be called only for members\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3021, __extension__ __PRETTY_FUNCTION__))
;
3022 const Expr *InitExpr = Field->getInClassInitializer();
3023 if (!InitExpr)
3024 return EndOfTU ? NoMismatch : AnalyzeLater;
3025 if (const CXXNewExpr *NE = getNewExprFromInitListOrExpr(InitExpr)) {
3026 if (NE->isArray() != IsArrayForm) {
3027 NewExprs.push_back(NE);
3028 return MemberInitMismatches;
3029 }
3030 }
3031 return NoMismatch;
3032}
3033
3034MismatchingNewDeleteDetector::MismatchResult
3035MismatchingNewDeleteDetector::analyzeField(FieldDecl *Field,
3036 bool DeleteWasArrayForm) {
3037 assert(Field != nullptr && "Analysis requires a valid class member.")(static_cast <bool> (Field != nullptr && "Analysis requires a valid class member."
) ? void (0) : __assert_fail ("Field != nullptr && \"Analysis requires a valid class member.\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3037, __extension__ __PRETTY_FUNCTION__))
;
3038 this->Field = Field;
3039 IsArrayForm = DeleteWasArrayForm;
3040 const CXXRecordDecl *RD = cast<const CXXRecordDecl>(Field->getParent());
3041 for (const auto *CD : RD->ctors()) {
3042 if (hasMatchingNewInCtor(CD))
3043 return NoMismatch;
3044 }
3045 if (HasUndefinedConstructors)
3046 return EndOfTU ? NoMismatch : AnalyzeLater;
3047 if (!NewExprs.empty())
3048 return MemberInitMismatches;
3049 return Field->hasInClassInitializer() ? analyzeInClassInitializer()
3050 : NoMismatch;
3051}
3052
3053MismatchingNewDeleteDetector::MismatchResult
3054MismatchingNewDeleteDetector::analyzeMemberExpr(const MemberExpr *ME) {
3055 assert(ME != nullptr && "Expected a member expression")(static_cast <bool> (ME != nullptr && "Expected a member expression"
) ? void (0) : __assert_fail ("ME != nullptr && \"Expected a member expression\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3055, __extension__ __PRETTY_FUNCTION__))
;
3056 if (FieldDecl *F = dyn_cast<FieldDecl>(ME->getMemberDecl()))
3057 return analyzeField(F, IsArrayForm);
3058 return NoMismatch;
3059}
3060
3061bool MismatchingNewDeleteDetector::hasMatchingVarInit(const DeclRefExpr *D) {
3062 const CXXNewExpr *NE = nullptr;
3063 if (const VarDecl *VD = dyn_cast<const VarDecl>(D->getDecl())) {
3064 if (VD->hasInit() && (NE = getNewExprFromInitListOrExpr(VD->getInit())) &&
3065 NE->isArray() != IsArrayForm) {
3066 NewExprs.push_back(NE);
3067 }
3068 }
3069 return NewExprs.empty();
3070}
3071
3072static void
3073DiagnoseMismatchedNewDelete(Sema &SemaRef, SourceLocation DeleteLoc,
3074 const MismatchingNewDeleteDetector &Detector) {
3075 SourceLocation EndOfDelete = SemaRef.getLocForEndOfToken(DeleteLoc);
3076 FixItHint H;
3077 if (!Detector.IsArrayForm)
3078 H = FixItHint::CreateInsertion(EndOfDelete, "[]");
3079 else {
3080 SourceLocation RSquare = Lexer::findLocationAfterToken(
3081 DeleteLoc, tok::l_square, SemaRef.getSourceManager(),
3082 SemaRef.getLangOpts(), true);
3083 if (RSquare.isValid())
3084 H = FixItHint::CreateRemoval(SourceRange(EndOfDelete, RSquare));
3085 }
3086 SemaRef.Diag(DeleteLoc, diag::warn_mismatched_delete_new)
3087 << Detector.IsArrayForm << H;
3088
3089 for (const auto *NE : Detector.NewExprs)
3090 SemaRef.Diag(NE->getExprLoc(), diag::note_allocated_here)
3091 << Detector.IsArrayForm;
3092}
3093
3094void Sema::AnalyzeDeleteExprMismatch(const CXXDeleteExpr *DE) {
3095 if (Diags.isIgnored(diag::warn_mismatched_delete_new, SourceLocation()))
3096 return;
3097 MismatchingNewDeleteDetector Detector(/*EndOfTU=*/false);
3098 switch (Detector.analyzeDeleteExpr(DE)) {
3099 case MismatchingNewDeleteDetector::VarInitMismatches:
3100 case MismatchingNewDeleteDetector::MemberInitMismatches: {
3101 DiagnoseMismatchedNewDelete(*this, DE->getLocStart(), Detector);
3102 break;
3103 }
3104 case MismatchingNewDeleteDetector::AnalyzeLater: {
3105 DeleteExprs[Detector.Field].push_back(
3106 std::make_pair(DE->getLocStart(), DE->isArrayForm()));
3107 break;
3108 }
3109 case MismatchingNewDeleteDetector::NoMismatch:
3110 break;
3111 }
3112}
3113
3114void Sema::AnalyzeDeleteExprMismatch(FieldDecl *Field, SourceLocation DeleteLoc,
3115 bool DeleteWasArrayForm) {
3116 MismatchingNewDeleteDetector Detector(/*EndOfTU=*/true);
3117 switch (Detector.analyzeField(Field, DeleteWasArrayForm)) {
3118 case MismatchingNewDeleteDetector::VarInitMismatches:
3119 llvm_unreachable("This analysis should have been done for class members.")::llvm::llvm_unreachable_internal("This analysis should have been done for class members."
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3119)
;
3120 case MismatchingNewDeleteDetector::AnalyzeLater:
3121 llvm_unreachable("Analysis cannot be postponed any point beyond end of "::llvm::llvm_unreachable_internal("Analysis cannot be postponed any point beyond end of "
"translation unit.", "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3122)
3122 "translation unit.")::llvm::llvm_unreachable_internal("Analysis cannot be postponed any point beyond end of "
"translation unit.", "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3122)
;
3123 case MismatchingNewDeleteDetector::MemberInitMismatches:
3124 DiagnoseMismatchedNewDelete(*this, DeleteLoc, Detector);
3125 break;
3126 case MismatchingNewDeleteDetector::NoMismatch:
3127 break;
3128 }
3129}
3130
3131/// ActOnCXXDelete - Parsed a C++ 'delete' expression (C++ 5.3.5), as in:
3132/// @code ::delete ptr; @endcode
3133/// or
3134/// @code delete [] ptr; @endcode
3135ExprResult
3136Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
3137 bool ArrayForm, Expr *ExE) {
3138 // C++ [expr.delete]p1:
3139 // The operand shall have a pointer type, or a class type having a single
3140 // non-explicit conversion function to a pointer type. The result has type
3141 // void.
3142 //
3143 // DR599 amends "pointer type" to "pointer to object type" in both cases.
3144
3145 ExprResult Ex = ExE;
3146 FunctionDecl *OperatorDelete = nullptr;
3147 bool ArrayFormAsWritten = ArrayForm;
3148 bool UsualArrayDeleteWantsSize = false;
3149
3150 if (!Ex.get()->isTypeDependent()) {
3151 // Perform lvalue-to-rvalue cast, if needed.
3152 Ex = DefaultLvalueConversion(Ex.get());
3153 if (Ex.isInvalid())
3154 return ExprError();
3155
3156 QualType Type = Ex.get()->getType();
3157
3158 class DeleteConverter : public ContextualImplicitConverter {
3159 public:
3160 DeleteConverter() : ContextualImplicitConverter(false, true) {}
3161
3162 bool match(QualType ConvType) override {
3163 // FIXME: If we have an operator T* and an operator void*, we must pick
3164 // the operator T*.
3165 if (const PointerType *ConvPtrType = ConvType->getAs<PointerType>())
3166 if (ConvPtrType->getPointeeType()->isIncompleteOrObjectType())
3167 return true;
3168 return false;
3169 }
3170
3171 SemaDiagnosticBuilder diagnoseNoMatch(Sema &S, SourceLocation Loc,
3172 QualType T) override {
3173 return S.Diag(Loc, diag::err_delete_operand) << T;
3174 }
3175
3176 SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc,
3177 QualType T) override {
3178 return S.Diag(Loc, diag::err_delete_incomplete_class_type) << T;
3179 }
3180
3181 SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc,
3182 QualType T,
3183 QualType ConvTy) override {
3184 return S.Diag(Loc, diag::err_delete_explicit_conversion) << T << ConvTy;
3185 }
3186
3187 SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv,
3188 QualType ConvTy) override {
3189 return S.Diag(Conv->getLocation(), diag::note_delete_conversion)
3190 << ConvTy;
3191 }
3192
3193 SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc,
3194 QualType T) override {
3195 return S.Diag(Loc, diag::err_ambiguous_delete_operand) << T;
3196 }
3197
3198 SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv,
3199 QualType ConvTy) override {
3200 return S.Diag(Conv->getLocation(), diag::note_delete_conversion)
3201 << ConvTy;
3202 }
3203
3204 SemaDiagnosticBuilder diagnoseConversion(Sema &S, SourceLocation Loc,
3205 QualType T,
3206 QualType ConvTy) override {
3207 llvm_unreachable("conversion functions are permitted")::llvm::llvm_unreachable_internal("conversion functions are permitted"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3207)
;
3208 }
3209 } Converter;
3210
3211 Ex = PerformContextualImplicitConversion(StartLoc, Ex.get(), Converter);
3212 if (Ex.isInvalid())
3213 return ExprError();
3214 Type = Ex.get()->getType();
3215 if (!Converter.match(Type))
3216 // FIXME: PerformContextualImplicitConversion should return ExprError
3217 // itself in this case.
3218 return ExprError();
3219
3220 QualType Pointee = Type->getAs<PointerType>()->getPointeeType();
3221 QualType PointeeElem = Context.getBaseElementType(Pointee);
3222
3223 if (Pointee.getAddressSpace() != LangAS::Default)
3224 return Diag(Ex.get()->getLocStart(),
3225 diag::err_address_space_qualified_delete)
3226 << Pointee.getUnqualifiedType()
3227 << Pointee.getQualifiers().getAddressSpaceAttributePrintValue();
3228
3229 CXXRecordDecl *PointeeRD = nullptr;
3230 if (Pointee->isVoidType() && !isSFINAEContext()) {
3231 // The C++ standard bans deleting a pointer to a non-object type, which
3232 // effectively bans deletion of "void*". However, most compilers support
3233 // this, so we treat it as a warning unless we're in a SFINAE context.
3234 Diag(StartLoc, diag::ext_delete_void_ptr_operand)
3235 << Type << Ex.get()->getSourceRange();
3236 } else if (Pointee->isFunctionType() || Pointee->isVoidType()) {
3237 return ExprError(Diag(StartLoc, diag::err_delete_operand)
3238 << Type << Ex.get()->getSourceRange());
3239 } else if (!Pointee->isDependentType()) {
3240 // FIXME: This can result in errors if the definition was imported from a
3241 // module but is hidden.
3242 if (!RequireCompleteType(StartLoc, Pointee,
3243 diag::warn_delete_incomplete, Ex.get())) {
3244 if (const RecordType *RT = PointeeElem->getAs<RecordType>())
3245 PointeeRD = cast<CXXRecordDecl>(RT->getDecl());
3246 }
3247 }
3248
3249 if (Pointee->isArrayType() && !ArrayForm) {
3250 Diag(StartLoc, diag::warn_delete_array_type)
3251 << Type << Ex.get()->getSourceRange()
3252 << FixItHint::CreateInsertion(getLocForEndOfToken(StartLoc), "[]");
3253 ArrayForm = true;
3254 }
3255
3256 DeclarationName DeleteName = Context.DeclarationNames.getCXXOperatorName(
3257 ArrayForm ? OO_Array_Delete : OO_Delete);
3258
3259 if (PointeeRD) {
3260 if (!UseGlobal &&
3261 FindDeallocationFunction(StartLoc, PointeeRD, DeleteName,
3262 OperatorDelete))
3263 return ExprError();
3264
3265 // If we're allocating an array of records, check whether the
3266 // usual operator delete[] has a size_t parameter.
3267 if (ArrayForm) {
3268 // If the user specifically asked to use the global allocator,
3269 // we'll need to do the lookup into the class.
3270 if (UseGlobal)
3271 UsualArrayDeleteWantsSize =
3272 doesUsualArrayDeleteWantSize(*this, StartLoc, PointeeElem);
3273
3274 // Otherwise, the usual operator delete[] should be the
3275 // function we just found.
3276 else if (OperatorDelete && isa<CXXMethodDecl>(OperatorDelete))
3277 UsualArrayDeleteWantsSize =
3278 UsualDeallocFnInfo(*this,
3279 DeclAccessPair::make(OperatorDelete, AS_public))
3280 .HasSizeT;
3281 }
3282
3283 if (!PointeeRD->hasIrrelevantDestructor())
3284 if (CXXDestructorDecl *Dtor = LookupDestructor(PointeeRD)) {
3285 MarkFunctionReferenced(StartLoc,
3286 const_cast<CXXDestructorDecl*>(Dtor));
3287 if (DiagnoseUseOfDecl(Dtor, StartLoc))
3288 return ExprError();
3289 }
3290
3291 CheckVirtualDtorCall(PointeeRD->getDestructor(), StartLoc,
3292 /*IsDelete=*/true, /*CallCanBeVirtual=*/true,
3293 /*WarnOnNonAbstractTypes=*/!ArrayForm,
3294 SourceLocation());
3295 }
3296
3297 if (!OperatorDelete) {
3298 bool IsComplete = isCompleteType(StartLoc, Pointee);
3299 bool CanProvideSize =
3300 IsComplete && (!ArrayForm || UsualArrayDeleteWantsSize ||
3301 Pointee.isDestructedType());
3302 bool Overaligned = hasNewExtendedAlignment(*this, Pointee);
3303
3304 // Look for a global declaration.
3305 OperatorDelete = FindUsualDeallocationFunction(StartLoc, CanProvideSize,
3306 Overaligned, DeleteName);
3307 }
3308
3309 MarkFunctionReferenced(StartLoc, OperatorDelete);
3310
3311 // Check access and ambiguity of destructor if we're going to call it.
3312 // Note that this is required even for a virtual delete.
3313 bool IsVirtualDelete = false;
3314 if (PointeeRD) {
3315 if (CXXDestructorDecl *Dtor = LookupDestructor(PointeeRD)) {
3316 CheckDestructorAccess(Ex.get()->getExprLoc(), Dtor,
3317 PDiag(diag::err_access_dtor) << PointeeElem);
3318 IsVirtualDelete = Dtor->isVirtual();
3319 }
3320 }
3321
3322 diagnoseUnavailableAlignedAllocation(*OperatorDelete, StartLoc, true,
3323 *this);
3324
3325 // Convert the operand to the type of the first parameter of operator
3326 // delete. This is only necessary if we selected a destroying operator
3327 // delete that we are going to call (non-virtually); converting to void*
3328 // is trivial and left to AST consumers to handle.
3329 QualType ParamType = OperatorDelete->getParamDecl(0)->getType();
3330 if (!IsVirtualDelete && !ParamType->getPointeeType()->isVoidType()) {
3331 Qualifiers Qs = Pointee.getQualifiers();
3332 if (Qs.hasCVRQualifiers()) {
3333 // Qualifiers are irrelevant to this conversion; we're only looking
3334 // for access and ambiguity.
3335 Qs.removeCVRQualifiers();
3336 QualType Unqual = Context.getPointerType(
3337 Context.getQualifiedType(Pointee.getUnqualifiedType(), Qs));
3338 Ex = ImpCastExprToType(Ex.get(), Unqual, CK_NoOp);
3339 }
3340 Ex = PerformImplicitConversion(Ex.get(), ParamType, AA_Passing);
3341 if (Ex.isInvalid())
3342 return ExprError();
3343 }
3344 }
3345
3346 CXXDeleteExpr *Result = new (Context) CXXDeleteExpr(
3347 Context.VoidTy, UseGlobal, ArrayForm, ArrayFormAsWritten,
3348 UsualArrayDeleteWantsSize, OperatorDelete, Ex.get(), StartLoc);
3349 AnalyzeDeleteExprMismatch(Result);
3350 return Result;
3351}
3352
3353static bool resolveBuiltinNewDeleteOverload(Sema &S, CallExpr *TheCall,
3354 bool IsDelete,
3355 FunctionDecl *&Operator) {
3356
3357 DeclarationName NewName = S.Context.DeclarationNames.getCXXOperatorName(
3358 IsDelete ? OO_Delete : OO_New);
3359
3360 LookupResult R(S, NewName, TheCall->getLocStart(), Sema::LookupOrdinaryName);
3361 S.LookupQualifiedName(R, S.Context.getTranslationUnitDecl());
3362 assert(!R.empty() && "implicitly declared allocation functions not found")(static_cast <bool> (!R.empty() && "implicitly declared allocation functions not found"
) ? void (0) : __assert_fail ("!R.empty() && \"implicitly declared allocation functions not found\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3362, __extension__ __PRETTY_FUNCTION__))
;
3363 assert(!R.isAmbiguous() && "global allocation functions are ambiguous")(static_cast <bool> (!R.isAmbiguous() && "global allocation functions are ambiguous"
) ? void (0) : __assert_fail ("!R.isAmbiguous() && \"global allocation functions are ambiguous\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3363, __extension__ __PRETTY_FUNCTION__))
;
3364
3365 // We do our own custom access checks below.
3366 R.suppressDiagnostics();
3367
3368 SmallVector<Expr *, 8> Args(TheCall->arg_begin(), TheCall->arg_end());
3369 OverloadCandidateSet Candidates(R.getNameLoc(),
3370 OverloadCandidateSet::CSK_Normal);
3371 for (LookupResult::iterator FnOvl = R.begin(), FnOvlEnd = R.end();
3372 FnOvl != FnOvlEnd; ++FnOvl) {
3373 // Even member operator new/delete are implicitly treated as
3374 // static, so don't use AddMemberCandidate.
3375 NamedDecl *D = (*FnOvl)->getUnderlyingDecl();
3376
3377 if (FunctionTemplateDecl *FnTemplate = dyn_cast<FunctionTemplateDecl>(D)) {
3378 S.AddTemplateOverloadCandidate(FnTemplate, FnOvl.getPair(),
3379 /*ExplicitTemplateArgs=*/nullptr, Args,
3380 Candidates,
3381 /*SuppressUserConversions=*/false);
3382 continue;
3383 }
3384
3385 FunctionDecl *Fn = cast<FunctionDecl>(D);
3386 S.AddOverloadCandidate(Fn, FnOvl.getPair(), Args, Candidates,
3387 /*SuppressUserConversions=*/false);
3388 }
3389
3390 SourceRange Range = TheCall->getSourceRange();
3391
3392 // Do the resolution.
3393 OverloadCandidateSet::iterator Best;
3394 switch (Candidates.BestViableFunction(S, R.getNameLoc(), Best)) {
3395 case OR_Success: {
3396 // Got one!
3397 FunctionDecl *FnDecl = Best->Function;
3398 assert(R.getNamingClass() == nullptr &&(static_cast <bool> (R.getNamingClass() == nullptr &&
"class members should not be considered") ? void (0) : __assert_fail
("R.getNamingClass() == nullptr && \"class members should not be considered\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3399, __extension__ __PRETTY_FUNCTION__))
3399 "class members should not be considered")(static_cast <bool> (R.getNamingClass() == nullptr &&
"class members should not be considered") ? void (0) : __assert_fail
("R.getNamingClass() == nullptr && \"class members should not be considered\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3399, __extension__ __PRETTY_FUNCTION__))
;
3400
3401 if (!FnDecl->isReplaceableGlobalAllocationFunction()) {
3402 S.Diag(R.getNameLoc(), diag::err_builtin_operator_new_delete_not_usual)
3403 << (IsDelete ? 1 : 0) << Range;
3404 S.Diag(FnDecl->getLocation(), diag::note_non_usual_function_declared_here)
3405 << R.getLookupName() << FnDecl->getSourceRange();
3406 return true;
3407 }
3408
3409 Operator = FnDecl;
3410 return false;
3411 }
3412
3413 case OR_No_Viable_Function:
3414 S.Diag(R.getNameLoc(), diag::err_ovl_no_viable_function_in_call)
3415 << R.getLookupName() << Range;
3416 Candidates.NoteCandidates(S, OCD_AllCandidates, Args);
3417 return true;
3418
3419 case OR_Ambiguous:
3420 S.Diag(R.getNameLoc(), diag::err_ovl_ambiguous_call)
3421 << R.getLookupName() << Range;
3422 Candidates.NoteCandidates(S, OCD_ViableCandidates, Args);
3423 return true;
3424
3425 case OR_Deleted: {
3426 S.Diag(R.getNameLoc(), diag::err_ovl_deleted_call)
3427 << Best->Function->isDeleted() << R.getLookupName()
3428 << S.getDeletedOrUnavailableSuffix(Best->Function) << Range;
3429 Candidates.NoteCandidates(S, OCD_AllCandidates, Args);
3430 return true;
3431 }
3432 }
3433 llvm_unreachable("Unreachable, bad result from BestViableFunction")::llvm::llvm_unreachable_internal("Unreachable, bad result from BestViableFunction"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3433)
;
3434}
3435
3436ExprResult
3437Sema::SemaBuiltinOperatorNewDeleteOverloaded(ExprResult TheCallResult,
3438 bool IsDelete) {
3439 CallExpr *TheCall = cast<CallExpr>(TheCallResult.get());
3440 if (!getLangOpts().CPlusPlus) {
3441 Diag(TheCall->getExprLoc(), diag::err_builtin_requires_language)
3442 << (IsDelete ? "__builtin_operator_delete" : "__builtin_operator_new")
3443 << "C++";
3444 return ExprError();
3445 }
3446 // CodeGen assumes it can find the global new and delete to call,
3447 // so ensure that they are declared.
3448 DeclareGlobalNewDelete();
3449
3450 FunctionDecl *OperatorNewOrDelete = nullptr;
3451 if (resolveBuiltinNewDeleteOverload(*this, TheCall, IsDelete,
3452 OperatorNewOrDelete))
3453 return ExprError();
3454 assert(OperatorNewOrDelete && "should be found")(static_cast <bool> (OperatorNewOrDelete && "should be found"
) ? void (0) : __assert_fail ("OperatorNewOrDelete && \"should be found\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3454, __extension__ __PRETTY_FUNCTION__))
;
3455
3456 TheCall->setType(OperatorNewOrDelete->getReturnType());
3457 for (unsigned i = 0; i != TheCall->getNumArgs(); ++i) {
3458 QualType ParamTy = OperatorNewOrDelete->getParamDecl(i)->getType();
3459 InitializedEntity Entity =
3460 InitializedEntity::InitializeParameter(Context, ParamTy, false);
3461 ExprResult Arg = PerformCopyInitialization(
3462 Entity, TheCall->getArg(i)->getLocStart(), TheCall->getArg(i));
3463 if (Arg.isInvalid())
3464 return ExprError();
3465 TheCall->setArg(i, Arg.get());
3466 }
3467 auto Callee = dyn_cast<ImplicitCastExpr>(TheCall->getCallee());
3468 assert(Callee && Callee->getCastKind() == CK_BuiltinFnToFnPtr &&(static_cast <bool> (Callee && Callee->getCastKind
() == CK_BuiltinFnToFnPtr && "Callee expected to be implicit cast to a builtin function pointer"
) ? void (0) : __assert_fail ("Callee && Callee->getCastKind() == CK_BuiltinFnToFnPtr && \"Callee expected to be implicit cast to a builtin function pointer\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3469, __extension__ __PRETTY_FUNCTION__))
3469 "Callee expected to be implicit cast to a builtin function pointer")(static_cast <bool> (Callee && Callee->getCastKind
() == CK_BuiltinFnToFnPtr && "Callee expected to be implicit cast to a builtin function pointer"
) ? void (0) : __assert_fail ("Callee && Callee->getCastKind() == CK_BuiltinFnToFnPtr && \"Callee expected to be implicit cast to a builtin function pointer\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3469, __extension__ __PRETTY_FUNCTION__))
;
3470 Callee->setType(OperatorNewOrDelete->getType());
3471
3472 return TheCallResult;
3473}
3474
3475void Sema::CheckVirtualDtorCall(CXXDestructorDecl *dtor, SourceLocation Loc,
3476 bool IsDelete, bool CallCanBeVirtual,
3477 bool WarnOnNonAbstractTypes,
3478 SourceLocation DtorLoc) {
3479 if (!dtor || dtor->isVirtual() || !CallCanBeVirtual || isUnevaluatedContext())
3480 return;
3481
3482 // C++ [expr.delete]p3:
3483 // In the first alternative (delete object), if the static type of the
3484 // object to be deleted is different from its dynamic type, the static
3485 // type shall be a base class of the dynamic type of the object to be
3486 // deleted and the static type shall have a virtual destructor or the
3487 // behavior is undefined.
3488 //
3489 const CXXRecordDecl *PointeeRD = dtor->getParent();
3490 // Note: a final class cannot be derived from, no issue there
3491 if (!PointeeRD->isPolymorphic() || PointeeRD->hasAttr<FinalAttr>())
3492 return;
3493
3494 // If the superclass is in a system header, there's nothing that can be done.
3495 // The `delete` (where we emit the warning) can be in a system header,
3496 // what matters for this warning is where the deleted type is defined.
3497 if (getSourceManager().isInSystemHeader(PointeeRD->getLocation()))
3498 return;
3499
3500 QualType ClassType = dtor->getThisType(Context)->getPointeeType();
3501 if (PointeeRD->isAbstract()) {
3502 // If the class is abstract, we warn by default, because we're
3503 // sure the code has undefined behavior.
3504 Diag(Loc, diag::warn_delete_abstract_non_virtual_dtor) << (IsDelete ? 0 : 1)
3505 << ClassType;
3506 } else if (WarnOnNonAbstractTypes) {
3507 // Otherwise, if this is not an array delete, it's a bit suspect,
3508 // but not necessarily wrong.
3509 Diag(Loc, diag::warn_delete_non_virtual_dtor) << (IsDelete ? 0 : 1)
3510 << ClassType;
3511 }
3512 if (!IsDelete) {
3513 std::string TypeStr;
3514 ClassType.getAsStringInternal(TypeStr, getPrintingPolicy());
3515 Diag(DtorLoc, diag::note_delete_non_virtual)
3516 << FixItHint::CreateInsertion(DtorLoc, TypeStr + "::");
3517 }
3518}
3519
3520Sema::ConditionResult Sema::ActOnConditionVariable(Decl *ConditionVar,
3521 SourceLocation StmtLoc,
3522 ConditionKind CK) {
3523 ExprResult E =
3524 CheckConditionVariable(cast<VarDecl>(ConditionVar), StmtLoc, CK);
3525 if (E.isInvalid())
3526 return ConditionError();
3527 return ConditionResult(*this, ConditionVar, MakeFullExpr(E.get(), StmtLoc),
3528 CK == ConditionKind::ConstexprIf);
3529}
3530
3531/// \brief Check the use of the given variable as a C++ condition in an if,
3532/// while, do-while, or switch statement.
3533ExprResult Sema::CheckConditionVariable(VarDecl *ConditionVar,
3534 SourceLocation StmtLoc,
3535 ConditionKind CK) {
3536 if (ConditionVar->isInvalidDecl())
3537 return ExprError();
3538
3539 QualType T = ConditionVar->getType();
3540
3541 // C++ [stmt.select]p2:
3542 // The declarator shall not specify a function or an array.
3543 if (T->isFunctionType())
3544 return ExprError(Diag(ConditionVar->getLocation(),
3545 diag::err_invalid_use_of_function_type)
3546 << ConditionVar->getSourceRange());
3547 else if (T->isArrayType())
3548 return ExprError(Diag(ConditionVar->getLocation(),
3549 diag::err_invalid_use_of_array_type)
3550 << ConditionVar->getSourceRange());
3551
3552 ExprResult Condition = DeclRefExpr::Create(
3553 Context, NestedNameSpecifierLoc(), SourceLocation(), ConditionVar,
3554 /*enclosing*/ false, ConditionVar->getLocation(),
3555 ConditionVar->getType().getNonReferenceType(), VK_LValue);
3556
3557 MarkDeclRefReferenced(cast<DeclRefExpr>(Condition.get()));
3558
3559 switch (CK) {
3560 case ConditionKind::Boolean:
3561 return CheckBooleanCondition(StmtLoc, Condition.get());
3562
3563 case ConditionKind::ConstexprIf:
3564 return CheckBooleanCondition(StmtLoc, Condition.get(), true);
3565
3566 case ConditionKind::Switch:
3567 return CheckSwitchCondition(StmtLoc, Condition.get());
3568 }
3569
3570 llvm_unreachable("unexpected condition kind")::llvm::llvm_unreachable_internal("unexpected condition kind"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3570)
;
3571}
3572
3573/// CheckCXXBooleanCondition - Returns true if a conversion to bool is invalid.
3574ExprResult Sema::CheckCXXBooleanCondition(Expr *CondExpr, bool IsConstexpr) {
3575 // C++ 6.4p4:
3576 // The value of a condition that is an initialized declaration in a statement
3577 // other than a switch statement is the value of the declared variable
3578 // implicitly converted to type bool. If that conversion is ill-formed, the
3579 // program is ill-formed.
3580 // The value of a condition that is an expression is the value of the
3581 // expression, implicitly converted to bool.
3582 //
3583 // FIXME: Return this value to the caller so they don't need to recompute it.
3584 llvm::APSInt Value(/*BitWidth*/1);
3585 return (IsConstexpr && !CondExpr->isValueDependent())
3586 ? CheckConvertedConstantExpression(CondExpr, Context.BoolTy, Value,
3587 CCEK_ConstexprIf)
3588 : PerformContextuallyConvertToBool(CondExpr);
3589}
3590
3591/// Helper function to determine whether this is the (deprecated) C++
3592/// conversion from a string literal to a pointer to non-const char or
3593/// non-const wchar_t (for narrow and wide string literals,
3594/// respectively).
3595bool
3596Sema::IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType) {
3597 // Look inside the implicit cast, if it exists.
3598 if (ImplicitCastExpr *Cast = dyn_cast<ImplicitCastExpr>(From))
3599 From = Cast->getSubExpr();
3600
3601 // A string literal (2.13.4) that is not a wide string literal can
3602 // be converted to an rvalue of type "pointer to char"; a wide
3603 // string literal can be converted to an rvalue of type "pointer
3604 // to wchar_t" (C++ 4.2p2).
3605 if (StringLiteral *StrLit = dyn_cast<StringLiteral>(From->IgnoreParens()))
3606 if (const PointerType *ToPtrType = ToType->getAs<PointerType>())
3607 if (const BuiltinType *ToPointeeType
3608 = ToPtrType->getPointeeType()->getAs<BuiltinType>()) {
3609 // This conversion is considered only when there is an
3610 // explicit appropriate pointer target type (C++ 4.2p2).
3611 if (!ToPtrType->getPointeeType().hasQualifiers()) {
3612 switch (StrLit->getKind()) {
3613 case StringLiteral::UTF8:
3614 case StringLiteral::UTF16:
3615 case StringLiteral::UTF32:
3616 // We don't allow UTF literals to be implicitly converted
3617 break;
3618 case StringLiteral::Ascii:
3619 return (ToPointeeType->getKind() == BuiltinType::Char_U ||
3620 ToPointeeType->getKind() == BuiltinType::Char_S);
3621 case StringLiteral::Wide:
3622 return Context.typesAreCompatible(Context.getWideCharType(),
3623 QualType(ToPointeeType, 0));
3624 }
3625 }
3626 }
3627
3628 return false;
3629}
3630
3631static ExprResult BuildCXXCastArgument(Sema &S,
3632 SourceLocation CastLoc,
3633 QualType Ty,
3634 CastKind Kind,
3635 CXXMethodDecl *Method,
3636 DeclAccessPair FoundDecl,
3637 bool HadMultipleCandidates,
3638 Expr *From) {
3639 switch (Kind) {
3640 default: llvm_unreachable("Unhandled cast kind!")::llvm::llvm_unreachable_internal("Unhandled cast kind!", "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3640)
;
3641 case CK_ConstructorConversion: {
3642 CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(Method);
3643 SmallVector<Expr*, 8> ConstructorArgs;
3644
3645 if (S.RequireNonAbstractType(CastLoc, Ty,
3646 diag::err_allocation_of_abstract_type))
3647 return ExprError();
3648
3649 if (S.CompleteConstructorCall(Constructor, From, CastLoc, ConstructorArgs))
3650 return ExprError();
3651
3652 S.CheckConstructorAccess(CastLoc, Constructor, FoundDecl,
3653 InitializedEntity::InitializeTemporary(Ty));
3654 if (S.DiagnoseUseOfDecl(Method, CastLoc))
3655 return ExprError();
3656
3657 ExprResult Result = S.BuildCXXConstructExpr(
3658 CastLoc, Ty, FoundDecl, cast<CXXConstructorDecl>(Method),
3659 ConstructorArgs, HadMultipleCandidates,
3660 /*ListInit*/ false, /*StdInitListInit*/ false, /*ZeroInit*/ false,
3661 CXXConstructExpr::CK_Complete, SourceRange());
3662 if (Result.isInvalid())
3663 return ExprError();
3664
3665 return S.MaybeBindToTemporary(Result.getAs<Expr>());
3666 }
3667
3668 case CK_UserDefinedConversion: {
3669 assert(!From->getType()->isPointerType() && "Arg can't have pointer type!")(static_cast <bool> (!From->getType()->isPointerType
() && "Arg can't have pointer type!") ? void (0) : __assert_fail
("!From->getType()->isPointerType() && \"Arg can't have pointer type!\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3669, __extension__ __PRETTY_FUNCTION__))
;
3670
3671 S.CheckMemberOperatorAccess(CastLoc, From, /*arg*/ nullptr, FoundDecl);
3672 if (S.DiagnoseUseOfDecl(Method, CastLoc))
3673 return ExprError();
3674
3675 // Create an implicit call expr that calls it.
3676 CXXConversionDecl *Conv = cast<CXXConversionDecl>(Method);
3677 ExprResult Result = S.BuildCXXMemberCallExpr(From, FoundDecl, Conv,
3678 HadMultipleCandidates);
3679 if (Result.isInvalid())
3680 return ExprError();
3681 // Record usage of conversion in an implicit cast.
3682 Result = ImplicitCastExpr::Create(S.Context, Result.get()->getType(),
3683 CK_UserDefinedConversion, Result.get(),
3684 nullptr, Result.get()->getValueKind());
3685
3686 return S.MaybeBindToTemporary(Result.get());
3687 }
3688 }
3689}
3690
3691/// PerformImplicitConversion - Perform an implicit conversion of the
3692/// expression From to the type ToType using the pre-computed implicit
3693/// conversion sequence ICS. Returns the converted
3694/// expression. Action is the kind of conversion we're performing,
3695/// used in the error message.
3696ExprResult
3697Sema::PerformImplicitConversion(Expr *From, QualType ToType,
3698 const ImplicitConversionSequence &ICS,
3699 AssignmentAction Action,
3700 CheckedConversionKind CCK) {
3701 switch (ICS.getKind()) {
3702 case ImplicitConversionSequence::StandardConversion: {
3703 ExprResult Res = PerformImplicitConversion(From, ToType, ICS.Standard,
3704 Action, CCK);
3705 if (Res.isInvalid())
3706 return ExprError();
3707 From = Res.get();
3708 break;
3709 }
3710
3711 case ImplicitConversionSequence::UserDefinedConversion: {
3712
3713 FunctionDecl *FD = ICS.UserDefined.ConversionFunction;
3714 CastKind CastKind;
3715 QualType BeforeToType;
3716 assert(FD && "no conversion function for user-defined conversion seq")(static_cast <bool> (FD && "no conversion function for user-defined conversion seq"
) ? void (0) : __assert_fail ("FD && \"no conversion function for user-defined conversion seq\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3716, __extension__ __PRETTY_FUNCTION__))
;
3717 if (const CXXConversionDecl *Conv = dyn_cast<CXXConversionDecl>(FD)) {
3718 CastKind = CK_UserDefinedConversion;
3719
3720 // If the user-defined conversion is specified by a conversion function,
3721 // the initial standard conversion sequence converts the source type to
3722 // the implicit object parameter of the conversion function.
3723 BeforeToType = Context.getTagDeclType(Conv->getParent());
3724 } else {
3725 const CXXConstructorDecl *Ctor = cast<CXXConstructorDecl>(FD);
3726 CastKind = CK_ConstructorConversion;
3727 // Do no conversion if dealing with ... for the first conversion.
3728 if (!ICS.UserDefined.EllipsisConversion) {
3729 // If the user-defined conversion is specified by a constructor, the
3730 // initial standard conversion sequence converts the source type to
3731 // the type required by the argument of the constructor
3732 BeforeToType = Ctor->getParamDecl(0)->getType().getNonReferenceType();
3733 }
3734 }
3735 // Watch out for ellipsis conversion.
3736 if (!ICS.UserDefined.EllipsisConversion) {
3737 ExprResult Res =
3738 PerformImplicitConversion(From, BeforeToType,
3739 ICS.UserDefined.Before, AA_Converting,
3740 CCK);
3741 if (Res.isInvalid())
3742 return ExprError();
3743 From = Res.get();
3744 }
3745
3746 ExprResult CastArg
3747 = BuildCXXCastArgument(*this,
3748 From->getLocStart(),
3749 ToType.getNonReferenceType(),
3750 CastKind, cast<CXXMethodDecl>(FD),
3751 ICS.UserDefined.FoundConversionFunction,
3752 ICS.UserDefined.HadMultipleCandidates,
3753 From);
3754
3755 if (CastArg.isInvalid())
3756 return ExprError();
3757
3758 From = CastArg.get();
3759
3760 return PerformImplicitConversion(From, ToType, ICS.UserDefined.After,
3761 AA_Converting, CCK);
3762 }
3763
3764 case ImplicitConversionSequence::AmbiguousConversion:
3765 ICS.DiagnoseAmbiguousConversion(*this, From->getExprLoc(),
3766 PDiag(diag::err_typecheck_ambiguous_condition)
3767 << From->getSourceRange());
3768 return ExprError();
3769
3770 case ImplicitConversionSequence::EllipsisConversion:
3771 llvm_unreachable("Cannot perform an ellipsis conversion")::llvm::llvm_unreachable_internal("Cannot perform an ellipsis conversion"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3771)
;
3772
3773 case ImplicitConversionSequence::BadConversion:
3774 bool Diagnosed =
3775 DiagnoseAssignmentResult(Incompatible, From->getExprLoc(), ToType,
3776 From->getType(), From, Action);
3777 assert(Diagnosed && "failed to diagnose bad conversion")(static_cast <bool> (Diagnosed && "failed to diagnose bad conversion"
) ? void (0) : __assert_fail ("Diagnosed && \"failed to diagnose bad conversion\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3777, __extension__ __PRETTY_FUNCTION__))
; (void)Diagnosed;
3778 return ExprError();
3779 }
3780
3781 // Everything went well.
3782 return From;
3783}
3784
3785/// PerformImplicitConversion - Perform an implicit conversion of the
3786/// expression From to the type ToType by following the standard
3787/// conversion sequence SCS. Returns the converted
3788/// expression. Flavor is the context in which we're performing this
3789/// conversion, for use in error messages.
3790ExprResult
3791Sema::PerformImplicitConversion(Expr *From, QualType ToType,
3792 const StandardConversionSequence& SCS,
3793 AssignmentAction Action,
3794 CheckedConversionKind CCK) {
3795 bool CStyle = (CCK == CCK_CStyleCast || CCK == CCK_FunctionalCast);
3796
3797 // Overall FIXME: we are recomputing too many types here and doing far too
3798 // much extra work. What this means is that we need to keep track of more
3799 // information that is computed when we try the implicit conversion initially,
3800 // so that we don't need to recompute anything here.
3801 QualType FromType = From->getType();
3802
3803 if (SCS.CopyConstructor) {
3804 // FIXME: When can ToType be a reference type?
3805 assert(!ToType->isReferenceType())(static_cast <bool> (!ToType->isReferenceType()) ? void
(0) : __assert_fail ("!ToType->isReferenceType()", "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3805, __extension__ __PRETTY_FUNCTION__))
;
3806 if (SCS.Second == ICK_Derived_To_Base) {
3807 SmallVector<Expr*, 8> ConstructorArgs;
3808 if (CompleteConstructorCall(cast<CXXConstructorDecl>(SCS.CopyConstructor),
3809 From, /*FIXME:ConstructLoc*/SourceLocation(),
3810 ConstructorArgs))
3811 return ExprError();
3812 return BuildCXXConstructExpr(
3813 /*FIXME:ConstructLoc*/ SourceLocation(), ToType,
3814 SCS.FoundCopyConstructor, SCS.CopyConstructor,
3815 ConstructorArgs, /*HadMultipleCandidates*/ false,
3816 /*ListInit*/ false, /*StdInitListInit*/ false, /*ZeroInit*/ false,
3817 CXXConstructExpr::CK_Complete, SourceRange());
3818 }
3819 return BuildCXXConstructExpr(
3820 /*FIXME:ConstructLoc*/ SourceLocation(), ToType,
3821 SCS.FoundCopyConstructor, SCS.CopyConstructor,
3822 From, /*HadMultipleCandidates*/ false,
3823 /*ListInit*/ false, /*StdInitListInit*/ false, /*ZeroInit*/ false,
3824 CXXConstructExpr::CK_Complete, SourceRange());
3825 }
3826
3827 // Resolve overloaded function references.
3828 if (Context.hasSameType(FromType, Context.OverloadTy)) {
3829 DeclAccessPair Found;
3830 FunctionDecl *Fn = ResolveAddressOfOverloadedFunction(From, ToType,
3831 true, Found);
3832 if (!Fn)
3833 return ExprError();
3834
3835 if (DiagnoseUseOfDecl(Fn, From->getLocStart()))
3836 return ExprError();
3837
3838 From = FixOverloadedFunctionReference(From, Found, Fn);
3839 FromType = From->getType();
3840 }
3841
3842 // If we're converting to an atomic type, first convert to the corresponding
3843 // non-atomic type.
3844 QualType ToAtomicType;
3845 if (const AtomicType *ToAtomic = ToType->getAs<AtomicType>()) {
3846 ToAtomicType = ToType;
3847 ToType = ToAtomic->getValueType();
3848 }
3849
3850 QualType InitialFromType = FromType;
3851 // Perform the first implicit conversion.
3852 switch (SCS.First) {
3853 case ICK_Identity:
3854 if (const AtomicType *FromAtomic = FromType->getAs<AtomicType>()) {
3855 FromType = FromAtomic->getValueType().getUnqualifiedType();
3856 From = ImplicitCastExpr::Create(Context, FromType, CK_AtomicToNonAtomic,
3857 From, /*BasePath=*/nullptr, VK_RValue);
3858 }
3859 break;
3860
3861 case ICK_Lvalue_To_Rvalue: {
3862 assert(From->getObjectKind() != OK_ObjCProperty)(static_cast <bool> (From->getObjectKind() != OK_ObjCProperty
) ? void (0) : __assert_fail ("From->getObjectKind() != OK_ObjCProperty"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3862, __extension__ __PRETTY_FUNCTION__))
;
3863 ExprResult FromRes = DefaultLvalueConversion(From);
3864 assert(!FromRes.isInvalid() && "Can't perform deduced conversion?!")(static_cast <bool> (!FromRes.isInvalid() && "Can't perform deduced conversion?!"
) ? void (0) : __assert_fail ("!FromRes.isInvalid() && \"Can't perform deduced conversion?!\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3864, __extension__ __PRETTY_FUNCTION__))
;
3865 From = FromRes.get();
3866 FromType = From->getType();
3867 break;
3868 }
3869
3870 case ICK_Array_To_Pointer:
3871 FromType = Context.getArrayDecayedType(FromType);
3872 From = ImpCastExprToType(From, FromType, CK_ArrayToPointerDecay,
3873 VK_RValue, /*BasePath=*/nullptr, CCK).get();
3874 break;
3875
3876 case ICK_Function_To_Pointer:
3877 FromType = Context.getPointerType(FromType);
3878 From = ImpCastExprToType(From, FromType, CK_FunctionToPointerDecay,
3879 VK_RValue, /*BasePath=*/nullptr, CCK).get();
3880 break;
3881
3882 default:
3883 llvm_unreachable("Improper first standard conversion")::llvm::llvm_unreachable_internal("Improper first standard conversion"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3883)
;
3884 }
3885
3886 // Perform the second implicit conversion
3887 switch (SCS.Second) {
3888 case ICK_Identity:
3889 // C++ [except.spec]p5:
3890 // [For] assignment to and initialization of pointers to functions,
3891 // pointers to member functions, and references to functions: the
3892 // target entity shall allow at least the exceptions allowed by the
3893 // source value in the assignment or initialization.
3894 switch (Action) {
3895 case AA_Assigning:
3896 case AA_Initializing:
3897 // Note, function argument passing and returning are initialization.
3898 case AA_Passing:
3899 case AA_Returning:
3900 case AA_Sending:
3901 case AA_Passing_CFAudited:
3902 if (CheckExceptionSpecCompatibility(From, ToType))
3903 return ExprError();
3904 break;
3905
3906 case AA_Casting:
3907 case AA_Converting:
3908 // Casts and implicit conversions are not initialization, so are not
3909 // checked for exception specification mismatches.
3910 break;
3911 }
3912 // Nothing else to do.
3913 break;
3914
3915 case ICK_Integral_Promotion:
3916 case ICK_Integral_Conversion:
3917 if (ToType->isBooleanType()) {
3918 assert(FromType->castAs<EnumType>()->getDecl()->isFixed() &&(static_cast <bool> (FromType->castAs<EnumType>
()->getDecl()->isFixed() && SCS.Second == ICK_Integral_Promotion
&& "only enums with fixed underlying type can promote to bool"
) ? void (0) : __assert_fail ("FromType->castAs<EnumType>()->getDecl()->isFixed() && SCS.Second == ICK_Integral_Promotion && \"only enums with fixed underlying type can promote to bool\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3920, __extension__ __PRETTY_FUNCTION__))
3919 SCS.Second == ICK_Integral_Promotion &&(static_cast <bool> (FromType->castAs<EnumType>
()->getDecl()->isFixed() && SCS.Second == ICK_Integral_Promotion
&& "only enums with fixed underlying type can promote to bool"
) ? void (0) : __assert_fail ("FromType->castAs<EnumType>()->getDecl()->isFixed() && SCS.Second == ICK_Integral_Promotion && \"only enums with fixed underlying type can promote to bool\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3920, __extension__ __PRETTY_FUNCTION__))
3920 "only enums with fixed underlying type can promote to bool")(static_cast <bool> (FromType->castAs<EnumType>
()->getDecl()->isFixed() && SCS.Second == ICK_Integral_Promotion
&& "only enums with fixed underlying type can promote to bool"
) ? void (0) : __assert_fail ("FromType->castAs<EnumType>()->getDecl()->isFixed() && SCS.Second == ICK_Integral_Promotion && \"only enums with fixed underlying type can promote to bool\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 3920, __extension__ __PRETTY_FUNCTION__))
;
3921 From = ImpCastExprToType(From, ToType, CK_IntegralToBoolean,
3922 VK_RValue, /*BasePath=*/nullptr, CCK).get();
3923 } else {
3924 From = ImpCastExprToType(From, ToType, CK_IntegralCast,
3925 VK_RValue, /*BasePath=*/nullptr, CCK).get();
3926 }
3927 break;
3928
3929 case ICK_Floating_Promotion:
3930 case ICK_Floating_Conversion:
3931 From = ImpCastExprToType(From, ToType, CK_FloatingCast,
3932 VK_RValue, /*BasePath=*/nullptr, CCK).get();
3933 break;
3934
3935 case ICK_Complex_Promotion:
3936 case ICK_Complex_Conversion: {
3937 QualType FromEl = From->getType()->getAs<ComplexType>()->getElementType();
3938 QualType ToEl = ToType->getAs<ComplexType>()->getElementType();
3939 CastKind CK;
3940 if (FromEl->isRealFloatingType()) {
3941 if (ToEl->isRealFloatingType())
3942 CK = CK_FloatingComplexCast;
3943 else
3944 CK = CK_FloatingComplexToIntegralComplex;
3945 } else if (ToEl->isRealFloatingType()) {
3946 CK = CK_IntegralComplexToFloatingComplex;
3947 } else {
3948 CK = CK_IntegralComplexCast;
3949 }
3950 From = ImpCastExprToType(From, ToType, CK,
3951 VK_RValue, /*BasePath=*/nullptr, CCK).get();
3952 break;
3953 }
3954
3955 case ICK_Floating_Integral:
3956 if (ToType->isRealFloatingType())
3957 From = ImpCastExprToType(From, ToType, CK_IntegralToFloating,
3958 VK_RValue, /*BasePath=*/nullptr, CCK).get();
3959 else
3960 From = ImpCastExprToType(From, ToType, CK_FloatingToIntegral,
3961 VK_RValue, /*BasePath=*/nullptr, CCK).get();
3962 break;
3963
3964 case ICK_Compatible_Conversion:
3965 From = ImpCastExprToType(From, ToType, CK_NoOp,
3966 VK_RValue, /*BasePath=*/nullptr, CCK).get();
3967 break;
3968
3969 case ICK_Writeback_Conversion:
3970 case ICK_Pointer_Conversion: {
3971 if (SCS.IncompatibleObjC && Action != AA_Casting) {
3972 // Diagnose incompatible Objective-C conversions
3973 if (Action == AA_Initializing || Action == AA_Assigning)
3974 Diag(From->getLocStart(),
3975 diag::ext_typecheck_convert_incompatible_pointer)
3976 << ToType << From->getType() << Action
3977 << From->getSourceRange() << 0;
3978 else
3979 Diag(From->getLocStart(),
3980 diag::ext_typecheck_convert_incompatible_pointer)
3981 << From->getType() << ToType << Action
3982 << From->getSourceRange() << 0;
3983
3984 if (From->getType()->isObjCObjectPointerType() &&
3985 ToType->isObjCObjectPointerType())
3986 EmitRelatedResultTypeNote(From);
3987 } else if (getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&
3988 !CheckObjCARCUnavailableWeakConversion(ToType,
3989 From->getType())) {
3990 if (Action == AA_Initializing)
3991 Diag(From->getLocStart(),
3992 diag::err_arc_weak_unavailable_assign);
3993 else
3994 Diag(From->getLocStart(),
3995 diag::err_arc_convesion_of_weak_unavailable)
3996 << (Action == AA_Casting) << From->getType() << ToType
3997 << From->getSourceRange();
3998 }
3999
4000 CastKind Kind;
4001 CXXCastPath BasePath;
4002 if (CheckPointerConversion(From, ToType, Kind, BasePath, CStyle))
4003 return ExprError();
4004
4005 // Make sure we extend blocks if necessary.
4006 // FIXME: doing this here is really ugly.
4007 if (Kind == CK_BlockPointerToObjCPointerCast) {
4008 ExprResult E = From;
4009 (void) PrepareCastToObjCObjectPointer(E);
4010 From = E.get();
4011 }
4012 if (getLangOpts().allowsNonTrivialObjCLifetimeQualifiers())
4013 CheckObjCConversion(SourceRange(), ToType, From, CCK);
4014 From = ImpCastExprToType(From, ToType, Kind, VK_RValue, &BasePath, CCK)
4015 .get();
4016 break;
4017 }
4018
4019 case ICK_Pointer_Member: {
4020 CastKind Kind;
4021 CXXCastPath BasePath;
4022 if (CheckMemberPointerConversion(From, ToType, Kind, BasePath, CStyle))
4023 return ExprError();
4024 if (CheckExceptionSpecCompatibility(From, ToType))
4025 return ExprError();
4026
4027 // We may not have been able to figure out what this member pointer resolved
4028 // to up until this exact point. Attempt to lock-in it's inheritance model.
4029 if (Context.getTargetInfo().getCXXABI().isMicrosoft()) {
4030 (void)isCompleteType(From->getExprLoc(), From->getType());
4031 (void)isCompleteType(From->getExprLoc(), ToType);
4032 }
4033
4034 From = ImpCastExprToType(From, ToType, Kind, VK_RValue, &BasePath, CCK)
4035 .get();
4036 break;
4037 }
4038
4039 case ICK_Boolean_Conversion:
4040 // Perform half-to-boolean conversion via float.
4041 if (From->getType()->isHalfType()) {
4042 From = ImpCastExprToType(From, Context.FloatTy, CK_FloatingCast).get();
4043 FromType = Context.FloatTy;
4044 }
4045
4046 From = ImpCastExprToType(From, Context.BoolTy,
4047 ScalarTypeToBooleanCastKind(FromType),
4048 VK_RValue, /*BasePath=*/nullptr, CCK).get();
4049 break;
4050
4051 case ICK_Derived_To_Base: {
4052 CXXCastPath BasePath;
4053 if (CheckDerivedToBaseConversion(From->getType(),
4054 ToType.getNonReferenceType(),
4055 From->getLocStart(),
4056 From->getSourceRange(),
4057 &BasePath,
4058 CStyle))
4059 return ExprError();
4060
4061 From = ImpCastExprToType(From, ToType.getNonReferenceType(),
4062 CK_DerivedToBase, From->getValueKind(),
4063 &BasePath, CCK).get();
4064 break;
4065 }
4066
4067 case ICK_Vector_Conversion:
4068 From = ImpCastExprToType(From, ToType, CK_BitCast,
4069 VK_RValue, /*BasePath=*/nullptr, CCK).get();
4070 break;
4071
4072 case ICK_Vector_Splat: {
4073 // Vector splat from any arithmetic type to a vector.
4074 Expr *Elem = prepareVectorSplat(ToType, From).get();
4075 From = ImpCastExprToType(Elem, ToType, CK_VectorSplat, VK_RValue,
4076 /*BasePath=*/nullptr, CCK).get();
4077 break;
4078 }
4079
4080 case ICK_Complex_Real:
4081 // Case 1. x -> _Complex y
4082 if (const ComplexType *ToComplex = ToType->getAs<ComplexType>()) {
4083 QualType ElType = ToComplex->getElementType();
4084 bool isFloatingComplex = ElType->isRealFloatingType();
4085
4086 // x -> y
4087 if (Context.hasSameUnqualifiedType(ElType, From->getType())) {
4088 // do nothing
4089 } else if (From->getType()->isRealFloatingType()) {
4090 From = ImpCastExprToType(From, ElType,
4091 isFloatingComplex ? CK_FloatingCast : CK_FloatingToIntegral).get();
4092 } else {
4093 assert(From->getType()->isIntegerType())(static_cast <bool> (From->getType()->isIntegerType
()) ? void (0) : __assert_fail ("From->getType()->isIntegerType()"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4093, __extension__ __PRETTY_FUNCTION__))
;
4094 From = ImpCastExprToType(From, ElType,
4095 isFloatingComplex ? CK_IntegralToFloating : CK_IntegralCast).get();
4096 }
4097 // y -> _Complex y
4098 From = ImpCastExprToType(From, ToType,
4099 isFloatingComplex ? CK_FloatingRealToComplex
4100 : CK_IntegralRealToComplex).get();
4101
4102 // Case 2. _Complex x -> y
4103 } else {
4104 const ComplexType *FromComplex = From->getType()->getAs<ComplexType>();
4105 assert(FromComplex)(static_cast <bool> (FromComplex) ? void (0) : __assert_fail
("FromComplex", "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4105, __extension__ __PRETTY_FUNCTION__))
;
4106
4107 QualType ElType = FromComplex->getElementType();
4108 bool isFloatingComplex = ElType->isRealFloatingType();
4109
4110 // _Complex x -> x
4111 From = ImpCastExprToType(From, ElType,
4112 isFloatingComplex ? CK_FloatingComplexToReal
4113 : CK_IntegralComplexToReal,
4114 VK_RValue, /*BasePath=*/nullptr, CCK).get();
4115
4116 // x -> y
4117 if (Context.hasSameUnqualifiedType(ElType, ToType)) {
4118 // do nothing
4119 } else if (ToType->isRealFloatingType()) {
4120 From = ImpCastExprToType(From, ToType,
4121 isFloatingComplex ? CK_FloatingCast : CK_IntegralToFloating,
4122 VK_RValue, /*BasePath=*/nullptr, CCK).get();
4123 } else {
4124 assert(ToType->isIntegerType())(static_cast <bool> (ToType->isIntegerType()) ? void
(0) : __assert_fail ("ToType->isIntegerType()", "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4124, __extension__ __PRETTY_FUNCTION__))
;
4125 From = ImpCastExprToType(From, ToType,
4126 isFloatingComplex ? CK_FloatingToIntegral : CK_IntegralCast,
4127 VK_RValue, /*BasePath=*/nullptr, CCK).get();
4128 }
4129 }
4130 break;
4131
4132 case ICK_Block_Pointer_Conversion: {
4133 From = ImpCastExprToType(From, ToType.getUnqualifiedType(), CK_BitCast,
4134 VK_RValue, /*BasePath=*/nullptr, CCK).get();
4135 break;
4136 }
4137
4138 case ICK_TransparentUnionConversion: {
4139 ExprResult FromRes = From;
4140 Sema::AssignConvertType ConvTy =
4141 CheckTransparentUnionArgumentConstraints(ToType, FromRes);
4142 if (FromRes.isInvalid())
4143 return ExprError();
4144 From = FromRes.get();
4145 assert ((ConvTy == Sema::Compatible) &&(static_cast <bool> ((ConvTy == Sema::Compatible) &&
"Improper transparent union conversion") ? void (0) : __assert_fail
("(ConvTy == Sema::Compatible) && \"Improper transparent union conversion\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4146, __extension__ __PRETTY_FUNCTION__))
4146 "Improper transparent union conversion")(static_cast <bool> ((ConvTy == Sema::Compatible) &&
"Improper transparent union conversion") ? void (0) : __assert_fail
("(ConvTy == Sema::Compatible) && \"Improper transparent union conversion\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4146, __extension__ __PRETTY_FUNCTION__))
;
4147 (void)ConvTy;
4148 break;
4149 }
4150
4151 case ICK_Zero_Event_Conversion:
4152 From = ImpCastExprToType(From, ToType,
4153 CK_ZeroToOCLEvent,
4154 From->getValueKind()).get();
4155 break;
4156
4157 case ICK_Zero_Queue_Conversion:
4158 From = ImpCastExprToType(From, ToType,
4159 CK_ZeroToOCLQueue,
4160 From->getValueKind()).get();
4161 break;
4162
4163 case ICK_Lvalue_To_Rvalue:
4164 case ICK_Array_To_Pointer:
4165 case ICK_Function_To_Pointer:
4166 case ICK_Function_Conversion:
4167 case ICK_Qualification:
4168 case ICK_Num_Conversion_Kinds:
4169 case ICK_C_Only_Conversion:
4170 case ICK_Incompatible_Pointer_Conversion:
4171 llvm_unreachable("Improper second standard conversion")::llvm::llvm_unreachable_internal("Improper second standard conversion"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4171)
;
4172 }
4173
4174 switch (SCS.Third) {
4175 case ICK_Identity:
4176 // Nothing to do.
4177 break;
4178
4179 case ICK_Function_Conversion:
4180 // If both sides are functions (or pointers/references to them), there could
4181 // be incompatible exception declarations.
4182 if (CheckExceptionSpecCompatibility(From, ToType))
4183 return ExprError();
4184
4185 From = ImpCastExprToType(From, ToType, CK_NoOp,
4186 VK_RValue, /*BasePath=*/nullptr, CCK).get();
4187 break;
4188
4189 case ICK_Qualification: {
4190 // The qualification keeps the category of the inner expression, unless the
4191 // target type isn't a reference.
4192 ExprValueKind VK = ToType->isReferenceType() ?
4193 From->getValueKind() : VK_RValue;
4194 From = ImpCastExprToType(From, ToType.getNonLValueExprType(Context),
4195 CK_NoOp, VK, /*BasePath=*/nullptr, CCK).get();
4196
4197 if (SCS.DeprecatedStringLiteralToCharPtr &&
4198 !getLangOpts().WritableStrings) {
4199 Diag(From->getLocStart(), getLangOpts().CPlusPlus11
4200 ? diag::ext_deprecated_string_literal_conversion
4201 : diag::warn_deprecated_string_literal_conversion)
4202 << ToType.getNonReferenceType();
4203 }
4204
4205 break;
4206 }
4207
4208 default:
4209 llvm_unreachable("Improper third standard conversion")::llvm::llvm_unreachable_internal("Improper third standard conversion"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4209)
;
4210 }
4211
4212 // If this conversion sequence involved a scalar -> atomic conversion, perform
4213 // that conversion now.
4214 if (!ToAtomicType.isNull()) {
4215 assert(Context.hasSameType((static_cast <bool> (Context.hasSameType( ToAtomicType->
castAs<AtomicType>()->getValueType(), From->getType
())) ? void (0) : __assert_fail ("Context.hasSameType( ToAtomicType->castAs<AtomicType>()->getValueType(), From->getType())"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4216, __extension__ __PRETTY_FUNCTION__))
4216 ToAtomicType->castAs<AtomicType>()->getValueType(), From->getType()))(static_cast <bool> (Context.hasSameType( ToAtomicType->
castAs<AtomicType>()->getValueType(), From->getType
())) ? void (0) : __assert_fail ("Context.hasSameType( ToAtomicType->castAs<AtomicType>()->getValueType(), From->getType())"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4216, __extension__ __PRETTY_FUNCTION__))
;
4217 From = ImpCastExprToType(From, ToAtomicType, CK_NonAtomicToAtomic,
4218 VK_RValue, nullptr, CCK).get();
4219 }
4220
4221 // If this conversion sequence succeeded and involved implicitly converting a
4222 // _Nullable type to a _Nonnull one, complain.
4223 if (CCK == CCK_ImplicitConversion)
4224 diagnoseNullableToNonnullConversion(ToType, InitialFromType,
4225 From->getLocStart());
4226
4227 return From;
4228}
4229
4230/// \brief Check the completeness of a type in a unary type trait.
4231///
4232/// If the particular type trait requires a complete type, tries to complete
4233/// it. If completing the type fails, a diagnostic is emitted and false
4234/// returned. If completing the type succeeds or no completion was required,
4235/// returns true.
4236static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, TypeTrait UTT,
4237 SourceLocation Loc,
4238 QualType ArgTy) {
4239 // C++0x [meta.unary.prop]p3:
4240 // For all of the class templates X declared in this Clause, instantiating
4241 // that template with a template argument that is a class template
4242 // specialization may result in the implicit instantiation of the template
4243 // argument if and only if the semantics of X require that the argument
4244 // must be a complete type.
4245 // We apply this rule to all the type trait expressions used to implement
4246 // these class templates. We also try to follow any GCC documented behavior
4247 // in these expressions to ensure portability of standard libraries.
4248 switch (UTT) {
4249 default: llvm_unreachable("not a UTT")::llvm::llvm_unreachable_internal("not a UTT", "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4249)
;
4250 // is_complete_type somewhat obviously cannot require a complete type.
4251 case UTT_IsCompleteType:
4252 // Fall-through
4253
4254 // These traits are modeled on the type predicates in C++0x
4255 // [meta.unary.cat] and [meta.unary.comp]. They are not specified as
4256 // requiring a complete type, as whether or not they return true cannot be
4257 // impacted by the completeness of the type.
4258 case UTT_IsVoid:
4259 case UTT_IsIntegral:
4260 case UTT_IsFloatingPoint:
4261 case UTT_IsArray:
4262 case UTT_IsPointer:
4263 case UTT_IsLvalueReference:
4264 case UTT_IsRvalueReference:
4265 case UTT_IsMemberFunctionPointer:
4266 case UTT_IsMemberObjectPointer:
4267 case UTT_IsEnum:
4268 case UTT_IsUnion:
4269 case UTT_IsClass:
4270 case UTT_IsFunction:
4271 case UTT_IsReference:
4272 case UTT_IsArithmetic:
4273 case UTT_IsFundamental:
4274 case UTT_IsObject:
4275 case UTT_IsScalar:
4276 case UTT_IsCompound:
4277 case UTT_IsMemberPointer:
4278 // Fall-through
4279
4280 // These traits are modeled on type predicates in C++0x [meta.unary.prop]
4281 // which requires some of its traits to have the complete type. However,
4282 // the completeness of the type cannot impact these traits' semantics, and
4283 // so they don't require it. This matches the comments on these traits in
4284 // Table 49.
4285 case UTT_IsConst:
4286 case UTT_IsVolatile:
4287 case UTT_IsSigned:
4288 case UTT_IsUnsigned:
4289
4290 // This type trait always returns false, checking the type is moot.
4291 case UTT_IsInterfaceClass:
4292 return true;
4293
4294 // C++14 [meta.unary.prop]:
4295 // If T is a non-union class type, T shall be a complete type.
4296 case UTT_IsEmpty:
4297 case UTT_IsPolymorphic:
4298 case UTT_IsAbstract:
4299 if (const auto *RD = ArgTy->getAsCXXRecordDecl())
4300 if (!RD->isUnion())
4301 return !S.RequireCompleteType(
4302 Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
4303 return true;
4304
4305 // C++14 [meta.unary.prop]:
4306 // If T is a class type, T shall be a complete type.
4307 case UTT_IsFinal:
4308 case UTT_IsSealed:
4309 if (ArgTy->getAsCXXRecordDecl())
4310 return !S.RequireCompleteType(
4311 Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
4312 return true;
4313
4314 // C++1z [meta.unary.prop]:
4315 // remove_all_extents_t<T> shall be a complete type or cv void.
4316 case UTT_IsAggregate:
4317 case UTT_IsTrivial:
4318 case UTT_IsTriviallyCopyable:
4319 case UTT_IsStandardLayout:
4320 case UTT_IsPOD:
4321 case UTT_IsLiteral:
4322 // Per the GCC type traits documentation, T shall be a complete type, cv void,
4323 // or an array of unknown bound. But GCC actually imposes the same constraints
4324 // as above.
4325 case UTT_HasNothrowAssign:
4326 case UTT_HasNothrowMoveAssign:
4327 case UTT_HasNothrowConstructor:
4328 case UTT_HasNothrowCopy:
4329 case UTT_HasTrivialAssign:
4330 case UTT_HasTrivialMoveAssign:
4331 case UTT_HasTrivialDefaultConstructor:
4332 case UTT_HasTrivialMoveConstructor:
4333 case UTT_HasTrivialCopy:
4334 case UTT_HasTrivialDestructor:
4335 case UTT_HasVirtualDestructor:
4336 ArgTy = QualType(ArgTy->getBaseElementTypeUnsafe(), 0);
4337 LLVM_FALLTHROUGH[[clang::fallthrough]];
4338
4339 // C++1z [meta.unary.prop]:
4340 // T shall be a complete type, cv void, or an array of unknown bound.
4341 case UTT_IsDestructible:
4342 case UTT_IsNothrowDestructible:
4343 case UTT_IsTriviallyDestructible:
4344 case UTT_HasUniqueObjectRepresentations:
4345 if (ArgTy->isIncompleteArrayType() || ArgTy->isVoidType())
4346 return true;
4347
4348 return !S.RequireCompleteType(
4349 Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
4350 }
4351}
4352
4353static bool HasNoThrowOperator(const RecordType *RT, OverloadedOperatorKind Op,
4354 Sema &Self, SourceLocation KeyLoc, ASTContext &C,
4355 bool (CXXRecordDecl::*HasTrivial)() const,
4356 bool (CXXRecordDecl::*HasNonTrivial)() const,
4357 bool (CXXMethodDecl::*IsDesiredOp)() const)
4358{
4359 CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
4360 if ((RD->*HasTrivial)() && !(RD->*HasNonTrivial)())
4361 return true;
4362
4363 DeclarationName Name = C.DeclarationNames.getCXXOperatorName(Op);
4364 DeclarationNameInfo NameInfo(Name, KeyLoc);
4365 LookupResult Res(Self, NameInfo, Sema::LookupOrdinaryName);
4366 if (Self.LookupQualifiedName(Res, RD)) {
4367 bool FoundOperator = false;
4368 Res.suppressDiagnostics();
4369 for (LookupResult::iterator Op = Res.begin(), OpEnd = Res.end();
4370 Op != OpEnd; ++Op) {
4371 if (isa<FunctionTemplateDecl>(*Op))
4372 continue;
4373
4374 CXXMethodDecl *Operator = cast<CXXMethodDecl>(*Op);
4375 if((Operator->*IsDesiredOp)()) {
4376 FoundOperator = true;
4377 const FunctionProtoType *CPT =
4378 Operator->getType()->getAs<FunctionProtoType>();
4379 CPT = Self.ResolveExceptionSpec(KeyLoc, CPT);
4380 if (!CPT || !CPT->isNothrow(C))
4381 return false;
4382 }
4383 }
4384 return FoundOperator;
4385 }
4386 return false;
4387}
4388
4389static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT,
4390 SourceLocation KeyLoc, QualType T) {
4391 assert(!T->isDependentType() && "Cannot evaluate traits of dependent type")(static_cast <bool> (!T->isDependentType() &&
"Cannot evaluate traits of dependent type") ? void (0) : __assert_fail
("!T->isDependentType() && \"Cannot evaluate traits of dependent type\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4391, __extension__ __PRETTY_FUNCTION__))
;
4392
4393 ASTContext &C = Self.Context;
4394 switch(UTT) {
4395 default: llvm_unreachable("not a UTT")::llvm::llvm_unreachable_internal("not a UTT", "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4395)
;
4396 // Type trait expressions corresponding to the primary type category
4397 // predicates in C++0x [meta.unary.cat].
4398 case UTT_IsVoid:
4399 return T->isVoidType();
4400 case UTT_IsIntegral:
4401 return T->isIntegralType(C);
4402 case UTT_IsFloatingPoint:
4403 return T->isFloatingType();
4404 case UTT_IsArray:
4405 return T->isArrayType();
4406 case UTT_IsPointer:
4407 return T->isPointerType();
4408 case UTT_IsLvalueReference:
4409 return T->isLValueReferenceType();
4410 case UTT_IsRvalueReference:
4411 return T->isRValueReferenceType();
4412 case UTT_IsMemberFunctionPointer:
4413 return T->isMemberFunctionPointerType();
4414 case UTT_IsMemberObjectPointer:
4415 return T->isMemberDataPointerType();
4416 case UTT_IsEnum:
4417 return T->isEnumeralType();
4418 case UTT_IsUnion:
4419 return T->isUnionType();
4420 case UTT_IsClass:
4421 return T->isClassType() || T->isStructureType() || T->isInterfaceType();
4422 case UTT_IsFunction:
4423 return T->isFunctionType();
4424
4425 // Type trait expressions which correspond to the convenient composition
4426 // predicates in C++0x [meta.unary.comp].
4427 case UTT_IsReference:
4428 return T->isReferenceType();
4429 case UTT_IsArithmetic:
4430 return T->isArithmeticType() && !T->isEnumeralType();
4431 case UTT_IsFundamental:
4432 return T->isFundamentalType();
4433 case UTT_IsObject:
4434 return T->isObjectType();
4435 case UTT_IsScalar:
4436 // Note: semantic analysis depends on Objective-C lifetime types to be
4437 // considered scalar types. However, such types do not actually behave
4438 // like scalar types at run time (since they may require retain/release
4439 // operations), so we report them as non-scalar.
4440 if (T->isObjCLifetimeType()) {
4441 switch (T.getObjCLifetime()) {
4442 case Qualifiers::OCL_None:
4443 case Qualifiers::OCL_ExplicitNone:
4444 return true;
4445
4446 case Qualifiers::OCL_Strong:
4447 case Qualifiers::OCL_Weak:
4448 case Qualifiers::OCL_Autoreleasing:
4449 return false;
4450 }
4451 }
4452
4453 return T->isScalarType();
4454 case UTT_IsCompound:
4455 return T->isCompoundType();
4456 case UTT_IsMemberPointer:
4457 return T->isMemberPointerType();
4458
4459 // Type trait expressions which correspond to the type property predicates
4460 // in C++0x [meta.unary.prop].
4461 case UTT_IsConst:
4462 return T.isConstQualified();
4463 case UTT_IsVolatile:
4464 return T.isVolatileQualified();
4465 case UTT_IsTrivial:
4466 return T.isTrivialType(C);
4467 case UTT_IsTriviallyCopyable:
4468 return T.isTriviallyCopyableType(C);
4469 case UTT_IsStandardLayout:
4470 return T->isStandardLayoutType();
4471 case UTT_IsPOD:
4472 return T.isPODType(C);
4473 case UTT_IsLiteral:
4474 return T->isLiteralType(C);
4475 case UTT_IsEmpty:
4476 if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl())
4477 return !RD->isUnion() && RD->isEmpty();
4478 return false;
4479 case UTT_IsPolymorphic:
4480 if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl())
4481 return !RD->isUnion() && RD->isPolymorphic();
4482 return false;
4483 case UTT_IsAbstract:
4484 if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl())
4485 return !RD->isUnion() && RD->isAbstract();
4486 return false;
4487 case UTT_IsAggregate:
4488 // Report vector extensions and complex types as aggregates because they
4489 // support aggregate initialization. GCC mirrors this behavior for vectors
4490 // but not _Complex.
4491 return T->isAggregateType() || T->isVectorType() || T->isExtVectorType() ||
4492 T->isAnyComplexType();
4493 // __is_interface_class only returns true when CL is invoked in /CLR mode and
4494 // even then only when it is used with the 'interface struct ...' syntax
4495 // Clang doesn't support /CLR which makes this type trait moot.
4496 case UTT_IsInterfaceClass:
4497 return false;
4498 case UTT_IsFinal:
4499 case UTT_IsSealed:
4500 if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl())
4501 return RD->hasAttr<FinalAttr>();
4502 return false;
4503 case UTT_IsSigned:
4504 return T->isSignedIntegerType();
4505 case UTT_IsUnsigned:
4506 return T->isUnsignedIntegerType();
4507
4508 // Type trait expressions which query classes regarding their construction,
4509 // destruction, and copying. Rather than being based directly on the
4510 // related type predicates in the standard, they are specified by both
4511 // GCC[1] and the Embarcadero C++ compiler[2], and Clang implements those
4512 // specifications.
4513 //
4514 // 1: http://gcc.gnu/.org/onlinedocs/gcc/Type-Traits.html
4515 // 2: http://docwiki.embarcadero.com/RADStudio/XE/en/Type_Trait_Functions_(C%2B%2B0x)_Index
4516 //
4517 // Note that these builtins do not behave as documented in g++: if a class
4518 // has both a trivial and a non-trivial special member of a particular kind,
4519 // they return false! For now, we emulate this behavior.
4520 // FIXME: This appears to be a g++ bug: more complex cases reveal that it
4521 // does not correctly compute triviality in the presence of multiple special
4522 // members of the same kind. Revisit this once the g++ bug is fixed.
4523 case UTT_HasTrivialDefaultConstructor:
4524 // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html:
4525 // If __is_pod (type) is true then the trait is true, else if type is
4526 // a cv class or union type (or array thereof) with a trivial default
4527 // constructor ([class.ctor]) then the trait is true, else it is false.
4528 if (T.isPODType(C))
4529 return true;
4530 if (CXXRecordDecl *RD = C.getBaseElementType(T)->getAsCXXRecordDecl())
4531 return RD->hasTrivialDefaultConstructor() &&
4532 !RD->hasNonTrivialDefaultConstructor();
4533 return false;
4534 case UTT_HasTrivialMoveConstructor:
4535 // This trait is implemented by MSVC 2012 and needed to parse the
4536 // standard library headers. Specifically this is used as the logic
4537 // behind std::is_trivially_move_constructible (20.9.4.3).
4538 if (T.isPODType(C))
4539 return true;
4540 if (CXXRecordDecl *RD = C.getBaseElementType(T)->getAsCXXRecordDecl())
4541 return RD->hasTrivialMoveConstructor() && !RD->hasNonTrivialMoveConstructor();
4542 return false;
4543 case UTT_HasTrivialCopy:
4544 // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html:
4545 // If __is_pod (type) is true or type is a reference type then
4546 // the trait is true, else if type is a cv class or union type
4547 // with a trivial copy constructor ([class.copy]) then the trait
4548 // is true, else it is false.
4549 if (T.isPODType(C) || T->isReferenceType())
4550 return true;
4551 if (CXXRecordDecl *RD = T->getAsCXXRecordDecl())
4552 return RD->hasTrivialCopyConstructor() &&
4553 !RD->hasNonTrivialCopyConstructor();
4554 return false;
4555 case UTT_HasTrivialMoveAssign:
4556 // This trait is implemented by MSVC 2012 and needed to parse the
4557 // standard library headers. Specifically it is used as the logic
4558 // behind std::is_trivially_move_assignable (20.9.4.3)
4559 if (T.isPODType(C))
4560 return true;
4561 if (CXXRecordDecl *RD = C.getBaseElementType(T)->getAsCXXRecordDecl())
4562 return RD->hasTrivialMoveAssignment() && !RD->hasNonTrivialMoveAssignment();
4563 return false;
4564 case UTT_HasTrivialAssign:
4565 // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html:
4566 // If type is const qualified or is a reference type then the
4567 // trait is false. Otherwise if __is_pod (type) is true then the
4568 // trait is true, else if type is a cv class or union type with
4569 // a trivial copy assignment ([class.copy]) then the trait is
4570 // true, else it is false.
4571 // Note: the const and reference restrictions are interesting,
4572 // given that const and reference members don't prevent a class
4573 // from having a trivial copy assignment operator (but do cause
4574 // errors if the copy assignment operator is actually used, q.v.
4575 // [class.copy]p12).
4576
4577 if (T.isConstQualified())
4578 return false;
4579 if (T.isPODType(C))
4580 return true;
4581 if (CXXRecordDecl *RD = T->getAsCXXRecordDecl())
4582 return RD->hasTrivialCopyAssignment() &&
4583 !RD->hasNonTrivialCopyAssignment();
4584 return false;
4585 case UTT_IsDestructible:
4586 case UTT_IsTriviallyDestructible:
4587 case UTT_IsNothrowDestructible:
4588 // C++14 [meta.unary.prop]:
4589 // For reference types, is_destructible<T>::value is true.
4590 if (T->isReferenceType())
4591 return true;
4592
4593 // Objective-C++ ARC: autorelease types don't require destruction.
4594 if (T->isObjCLifetimeType() &&
4595 T.getObjCLifetime() == Qualifiers::OCL_Autoreleasing)
4596 return true;
4597
4598 // C++14 [meta.unary.prop]:
4599 // For incomplete types and function types, is_destructible<T>::value is
4600 // false.
4601 if (T->isIncompleteType() || T->isFunctionType())
4602 return false;
4603
4604 // A type that requires destruction (via a non-trivial destructor or ARC
4605 // lifetime semantics) is not trivially-destructible.
4606 if (UTT == UTT_IsTriviallyDestructible && T.isDestructedType())
4607 return false;
4608
4609 // C++14 [meta.unary.prop]:
4610 // For object types and given U equal to remove_all_extents_t<T>, if the
4611 // expression std::declval<U&>().~U() is well-formed when treated as an
4612 // unevaluated operand (Clause 5), then is_destructible<T>::value is true
4613 if (auto *RD = C.getBaseElementType(T)->getAsCXXRecordDecl()) {
4614 CXXDestructorDecl *Destructor = Self.LookupDestructor(RD);
4615 if (!Destructor)
4616 return false;
4617 // C++14 [dcl.fct.def.delete]p2:
4618 // A program that refers to a deleted function implicitly or
4619 // explicitly, other than to declare it, is ill-formed.
4620 if (Destructor->isDeleted())
4621 return false;
4622 if (C.getLangOpts().AccessControl && Destructor->getAccess() != AS_public)
4623 return false;
4624 if (UTT == UTT_IsNothrowDestructible) {
4625 const FunctionProtoType *CPT =
4626 Destructor->getType()->getAs<FunctionProtoType>();
4627 CPT = Self.ResolveExceptionSpec(KeyLoc, CPT);
4628 if (!CPT || !CPT->isNothrow(C))
4629 return false;
4630 }
4631 }
4632 return true;
4633
4634 case UTT_HasTrivialDestructor:
4635 // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html
4636 // If __is_pod (type) is true or type is a reference type
4637 // then the trait is true, else if type is a cv class or union
4638 // type (or array thereof) with a trivial destructor
4639 // ([class.dtor]) then the trait is true, else it is
4640 // false.
4641 if (T.isPODType(C) || T->isReferenceType())
4642 return true;
4643
4644 // Objective-C++ ARC: autorelease types don't require destruction.
4645 if (T->isObjCLifetimeType() &&
4646 T.getObjCLifetime() == Qualifiers::OCL_Autoreleasing)
4647 return true;
4648
4649 if (CXXRecordDecl *RD = C.getBaseElementType(T)->getAsCXXRecordDecl())
4650 return RD->hasTrivialDestructor();
4651 return false;
4652 // TODO: Propagate nothrowness for implicitly declared special members.
4653 case UTT_HasNothrowAssign:
4654 // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html:
4655 // If type is const qualified or is a reference type then the
4656 // trait is false. Otherwise if __has_trivial_assign (type)
4657 // is true then the trait is true, else if type is a cv class
4658 // or union type with copy assignment operators that are known
4659 // not to throw an exception then the trait is true, else it is
4660 // false.
4661 if (C.getBaseElementType(T).isConstQualified())
4662 return false;
4663 if (T->isReferenceType())
4664 return false;
4665 if (T.isPODType(C) || T->isObjCLifetimeType())
4666 return true;
4667
4668 if (const RecordType *RT = T->getAs<RecordType>())
4669 return HasNoThrowOperator(RT, OO_Equal, Self, KeyLoc, C,
4670 &CXXRecordDecl::hasTrivialCopyAssignment,
4671 &CXXRecordDecl::hasNonTrivialCopyAssignment,
4672 &CXXMethodDecl::isCopyAssignmentOperator);
4673 return false;
4674 case UTT_HasNothrowMoveAssign:
4675 // This trait is implemented by MSVC 2012 and needed to parse the
4676 // standard library headers. Specifically this is used as the logic
4677 // behind std::is_nothrow_move_assignable (20.9.4.3).
4678 if (T.isPODType(C))
4679 return true;
4680
4681 if (const RecordType *RT = C.getBaseElementType(T)->getAs<RecordType>())
4682 return HasNoThrowOperator(RT, OO_Equal, Self, KeyLoc, C,
4683 &CXXRecordDecl::hasTrivialMoveAssignment,
4684 &CXXRecordDecl::hasNonTrivialMoveAssignment,
4685 &CXXMethodDecl::isMoveAssignmentOperator);
4686 return false;
4687 case UTT_HasNothrowCopy:
4688 // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html:
4689 // If __has_trivial_copy (type) is true then the trait is true, else
4690 // if type is a cv class or union type with copy constructors that are
4691 // known not to throw an exception then the trait is true, else it is
4692 // false.
4693 if (T.isPODType(C) || T->isReferenceType() || T->isObjCLifetimeType())
4694 return true;
4695 if (CXXRecordDecl *RD = T->getAsCXXRecordDecl()) {
4696 if (RD->hasTrivialCopyConstructor() &&
4697 !RD->hasNonTrivialCopyConstructor())
4698 return true;
4699
4700 bool FoundConstructor = false;
4701 unsigned FoundTQs;
4702 for (const auto *ND : Self.LookupConstructors(RD)) {
4703 // A template constructor is never a copy constructor.
4704 // FIXME: However, it may actually be selected at the actual overload
4705 // resolution point.
4706 if (isa<FunctionTemplateDecl>(ND->getUnderlyingDecl()))
4707 continue;
4708 // UsingDecl itself is not a constructor
4709 if (isa<UsingDecl>(ND))
4710 continue;
4711 auto *Constructor = cast<CXXConstructorDecl>(ND->getUnderlyingDecl());
4712 if (Constructor->isCopyConstructor(FoundTQs)) {
4713 FoundConstructor = true;
4714 const FunctionProtoType *CPT
4715 = Constructor->getType()->getAs<FunctionProtoType>();
4716 CPT = Self.ResolveExceptionSpec(KeyLoc, CPT);
4717 if (!CPT)
4718 return false;
4719 // TODO: check whether evaluating default arguments can throw.
4720 // For now, we'll be conservative and assume that they can throw.
4721 if (!CPT->isNothrow(C) || CPT->getNumParams() > 1)
4722 return false;
4723 }
4724 }
4725
4726 return FoundConstructor;
4727 }
4728 return false;
4729 case UTT_HasNothrowConstructor:
4730 // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html
4731 // If __has_trivial_constructor (type) is true then the trait is
4732 // true, else if type is a cv class or union type (or array
4733 // thereof) with a default constructor that is known not to
4734 // throw an exception then the trait is true, else it is false.
4735 if (T.isPODType(C) || T->isObjCLifetimeType())
4736 return true;
4737 if (CXXRecordDecl *RD = C.getBaseElementType(T)->getAsCXXRecordDecl()) {
4738 if (RD->hasTrivialDefaultConstructor() &&
4739 !RD->hasNonTrivialDefaultConstructor())
4740 return true;
4741
4742 bool FoundConstructor = false;
4743 for (const auto *ND : Self.LookupConstructors(RD)) {
4744 // FIXME: In C++0x, a constructor template can be a default constructor.
4745 if (isa<FunctionTemplateDecl>(ND->getUnderlyingDecl()))
4746 continue;
4747 // UsingDecl itself is not a constructor
4748 if (isa<UsingDecl>(ND))
4749 continue;
4750 auto *Constructor = cast<CXXConstructorDecl>(ND->getUnderlyingDecl());
4751 if (Constructor->isDefaultConstructor()) {
4752 FoundConstructor = true;
4753 const FunctionProtoType *CPT
4754 = Constructor->getType()->getAs<FunctionProtoType>();
4755 CPT = Self.ResolveExceptionSpec(KeyLoc, CPT);
4756 if (!CPT)
4757 return false;
4758 // FIXME: check whether evaluating default arguments can throw.
4759 // For now, we'll be conservative and assume that they can throw.
4760 if (!CPT->isNothrow(C) || CPT->getNumParams() > 0)
4761 return false;
4762 }
4763 }
4764 return FoundConstructor;
4765 }
4766 return false;
4767 case UTT_HasVirtualDestructor:
4768 // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html:
4769 // If type is a class type with a virtual destructor ([class.dtor])
4770 // then the trait is true, else it is false.
4771 if (CXXRecordDecl *RD = T->getAsCXXRecordDecl())
4772 if (CXXDestructorDecl *Destructor = Self.LookupDestructor(RD))
4773 return Destructor->isVirtual();
4774 return false;
4775
4776 // These type trait expressions are modeled on the specifications for the
4777 // Embarcadero C++0x type trait functions:
4778 // http://docwiki.embarcadero.com/RADStudio/XE/en/Type_Trait_Functions_(C%2B%2B0x)_Index
4779 case UTT_IsCompleteType:
4780 // http://docwiki.embarcadero.com/RADStudio/XE/en/Is_complete_type_(typename_T_):
4781 // Returns True if and only if T is a complete type at the point of the
4782 // function call.
4783 return !T->isIncompleteType();
4784 case UTT_HasUniqueObjectRepresentations:
4785 return C.hasUniqueObjectRepresentations(T);
4786 }
4787}
4788
4789static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, QualType LhsT,
4790 QualType RhsT, SourceLocation KeyLoc);
4791
4792static bool evaluateTypeTrait(Sema &S, TypeTrait Kind, SourceLocation KWLoc,
4793 ArrayRef<TypeSourceInfo *> Args,
4794 SourceLocation RParenLoc) {
4795 if (Kind <= UTT_Last)
4796 return EvaluateUnaryTypeTrait(S, Kind, KWLoc, Args[0]->getType());
4797
4798 // Evaluate BTT_ReferenceBindsToTemporary alongside the IsConstructible
4799 // traits to avoid duplication.
4800 if (Kind <= BTT_Last && Kind != BTT_ReferenceBindsToTemporary)
4801 return EvaluateBinaryTypeTrait(S, Kind, Args[0]->getType(),
4802 Args[1]->getType(), RParenLoc);
4803
4804 switch (Kind) {
4805 case clang::BTT_ReferenceBindsToTemporary:
4806 case clang::TT_IsConstructible:
4807 case clang::TT_IsNothrowConstructible:
4808 case clang::TT_IsTriviallyConstructible: {
4809 // C++11 [meta.unary.prop]:
4810 // is_trivially_constructible is defined as:
4811 //
4812 // is_constructible<T, Args...>::value is true and the variable
4813 // definition for is_constructible, as defined below, is known to call
4814 // no operation that is not trivial.
4815 //
4816 // The predicate condition for a template specialization
4817 // is_constructible<T, Args...> shall be satisfied if and only if the
4818 // following variable definition would be well-formed for some invented
4819 // variable t:
4820 //
4821 // T t(create<Args>()...);
4822 assert(!Args.empty())(static_cast <bool> (!Args.empty()) ? void (0) : __assert_fail
("!Args.empty()", "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4822, __extension__ __PRETTY_FUNCTION__))
;
4823
4824 // Precondition: T and all types in the parameter pack Args shall be
4825 // complete types, (possibly cv-qualified) void, or arrays of
4826 // unknown bound.
4827 for (const auto *TSI : Args) {
4828 QualType ArgTy = TSI->getType();
4829 if (ArgTy->isVoidType() || ArgTy->isIncompleteArrayType())
4830 continue;
4831
4832 if (S.RequireCompleteType(KWLoc, ArgTy,
4833 diag::err_incomplete_type_used_in_type_trait_expr))
4834 return false;
4835 }
4836
4837 // Make sure the first argument is not incomplete nor a function type.
4838 QualType T = Args[0]->getType();
4839 if (T->isIncompleteType() || T->isFunctionType())
4840 return false;
4841
4842 // Make sure the first argument is not an abstract type.
4843 CXXRecordDecl *RD = T->getAsCXXRecordDecl();
4844 if (RD && RD->isAbstract())
4845 return false;
4846
4847 SmallVector<OpaqueValueExpr, 2> OpaqueArgExprs;
4848 SmallVector<Expr *, 2> ArgExprs;
4849 ArgExprs.reserve(Args.size() - 1);
4850 for (unsigned I = 1, N = Args.size(); I != N; ++I) {
4851 QualType ArgTy = Args[I]->getType();
4852 if (ArgTy->isObjectType() || ArgTy->isFunctionType())
4853 ArgTy = S.Context.getRValueReferenceType(ArgTy);
4854 OpaqueArgExprs.push_back(
4855 OpaqueValueExpr(Args[I]->getTypeLoc().getLocStart(),
4856 ArgTy.getNonLValueExprType(S.Context),
4857 Expr::getValueKindForType(ArgTy)));
4858 }
4859 for (Expr &E : OpaqueArgExprs)
4860 ArgExprs.push_back(&E);
4861
4862 // Perform the initialization in an unevaluated context within a SFINAE
4863 // trap at translation unit scope.
4864 EnterExpressionEvaluationContext Unevaluated(
4865 S, Sema::ExpressionEvaluationContext::Unevaluated);
4866 Sema::SFINAETrap SFINAE(S, /*AccessCheckingSFINAE=*/true);
4867 Sema::ContextRAII TUContext(S, S.Context.getTranslationUnitDecl());
4868 InitializedEntity To(InitializedEntity::InitializeTemporary(Args[0]));
4869 InitializationKind InitKind(InitializationKind::CreateDirect(KWLoc, KWLoc,
4870 RParenLoc));
4871 InitializationSequence Init(S, To, InitKind, ArgExprs);
4872 if (Init.Failed())
4873 return false;
4874
4875 ExprResult Result = Init.Perform(S, To, InitKind, ArgExprs);
4876 if (Result.isInvalid() || SFINAE.hasErrorOccurred())
4877 return false;
4878
4879 if (Kind == clang::TT_IsConstructible)
4880 return true;
4881
4882 if (Kind == clang::BTT_ReferenceBindsToTemporary) {
4883 if (!T->isReferenceType())
4884 return false;
4885
4886 return !Init.isDirectReferenceBinding();
4887 }
4888
4889 if (Kind == clang::TT_IsNothrowConstructible)
4890 return S.canThrow(Result.get()) == CT_Cannot;
4891
4892 if (Kind == clang::TT_IsTriviallyConstructible) {
4893 // Under Objective-C ARC and Weak, if the destination has non-trivial
4894 // Objective-C lifetime, this is a non-trivial construction.
4895 if (T.getNonReferenceType().hasNonTrivialObjCLifetime())
4896 return false;
4897
4898 // The initialization succeeded; now make sure there are no non-trivial
4899 // calls.
4900 return !Result.get()->hasNonTrivialCall(S.Context);
4901 }
4902
4903 llvm_unreachable("unhandled type trait")::llvm::llvm_unreachable_internal("unhandled type trait", "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4903)
;
4904 return false;
4905 }
4906 default: llvm_unreachable("not a TT")::llvm::llvm_unreachable_internal("not a TT", "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4906)
;
4907 }
4908
4909 return false;
4910}
4911
4912ExprResult Sema::BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc,
4913 ArrayRef<TypeSourceInfo *> Args,
4914 SourceLocation RParenLoc) {
4915 QualType ResultType = Context.getLogicalOperationType();
4916
4917 if (Kind <= UTT_Last && !CheckUnaryTypeTraitTypeCompleteness(
4918 *this, Kind, KWLoc, Args[0]->getType()))
4919 return ExprError();
4920
4921 bool Dependent = false;
4922 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
4923 if (Args[I]->getType()->isDependentType()) {
4924 Dependent = true;
4925 break;
4926 }
4927 }
4928
4929 bool Result = false;
4930 if (!Dependent)
4931 Result = evaluateTypeTrait(*this, Kind, KWLoc, Args, RParenLoc);
4932
4933 return TypeTraitExpr::Create(Context, ResultType, KWLoc, Kind, Args,
4934 RParenLoc, Result);
4935}
4936
4937ExprResult Sema::ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc,
4938 ArrayRef<ParsedType> Args,
4939 SourceLocation RParenLoc) {
4940 SmallVector<TypeSourceInfo *, 4> ConvertedArgs;
4941 ConvertedArgs.reserve(Args.size());
4942
4943 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
4944 TypeSourceInfo *TInfo;
4945 QualType T = GetTypeFromParser(Args[I], &TInfo);
4946 if (!TInfo)
4947 TInfo = Context.getTrivialTypeSourceInfo(T, KWLoc);
4948
4949 ConvertedArgs.push_back(TInfo);
4950 }
4951
4952 return BuildTypeTrait(Kind, KWLoc, ConvertedArgs, RParenLoc);
4953}
4954
4955static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, QualType LhsT,
4956 QualType RhsT, SourceLocation KeyLoc) {
4957 assert(!LhsT->isDependentType() && !RhsT->isDependentType() &&(static_cast <bool> (!LhsT->isDependentType() &&
!RhsT->isDependentType() && "Cannot evaluate traits of dependent types"
) ? void (0) : __assert_fail ("!LhsT->isDependentType() && !RhsT->isDependentType() && \"Cannot evaluate traits of dependent types\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4958, __extension__ __PRETTY_FUNCTION__))
4958 "Cannot evaluate traits of dependent types")(static_cast <bool> (!LhsT->isDependentType() &&
!RhsT->isDependentType() && "Cannot evaluate traits of dependent types"
) ? void (0) : __assert_fail ("!LhsT->isDependentType() && !RhsT->isDependentType() && \"Cannot evaluate traits of dependent types\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4958, __extension__ __PRETTY_FUNCTION__))
;
4959
4960 switch(BTT) {
4961 case BTT_IsBaseOf: {
4962 // C++0x [meta.rel]p2
4963 // Base is a base class of Derived without regard to cv-qualifiers or
4964 // Base and Derived are not unions and name the same class type without
4965 // regard to cv-qualifiers.
4966
4967 const RecordType *lhsRecord = LhsT->getAs<RecordType>();
4968 const RecordType *rhsRecord = RhsT->getAs<RecordType>();
4969 if (!rhsRecord || !lhsRecord) {
4970 const ObjCObjectType *LHSObjTy = LhsT->getAs<ObjCObjectType>();
4971 const ObjCObjectType *RHSObjTy = RhsT->getAs<ObjCObjectType>();
4972 if (!LHSObjTy || !RHSObjTy)
4973 return false;
4974
4975 ObjCInterfaceDecl *BaseInterface = LHSObjTy->getInterface();
4976 ObjCInterfaceDecl *DerivedInterface = RHSObjTy->getInterface();
4977 if (!BaseInterface || !DerivedInterface)
4978 return false;
4979
4980 if (Self.RequireCompleteType(
4981 KeyLoc, RhsT, diag::err_incomplete_type_used_in_type_trait_expr))
4982 return false;
4983
4984 return BaseInterface->isSuperClassOf(DerivedInterface);
4985 }
4986
4987 assert(Self.Context.hasSameUnqualifiedType(LhsT, RhsT)(static_cast <bool> (Self.Context.hasSameUnqualifiedType
(LhsT, RhsT) == (lhsRecord == rhsRecord)) ? void (0) : __assert_fail
("Self.Context.hasSameUnqualifiedType(LhsT, RhsT) == (lhsRecord == rhsRecord)"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4988, __extension__ __PRETTY_FUNCTION__))
4988 == (lhsRecord == rhsRecord))(static_cast <bool> (Self.Context.hasSameUnqualifiedType
(LhsT, RhsT) == (lhsRecord == rhsRecord)) ? void (0) : __assert_fail
("Self.Context.hasSameUnqualifiedType(LhsT, RhsT) == (lhsRecord == rhsRecord)"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 4988, __extension__ __PRETTY_FUNCTION__))
;
4989
4990 if (lhsRecord == rhsRecord)
4991 return !lhsRecord->getDecl()->isUnion();
4992
4993 // C++0x [meta.rel]p2:
4994 // If Base and Derived are class types and are different types
4995 // (ignoring possible cv-qualifiers) then Derived shall be a
4996 // complete type.
4997 if (Self.RequireCompleteType(KeyLoc, RhsT,
4998 diag::err_incomplete_type_used_in_type_trait_expr))
4999 return false;
5000
5001 return cast<CXXRecordDecl>(rhsRecord->getDecl())
5002 ->isDerivedFrom(cast<CXXRecordDecl>(lhsRecord->getDecl()));
5003 }
5004 case BTT_IsSame:
5005 return Self.Context.hasSameType(LhsT, RhsT);
5006 case BTT_TypeCompatible: {
5007 // GCC ignores cv-qualifiers on arrays for this builtin.
5008 Qualifiers LhsQuals, RhsQuals;
5009 QualType Lhs = Self.getASTContext().getUnqualifiedArrayType(LhsT, LhsQuals);
5010 QualType Rhs = Self.getASTContext().getUnqualifiedArrayType(RhsT, RhsQuals);
5011 return Self.Context.typesAreCompatible(Lhs, Rhs);
5012 }
5013 case BTT_IsConvertible:
5014 case BTT_IsConvertibleTo: {
5015 // C++0x [meta.rel]p4:
5016 // Given the following function prototype:
5017 //
5018 // template <class T>
5019 // typename add_rvalue_reference<T>::type create();
5020 //
5021 // the predicate condition for a template specialization
5022 // is_convertible<From, To> shall be satisfied if and only if
5023 // the return expression in the following code would be
5024 // well-formed, including any implicit conversions to the return
5025 // type of the function:
5026 //
5027 // To test() {
5028 // return create<From>();
5029 // }
5030 //
5031 // Access checking is performed as if in a context unrelated to To and
5032 // From. Only the validity of the immediate context of the expression
5033 // of the return-statement (including conversions to the return type)
5034 // is considered.
5035 //
5036 // We model the initialization as a copy-initialization of a temporary
5037 // of the appropriate type, which for this expression is identical to the
5038 // return statement (since NRVO doesn't apply).
5039
5040 // Functions aren't allowed to return function or array types.
5041 if (RhsT->isFunctionType() || RhsT->isArrayType())
5042 return false;
5043
5044 // A return statement in a void function must have void type.
5045 if (RhsT->isVoidType())
5046 return LhsT->isVoidType();
5047
5048 // A function definition requires a complete, non-abstract return type.
5049 if (!Self.isCompleteType(KeyLoc, RhsT) || Self.isAbstractType(KeyLoc, RhsT))
5050 return false;
5051
5052 // Compute the result of add_rvalue_reference.
5053 if (LhsT->isObjectType() || LhsT->isFunctionType())
5054 LhsT = Self.Context.getRValueReferenceType(LhsT);
5055
5056 // Build a fake source and destination for initialization.
5057 InitializedEntity To(InitializedEntity::InitializeTemporary(RhsT));
5058 OpaqueValueExpr From(KeyLoc, LhsT.getNonLValueExprType(Self.Context),
5059 Expr::getValueKindForType(LhsT));
5060 Expr *FromPtr = &From;
5061 InitializationKind Kind(InitializationKind::CreateCopy(KeyLoc,
5062 SourceLocation()));
5063
5064 // Perform the initialization in an unevaluated context within a SFINAE
5065 // trap at translation unit scope.
5066 EnterExpressionEvaluationContext Unevaluated(
5067 Self, Sema::ExpressionEvaluationContext::Unevaluated);
5068 Sema::SFINAETrap SFINAE(Self, /*AccessCheckingSFINAE=*/true);
5069 Sema::ContextRAII TUContext(Self, Self.Context.getTranslationUnitDecl());
5070 InitializationSequence Init(Self, To, Kind, FromPtr);
5071 if (Init.Failed())
5072 return false;
5073
5074 ExprResult Result = Init.Perform(Self, To, Kind, FromPtr);
5075 return !Result.isInvalid() && !SFINAE.hasErrorOccurred();
5076 }
5077
5078 case BTT_IsAssignable:
5079 case BTT_IsNothrowAssignable:
5080 case BTT_IsTriviallyAssignable: {
5081 // C++11 [meta.unary.prop]p3:
5082 // is_trivially_assignable is defined as:
5083 // is_assignable<T, U>::value is true and the assignment, as defined by
5084 // is_assignable, is known to call no operation that is not trivial
5085 //
5086 // is_assignable is defined as:
5087 // The expression declval<T>() = declval<U>() is well-formed when
5088 // treated as an unevaluated operand (Clause 5).
5089 //
5090 // For both, T and U shall be complete types, (possibly cv-qualified)
5091 // void, or arrays of unknown bound.
5092 if (!LhsT->isVoidType() && !LhsT->isIncompleteArrayType() &&
5093 Self.RequireCompleteType(KeyLoc, LhsT,
5094 diag::err_incomplete_type_used_in_type_trait_expr))
5095 return false;
5096 if (!RhsT->isVoidType() && !RhsT->isIncompleteArrayType() &&
5097 Self.RequireCompleteType(KeyLoc, RhsT,
5098 diag::err_incomplete_type_used_in_type_trait_expr))
5099 return false;
5100
5101 // cv void is never assignable.
5102 if (LhsT->isVoidType() || RhsT->isVoidType())
5103 return false;
5104
5105 // Build expressions that emulate the effect of declval<T>() and
5106 // declval<U>().
5107 if (LhsT->isObjectType() || LhsT->isFunctionType())
5108 LhsT = Self.Context.getRValueReferenceType(LhsT);
5109 if (RhsT->isObjectType() || RhsT->isFunctionType())
5110 RhsT = Self.Context.getRValueReferenceType(RhsT);
5111 OpaqueValueExpr Lhs(KeyLoc, LhsT.getNonLValueExprType(Self.Context),
5112 Expr::getValueKindForType(LhsT));
5113 OpaqueValueExpr Rhs(KeyLoc, RhsT.getNonLValueExprType(Self.Context),
5114 Expr::getValueKindForType(RhsT));
5115
5116 // Attempt the assignment in an unevaluated context within a SFINAE
5117 // trap at translation unit scope.
5118 EnterExpressionEvaluationContext Unevaluated(
5119 Self, Sema::ExpressionEvaluationContext::Unevaluated);
5120 Sema::SFINAETrap SFINAE(Self, /*AccessCheckingSFINAE=*/true);
5121 Sema::ContextRAII TUContext(Self, Self.Context.getTranslationUnitDecl());
5122 ExprResult Result = Self.BuildBinOp(/*S=*/nullptr, KeyLoc, BO_Assign, &Lhs,
5123 &Rhs);
5124 if (Result.isInvalid() || SFINAE.hasErrorOccurred())
5125 return false;
5126
5127 if (BTT == BTT_IsAssignable)
5128 return true;
5129
5130 if (BTT == BTT_IsNothrowAssignable)
5131 return Self.canThrow(Result.get()) == CT_Cannot;
5132
5133 if (BTT == BTT_IsTriviallyAssignable) {
5134 // Under Objective-C ARC and Weak, if the destination has non-trivial
5135 // Objective-C lifetime, this is a non-trivial assignment.
5136 if (LhsT.getNonReferenceType().hasNonTrivialObjCLifetime())
5137 return false;
5138
5139 return !Result.get()->hasNonTrivialCall(Self.Context);
5140 }
5141
5142 llvm_unreachable("unhandled type trait")::llvm::llvm_unreachable_internal("unhandled type trait", "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5142)
;
5143 return false;
5144 }
5145 default: llvm_unreachable("not a BTT")::llvm::llvm_unreachable_internal("not a BTT", "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5145)
;
5146 }
5147 llvm_unreachable("Unknown type trait or not implemented")::llvm::llvm_unreachable_internal("Unknown type trait or not implemented"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5147)
;
5148}
5149
5150ExprResult Sema::ActOnArrayTypeTrait(ArrayTypeTrait ATT,
5151 SourceLocation KWLoc,
5152 ParsedType Ty,
5153 Expr* DimExpr,
5154 SourceLocation RParen) {
5155 TypeSourceInfo *TSInfo;
5156 QualType T = GetTypeFromParser(Ty, &TSInfo);
5157 if (!TSInfo)
5158 TSInfo = Context.getTrivialTypeSourceInfo(T);
5159
5160 return BuildArrayTypeTrait(ATT, KWLoc, TSInfo, DimExpr, RParen);
5161}
5162
5163static uint64_t EvaluateArrayTypeTrait(Sema &Self, ArrayTypeTrait ATT,
5164 QualType T, Expr *DimExpr,
5165 SourceLocation KeyLoc) {
5166 assert(!T->isDependentType() && "Cannot evaluate traits of dependent type")(static_cast <bool> (!T->isDependentType() &&
"Cannot evaluate traits of dependent type") ? void (0) : __assert_fail
("!T->isDependentType() && \"Cannot evaluate traits of dependent type\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5166, __extension__ __PRETTY_FUNCTION__))
;
5167
5168 switch(ATT) {
5169 case ATT_ArrayRank:
5170 if (T->isArrayType()) {
5171 unsigned Dim = 0;
5172 while (const ArrayType *AT = Self.Context.getAsArrayType(T)) {
5173 ++Dim;
5174 T = AT->getElementType();
5175 }
5176 return Dim;
5177 }
5178 return 0;
5179
5180 case ATT_ArrayExtent: {
5181 llvm::APSInt Value;
5182 uint64_t Dim;
5183 if (Self.VerifyIntegerConstantExpression(DimExpr, &Value,
5184 diag::err_dimension_expr_not_constant_integer,
5185 false).isInvalid())
5186 return 0;
5187 if (Value.isSigned() && Value.isNegative()) {
5188 Self.Diag(KeyLoc, diag::err_dimension_expr_not_constant_integer)
5189 << DimExpr->getSourceRange();
5190 return 0;
5191 }
5192 Dim = Value.getLimitedValue();
5193
5194 if (T->isArrayType()) {
5195 unsigned D = 0;
5196 bool Matched = false;
5197 while (const ArrayType *AT = Self.Context.getAsArrayType(T)) {
5198 if (Dim == D) {
5199 Matched = true;
5200 break;
5201 }
5202 ++D;
5203 T = AT->getElementType();
5204 }
5205
5206 if (Matched && T->isArrayType()) {
5207 if (const ConstantArrayType *CAT = Self.Context.getAsConstantArrayType(T))
5208 return CAT->getSize().getLimitedValue();
5209 }
5210 }
5211 return 0;
5212 }
5213 }
5214 llvm_unreachable("Unknown type trait or not implemented")::llvm::llvm_unreachable_internal("Unknown type trait or not implemented"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5214)
;
5215}
5216
5217ExprResult Sema::BuildArrayTypeTrait(ArrayTypeTrait ATT,
5218 SourceLocation KWLoc,
5219 TypeSourceInfo *TSInfo,
5220 Expr* DimExpr,
5221 SourceLocation RParen) {
5222 QualType T = TSInfo->getType();
5223
5224 // FIXME: This should likely be tracked as an APInt to remove any host
5225 // assumptions about the width of size_t on the target.
5226 uint64_t Value = 0;
5227 if (!T->isDependentType())
5228 Value = EvaluateArrayTypeTrait(*this, ATT, T, DimExpr, KWLoc);
5229
5230 // While the specification for these traits from the Embarcadero C++
5231 // compiler's documentation says the return type is 'unsigned int', Clang
5232 // returns 'size_t'. On Windows, the primary platform for the Embarcadero
5233 // compiler, there is no difference. On several other platforms this is an
5234 // important distinction.
5235 return new (Context) ArrayTypeTraitExpr(KWLoc, ATT, TSInfo, Value, DimExpr,
5236 RParen, Context.getSizeType());
5237}
5238
5239ExprResult Sema::ActOnExpressionTrait(ExpressionTrait ET,
5240 SourceLocation KWLoc,
5241 Expr *Queried,
5242 SourceLocation RParen) {
5243 // If error parsing the expression, ignore.
5244 if (!Queried)
5245 return ExprError();
5246
5247 ExprResult Result = BuildExpressionTrait(ET, KWLoc, Queried, RParen);
5248
5249 return Result;
5250}
5251
5252static bool EvaluateExpressionTrait(ExpressionTrait ET, Expr *E) {
5253 switch (ET) {
5254 case ET_IsLValueExpr: return E->isLValue();
5255 case ET_IsRValueExpr: return E->isRValue();
5256 }
5257 llvm_unreachable("Expression trait not covered by switch")::llvm::llvm_unreachable_internal("Expression trait not covered by switch"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5257)
;
5258}
5259
5260ExprResult Sema::BuildExpressionTrait(ExpressionTrait ET,
5261 SourceLocation KWLoc,
5262 Expr *Queried,
5263 SourceLocation RParen) {
5264 if (Queried->isTypeDependent()) {
5265 // Delay type-checking for type-dependent expressions.
5266 } else if (Queried->getType()->isPlaceholderType()) {
5267 ExprResult PE = CheckPlaceholderExpr(Queried);
5268 if (PE.isInvalid()) return ExprError();
5269 return BuildExpressionTrait(ET, KWLoc, PE.get(), RParen);
5270 }
5271
5272 bool Value = EvaluateExpressionTrait(ET, Queried);
5273
5274 return new (Context)
5275 ExpressionTraitExpr(KWLoc, ET, Queried, Value, RParen, Context.BoolTy);
5276}
5277
5278QualType Sema::CheckPointerToMemberOperands(ExprResult &LHS, ExprResult &RHS,
5279 ExprValueKind &VK,
5280 SourceLocation Loc,
5281 bool isIndirect) {
5282 assert(!LHS.get()->getType()->isPlaceholderType() &&(static_cast <bool> (!LHS.get()->getType()->isPlaceholderType
() && !RHS.get()->getType()->isPlaceholderType(
) && "placeholders should have been weeded out by now"
) ? void (0) : __assert_fail ("!LHS.get()->getType()->isPlaceholderType() && !RHS.get()->getType()->isPlaceholderType() && \"placeholders should have been weeded out by now\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5284, __extension__ __PRETTY_FUNCTION__))
5283 !RHS.get()->getType()->isPlaceholderType() &&(static_cast <bool> (!LHS.get()->getType()->isPlaceholderType
() && !RHS.get()->getType()->isPlaceholderType(
) && "placeholders should have been weeded out by now"
) ? void (0) : __assert_fail ("!LHS.get()->getType()->isPlaceholderType() && !RHS.get()->getType()->isPlaceholderType() && \"placeholders should have been weeded out by now\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5284, __extension__ __PRETTY_FUNCTION__))
5284 "placeholders should have been weeded out by now")(static_cast <bool> (!LHS.get()->getType()->isPlaceholderType
() && !RHS.get()->getType()->isPlaceholderType(
) && "placeholders should have been weeded out by now"
) ? void (0) : __assert_fail ("!LHS.get()->getType()->isPlaceholderType() && !RHS.get()->getType()->isPlaceholderType() && \"placeholders should have been weeded out by now\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5284, __extension__ __PRETTY_FUNCTION__))
;
5285
5286 // The LHS undergoes lvalue conversions if this is ->*, and undergoes the
5287 // temporary materialization conversion otherwise.
5288 if (isIndirect)
5289 LHS = DefaultLvalueConversion(LHS.get());
5290 else if (LHS.get()->isRValue())
5291 LHS = TemporaryMaterializationConversion(LHS.get());
5292 if (LHS.isInvalid())
5293 return QualType();
5294
5295 // The RHS always undergoes lvalue conversions.
5296 RHS = DefaultLvalueConversion(RHS.get());
5297 if (RHS.isInvalid()) return QualType();
5298
5299 const char *OpSpelling = isIndirect ? "->*" : ".*";
5300 // C++ 5.5p2
5301 // The binary operator .* [p3: ->*] binds its second operand, which shall
5302 // be of type "pointer to member of T" (where T is a completely-defined
5303 // class type) [...]
5304 QualType RHSType = RHS.get()->getType();
5305 const MemberPointerType *MemPtr = RHSType->getAs<MemberPointerType>();
5306 if (!MemPtr) {
5307 Diag(Loc, diag::err_bad_memptr_rhs)
5308 << OpSpelling << RHSType << RHS.get()->getSourceRange();
5309 return QualType();
5310 }
5311
5312 QualType Class(MemPtr->getClass(), 0);
5313
5314 // Note: C++ [expr.mptr.oper]p2-3 says that the class type into which the
5315 // member pointer points must be completely-defined. However, there is no
5316 // reason for this semantic distinction, and the rule is not enforced by
5317 // other compilers. Therefore, we do not check this property, as it is
5318 // likely to be considered a defect.
5319
5320 // C++ 5.5p2
5321 // [...] to its first operand, which shall be of class T or of a class of
5322 // which T is an unambiguous and accessible base class. [p3: a pointer to
5323 // such a class]
5324 QualType LHSType = LHS.get()->getType();
5325 if (isIndirect) {
5326 if (const PointerType *Ptr = LHSType->getAs<PointerType>())
5327 LHSType = Ptr->getPointeeType();
5328 else {
5329 Diag(Loc, diag::err_bad_memptr_lhs)
5330 << OpSpelling << 1 << LHSType
5331 << FixItHint::CreateReplacement(SourceRange(Loc), ".*");
5332 return QualType();
5333 }
5334 }
5335
5336 if (!Context.hasSameUnqualifiedType(Class, LHSType)) {
5337 // If we want to check the hierarchy, we need a complete type.
5338 if (RequireCompleteType(Loc, LHSType, diag::err_bad_memptr_lhs,
5339 OpSpelling, (int)isIndirect)) {
5340 return QualType();
5341 }
5342
5343 if (!IsDerivedFrom(Loc, LHSType, Class)) {
5344 Diag(Loc, diag::err_bad_memptr_lhs) << OpSpelling
5345 << (int)isIndirect << LHS.get()->getType();
5346 return QualType();
5347 }
5348
5349 CXXCastPath BasePath;
5350 if (CheckDerivedToBaseConversion(LHSType, Class, Loc,
5351 SourceRange(LHS.get()->getLocStart(),
5352 RHS.get()->getLocEnd()),
5353 &BasePath))
5354 return QualType();
5355
5356 // Cast LHS to type of use.
5357 QualType UseType = Context.getQualifiedType(Class, LHSType.getQualifiers());
5358 if (isIndirect)
5359 UseType = Context.getPointerType(UseType);
5360 ExprValueKind VK = isIndirect ? VK_RValue : LHS.get()->getValueKind();
5361 LHS = ImpCastExprToType(LHS.get(), UseType, CK_DerivedToBase, VK,
5362 &BasePath);
5363 }
5364
5365 if (isa<CXXScalarValueInitExpr>(RHS.get()->IgnoreParens())) {
5366 // Diagnose use of pointer-to-member type which when used as
5367 // the functional cast in a pointer-to-member expression.
5368 Diag(Loc, diag::err_pointer_to_member_type) << isIndirect;
5369 return QualType();
5370 }
5371
5372 // C++ 5.5p2
5373 // The result is an object or a function of the type specified by the
5374 // second operand.
5375 // The cv qualifiers are the union of those in the pointer and the left side,
5376 // in accordance with 5.5p5 and 5.2.5.
5377 QualType Result = MemPtr->getPointeeType();
5378 Result = Context.getCVRQualifiedType(Result, LHSType.getCVRQualifiers());
5379
5380 // C++0x [expr.mptr.oper]p6:
5381 // In a .* expression whose object expression is an rvalue, the program is
5382 // ill-formed if the second operand is a pointer to member function with
5383 // ref-qualifier &. In a ->* expression or in a .* expression whose object
5384 // expression is an lvalue, the program is ill-formed if the second operand
5385 // is a pointer to member function with ref-qualifier &&.
5386 if (const FunctionProtoType *Proto = Result->getAs<FunctionProtoType>()) {
5387 switch (Proto->getRefQualifier()) {
5388 case RQ_None:
5389 // Do nothing
5390 break;
5391
5392 case RQ_LValue:
5393 if (!isIndirect && !LHS.get()->Classify(Context).isLValue()) {
5394 // C++2a allows functions with ref-qualifier & if they are also 'const'.
5395 if (Proto->isConst())
5396 Diag(Loc, getLangOpts().CPlusPlus2a
5397 ? diag::warn_cxx17_compat_pointer_to_const_ref_member_on_rvalue
5398 : diag::ext_pointer_to_const_ref_member_on_rvalue);
5399 else
5400 Diag(Loc, diag::err_pointer_to_member_oper_value_classify)
5401 << RHSType << 1 << LHS.get()->getSourceRange();
5402 }
5403 break;
5404
5405 case RQ_RValue:
5406 if (isIndirect || !LHS.get()->Classify(Context).isRValue())
5407 Diag(Loc, diag::err_pointer_to_member_oper_value_classify)
5408 << RHSType << 0 << LHS.get()->getSourceRange();
5409 break;
5410 }
5411 }
5412
5413 // C++ [expr.mptr.oper]p6:
5414 // The result of a .* expression whose second operand is a pointer
5415 // to a data member is of the same value category as its
5416 // first operand. The result of a .* expression whose second
5417 // operand is a pointer to a member function is a prvalue. The
5418 // result of an ->* expression is an lvalue if its second operand
5419 // is a pointer to data member and a prvalue otherwise.
5420 if (Result->isFunctionType()) {
5421 VK = VK_RValue;
5422 return Context.BoundMemberTy;
5423 } else if (isIndirect) {
5424 VK = VK_LValue;
5425 } else {
5426 VK = LHS.get()->getValueKind();
5427 }
5428
5429 return Result;
5430}
5431
5432/// \brief Try to convert a type to another according to C++11 5.16p3.
5433///
5434/// This is part of the parameter validation for the ? operator. If either
5435/// value operand is a class type, the two operands are attempted to be
5436/// converted to each other. This function does the conversion in one direction.
5437/// It returns true if the program is ill-formed and has already been diagnosed
5438/// as such.
5439static bool TryClassUnification(Sema &Self, Expr *From, Expr *To,
5440 SourceLocation QuestionLoc,
5441 bool &HaveConversion,
5442 QualType &ToType) {
5443 HaveConversion = false;
5444 ToType = To->getType();
5445
5446 InitializationKind Kind = InitializationKind::CreateCopy(To->getLocStart(),
5447 SourceLocation());
5448 // C++11 5.16p3
5449 // The process for determining whether an operand expression E1 of type T1
5450 // can be converted to match an operand expression E2 of type T2 is defined
5451 // as follows:
5452 // -- If E2 is an lvalue: E1 can be converted to match E2 if E1 can be
5453 // implicitly converted to type "lvalue reference to T2", subject to the
5454 // constraint that in the conversion the reference must bind directly to
5455 // an lvalue.
5456 // -- If E2 is an xvalue: E1 can be converted to match E2 if E1 can be
5457 // implicitly converted to the type "rvalue reference to R2", subject to
5458 // the constraint that the reference must bind directly.
5459 if (To->isLValue() || To->isXValue()) {
5460 QualType T = To->isLValue() ? Self.Context.getLValueReferenceType(ToType)
5461 : Self.Context.getRValueReferenceType(ToType);
5462
5463 InitializedEntity Entity = InitializedEntity::InitializeTemporary(T);
5464
5465 InitializationSequence InitSeq(Self, Entity, Kind, From);
5466 if (InitSeq.isDirectReferenceBinding()) {
5467 ToType = T;
5468 HaveConversion = true;
5469 return false;
5470 }
5471
5472 if (InitSeq.isAmbiguous())
5473 return InitSeq.Diagnose(Self, Entity, Kind, From);
5474 }
5475
5476 // -- If E2 is an rvalue, or if the conversion above cannot be done:
5477 // -- if E1 and E2 have class type, and the underlying class types are
5478 // the same or one is a base class of the other:
5479 QualType FTy = From->getType();
5480 QualType TTy = To->getType();
5481 const RecordType *FRec = FTy->getAs<RecordType>();
5482 const RecordType *TRec = TTy->getAs<RecordType>();
5483 bool FDerivedFromT = FRec && TRec && FRec != TRec &&
5484 Self.IsDerivedFrom(QuestionLoc, FTy, TTy);
5485 if (FRec && TRec && (FRec == TRec || FDerivedFromT ||
5486 Self.IsDerivedFrom(QuestionLoc, TTy, FTy))) {
5487 // E1 can be converted to match E2 if the class of T2 is the
5488 // same type as, or a base class of, the class of T1, and
5489 // [cv2 > cv1].
5490 if (FRec == TRec || FDerivedFromT) {
5491 if (TTy.isAtLeastAsQualifiedAs(FTy)) {
5492 InitializedEntity Entity = InitializedEntity::InitializeTemporary(TTy);
5493 InitializationSequence InitSeq(Self, Entity, Kind, From);
5494 if (InitSeq) {
5495 HaveConversion = true;
5496 return false;
5497 }
5498
5499 if (InitSeq.isAmbiguous())
5500 return InitSeq.Diagnose(Self, Entity, Kind, From);
5501 }
5502 }
5503
5504 return false;
5505 }
5506
5507 // -- Otherwise: E1 can be converted to match E2 if E1 can be
5508 // implicitly converted to the type that expression E2 would have
5509 // if E2 were converted to an rvalue (or the type it has, if E2 is
5510 // an rvalue).
5511 //
5512 // This actually refers very narrowly to the lvalue-to-rvalue conversion, not
5513 // to the array-to-pointer or function-to-pointer conversions.
5514 TTy = TTy.getNonLValueExprType(Self.Context);
5515
5516 InitializedEntity Entity = InitializedEntity::InitializeTemporary(TTy);
5517 InitializationSequence InitSeq(Self, Entity, Kind, From);
5518 HaveConversion = !InitSeq.Failed();
5519 ToType = TTy;
5520 if (InitSeq.isAmbiguous())
5521 return InitSeq.Diagnose(Self, Entity, Kind, From);
5522
5523 return false;
5524}
5525
5526/// \brief Try to find a common type for two according to C++0x 5.16p5.
5527///
5528/// This is part of the parameter validation for the ? operator. If either
5529/// value operand is a class type, overload resolution is used to find a
5530/// conversion to a common type.
5531static bool FindConditionalOverload(Sema &Self, ExprResult &LHS, ExprResult &RHS,
5532 SourceLocation QuestionLoc) {
5533 Expr *Args[2] = { LHS.get(), RHS.get() };
5534 OverloadCandidateSet CandidateSet(QuestionLoc,
5535 OverloadCandidateSet::CSK_Operator);
5536 Self.AddBuiltinOperatorCandidates(OO_Conditional, QuestionLoc, Args,
5537 CandidateSet);
5538
5539 OverloadCandidateSet::iterator Best;
5540 switch (CandidateSet.BestViableFunction(Self, QuestionLoc, Best)) {
5541 case OR_Success: {
5542 // We found a match. Perform the conversions on the arguments and move on.
5543 ExprResult LHSRes = Self.PerformImplicitConversion(
5544 LHS.get(), Best->BuiltinParamTypes[0], Best->Conversions[0],
5545 Sema::AA_Converting);
5546 if (LHSRes.isInvalid())
5547 break;
5548 LHS = LHSRes;
5549
5550 ExprResult RHSRes = Self.PerformImplicitConversion(
5551 RHS.get(), Best->BuiltinParamTypes[1], Best->Conversions[1],
5552 Sema::AA_Converting);
5553 if (RHSRes.isInvalid())
5554 break;
5555 RHS = RHSRes;
5556 if (Best->Function)
5557 Self.MarkFunctionReferenced(QuestionLoc, Best->Function);
5558 return false;
5559 }
5560
5561 case OR_No_Viable_Function:
5562
5563 // Emit a better diagnostic if one of the expressions is a null pointer
5564 // constant and the other is a pointer type. In this case, the user most
5565 // likely forgot to take the address of the other expression.
5566 if (Self.DiagnoseConditionalForNull(LHS.get(), RHS.get(), QuestionLoc))
5567 return true;
5568
5569 Self.Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands)
5570 << LHS.get()->getType() << RHS.get()->getType()
5571 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
5572 return true;
5573
5574 case OR_Ambiguous:
5575 Self.Diag(QuestionLoc, diag::err_conditional_ambiguous_ovl)
5576 << LHS.get()->getType() << RHS.get()->getType()
5577 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
5578 // FIXME: Print the possible common types by printing the return types of
5579 // the viable candidates.
5580 break;
5581
5582 case OR_Deleted:
5583 llvm_unreachable("Conditional operator has only built-in overloads")::llvm::llvm_unreachable_internal("Conditional operator has only built-in overloads"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5583)
;
5584 }
5585 return true;
5586}
5587
5588/// \brief Perform an "extended" implicit conversion as returned by
5589/// TryClassUnification.
5590static bool ConvertForConditional(Sema &Self, ExprResult &E, QualType T) {
5591 InitializedEntity Entity = InitializedEntity::InitializeTemporary(T);
5592 InitializationKind Kind = InitializationKind::CreateCopy(E.get()->getLocStart(),
5593 SourceLocation());
5594 Expr *Arg = E.get();
5595 InitializationSequence InitSeq(Self, Entity, Kind, Arg);
5596 ExprResult Result = InitSeq.Perform(Self, Entity, Kind, Arg);
5597 if (Result.isInvalid())
5598 return true;
5599
5600 E = Result;
5601 return false;
5602}
5603
5604/// \brief Check the operands of ?: under C++ semantics.
5605///
5606/// See C++ [expr.cond]. Note that LHS is never null, even for the GNU x ?: y
5607/// extension. In this case, LHS == Cond. (But they're not aliases.)
5608QualType Sema::CXXCheckConditionalOperands(ExprResult &Cond, ExprResult &LHS,
5609 ExprResult &RHS, ExprValueKind &VK,
5610 ExprObjectKind &OK,
5611 SourceLocation QuestionLoc) {
5612 // FIXME: Handle C99's complex types, vector types, block pointers and Obj-C++
5613 // interface pointers.
5614
5615 // C++11 [expr.cond]p1
5616 // The first expression is contextually converted to bool.
5617 //
5618 // FIXME; GCC's vector extension permits the use of a?b:c where the type of
5619 // a is that of a integer vector with the same number of elements and
5620 // size as the vectors of b and c. If one of either b or c is a scalar
5621 // it is implicitly converted to match the type of the vector.
5622 // Otherwise the expression is ill-formed. If both b and c are scalars,
5623 // then b and c are checked and converted to the type of a if possible.
5624 // Unlike the OpenCL ?: operator, the expression is evaluated as
5625 // (a[0] != 0 ? b[0] : c[0], .. , a[n] != 0 ? b[n] : c[n]).
5626 if (!Cond.get()->isTypeDependent()) {
5627 ExprResult CondRes = CheckCXXBooleanCondition(Cond.get());
5628 if (CondRes.isInvalid())
5629 return QualType();
5630 Cond = CondRes;
5631 }
5632
5633 // Assume r-value.
5634 VK = VK_RValue;
5635 OK = OK_Ordinary;
5636
5637 // Either of the arguments dependent?
5638 if (LHS.get()->isTypeDependent() || RHS.get()->isTypeDependent())
5639 return Context.DependentTy;
5640
5641 // C++11 [expr.cond]p2
5642 // If either the second or the third operand has type (cv) void, ...
5643 QualType LTy = LHS.get()->getType();
5644 QualType RTy = RHS.get()->getType();
5645 bool LVoid = LTy->isVoidType();
5646 bool RVoid = RTy->isVoidType();
5647 if (LVoid || RVoid) {
5648 // ... one of the following shall hold:
5649 // -- The second or the third operand (but not both) is a (possibly
5650 // parenthesized) throw-expression; the result is of the type
5651 // and value category of the other.
5652 bool LThrow = isa<CXXThrowExpr>(LHS.get()->IgnoreParenImpCasts());
5653 bool RThrow = isa<CXXThrowExpr>(RHS.get()->IgnoreParenImpCasts());
5654 if (LThrow != RThrow) {
5655 Expr *NonThrow = LThrow ? RHS.get() : LHS.get();
5656 VK = NonThrow->getValueKind();
5657 // DR (no number yet): the result is a bit-field if the
5658 // non-throw-expression operand is a bit-field.
5659 OK = NonThrow->getObjectKind();
5660 return NonThrow->getType();
5661 }
5662
5663 // -- Both the second and third operands have type void; the result is of
5664 // type void and is a prvalue.
5665 if (LVoid && RVoid)
5666 return Context.VoidTy;
5667
5668 // Neither holds, error.
5669 Diag(QuestionLoc, diag::err_conditional_void_nonvoid)
5670 << (LVoid ? RTy : LTy) << (LVoid ? 0 : 1)
5671 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
5672 return QualType();
5673 }
5674
5675 // Neither is void.
5676
5677 // C++11 [expr.cond]p3
5678 // Otherwise, if the second and third operand have different types, and
5679 // either has (cv) class type [...] an attempt is made to convert each of
5680 // those operands to the type of the other.
5681 if (!Context.hasSameType(LTy, RTy) &&
5682 (LTy->isRecordType() || RTy->isRecordType())) {
5683 // These return true if a single direction is already ambiguous.
5684 QualType L2RType, R2LType;
5685 bool HaveL2R, HaveR2L;
5686 if (TryClassUnification(*this, LHS.get(), RHS.get(), QuestionLoc, HaveL2R, L2RType))
5687 return QualType();
5688 if (TryClassUnification(*this, RHS.get(), LHS.get(), QuestionLoc, HaveR2L, R2LType))
5689 return QualType();
5690
5691 // If both can be converted, [...] the program is ill-formed.
5692 if (HaveL2R && HaveR2L) {
5693 Diag(QuestionLoc, diag::err_conditional_ambiguous)
5694 << LTy << RTy << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
5695 return QualType();
5696 }
5697
5698 // If exactly one conversion is possible, that conversion is applied to
5699 // the chosen operand and the converted operands are used in place of the
5700 // original operands for the remainder of this section.
5701 if (HaveL2R) {
5702 if (ConvertForConditional(*this, LHS, L2RType) || LHS.isInvalid())
5703 return QualType();
5704 LTy = LHS.get()->getType();
5705 } else if (HaveR2L) {
5706 if (ConvertForConditional(*this, RHS, R2LType) || RHS.isInvalid())
5707 return QualType();
5708 RTy = RHS.get()->getType();
5709 }
5710 }
5711
5712 // C++11 [expr.cond]p3
5713 // if both are glvalues of the same value category and the same type except
5714 // for cv-qualification, an attempt is made to convert each of those
5715 // operands to the type of the other.
5716 // FIXME:
5717 // Resolving a defect in P0012R1: we extend this to cover all cases where
5718 // one of the operands is reference-compatible with the other, in order
5719 // to support conditionals between functions differing in noexcept.
5720 ExprValueKind LVK = LHS.get()->getValueKind();
5721 ExprValueKind RVK = RHS.get()->getValueKind();
5722 if (!Context.hasSameType(LTy, RTy) &&
5723 LVK == RVK && LVK != VK_RValue) {
5724 // DerivedToBase was already handled by the class-specific case above.
5725 // FIXME: Should we allow ObjC conversions here?
5726 bool DerivedToBase, ObjCConversion, ObjCLifetimeConversion;
5727 if (CompareReferenceRelationship(
5728 QuestionLoc, LTy, RTy, DerivedToBase,
5729 ObjCConversion, ObjCLifetimeConversion) == Ref_Compatible &&
5730 !DerivedToBase && !ObjCConversion && !ObjCLifetimeConversion &&
5731 // [...] subject to the constraint that the reference must bind
5732 // directly [...]
5733 !RHS.get()->refersToBitField() &&
5734 !RHS.get()->refersToVectorElement()) {
5735 RHS = ImpCastExprToType(RHS.get(), LTy, CK_NoOp, RVK);
5736 RTy = RHS.get()->getType();
5737 } else if (CompareReferenceRelationship(
5738 QuestionLoc, RTy, LTy, DerivedToBase,
5739 ObjCConversion, ObjCLifetimeConversion) == Ref_Compatible &&
5740 !DerivedToBase && !ObjCConversion && !ObjCLifetimeConversion &&
5741 !LHS.get()->refersToBitField() &&
5742 !LHS.get()->refersToVectorElement()) {
5743 LHS = ImpCastExprToType(LHS.get(), RTy, CK_NoOp, LVK);
5744 LTy = LHS.get()->getType();
5745 }
5746 }
5747
5748 // C++11 [expr.cond]p4
5749 // If the second and third operands are glvalues of the same value
5750 // category and have the same type, the result is of that type and
5751 // value category and it is a bit-field if the second or the third
5752 // operand is a bit-field, or if both are bit-fields.
5753 // We only extend this to bitfields, not to the crazy other kinds of
5754 // l-values.
5755 bool Same = Context.hasSameType(LTy, RTy);
5756 if (Same && LVK == RVK && LVK != VK_RValue &&
5757 LHS.get()->isOrdinaryOrBitFieldObject() &&
5758 RHS.get()->isOrdinaryOrBitFieldObject()) {
5759 VK = LHS.get()->getValueKind();
5760 if (LHS.get()->getObjectKind() == OK_BitField ||
5761 RHS.get()->getObjectKind() == OK_BitField)
5762 OK = OK_BitField;
5763
5764 // If we have function pointer types, unify them anyway to unify their
5765 // exception specifications, if any.
5766 if (LTy->isFunctionPointerType() || LTy->isMemberFunctionPointerType()) {
5767 Qualifiers Qs = LTy.getQualifiers();
5768 LTy = FindCompositePointerType(QuestionLoc, LHS, RHS,
5769 /*ConvertArgs*/false);
5770 LTy = Context.getQualifiedType(LTy, Qs);
5771
5772 assert(!LTy.isNull() && "failed to find composite pointer type for "(static_cast <bool> (!LTy.isNull() && "failed to find composite pointer type for "
"canonically equivalent function ptr types") ? void (0) : __assert_fail
("!LTy.isNull() && \"failed to find composite pointer type for \" \"canonically equivalent function ptr types\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5773, __extension__ __PRETTY_FUNCTION__))
5773 "canonically equivalent function ptr types")(static_cast <bool> (!LTy.isNull() && "failed to find composite pointer type for "
"canonically equivalent function ptr types") ? void (0) : __assert_fail
("!LTy.isNull() && \"failed to find composite pointer type for \" \"canonically equivalent function ptr types\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5773, __extension__ __PRETTY_FUNCTION__))
;
5774 assert(Context.hasSameType(LTy, RTy) && "bad composite pointer type")(static_cast <bool> (Context.hasSameType(LTy, RTy) &&
"bad composite pointer type") ? void (0) : __assert_fail ("Context.hasSameType(LTy, RTy) && \"bad composite pointer type\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5774, __extension__ __PRETTY_FUNCTION__))
;
5775 }
5776
5777 return LTy;
5778 }
5779
5780 // C++11 [expr.cond]p5
5781 // Otherwise, the result is a prvalue. If the second and third operands
5782 // do not have the same type, and either has (cv) class type, ...
5783 if (!Same && (LTy->isRecordType() || RTy->isRecordType())) {
5784 // ... overload resolution is used to determine the conversions (if any)
5785 // to be applied to the operands. If the overload resolution fails, the
5786 // program is ill-formed.
5787 if (FindConditionalOverload(*this, LHS, RHS, QuestionLoc))
5788 return QualType();
5789 }
5790
5791 // C++11 [expr.cond]p6
5792 // Lvalue-to-rvalue, array-to-pointer, and function-to-pointer standard
5793 // conversions are performed on the second and third operands.
5794 LHS = DefaultFunctionArrayLvalueConversion(LHS.get());
5795 RHS = DefaultFunctionArrayLvalueConversion(RHS.get());
5796 if (LHS.isInvalid() || RHS.isInvalid())
5797 return QualType();
5798 LTy = LHS.get()->getType();
5799 RTy = RHS.get()->getType();
5800
5801 // After those conversions, one of the following shall hold:
5802 // -- The second and third operands have the same type; the result
5803 // is of that type. If the operands have class type, the result
5804 // is a prvalue temporary of the result type, which is
5805 // copy-initialized from either the second operand or the third
5806 // operand depending on the value of the first operand.
5807 if (Context.getCanonicalType(LTy) == Context.getCanonicalType(RTy)) {
5808 if (LTy->isRecordType()) {
5809 // The operands have class type. Make a temporary copy.
5810 InitializedEntity Entity = InitializedEntity::InitializeTemporary(LTy);
5811
5812 ExprResult LHSCopy = PerformCopyInitialization(Entity,
5813 SourceLocation(),
5814 LHS);
5815 if (LHSCopy.isInvalid())
5816 return QualType();
5817
5818 ExprResult RHSCopy = PerformCopyInitialization(Entity,
5819 SourceLocation(),
5820 RHS);
5821 if (RHSCopy.isInvalid())
5822 return QualType();
5823
5824 LHS = LHSCopy;
5825 RHS = RHSCopy;
5826 }
5827
5828 // If we have function pointer types, unify them anyway to unify their
5829 // exception specifications, if any.
5830 if (LTy->isFunctionPointerType() || LTy->isMemberFunctionPointerType()) {
5831 LTy = FindCompositePointerType(QuestionLoc, LHS, RHS);
5832 assert(!LTy.isNull() && "failed to find composite pointer type for "(static_cast <bool> (!LTy.isNull() && "failed to find composite pointer type for "
"canonically equivalent function ptr types") ? void (0) : __assert_fail
("!LTy.isNull() && \"failed to find composite pointer type for \" \"canonically equivalent function ptr types\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5833, __extension__ __PRETTY_FUNCTION__))
5833 "canonically equivalent function ptr types")(static_cast <bool> (!LTy.isNull() && "failed to find composite pointer type for "
"canonically equivalent function ptr types") ? void (0) : __assert_fail
("!LTy.isNull() && \"failed to find composite pointer type for \" \"canonically equivalent function ptr types\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5833, __extension__ __PRETTY_FUNCTION__))
;
5834 }
5835
5836 return LTy;
5837 }
5838
5839 // Extension: conditional operator involving vector types.
5840 if (LTy->isVectorType() || RTy->isVectorType())
5841 return CheckVectorOperands(LHS, RHS, QuestionLoc, /*isCompAssign*/false,
5842 /*AllowBothBool*/true,
5843 /*AllowBoolConversions*/false);
5844
5845 // -- The second and third operands have arithmetic or enumeration type;
5846 // the usual arithmetic conversions are performed to bring them to a
5847 // common type, and the result is of that type.
5848 if (LTy->isArithmeticType() && RTy->isArithmeticType()) {
5849 QualType ResTy = UsualArithmeticConversions(LHS, RHS);
5850 if (LHS.isInvalid() || RHS.isInvalid())
5851 return QualType();
5852 if (ResTy.isNull()) {
5853 Diag(QuestionLoc,
5854 diag::err_typecheck_cond_incompatible_operands) << LTy << RTy
5855 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
5856 return QualType();
5857 }
5858
5859 LHS = ImpCastExprToType(LHS.get(), ResTy, PrepareScalarCast(LHS, ResTy));
5860 RHS = ImpCastExprToType(RHS.get(), ResTy, PrepareScalarCast(RHS, ResTy));
5861
5862 return ResTy;
5863 }
5864
5865 // -- The second and third operands have pointer type, or one has pointer
5866 // type and the other is a null pointer constant, or both are null
5867 // pointer constants, at least one of which is non-integral; pointer
5868 // conversions and qualification conversions are performed to bring them
5869 // to their composite pointer type. The result is of the composite
5870 // pointer type.
5871 // -- The second and third operands have pointer to member type, or one has
5872 // pointer to member type and the other is a null pointer constant;
5873 // pointer to member conversions and qualification conversions are
5874 // performed to bring them to a common type, whose cv-qualification
5875 // shall match the cv-qualification of either the second or the third
5876 // operand. The result is of the common type.
5877 QualType Composite = FindCompositePointerType(QuestionLoc, LHS, RHS);
5878 if (!Composite.isNull())
5879 return Composite;
5880
5881 // Similarly, attempt to find composite type of two objective-c pointers.
5882 Composite = FindCompositeObjCPointerType(LHS, RHS, QuestionLoc);
5883 if (!Composite.isNull())
5884 return Composite;
5885
5886 // Check if we are using a null with a non-pointer type.
5887 if (DiagnoseConditionalForNull(LHS.get(), RHS.get(), QuestionLoc))
5888 return QualType();
5889
5890 Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands)
5891 << LHS.get()->getType() << RHS.get()->getType()
5892 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
5893 return QualType();
5894}
5895
5896static FunctionProtoType::ExceptionSpecInfo
5897mergeExceptionSpecs(Sema &S, FunctionProtoType::ExceptionSpecInfo ESI1,
5898 FunctionProtoType::ExceptionSpecInfo ESI2,
5899 SmallVectorImpl<QualType> &ExceptionTypeStorage) {
5900 ExceptionSpecificationType EST1 = ESI1.Type;
5901 ExceptionSpecificationType EST2 = ESI2.Type;
5902
5903 // If either of them can throw anything, that is the result.
5904 if (EST1 == EST_None) return ESI1;
5905 if (EST2 == EST_None) return ESI2;
5906 if (EST1 == EST_MSAny) return ESI1;
5907 if (EST2 == EST_MSAny) return ESI2;
5908
5909 // If either of them is non-throwing, the result is the other.
5910 if (EST1 == EST_DynamicNone) return ESI2;
5911 if (EST2 == EST_DynamicNone) return ESI1;
5912 if (EST1 == EST_BasicNoexcept) return ESI2;
5913 if (EST2 == EST_BasicNoexcept) return ESI1;
5914
5915 // If either of them is a non-value-dependent computed noexcept, that
5916 // determines the result.
5917 if (EST2 == EST_ComputedNoexcept && ESI2.NoexceptExpr &&
5918 !ESI2.NoexceptExpr->isValueDependent())
5919 return !ESI2.NoexceptExpr->EvaluateKnownConstInt(S.Context) ? ESI2 : ESI1;
5920 if (EST1 == EST_ComputedNoexcept && ESI1.NoexceptExpr &&
5921 !ESI1.NoexceptExpr->isValueDependent())
5922 return !ESI1.NoexceptExpr->EvaluateKnownConstInt(S.Context) ? ESI1 : ESI2;
5923 // If we're left with value-dependent computed noexcept expressions, we're
5924 // stuck. Before C++17, we can just drop the exception specification entirely,
5925 // since it's not actually part of the canonical type. And this should never
5926 // happen in C++17, because it would mean we were computing the composite
5927 // pointer type of dependent types, which should never happen.
5928 if (EST1 == EST_ComputedNoexcept || EST2 == EST_ComputedNoexcept) {
5929 assert(!S.getLangOpts().CPlusPlus17 &&(static_cast <bool> (!S.getLangOpts().CPlusPlus17 &&
"computing composite pointer type of dependent types") ? void
(0) : __assert_fail ("!S.getLangOpts().CPlusPlus17 && \"computing composite pointer type of dependent types\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5930, __extension__ __PRETTY_FUNCTION__))
5930 "computing composite pointer type of dependent types")(static_cast <bool> (!S.getLangOpts().CPlusPlus17 &&
"computing composite pointer type of dependent types") ? void
(0) : __assert_fail ("!S.getLangOpts().CPlusPlus17 && \"computing composite pointer type of dependent types\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5930, __extension__ __PRETTY_FUNCTION__))
;
5931 return FunctionProtoType::ExceptionSpecInfo();
5932 }
5933
5934 // Switch over the possibilities so that people adding new values know to
5935 // update this function.
5936 switch (EST1) {
5937 case EST_None:
5938 case EST_DynamicNone:
5939 case EST_MSAny:
5940 case EST_BasicNoexcept:
5941 case EST_ComputedNoexcept:
5942 llvm_unreachable("handled above")::llvm::llvm_unreachable_internal("handled above", "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5942)
;
5943
5944 case EST_Dynamic: {
5945 // This is the fun case: both exception specifications are dynamic. Form
5946 // the union of the two lists.
5947 assert(EST2 == EST_Dynamic && "other cases should already be handled")(static_cast <bool> (EST2 == EST_Dynamic && "other cases should already be handled"
) ? void (0) : __assert_fail ("EST2 == EST_Dynamic && \"other cases should already be handled\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5947, __extension__ __PRETTY_FUNCTION__))
;
5948 llvm::SmallPtrSet<QualType, 8> Found;
5949 for (auto &Exceptions : {ESI1.Exceptions, ESI2.Exceptions})
5950 for (QualType E : Exceptions)
5951 if (Found.insert(S.Context.getCanonicalType(E)).second)
5952 ExceptionTypeStorage.push_back(E);
5953
5954 FunctionProtoType::ExceptionSpecInfo Result(EST_Dynamic);
5955 Result.Exceptions = ExceptionTypeStorage;
5956 return Result;
5957 }
5958
5959 case EST_Unevaluated:
5960 case EST_Uninstantiated:
5961 case EST_Unparsed:
5962 llvm_unreachable("shouldn't see unresolved exception specifications here")::llvm::llvm_unreachable_internal("shouldn't see unresolved exception specifications here"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5962)
;
5963 }
5964
5965 llvm_unreachable("invalid ExceptionSpecificationType")::llvm::llvm_unreachable_internal("invalid ExceptionSpecificationType"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5965)
;
5966}
5967
5968/// \brief Find a merged pointer type and convert the two expressions to it.
5969///
5970/// This finds the composite pointer type (or member pointer type) for @p E1
5971/// and @p E2 according to C++1z 5p14. It converts both expressions to this
5972/// type and returns it.
5973/// It does not emit diagnostics.
5974///
5975/// \param Loc The location of the operator requiring these two expressions to
5976/// be converted to the composite pointer type.
5977///
5978/// \param ConvertArgs If \c false, do not convert E1 and E2 to the target type.
5979QualType Sema::FindCompositePointerType(SourceLocation Loc,
5980 Expr *&E1, Expr *&E2,
5981 bool ConvertArgs) {
5982 assert(getLangOpts().CPlusPlus && "This function assumes C++")(static_cast <bool> (getLangOpts().CPlusPlus &&
"This function assumes C++") ? void (0) : __assert_fail ("getLangOpts().CPlusPlus && \"This function assumes C++\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 5982, __extension__ __PRETTY_FUNCTION__))
;
5983
5984 // C++1z [expr]p14:
5985 // The composite pointer type of two operands p1 and p2 having types T1
5986 // and T2
5987 QualType T1 = E1->getType(), T2 = E2->getType();
5988
5989 // where at least one is a pointer or pointer to member type or
5990 // std::nullptr_t is:
5991 bool T1IsPointerLike = T1->isAnyPointerType() || T1->isMemberPointerType() ||
5992 T1->isNullPtrType();
5993 bool T2IsPointerLike = T2->isAnyPointerType() || T2->isMemberPointerType() ||
5994 T2->isNullPtrType();
5995 if (!T1IsPointerLike && !T2IsPointerLike)
5996 return QualType();
5997
5998 // - if both p1 and p2 are null pointer constants, std::nullptr_t;
5999 // This can't actually happen, following the standard, but we also use this
6000 // to implement the end of [expr.conv], which hits this case.
6001 //
6002 // - if either p1 or p2 is a null pointer constant, T2 or T1, respectively;
6003 if (T1IsPointerLike &&
6004 E2->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNull)) {
6005 if (ConvertArgs)
6006 E2 = ImpCastExprToType(E2, T1, T1->isMemberPointerType()
6007 ? CK_NullToMemberPointer
6008 : CK_NullToPointer).get();
6009 return T1;
6010 }
6011 if (T2IsPointerLike &&
6012 E1->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNull)) {
6013 if (ConvertArgs)
6014 E1 = ImpCastExprToType(E1, T2, T2->isMemberPointerType()
6015 ? CK_NullToMemberPointer
6016 : CK_NullToPointer).get();
6017 return T2;
6018 }
6019
6020 // Now both have to be pointers or member pointers.
6021 if (!T1IsPointerLike || !T2IsPointerLike)
6022 return QualType();
6023 assert(!T1->isNullPtrType() && !T2->isNullPtrType() &&(static_cast <bool> (!T1->isNullPtrType() &&
!T2->isNullPtrType() && "nullptr_t should be a null pointer constant"
) ? void (0) : __assert_fail ("!T1->isNullPtrType() && !T2->isNullPtrType() && \"nullptr_t should be a null pointer constant\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 6024, __extension__ __PRETTY_FUNCTION__))
6024 "nullptr_t should be a null pointer constant")(static_cast <bool> (!T1->isNullPtrType() &&
!T2->isNullPtrType() && "nullptr_t should be a null pointer constant"
) ? void (0) : __assert_fail ("!T1->isNullPtrType() && !T2->isNullPtrType() && \"nullptr_t should be a null pointer constant\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 6024, __extension__ __PRETTY_FUNCTION__))
;
6025
6026 // - if T1 or T2 is "pointer to cv1 void" and the other type is
6027 // "pointer to cv2 T", "pointer to cv12 void", where cv12 is
6028 // the union of cv1 and cv2;
6029 // - if T1 or T2 is "pointer to noexcept function" and the other type is
6030 // "pointer to function", where the function types are otherwise the same,
6031 // "pointer to function";
6032 // FIXME: This rule is defective: it should also permit removing noexcept
6033 // from a pointer to member function. As a Clang extension, we also
6034 // permit removing 'noreturn', so we generalize this rule to;
6035 // - [Clang] If T1 and T2 are both of type "pointer to function" or
6036 // "pointer to member function" and the pointee types can be unified
6037 // by a function pointer conversion, that conversion is applied
6038 // before checking the following rules.
6039 // - if T1 is "pointer to cv1 C1" and T2 is "pointer to cv2 C2", where C1
6040 // is reference-related to C2 or C2 is reference-related to C1 (8.6.3),
6041 // the cv-combined type of T1 and T2 or the cv-combined type of T2 and T1,
6042 // respectively;
6043 // - if T1 is "pointer to member of C1 of type cv1 U1" and T2 is "pointer
6044 // to member of C2 of type cv2 U2" where C1 is reference-related to C2 or
6045 // C2 is reference-related to C1 (8.6.3), the cv-combined type of T2 and
6046 // T1 or the cv-combined type of T1 and T2, respectively;
6047 // - if T1 and T2 are similar types (4.5), the cv-combined type of T1 and
6048 // T2;
6049 //
6050 // If looked at in the right way, these bullets all do the same thing.
6051 // What we do here is, we build the two possible cv-combined types, and try
6052 // the conversions in both directions. If only one works, or if the two
6053 // composite types are the same, we have succeeded.
6054 // FIXME: extended qualifiers?
6055 //
6056 // Note that this will fail to find a composite pointer type for "pointer
6057 // to void" and "pointer to function". We can't actually perform the final
6058 // conversion in this case, even though a composite pointer type formally
6059 // exists.
6060 SmallVector<unsigned, 4> QualifierUnion;
6061 SmallVector<std::pair<const Type *, const Type *>, 4> MemberOfClass;
6062 QualType Composite1 = T1;
6063 QualType Composite2 = T2;
6064 unsigned NeedConstBefore = 0;
6065 while (true) {
6066 const PointerType *Ptr1, *Ptr2;
6067 if ((Ptr1 = Composite1->getAs<PointerType>()) &&
6068 (Ptr2 = Composite2->getAs<PointerType>())) {
6069 Composite1 = Ptr1->getPointeeType();
6070 Composite2 = Ptr2->getPointeeType();
6071
6072 // If we're allowed to create a non-standard composite type, keep track
6073 // of where we need to fill in additional 'const' qualifiers.
6074 if (Composite1.getCVRQualifiers() != Composite2.getCVRQualifiers())
6075 NeedConstBefore = QualifierUnion.size();
6076
6077 QualifierUnion.push_back(
6078 Composite1.getCVRQualifiers() | Composite2.getCVRQualifiers());
6079 MemberOfClass.push_back(std::make_pair(nullptr, nullptr));
6080 continue;
6081 }
6082
6083 const MemberPointerType *MemPtr1, *MemPtr2;
6084 if ((MemPtr1 = Composite1->getAs<MemberPointerType>()) &&
6085 (MemPtr2 = Composite2->getAs<MemberPointerType>())) {
6086 Composite1 = MemPtr1->getPointeeType();
6087 Composite2 = MemPtr2->getPointeeType();
6088
6089 // If we're allowed to create a non-standard composite type, keep track
6090 // of where we need to fill in additional 'const' qualifiers.
6091 if (Composite1.getCVRQualifiers() != Composite2.getCVRQualifiers())
6092 NeedConstBefore = QualifierUnion.size();
6093
6094 QualifierUnion.push_back(
6095 Composite1.getCVRQualifiers() | Composite2.getCVRQualifiers());
6096 MemberOfClass.push_back(std::make_pair(MemPtr1->getClass(),
6097 MemPtr2->getClass()));
6098 continue;
6099 }
6100
6101 // FIXME: block pointer types?
6102
6103 // Cannot unwrap any more types.
6104 break;
6105 }
6106
6107 // Apply the function pointer conversion to unify the types. We've already
6108 // unwrapped down to the function types, and we want to merge rather than
6109 // just convert, so do this ourselves rather than calling
6110 // IsFunctionConversion.
6111 //
6112 // FIXME: In order to match the standard wording as closely as possible, we
6113 // currently only do this under a single level of pointers. Ideally, we would
6114 // allow this in general, and set NeedConstBefore to the relevant depth on
6115 // the side(s) where we changed anything.
6116 if (QualifierUnion.size() == 1) {
6117 if (auto *FPT1 = Composite1->getAs<FunctionProtoType>()) {
6118 if (auto *FPT2 = Composite2->getAs<FunctionProtoType>()) {
6119 FunctionProtoType::ExtProtoInfo EPI1 = FPT1->getExtProtoInfo();
6120 FunctionProtoType::ExtProtoInfo EPI2 = FPT2->getExtProtoInfo();
6121
6122 // The result is noreturn if both operands are.
6123 bool Noreturn =
6124 EPI1.ExtInfo.getNoReturn() && EPI2.ExtInfo.getNoReturn();
6125 EPI1.ExtInfo = EPI1.ExtInfo.withNoReturn(Noreturn);
6126 EPI2.ExtInfo = EPI2.ExtInfo.withNoReturn(Noreturn);
6127
6128 // The result is nothrow if both operands are.
6129 SmallVector<QualType, 8> ExceptionTypeStorage;
6130 EPI1.ExceptionSpec = EPI2.ExceptionSpec =
6131 mergeExceptionSpecs(*this, EPI1.ExceptionSpec, EPI2.ExceptionSpec,
6132 ExceptionTypeStorage);
6133
6134 Composite1 = Context.getFunctionType(FPT1->getReturnType(),
6135 FPT1->getParamTypes(), EPI1);
6136 Composite2 = Context.getFunctionType(FPT2->getReturnType(),
6137 FPT2->getParamTypes(), EPI2);
6138 }
6139 }
6140 }
6141
6142 if (NeedConstBefore) {
6143 // Extension: Add 'const' to qualifiers that come before the first qualifier
6144 // mismatch, so that our (non-standard!) composite type meets the
6145 // requirements of C++ [conv.qual]p4 bullet 3.
6146 for (unsigned I = 0; I != NeedConstBefore; ++I)
6147 if ((QualifierUnion[I] & Qualifiers::Const) == 0)
6148 QualifierUnion[I] = QualifierUnion[I] | Qualifiers::Const;
6149 }
6150
6151 // Rewrap the composites as pointers or member pointers with the union CVRs.
6152 auto MOC = MemberOfClass.rbegin();
6153 for (unsigned CVR : llvm::reverse(QualifierUnion)) {
6154 Qualifiers Quals = Qualifiers::fromCVRMask(CVR);
6155 auto Classes = *MOC++;
6156 if (Classes.first && Classes.second) {
6157 // Rebuild member pointer type
6158 Composite1 = Context.getMemberPointerType(
6159 Context.getQualifiedType(Composite1, Quals), Classes.first);
6160 Composite2 = Context.getMemberPointerType(
6161 Context.getQualifiedType(Composite2, Quals), Classes.second);
6162 } else {
6163 // Rebuild pointer type
6164 Composite1 =
6165 Context.getPointerType(Context.getQualifiedType(Composite1, Quals));
6166 Composite2 =
6167 Context.getPointerType(Context.getQualifiedType(Composite2, Quals));
6168 }
6169 }
6170
6171 struct Conversion {
6172 Sema &S;
6173 Expr *&E1, *&E2;
6174 QualType Composite;
6175 InitializedEntity Entity;
6176 InitializationKind Kind;
6177 InitializationSequence E1ToC, E2ToC;
6178 bool Viable;
6179
6180 Conversion(Sema &S, SourceLocation Loc, Expr *&E1, Expr *&E2,
6181 QualType Composite)
6182 : S(S), E1(E1), E2(E2), Composite(Composite),
6183 Entity(InitializedEntity::InitializeTemporary(Composite)),
6184 Kind(InitializationKind::CreateCopy(Loc, SourceLocation())),
6185 E1ToC(S, Entity, Kind, E1), E2ToC(S, Entity, Kind, E2),
6186 Viable(E1ToC && E2ToC) {}
6187
6188 bool perform() {
6189 ExprResult E1Result = E1ToC.Perform(S, Entity, Kind, E1);
6190 if (E1Result.isInvalid())
6191 return true;
6192 E1 = E1Result.getAs<Expr>();
6193
6194 ExprResult E2Result = E2ToC.Perform(S, Entity, Kind, E2);
6195 if (E2Result.isInvalid())
6196 return true;
6197 E2 = E2Result.getAs<Expr>();
6198
6199 return false;
6200 }
6201 };
6202
6203 // Try to convert to each composite pointer type.
6204 Conversion C1(*this, Loc, E1, E2, Composite1);
6205 if (C1.Viable && Context.hasSameType(Composite1, Composite2)) {
6206 if (ConvertArgs && C1.perform())
6207 return QualType();
6208 return C1.Composite;
6209 }
6210 Conversion C2(*this, Loc, E1, E2, Composite2);
6211
6212 if (C1.Viable == C2.Viable) {
6213 // Either Composite1 and Composite2 are viable and are different, or
6214 // neither is viable.
6215 // FIXME: How both be viable and different?
6216 return QualType();
6217 }
6218
6219 // Convert to the chosen type.
6220 if (ConvertArgs && (C1.Viable ? C1 : C2).perform())
6221 return QualType();
6222
6223 return C1.Viable ? C1.Composite : C2.Composite;
6224}
6225
6226ExprResult Sema::MaybeBindToTemporary(Expr *E) {
6227 if (!E)
6228 return ExprError();
6229
6230 assert(!isa<CXXBindTemporaryExpr>(E) && "Double-bound temporary?")(static_cast <bool> (!isa<CXXBindTemporaryExpr>(E
) && "Double-bound temporary?") ? void (0) : __assert_fail
("!isa<CXXBindTemporaryExpr>(E) && \"Double-bound temporary?\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 6230, __extension__ __PRETTY_FUNCTION__))
;
6231
6232 // If the result is a glvalue, we shouldn't bind it.
6233 if (!E->isRValue())
6234 return E;
6235
6236 // In ARC, calls that return a retainable type can return retained,
6237 // in which case we have to insert a consuming cast.
6238 if (getLangOpts().ObjCAutoRefCount &&
6239 E->getType()->isObjCRetainableType()) {
6240
6241 bool ReturnsRetained;
6242
6243 // For actual calls, we compute this by examining the type of the
6244 // called value.
6245 if (CallExpr *Call = dyn_cast<CallExpr>(E)) {
6246 Expr *Callee = Call->getCallee()->IgnoreParens();
6247 QualType T = Callee->getType();
6248
6249 if (T == Context.BoundMemberTy) {
6250 // Handle pointer-to-members.
6251 if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(Callee))
6252 T = BinOp->getRHS()->getType();
6253 else if (MemberExpr *Mem = dyn_cast<MemberExpr>(Callee))
6254 T = Mem->getMemberDecl()->getType();
6255 }
6256
6257 if (const PointerType *Ptr = T->getAs<PointerType>())
6258 T = Ptr->getPointeeType();
6259 else if (const BlockPointerType *Ptr = T->getAs<BlockPointerType>())
6260 T = Ptr->getPointeeType();
6261 else if (const MemberPointerType *MemPtr = T->getAs<MemberPointerType>())
6262 T = MemPtr->getPointeeType();
6263
6264 const FunctionType *FTy = T->getAs<FunctionType>();
6265 assert(FTy && "call to value not of function type?")(static_cast <bool> (FTy && "call to value not of function type?"
) ? void (0) : __assert_fail ("FTy && \"call to value not of function type?\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 6265, __extension__ __PRETTY_FUNCTION__))
;
6266 ReturnsRetained = FTy->getExtInfo().getProducesResult();
6267
6268 // ActOnStmtExpr arranges things so that StmtExprs of retainable
6269 // type always produce a +1 object.
6270 } else if (isa<StmtExpr>(E)) {
6271 ReturnsRetained = true;
6272
6273 // We hit this case with the lambda conversion-to-block optimization;
6274 // we don't want any extra casts here.
6275 } else if (isa<CastExpr>(E) &&
6276 isa<BlockExpr>(cast<CastExpr>(E)->getSubExpr())) {
6277 return E;
6278
6279 // For message sends and property references, we try to find an
6280 // actual method. FIXME: we should infer retention by selector in
6281 // cases where we don't have an actual method.
6282 } else {
6283 ObjCMethodDecl *D = nullptr;
6284 if (ObjCMessageExpr *Send = dyn_cast<ObjCMessageExpr>(E)) {
6285 D = Send->getMethodDecl();
6286 } else if (ObjCBoxedExpr *BoxedExpr = dyn_cast<ObjCBoxedExpr>(E)) {
6287 D = BoxedExpr->getBoxingMethod();
6288 } else if (ObjCArrayLiteral *ArrayLit = dyn_cast<ObjCArrayLiteral>(E)) {
6289 // Don't do reclaims if we're using the zero-element array
6290 // constant.
6291 if (ArrayLit->getNumElements() == 0 &&
6292 Context.getLangOpts().ObjCRuntime.hasEmptyCollections())
6293 return E;
6294
6295 D = ArrayLit->getArrayWithObjectsMethod();
6296 } else if (ObjCDictionaryLiteral *DictLit
6297 = dyn_cast<ObjCDictionaryLiteral>(E)) {
6298 // Don't do reclaims if we're using the zero-element dictionary
6299 // constant.
6300 if (DictLit->getNumElements() == 0 &&
6301 Context.getLangOpts().ObjCRuntime.hasEmptyCollections())
6302 return E;
6303
6304 D = DictLit->getDictWithObjectsMethod();
6305 }
6306
6307 ReturnsRetained = (D && D->hasAttr<NSReturnsRetainedAttr>());
6308
6309 // Don't do reclaims on performSelector calls; despite their
6310 // return type, the invoked method doesn't necessarily actually
6311 // return an object.
6312 if (!ReturnsRetained &&
6313 D && D->getMethodFamily() == OMF_performSelector)
6314 return E;
6315 }
6316
6317 // Don't reclaim an object of Class type.
6318 if (!ReturnsRetained && E->getType()->isObjCARCImplicitlyUnretainedType())
6319 return E;
6320
6321 Cleanup.setExprNeedsCleanups(true);
6322
6323 CastKind ck = (ReturnsRetained ? CK_ARCConsumeObject
6324 : CK_ARCReclaimReturnedObject);
6325 return ImplicitCastExpr::Create(Context, E->getType(), ck, E, nullptr,
6326 VK_RValue);
6327 }
6328
6329 if (!getLangOpts().CPlusPlus)
6330 return E;
6331
6332 // Search for the base element type (cf. ASTContext::getBaseElementType) with
6333 // a fast path for the common case that the type is directly a RecordType.
6334 const Type *T = Context.getCanonicalType(E->getType().getTypePtr());
6335 const RecordType *RT = nullptr;
6336 while (!RT) {
6337 switch (T->getTypeClass()) {
6338 case Type::Record:
6339 RT = cast<RecordType>(T);
6340 break;
6341 case Type::ConstantArray:
6342 case Type::IncompleteArray:
6343 case Type::VariableArray:
6344 case Type::DependentSizedArray:
6345 T = cast<ArrayType>(T)->getElementType().getTypePtr();
6346 break;
6347 default:
6348 return E;
6349 }
6350 }
6351
6352 // That should be enough to guarantee that this type is complete, if we're
6353 // not processing a decltype expression.
6354 CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
6355 if (RD->isInvalidDecl() || RD->isDependentContext())
6356 return E;
6357
6358 bool IsDecltype = ExprEvalContexts.back().IsDecltype;
6359 CXXDestructorDecl *Destructor = IsDecltype ? nullptr : LookupDestructor(RD);
6360
6361 if (Destructor) {
6362 MarkFunctionReferenced(E->getExprLoc(), Destructor);
6363 CheckDestructorAccess(E->getExprLoc(), Destructor,
6364 PDiag(diag::err_access_dtor_temp)
6365 << E->getType());
6366 if (DiagnoseUseOfDecl(Destructor, E->getExprLoc()))
6367 return ExprError();
6368
6369 // If destructor is trivial, we can avoid the extra copy.
6370 if (Destructor->isTrivial())
6371 return E;
6372
6373 // We need a cleanup, but we don't need to remember the temporary.
6374 Cleanup.setExprNeedsCleanups(true);
6375 }
6376
6377 CXXTemporary *Temp = CXXTemporary::Create(Context, Destructor);
6378 CXXBindTemporaryExpr *Bind = CXXBindTemporaryExpr::Create(Context, Temp, E);
6379
6380 if (IsDecltype)
6381 ExprEvalContexts.back().DelayedDecltypeBinds.push_back(Bind);
6382
6383 return Bind;
6384}
6385
6386ExprResult
6387Sema::MaybeCreateExprWithCleanups(ExprResult SubExpr) {
6388 if (SubExpr.isInvalid())
6389 return ExprError();
6390
6391 return MaybeCreateExprWithCleanups(SubExpr.get());
6392}
6393
6394Expr *Sema::MaybeCreateExprWithCleanups(Expr *SubExpr) {
6395 assert(SubExpr && "subexpression can't be null!")(static_cast <bool> (SubExpr && "subexpression can't be null!"
) ? void (0) : __assert_fail ("SubExpr && \"subexpression can't be null!\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 6395, __extension__ __PRETTY_FUNCTION__))
;
6396
6397 CleanupVarDeclMarking();
6398
6399 unsigned FirstCleanup = ExprEvalContexts.back().NumCleanupObjects;
6400 assert(ExprCleanupObjects.size() >= FirstCleanup)(static_cast <bool> (ExprCleanupObjects.size() >= FirstCleanup
) ? void (0) : __assert_fail ("ExprCleanupObjects.size() >= FirstCleanup"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 6400, __extension__ __PRETTY_FUNCTION__))
;
6401 assert(Cleanup.exprNeedsCleanups() ||(static_cast <bool> (Cleanup.exprNeedsCleanups() || ExprCleanupObjects
.size() == FirstCleanup) ? void (0) : __assert_fail ("Cleanup.exprNeedsCleanups() || ExprCleanupObjects.size() == FirstCleanup"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 6402, __extension__ __PRETTY_FUNCTION__))
6402 ExprCleanupObjects.size() == FirstCleanup)(static_cast <bool> (Cleanup.exprNeedsCleanups() || ExprCleanupObjects
.size() == FirstCleanup) ? void (0) : __assert_fail ("Cleanup.exprNeedsCleanups() || ExprCleanupObjects.size() == FirstCleanup"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 6402, __extension__ __PRETTY_FUNCTION__))
;
6403 if (!Cleanup.exprNeedsCleanups())
6404 return SubExpr;
6405
6406 auto Cleanups = llvm::makeArrayRef(ExprCleanupObjects.begin() + FirstCleanup,
6407 ExprCleanupObjects.size() - FirstCleanup);
6408
6409 auto *E = ExprWithCleanups::Create(
6410 Context, SubExpr, Cleanup.cleanupsHaveSideEffects(), Cleanups);
6411 DiscardCleanupsInEvaluationContext();
6412
6413 return E;
6414}
6415
6416Stmt *Sema::MaybeCreateStmtWithCleanups(Stmt *SubStmt) {
6417 assert(SubStmt && "sub-statement can't be null!")(static_cast <bool> (SubStmt && "sub-statement can't be null!"
) ? void (0) : __assert_fail ("SubStmt && \"sub-statement can't be null!\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 6417, __extension__ __PRETTY_FUNCTION__))
;
6418
6419 CleanupVarDeclMarking();
6420
6421 if (!Cleanup.exprNeedsCleanups())
6422 return SubStmt;
6423
6424 // FIXME: In order to attach the temporaries, wrap the statement into
6425 // a StmtExpr; currently this is only used for asm statements.
6426 // This is hacky, either create a new CXXStmtWithTemporaries statement or
6427 // a new AsmStmtWithTemporaries.
6428 CompoundStmt *CompStmt = CompoundStmt::Create(
6429 Context, SubStmt, SourceLocation(), SourceLocation());
6430 Expr *E = new (Context) StmtExpr(CompStmt, Context.VoidTy, SourceLocation(),
6431 SourceLocation());
6432 return MaybeCreateExprWithCleanups(E);
6433}
6434
6435/// Process the expression contained within a decltype. For such expressions,
6436/// certain semantic checks on temporaries are delayed until this point, and
6437/// are omitted for the 'topmost' call in the decltype expression. If the
6438/// topmost call bound a temporary, strip that temporary off the expression.
6439ExprResult Sema::ActOnDecltypeExpression(Expr *E) {
6440 assert(ExprEvalContexts.back().IsDecltype && "not in a decltype expression")(static_cast <bool> (ExprEvalContexts.back().IsDecltype
&& "not in a decltype expression") ? void (0) : __assert_fail
("ExprEvalContexts.back().IsDecltype && \"not in a decltype expression\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 6440, __extension__ __PRETTY_FUNCTION__))
;
6441
6442 // C++11 [expr.call]p11:
6443 // If a function call is a prvalue of object type,
6444 // -- if the function call is either
6445 // -- the operand of a decltype-specifier, or
6446 // -- the right operand of a comma operator that is the operand of a
6447 // decltype-specifier,
6448 // a temporary object is not introduced for the prvalue.
6449
6450 // Recursively rebuild ParenExprs and comma expressions to strip out the
6451 // outermost CXXBindTemporaryExpr, if any.
6452 if (ParenExpr *PE = dyn_cast<ParenExpr>(E)) {
6453 ExprResult SubExpr = ActOnDecltypeExpression(PE->getSubExpr());
6454 if (SubExpr.isInvalid())
6455 return ExprError();
6456 if (SubExpr.get() == PE->getSubExpr())
6457 return E;
6458 return ActOnParenExpr(PE->getLParen(), PE->getRParen(), SubExpr.get());
6459 }
6460 if (BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
6461 if (BO->getOpcode() == BO_Comma) {
6462 ExprResult RHS = ActOnDecltypeExpression(BO->getRHS());
6463 if (RHS.isInvalid())
6464 return ExprError();
6465 if (RHS.get() == BO->getRHS())
6466 return E;
6467 return new (Context) BinaryOperator(
6468 BO->getLHS(), RHS.get(), BO_Comma, BO->getType(), BO->getValueKind(),
6469 BO->getObjectKind(), BO->getOperatorLoc(), BO->getFPFeatures());
6470 }
6471 }
6472
6473 CXXBindTemporaryExpr *TopBind = dyn_cast<CXXBindTemporaryExpr>(E);
6474 CallExpr *TopCall = TopBind ? dyn_cast<CallExpr>(TopBind->getSubExpr())
6475 : nullptr;
6476 if (TopCall)
6477 E = TopCall;
6478 else
6479 TopBind = nullptr;
6480
6481 // Disable the special decltype handling now.
6482 ExprEvalContexts.back().IsDecltype = false;
6483
6484 // In MS mode, don't perform any extra checking of call return types within a
6485 // decltype expression.
6486 if (getLangOpts().MSVCCompat)
6487 return E;
6488
6489 // Perform the semantic checks we delayed until this point.
6490 for (unsigned I = 0, N = ExprEvalContexts.back().DelayedDecltypeCalls.size();
6491 I != N; ++I) {
6492 CallExpr *Call = ExprEvalContexts.back().DelayedDecltypeCalls[I];
6493 if (Call == TopCall)
6494 continue;
6495
6496 if (CheckCallReturnType(Call->getCallReturnType(Context),
6497 Call->getLocStart(),
6498 Call, Call->getDirectCallee()))
6499 return ExprError();
6500 }
6501
6502 // Now all relevant types are complete, check the destructors are accessible
6503 // and non-deleted, and annotate them on the temporaries.
6504 for (unsigned I = 0, N = ExprEvalContexts.back().DelayedDecltypeBinds.size();
6505 I != N; ++I) {
6506 CXXBindTemporaryExpr *Bind =
6507 ExprEvalContexts.back().DelayedDecltypeBinds[I];
6508 if (Bind == TopBind)
6509 continue;
6510
6511 CXXTemporary *Temp = Bind->getTemporary();
6512
6513 CXXRecordDecl *RD =
6514 Bind->getType()->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();
6515 CXXDestructorDecl *Destructor = LookupDestructor(RD);
6516 Temp->setDestructor(Destructor);
6517
6518 MarkFunctionReferenced(Bind->getExprLoc(), Destructor);
6519 CheckDestructorAccess(Bind->getExprLoc(), Destructor,
6520 PDiag(diag::err_access_dtor_temp)
6521 << Bind->getType());
6522 if (DiagnoseUseOfDecl(Destructor, Bind->getExprLoc()))
6523 return ExprError();
6524
6525 // We need a cleanup, but we don't need to remember the temporary.
6526 Cleanup.setExprNeedsCleanups(true);
6527 }
6528
6529 // Possibly strip off the top CXXBindTemporaryExpr.
6530 return E;
6531}
6532
6533/// Note a set of 'operator->' functions that were used for a member access.
6534static void noteOperatorArrows(Sema &S,
6535 ArrayRef<FunctionDecl *> OperatorArrows) {
6536 unsigned SkipStart = OperatorArrows.size(), SkipCount = 0;
6537 // FIXME: Make this configurable?
6538 unsigned Limit = 9;
6539 if (OperatorArrows.size() > Limit) {
6540 // Produce Limit-1 normal notes and one 'skipping' note.
6541 SkipStart = (Limit - 1) / 2 + (Limit - 1) % 2;
6542 SkipCount = OperatorArrows.size() - (Limit - 1);
6543 }
6544
6545 for (unsigned I = 0; I < OperatorArrows.size(); /**/) {
6546 if (I == SkipStart) {
6547 S.Diag(OperatorArrows[I]->getLocation(),
6548 diag::note_operator_arrows_suppressed)
6549 << SkipCount;
6550 I += SkipCount;
6551 } else {
6552 S.Diag(OperatorArrows[I]->getLocation(), diag::note_operator_arrow_here)
6553 << OperatorArrows[I]->getCallResultType();
6554 ++I;
6555 }
6556 }
6557}
6558
6559ExprResult Sema::ActOnStartCXXMemberReference(Scope *S, Expr *Base,
6560 SourceLocation OpLoc,
6561 tok::TokenKind OpKind,
6562 ParsedType &ObjectType,
6563 bool &MayBePseudoDestructor) {
6564 // Since this might be a postfix expression, get rid of ParenListExprs.
6565 ExprResult Result = MaybeConvertParenListExprToParenExpr(S, Base);
6566 if (Result.isInvalid()) return ExprError();
6567 Base = Result.get();
6568
6569 Result = CheckPlaceholderExpr(Base);
6570 if (Result.isInvalid()) return ExprError();
6571 Base = Result.get();
6572
6573 QualType BaseType = Base->getType();
6574 MayBePseudoDestructor = false;
6575 if (BaseType->isDependentType()) {
6576 // If we have a pointer to a dependent type and are using the -> operator,
6577 // the object type is the type that the pointer points to. We might still
6578 // have enough information about that type to do something useful.
6579 if (OpKind == tok::arrow)
6580 if (const PointerType *Ptr = BaseType->getAs<PointerType>())
6581 BaseType = Ptr->getPointeeType();
6582
6583 ObjectType = ParsedType::make(BaseType);
6584 MayBePseudoDestructor = true;
6585 return Base;
6586 }
6587
6588 // C++ [over.match.oper]p8:
6589 // [...] When operator->returns, the operator-> is applied to the value
6590 // returned, with the original second operand.
6591 if (OpKind == tok::arrow) {
6592 QualType StartingType = BaseType;
6593 bool NoArrowOperatorFound = false;
6594 bool FirstIteration = true;
6595 FunctionDecl *CurFD = dyn_cast<FunctionDecl>(CurContext);
6596 // The set of types we've considered so far.
6597 llvm::SmallPtrSet<CanQualType,8> CTypes;
6598 SmallVector<FunctionDecl*, 8> OperatorArrows;
6599 CTypes.insert(Context.getCanonicalType(BaseType));
6600
6601 while (BaseType->isRecordType()) {
6602 if (OperatorArrows.size() >= getLangOpts().ArrowDepth) {
6603 Diag(OpLoc, diag::err_operator_arrow_depth_exceeded)
6604 << StartingType << getLangOpts().ArrowDepth << Base->getSourceRange();
6605 noteOperatorArrows(*this, OperatorArrows);
6606 Diag(OpLoc, diag::note_operator_arrow_depth)
6607 << getLangOpts().ArrowDepth;
6608 return ExprError();
6609 }
6610
6611 Result = BuildOverloadedArrowExpr(
6612 S, Base, OpLoc,
6613 // When in a template specialization and on the first loop iteration,
6614 // potentially give the default diagnostic (with the fixit in a
6615 // separate note) instead of having the error reported back to here
6616 // and giving a diagnostic with a fixit attached to the error itself.
6617 (FirstIteration && CurFD && CurFD->isFunctionTemplateSpecialization())
6618 ? nullptr
6619 : &NoArrowOperatorFound);
6620 if (Result.isInvalid()) {
6621 if (NoArrowOperatorFound) {
6622 if (FirstIteration) {
6623 Diag(OpLoc, diag::err_typecheck_member_reference_suggestion)
6624 << BaseType << 1 << Base->getSourceRange()
6625 << FixItHint::CreateReplacement(OpLoc, ".");
6626 OpKind = tok::period;
6627 break;
6628 }
6629 Diag(OpLoc, diag::err_typecheck_member_reference_arrow)
6630 << BaseType << Base->getSourceRange();
6631 CallExpr *CE = dyn_cast<CallExpr>(Base);
6632 if (Decl *CD = (CE ? CE->getCalleeDecl() : nullptr)) {
6633 Diag(CD->getLocStart(),
6634 diag::note_member_reference_arrow_from_operator_arrow);
6635 }
6636 }
6637 return ExprError();
6638 }
6639 Base = Result.get();
6640 if (CXXOperatorCallExpr *OpCall = dyn_cast<CXXOperatorCallExpr>(Base))
6641 OperatorArrows.push_back(OpCall->getDirectCallee());
6642 BaseType = Base->getType();
6643 CanQualType CBaseType = Context.getCanonicalType(BaseType);
6644 if (!CTypes.insert(CBaseType).second) {
6645 Diag(OpLoc, diag::err_operator_arrow_circular) << StartingType;
6646 noteOperatorArrows(*this, OperatorArrows);
6647 return ExprError();
6648 }
6649 FirstIteration = false;
6650 }
6651
6652 if (OpKind == tok::arrow &&
6653 (BaseType->isPointerType() || BaseType->isObjCObjectPointerType()))
6654 BaseType = BaseType->getPointeeType();
6655 }
6656
6657 // Objective-C properties allow "." access on Objective-C pointer types,
6658 // so adjust the base type to the object type itself.
6659 if (BaseType->isObjCObjectPointerType())
6660 BaseType = BaseType->getPointeeType();
6661
6662 // C++ [basic.lookup.classref]p2:
6663 // [...] If the type of the object expression is of pointer to scalar
6664 // type, the unqualified-id is looked up in the context of the complete
6665 // postfix-expression.
6666 //
6667 // This also indicates that we could be parsing a pseudo-destructor-name.
6668 // Note that Objective-C class and object types can be pseudo-destructor
6669 // expressions or normal member (ivar or property) access expressions, and
6670 // it's legal for the type to be incomplete if this is a pseudo-destructor
6671 // call. We'll do more incomplete-type checks later in the lookup process,
6672 // so just skip this check for ObjC types.
6673 if (BaseType->isObjCObjectOrInterfaceType()) {
6674 ObjectType = ParsedType::make(BaseType);
6675 MayBePseudoDestructor = true;
6676 return Base;
6677 } else if (!BaseType->isRecordType()) {
6678 ObjectType = nullptr;
6679 MayBePseudoDestructor = true;
6680 return Base;
6681 }
6682
6683 // The object type must be complete (or dependent), or
6684 // C++11 [expr.prim.general]p3:
6685 // Unlike the object expression in other contexts, *this is not required to
6686 // be of complete type for purposes of class member access (5.2.5) outside
6687 // the member function body.
6688 if (!BaseType->isDependentType() &&
6689 !isThisOutsideMemberFunctionBody(BaseType) &&
6690 RequireCompleteType(OpLoc, BaseType, diag::err_incomplete_member_access))
6691 return ExprError();
6692
6693 // C++ [basic.lookup.classref]p2:
6694 // If the id-expression in a class member access (5.2.5) is an
6695 // unqualified-id, and the type of the object expression is of a class
6696 // type C (or of pointer to a class type C), the unqualified-id is looked
6697 // up in the scope of class C. [...]
6698 ObjectType = ParsedType::make(BaseType);
6699 return Base;
6700}
6701
6702static bool CheckArrow(Sema& S, QualType& ObjectType, Expr *&Base,
6703 tok::TokenKind& OpKind, SourceLocation OpLoc) {
6704 if (Base->hasPlaceholderType()) {
6705 ExprResult result = S.CheckPlaceholderExpr(Base);
6706 if (result.isInvalid()) return true;
6707 Base = result.get();
6708 }
6709 ObjectType = Base->getType();
6710
6711 // C++ [expr.pseudo]p2:
6712 // The left-hand side of the dot operator shall be of scalar type. The
6713 // left-hand side of the arrow operator shall be of pointer to scalar type.
6714 // This scalar type is the object type.
6715 // Note that this is rather different from the normal handling for the
6716 // arrow operator.
6717 if (OpKind == tok::arrow) {
6718 if (const PointerType *Ptr = ObjectType->getAs<PointerType>()) {
6719 ObjectType = Ptr->getPointeeType();
6720 } else if (!Base->isTypeDependent()) {
6721 // The user wrote "p->" when they probably meant "p."; fix it.
6722 S.Diag(OpLoc, diag::err_typecheck_member_reference_suggestion)
6723 << ObjectType << true
6724 << FixItHint::CreateReplacement(OpLoc, ".");
6725 if (S.isSFINAEContext())
6726 return true;
6727
6728 OpKind = tok::period;
6729 }
6730 }
6731
6732 return false;
6733}
6734
6735/// \brief Check if it's ok to try and recover dot pseudo destructor calls on
6736/// pointer objects.
6737static bool
6738canRecoverDotPseudoDestructorCallsOnPointerObjects(Sema &SemaRef,
6739 QualType DestructedType) {
6740 // If this is a record type, check if its destructor is callable.
6741 if (auto *RD = DestructedType->getAsCXXRecordDecl()) {
6742 if (CXXDestructorDecl *D = SemaRef.LookupDestructor(RD))
6743 return SemaRef.CanUseDecl(D, /*TreatUnavailableAsInvalid=*/false);
6744 return false;
6745 }
6746
6747 // Otherwise, check if it's a type for which it's valid to use a pseudo-dtor.
6748 return DestructedType->isDependentType() || DestructedType->isScalarType() ||
6749 DestructedType->isVectorType();
6750}
6751
6752ExprResult Sema::BuildPseudoDestructorExpr(Expr *Base,
6753 SourceLocation OpLoc,
6754 tok::TokenKind OpKind,
6755 const CXXScopeSpec &SS,
6756 TypeSourceInfo *ScopeTypeInfo,
6757 SourceLocation CCLoc,
6758 SourceLocation TildeLoc,
6759 PseudoDestructorTypeStorage Destructed) {
6760 TypeSourceInfo *DestructedTypeInfo = Destructed.getTypeSourceInfo();
6761
6762 QualType ObjectType;
6763 if (CheckArrow(*this, ObjectType, Base, OpKind, OpLoc))
6764 return ExprError();
6765
6766 if (!ObjectType->isDependentType() && !ObjectType->isScalarType() &&
6767 !ObjectType->isVectorType()) {
6768 if (getLangOpts().MSVCCompat && ObjectType->isVoidType())
6769 Diag(OpLoc, diag::ext_pseudo_dtor_on_void) << Base->getSourceRange();
6770 else {
6771 Diag(OpLoc, diag::err_pseudo_dtor_base_not_scalar)
6772 << ObjectType << Base->getSourceRange();
6773 return ExprError();
6774 }
6775 }
6776
6777 // C++ [expr.pseudo]p2:
6778 // [...] The cv-unqualified versions of the object type and of the type
6779 // designated by the pseudo-destructor-name shall be the same type.
6780 if (DestructedTypeInfo) {
6781 QualType DestructedType = DestructedTypeInfo->getType();
6782 SourceLocation DestructedTypeStart
6783 = DestructedTypeInfo->getTypeLoc().getLocalSourceRange().getBegin();
6784 if (!DestructedType->isDependentType() && !ObjectType->isDependentType()) {
6785 if (!Context.hasSameUnqualifiedType(DestructedType, ObjectType)) {
6786 // Detect dot pseudo destructor calls on pointer objects, e.g.:
6787 // Foo *foo;
6788 // foo.~Foo();
6789 if (OpKind == tok::period && ObjectType->isPointerType() &&
6790 Context.hasSameUnqualifiedType(DestructedType,
6791 ObjectType->getPointeeType())) {
6792 auto Diagnostic =
6793 Diag(OpLoc, diag::err_typecheck_member_reference_suggestion)
6794 << ObjectType << /*IsArrow=*/0 << Base->getSourceRange();
6795
6796 // Issue a fixit only when the destructor is valid.
6797 if (canRecoverDotPseudoDestructorCallsOnPointerObjects(
6798 *this, DestructedType))
6799 Diagnostic << FixItHint::CreateReplacement(OpLoc, "->");
6800
6801 // Recover by setting the object type to the destructed type and the
6802 // operator to '->'.
6803 ObjectType = DestructedType;
6804 OpKind = tok::arrow;
6805 } else {
6806 Diag(DestructedTypeStart, diag::err_pseudo_dtor_type_mismatch)
6807 << ObjectType << DestructedType << Base->getSourceRange()
6808 << DestructedTypeInfo->getTypeLoc().getLocalSourceRange();
6809
6810 // Recover by setting the destructed type to the object type.
6811 DestructedType = ObjectType;
6812 DestructedTypeInfo =
6813 Context.getTrivialTypeSourceInfo(ObjectType, DestructedTypeStart);
6814 Destructed = PseudoDestructorTypeStorage(DestructedTypeInfo);
6815 }
6816 } else if (DestructedType.getObjCLifetime() !=
6817 ObjectType.getObjCLifetime()) {
6818
6819 if (DestructedType.getObjCLifetime() == Qualifiers::OCL_None) {
6820 // Okay: just pretend that the user provided the correctly-qualified
6821 // type.
6822 } else {
6823 Diag(DestructedTypeStart, diag::err_arc_pseudo_dtor_inconstant_quals)
6824 << ObjectType << DestructedType << Base->getSourceRange()
6825 << DestructedTypeInfo->getTypeLoc().getLocalSourceRange();
6826 }
6827
6828 // Recover by setting the destructed type to the object type.
6829 DestructedType = ObjectType;
6830 DestructedTypeInfo = Context.getTrivialTypeSourceInfo(ObjectType,
6831 DestructedTypeStart);
6832 Destructed = PseudoDestructorTypeStorage(DestructedTypeInfo);
6833 }
6834 }
6835 }
6836
6837 // C++ [expr.pseudo]p2:
6838 // [...] Furthermore, the two type-names in a pseudo-destructor-name of the
6839 // form
6840 //
6841 // ::[opt] nested-name-specifier[opt] type-name :: ~ type-name
6842 //
6843 // shall designate the same scalar type.
6844 if (ScopeTypeInfo) {
6845 QualType ScopeType = ScopeTypeInfo->getType();
6846 if (!ScopeType->isDependentType() && !ObjectType->isDependentType() &&
6847 !Context.hasSameUnqualifiedType(ScopeType, ObjectType)) {
6848
6849 Diag(ScopeTypeInfo->getTypeLoc().getLocalSourceRange().getBegin(),
6850 diag::err_pseudo_dtor_type_mismatch)
6851 << ObjectType << ScopeType << Base->getSourceRange()
6852 << ScopeTypeInfo->getTypeLoc().getLocalSourceRange();
6853
6854 ScopeType = QualType();
6855 ScopeTypeInfo = nullptr;
6856 }
6857 }
6858
6859 Expr *Result
6860 = new (Context) CXXPseudoDestructorExpr(Context, Base,
6861 OpKind == tok::arrow, OpLoc,
6862 SS.getWithLocInContext(Context),
6863 ScopeTypeInfo,
6864 CCLoc,
6865 TildeLoc,
6866 Destructed);
6867
6868 return Result;
6869}
6870
6871ExprResult Sema::ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
6872 SourceLocation OpLoc,
6873 tok::TokenKind OpKind,
6874 CXXScopeSpec &SS,
6875 UnqualifiedId &FirstTypeName,
6876 SourceLocation CCLoc,
6877 SourceLocation TildeLoc,
6878 UnqualifiedId &SecondTypeName) {
6879 assert((FirstTypeName.getKind() == UnqualifiedIdKind::IK_TemplateId ||(static_cast <bool> ((FirstTypeName.getKind() == UnqualifiedIdKind
::IK_TemplateId || FirstTypeName.getKind() == UnqualifiedIdKind
::IK_Identifier) && "Invalid first type name in pseudo-destructor"
) ? void (0) : __assert_fail ("(FirstTypeName.getKind() == UnqualifiedIdKind::IK_TemplateId || FirstTypeName.getKind() == UnqualifiedIdKind::IK_Identifier) && \"Invalid first type name in pseudo-destructor\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 6881, __extension__ __PRETTY_FUNCTION__))
6880 FirstTypeName.getKind() == UnqualifiedIdKind::IK_Identifier) &&(static_cast <bool> ((FirstTypeName.getKind() == UnqualifiedIdKind
::IK_TemplateId || FirstTypeName.getKind() == UnqualifiedIdKind
::IK_Identifier) && "Invalid first type name in pseudo-destructor"
) ? void (0) : __assert_fail ("(FirstTypeName.getKind() == UnqualifiedIdKind::IK_TemplateId || FirstTypeName.getKind() == UnqualifiedIdKind::IK_Identifier) && \"Invalid first type name in pseudo-destructor\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 6881, __extension__ __PRETTY_FUNCTION__))
6881 "Invalid first type name in pseudo-destructor")(static_cast <bool> ((FirstTypeName.getKind() == UnqualifiedIdKind
::IK_TemplateId || FirstTypeName.getKind() == UnqualifiedIdKind
::IK_Identifier) && "Invalid first type name in pseudo-destructor"
) ? void (0) : __assert_fail ("(FirstTypeName.getKind() == UnqualifiedIdKind::IK_TemplateId || FirstTypeName.getKind() == UnqualifiedIdKind::IK_Identifier) && \"Invalid first type name in pseudo-destructor\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 6881, __extension__ __PRETTY_FUNCTION__))
;
6882 assert((SecondTypeName.getKind() == UnqualifiedIdKind::IK_TemplateId ||(static_cast <bool> ((SecondTypeName.getKind() == UnqualifiedIdKind
::IK_TemplateId || SecondTypeName.getKind() == UnqualifiedIdKind
::IK_Identifier) && "Invalid second type name in pseudo-destructor"
) ? void (0) : __assert_fail ("(SecondTypeName.getKind() == UnqualifiedIdKind::IK_TemplateId || SecondTypeName.getKind() == UnqualifiedIdKind::IK_Identifier) && \"Invalid second type name in pseudo-destructor\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 6884, __extension__ __PRETTY_FUNCTION__))
6883 SecondTypeName.getKind() == UnqualifiedIdKind::IK_Identifier) &&(static_cast <bool> ((SecondTypeName.getKind() == UnqualifiedIdKind
::IK_TemplateId || SecondTypeName.getKind() == UnqualifiedIdKind
::IK_Identifier) && "Invalid second type name in pseudo-destructor"
) ? void (0) : __assert_fail ("(SecondTypeName.getKind() == UnqualifiedIdKind::IK_TemplateId || SecondTypeName.getKind() == UnqualifiedIdKind::IK_Identifier) && \"Invalid second type name in pseudo-destructor\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 6884, __extension__ __PRETTY_FUNCTION__))
6884 "Invalid second type name in pseudo-destructor")(static_cast <bool> ((SecondTypeName.getKind() == UnqualifiedIdKind
::IK_TemplateId || SecondTypeName.getKind() == UnqualifiedIdKind
::IK_Identifier) && "Invalid second type name in pseudo-destructor"
) ? void (0) : __assert_fail ("(SecondTypeName.getKind() == UnqualifiedIdKind::IK_TemplateId || SecondTypeName.getKind() == UnqualifiedIdKind::IK_Identifier) && \"Invalid second type name in pseudo-destructor\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 6884, __extension__ __PRETTY_FUNCTION__))
;
6885
6886 QualType ObjectType;
6887 if (CheckArrow(*this, ObjectType, Base, OpKind, OpLoc))
6888 return ExprError();
6889
6890 // Compute the object type that we should use for name lookup purposes. Only
6891 // record types and dependent types matter.
6892 ParsedType ObjectTypePtrForLookup;
6893 if (!SS.isSet()) {
6894 if (ObjectType->isRecordType())
6895 ObjectTypePtrForLookup = ParsedType::make(ObjectType);
6896 else if (ObjectType->isDependentType())
6897 ObjectTypePtrForLookup = ParsedType::make(Context.DependentTy);
6898 }
6899
6900 // Convert the name of the type being destructed (following the ~) into a
6901 // type (with source-location information).
6902 QualType DestructedType;
6903 TypeSourceInfo *DestructedTypeInfo = nullptr;
6904 PseudoDestructorTypeStorage Destructed;
6905 if (SecondTypeName.getKind() == UnqualifiedIdKind::IK_Identifier) {
6906 ParsedType T = getTypeName(*SecondTypeName.Identifier,
6907 SecondTypeName.StartLocation,
6908 S, &SS, true, false, ObjectTypePtrForLookup,
6909 /*IsCtorOrDtorName*/true);
6910 if (!T &&
6911 ((SS.isSet() && !computeDeclContext(SS, false)) ||
6912 (!SS.isSet() && ObjectType->isDependentType()))) {
6913 // The name of the type being destroyed is a dependent name, and we
6914 // couldn't find anything useful in scope. Just store the identifier and
6915 // it's location, and we'll perform (qualified) name lookup again at
6916 // template instantiation time.
6917 Destructed = PseudoDestructorTypeStorage(SecondTypeName.Identifier,
6918 SecondTypeName.StartLocation);
6919 } else if (!T) {
6920 Diag(SecondTypeName.StartLocation,
6921 diag::err_pseudo_dtor_destructor_non_type)
6922 << SecondTypeName.Identifier << ObjectType;
6923 if (isSFINAEContext())
6924 return ExprError();
6925
6926 // Recover by assuming we had the right type all along.
6927 DestructedType = ObjectType;
6928 } else
6929 DestructedType = GetTypeFromParser(T, &DestructedTypeInfo);
6930 } else {
6931 // Resolve the template-id to a type.
6932 TemplateIdAnnotation *TemplateId = SecondTypeName.TemplateId;
6933 ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(),
6934 TemplateId->NumArgs);
6935 TypeResult T = ActOnTemplateIdType(TemplateId->SS,
6936 TemplateId->TemplateKWLoc,
6937 TemplateId->Template,
6938 TemplateId->Name,
6939 TemplateId->TemplateNameLoc,
6940 TemplateId->LAngleLoc,
6941 TemplateArgsPtr,
6942 TemplateId->RAngleLoc,
6943 /*IsCtorOrDtorName*/true);
6944 if (T.isInvalid() || !T.get()) {
6945 // Recover by assuming we had the right type all along.
6946 DestructedType = ObjectType;
6947 } else
6948 DestructedType = GetTypeFromParser(T.get(), &DestructedTypeInfo);
6949 }
6950
6951 // If we've performed some kind of recovery, (re-)build the type source
6952 // information.
6953 if (!DestructedType.isNull()) {
6954 if (!DestructedTypeInfo)
6955 DestructedTypeInfo = Context.getTrivialTypeSourceInfo(DestructedType,
6956 SecondTypeName.StartLocation);
6957 Destructed = PseudoDestructorTypeStorage(DestructedTypeInfo);
6958 }
6959
6960 // Convert the name of the scope type (the type prior to '::') into a type.
6961 TypeSourceInfo *ScopeTypeInfo = nullptr;
6962 QualType ScopeType;
6963 if (FirstTypeName.getKind() == UnqualifiedIdKind::IK_TemplateId ||
6964 FirstTypeName.Identifier) {
6965 if (FirstTypeName.getKind() == UnqualifiedIdKind::IK_Identifier) {
6966 ParsedType T = getTypeName(*FirstTypeName.Identifier,
6967 FirstTypeName.StartLocation,
6968 S, &SS, true, false, ObjectTypePtrForLookup,
6969 /*IsCtorOrDtorName*/true);
6970 if (!T) {
6971 Diag(FirstTypeName.StartLocation,
6972 diag::err_pseudo_dtor_destructor_non_type)
6973 << FirstTypeName.Identifier << ObjectType;
6974
6975 if (isSFINAEContext())
6976 return ExprError();
6977
6978 // Just drop this type. It's unnecessary anyway.
6979 ScopeType = QualType();
6980 } else
6981 ScopeType = GetTypeFromParser(T, &ScopeTypeInfo);
6982 } else {
6983 // Resolve the template-id to a type.
6984 TemplateIdAnnotation *TemplateId = FirstTypeName.TemplateId;
6985 ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(),
6986 TemplateId->NumArgs);
6987 TypeResult T = ActOnTemplateIdType(TemplateId->SS,
6988 TemplateId->TemplateKWLoc,
6989 TemplateId->Template,
6990 TemplateId->Name,
6991 TemplateId->TemplateNameLoc,
6992 TemplateId->LAngleLoc,
6993 TemplateArgsPtr,
6994 TemplateId->RAngleLoc,
6995 /*IsCtorOrDtorName*/true);
6996 if (T.isInvalid() || !T.get()) {
6997 // Recover by dropping this type.
6998 ScopeType = QualType();
6999 } else
7000 ScopeType = GetTypeFromParser(T.get(), &ScopeTypeInfo);
7001 }
7002 }
7003
7004 if (!ScopeType.isNull() && !ScopeTypeInfo)
7005 ScopeTypeInfo = Context.getTrivialTypeSourceInfo(ScopeType,
7006 FirstTypeName.StartLocation);
7007
7008
7009 return BuildPseudoDestructorExpr(Base, OpLoc, OpKind, SS,
7010 ScopeTypeInfo, CCLoc, TildeLoc,
7011 Destructed);
7012}
7013
7014ExprResult Sema::ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
7015 SourceLocation OpLoc,
7016 tok::TokenKind OpKind,
7017 SourceLocation TildeLoc,
7018 const DeclSpec& DS) {
7019 QualType ObjectType;
7020 if (CheckArrow(*this, ObjectType, Base, OpKind, OpLoc))
7021 return ExprError();
7022
7023 QualType T = BuildDecltypeType(DS.getRepAsExpr(), DS.getTypeSpecTypeLoc(),
7024 false);
7025
7026 TypeLocBuilder TLB;
7027 DecltypeTypeLoc DecltypeTL = TLB.push<DecltypeTypeLoc>(T);
7028 DecltypeTL.setNameLoc(DS.getTypeSpecTypeLoc());
7029 TypeSourceInfo *DestructedTypeInfo = TLB.getTypeSourceInfo(Context, T);
7030 PseudoDestructorTypeStorage Destructed(DestructedTypeInfo);
7031
7032 return BuildPseudoDestructorExpr(Base, OpLoc, OpKind, CXXScopeSpec(),
7033 nullptr, SourceLocation(), TildeLoc,
7034 Destructed);
7035}
7036
7037ExprResult Sema::BuildCXXMemberCallExpr(Expr *E, NamedDecl *FoundDecl,
7038 CXXConversionDecl *Method,
7039 bool HadMultipleCandidates) {
7040 if (Method->getParent()->isLambda() &&
7041 Method->getConversionType()->isBlockPointerType()) {
7042 // This is a lambda coversion to block pointer; check if the argument
7043 // is a LambdaExpr.
7044 Expr *SubE = E;
7045 CastExpr *CE = dyn_cast<CastExpr>(SubE);
7046 if (CE && CE->getCastKind() == CK_NoOp)
7047 SubE = CE->getSubExpr();
7048 SubE = SubE->IgnoreParens();
7049 if (CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(SubE))
7050 SubE = BE->getSubExpr();
7051 if (isa<LambdaExpr>(SubE)) {
7052 // For the conversion to block pointer on a lambda expression, we
7053 // construct a special BlockLiteral instead; this doesn't really make
7054 // a difference in ARC, but outside of ARC the resulting block literal
7055 // follows the normal lifetime rules for block literals instead of being
7056 // autoreleased.
7057 DiagnosticErrorTrap Trap(Diags);
7058 PushExpressionEvaluationContext(
7059 ExpressionEvaluationContext::PotentiallyEvaluated);
7060 ExprResult Exp = BuildBlockForLambdaConversion(E->getExprLoc(),
7061 E->getExprLoc(),
7062 Method, E);
7063 PopExpressionEvaluationContext();
7064
7065 if (Exp.isInvalid())
7066 Diag(E->getExprLoc(), diag::note_lambda_to_block_conv);
7067 return Exp;
7068 }
7069 }
7070
7071 ExprResult Exp = PerformObjectArgumentInitialization(E, /*Qualifier=*/nullptr,
7072 FoundDecl, Method);
7073 if (Exp.isInvalid())
7074 return true;
7075
7076 MemberExpr *ME = new (Context) MemberExpr(
7077 Exp.get(), /*IsArrow=*/false, SourceLocation(), Method, SourceLocation(),
7078 Context.BoundMemberTy, VK_RValue, OK_Ordinary);
7079 if (HadMultipleCandidates)
7080 ME->setHadMultipleCandidates(true);
7081 MarkMemberReferenced(ME);
7082
7083 QualType ResultType = Method->getReturnType();
7084 ExprValueKind VK = Expr::getValueKindForType(ResultType);
7085 ResultType = ResultType.getNonLValueExprType(Context);
7086
7087 CXXMemberCallExpr *CE =
7088 new (Context) CXXMemberCallExpr(Context, ME, None, ResultType, VK,
7089 Exp.get()->getLocEnd());
7090
7091 if (CheckFunctionCall(Method, CE,
7092 Method->getType()->castAs<FunctionProtoType>()))
7093 return ExprError();
7094
7095 return CE;
7096}
7097
7098ExprResult Sema::BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand,
7099 SourceLocation RParen) {
7100 // If the operand is an unresolved lookup expression, the expression is ill-
7101 // formed per [over.over]p1, because overloaded function names cannot be used
7102 // without arguments except in explicit contexts.
7103 ExprResult R = CheckPlaceholderExpr(Operand);
7104 if (R.isInvalid())
7105 return R;
7106
7107 // The operand may have been modified when checking the placeholder type.
7108 Operand = R.get();
7109
7110 if (!inTemplateInstantiation() && Operand->HasSideEffects(Context, false)) {
7111 // The expression operand for noexcept is in an unevaluated expression
7112 // context, so side effects could result in unintended consequences.
7113 Diag(Operand->getExprLoc(), diag::warn_side_effects_unevaluated_context);
7114 }
7115
7116 CanThrowResult CanThrow = canThrow(Operand);
7117 return new (Context)
7118 CXXNoexceptExpr(Context.BoolTy, Operand, CanThrow, KeyLoc, RParen);
7119}
7120
7121ExprResult Sema::ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation,
7122 Expr *Operand, SourceLocation RParen) {
7123 return BuildCXXNoexceptExpr(KeyLoc, Operand, RParen);
7124}
7125
7126static bool IsSpecialDiscardedValue(Expr *E) {
7127 // In C++11, discarded-value expressions of a certain form are special,
7128 // according to [expr]p10:
7129 // The lvalue-to-rvalue conversion (4.1) is applied only if the
7130 // expression is an lvalue of volatile-qualified type and it has
7131 // one of the following forms:
7132 E = E->IgnoreParens();
7133
7134 // - id-expression (5.1.1),
7135 if (isa<DeclRefExpr>(E))
7136 return true;
7137
7138 // - subscripting (5.2.1),
7139 if (isa<ArraySubscriptExpr>(E))
7140 return true;
7141
7142 // - class member access (5.2.5),
7143 if (isa<MemberExpr>(E))
7144 return true;
7145
7146 // - indirection (5.3.1),
7147 if (UnaryOperator *UO = dyn_cast<UnaryOperator>(E))
7148 if (UO->getOpcode() == UO_Deref)
7149 return true;
7150
7151 if (BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
7152 // - pointer-to-member operation (5.5),
7153 if (BO->isPtrMemOp())
7154 return true;
7155
7156 // - comma expression (5.18) where the right operand is one of the above.
7157 if (BO->getOpcode() == BO_Comma)
7158 return IsSpecialDiscardedValue(BO->getRHS());
7159 }
7160
7161 // - conditional expression (5.16) where both the second and the third
7162 // operands are one of the above, or
7163 if (ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E))
7164 return IsSpecialDiscardedValue(CO->getTrueExpr()) &&
7165 IsSpecialDiscardedValue(CO->getFalseExpr());
7166 // The related edge case of "*x ?: *x".
7167 if (BinaryConditionalOperator *BCO =
7168 dyn_cast<BinaryConditionalOperator>(E)) {
7169 if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(BCO->getTrueExpr()))
7170 return IsSpecialDiscardedValue(OVE->getSourceExpr()) &&
7171 IsSpecialDiscardedValue(BCO->getFalseExpr());
7172 }
7173
7174 // Objective-C++ extensions to the rule.
7175 if (isa<PseudoObjectExpr>(E) || isa<ObjCIvarRefExpr>(E))
7176 return true;
7177
7178 return false;
7179}
7180
7181/// Perform the conversions required for an expression used in a
7182/// context that ignores the result.
7183ExprResult Sema::IgnoredValueConversions(Expr *E) {
7184 if (E->hasPlaceholderType()) {
7185 ExprResult result = CheckPlaceholderExpr(E);
7186 if (result.isInvalid()) return E;
7187 E = result.get();
7188 }
7189
7190 // C99 6.3.2.1:
7191 // [Except in specific positions,] an lvalue that does not have
7192 // array type is converted to the value stored in the
7193 // designated object (and is no longer an lvalue).
7194 if (E->isRValue()) {
7195 // In C, function designators (i.e. expressions of function type)
7196 // are r-values, but we still want to do function-to-pointer decay
7197 // on them. This is both technically correct and convenient for
7198 // some clients.
7199 if (!getLangOpts().CPlusPlus && E->getType()->isFunctionType())
7200 return DefaultFunctionArrayConversion(E);
7201
7202 return E;
7203 }
7204
7205 if (getLangOpts().CPlusPlus) {
7206 // The C++11 standard defines the notion of a discarded-value expression;
7207 // normally, we don't need to do anything to handle it, but if it is a
7208 // volatile lvalue with a special form, we perform an lvalue-to-rvalue
7209 // conversion.
7210 if (getLangOpts().CPlusPlus11 && E->isGLValue() &&
7211 E->getType().isVolatileQualified() &&
7212 IsSpecialDiscardedValue(E)) {
7213 ExprResult Res = DefaultLvalueConversion(E);
7214 if (Res.isInvalid())
7215 return E;
7216 E = Res.get();
7217 }
7218
7219 // C++1z:
7220 // If the expression is a prvalue after this optional conversion, the
7221 // temporary materialization conversion is applied.
7222 //
7223 // We skip this step: IR generation is able to synthesize the storage for
7224 // itself in the aggregate case, and adding the extra node to the AST is
7225 // just clutter.
7226 // FIXME: We don't emit lifetime markers for the temporaries due to this.
7227 // FIXME: Do any other AST consumers care about this?
7228 return E;
7229 }
7230
7231 // GCC seems to also exclude expressions of incomplete enum type.
7232 if (const EnumType *T = E->getType()->getAs<EnumType>()) {
7233 if (!T->getDecl()->isComplete()) {
7234 // FIXME: stupid workaround for a codegen bug!
7235 E = ImpCastExprToType(E, Context.VoidTy, CK_ToVoid).get();
7236 return E;
7237 }
7238 }
7239
7240 ExprResult Res = DefaultFunctionArrayLvalueConversion(E);
7241 if (Res.isInvalid())
7242 return E;
7243 E = Res.get();
7244
7245 if (!E->getType()->isVoidType())
7246 RequireCompleteType(E->getExprLoc(), E->getType(),
7247 diag::err_incomplete_type);
7248 return E;
7249}
7250
7251// If we can unambiguously determine whether Var can never be used
7252// in a constant expression, return true.
7253// - if the variable and its initializer are non-dependent, then
7254// we can unambiguously check if the variable is a constant expression.
7255// - if the initializer is not value dependent - we can determine whether
7256// it can be used to initialize a constant expression. If Init can not
7257// be used to initialize a constant expression we conclude that Var can
7258// never be a constant expression.
7259// - FXIME: if the initializer is dependent, we can still do some analysis and
7260// identify certain cases unambiguously as non-const by using a Visitor:
7261// - such as those that involve odr-use of a ParmVarDecl, involve a new
7262// delete, lambda-expr, dynamic-cast, reinterpret-cast etc...
7263static inline bool VariableCanNeverBeAConstantExpression(VarDecl *Var,
7264 ASTContext &Context) {
7265 if (isa<ParmVarDecl>(Var)) return true;
7266 const VarDecl *DefVD = nullptr;
7267
7268 // If there is no initializer - this can not be a constant expression.
7269 if (!Var->getAnyInitializer(DefVD)) return true;
7270 assert(DefVD)(static_cast <bool> (DefVD) ? void (0) : __assert_fail (
"DefVD", "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 7270, __extension__ __PRETTY_FUNCTION__))
;
7271 if (DefVD->isWeak()) return false;
7272 EvaluatedStmt *Eval = DefVD->ensureEvaluatedStmt();
7273
7274 Expr *Init = cast<Expr>(Eval->Value);
7275
7276 if (Var->getType()->isDependentType() || Init->isValueDependent()) {
7277 // FIXME: Teach the constant evaluator to deal with the non-dependent parts
7278 // of value-dependent expressions, and use it here to determine whether the
7279 // initializer is a potential constant expression.
7280 return false;
7281 }
7282
7283 return !IsVariableAConstantExpression(Var, Context);
7284}
7285
7286/// \brief Check if the current lambda has any potential captures
7287/// that must be captured by any of its enclosing lambdas that are ready to
7288/// capture. If there is a lambda that can capture a nested
7289/// potential-capture, go ahead and do so. Also, check to see if any
7290/// variables are uncaptureable or do not involve an odr-use so do not
7291/// need to be captured.
7292
7293static void CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures(
7294 Expr *const FE, LambdaScopeInfo *const CurrentLSI, Sema &S) {
7295
7296 assert(!S.isUnevaluatedContext())(static_cast <bool> (!S.isUnevaluatedContext()) ? void (
0) : __assert_fail ("!S.isUnevaluatedContext()", "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 7296, __extension__ __PRETTY_FUNCTION__))
;
7297 assert(S.CurContext->isDependentContext())(static_cast <bool> (S.CurContext->isDependentContext
()) ? void (0) : __assert_fail ("S.CurContext->isDependentContext()"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 7297, __extension__ __PRETTY_FUNCTION__))
;
7298#ifndef NDEBUG
7299 DeclContext *DC = S.CurContext;
7300 while (DC && isa<CapturedDecl>(DC))
7301 DC = DC->getParent();
7302 assert((static_cast <bool> (CurrentLSI->CallOperator == DC &&
"The current call operator must be synchronized with Sema's CurContext"
) ? void (0) : __assert_fail ("CurrentLSI->CallOperator == DC && \"The current call operator must be synchronized with Sema's CurContext\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 7304, __extension__ __PRETTY_FUNCTION__))
7303 CurrentLSI->CallOperator == DC &&(static_cast <bool> (CurrentLSI->CallOperator == DC &&
"The current call operator must be synchronized with Sema's CurContext"
) ? void (0) : __assert_fail ("CurrentLSI->CallOperator == DC && \"The current call operator must be synchronized with Sema's CurContext\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 7304, __extension__ __PRETTY_FUNCTION__))
7304 "The current call operator must be synchronized with Sema's CurContext")(static_cast <bool> (CurrentLSI->CallOperator == DC &&
"The current call operator must be synchronized with Sema's CurContext"
) ? void (0) : __assert_fail ("CurrentLSI->CallOperator == DC && \"The current call operator must be synchronized with Sema's CurContext\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 7304, __extension__ __PRETTY_FUNCTION__))
;
7305#endif // NDEBUG
7306
7307 const bool IsFullExprInstantiationDependent = FE->isInstantiationDependent();
7308
7309 // All the potentially captureable variables in the current nested
7310 // lambda (within a generic outer lambda), must be captured by an
7311 // outer lambda that is enclosed within a non-dependent context.
7312 const unsigned NumPotentialCaptures =
7313 CurrentLSI->getNumPotentialVariableCaptures();
7314 for (unsigned I = 0; I != NumPotentialCaptures; ++I) {
7315 Expr *VarExpr = nullptr;
7316 VarDecl *Var = nullptr;
7317 CurrentLSI->getPotentialVariableCapture(I, Var, VarExpr);
7318 // If the variable is clearly identified as non-odr-used and the full
7319 // expression is not instantiation dependent, only then do we not
7320 // need to check enclosing lambda's for speculative captures.
7321 // For e.g.:
7322 // Even though 'x' is not odr-used, it should be captured.
7323 // int test() {
7324 // const int x = 10;
7325 // auto L = [=](auto a) {
7326 // (void) +x + a;
7327 // };
7328 // }
7329 if (CurrentLSI->isVariableExprMarkedAsNonODRUsed(VarExpr) &&
7330 !IsFullExprInstantiationDependent)
7331 continue;
7332
7333 // If we have a capture-capable lambda for the variable, go ahead and
7334 // capture the variable in that lambda (and all its enclosing lambdas).
7335 if (const Optional<unsigned> Index =
7336 getStackIndexOfNearestEnclosingCaptureCapableLambda(
7337 S.FunctionScopes, Var, S)) {
7338 const unsigned FunctionScopeIndexOfCapturableLambda = Index.getValue();
7339 MarkVarDeclODRUsed(Var, VarExpr->getExprLoc(), S,
7340 &FunctionScopeIndexOfCapturableLambda);
7341 }
7342 const bool IsVarNeverAConstantExpression =
7343 VariableCanNeverBeAConstantExpression(Var, S.Context);
7344 if (!IsFullExprInstantiationDependent || IsVarNeverAConstantExpression) {
7345 // This full expression is not instantiation dependent or the variable
7346 // can not be used in a constant expression - which means
7347 // this variable must be odr-used here, so diagnose a
7348 // capture violation early, if the variable is un-captureable.
7349 // This is purely for diagnosing errors early. Otherwise, this
7350 // error would get diagnosed when the lambda becomes capture ready.
7351 QualType CaptureType, DeclRefType;
7352 SourceLocation ExprLoc = VarExpr->getExprLoc();
7353 if (S.tryCaptureVariable(Var, ExprLoc, S.TryCapture_Implicit,
7354 /*EllipsisLoc*/ SourceLocation(),
7355 /*BuildAndDiagnose*/false, CaptureType,
7356 DeclRefType, nullptr)) {
7357 // We will never be able to capture this variable, and we need
7358 // to be able to in any and all instantiations, so diagnose it.
7359 S.tryCaptureVariable(Var, ExprLoc, S.TryCapture_Implicit,
7360 /*EllipsisLoc*/ SourceLocation(),
7361 /*BuildAndDiagnose*/true, CaptureType,
7362 DeclRefType, nullptr);
7363 }
7364 }
7365 }
7366
7367 // Check if 'this' needs to be captured.
7368 if (CurrentLSI->hasPotentialThisCapture()) {
7369 // If we have a capture-capable lambda for 'this', go ahead and capture
7370 // 'this' in that lambda (and all its enclosing lambdas).
7371 if (const Optional<unsigned> Index =
7372 getStackIndexOfNearestEnclosingCaptureCapableLambda(
7373 S.FunctionScopes, /*0 is 'this'*/ nullptr, S)) {
7374 const unsigned FunctionScopeIndexOfCapturableLambda = Index.getValue();
7375 S.CheckCXXThisCapture(CurrentLSI->PotentialThisCaptureLocation,
7376 /*Explicit*/ false, /*BuildAndDiagnose*/ true,
7377 &FunctionScopeIndexOfCapturableLambda);
7378 }
7379 }
7380
7381 // Reset all the potential captures at the end of each full-expression.
7382 CurrentLSI->clearPotentialCaptures();
7383}
7384
7385static ExprResult attemptRecovery(Sema &SemaRef,
7386 const TypoCorrectionConsumer &Consumer,
7387 const TypoCorrection &TC) {
7388 LookupResult R(SemaRef, Consumer.getLookupResult().getLookupNameInfo(),
7389 Consumer.getLookupResult().getLookupKind());
7390 const CXXScopeSpec *SS = Consumer.getSS();
7391 CXXScopeSpec NewSS;
7392
7393 // Use an approprate CXXScopeSpec for building the expr.
7394 if (auto *NNS = TC.getCorrectionSpecifier())
7395 NewSS.MakeTrivial(SemaRef.Context, NNS, TC.getCorrectionRange());
7396 else if (SS && !TC.WillReplaceSpecifier())
7397 NewSS = *SS;
7398
7399 if (auto *ND = TC.getFoundDecl()) {
7400 R.setLookupName(ND->getDeclName());
7401 R.addDecl(ND);
7402 if (ND->isCXXClassMember()) {
7403 // Figure out the correct naming class to add to the LookupResult.
7404 CXXRecordDecl *Record = nullptr;
7405 if (auto *NNS = TC.getCorrectionSpecifier())
7406 Record = NNS->getAsType()->getAsCXXRecordDecl();
7407 if (!Record)
7408 Record =
7409 dyn_cast<CXXRecordDecl>(ND->getDeclContext()->getRedeclContext());
7410 if (Record)
7411 R.setNamingClass(Record);
7412
7413 // Detect and handle the case where the decl might be an implicit
7414 // member.
7415 bool MightBeImplicitMember;
7416 if (!Consumer.isAddressOfOperand())
7417 MightBeImplicitMember = true;
7418 else if (!NewSS.isEmpty())
7419 MightBeImplicitMember = false;
7420 else if (R.isOverloadedResult())
7421 MightBeImplicitMember = false;
7422 else if (R.isUnresolvableResult())
7423 MightBeImplicitMember = true;
7424 else
7425 MightBeImplicitMember = isa<FieldDecl>(ND) ||
7426 isa<IndirectFieldDecl>(ND) ||
7427 isa<MSPropertyDecl>(ND);
7428
7429 if (MightBeImplicitMember)
7430 return SemaRef.BuildPossibleImplicitMemberExpr(
7431 NewSS, /*TemplateKWLoc*/ SourceLocation(), R,
7432 /*TemplateArgs*/ nullptr, /*S*/ nullptr);
7433 } else if (auto *Ivar = dyn_cast<ObjCIvarDecl>(ND)) {
7434 return SemaRef.LookupInObjCMethod(R, Consumer.getScope(),
7435 Ivar->getIdentifier());
7436 }
7437 }
7438
7439 return SemaRef.BuildDeclarationNameExpr(NewSS, R, /*NeedsADL*/ false,
7440 /*AcceptInvalidDecl*/ true);
7441}
7442
7443namespace {
7444class FindTypoExprs : public RecursiveASTVisitor<FindTypoExprs> {
7445 llvm::SmallSetVector<TypoExpr *, 2> &TypoExprs;
7446
7447public:
7448 explicit FindTypoExprs(llvm::SmallSetVector<TypoExpr *, 2> &TypoExprs)
7449 : TypoExprs(TypoExprs) {}
7450 bool VisitTypoExpr(TypoExpr *TE) {
7451 TypoExprs.insert(TE);
7452 return true;
7453 }
7454};
7455
7456class TransformTypos : public TreeTransform<TransformTypos> {
7457 typedef TreeTransform<TransformTypos> BaseTransform;
7458
7459 VarDecl *InitDecl; // A decl to avoid as a correction because it is in the
7460 // process of being initialized.
7461 llvm::function_ref<ExprResult(Expr *)> ExprFilter;
7462 llvm::SmallSetVector<TypoExpr *, 2> TypoExprs, AmbiguousTypoExprs;
7463 llvm::SmallDenseMap<TypoExpr *, ExprResult, 2> TransformCache;
7464 llvm::SmallDenseMap<OverloadExpr *, Expr *, 4> OverloadResolution;
7465
7466 /// \brief Emit diagnostics for all of the TypoExprs encountered.
7467 /// If the TypoExprs were successfully corrected, then the diagnostics should
7468 /// suggest the corrections. Otherwise the diagnostics will not suggest
7469 /// anything (having been passed an empty TypoCorrection).
7470 void EmitAllDiagnostics() {
7471 for (TypoExpr *TE : TypoExprs) {
7472 auto &State = SemaRef.getTypoExprState(TE);
7473 if (State.DiagHandler) {
7474 TypoCorrection TC = State.Consumer->getCurrentCorrection();
7475 ExprResult Replacement = TransformCache[TE];
7476
7477 // Extract the NamedDecl from the transformed TypoExpr and add it to the
7478 // TypoCorrection, replacing the existing decls. This ensures the right
7479 // NamedDecl is used in diagnostics e.g. in the case where overload
7480 // resolution was used to select one from several possible decls that
7481 // had been stored in the TypoCorrection.
7482 if (auto *ND = getDeclFromExpr(
7483 Replacement.isInvalid() ? nullptr : Replacement.get()))
7484 TC.setCorrectionDecl(ND);
7485
7486 State.DiagHandler(TC);
7487 }
7488 SemaRef.clearDelayedTypo(TE);
7489 }
7490 }
7491
7492 /// \brief If corrections for the first TypoExpr have been exhausted for a
7493 /// given combination of the other TypoExprs, retry those corrections against
7494 /// the next combination of substitutions for the other TypoExprs by advancing
7495 /// to the next potential correction of the second TypoExpr. For the second
7496 /// and subsequent TypoExprs, if its stream of corrections has been exhausted,
7497 /// the stream is reset and the next TypoExpr's stream is advanced by one (a
7498 /// TypoExpr's correction stream is advanced by removing the TypoExpr from the
7499 /// TransformCache). Returns true if there is still any untried combinations
7500 /// of corrections.
7501 bool CheckAndAdvanceTypoExprCorrectionStreams() {
7502 for (auto TE : TypoExprs) {
7503 auto &State = SemaRef.getTypoExprState(TE);
7504 TransformCache.erase(TE);
7505 if (!State.Consumer->finished())
7506 return true;
7507 State.Consumer->resetCorrectionStream();
7508 }
7509 return false;
7510 }
7511
7512 NamedDecl *getDeclFromExpr(Expr *E) {
7513 if (auto *OE = dyn_cast_or_null<OverloadExpr>(E))
7514 E = OverloadResolution[OE];
7515
7516 if (!E)
7517 return nullptr;
7518 if (auto *DRE = dyn_cast<DeclRefExpr>(E))
7519 return DRE->getFoundDecl();
7520 if (auto *ME = dyn_cast<MemberExpr>(E))
7521 return ME->getFoundDecl();
7522 // FIXME: Add any other expr types that could be be seen by the delayed typo
7523 // correction TreeTransform for which the corresponding TypoCorrection could
7524 // contain multiple decls.
7525 return nullptr;
7526 }
7527
7528 ExprResult TryTransform(Expr *E) {
7529 Sema::SFINAETrap Trap(SemaRef);
7530 ExprResult Res = TransformExpr(E);
7531 if (Trap.hasErrorOccurred() || Res.isInvalid())
7532 return ExprError();
7533
7534 return ExprFilter(Res.get());
7535 }
7536
7537public:
7538 TransformTypos(Sema &SemaRef, VarDecl *InitDecl, llvm::function_ref<ExprResult(Expr *)> Filter)
7539 : BaseTransform(SemaRef), InitDecl(InitDecl), ExprFilter(Filter) {}
7540
7541 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
7542 MultiExprArg Args,
7543 SourceLocation RParenLoc,
7544 Expr *ExecConfig = nullptr) {
7545 auto Result = BaseTransform::RebuildCallExpr(Callee, LParenLoc, Args,
7546 RParenLoc, ExecConfig);
7547 if (auto *OE = dyn_cast<OverloadExpr>(Callee)) {
7548 if (Result.isUsable()) {
7549 Expr *ResultCall = Result.get();
7550 if (auto *BE = dyn_cast<CXXBindTemporaryExpr>(ResultCall))
7551 ResultCall = BE->getSubExpr();
7552 if (auto *CE = dyn_cast<CallExpr>(ResultCall))
7553 OverloadResolution[OE] = CE->getCallee();
7554 }
7555 }
7556 return Result;
7557 }
7558
7559 ExprResult TransformLambdaExpr(LambdaExpr *E) { return Owned(E); }
7560
7561 ExprResult TransformBlockExpr(BlockExpr *E) { return Owned(E); }
7562
7563 ExprResult Transform(Expr *E) {
7564 ExprResult Res;
7565 while (true) {
7566 Res = TryTransform(E);
7567
7568 // Exit if either the transform was valid or if there were no TypoExprs
7569 // to transform that still have any untried correction candidates..
7570 if (!Res.isInvalid() ||
7571 !CheckAndAdvanceTypoExprCorrectionStreams())
7572 break;
7573 }
7574
7575 // Ensure none of the TypoExprs have multiple typo correction candidates
7576 // with the same edit length that pass all the checks and filters.
7577 // TODO: Properly handle various permutations of possible corrections when
7578 // there is more than one potentially ambiguous typo correction.
7579 // Also, disable typo correction while attempting the transform when
7580 // handling potentially ambiguous typo corrections as any new TypoExprs will
7581 // have been introduced by the application of one of the correction
7582 // candidates and add little to no value if corrected.
7583 SemaRef.DisableTypoCorrection = true;
7584 while (!AmbiguousTypoExprs.empty()) {
7585 auto TE = AmbiguousTypoExprs.back();
7586 auto Cached = TransformCache[TE];
7587 auto &State = SemaRef.getTypoExprState(TE);
7588 State.Consumer->saveCurrentPosition();
7589 TransformCache.erase(TE);
7590 if (!TryTransform(E).isInvalid()) {
7591 State.Consumer->resetCorrectionStream();
7592 TransformCache.erase(TE);
7593 Res = ExprError();
7594 break;
7595 }
7596 AmbiguousTypoExprs.remove(TE);
7597 State.Consumer->restoreSavedPosition();
7598 TransformCache[TE] = Cached;
7599 }
7600 SemaRef.DisableTypoCorrection = false;
7601
7602 // Ensure that all of the TypoExprs within the current Expr have been found.
7603 if (!Res.isUsable())
7604 FindTypoExprs(TypoExprs).TraverseStmt(E);
7605
7606 EmitAllDiagnostics();
7607
7608 return Res;
7609 }
7610
7611 ExprResult TransformTypoExpr(TypoExpr *E) {
7612 // If the TypoExpr hasn't been seen before, record it. Otherwise, return the
7613 // cached transformation result if there is one and the TypoExpr isn't the
7614 // first one that was encountered.
7615 auto &CacheEntry = TransformCache[E];
7616 if (!TypoExprs.insert(E) && !CacheEntry.isUnset()) {
7617 return CacheEntry;
7618 }
7619
7620 auto &State = SemaRef.getTypoExprState(E);
7621 assert(State.Consumer && "Cannot transform a cleared TypoExpr")(static_cast <bool> (State.Consumer && "Cannot transform a cleared TypoExpr"
) ? void (0) : __assert_fail ("State.Consumer && \"Cannot transform a cleared TypoExpr\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 7621, __extension__ __PRETTY_FUNCTION__))
;
7622
7623 // For the first TypoExpr and an uncached TypoExpr, find the next likely
7624 // typo correction and return it.
7625 while (TypoCorrection TC = State.Consumer->getNextCorrection()) {
7626 if (InitDecl && TC.getFoundDecl() == InitDecl)
7627 continue;
7628 // FIXME: If we would typo-correct to an invalid declaration, it's
7629 // probably best to just suppress all errors from this typo correction.
7630 ExprResult NE = State.RecoveryHandler ?
7631 State.RecoveryHandler(SemaRef, E, TC) :
7632 attemptRecovery(SemaRef, *State.Consumer, TC);
7633 if (!NE.isInvalid()) {
7634 // Check whether there may be a second viable correction with the same
7635 // edit distance; if so, remember this TypoExpr may have an ambiguous
7636 // correction so it can be more thoroughly vetted later.
7637 TypoCorrection Next;
7638 if ((Next = State.Consumer->peekNextCorrection()) &&
7639 Next.getEditDistance(false) == TC.getEditDistance(false)) {
7640 AmbiguousTypoExprs.insert(E);
7641 } else {
7642 AmbiguousTypoExprs.remove(E);
7643 }
7644 assert(!NE.isUnset() &&(static_cast <bool> (!NE.isUnset() && "Typo was transformed into a valid-but-null ExprResult"
) ? void (0) : __assert_fail ("!NE.isUnset() && \"Typo was transformed into a valid-but-null ExprResult\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 7645, __extension__ __PRETTY_FUNCTION__))
7645 "Typo was transformed into a valid-but-null ExprResult")(static_cast <bool> (!NE.isUnset() && "Typo was transformed into a valid-but-null ExprResult"
) ? void (0) : __assert_fail ("!NE.isUnset() && \"Typo was transformed into a valid-but-null ExprResult\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 7645, __extension__ __PRETTY_FUNCTION__))
;
7646 return CacheEntry = NE;
7647 }
7648 }
7649 return CacheEntry = ExprError();
7650 }
7651};
7652}
7653
7654ExprResult
7655Sema::CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl,
7656 llvm::function_ref<ExprResult(Expr *)> Filter) {
7657 // If the current evaluation context indicates there are uncorrected typos
7658 // and the current expression isn't guaranteed to not have typos, try to
7659 // resolve any TypoExpr nodes that might be in the expression.
7660 if (E && !ExprEvalContexts.empty() && ExprEvalContexts.back().NumTypos &&
7661 (E->isTypeDependent() || E->isValueDependent() ||
7662 E->isInstantiationDependent())) {
7663 auto TyposInContext = ExprEvalContexts.back().NumTypos;
7664 assert(TyposInContext < ~0U && "Recursive call of CorrectDelayedTyposInExpr")(static_cast <bool> (TyposInContext < ~0U &&
"Recursive call of CorrectDelayedTyposInExpr") ? void (0) : __assert_fail
("TyposInContext < ~0U && \"Recursive call of CorrectDelayedTyposInExpr\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 7664, __extension__ __PRETTY_FUNCTION__))
;
7665 ExprEvalContexts.back().NumTypos = ~0U;
7666 auto TyposResolved = DelayedTypos.size();
7667 auto Result = TransformTypos(*this, InitDecl, Filter).Transform(E);
7668 ExprEvalContexts.back().NumTypos = TyposInContext;
7669 TyposResolved -= DelayedTypos.size();
7670 if (Result.isInvalid() || Result.get() != E) {
7671 ExprEvalContexts.back().NumTypos -= TyposResolved;
7672 return Result;
7673 }
7674 assert(TyposResolved == 0 && "Corrected typo but got same Expr back?")(static_cast <bool> (TyposResolved == 0 && "Corrected typo but got same Expr back?"
) ? void (0) : __assert_fail ("TyposResolved == 0 && \"Corrected typo but got same Expr back?\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 7674, __extension__ __PRETTY_FUNCTION__))
;
7675 }
7676 return E;
7677}
7678
7679ExprResult Sema::ActOnFinishFullExpr(Expr *FE, SourceLocation CC,
7680 bool DiscardedValue,
7681 bool IsConstexpr,
7682 bool IsLambdaInitCaptureInitializer) {
7683 ExprResult FullExpr = FE;
7684
7685 if (!FullExpr.get())
7686 return ExprError();
7687
7688 // If we are an init-expression in a lambdas init-capture, we should not
7689 // diagnose an unexpanded pack now (will be diagnosed once lambda-expr
7690 // containing full-expression is done).
7691 // template<class ... Ts> void test(Ts ... t) {
7692 // test([&a(t)]() { <-- (t) is an init-expr that shouldn't be diagnosed now.
7693 // return a;
7694 // }() ...);
7695 // }
7696 // FIXME: This is a hack. It would be better if we pushed the lambda scope
7697 // when we parse the lambda introducer, and teach capturing (but not
7698 // unexpanded pack detection) to walk over LambdaScopeInfos which don't have a
7699 // corresponding class yet (that is, have LambdaScopeInfo either represent a
7700 // lambda where we've entered the introducer but not the body, or represent a
7701 // lambda where we've entered the body, depending on where the
7702 // parser/instantiation has got to).
7703 if (!IsLambdaInitCaptureInitializer &&
7704 DiagnoseUnexpandedParameterPack(FullExpr.get()))
7705 return ExprError();
7706
7707 // Top-level expressions default to 'id' when we're in a debugger.
7708 if (DiscardedValue && getLangOpts().DebuggerCastResultToId &&
7709 FullExpr.get()->getType() == Context.UnknownAnyTy) {
7710 FullExpr = forceUnknownAnyToType(FullExpr.get(), Context.getObjCIdType());
7711 if (FullExpr.isInvalid())
7712 return ExprError();
7713 }
7714
7715 if (DiscardedValue) {
7716 FullExpr = CheckPlaceholderExpr(FullExpr.get());
7717 if (FullExpr.isInvalid())
7718 return ExprError();
7719
7720 FullExpr = IgnoredValueConversions(FullExpr.get());
7721 if (FullExpr.isInvalid())
7722 return ExprError();
7723 }
7724
7725 FullExpr = CorrectDelayedTyposInExpr(FullExpr.get());
7726 if (FullExpr.isInvalid())
7727 return ExprError();
7728
7729 CheckCompletedExpr(FullExpr.get(), CC, IsConstexpr);
7730
7731 // At the end of this full expression (which could be a deeply nested
7732 // lambda), if there is a potential capture within the nested lambda,
7733 // have the outer capture-able lambda try and capture it.
7734 // Consider the following code:
7735 // void f(int, int);
7736 // void f(const int&, double);
7737 // void foo() {
7738 // const int x = 10, y = 20;
7739 // auto L = [=](auto a) {
7740 // auto M = [=](auto b) {
7741 // f(x, b); <-- requires x to be captured by L and M
7742 // f(y, a); <-- requires y to be captured by L, but not all Ms
7743 // };
7744 // };
7745 // }
7746
7747 // FIXME: Also consider what happens for something like this that involves
7748 // the gnu-extension statement-expressions or even lambda-init-captures:
7749 // void f() {
7750 // const int n = 0;
7751 // auto L = [&](auto a) {
7752 // +n + ({ 0; a; });
7753 // };
7754 // }
7755 //
7756 // Here, we see +n, and then the full-expression 0; ends, so we don't
7757 // capture n (and instead remove it from our list of potential captures),
7758 // and then the full-expression +n + ({ 0; }); ends, but it's too late
7759 // for us to see that we need to capture n after all.
7760
7761 LambdaScopeInfo *const CurrentLSI =
7762 getCurLambda(/*IgnoreCapturedRegions=*/true);
7763 // FIXME: PR 17877 showed that getCurLambda() can return a valid pointer
7764 // even if CurContext is not a lambda call operator. Refer to that Bug Report
7765 // for an example of the code that might cause this asynchrony.
7766 // By ensuring we are in the context of a lambda's call operator
7767 // we can fix the bug (we only need to check whether we need to capture
7768 // if we are within a lambda's body); but per the comments in that
7769 // PR, a proper fix would entail :
7770 // "Alternative suggestion:
7771 // - Add to Sema an integer holding the smallest (outermost) scope
7772 // index that we are *lexically* within, and save/restore/set to
7773 // FunctionScopes.size() in InstantiatingTemplate's
7774 // constructor/destructor.
7775 // - Teach the handful of places that iterate over FunctionScopes to
7776 // stop at the outermost enclosing lexical scope."
7777 DeclContext *DC = CurContext;
7778 while (DC && isa<CapturedDecl>(DC))
7779 DC = DC->getParent();
7780 const bool IsInLambdaDeclContext = isLambdaCallOperator(DC);
7781 if (IsInLambdaDeclContext && CurrentLSI &&
7782 CurrentLSI->hasPotentialCaptures() && !FullExpr.isInvalid())
7783 CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures(FE, CurrentLSI,
7784 *this);
7785 return MaybeCreateExprWithCleanups(FullExpr);
7786}
7787
7788StmtResult Sema::ActOnFinishFullStmt(Stmt *FullStmt) {
7789 if (!FullStmt) return StmtError();
7790
7791 return MaybeCreateStmtWithCleanups(FullStmt);
7792}
7793
7794Sema::IfExistsResult
7795Sema::CheckMicrosoftIfExistsSymbol(Scope *S,
7796 CXXScopeSpec &SS,
7797 const DeclarationNameInfo &TargetNameInfo) {
7798 DeclarationName TargetName = TargetNameInfo.getName();
7799 if (!TargetName)
7800 return IER_DoesNotExist;
7801
7802 // If the name itself is dependent, then the result is dependent.
7803 if (TargetName.isDependentName())
7804 return IER_Dependent;
7805
7806 // Do the redeclaration lookup in the current scope.
7807 LookupResult R(*this, TargetNameInfo, Sema::LookupAnyName,
7808 Sema::NotForRedeclaration);
7809 LookupParsedName(R, S, &SS);
7810 R.suppressDiagnostics();
7811
7812 switch (R.getResultKind()) {
7813 case LookupResult::Found:
7814 case LookupResult::FoundOverloaded:
7815 case LookupResult::FoundUnresolvedValue:
7816 case LookupResult::Ambiguous:
7817 return IER_Exists;
7818
7819 case LookupResult::NotFound:
7820 return IER_DoesNotExist;
7821
7822 case LookupResult::NotFoundInCurrentInstantiation:
7823 return IER_Dependent;
7824 }
7825
7826 llvm_unreachable("Invalid LookupResult Kind!")::llvm::llvm_unreachable_internal("Invalid LookupResult Kind!"
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Sema/SemaExprCXX.cpp"
, 7826)
;
7827}
7828
7829Sema::IfExistsResult
7830Sema::CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc,
7831 bool IsIfExists, CXXScopeSpec &SS,
7832 UnqualifiedId &Name) {
7833 DeclarationNameInfo TargetNameInfo = GetNameFromUnqualifiedId(Name);
7834
7835 // Check for an unexpanded parameter pack.
7836 auto UPPC = IsIfExists ? UPPC_IfExists : UPPC_IfNotExists;
7837 if (DiagnoseUnexpandedParameterPack(SS, UPPC) ||
7838 DiagnoseUnexpandedParameterPack(TargetNameInfo, UPPC))
7839 return IER_Error;
7840
7841 return CheckMicrosoftIfExistsSymbol(S, SS, TargetNameInfo);
7842}

/build/llvm-toolchain-snapshot-7~svn329677/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 AMDGPUFlatWorkGroupSizeAttr : public InheritableAttr {
13unsigned min;
14
15unsigned max;
16
17public:
18 static AMDGPUFlatWorkGroupSizeAttr *CreateImplicit(ASTContext &Ctx, unsigned Min, unsigned Max, SourceRange Loc = SourceRange()) {
19 auto *A = new (Ctx) AMDGPUFlatWorkGroupSizeAttr(Loc, Ctx, Min, Max, 0);
20 A->setImplicit(true);
21 return A;
22 }
23
24 AMDGPUFlatWorkGroupSizeAttr(SourceRange R, ASTContext &Ctx
25 , unsigned Min
26 , unsigned Max
27 , unsigned SI
28 )
29 : InheritableAttr(attr::AMDGPUFlatWorkGroupSize, R, SI, false, false)
30 , min(Min)
31 , max(Max)
32 {
33 }
34
35 AMDGPUFlatWorkGroupSizeAttr *clone(ASTContext &C) const;
36 void printPretty(raw_ostream &OS,
37 const PrintingPolicy &Policy) const;
38 const char *getSpelling() const;
39 unsigned getMin() const {
40 return min;
41 }
42
43 unsigned getMax() const {
44 return max;
45 }
46
47
48
49 static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUFlatWorkGroupSize; }
50};
51
52class AMDGPUNumSGPRAttr : public InheritableAttr {
53unsigned numSGPR;
54
55public:
56 static AMDGPUNumSGPRAttr *CreateImplicit(ASTContext &Ctx, unsigned NumSGPR, SourceRange Loc = SourceRange()) {
57 auto *A = new (Ctx) AMDGPUNumSGPRAttr(Loc, Ctx, NumSGPR, 0);
58 A->setImplicit(true);
59 return A;
60 }
61
62 AMDGPUNumSGPRAttr(SourceRange R, ASTContext &Ctx
63 , unsigned NumSGPR
64 , unsigned SI
65 )
66 : InheritableAttr(attr::AMDGPUNumSGPR, R, SI, false, false)
67 , numSGPR(NumSGPR)
68 {
69 }
70
71 AMDGPUNumSGPRAttr *clone(ASTContext &C) const;
72 void printPretty(raw_ostream &OS,
73 const PrintingPolicy &Policy) const;
74 const char *getSpelling() const;
75 unsigned getNumSGPR() const {
76 return numSGPR;
77 }
78
79
80
81 static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUNumSGPR; }
82};
83
84class AMDGPUNumVGPRAttr : public InheritableAttr {
85unsigned numVGPR;
86
87public:
88 static AMDGPUNumVGPRAttr *CreateImplicit(ASTContext &Ctx, unsigned NumVGPR, SourceRange Loc = SourceRange()) {
89 auto *A = new (Ctx) AMDGPUNumVGPRAttr(Loc, Ctx, NumVGPR, 0);
90 A->setImplicit(true);
91 return A;
92 }
93
94 AMDGPUNumVGPRAttr(SourceRange R, ASTContext &Ctx
95 , unsigned NumVGPR
96 , unsigned SI
97 )
98 : InheritableAttr(attr::AMDGPUNumVGPR, R, SI, false, false)
99 , numVGPR(NumVGPR)
100 {
101 }
102
103 AMDGPUNumVGPRAttr *clone(ASTContext &C) const;
104 void printPretty(raw_ostream &OS,
105 const PrintingPolicy &Policy) const;
106 const char *getSpelling() const;
107 unsigned getNumVGPR() const {
108 return numVGPR;
109 }
110
111
112
113 static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUNumVGPR; }
114};
115
116class AMDGPUWavesPerEUAttr : public InheritableAttr {
117unsigned min;
118
119unsigned max;
120
121public:
122 static AMDGPUWavesPerEUAttr *CreateImplicit(ASTContext &Ctx, unsigned Min, unsigned Max, SourceRange Loc = SourceRange()) {
123 auto *A = new (Ctx) AMDGPUWavesPerEUAttr(Loc, Ctx, Min, Max, 0);
124 A->setImplicit(true);
125 return A;
126 }
127
128 AMDGPUWavesPerEUAttr(SourceRange R, ASTContext &Ctx
129 , unsigned Min
130 , unsigned Max
131 , unsigned SI
132 )
133 : InheritableAttr(attr::AMDGPUWavesPerEU, R, SI, false, false)
134 , min(Min)
135 , max(Max)
136 {
137 }
138
139 AMDGPUWavesPerEUAttr(SourceRange R, ASTContext &Ctx
140 , unsigned Min
141 , unsigned SI
142 )
143 : InheritableAttr(attr::AMDGPUWavesPerEU, R, SI, false, false)
144 , min(Min)
145 , max()
146 {
147 }
148
149 AMDGPUWavesPerEUAttr *clone(ASTContext &C) const;
150 void printPretty(raw_ostream &OS,
151 const PrintingPolicy &Policy) const;
152 const char *getSpelling() const;
153 unsigned getMin() const {
154 return min;
155 }
156
157 unsigned getMax() const {
158 return max;
159 }
160
161
162
163 static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUWavesPerEU; }
164};
165
166class ARMInterruptAttr : public InheritableAttr {
167public:
168 enum InterruptType {
169 IRQ,
170 FIQ,
171 SWI,
172 ABORT,
173 UNDEF,
174 Generic
175 };
176private:
177 InterruptType interrupt;
178
179public:
180 static ARMInterruptAttr *CreateImplicit(ASTContext &Ctx, InterruptType Interrupt, SourceRange Loc = SourceRange()) {
181 auto *A = new (Ctx) ARMInterruptAttr(Loc, Ctx, Interrupt, 0);
182 A->setImplicit(true);
183 return A;
184 }
185
186 ARMInterruptAttr(SourceRange R, ASTContext &Ctx
187 , InterruptType Interrupt
188 , unsigned SI
189 )
190 : InheritableAttr(attr::ARMInterrupt, R, SI, false, false)
191 , interrupt(Interrupt)
192 {
193 }
194
195 ARMInterruptAttr(SourceRange R, ASTContext &Ctx
196 , unsigned SI
197 )
198 : InheritableAttr(attr::ARMInterrupt, R, SI, false, false)
199 , interrupt(InterruptType(0))
200 {
201 }
202
203 ARMInterruptAttr *clone(ASTContext &C) const;
204 void printPretty(raw_ostream &OS,
205 const PrintingPolicy &Policy) const;
206 const char *getSpelling() const;
207 InterruptType getInterrupt() const {
208 return interrupt;
209 }
210
211 static bool ConvertStrToInterruptType(StringRef Val, InterruptType &Out) {
212 Optional<InterruptType> R = llvm::StringSwitch<Optional<InterruptType>>(Val)
213 .Case("IRQ", ARMInterruptAttr::IRQ)
214 .Case("FIQ", ARMInterruptAttr::FIQ)
215 .Case("SWI", ARMInterruptAttr::SWI)
216 .Case("ABORT", ARMInterruptAttr::ABORT)
217 .Case("UNDEF", ARMInterruptAttr::UNDEF)
218 .Case("", ARMInterruptAttr::Generic)
219 .Default(Optional<InterruptType>());
220 if (R) {
221 Out = *R;
222 return true;
223 }
224 return false;
225 }
226
227 static const char *ConvertInterruptTypeToStr(InterruptType Val) {
228 switch(Val) {
229 case ARMInterruptAttr::IRQ: return "IRQ";
230 case ARMInterruptAttr::FIQ: return "FIQ";
231 case ARMInterruptAttr::SWI: return "SWI";
232 case ARMInterruptAttr::ABORT: return "ABORT";
233 case ARMInterruptAttr::UNDEF: return "UNDEF";
234 case ARMInterruptAttr::Generic: return "";
235 }
236 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 236)
;
237 }
238
239
240 static bool classof(const Attr *A) { return A->getKind() == attr::ARMInterrupt; }
241};
242
243class AVRInterruptAttr : public InheritableAttr {
244public:
245 static AVRInterruptAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
246 auto *A = new (Ctx) AVRInterruptAttr(Loc, Ctx, 0);
247 A->setImplicit(true);
248 return A;
249 }
250
251 AVRInterruptAttr(SourceRange R, ASTContext &Ctx
252 , unsigned SI
253 )
254 : InheritableAttr(attr::AVRInterrupt, R, SI, false, false)
255 {
256 }
257
258 AVRInterruptAttr *clone(ASTContext &C) const;
259 void printPretty(raw_ostream &OS,
260 const PrintingPolicy &Policy) const;
261 const char *getSpelling() const;
262
263
264 static bool classof(const Attr *A) { return A->getKind() == attr::AVRInterrupt; }
265};
266
267class AVRSignalAttr : public InheritableAttr {
268public:
269 static AVRSignalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
270 auto *A = new (Ctx) AVRSignalAttr(Loc, Ctx, 0);
271 A->setImplicit(true);
272 return A;
273 }
274
275 AVRSignalAttr(SourceRange R, ASTContext &Ctx
276 , unsigned SI
277 )
278 : InheritableAttr(attr::AVRSignal, R, SI, false, false)
279 {
280 }
281
282 AVRSignalAttr *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::AVRSignal; }
289};
290
291class AbiTagAttr : public Attr {
292 unsigned tags_Size;
293 StringRef *tags_;
294
295public:
296 static AbiTagAttr *CreateImplicit(ASTContext &Ctx, StringRef *Tags, unsigned TagsSize, SourceRange Loc = SourceRange()) {
297 auto *A = new (Ctx) AbiTagAttr(Loc, Ctx, Tags, TagsSize, 0);
298 A->setImplicit(true);
299 return A;
300 }
301
302 AbiTagAttr(SourceRange R, ASTContext &Ctx
303 , StringRef *Tags, unsigned TagsSize
304 , unsigned SI
305 )
306 : Attr(attr::AbiTag, R, SI, false)
307 , tags_Size(TagsSize), tags_(new (Ctx, 16) StringRef[tags_Size])
308 {
309 for (size_t I = 0, E = tags_Size; I != E;
310 ++I) {
311 StringRef Ref = Tags[I];
312 if (!Ref.empty()) {
313 char *Mem = new (Ctx, 1) char[Ref.size()];
314 std::memcpy(Mem, Ref.data(), Ref.size());
315 tags_[I] = StringRef(Mem, Ref.size());
316 }
317 }
318 }
319
320 AbiTagAttr(SourceRange R, ASTContext &Ctx
321 , unsigned SI
322 )
323 : Attr(attr::AbiTag, R, SI, false)
324 , tags_Size(0), tags_(nullptr)
325 {
326 }
327
328 AbiTagAttr *clone(ASTContext &C) const;
329 void printPretty(raw_ostream &OS,
330 const PrintingPolicy &Policy) const;
331 const char *getSpelling() const;
332 typedef StringRef* tags_iterator;
333 tags_iterator tags_begin() const { return tags_; }
334 tags_iterator tags_end() const { return tags_ + tags_Size; }
335 unsigned tags_size() const { return tags_Size; }
336 llvm::iterator_range<tags_iterator> tags() const { return llvm::make_range(tags_begin(), tags_end()); }
337
338
339
340
341 static bool classof(const Attr *A) { return A->getKind() == attr::AbiTag; }
342};
343
344class AcquireCapabilityAttr : public InheritableAttr {
345 unsigned args_Size;
346 Expr * *args_;
347
348public:
349 enum Spelling {
350 GNU_acquire_capability = 0,
351 CXX11_clang_acquire_capability = 1,
352 GNU_acquire_shared_capability = 2,
353 CXX11_clang_acquire_shared_capability = 3,
354 GNU_exclusive_lock_function = 4,
355 GNU_shared_lock_function = 5
356 };
357
358 static AcquireCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
359 auto *A = new (Ctx) AcquireCapabilityAttr(Loc, Ctx, Args, ArgsSize, S);
360 A->setImplicit(true);
361 return A;
362 }
363
364 AcquireCapabilityAttr(SourceRange R, ASTContext &Ctx
365 , Expr * *Args, unsigned ArgsSize
366 , unsigned SI
367 )
368 : InheritableAttr(attr::AcquireCapability, R, SI, true, true)
369 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
370 {
371 std::copy(Args, Args + args_Size, args_);
372 }
373
374 AcquireCapabilityAttr(SourceRange R, ASTContext &Ctx
375 , unsigned SI
376 )
377 : InheritableAttr(attr::AcquireCapability, R, SI, true, true)
378 , args_Size(0), args_(nullptr)
379 {
380 }
381
382 AcquireCapabilityAttr *clone(ASTContext &C) const;
383 void printPretty(raw_ostream &OS,
384 const PrintingPolicy &Policy) const;
385 const char *getSpelling() const;
386 Spelling getSemanticSpelling() const {
387 switch (SpellingListIndex) {
388 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 388)
;
389 case 0: return GNU_acquire_capability;
390 case 1: return CXX11_clang_acquire_capability;
391 case 2: return GNU_acquire_shared_capability;
392 case 3: return CXX11_clang_acquire_shared_capability;
393 case 4: return GNU_exclusive_lock_function;
394 case 5: return GNU_shared_lock_function;
395 }
396 }
397 bool isShared() const { return SpellingListIndex == 2 ||
398 SpellingListIndex == 3 ||
399 SpellingListIndex == 5; }
400 typedef Expr ** args_iterator;
401 args_iterator args_begin() const { return args_; }
402 args_iterator args_end() const { return args_ + args_Size; }
403 unsigned args_size() const { return args_Size; }
404 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
405
406
407
408
409 static bool classof(const Attr *A) { return A->getKind() == attr::AcquireCapability; }
410};
411
412class AcquiredAfterAttr : public InheritableAttr {
413 unsigned args_Size;
414 Expr * *args_;
415
416public:
417 static AcquiredAfterAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
418 auto *A = new (Ctx) AcquiredAfterAttr(Loc, Ctx, Args, ArgsSize, 0);
419 A->setImplicit(true);
420 return A;
421 }
422
423 AcquiredAfterAttr(SourceRange R, ASTContext &Ctx
424 , Expr * *Args, unsigned ArgsSize
425 , unsigned SI
426 )
427 : InheritableAttr(attr::AcquiredAfter, R, SI, true, true)
428 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
429 {
430 std::copy(Args, Args + args_Size, args_);
431 }
432
433 AcquiredAfterAttr(SourceRange R, ASTContext &Ctx
434 , unsigned SI
435 )
436 : InheritableAttr(attr::AcquiredAfter, R, SI, true, true)
437 , args_Size(0), args_(nullptr)
438 {
439 }
440
441 AcquiredAfterAttr *clone(ASTContext &C) const;
442 void printPretty(raw_ostream &OS,
443 const PrintingPolicy &Policy) const;
444 const char *getSpelling() const;
445 typedef Expr ** args_iterator;
446 args_iterator args_begin() const { return args_; }
447 args_iterator args_end() const { return args_ + args_Size; }
448 unsigned args_size() const { return args_Size; }
449 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
450
451
452
453
454 static bool classof(const Attr *A) { return A->getKind() == attr::AcquiredAfter; }
455};
456
457class AcquiredBeforeAttr : public InheritableAttr {
458 unsigned args_Size;
459 Expr * *args_;
460
461public:
462 static AcquiredBeforeAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
463 auto *A = new (Ctx) AcquiredBeforeAttr(Loc, Ctx, Args, ArgsSize, 0);
464 A->setImplicit(true);
465 return A;
466 }
467
468 AcquiredBeforeAttr(SourceRange R, ASTContext &Ctx
469 , Expr * *Args, unsigned ArgsSize
470 , unsigned SI
471 )
472 : InheritableAttr(attr::AcquiredBefore, R, SI, true, true)
473 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
474 {
475 std::copy(Args, Args + args_Size, args_);
476 }
477
478 AcquiredBeforeAttr(SourceRange R, ASTContext &Ctx
479 , unsigned SI
480 )
481 : InheritableAttr(attr::AcquiredBefore, R, SI, true, true)
482 , args_Size(0), args_(nullptr)
483 {
484 }
485
486 AcquiredBeforeAttr *clone(ASTContext &C) const;
487 void printPretty(raw_ostream &OS,
488 const PrintingPolicy &Policy) const;
489 const char *getSpelling() const;
490 typedef Expr ** args_iterator;
491 args_iterator args_begin() const { return args_; }
492 args_iterator args_end() const { return args_ + args_Size; }
493 unsigned args_size() const { return args_Size; }
494 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
495
496
497
498
499 static bool classof(const Attr *A) { return A->getKind() == attr::AcquiredBefore; }
500};
501
502class AliasAttr : public Attr {
503unsigned aliaseeLength;
504char *aliasee;
505
506public:
507 static AliasAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Aliasee, SourceRange Loc = SourceRange()) {
508 auto *A = new (Ctx) AliasAttr(Loc, Ctx, Aliasee, 0);
509 A->setImplicit(true);
510 return A;
511 }
512
513 AliasAttr(SourceRange R, ASTContext &Ctx
514 , llvm::StringRef Aliasee
515 , unsigned SI
516 )
517 : Attr(attr::Alias, R, SI, false)
518 , aliaseeLength(Aliasee.size()),aliasee(new (Ctx, 1) char[aliaseeLength])
519 {
520 if (!Aliasee.empty())
521 std::memcpy(aliasee, Aliasee.data(), aliaseeLength);
522 }
523
524 AliasAttr *clone(ASTContext &C) const;
525 void printPretty(raw_ostream &OS,
526 const PrintingPolicy &Policy) const;
527 const char *getSpelling() const;
528 llvm::StringRef getAliasee() const {
529 return llvm::StringRef(aliasee, aliaseeLength);
530 }
531 unsigned getAliaseeLength() const {
532 return aliaseeLength;
533 }
534 void setAliasee(ASTContext &C, llvm::StringRef S) {
535 aliaseeLength = S.size();
536 this->aliasee = new (C, 1) char [aliaseeLength];
537 if (!S.empty())
538 std::memcpy(this->aliasee, S.data(), aliaseeLength);
539 }
540
541
542
543 static bool classof(const Attr *A) { return A->getKind() == attr::Alias; }
544};
545
546class AlignMac68kAttr : public InheritableAttr {
547public:
548 static AlignMac68kAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
549 auto *A = new (Ctx) AlignMac68kAttr(Loc, Ctx, 0);
550 A->setImplicit(true);
551 return A;
552 }
553
554 AlignMac68kAttr(SourceRange R, ASTContext &Ctx
555 , unsigned SI
556 )
557 : InheritableAttr(attr::AlignMac68k, R, SI, false, false)
558 {
559 }
560
561 AlignMac68kAttr *clone(ASTContext &C) const;
562 void printPretty(raw_ostream &OS,
563 const PrintingPolicy &Policy) const;
564 const char *getSpelling() const;
565
566
567 static bool classof(const Attr *A) { return A->getKind() == attr::AlignMac68k; }
568};
569
570class AlignValueAttr : public Attr {
571Expr * alignment;
572
573public:
574 static AlignValueAttr *CreateImplicit(ASTContext &Ctx, Expr * Alignment, SourceRange Loc = SourceRange()) {
575 auto *A = new (Ctx) AlignValueAttr(Loc, Ctx, Alignment, 0);
576 A->setImplicit(true);
577 return A;
578 }
579
580 AlignValueAttr(SourceRange R, ASTContext &Ctx
581 , Expr * Alignment
582 , unsigned SI
583 )
584 : Attr(attr::AlignValue, R, SI, false)
585 , alignment(Alignment)
586 {
587 }
588
589 AlignValueAttr *clone(ASTContext &C) const;
590 void printPretty(raw_ostream &OS,
591 const PrintingPolicy &Policy) const;
592 const char *getSpelling() const;
593 Expr * getAlignment() const {
594 return alignment;
595 }
596
597
598
599 static bool classof(const Attr *A) { return A->getKind() == attr::AlignValue; }
600};
601
602class AlignedAttr : public InheritableAttr {
603bool isalignmentExpr;
604union {
605Expr *alignmentExpr;
606TypeSourceInfo *alignmentType;
607};
608
609public:
610 enum Spelling {
611 GNU_aligned = 0,
612 CXX11_gnu_aligned = 1,
613 Declspec_align = 2,
614 Keyword_alignas = 3,
615 Keyword_Alignas = 4
616 };
617
618 static AlignedAttr *CreateImplicit(ASTContext &Ctx, Spelling S, bool IsAlignmentExpr, void *Alignment, SourceRange Loc = SourceRange()) {
619 auto *A = new (Ctx) AlignedAttr(Loc, Ctx, IsAlignmentExpr, Alignment, S);
620 A->setImplicit(true);
621 return A;
622 }
623
624 AlignedAttr(SourceRange R, ASTContext &Ctx
625 , bool IsAlignmentExpr, void *Alignment
626 , unsigned SI
627 )
628 : InheritableAttr(attr::Aligned, R, SI, false, false)
629 , isalignmentExpr(IsAlignmentExpr)
630 {
631 if (isalignmentExpr)
632 alignmentExpr = reinterpret_cast<Expr *>(Alignment);
633 else
634 alignmentType = reinterpret_cast<TypeSourceInfo *>(Alignment);
635 }
636
637 AlignedAttr(SourceRange R, ASTContext &Ctx
638 , unsigned SI
639 )
640 : InheritableAttr(attr::Aligned, R, SI, false, false)
641 , isalignmentExpr(false)
642 {
643 }
644
645 AlignedAttr *clone(ASTContext &C) const;
646 void printPretty(raw_ostream &OS,
647 const PrintingPolicy &Policy) const;
648 const char *getSpelling() const;
649 Spelling getSemanticSpelling() const {
650 switch (SpellingListIndex) {
651 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 651)
;
652 case 0: return GNU_aligned;
653 case 1: return CXX11_gnu_aligned;
654 case 2: return Declspec_align;
655 case 3: return Keyword_alignas;
656 case 4: return Keyword_Alignas;
657 }
658 }
659 bool isGNU() const { return SpellingListIndex == 0 ||
660 SpellingListIndex == 1; }
661 bool isC11() const { return SpellingListIndex == 4; }
662 bool isAlignas() const { return SpellingListIndex == 3 ||
663 SpellingListIndex == 4; }
664 bool isDeclspec() const { return SpellingListIndex == 2; }
665 bool isAlignmentDependent() const;
666 unsigned getAlignment(ASTContext &Ctx) const;
667 bool isAlignmentExpr() const {
668 return isalignmentExpr;
669 }
670 Expr *getAlignmentExpr() const {
671 assert(isalignmentExpr)(static_cast <bool> (isalignmentExpr) ? void (0) : __assert_fail
("isalignmentExpr", "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 671, __extension__ __PRETTY_FUNCTION__))
;
672 return alignmentExpr;
673 }
674 TypeSourceInfo *getAlignmentType() const {
675 assert(!isalignmentExpr)(static_cast <bool> (!isalignmentExpr) ? void (0) : __assert_fail
("!isalignmentExpr", "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 675, __extension__ __PRETTY_FUNCTION__))
;
676 return alignmentType;
677 }
678
679
680
681 static bool classof(const Attr *A) { return A->getKind() == attr::Aligned; }
682};
683
684class AllocAlignAttr : public InheritableAttr {
685ParamIdx paramIndex;
686
687public:
688 static AllocAlignAttr *CreateImplicit(ASTContext &Ctx, ParamIdx ParamIndex, SourceRange Loc = SourceRange()) {
689 auto *A = new (Ctx) AllocAlignAttr(Loc, Ctx, ParamIndex, 0);
690 A->setImplicit(true);
691 return A;
692 }
693
694 AllocAlignAttr(SourceRange R, ASTContext &Ctx
695 , ParamIdx ParamIndex
696 , unsigned SI
697 )
698 : InheritableAttr(attr::AllocAlign, R, SI, false, false)
699 , paramIndex(ParamIndex)
700 {
701 }
702
703 AllocAlignAttr *clone(ASTContext &C) const;
704 void printPretty(raw_ostream &OS,
705 const PrintingPolicy &Policy) const;
706 const char *getSpelling() const;
707 ParamIdx getParamIndex() const {
708 return paramIndex;
709 }
710
711
712
713 static bool classof(const Attr *A) { return A->getKind() == attr::AllocAlign; }
714};
715
716class AllocSizeAttr : public InheritableAttr {
717ParamIdx elemSizeParam;
718
719ParamIdx numElemsParam;
720
721public:
722 static AllocSizeAttr *CreateImplicit(ASTContext &Ctx, ParamIdx ElemSizeParam, ParamIdx NumElemsParam, SourceRange Loc = SourceRange()) {
723 auto *A = new (Ctx) AllocSizeAttr(Loc, Ctx, ElemSizeParam, NumElemsParam, 0);
724 A->setImplicit(true);
725 return A;
726 }
727
728 AllocSizeAttr(SourceRange R, ASTContext &Ctx
729 , ParamIdx ElemSizeParam
730 , ParamIdx NumElemsParam
731 , unsigned SI
732 )
733 : InheritableAttr(attr::AllocSize, R, SI, false, false)
734 , elemSizeParam(ElemSizeParam)
735 , numElemsParam(NumElemsParam)
736 {
737 }
738
739 AllocSizeAttr(SourceRange R, ASTContext &Ctx
740 , ParamIdx ElemSizeParam
741 , unsigned SI
742 )
743 : InheritableAttr(attr::AllocSize, R, SI, false, false)
744 , elemSizeParam(ElemSizeParam)
745 , numElemsParam()
746 {
747 }
748
749 AllocSizeAttr *clone(ASTContext &C) const;
750 void printPretty(raw_ostream &OS,
751 const PrintingPolicy &Policy) const;
752 const char *getSpelling() const;
753 ParamIdx getElemSizeParam() const {
754 return elemSizeParam;
755 }
756
757 ParamIdx getNumElemsParam() const {
758 return numElemsParam;
759 }
760
761
762
763 static bool classof(const Attr *A) { return A->getKind() == attr::AllocSize; }
764};
765
766class AlwaysInlineAttr : public InheritableAttr {
767public:
768 enum Spelling {
769 GNU_always_inline = 0,
770 CXX11_gnu_always_inline = 1,
771 Keyword_forceinline = 2
772 };
773
774 static AlwaysInlineAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
775 auto *A = new (Ctx) AlwaysInlineAttr(Loc, Ctx, S);
776 A->setImplicit(true);
777 return A;
778 }
779
780 AlwaysInlineAttr(SourceRange R, ASTContext &Ctx
781 , unsigned SI
782 )
783 : InheritableAttr(attr::AlwaysInline, R, SI, false, false)
784 {
785 }
786
787 AlwaysInlineAttr *clone(ASTContext &C) const;
788 void printPretty(raw_ostream &OS,
789 const PrintingPolicy &Policy) const;
790 const char *getSpelling() const;
791 Spelling getSemanticSpelling() const {
792 switch (SpellingListIndex) {
793 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 793)
;
794 case 0: return GNU_always_inline;
795 case 1: return CXX11_gnu_always_inline;
796 case 2: return Keyword_forceinline;
797 }
798 }
799
800
801 static bool classof(const Attr *A) { return A->getKind() == attr::AlwaysInline; }
802};
803
804class AnalyzerNoReturnAttr : public InheritableAttr {
805public:
806 static AnalyzerNoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
807 auto *A = new (Ctx) AnalyzerNoReturnAttr(Loc, Ctx, 0);
808 A->setImplicit(true);
809 return A;
810 }
811
812 AnalyzerNoReturnAttr(SourceRange R, ASTContext &Ctx
813 , unsigned SI
814 )
815 : InheritableAttr(attr::AnalyzerNoReturn, R, SI, false, false)
816 {
817 }
818
819 AnalyzerNoReturnAttr *clone(ASTContext &C) const;
820 void printPretty(raw_ostream &OS,
821 const PrintingPolicy &Policy) const;
822 const char *getSpelling() const;
823
824
825 static bool classof(const Attr *A) { return A->getKind() == attr::AnalyzerNoReturn; }
826};
827
828class AnnotateAttr : public InheritableParamAttr {
829unsigned annotationLength;
830char *annotation;
831
832public:
833 static AnnotateAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Annotation, SourceRange Loc = SourceRange()) {
834 auto *A = new (Ctx) AnnotateAttr(Loc, Ctx, Annotation, 0);
835 A->setImplicit(true);
836 return A;
837 }
838
839 AnnotateAttr(SourceRange R, ASTContext &Ctx
840 , llvm::StringRef Annotation
841 , unsigned SI
842 )
843 : InheritableParamAttr(attr::Annotate, R, SI, false, false)
844 , annotationLength(Annotation.size()),annotation(new (Ctx, 1) char[annotationLength])
845 {
846 if (!Annotation.empty())
847 std::memcpy(annotation, Annotation.data(), annotationLength);
848 }
849
850 AnnotateAttr *clone(ASTContext &C) const;
851 void printPretty(raw_ostream &OS,
852 const PrintingPolicy &Policy) const;
853 const char *getSpelling() const;
854 llvm::StringRef getAnnotation() const {
855 return llvm::StringRef(annotation, annotationLength);
856 }
857 unsigned getAnnotationLength() const {
858 return annotationLength;
859 }
860 void setAnnotation(ASTContext &C, llvm::StringRef S) {
861 annotationLength = S.size();
862 this->annotation = new (C, 1) char [annotationLength];
863 if (!S.empty())
864 std::memcpy(this->annotation, S.data(), annotationLength);
865 }
866
867
868
869 static bool classof(const Attr *A) { return A->getKind() == attr::Annotate; }
870};
871
872class AnyX86InterruptAttr : public InheritableAttr {
873public:
874 static AnyX86InterruptAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
875 auto *A = new (Ctx) AnyX86InterruptAttr(Loc, Ctx, 0);
876 A->setImplicit(true);
877 return A;
878 }
879
880 AnyX86InterruptAttr(SourceRange R, ASTContext &Ctx
881 , unsigned SI
882 )
883 : InheritableAttr(attr::AnyX86Interrupt, R, SI, false, false)
884 {
885 }
886
887 AnyX86InterruptAttr *clone(ASTContext &C) const;
888 void printPretty(raw_ostream &OS,
889 const PrintingPolicy &Policy) const;
890 const char *getSpelling() const;
891
892
893 static bool classof(const Attr *A) { return A->getKind() == attr::AnyX86Interrupt; }
894};
895
896class AnyX86NoCallerSavedRegistersAttr : public InheritableAttr {
897public:
898 static AnyX86NoCallerSavedRegistersAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
899 auto *A = new (Ctx) AnyX86NoCallerSavedRegistersAttr(Loc, Ctx, 0);
900 A->setImplicit(true);
901 return A;
902 }
903
904 AnyX86NoCallerSavedRegistersAttr(SourceRange R, ASTContext &Ctx
905 , unsigned SI
906 )
907 : InheritableAttr(attr::AnyX86NoCallerSavedRegisters, R, SI, false, false)
908 {
909 }
910
911 AnyX86NoCallerSavedRegistersAttr *clone(ASTContext &C) const;
912 void printPretty(raw_ostream &OS,
913 const PrintingPolicy &Policy) const;
914 const char *getSpelling() const;
915
916
917 static bool classof(const Attr *A) { return A->getKind() == attr::AnyX86NoCallerSavedRegisters; }
918};
919
920class AnyX86NoCfCheckAttr : public InheritableAttr {
921public:
922 static AnyX86NoCfCheckAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
923 auto *A = new (Ctx) AnyX86NoCfCheckAttr(Loc, Ctx, 0);
924 A->setImplicit(true);
925 return A;
926 }
927
928 AnyX86NoCfCheckAttr(SourceRange R, ASTContext &Ctx
929 , unsigned SI
930 )
931 : InheritableAttr(attr::AnyX86NoCfCheck, R, SI, false, false)
932 {
933 }
934
935 AnyX86NoCfCheckAttr *clone(ASTContext &C) const;
936 void printPretty(raw_ostream &OS,
937 const PrintingPolicy &Policy) const;
938 const char *getSpelling() const;
939
940
941 static bool classof(const Attr *A) { return A->getKind() == attr::AnyX86NoCfCheck; }
942};
943
944class ArcWeakrefUnavailableAttr : public InheritableAttr {
945public:
946 static ArcWeakrefUnavailableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
947 auto *A = new (Ctx) ArcWeakrefUnavailableAttr(Loc, Ctx, 0);
948 A->setImplicit(true);
949 return A;
950 }
951
952 ArcWeakrefUnavailableAttr(SourceRange R, ASTContext &Ctx
953 , unsigned SI
954 )
955 : InheritableAttr(attr::ArcWeakrefUnavailable, R, SI, false, false)
956 {
957 }
958
959 ArcWeakrefUnavailableAttr *clone(ASTContext &C) const;
960 void printPretty(raw_ostream &OS,
961 const PrintingPolicy &Policy) const;
962 const char *getSpelling() const;
963
964
965 static bool classof(const Attr *A) { return A->getKind() == attr::ArcWeakrefUnavailable; }
966};
967
968class ArgumentWithTypeTagAttr : public InheritableAttr {
969IdentifierInfo * argumentKind;
970
971ParamIdx argumentIdx;
972
973ParamIdx typeTagIdx;
974
975bool isPointer;
976
977public:
978 enum Spelling {
979 GNU_argument_with_type_tag = 0,
980 CXX11_clang_argument_with_type_tag = 1,
981 C2x_clang_argument_with_type_tag = 2,
982 GNU_pointer_with_type_tag = 3,
983 CXX11_clang_pointer_with_type_tag = 4,
984 C2x_clang_pointer_with_type_tag = 5
985 };
986
987 static ArgumentWithTypeTagAttr *CreateImplicit(ASTContext &Ctx, Spelling S, IdentifierInfo * ArgumentKind, ParamIdx ArgumentIdx, ParamIdx TypeTagIdx, bool IsPointer, SourceRange Loc = SourceRange()) {
988 auto *A = new (Ctx) ArgumentWithTypeTagAttr(Loc, Ctx, ArgumentKind, ArgumentIdx, TypeTagIdx, IsPointer, S);
989 A->setImplicit(true);
990 return A;
991 }
992
993 static ArgumentWithTypeTagAttr *CreateImplicit(ASTContext &Ctx, Spelling S, IdentifierInfo * ArgumentKind, ParamIdx ArgumentIdx, ParamIdx TypeTagIdx, SourceRange Loc = SourceRange()) {
994 auto *A = new (Ctx) ArgumentWithTypeTagAttr(Loc, Ctx, ArgumentKind, ArgumentIdx, TypeTagIdx, S);
995 A->setImplicit(true);
996 return A;
997 }
998
999 ArgumentWithTypeTagAttr(SourceRange R, ASTContext &Ctx
1000 , IdentifierInfo * ArgumentKind
1001 , ParamIdx ArgumentIdx
1002 , ParamIdx TypeTagIdx
1003 , bool IsPointer
1004 , unsigned SI
1005 )
1006 : InheritableAttr(attr::ArgumentWithTypeTag, R, SI, false, false)
1007 , argumentKind(ArgumentKind)
1008 , argumentIdx(ArgumentIdx)
1009 , typeTagIdx(TypeTagIdx)
1010 , isPointer(IsPointer)
1011 {
1012 }
1013
1014 ArgumentWithTypeTagAttr(SourceRange R, ASTContext &Ctx
1015 , IdentifierInfo * ArgumentKind
1016 , ParamIdx ArgumentIdx
1017 , ParamIdx TypeTagIdx
1018 , unsigned SI
1019 )
1020 : InheritableAttr(attr::ArgumentWithTypeTag, R, SI, false, false)
1021 , argumentKind(ArgumentKind)
1022 , argumentIdx(ArgumentIdx)
1023 , typeTagIdx(TypeTagIdx)
1024 , isPointer()
1025 {
1026 }
1027
1028 ArgumentWithTypeTagAttr *clone(ASTContext &C) const;
1029 void printPretty(raw_ostream &OS,
1030 const PrintingPolicy &Policy) const;
1031 const char *getSpelling() const;
1032 Spelling getSemanticSpelling() const {
1033 switch (SpellingListIndex) {
1034 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 1034)
;
1035 case 0: return GNU_argument_with_type_tag;
1036 case 1: return CXX11_clang_argument_with_type_tag;
1037 case 2: return C2x_clang_argument_with_type_tag;
1038 case 3: return GNU_pointer_with_type_tag;
1039 case 4: return CXX11_clang_pointer_with_type_tag;
1040 case 5: return C2x_clang_pointer_with_type_tag;
1041 }
1042 }
1043 IdentifierInfo * getArgumentKind() const {
1044 return argumentKind;
1045 }
1046
1047 ParamIdx getArgumentIdx() const {
1048 return argumentIdx;
1049 }
1050
1051 ParamIdx getTypeTagIdx() const {
1052 return typeTagIdx;
1053 }
1054
1055 bool getIsPointer() const {
1056 return isPointer;
1057 }
1058
1059
1060
1061 static bool classof(const Attr *A) { return A->getKind() == attr::ArgumentWithTypeTag; }
1062};
1063
1064class ArtificialAttr : public InheritableAttr {
1065public:
1066 static ArtificialAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1067 auto *A = new (Ctx) ArtificialAttr(Loc, Ctx, 0);
1068 A->setImplicit(true);
1069 return A;
1070 }
1071
1072 ArtificialAttr(SourceRange R, ASTContext &Ctx
1073 , unsigned SI
1074 )
1075 : InheritableAttr(attr::Artificial, R, SI, false, false)
1076 {
1077 }
1078
1079 ArtificialAttr *clone(ASTContext &C) const;
1080 void printPretty(raw_ostream &OS,
1081 const PrintingPolicy &Policy) const;
1082 const char *getSpelling() const;
1083
1084
1085 static bool classof(const Attr *A) { return A->getKind() == attr::Artificial; }
1086};
1087
1088class AsmLabelAttr : public InheritableAttr {
1089unsigned labelLength;
1090char *label;
1091
1092public:
1093 static AsmLabelAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Label, SourceRange Loc = SourceRange()) {
1094 auto *A = new (Ctx) AsmLabelAttr(Loc, Ctx, Label, 0);
1095 A->setImplicit(true);
1096 return A;
1097 }
1098
1099 AsmLabelAttr(SourceRange R, ASTContext &Ctx
1100 , llvm::StringRef Label
1101 , unsigned SI
1102 )
1103 : InheritableAttr(attr::AsmLabel, R, SI, false, false)
1104 , labelLength(Label.size()),label(new (Ctx, 1) char[labelLength])
1105 {
1106 if (!Label.empty())
1107 std::memcpy(label, Label.data(), labelLength);
1108 }
1109
1110 AsmLabelAttr *clone(ASTContext &C) const;
1111 void printPretty(raw_ostream &OS,
1112 const PrintingPolicy &Policy) const;
1113 const char *getSpelling() const;
1114 llvm::StringRef getLabel() const {
1115 return llvm::StringRef(label, labelLength);
1116 }
1117 unsigned getLabelLength() const {
1118 return labelLength;
1119 }
1120 void setLabel(ASTContext &C, llvm::StringRef S) {
1121 labelLength = S.size();
1122 this->label = new (C, 1) char [labelLength];
1123 if (!S.empty())
1124 std::memcpy(this->label, S.data(), labelLength);
1125 }
1126
1127
1128
1129 static bool classof(const Attr *A) { return A->getKind() == attr::AsmLabel; }
1130};
1131
1132class AssertCapabilityAttr : public InheritableAttr {
1133 unsigned args_Size;
1134 Expr * *args_;
1135
1136public:
1137 enum Spelling {
1138 GNU_assert_capability = 0,
1139 CXX11_clang_assert_capability = 1,
1140 GNU_assert_shared_capability = 2,
1141 CXX11_clang_assert_shared_capability = 3
1142 };
1143
1144 static AssertCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
1145 auto *A = new (Ctx) AssertCapabilityAttr(Loc, Ctx, Args, ArgsSize, S);
1146 A->setImplicit(true);
1147 return A;
1148 }
1149
1150 AssertCapabilityAttr(SourceRange R, ASTContext &Ctx
1151 , Expr * *Args, unsigned ArgsSize
1152 , unsigned SI
1153 )
1154 : InheritableAttr(attr::AssertCapability, R, SI, true, true)
1155 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
1156 {
1157 std::copy(Args, Args + args_Size, args_);
1158 }
1159
1160 AssertCapabilityAttr(SourceRange R, ASTContext &Ctx
1161 , unsigned SI
1162 )
1163 : InheritableAttr(attr::AssertCapability, R, SI, true, true)
1164 , args_Size(0), args_(nullptr)
1165 {
1166 }
1167
1168 AssertCapabilityAttr *clone(ASTContext &C) const;
1169 void printPretty(raw_ostream &OS,
1170 const PrintingPolicy &Policy) const;
1171 const char *getSpelling() const;
1172 Spelling getSemanticSpelling() const {
1173 switch (SpellingListIndex) {
1174 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 1174)
;
1175 case 0: return GNU_assert_capability;
1176 case 1: return CXX11_clang_assert_capability;
1177 case 2: return GNU_assert_shared_capability;
1178 case 3: return CXX11_clang_assert_shared_capability;
1179 }
1180 }
1181 bool isShared() const { return SpellingListIndex == 2 ||
1182 SpellingListIndex == 3; }
1183 typedef Expr ** args_iterator;
1184 args_iterator args_begin() const { return args_; }
1185 args_iterator args_end() const { return args_ + args_Size; }
1186 unsigned args_size() const { return args_Size; }
1187 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
1188
1189
1190
1191
1192 static bool classof(const Attr *A) { return A->getKind() == attr::AssertCapability; }
1193};
1194
1195class AssertExclusiveLockAttr : public InheritableAttr {
1196 unsigned args_Size;
1197 Expr * *args_;
1198
1199public:
1200 static AssertExclusiveLockAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
1201 auto *A = new (Ctx) AssertExclusiveLockAttr(Loc, Ctx, Args, ArgsSize, 0);
1202 A->setImplicit(true);
1203 return A;
1204 }
1205
1206 AssertExclusiveLockAttr(SourceRange R, ASTContext &Ctx
1207 , Expr * *Args, unsigned ArgsSize
1208 , unsigned SI
1209 )
1210 : InheritableAttr(attr::AssertExclusiveLock, R, SI, true, true)
1211 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
1212 {
1213 std::copy(Args, Args + args_Size, args_);
1214 }
1215
1216 AssertExclusiveLockAttr(SourceRange R, ASTContext &Ctx
1217 , unsigned SI
1218 )
1219 : InheritableAttr(attr::AssertExclusiveLock, R, SI, true, true)
1220 , args_Size(0), args_(nullptr)
1221 {
1222 }
1223
1224 AssertExclusiveLockAttr *clone(ASTContext &C) const;
1225 void printPretty(raw_ostream &OS,
1226 const PrintingPolicy &Policy) const;
1227 const char *getSpelling() const;
1228 typedef Expr ** args_iterator;
1229 args_iterator args_begin() const { return args_; }
1230 args_iterator args_end() const { return args_ + args_Size; }
1231 unsigned args_size() const { return args_Size; }
1232 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
1233
1234
1235
1236
1237 static bool classof(const Attr *A) { return A->getKind() == attr::AssertExclusiveLock; }
1238};
1239
1240class AssertSharedLockAttr : public InheritableAttr {
1241 unsigned args_Size;
1242 Expr * *args_;
1243
1244public:
1245 static AssertSharedLockAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
1246 auto *A = new (Ctx) AssertSharedLockAttr(Loc, Ctx, Args, ArgsSize, 0);
1247 A->setImplicit(true);
1248 return A;
1249 }
1250
1251 AssertSharedLockAttr(SourceRange R, ASTContext &Ctx
1252 , Expr * *Args, unsigned ArgsSize
1253 , unsigned SI
1254 )
1255 : InheritableAttr(attr::AssertSharedLock, R, SI, true, true)
1256 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
1257 {
1258 std::copy(Args, Args + args_Size, args_);
1259 }
1260
1261 AssertSharedLockAttr(SourceRange R, ASTContext &Ctx
1262 , unsigned SI
1263 )
1264 : InheritableAttr(attr::AssertSharedLock, R, SI, true, true)
1265 , args_Size(0), args_(nullptr)
1266 {
1267 }
1268
1269 AssertSharedLockAttr *clone(ASTContext &C) const;
1270 void printPretty(raw_ostream &OS,
1271 const PrintingPolicy &Policy) const;
1272 const char *getSpelling() const;
1273 typedef Expr ** args_iterator;
1274 args_iterator args_begin() const { return args_; }
1275 args_iterator args_end() const { return args_ + args_Size; }
1276 unsigned args_size() const { return args_Size; }
1277 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
1278
1279
1280
1281
1282 static bool classof(const Attr *A) { return A->getKind() == attr::AssertSharedLock; }
1283};
1284
1285class AssumeAlignedAttr : public InheritableAttr {
1286Expr * alignment;
1287
1288Expr * offset;
1289
1290public:
1291 static AssumeAlignedAttr *CreateImplicit(ASTContext &Ctx, Expr * Alignment, Expr * Offset, SourceRange Loc = SourceRange()) {
1292 auto *A = new (Ctx) AssumeAlignedAttr(Loc, Ctx, Alignment, Offset, 0);
1293 A->setImplicit(true);
1294 return A;
1295 }
1296
1297 AssumeAlignedAttr(SourceRange R, ASTContext &Ctx
1298 , Expr * Alignment
1299 , Expr * Offset
1300 , unsigned SI
1301 )
1302 : InheritableAttr(attr::AssumeAligned, R, SI, false, false)
1303 , alignment(Alignment)
1304 , offset(Offset)
1305 {
1306 }
1307
1308 AssumeAlignedAttr(SourceRange R, ASTContext &Ctx
1309 , Expr * Alignment
1310 , unsigned SI
1311 )
1312 : InheritableAttr(attr::AssumeAligned, R, SI, false, false)
1313 , alignment(Alignment)
1314 , offset()
1315 {
1316 }
1317
1318 AssumeAlignedAttr *clone(ASTContext &C) const;
1319 void printPretty(raw_ostream &OS,
1320 const PrintingPolicy &Policy) const;
1321 const char *getSpelling() const;
1322 Expr * getAlignment() const {
1323 return alignment;
1324 }
1325
1326 Expr * getOffset() const {
1327 return offset;
1328 }
1329
1330
1331
1332 static bool classof(const Attr *A) { return A->getKind() == attr::AssumeAligned; }
1333};
1334
1335class AvailabilityAttr : public InheritableAttr {
1336IdentifierInfo * platform;
1337
1338VersionTuple introduced;
1339
1340
1341VersionTuple deprecated;
1342
1343
1344VersionTuple obsoleted;
1345
1346
1347bool unavailable;
1348
1349unsigned messageLength;
1350char *message;
1351
1352bool strict;
1353
1354unsigned replacementLength;
1355char *replacement;
1356
1357public:
1358 static AvailabilityAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Platform, VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted, bool Unavailable, llvm::StringRef Message, bool Strict, llvm::StringRef Replacement, SourceRange Loc = SourceRange()) {
1359 auto *A = new (Ctx) AvailabilityAttr(Loc, Ctx, Platform, Introduced, Deprecated, Obsoleted, Unavailable, Message, Strict, Replacement, 0);
1360 A->setImplicit(true);
1361 return A;
1362 }
1363
1364 AvailabilityAttr(SourceRange R, ASTContext &Ctx
1365 , IdentifierInfo * Platform
1366 , VersionTuple Introduced
1367 , VersionTuple Deprecated
1368 , VersionTuple Obsoleted
1369 , bool Unavailable
1370 , llvm::StringRef Message
1371 , bool Strict
1372 , llvm::StringRef Replacement
1373 , unsigned SI
1374 )
1375 : InheritableAttr(attr::Availability, R, SI, false, true)
1376 , platform(Platform)
1377 , introduced(Introduced)
1378 , deprecated(Deprecated)
1379 , obsoleted(Obsoleted)
1380 , unavailable(Unavailable)
1381 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
1382 , strict(Strict)
1383 , replacementLength(Replacement.size()),replacement(new (Ctx, 1) char[replacementLength])
1384 {
1385 if (!Message.empty())
1386 std::memcpy(message, Message.data(), messageLength);
1387 if (!Replacement.empty())
1388 std::memcpy(replacement, Replacement.data(), replacementLength);
1389 }
1390
1391 AvailabilityAttr *clone(ASTContext &C) const;
1392 void printPretty(raw_ostream &OS,
1393 const PrintingPolicy &Policy) const;
1394 const char *getSpelling() const;
1395 IdentifierInfo * getPlatform() const {
1396 return platform;
1397 }
1398
1399 VersionTuple getIntroduced() const {
1400 return introduced;
1401 }
1402 void setIntroduced(ASTContext &C, VersionTuple V) {
1403 introduced = V;
1404 }
1405
1406 VersionTuple getDeprecated() const {
1407 return deprecated;
1408 }
1409 void setDeprecated(ASTContext &C, VersionTuple V) {
1410 deprecated = V;
1411 }
1412
1413 VersionTuple getObsoleted() const {
1414 return obsoleted;
1415 }
1416 void setObsoleted(ASTContext &C, VersionTuple V) {
1417 obsoleted = V;
1418 }
1419
1420 bool getUnavailable() const {
1421 return unavailable;
1422 }
1423
1424 llvm::StringRef getMessage() const {
1425 return llvm::StringRef(message, messageLength);
1426 }
1427 unsigned getMessageLength() const {
1428 return messageLength;
1429 }
1430 void setMessage(ASTContext &C, llvm::StringRef S) {
1431 messageLength = S.size();
1432 this->message = new (C, 1) char [messageLength];
1433 if (!S.empty())
1434 std::memcpy(this->message, S.data(), messageLength);
1435 }
1436
1437 bool getStrict() const {
1438 return strict;
1439 }
1440
1441 llvm::StringRef getReplacement() const {
1442 return llvm::StringRef(replacement, replacementLength);
1443 }
1444 unsigned getReplacementLength() const {
1445 return replacementLength;
1446 }
1447 void setReplacement(ASTContext &C, llvm::StringRef S) {
1448 replacementLength = S.size();
1449 this->replacement = new (C, 1) char [replacementLength];
1450 if (!S.empty())
1451 std::memcpy(this->replacement, S.data(), replacementLength);
1452 }
1453
1454static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
1455 return llvm::StringSwitch<llvm::StringRef>(Platform)
1456 .Case("android", "Android")
1457 .Case("ios", "iOS")
1458 .Case("macos", "macOS")
1459 .Case("tvos", "tvOS")
1460 .Case("watchos", "watchOS")
1461 .Case("ios_app_extension", "iOS (App Extension)")
1462 .Case("macos_app_extension", "macOS (App Extension)")
1463 .Case("tvos_app_extension", "tvOS (App Extension)")
1464 .Case("watchos_app_extension", "watchOS (App Extension)")
1465 .Default(llvm::StringRef());
1466}
1467static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) {
1468 return llvm::StringSwitch<llvm::StringRef>(Platform)
1469 .Case("ios", "iOS")
1470 .Case("macos", "macOS")
1471 .Case("tvos", "tvOS")
1472 .Case("watchos", "watchOS")
1473 .Case("ios_app_extension", "iOSApplicationExtension")
1474 .Case("macos_app_extension", "macOSApplicationExtension")
1475 .Case("tvos_app_extension", "tvOSApplicationExtension")
1476 .Case("watchos_app_extension", "watchOSApplicationExtension")
1477 .Default(Platform);
1478}
1479static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) {
1480 return llvm::StringSwitch<llvm::StringRef>(Platform)
1481 .Case("iOS", "ios")
1482 .Case("macOS", "macos")
1483 .Case("tvOS", "tvos")
1484 .Case("watchOS", "watchos")
1485 .Case("iOSApplicationExtension", "ios_app_extension")
1486 .Case("macOSApplicationExtension", "macos_app_extension")
1487 .Case("tvOSApplicationExtension", "tvos_app_extension")
1488 .Case("watchOSApplicationExtension", "watchos_app_extension")
1489 .Default(Platform);
1490}
1491
1492 static bool classof(const Attr *A) { return A->getKind() == attr::Availability; }
1493};
1494
1495class BlocksAttr : public InheritableAttr {
1496public:
1497 enum BlockType {
1498 ByRef
1499 };
1500private:
1501 BlockType type;
1502
1503public:
1504 static BlocksAttr *CreateImplicit(ASTContext &Ctx, BlockType Type, SourceRange Loc = SourceRange()) {
1505 auto *A = new (Ctx) BlocksAttr(Loc, Ctx, Type, 0);
1506 A->setImplicit(true);
1507 return A;
1508 }
1509
1510 BlocksAttr(SourceRange R, ASTContext &Ctx
1511 , BlockType Type
1512 , unsigned SI
1513 )
1514 : InheritableAttr(attr::Blocks, R, SI, false, false)
1515 , type(Type)
1516 {
1517 }
1518
1519 BlocksAttr *clone(ASTContext &C) const;
1520 void printPretty(raw_ostream &OS,
1521 const PrintingPolicy &Policy) const;
1522 const char *getSpelling() const;
1523 BlockType getType() const {
1524 return type;
1525 }
1526
1527 static bool ConvertStrToBlockType(StringRef Val, BlockType &Out) {
1528 Optional<BlockType> R = llvm::StringSwitch<Optional<BlockType>>(Val)
1529 .Case("byref", BlocksAttr::ByRef)
1530 .Default(Optional<BlockType>());
1531 if (R) {
1532 Out = *R;
1533 return true;
1534 }
1535 return false;
1536 }
1537
1538 static const char *ConvertBlockTypeToStr(BlockType Val) {
1539 switch(Val) {
1540 case BlocksAttr::ByRef: return "byref";
1541 }
1542 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 1542)
;
1543 }
1544
1545
1546 static bool classof(const Attr *A) { return A->getKind() == attr::Blocks; }
1547};
1548
1549class C11NoReturnAttr : public InheritableAttr {
1550public:
1551 static C11NoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1552 auto *A = new (Ctx) C11NoReturnAttr(Loc, Ctx, 0);
1553 A->setImplicit(true);
1554 return A;
1555 }
1556
1557 C11NoReturnAttr(SourceRange R, ASTContext &Ctx
1558 , unsigned SI
1559 )
1560 : InheritableAttr(attr::C11NoReturn, R, SI, false, false)
1561 {
1562 }
1563
1564 C11NoReturnAttr *clone(ASTContext &C) const;
1565 void printPretty(raw_ostream &OS,
1566 const PrintingPolicy &Policy) const;
1567 const char *getSpelling() const;
1568
1569
1570 static bool classof(const Attr *A) { return A->getKind() == attr::C11NoReturn; }
1571};
1572
1573class CDeclAttr : public InheritableAttr {
1574public:
1575 static CDeclAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1576 auto *A = new (Ctx) CDeclAttr(Loc, Ctx, 0);
1577 A->setImplicit(true);
1578 return A;
1579 }
1580
1581 CDeclAttr(SourceRange R, ASTContext &Ctx
1582 , unsigned SI
1583 )
1584 : InheritableAttr(attr::CDecl, R, SI, false, false)
1585 {
1586 }
1587
1588 CDeclAttr *clone(ASTContext &C) const;
1589 void printPretty(raw_ostream &OS,
1590 const PrintingPolicy &Policy) const;
1591 const char *getSpelling() const;
1592
1593
1594 static bool classof(const Attr *A) { return A->getKind() == attr::CDecl; }
1595};
1596
1597class CFAuditedTransferAttr : public InheritableAttr {
1598public:
1599 static CFAuditedTransferAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1600 auto *A = new (Ctx) CFAuditedTransferAttr(Loc, Ctx, 0);
1601 A->setImplicit(true);
1602 return A;
1603 }
1604
1605 CFAuditedTransferAttr(SourceRange R, ASTContext &Ctx
1606 , unsigned SI
1607 )
1608 : InheritableAttr(attr::CFAuditedTransfer, R, SI, false, false)
1609 {
1610 }
1611
1612 CFAuditedTransferAttr *clone(ASTContext &C) const;
1613 void printPretty(raw_ostream &OS,
1614 const PrintingPolicy &Policy) const;
1615 const char *getSpelling() const;
1616
1617
1618 static bool classof(const Attr *A) { return A->getKind() == attr::CFAuditedTransfer; }
1619};
1620
1621class CFConsumedAttr : public InheritableParamAttr {
1622public:
1623 static CFConsumedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1624 auto *A = new (Ctx) CFConsumedAttr(Loc, Ctx, 0);
1625 A->setImplicit(true);
1626 return A;
1627 }
1628
1629 CFConsumedAttr(SourceRange R, ASTContext &Ctx
1630 , unsigned SI
1631 )
1632 : InheritableParamAttr(attr::CFConsumed, R, SI, false, false)
1633 {
1634 }
1635
1636 CFConsumedAttr *clone(ASTContext &C) const;
1637 void printPretty(raw_ostream &OS,
1638 const PrintingPolicy &Policy) const;
1639 const char *getSpelling() const;
1640
1641
1642 static bool classof(const Attr *A) { return A->getKind() == attr::CFConsumed; }
1643};
1644
1645class CFReturnsNotRetainedAttr : public InheritableAttr {
1646public:
1647 static CFReturnsNotRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1648 auto *A = new (Ctx) CFReturnsNotRetainedAttr(Loc, Ctx, 0);
1649 A->setImplicit(true);
1650 return A;
1651 }
1652
1653 CFReturnsNotRetainedAttr(SourceRange R, ASTContext &Ctx
1654 , unsigned SI
1655 )
1656 : InheritableAttr(attr::CFReturnsNotRetained, R, SI, false, false)
1657 {
1658 }
1659
1660 CFReturnsNotRetainedAttr *clone(ASTContext &C) const;
1661 void printPretty(raw_ostream &OS,
1662 const PrintingPolicy &Policy) const;
1663 const char *getSpelling() const;
1664
1665
1666 static bool classof(const Attr *A) { return A->getKind() == attr::CFReturnsNotRetained; }
1667};
1668
1669class CFReturnsRetainedAttr : public InheritableAttr {
1670public:
1671 static CFReturnsRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1672 auto *A = new (Ctx) CFReturnsRetainedAttr(Loc, Ctx, 0);
1673 A->setImplicit(true);
1674 return A;
1675 }
1676
1677 CFReturnsRetainedAttr(SourceRange R, ASTContext &Ctx
1678 , unsigned SI
1679 )
1680 : InheritableAttr(attr::CFReturnsRetained, R, SI, false, false)
1681 {
1682 }
1683
1684 CFReturnsRetainedAttr *clone(ASTContext &C) const;
1685 void printPretty(raw_ostream &OS,
1686 const PrintingPolicy &Policy) const;
1687 const char *getSpelling() const;
1688
1689
1690 static bool classof(const Attr *A) { return A->getKind() == attr::CFReturnsRetained; }
1691};
1692
1693class CFUnknownTransferAttr : public InheritableAttr {
1694public:
1695 static CFUnknownTransferAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1696 auto *A = new (Ctx) CFUnknownTransferAttr(Loc, Ctx, 0);
1697 A->setImplicit(true);
1698 return A;
1699 }
1700
1701 CFUnknownTransferAttr(SourceRange R, ASTContext &Ctx
1702 , unsigned SI
1703 )
1704 : InheritableAttr(attr::CFUnknownTransfer, R, SI, false, false)
1705 {
1706 }
1707
1708 CFUnknownTransferAttr *clone(ASTContext &C) const;
1709 void printPretty(raw_ostream &OS,
1710 const PrintingPolicy &Policy) const;
1711 const char *getSpelling() const;
1712
1713
1714 static bool classof(const Attr *A) { return A->getKind() == attr::CFUnknownTransfer; }
1715};
1716
1717class CUDAConstantAttr : public InheritableAttr {
1718public:
1719 static CUDAConstantAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1720 auto *A = new (Ctx) CUDAConstantAttr(Loc, Ctx, 0);
1721 A->setImplicit(true);
1722 return A;
1723 }
1724
1725 CUDAConstantAttr(SourceRange R, ASTContext &Ctx
1726 , unsigned SI
1727 )
1728 : InheritableAttr(attr::CUDAConstant, R, SI, false, false)
1729 {
1730 }
1731
1732 CUDAConstantAttr *clone(ASTContext &C) const;
1733 void printPretty(raw_ostream &OS,
1734 const PrintingPolicy &Policy) const;
1735 const char *getSpelling() const;
1736
1737
1738 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAConstant; }
1739};
1740
1741class CUDADeviceAttr : public InheritableAttr {
1742public:
1743 static CUDADeviceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1744 auto *A = new (Ctx) CUDADeviceAttr(Loc, Ctx, 0);
1745 A->setImplicit(true);
1746 return A;
1747 }
1748
1749 CUDADeviceAttr(SourceRange R, ASTContext &Ctx
1750 , unsigned SI
1751 )
1752 : InheritableAttr(attr::CUDADevice, R, SI, false, false)
1753 {
1754 }
1755
1756 CUDADeviceAttr *clone(ASTContext &C) const;
1757 void printPretty(raw_ostream &OS,
1758 const PrintingPolicy &Policy) const;
1759 const char *getSpelling() const;
1760
1761
1762 static bool classof(const Attr *A) { return A->getKind() == attr::CUDADevice; }
1763};
1764
1765class CUDAGlobalAttr : public InheritableAttr {
1766public:
1767 static CUDAGlobalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1768 auto *A = new (Ctx) CUDAGlobalAttr(Loc, Ctx, 0);
1769 A->setImplicit(true);
1770 return A;
1771 }
1772
1773 CUDAGlobalAttr(SourceRange R, ASTContext &Ctx
1774 , unsigned SI
1775 )
1776 : InheritableAttr(attr::CUDAGlobal, R, SI, false, false)
1777 {
1778 }
1779
1780 CUDAGlobalAttr *clone(ASTContext &C) const;
1781 void printPretty(raw_ostream &OS,
1782 const PrintingPolicy &Policy) const;
1783 const char *getSpelling() const;
1784
1785
1786 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAGlobal; }
1787};
1788
1789class CUDAHostAttr : public InheritableAttr {
1790public:
1791 static CUDAHostAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1792 auto *A = new (Ctx) CUDAHostAttr(Loc, Ctx, 0);
1793 A->setImplicit(true);
1794 return A;
1795 }
1796
1797 CUDAHostAttr(SourceRange R, ASTContext &Ctx
1798 , unsigned SI
1799 )
1800 : InheritableAttr(attr::CUDAHost, R, SI, false, false)
1801 {
1802 }
1803
1804 CUDAHostAttr *clone(ASTContext &C) const;
1805 void printPretty(raw_ostream &OS,
1806 const PrintingPolicy &Policy) const;
1807 const char *getSpelling() const;
1808
1809
1810 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAHost; }
1811};
1812
1813class CUDAInvalidTargetAttr : public InheritableAttr {
1814public:
1815 static CUDAInvalidTargetAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1816 auto *A = new (Ctx) CUDAInvalidTargetAttr(Loc, Ctx, 0);
1817 A->setImplicit(true);
1818 return A;
1819 }
1820
1821 CUDAInvalidTargetAttr(SourceRange R, ASTContext &Ctx
1822 , unsigned SI
1823 )
1824 : InheritableAttr(attr::CUDAInvalidTarget, R, SI, false, false)
1825 {
1826 }
1827
1828 CUDAInvalidTargetAttr *clone(ASTContext &C) const;
1829 void printPretty(raw_ostream &OS,
1830 const PrintingPolicy &Policy) const;
1831 const char *getSpelling() const;
1832
1833
1834 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAInvalidTarget; }
1835};
1836
1837class CUDALaunchBoundsAttr : public InheritableAttr {
1838Expr * maxThreads;
1839
1840Expr * minBlocks;
1841
1842public:
1843 static CUDALaunchBoundsAttr *CreateImplicit(ASTContext &Ctx, Expr * MaxThreads, Expr * MinBlocks, SourceRange Loc = SourceRange()) {
1844 auto *A = new (Ctx) CUDALaunchBoundsAttr(Loc, Ctx, MaxThreads, MinBlocks, 0);
1845 A->setImplicit(true);
1846 return A;
1847 }
1848
1849 CUDALaunchBoundsAttr(SourceRange R, ASTContext &Ctx
1850 , Expr * MaxThreads
1851 , Expr * MinBlocks
1852 , unsigned SI
1853 )
1854 : InheritableAttr(attr::CUDALaunchBounds, R, SI, false, false)
1855 , maxThreads(MaxThreads)
1856 , minBlocks(MinBlocks)
1857 {
1858 }
1859
1860 CUDALaunchBoundsAttr(SourceRange R, ASTContext &Ctx
1861 , Expr * MaxThreads
1862 , unsigned SI
1863 )
1864 : InheritableAttr(attr::CUDALaunchBounds, R, SI, false, false)
1865 , maxThreads(MaxThreads)
1866 , minBlocks()
1867 {
1868 }
1869
1870 CUDALaunchBoundsAttr *clone(ASTContext &C) const;
1871 void printPretty(raw_ostream &OS,
1872 const PrintingPolicy &Policy) const;
1873 const char *getSpelling() const;
1874 Expr * getMaxThreads() const {
1875 return maxThreads;
1876 }
1877
1878 Expr * getMinBlocks() const {
1879 return minBlocks;
1880 }
1881
1882
1883
1884 static bool classof(const Attr *A) { return A->getKind() == attr::CUDALaunchBounds; }
1885};
1886
1887class CUDASharedAttr : public InheritableAttr {
1888public:
1889 static CUDASharedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1890 auto *A = new (Ctx) CUDASharedAttr(Loc, Ctx, 0);
1891 A->setImplicit(true);
1892 return A;
1893 }
1894
1895 CUDASharedAttr(SourceRange R, ASTContext &Ctx
1896 , unsigned SI
1897 )
1898 : InheritableAttr(attr::CUDAShared, R, SI, false, false)
1899 {
1900 }
1901
1902 CUDASharedAttr *clone(ASTContext &C) const;
1903 void printPretty(raw_ostream &OS,
1904 const PrintingPolicy &Policy) const;
1905 const char *getSpelling() const;
1906
1907
1908 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAShared; }
1909};
1910
1911class CXX11NoReturnAttr : public InheritableAttr {
1912public:
1913 static CXX11NoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1914 auto *A = new (Ctx) CXX11NoReturnAttr(Loc, Ctx, 0);
1915 A->setImplicit(true);
1916 return A;
1917 }
1918
1919 CXX11NoReturnAttr(SourceRange R, ASTContext &Ctx
1920 , unsigned SI
1921 )
1922 : InheritableAttr(attr::CXX11NoReturn, R, SI, false, false)
1923 {
1924 }
1925
1926 CXX11NoReturnAttr *clone(ASTContext &C) const;
1927 void printPretty(raw_ostream &OS,
1928 const PrintingPolicy &Policy) const;
1929 const char *getSpelling() const;
1930
1931
1932 static bool classof(const Attr *A) { return A->getKind() == attr::CXX11NoReturn; }
1933};
1934
1935class CallableWhenAttr : public InheritableAttr {
1936public:
1937 enum ConsumedState {
1938 Unknown,
1939 Consumed,
1940 Unconsumed
1941 };
1942private:
1943 unsigned callableStates_Size;
1944 ConsumedState *callableStates_;
1945
1946public:
1947 static CallableWhenAttr *CreateImplicit(ASTContext &Ctx, ConsumedState *CallableStates, unsigned CallableStatesSize, SourceRange Loc = SourceRange()) {
1948 auto *A = new (Ctx) CallableWhenAttr(Loc, Ctx, CallableStates, CallableStatesSize, 0);
1949 A->setImplicit(true);
1950 return A;
1951 }
1952
1953 CallableWhenAttr(SourceRange R, ASTContext &Ctx
1954 , ConsumedState *CallableStates, unsigned CallableStatesSize
1955 , unsigned SI
1956 )
1957 : InheritableAttr(attr::CallableWhen, R, SI, false, false)
1958 , callableStates_Size(CallableStatesSize), callableStates_(new (Ctx, 16) ConsumedState[callableStates_Size])
1959 {
1960 std::copy(CallableStates, CallableStates + callableStates_Size, callableStates_);
1961 }
1962
1963 CallableWhenAttr(SourceRange R, ASTContext &Ctx
1964 , unsigned SI
1965 )
1966 : InheritableAttr(attr::CallableWhen, R, SI, false, false)
1967 , callableStates_Size(0), callableStates_(nullptr)
1968 {
1969 }
1970
1971 CallableWhenAttr *clone(ASTContext &C) const;
1972 void printPretty(raw_ostream &OS,
1973 const PrintingPolicy &Policy) const;
1974 const char *getSpelling() const;
1975 typedef ConsumedState* callableStates_iterator;
1976 callableStates_iterator callableStates_begin() const { return callableStates_; }
1977 callableStates_iterator callableStates_end() const { return callableStates_ + callableStates_Size; }
1978 unsigned callableStates_size() const { return callableStates_Size; }
1979 llvm::iterator_range<callableStates_iterator> callableStates() const { return llvm::make_range(callableStates_begin(), callableStates_end()); }
1980
1981
1982 static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) {
1983 Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val)
1984 .Case("unknown", CallableWhenAttr::Unknown)
1985 .Case("consumed", CallableWhenAttr::Consumed)
1986 .Case("unconsumed", CallableWhenAttr::Unconsumed)
1987 .Default(Optional<ConsumedState>());
1988 if (R) {
1989 Out = *R;
1990 return true;
1991 }
1992 return false;
1993 }
1994
1995 static const char *ConvertConsumedStateToStr(ConsumedState Val) {
1996 switch(Val) {
1997 case CallableWhenAttr::Unknown: return "unknown";
1998 case CallableWhenAttr::Consumed: return "consumed";
1999 case CallableWhenAttr::Unconsumed: return "unconsumed";
2000 }
2001 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 2001)
;
2002 }
2003
2004
2005 static bool classof(const Attr *A) { return A->getKind() == attr::CallableWhen; }
2006};
2007
2008class CapabilityAttr : public InheritableAttr {
2009unsigned nameLength;
2010char *name;
2011
2012public:
2013 enum Spelling {
2014 GNU_capability = 0,
2015 CXX11_clang_capability = 1,
2016 GNU_shared_capability = 2,
2017 CXX11_clang_shared_capability = 3
2018 };
2019
2020 static CapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, llvm::StringRef Name, SourceRange Loc = SourceRange()) {
2021 auto *A = new (Ctx) CapabilityAttr(Loc, Ctx, Name, S);
2022 A->setImplicit(true);
2023 return A;
2024 }
2025
2026 CapabilityAttr(SourceRange R, ASTContext &Ctx
2027 , llvm::StringRef Name
2028 , unsigned SI
2029 )
2030 : InheritableAttr(attr::Capability, R, SI, false, false)
2031 , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength])
2032 {
2033 if (!Name.empty())
2034 std::memcpy(name, Name.data(), nameLength);
2035 }
2036
2037 CapabilityAttr *clone(ASTContext &C) const;
2038 void printPretty(raw_ostream &OS,
2039 const PrintingPolicy &Policy) const;
2040 const char *getSpelling() const;
2041 Spelling getSemanticSpelling() const {
2042 switch (SpellingListIndex) {
2043 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 2043)
;
2044 case 0: return GNU_capability;
2045 case 1: return CXX11_clang_capability;
2046 case 2: return GNU_shared_capability;
2047 case 3: return CXX11_clang_shared_capability;
2048 }
2049 }
2050 bool isShared() const { return SpellingListIndex == 2 ||
2051 SpellingListIndex == 3; }
2052 llvm::StringRef getName() const {
2053 return llvm::StringRef(name, nameLength);
2054 }
2055 unsigned getNameLength() const {
2056 return nameLength;
2057 }
2058 void setName(ASTContext &C, llvm::StringRef S) {
2059 nameLength = S.size();
2060 this->name = new (C, 1) char [nameLength];
2061 if (!S.empty())
2062 std::memcpy(this->name, S.data(), nameLength);
2063 }
2064
2065
2066 bool isMutex() const { return getName().equals_lower("mutex"); }
2067 bool isRole() const { return getName().equals_lower("role"); }
2068
2069
2070 static bool classof(const Attr *A) { return A->getKind() == attr::Capability; }
2071};
2072
2073class CapturedRecordAttr : public InheritableAttr {
2074public:
2075 static CapturedRecordAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2076 auto *A = new (Ctx) CapturedRecordAttr(Loc, Ctx, 0);
2077 A->setImplicit(true);
2078 return A;
2079 }
2080
2081 CapturedRecordAttr(SourceRange R, ASTContext &Ctx
2082 , unsigned SI
2083 )
2084 : InheritableAttr(attr::CapturedRecord, R, SI, false, false)
2085 {
2086 }
2087
2088 CapturedRecordAttr *clone(ASTContext &C) const;
2089 void printPretty(raw_ostream &OS,
2090 const PrintingPolicy &Policy) const;
2091 const char *getSpelling() const;
2092
2093
2094 static bool classof(const Attr *A) { return A->getKind() == attr::CapturedRecord; }
2095};
2096
2097class CarriesDependencyAttr : public InheritableParamAttr {
2098public:
2099 static CarriesDependencyAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2100 auto *A = new (Ctx) CarriesDependencyAttr(Loc, Ctx, 0);
2101 A->setImplicit(true);
2102 return A;
2103 }
2104
2105 CarriesDependencyAttr(SourceRange R, ASTContext &Ctx
2106 , unsigned SI
2107 )
2108 : InheritableParamAttr(attr::CarriesDependency, R, SI, false, false)
2109 {
2110 }
2111
2112 CarriesDependencyAttr *clone(ASTContext &C) const;
2113 void printPretty(raw_ostream &OS,
2114 const PrintingPolicy &Policy) const;
2115 const char *getSpelling() const;
2116
2117
2118 static bool classof(const Attr *A) { return A->getKind() == attr::CarriesDependency; }
2119};
2120
2121class CleanupAttr : public InheritableAttr {
2122FunctionDecl * functionDecl;
2123
2124public:
2125 static CleanupAttr *CreateImplicit(ASTContext &Ctx, FunctionDecl * FunctionDecl, SourceRange Loc = SourceRange()) {
2126 auto *A = new (Ctx) CleanupAttr(Loc, Ctx, FunctionDecl, 0);
2127 A->setImplicit(true);
2128 return A;
2129 }
2130
2131 CleanupAttr(SourceRange R, ASTContext &Ctx
2132 , FunctionDecl * FunctionDecl
2133 , unsigned SI
2134 )
2135 : InheritableAttr(attr::Cleanup, R, SI, false, false)
2136 , functionDecl(FunctionDecl)
2137 {
2138 }
2139
2140 CleanupAttr *clone(ASTContext &C) const;
2141 void printPretty(raw_ostream &OS,
2142 const PrintingPolicy &Policy) const;
2143 const char *getSpelling() const;
2144 FunctionDecl * getFunctionDecl() const {
2145 return functionDecl;
2146 }
2147
2148
2149
2150 static bool classof(const Attr *A) { return A->getKind() == attr::Cleanup; }
2151};
2152
2153class ColdAttr : public InheritableAttr {
2154public:
2155 static ColdAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2156 auto *A = new (Ctx) ColdAttr(Loc, Ctx, 0);
2157 A->setImplicit(true);
2158 return A;
2159 }
2160
2161 ColdAttr(SourceRange R, ASTContext &Ctx
2162 , unsigned SI
2163 )
2164 : InheritableAttr(attr::Cold, R, SI, false, false)
2165 {
2166 }
2167
2168 ColdAttr *clone(ASTContext &C) const;
2169 void printPretty(raw_ostream &OS,
2170 const PrintingPolicy &Policy) const;
2171 const char *getSpelling() const;
2172
2173
2174 static bool classof(const Attr *A) { return A->getKind() == attr::Cold; }
2175};
2176
2177class CommonAttr : public InheritableAttr {
2178public:
2179 static CommonAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2180 auto *A = new (Ctx) CommonAttr(Loc, Ctx, 0);
2181 A->setImplicit(true);
2182 return A;
2183 }
2184
2185 CommonAttr(SourceRange R, ASTContext &Ctx
2186 , unsigned SI
2187 )
2188 : InheritableAttr(attr::Common, R, SI, false, false)
2189 {
2190 }
2191
2192 CommonAttr *clone(ASTContext &C) const;
2193 void printPretty(raw_ostream &OS,
2194 const PrintingPolicy &Policy) const;
2195 const char *getSpelling() const;
2196
2197
2198 static bool classof(const Attr *A) { return A->getKind() == attr::Common; }
2199};
2200
2201class ConstAttr : public InheritableAttr {
2202public:
2203 static ConstAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2204 auto *A = new (Ctx) ConstAttr(Loc, Ctx, 0);
2205 A->setImplicit(true);
2206 return A;
2207 }
2208
2209 ConstAttr(SourceRange R, ASTContext &Ctx
2210 , unsigned SI
2211 )
2212 : InheritableAttr(attr::Const, R, SI, false, false)
2213 {
2214 }
2215
2216 ConstAttr *clone(ASTContext &C) const;
2217 void printPretty(raw_ostream &OS,
2218 const PrintingPolicy &Policy) const;
2219 const char *getSpelling() const;
2220
2221
2222 static bool classof(const Attr *A) { return A->getKind() == attr::Const; }
2223};
2224
2225class ConstructorAttr : public InheritableAttr {
2226int priority;
2227
2228public:
2229 static ConstructorAttr *CreateImplicit(ASTContext &Ctx, int Priority, SourceRange Loc = SourceRange()) {
2230 auto *A = new (Ctx) ConstructorAttr(Loc, Ctx, Priority, 0);
2231 A->setImplicit(true);
2232 return A;
2233 }
2234
2235 ConstructorAttr(SourceRange R, ASTContext &Ctx
2236 , int Priority
2237 , unsigned SI
2238 )
2239 : InheritableAttr(attr::Constructor, R, SI, false, false)
2240 , priority(Priority)
2241 {
2242 }
2243
2244 ConstructorAttr(SourceRange R, ASTContext &Ctx
2245 , unsigned SI
2246 )
2247 : InheritableAttr(attr::Constructor, R, SI, false, false)
2248 , priority()
2249 {
2250 }
2251
2252 ConstructorAttr *clone(ASTContext &C) const;
2253 void printPretty(raw_ostream &OS,
2254 const PrintingPolicy &Policy) const;
2255 const char *getSpelling() const;
2256 int getPriority() const {
2257 return priority;
2258 }
2259
2260 static const int DefaultPriority = 65535;
2261
2262
2263
2264 static bool classof(const Attr *A) { return A->getKind() == attr::Constructor; }
2265};
2266
2267class ConsumableAttr : public InheritableAttr {
2268public:
2269 enum ConsumedState {
2270 Unknown,
2271 Consumed,
2272 Unconsumed
2273 };
2274private:
2275 ConsumedState defaultState;
2276
2277public:
2278 static ConsumableAttr *CreateImplicit(ASTContext &Ctx, ConsumedState DefaultState, SourceRange Loc = SourceRange()) {
2279 auto *A = new (Ctx) ConsumableAttr(Loc, Ctx, DefaultState, 0);
2280 A->setImplicit(true);
2281 return A;
2282 }
2283
2284 ConsumableAttr(SourceRange R, ASTContext &Ctx
2285 , ConsumedState DefaultState
2286 , unsigned SI
2287 )
2288 : InheritableAttr(attr::Consumable, R, SI, false, false)
2289 , defaultState(DefaultState)
2290 {
2291 }
2292
2293 ConsumableAttr *clone(ASTContext &C) const;
2294 void printPretty(raw_ostream &OS,
2295 const PrintingPolicy &Policy) const;
2296 const char *getSpelling() const;
2297 ConsumedState getDefaultState() const {
2298 return defaultState;
2299 }
2300
2301 static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) {
2302 Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val)
2303 .Case("unknown", ConsumableAttr::Unknown)
2304 .Case("consumed", ConsumableAttr::Consumed)
2305 .Case("unconsumed", ConsumableAttr::Unconsumed)
2306 .Default(Optional<ConsumedState>());
2307 if (R) {
2308 Out = *R;
2309 return true;
2310 }
2311 return false;
2312 }
2313
2314 static const char *ConvertConsumedStateToStr(ConsumedState Val) {
2315 switch(Val) {
2316 case ConsumableAttr::Unknown: return "unknown";
2317 case ConsumableAttr::Consumed: return "consumed";
2318 case ConsumableAttr::Unconsumed: return "unconsumed";
2319 }
2320 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 2320)
;
2321 }
2322
2323
2324 static bool classof(const Attr *A) { return A->getKind() == attr::Consumable; }
2325};
2326
2327class ConsumableAutoCastAttr : public InheritableAttr {
2328public:
2329 static ConsumableAutoCastAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2330 auto *A = new (Ctx) ConsumableAutoCastAttr(Loc, Ctx, 0);
2331 A->setImplicit(true);
2332 return A;
2333 }
2334
2335 ConsumableAutoCastAttr(SourceRange R, ASTContext &Ctx
2336 , unsigned SI
2337 )
2338 : InheritableAttr(attr::ConsumableAutoCast, R, SI, false, false)
2339 {
2340 }
2341
2342 ConsumableAutoCastAttr *clone(ASTContext &C) const;
2343 void printPretty(raw_ostream &OS,
2344 const PrintingPolicy &Policy) const;
2345 const char *getSpelling() const;
2346
2347
2348 static bool classof(const Attr *A) { return A->getKind() == attr::ConsumableAutoCast; }
2349};
2350
2351class ConsumableSetOnReadAttr : public InheritableAttr {
2352public:
2353 static ConsumableSetOnReadAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2354 auto *A = new (Ctx) ConsumableSetOnReadAttr(Loc, Ctx, 0);
2355 A->setImplicit(true);
2356 return A;
2357 }
2358
2359 ConsumableSetOnReadAttr(SourceRange R, ASTContext &Ctx
2360 , unsigned SI
2361 )
2362 : InheritableAttr(attr::ConsumableSetOnRead, R, SI, false, false)
2363 {
2364 }
2365
2366 ConsumableSetOnReadAttr *clone(ASTContext &C) const;
2367 void printPretty(raw_ostream &OS,
2368 const PrintingPolicy &Policy) const;
2369 const char *getSpelling() const;
2370
2371
2372 static bool classof(const Attr *A) { return A->getKind() == attr::ConsumableSetOnRead; }
2373};
2374
2375class ConvergentAttr : public InheritableAttr {
2376public:
2377 static ConvergentAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2378 auto *A = new (Ctx) ConvergentAttr(Loc, Ctx, 0);
2379 A->setImplicit(true);
2380 return A;
2381 }
2382
2383 ConvergentAttr(SourceRange R, ASTContext &Ctx
2384 , unsigned SI
2385 )
2386 : InheritableAttr(attr::Convergent, R, SI, false, false)
2387 {
2388 }
2389
2390 ConvergentAttr *clone(ASTContext &C) const;
2391 void printPretty(raw_ostream &OS,
2392 const PrintingPolicy &Policy) const;
2393 const char *getSpelling() const;
2394
2395
2396 static bool classof(const Attr *A) { return A->getKind() == attr::Convergent; }
2397};
2398
2399class DLLExportAttr : public InheritableAttr {
2400public:
2401 static DLLExportAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2402 auto *A = new (Ctx) DLLExportAttr(Loc, Ctx, 0);
2403 A->setImplicit(true);
2404 return A;
2405 }
2406
2407 DLLExportAttr(SourceRange R, ASTContext &Ctx
2408 , unsigned SI
2409 )
2410 : InheritableAttr(attr::DLLExport, R, SI, false, false)
2411 {
2412 }
2413
2414 DLLExportAttr *clone(ASTContext &C) const;
2415 void printPretty(raw_ostream &OS,
2416 const PrintingPolicy &Policy) const;
2417 const char *getSpelling() const;
2418
2419
2420 static bool classof(const Attr *A) { return A->getKind() == attr::DLLExport; }
2421};
2422
2423class DLLImportAttr : public InheritableAttr {
2424public:
2425 static DLLImportAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2426 auto *A = new (Ctx) DLLImportAttr(Loc, Ctx, 0);
2427 A->setImplicit(true);
2428 return A;
2429 }
2430
2431 DLLImportAttr(SourceRange R, ASTContext &Ctx
2432 , unsigned SI
2433 )
2434 : InheritableAttr(attr::DLLImport, R, SI, false, false)
2435 {
2436 }
2437
2438 DLLImportAttr *clone(ASTContext &C) const;
2439 void printPretty(raw_ostream &OS,
2440 const PrintingPolicy &Policy) const;
2441 const char *getSpelling() const;
2442
2443
2444 static bool classof(const Attr *A) { return A->getKind() == attr::DLLImport; }
2445};
2446
2447class DeprecatedAttr : public InheritableAttr {
2448unsigned messageLength;
2449char *message;
2450
2451unsigned replacementLength;
2452char *replacement;
2453
2454public:
2455 static DeprecatedAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Message, llvm::StringRef Replacement, SourceRange Loc = SourceRange()) {
2456 auto *A = new (Ctx) DeprecatedAttr(Loc, Ctx, Message, Replacement, 0);
2457 A->setImplicit(true);
2458 return A;
2459 }
2460
2461 DeprecatedAttr(SourceRange R, ASTContext &Ctx
2462 , llvm::StringRef Message
2463 , llvm::StringRef Replacement
2464 , unsigned SI
2465 )
2466 : InheritableAttr(attr::Deprecated, R, SI, false, false)
2467 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
2468 , replacementLength(Replacement.size()),replacement(new (Ctx, 1) char[replacementLength])
2469 {
2470 if (!Message.empty())
2471 std::memcpy(message, Message.data(), messageLength);
2472 if (!Replacement.empty())
2473 std::memcpy(replacement, Replacement.data(), replacementLength);
2474 }
2475
2476 DeprecatedAttr(SourceRange R, ASTContext &Ctx
2477 , unsigned SI
2478 )
2479 : InheritableAttr(attr::Deprecated, R, SI, false, false)
2480 , messageLength(0),message(nullptr)
2481 , replacementLength(0),replacement(nullptr)
2482 {
2483 }
2484
2485 DeprecatedAttr *clone(ASTContext &C) const;
2486 void printPretty(raw_ostream &OS,
2487 const PrintingPolicy &Policy) const;
2488 const char *getSpelling() const;
2489 llvm::StringRef getMessage() const {
2490 return llvm::StringRef(message, messageLength);
2491 }
2492 unsigned getMessageLength() const {
2493 return messageLength;
2494 }
2495 void setMessage(ASTContext &C, llvm::StringRef S) {
2496 messageLength = S.size();
2497 this->message = new (C, 1) char [messageLength];
2498 if (!S.empty())
2499 std::memcpy(this->message, S.data(), messageLength);
2500 }
2501
2502 llvm::StringRef getReplacement() const {
2503 return llvm::StringRef(replacement, replacementLength);
2504 }
2505 unsigned getReplacementLength() const {
2506 return replacementLength;
2507 }
2508 void setReplacement(ASTContext &C, llvm::StringRef S) {
2509 replacementLength = S.size();
2510 this->replacement = new (C, 1) char [replacementLength];
2511 if (!S.empty())
2512 std::memcpy(this->replacement, S.data(), replacementLength);
2513 }
2514
2515
2516
2517 static bool classof(const Attr *A) { return A->getKind() == attr::Deprecated; }
2518};
2519
2520class DestructorAttr : public InheritableAttr {
2521int priority;
2522
2523public:
2524 static DestructorAttr *CreateImplicit(ASTContext &Ctx, int Priority, SourceRange Loc = SourceRange()) {
2525 auto *A = new (Ctx) DestructorAttr(Loc, Ctx, Priority, 0);
2526 A->setImplicit(true);
2527 return A;
2528 }
2529
2530 DestructorAttr(SourceRange R, ASTContext &Ctx
2531 , int Priority
2532 , unsigned SI
2533 )
2534 : InheritableAttr(attr::Destructor, R, SI, false, false)
2535 , priority(Priority)
2536 {
2537 }
2538
2539 DestructorAttr(SourceRange R, ASTContext &Ctx
2540 , unsigned SI
2541 )
2542 : InheritableAttr(attr::Destructor, R, SI, false, false)
2543 , priority()
2544 {
2545 }
2546
2547 DestructorAttr *clone(ASTContext &C) const;
2548 void printPretty(raw_ostream &OS,
2549 const PrintingPolicy &Policy) const;
2550 const char *getSpelling() const;
2551 int getPriority() const {
2552 return priority;
2553 }
2554
2555 static const int DefaultPriority = 65535;
2556
2557
2558
2559 static bool classof(const Attr *A) { return A->getKind() == attr::Destructor; }
2560};
2561
2562class DiagnoseIfAttr : public InheritableAttr {
2563Expr * cond;
2564
2565unsigned messageLength;
2566char *message;
2567
2568public:
2569 enum DiagnosticType {
2570 DT_Error,
2571 DT_Warning
2572 };
2573private:
2574 DiagnosticType diagnosticType;
2575
2576bool argDependent;
2577
2578NamedDecl * parent;
2579
2580public:
2581 static DiagnoseIfAttr *CreateImplicit(ASTContext &Ctx, Expr * Cond, llvm::StringRef Message, DiagnosticType DiagnosticType, bool ArgDependent, NamedDecl * Parent, SourceRange Loc = SourceRange()) {
2582 auto *A = new (Ctx) DiagnoseIfAttr(Loc, Ctx, Cond, Message, DiagnosticType, ArgDependent, Parent, 0);
2583 A->setImplicit(true);
2584 return A;
2585 }
2586
2587 static DiagnoseIfAttr *CreateImplicit(ASTContext &Ctx, Expr * Cond, llvm::StringRef Message, DiagnosticType DiagnosticType, SourceRange Loc = SourceRange()) {
2588 auto *A = new (Ctx) DiagnoseIfAttr(Loc, Ctx, Cond, Message, DiagnosticType, 0);
2589 A->setImplicit(true);
2590 return A;
2591 }
2592
2593 DiagnoseIfAttr(SourceRange R, ASTContext &Ctx
2594 , Expr * Cond
2595 , llvm::StringRef Message
2596 , DiagnosticType DiagnosticType
2597 , bool ArgDependent
2598 , NamedDecl * Parent
2599 , unsigned SI
2600 )
2601 : InheritableAttr(attr::DiagnoseIf, R, SI, true, true)
2602 , cond(Cond)
2603 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
2604 , diagnosticType(DiagnosticType)
2605 , argDependent(ArgDependent)
2606 , parent(Parent)
2607 {
2608 if (!Message.empty())
2609 std::memcpy(message, Message.data(), messageLength);
2610 }
2611
2612 DiagnoseIfAttr(SourceRange R, ASTContext &Ctx
2613 , Expr * Cond
2614 , llvm::StringRef Message
2615 , DiagnosticType DiagnosticType
2616 , unsigned SI
2617 )
2618 : InheritableAttr(attr::DiagnoseIf, R, SI, true, true)
2619 , cond(Cond)
2620 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
2621 , diagnosticType(DiagnosticType)
2622 , argDependent()
2623 , parent()
2624 {
2625 if (!Message.empty())
2626 std::memcpy(message, Message.data(), messageLength);
2627 }
2628
2629 DiagnoseIfAttr *clone(ASTContext &C) const;
2630 void printPretty(raw_ostream &OS,
2631 const PrintingPolicy &Policy) const;
2632 const char *getSpelling() const;
2633 Expr * getCond() const {
2634 return cond;
2635 }
2636
2637 llvm::StringRef getMessage() const {
2638 return llvm::StringRef(message, messageLength);
2639 }
2640 unsigned getMessageLength() const {
2641 return messageLength;
2642 }
2643 void setMessage(ASTContext &C, llvm::StringRef S) {
2644 messageLength = S.size();
2645 this->message = new (C, 1) char [messageLength];
2646 if (!S.empty())
2647 std::memcpy(this->message, S.data(), messageLength);
2648 }
2649
2650 DiagnosticType getDiagnosticType() const {
2651 return diagnosticType;
2652 }
2653
2654 static bool ConvertStrToDiagnosticType(StringRef Val, DiagnosticType &Out) {
2655 Optional<DiagnosticType> R = llvm::StringSwitch<Optional<DiagnosticType>>(Val)
2656 .Case("error", DiagnoseIfAttr::DT_Error)
2657 .Case("warning", DiagnoseIfAttr::DT_Warning)
2658 .Default(Optional<DiagnosticType>());
2659 if (R) {
2660 Out = *R;
2661 return true;
2662 }
2663 return false;
2664 }
2665
2666 static const char *ConvertDiagnosticTypeToStr(DiagnosticType Val) {
2667 switch(Val) {
2668 case DiagnoseIfAttr::DT_Error: return "error";
2669 case DiagnoseIfAttr::DT_Warning: return "warning";
2670 }
2671 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 2671)
;
2672 }
2673 bool getArgDependent() const {
2674 return argDependent;
2675 }
2676
2677 NamedDecl * getParent() const {
2678 return parent;
2679 }
2680
2681
2682 bool isError() const { return diagnosticType == DT_Error; }
2683 bool isWarning() const { return diagnosticType == DT_Warning; }
2684
2685
2686 static bool classof(const Attr *A) { return A->getKind() == attr::DiagnoseIf; }
2687};
2688
2689class DisableTailCallsAttr : public InheritableAttr {
2690public:
2691 static DisableTailCallsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2692 auto *A = new (Ctx) DisableTailCallsAttr(Loc, Ctx, 0);
2693 A->setImplicit(true);
2694 return A;
2695 }
2696
2697 DisableTailCallsAttr(SourceRange R, ASTContext &Ctx
2698 , unsigned SI
2699 )
2700 : InheritableAttr(attr::DisableTailCalls, R, SI, false, false)
2701 {
2702 }
2703
2704 DisableTailCallsAttr *clone(ASTContext &C) const;
2705 void printPretty(raw_ostream &OS,
2706 const PrintingPolicy &Policy) const;
2707 const char *getSpelling() const;
2708
2709
2710 static bool classof(const Attr *A) { return A->getKind() == attr::DisableTailCalls; }
2711};
2712
2713class EmptyBasesAttr : public InheritableAttr {
2714public:
2715 static EmptyBasesAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2716 auto *A = new (Ctx) EmptyBasesAttr(Loc, Ctx, 0);
2717 A->setImplicit(true);
2718 return A;
2719 }
2720
2721 EmptyBasesAttr(SourceRange R, ASTContext &Ctx
2722 , unsigned SI
2723 )
2724 : InheritableAttr(attr::EmptyBases, R, SI, false, false)
2725 {
2726 }
2727
2728 EmptyBasesAttr *clone(ASTContext &C) const;
2729 void printPretty(raw_ostream &OS,
2730 const PrintingPolicy &Policy) const;
2731 const char *getSpelling() const;
2732
2733
2734 static bool classof(const Attr *A) { return A->getKind() == attr::EmptyBases; }
2735};
2736
2737class EnableIfAttr : public InheritableAttr {
2738Expr * cond;
2739
2740unsigned messageLength;
2741char *message;
2742
2743public:
2744 static EnableIfAttr *CreateImplicit(ASTContext &Ctx, Expr * Cond, llvm::StringRef Message, SourceRange Loc = SourceRange()) {
2745 auto *A = new (Ctx) EnableIfAttr(Loc, Ctx, Cond, Message, 0);
2746 A->setImplicit(true);
2747 return A;
2748 }
2749
2750 EnableIfAttr(SourceRange R, ASTContext &Ctx
2751 , Expr * Cond
2752 , llvm::StringRef Message
2753 , unsigned SI
2754 )
2755 : InheritableAttr(attr::EnableIf, R, SI, false, false)
2756 , cond(Cond)
2757 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
2758 {
2759 if (!Message.empty())
2760 std::memcpy(message, Message.data(), messageLength);
2761 }
2762
2763 EnableIfAttr *clone(ASTContext &C) const;
2764 void printPretty(raw_ostream &OS,
2765 const PrintingPolicy &Policy) const;
2766 const char *getSpelling() const;
2767 Expr * getCond() const {
2768 return cond;
2769 }
2770
2771 llvm::StringRef getMessage() const {
2772 return llvm::StringRef(message, messageLength);
2773 }
2774 unsigned getMessageLength() const {
2775 return messageLength;
2776 }
2777 void setMessage(ASTContext &C, llvm::StringRef S) {
2778 messageLength = S.size();
2779 this->message = new (C, 1) char [messageLength];
2780 if (!S.empty())
2781 std::memcpy(this->message, S.data(), messageLength);
2782 }
2783
2784
2785
2786 static bool classof(const Attr *A) { return A->getKind() == attr::EnableIf; }
2787};
2788
2789class EnumExtensibilityAttr : public InheritableAttr {
2790public:
2791 enum Kind {
2792 Closed,
2793 Open
2794 };
2795private:
2796 Kind extensibility;
2797
2798public:
2799 static EnumExtensibilityAttr *CreateImplicit(ASTContext &Ctx, Kind Extensibility, SourceRange Loc = SourceRange()) {
2800 auto *A = new (Ctx) EnumExtensibilityAttr(Loc, Ctx, Extensibility, 0);
2801 A->setImplicit(true);
2802 return A;
2803 }
2804
2805 EnumExtensibilityAttr(SourceRange R, ASTContext &Ctx
2806 , Kind Extensibility
2807 , unsigned SI
2808 )
2809 : InheritableAttr(attr::EnumExtensibility, R, SI, false, false)
2810 , extensibility(Extensibility)
2811 {
2812 }
2813
2814 EnumExtensibilityAttr *clone(ASTContext &C) const;
2815 void printPretty(raw_ostream &OS,
2816 const PrintingPolicy &Policy) const;
2817 const char *getSpelling() const;
2818 Kind getExtensibility() const {
2819 return extensibility;
2820 }
2821
2822 static bool ConvertStrToKind(StringRef Val, Kind &Out) {
2823 Optional<Kind> R = llvm::StringSwitch<Optional<Kind>>(Val)
2824 .Case("closed", EnumExtensibilityAttr::Closed)
2825 .Case("open", EnumExtensibilityAttr::Open)
2826 .Default(Optional<Kind>());
2827 if (R) {
2828 Out = *R;
2829 return true;
2830 }
2831 return false;
2832 }
2833
2834 static const char *ConvertKindToStr(Kind Val) {
2835 switch(Val) {
2836 case EnumExtensibilityAttr::Closed: return "closed";
2837 case EnumExtensibilityAttr::Open: return "open";
2838 }
2839 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 2839)
;
2840 }
2841
2842
2843 static bool classof(const Attr *A) { return A->getKind() == attr::EnumExtensibility; }
2844};
2845
2846class ExclusiveTrylockFunctionAttr : public InheritableAttr {
2847Expr * successValue;
2848
2849 unsigned args_Size;
2850 Expr * *args_;
2851
2852public:
2853 static ExclusiveTrylockFunctionAttr *CreateImplicit(ASTContext &Ctx, Expr * SuccessValue, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
2854 auto *A = new (Ctx) ExclusiveTrylockFunctionAttr(Loc, Ctx, SuccessValue, Args, ArgsSize, 0);
2855 A->setImplicit(true);
2856 return A;
2857 }
2858
2859 ExclusiveTrylockFunctionAttr(SourceRange R, ASTContext &Ctx
2860 , Expr * SuccessValue
2861 , Expr * *Args, unsigned ArgsSize
2862 , unsigned SI
2863 )
2864 : InheritableAttr(attr::ExclusiveTrylockFunction, R, SI, true, true)
2865 , successValue(SuccessValue)
2866 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
2867 {
2868 std::copy(Args, Args + args_Size, args_);
2869 }
2870
2871 ExclusiveTrylockFunctionAttr(SourceRange R, ASTContext &Ctx
2872 , Expr * SuccessValue
2873 , unsigned SI
2874 )
2875 : InheritableAttr(attr::ExclusiveTrylockFunction, R, SI, true, true)
2876 , successValue(SuccessValue)
2877 , args_Size(0), args_(nullptr)
2878 {
2879 }
2880
2881 ExclusiveTrylockFunctionAttr *clone(ASTContext &C) const;
2882 void printPretty(raw_ostream &OS,
2883 const PrintingPolicy &Policy) const;
2884 const char *getSpelling() const;
2885 Expr * getSuccessValue() const {
2886 return successValue;
2887 }
2888
2889 typedef Expr ** args_iterator;
2890 args_iterator args_begin() const { return args_; }
2891 args_iterator args_end() const { return args_ + args_Size; }
2892 unsigned args_size() const { return args_Size; }
2893 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
2894
2895
2896
2897
2898 static bool classof(const Attr *A) { return A->getKind() == attr::ExclusiveTrylockFunction; }
2899};
2900
2901class ExternalSourceSymbolAttr : public InheritableAttr {
2902unsigned languageLength;
2903char *language;
2904
2905unsigned definedInLength;
2906char *definedIn;
2907
2908bool generatedDeclaration;
2909
2910public:
2911 static ExternalSourceSymbolAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Language, llvm::StringRef DefinedIn, bool GeneratedDeclaration, SourceRange Loc = SourceRange()) {
2912 auto *A = new (Ctx) ExternalSourceSymbolAttr(Loc, Ctx, Language, DefinedIn, GeneratedDeclaration, 0);
2913 A->setImplicit(true);
2914 return A;
2915 }
2916
2917 ExternalSourceSymbolAttr(SourceRange R, ASTContext &Ctx
2918 , llvm::StringRef Language
2919 , llvm::StringRef DefinedIn
2920 , bool GeneratedDeclaration
2921 , unsigned SI
2922 )
2923 : InheritableAttr(attr::ExternalSourceSymbol, R, SI, false, false)
2924 , languageLength(Language.size()),language(new (Ctx, 1) char[languageLength])
2925 , definedInLength(DefinedIn.size()),definedIn(new (Ctx, 1) char[definedInLength])
2926 , generatedDeclaration(GeneratedDeclaration)
2927 {
2928 if (!Language.empty())
2929 std::memcpy(language, Language.data(), languageLength);
2930 if (!DefinedIn.empty())
2931 std::memcpy(definedIn, DefinedIn.data(), definedInLength);
2932 }
2933
2934 ExternalSourceSymbolAttr(SourceRange R, ASTContext &Ctx
2935 , unsigned SI
2936 )
2937 : InheritableAttr(attr::ExternalSourceSymbol, R, SI, false, false)
2938 , languageLength(0),language(nullptr)
2939 , definedInLength(0),definedIn(nullptr)
2940 , generatedDeclaration()
2941 {
2942 }
2943
2944 ExternalSourceSymbolAttr *clone(ASTContext &C) const;
2945 void printPretty(raw_ostream &OS,
2946 const PrintingPolicy &Policy) const;
2947 const char *getSpelling() const;
2948 llvm::StringRef getLanguage() const {
2949 return llvm::StringRef(language, languageLength);
2950 }
2951 unsigned getLanguageLength() const {
2952 return languageLength;
2953 }
2954 void setLanguage(ASTContext &C, llvm::StringRef S) {
2955 languageLength = S.size();
2956 this->language = new (C, 1) char [languageLength];
2957 if (!S.empty())
2958 std::memcpy(this->language, S.data(), languageLength);
2959 }
2960
2961 llvm::StringRef getDefinedIn() const {
2962 return llvm::StringRef(definedIn, definedInLength);
2963 }
2964 unsigned getDefinedInLength() const {
2965 return definedInLength;
2966 }
2967 void setDefinedIn(ASTContext &C, llvm::StringRef S) {
2968 definedInLength = S.size();
2969 this->definedIn = new (C, 1) char [definedInLength];
2970 if (!S.empty())
2971 std::memcpy(this->definedIn, S.data(), definedInLength);
2972 }
2973
2974 bool getGeneratedDeclaration() const {
2975 return generatedDeclaration;
2976 }
2977
2978
2979
2980 static bool classof(const Attr *A) { return A->getKind() == attr::ExternalSourceSymbol; }
2981};
2982
2983class FallThroughAttr : public StmtAttr {
2984public:
2985 static FallThroughAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2986 auto *A = new (Ctx) FallThroughAttr(Loc, Ctx, 0);
2987 A->setImplicit(true);
2988 return A;
2989 }
2990
2991 FallThroughAttr(SourceRange R, ASTContext &Ctx
2992 , unsigned SI
2993 )
2994 : StmtAttr(attr::FallThrough, R, SI, false)
2995 {
2996 }
2997
2998 FallThroughAttr *clone(ASTContext &C) const;
2999 void printPretty(raw_ostream &OS,
3000 const PrintingPolicy &Policy) const;
3001 const char *getSpelling() const;
3002
3003
3004 static bool classof(const Attr *A) { return A->getKind() == attr::FallThrough; }
3005};
3006
3007class FastCallAttr : public InheritableAttr {
3008public:
3009 static FastCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3010 auto *A = new (Ctx) FastCallAttr(Loc, Ctx, 0);
3011 A->setImplicit(true);
3012 return A;
3013 }
3014
3015 FastCallAttr(SourceRange R, ASTContext &Ctx
3016 , unsigned SI
3017 )
3018 : InheritableAttr(attr::FastCall, R, SI, false, false)
3019 {
3020 }
3021
3022 FastCallAttr *clone(ASTContext &C) const;
3023 void printPretty(raw_ostream &OS,
3024 const PrintingPolicy &Policy) const;
3025 const char *getSpelling() const;
3026
3027
3028 static bool classof(const Attr *A) { return A->getKind() == attr::FastCall; }
3029};
3030
3031class FinalAttr : public InheritableAttr {
3032public:
3033 enum Spelling {
3034 Keyword_final = 0,
3035 Keyword_sealed = 1
3036 };
3037
3038 static FinalAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
3039 auto *A = new (Ctx) FinalAttr(Loc, Ctx, S);
3040 A->setImplicit(true);
3041 return A;
3042 }
3043
3044 FinalAttr(SourceRange R, ASTContext &Ctx
3045 , unsigned SI
3046 )
3047 : InheritableAttr(attr::Final, R, SI, false, false)
3048 {
3049 }
3050
3051 FinalAttr *clone(ASTContext &C) const;
3052 void printPretty(raw_ostream &OS,
3053 const PrintingPolicy &Policy) const;
3054 const char *getSpelling() const;
3055 Spelling getSemanticSpelling() const {
3056 switch (SpellingListIndex) {
3057 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 3057)
;
3058 case 0: return Keyword_final;
3059 case 1: return Keyword_sealed;
3060 }
3061 }
3062 bool isSpelledAsSealed() const { return SpellingListIndex == 1; }
3063
3064
3065 static bool classof(const Attr *A) { return A->getKind() == attr::Final; }
3066};
3067
3068class FlagEnumAttr : public InheritableAttr {
3069public:
3070 static FlagEnumAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3071 auto *A = new (Ctx) FlagEnumAttr(Loc, Ctx, 0);
3072 A->setImplicit(true);
3073 return A;
3074 }
3075
3076 FlagEnumAttr(SourceRange R, ASTContext &Ctx
3077 , unsigned SI
3078 )
3079 : InheritableAttr(attr::FlagEnum, R, SI, false, false)
3080 {
3081 }
3082
3083 FlagEnumAttr *clone(ASTContext &C) const;
3084 void printPretty(raw_ostream &OS,
3085 const PrintingPolicy &Policy) const;
3086 const char *getSpelling() const;
3087
3088
3089 static bool classof(const Attr *A) { return A->getKind() == attr::FlagEnum; }
3090};
3091
3092class FlattenAttr : public InheritableAttr {
3093public:
3094 static FlattenAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3095 auto *A = new (Ctx) FlattenAttr(Loc, Ctx, 0);
3096 A->setImplicit(true);
3097 return A;
3098 }
3099
3100 FlattenAttr(SourceRange R, ASTContext &Ctx
3101 , unsigned SI
3102 )
3103 : InheritableAttr(attr::Flatten, R, SI, false, false)
3104 {
3105 }
3106
3107 FlattenAttr *clone(ASTContext &C) const;
3108 void printPretty(raw_ostream &OS,
3109 const PrintingPolicy &Policy) const;
3110 const char *getSpelling() const;
3111
3112
3113 static bool classof(const Attr *A) { return A->getKind() == attr::Flatten; }
3114};
3115
3116class FormatAttr : public InheritableAttr {
3117IdentifierInfo * type;
3118
3119int formatIdx;
3120
3121int firstArg;
3122
3123public:
3124 static FormatAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Type, int FormatIdx, int FirstArg, SourceRange Loc = SourceRange()) {
3125 auto *A = new (Ctx) FormatAttr(Loc, Ctx, Type, FormatIdx, FirstArg, 0);
3126 A->setImplicit(true);
3127 return A;
3128 }
3129
3130 FormatAttr(SourceRange R, ASTContext &Ctx
3131 , IdentifierInfo * Type
3132 , int FormatIdx
3133 , int FirstArg
3134 , unsigned SI
3135 )
3136 : InheritableAttr(attr::Format, R, SI, false, false)
3137 , type(Type)
3138 , formatIdx(FormatIdx)
3139 , firstArg(FirstArg)
3140 {
3141 }
3142
3143 FormatAttr *clone(ASTContext &C) const;
3144 void printPretty(raw_ostream &OS,
3145 const PrintingPolicy &Policy) const;
3146 const char *getSpelling() const;
3147 IdentifierInfo * getType() const {
3148 return type;
3149 }
3150
3151 int getFormatIdx() const {
3152 return formatIdx;
3153 }
3154
3155 int getFirstArg() const {
3156 return firstArg;
3157 }
3158
3159
3160
3161 static bool classof(const Attr *A) { return A->getKind() == attr::Format; }
3162};
3163
3164class FormatArgAttr : public InheritableAttr {
3165ParamIdx formatIdx;
3166
3167public:
3168 static FormatArgAttr *CreateImplicit(ASTContext &Ctx, ParamIdx FormatIdx, SourceRange Loc = SourceRange()) {
3169 auto *A = new (Ctx) FormatArgAttr(Loc, Ctx, FormatIdx, 0);
3170 A->setImplicit(true);
3171 return A;
3172 }
3173
3174 FormatArgAttr(SourceRange R, ASTContext &Ctx
3175 , ParamIdx FormatIdx
3176 , unsigned SI
3177 )
3178 : InheritableAttr(attr::FormatArg, R, SI, false, false)
3179 , formatIdx(FormatIdx)
3180 {
3181 }
3182
3183 FormatArgAttr *clone(ASTContext &C) const;
3184 void printPretty(raw_ostream &OS,
3185 const PrintingPolicy &Policy) const;
3186 const char *getSpelling() const;
3187 ParamIdx getFormatIdx() const {
3188 return formatIdx;
3189 }
3190
3191
3192
3193 static bool classof(const Attr *A) { return A->getKind() == attr::FormatArg; }
3194};
3195
3196class GNUInlineAttr : public InheritableAttr {
3197public:
3198 static GNUInlineAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3199 auto *A = new (Ctx) GNUInlineAttr(Loc, Ctx, 0);
3200 A->setImplicit(true);
3201 return A;
3202 }
3203
3204 GNUInlineAttr(SourceRange R, ASTContext &Ctx
3205 , unsigned SI
3206 )
3207 : InheritableAttr(attr::GNUInline, R, SI, false, false)
3208 {
3209 }
3210
3211 GNUInlineAttr *clone(ASTContext &C) const;
3212 void printPretty(raw_ostream &OS,
3213 const PrintingPolicy &Policy) const;
3214 const char *getSpelling() const;
3215
3216
3217 static bool classof(const Attr *A) { return A->getKind() == attr::GNUInline; }
3218};
3219
3220class GuardedByAttr : public InheritableAttr {
3221Expr * arg;
3222
3223public:
3224 static GuardedByAttr *CreateImplicit(ASTContext &Ctx, Expr * Arg, SourceRange Loc = SourceRange()) {
3225 auto *A = new (Ctx) GuardedByAttr(Loc, Ctx, Arg, 0);
3226 A->setImplicit(true);
3227 return A;
3228 }
3229
3230 GuardedByAttr(SourceRange R, ASTContext &Ctx
3231 , Expr * Arg
3232 , unsigned SI
3233 )
3234 : InheritableAttr(attr::GuardedBy, R, SI, true, true)
3235 , arg(Arg)
3236 {
3237 }
3238
3239 GuardedByAttr *clone(ASTContext &C) const;
3240 void printPretty(raw_ostream &OS,
3241 const PrintingPolicy &Policy) const;
3242 const char *getSpelling() const;
3243 Expr * getArg() const {
3244 return arg;
3245 }
3246
3247
3248
3249 static bool classof(const Attr *A) { return A->getKind() == attr::GuardedBy; }
3250};
3251
3252class GuardedVarAttr : public InheritableAttr {
3253public:
3254 static GuardedVarAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3255 auto *A = new (Ctx) GuardedVarAttr(Loc, Ctx, 0);
3256 A->setImplicit(true);
3257 return A;
3258 }
3259
3260 GuardedVarAttr(SourceRange R, ASTContext &Ctx
3261 , unsigned SI
3262 )
3263 : InheritableAttr(attr::GuardedVar, R, SI, false, false)
3264 {
3265 }
3266
3267 GuardedVarAttr *clone(ASTContext &C) const;
3268 void printPretty(raw_ostream &OS,
3269 const PrintingPolicy &Policy) const;
3270 const char *getSpelling() const;
3271
3272
3273 static bool classof(const Attr *A) { return A->getKind() == attr::GuardedVar; }
3274};
3275
3276class HotAttr : public InheritableAttr {
3277public:
3278 static HotAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3279 auto *A = new (Ctx) HotAttr(Loc, Ctx, 0);
3280 A->setImplicit(true);
3281 return A;
3282 }
3283
3284 HotAttr(SourceRange R, ASTContext &Ctx
3285 , unsigned SI
3286 )
3287 : InheritableAttr(attr::Hot, R, SI, false, false)
3288 {
3289 }
3290
3291 HotAttr *clone(ASTContext &C) const;
3292 void printPretty(raw_ostream &OS,
3293 const PrintingPolicy &Policy) const;
3294 const char *getSpelling() const;
3295
3296
3297 static bool classof(const Attr *A) { return A->getKind() == attr::Hot; }
3298};
3299
3300class IBActionAttr : public InheritableAttr {
3301public:
3302 static IBActionAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3303 auto *A = new (Ctx) IBActionAttr(Loc, Ctx, 0);
3304 A->setImplicit(true);
3305 return A;
3306 }
3307
3308 IBActionAttr(SourceRange R, ASTContext &Ctx
3309 , unsigned SI
3310 )
3311 : InheritableAttr(attr::IBAction, R, SI, false, false)
3312 {
3313 }
3314
3315 IBActionAttr *clone(ASTContext &C) const;
3316 void printPretty(raw_ostream &OS,
3317 const PrintingPolicy &Policy) const;
3318 const char *getSpelling() const;
3319
3320
3321 static bool classof(const Attr *A) { return A->getKind() == attr::IBAction; }
3322};
3323
3324class IBOutletAttr : public InheritableAttr {
3325public:
3326 static IBOutletAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3327 auto *A = new (Ctx) IBOutletAttr(Loc, Ctx, 0);
3328 A->setImplicit(true);
3329 return A;
3330 }
3331
3332 IBOutletAttr(SourceRange R, ASTContext &Ctx
3333 , unsigned SI
3334 )
3335 : InheritableAttr(attr::IBOutlet, R, SI, false, false)
3336 {
3337 }
3338
3339 IBOutletAttr *clone(ASTContext &C) const;
3340 void printPretty(raw_ostream &OS,
3341 const PrintingPolicy &Policy) const;
3342 const char *getSpelling() const;
3343
3344
3345 static bool classof(const Attr *A) { return A->getKind() == attr::IBOutlet; }
3346};
3347
3348class IBOutletCollectionAttr : public InheritableAttr {
3349TypeSourceInfo * interface_;
3350
3351public:
3352 static IBOutletCollectionAttr *CreateImplicit(ASTContext &Ctx, TypeSourceInfo * Interface, SourceRange Loc = SourceRange()) {
3353 auto *A = new (Ctx) IBOutletCollectionAttr(Loc, Ctx, Interface, 0);
3354 A->setImplicit(true);
3355 return A;
3356 }
3357
3358 IBOutletCollectionAttr(SourceRange R, ASTContext &Ctx
3359 , TypeSourceInfo * Interface
3360 , unsigned SI
3361 )
3362 : InheritableAttr(attr::IBOutletCollection, R, SI, false, false)
3363 , interface_(Interface)
3364 {
3365 }
3366
3367 IBOutletCollectionAttr(SourceRange R, ASTContext &Ctx
3368 , unsigned SI
3369 )
3370 : InheritableAttr(attr::IBOutletCollection, R, SI, false, false)
3371 , interface_()
3372 {
3373 }
3374
3375 IBOutletCollectionAttr *clone(ASTContext &C) const;
3376 void printPretty(raw_ostream &OS,
3377 const PrintingPolicy &Policy) const;
3378 const char *getSpelling() const;
3379 QualType getInterface() const {
3380 return interface_->getType();
3381 } TypeSourceInfo * getInterfaceLoc() const {
3382 return interface_;
3383 }
3384
3385
3386
3387 static bool classof(const Attr *A) { return A->getKind() == attr::IBOutletCollection; }
3388};
3389
3390class IFuncAttr : public Attr {
3391unsigned resolverLength;
3392char *resolver;
3393
3394public:
3395 static IFuncAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Resolver, SourceRange Loc = SourceRange()) {
3396 auto *A = new (Ctx) IFuncAttr(Loc, Ctx, Resolver, 0);
3397 A->setImplicit(true);
3398 return A;
3399 }
3400
3401 IFuncAttr(SourceRange R, ASTContext &Ctx
3402 , llvm::StringRef Resolver
3403 , unsigned SI
3404 )
3405 : Attr(attr::IFunc, R, SI, false)
3406 , resolverLength(Resolver.size()),resolver(new (Ctx, 1) char[resolverLength])
3407 {
3408 if (!Resolver.empty())
3409 std::memcpy(resolver, Resolver.data(), resolverLength);
3410 }
3411
3412 IFuncAttr *clone(ASTContext &C) const;
3413 void printPretty(raw_ostream &OS,
3414 const PrintingPolicy &Policy) const;
3415 const char *getSpelling() const;
3416 llvm::StringRef getResolver() const {
3417 return llvm::StringRef(resolver, resolverLength);
3418 }
3419 unsigned getResolverLength() const {
3420 return resolverLength;
3421 }
3422 void setResolver(ASTContext &C, llvm::StringRef S) {
3423 resolverLength = S.size();
3424 this->resolver = new (C, 1) char [resolverLength];
3425 if (!S.empty())
3426 std::memcpy(this->resolver, S.data(), resolverLength);
3427 }
3428
3429
3430
3431 static bool classof(const Attr *A) { return A->getKind() == attr::IFunc; }
3432};
3433
3434class InitPriorityAttr : public InheritableAttr {
3435unsigned priority;
3436
3437public:
3438 static InitPriorityAttr *CreateImplicit(ASTContext &Ctx, unsigned Priority, SourceRange Loc = SourceRange()) {
3439 auto *A = new (Ctx) InitPriorityAttr(Loc, Ctx, Priority, 0);
3440 A->setImplicit(true);
3441 return A;
3442 }
3443
3444 InitPriorityAttr(SourceRange R, ASTContext &Ctx
3445 , unsigned Priority
3446 , unsigned SI
3447 )
3448 : InheritableAttr(attr::InitPriority, R, SI, false, false)
3449 , priority(Priority)
3450 {
3451 }
3452
3453 InitPriorityAttr *clone(ASTContext &C) const;
3454 void printPretty(raw_ostream &OS,
3455 const PrintingPolicy &Policy) const;
3456 const char *getSpelling() const;
3457 unsigned getPriority() const {
3458 return priority;
3459 }
3460
3461
3462
3463 static bool classof(const Attr *A) { return A->getKind() == attr::InitPriority; }
3464};
3465
3466class InitSegAttr : public Attr {
3467unsigned sectionLength;
3468char *section;
3469
3470public:
3471 static InitSegAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Section, SourceRange Loc = SourceRange()) {
3472 auto *A = new (Ctx) InitSegAttr(Loc, Ctx, Section, 0);
3473 A->setImplicit(true);
3474 return A;
3475 }
3476
3477 InitSegAttr(SourceRange R, ASTContext &Ctx
3478 , llvm::StringRef Section
3479 , unsigned SI
3480 )
3481 : Attr(attr::InitSeg, R, SI, false)
3482 , sectionLength(Section.size()),section(new (Ctx, 1) char[sectionLength])
3483 {
3484 if (!Section.empty())
3485 std::memcpy(section, Section.data(), sectionLength);
3486 }
3487
3488 InitSegAttr *clone(ASTContext &C) const;
3489 void printPretty(raw_ostream &OS,
3490 const PrintingPolicy &Policy) const;
3491 const char *getSpelling() const;
3492 llvm::StringRef getSection() const {
3493 return llvm::StringRef(section, sectionLength);
3494 }
3495 unsigned getSectionLength() const {
3496 return sectionLength;
3497 }
3498 void setSection(ASTContext &C, llvm::StringRef S) {
3499 sectionLength = S.size();
3500 this->section = new (C, 1) char [sectionLength];
3501 if (!S.empty())
3502 std::memcpy(this->section, S.data(), sectionLength);
3503 }
3504
3505
3506 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
3507 OS << " (" << getSection() << ')';
3508 }
3509
3510
3511 static bool classof(const Attr *A) { return A->getKind() == attr::InitSeg; }
3512};
3513
3514class IntelOclBiccAttr : public InheritableAttr {
3515public:
3516 static IntelOclBiccAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3517 auto *A = new (Ctx) IntelOclBiccAttr(Loc, Ctx, 0);
3518 A->setImplicit(true);
3519 return A;
3520 }
3521
3522 IntelOclBiccAttr(SourceRange R, ASTContext &Ctx
3523 , unsigned SI
3524 )
3525 : InheritableAttr(attr::IntelOclBicc, R, SI, false, false)
3526 {
3527 }
3528
3529 IntelOclBiccAttr *clone(ASTContext &C) const;
3530 void printPretty(raw_ostream &OS,
3531 const PrintingPolicy &Policy) const;
3532 const char *getSpelling() const;
3533
3534
3535 static bool classof(const Attr *A) { return A->getKind() == attr::IntelOclBicc; }
3536};
3537
3538class InternalLinkageAttr : public InheritableAttr {
3539public:
3540 static InternalLinkageAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3541 auto *A = new (Ctx) InternalLinkageAttr(Loc, Ctx, 0);
3542 A->setImplicit(true);
3543 return A;
3544 }
3545
3546 InternalLinkageAttr(SourceRange R, ASTContext &Ctx
3547 , unsigned SI
3548 )
3549 : InheritableAttr(attr::InternalLinkage, R, SI, false, false)
3550 {
3551 }
3552
3553 InternalLinkageAttr *clone(ASTContext &C) const;
3554 void printPretty(raw_ostream &OS,
3555 const PrintingPolicy &Policy) const;
3556 const char *getSpelling() const;
3557
3558
3559 static bool classof(const Attr *A) { return A->getKind() == attr::InternalLinkage; }
3560};
3561
3562class LTOVisibilityPublicAttr : public InheritableAttr {
3563public:
3564 static LTOVisibilityPublicAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3565 auto *A = new (Ctx) LTOVisibilityPublicAttr(Loc, Ctx, 0);
3566 A->setImplicit(true);
3567 return A;
3568 }
3569
3570 LTOVisibilityPublicAttr(SourceRange R, ASTContext &Ctx
3571 , unsigned SI
3572 )
3573 : InheritableAttr(attr::LTOVisibilityPublic, R, SI, false, false)
3574 {
3575 }
3576
3577 LTOVisibilityPublicAttr *clone(ASTContext &C) const;
3578 void printPretty(raw_ostream &OS,
3579 const PrintingPolicy &Policy) const;
3580 const char *getSpelling() const;
3581
3582
3583 static bool classof(const Attr *A) { return A->getKind() == attr::LTOVisibilityPublic; }
3584};
3585
3586class LayoutVersionAttr : public InheritableAttr {
3587unsigned version;
3588
3589public:
3590 static LayoutVersionAttr *CreateImplicit(ASTContext &Ctx, unsigned Version, SourceRange Loc = SourceRange()) {
3591 auto *A = new (Ctx) LayoutVersionAttr(Loc, Ctx, Version, 0);
3592 A->setImplicit(true);
3593 return A;
3594 }
3595
3596 LayoutVersionAttr(SourceRange R, ASTContext &Ctx
3597 , unsigned Version
3598 , unsigned SI
3599 )
3600 : InheritableAttr(attr::LayoutVersion, R, SI, false, false)
3601 , version(Version)
3602 {
3603 }
3604
3605 LayoutVersionAttr *clone(ASTContext &C) const;
3606 void printPretty(raw_ostream &OS,
3607 const PrintingPolicy &Policy) const;
3608 const char *getSpelling() const;
3609 unsigned getVersion() const {
3610 return version;
3611 }
3612
3613
3614
3615 static bool classof(const Attr *A) { return A->getKind() == attr::LayoutVersion; }
3616};
3617
3618class LockReturnedAttr : public InheritableAttr {
3619Expr * arg;
3620
3621public:
3622 static LockReturnedAttr *CreateImplicit(ASTContext &Ctx, Expr * Arg, SourceRange Loc = SourceRange()) {
3623 auto *A = new (Ctx) LockReturnedAttr(Loc, Ctx, Arg, 0);
3624 A->setImplicit(true);
3625 return A;
3626 }
3627
3628 LockReturnedAttr(SourceRange R, ASTContext &Ctx
3629 , Expr * Arg
3630 , unsigned SI
3631 )
3632 : InheritableAttr(attr::LockReturned, R, SI, true, false)
3633 , arg(Arg)
3634 {
3635 }
3636
3637 LockReturnedAttr *clone(ASTContext &C) const;
3638 void printPretty(raw_ostream &OS,
3639 const PrintingPolicy &Policy) const;
3640 const char *getSpelling() const;
3641 Expr * getArg() const {
3642 return arg;
3643 }
3644
3645
3646
3647 static bool classof(const Attr *A) { return A->getKind() == attr::LockReturned; }
3648};
3649
3650class LocksExcludedAttr : public InheritableAttr {
3651 unsigned args_Size;
3652 Expr * *args_;
3653
3654public:
3655 static LocksExcludedAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
3656 auto *A = new (Ctx) LocksExcludedAttr(Loc, Ctx, Args, ArgsSize, 0);
3657 A->setImplicit(true);
3658 return A;
3659 }
3660
3661 LocksExcludedAttr(SourceRange R, ASTContext &Ctx
3662 , Expr * *Args, unsigned ArgsSize
3663 , unsigned SI
3664 )
3665 : InheritableAttr(attr::LocksExcluded, R, SI, true, true)
3666 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
3667 {
3668 std::copy(Args, Args + args_Size, args_);
3669 }
3670
3671 LocksExcludedAttr(SourceRange R, ASTContext &Ctx
3672 , unsigned SI
3673 )
3674 : InheritableAttr(attr::LocksExcluded, R, SI, true, true)
3675 , args_Size(0), args_(nullptr)
3676 {
3677 }
3678
3679 LocksExcludedAttr *clone(ASTContext &C) const;
3680 void printPretty(raw_ostream &OS,
3681 const PrintingPolicy &Policy) const;
3682 const char *getSpelling() const;
3683 typedef Expr ** args_iterator;
3684 args_iterator args_begin() const { return args_; }
3685 args_iterator args_end() const { return args_ + args_Size; }
3686 unsigned args_size() const { return args_Size; }
3687 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
3688
3689
3690
3691
3692 static bool classof(const Attr *A) { return A->getKind() == attr::LocksExcluded; }
3693};
3694
3695class LoopHintAttr : public Attr {
3696public:
3697 enum OptionType {
3698 Vectorize,
3699 VectorizeWidth,
3700 Interleave,
3701 InterleaveCount,
3702 Unroll,
3703 UnrollCount,
3704 Distribute
3705 };
3706private:
3707 OptionType option;
3708
3709public:
3710 enum LoopHintState {
3711 Enable,
3712 Disable,
3713 Numeric,
3714 AssumeSafety,
3715 Full
3716 };
3717private:
3718 LoopHintState state;
3719
3720Expr * value;
3721
3722public:
3723 enum Spelling {
3724 Pragma_clang_loop = 0,
3725 Pragma_unroll = 1,
3726 Pragma_nounroll = 2
3727 };
3728
3729 static LoopHintAttr *CreateImplicit(ASTContext &Ctx, Spelling S, OptionType Option, LoopHintState State, Expr * Value, SourceRange Loc = SourceRange()) {
3730 auto *A = new (Ctx) LoopHintAttr(Loc, Ctx, Option, State, Value, S);
3731 A->setImplicit(true);
3732 return A;
3733 }
3734
3735 LoopHintAttr(SourceRange R, ASTContext &Ctx
3736 , OptionType Option
3737 , LoopHintState State
3738 , Expr * Value
3739 , unsigned SI
3740 )
3741 : Attr(attr::LoopHint, R, SI, false)
3742 , option(Option)
3743 , state(State)
3744 , value(Value)
3745 {
3746 }
3747
3748 LoopHintAttr *clone(ASTContext &C) const;
3749 void printPretty(raw_ostream &OS,
3750 const PrintingPolicy &Policy) const;
3751 const char *getSpelling() const;
3752 Spelling getSemanticSpelling() const {
3753 switch (SpellingListIndex) {
3754 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 3754)
;
3755 case 0: return Pragma_clang_loop;
3756 case 1: return Pragma_unroll;
3757 case 2: return Pragma_nounroll;
3758 }
3759 }
3760 OptionType getOption() const {
3761 return option;
3762 }
3763
3764 static bool ConvertStrToOptionType(StringRef Val, OptionType &Out) {
3765 Optional<OptionType> R = llvm::StringSwitch<Optional<OptionType>>(Val)
3766 .Case("vectorize", LoopHintAttr::Vectorize)
3767 .Case("vectorize_width", LoopHintAttr::VectorizeWidth)
3768 .Case("interleave", LoopHintAttr::Interleave)
3769 .Case("interleave_count", LoopHintAttr::InterleaveCount)
3770 .Case("unroll", LoopHintAttr::Unroll)
3771 .Case("unroll_count", LoopHintAttr::UnrollCount)
3772 .Case("distribute", LoopHintAttr::Distribute)
3773 .Default(Optional<OptionType>());
3774 if (R) {
3775 Out = *R;
3776 return true;
3777 }
3778 return false;
3779 }
3780
3781 static const char *ConvertOptionTypeToStr(OptionType Val) {
3782 switch(Val) {
3783 case LoopHintAttr::Vectorize: return "vectorize";
3784 case LoopHintAttr::VectorizeWidth: return "vectorize_width";
3785 case LoopHintAttr::Interleave: return "interleave";
3786 case LoopHintAttr::InterleaveCount: return "interleave_count";
3787 case LoopHintAttr::Unroll: return "unroll";
3788 case LoopHintAttr::UnrollCount: return "unroll_count";
3789 case LoopHintAttr::Distribute: return "distribute";
3790 }
3791 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 3791)
;
3792 }
3793 LoopHintState getState() const {
3794 return state;
3795 }
3796
3797 static bool ConvertStrToLoopHintState(StringRef Val, LoopHintState &Out) {
3798 Optional<LoopHintState> R = llvm::StringSwitch<Optional<LoopHintState>>(Val)
3799 .Case("enable", LoopHintAttr::Enable)
3800 .Case("disable", LoopHintAttr::Disable)
3801 .Case("numeric", LoopHintAttr::Numeric)
3802 .Case("assume_safety", LoopHintAttr::AssumeSafety)
3803 .Case("full", LoopHintAttr::Full)
3804 .Default(Optional<LoopHintState>());
3805 if (R) {
3806 Out = *R;
3807 return true;
3808 }
3809 return false;
3810 }
3811
3812 static const char *ConvertLoopHintStateToStr(LoopHintState Val) {
3813 switch(Val) {
3814 case LoopHintAttr::Enable: return "enable";
3815 case LoopHintAttr::Disable: return "disable";
3816 case LoopHintAttr::Numeric: return "numeric";
3817 case LoopHintAttr::AssumeSafety: return "assume_safety";
3818 case LoopHintAttr::Full: return "full";
3819 }
3820 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 3820)
;
3821 }
3822 Expr * getValue() const {
3823 return value;
3824 }
3825
3826
3827 static const char *getOptionName(int Option) {
3828 switch(Option) {
3829 case Vectorize: return "vectorize";
3830 case VectorizeWidth: return "vectorize_width";
3831 case Interleave: return "interleave";
3832 case InterleaveCount: return "interleave_count";
3833 case Unroll: return "unroll";
3834 case UnrollCount: return "unroll_count";
3835 case Distribute: return "distribute";
3836 }
3837 llvm_unreachable("Unhandled LoopHint option.")::llvm::llvm_unreachable_internal("Unhandled LoopHint option."
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 3837)
;
3838 }
3839
3840 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
3841 unsigned SpellingIndex = getSpellingListIndex();
3842 // For "#pragma unroll" and "#pragma nounroll" the string "unroll" or
3843 // "nounroll" is already emitted as the pragma name.
3844 if (SpellingIndex == Pragma_nounroll)
3845 return;
3846 else if (SpellingIndex == Pragma_unroll) {
3847 OS << ' ' << getValueString(Policy);
3848 return;
3849 }
3850
3851 assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling")(static_cast <bool> (SpellingIndex == Pragma_clang_loop
&& "Unexpected spelling") ? void (0) : __assert_fail
("SpellingIndex == Pragma_clang_loop && \"Unexpected spelling\""
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 3851, __extension__ __PRETTY_FUNCTION__))
;
3852 OS << ' ' << getOptionName(option) << getValueString(Policy);
3853 }
3854
3855 // Return a string containing the loop hint argument including the
3856 // enclosing parentheses.
3857 std::string getValueString(const PrintingPolicy &Policy) const {
3858 std::string ValueName;
3859 llvm::raw_string_ostream OS(ValueName);
3860 OS << "(";
3861 if (state == Numeric)
3862 value->printPretty(OS, nullptr, Policy);
3863 else if (state == Enable)
3864 OS << "enable";
3865 else if (state == Full)
3866 OS << "full";
3867 else if (state == AssumeSafety)
3868 OS << "assume_safety";
3869 else
3870 OS << "disable";
3871 OS << ")";
3872 return OS.str();
3873 }
3874
3875 // Return a string suitable for identifying this attribute in diagnostics.
3876 std::string getDiagnosticName(const PrintingPolicy &Policy) const {
3877 unsigned SpellingIndex = getSpellingListIndex();
3878 if (SpellingIndex == Pragma_nounroll)
3879 return "#pragma nounroll";
3880 else if (SpellingIndex == Pragma_unroll)
3881 return "#pragma unroll" + (option == UnrollCount ? getValueString(Policy) : "");
3882
3883 assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling")(static_cast <bool> (SpellingIndex == Pragma_clang_loop
&& "Unexpected spelling") ? void (0) : __assert_fail
("SpellingIndex == Pragma_clang_loop && \"Unexpected spelling\""
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 3883, __extension__ __PRETTY_FUNCTION__))
;
3884 return getOptionName(option) + getValueString(Policy);
3885 }
3886
3887
3888 static bool classof(const Attr *A) { return A->getKind() == attr::LoopHint; }
3889};
3890
3891class MSABIAttr : public InheritableAttr {
3892public:
3893 static MSABIAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3894 auto *A = new (Ctx) MSABIAttr(Loc, Ctx, 0);
3895 A->setImplicit(true);
3896 return A;
3897 }
3898
3899 MSABIAttr(SourceRange R, ASTContext &Ctx
3900 , unsigned SI
3901 )
3902 : InheritableAttr(attr::MSABI, R, SI, false, false)
3903 {
3904 }
3905
3906 MSABIAttr *clone(ASTContext &C) const;
3907 void printPretty(raw_ostream &OS,
3908 const PrintingPolicy &Policy) const;
3909 const char *getSpelling() const;
3910
3911
3912 static bool classof(const Attr *A) { return A->getKind() == attr::MSABI; }
3913};
3914
3915class MSInheritanceAttr : public InheritableAttr {
3916bool bestCase;
3917
3918public:
3919 enum Spelling {
3920 Keyword_single_inheritance = 0,
3921 Keyword_multiple_inheritance = 1,
3922 Keyword_virtual_inheritance = 2,
3923 Keyword_unspecified_inheritance = 3
3924 };
3925
3926 static MSInheritanceAttr *CreateImplicit(ASTContext &Ctx, Spelling S, bool BestCase, SourceRange Loc = SourceRange()) {
3927 auto *A = new (Ctx) MSInheritanceAttr(Loc, Ctx, BestCase, S);
3928 A->setImplicit(true);
3929 return A;
3930 }
3931
3932 MSInheritanceAttr(SourceRange R, ASTContext &Ctx
3933 , bool BestCase
3934 , unsigned SI
3935 )
3936 : InheritableAttr(attr::MSInheritance, R, SI, false, false)
3937 , bestCase(BestCase)
3938 {
3939 }
3940
3941 MSInheritanceAttr(SourceRange R, ASTContext &Ctx
3942 , unsigned SI
3943 )
3944 : InheritableAttr(attr::MSInheritance, R, SI, false, false)
3945 , bestCase()
3946 {
3947 }
3948
3949 MSInheritanceAttr *clone(ASTContext &C) const;
3950 void printPretty(raw_ostream &OS,
3951 const PrintingPolicy &Policy) const;
3952 const char *getSpelling() const;
3953 Spelling getSemanticSpelling() const {
3954 switch (SpellingListIndex) {
3955 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 3955)
;
3956 case 0: return Keyword_single_inheritance;
3957 case 1: return Keyword_multiple_inheritance;
3958 case 2: return Keyword_virtual_inheritance;
3959 case 3: return Keyword_unspecified_inheritance;
3960 }
3961 }
3962 bool getBestCase() const {
3963 return bestCase;
3964 }
3965
3966 static const bool DefaultBestCase = true;
3967
3968
3969 static bool hasVBPtrOffsetField(Spelling Inheritance) {
3970 return Inheritance == Keyword_unspecified_inheritance;
3971 }
3972
3973 // Only member pointers to functions need a this adjustment, since it can be
3974 // combined with the field offset for data pointers.
3975 static bool hasNVOffsetField(bool IsMemberFunction, Spelling Inheritance) {
3976 return IsMemberFunction && Inheritance >= Keyword_multiple_inheritance;
3977 }
3978
3979 static bool hasVBTableOffsetField(Spelling Inheritance) {
3980 return Inheritance >= Keyword_virtual_inheritance;
3981 }
3982
3983 static bool hasOnlyOneField(bool IsMemberFunction,
3984 Spelling Inheritance) {
3985 if (IsMemberFunction)
3986 return Inheritance <= Keyword_single_inheritance;
3987 return Inheritance <= Keyword_multiple_inheritance;
3988 }
3989
3990
3991 static bool classof(const Attr *A) { return A->getKind() == attr::MSInheritance; }
3992};
3993
3994class MSNoVTableAttr : public InheritableAttr {
3995public:
3996 static MSNoVTableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3997 auto *A = new (Ctx) MSNoVTableAttr(Loc, Ctx, 0);
3998 A->setImplicit(true);
3999 return A;
4000 }
4001
4002 MSNoVTableAttr(SourceRange R, ASTContext &Ctx
4003 , unsigned SI
4004 )
4005 : InheritableAttr(attr::MSNoVTable, R, SI, false, false)
4006 {
4007 }
4008
4009 MSNoVTableAttr *clone(ASTContext &C) const;
4010 void printPretty(raw_ostream &OS,
4011 const PrintingPolicy &Policy) const;
4012 const char *getSpelling() const;
4013
4014
4015 static bool classof(const Attr *A) { return A->getKind() == attr::MSNoVTable; }
4016};
4017
4018class MSP430InterruptAttr : public InheritableAttr {
4019unsigned number;
4020
4021public:
4022 static MSP430InterruptAttr *CreateImplicit(ASTContext &Ctx, unsigned Number, SourceRange Loc = SourceRange()) {
4023 auto *A = new (Ctx) MSP430InterruptAttr(Loc, Ctx, Number, 0);
4024 A->setImplicit(true);
4025 return A;
4026 }
4027
4028 MSP430InterruptAttr(SourceRange R, ASTContext &Ctx
4029 , unsigned Number
4030 , unsigned SI
4031 )
4032 : InheritableAttr(attr::MSP430Interrupt, R, SI, false, false)
4033 , number(Number)
4034 {
4035 }
4036
4037 MSP430InterruptAttr *clone(ASTContext &C) const;
4038 void printPretty(raw_ostream &OS,
4039 const PrintingPolicy &Policy) const;
4040 const char *getSpelling() const;
4041 unsigned getNumber() const {
4042 return number;
4043 }
4044
4045
4046
4047 static bool classof(const Attr *A) { return A->getKind() == attr::MSP430Interrupt; }
4048};
4049
4050class MSStructAttr : public InheritableAttr {
4051public:
4052 static MSStructAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4053 auto *A = new (Ctx) MSStructAttr(Loc, Ctx, 0);
4054 A->setImplicit(true);
4055 return A;
4056 }
4057
4058 MSStructAttr(SourceRange R, ASTContext &Ctx
4059 , unsigned SI
4060 )
4061 : InheritableAttr(attr::MSStruct, R, SI, false, false)
4062 {
4063 }
4064
4065 MSStructAttr *clone(ASTContext &C) const;
4066 void printPretty(raw_ostream &OS,
4067 const PrintingPolicy &Policy) const;
4068 const char *getSpelling() const;
4069
4070
4071 static bool classof(const Attr *A) { return A->getKind() == attr::MSStruct; }
4072};
4073
4074class MSVtorDispAttr : public InheritableAttr {
4075unsigned vdm;
4076
4077public:
4078 static MSVtorDispAttr *CreateImplicit(ASTContext &Ctx, unsigned Vdm, SourceRange Loc = SourceRange()) {
4079 auto *A = new (Ctx) MSVtorDispAttr(Loc, Ctx, Vdm, 0);
4080 A->setImplicit(true);
4081 return A;
4082 }
4083
4084 MSVtorDispAttr(SourceRange R, ASTContext &Ctx
4085 , unsigned Vdm
4086 , unsigned SI
4087 )
4088 : InheritableAttr(attr::MSVtorDisp, R, SI, false, false)
4089 , vdm(Vdm)
4090 {
4091 }
4092
4093 MSVtorDispAttr *clone(ASTContext &C) const;
4094 void printPretty(raw_ostream &OS,
4095 const PrintingPolicy &Policy) const;
4096 const char *getSpelling() const;
4097 unsigned getVdm() const {
4098 return vdm;
4099 }
4100
4101
4102 enum Mode {
4103 Never,
4104 ForVBaseOverride,
4105 ForVFTable
4106 };
4107
4108 Mode getVtorDispMode() const { return Mode(vdm); }
4109
4110
4111 static bool classof(const Attr *A) { return A->getKind() == attr::MSVtorDisp; }
4112};
4113
4114class MaxFieldAlignmentAttr : public InheritableAttr {
4115unsigned alignment;
4116
4117public:
4118 static MaxFieldAlignmentAttr *CreateImplicit(ASTContext &Ctx, unsigned Alignment, SourceRange Loc = SourceRange()) {
4119 auto *A = new (Ctx) MaxFieldAlignmentAttr(Loc, Ctx, Alignment, 0);
4120 A->setImplicit(true);
4121 return A;
4122 }
4123
4124 MaxFieldAlignmentAttr(SourceRange R, ASTContext &Ctx
4125 , unsigned Alignment
4126 , unsigned SI
4127 )
4128 : InheritableAttr(attr::MaxFieldAlignment, R, SI, false, false)
4129 , alignment(Alignment)
4130 {
4131 }
4132
4133 MaxFieldAlignmentAttr *clone(ASTContext &C) const;
4134 void printPretty(raw_ostream &OS,
4135 const PrintingPolicy &Policy) const;
4136 const char *getSpelling() const;
4137 unsigned getAlignment() const {
4138 return alignment;
4139 }
4140
4141
4142
4143 static bool classof(const Attr *A) { return A->getKind() == attr::MaxFieldAlignment; }
4144};
4145
4146class MayAliasAttr : public InheritableAttr {
4147public:
4148 static MayAliasAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4149 auto *A = new (Ctx) MayAliasAttr(Loc, Ctx, 0);
4150 A->setImplicit(true);
4151 return A;
4152 }
4153
4154 MayAliasAttr(SourceRange R, ASTContext &Ctx
4155 , unsigned SI
4156 )
4157 : InheritableAttr(attr::MayAlias, R, SI, false, false)
4158 {
4159 }
4160
4161 MayAliasAttr *clone(ASTContext &C) const;
4162 void printPretty(raw_ostream &OS,
4163 const PrintingPolicy &Policy) const;
4164 const char *getSpelling() const;
4165
4166
4167 static bool classof(const Attr *A) { return A->getKind() == attr::MayAlias; }
4168};
4169
4170class MicroMipsAttr : public InheritableAttr {
4171public:
4172 static MicroMipsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4173 auto *A = new (Ctx) MicroMipsAttr(Loc, Ctx, 0);
4174 A->setImplicit(true);
4175 return A;
4176 }
4177
4178 MicroMipsAttr(SourceRange R, ASTContext &Ctx
4179 , unsigned SI
4180 )
4181 : InheritableAttr(attr::MicroMips, R, SI, false, false)
4182 {
4183 }
4184
4185 MicroMipsAttr *clone(ASTContext &C) const;
4186 void printPretty(raw_ostream &OS,
4187 const PrintingPolicy &Policy) const;
4188 const char *getSpelling() const;
4189
4190
4191 static bool classof(const Attr *A) { return A->getKind() == attr::MicroMips; }
4192};
4193
4194class MinSizeAttr : public InheritableAttr {
4195public:
4196 static MinSizeAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4197 auto *A = new (Ctx) MinSizeAttr(Loc, Ctx, 0);
4198 A->setImplicit(true);
4199 return A;
4200 }
4201
4202 MinSizeAttr(SourceRange R, ASTContext &Ctx
4203 , unsigned SI
4204 )
4205 : InheritableAttr(attr::MinSize, R, SI, false, false)
4206 {
4207 }
4208
4209 MinSizeAttr *clone(ASTContext &C) const;
4210 void printPretty(raw_ostream &OS,
4211 const PrintingPolicy &Policy) const;
4212 const char *getSpelling() const;
4213
4214
4215 static bool classof(const Attr *A) { return A->getKind() == attr::MinSize; }
4216};
4217
4218class Mips16Attr : public InheritableAttr {
4219public:
4220 static Mips16Attr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4221 auto *A = new (Ctx) Mips16Attr(Loc, Ctx, 0);
4222 A->setImplicit(true);
4223 return A;
4224 }
4225
4226 Mips16Attr(SourceRange R, ASTContext &Ctx
4227 , unsigned SI
4228 )
4229 : InheritableAttr(attr::Mips16, R, SI, false, false)
4230 {
4231 }
4232
4233 Mips16Attr *clone(ASTContext &C) const;
4234 void printPretty(raw_ostream &OS,
4235 const PrintingPolicy &Policy) const;
4236 const char *getSpelling() const;
4237
4238
4239 static bool classof(const Attr *A) { return A->getKind() == attr::Mips16; }
4240};
4241
4242class MipsInterruptAttr : public InheritableAttr {
4243public:
4244 enum InterruptType {
4245 sw0,
4246 sw1,
4247 hw0,
4248 hw1,
4249 hw2,
4250 hw3,
4251 hw4,
4252 hw5,
4253 eic
4254 };
4255private:
4256 InterruptType interrupt;
4257
4258public:
4259 static MipsInterruptAttr *CreateImplicit(ASTContext &Ctx, InterruptType Interrupt, SourceRange Loc = SourceRange()) {
4260 auto *A = new (Ctx) MipsInterruptAttr(Loc, Ctx, Interrupt, 0);
4261 A->setImplicit(true);
4262 return A;
4263 }
4264
4265 MipsInterruptAttr(SourceRange R, ASTContext &Ctx
4266 , InterruptType Interrupt
4267 , unsigned SI
4268 )
4269 : InheritableAttr(attr::MipsInterrupt, R, SI, false, false)
4270 , interrupt(Interrupt)
4271 {
4272 }
4273
4274 MipsInterruptAttr *clone(ASTContext &C) const;
4275 void printPretty(raw_ostream &OS,
4276 const PrintingPolicy &Policy) const;
4277 const char *getSpelling() const;
4278 InterruptType getInterrupt() const {
4279 return interrupt;
4280 }
4281
4282 static bool ConvertStrToInterruptType(StringRef Val, InterruptType &Out) {
4283 Optional<InterruptType> R = llvm::StringSwitch<Optional<InterruptType>>(Val)
4284 .Case("vector=sw0", MipsInterruptAttr::sw0)
4285 .Case("vector=sw1", MipsInterruptAttr::sw1)
4286 .Case("vector=hw0", MipsInterruptAttr::hw0)
4287 .Case("vector=hw1", MipsInterruptAttr::hw1)
4288 .Case("vector=hw2", MipsInterruptAttr::hw2)
4289 .Case("vector=hw3", MipsInterruptAttr::hw3)
4290 .Case("vector=hw4", MipsInterruptAttr::hw4)
4291 .Case("vector=hw5", MipsInterruptAttr::hw5)
4292 .Case("eic", MipsInterruptAttr::eic)
4293 .Case("", MipsInterruptAttr::eic)
4294 .Default(Optional<InterruptType>());
4295 if (R) {
4296 Out = *R;
4297 return true;
4298 }
4299 return false;
4300 }
4301
4302 static const char *ConvertInterruptTypeToStr(InterruptType Val) {
4303 switch(Val) {
4304 case MipsInterruptAttr::sw0: return "vector=sw0";
4305 case MipsInterruptAttr::sw1: return "vector=sw1";
4306 case MipsInterruptAttr::hw0: return "vector=hw0";
4307 case MipsInterruptAttr::hw1: return "vector=hw1";
4308 case MipsInterruptAttr::hw2: return "vector=hw2";
4309 case MipsInterruptAttr::hw3: return "vector=hw3";
4310 case MipsInterruptAttr::hw4: return "vector=hw4";
4311 case MipsInterruptAttr::hw5: return "vector=hw5";
4312 case MipsInterruptAttr::eic: return "eic";
4313 }
4314 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 4314)
;
4315 }
4316
4317
4318 static bool classof(const Attr *A) { return A->getKind() == attr::MipsInterrupt; }
4319};
4320
4321class MipsLongCallAttr : public InheritableAttr {
4322public:
4323 enum Spelling {
4324 GNU_long_call = 0,
4325 CXX11_gnu_long_call = 1,
4326 GNU_far = 2,
4327 CXX11_gnu_far = 3
4328 };
4329
4330 static MipsLongCallAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
4331 auto *A = new (Ctx) MipsLongCallAttr(Loc, Ctx, S);
4332 A->setImplicit(true);
4333 return A;
4334 }
4335
4336 MipsLongCallAttr(SourceRange R, ASTContext &Ctx
4337 , unsigned SI
4338 )
4339 : InheritableAttr(attr::MipsLongCall, R, SI, false, false)
4340 {
4341 }
4342
4343 MipsLongCallAttr *clone(ASTContext &C) const;
4344 void printPretty(raw_ostream &OS,
4345 const PrintingPolicy &Policy) const;
4346 const char *getSpelling() const;
4347 Spelling getSemanticSpelling() const {
4348 switch (SpellingListIndex) {
4349 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 4349)
;
4350 case 0: return GNU_long_call;
4351 case 1: return CXX11_gnu_long_call;
4352 case 2: return GNU_far;
4353 case 3: return CXX11_gnu_far;
4354 }
4355 }
4356
4357
4358 static bool classof(const Attr *A) { return A->getKind() == attr::MipsLongCall; }
4359};
4360
4361class MipsShortCallAttr : public InheritableAttr {
4362public:
4363 enum Spelling {
4364 GNU_short_call = 0,
4365 CXX11_gnu_short_call = 1,
4366 GNU_near = 2,
4367 CXX11_gnu_near = 3
4368 };
4369
4370 static MipsShortCallAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
4371 auto *A = new (Ctx) MipsShortCallAttr(Loc, Ctx, S);
4372 A->setImplicit(true);
4373 return A;
4374 }
4375
4376 MipsShortCallAttr(SourceRange R, ASTContext &Ctx
4377 , unsigned SI
4378 )
4379 : InheritableAttr(attr::MipsShortCall, R, SI, false, false)
4380 {
4381 }
4382
4383 MipsShortCallAttr *clone(ASTContext &C) const;
4384 void printPretty(raw_ostream &OS,
4385 const PrintingPolicy &Policy) const;
4386 const char *getSpelling() const;
4387 Spelling getSemanticSpelling() const {
4388 switch (SpellingListIndex) {
4389 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 4389)
;
4390 case 0: return GNU_short_call;
4391 case 1: return CXX11_gnu_short_call;
4392 case 2: return GNU_near;
4393 case 3: return CXX11_gnu_near;
4394 }
4395 }
4396
4397
4398 static bool classof(const Attr *A) { return A->getKind() == attr::MipsShortCall; }
4399};
4400
4401class ModeAttr : public Attr {
4402IdentifierInfo * mode;
4403
4404public:
4405 static ModeAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Mode, SourceRange Loc = SourceRange()) {
4406 auto *A = new (Ctx) ModeAttr(Loc, Ctx, Mode, 0);
4407 A->setImplicit(true);
4408 return A;
4409 }
4410
4411 ModeAttr(SourceRange R, ASTContext &Ctx
4412 , IdentifierInfo * Mode
4413 , unsigned SI
4414 )
4415 : Attr(attr::Mode, R, SI, false)
4416 , mode(Mode)
4417 {
4418 }
4419
4420 ModeAttr *clone(ASTContext &C) const;
4421 void printPretty(raw_ostream &OS,
4422 const PrintingPolicy &Policy) const;
4423 const char *getSpelling() const;
4424 IdentifierInfo * getMode() const {
4425 return mode;
4426 }
4427
4428
4429
4430 static bool classof(const Attr *A) { return A->getKind() == attr::Mode; }
4431};
4432
4433class NSConsumedAttr : public InheritableParamAttr {
4434public:
4435 static NSConsumedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4436 auto *A = new (Ctx) NSConsumedAttr(Loc, Ctx, 0);
4437 A->setImplicit(true);
4438 return A;
4439 }
4440
4441 NSConsumedAttr(SourceRange R, ASTContext &Ctx
4442 , unsigned SI
4443 )
4444 : InheritableParamAttr(attr::NSConsumed, R, SI, false, false)
4445 {
4446 }
4447
4448 NSConsumedAttr *clone(ASTContext &C) const;
4449 void printPretty(raw_ostream &OS,
4450 const PrintingPolicy &Policy) const;
4451 const char *getSpelling() const;
4452
4453
4454 static bool classof(const Attr *A) { return A->getKind() == attr::NSConsumed; }
4455};
4456
4457class NSConsumesSelfAttr : public InheritableAttr {
4458public:
4459 static NSConsumesSelfAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4460 auto *A = new (Ctx) NSConsumesSelfAttr(Loc, Ctx, 0);
4461 A->setImplicit(true);
4462 return A;
4463 }
4464
4465 NSConsumesSelfAttr(SourceRange R, ASTContext &Ctx
4466 , unsigned SI
4467 )
4468 : InheritableAttr(attr::NSConsumesSelf, R, SI, false, false)
4469 {
4470 }
4471
4472 NSConsumesSelfAttr *clone(ASTContext &C) const;
4473 void printPretty(raw_ostream &OS,
4474 const PrintingPolicy &Policy) const;
4475 const char *getSpelling() const;
4476
4477
4478 static bool classof(const Attr *A) { return A->getKind() == attr::NSConsumesSelf; }
4479};
4480
4481class NSReturnsAutoreleasedAttr : public InheritableAttr {
4482public:
4483 static NSReturnsAutoreleasedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4484 auto *A = new (Ctx) NSReturnsAutoreleasedAttr(Loc, Ctx, 0);
4485 A->setImplicit(true);
4486 return A;
4487 }
4488
4489 NSReturnsAutoreleasedAttr(SourceRange R, ASTContext &Ctx
4490 , unsigned SI
4491 )
4492 : InheritableAttr(attr::NSReturnsAutoreleased, R, SI, false, false)
4493 {
4494 }
4495
4496 NSReturnsAutoreleasedAttr *clone(ASTContext &C) const;
4497 void printPretty(raw_ostream &OS,
4498 const PrintingPolicy &Policy) const;
4499 const char *getSpelling() const;
4500
4501
4502 static bool classof(const Attr *A) { return A->getKind() == attr::NSReturnsAutoreleased; }
4503};
4504
4505class NSReturnsNotRetainedAttr : public InheritableAttr {
4506public:
4507 static NSReturnsNotRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4508 auto *A = new (Ctx) NSReturnsNotRetainedAttr(Loc, Ctx, 0);
4509 A->setImplicit(true);
4510 return A;
4511 }
4512
4513 NSReturnsNotRetainedAttr(SourceRange R, ASTContext &Ctx
4514 , unsigned SI
4515 )
4516 : InheritableAttr(attr::NSReturnsNotRetained, R, SI, false, false)
4517 {
4518 }
4519
4520 NSReturnsNotRetainedAttr *clone(ASTContext &C) const;
4521 void printPretty(raw_ostream &OS,
4522 const PrintingPolicy &Policy) const;
4523 const char *getSpelling() const;
4524
4525
4526 static bool classof(const Attr *A) { return A->getKind() == attr::NSReturnsNotRetained; }
4527};
4528
4529class NSReturnsRetainedAttr : public InheritableAttr {
4530public:
4531 static NSReturnsRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4532 auto *A = new (Ctx) NSReturnsRetainedAttr(Loc, Ctx, 0);
4533 A->setImplicit(true);
4534 return A;
4535 }
4536
4537 NSReturnsRetainedAttr(SourceRange R, ASTContext &Ctx
4538 , unsigned SI
4539 )
4540 : InheritableAttr(attr::NSReturnsRetained, R, SI, false, false)
4541 {
4542 }
4543
4544 NSReturnsRetainedAttr *clone(ASTContext &C) const;
4545 void printPretty(raw_ostream &OS,
4546 const PrintingPolicy &Policy) const;
4547 const char *getSpelling() const;
4548
4549
4550 static bool classof(const Attr *A) { return A->getKind() == attr::NSReturnsRetained; }
4551};
4552
4553class NakedAttr : public InheritableAttr {
4554public:
4555 static NakedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4556 auto *A = new (Ctx) NakedAttr(Loc, Ctx, 0);
4557 A->setImplicit(true);
4558 return A;
4559 }
4560
4561 NakedAttr(SourceRange R, ASTContext &Ctx
4562 , unsigned SI
4563 )
4564 : InheritableAttr(attr::Naked, R, SI, false, false)
4565 {
4566 }
4567
4568 NakedAttr *clone(ASTContext &C) const;
4569 void printPretty(raw_ostream &OS,
4570 const PrintingPolicy &Policy) const;
4571 const char *getSpelling() const;
4572
4573
4574 static bool classof(const Attr *A) { return A->getKind() == attr::Naked; }
4575};
4576
4577class NoAliasAttr : public InheritableAttr {
4578public:
4579 static NoAliasAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4580 auto *A = new (Ctx) NoAliasAttr(Loc, Ctx, 0);
4581 A->setImplicit(true);
4582 return A;
4583 }
4584
4585 NoAliasAttr(SourceRange R, ASTContext &Ctx
4586 , unsigned SI
4587 )
4588 : InheritableAttr(attr::NoAlias, R, SI, false, false)
4589 {
4590 }
4591
4592 NoAliasAttr *clone(ASTContext &C) const;
4593 void printPretty(raw_ostream &OS,
4594 const PrintingPolicy &Policy) const;
4595 const char *getSpelling() const;
4596
4597
4598 static bool classof(const Attr *A) { return A->getKind() == attr::NoAlias; }
4599};
4600
4601class NoCommonAttr : public InheritableAttr {
4602public:
4603 static NoCommonAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4604 auto *A = new (Ctx) NoCommonAttr(Loc, Ctx, 0);
4605 A->setImplicit(true);
4606 return A;
4607 }
4608
4609 NoCommonAttr(SourceRange R, ASTContext &Ctx
4610 , unsigned SI
4611 )
4612 : InheritableAttr(attr::NoCommon, R, SI, false, false)
4613 {
4614 }
4615
4616 NoCommonAttr *clone(ASTContext &C) const;
4617 void printPretty(raw_ostream &OS,
4618 const PrintingPolicy &Policy) const;
4619 const char *getSpelling() const;
4620
4621
4622 static bool classof(const Attr *A) { return A->getKind() == attr::NoCommon; }
4623};
4624
4625class NoDebugAttr : public InheritableAttr {
4626public:
4627 static NoDebugAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4628 auto *A = new (Ctx) NoDebugAttr(Loc, Ctx, 0);
4629 A->setImplicit(true);
4630 return A;
4631 }
4632
4633 NoDebugAttr(SourceRange R, ASTContext &Ctx
4634 , unsigned SI
4635 )
4636 : InheritableAttr(attr::NoDebug, R, SI, false, false)
4637 {
4638 }
4639
4640 NoDebugAttr *clone(ASTContext &C) const;
4641 void printPretty(raw_ostream &OS,
4642 const PrintingPolicy &Policy) const;
4643 const char *getSpelling() const;
4644
4645
4646 static bool classof(const Attr *A) { return A->getKind() == attr::NoDebug; }
4647};
4648
4649class NoDuplicateAttr : public InheritableAttr {
4650public:
4651 static NoDuplicateAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4652 auto *A = new (Ctx) NoDuplicateAttr(Loc, Ctx, 0);
4653 A->setImplicit(true);
4654 return A;
4655 }
4656
4657 NoDuplicateAttr(SourceRange R, ASTContext &Ctx
4658 , unsigned SI
4659 )
4660 : InheritableAttr(attr::NoDuplicate, R, SI, false, false)
4661 {
4662 }
4663
4664 NoDuplicateAttr *clone(ASTContext &C) const;
4665 void printPretty(raw_ostream &OS,
4666 const PrintingPolicy &Policy) const;
4667 const char *getSpelling() const;
4668
4669
4670 static bool classof(const Attr *A) { return A->getKind() == attr::NoDuplicate; }
4671};
4672
4673class NoEscapeAttr : public Attr {
4674public:
4675 static NoEscapeAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4676 auto *A = new (Ctx) NoEscapeAttr(Loc, Ctx, 0);
4677 A->setImplicit(true);
4678 return A;
4679 }
4680
4681 NoEscapeAttr(SourceRange R, ASTContext &Ctx
4682 , unsigned SI
4683 )
4684 : Attr(attr::NoEscape, R, SI, false)
4685 {
4686 }
4687
4688 NoEscapeAttr *clone(ASTContext &C) const;
4689 void printPretty(raw_ostream &OS,
4690 const PrintingPolicy &Policy) const;
4691 const char *getSpelling() const;
4692
4693
4694 static bool classof(const Attr *A) { return A->getKind() == attr::NoEscape; }
4695};
4696
4697class NoInlineAttr : public InheritableAttr {
4698public:
4699 static NoInlineAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4700 auto *A = new (Ctx) NoInlineAttr(Loc, Ctx, 0);
4701 A->setImplicit(true);
4702 return A;
4703 }
4704
4705 NoInlineAttr(SourceRange R, ASTContext &Ctx
4706 , unsigned SI
4707 )
4708 : InheritableAttr(attr::NoInline, R, SI, false, false)
4709 {
4710 }
4711
4712 NoInlineAttr *clone(ASTContext &C) const;
4713 void printPretty(raw_ostream &OS,
4714 const PrintingPolicy &Policy) const;
4715 const char *getSpelling() const;
4716
4717
4718 static bool classof(const Attr *A) { return A->getKind() == attr::NoInline; }
4719};
4720
4721class NoInstrumentFunctionAttr : public InheritableAttr {
4722public:
4723 static NoInstrumentFunctionAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4724 auto *A = new (Ctx) NoInstrumentFunctionAttr(Loc, Ctx, 0);
4725 A->setImplicit(true);
4726 return A;
4727 }
4728
4729 NoInstrumentFunctionAttr(SourceRange R, ASTContext &Ctx
4730 , unsigned SI
4731 )
4732 : InheritableAttr(attr::NoInstrumentFunction, R, SI, false, false)
4733 {
4734 }
4735
4736 NoInstrumentFunctionAttr *clone(ASTContext &C) const;
4737 void printPretty(raw_ostream &OS,
4738 const PrintingPolicy &Policy) const;
4739 const char *getSpelling() const;
4740
4741
4742 static bool classof(const Attr *A) { return A->getKind() == attr::NoInstrumentFunction; }
4743};
4744
4745class NoMicroMipsAttr : public InheritableAttr {
4746public:
4747 static NoMicroMipsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4748 auto *A = new (Ctx) NoMicroMipsAttr(Loc, Ctx, 0);
4749 A->setImplicit(true);
4750 return A;
4751 }
4752
4753 NoMicroMipsAttr(SourceRange R, ASTContext &Ctx
4754 , unsigned SI
4755 )
4756 : InheritableAttr(attr::NoMicroMips, R, SI, false, false)
4757 {
4758 }
4759
4760 NoMicroMipsAttr *clone(ASTContext &C) const;
4761 void printPretty(raw_ostream &OS,
4762 const PrintingPolicy &Policy) const;
4763 const char *getSpelling() const;
4764
4765
4766 static bool classof(const Attr *A) { return A->getKind() == attr::NoMicroMips; }
4767};
4768
4769class NoMips16Attr : public InheritableAttr {
4770public:
4771 static NoMips16Attr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4772 auto *A = new (Ctx) NoMips16Attr(Loc, Ctx, 0);
4773 A->setImplicit(true);
4774 return A;
4775 }
4776
4777 NoMips16Attr(SourceRange R, ASTContext &Ctx
4778 , unsigned SI
4779 )
4780 : InheritableAttr(attr::NoMips16, R, SI, false, false)
4781 {
4782 }
4783
4784 NoMips16Attr *clone(ASTContext &C) const;
4785 void printPretty(raw_ostream &OS,
4786 const PrintingPolicy &Policy) const;
4787 const char *getSpelling() const;
4788
4789
4790 static bool classof(const Attr *A) { return A->getKind() == attr::NoMips16; }
4791};
4792
4793class NoReturnAttr : public InheritableAttr {
4794public:
4795 static NoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4796 auto *A = new (Ctx) NoReturnAttr(Loc, Ctx, 0);
4797 A->setImplicit(true);
4798 return A;
4799 }
4800
4801 NoReturnAttr(SourceRange R, ASTContext &Ctx
4802 , unsigned SI
4803 )
4804 : InheritableAttr(attr::NoReturn, R, SI, false, false)
4805 {
4806 }
4807
4808 NoReturnAttr *clone(ASTContext &C) const;
4809 void printPretty(raw_ostream &OS,
4810 const PrintingPolicy &Policy) const;
4811 const char *getSpelling() const;
4812
4813
4814 static bool classof(const Attr *A) { return A->getKind() == attr::NoReturn; }
4815};
4816
4817class NoSanitizeAttr : public InheritableAttr {
4818 unsigned sanitizers_Size;
4819 StringRef *sanitizers_;
4820
4821public:
4822 static NoSanitizeAttr *CreateImplicit(ASTContext &Ctx, StringRef *Sanitizers, unsigned SanitizersSize, SourceRange Loc = SourceRange()) {
4823 auto *A = new (Ctx) NoSanitizeAttr(Loc, Ctx, Sanitizers, SanitizersSize, 0);
4824 A->setImplicit(true);
4825 return A;
4826 }
4827
4828 NoSanitizeAttr(SourceRange R, ASTContext &Ctx
4829 , StringRef *Sanitizers, unsigned SanitizersSize
4830 , unsigned SI
4831 )
4832 : InheritableAttr(attr::NoSanitize, R, SI, false, false)
4833 , sanitizers_Size(SanitizersSize), sanitizers_(new (Ctx, 16) StringRef[sanitizers_Size])
4834 {
4835 for (size_t I = 0, E = sanitizers_Size; I != E;
4836 ++I) {
4837 StringRef Ref = Sanitizers[I];
4838 if (!Ref.empty()) {
4839 char *Mem = new (Ctx, 1) char[Ref.size()];
4840 std::memcpy(Mem, Ref.data(), Ref.size());
4841 sanitizers_[I] = StringRef(Mem, Ref.size());
4842 }
4843 }
4844 }
4845
4846 NoSanitizeAttr(SourceRange R, ASTContext &Ctx
4847 , unsigned SI
4848 )
4849 : InheritableAttr(attr::NoSanitize, R, SI, false, false)
4850 , sanitizers_Size(0), sanitizers_(nullptr)
4851 {
4852 }
4853
4854 NoSanitizeAttr *clone(ASTContext &C) const;
4855 void printPretty(raw_ostream &OS,
4856 const PrintingPolicy &Policy) const;
4857 const char *getSpelling() const;
4858 typedef StringRef* sanitizers_iterator;
4859 sanitizers_iterator sanitizers_begin() const { return sanitizers_; }
4860 sanitizers_iterator sanitizers_end() const { return sanitizers_ + sanitizers_Size; }
4861 unsigned sanitizers_size() const { return sanitizers_Size; }
4862 llvm::iterator_range<sanitizers_iterator> sanitizers() const { return llvm::make_range(sanitizers_begin(), sanitizers_end()); }
4863
4864
4865
4866 SanitizerMask getMask() const {
4867 SanitizerMask Mask = 0;
4868 for (auto SanitizerName : sanitizers()) {
4869 SanitizerMask ParsedMask =
4870 parseSanitizerValue(SanitizerName, /*AllowGroups=*/true);
4871 Mask |= expandSanitizerGroups(ParsedMask);
4872 }
4873 return Mask;
4874 }
4875
4876
4877 static bool classof(const Attr *A) { return A->getKind() == attr::NoSanitize; }
4878};
4879
4880class NoSplitStackAttr : public InheritableAttr {
4881public:
4882 static NoSplitStackAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4883 auto *A = new (Ctx) NoSplitStackAttr(Loc, Ctx, 0);
4884 A->setImplicit(true);
4885 return A;
4886 }
4887
4888 NoSplitStackAttr(SourceRange R, ASTContext &Ctx
4889 , unsigned SI
4890 )
4891 : InheritableAttr(attr::NoSplitStack, R, SI, false, false)
4892 {
4893 }
4894
4895 NoSplitStackAttr *clone(ASTContext &C) const;
4896 void printPretty(raw_ostream &OS,
4897 const PrintingPolicy &Policy) const;
4898 const char *getSpelling() const;
4899
4900
4901 static bool classof(const Attr *A) { return A->getKind() == attr::NoSplitStack; }
4902};
4903
4904class NoThreadSafetyAnalysisAttr : public InheritableAttr {
4905public:
4906 static NoThreadSafetyAnalysisAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4907 auto *A = new (Ctx) NoThreadSafetyAnalysisAttr(Loc, Ctx, 0);
4908 A->setImplicit(true);
4909 return A;
4910 }
4911
4912 NoThreadSafetyAnalysisAttr(SourceRange R, ASTContext &Ctx
4913 , unsigned SI
4914 )
4915 : InheritableAttr(attr::NoThreadSafetyAnalysis, R, SI, false, false)
4916 {
4917 }
4918
4919 NoThreadSafetyAnalysisAttr *clone(ASTContext &C) const;
4920 void printPretty(raw_ostream &OS,
4921 const PrintingPolicy &Policy) const;
4922 const char *getSpelling() const;
4923
4924
4925 static bool classof(const Attr *A) { return A->getKind() == attr::NoThreadSafetyAnalysis; }
4926};
4927
4928class NoThrowAttr : public InheritableAttr {
4929public:
4930 static NoThrowAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4931 auto *A = new (Ctx) NoThrowAttr(Loc, Ctx, 0);
4932 A->setImplicit(true);
4933 return A;
4934 }
4935
4936 NoThrowAttr(SourceRange R, ASTContext &Ctx
4937 , unsigned SI
4938 )
4939 : InheritableAttr(attr::NoThrow, R, SI, false, false)
4940 {
4941 }
4942
4943 NoThrowAttr *clone(ASTContext &C) const;
4944 void printPretty(raw_ostream &OS,
4945 const PrintingPolicy &Policy) const;
4946 const char *getSpelling() const;
4947
4948
4949 static bool classof(const Attr *A) { return A->getKind() == attr::NoThrow; }
4950};
4951
4952class NonNullAttr : public InheritableParamAttr {
4953 unsigned args_Size;
4954 ParamIdx *args_;
4955
4956public:
4957 static NonNullAttr *CreateImplicit(ASTContext &Ctx, ParamIdx *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
4958 auto *A = new (Ctx) NonNullAttr(Loc, Ctx, Args, ArgsSize, 0);
4959 A->setImplicit(true);
4960 return A;
4961 }
4962
4963 NonNullAttr(SourceRange R, ASTContext &Ctx
4964 , ParamIdx *Args, unsigned ArgsSize
4965 , unsigned SI
4966 )
4967 : InheritableParamAttr(attr::NonNull, R, SI, false, true)
4968 , args_Size(ArgsSize), args_(new (Ctx, 16) ParamIdx[args_Size])
4969 {
4970 std::copy(Args, Args + args_Size, args_);
4971 }
4972
4973 NonNullAttr(SourceRange R, ASTContext &Ctx
4974 , unsigned SI
4975 )
4976 : InheritableParamAttr(attr::NonNull, R, SI, false, true)
4977 , args_Size(0), args_(nullptr)
4978 {
4979 }
4980
4981 NonNullAttr *clone(ASTContext &C) const;
4982 void printPretty(raw_ostream &OS,
4983 const PrintingPolicy &Policy) const;
4984 const char *getSpelling() const;
4985 typedef ParamIdx* args_iterator;
4986 args_iterator args_begin() const { return args_; }
4987 args_iterator args_end() const { return args_ + args_Size; }
4988 unsigned args_size() const { return args_Size; }
4989 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
4990
4991
4992
4993 bool isNonNull(unsigned IdxAST) const {
4994 if (!args_size())
4995 return true;
4996 return args_end() != std::find_if(
4997 args_begin(), args_end(),
4998 [=](const ParamIdx &Idx) { return Idx.getASTIndex() == IdxAST; });
4999 }
5000
5001
5002 static bool classof(const Attr *A) { return A->getKind() == attr::NonNull; }
5003};
5004
5005class NotTailCalledAttr : public InheritableAttr {
5006public:
5007 static NotTailCalledAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5008 auto *A = new (Ctx) NotTailCalledAttr(Loc, Ctx, 0);
5009 A->setImplicit(true);
5010 return A;
5011 }
5012
5013 NotTailCalledAttr(SourceRange R, ASTContext &Ctx
5014 , unsigned SI
5015 )
5016 : InheritableAttr(attr::NotTailCalled, R, SI, false, false)
5017 {
5018 }
5019
5020 NotTailCalledAttr *clone(ASTContext &C) const;
5021 void printPretty(raw_ostream &OS,
5022 const PrintingPolicy &Policy) const;
5023 const char *getSpelling() const;
5024
5025
5026 static bool classof(const Attr *A) { return A->getKind() == attr::NotTailCalled; }
5027};
5028
5029class OMPCaptureKindAttr : public Attr {
5030unsigned captureKind;
5031
5032public:
5033 static OMPCaptureKindAttr *CreateImplicit(ASTContext &Ctx, unsigned CaptureKind, SourceRange Loc = SourceRange()) {
5034 auto *A = new (Ctx) OMPCaptureKindAttr(Loc, Ctx, CaptureKind, 0);
5035 A->setImplicit(true);
5036 return A;
5037 }
5038
5039 OMPCaptureKindAttr(SourceRange R, ASTContext &Ctx
5040 , unsigned CaptureKind
5041 , unsigned SI
5042 )
5043 : Attr(attr::OMPCaptureKind, R, SI, false)
5044 , captureKind(CaptureKind)
5045 {
5046 }
5047
5048 OMPCaptureKindAttr *clone(ASTContext &C) const;
5049 void printPretty(raw_ostream &OS,
5050 const PrintingPolicy &Policy) const;
5051 const char *getSpelling() const;
5052 unsigned getCaptureKind() const {
5053 return captureKind;
5054 }
5055
5056
5057
5058 static bool classof(const Attr *A) { return A->getKind() == attr::OMPCaptureKind; }
5059};
5060
5061class OMPCaptureNoInitAttr : public InheritableAttr {
5062public:
5063 static OMPCaptureNoInitAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5064 auto *A = new (Ctx) OMPCaptureNoInitAttr(Loc, Ctx, 0);
5065 A->setImplicit(true);
5066 return A;
5067 }
5068
5069 OMPCaptureNoInitAttr(SourceRange R, ASTContext &Ctx
5070 , unsigned SI
5071 )
5072 : InheritableAttr(attr::OMPCaptureNoInit, R, SI, false, false)
5073 {
5074 }
5075
5076 OMPCaptureNoInitAttr *clone(ASTContext &C) const;
5077 void printPretty(raw_ostream &OS,
5078 const PrintingPolicy &Policy) const;
5079 const char *getSpelling() const;
5080
5081
5082 static bool classof(const Attr *A) { return A->getKind() == attr::OMPCaptureNoInit; }
5083};
5084
5085class OMPDeclareSimdDeclAttr : public Attr {
5086public:
5087 enum BranchStateTy {
5088 BS_Undefined,
5089 BS_Inbranch,
5090 BS_Notinbranch
5091 };
5092private:
5093 BranchStateTy branchState;
5094
5095Expr * simdlen;
5096
5097 unsigned uniforms_Size;
5098 Expr * *uniforms_;
5099
5100 unsigned aligneds_Size;
5101 Expr * *aligneds_;
5102
5103 unsigned alignments_Size;
5104 Expr * *alignments_;
5105
5106 unsigned linears_Size;
5107 Expr * *linears_;
5108
5109 unsigned modifiers_Size;
5110 unsigned *modifiers_;
5111
5112 unsigned steps_Size;
5113 Expr * *steps_;
5114
5115public:
5116 static OMPDeclareSimdDeclAttr *CreateImplicit(ASTContext &Ctx, BranchStateTy BranchState, Expr * Simdlen, Expr * *Uniforms, unsigned UniformsSize, Expr * *Aligneds, unsigned AlignedsSize, Expr * *Alignments, unsigned AlignmentsSize, Expr * *Linears, unsigned LinearsSize, unsigned *Modifiers, unsigned ModifiersSize, Expr * *Steps, unsigned StepsSize, SourceRange Loc = SourceRange()) {
5117 auto *A = new (Ctx) OMPDeclareSimdDeclAttr(Loc, Ctx, BranchState, Simdlen, Uniforms, UniformsSize, Aligneds, AlignedsSize, Alignments, AlignmentsSize, Linears, LinearsSize, Modifiers, ModifiersSize, Steps, StepsSize, 0);
5118 A->setImplicit(true);
5119 return A;
5120 }
5121
5122 OMPDeclareSimdDeclAttr(SourceRange R, ASTContext &Ctx
5123 , BranchStateTy BranchState
5124 , Expr * Simdlen
5125 , Expr * *Uniforms, unsigned UniformsSize
5126 , Expr * *Aligneds, unsigned AlignedsSize
5127 , Expr * *Alignments, unsigned AlignmentsSize
5128 , Expr * *Linears, unsigned LinearsSize
5129 , unsigned *Modifiers, unsigned ModifiersSize
5130 , Expr * *Steps, unsigned StepsSize
5131 , unsigned SI
5132 )
5133 : Attr(attr::OMPDeclareSimdDecl, R, SI, false)
5134 , branchState(BranchState)
5135 , simdlen(Simdlen)
5136 , uniforms_Size(UniformsSize), uniforms_(new (Ctx, 16) Expr *[uniforms_Size])
5137 , aligneds_Size(AlignedsSize), aligneds_(new (Ctx, 16) Expr *[aligneds_Size])
5138 , alignments_Size(AlignmentsSize), alignments_(new (Ctx, 16) Expr *[alignments_Size])
5139 , linears_Size(LinearsSize), linears_(new (Ctx, 16) Expr *[linears_Size])
5140 , modifiers_Size(ModifiersSize), modifiers_(new (Ctx, 16) unsigned[modifiers_Size])
5141 , steps_Size(StepsSize), steps_(new (Ctx, 16) Expr *[steps_Size])
5142 {
5143 std::copy(Uniforms, Uniforms + uniforms_Size, uniforms_);
5144 std::copy(Aligneds, Aligneds + aligneds_Size, aligneds_);
5145 std::copy(Alignments, Alignments + alignments_Size, alignments_);
5146 std::copy(Linears, Linears + linears_Size, linears_);
5147 std::copy(Modifiers, Modifiers + modifiers_Size, modifiers_);
5148 std::copy(Steps, Steps + steps_Size, steps_);
5149 }
5150
5151 OMPDeclareSimdDeclAttr(SourceRange R, ASTContext &Ctx
5152 , BranchStateTy BranchState
5153 , Expr * Simdlen
5154 , unsigned SI
5155 )
5156 : Attr(attr::OMPDeclareSimdDecl, R, SI, false)
5157 , branchState(BranchState)
5158 , simdlen(Simdlen)
5159 , uniforms_Size(0), uniforms_(nullptr)
5160 , aligneds_Size(0), aligneds_(nullptr)
5161 , alignments_Size(0), alignments_(nullptr)
5162 , linears_Size(0), linears_(nullptr)
5163 , modifiers_Size(0), modifiers_(nullptr)
5164 , steps_Size(0), steps_(nullptr)
5165 {
5166 }
5167
5168 OMPDeclareSimdDeclAttr *clone(ASTContext &C) const;
5169 void printPretty(raw_ostream &OS,
5170 const PrintingPolicy &Policy) const;
5171 const char *getSpelling() const;
5172 BranchStateTy getBranchState() const {
5173 return branchState;
5174 }
5175
5176 static bool ConvertStrToBranchStateTy(StringRef Val, BranchStateTy &Out) {
5177 Optional<BranchStateTy> R = llvm::StringSwitch<Optional<BranchStateTy>>(Val)
5178 .Case("", OMPDeclareSimdDeclAttr::BS_Undefined)
5179 .Case("inbranch", OMPDeclareSimdDeclAttr::BS_Inbranch)
5180 .Case("notinbranch", OMPDeclareSimdDeclAttr::BS_Notinbranch)
5181 .Default(Optional<BranchStateTy>());
5182 if (R) {
5183 Out = *R;
5184 return true;
5185 }
5186 return false;
5187 }
5188
5189 static const char *ConvertBranchStateTyToStr(BranchStateTy Val) {
5190 switch(Val) {
5191 case OMPDeclareSimdDeclAttr::BS_Undefined: return "";
5192 case OMPDeclareSimdDeclAttr::BS_Inbranch: return "inbranch";
5193 case OMPDeclareSimdDeclAttr::BS_Notinbranch: return "notinbranch";
5194 }
5195 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 5195)
;
5196 }
5197 Expr * getSimdlen() const {
5198 return simdlen;
5199 }
5200
5201 typedef Expr ** uniforms_iterator;
5202 uniforms_iterator uniforms_begin() const { return uniforms_; }
5203 uniforms_iterator uniforms_end() const { return uniforms_ + uniforms_Size; }
5204 unsigned uniforms_size() const { return uniforms_Size; }
5205 llvm::iterator_range<uniforms_iterator> uniforms() const { return llvm::make_range(uniforms_begin(), uniforms_end()); }
5206
5207
5208 typedef Expr ** aligneds_iterator;
5209 aligneds_iterator aligneds_begin() const { return aligneds_; }
5210 aligneds_iterator aligneds_end() const { return aligneds_ + aligneds_Size; }
5211 unsigned aligneds_size() const { return aligneds_Size; }
5212 llvm::iterator_range<aligneds_iterator> aligneds() const { return llvm::make_range(aligneds_begin(), aligneds_end()); }
5213
5214
5215 typedef Expr ** alignments_iterator;
5216 alignments_iterator alignments_begin() const { return alignments_; }
5217 alignments_iterator alignments_end() const { return alignments_ + alignments_Size; }
5218 unsigned alignments_size() const { return alignments_Size; }
5219 llvm::iterator_range<alignments_iterator> alignments() const { return llvm::make_range(alignments_begin(), alignments_end()); }
5220
5221
5222 typedef Expr ** linears_iterator;
5223 linears_iterator linears_begin() const { return linears_; }
5224 linears_iterator linears_end() const { return linears_ + linears_Size; }
5225 unsigned linears_size() const { return linears_Size; }
5226 llvm::iterator_range<linears_iterator> linears() const { return llvm::make_range(linears_begin(), linears_end()); }
5227
5228
5229 typedef unsigned* modifiers_iterator;
5230 modifiers_iterator modifiers_begin() const { return modifiers_; }
5231 modifiers_iterator modifiers_end() const { return modifiers_ + modifiers_Size; }
5232 unsigned modifiers_size() const { return modifiers_Size; }
5233 llvm::iterator_range<modifiers_iterator> modifiers() const { return llvm::make_range(modifiers_begin(), modifiers_end()); }
5234
5235
5236 typedef Expr ** steps_iterator;
5237 steps_iterator steps_begin() const { return steps_; }
5238 steps_iterator steps_end() const { return steps_ + steps_Size; }
5239 unsigned steps_size() const { return steps_Size; }
5240 llvm::iterator_range<steps_iterator> steps() const { return llvm::make_range(steps_begin(), steps_end()); }
5241
5242
5243
5244 void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy)
5245 const {
5246 if (getBranchState() != BS_Undefined)
5247 OS << ' ' << ConvertBranchStateTyToStr(getBranchState());
5248 if (auto *E = getSimdlen()) {
5249 OS << " simdlen(";
5250 E->printPretty(OS, nullptr, Policy);
5251 OS << ")";
5252 }
5253 if (uniforms_size() > 0) {
5254 OS << " uniform";
5255 StringRef Sep = "(";
5256 for (auto *E : uniforms()) {
5257 OS << Sep;
5258 E->printPretty(OS, nullptr, Policy);
5259 Sep = ", ";
5260 }
5261 OS << ")";
5262 }
5263 alignments_iterator NI = alignments_begin();
5264 for (auto *E : aligneds()) {
5265 OS << " aligned(";
5266 E->printPretty(OS, nullptr, Policy);
5267 if (*NI) {
5268 OS << ": ";
5269 (*NI)->printPretty(OS, nullptr, Policy);
5270 }
5271 OS << ")";
5272 ++NI;
5273 }
5274 steps_iterator I = steps_begin();
5275 modifiers_iterator MI = modifiers_begin();
5276 for (auto *E : linears()) {
5277 OS << " linear(";
5278 if (*MI != OMPC_LINEAR_unknown)
5279 OS << getOpenMPSimpleClauseTypeName(OMPC_linear, *MI) << "(";
5280 E->printPretty(OS, nullptr, Policy);
5281 if (*MI != OMPC_LINEAR_unknown)
5282 OS << ")";
5283 if (*I) {
5284 OS << ": ";
5285 (*I)->printPretty(OS, nullptr, Policy);
5286 }
5287 OS << ")";
5288 ++I;
5289 ++MI;
5290 }
5291 }
5292
5293
5294 static bool classof(const Attr *A) { return A->getKind() == attr::OMPDeclareSimdDecl; }
5295};
5296
5297class OMPDeclareTargetDeclAttr : public Attr {
5298public:
5299 enum MapTypeTy {
5300 MT_To,
5301 MT_Link
5302 };
5303private:
5304 MapTypeTy mapType;
5305
5306public:
5307 static OMPDeclareTargetDeclAttr *CreateImplicit(ASTContext &Ctx, MapTypeTy MapType, SourceRange Loc = SourceRange()) {
5308 auto *A = new (Ctx) OMPDeclareTargetDeclAttr(Loc, Ctx, MapType, 0);
5309 A->setImplicit(true);
5310 return A;
5311 }
5312
5313 OMPDeclareTargetDeclAttr(SourceRange R, ASTContext &Ctx
5314 , MapTypeTy MapType
5315 , unsigned SI
5316 )
5317 : Attr(attr::OMPDeclareTargetDecl, R, SI, false)
5318 , mapType(MapType)
5319 {
5320 }
5321
5322 OMPDeclareTargetDeclAttr *clone(ASTContext &C) const;
5323 void printPretty(raw_ostream &OS,
5324 const PrintingPolicy &Policy) const;
5325 const char *getSpelling() const;
5326 MapTypeTy getMapType() const {
5327 return mapType;
5328 }
5329
5330 static bool ConvertStrToMapTypeTy(StringRef Val, MapTypeTy &Out) {
5331 Optional<MapTypeTy> R = llvm::StringSwitch<Optional<MapTypeTy>>(Val)
5332 .Case("to", OMPDeclareTargetDeclAttr::MT_To)
5333 .Case("link", OMPDeclareTargetDeclAttr::MT_Link)
5334 .Default(Optional<MapTypeTy>());
5335 if (R) {
5336 Out = *R;
5337 return true;
5338 }
5339 return false;
5340 }
5341
5342 static const char *ConvertMapTypeTyToStr(MapTypeTy Val) {
5343 switch(Val) {
5344 case OMPDeclareTargetDeclAttr::MT_To: return "to";
5345 case OMPDeclareTargetDeclAttr::MT_Link: return "link";
5346 }
5347 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 5347)
;
5348 }
5349
5350 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
5351 // Use fake syntax because it is for testing and debugging purpose only.
5352 if (getMapType() != MT_To)
5353 OS << ' ' << ConvertMapTypeTyToStr(getMapType());
5354 }
5355
5356
5357 static bool classof(const Attr *A) { return A->getKind() == attr::OMPDeclareTargetDecl; }
5358};
5359
5360class OMPReferencedVarAttr : public Attr {
5361Expr * ref;
5362
5363public:
5364 static OMPReferencedVarAttr *CreateImplicit(ASTContext &Ctx, Expr * Ref, SourceRange Loc = SourceRange()) {
5365 auto *A = new (Ctx) OMPReferencedVarAttr(Loc, Ctx, Ref, 0);
5366 A->setImplicit(true);
5367 return A;
5368 }
5369
5370 OMPReferencedVarAttr(SourceRange R, ASTContext &Ctx
5371 , Expr * Ref
5372 , unsigned SI
5373 )
5374 : Attr(attr::OMPReferencedVar, R, SI, false)
5375 , ref(Ref)
5376 {
5377 }
5378
5379 OMPReferencedVarAttr *clone(ASTContext &C) const;
5380 void printPretty(raw_ostream &OS,
5381 const PrintingPolicy &Policy) const;
5382 const char *getSpelling() const;
5383 Expr * getRef() const {
5384 return ref;
5385 }
5386
5387
5388
5389 static bool classof(const Attr *A) { return A->getKind() == attr::OMPReferencedVar; }
5390};
5391
5392class OMPThreadPrivateDeclAttr : public InheritableAttr {
5393public:
5394 static OMPThreadPrivateDeclAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5395 auto *A = new (Ctx) OMPThreadPrivateDeclAttr(Loc, Ctx, 0);
5396 A->setImplicit(true);
5397 return A;
5398 }
5399
5400 OMPThreadPrivateDeclAttr(SourceRange R, ASTContext &Ctx
5401 , unsigned SI
5402 )
5403 : InheritableAttr(attr::OMPThreadPrivateDecl, R, SI, false, false)
5404 {
5405 }
5406
5407 OMPThreadPrivateDeclAttr *clone(ASTContext &C) const;
5408 void printPretty(raw_ostream &OS,
5409 const PrintingPolicy &Policy) const;
5410 const char *getSpelling() const;
5411
5412
5413 static bool classof(const Attr *A) { return A->getKind() == attr::OMPThreadPrivateDecl; }
5414};
5415
5416class ObjCBoxableAttr : public Attr {
5417public:
5418 static ObjCBoxableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5419 auto *A = new (Ctx) ObjCBoxableAttr(Loc, Ctx, 0);
5420 A->setImplicit(true);
5421 return A;
5422 }
5423
5424 ObjCBoxableAttr(SourceRange R, ASTContext &Ctx
5425 , unsigned SI
5426 )
5427 : Attr(attr::ObjCBoxable, R, SI, false)
5428 {
5429 }
5430
5431 ObjCBoxableAttr *clone(ASTContext &C) const;
5432 void printPretty(raw_ostream &OS,
5433 const PrintingPolicy &Policy) const;
5434 const char *getSpelling() const;
5435
5436
5437 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCBoxable; }
5438};
5439
5440class ObjCBridgeAttr : public InheritableAttr {
5441IdentifierInfo * bridgedType;
5442
5443public:
5444 static ObjCBridgeAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * BridgedType, SourceRange Loc = SourceRange()) {
5445 auto *A = new (Ctx) ObjCBridgeAttr(Loc, Ctx, BridgedType, 0);
5446 A->setImplicit(true);
5447 return A;
5448 }
5449
5450 ObjCBridgeAttr(SourceRange R, ASTContext &Ctx
5451 , IdentifierInfo * BridgedType
5452 , unsigned SI
5453 )
5454 : InheritableAttr(attr::ObjCBridge, R, SI, false, false)
5455 , bridgedType(BridgedType)
5456 {
5457 }
5458
5459 ObjCBridgeAttr *clone(ASTContext &C) const;
5460 void printPretty(raw_ostream &OS,
5461 const PrintingPolicy &Policy) const;
5462 const char *getSpelling() const;
5463 IdentifierInfo * getBridgedType() const {
5464 return bridgedType;
5465 }
5466
5467
5468
5469 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCBridge; }
5470};
5471
5472class ObjCBridgeMutableAttr : public InheritableAttr {
5473IdentifierInfo * bridgedType;
5474
5475public:
5476 static ObjCBridgeMutableAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * BridgedType, SourceRange Loc = SourceRange()) {
5477 auto *A = new (Ctx) ObjCBridgeMutableAttr(Loc, Ctx, BridgedType, 0);
5478 A->setImplicit(true);
5479 return A;
5480 }
5481
5482 ObjCBridgeMutableAttr(SourceRange R, ASTContext &Ctx
5483 , IdentifierInfo * BridgedType
5484 , unsigned SI
5485 )
5486 : InheritableAttr(attr::ObjCBridgeMutable, R, SI, false, false)
5487 , bridgedType(BridgedType)
5488 {
5489 }
5490
5491 ObjCBridgeMutableAttr *clone(ASTContext &C) const;
5492 void printPretty(raw_ostream &OS,
5493 const PrintingPolicy &Policy) const;
5494 const char *getSpelling() const;
5495 IdentifierInfo * getBridgedType() const {
5496 return bridgedType;
5497 }
5498
5499
5500
5501 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCBridgeMutable; }
5502};
5503
5504class ObjCBridgeRelatedAttr : public InheritableAttr {
5505IdentifierInfo * relatedClass;
5506
5507IdentifierInfo * classMethod;
5508
5509IdentifierInfo * instanceMethod;
5510
5511public:
5512 static ObjCBridgeRelatedAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * RelatedClass, IdentifierInfo * ClassMethod, IdentifierInfo * InstanceMethod, SourceRange Loc = SourceRange()) {
5513 auto *A = new (Ctx) ObjCBridgeRelatedAttr(Loc, Ctx, RelatedClass, ClassMethod, InstanceMethod, 0);
5514 A->setImplicit(true);
5515 return A;
5516 }
5517
5518 ObjCBridgeRelatedAttr(SourceRange R, ASTContext &Ctx
5519 , IdentifierInfo * RelatedClass
5520 , IdentifierInfo * ClassMethod
5521 , IdentifierInfo * InstanceMethod
5522 , unsigned SI
5523 )
5524 : InheritableAttr(attr::ObjCBridgeRelated, R, SI, false, false)
5525 , relatedClass(RelatedClass)
5526 , classMethod(ClassMethod)
5527 , instanceMethod(InstanceMethod)
5528 {
5529 }
5530
5531 ObjCBridgeRelatedAttr *clone(ASTContext &C) const;
5532 void printPretty(raw_ostream &OS,
5533 const PrintingPolicy &Policy) const;
5534 const char *getSpelling() const;
5535 IdentifierInfo * getRelatedClass() const {
5536 return relatedClass;
5537 }
5538
5539 IdentifierInfo * getClassMethod() const {
5540 return classMethod;
5541 }
5542
5543 IdentifierInfo * getInstanceMethod() const {
5544 return instanceMethod;
5545 }
5546
5547
5548
5549 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCBridgeRelated; }
5550};
5551
5552class ObjCDesignatedInitializerAttr : public Attr {
5553public:
5554 static ObjCDesignatedInitializerAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5555 auto *A = new (Ctx) ObjCDesignatedInitializerAttr(Loc, Ctx, 0);
5556 A->setImplicit(true);
5557 return A;
5558 }
5559
5560 ObjCDesignatedInitializerAttr(SourceRange R, ASTContext &Ctx
5561 , unsigned SI
5562 )
5563 : Attr(attr::ObjCDesignatedInitializer, R, SI, false)
5564 {
5565 }
5566
5567 ObjCDesignatedInitializerAttr *clone(ASTContext &C) const;
5568 void printPretty(raw_ostream &OS,
5569 const PrintingPolicy &Policy) const;
5570 const char *getSpelling() const;
5571
5572
5573 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCDesignatedInitializer; }
5574};
5575
5576class ObjCExceptionAttr : public InheritableAttr {
5577public:
5578 static ObjCExceptionAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5579 auto *A = new (Ctx) ObjCExceptionAttr(Loc, Ctx, 0);
5580 A->setImplicit(true);
5581 return A;
5582 }
5583
5584 ObjCExceptionAttr(SourceRange R, ASTContext &Ctx
5585 , unsigned SI
5586 )
5587 : InheritableAttr(attr::ObjCException, R, SI, false, false)
5588 {
5589 }
5590
5591 ObjCExceptionAttr *clone(ASTContext &C) const;
5592 void printPretty(raw_ostream &OS,
5593 const PrintingPolicy &Policy) const;
5594 const char *getSpelling() const;
5595
5596
5597 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCException; }
5598};
5599
5600class ObjCExplicitProtocolImplAttr : public InheritableAttr {
5601public:
5602 static ObjCExplicitProtocolImplAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5603 auto *A = new (Ctx) ObjCExplicitProtocolImplAttr(Loc, Ctx, 0);
5604 A->setImplicit(true);
5605 return A;
5606 }
5607
5608 ObjCExplicitProtocolImplAttr(SourceRange R, ASTContext &Ctx
5609 , unsigned SI
5610 )
5611 : InheritableAttr(attr::ObjCExplicitProtocolImpl, R, SI, false, false)
5612 {
5613 }
5614
5615 ObjCExplicitProtocolImplAttr *clone(ASTContext &C) const;
5616 void printPretty(raw_ostream &OS,
5617 const PrintingPolicy &Policy) const;
5618 const char *getSpelling() const;
5619
5620
5621 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCExplicitProtocolImpl; }
5622};
5623
5624class ObjCIndependentClassAttr : public InheritableAttr {
5625public:
5626 static ObjCIndependentClassAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5627 auto *A = new (Ctx) ObjCIndependentClassAttr(Loc, Ctx, 0);
5628 A->setImplicit(true);
5629 return A;
5630 }
5631
5632 ObjCIndependentClassAttr(SourceRange R, ASTContext &Ctx
5633 , unsigned SI
5634 )
5635 : InheritableAttr(attr::ObjCIndependentClass, R, SI, false, false)
5636 {
5637 }
5638
5639 ObjCIndependentClassAttr *clone(ASTContext &C) const;
5640 void printPretty(raw_ostream &OS,
5641 const PrintingPolicy &Policy) const;
5642 const char *getSpelling() const;
5643
5644
5645 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCIndependentClass; }
5646};
5647
5648class ObjCMethodFamilyAttr : public InheritableAttr {
5649public:
5650 enum FamilyKind {
5651 OMF_None,
5652 OMF_alloc,
5653 OMF_copy,
5654 OMF_init,
5655 OMF_mutableCopy,
5656 OMF_new
5657 };
5658private:
5659 FamilyKind family;
5660
5661public:
5662 static ObjCMethodFamilyAttr *CreateImplicit(ASTContext &Ctx, FamilyKind Family, SourceRange Loc = SourceRange()) {
5663 auto *A = new (Ctx) ObjCMethodFamilyAttr(Loc, Ctx, Family, 0);
5664 A->setImplicit(true);
5665 return A;
5666 }
5667
5668 ObjCMethodFamilyAttr(SourceRange R, ASTContext &Ctx
5669 , FamilyKind Family
5670 , unsigned SI
5671 )
5672 : InheritableAttr(attr::ObjCMethodFamily, R, SI, false, false)
5673 , family(Family)
5674 {
5675 }
5676
5677 ObjCMethodFamilyAttr *clone(ASTContext &C) const;
5678 void printPretty(raw_ostream &OS,
5679 const PrintingPolicy &Policy) const;
5680 const char *getSpelling() const;
5681 FamilyKind getFamily() const {
5682 return family;
5683 }
5684
5685 static bool ConvertStrToFamilyKind(StringRef Val, FamilyKind &Out) {
5686 Optional<FamilyKind> R = llvm::StringSwitch<Optional<FamilyKind>>(Val)
5687 .Case("none", ObjCMethodFamilyAttr::OMF_None)
5688 .Case("alloc", ObjCMethodFamilyAttr::OMF_alloc)
5689 .Case("copy", ObjCMethodFamilyAttr::OMF_copy)
5690 .Case("init", ObjCMethodFamilyAttr::OMF_init)
5691 .Case("mutableCopy", ObjCMethodFamilyAttr::OMF_mutableCopy)
5692 .Case("new", ObjCMethodFamilyAttr::OMF_new)
5693 .Default(Optional<FamilyKind>());
5694 if (R) {
5695 Out = *R;
5696 return true;
5697 }
5698 return false;
5699 }
5700
5701 static const char *ConvertFamilyKindToStr(FamilyKind Val) {
5702 switch(Val) {
5703 case ObjCMethodFamilyAttr::OMF_None: return "none";
5704 case ObjCMethodFamilyAttr::OMF_alloc: return "alloc";
5705 case ObjCMethodFamilyAttr::OMF_copy: return "copy";
5706 case ObjCMethodFamilyAttr::OMF_init: return "init";
5707 case ObjCMethodFamilyAttr::OMF_mutableCopy: return "mutableCopy";
5708 case ObjCMethodFamilyAttr::OMF_new: return "new";
5709 }
5710 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 5710)
;
5711 }
5712
5713
5714 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCMethodFamily; }
5715};
5716
5717class ObjCNSObjectAttr : public InheritableAttr {
5718public:
5719 static ObjCNSObjectAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5720 auto *A = new (Ctx) ObjCNSObjectAttr(Loc, Ctx, 0);
5721 A->setImplicit(true);
5722 return A;
5723 }
5724
5725 ObjCNSObjectAttr(SourceRange R, ASTContext &Ctx
5726 , unsigned SI
5727 )
5728 : InheritableAttr(attr::ObjCNSObject, R, SI, false, false)
5729 {
5730 }
5731
5732 ObjCNSObjectAttr *clone(ASTContext &C) const;
5733 void printPretty(raw_ostream &OS,
5734 const PrintingPolicy &Policy) const;
5735 const char *getSpelling() const;
5736
5737
5738 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCNSObject; }
5739};
5740
5741class ObjCPreciseLifetimeAttr : public InheritableAttr {
5742public:
5743 static ObjCPreciseLifetimeAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5744 auto *A = new (Ctx) ObjCPreciseLifetimeAttr(Loc, Ctx, 0);
5745 A->setImplicit(true);
5746 return A;
5747 }
5748
5749 ObjCPreciseLifetimeAttr(SourceRange R, ASTContext &Ctx
5750 , unsigned SI
5751 )
5752 : InheritableAttr(attr::ObjCPreciseLifetime, R, SI, false, false)
5753 {
5754 }
5755
5756 ObjCPreciseLifetimeAttr *clone(ASTContext &C) const;
5757 void printPretty(raw_ostream &OS,
5758 const PrintingPolicy &Policy) const;
5759 const char *getSpelling() const;
5760
5761
5762 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCPreciseLifetime; }
5763};
5764
5765class ObjCRequiresPropertyDefsAttr : public InheritableAttr {
5766public:
5767 static ObjCRequiresPropertyDefsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5768 auto *A = new (Ctx) ObjCRequiresPropertyDefsAttr(Loc, Ctx, 0);
5769 A->setImplicit(true);
5770 return A;
5771 }
5772
5773 ObjCRequiresPropertyDefsAttr(SourceRange R, ASTContext &Ctx
5774 , unsigned SI
5775 )
5776 : InheritableAttr(attr::ObjCRequiresPropertyDefs, R, SI, false, false)
5777 {
5778 }
5779
5780 ObjCRequiresPropertyDefsAttr *clone(ASTContext &C) const;
5781 void printPretty(raw_ostream &OS,
5782 const PrintingPolicy &Policy) const;
5783 const char *getSpelling() const;
5784
5785
5786 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRequiresPropertyDefs; }
5787};
5788
5789class ObjCRequiresSuperAttr : public InheritableAttr {
5790public:
5791 static ObjCRequiresSuperAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5792 auto *A = new (Ctx) ObjCRequiresSuperAttr(Loc, Ctx, 0);
5793 A->setImplicit(true);
5794 return A;
5795 }
5796
5797 ObjCRequiresSuperAttr(SourceRange R, ASTContext &Ctx
5798 , unsigned SI
5799 )
5800 : InheritableAttr(attr::ObjCRequiresSuper, R, SI, false, false)
5801 {
5802 }
5803
5804 ObjCRequiresSuperAttr *clone(ASTContext &C) const;
5805 void printPretty(raw_ostream &OS,
5806 const PrintingPolicy &Policy) const;
5807 const char *getSpelling() const;
5808
5809
5810 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRequiresSuper; }
5811};
5812
5813class ObjCReturnsInnerPointerAttr : public InheritableAttr {
5814public:
5815 static ObjCReturnsInnerPointerAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5816 auto *A = new (Ctx) ObjCReturnsInnerPointerAttr(Loc, Ctx, 0);
5817 A->setImplicit(true);
5818 return A;
5819 }
5820
5821 ObjCReturnsInnerPointerAttr(SourceRange R, ASTContext &Ctx
5822 , unsigned SI
5823 )
5824 : InheritableAttr(attr::ObjCReturnsInnerPointer, R, SI, false, false)
5825 {
5826 }
5827
5828 ObjCReturnsInnerPointerAttr *clone(ASTContext &C) const;
5829 void printPretty(raw_ostream &OS,
5830 const PrintingPolicy &Policy) const;
5831 const char *getSpelling() const;
5832
5833
5834 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCReturnsInnerPointer; }
5835};
5836
5837class ObjCRootClassAttr : public InheritableAttr {
5838public:
5839 static ObjCRootClassAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5840 auto *A = new (Ctx) ObjCRootClassAttr(Loc, Ctx, 0);
5841 A->setImplicit(true);
5842 return A;
5843 }
5844
5845 ObjCRootClassAttr(SourceRange R, ASTContext &Ctx
5846 , unsigned SI
5847 )
5848 : InheritableAttr(attr::ObjCRootClass, R, SI, false, false)
5849 {
5850 }
5851
5852 ObjCRootClassAttr *clone(ASTContext &C) const;
5853 void printPretty(raw_ostream &OS,
5854 const PrintingPolicy &Policy) const;
5855 const char *getSpelling() const;
5856
5857
5858 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRootClass; }
5859};
5860
5861class ObjCRuntimeNameAttr : public Attr {
5862unsigned metadataNameLength;
5863char *metadataName;
5864
5865public:
5866 static ObjCRuntimeNameAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef MetadataName, SourceRange Loc = SourceRange()) {
5867 auto *A = new (Ctx) ObjCRuntimeNameAttr(Loc, Ctx, MetadataName, 0);
5868 A->setImplicit(true);
5869 return A;
5870 }
5871
5872 ObjCRuntimeNameAttr(SourceRange R, ASTContext &Ctx
5873 , llvm::StringRef MetadataName
5874 , unsigned SI
5875 )
5876 : Attr(attr::ObjCRuntimeName, R, SI, false)
5877 , metadataNameLength(MetadataName.size()),metadataName(new (Ctx, 1) char[metadataNameLength])
5878 {
5879 if (!MetadataName.empty())
5880 std::memcpy(metadataName, MetadataName.data(), metadataNameLength);
5881 }
5882
5883 ObjCRuntimeNameAttr *clone(ASTContext &C) const;
5884 void printPretty(raw_ostream &OS,
5885 const PrintingPolicy &Policy) const;
5886 const char *getSpelling() const;
5887 llvm::StringRef getMetadataName() const {
5888 return llvm::StringRef(metadataName, metadataNameLength);
5889 }
5890 unsigned getMetadataNameLength() const {
5891 return metadataNameLength;
5892 }
5893 void setMetadataName(ASTContext &C, llvm::StringRef S) {
5894 metadataNameLength = S.size();
5895 this->metadataName = new (C, 1) char [metadataNameLength];
5896 if (!S.empty())
5897 std::memcpy(this->metadataName, S.data(), metadataNameLength);
5898 }
5899
5900
5901
5902 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRuntimeName; }
5903};
5904
5905class ObjCRuntimeVisibleAttr : public Attr {
5906public:
5907 static ObjCRuntimeVisibleAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5908 auto *A = new (Ctx) ObjCRuntimeVisibleAttr(Loc, Ctx, 0);
5909 A->setImplicit(true);
5910 return A;
5911 }
5912
5913 ObjCRuntimeVisibleAttr(SourceRange R, ASTContext &Ctx
5914 , unsigned SI
5915 )
5916 : Attr(attr::ObjCRuntimeVisible, R, SI, false)
5917 {
5918 }
5919
5920 ObjCRuntimeVisibleAttr *clone(ASTContext &C) const;
5921 void printPretty(raw_ostream &OS,
5922 const PrintingPolicy &Policy) const;
5923 const char *getSpelling() const;
5924
5925
5926 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRuntimeVisible; }
5927};
5928
5929class ObjCSubclassingRestrictedAttr : public InheritableAttr {
5930public:
5931 static ObjCSubclassingRestrictedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5932 auto *A = new (Ctx) ObjCSubclassingRestrictedAttr(Loc, Ctx, 0);
5933 A->setImplicit(true);
5934 return A;
5935 }
5936
5937 ObjCSubclassingRestrictedAttr(SourceRange R, ASTContext &Ctx
5938 , unsigned SI
5939 )
5940 : InheritableAttr(attr::ObjCSubclassingRestricted, R, SI, false, false)
5941 {
5942 }
5943
5944 ObjCSubclassingRestrictedAttr *clone(ASTContext &C) const;
5945 void printPretty(raw_ostream &OS,
5946 const PrintingPolicy &Policy) const;
5947 const char *getSpelling() const;
5948
5949
5950 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCSubclassingRestricted; }
5951};
5952
5953class OpenCLAccessAttr : public Attr {
5954public:
5955 enum Spelling {
5956 Keyword_read_only = 0,
5957 Keyword_write_only = 2,
5958 Keyword_read_write = 4
5959 };
5960
5961 static OpenCLAccessAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
5962 auto *A = new (Ctx) OpenCLAccessAttr(Loc, Ctx, S);
5963 A->setImplicit(true);
5964 return A;
5965 }
5966
5967 OpenCLAccessAttr(SourceRange R, ASTContext &Ctx
5968 , unsigned SI
5969 )
5970 : Attr(attr::OpenCLAccess, R, SI, false)
5971 {
5972 }
5973
5974 OpenCLAccessAttr *clone(ASTContext &C) const;
5975 void printPretty(raw_ostream &OS,
5976 const PrintingPolicy &Policy) const;
5977 const char *getSpelling() const;
5978 Spelling getSemanticSpelling() const {
5979 switch (SpellingListIndex) {
5980 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 5980)
;
5981 case 0: return Keyword_read_only;
5982 case 1: return Keyword_read_only;
5983 case 2: return Keyword_write_only;
5984 case 3: return Keyword_write_only;
5985 case 4: return Keyword_read_write;
5986 case 5: return Keyword_read_write;
5987 }
5988 }
5989 bool isReadOnly() const { return SpellingListIndex == 0 ||
5990 SpellingListIndex == 1; }
5991 bool isReadWrite() const { return SpellingListIndex == 4 ||
5992 SpellingListIndex == 5; }
5993 bool isWriteOnly() const { return SpellingListIndex == 2 ||
5994 SpellingListIndex == 3; }
5995
5996
5997 static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLAccess; }
5998};
5999
6000class OpenCLIntelReqdSubGroupSizeAttr : public InheritableAttr {
6001unsigned subGroupSize;
6002
6003public:
6004 static OpenCLIntelReqdSubGroupSizeAttr *CreateImplicit(ASTContext &Ctx, unsigned SubGroupSize, SourceRange Loc = SourceRange()) {
6005 auto *A = new (Ctx) OpenCLIntelReqdSubGroupSizeAttr(Loc, Ctx, SubGroupSize, 0);
6006 A->setImplicit(true);
6007 return A;
6008 }
6009
6010 OpenCLIntelReqdSubGroupSizeAttr(SourceRange R, ASTContext &Ctx
6011 , unsigned SubGroupSize
6012 , unsigned SI
6013 )
6014 : InheritableAttr(attr::OpenCLIntelReqdSubGroupSize, R, SI, false, false)
6015 , subGroupSize(SubGroupSize)
6016 {
6017 }
6018
6019 OpenCLIntelReqdSubGroupSizeAttr *clone(ASTContext &C) const;
6020 void printPretty(raw_ostream &OS,
6021 const PrintingPolicy &Policy) const;
6022 const char *getSpelling() const;
6023 unsigned getSubGroupSize() const {
6024 return subGroupSize;
6025 }
6026
6027
6028
6029 static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLIntelReqdSubGroupSize; }
6030};
6031
6032class OpenCLKernelAttr : public InheritableAttr {
6033public:
6034 static OpenCLKernelAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6035 auto *A = new (Ctx) OpenCLKernelAttr(Loc, Ctx, 0);
6036 A->setImplicit(true);
6037 return A;
6038 }
6039
6040 OpenCLKernelAttr(SourceRange R, ASTContext &Ctx
6041 , unsigned SI
6042 )
6043 : InheritableAttr(attr::OpenCLKernel, R, SI, false, false)
6044 {
6045 }
6046
6047 OpenCLKernelAttr *clone(ASTContext &C) const;
6048 void printPretty(raw_ostream &OS,
6049 const PrintingPolicy &Policy) const;
6050 const char *getSpelling() const;
6051
6052
6053 static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLKernel; }
6054};
6055
6056class OpenCLUnrollHintAttr : public InheritableAttr {
6057unsigned unrollHint;
6058
6059public:
6060 static OpenCLUnrollHintAttr *CreateImplicit(ASTContext &Ctx, unsigned UnrollHint, SourceRange Loc = SourceRange()) {
6061 auto *A = new (Ctx) OpenCLUnrollHintAttr(Loc, Ctx, UnrollHint, 0);
6062 A->setImplicit(true);
6063 return A;
6064 }
6065
6066 OpenCLUnrollHintAttr(SourceRange R, ASTContext &Ctx
6067 , unsigned UnrollHint
6068 , unsigned SI
6069 )
6070 : InheritableAttr(attr::OpenCLUnrollHint, R, SI, false, false)
6071 , unrollHint(UnrollHint)
6072 {
6073 }
6074
6075 OpenCLUnrollHintAttr *clone(ASTContext &C) const;
6076 void printPretty(raw_ostream &OS,
6077 const PrintingPolicy &Policy) const;
6078 const char *getSpelling() const;
6079 unsigned getUnrollHint() const {
6080 return unrollHint;
6081 }
6082
6083
6084
6085 static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLUnrollHint; }
6086};
6087
6088class OptimizeNoneAttr : public InheritableAttr {
6089public:
6090 static OptimizeNoneAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6091 auto *A = new (Ctx) OptimizeNoneAttr(Loc, Ctx, 0);
6092 A->setImplicit(true);
6093 return A;
6094 }
6095
6096 OptimizeNoneAttr(SourceRange R, ASTContext &Ctx
6097 , unsigned SI
6098 )
6099 : InheritableAttr(attr::OptimizeNone, R, SI, false, false)
6100 {
6101 }
6102
6103 OptimizeNoneAttr *clone(ASTContext &C) const;
6104 void printPretty(raw_ostream &OS,
6105 const PrintingPolicy &Policy) const;
6106 const char *getSpelling() const;
6107
6108
6109 static bool classof(const Attr *A) { return A->getKind() == attr::OptimizeNone; }
6110};
6111
6112class OverloadableAttr : public Attr {
6113public:
6114 static OverloadableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6115 auto *A = new (Ctx) OverloadableAttr(Loc, Ctx, 0);
6116 A->setImplicit(true);
6117 return A;
6118 }
6119
6120 OverloadableAttr(SourceRange R, ASTContext &Ctx
6121 , unsigned SI
6122 )
6123 : Attr(attr::Overloadable, R, SI, false)
6124 {
6125 }
6126
6127 OverloadableAttr *clone(ASTContext &C) const;
6128 void printPretty(raw_ostream &OS,
6129 const PrintingPolicy &Policy) const;
6130 const char *getSpelling() const;
6131
6132
6133 static bool classof(const Attr *A) { return A->getKind() == attr::Overloadable; }
6134};
6135
6136class OverrideAttr : public InheritableAttr {
6137public:
6138 static OverrideAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6139 auto *A = new (Ctx) OverrideAttr(Loc, Ctx, 0);
6140 A->setImplicit(true);
6141 return A;
6142 }
6143
6144 OverrideAttr(SourceRange R, ASTContext &Ctx
6145 , unsigned SI
6146 )
6147 : InheritableAttr(attr::Override, R, SI, false, false)
6148 {
6149 }
6150
6151 OverrideAttr *clone(ASTContext &C) const;
6152 void printPretty(raw_ostream &OS,
6153 const PrintingPolicy &Policy) const;
6154 const char *getSpelling() const;
6155
6156
6157 static bool classof(const Attr *A) { return A->getKind() == attr::Override; }
6158};
6159
6160class OwnershipAttr : public InheritableAttr {
6161IdentifierInfo * module;
6162
6163 unsigned args_Size;
6164 ParamIdx *args_;
6165
6166public:
6167 enum Spelling {
6168 GNU_ownership_holds = 0,
6169 CXX11_clang_ownership_holds = 1,
6170 C2x_clang_ownership_holds = 2,
6171 GNU_ownership_returns = 3,
6172 CXX11_clang_ownership_returns = 4,
6173 C2x_clang_ownership_returns = 5,
6174 GNU_ownership_takes = 6,
6175 CXX11_clang_ownership_takes = 7,
6176 C2x_clang_ownership_takes = 8
6177 };
6178
6179 static OwnershipAttr *CreateImplicit(ASTContext &Ctx, Spelling S, IdentifierInfo * Module, ParamIdx *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
6180 auto *A = new (Ctx) OwnershipAttr(Loc, Ctx, Module, Args, ArgsSize, S);
6181 A->setImplicit(true);
6182 return A;
6183 }
6184
6185 OwnershipAttr(SourceRange R, ASTContext &Ctx
6186 , IdentifierInfo * Module
6187 , ParamIdx *Args, unsigned ArgsSize
6188 , unsigned SI
6189 )
6190 : InheritableAttr(attr::Ownership, R, SI, false, false)
6191 , module(Module)
6192 , args_Size(ArgsSize), args_(new (Ctx, 16) ParamIdx[args_Size])
6193 {
6194 std::copy(Args, Args + args_Size, args_);
6195 }
6196
6197 OwnershipAttr(SourceRange R, ASTContext &Ctx
6198 , IdentifierInfo * Module
6199 , unsigned SI
6200 )
6201 : InheritableAttr(attr::Ownership, R, SI, false, false)
6202 , module(Module)
6203 , args_Size(0), args_(nullptr)
6204 {
6205 }
6206
6207 OwnershipAttr *clone(ASTContext &C) const;
6208 void printPretty(raw_ostream &OS,
6209 const PrintingPolicy &Policy) const;
6210 const char *getSpelling() const;
6211 Spelling getSemanticSpelling() const {
6212 switch (SpellingListIndex) {
6213 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 6213)
;
6214 case 0: return GNU_ownership_holds;
6215 case 1: return CXX11_clang_ownership_holds;
6216 case 2: return C2x_clang_ownership_holds;
6217 case 3: return GNU_ownership_returns;
6218 case 4: return CXX11_clang_ownership_returns;
6219 case 5: return C2x_clang_ownership_returns;
6220 case 6: return GNU_ownership_takes;
6221 case 7: return CXX11_clang_ownership_takes;
6222 case 8: return C2x_clang_ownership_takes;
6223 }
6224 }
6225 bool isHolds() const { return SpellingListIndex == 0 ||
6226 SpellingListIndex == 1 ||
6227 SpellingListIndex == 2; }
6228 bool isReturns() const { return SpellingListIndex == 3 ||
6229 SpellingListIndex == 4 ||
6230 SpellingListIndex == 5; }
6231 bool isTakes() const { return SpellingListIndex == 6 ||
6232 SpellingListIndex == 7 ||
6233 SpellingListIndex == 8; }
6234 IdentifierInfo * getModule() const {
6235 return module;
6236 }
6237
6238 typedef ParamIdx* args_iterator;
6239 args_iterator args_begin() const { return args_; }
6240 args_iterator args_end() const { return args_ + args_Size; }
6241 unsigned args_size() const { return args_Size; }
6242 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
6243
6244
6245
6246 enum OwnershipKind { Holds, Returns, Takes };
6247 OwnershipKind getOwnKind() const {
6248 return isHolds() ? Holds :
6249 isTakes() ? Takes :
6250 Returns;
6251 }
6252
6253
6254 static bool classof(const Attr *A) { return A->getKind() == attr::Ownership; }
6255};
6256
6257class PackedAttr : public InheritableAttr {
6258public:
6259 static PackedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6260 auto *A = new (Ctx) PackedAttr(Loc, Ctx, 0);
6261 A->setImplicit(true);
6262 return A;
6263 }
6264
6265 PackedAttr(SourceRange R, ASTContext &Ctx
6266 , unsigned SI
6267 )
6268 : InheritableAttr(attr::Packed, R, SI, false, false)
6269 {
6270 }
6271
6272 PackedAttr *clone(ASTContext &C) const;
6273 void printPretty(raw_ostream &OS,
6274 const PrintingPolicy &Policy) const;
6275 const char *getSpelling() const;
6276
6277
6278 static bool classof(const Attr *A) { return A->getKind() == attr::Packed; }
6279};
6280
6281class ParamTypestateAttr : public InheritableAttr {
6282public:
6283 enum ConsumedState {
6284 Unknown,
6285 Consumed,
6286 Unconsumed
6287 };
6288private:
6289 ConsumedState paramState;
6290
6291public:
6292 static ParamTypestateAttr *CreateImplicit(ASTContext &Ctx, ConsumedState ParamState, SourceRange Loc = SourceRange()) {
6293 auto *A = new (Ctx) ParamTypestateAttr(Loc, Ctx, ParamState, 0);
6294 A->setImplicit(true);
6295 return A;
6296 }
6297
6298 ParamTypestateAttr(SourceRange R, ASTContext &Ctx
6299 , ConsumedState ParamState
6300 , unsigned SI
6301 )
6302 : InheritableAttr(attr::ParamTypestate, R, SI, false, false)
6303 , paramState(ParamState)
6304 {
6305 }
6306
6307 ParamTypestateAttr *clone(ASTContext &C) const;
6308 void printPretty(raw_ostream &OS,
6309 const PrintingPolicy &Policy) const;
6310 const char *getSpelling() const;
6311 ConsumedState getParamState() const {
6312 return paramState;
6313 }
6314
6315 static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) {
6316 Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val)
6317 .Case("unknown", ParamTypestateAttr::Unknown)
6318 .Case("consumed", ParamTypestateAttr::Consumed)
6319 .Case("unconsumed", ParamTypestateAttr::Unconsumed)
6320 .Default(Optional<ConsumedState>());
6321 if (R) {
6322 Out = *R;
6323 return true;
6324 }
6325 return false;
6326 }
6327
6328 static const char *ConvertConsumedStateToStr(ConsumedState Val) {
6329 switch(Val) {
6330 case ParamTypestateAttr::Unknown: return "unknown";
6331 case ParamTypestateAttr::Consumed: return "consumed";
6332 case ParamTypestateAttr::Unconsumed: return "unconsumed";
6333 }
6334 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 6334)
;
6335 }
6336
6337
6338 static bool classof(const Attr *A) { return A->getKind() == attr::ParamTypestate; }
6339};
6340
6341class PascalAttr : public InheritableAttr {
6342public:
6343 static PascalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6344 auto *A = new (Ctx) PascalAttr(Loc, Ctx, 0);
6345 A->setImplicit(true);
6346 return A;
6347 }
6348
6349 PascalAttr(SourceRange R, ASTContext &Ctx
6350 , unsigned SI
6351 )
6352 : InheritableAttr(attr::Pascal, R, SI, false, false)
6353 {
6354 }
6355
6356 PascalAttr *clone(ASTContext &C) const;
6357 void printPretty(raw_ostream &OS,
6358 const PrintingPolicy &Policy) const;
6359 const char *getSpelling() const;
6360
6361
6362 static bool classof(const Attr *A) { return A->getKind() == attr::Pascal; }
6363};
6364
6365class PassObjectSizeAttr : public InheritableParamAttr {
6366int type;
6367
6368public:
6369 static PassObjectSizeAttr *CreateImplicit(ASTContext &Ctx, int Type, SourceRange Loc = SourceRange()) {
6370 auto *A = new (Ctx) PassObjectSizeAttr(Loc, Ctx, Type, 0);
6371 A->setImplicit(true);
6372 return A;
6373 }
6374
6375 PassObjectSizeAttr(SourceRange R, ASTContext &Ctx
6376 , int Type
6377 , unsigned SI
6378 )
6379 : InheritableParamAttr(attr::PassObjectSize, R, SI, false, false)
6380 , type(Type)
6381 {
6382 }
6383
6384 PassObjectSizeAttr *clone(ASTContext &C) const;
6385 void printPretty(raw_ostream &OS,
6386 const PrintingPolicy &Policy) const;
6387 const char *getSpelling() const;
6388 int getType() const {
6389 return type;
6390 }
6391
6392
6393
6394 static bool classof(const Attr *A) { return A->getKind() == attr::PassObjectSize; }
6395};
6396
6397class PcsAttr : public InheritableAttr {
6398public:
6399 enum PCSType {
6400 AAPCS,
6401 AAPCS_VFP
6402 };
6403private:
6404 PCSType pCS;
6405
6406public:
6407 static PcsAttr *CreateImplicit(ASTContext &Ctx, PCSType PCS, SourceRange Loc = SourceRange()) {
6408 auto *A = new (Ctx) PcsAttr(Loc, Ctx, PCS, 0);
6409 A->setImplicit(true);
6410 return A;
6411 }
6412
6413 PcsAttr(SourceRange R, ASTContext &Ctx
6414 , PCSType PCS
6415 , unsigned SI
6416 )
6417 : InheritableAttr(attr::Pcs, R, SI, false, false)
6418 , pCS(PCS)
6419 {
6420 }
6421
6422 PcsAttr *clone(ASTContext &C) const;
6423 void printPretty(raw_ostream &OS,
6424 const PrintingPolicy &Policy) const;
6425 const char *getSpelling() const;
6426 PCSType getPCS() const {
6427 return pCS;
6428 }
6429
6430 static bool ConvertStrToPCSType(StringRef Val, PCSType &Out) {
6431 Optional<PCSType> R = llvm::StringSwitch<Optional<PCSType>>(Val)
6432 .Case("aapcs", PcsAttr::AAPCS)
6433 .Case("aapcs-vfp", PcsAttr::AAPCS_VFP)
6434 .Default(Optional<PCSType>());
6435 if (R) {
6436 Out = *R;
6437 return true;
6438 }
6439 return false;
6440 }
6441
6442 static const char *ConvertPCSTypeToStr(PCSType Val) {
6443 switch(Val) {
6444 case PcsAttr::AAPCS: return "aapcs";
6445 case PcsAttr::AAPCS_VFP: return "aapcs-vfp";
6446 }
6447 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 6447)
;
6448 }
6449
6450
6451 static bool classof(const Attr *A) { return A->getKind() == attr::Pcs; }
6452};
6453
6454class PragmaClangBSSSectionAttr : public InheritableAttr {
6455unsigned nameLength;
6456char *name;
6457
6458public:
6459 static PragmaClangBSSSectionAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) {
6460 auto *A = new (Ctx) PragmaClangBSSSectionAttr(Loc, Ctx, Name, 0);
6461 A->setImplicit(true);
6462 return A;
6463 }
6464
6465 PragmaClangBSSSectionAttr(SourceRange R, ASTContext &Ctx
6466 , llvm::StringRef Name
6467 , unsigned SI
6468 )
6469 : InheritableAttr(attr::PragmaClangBSSSection, R, SI, false, false)
6470 , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength])
6471 {
6472 if (!Name.empty())
6473 std::memcpy(name, Name.data(), nameLength);
6474 }
6475
6476 PragmaClangBSSSectionAttr *clone(ASTContext &C) const;
6477 void printPretty(raw_ostream &OS,
6478 const PrintingPolicy &Policy) const;
6479 const char *getSpelling() const;
6480 llvm::StringRef getName() const {
6481 return llvm::StringRef(name, nameLength);
6482 }
6483 unsigned getNameLength() const {
6484 return nameLength;
6485 }
6486 void setName(ASTContext &C, llvm::StringRef S) {
6487 nameLength = S.size();
6488 this->name = new (C, 1) char [nameLength];
6489 if (!S.empty())
6490 std::memcpy(this->name, S.data(), nameLength);
6491 }
6492
6493
6494
6495 static bool classof(const Attr *A) { return A->getKind() == attr::PragmaClangBSSSection; }
6496};
6497
6498class PragmaClangDataSectionAttr : public InheritableAttr {
6499unsigned nameLength;
6500char *name;
6501
6502public:
6503 static PragmaClangDataSectionAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) {
6504 auto *A = new (Ctx) PragmaClangDataSectionAttr(Loc, Ctx, Name, 0);
6505 A->setImplicit(true);
6506 return A;
6507 }
6508
6509 PragmaClangDataSectionAttr(SourceRange R, ASTContext &Ctx
6510 , llvm::StringRef Name
6511 , unsigned SI
6512 )
6513 : InheritableAttr(attr::PragmaClangDataSection, R, SI, false, false)
6514 , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength])
6515 {
6516 if (!Name.empty())
6517 std::memcpy(name, Name.data(), nameLength);
6518 }
6519
6520 PragmaClangDataSectionAttr *clone(ASTContext &C) const;
6521 void printPretty(raw_ostream &OS,
6522 const PrintingPolicy &Policy) const;
6523 const char *getSpelling() const;
6524 llvm::StringRef getName() const {
6525 return llvm::StringRef(name, nameLength);
6526 }
6527 unsigned getNameLength() const {
6528 return nameLength;
6529 }
6530 void setName(ASTContext &C, llvm::StringRef S) {
6531 nameLength = S.size();
6532 this->name = new (C, 1) char [nameLength];
6533 if (!S.empty())
6534 std::memcpy(this->name, S.data(), nameLength);
6535 }
6536
6537
6538
6539 static bool classof(const Attr *A) { return A->getKind() == attr::PragmaClangDataSection; }
6540};
6541
6542class PragmaClangRodataSectionAttr : public InheritableAttr {
6543unsigned nameLength;
6544char *name;
6545
6546public:
6547 static PragmaClangRodataSectionAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) {
6548 auto *A = new (Ctx) PragmaClangRodataSectionAttr(Loc, Ctx, Name, 0);
6549 A->setImplicit(true);
6550 return A;
6551 }
6552
6553 PragmaClangRodataSectionAttr(SourceRange R, ASTContext &Ctx
6554 , llvm::StringRef Name
6555 , unsigned SI
6556 )
6557 : InheritableAttr(attr::PragmaClangRodataSection, R, SI, false, false)
6558 , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength])
6559 {
6560 if (!Name.empty())
6561 std::memcpy(name, Name.data(), nameLength);
6562 }
6563
6564 PragmaClangRodataSectionAttr *clone(ASTContext &C) const;
6565 void printPretty(raw_ostream &OS,
6566 const PrintingPolicy &Policy) const;
6567 const char *getSpelling() const;
6568 llvm::StringRef getName() const {
6569 return llvm::StringRef(name, nameLength);
6570 }
6571 unsigned getNameLength() const {
6572 return nameLength;
6573 }
6574 void setName(ASTContext &C, llvm::StringRef S) {
6575 nameLength = S.size();
6576 this->name = new (C, 1) char [nameLength];
6577 if (!S.empty())
6578 std::memcpy(this->name, S.data(), nameLength);
6579 }
6580
6581
6582
6583 static bool classof(const Attr *A) { return A->getKind() == attr::PragmaClangRodataSection; }
6584};
6585
6586class PragmaClangTextSectionAttr : public InheritableAttr {
6587unsigned nameLength;
6588char *name;
6589
6590public:
6591 static PragmaClangTextSectionAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) {
6592 auto *A = new (Ctx) PragmaClangTextSectionAttr(Loc, Ctx, Name, 0);
6593 A->setImplicit(true);
6594 return A;
6595 }
6596
6597 PragmaClangTextSectionAttr(SourceRange R, ASTContext &Ctx
6598 , llvm::StringRef Name
6599 , unsigned SI
6600 )
6601 : InheritableAttr(attr::PragmaClangTextSection, R, SI, false, false)
6602 , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength])
6603 {
6604 if (!Name.empty())
6605 std::memcpy(name, Name.data(), nameLength);
6606 }
6607
6608 PragmaClangTextSectionAttr *clone(ASTContext &C) const;
6609 void printPretty(raw_ostream &OS,
6610 const PrintingPolicy &Policy) const;
6611 const char *getSpelling() const;
6612 llvm::StringRef getName() const {
6613 return llvm::StringRef(name, nameLength);
6614 }
6615 unsigned getNameLength() const {
6616 return nameLength;
6617 }
6618 void setName(ASTContext &C, llvm::StringRef S) {
6619 nameLength = S.size();
6620 this->name = new (C, 1) char [nameLength];
6621 if (!S.empty())
6622 std::memcpy(this->name, S.data(), nameLength);
6623 }
6624
6625
6626
6627 static bool classof(const Attr *A) { return A->getKind() == attr::PragmaClangTextSection; }
6628};
6629
6630class PreserveAllAttr : public InheritableAttr {
6631public:
6632 static PreserveAllAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6633 auto *A = new (Ctx) PreserveAllAttr(Loc, Ctx, 0);
6634 A->setImplicit(true);
6635 return A;
6636 }
6637
6638 PreserveAllAttr(SourceRange R, ASTContext &Ctx
6639 , unsigned SI
6640 )
6641 : InheritableAttr(attr::PreserveAll, R, SI, false, false)
6642 {
6643 }
6644
6645 PreserveAllAttr *clone(ASTContext &C) const;
6646 void printPretty(raw_ostream &OS,
6647 const PrintingPolicy &Policy) const;
6648 const char *getSpelling() const;
6649
6650
6651 static bool classof(const Attr *A) { return A->getKind() == attr::PreserveAll; }
6652};
6653
6654class PreserveMostAttr : public InheritableAttr {
6655public:
6656 static PreserveMostAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6657 auto *A = new (Ctx) PreserveMostAttr(Loc, Ctx, 0);
6658 A->setImplicit(true);
6659 return A;
6660 }
6661
6662 PreserveMostAttr(SourceRange R, ASTContext &Ctx
6663 , unsigned SI
6664 )
6665 : InheritableAttr(attr::PreserveMost, R, SI, false, false)
6666 {
6667 }
6668
6669 PreserveMostAttr *clone(ASTContext &C) const;
6670 void printPretty(raw_ostream &OS,
6671 const PrintingPolicy &Policy) const;
6672 const char *getSpelling() const;
6673
6674
6675 static bool classof(const Attr *A) { return A->getKind() == attr::PreserveMost; }
6676};
6677
6678class PtGuardedByAttr : public InheritableAttr {
6679Expr * arg;
6680
6681public:
6682 static PtGuardedByAttr *CreateImplicit(ASTContext &Ctx, Expr * Arg, SourceRange Loc = SourceRange()) {
6683 auto *A = new (Ctx) PtGuardedByAttr(Loc, Ctx, Arg, 0);
6684 A->setImplicit(true);
6685 return A;
6686 }
6687
6688 PtGuardedByAttr(SourceRange R, ASTContext &Ctx
6689 , Expr * Arg
6690 , unsigned SI
6691 )
6692 : InheritableAttr(attr::PtGuardedBy, R, SI, true, true)
6693 , arg(Arg)
6694 {
6695 }
6696
6697 PtGuardedByAttr *clone(ASTContext &C) const;
6698 void printPretty(raw_ostream &OS,
6699 const PrintingPolicy &Policy) const;
6700 const char *getSpelling() const;
6701 Expr * getArg() const {
6702 return arg;
6703 }
6704
6705
6706
6707 static bool classof(const Attr *A) { return A->getKind() == attr::PtGuardedBy; }
6708};
6709
6710class PtGuardedVarAttr : public InheritableAttr {
6711public:
6712 static PtGuardedVarAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6713 auto *A = new (Ctx) PtGuardedVarAttr(Loc, Ctx, 0);
6714 A->setImplicit(true);
6715 return A;
6716 }
6717
6718 PtGuardedVarAttr(SourceRange R, ASTContext &Ctx
6719 , unsigned SI
6720 )
6721 : InheritableAttr(attr::PtGuardedVar, R, SI, false, false)
6722 {
6723 }
6724
6725 PtGuardedVarAttr *clone(ASTContext &C) const;
6726 void printPretty(raw_ostream &OS,
6727 const PrintingPolicy &Policy) const;
6728 const char *getSpelling() const;
6729
6730
6731 static bool classof(const Attr *A) { return A->getKind() == attr::PtGuardedVar; }
6732};
6733
6734class PureAttr : public InheritableAttr {
6735public:
6736 static PureAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6737 auto *A = new (Ctx) PureAttr(Loc, Ctx, 0);
6738 A->setImplicit(true);
6739 return A;
6740 }
6741
6742 PureAttr(SourceRange R, ASTContext &Ctx
6743 , unsigned SI
6744 )
6745 : InheritableAttr(attr::Pure, R, SI, false, false)
6746 {
6747 }
6748
6749 PureAttr *clone(ASTContext &C) const;
6750 void printPretty(raw_ostream &OS,
6751 const PrintingPolicy &Policy) const;
6752 const char *getSpelling() const;
6753
6754
6755 static bool classof(const Attr *A) { return A->getKind() == attr::Pure; }
6756};
6757
6758class RegCallAttr : public InheritableAttr {
6759public:
6760 static RegCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6761 auto *A = new (Ctx) RegCallAttr(Loc, Ctx, 0);
6762 A->setImplicit(true);
6763 return A;
6764 }
6765
6766 RegCallAttr(SourceRange R, ASTContext &Ctx
6767 , unsigned SI
6768 )
6769 : InheritableAttr(attr::RegCall, R, SI, false, false)
6770 {
6771 }
6772
6773 RegCallAttr *clone(ASTContext &C) const;
6774 void printPretty(raw_ostream &OS,
6775 const PrintingPolicy &Policy) const;
6776 const char *getSpelling() const;
6777
6778
6779 static bool classof(const Attr *A) { return A->getKind() == attr::RegCall; }
6780};
6781
6782class ReleaseCapabilityAttr : public InheritableAttr {
6783 unsigned args_Size;
6784 Expr * *args_;
6785
6786public:
6787 enum Spelling {
6788 GNU_release_capability = 0,
6789 CXX11_clang_release_capability = 1,
6790 GNU_release_shared_capability = 2,
6791 CXX11_clang_release_shared_capability = 3,
6792 GNU_release_generic_capability = 4,
6793 CXX11_clang_release_generic_capability = 5,
6794 GNU_unlock_function = 6,
6795 CXX11_clang_unlock_function = 7
6796 };
6797
6798 static ReleaseCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
6799 auto *A = new (Ctx) ReleaseCapabilityAttr(Loc, Ctx, Args, ArgsSize, S);
6800 A->setImplicit(true);
6801 return A;
6802 }
6803
6804 ReleaseCapabilityAttr(SourceRange R, ASTContext &Ctx
6805 , Expr * *Args, unsigned ArgsSize
6806 , unsigned SI
6807 )
6808 : InheritableAttr(attr::ReleaseCapability, R, SI, true, true)
6809 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
6810 {
6811 std::copy(Args, Args + args_Size, args_);
6812 }
6813
6814 ReleaseCapabilityAttr(SourceRange R, ASTContext &Ctx
6815 , unsigned SI
6816 )
6817 : InheritableAttr(attr::ReleaseCapability, R, SI, true, true)
6818 , args_Size(0), args_(nullptr)
6819 {
6820 }
6821
6822 ReleaseCapabilityAttr *clone(ASTContext &C) const;
6823 void printPretty(raw_ostream &OS,
6824 const PrintingPolicy &Policy) const;
6825 const char *getSpelling() const;
6826 Spelling getSemanticSpelling() const {
6827 switch (SpellingListIndex) {
6828 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 6828)
;
6829 case 0: return GNU_release_capability;
6830 case 1: return CXX11_clang_release_capability;
6831 case 2: return GNU_release_shared_capability;
6832 case 3: return CXX11_clang_release_shared_capability;
6833 case 4: return GNU_release_generic_capability;
6834 case 5: return CXX11_clang_release_generic_capability;
6835 case 6: return GNU_unlock_function;
6836 case 7: return CXX11_clang_unlock_function;
6837 }
6838 }
6839 bool isShared() const { return SpellingListIndex == 2 ||
6840 SpellingListIndex == 3; }
6841 bool isGeneric() const { return SpellingListIndex == 4 ||
6842 SpellingListIndex == 5 ||
6843 SpellingListIndex == 6 ||
6844 SpellingListIndex == 7; }
6845 typedef Expr ** args_iterator;
6846 args_iterator args_begin() const { return args_; }
6847 args_iterator args_end() const { return args_ + args_Size; }
6848 unsigned args_size() const { return args_Size; }
6849 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
6850
6851
6852
6853
6854 static bool classof(const Attr *A) { return A->getKind() == attr::ReleaseCapability; }
6855};
6856
6857class RenderScriptKernelAttr : public Attr {
6858public:
6859 static RenderScriptKernelAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6860 auto *A = new (Ctx) RenderScriptKernelAttr(Loc, Ctx, 0);
6861 A->setImplicit(true);
6862 return A;
6863 }
6864
6865 RenderScriptKernelAttr(SourceRange R, ASTContext &Ctx
6866 , unsigned SI
6867 )
6868 : Attr(attr::RenderScriptKernel, R, SI, false)
6869 {
6870 }
6871
6872 RenderScriptKernelAttr *clone(ASTContext &C) const;
6873 void printPretty(raw_ostream &OS,
6874 const PrintingPolicy &Policy) const;
6875 const char *getSpelling() const;
6876
6877
6878 static bool classof(const Attr *A) { return A->getKind() == attr::RenderScriptKernel; }
6879};
6880
6881class ReqdWorkGroupSizeAttr : public InheritableAttr {
6882unsigned xDim;
6883
6884unsigned yDim;
6885
6886unsigned zDim;
6887
6888public:
6889 static ReqdWorkGroupSizeAttr *CreateImplicit(ASTContext &Ctx, unsigned XDim, unsigned YDim, unsigned ZDim, SourceRange Loc = SourceRange()) {
6890 auto *A = new (Ctx) ReqdWorkGroupSizeAttr(Loc, Ctx, XDim, YDim, ZDim, 0);
6891 A->setImplicit(true);
6892 return A;
6893 }
6894
6895 ReqdWorkGroupSizeAttr(SourceRange R, ASTContext &Ctx
6896 , unsigned XDim
6897 , unsigned YDim
6898 , unsigned ZDim
6899 , unsigned SI
6900 )
6901 : InheritableAttr(attr::ReqdWorkGroupSize, R, SI, false, false)
6902 , xDim(XDim)
6903 , yDim(YDim)
6904 , zDim(ZDim)
6905 {
6906 }
6907
6908 ReqdWorkGroupSizeAttr *clone(ASTContext &C) const;
6909 void printPretty(raw_ostream &OS,
6910 const PrintingPolicy &Policy) const;
6911 const char *getSpelling() const;
6912 unsigned getXDim() const {
6913 return xDim;
6914 }
6915
6916 unsigned getYDim() const {
6917 return yDim;
6918 }
6919
6920 unsigned getZDim() const {
6921 return zDim;
6922 }
6923
6924
6925
6926 static bool classof(const Attr *A) { return A->getKind() == attr::ReqdWorkGroupSize; }
6927};
6928
6929class RequireConstantInitAttr : public InheritableAttr {
6930public:
6931 static RequireConstantInitAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6932 auto *A = new (Ctx) RequireConstantInitAttr(Loc, Ctx, 0);
6933 A->setImplicit(true);
6934 return A;
6935 }
6936
6937 RequireConstantInitAttr(SourceRange R, ASTContext &Ctx
6938 , unsigned SI
6939 )
6940 : InheritableAttr(attr::RequireConstantInit, R, SI, false, false)
6941 {
6942 }
6943
6944 RequireConstantInitAttr *clone(ASTContext &C) const;
6945 void printPretty(raw_ostream &OS,
6946 const PrintingPolicy &Policy) const;
6947 const char *getSpelling() const;
6948
6949
6950 static bool classof(const Attr *A) { return A->getKind() == attr::RequireConstantInit; }
6951};
6952
6953class RequiresCapabilityAttr : public InheritableAttr {
6954 unsigned args_Size;
6955 Expr * *args_;
6956
6957public:
6958 enum Spelling {
6959 GNU_requires_capability = 0,
6960 CXX11_clang_requires_capability = 1,
6961 GNU_exclusive_locks_required = 2,
6962 CXX11_clang_exclusive_locks_required = 3,
6963 GNU_requires_shared_capability = 4,
6964 CXX11_clang_requires_shared_capability = 5,
6965 GNU_shared_locks_required = 6,
6966 CXX11_clang_shared_locks_required = 7
6967 };
6968
6969 static RequiresCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
6970 auto *A = new (Ctx) RequiresCapabilityAttr(Loc, Ctx, Args, ArgsSize, S);
6971 A->setImplicit(true);
6972 return A;
6973 }
6974
6975 RequiresCapabilityAttr(SourceRange R, ASTContext &Ctx
6976 , Expr * *Args, unsigned ArgsSize
6977 , unsigned SI
6978 )
6979 : InheritableAttr(attr::RequiresCapability, R, SI, true, true)
6980 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
6981 {
6982 std::copy(Args, Args + args_Size, args_);
6983 }
6984
6985 RequiresCapabilityAttr(SourceRange R, ASTContext &Ctx
6986 , unsigned SI
6987 )
6988 : InheritableAttr(attr::RequiresCapability, R, SI, true, true)
6989 , args_Size(0), args_(nullptr)
6990 {
6991 }
6992
6993 RequiresCapabilityAttr *clone(ASTContext &C) const;
6994 void printPretty(raw_ostream &OS,
6995 const PrintingPolicy &Policy) const;
6996 const char *getSpelling() const;
6997 Spelling getSemanticSpelling() const {
6998 switch (SpellingListIndex) {
6999 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 6999)
;
7000 case 0: return GNU_requires_capability;
7001 case 1: return CXX11_clang_requires_capability;
7002 case 2: return GNU_exclusive_locks_required;
7003 case 3: return CXX11_clang_exclusive_locks_required;
7004 case 4: return GNU_requires_shared_capability;
7005 case 5: return CXX11_clang_requires_shared_capability;
7006 case 6: return GNU_shared_locks_required;
7007 case 7: return CXX11_clang_shared_locks_required;
7008 }
7009 }
7010 bool isShared() const { return SpellingListIndex == 4 ||
7011 SpellingListIndex == 5 ||
7012 SpellingListIndex == 6 ||
7013 SpellingListIndex == 7; }
7014 typedef Expr ** args_iterator;
7015 args_iterator args_begin() const { return args_; }
7016 args_iterator args_end() const { return args_ + args_Size; }
7017 unsigned args_size() const { return args_Size; }
7018 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
7019
7020
7021
7022
7023 static bool classof(const Attr *A) { return A->getKind() == attr::RequiresCapability; }
7024};
7025
7026class RestrictAttr : public InheritableAttr {
7027public:
7028 enum Spelling {
7029 Declspec_restrict = 0,
7030 GNU_malloc = 1,
7031 CXX11_gnu_malloc = 2
7032 };
7033
7034 static RestrictAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
7035 auto *A = new (Ctx) RestrictAttr(Loc, Ctx, S);
7036 A->setImplicit(true);
7037 return A;
7038 }
7039
7040 RestrictAttr(SourceRange R, ASTContext &Ctx
7041 , unsigned SI
7042 )
7043 : InheritableAttr(attr::Restrict, R, SI, false, false)
7044 {
7045 }
7046
7047 RestrictAttr *clone(ASTContext &C) const;
7048 void printPretty(raw_ostream &OS,
7049 const PrintingPolicy &Policy) const;
7050 const char *getSpelling() const;
7051 Spelling getSemanticSpelling() const {
7052 switch (SpellingListIndex) {
7053 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 7053)
;
7054 case 0: return Declspec_restrict;
7055 case 1: return GNU_malloc;
7056 case 2: return CXX11_gnu_malloc;
7057 }
7058 }
7059
7060
7061 static bool classof(const Attr *A) { return A->getKind() == attr::Restrict; }
7062};
7063
7064class ReturnTypestateAttr : public InheritableAttr {
7065public:
7066 enum ConsumedState {
7067 Unknown,
7068 Consumed,
7069 Unconsumed
7070 };
7071private:
7072 ConsumedState state;
7073
7074public:
7075 static ReturnTypestateAttr *CreateImplicit(ASTContext &Ctx, ConsumedState State, SourceRange Loc = SourceRange()) {
7076 auto *A = new (Ctx) ReturnTypestateAttr(Loc, Ctx, State, 0);
7077 A->setImplicit(true);
7078 return A;
7079 }
7080
7081 ReturnTypestateAttr(SourceRange R, ASTContext &Ctx
7082 , ConsumedState State
7083 , unsigned SI
7084 )
7085 : InheritableAttr(attr::ReturnTypestate, R, SI, false, false)
7086 , state(State)
7087 {
7088 }
7089
7090 ReturnTypestateAttr *clone(ASTContext &C) const;
7091 void printPretty(raw_ostream &OS,
7092 const PrintingPolicy &Policy) const;
7093 const char *getSpelling() const;
7094 ConsumedState getState() const {
7095 return state;
7096 }
7097
7098 static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) {
7099 Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val)
7100 .Case("unknown", ReturnTypestateAttr::Unknown)
7101 .Case("consumed", ReturnTypestateAttr::Consumed)
7102 .Case("unconsumed", ReturnTypestateAttr::Unconsumed)
7103 .Default(Optional<ConsumedState>());
7104 if (R) {
7105 Out = *R;
7106 return true;
7107 }
7108 return false;
7109 }
7110
7111 static const char *ConvertConsumedStateToStr(ConsumedState Val) {
7112 switch(Val) {
7113 case ReturnTypestateAttr::Unknown: return "unknown";
7114 case ReturnTypestateAttr::Consumed: return "consumed";
7115 case ReturnTypestateAttr::Unconsumed: return "unconsumed";
7116 }
7117 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 7117)
;
7118 }
7119
7120
7121 static bool classof(const Attr *A) { return A->getKind() == attr::ReturnTypestate; }
7122};
7123
7124class ReturnsNonNullAttr : public InheritableAttr {
7125public:
7126 static ReturnsNonNullAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7127 auto *A = new (Ctx) ReturnsNonNullAttr(Loc, Ctx, 0);
7128 A->setImplicit(true);
7129 return A;
7130 }
7131
7132 ReturnsNonNullAttr(SourceRange R, ASTContext &Ctx
7133 , unsigned SI
7134 )
7135 : InheritableAttr(attr::ReturnsNonNull, R, SI, false, false)
7136 {
7137 }
7138
7139 ReturnsNonNullAttr *clone(ASTContext &C) const;
7140 void printPretty(raw_ostream &OS,
7141 const PrintingPolicy &Policy) const;
7142 const char *getSpelling() const;
7143
7144
7145 static bool classof(const Attr *A) { return A->getKind() == attr::ReturnsNonNull; }
7146};
7147
7148class ReturnsTwiceAttr : public InheritableAttr {
7149public:
7150 static ReturnsTwiceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7151 auto *A = new (Ctx) ReturnsTwiceAttr(Loc, Ctx, 0);
7152 A->setImplicit(true);
7153 return A;
7154 }
7155
7156 ReturnsTwiceAttr(SourceRange R, ASTContext &Ctx
7157 , unsigned SI
7158 )
7159 : InheritableAttr(attr::ReturnsTwice, R, SI, false, false)
7160 {
7161 }
7162
7163 ReturnsTwiceAttr *clone(ASTContext &C) const;
7164 void printPretty(raw_ostream &OS,
7165 const PrintingPolicy &Policy) const;
7166 const char *getSpelling() const;
7167
7168
7169 static bool classof(const Attr *A) { return A->getKind() == attr::ReturnsTwice; }
7170};
7171
7172class ScopedLockableAttr : public InheritableAttr {
7173public:
7174 static ScopedLockableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7175 auto *A = new (Ctx) ScopedLockableAttr(Loc, Ctx, 0);
7176 A->setImplicit(true);
7177 return A;
7178 }
7179
7180 ScopedLockableAttr(SourceRange R, ASTContext &Ctx
7181 , unsigned SI
7182 )
7183 : InheritableAttr(attr::ScopedLockable, R, SI, false, false)
7184 {
7185 }
7186
7187 ScopedLockableAttr *clone(ASTContext &C) const;
7188 void printPretty(raw_ostream &OS,
7189 const PrintingPolicy &Policy) const;
7190 const char *getSpelling() const;
7191
7192
7193 static bool classof(const Attr *A) { return A->getKind() == attr::ScopedLockable; }
7194};
7195
7196class SectionAttr : public InheritableAttr {
7197unsigned nameLength;
7198char *name;
7199
7200public:
7201 enum Spelling {
7202 GNU_section = 0,
7203 CXX11_gnu_section = 1,
7204 Declspec_allocate = 2
7205 };
7206
7207 static SectionAttr *CreateImplicit(ASTContext &Ctx, Spelling S, llvm::StringRef Name, SourceRange Loc = SourceRange()) {
7208 auto *A = new (Ctx) SectionAttr(Loc, Ctx, Name, S);
7209 A->setImplicit(true);
7210 return A;
7211 }
7212
7213 SectionAttr(SourceRange R, ASTContext &Ctx
7214 , llvm::StringRef Name
7215 , unsigned SI
7216 )
7217 : InheritableAttr(attr::Section, R, SI, false, false)
7218 , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength])
7219 {
7220 if (!Name.empty())
7221 std::memcpy(name, Name.data(), nameLength);
7222 }
7223
7224 SectionAttr *clone(ASTContext &C) const;
7225 void printPretty(raw_ostream &OS,
7226 const PrintingPolicy &Policy) const;
7227 const char *getSpelling() const;
7228 Spelling getSemanticSpelling() const {
7229 switch (SpellingListIndex) {
7230 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 7230)
;
7231 case 0: return GNU_section;
7232 case 1: return CXX11_gnu_section;
7233 case 2: return Declspec_allocate;
7234 }
7235 }
7236 llvm::StringRef getName() const {
7237 return llvm::StringRef(name, nameLength);
7238 }
7239 unsigned getNameLength() const {
7240 return nameLength;
7241 }
7242 void setName(ASTContext &C, llvm::StringRef S) {
7243 nameLength = S.size();
7244 this->name = new (C, 1) char [nameLength];
7245 if (!S.empty())
7246 std::memcpy(this->name, S.data(), nameLength);
7247 }
7248
7249
7250
7251 static bool classof(const Attr *A) { return A->getKind() == attr::Section; }
7252};
7253
7254class SelectAnyAttr : public InheritableAttr {
7255public:
7256 static SelectAnyAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7257 auto *A = new (Ctx) SelectAnyAttr(Loc, Ctx, 0);
7258 A->setImplicit(true);
7259 return A;
7260 }
7261
7262 SelectAnyAttr(SourceRange R, ASTContext &Ctx
7263 , unsigned SI
7264 )
7265 : InheritableAttr(attr::SelectAny, R, SI, false, false)
7266 {
7267 }
7268
7269 SelectAnyAttr *clone(ASTContext &C) const;
7270 void printPretty(raw_ostream &OS,
7271 const PrintingPolicy &Policy) const;
7272 const char *getSpelling() const;
7273
7274
7275 static bool classof(const Attr *A) { return A->getKind() == attr::SelectAny; }
7276};
7277
7278class SentinelAttr : public InheritableAttr {
7279int sentinel;
7280
7281int nullPos;
7282
7283public:
7284 static SentinelAttr *CreateImplicit(ASTContext &Ctx, int Sentinel, int NullPos, SourceRange Loc = SourceRange()) {
7285 auto *A = new (Ctx) SentinelAttr(Loc, Ctx, Sentinel, NullPos, 0);
7286 A->setImplicit(true);
7287 return A;
7288 }
7289
7290 SentinelAttr(SourceRange R, ASTContext &Ctx
7291 , int Sentinel
7292 , int NullPos
7293 , unsigned SI
7294 )
7295 : InheritableAttr(attr::Sentinel, R, SI, false, false)
7296 , sentinel(Sentinel)
7297 , nullPos(NullPos)
7298 {
7299 }
7300
7301 SentinelAttr(SourceRange R, ASTContext &Ctx
7302 , unsigned SI
7303 )
7304 : InheritableAttr(attr::Sentinel, R, SI, false, false)
7305 , sentinel()
7306 , nullPos()
7307 {
7308 }
7309
7310 SentinelAttr *clone(ASTContext &C) const;
7311 void printPretty(raw_ostream &OS,
7312 const PrintingPolicy &Policy) const;
7313 const char *getSpelling() const;
7314 int getSentinel() const {
7315 return sentinel;
7316 }
7317
7318 static const int DefaultSentinel = 0;
7319
7320 int getNullPos() const {
7321 return nullPos;
7322 }
7323
7324 static const int DefaultNullPos = 0;
7325
7326
7327
7328 static bool classof(const Attr *A) { return A->getKind() == attr::Sentinel; }
7329};
7330
7331class SetTypestateAttr : public InheritableAttr {
7332public:
7333 enum ConsumedState {
7334 Unknown,
7335 Consumed,
7336 Unconsumed
7337 };
7338private:
7339 ConsumedState newState;
7340
7341public:
7342 static SetTypestateAttr *CreateImplicit(ASTContext &Ctx, ConsumedState NewState, SourceRange Loc = SourceRange()) {
7343 auto *A = new (Ctx) SetTypestateAttr(Loc, Ctx, NewState, 0);
7344 A->setImplicit(true);
7345 return A;
7346 }
7347
7348 SetTypestateAttr(SourceRange R, ASTContext &Ctx
7349 , ConsumedState NewState
7350 , unsigned SI
7351 )
7352 : InheritableAttr(attr::SetTypestate, R, SI, false, false)
7353 , newState(NewState)
7354 {
7355 }
7356
7357 SetTypestateAttr *clone(ASTContext &C) const;
7358 void printPretty(raw_ostream &OS,
7359 const PrintingPolicy &Policy) const;
7360 const char *getSpelling() const;
7361 ConsumedState getNewState() const {
7362 return newState;
7363 }
7364
7365 static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) {
7366 Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val)
7367 .Case("unknown", SetTypestateAttr::Unknown)
7368 .Case("consumed", SetTypestateAttr::Consumed)
7369 .Case("unconsumed", SetTypestateAttr::Unconsumed)
7370 .Default(Optional<ConsumedState>());
7371 if (R) {
7372 Out = *R;
7373 return true;
7374 }
7375 return false;
7376 }
7377
7378 static const char *ConvertConsumedStateToStr(ConsumedState Val) {
7379 switch(Val) {
7380 case SetTypestateAttr::Unknown: return "unknown";
7381 case SetTypestateAttr::Consumed: return "consumed";
7382 case SetTypestateAttr::Unconsumed: return "unconsumed";
7383 }
7384 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 7384)
;
7385 }
7386
7387
7388 static bool classof(const Attr *A) { return A->getKind() == attr::SetTypestate; }
7389};
7390
7391class SharedTrylockFunctionAttr : public InheritableAttr {
7392Expr * successValue;
7393
7394 unsigned args_Size;
7395 Expr * *args_;
7396
7397public:
7398 static SharedTrylockFunctionAttr *CreateImplicit(ASTContext &Ctx, Expr * SuccessValue, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
7399 auto *A = new (Ctx) SharedTrylockFunctionAttr(Loc, Ctx, SuccessValue, Args, ArgsSize, 0);
7400 A->setImplicit(true);
7401 return A;
7402 }
7403
7404 SharedTrylockFunctionAttr(SourceRange R, ASTContext &Ctx
7405 , Expr * SuccessValue
7406 , Expr * *Args, unsigned ArgsSize
7407 , unsigned SI
7408 )
7409 : InheritableAttr(attr::SharedTrylockFunction, R, SI, true, true)
7410 , successValue(SuccessValue)
7411 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
7412 {
7413 std::copy(Args, Args + args_Size, args_);
7414 }
7415
7416 SharedTrylockFunctionAttr(SourceRange R, ASTContext &Ctx
7417 , Expr * SuccessValue
7418 , unsigned SI
7419 )
7420 : InheritableAttr(attr::SharedTrylockFunction, R, SI, true, true)
7421 , successValue(SuccessValue)
7422 , args_Size(0), args_(nullptr)
7423 {
7424 }
7425
7426 SharedTrylockFunctionAttr *clone(ASTContext &C) const;
7427 void printPretty(raw_ostream &OS,
7428 const PrintingPolicy &Policy) const;
7429 const char *getSpelling() const;
7430 Expr * getSuccessValue() const {
7431 return successValue;
7432 }
7433
7434 typedef Expr ** args_iterator;
7435 args_iterator args_begin() const { return args_; }
7436 args_iterator args_end() const { return args_ + args_Size; }
7437 unsigned args_size() const { return args_Size; }
7438 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
7439
7440
7441
7442
7443 static bool classof(const Attr *A) { return A->getKind() == attr::SharedTrylockFunction; }
7444};
7445
7446class StdCallAttr : public InheritableAttr {
7447public:
7448 static StdCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7449 auto *A = new (Ctx) StdCallAttr(Loc, Ctx, 0);
7450 A->setImplicit(true);
7451 return A;
7452 }
7453
7454 StdCallAttr(SourceRange R, ASTContext &Ctx
7455 , unsigned SI
7456 )
7457 : InheritableAttr(attr::StdCall, R, SI, false, false)
7458 {
7459 }
7460
7461 StdCallAttr *clone(ASTContext &C) const;
7462 void printPretty(raw_ostream &OS,
7463 const PrintingPolicy &Policy) const;
7464 const char *getSpelling() const;
7465
7466
7467 static bool classof(const Attr *A) { return A->getKind() == attr::StdCall; }
7468};
7469
7470class SuppressAttr : public StmtAttr {
7471 unsigned diagnosticIdentifiers_Size;
7472 StringRef *diagnosticIdentifiers_;
7473
7474public:
7475 static SuppressAttr *CreateImplicit(ASTContext &Ctx, StringRef *DiagnosticIdentifiers, unsigned DiagnosticIdentifiersSize, SourceRange Loc = SourceRange()) {
7476 auto *A = new (Ctx) SuppressAttr(Loc, Ctx, DiagnosticIdentifiers, DiagnosticIdentifiersSize, 0);
7477 A->setImplicit(true);
7478 return A;
7479 }
7480
7481 SuppressAttr(SourceRange R, ASTContext &Ctx
7482 , StringRef *DiagnosticIdentifiers, unsigned DiagnosticIdentifiersSize
7483 , unsigned SI
7484 )
7485 : StmtAttr(attr::Suppress, R, SI, false)
7486 , diagnosticIdentifiers_Size(DiagnosticIdentifiersSize), diagnosticIdentifiers_(new (Ctx, 16) StringRef[diagnosticIdentifiers_Size])
7487 {
7488 for (size_t I = 0, E = diagnosticIdentifiers_Size; I != E;
7489 ++I) {
7490 StringRef Ref = DiagnosticIdentifiers[I];
7491 if (!Ref.empty()) {
7492 char *Mem = new (Ctx, 1) char[Ref.size()];
7493 std::memcpy(Mem, Ref.data(), Ref.size());
7494 diagnosticIdentifiers_[I] = StringRef(Mem, Ref.size());
7495 }
7496 }
7497 }
7498
7499 SuppressAttr(SourceRange R, ASTContext &Ctx
7500 , unsigned SI
7501 )
7502 : StmtAttr(attr::Suppress, R, SI, false)
7503 , diagnosticIdentifiers_Size(0), diagnosticIdentifiers_(nullptr)
7504 {
7505 }
7506
7507 SuppressAttr *clone(ASTContext &C) const;
7508 void printPretty(raw_ostream &OS,
7509 const PrintingPolicy &Policy) const;
7510 const char *getSpelling() const;
7511 typedef StringRef* diagnosticIdentifiers_iterator;
7512 diagnosticIdentifiers_iterator diagnosticIdentifiers_begin() const { return diagnosticIdentifiers_; }
7513 diagnosticIdentifiers_iterator diagnosticIdentifiers_end() const { return diagnosticIdentifiers_ + diagnosticIdentifiers_Size; }
7514 unsigned diagnosticIdentifiers_size() const { return diagnosticIdentifiers_Size; }
7515 llvm::iterator_range<diagnosticIdentifiers_iterator> diagnosticIdentifiers() const { return llvm::make_range(diagnosticIdentifiers_begin(), diagnosticIdentifiers_end()); }
7516
7517
7518
7519
7520 static bool classof(const Attr *A) { return A->getKind() == attr::Suppress; }
7521};
7522
7523class SwiftCallAttr : public InheritableAttr {
7524public:
7525 static SwiftCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7526 auto *A = new (Ctx) SwiftCallAttr(Loc, Ctx, 0);
7527 A->setImplicit(true);
7528 return A;
7529 }
7530
7531 SwiftCallAttr(SourceRange R, ASTContext &Ctx
7532 , unsigned SI
7533 )
7534 : InheritableAttr(attr::SwiftCall, R, SI, false, false)
7535 {
7536 }
7537
7538 SwiftCallAttr *clone(ASTContext &C) const;
7539 void printPretty(raw_ostream &OS,
7540 const PrintingPolicy &Policy) const;
7541 const char *getSpelling() const;
7542
7543
7544 static bool classof(const Attr *A) { return A->getKind() == attr::SwiftCall; }
7545};
7546
7547class SwiftContextAttr : public ParameterABIAttr {
7548public:
7549 static SwiftContextAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7550 auto *A = new (Ctx) SwiftContextAttr(Loc, Ctx, 0);
7551 A->setImplicit(true);
7552 return A;
7553 }
7554
7555 SwiftContextAttr(SourceRange R, ASTContext &Ctx
7556 , unsigned SI
7557 )
7558 : ParameterABIAttr(attr::SwiftContext, R, SI, false, false)
7559 {
7560 }
7561
7562 SwiftContextAttr *clone(ASTContext &C) const;
7563 void printPretty(raw_ostream &OS,
7564 const PrintingPolicy &Policy) const;
7565 const char *getSpelling() const;
7566
7567
7568 static bool classof(const Attr *A) { return A->getKind() == attr::SwiftContext; }
7569};
7570
7571class SwiftErrorResultAttr : public ParameterABIAttr {
7572public:
7573 static SwiftErrorResultAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7574 auto *A = new (Ctx) SwiftErrorResultAttr(Loc, Ctx, 0);
7575 A->setImplicit(true);
7576 return A;
7577 }
7578
7579 SwiftErrorResultAttr(SourceRange R, ASTContext &Ctx
7580 , unsigned SI
7581 )
7582 : ParameterABIAttr(attr::SwiftErrorResult, R, SI, false, false)
7583 {
7584 }
7585
7586 SwiftErrorResultAttr *clone(ASTContext &C) const;
7587 void printPretty(raw_ostream &OS,
7588 const PrintingPolicy &Policy) const;
7589 const char *getSpelling() const;
7590
7591
7592 static bool classof(const Attr *A) { return A->getKind() == attr::SwiftErrorResult; }
7593};
7594
7595class SwiftIndirectResultAttr : public ParameterABIAttr {
7596public:
7597 static SwiftIndirectResultAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7598 auto *A = new (Ctx) SwiftIndirectResultAttr(Loc, Ctx, 0);
7599 A->setImplicit(true);
7600 return A;
7601 }
7602
7603 SwiftIndirectResultAttr(SourceRange R, ASTContext &Ctx
7604 , unsigned SI
7605 )
7606 : ParameterABIAttr(attr::SwiftIndirectResult, R, SI, false, false)
7607 {
7608 }
7609
7610 SwiftIndirectResultAttr *clone(ASTContext &C) const;
7611 void printPretty(raw_ostream &OS,
7612 const PrintingPolicy &Policy) const;
7613 const char *getSpelling() const;
7614
7615
7616 static bool classof(const Attr *A) { return A->getKind() == attr::SwiftIndirectResult; }
7617};
7618
7619class SysVABIAttr : public InheritableAttr {
7620public:
7621 static SysVABIAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7622 auto *A = new (Ctx) SysVABIAttr(Loc, Ctx, 0);
7623 A->setImplicit(true);
7624 return A;
7625 }
7626
7627 SysVABIAttr(SourceRange R, ASTContext &Ctx
7628 , unsigned SI
7629 )
7630 : InheritableAttr(attr::SysVABI, R, SI, false, false)
7631 {
7632 }
7633
7634 SysVABIAttr *clone(ASTContext &C) const;
7635 void printPretty(raw_ostream &OS,
7636 const PrintingPolicy &Policy) const;
7637 const char *getSpelling() const;
7638
7639
7640 static bool classof(const Attr *A) { return A->getKind() == attr::SysVABI; }
7641};
7642
7643class TLSModelAttr : public InheritableAttr {
7644unsigned modelLength;
7645char *model;
7646
7647public:
7648 static TLSModelAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Model, SourceRange Loc = SourceRange()) {
7649 auto *A = new (Ctx) TLSModelAttr(Loc, Ctx, Model, 0);
7650 A->setImplicit(true);
7651 return A;
7652 }
7653
7654 TLSModelAttr(SourceRange R, ASTContext &Ctx
7655 , llvm::StringRef Model
7656 , unsigned SI
7657 )
7658 : InheritableAttr(attr::TLSModel, R, SI, false, false)
7659 , modelLength(Model.size()),model(new (Ctx, 1) char[modelLength])
7660 {
7661 if (!Model.empty())
7662 std::memcpy(model, Model.data(), modelLength);
7663 }
7664
7665 TLSModelAttr *clone(ASTContext &C) const;
7666 void printPretty(raw_ostream &OS,
7667 const PrintingPolicy &Policy) const;
7668 const char *getSpelling() const;
7669 llvm::StringRef getModel() const {
7670 return llvm::StringRef(model, modelLength);
7671 }
7672 unsigned getModelLength() const {
7673 return modelLength;
7674 }
7675 void setModel(ASTContext &C, llvm::StringRef S) {
7676 modelLength = S.size();
7677 this->model = new (C, 1) char [modelLength];
7678 if (!S.empty())
7679 std::memcpy(this->model, S.data(), modelLength);
7680 }
7681
7682
7683
7684 static bool classof(const Attr *A) { return A->getKind() == attr::TLSModel; }
7685};
7686
7687class TargetAttr : public InheritableAttr {
7688unsigned featuresStrLength;
7689char *featuresStr;
7690
7691public:
7692 static TargetAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef FeaturesStr, SourceRange Loc = SourceRange()) {
7693 auto *A = new (Ctx) TargetAttr(Loc, Ctx, FeaturesStr, 0);
7694 A->setImplicit(true);
7695 return A;
7696 }
7697
7698 TargetAttr(SourceRange R, ASTContext &Ctx
7699 , llvm::StringRef FeaturesStr
7700 , unsigned SI
7701 )
7702 : InheritableAttr(attr::Target, R, SI, false, false)
7703 , featuresStrLength(FeaturesStr.size()),featuresStr(new (Ctx, 1) char[featuresStrLength])
7704 {
7705 if (!FeaturesStr.empty())
7706 std::memcpy(featuresStr, FeaturesStr.data(), featuresStrLength);
7707 }
7708
7709 TargetAttr *clone(ASTContext &C) const;
7710 void printPretty(raw_ostream &OS,
7711 const PrintingPolicy &Policy) const;
7712 const char *getSpelling() const;
7713 llvm::StringRef getFeaturesStr() const {
7714 return llvm::StringRef(featuresStr, featuresStrLength);
7715 }
7716 unsigned getFeaturesStrLength() const {
7717 return featuresStrLength;
7718 }
7719 void setFeaturesStr(ASTContext &C, llvm::StringRef S) {
7720 featuresStrLength = S.size();
7721 this->featuresStr = new (C, 1) char [featuresStrLength];
7722 if (!S.empty())
7723 std::memcpy(this->featuresStr, S.data(), featuresStrLength);
7724 }
7725
7726
7727 struct ParsedTargetAttr {
7728 std::vector<std::string> Features;
7729 StringRef Architecture;
7730 bool DuplicateArchitecture = false;
7731 bool operator ==(const ParsedTargetAttr &Other) const {
7732 return DuplicateArchitecture == Other.DuplicateArchitecture &&
7733 Architecture == Other.Architecture && Features == Other.Features;
7734 }
7735 };
7736 ParsedTargetAttr parse() const {
7737 return parse(getFeaturesStr());
7738 }
7739
7740 template<class Compare>
7741 ParsedTargetAttr parse(Compare cmp) const {
7742 ParsedTargetAttr Attrs = parse();
7743 llvm::sort(std::begin(Attrs.Features), std::end(Attrs.Features), cmp);
7744 return Attrs;
7745 }
7746
7747 bool isDefaultVersion() const { return getFeaturesStr() == "default"; }
7748
7749 static ParsedTargetAttr parse(StringRef Features) {
7750 ParsedTargetAttr Ret;
7751 if (Features == "default") return Ret;
7752 SmallVector<StringRef, 1> AttrFeatures;
7753 Features.split(AttrFeatures, ",");
7754
7755 // Grab the various features and prepend a "+" to turn on the feature to
7756 // the backend and add them to our existing set of features.
7757 for (auto &Feature : AttrFeatures) {
7758 // Go ahead and trim whitespace rather than either erroring or
7759 // accepting it weirdly.
7760 Feature = Feature.trim();
7761
7762 // We don't support cpu tuning this way currently.
7763 // TODO: Support the fpmath option. It will require checking
7764 // overall feature validity for the function with the rest of the
7765 // attributes on the function.
7766 if (Feature.startswith("fpmath=") || Feature.startswith("tune="))
7767 continue;
7768
7769 // While we're here iterating check for a different target cpu.
7770 if (Feature.startswith("arch=")) {
7771 if (!Ret.Architecture.empty())
7772 Ret.DuplicateArchitecture = true;
7773 else
7774 Ret.Architecture = Feature.split("=").second.trim();
7775 } else if (Feature.startswith("no-"))
7776 Ret.Features.push_back("-" + Feature.split("-").second.str());
7777 else
7778 Ret.Features.push_back("+" + Feature.str());
7779 }
7780 return Ret;
7781 }
7782
7783
7784 static bool classof(const Attr *A) { return A->getKind() == attr::Target; }
7785};
7786
7787class TestTypestateAttr : public InheritableAttr {
7788public:
7789 enum ConsumedState {
7790 Consumed,
7791 Unconsumed
7792 };
7793private:
7794 ConsumedState testState;
7795
7796public:
7797 static TestTypestateAttr *CreateImplicit(ASTContext &Ctx, ConsumedState TestState, SourceRange Loc = SourceRange()) {
7798 auto *A = new (Ctx) TestTypestateAttr(Loc, Ctx, TestState, 0);
7799 A->setImplicit(true);
7800 return A;
7801 }
7802
7803 TestTypestateAttr(SourceRange R, ASTContext &Ctx
7804 , ConsumedState TestState
7805 , unsigned SI
7806 )
7807 : InheritableAttr(attr::TestTypestate, R, SI, false, false)
7808 , testState(TestState)
7809 {
7810 }
7811
7812 TestTypestateAttr *clone(ASTContext &C) const;
7813 void printPretty(raw_ostream &OS,
7814 const PrintingPolicy &Policy) const;
7815 const char *getSpelling() const;
7816 ConsumedState getTestState() const {
7817 return testState;
7818 }
7819
7820 static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) {
7821 Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val)
7822 .Case("consumed", TestTypestateAttr::Consumed)
7823 .Case("unconsumed", TestTypestateAttr::Unconsumed)
7824 .Default(Optional<ConsumedState>());
7825 if (R) {
7826 Out = *R;
7827 return true;
7828 }
7829 return false;
7830 }
7831
7832 static const char *ConvertConsumedStateToStr(ConsumedState Val) {
7833 switch(Val) {
7834 case TestTypestateAttr::Consumed: return "consumed";
7835 case TestTypestateAttr::Unconsumed: return "unconsumed";
7836 }
7837 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 7837)
;
7838 }
7839
7840
7841 static bool classof(const Attr *A) { return A->getKind() == attr::TestTypestate; }
7842};
7843
7844class ThisCallAttr : public InheritableAttr {
7845public:
7846 static ThisCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7847 auto *A = new (Ctx) ThisCallAttr(Loc, Ctx, 0);
7848 A->setImplicit(true);
7849 return A;
7850 }
7851
7852 ThisCallAttr(SourceRange R, ASTContext &Ctx
7853 , unsigned SI
7854 )
7855 : InheritableAttr(attr::ThisCall, R, SI, false, false)
7856 {
7857 }
7858
7859 ThisCallAttr *clone(ASTContext &C) const;
7860 void printPretty(raw_ostream &OS,
7861 const PrintingPolicy &Policy) const;
7862 const char *getSpelling() const;
7863
7864
7865 static bool classof(const Attr *A) { return A->getKind() == attr::ThisCall; }
7866};
7867
7868class ThreadAttr : public Attr {
7869public:
7870 static ThreadAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7871 auto *A = new (Ctx) ThreadAttr(Loc, Ctx, 0);
7872 A->setImplicit(true);
7873 return A;
7874 }
7875
7876 ThreadAttr(SourceRange R, ASTContext &Ctx
7877 , unsigned SI
7878 )
7879 : Attr(attr::Thread, R, SI, false)
7880 {
7881 }
7882
7883 ThreadAttr *clone(ASTContext &C) const;
7884 void printPretty(raw_ostream &OS,
7885 const PrintingPolicy &Policy) const;
7886 const char *getSpelling() const;
7887
7888
7889 static bool classof(const Attr *A) { return A->getKind() == attr::Thread; }
7890};
7891
7892class TransparentUnionAttr : public InheritableAttr {
7893public:
7894 static TransparentUnionAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7895 auto *A = new (Ctx) TransparentUnionAttr(Loc, Ctx, 0);
7896 A->setImplicit(true);
7897 return A;
7898 }
7899
7900 TransparentUnionAttr(SourceRange R, ASTContext &Ctx
7901 , unsigned SI
7902 )
7903 : InheritableAttr(attr::TransparentUnion, R, SI, false, false)
7904 {
7905 }
7906
7907 TransparentUnionAttr *clone(ASTContext &C) const;
7908 void printPretty(raw_ostream &OS,
7909 const PrintingPolicy &Policy) const;
7910 const char *getSpelling() const;
7911
7912
7913 static bool classof(const Attr *A) { return A->getKind() == attr::TransparentUnion; }
7914};
7915
7916class TrivialABIAttr : public InheritableAttr {
7917public:
7918 static TrivialABIAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7919 auto *A = new (Ctx) TrivialABIAttr(Loc, Ctx, 0);
7920 A->setImplicit(true);
7921 return A;
7922 }
7923
7924 TrivialABIAttr(SourceRange R, ASTContext &Ctx
7925 , unsigned SI
7926 )
7927 : InheritableAttr(attr::TrivialABI, R, SI, false, false)
7928 {
7929 }
7930
7931 TrivialABIAttr *clone(ASTContext &C) const;
7932 void printPretty(raw_ostream &OS,
7933 const PrintingPolicy &Policy) const;
7934 const char *getSpelling() const;
7935
7936
7937 static bool classof(const Attr *A) { return A->getKind() == attr::TrivialABI; }
7938};
7939
7940class TryAcquireCapabilityAttr : public InheritableAttr {
7941Expr * successValue;
7942
7943 unsigned args_Size;
7944 Expr * *args_;
7945
7946public:
7947 enum Spelling {
7948 GNU_try_acquire_capability = 0,
7949 CXX11_clang_try_acquire_capability = 1,
7950 GNU_try_acquire_shared_capability = 2,
7951 CXX11_clang_try_acquire_shared_capability = 3
7952 };
7953
7954 static TryAcquireCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * SuccessValue, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
7955 auto *A = new (Ctx) TryAcquireCapabilityAttr(Loc, Ctx, SuccessValue, Args, ArgsSize, S);
7956 A->setImplicit(true);
7957 return A;
7958 }
7959
7960 TryAcquireCapabilityAttr(SourceRange R, ASTContext &Ctx
7961 , Expr * SuccessValue
7962 , Expr * *Args, unsigned ArgsSize
7963 , unsigned SI
7964 )
7965 : InheritableAttr(attr::TryAcquireCapability, R, SI, true, true)
7966 , successValue(SuccessValue)
7967 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
7968 {
7969 std::copy(Args, Args + args_Size, args_);
7970 }
7971
7972 TryAcquireCapabilityAttr(SourceRange R, ASTContext &Ctx
7973 , Expr * SuccessValue
7974 , unsigned SI
7975 )
7976 : InheritableAttr(attr::TryAcquireCapability, R, SI, true, true)
7977 , successValue(SuccessValue)
7978 , args_Size(0), args_(nullptr)
7979 {
7980 }
7981
7982 TryAcquireCapabilityAttr *clone(ASTContext &C) const;
7983 void printPretty(raw_ostream &OS,
7984 const PrintingPolicy &Policy) const;
7985 const char *getSpelling() const;
7986 Spelling getSemanticSpelling() const {
7987 switch (SpellingListIndex) {
7988 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 7988)
;
7989 case 0: return GNU_try_acquire_capability;
7990 case 1: return CXX11_clang_try_acquire_capability;
7991 case 2: return GNU_try_acquire_shared_capability;
7992 case 3: return CXX11_clang_try_acquire_shared_capability;
7993 }
7994 }
7995 bool isShared() const { return SpellingListIndex == 2 ||
7996 SpellingListIndex == 3; }
7997 Expr * getSuccessValue() const {
7998 return successValue;
7999 }
8000
8001 typedef Expr ** args_iterator;
8002 args_iterator args_begin() const { return args_; }
8003 args_iterator args_end() const { return args_ + args_Size; }
8004 unsigned args_size() const { return args_Size; }
8005 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
8006
8007
8008
8009
8010 static bool classof(const Attr *A) { return A->getKind() == attr::TryAcquireCapability; }
8011};
8012
8013class TypeTagForDatatypeAttr : public InheritableAttr {
8014IdentifierInfo * argumentKind;
8015
8016TypeSourceInfo * matchingCType;
8017
8018bool layoutCompatible;
8019
8020bool mustBeNull;
8021
8022public:
8023 static TypeTagForDatatypeAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * ArgumentKind, TypeSourceInfo * MatchingCType, bool LayoutCompatible, bool MustBeNull, SourceRange Loc = SourceRange()) {
8024 auto *A = new (Ctx) TypeTagForDatatypeAttr(Loc, Ctx, ArgumentKind, MatchingCType, LayoutCompatible, MustBeNull, 0);
8025 A->setImplicit(true);
8026 return A;
8027 }
8028
8029 TypeTagForDatatypeAttr(SourceRange R, ASTContext &Ctx
8030 , IdentifierInfo * ArgumentKind
8031 , TypeSourceInfo * MatchingCType
8032 , bool LayoutCompatible
8033 , bool MustBeNull
8034 , unsigned SI
8035 )
8036 : InheritableAttr(attr::TypeTagForDatatype, R, SI, false, false)
8037 , argumentKind(ArgumentKind)
8038 , matchingCType(MatchingCType)
8039 , layoutCompatible(LayoutCompatible)
8040 , mustBeNull(MustBeNull)
8041 {
8042 }
8043
8044 TypeTagForDatatypeAttr *clone(ASTContext &C) const;
8045 void printPretty(raw_ostream &OS,
8046 const PrintingPolicy &Policy) const;
8047 const char *getSpelling() const;
8048 IdentifierInfo * getArgumentKind() const {
8049 return argumentKind;
8050 }
8051
8052 QualType getMatchingCType() const {
8053 return matchingCType->getType();
8054 } TypeSourceInfo * getMatchingCTypeLoc() const {
8055 return matchingCType;
8056 }
8057
8058 bool getLayoutCompatible() const {
8059 return layoutCompatible;
8060 }
8061
8062 bool getMustBeNull() const {
8063 return mustBeNull;
8064 }
8065
8066
8067
8068 static bool classof(const Attr *A) { return A->getKind() == attr::TypeTagForDatatype; }
8069};
8070
8071class TypeVisibilityAttr : public InheritableAttr {
8072public:
8073 enum VisibilityType {
8074 Default,
8075 Hidden,
8076 Protected
8077 };
8078private:
8079 VisibilityType visibility;
8080
8081public:
8082 static TypeVisibilityAttr *CreateImplicit(ASTContext &Ctx, VisibilityType Visibility, SourceRange Loc = SourceRange()) {
8083 auto *A = new (Ctx) TypeVisibilityAttr(Loc, Ctx, Visibility, 0);
8084 A->setImplicit(true);
8085 return A;
8086 }
8087
8088 TypeVisibilityAttr(SourceRange R, ASTContext &Ctx
8089 , VisibilityType Visibility
8090 , unsigned SI
8091 )
8092 : InheritableAttr(attr::TypeVisibility, R, SI, false, false)
8093 , visibility(Visibility)
8094 {
8095 }
8096
8097 TypeVisibilityAttr *clone(ASTContext &C) const;
8098 void printPretty(raw_ostream &OS,
8099 const PrintingPolicy &Policy) const;
8100 const char *getSpelling() const;
8101 VisibilityType getVisibility() const {
8102 return visibility;
8103 }
8104
8105 static bool ConvertStrToVisibilityType(StringRef Val, VisibilityType &Out) {
8106 Optional<VisibilityType> R = llvm::StringSwitch<Optional<VisibilityType>>(Val)
8107 .Case("default", TypeVisibilityAttr::Default)
8108 .Case("hidden", TypeVisibilityAttr::Hidden)
8109 .Case("internal", TypeVisibilityAttr::Hidden)
8110 .Case("protected", TypeVisibilityAttr::Protected)
8111 .Default(Optional<VisibilityType>());
8112 if (R) {
8113 Out = *R;
8114 return true;
8115 }
8116 return false;
8117 }
8118
8119 static const char *ConvertVisibilityTypeToStr(VisibilityType Val) {
8120 switch(Val) {
8121 case TypeVisibilityAttr::Default: return "default";
8122 case TypeVisibilityAttr::Hidden: return "hidden";
8123 case TypeVisibilityAttr::Protected: return "protected";
8124 }
8125 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 8125)
;
8126 }
8127
8128
8129 static bool classof(const Attr *A) { return A->getKind() == attr::TypeVisibility; }
8130};
8131
8132class UnavailableAttr : public InheritableAttr {
8133unsigned messageLength;
8134char *message;
8135
8136public:
8137 enum ImplicitReason {
8138 IR_None,
8139 IR_ARCForbiddenType,
8140 IR_ForbiddenWeak,
8141 IR_ARCForbiddenConversion,
8142 IR_ARCInitReturnsUnrelated,
8143 IR_ARCFieldWithOwnership
8144 };
8145private:
8146 ImplicitReason implicitReason;
8147
8148public:
8149 static UnavailableAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Message, ImplicitReason ImplicitReason, SourceRange Loc = SourceRange()) {
8150 auto *A = new (Ctx) UnavailableAttr(Loc, Ctx, Message, ImplicitReason, 0);
8151 A->setImplicit(true);
8152 return A;
8153 }
8154
8155 static UnavailableAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Message, SourceRange Loc = SourceRange()) {
8156 auto *A = new (Ctx) UnavailableAttr(Loc, Ctx, Message, 0);
8157 A->setImplicit(true);
8158 return A;
8159 }
8160
8161 UnavailableAttr(SourceRange R, ASTContext &Ctx
8162 , llvm::StringRef Message
8163 , ImplicitReason ImplicitReason
8164 , unsigned SI
8165 )
8166 : InheritableAttr(attr::Unavailable, R, SI, false, false)
8167 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
8168 , implicitReason(ImplicitReason)
8169 {
8170 if (!Message.empty())
8171 std::memcpy(message, Message.data(), messageLength);
8172 }
8173
8174 UnavailableAttr(SourceRange R, ASTContext &Ctx
8175 , llvm::StringRef Message
8176 , unsigned SI
8177 )
8178 : InheritableAttr(attr::Unavailable, R, SI, false, false)
8179 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
8180 , implicitReason(ImplicitReason(0))
8181 {
8182 if (!Message.empty())
8183 std::memcpy(message, Message.data(), messageLength);
8184 }
8185
8186 UnavailableAttr(SourceRange R, ASTContext &Ctx
8187 , unsigned SI
8188 )
8189 : InheritableAttr(attr::Unavailable, R, SI, false, false)
8190 , messageLength(0),message(nullptr)
8191 , implicitReason(ImplicitReason(0))
8192 {
8193 }
8194
8195 UnavailableAttr *clone(ASTContext &C) const;
8196 void printPretty(raw_ostream &OS,
8197 const PrintingPolicy &Policy) const;
8198 const char *getSpelling() const;
8199 llvm::StringRef getMessage() const {
8200 return llvm::StringRef(message, messageLength);
8201 }
8202 unsigned getMessageLength() const {
8203 return messageLength;
8204 }
8205 void setMessage(ASTContext &C, llvm::StringRef S) {
8206 messageLength = S.size();
8207 this->message = new (C, 1) char [messageLength];
8208 if (!S.empty())
8209 std::memcpy(this->message, S.data(), messageLength);
8210 }
8211
8212 ImplicitReason getImplicitReason() const {
8213 return implicitReason;
8214 }
8215
8216
8217
8218 static bool classof(const Attr *A) { return A->getKind() == attr::Unavailable; }
8219};
8220
8221class UnusedAttr : public InheritableAttr {
8222public:
8223 enum Spelling {
8224 CXX11_maybe_unused = 0,
8225 GNU_unused = 1,
8226 CXX11_gnu_unused = 2,
8227 C2x_maybe_unused = 3
8228 };
8229
8230 static UnusedAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
8231 auto *A = new (Ctx) UnusedAttr(Loc, Ctx, S);
8232 A->setImplicit(true);
8233 return A;
8234 }
8235
8236 UnusedAttr(SourceRange R, ASTContext &Ctx
8237 , unsigned SI
8238 )
8239 : InheritableAttr(attr::Unused, R, SI, false, false)
8240 {
8241 }
8242
8243 UnusedAttr *clone(ASTContext &C) const;
8244 void printPretty(raw_ostream &OS,
8245 const PrintingPolicy &Policy) const;
8246 const char *getSpelling() const;
8247 Spelling getSemanticSpelling() const {
8248 switch (SpellingListIndex) {
8249 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 8249)
;
8250 case 0: return CXX11_maybe_unused;
8251 case 1: return GNU_unused;
8252 case 2: return CXX11_gnu_unused;
8253 case 3: return C2x_maybe_unused;
8254 }
8255 }
8256
8257
8258 static bool classof(const Attr *A) { return A->getKind() == attr::Unused; }
8259};
8260
8261class UsedAttr : public InheritableAttr {
8262public:
8263 static UsedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
8264 auto *A = new (Ctx) UsedAttr(Loc, Ctx, 0);
8265 A->setImplicit(true);
8266 return A;
8267 }
8268
8269 UsedAttr(SourceRange R, ASTContext &Ctx
8270 , unsigned SI
8271 )
8272 : InheritableAttr(attr::Used, R, SI, false, false)
8273 {
8274 }
8275
8276 UsedAttr *clone(ASTContext &C) const;
8277 void printPretty(raw_ostream &OS,
8278 const PrintingPolicy &Policy) const;
8279 const char *getSpelling() const;
8280
8281
8282 static bool classof(const Attr *A) { return A->getKind() == attr::Used; }
8283};
8284
8285class UuidAttr : public InheritableAttr {
8286unsigned guidLength;
8287char *guid;
8288
8289public:
8290 static UuidAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Guid, SourceRange Loc = SourceRange()) {
8291 auto *A = new (Ctx) UuidAttr(Loc, Ctx, Guid, 0);
8292 A->setImplicit(true);
8293 return A;
8294 }
8295
8296 UuidAttr(SourceRange R, ASTContext &Ctx
8297 , llvm::StringRef Guid
8298 , unsigned SI
8299 )
8300 : InheritableAttr(attr::Uuid, R, SI, false, false)
8301 , guidLength(Guid.size()),guid(new (Ctx, 1) char[guidLength])
8302 {
8303 if (!Guid.empty())
8304 std::memcpy(guid, Guid.data(), guidLength);
8305 }
8306
8307 UuidAttr *clone(ASTContext &C) const;
8308 void printPretty(raw_ostream &OS,
8309 const PrintingPolicy &Policy) const;
8310 const char *getSpelling() const;
8311 llvm::StringRef getGuid() const {
8312 return llvm::StringRef(guid, guidLength);
8313 }
8314 unsigned getGuidLength() const {
8315 return guidLength;
8316 }
8317 void setGuid(ASTContext &C, llvm::StringRef S) {
8318 guidLength = S.size();
8319 this->guid = new (C, 1) char [guidLength];
8320 if (!S.empty())
8321 std::memcpy(this->guid, S.data(), guidLength);
8322 }
8323
8324
8325
8326 static bool classof(const Attr *A) { return A->getKind() == attr::Uuid; }
8327};
8328
8329class VecReturnAttr : public InheritableAttr {
8330public:
8331 static VecReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
8332 auto *A = new (Ctx) VecReturnAttr(Loc, Ctx, 0);
8333 A->setImplicit(true);
8334 return A;
8335 }
8336
8337 VecReturnAttr(SourceRange R, ASTContext &Ctx
8338 , unsigned SI
8339 )
8340 : InheritableAttr(attr::VecReturn, R, SI, false, false)
8341 {
8342 }
8343
8344 VecReturnAttr *clone(ASTContext &C) const;
8345 void printPretty(raw_ostream &OS,
8346 const PrintingPolicy &Policy) const;
8347 const char *getSpelling() const;
8348
8349
8350 static bool classof(const Attr *A) { return A->getKind() == attr::VecReturn; }
8351};
8352
8353class VecTypeHintAttr : public InheritableAttr {
8354TypeSourceInfo * typeHint;
8355
8356public:
8357 static VecTypeHintAttr *CreateImplicit(ASTContext &Ctx, TypeSourceInfo * TypeHint, SourceRange Loc = SourceRange()) {
8358 auto *A = new (Ctx) VecTypeHintAttr(Loc, Ctx, TypeHint, 0);
8359 A->setImplicit(true);
8360 return A;
8361 }
8362
8363 VecTypeHintAttr(SourceRange R, ASTContext &Ctx
8364 , TypeSourceInfo * TypeHint
8365 , unsigned SI
8366 )
8367 : InheritableAttr(attr::VecTypeHint, R, SI, false, false)
8368 , typeHint(TypeHint)
8369 {
8370 }
8371
8372 VecTypeHintAttr *clone(ASTContext &C) const;
8373 void printPretty(raw_ostream &OS,
8374 const PrintingPolicy &Policy) const;
8375 const char *getSpelling() const;
8376 QualType getTypeHint() const {
8377 return typeHint->getType();
8378 } TypeSourceInfo * getTypeHintLoc() const {
8379 return typeHint;
8380 }
8381
8382
8383
8384 static bool classof(const Attr *A) { return A->getKind() == attr::VecTypeHint; }
8385};
8386
8387class VectorCallAttr : public InheritableAttr {
8388public:
8389 static VectorCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
8390 auto *A = new (Ctx) VectorCallAttr(Loc, Ctx, 0);
8391 A->setImplicit(true);
8392 return A;
8393 }
8394
8395 VectorCallAttr(SourceRange R, ASTContext &Ctx
8396 , unsigned SI
8397 )
8398 : InheritableAttr(attr::VectorCall, R, SI, false, false)
8399 {
8400 }
8401
8402 VectorCallAttr *clone(ASTContext &C) const;
8403 void printPretty(raw_ostream &OS,
8404 const PrintingPolicy &Policy) const;
8405 const char *getSpelling() const;
8406
8407
8408 static bool classof(const Attr *A) { return A->getKind() == attr::VectorCall; }
8409};
8410
8411class VisibilityAttr : public InheritableAttr {
8412public:
8413 enum VisibilityType {
8414 Default,
8415 Hidden,
8416 Protected
8417 };
8418private:
8419 VisibilityType visibility;
8420
8421public:
8422 static VisibilityAttr *CreateImplicit(ASTContext &Ctx, VisibilityType Visibility, SourceRange Loc = SourceRange()) {
8423 auto *A = new (Ctx) VisibilityAttr(Loc, Ctx, Visibility, 0);
2
'A' initialized to a null pointer value
8424 A->setImplicit(true);
3
Called C++ object pointer is null
8425 return A;
8426 }
8427
8428 VisibilityAttr(SourceRange R, ASTContext &Ctx
8429 , VisibilityType Visibility
8430 , unsigned SI
8431 )
8432 : InheritableAttr(attr::Visibility, R, SI, false, false)
8433 , visibility(Visibility)
8434 {
8435 }
8436
8437 VisibilityAttr *clone(ASTContext &C) const;
8438 void printPretty(raw_ostream &OS,
8439 const PrintingPolicy &Policy) const;
8440 const char *getSpelling() const;
8441 VisibilityType getVisibility() const {
8442 return visibility;
8443 }
8444
8445 static bool ConvertStrToVisibilityType(StringRef Val, VisibilityType &Out) {
8446 Optional<VisibilityType> R = llvm::StringSwitch<Optional<VisibilityType>>(Val)
8447 .Case("default", VisibilityAttr::Default)
8448 .Case("hidden", VisibilityAttr::Hidden)
8449 .Case("internal", VisibilityAttr::Hidden)
8450 .Case("protected", VisibilityAttr::Protected)
8451 .Default(Optional<VisibilityType>());
8452 if (R) {
8453 Out = *R;
8454 return true;
8455 }
8456 return false;
8457 }
8458
8459 static const char *ConvertVisibilityTypeToStr(VisibilityType Val) {
8460 switch(Val) {
8461 case VisibilityAttr::Default: return "default";
8462 case VisibilityAttr::Hidden: return "hidden";
8463 case VisibilityAttr::Protected: return "protected";
8464 }
8465 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 8465)
;
8466 }
8467
8468
8469 static bool classof(const Attr *A) { return A->getKind() == attr::Visibility; }
8470};
8471
8472class WarnUnusedAttr : public InheritableAttr {
8473public:
8474 static WarnUnusedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
8475 auto *A = new (Ctx) WarnUnusedAttr(Loc, Ctx, 0);
8476 A->setImplicit(true);
8477 return A;
8478 }
8479
8480 WarnUnusedAttr(SourceRange R, ASTContext &Ctx
8481 , unsigned SI
8482 )
8483 : InheritableAttr(attr::WarnUnused, R, SI, false, false)
8484 {
8485 }
8486
8487 WarnUnusedAttr *clone(ASTContext &C) const;
8488 void printPretty(raw_ostream &OS,
8489 const PrintingPolicy &Policy) const;
8490 const char *getSpelling() const;
8491
8492
8493 static bool classof(const Attr *A) { return A->getKind() == attr::WarnUnused; }
8494};
8495
8496class WarnUnusedResultAttr : public InheritableAttr {
8497public:
8498 enum Spelling {
8499 CXX11_nodiscard = 0,
8500 C2x_nodiscard = 1,
8501 CXX11_clang_warn_unused_result = 2,
8502 GNU_warn_unused_result = 3,
8503 CXX11_gnu_warn_unused_result = 4
8504 };
8505
8506 static WarnUnusedResultAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
8507 auto *A = new (Ctx) WarnUnusedResultAttr(Loc, Ctx, S);
8508 A->setImplicit(true);
8509 return A;
8510 }
8511
8512 WarnUnusedResultAttr(SourceRange R, ASTContext &Ctx
8513 , unsigned SI
8514 )
8515 : InheritableAttr(attr::WarnUnusedResult, R, SI, false, false)
8516 {
8517 }
8518
8519 WarnUnusedResultAttr *clone(ASTContext &C) const;
8520 void printPretty(raw_ostream &OS,
8521 const PrintingPolicy &Policy) const;
8522 const char *getSpelling() const;
8523 Spelling getSemanticSpelling() const {
8524 switch (SpellingListIndex) {
8525 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 8525)
;
8526 case 0: return CXX11_nodiscard;
8527 case 1: return C2x_nodiscard;
8528 case 2: return CXX11_clang_warn_unused_result;
8529 case 3: return GNU_warn_unused_result;
8530 case 4: return CXX11_gnu_warn_unused_result;
8531 }
8532 }
8533
8534
8535 static bool classof(const Attr *A) { return A->getKind() == attr::WarnUnusedResult; }
8536};
8537
8538class WeakAttr : public InheritableAttr {
8539public:
8540 static WeakAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
8541 auto *A = new (Ctx) WeakAttr(Loc, Ctx, 0);
8542 A->setImplicit(true);
8543 return A;
8544 }
8545
8546 WeakAttr(SourceRange R, ASTContext &Ctx
8547 , unsigned SI
8548 )
8549 : InheritableAttr(attr::Weak, R, SI, false, false)
8550 {
8551 }
8552
8553 WeakAttr *clone(ASTContext &C) const;
8554 void printPretty(raw_ostream &OS,
8555 const PrintingPolicy &Policy) const;
8556 const char *getSpelling() const;
8557
8558
8559 static bool classof(const Attr *A) { return A->getKind() == attr::Weak; }
8560};
8561
8562class WeakImportAttr : public InheritableAttr {
8563public:
8564 static WeakImportAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
8565 auto *A = new (Ctx) WeakImportAttr(Loc, Ctx, 0);
8566 A->setImplicit(true);
8567 return A;
8568 }
8569
8570 WeakImportAttr(SourceRange R, ASTContext &Ctx
8571 , unsigned SI
8572 )
8573 : InheritableAttr(attr::WeakImport, R, SI, false, false)
8574 {
8575 }
8576
8577 WeakImportAttr *clone(ASTContext &C) const;
8578 void printPretty(raw_ostream &OS,
8579 const PrintingPolicy &Policy) const;
8580 const char *getSpelling() const;
8581
8582
8583 static bool classof(const Attr *A) { return A->getKind() == attr::WeakImport; }
8584};
8585
8586class WeakRefAttr : public InheritableAttr {
8587unsigned aliaseeLength;
8588char *aliasee;
8589
8590public:
8591 static WeakRefAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Aliasee, SourceRange Loc = SourceRange()) {
8592 auto *A = new (Ctx) WeakRefAttr(Loc, Ctx, Aliasee, 0);
8593 A->setImplicit(true);
8594 return A;
8595 }
8596
8597 WeakRefAttr(SourceRange R, ASTContext &Ctx
8598 , llvm::StringRef Aliasee
8599 , unsigned SI
8600 )
8601 : InheritableAttr(attr::WeakRef, R, SI, false, false)
8602 , aliaseeLength(Aliasee.size()),aliasee(new (Ctx, 1) char[aliaseeLength])
8603 {
8604 if (!Aliasee.empty())
8605 std::memcpy(aliasee, Aliasee.data(), aliaseeLength);
8606 }
8607
8608 WeakRefAttr(SourceRange R, ASTContext &Ctx
8609 , unsigned SI
8610 )
8611 : InheritableAttr(attr::WeakRef, R, SI, false, false)
8612 , aliaseeLength(0),aliasee(nullptr)
8613 {
8614 }
8615
8616 WeakRefAttr *clone(ASTContext &C) const;
8617 void printPretty(raw_ostream &OS,
8618 const PrintingPolicy &Policy) const;
8619 const char *getSpelling() const;
8620 llvm::StringRef getAliasee() const {
8621 return llvm::StringRef(aliasee, aliaseeLength);
8622 }
8623 unsigned getAliaseeLength() const {
8624 return aliaseeLength;
8625 }
8626 void setAliasee(ASTContext &C, llvm::StringRef S) {
8627 aliaseeLength = S.size();
8628 this->aliasee = new (C, 1) char [aliaseeLength];
8629 if (!S.empty())
8630 std::memcpy(this->aliasee, S.data(), aliaseeLength);
8631 }
8632
8633
8634
8635 static bool classof(const Attr *A) { return A->getKind() == attr::WeakRef; }
8636};
8637
8638class WorkGroupSizeHintAttr : public InheritableAttr {
8639unsigned xDim;
8640
8641unsigned yDim;
8642
8643unsigned zDim;
8644
8645public:
8646 static WorkGroupSizeHintAttr *CreateImplicit(ASTContext &Ctx, unsigned XDim, unsigned YDim, unsigned ZDim, SourceRange Loc = SourceRange()) {
8647 auto *A = new (Ctx) WorkGroupSizeHintAttr(Loc, Ctx, XDim, YDim, ZDim, 0);
8648 A->setImplicit(true);
8649 return A;
8650 }
8651
8652 WorkGroupSizeHintAttr(SourceRange R, ASTContext &Ctx
8653 , unsigned XDim
8654 , unsigned YDim
8655 , unsigned ZDim
8656 , unsigned SI
8657 )
8658 : InheritableAttr(attr::WorkGroupSizeHint, R, SI, false, false)
8659 , xDim(XDim)
8660 , yDim(YDim)
8661 , zDim(ZDim)
8662 {
8663 }
8664
8665 WorkGroupSizeHintAttr *clone(ASTContext &C) const;
8666 void printPretty(raw_ostream &OS,
8667 const PrintingPolicy &Policy) const;
8668 const char *getSpelling() const;
8669 unsigned getXDim() const {
8670 return xDim;
8671 }
8672
8673 unsigned getYDim() const {
8674 return yDim;
8675 }
8676
8677 unsigned getZDim() const {
8678 return zDim;
8679 }
8680
8681
8682
8683 static bool classof(const Attr *A) { return A->getKind() == attr::WorkGroupSizeHint; }
8684};
8685
8686class X86ForceAlignArgPointerAttr : public InheritableAttr {
8687public:
8688 static X86ForceAlignArgPointerAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
8689 auto *A = new (Ctx) X86ForceAlignArgPointerAttr(Loc, Ctx, 0);
8690 A->setImplicit(true);
8691 return A;
8692 }
8693
8694 X86ForceAlignArgPointerAttr(SourceRange R, ASTContext &Ctx
8695 , unsigned SI
8696 )
8697 : InheritableAttr(attr::X86ForceAlignArgPointer, R, SI, false, false)
8698 {
8699 }
8700
8701 X86ForceAlignArgPointerAttr *clone(ASTContext &C) const;
8702 void printPretty(raw_ostream &OS,
8703 const PrintingPolicy &Policy) const;
8704 const char *getSpelling() const;
8705
8706
8707 static bool classof(const Attr *A) { return A->getKind() == attr::X86ForceAlignArgPointer; }
8708};
8709
8710class XRayInstrumentAttr : public InheritableAttr {
8711public:
8712 enum Spelling {
8713 GNU_xray_always_instrument = 0,
8714 CXX11_clang_xray_always_instrument = 1,
8715 C2x_clang_xray_always_instrument = 2,
8716 GNU_xray_never_instrument = 3,
8717 CXX11_clang_xray_never_instrument = 4,
8718 C2x_clang_xray_never_instrument = 5
8719 };
8720
8721 static XRayInstrumentAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
8722 auto *A = new (Ctx) XRayInstrumentAttr(Loc, Ctx, S);
8723 A->setImplicit(true);
8724 return A;
8725 }
8726
8727 XRayInstrumentAttr(SourceRange R, ASTContext &Ctx
8728 , unsigned SI
8729 )
8730 : InheritableAttr(attr::XRayInstrument, R, SI, false, false)
8731 {
8732 }
8733
8734 XRayInstrumentAttr *clone(ASTContext &C) const;
8735 void printPretty(raw_ostream &OS,
8736 const PrintingPolicy &Policy) const;
8737 const char *getSpelling() const;
8738 Spelling getSemanticSpelling() const {
8739 switch (SpellingListIndex) {
8740 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 8740)
;
8741 case 0: return GNU_xray_always_instrument;
8742 case 1: return CXX11_clang_xray_always_instrument;
8743 case 2: return C2x_clang_xray_always_instrument;
8744 case 3: return GNU_xray_never_instrument;
8745 case 4: return CXX11_clang_xray_never_instrument;
8746 case 5: return C2x_clang_xray_never_instrument;
8747 }
8748 }
8749 bool alwaysXRayInstrument() const { return SpellingListIndex == 0 ||
8750 SpellingListIndex == 1 ||
8751 SpellingListIndex == 2; }
8752 bool neverXRayInstrument() const { return SpellingListIndex == 3 ||
8753 SpellingListIndex == 4 ||
8754 SpellingListIndex == 5; }
8755
8756
8757 static bool classof(const Attr *A) { return A->getKind() == attr::XRayInstrument; }
8758};
8759
8760class XRayLogArgsAttr : public InheritableAttr {
8761unsigned argumentCount;
8762
8763public:
8764 static XRayLogArgsAttr *CreateImplicit(ASTContext &Ctx, unsigned ArgumentCount, SourceRange Loc = SourceRange()) {
8765 auto *A = new (Ctx) XRayLogArgsAttr(Loc, Ctx, ArgumentCount, 0);
8766 A->setImplicit(true);
8767 return A;
8768 }
8769
8770 XRayLogArgsAttr(SourceRange R, ASTContext &Ctx
8771 , unsigned ArgumentCount
8772 , unsigned SI
8773 )
8774 : InheritableAttr(attr::XRayLogArgs, R, SI, false, false)
8775 , argumentCount(ArgumentCount)
8776 {
8777 }
8778
8779 XRayLogArgsAttr *clone(ASTContext &C) const;
8780 void printPretty(raw_ostream &OS,
8781 const PrintingPolicy &Policy) const;
8782 const char *getSpelling() const;
8783 unsigned getArgumentCount() const {
8784 return argumentCount;
8785 }
8786
8787
8788
8789 static bool classof(const Attr *A) { return A->getKind() == attr::XRayLogArgs; }
8790};
8791
8792#endif // LLVM_CLANG_ATTR_CLASSES_INC