File: | tools/clang/lib/AST/ASTContext.cpp |
Warning: | line 10320, column 24 Potential leak of memory pointed to by 'Vector' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===- ASTContext.cpp - Context to hold long-lived AST nodes --------------===// | |||
2 | // | |||
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |||
4 | // See https://llvm.org/LICENSE.txt for license information. | |||
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |||
6 | // | |||
7 | //===----------------------------------------------------------------------===// | |||
8 | // | |||
9 | // This file implements the ASTContext interface. | |||
10 | // | |||
11 | //===----------------------------------------------------------------------===// | |||
12 | ||||
13 | #include "clang/AST/ASTContext.h" | |||
14 | #include "CXXABI.h" | |||
15 | #include "clang/AST/APValue.h" | |||
16 | #include "clang/AST/ASTMutationListener.h" | |||
17 | #include "clang/AST/ASTTypeTraits.h" | |||
18 | #include "clang/AST/Attr.h" | |||
19 | #include "clang/AST/AttrIterator.h" | |||
20 | #include "clang/AST/CharUnits.h" | |||
21 | #include "clang/AST/Comment.h" | |||
22 | #include "clang/AST/Decl.h" | |||
23 | #include "clang/AST/DeclBase.h" | |||
24 | #include "clang/AST/DeclCXX.h" | |||
25 | #include "clang/AST/DeclContextInternals.h" | |||
26 | #include "clang/AST/DeclObjC.h" | |||
27 | #include "clang/AST/DeclOpenMP.h" | |||
28 | #include "clang/AST/DeclTemplate.h" | |||
29 | #include "clang/AST/DeclarationName.h" | |||
30 | #include "clang/AST/Expr.h" | |||
31 | #include "clang/AST/ExprCXX.h" | |||
32 | #include "clang/AST/ExternalASTSource.h" | |||
33 | #include "clang/AST/Mangle.h" | |||
34 | #include "clang/AST/MangleNumberingContext.h" | |||
35 | #include "clang/AST/NestedNameSpecifier.h" | |||
36 | #include "clang/AST/RawCommentList.h" | |||
37 | #include "clang/AST/RecordLayout.h" | |||
38 | #include "clang/AST/RecursiveASTVisitor.h" | |||
39 | #include "clang/AST/Stmt.h" | |||
40 | #include "clang/AST/TemplateBase.h" | |||
41 | #include "clang/AST/TemplateName.h" | |||
42 | #include "clang/AST/Type.h" | |||
43 | #include "clang/AST/TypeLoc.h" | |||
44 | #include "clang/AST/UnresolvedSet.h" | |||
45 | #include "clang/AST/VTableBuilder.h" | |||
46 | #include "clang/Basic/AddressSpaces.h" | |||
47 | #include "clang/Basic/Builtins.h" | |||
48 | #include "clang/Basic/CommentOptions.h" | |||
49 | #include "clang/Basic/ExceptionSpecificationType.h" | |||
50 | #include "clang/Basic/FixedPoint.h" | |||
51 | #include "clang/Basic/IdentifierTable.h" | |||
52 | #include "clang/Basic/LLVM.h" | |||
53 | #include "clang/Basic/LangOptions.h" | |||
54 | #include "clang/Basic/Linkage.h" | |||
55 | #include "clang/Basic/ObjCRuntime.h" | |||
56 | #include "clang/Basic/SanitizerBlacklist.h" | |||
57 | #include "clang/Basic/SourceLocation.h" | |||
58 | #include "clang/Basic/SourceManager.h" | |||
59 | #include "clang/Basic/Specifiers.h" | |||
60 | #include "clang/Basic/TargetCXXABI.h" | |||
61 | #include "clang/Basic/TargetInfo.h" | |||
62 | #include "clang/Basic/XRayLists.h" | |||
63 | #include "llvm/ADT/APInt.h" | |||
64 | #include "llvm/ADT/APSInt.h" | |||
65 | #include "llvm/ADT/ArrayRef.h" | |||
66 | #include "llvm/ADT/DenseMap.h" | |||
67 | #include "llvm/ADT/DenseSet.h" | |||
68 | #include "llvm/ADT/FoldingSet.h" | |||
69 | #include "llvm/ADT/None.h" | |||
70 | #include "llvm/ADT/Optional.h" | |||
71 | #include "llvm/ADT/PointerUnion.h" | |||
72 | #include "llvm/ADT/STLExtras.h" | |||
73 | #include "llvm/ADT/SmallPtrSet.h" | |||
74 | #include "llvm/ADT/SmallVector.h" | |||
75 | #include "llvm/ADT/StringExtras.h" | |||
76 | #include "llvm/ADT/StringRef.h" | |||
77 | #include "llvm/ADT/Triple.h" | |||
78 | #include "llvm/Support/Capacity.h" | |||
79 | #include "llvm/Support/Casting.h" | |||
80 | #include "llvm/Support/Compiler.h" | |||
81 | #include "llvm/Support/ErrorHandling.h" | |||
82 | #include "llvm/Support/MathExtras.h" | |||
83 | #include "llvm/Support/raw_ostream.h" | |||
84 | #include <algorithm> | |||
85 | #include <cassert> | |||
86 | #include <cstddef> | |||
87 | #include <cstdint> | |||
88 | #include <cstdlib> | |||
89 | #include <map> | |||
90 | #include <memory> | |||
91 | #include <string> | |||
92 | #include <tuple> | |||
93 | #include <utility> | |||
94 | ||||
95 | using namespace clang; | |||
96 | ||||
97 | enum FloatingRank { | |||
98 | Float16Rank, HalfRank, FloatRank, DoubleRank, LongDoubleRank, Float128Rank | |||
99 | }; | |||
100 | ||||
101 | RawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const { | |||
102 | assert(D)((D) ? static_cast<void> (0) : __assert_fail ("D", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 102, __PRETTY_FUNCTION__)); | |||
103 | ||||
104 | // If we already tried to load comments but there are none, | |||
105 | // we won't find anything. | |||
106 | if (CommentsLoaded && Comments.getComments().empty()) | |||
107 | return nullptr; | |||
108 | ||||
109 | // User can not attach documentation to implicit declarations. | |||
110 | if (D->isImplicit()) | |||
111 | return nullptr; | |||
112 | ||||
113 | // User can not attach documentation to implicit instantiations. | |||
114 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) { | |||
115 | if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) | |||
116 | return nullptr; | |||
117 | } | |||
118 | ||||
119 | if (const auto *VD = dyn_cast<VarDecl>(D)) { | |||
120 | if (VD->isStaticDataMember() && | |||
121 | VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) | |||
122 | return nullptr; | |||
123 | } | |||
124 | ||||
125 | if (const auto *CRD = dyn_cast<CXXRecordDecl>(D)) { | |||
126 | if (CRD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) | |||
127 | return nullptr; | |||
128 | } | |||
129 | ||||
130 | if (const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D)) { | |||
131 | TemplateSpecializationKind TSK = CTSD->getSpecializationKind(); | |||
132 | if (TSK == TSK_ImplicitInstantiation || | |||
133 | TSK == TSK_Undeclared) | |||
134 | return nullptr; | |||
135 | } | |||
136 | ||||
137 | if (const auto *ED = dyn_cast<EnumDecl>(D)) { | |||
138 | if (ED->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) | |||
139 | return nullptr; | |||
140 | } | |||
141 | if (const auto *TD = dyn_cast<TagDecl>(D)) { | |||
142 | // When tag declaration (but not definition!) is part of the | |||
143 | // decl-specifier-seq of some other declaration, it doesn't get comment | |||
144 | if (TD->isEmbeddedInDeclarator() && !TD->isCompleteDefinition()) | |||
145 | return nullptr; | |||
146 | } | |||
147 | // TODO: handle comments for function parameters properly. | |||
148 | if (isa<ParmVarDecl>(D)) | |||
149 | return nullptr; | |||
150 | ||||
151 | // TODO: we could look up template parameter documentation in the template | |||
152 | // documentation. | |||
153 | if (isa<TemplateTypeParmDecl>(D) || | |||
154 | isa<NonTypeTemplateParmDecl>(D) || | |||
155 | isa<TemplateTemplateParmDecl>(D)) | |||
156 | return nullptr; | |||
157 | ||||
158 | // Find declaration location. | |||
159 | // For Objective-C declarations we generally don't expect to have multiple | |||
160 | // declarators, thus use declaration starting location as the "declaration | |||
161 | // location". | |||
162 | // For all other declarations multiple declarators are used quite frequently, | |||
163 | // so we use the location of the identifier as the "declaration location". | |||
164 | SourceLocation DeclLoc; | |||
165 | if (isa<ObjCMethodDecl>(D) || isa<ObjCContainerDecl>(D) || | |||
166 | isa<ObjCPropertyDecl>(D) || | |||
167 | isa<RedeclarableTemplateDecl>(D) || | |||
168 | isa<ClassTemplateSpecializationDecl>(D)) | |||
169 | DeclLoc = D->getBeginLoc(); | |||
170 | else { | |||
171 | DeclLoc = D->getLocation(); | |||
172 | if (DeclLoc.isMacroID()) { | |||
173 | if (isa<TypedefDecl>(D)) { | |||
174 | // If location of the typedef name is in a macro, it is because being | |||
175 | // declared via a macro. Try using declaration's starting location as | |||
176 | // the "declaration location". | |||
177 | DeclLoc = D->getBeginLoc(); | |||
178 | } else if (const auto *TD = dyn_cast<TagDecl>(D)) { | |||
179 | // If location of the tag decl is inside a macro, but the spelling of | |||
180 | // the tag name comes from a macro argument, it looks like a special | |||
181 | // macro like NS_ENUM is being used to define the tag decl. In that | |||
182 | // case, adjust the source location to the expansion loc so that we can | |||
183 | // attach the comment to the tag decl. | |||
184 | if (SourceMgr.isMacroArgExpansion(DeclLoc) && | |||
185 | TD->isCompleteDefinition()) | |||
186 | DeclLoc = SourceMgr.getExpansionLoc(DeclLoc); | |||
187 | } | |||
188 | } | |||
189 | } | |||
190 | ||||
191 | // If the declaration doesn't map directly to a location in a file, we | |||
192 | // can't find the comment. | |||
193 | if (DeclLoc.isInvalid() || !DeclLoc.isFileID()) | |||
194 | return nullptr; | |||
195 | ||||
196 | if (!CommentsLoaded && ExternalSource) { | |||
197 | ExternalSource->ReadComments(); | |||
198 | ||||
199 | #ifndef NDEBUG | |||
200 | ArrayRef<RawComment *> RawComments = Comments.getComments(); | |||
201 | assert(std::is_sorted(RawComments.begin(), RawComments.end(),((std::is_sorted(RawComments.begin(), RawComments.end(), BeforeThanCompare <RawComment>(SourceMgr))) ? static_cast<void> (0) : __assert_fail ("std::is_sorted(RawComments.begin(), RawComments.end(), BeforeThanCompare<RawComment>(SourceMgr))" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 202, __PRETTY_FUNCTION__)) | |||
202 | BeforeThanCompare<RawComment>(SourceMgr)))((std::is_sorted(RawComments.begin(), RawComments.end(), BeforeThanCompare <RawComment>(SourceMgr))) ? static_cast<void> (0) : __assert_fail ("std::is_sorted(RawComments.begin(), RawComments.end(), BeforeThanCompare<RawComment>(SourceMgr))" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 202, __PRETTY_FUNCTION__)); | |||
203 | #endif | |||
204 | ||||
205 | CommentsLoaded = true; | |||
206 | } | |||
207 | ||||
208 | ArrayRef<RawComment *> RawComments = Comments.getComments(); | |||
209 | // If there are no comments anywhere, we won't find anything. | |||
210 | if (RawComments.empty()) | |||
211 | return nullptr; | |||
212 | ||||
213 | // Find the comment that occurs just after this declaration. | |||
214 | ArrayRef<RawComment *>::iterator Comment; | |||
215 | { | |||
216 | // When searching for comments during parsing, the comment we are looking | |||
217 | // for is usually among the last two comments we parsed -- check them | |||
218 | // first. | |||
219 | RawComment CommentAtDeclLoc( | |||
220 | SourceMgr, SourceRange(DeclLoc), LangOpts.CommentOpts, false); | |||
221 | BeforeThanCompare<RawComment> Compare(SourceMgr); | |||
222 | ArrayRef<RawComment *>::iterator MaybeBeforeDecl = RawComments.end() - 1; | |||
223 | bool Found = Compare(*MaybeBeforeDecl, &CommentAtDeclLoc); | |||
224 | if (!Found && RawComments.size() >= 2) { | |||
225 | MaybeBeforeDecl--; | |||
226 | Found = Compare(*MaybeBeforeDecl, &CommentAtDeclLoc); | |||
227 | } | |||
228 | ||||
229 | if (Found) { | |||
230 | Comment = MaybeBeforeDecl + 1; | |||
231 | assert(Comment == std::lower_bound(RawComments.begin(), RawComments.end(),((Comment == std::lower_bound(RawComments.begin(), RawComments .end(), &CommentAtDeclLoc, Compare)) ? static_cast<void > (0) : __assert_fail ("Comment == std::lower_bound(RawComments.begin(), RawComments.end(), &CommentAtDeclLoc, Compare)" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 232, __PRETTY_FUNCTION__)) | |||
232 | &CommentAtDeclLoc, Compare))((Comment == std::lower_bound(RawComments.begin(), RawComments .end(), &CommentAtDeclLoc, Compare)) ? static_cast<void > (0) : __assert_fail ("Comment == std::lower_bound(RawComments.begin(), RawComments.end(), &CommentAtDeclLoc, Compare)" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 232, __PRETTY_FUNCTION__)); | |||
233 | } else { | |||
234 | // Slow path. | |||
235 | Comment = std::lower_bound(RawComments.begin(), RawComments.end(), | |||
236 | &CommentAtDeclLoc, Compare); | |||
237 | } | |||
238 | } | |||
239 | ||||
240 | // Decompose the location for the declaration and find the beginning of the | |||
241 | // file buffer. | |||
242 | std::pair<FileID, unsigned> DeclLocDecomp = SourceMgr.getDecomposedLoc(DeclLoc); | |||
243 | ||||
244 | // First check whether we have a trailing comment. | |||
245 | if (Comment != RawComments.end() && | |||
246 | ((*Comment)->isDocumentation() || LangOpts.CommentOpts.ParseAllComments) | |||
247 | && (*Comment)->isTrailingComment() && | |||
248 | (isa<FieldDecl>(D) || isa<EnumConstantDecl>(D) || isa<VarDecl>(D) || | |||
249 | isa<ObjCMethodDecl>(D) || isa<ObjCPropertyDecl>(D))) { | |||
250 | std::pair<FileID, unsigned> CommentBeginDecomp | |||
251 | = SourceMgr.getDecomposedLoc((*Comment)->getSourceRange().getBegin()); | |||
252 | // Check that Doxygen trailing comment comes after the declaration, starts | |||
253 | // on the same line and in the same file as the declaration. | |||
254 | if (DeclLocDecomp.first == CommentBeginDecomp.first && | |||
255 | SourceMgr.getLineNumber(DeclLocDecomp.first, DeclLocDecomp.second) | |||
256 | == SourceMgr.getLineNumber(CommentBeginDecomp.first, | |||
257 | CommentBeginDecomp.second)) { | |||
258 | (**Comment).setAttached(); | |||
259 | return *Comment; | |||
260 | } | |||
261 | } | |||
262 | ||||
263 | // The comment just after the declaration was not a trailing comment. | |||
264 | // Let's look at the previous comment. | |||
265 | if (Comment == RawComments.begin()) | |||
266 | return nullptr; | |||
267 | --Comment; | |||
268 | ||||
269 | // Check that we actually have a non-member Doxygen comment. | |||
270 | if (!((*Comment)->isDocumentation() || | |||
271 | LangOpts.CommentOpts.ParseAllComments) || | |||
272 | (*Comment)->isTrailingComment()) | |||
273 | return nullptr; | |||
274 | ||||
275 | // Decompose the end of the comment. | |||
276 | std::pair<FileID, unsigned> CommentEndDecomp | |||
277 | = SourceMgr.getDecomposedLoc((*Comment)->getSourceRange().getEnd()); | |||
278 | ||||
279 | // If the comment and the declaration aren't in the same file, then they | |||
280 | // aren't related. | |||
281 | if (DeclLocDecomp.first != CommentEndDecomp.first) | |||
282 | return nullptr; | |||
283 | ||||
284 | // Get the corresponding buffer. | |||
285 | bool Invalid = false; | |||
286 | const char *Buffer = SourceMgr.getBufferData(DeclLocDecomp.first, | |||
287 | &Invalid).data(); | |||
288 | if (Invalid) | |||
289 | return nullptr; | |||
290 | ||||
291 | // Extract text between the comment and declaration. | |||
292 | StringRef Text(Buffer + CommentEndDecomp.second, | |||
293 | DeclLocDecomp.second - CommentEndDecomp.second); | |||
294 | ||||
295 | // There should be no other declarations or preprocessor directives between | |||
296 | // comment and declaration. | |||
297 | if (Text.find_first_of(";{}#@") != StringRef::npos) | |||
298 | return nullptr; | |||
299 | ||||
300 | (**Comment).setAttached(); | |||
301 | return *Comment; | |||
302 | } | |||
303 | ||||
304 | /// If we have a 'templated' declaration for a template, adjust 'D' to | |||
305 | /// refer to the actual template. | |||
306 | /// If we have an implicit instantiation, adjust 'D' to refer to template. | |||
307 | static const Decl *adjustDeclToTemplate(const Decl *D) { | |||
308 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) { | |||
309 | // Is this function declaration part of a function template? | |||
310 | if (const FunctionTemplateDecl *FTD = FD->getDescribedFunctionTemplate()) | |||
311 | return FTD; | |||
312 | ||||
313 | // Nothing to do if function is not an implicit instantiation. | |||
314 | if (FD->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) | |||
315 | return D; | |||
316 | ||||
317 | // Function is an implicit instantiation of a function template? | |||
318 | if (const FunctionTemplateDecl *FTD = FD->getPrimaryTemplate()) | |||
319 | return FTD; | |||
320 | ||||
321 | // Function is instantiated from a member definition of a class template? | |||
322 | if (const FunctionDecl *MemberDecl = | |||
323 | FD->getInstantiatedFromMemberFunction()) | |||
324 | return MemberDecl; | |||
325 | ||||
326 | return D; | |||
327 | } | |||
328 | if (const auto *VD = dyn_cast<VarDecl>(D)) { | |||
329 | // Static data member is instantiated from a member definition of a class | |||
330 | // template? | |||
331 | if (VD->isStaticDataMember()) | |||
332 | if (const VarDecl *MemberDecl = VD->getInstantiatedFromStaticDataMember()) | |||
333 | return MemberDecl; | |||
334 | ||||
335 | return D; | |||
336 | } | |||
337 | if (const auto *CRD = dyn_cast<CXXRecordDecl>(D)) { | |||
338 | // Is this class declaration part of a class template? | |||
339 | if (const ClassTemplateDecl *CTD = CRD->getDescribedClassTemplate()) | |||
340 | return CTD; | |||
341 | ||||
342 | // Class is an implicit instantiation of a class template or partial | |||
343 | // specialization? | |||
344 | if (const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(CRD)) { | |||
345 | if (CTSD->getSpecializationKind() != TSK_ImplicitInstantiation) | |||
346 | return D; | |||
347 | llvm::PointerUnion<ClassTemplateDecl *, | |||
348 | ClassTemplatePartialSpecializationDecl *> | |||
349 | PU = CTSD->getSpecializedTemplateOrPartial(); | |||
350 | return PU.is<ClassTemplateDecl*>() ? | |||
351 | static_cast<const Decl*>(PU.get<ClassTemplateDecl *>()) : | |||
352 | static_cast<const Decl*>( | |||
353 | PU.get<ClassTemplatePartialSpecializationDecl *>()); | |||
354 | } | |||
355 | ||||
356 | // Class is instantiated from a member definition of a class template? | |||
357 | if (const MemberSpecializationInfo *Info = | |||
358 | CRD->getMemberSpecializationInfo()) | |||
359 | return Info->getInstantiatedFrom(); | |||
360 | ||||
361 | return D; | |||
362 | } | |||
363 | if (const auto *ED = dyn_cast<EnumDecl>(D)) { | |||
364 | // Enum is instantiated from a member definition of a class template? | |||
365 | if (const EnumDecl *MemberDecl = ED->getInstantiatedFromMemberEnum()) | |||
366 | return MemberDecl; | |||
367 | ||||
368 | return D; | |||
369 | } | |||
370 | // FIXME: Adjust alias templates? | |||
371 | return D; | |||
372 | } | |||
373 | ||||
374 | const RawComment *ASTContext::getRawCommentForAnyRedecl( | |||
375 | const Decl *D, | |||
376 | const Decl **OriginalDecl) const { | |||
377 | D = adjustDeclToTemplate(D); | |||
378 | ||||
379 | // Check whether we have cached a comment for this declaration already. | |||
380 | { | |||
381 | llvm::DenseMap<const Decl *, RawCommentAndCacheFlags>::iterator Pos = | |||
382 | RedeclComments.find(D); | |||
383 | if (Pos != RedeclComments.end()) { | |||
384 | const RawCommentAndCacheFlags &Raw = Pos->second; | |||
385 | if (Raw.getKind() != RawCommentAndCacheFlags::NoCommentInDecl) { | |||
386 | if (OriginalDecl) | |||
387 | *OriginalDecl = Raw.getOriginalDecl(); | |||
388 | return Raw.getRaw(); | |||
389 | } | |||
390 | } | |||
391 | } | |||
392 | ||||
393 | // Search for comments attached to declarations in the redeclaration chain. | |||
394 | const RawComment *RC = nullptr; | |||
395 | const Decl *OriginalDeclForRC = nullptr; | |||
396 | for (auto I : D->redecls()) { | |||
397 | llvm::DenseMap<const Decl *, RawCommentAndCacheFlags>::iterator Pos = | |||
398 | RedeclComments.find(I); | |||
399 | if (Pos != RedeclComments.end()) { | |||
400 | const RawCommentAndCacheFlags &Raw = Pos->second; | |||
401 | if (Raw.getKind() != RawCommentAndCacheFlags::NoCommentInDecl) { | |||
402 | RC = Raw.getRaw(); | |||
403 | OriginalDeclForRC = Raw.getOriginalDecl(); | |||
404 | break; | |||
405 | } | |||
406 | } else { | |||
407 | RC = getRawCommentForDeclNoCache(I); | |||
408 | OriginalDeclForRC = I; | |||
409 | RawCommentAndCacheFlags Raw; | |||
410 | if (RC) { | |||
411 | // Call order swapped to work around ICE in VS2015 RTM (Release Win32) | |||
412 | // https://connect.microsoft.com/VisualStudio/feedback/details/1741530 | |||
413 | Raw.setKind(RawCommentAndCacheFlags::FromDecl); | |||
414 | Raw.setRaw(RC); | |||
415 | } else | |||
416 | Raw.setKind(RawCommentAndCacheFlags::NoCommentInDecl); | |||
417 | Raw.setOriginalDecl(I); | |||
418 | RedeclComments[I] = Raw; | |||
419 | if (RC) | |||
420 | break; | |||
421 | } | |||
422 | } | |||
423 | ||||
424 | // If we found a comment, it should be a documentation comment. | |||
425 | assert(!RC || RC->isDocumentation() || LangOpts.CommentOpts.ParseAllComments)((!RC || RC->isDocumentation() || LangOpts.CommentOpts.ParseAllComments ) ? static_cast<void> (0) : __assert_fail ("!RC || RC->isDocumentation() || LangOpts.CommentOpts.ParseAllComments" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 425, __PRETTY_FUNCTION__)); | |||
426 | ||||
427 | if (OriginalDecl) | |||
428 | *OriginalDecl = OriginalDeclForRC; | |||
429 | ||||
430 | // Update cache for every declaration in the redeclaration chain. | |||
431 | RawCommentAndCacheFlags Raw; | |||
432 | Raw.setRaw(RC); | |||
433 | Raw.setKind(RawCommentAndCacheFlags::FromRedecl); | |||
434 | Raw.setOriginalDecl(OriginalDeclForRC); | |||
435 | ||||
436 | for (auto I : D->redecls()) { | |||
437 | RawCommentAndCacheFlags &R = RedeclComments[I]; | |||
438 | if (R.getKind() == RawCommentAndCacheFlags::NoCommentInDecl) | |||
439 | R = Raw; | |||
440 | } | |||
441 | ||||
442 | return RC; | |||
443 | } | |||
444 | ||||
445 | static void addRedeclaredMethods(const ObjCMethodDecl *ObjCMethod, | |||
446 | SmallVectorImpl<const NamedDecl *> &Redeclared) { | |||
447 | const DeclContext *DC = ObjCMethod->getDeclContext(); | |||
448 | if (const auto *IMD = dyn_cast<ObjCImplDecl>(DC)) { | |||
449 | const ObjCInterfaceDecl *ID = IMD->getClassInterface(); | |||
450 | if (!ID) | |||
451 | return; | |||
452 | // Add redeclared method here. | |||
453 | for (const auto *Ext : ID->known_extensions()) { | |||
454 | if (ObjCMethodDecl *RedeclaredMethod = | |||
455 | Ext->getMethod(ObjCMethod->getSelector(), | |||
456 | ObjCMethod->isInstanceMethod())) | |||
457 | Redeclared.push_back(RedeclaredMethod); | |||
458 | } | |||
459 | } | |||
460 | } | |||
461 | ||||
462 | comments::FullComment *ASTContext::cloneFullComment(comments::FullComment *FC, | |||
463 | const Decl *D) const { | |||
464 | auto *ThisDeclInfo = new (*this) comments::DeclInfo; | |||
465 | ThisDeclInfo->CommentDecl = D; | |||
466 | ThisDeclInfo->IsFilled = false; | |||
467 | ThisDeclInfo->fill(); | |||
468 | ThisDeclInfo->CommentDecl = FC->getDecl(); | |||
469 | if (!ThisDeclInfo->TemplateParameters) | |||
470 | ThisDeclInfo->TemplateParameters = FC->getDeclInfo()->TemplateParameters; | |||
471 | comments::FullComment *CFC = | |||
472 | new (*this) comments::FullComment(FC->getBlocks(), | |||
473 | ThisDeclInfo); | |||
474 | return CFC; | |||
475 | } | |||
476 | ||||
477 | comments::FullComment *ASTContext::getLocalCommentForDeclUncached(const Decl *D) const { | |||
478 | const RawComment *RC = getRawCommentForDeclNoCache(D); | |||
479 | return RC ? RC->parse(*this, nullptr, D) : nullptr; | |||
480 | } | |||
481 | ||||
482 | comments::FullComment *ASTContext::getCommentForDecl( | |||
483 | const Decl *D, | |||
484 | const Preprocessor *PP) const { | |||
485 | if (D->isInvalidDecl()) | |||
486 | return nullptr; | |||
487 | D = adjustDeclToTemplate(D); | |||
488 | ||||
489 | const Decl *Canonical = D->getCanonicalDecl(); | |||
490 | llvm::DenseMap<const Decl *, comments::FullComment *>::iterator Pos = | |||
491 | ParsedComments.find(Canonical); | |||
492 | ||||
493 | if (Pos != ParsedComments.end()) { | |||
494 | if (Canonical != D) { | |||
495 | comments::FullComment *FC = Pos->second; | |||
496 | comments::FullComment *CFC = cloneFullComment(FC, D); | |||
497 | return CFC; | |||
498 | } | |||
499 | return Pos->second; | |||
500 | } | |||
501 | ||||
502 | const Decl *OriginalDecl; | |||
503 | ||||
504 | const RawComment *RC = getRawCommentForAnyRedecl(D, &OriginalDecl); | |||
505 | if (!RC) { | |||
506 | if (isa<ObjCMethodDecl>(D) || isa<FunctionDecl>(D)) { | |||
507 | SmallVector<const NamedDecl*, 8> Overridden; | |||
508 | const auto *OMD = dyn_cast<ObjCMethodDecl>(D); | |||
509 | if (OMD && OMD->isPropertyAccessor()) | |||
510 | if (const ObjCPropertyDecl *PDecl = OMD->findPropertyDecl()) | |||
511 | if (comments::FullComment *FC = getCommentForDecl(PDecl, PP)) | |||
512 | return cloneFullComment(FC, D); | |||
513 | if (OMD) | |||
514 | addRedeclaredMethods(OMD, Overridden); | |||
515 | getOverriddenMethods(dyn_cast<NamedDecl>(D), Overridden); | |||
516 | for (unsigned i = 0, e = Overridden.size(); i < e; i++) | |||
517 | if (comments::FullComment *FC = getCommentForDecl(Overridden[i], PP)) | |||
518 | return cloneFullComment(FC, D); | |||
519 | } | |||
520 | else if (const auto *TD = dyn_cast<TypedefNameDecl>(D)) { | |||
521 | // Attach any tag type's documentation to its typedef if latter | |||
522 | // does not have one of its own. | |||
523 | QualType QT = TD->getUnderlyingType(); | |||
524 | if (const auto *TT = QT->getAs<TagType>()) | |||
525 | if (const Decl *TD = TT->getDecl()) | |||
526 | if (comments::FullComment *FC = getCommentForDecl(TD, PP)) | |||
527 | return cloneFullComment(FC, D); | |||
528 | } | |||
529 | else if (const auto *IC = dyn_cast<ObjCInterfaceDecl>(D)) { | |||
530 | while (IC->getSuperClass()) { | |||
531 | IC = IC->getSuperClass(); | |||
532 | if (comments::FullComment *FC = getCommentForDecl(IC, PP)) | |||
533 | return cloneFullComment(FC, D); | |||
534 | } | |||
535 | } | |||
536 | else if (const auto *CD = dyn_cast<ObjCCategoryDecl>(D)) { | |||
537 | if (const ObjCInterfaceDecl *IC = CD->getClassInterface()) | |||
538 | if (comments::FullComment *FC = getCommentForDecl(IC, PP)) | |||
539 | return cloneFullComment(FC, D); | |||
540 | } | |||
541 | else if (const auto *RD = dyn_cast<CXXRecordDecl>(D)) { | |||
542 | if (!(RD = RD->getDefinition())) | |||
543 | return nullptr; | |||
544 | // Check non-virtual bases. | |||
545 | for (const auto &I : RD->bases()) { | |||
546 | if (I.isVirtual() || (I.getAccessSpecifier() != AS_public)) | |||
547 | continue; | |||
548 | QualType Ty = I.getType(); | |||
549 | if (Ty.isNull()) | |||
550 | continue; | |||
551 | if (const CXXRecordDecl *NonVirtualBase = Ty->getAsCXXRecordDecl()) { | |||
552 | if (!(NonVirtualBase= NonVirtualBase->getDefinition())) | |||
553 | continue; | |||
554 | ||||
555 | if (comments::FullComment *FC = getCommentForDecl((NonVirtualBase), PP)) | |||
556 | return cloneFullComment(FC, D); | |||
557 | } | |||
558 | } | |||
559 | // Check virtual bases. | |||
560 | for (const auto &I : RD->vbases()) { | |||
561 | if (I.getAccessSpecifier() != AS_public) | |||
562 | continue; | |||
563 | QualType Ty = I.getType(); | |||
564 | if (Ty.isNull()) | |||
565 | continue; | |||
566 | if (const CXXRecordDecl *VirtualBase = Ty->getAsCXXRecordDecl()) { | |||
567 | if (!(VirtualBase= VirtualBase->getDefinition())) | |||
568 | continue; | |||
569 | if (comments::FullComment *FC = getCommentForDecl((VirtualBase), PP)) | |||
570 | return cloneFullComment(FC, D); | |||
571 | } | |||
572 | } | |||
573 | } | |||
574 | return nullptr; | |||
575 | } | |||
576 | ||||
577 | // If the RawComment was attached to other redeclaration of this Decl, we | |||
578 | // should parse the comment in context of that other Decl. This is important | |||
579 | // because comments can contain references to parameter names which can be | |||
580 | // different across redeclarations. | |||
581 | if (D != OriginalDecl) | |||
582 | return getCommentForDecl(OriginalDecl, PP); | |||
583 | ||||
584 | comments::FullComment *FC = RC->parse(*this, PP, D); | |||
585 | ParsedComments[Canonical] = FC; | |||
586 | return FC; | |||
587 | } | |||
588 | ||||
589 | void | |||
590 | ASTContext::CanonicalTemplateTemplateParm::Profile(llvm::FoldingSetNodeID &ID, | |||
591 | TemplateTemplateParmDecl *Parm) { | |||
592 | ID.AddInteger(Parm->getDepth()); | |||
593 | ID.AddInteger(Parm->getPosition()); | |||
594 | ID.AddBoolean(Parm->isParameterPack()); | |||
595 | ||||
596 | TemplateParameterList *Params = Parm->getTemplateParameters(); | |||
597 | ID.AddInteger(Params->size()); | |||
598 | for (TemplateParameterList::const_iterator P = Params->begin(), | |||
599 | PEnd = Params->end(); | |||
600 | P != PEnd; ++P) { | |||
601 | if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) { | |||
602 | ID.AddInteger(0); | |||
603 | ID.AddBoolean(TTP->isParameterPack()); | |||
604 | continue; | |||
605 | } | |||
606 | ||||
607 | if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) { | |||
608 | ID.AddInteger(1); | |||
609 | ID.AddBoolean(NTTP->isParameterPack()); | |||
610 | ID.AddPointer(NTTP->getType().getCanonicalType().getAsOpaquePtr()); | |||
611 | if (NTTP->isExpandedParameterPack()) { | |||
612 | ID.AddBoolean(true); | |||
613 | ID.AddInteger(NTTP->getNumExpansionTypes()); | |||
614 | for (unsigned I = 0, N = NTTP->getNumExpansionTypes(); I != N; ++I) { | |||
615 | QualType T = NTTP->getExpansionType(I); | |||
616 | ID.AddPointer(T.getCanonicalType().getAsOpaquePtr()); | |||
617 | } | |||
618 | } else | |||
619 | ID.AddBoolean(false); | |||
620 | continue; | |||
621 | } | |||
622 | ||||
623 | auto *TTP = cast<TemplateTemplateParmDecl>(*P); | |||
624 | ID.AddInteger(2); | |||
625 | Profile(ID, TTP); | |||
626 | } | |||
627 | } | |||
628 | ||||
629 | TemplateTemplateParmDecl * | |||
630 | ASTContext::getCanonicalTemplateTemplateParmDecl( | |||
631 | TemplateTemplateParmDecl *TTP) const { | |||
632 | // Check if we already have a canonical template template parameter. | |||
633 | llvm::FoldingSetNodeID ID; | |||
634 | CanonicalTemplateTemplateParm::Profile(ID, TTP); | |||
635 | void *InsertPos = nullptr; | |||
636 | CanonicalTemplateTemplateParm *Canonical | |||
637 | = CanonTemplateTemplateParms.FindNodeOrInsertPos(ID, InsertPos); | |||
638 | if (Canonical) | |||
639 | return Canonical->getParam(); | |||
640 | ||||
641 | // Build a canonical template parameter list. | |||
642 | TemplateParameterList *Params = TTP->getTemplateParameters(); | |||
643 | SmallVector<NamedDecl *, 4> CanonParams; | |||
644 | CanonParams.reserve(Params->size()); | |||
645 | for (TemplateParameterList::const_iterator P = Params->begin(), | |||
646 | PEnd = Params->end(); | |||
647 | P != PEnd; ++P) { | |||
648 | if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) | |||
649 | CanonParams.push_back( | |||
650 | TemplateTypeParmDecl::Create(*this, getTranslationUnitDecl(), | |||
651 | SourceLocation(), | |||
652 | SourceLocation(), | |||
653 | TTP->getDepth(), | |||
654 | TTP->getIndex(), nullptr, false, | |||
655 | TTP->isParameterPack())); | |||
656 | else if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) { | |||
657 | QualType T = getCanonicalType(NTTP->getType()); | |||
658 | TypeSourceInfo *TInfo = getTrivialTypeSourceInfo(T); | |||
659 | NonTypeTemplateParmDecl *Param; | |||
660 | if (NTTP->isExpandedParameterPack()) { | |||
661 | SmallVector<QualType, 2> ExpandedTypes; | |||
662 | SmallVector<TypeSourceInfo *, 2> ExpandedTInfos; | |||
663 | for (unsigned I = 0, N = NTTP->getNumExpansionTypes(); I != N; ++I) { | |||
664 | ExpandedTypes.push_back(getCanonicalType(NTTP->getExpansionType(I))); | |||
665 | ExpandedTInfos.push_back( | |||
666 | getTrivialTypeSourceInfo(ExpandedTypes.back())); | |||
667 | } | |||
668 | ||||
669 | Param = NonTypeTemplateParmDecl::Create(*this, getTranslationUnitDecl(), | |||
670 | SourceLocation(), | |||
671 | SourceLocation(), | |||
672 | NTTP->getDepth(), | |||
673 | NTTP->getPosition(), nullptr, | |||
674 | T, | |||
675 | TInfo, | |||
676 | ExpandedTypes, | |||
677 | ExpandedTInfos); | |||
678 | } else { | |||
679 | Param = NonTypeTemplateParmDecl::Create(*this, getTranslationUnitDecl(), | |||
680 | SourceLocation(), | |||
681 | SourceLocation(), | |||
682 | NTTP->getDepth(), | |||
683 | NTTP->getPosition(), nullptr, | |||
684 | T, | |||
685 | NTTP->isParameterPack(), | |||
686 | TInfo); | |||
687 | } | |||
688 | CanonParams.push_back(Param); | |||
689 | ||||
690 | } else | |||
691 | CanonParams.push_back(getCanonicalTemplateTemplateParmDecl( | |||
692 | cast<TemplateTemplateParmDecl>(*P))); | |||
693 | } | |||
694 | ||||
695 | assert(!TTP->getRequiresClause() &&((!TTP->getRequiresClause() && "Unexpected requires-clause on template template-parameter" ) ? static_cast<void> (0) : __assert_fail ("!TTP->getRequiresClause() && \"Unexpected requires-clause on template template-parameter\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 696, __PRETTY_FUNCTION__)) | |||
696 | "Unexpected requires-clause on template template-parameter")((!TTP->getRequiresClause() && "Unexpected requires-clause on template template-parameter" ) ? static_cast<void> (0) : __assert_fail ("!TTP->getRequiresClause() && \"Unexpected requires-clause on template template-parameter\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 696, __PRETTY_FUNCTION__)); | |||
697 | Expr *const CanonRequiresClause = nullptr; | |||
698 | ||||
699 | TemplateTemplateParmDecl *CanonTTP | |||
700 | = TemplateTemplateParmDecl::Create(*this, getTranslationUnitDecl(), | |||
701 | SourceLocation(), TTP->getDepth(), | |||
702 | TTP->getPosition(), | |||
703 | TTP->isParameterPack(), | |||
704 | nullptr, | |||
705 | TemplateParameterList::Create(*this, SourceLocation(), | |||
706 | SourceLocation(), | |||
707 | CanonParams, | |||
708 | SourceLocation(), | |||
709 | CanonRequiresClause)); | |||
710 | ||||
711 | // Get the new insert position for the node we care about. | |||
712 | Canonical = CanonTemplateTemplateParms.FindNodeOrInsertPos(ID, InsertPos); | |||
713 | assert(!Canonical && "Shouldn't be in the map!")((!Canonical && "Shouldn't be in the map!") ? static_cast <void> (0) : __assert_fail ("!Canonical && \"Shouldn't be in the map!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 713, __PRETTY_FUNCTION__)); | |||
714 | (void)Canonical; | |||
715 | ||||
716 | // Create the canonical template template parameter entry. | |||
717 | Canonical = new (*this) CanonicalTemplateTemplateParm(CanonTTP); | |||
718 | CanonTemplateTemplateParms.InsertNode(Canonical, InsertPos); | |||
719 | return CanonTTP; | |||
720 | } | |||
721 | ||||
722 | CXXABI *ASTContext::createCXXABI(const TargetInfo &T) { | |||
723 | if (!LangOpts.CPlusPlus) return nullptr; | |||
724 | ||||
725 | switch (T.getCXXABI().getKind()) { | |||
726 | case TargetCXXABI::GenericARM: // Same as Itanium at this level | |||
727 | case TargetCXXABI::iOS: | |||
728 | case TargetCXXABI::iOS64: | |||
729 | case TargetCXXABI::WatchOS: | |||
730 | case TargetCXXABI::GenericAArch64: | |||
731 | case TargetCXXABI::GenericMIPS: | |||
732 | case TargetCXXABI::GenericItanium: | |||
733 | case TargetCXXABI::WebAssembly: | |||
734 | return CreateItaniumCXXABI(*this); | |||
735 | case TargetCXXABI::Microsoft: | |||
736 | return CreateMicrosoftCXXABI(*this); | |||
737 | } | |||
738 | llvm_unreachable("Invalid CXXABI type!")::llvm::llvm_unreachable_internal("Invalid CXXABI type!", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 738); | |||
739 | } | |||
740 | ||||
741 | static const LangASMap *getAddressSpaceMap(const TargetInfo &T, | |||
742 | const LangOptions &LOpts) { | |||
743 | if (LOpts.FakeAddressSpaceMap) { | |||
744 | // The fake address space map must have a distinct entry for each | |||
745 | // language-specific address space. | |||
746 | static const unsigned FakeAddrSpaceMap[] = { | |||
747 | 0, // Default | |||
748 | 1, // opencl_global | |||
749 | 3, // opencl_local | |||
750 | 2, // opencl_constant | |||
751 | 0, // opencl_private | |||
752 | 4, // opencl_generic | |||
753 | 5, // cuda_device | |||
754 | 6, // cuda_constant | |||
755 | 7 // cuda_shared | |||
756 | }; | |||
757 | return &FakeAddrSpaceMap; | |||
758 | } else { | |||
759 | return &T.getAddressSpaceMap(); | |||
760 | } | |||
761 | } | |||
762 | ||||
763 | static bool isAddrSpaceMapManglingEnabled(const TargetInfo &TI, | |||
764 | const LangOptions &LangOpts) { | |||
765 | switch (LangOpts.getAddressSpaceMapMangling()) { | |||
766 | case LangOptions::ASMM_Target: | |||
767 | return TI.useAddressSpaceMapMangling(); | |||
768 | case LangOptions::ASMM_On: | |||
769 | return true; | |||
770 | case LangOptions::ASMM_Off: | |||
771 | return false; | |||
772 | } | |||
773 | llvm_unreachable("getAddressSpaceMapMangling() doesn't cover anything.")::llvm::llvm_unreachable_internal("getAddressSpaceMapMangling() doesn't cover anything." , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 773); | |||
774 | } | |||
775 | ||||
776 | ASTContext::ASTContext(LangOptions &LOpts, SourceManager &SM, | |||
777 | IdentifierTable &idents, SelectorTable &sels, | |||
778 | Builtin::Context &builtins) | |||
779 | : FunctionProtoTypes(this_()), TemplateSpecializationTypes(this_()), | |||
780 | DependentTemplateSpecializationTypes(this_()), | |||
781 | SubstTemplateTemplateParmPacks(this_()), SourceMgr(SM), LangOpts(LOpts), | |||
782 | SanitizerBL(new SanitizerBlacklist(LangOpts.SanitizerBlacklistFiles, SM)), | |||
783 | XRayFilter(new XRayFunctionFilter(LangOpts.XRayAlwaysInstrumentFiles, | |||
784 | LangOpts.XRayNeverInstrumentFiles, | |||
785 | LangOpts.XRayAttrListFiles, SM)), | |||
786 | PrintingPolicy(LOpts), Idents(idents), Selectors(sels), | |||
787 | BuiltinInfo(builtins), DeclarationNames(*this), Comments(SM), | |||
788 | CommentCommandTraits(BumpAlloc, LOpts.CommentOpts), | |||
789 | CompCategories(this_()), LastSDM(nullptr, 0) { | |||
790 | TUDecl = TranslationUnitDecl::Create(*this); | |||
791 | TraversalScope = {TUDecl}; | |||
792 | } | |||
793 | ||||
794 | ASTContext::~ASTContext() { | |||
795 | // Release the DenseMaps associated with DeclContext objects. | |||
796 | // FIXME: Is this the ideal solution? | |||
797 | ReleaseDeclContextMaps(); | |||
798 | ||||
799 | // Call all of the deallocation functions on all of their targets. | |||
800 | for (auto &Pair : Deallocations) | |||
801 | (Pair.first)(Pair.second); | |||
802 | ||||
803 | // ASTRecordLayout objects in ASTRecordLayouts must always be destroyed | |||
804 | // because they can contain DenseMaps. | |||
805 | for (llvm::DenseMap<const ObjCContainerDecl*, | |||
806 | const ASTRecordLayout*>::iterator | |||
807 | I = ObjCLayouts.begin(), E = ObjCLayouts.end(); I != E; ) | |||
808 | // Increment in loop to prevent using deallocated memory. | |||
809 | if (auto *R = const_cast<ASTRecordLayout *>((I++)->second)) | |||
810 | R->Destroy(*this); | |||
811 | ||||
812 | for (llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>::iterator | |||
813 | I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) { | |||
814 | // Increment in loop to prevent using deallocated memory. | |||
815 | if (auto *R = const_cast<ASTRecordLayout *>((I++)->second)) | |||
816 | R->Destroy(*this); | |||
817 | } | |||
818 | ||||
819 | for (llvm::DenseMap<const Decl*, AttrVec*>::iterator A = DeclAttrs.begin(), | |||
820 | AEnd = DeclAttrs.end(); | |||
821 | A != AEnd; ++A) | |||
822 | A->second->~AttrVec(); | |||
823 | ||||
824 | for (std::pair<const MaterializeTemporaryExpr *, APValue *> &MTVPair : | |||
825 | MaterializedTemporaryValues) | |||
826 | MTVPair.second->~APValue(); | |||
827 | ||||
828 | for (const auto &Value : ModuleInitializers) | |||
829 | Value.second->~PerModuleInitializers(); | |||
830 | } | |||
831 | ||||
832 | class ASTContext::ParentMap { | |||
833 | /// Contains parents of a node. | |||
834 | using ParentVector = llvm::SmallVector<ast_type_traits::DynTypedNode, 2>; | |||
835 | ||||
836 | /// Maps from a node to its parents. This is used for nodes that have | |||
837 | /// pointer identity only, which are more common and we can save space by | |||
838 | /// only storing a unique pointer to them. | |||
839 | using ParentMapPointers = llvm::DenseMap< | |||
840 | const void *, | |||
841 | llvm::PointerUnion4<const Decl *, const Stmt *, | |||
842 | ast_type_traits::DynTypedNode *, ParentVector *>>; | |||
843 | ||||
844 | /// Parent map for nodes without pointer identity. We store a full | |||
845 | /// DynTypedNode for all keys. | |||
846 | using ParentMapOtherNodes = llvm::DenseMap< | |||
847 | ast_type_traits::DynTypedNode, | |||
848 | llvm::PointerUnion4<const Decl *, const Stmt *, | |||
849 | ast_type_traits::DynTypedNode *, ParentVector *>>; | |||
850 | ||||
851 | ParentMapPointers PointerParents; | |||
852 | ParentMapOtherNodes OtherParents; | |||
853 | class ASTVisitor; | |||
854 | ||||
855 | static ast_type_traits::DynTypedNode | |||
856 | getSingleDynTypedNodeFromParentMap(ParentMapPointers::mapped_type U) { | |||
857 | if (const auto *D = U.dyn_cast<const Decl *>()) | |||
858 | return ast_type_traits::DynTypedNode::create(*D); | |||
859 | if (const auto *S = U.dyn_cast<const Stmt *>()) | |||
860 | return ast_type_traits::DynTypedNode::create(*S); | |||
861 | return *U.get<ast_type_traits::DynTypedNode *>(); | |||
862 | } | |||
863 | ||||
864 | template <typename NodeTy, typename MapTy> | |||
865 | static ASTContext::DynTypedNodeList getDynNodeFromMap(const NodeTy &Node, | |||
866 | const MapTy &Map) { | |||
867 | auto I = Map.find(Node); | |||
868 | if (I == Map.end()) { | |||
869 | return llvm::ArrayRef<ast_type_traits::DynTypedNode>(); | |||
870 | } | |||
871 | if (const auto *V = I->second.template dyn_cast<ParentVector *>()) { | |||
872 | return llvm::makeArrayRef(*V); | |||
873 | } | |||
874 | return getSingleDynTypedNodeFromParentMap(I->second); | |||
875 | } | |||
876 | ||||
877 | public: | |||
878 | ParentMap(ASTContext &Ctx); | |||
879 | ~ParentMap() { | |||
880 | for (const auto &Entry : PointerParents) { | |||
881 | if (Entry.second.is<ast_type_traits::DynTypedNode *>()) { | |||
882 | delete Entry.second.get<ast_type_traits::DynTypedNode *>(); | |||
883 | } else if (Entry.second.is<ParentVector *>()) { | |||
884 | delete Entry.second.get<ParentVector *>(); | |||
885 | } | |||
886 | } | |||
887 | for (const auto &Entry : OtherParents) { | |||
888 | if (Entry.second.is<ast_type_traits::DynTypedNode *>()) { | |||
889 | delete Entry.second.get<ast_type_traits::DynTypedNode *>(); | |||
890 | } else if (Entry.second.is<ParentVector *>()) { | |||
891 | delete Entry.second.get<ParentVector *>(); | |||
892 | } | |||
893 | } | |||
894 | } | |||
895 | ||||
896 | DynTypedNodeList getParents(const ast_type_traits::DynTypedNode &Node) { | |||
897 | if (Node.getNodeKind().hasPointerIdentity()) | |||
898 | return getDynNodeFromMap(Node.getMemoizationData(), PointerParents); | |||
899 | return getDynNodeFromMap(Node, OtherParents); | |||
900 | } | |||
901 | }; | |||
902 | ||||
903 | void ASTContext::setTraversalScope(const std::vector<Decl *> &TopLevelDecls) { | |||
904 | TraversalScope = TopLevelDecls; | |||
905 | Parents.reset(); | |||
906 | } | |||
907 | ||||
908 | void ASTContext::AddDeallocation(void (*Callback)(void*), void *Data) { | |||
909 | Deallocations.push_back({Callback, Data}); | |||
910 | } | |||
911 | ||||
912 | void | |||
913 | ASTContext::setExternalSource(IntrusiveRefCntPtr<ExternalASTSource> Source) { | |||
914 | ExternalSource = std::move(Source); | |||
915 | } | |||
916 | ||||
917 | void ASTContext::PrintStats() const { | |||
918 | llvm::errs() << "\n*** AST Context Stats:\n"; | |||
919 | llvm::errs() << " " << Types.size() << " types total.\n"; | |||
920 | ||||
921 | unsigned counts[] = { | |||
922 | #define TYPE(Name, Parent) 0, | |||
923 | #define ABSTRACT_TYPE(Name, Parent) | |||
924 | #include "clang/AST/TypeNodes.def" | |||
925 | 0 // Extra | |||
926 | }; | |||
927 | ||||
928 | for (unsigned i = 0, e = Types.size(); i != e; ++i) { | |||
929 | Type *T = Types[i]; | |||
930 | counts[(unsigned)T->getTypeClass()]++; | |||
931 | } | |||
932 | ||||
933 | unsigned Idx = 0; | |||
934 | unsigned TotalBytes = 0; | |||
935 | #define TYPE(Name, Parent) \ | |||
936 | if (counts[Idx]) \ | |||
937 | llvm::errs() << " " << counts[Idx] << " " << #Name \ | |||
938 | << " types, " << sizeof(Name##Type) << " each " \ | |||
939 | << "(" << counts[Idx] * sizeof(Name##Type) \ | |||
940 | << " bytes)\n"; \ | |||
941 | TotalBytes += counts[Idx] * sizeof(Name##Type); \ | |||
942 | ++Idx; | |||
943 | #define ABSTRACT_TYPE(Name, Parent) | |||
944 | #include "clang/AST/TypeNodes.def" | |||
945 | ||||
946 | llvm::errs() << "Total bytes = " << TotalBytes << "\n"; | |||
947 | ||||
948 | // Implicit special member functions. | |||
949 | llvm::errs() << NumImplicitDefaultConstructorsDeclared << "/" | |||
950 | << NumImplicitDefaultConstructors | |||
951 | << " implicit default constructors created\n"; | |||
952 | llvm::errs() << NumImplicitCopyConstructorsDeclared << "/" | |||
953 | << NumImplicitCopyConstructors | |||
954 | << " implicit copy constructors created\n"; | |||
955 | if (getLangOpts().CPlusPlus) | |||
956 | llvm::errs() << NumImplicitMoveConstructorsDeclared << "/" | |||
957 | << NumImplicitMoveConstructors | |||
958 | << " implicit move constructors created\n"; | |||
959 | llvm::errs() << NumImplicitCopyAssignmentOperatorsDeclared << "/" | |||
960 | << NumImplicitCopyAssignmentOperators | |||
961 | << " implicit copy assignment operators created\n"; | |||
962 | if (getLangOpts().CPlusPlus) | |||
963 | llvm::errs() << NumImplicitMoveAssignmentOperatorsDeclared << "/" | |||
964 | << NumImplicitMoveAssignmentOperators | |||
965 | << " implicit move assignment operators created\n"; | |||
966 | llvm::errs() << NumImplicitDestructorsDeclared << "/" | |||
967 | << NumImplicitDestructors | |||
968 | << " implicit destructors created\n"; | |||
969 | ||||
970 | if (ExternalSource) { | |||
971 | llvm::errs() << "\n"; | |||
972 | ExternalSource->PrintStats(); | |||
973 | } | |||
974 | ||||
975 | BumpAlloc.PrintStats(); | |||
976 | } | |||
977 | ||||
978 | void ASTContext::mergeDefinitionIntoModule(NamedDecl *ND, Module *M, | |||
979 | bool NotifyListeners) { | |||
980 | if (NotifyListeners) | |||
981 | if (auto *Listener = getASTMutationListener()) | |||
982 | Listener->RedefinedHiddenDefinition(ND, M); | |||
983 | ||||
984 | MergedDefModules[cast<NamedDecl>(ND->getCanonicalDecl())].push_back(M); | |||
985 | } | |||
986 | ||||
987 | void ASTContext::deduplicateMergedDefinitonsFor(NamedDecl *ND) { | |||
988 | auto It = MergedDefModules.find(cast<NamedDecl>(ND->getCanonicalDecl())); | |||
989 | if (It == MergedDefModules.end()) | |||
990 | return; | |||
991 | ||||
992 | auto &Merged = It->second; | |||
993 | llvm::DenseSet<Module*> Found; | |||
994 | for (Module *&M : Merged) | |||
995 | if (!Found.insert(M).second) | |||
996 | M = nullptr; | |||
997 | Merged.erase(std::remove(Merged.begin(), Merged.end(), nullptr), Merged.end()); | |||
998 | } | |||
999 | ||||
1000 | void ASTContext::PerModuleInitializers::resolve(ASTContext &Ctx) { | |||
1001 | if (LazyInitializers.empty()) | |||
1002 | return; | |||
1003 | ||||
1004 | auto *Source = Ctx.getExternalSource(); | |||
1005 | assert(Source && "lazy initializers but no external source")((Source && "lazy initializers but no external source" ) ? static_cast<void> (0) : __assert_fail ("Source && \"lazy initializers but no external source\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1005, __PRETTY_FUNCTION__)); | |||
1006 | ||||
1007 | auto LazyInits = std::move(LazyInitializers); | |||
1008 | LazyInitializers.clear(); | |||
1009 | ||||
1010 | for (auto ID : LazyInits) | |||
1011 | Initializers.push_back(Source->GetExternalDecl(ID)); | |||
1012 | ||||
1013 | assert(LazyInitializers.empty() &&((LazyInitializers.empty() && "GetExternalDecl for lazy module initializer added more inits" ) ? static_cast<void> (0) : __assert_fail ("LazyInitializers.empty() && \"GetExternalDecl for lazy module initializer added more inits\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1014, __PRETTY_FUNCTION__)) | |||
1014 | "GetExternalDecl for lazy module initializer added more inits")((LazyInitializers.empty() && "GetExternalDecl for lazy module initializer added more inits" ) ? static_cast<void> (0) : __assert_fail ("LazyInitializers.empty() && \"GetExternalDecl for lazy module initializer added more inits\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1014, __PRETTY_FUNCTION__)); | |||
1015 | } | |||
1016 | ||||
1017 | void ASTContext::addModuleInitializer(Module *M, Decl *D) { | |||
1018 | // One special case: if we add a module initializer that imports another | |||
1019 | // module, and that module's only initializer is an ImportDecl, simplify. | |||
1020 | if (const auto *ID = dyn_cast<ImportDecl>(D)) { | |||
1021 | auto It = ModuleInitializers.find(ID->getImportedModule()); | |||
1022 | ||||
1023 | // Maybe the ImportDecl does nothing at all. (Common case.) | |||
1024 | if (It == ModuleInitializers.end()) | |||
1025 | return; | |||
1026 | ||||
1027 | // Maybe the ImportDecl only imports another ImportDecl. | |||
1028 | auto &Imported = *It->second; | |||
1029 | if (Imported.Initializers.size() + Imported.LazyInitializers.size() == 1) { | |||
1030 | Imported.resolve(*this); | |||
1031 | auto *OnlyDecl = Imported.Initializers.front(); | |||
1032 | if (isa<ImportDecl>(OnlyDecl)) | |||
1033 | D = OnlyDecl; | |||
1034 | } | |||
1035 | } | |||
1036 | ||||
1037 | auto *&Inits = ModuleInitializers[M]; | |||
1038 | if (!Inits) | |||
1039 | Inits = new (*this) PerModuleInitializers; | |||
1040 | Inits->Initializers.push_back(D); | |||
1041 | } | |||
1042 | ||||
1043 | void ASTContext::addLazyModuleInitializers(Module *M, ArrayRef<uint32_t> IDs) { | |||
1044 | auto *&Inits = ModuleInitializers[M]; | |||
1045 | if (!Inits) | |||
1046 | Inits = new (*this) PerModuleInitializers; | |||
1047 | Inits->LazyInitializers.insert(Inits->LazyInitializers.end(), | |||
1048 | IDs.begin(), IDs.end()); | |||
1049 | } | |||
1050 | ||||
1051 | ArrayRef<Decl *> ASTContext::getModuleInitializers(Module *M) { | |||
1052 | auto It = ModuleInitializers.find(M); | |||
1053 | if (It == ModuleInitializers.end()) | |||
1054 | return None; | |||
1055 | ||||
1056 | auto *Inits = It->second; | |||
1057 | Inits->resolve(*this); | |||
1058 | return Inits->Initializers; | |||
1059 | } | |||
1060 | ||||
1061 | ExternCContextDecl *ASTContext::getExternCContextDecl() const { | |||
1062 | if (!ExternCContext) | |||
1063 | ExternCContext = ExternCContextDecl::Create(*this, getTranslationUnitDecl()); | |||
1064 | ||||
1065 | return ExternCContext; | |||
1066 | } | |||
1067 | ||||
1068 | BuiltinTemplateDecl * | |||
1069 | ASTContext::buildBuiltinTemplateDecl(BuiltinTemplateKind BTK, | |||
1070 | const IdentifierInfo *II) const { | |||
1071 | auto *BuiltinTemplate = BuiltinTemplateDecl::Create(*this, TUDecl, II, BTK); | |||
1072 | BuiltinTemplate->setImplicit(); | |||
1073 | TUDecl->addDecl(BuiltinTemplate); | |||
1074 | ||||
1075 | return BuiltinTemplate; | |||
1076 | } | |||
1077 | ||||
1078 | BuiltinTemplateDecl * | |||
1079 | ASTContext::getMakeIntegerSeqDecl() const { | |||
1080 | if (!MakeIntegerSeqDecl) | |||
1081 | MakeIntegerSeqDecl = buildBuiltinTemplateDecl(BTK__make_integer_seq, | |||
1082 | getMakeIntegerSeqName()); | |||
1083 | return MakeIntegerSeqDecl; | |||
1084 | } | |||
1085 | ||||
1086 | BuiltinTemplateDecl * | |||
1087 | ASTContext::getTypePackElementDecl() const { | |||
1088 | if (!TypePackElementDecl) | |||
1089 | TypePackElementDecl = buildBuiltinTemplateDecl(BTK__type_pack_element, | |||
1090 | getTypePackElementName()); | |||
1091 | return TypePackElementDecl; | |||
1092 | } | |||
1093 | ||||
1094 | RecordDecl *ASTContext::buildImplicitRecord(StringRef Name, | |||
1095 | RecordDecl::TagKind TK) const { | |||
1096 | SourceLocation Loc; | |||
1097 | RecordDecl *NewDecl; | |||
1098 | if (getLangOpts().CPlusPlus) | |||
1099 | NewDecl = CXXRecordDecl::Create(*this, TK, getTranslationUnitDecl(), Loc, | |||
1100 | Loc, &Idents.get(Name)); | |||
1101 | else | |||
1102 | NewDecl = RecordDecl::Create(*this, TK, getTranslationUnitDecl(), Loc, Loc, | |||
1103 | &Idents.get(Name)); | |||
1104 | NewDecl->setImplicit(); | |||
1105 | NewDecl->addAttr(TypeVisibilityAttr::CreateImplicit( | |||
1106 | const_cast<ASTContext &>(*this), TypeVisibilityAttr::Default)); | |||
1107 | return NewDecl; | |||
1108 | } | |||
1109 | ||||
1110 | TypedefDecl *ASTContext::buildImplicitTypedef(QualType T, | |||
1111 | StringRef Name) const { | |||
1112 | TypeSourceInfo *TInfo = getTrivialTypeSourceInfo(T); | |||
1113 | TypedefDecl *NewDecl = TypedefDecl::Create( | |||
1114 | const_cast<ASTContext &>(*this), getTranslationUnitDecl(), | |||
1115 | SourceLocation(), SourceLocation(), &Idents.get(Name), TInfo); | |||
1116 | NewDecl->setImplicit(); | |||
1117 | return NewDecl; | |||
1118 | } | |||
1119 | ||||
1120 | TypedefDecl *ASTContext::getInt128Decl() const { | |||
1121 | if (!Int128Decl) | |||
1122 | Int128Decl = buildImplicitTypedef(Int128Ty, "__int128_t"); | |||
1123 | return Int128Decl; | |||
1124 | } | |||
1125 | ||||
1126 | TypedefDecl *ASTContext::getUInt128Decl() const { | |||
1127 | if (!UInt128Decl) | |||
1128 | UInt128Decl = buildImplicitTypedef(UnsignedInt128Ty, "__uint128_t"); | |||
1129 | return UInt128Decl; | |||
1130 | } | |||
1131 | ||||
1132 | void ASTContext::InitBuiltinType(CanQualType &R, BuiltinType::Kind K) { | |||
1133 | auto *Ty = new (*this, TypeAlignment) BuiltinType(K); | |||
1134 | R = CanQualType::CreateUnsafe(QualType(Ty, 0)); | |||
1135 | Types.push_back(Ty); | |||
1136 | } | |||
1137 | ||||
1138 | void ASTContext::InitBuiltinTypes(const TargetInfo &Target, | |||
1139 | const TargetInfo *AuxTarget) { | |||
1140 | assert((!this->Target || this->Target == &Target) &&(((!this->Target || this->Target == &Target) && "Incorrect target reinitialization") ? static_cast<void> (0) : __assert_fail ("(!this->Target || this->Target == &Target) && \"Incorrect target reinitialization\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1141, __PRETTY_FUNCTION__)) | |||
1141 | "Incorrect target reinitialization")(((!this->Target || this->Target == &Target) && "Incorrect target reinitialization") ? static_cast<void> (0) : __assert_fail ("(!this->Target || this->Target == &Target) && \"Incorrect target reinitialization\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1141, __PRETTY_FUNCTION__)); | |||
1142 | assert(VoidTy.isNull() && "Context reinitialized?")((VoidTy.isNull() && "Context reinitialized?") ? static_cast <void> (0) : __assert_fail ("VoidTy.isNull() && \"Context reinitialized?\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1142, __PRETTY_FUNCTION__)); | |||
1143 | ||||
1144 | this->Target = &Target; | |||
1145 | this->AuxTarget = AuxTarget; | |||
1146 | ||||
1147 | ABI.reset(createCXXABI(Target)); | |||
1148 | AddrSpaceMap = getAddressSpaceMap(Target, LangOpts); | |||
1149 | AddrSpaceMapMangling = isAddrSpaceMapManglingEnabled(Target, LangOpts); | |||
1150 | ||||
1151 | // C99 6.2.5p19. | |||
1152 | InitBuiltinType(VoidTy, BuiltinType::Void); | |||
1153 | ||||
1154 | // C99 6.2.5p2. | |||
1155 | InitBuiltinType(BoolTy, BuiltinType::Bool); | |||
1156 | // C99 6.2.5p3. | |||
1157 | if (LangOpts.CharIsSigned) | |||
1158 | InitBuiltinType(CharTy, BuiltinType::Char_S); | |||
1159 | else | |||
1160 | InitBuiltinType(CharTy, BuiltinType::Char_U); | |||
1161 | // C99 6.2.5p4. | |||
1162 | InitBuiltinType(SignedCharTy, BuiltinType::SChar); | |||
1163 | InitBuiltinType(ShortTy, BuiltinType::Short); | |||
1164 | InitBuiltinType(IntTy, BuiltinType::Int); | |||
1165 | InitBuiltinType(LongTy, BuiltinType::Long); | |||
1166 | InitBuiltinType(LongLongTy, BuiltinType::LongLong); | |||
1167 | ||||
1168 | // C99 6.2.5p6. | |||
1169 | InitBuiltinType(UnsignedCharTy, BuiltinType::UChar); | |||
1170 | InitBuiltinType(UnsignedShortTy, BuiltinType::UShort); | |||
1171 | InitBuiltinType(UnsignedIntTy, BuiltinType::UInt); | |||
1172 | InitBuiltinType(UnsignedLongTy, BuiltinType::ULong); | |||
1173 | InitBuiltinType(UnsignedLongLongTy, BuiltinType::ULongLong); | |||
1174 | ||||
1175 | // C99 6.2.5p10. | |||
1176 | InitBuiltinType(FloatTy, BuiltinType::Float); | |||
1177 | InitBuiltinType(DoubleTy, BuiltinType::Double); | |||
1178 | InitBuiltinType(LongDoubleTy, BuiltinType::LongDouble); | |||
1179 | ||||
1180 | // GNU extension, __float128 for IEEE quadruple precision | |||
1181 | InitBuiltinType(Float128Ty, BuiltinType::Float128); | |||
1182 | ||||
1183 | // C11 extension ISO/IEC TS 18661-3 | |||
1184 | InitBuiltinType(Float16Ty, BuiltinType::Float16); | |||
1185 | ||||
1186 | // ISO/IEC JTC1 SC22 WG14 N1169 Extension | |||
1187 | InitBuiltinType(ShortAccumTy, BuiltinType::ShortAccum); | |||
1188 | InitBuiltinType(AccumTy, BuiltinType::Accum); | |||
1189 | InitBuiltinType(LongAccumTy, BuiltinType::LongAccum); | |||
1190 | InitBuiltinType(UnsignedShortAccumTy, BuiltinType::UShortAccum); | |||
1191 | InitBuiltinType(UnsignedAccumTy, BuiltinType::UAccum); | |||
1192 | InitBuiltinType(UnsignedLongAccumTy, BuiltinType::ULongAccum); | |||
1193 | InitBuiltinType(ShortFractTy, BuiltinType::ShortFract); | |||
1194 | InitBuiltinType(FractTy, BuiltinType::Fract); | |||
1195 | InitBuiltinType(LongFractTy, BuiltinType::LongFract); | |||
1196 | InitBuiltinType(UnsignedShortFractTy, BuiltinType::UShortFract); | |||
1197 | InitBuiltinType(UnsignedFractTy, BuiltinType::UFract); | |||
1198 | InitBuiltinType(UnsignedLongFractTy, BuiltinType::ULongFract); | |||
1199 | InitBuiltinType(SatShortAccumTy, BuiltinType::SatShortAccum); | |||
1200 | InitBuiltinType(SatAccumTy, BuiltinType::SatAccum); | |||
1201 | InitBuiltinType(SatLongAccumTy, BuiltinType::SatLongAccum); | |||
1202 | InitBuiltinType(SatUnsignedShortAccumTy, BuiltinType::SatUShortAccum); | |||
1203 | InitBuiltinType(SatUnsignedAccumTy, BuiltinType::SatUAccum); | |||
1204 | InitBuiltinType(SatUnsignedLongAccumTy, BuiltinType::SatULongAccum); | |||
1205 | InitBuiltinType(SatShortFractTy, BuiltinType::SatShortFract); | |||
1206 | InitBuiltinType(SatFractTy, BuiltinType::SatFract); | |||
1207 | InitBuiltinType(SatLongFractTy, BuiltinType::SatLongFract); | |||
1208 | InitBuiltinType(SatUnsignedShortFractTy, BuiltinType::SatUShortFract); | |||
1209 | InitBuiltinType(SatUnsignedFractTy, BuiltinType::SatUFract); | |||
1210 | InitBuiltinType(SatUnsignedLongFractTy, BuiltinType::SatULongFract); | |||
1211 | ||||
1212 | // GNU extension, 128-bit integers. | |||
1213 | InitBuiltinType(Int128Ty, BuiltinType::Int128); | |||
1214 | InitBuiltinType(UnsignedInt128Ty, BuiltinType::UInt128); | |||
1215 | ||||
1216 | // C++ 3.9.1p5 | |||
1217 | if (TargetInfo::isTypeSigned(Target.getWCharType())) | |||
1218 | InitBuiltinType(WCharTy, BuiltinType::WChar_S); | |||
1219 | else // -fshort-wchar makes wchar_t be unsigned. | |||
1220 | InitBuiltinType(WCharTy, BuiltinType::WChar_U); | |||
1221 | if (LangOpts.CPlusPlus && LangOpts.WChar) | |||
1222 | WideCharTy = WCharTy; | |||
1223 | else { | |||
1224 | // C99 (or C++ using -fno-wchar). | |||
1225 | WideCharTy = getFromTargetType(Target.getWCharType()); | |||
1226 | } | |||
1227 | ||||
1228 | WIntTy = getFromTargetType(Target.getWIntType()); | |||
1229 | ||||
1230 | // C++20 (proposed) | |||
1231 | InitBuiltinType(Char8Ty, BuiltinType::Char8); | |||
1232 | ||||
1233 | if (LangOpts.CPlusPlus) // C++0x 3.9.1p5, extension for C++ | |||
1234 | InitBuiltinType(Char16Ty, BuiltinType::Char16); | |||
1235 | else // C99 | |||
1236 | Char16Ty = getFromTargetType(Target.getChar16Type()); | |||
1237 | ||||
1238 | if (LangOpts.CPlusPlus) // C++0x 3.9.1p5, extension for C++ | |||
1239 | InitBuiltinType(Char32Ty, BuiltinType::Char32); | |||
1240 | else // C99 | |||
1241 | Char32Ty = getFromTargetType(Target.getChar32Type()); | |||
1242 | ||||
1243 | // Placeholder type for type-dependent expressions whose type is | |||
1244 | // completely unknown. No code should ever check a type against | |||
1245 | // DependentTy and users should never see it; however, it is here to | |||
1246 | // help diagnose failures to properly check for type-dependent | |||
1247 | // expressions. | |||
1248 | InitBuiltinType(DependentTy, BuiltinType::Dependent); | |||
1249 | ||||
1250 | // Placeholder type for functions. | |||
1251 | InitBuiltinType(OverloadTy, BuiltinType::Overload); | |||
1252 | ||||
1253 | // Placeholder type for bound members. | |||
1254 | InitBuiltinType(BoundMemberTy, BuiltinType::BoundMember); | |||
1255 | ||||
1256 | // Placeholder type for pseudo-objects. | |||
1257 | InitBuiltinType(PseudoObjectTy, BuiltinType::PseudoObject); | |||
1258 | ||||
1259 | // "any" type; useful for debugger-like clients. | |||
1260 | InitBuiltinType(UnknownAnyTy, BuiltinType::UnknownAny); | |||
1261 | ||||
1262 | // Placeholder type for unbridged ARC casts. | |||
1263 | InitBuiltinType(ARCUnbridgedCastTy, BuiltinType::ARCUnbridgedCast); | |||
1264 | ||||
1265 | // Placeholder type for builtin functions. | |||
1266 | InitBuiltinType(BuiltinFnTy, BuiltinType::BuiltinFn); | |||
1267 | ||||
1268 | // Placeholder type for OMP array sections. | |||
1269 | if (LangOpts.OpenMP) | |||
1270 | InitBuiltinType(OMPArraySectionTy, BuiltinType::OMPArraySection); | |||
1271 | ||||
1272 | // C99 6.2.5p11. | |||
1273 | FloatComplexTy = getComplexType(FloatTy); | |||
1274 | DoubleComplexTy = getComplexType(DoubleTy); | |||
1275 | LongDoubleComplexTy = getComplexType(LongDoubleTy); | |||
1276 | Float128ComplexTy = getComplexType(Float128Ty); | |||
1277 | ||||
1278 | // Builtin types for 'id', 'Class', and 'SEL'. | |||
1279 | InitBuiltinType(ObjCBuiltinIdTy, BuiltinType::ObjCId); | |||
1280 | InitBuiltinType(ObjCBuiltinClassTy, BuiltinType::ObjCClass); | |||
1281 | InitBuiltinType(ObjCBuiltinSelTy, BuiltinType::ObjCSel); | |||
1282 | ||||
1283 | if (LangOpts.OpenCL) { | |||
1284 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ | |||
1285 | InitBuiltinType(SingletonId, BuiltinType::Id); | |||
1286 | #include "clang/Basic/OpenCLImageTypes.def" | |||
1287 | ||||
1288 | InitBuiltinType(OCLSamplerTy, BuiltinType::OCLSampler); | |||
1289 | InitBuiltinType(OCLEventTy, BuiltinType::OCLEvent); | |||
1290 | InitBuiltinType(OCLClkEventTy, BuiltinType::OCLClkEvent); | |||
1291 | InitBuiltinType(OCLQueueTy, BuiltinType::OCLQueue); | |||
1292 | InitBuiltinType(OCLReserveIDTy, BuiltinType::OCLReserveID); | |||
1293 | ||||
1294 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ | |||
1295 | InitBuiltinType(Id##Ty, BuiltinType::Id); | |||
1296 | #include "clang/Basic/OpenCLExtensionTypes.def" | |||
1297 | } | |||
1298 | ||||
1299 | // Builtin type for __objc_yes and __objc_no | |||
1300 | ObjCBuiltinBoolTy = (Target.useSignedCharForObjCBool() ? | |||
1301 | SignedCharTy : BoolTy); | |||
1302 | ||||
1303 | ObjCConstantStringType = QualType(); | |||
1304 | ||||
1305 | ObjCSuperType = QualType(); | |||
1306 | ||||
1307 | // void * type | |||
1308 | if (LangOpts.OpenCLVersion >= 200) { | |||
1309 | auto Q = VoidTy.getQualifiers(); | |||
1310 | Q.setAddressSpace(LangAS::opencl_generic); | |||
1311 | VoidPtrTy = getPointerType(getCanonicalType( | |||
1312 | getQualifiedType(VoidTy.getUnqualifiedType(), Q))); | |||
1313 | } else { | |||
1314 | VoidPtrTy = getPointerType(VoidTy); | |||
1315 | } | |||
1316 | ||||
1317 | // nullptr type (C++0x 2.14.7) | |||
1318 | InitBuiltinType(NullPtrTy, BuiltinType::NullPtr); | |||
1319 | ||||
1320 | // half type (OpenCL 6.1.1.1) / ARM NEON __fp16 | |||
1321 | InitBuiltinType(HalfTy, BuiltinType::Half); | |||
1322 | ||||
1323 | // Builtin type used to help define __builtin_va_list. | |||
1324 | VaListTagDecl = nullptr; | |||
1325 | } | |||
1326 | ||||
1327 | DiagnosticsEngine &ASTContext::getDiagnostics() const { | |||
1328 | return SourceMgr.getDiagnostics(); | |||
1329 | } | |||
1330 | ||||
1331 | AttrVec& ASTContext::getDeclAttrs(const Decl *D) { | |||
1332 | AttrVec *&Result = DeclAttrs[D]; | |||
1333 | if (!Result) { | |||
1334 | void *Mem = Allocate(sizeof(AttrVec)); | |||
1335 | Result = new (Mem) AttrVec; | |||
1336 | } | |||
1337 | ||||
1338 | return *Result; | |||
1339 | } | |||
1340 | ||||
1341 | /// Erase the attributes corresponding to the given declaration. | |||
1342 | void ASTContext::eraseDeclAttrs(const Decl *D) { | |||
1343 | llvm::DenseMap<const Decl*, AttrVec*>::iterator Pos = DeclAttrs.find(D); | |||
1344 | if (Pos != DeclAttrs.end()) { | |||
1345 | Pos->second->~AttrVec(); | |||
1346 | DeclAttrs.erase(Pos); | |||
1347 | } | |||
1348 | } | |||
1349 | ||||
1350 | // FIXME: Remove ? | |||
1351 | MemberSpecializationInfo * | |||
1352 | ASTContext::getInstantiatedFromStaticDataMember(const VarDecl *Var) { | |||
1353 | assert(Var->isStaticDataMember() && "Not a static data member")((Var->isStaticDataMember() && "Not a static data member" ) ? static_cast<void> (0) : __assert_fail ("Var->isStaticDataMember() && \"Not a static data member\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1353, __PRETTY_FUNCTION__)); | |||
1354 | return getTemplateOrSpecializationInfo(Var) | |||
1355 | .dyn_cast<MemberSpecializationInfo *>(); | |||
1356 | } | |||
1357 | ||||
1358 | ASTContext::TemplateOrSpecializationInfo | |||
1359 | ASTContext::getTemplateOrSpecializationInfo(const VarDecl *Var) { | |||
1360 | llvm::DenseMap<const VarDecl *, TemplateOrSpecializationInfo>::iterator Pos = | |||
1361 | TemplateOrInstantiation.find(Var); | |||
1362 | if (Pos == TemplateOrInstantiation.end()) | |||
1363 | return {}; | |||
1364 | ||||
1365 | return Pos->second; | |||
1366 | } | |||
1367 | ||||
1368 | void | |||
1369 | ASTContext::setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl, | |||
1370 | TemplateSpecializationKind TSK, | |||
1371 | SourceLocation PointOfInstantiation) { | |||
1372 | assert(Inst->isStaticDataMember() && "Not a static data member")((Inst->isStaticDataMember() && "Not a static data member" ) ? static_cast<void> (0) : __assert_fail ("Inst->isStaticDataMember() && \"Not a static data member\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1372, __PRETTY_FUNCTION__)); | |||
1373 | assert(Tmpl->isStaticDataMember() && "Not a static data member")((Tmpl->isStaticDataMember() && "Not a static data member" ) ? static_cast<void> (0) : __assert_fail ("Tmpl->isStaticDataMember() && \"Not a static data member\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1373, __PRETTY_FUNCTION__)); | |||
1374 | setTemplateOrSpecializationInfo(Inst, new (*this) MemberSpecializationInfo( | |||
1375 | Tmpl, TSK, PointOfInstantiation)); | |||
1376 | } | |||
1377 | ||||
1378 | void | |||
1379 | ASTContext::setTemplateOrSpecializationInfo(VarDecl *Inst, | |||
1380 | TemplateOrSpecializationInfo TSI) { | |||
1381 | assert(!TemplateOrInstantiation[Inst] &&((!TemplateOrInstantiation[Inst] && "Already noted what the variable was instantiated from" ) ? static_cast<void> (0) : __assert_fail ("!TemplateOrInstantiation[Inst] && \"Already noted what the variable was instantiated from\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1382, __PRETTY_FUNCTION__)) | |||
1382 | "Already noted what the variable was instantiated from")((!TemplateOrInstantiation[Inst] && "Already noted what the variable was instantiated from" ) ? static_cast<void> (0) : __assert_fail ("!TemplateOrInstantiation[Inst] && \"Already noted what the variable was instantiated from\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1382, __PRETTY_FUNCTION__)); | |||
1383 | TemplateOrInstantiation[Inst] = TSI; | |||
1384 | } | |||
1385 | ||||
1386 | NamedDecl * | |||
1387 | ASTContext::getInstantiatedFromUsingDecl(NamedDecl *UUD) { | |||
1388 | auto Pos = InstantiatedFromUsingDecl.find(UUD); | |||
1389 | if (Pos == InstantiatedFromUsingDecl.end()) | |||
1390 | return nullptr; | |||
1391 | ||||
1392 | return Pos->second; | |||
1393 | } | |||
1394 | ||||
1395 | void | |||
1396 | ASTContext::setInstantiatedFromUsingDecl(NamedDecl *Inst, NamedDecl *Pattern) { | |||
1397 | assert((isa<UsingDecl>(Pattern) ||(((isa<UsingDecl>(Pattern) || isa<UnresolvedUsingValueDecl >(Pattern) || isa<UnresolvedUsingTypenameDecl>(Pattern )) && "pattern decl is not a using decl") ? static_cast <void> (0) : __assert_fail ("(isa<UsingDecl>(Pattern) || isa<UnresolvedUsingValueDecl>(Pattern) || isa<UnresolvedUsingTypenameDecl>(Pattern)) && \"pattern decl is not a using decl\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1400, __PRETTY_FUNCTION__)) | |||
1398 | isa<UnresolvedUsingValueDecl>(Pattern) ||(((isa<UsingDecl>(Pattern) || isa<UnresolvedUsingValueDecl >(Pattern) || isa<UnresolvedUsingTypenameDecl>(Pattern )) && "pattern decl is not a using decl") ? static_cast <void> (0) : __assert_fail ("(isa<UsingDecl>(Pattern) || isa<UnresolvedUsingValueDecl>(Pattern) || isa<UnresolvedUsingTypenameDecl>(Pattern)) && \"pattern decl is not a using decl\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1400, __PRETTY_FUNCTION__)) | |||
1399 | isa<UnresolvedUsingTypenameDecl>(Pattern)) &&(((isa<UsingDecl>(Pattern) || isa<UnresolvedUsingValueDecl >(Pattern) || isa<UnresolvedUsingTypenameDecl>(Pattern )) && "pattern decl is not a using decl") ? static_cast <void> (0) : __assert_fail ("(isa<UsingDecl>(Pattern) || isa<UnresolvedUsingValueDecl>(Pattern) || isa<UnresolvedUsingTypenameDecl>(Pattern)) && \"pattern decl is not a using decl\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1400, __PRETTY_FUNCTION__)) | |||
1400 | "pattern decl is not a using decl")(((isa<UsingDecl>(Pattern) || isa<UnresolvedUsingValueDecl >(Pattern) || isa<UnresolvedUsingTypenameDecl>(Pattern )) && "pattern decl is not a using decl") ? static_cast <void> (0) : __assert_fail ("(isa<UsingDecl>(Pattern) || isa<UnresolvedUsingValueDecl>(Pattern) || isa<UnresolvedUsingTypenameDecl>(Pattern)) && \"pattern decl is not a using decl\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1400, __PRETTY_FUNCTION__)); | |||
1401 | assert((isa<UsingDecl>(Inst) ||(((isa<UsingDecl>(Inst) || isa<UnresolvedUsingValueDecl >(Inst) || isa<UnresolvedUsingTypenameDecl>(Inst)) && "instantiation did not produce a using decl") ? static_cast< void> (0) : __assert_fail ("(isa<UsingDecl>(Inst) || isa<UnresolvedUsingValueDecl>(Inst) || isa<UnresolvedUsingTypenameDecl>(Inst)) && \"instantiation did not produce a using decl\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1404, __PRETTY_FUNCTION__)) | |||
1402 | isa<UnresolvedUsingValueDecl>(Inst) ||(((isa<UsingDecl>(Inst) || isa<UnresolvedUsingValueDecl >(Inst) || isa<UnresolvedUsingTypenameDecl>(Inst)) && "instantiation did not produce a using decl") ? static_cast< void> (0) : __assert_fail ("(isa<UsingDecl>(Inst) || isa<UnresolvedUsingValueDecl>(Inst) || isa<UnresolvedUsingTypenameDecl>(Inst)) && \"instantiation did not produce a using decl\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1404, __PRETTY_FUNCTION__)) | |||
1403 | isa<UnresolvedUsingTypenameDecl>(Inst)) &&(((isa<UsingDecl>(Inst) || isa<UnresolvedUsingValueDecl >(Inst) || isa<UnresolvedUsingTypenameDecl>(Inst)) && "instantiation did not produce a using decl") ? static_cast< void> (0) : __assert_fail ("(isa<UsingDecl>(Inst) || isa<UnresolvedUsingValueDecl>(Inst) || isa<UnresolvedUsingTypenameDecl>(Inst)) && \"instantiation did not produce a using decl\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1404, __PRETTY_FUNCTION__)) | |||
1404 | "instantiation did not produce a using decl")(((isa<UsingDecl>(Inst) || isa<UnresolvedUsingValueDecl >(Inst) || isa<UnresolvedUsingTypenameDecl>(Inst)) && "instantiation did not produce a using decl") ? static_cast< void> (0) : __assert_fail ("(isa<UsingDecl>(Inst) || isa<UnresolvedUsingValueDecl>(Inst) || isa<UnresolvedUsingTypenameDecl>(Inst)) && \"instantiation did not produce a using decl\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1404, __PRETTY_FUNCTION__)); | |||
1405 | assert(!InstantiatedFromUsingDecl[Inst] && "pattern already exists")((!InstantiatedFromUsingDecl[Inst] && "pattern already exists" ) ? static_cast<void> (0) : __assert_fail ("!InstantiatedFromUsingDecl[Inst] && \"pattern already exists\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1405, __PRETTY_FUNCTION__)); | |||
1406 | InstantiatedFromUsingDecl[Inst] = Pattern; | |||
1407 | } | |||
1408 | ||||
1409 | UsingShadowDecl * | |||
1410 | ASTContext::getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst) { | |||
1411 | llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*>::const_iterator Pos | |||
1412 | = InstantiatedFromUsingShadowDecl.find(Inst); | |||
1413 | if (Pos == InstantiatedFromUsingShadowDecl.end()) | |||
1414 | return nullptr; | |||
1415 | ||||
1416 | return Pos->second; | |||
1417 | } | |||
1418 | ||||
1419 | void | |||
1420 | ASTContext::setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, | |||
1421 | UsingShadowDecl *Pattern) { | |||
1422 | assert(!InstantiatedFromUsingShadowDecl[Inst] && "pattern already exists")((!InstantiatedFromUsingShadowDecl[Inst] && "pattern already exists" ) ? static_cast<void> (0) : __assert_fail ("!InstantiatedFromUsingShadowDecl[Inst] && \"pattern already exists\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1422, __PRETTY_FUNCTION__)); | |||
1423 | InstantiatedFromUsingShadowDecl[Inst] = Pattern; | |||
1424 | } | |||
1425 | ||||
1426 | FieldDecl *ASTContext::getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field) { | |||
1427 | llvm::DenseMap<FieldDecl *, FieldDecl *>::iterator Pos | |||
1428 | = InstantiatedFromUnnamedFieldDecl.find(Field); | |||
1429 | if (Pos == InstantiatedFromUnnamedFieldDecl.end()) | |||
1430 | return nullptr; | |||
1431 | ||||
1432 | return Pos->second; | |||
1433 | } | |||
1434 | ||||
1435 | void ASTContext::setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, | |||
1436 | FieldDecl *Tmpl) { | |||
1437 | assert(!Inst->getDeclName() && "Instantiated field decl is not unnamed")((!Inst->getDeclName() && "Instantiated field decl is not unnamed" ) ? static_cast<void> (0) : __assert_fail ("!Inst->getDeclName() && \"Instantiated field decl is not unnamed\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1437, __PRETTY_FUNCTION__)); | |||
1438 | assert(!Tmpl->getDeclName() && "Template field decl is not unnamed")((!Tmpl->getDeclName() && "Template field decl is not unnamed" ) ? static_cast<void> (0) : __assert_fail ("!Tmpl->getDeclName() && \"Template field decl is not unnamed\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1438, __PRETTY_FUNCTION__)); | |||
1439 | assert(!InstantiatedFromUnnamedFieldDecl[Inst] &&((!InstantiatedFromUnnamedFieldDecl[Inst] && "Already noted what unnamed field was instantiated from" ) ? static_cast<void> (0) : __assert_fail ("!InstantiatedFromUnnamedFieldDecl[Inst] && \"Already noted what unnamed field was instantiated from\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1440, __PRETTY_FUNCTION__)) | |||
1440 | "Already noted what unnamed field was instantiated from")((!InstantiatedFromUnnamedFieldDecl[Inst] && "Already noted what unnamed field was instantiated from" ) ? static_cast<void> (0) : __assert_fail ("!InstantiatedFromUnnamedFieldDecl[Inst] && \"Already noted what unnamed field was instantiated from\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1440, __PRETTY_FUNCTION__)); | |||
1441 | ||||
1442 | InstantiatedFromUnnamedFieldDecl[Inst] = Tmpl; | |||
1443 | } | |||
1444 | ||||
1445 | ASTContext::overridden_cxx_method_iterator | |||
1446 | ASTContext::overridden_methods_begin(const CXXMethodDecl *Method) const { | |||
1447 | return overridden_methods(Method).begin(); | |||
1448 | } | |||
1449 | ||||
1450 | ASTContext::overridden_cxx_method_iterator | |||
1451 | ASTContext::overridden_methods_end(const CXXMethodDecl *Method) const { | |||
1452 | return overridden_methods(Method).end(); | |||
1453 | } | |||
1454 | ||||
1455 | unsigned | |||
1456 | ASTContext::overridden_methods_size(const CXXMethodDecl *Method) const { | |||
1457 | auto Range = overridden_methods(Method); | |||
1458 | return Range.end() - Range.begin(); | |||
1459 | } | |||
1460 | ||||
1461 | ASTContext::overridden_method_range | |||
1462 | ASTContext::overridden_methods(const CXXMethodDecl *Method) const { | |||
1463 | llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector>::const_iterator Pos = | |||
1464 | OverriddenMethods.find(Method->getCanonicalDecl()); | |||
1465 | if (Pos == OverriddenMethods.end()) | |||
1466 | return overridden_method_range(nullptr, nullptr); | |||
1467 | return overridden_method_range(Pos->second.begin(), Pos->second.end()); | |||
1468 | } | |||
1469 | ||||
1470 | void ASTContext::addOverriddenMethod(const CXXMethodDecl *Method, | |||
1471 | const CXXMethodDecl *Overridden) { | |||
1472 | assert(Method->isCanonicalDecl() && Overridden->isCanonicalDecl())((Method->isCanonicalDecl() && Overridden->isCanonicalDecl ()) ? static_cast<void> (0) : __assert_fail ("Method->isCanonicalDecl() && Overridden->isCanonicalDecl()" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1472, __PRETTY_FUNCTION__)); | |||
1473 | OverriddenMethods[Method].push_back(Overridden); | |||
1474 | } | |||
1475 | ||||
1476 | void ASTContext::getOverriddenMethods( | |||
1477 | const NamedDecl *D, | |||
1478 | SmallVectorImpl<const NamedDecl *> &Overridden) const { | |||
1479 | assert(D)((D) ? static_cast<void> (0) : __assert_fail ("D", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1479, __PRETTY_FUNCTION__)); | |||
1480 | ||||
1481 | if (const auto *CXXMethod = dyn_cast<CXXMethodDecl>(D)) { | |||
1482 | Overridden.append(overridden_methods_begin(CXXMethod), | |||
1483 | overridden_methods_end(CXXMethod)); | |||
1484 | return; | |||
1485 | } | |||
1486 | ||||
1487 | const auto *Method = dyn_cast<ObjCMethodDecl>(D); | |||
1488 | if (!Method) | |||
1489 | return; | |||
1490 | ||||
1491 | SmallVector<const ObjCMethodDecl *, 8> OverDecls; | |||
1492 | Method->getOverriddenMethods(OverDecls); | |||
1493 | Overridden.append(OverDecls.begin(), OverDecls.end()); | |||
1494 | } | |||
1495 | ||||
1496 | void ASTContext::addedLocalImportDecl(ImportDecl *Import) { | |||
1497 | assert(!Import->NextLocalImport && "Import declaration already in the chain")((!Import->NextLocalImport && "Import declaration already in the chain" ) ? static_cast<void> (0) : __assert_fail ("!Import->NextLocalImport && \"Import declaration already in the chain\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1497, __PRETTY_FUNCTION__)); | |||
1498 | assert(!Import->isFromASTFile() && "Non-local import declaration")((!Import->isFromASTFile() && "Non-local import declaration" ) ? static_cast<void> (0) : __assert_fail ("!Import->isFromASTFile() && \"Non-local import declaration\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1498, __PRETTY_FUNCTION__)); | |||
1499 | if (!FirstLocalImport) { | |||
1500 | FirstLocalImport = Import; | |||
1501 | LastLocalImport = Import; | |||
1502 | return; | |||
1503 | } | |||
1504 | ||||
1505 | LastLocalImport->NextLocalImport = Import; | |||
1506 | LastLocalImport = Import; | |||
1507 | } | |||
1508 | ||||
1509 | //===----------------------------------------------------------------------===// | |||
1510 | // Type Sizing and Analysis | |||
1511 | //===----------------------------------------------------------------------===// | |||
1512 | ||||
1513 | /// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified | |||
1514 | /// scalar floating point type. | |||
1515 | const llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const { | |||
1516 | const auto *BT = T->getAs<BuiltinType>(); | |||
1517 | assert(BT && "Not a floating point type!")((BT && "Not a floating point type!") ? static_cast< void> (0) : __assert_fail ("BT && \"Not a floating point type!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1517, __PRETTY_FUNCTION__)); | |||
1518 | switch (BT->getKind()) { | |||
1519 | default: llvm_unreachable("Not a floating point type!")::llvm::llvm_unreachable_internal("Not a floating point type!" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1519); | |||
1520 | case BuiltinType::Float16: | |||
1521 | case BuiltinType::Half: | |||
1522 | return Target->getHalfFormat(); | |||
1523 | case BuiltinType::Float: return Target->getFloatFormat(); | |||
1524 | case BuiltinType::Double: return Target->getDoubleFormat(); | |||
1525 | case BuiltinType::LongDouble: return Target->getLongDoubleFormat(); | |||
1526 | case BuiltinType::Float128: return Target->getFloat128Format(); | |||
1527 | } | |||
1528 | } | |||
1529 | ||||
1530 | CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const { | |||
1531 | unsigned Align = Target->getCharWidth(); | |||
1532 | ||||
1533 | bool UseAlignAttrOnly = false; | |||
1534 | if (unsigned AlignFromAttr = D->getMaxAlignment()) { | |||
1535 | Align = AlignFromAttr; | |||
1536 | ||||
1537 | // __attribute__((aligned)) can increase or decrease alignment | |||
1538 | // *except* on a struct or struct member, where it only increases | |||
1539 | // alignment unless 'packed' is also specified. | |||
1540 | // | |||
1541 | // It is an error for alignas to decrease alignment, so we can | |||
1542 | // ignore that possibility; Sema should diagnose it. | |||
1543 | if (isa<FieldDecl>(D)) { | |||
1544 | UseAlignAttrOnly = D->hasAttr<PackedAttr>() || | |||
1545 | cast<FieldDecl>(D)->getParent()->hasAttr<PackedAttr>(); | |||
1546 | } else { | |||
1547 | UseAlignAttrOnly = true; | |||
1548 | } | |||
1549 | } | |||
1550 | else if (isa<FieldDecl>(D)) | |||
1551 | UseAlignAttrOnly = | |||
1552 | D->hasAttr<PackedAttr>() || | |||
1553 | cast<FieldDecl>(D)->getParent()->hasAttr<PackedAttr>(); | |||
1554 | ||||
1555 | // If we're using the align attribute only, just ignore everything | |||
1556 | // else about the declaration and its type. | |||
1557 | if (UseAlignAttrOnly) { | |||
1558 | // do nothing | |||
1559 | } else if (const auto *VD = dyn_cast<ValueDecl>(D)) { | |||
1560 | QualType T = VD->getType(); | |||
1561 | if (const auto *RT = T->getAs<ReferenceType>()) { | |||
1562 | if (ForAlignof) | |||
1563 | T = RT->getPointeeType(); | |||
1564 | else | |||
1565 | T = getPointerType(RT->getPointeeType()); | |||
1566 | } | |||
1567 | QualType BaseT = getBaseElementType(T); | |||
1568 | if (T->isFunctionType()) | |||
1569 | Align = getTypeInfoImpl(T.getTypePtr()).Align; | |||
1570 | else if (!BaseT->isIncompleteType()) { | |||
1571 | // Adjust alignments of declarations with array type by the | |||
1572 | // large-array alignment on the target. | |||
1573 | if (const ArrayType *arrayType = getAsArrayType(T)) { | |||
1574 | unsigned MinWidth = Target->getLargeArrayMinWidth(); | |||
1575 | if (!ForAlignof && MinWidth) { | |||
1576 | if (isa<VariableArrayType>(arrayType)) | |||
1577 | Align = std::max(Align, Target->getLargeArrayAlign()); | |||
1578 | else if (isa<ConstantArrayType>(arrayType) && | |||
1579 | MinWidth <= getTypeSize(cast<ConstantArrayType>(arrayType))) | |||
1580 | Align = std::max(Align, Target->getLargeArrayAlign()); | |||
1581 | } | |||
1582 | } | |||
1583 | Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr())); | |||
1584 | if (BaseT.getQualifiers().hasUnaligned()) | |||
1585 | Align = Target->getCharWidth(); | |||
1586 | if (const auto *VD = dyn_cast<VarDecl>(D)) { | |||
1587 | if (VD->hasGlobalStorage() && !ForAlignof) { | |||
1588 | uint64_t TypeSize = getTypeSize(T.getTypePtr()); | |||
1589 | Align = std::max(Align, getTargetInfo().getMinGlobalAlign(TypeSize)); | |||
1590 | } | |||
1591 | } | |||
1592 | } | |||
1593 | ||||
1594 | // Fields can be subject to extra alignment constraints, like if | |||
1595 | // the field is packed, the struct is packed, or the struct has a | |||
1596 | // a max-field-alignment constraint (#pragma pack). So calculate | |||
1597 | // the actual alignment of the field within the struct, and then | |||
1598 | // (as we're expected to) constrain that by the alignment of the type. | |||
1599 | if (const auto *Field = dyn_cast<FieldDecl>(VD)) { | |||
1600 | const RecordDecl *Parent = Field->getParent(); | |||
1601 | // We can only produce a sensible answer if the record is valid. | |||
1602 | if (!Parent->isInvalidDecl()) { | |||
1603 | const ASTRecordLayout &Layout = getASTRecordLayout(Parent); | |||
1604 | ||||
1605 | // Start with the record's overall alignment. | |||
1606 | unsigned FieldAlign = toBits(Layout.getAlignment()); | |||
1607 | ||||
1608 | // Use the GCD of that and the offset within the record. | |||
1609 | uint64_t Offset = Layout.getFieldOffset(Field->getFieldIndex()); | |||
1610 | if (Offset > 0) { | |||
1611 | // Alignment is always a power of 2, so the GCD will be a power of 2, | |||
1612 | // which means we get to do this crazy thing instead of Euclid's. | |||
1613 | uint64_t LowBitOfOffset = Offset & (~Offset + 1); | |||
1614 | if (LowBitOfOffset < FieldAlign) | |||
1615 | FieldAlign = static_cast<unsigned>(LowBitOfOffset); | |||
1616 | } | |||
1617 | ||||
1618 | Align = std::min(Align, FieldAlign); | |||
1619 | } | |||
1620 | } | |||
1621 | } | |||
1622 | ||||
1623 | return toCharUnitsFromBits(Align); | |||
1624 | } | |||
1625 | ||||
1626 | // getTypeInfoDataSizeInChars - Return the size of a type, in | |||
1627 | // chars. If the type is a record, its data size is returned. This is | |||
1628 | // the size of the memcpy that's performed when assigning this type | |||
1629 | // using a trivial copy/move assignment operator. | |||
1630 | std::pair<CharUnits, CharUnits> | |||
1631 | ASTContext::getTypeInfoDataSizeInChars(QualType T) const { | |||
1632 | std::pair<CharUnits, CharUnits> sizeAndAlign = getTypeInfoInChars(T); | |||
1633 | ||||
1634 | // In C++, objects can sometimes be allocated into the tail padding | |||
1635 | // of a base-class subobject. We decide whether that's possible | |||
1636 | // during class layout, so here we can just trust the layout results. | |||
1637 | if (getLangOpts().CPlusPlus) { | |||
1638 | if (const auto *RT = T->getAs<RecordType>()) { | |||
1639 | const ASTRecordLayout &layout = getASTRecordLayout(RT->getDecl()); | |||
1640 | sizeAndAlign.first = layout.getDataSize(); | |||
1641 | } | |||
1642 | } | |||
1643 | ||||
1644 | return sizeAndAlign; | |||
1645 | } | |||
1646 | ||||
1647 | /// getConstantArrayInfoInChars - Performing the computation in CharUnits | |||
1648 | /// instead of in bits prevents overflowing the uint64_t for some large arrays. | |||
1649 | std::pair<CharUnits, CharUnits> | |||
1650 | static getConstantArrayInfoInChars(const ASTContext &Context, | |||
1651 | const ConstantArrayType *CAT) { | |||
1652 | std::pair<CharUnits, CharUnits> EltInfo = | |||
1653 | Context.getTypeInfoInChars(CAT->getElementType()); | |||
1654 | uint64_t Size = CAT->getSize().getZExtValue(); | |||
1655 | assert((Size == 0 || static_cast<uint64_t>(EltInfo.first.getQuantity()) <=(((Size == 0 || static_cast<uint64_t>(EltInfo.first.getQuantity ()) <= (uint64_t)(-1)/Size) && "Overflow in array type char size evaluation" ) ? static_cast<void> (0) : __assert_fail ("(Size == 0 || static_cast<uint64_t>(EltInfo.first.getQuantity()) <= (uint64_t)(-1)/Size) && \"Overflow in array type char size evaluation\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1657, __PRETTY_FUNCTION__)) | |||
1656 | (uint64_t)(-1)/Size) &&(((Size == 0 || static_cast<uint64_t>(EltInfo.first.getQuantity ()) <= (uint64_t)(-1)/Size) && "Overflow in array type char size evaluation" ) ? static_cast<void> (0) : __assert_fail ("(Size == 0 || static_cast<uint64_t>(EltInfo.first.getQuantity()) <= (uint64_t)(-1)/Size) && \"Overflow in array type char size evaluation\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1657, __PRETTY_FUNCTION__)) | |||
1657 | "Overflow in array type char size evaluation")(((Size == 0 || static_cast<uint64_t>(EltInfo.first.getQuantity ()) <= (uint64_t)(-1)/Size) && "Overflow in array type char size evaluation" ) ? static_cast<void> (0) : __assert_fail ("(Size == 0 || static_cast<uint64_t>(EltInfo.first.getQuantity()) <= (uint64_t)(-1)/Size) && \"Overflow in array type char size evaluation\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1657, __PRETTY_FUNCTION__)); | |||
1658 | uint64_t Width = EltInfo.first.getQuantity() * Size; | |||
1659 | unsigned Align = EltInfo.second.getQuantity(); | |||
1660 | if (!Context.getTargetInfo().getCXXABI().isMicrosoft() || | |||
1661 | Context.getTargetInfo().getPointerWidth(0) == 64) | |||
1662 | Width = llvm::alignTo(Width, Align); | |||
1663 | return std::make_pair(CharUnits::fromQuantity(Width), | |||
1664 | CharUnits::fromQuantity(Align)); | |||
1665 | } | |||
1666 | ||||
1667 | std::pair<CharUnits, CharUnits> | |||
1668 | ASTContext::getTypeInfoInChars(const Type *T) const { | |||
1669 | if (const auto *CAT = dyn_cast<ConstantArrayType>(T)) | |||
1670 | return getConstantArrayInfoInChars(*this, CAT); | |||
1671 | TypeInfo Info = getTypeInfo(T); | |||
1672 | return std::make_pair(toCharUnitsFromBits(Info.Width), | |||
1673 | toCharUnitsFromBits(Info.Align)); | |||
1674 | } | |||
1675 | ||||
1676 | std::pair<CharUnits, CharUnits> | |||
1677 | ASTContext::getTypeInfoInChars(QualType T) const { | |||
1678 | return getTypeInfoInChars(T.getTypePtr()); | |||
1679 | } | |||
1680 | ||||
1681 | bool ASTContext::isAlignmentRequired(const Type *T) const { | |||
1682 | return getTypeInfo(T).AlignIsRequired; | |||
1683 | } | |||
1684 | ||||
1685 | bool ASTContext::isAlignmentRequired(QualType T) const { | |||
1686 | return isAlignmentRequired(T.getTypePtr()); | |||
1687 | } | |||
1688 | ||||
1689 | unsigned ASTContext::getTypeAlignIfKnown(QualType T) const { | |||
1690 | // An alignment on a typedef overrides anything else. | |||
1691 | if (const auto *TT = T->getAs<TypedefType>()) | |||
1692 | if (unsigned Align = TT->getDecl()->getMaxAlignment()) | |||
1693 | return Align; | |||
1694 | ||||
1695 | // If we have an (array of) complete type, we're done. | |||
1696 | T = getBaseElementType(T); | |||
1697 | if (!T->isIncompleteType()) | |||
1698 | return getTypeAlign(T); | |||
1699 | ||||
1700 | // If we had an array type, its element type might be a typedef | |||
1701 | // type with an alignment attribute. | |||
1702 | if (const auto *TT = T->getAs<TypedefType>()) | |||
1703 | if (unsigned Align = TT->getDecl()->getMaxAlignment()) | |||
1704 | return Align; | |||
1705 | ||||
1706 | // Otherwise, see if the declaration of the type had an attribute. | |||
1707 | if (const auto *TT = T->getAs<TagType>()) | |||
1708 | return TT->getDecl()->getMaxAlignment(); | |||
1709 | ||||
1710 | return 0; | |||
1711 | } | |||
1712 | ||||
1713 | TypeInfo ASTContext::getTypeInfo(const Type *T) const { | |||
1714 | TypeInfoMap::iterator I = MemoizedTypeInfo.find(T); | |||
1715 | if (I != MemoizedTypeInfo.end()) | |||
1716 | return I->second; | |||
1717 | ||||
1718 | // This call can invalidate MemoizedTypeInfo[T], so we need a second lookup. | |||
1719 | TypeInfo TI = getTypeInfoImpl(T); | |||
1720 | MemoizedTypeInfo[T] = TI; | |||
1721 | return TI; | |||
1722 | } | |||
1723 | ||||
1724 | /// getTypeInfoImpl - Return the size of the specified type, in bits. This | |||
1725 | /// method does not work on incomplete types. | |||
1726 | /// | |||
1727 | /// FIXME: Pointers into different addr spaces could have different sizes and | |||
1728 | /// alignment requirements: getPointerInfo should take an AddrSpace, this | |||
1729 | /// should take a QualType, &c. | |||
1730 | TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { | |||
1731 | uint64_t Width = 0; | |||
1732 | unsigned Align = 8; | |||
1733 | bool AlignIsRequired = false; | |||
1734 | unsigned AS = 0; | |||
1735 | switch (T->getTypeClass()) { | |||
1736 | #define TYPE(Class, Base) | |||
1737 | #define ABSTRACT_TYPE(Class, Base) | |||
1738 | #define NON_CANONICAL_TYPE(Class, Base) | |||
1739 | #define DEPENDENT_TYPE(Class, Base) case Type::Class: | |||
1740 | #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) \ | |||
1741 | case Type::Class: \ | |||
1742 | assert(!T->isDependentType() && "should not see dependent types here")((!T->isDependentType() && "should not see dependent types here" ) ? static_cast<void> (0) : __assert_fail ("!T->isDependentType() && \"should not see dependent types here\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1742, __PRETTY_FUNCTION__)); \ | |||
1743 | return getTypeInfo(cast<Class##Type>(T)->desugar().getTypePtr()); | |||
1744 | #include "clang/AST/TypeNodes.def" | |||
1745 | llvm_unreachable("Should not see dependent types")::llvm::llvm_unreachable_internal("Should not see dependent types" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1745); | |||
1746 | ||||
1747 | case Type::FunctionNoProto: | |||
1748 | case Type::FunctionProto: | |||
1749 | // GCC extension: alignof(function) = 32 bits | |||
1750 | Width = 0; | |||
1751 | Align = 32; | |||
1752 | break; | |||
1753 | ||||
1754 | case Type::IncompleteArray: | |||
1755 | case Type::VariableArray: | |||
1756 | Width = 0; | |||
1757 | Align = getTypeAlign(cast<ArrayType>(T)->getElementType()); | |||
1758 | break; | |||
1759 | ||||
1760 | case Type::ConstantArray: { | |||
1761 | const auto *CAT = cast<ConstantArrayType>(T); | |||
1762 | ||||
1763 | TypeInfo EltInfo = getTypeInfo(CAT->getElementType()); | |||
1764 | uint64_t Size = CAT->getSize().getZExtValue(); | |||
1765 | assert((Size == 0 || EltInfo.Width <= (uint64_t)(-1) / Size) &&(((Size == 0 || EltInfo.Width <= (uint64_t)(-1) / Size) && "Overflow in array type bit size evaluation") ? static_cast< void> (0) : __assert_fail ("(Size == 0 || EltInfo.Width <= (uint64_t)(-1) / Size) && \"Overflow in array type bit size evaluation\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1766, __PRETTY_FUNCTION__)) | |||
1766 | "Overflow in array type bit size evaluation")(((Size == 0 || EltInfo.Width <= (uint64_t)(-1) / Size) && "Overflow in array type bit size evaluation") ? static_cast< void> (0) : __assert_fail ("(Size == 0 || EltInfo.Width <= (uint64_t)(-1) / Size) && \"Overflow in array type bit size evaluation\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1766, __PRETTY_FUNCTION__)); | |||
1767 | Width = EltInfo.Width * Size; | |||
1768 | Align = EltInfo.Align; | |||
1769 | if (!getTargetInfo().getCXXABI().isMicrosoft() || | |||
1770 | getTargetInfo().getPointerWidth(0) == 64) | |||
1771 | Width = llvm::alignTo(Width, Align); | |||
1772 | break; | |||
1773 | } | |||
1774 | case Type::ExtVector: | |||
1775 | case Type::Vector: { | |||
1776 | const auto *VT = cast<VectorType>(T); | |||
1777 | TypeInfo EltInfo = getTypeInfo(VT->getElementType()); | |||
1778 | Width = EltInfo.Width * VT->getNumElements(); | |||
1779 | Align = Width; | |||
1780 | // If the alignment is not a power of 2, round up to the next power of 2. | |||
1781 | // This happens for non-power-of-2 length vectors. | |||
1782 | if (Align & (Align-1)) { | |||
1783 | Align = llvm::NextPowerOf2(Align); | |||
1784 | Width = llvm::alignTo(Width, Align); | |||
1785 | } | |||
1786 | // Adjust the alignment based on the target max. | |||
1787 | uint64_t TargetVectorAlign = Target->getMaxVectorAlign(); | |||
1788 | if (TargetVectorAlign && TargetVectorAlign < Align) | |||
1789 | Align = TargetVectorAlign; | |||
1790 | break; | |||
1791 | } | |||
1792 | ||||
1793 | case Type::Builtin: | |||
1794 | switch (cast<BuiltinType>(T)->getKind()) { | |||
1795 | default: llvm_unreachable("Unknown builtin type!")::llvm::llvm_unreachable_internal("Unknown builtin type!", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1795); | |||
1796 | case BuiltinType::Void: | |||
1797 | // GCC extension: alignof(void) = 8 bits. | |||
1798 | Width = 0; | |||
1799 | Align = 8; | |||
1800 | break; | |||
1801 | case BuiltinType::Bool: | |||
1802 | Width = Target->getBoolWidth(); | |||
1803 | Align = Target->getBoolAlign(); | |||
1804 | break; | |||
1805 | case BuiltinType::Char_S: | |||
1806 | case BuiltinType::Char_U: | |||
1807 | case BuiltinType::UChar: | |||
1808 | case BuiltinType::SChar: | |||
1809 | case BuiltinType::Char8: | |||
1810 | Width = Target->getCharWidth(); | |||
1811 | Align = Target->getCharAlign(); | |||
1812 | break; | |||
1813 | case BuiltinType::WChar_S: | |||
1814 | case BuiltinType::WChar_U: | |||
1815 | Width = Target->getWCharWidth(); | |||
1816 | Align = Target->getWCharAlign(); | |||
1817 | break; | |||
1818 | case BuiltinType::Char16: | |||
1819 | Width = Target->getChar16Width(); | |||
1820 | Align = Target->getChar16Align(); | |||
1821 | break; | |||
1822 | case BuiltinType::Char32: | |||
1823 | Width = Target->getChar32Width(); | |||
1824 | Align = Target->getChar32Align(); | |||
1825 | break; | |||
1826 | case BuiltinType::UShort: | |||
1827 | case BuiltinType::Short: | |||
1828 | Width = Target->getShortWidth(); | |||
1829 | Align = Target->getShortAlign(); | |||
1830 | break; | |||
1831 | case BuiltinType::UInt: | |||
1832 | case BuiltinType::Int: | |||
1833 | Width = Target->getIntWidth(); | |||
1834 | Align = Target->getIntAlign(); | |||
1835 | break; | |||
1836 | case BuiltinType::ULong: | |||
1837 | case BuiltinType::Long: | |||
1838 | Width = Target->getLongWidth(); | |||
1839 | Align = Target->getLongAlign(); | |||
1840 | break; | |||
1841 | case BuiltinType::ULongLong: | |||
1842 | case BuiltinType::LongLong: | |||
1843 | Width = Target->getLongLongWidth(); | |||
1844 | Align = Target->getLongLongAlign(); | |||
1845 | break; | |||
1846 | case BuiltinType::Int128: | |||
1847 | case BuiltinType::UInt128: | |||
1848 | Width = 128; | |||
1849 | Align = 128; // int128_t is 128-bit aligned on all targets. | |||
1850 | break; | |||
1851 | case BuiltinType::ShortAccum: | |||
1852 | case BuiltinType::UShortAccum: | |||
1853 | case BuiltinType::SatShortAccum: | |||
1854 | case BuiltinType::SatUShortAccum: | |||
1855 | Width = Target->getShortAccumWidth(); | |||
1856 | Align = Target->getShortAccumAlign(); | |||
1857 | break; | |||
1858 | case BuiltinType::Accum: | |||
1859 | case BuiltinType::UAccum: | |||
1860 | case BuiltinType::SatAccum: | |||
1861 | case BuiltinType::SatUAccum: | |||
1862 | Width = Target->getAccumWidth(); | |||
1863 | Align = Target->getAccumAlign(); | |||
1864 | break; | |||
1865 | case BuiltinType::LongAccum: | |||
1866 | case BuiltinType::ULongAccum: | |||
1867 | case BuiltinType::SatLongAccum: | |||
1868 | case BuiltinType::SatULongAccum: | |||
1869 | Width = Target->getLongAccumWidth(); | |||
1870 | Align = Target->getLongAccumAlign(); | |||
1871 | break; | |||
1872 | case BuiltinType::ShortFract: | |||
1873 | case BuiltinType::UShortFract: | |||
1874 | case BuiltinType::SatShortFract: | |||
1875 | case BuiltinType::SatUShortFract: | |||
1876 | Width = Target->getShortFractWidth(); | |||
1877 | Align = Target->getShortFractAlign(); | |||
1878 | break; | |||
1879 | case BuiltinType::Fract: | |||
1880 | case BuiltinType::UFract: | |||
1881 | case BuiltinType::SatFract: | |||
1882 | case BuiltinType::SatUFract: | |||
1883 | Width = Target->getFractWidth(); | |||
1884 | Align = Target->getFractAlign(); | |||
1885 | break; | |||
1886 | case BuiltinType::LongFract: | |||
1887 | case BuiltinType::ULongFract: | |||
1888 | case BuiltinType::SatLongFract: | |||
1889 | case BuiltinType::SatULongFract: | |||
1890 | Width = Target->getLongFractWidth(); | |||
1891 | Align = Target->getLongFractAlign(); | |||
1892 | break; | |||
1893 | case BuiltinType::Float16: | |||
1894 | case BuiltinType::Half: | |||
1895 | if (Target->hasFloat16Type() || !getLangOpts().OpenMP || | |||
1896 | !getLangOpts().OpenMPIsDevice) { | |||
1897 | Width = Target->getHalfWidth(); | |||
1898 | Align = Target->getHalfAlign(); | |||
1899 | } else { | |||
1900 | assert(getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&((getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice && "Expected OpenMP device compilation.") ? static_cast <void> (0) : __assert_fail ("getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice && \"Expected OpenMP device compilation.\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1901, __PRETTY_FUNCTION__)) | |||
1901 | "Expected OpenMP device compilation.")((getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice && "Expected OpenMP device compilation.") ? static_cast <void> (0) : __assert_fail ("getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice && \"Expected OpenMP device compilation.\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1901, __PRETTY_FUNCTION__)); | |||
1902 | Width = AuxTarget->getHalfWidth(); | |||
1903 | Align = AuxTarget->getHalfAlign(); | |||
1904 | } | |||
1905 | break; | |||
1906 | case BuiltinType::Float: | |||
1907 | Width = Target->getFloatWidth(); | |||
1908 | Align = Target->getFloatAlign(); | |||
1909 | break; | |||
1910 | case BuiltinType::Double: | |||
1911 | Width = Target->getDoubleWidth(); | |||
1912 | Align = Target->getDoubleAlign(); | |||
1913 | break; | |||
1914 | case BuiltinType::LongDouble: | |||
1915 | Width = Target->getLongDoubleWidth(); | |||
1916 | Align = Target->getLongDoubleAlign(); | |||
1917 | break; | |||
1918 | case BuiltinType::Float128: | |||
1919 | if (Target->hasFloat128Type() || !getLangOpts().OpenMP || | |||
1920 | !getLangOpts().OpenMPIsDevice) { | |||
1921 | Width = Target->getFloat128Width(); | |||
1922 | Align = Target->getFloat128Align(); | |||
1923 | } else { | |||
1924 | assert(getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&((getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice && "Expected OpenMP device compilation.") ? static_cast <void> (0) : __assert_fail ("getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice && \"Expected OpenMP device compilation.\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1925, __PRETTY_FUNCTION__)) | |||
1925 | "Expected OpenMP device compilation.")((getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice && "Expected OpenMP device compilation.") ? static_cast <void> (0) : __assert_fail ("getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice && \"Expected OpenMP device compilation.\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 1925, __PRETTY_FUNCTION__)); | |||
1926 | Width = AuxTarget->getFloat128Width(); | |||
1927 | Align = AuxTarget->getFloat128Align(); | |||
1928 | } | |||
1929 | break; | |||
1930 | case BuiltinType::NullPtr: | |||
1931 | Width = Target->getPointerWidth(0); // C++ 3.9.1p11: sizeof(nullptr_t) | |||
1932 | Align = Target->getPointerAlign(0); // == sizeof(void*) | |||
1933 | break; | |||
1934 | case BuiltinType::ObjCId: | |||
1935 | case BuiltinType::ObjCClass: | |||
1936 | case BuiltinType::ObjCSel: | |||
1937 | Width = Target->getPointerWidth(0); | |||
1938 | Align = Target->getPointerAlign(0); | |||
1939 | break; | |||
1940 | case BuiltinType::OCLSampler: | |||
1941 | case BuiltinType::OCLEvent: | |||
1942 | case BuiltinType::OCLClkEvent: | |||
1943 | case BuiltinType::OCLQueue: | |||
1944 | case BuiltinType::OCLReserveID: | |||
1945 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ | |||
1946 | case BuiltinType::Id: | |||
1947 | #include "clang/Basic/OpenCLImageTypes.def" | |||
1948 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ | |||
1949 | case BuiltinType::Id: | |||
1950 | #include "clang/Basic/OpenCLExtensionTypes.def" | |||
1951 | AS = getTargetAddressSpace( | |||
1952 | Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T))); | |||
1953 | Width = Target->getPointerWidth(AS); | |||
1954 | Align = Target->getPointerAlign(AS); | |||
1955 | break; | |||
1956 | } | |||
1957 | break; | |||
1958 | case Type::ObjCObjectPointer: | |||
1959 | Width = Target->getPointerWidth(0); | |||
1960 | Align = Target->getPointerAlign(0); | |||
1961 | break; | |||
1962 | case Type::BlockPointer: | |||
1963 | AS = getTargetAddressSpace(cast<BlockPointerType>(T)->getPointeeType()); | |||
1964 | Width = Target->getPointerWidth(AS); | |||
1965 | Align = Target->getPointerAlign(AS); | |||
1966 | break; | |||
1967 | case Type::LValueReference: | |||
1968 | case Type::RValueReference: | |||
1969 | // alignof and sizeof should never enter this code path here, so we go | |||
1970 | // the pointer route. | |||
1971 | AS = getTargetAddressSpace(cast<ReferenceType>(T)->getPointeeType()); | |||
1972 | Width = Target->getPointerWidth(AS); | |||
1973 | Align = Target->getPointerAlign(AS); | |||
1974 | break; | |||
1975 | case Type::Pointer: | |||
1976 | AS = getTargetAddressSpace(cast<PointerType>(T)->getPointeeType()); | |||
1977 | Width = Target->getPointerWidth(AS); | |||
1978 | Align = Target->getPointerAlign(AS); | |||
1979 | break; | |||
1980 | case Type::MemberPointer: { | |||
1981 | const auto *MPT = cast<MemberPointerType>(T); | |||
1982 | CXXABI::MemberPointerInfo MPI = ABI->getMemberPointerInfo(MPT); | |||
1983 | Width = MPI.Width; | |||
1984 | Align = MPI.Align; | |||
1985 | break; | |||
1986 | } | |||
1987 | case Type::Complex: { | |||
1988 | // Complex types have the same alignment as their elements, but twice the | |||
1989 | // size. | |||
1990 | TypeInfo EltInfo = getTypeInfo(cast<ComplexType>(T)->getElementType()); | |||
1991 | Width = EltInfo.Width * 2; | |||
1992 | Align = EltInfo.Align; | |||
1993 | break; | |||
1994 | } | |||
1995 | case Type::ObjCObject: | |||
1996 | return getTypeInfo(cast<ObjCObjectType>(T)->getBaseType().getTypePtr()); | |||
1997 | case Type::Adjusted: | |||
1998 | case Type::Decayed: | |||
1999 | return getTypeInfo(cast<AdjustedType>(T)->getAdjustedType().getTypePtr()); | |||
2000 | case Type::ObjCInterface: { | |||
2001 | const auto *ObjCI = cast<ObjCInterfaceType>(T); | |||
2002 | const ASTRecordLayout &Layout = getASTObjCInterfaceLayout(ObjCI->getDecl()); | |||
2003 | Width = toBits(Layout.getSize()); | |||
2004 | Align = toBits(Layout.getAlignment()); | |||
2005 | break; | |||
2006 | } | |||
2007 | case Type::Record: | |||
2008 | case Type::Enum: { | |||
2009 | const auto *TT = cast<TagType>(T); | |||
2010 | ||||
2011 | if (TT->getDecl()->isInvalidDecl()) { | |||
2012 | Width = 8; | |||
2013 | Align = 8; | |||
2014 | break; | |||
2015 | } | |||
2016 | ||||
2017 | if (const auto *ET = dyn_cast<EnumType>(TT)) { | |||
2018 | const EnumDecl *ED = ET->getDecl(); | |||
2019 | TypeInfo Info = | |||
2020 | getTypeInfo(ED->getIntegerType()->getUnqualifiedDesugaredType()); | |||
2021 | if (unsigned AttrAlign = ED->getMaxAlignment()) { | |||
2022 | Info.Align = AttrAlign; | |||
2023 | Info.AlignIsRequired = true; | |||
2024 | } | |||
2025 | return Info; | |||
2026 | } | |||
2027 | ||||
2028 | const auto *RT = cast<RecordType>(TT); | |||
2029 | const RecordDecl *RD = RT->getDecl(); | |||
2030 | const ASTRecordLayout &Layout = getASTRecordLayout(RD); | |||
2031 | Width = toBits(Layout.getSize()); | |||
2032 | Align = toBits(Layout.getAlignment()); | |||
2033 | AlignIsRequired = RD->hasAttr<AlignedAttr>(); | |||
2034 | break; | |||
2035 | } | |||
2036 | ||||
2037 | case Type::SubstTemplateTypeParm: | |||
2038 | return getTypeInfo(cast<SubstTemplateTypeParmType>(T)-> | |||
2039 | getReplacementType().getTypePtr()); | |||
2040 | ||||
2041 | case Type::Auto: | |||
2042 | case Type::DeducedTemplateSpecialization: { | |||
2043 | const auto *A = cast<DeducedType>(T); | |||
2044 | assert(!A->getDeducedType().isNull() &&((!A->getDeducedType().isNull() && "cannot request the size of an undeduced or dependent auto type" ) ? static_cast<void> (0) : __assert_fail ("!A->getDeducedType().isNull() && \"cannot request the size of an undeduced or dependent auto type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2045, __PRETTY_FUNCTION__)) | |||
2045 | "cannot request the size of an undeduced or dependent auto type")((!A->getDeducedType().isNull() && "cannot request the size of an undeduced or dependent auto type" ) ? static_cast<void> (0) : __assert_fail ("!A->getDeducedType().isNull() && \"cannot request the size of an undeduced or dependent auto type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2045, __PRETTY_FUNCTION__)); | |||
2046 | return getTypeInfo(A->getDeducedType().getTypePtr()); | |||
2047 | } | |||
2048 | ||||
2049 | case Type::Paren: | |||
2050 | return getTypeInfo(cast<ParenType>(T)->getInnerType().getTypePtr()); | |||
2051 | ||||
2052 | case Type::MacroQualified: | |||
2053 | return getTypeInfo( | |||
2054 | cast<MacroQualifiedType>(T)->getUnderlyingType().getTypePtr()); | |||
2055 | ||||
2056 | case Type::ObjCTypeParam: | |||
2057 | return getTypeInfo(cast<ObjCTypeParamType>(T)->desugar().getTypePtr()); | |||
2058 | ||||
2059 | case Type::Typedef: { | |||
2060 | const TypedefNameDecl *Typedef = cast<TypedefType>(T)->getDecl(); | |||
2061 | TypeInfo Info = getTypeInfo(Typedef->getUnderlyingType().getTypePtr()); | |||
2062 | // If the typedef has an aligned attribute on it, it overrides any computed | |||
2063 | // alignment we have. This violates the GCC documentation (which says that | |||
2064 | // attribute(aligned) can only round up) but matches its implementation. | |||
2065 | if (unsigned AttrAlign = Typedef->getMaxAlignment()) { | |||
2066 | Align = AttrAlign; | |||
2067 | AlignIsRequired = true; | |||
2068 | } else { | |||
2069 | Align = Info.Align; | |||
2070 | AlignIsRequired = Info.AlignIsRequired; | |||
2071 | } | |||
2072 | Width = Info.Width; | |||
2073 | break; | |||
2074 | } | |||
2075 | ||||
2076 | case Type::Elaborated: | |||
2077 | return getTypeInfo(cast<ElaboratedType>(T)->getNamedType().getTypePtr()); | |||
2078 | ||||
2079 | case Type::Attributed: | |||
2080 | return getTypeInfo( | |||
2081 | cast<AttributedType>(T)->getEquivalentType().getTypePtr()); | |||
2082 | ||||
2083 | case Type::Atomic: { | |||
2084 | // Start with the base type information. | |||
2085 | TypeInfo Info = getTypeInfo(cast<AtomicType>(T)->getValueType()); | |||
2086 | Width = Info.Width; | |||
2087 | Align = Info.Align; | |||
2088 | ||||
2089 | if (!Width) { | |||
2090 | // An otherwise zero-sized type should still generate an | |||
2091 | // atomic operation. | |||
2092 | Width = Target->getCharWidth(); | |||
2093 | assert(Align)((Align) ? static_cast<void> (0) : __assert_fail ("Align" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2093, __PRETTY_FUNCTION__)); | |||
2094 | } else if (Width <= Target->getMaxAtomicPromoteWidth()) { | |||
2095 | // If the size of the type doesn't exceed the platform's max | |||
2096 | // atomic promotion width, make the size and alignment more | |||
2097 | // favorable to atomic operations: | |||
2098 | ||||
2099 | // Round the size up to a power of 2. | |||
2100 | if (!llvm::isPowerOf2_64(Width)) | |||
2101 | Width = llvm::NextPowerOf2(Width); | |||
2102 | ||||
2103 | // Set the alignment equal to the size. | |||
2104 | Align = static_cast<unsigned>(Width); | |||
2105 | } | |||
2106 | } | |||
2107 | break; | |||
2108 | ||||
2109 | case Type::Pipe: | |||
2110 | Width = Target->getPointerWidth(getTargetAddressSpace(LangAS::opencl_global)); | |||
2111 | Align = Target->getPointerAlign(getTargetAddressSpace(LangAS::opencl_global)); | |||
2112 | break; | |||
2113 | } | |||
2114 | ||||
2115 | assert(llvm::isPowerOf2_32(Align) && "Alignment must be power of 2")((llvm::isPowerOf2_32(Align) && "Alignment must be power of 2" ) ? static_cast<void> (0) : __assert_fail ("llvm::isPowerOf2_32(Align) && \"Alignment must be power of 2\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2115, __PRETTY_FUNCTION__)); | |||
2116 | return TypeInfo(Width, Align, AlignIsRequired); | |||
2117 | } | |||
2118 | ||||
2119 | unsigned ASTContext::getTypeUnadjustedAlign(const Type *T) const { | |||
2120 | UnadjustedAlignMap::iterator I = MemoizedUnadjustedAlign.find(T); | |||
2121 | if (I != MemoizedUnadjustedAlign.end()) | |||
2122 | return I->second; | |||
2123 | ||||
2124 | unsigned UnadjustedAlign; | |||
2125 | if (const auto *RT = T->getAs<RecordType>()) { | |||
2126 | const RecordDecl *RD = RT->getDecl(); | |||
2127 | const ASTRecordLayout &Layout = getASTRecordLayout(RD); | |||
2128 | UnadjustedAlign = toBits(Layout.getUnadjustedAlignment()); | |||
2129 | } else if (const auto *ObjCI = T->getAs<ObjCInterfaceType>()) { | |||
2130 | const ASTRecordLayout &Layout = getASTObjCInterfaceLayout(ObjCI->getDecl()); | |||
2131 | UnadjustedAlign = toBits(Layout.getUnadjustedAlignment()); | |||
2132 | } else { | |||
2133 | UnadjustedAlign = getTypeAlign(T->getUnqualifiedDesugaredType()); | |||
2134 | } | |||
2135 | ||||
2136 | MemoizedUnadjustedAlign[T] = UnadjustedAlign; | |||
2137 | return UnadjustedAlign; | |||
2138 | } | |||
2139 | ||||
2140 | unsigned ASTContext::getOpenMPDefaultSimdAlign(QualType T) const { | |||
2141 | unsigned SimdAlign = getTargetInfo().getSimdDefaultAlign(); | |||
2142 | // Target ppc64 with QPX: simd default alignment for pointer to double is 32. | |||
2143 | if ((getTargetInfo().getTriple().getArch() == llvm::Triple::ppc64 || | |||
2144 | getTargetInfo().getTriple().getArch() == llvm::Triple::ppc64le) && | |||
2145 | getTargetInfo().getABI() == "elfv1-qpx" && | |||
2146 | T->isSpecificBuiltinType(BuiltinType::Double)) | |||
2147 | SimdAlign = 256; | |||
2148 | return SimdAlign; | |||
2149 | } | |||
2150 | ||||
2151 | /// toCharUnitsFromBits - Convert a size in bits to a size in characters. | |||
2152 | CharUnits ASTContext::toCharUnitsFromBits(int64_t BitSize) const { | |||
2153 | return CharUnits::fromQuantity(BitSize / getCharWidth()); | |||
2154 | } | |||
2155 | ||||
2156 | /// toBits - Convert a size in characters to a size in characters. | |||
2157 | int64_t ASTContext::toBits(CharUnits CharSize) const { | |||
2158 | return CharSize.getQuantity() * getCharWidth(); | |||
2159 | } | |||
2160 | ||||
2161 | /// getTypeSizeInChars - Return the size of the specified type, in characters. | |||
2162 | /// This method does not work on incomplete types. | |||
2163 | CharUnits ASTContext::getTypeSizeInChars(QualType T) const { | |||
2164 | return getTypeInfoInChars(T).first; | |||
2165 | } | |||
2166 | CharUnits ASTContext::getTypeSizeInChars(const Type *T) const { | |||
2167 | return getTypeInfoInChars(T).first; | |||
2168 | } | |||
2169 | ||||
2170 | /// getTypeAlignInChars - Return the ABI-specified alignment of a type, in | |||
2171 | /// characters. This method does not work on incomplete types. | |||
2172 | CharUnits ASTContext::getTypeAlignInChars(QualType T) const { | |||
2173 | return toCharUnitsFromBits(getTypeAlign(T)); | |||
2174 | } | |||
2175 | CharUnits ASTContext::getTypeAlignInChars(const Type *T) const { | |||
2176 | return toCharUnitsFromBits(getTypeAlign(T)); | |||
2177 | } | |||
2178 | ||||
2179 | /// getTypeUnadjustedAlignInChars - Return the ABI-specified alignment of a | |||
2180 | /// type, in characters, before alignment adustments. This method does | |||
2181 | /// not work on incomplete types. | |||
2182 | CharUnits ASTContext::getTypeUnadjustedAlignInChars(QualType T) const { | |||
2183 | return toCharUnitsFromBits(getTypeUnadjustedAlign(T)); | |||
2184 | } | |||
2185 | CharUnits ASTContext::getTypeUnadjustedAlignInChars(const Type *T) const { | |||
2186 | return toCharUnitsFromBits(getTypeUnadjustedAlign(T)); | |||
2187 | } | |||
2188 | ||||
2189 | /// getPreferredTypeAlign - Return the "preferred" alignment of the specified | |||
2190 | /// type for the current target in bits. This can be different than the ABI | |||
2191 | /// alignment in cases where it is beneficial for performance to overalign | |||
2192 | /// a data type. | |||
2193 | unsigned ASTContext::getPreferredTypeAlign(const Type *T) const { | |||
2194 | TypeInfo TI = getTypeInfo(T); | |||
2195 | unsigned ABIAlign = TI.Align; | |||
2196 | ||||
2197 | T = T->getBaseElementTypeUnsafe(); | |||
2198 | ||||
2199 | // The preferred alignment of member pointers is that of a pointer. | |||
2200 | if (T->isMemberPointerType()) | |||
2201 | return getPreferredTypeAlign(getPointerDiffType().getTypePtr()); | |||
2202 | ||||
2203 | if (!Target->allowsLargerPreferedTypeAlignment()) | |||
2204 | return ABIAlign; | |||
2205 | ||||
2206 | // Double and long long should be naturally aligned if possible. | |||
2207 | if (const auto *CT = T->getAs<ComplexType>()) | |||
2208 | T = CT->getElementType().getTypePtr(); | |||
2209 | if (const auto *ET = T->getAs<EnumType>()) | |||
2210 | T = ET->getDecl()->getIntegerType().getTypePtr(); | |||
2211 | if (T->isSpecificBuiltinType(BuiltinType::Double) || | |||
2212 | T->isSpecificBuiltinType(BuiltinType::LongLong) || | |||
2213 | T->isSpecificBuiltinType(BuiltinType::ULongLong)) | |||
2214 | // Don't increase the alignment if an alignment attribute was specified on a | |||
2215 | // typedef declaration. | |||
2216 | if (!TI.AlignIsRequired) | |||
2217 | return std::max(ABIAlign, (unsigned)getTypeSize(T)); | |||
2218 | ||||
2219 | return ABIAlign; | |||
2220 | } | |||
2221 | ||||
2222 | /// getTargetDefaultAlignForAttributeAligned - Return the default alignment | |||
2223 | /// for __attribute__((aligned)) on this target, to be used if no alignment | |||
2224 | /// value is specified. | |||
2225 | unsigned ASTContext::getTargetDefaultAlignForAttributeAligned() const { | |||
2226 | return getTargetInfo().getDefaultAlignForAttributeAligned(); | |||
2227 | } | |||
2228 | ||||
2229 | /// getAlignOfGlobalVar - Return the alignment in bits that should be given | |||
2230 | /// to a global variable of the specified type. | |||
2231 | unsigned ASTContext::getAlignOfGlobalVar(QualType T) const { | |||
2232 | uint64_t TypeSize = getTypeSize(T.getTypePtr()); | |||
2233 | return std::max(getTypeAlign(T), getTargetInfo().getMinGlobalAlign(TypeSize)); | |||
2234 | } | |||
2235 | ||||
2236 | /// getAlignOfGlobalVarInChars - Return the alignment in characters that | |||
2237 | /// should be given to a global variable of the specified type. | |||
2238 | CharUnits ASTContext::getAlignOfGlobalVarInChars(QualType T) const { | |||
2239 | return toCharUnitsFromBits(getAlignOfGlobalVar(T)); | |||
2240 | } | |||
2241 | ||||
2242 | CharUnits ASTContext::getOffsetOfBaseWithVBPtr(const CXXRecordDecl *RD) const { | |||
2243 | CharUnits Offset = CharUnits::Zero(); | |||
2244 | const ASTRecordLayout *Layout = &getASTRecordLayout(RD); | |||
2245 | while (const CXXRecordDecl *Base = Layout->getBaseSharingVBPtr()) { | |||
2246 | Offset += Layout->getBaseClassOffset(Base); | |||
2247 | Layout = &getASTRecordLayout(Base); | |||
2248 | } | |||
2249 | return Offset; | |||
2250 | } | |||
2251 | ||||
2252 | /// DeepCollectObjCIvars - | |||
2253 | /// This routine first collects all declared, but not synthesized, ivars in | |||
2254 | /// super class and then collects all ivars, including those synthesized for | |||
2255 | /// current class. This routine is used for implementation of current class | |||
2256 | /// when all ivars, declared and synthesized are known. | |||
2257 | void ASTContext::DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, | |||
2258 | bool leafClass, | |||
2259 | SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const { | |||
2260 | if (const ObjCInterfaceDecl *SuperClass = OI->getSuperClass()) | |||
2261 | DeepCollectObjCIvars(SuperClass, false, Ivars); | |||
2262 | if (!leafClass) { | |||
2263 | for (const auto *I : OI->ivars()) | |||
2264 | Ivars.push_back(I); | |||
2265 | } else { | |||
2266 | auto *IDecl = const_cast<ObjCInterfaceDecl *>(OI); | |||
2267 | for (const ObjCIvarDecl *Iv = IDecl->all_declared_ivar_begin(); Iv; | |||
2268 | Iv= Iv->getNextIvar()) | |||
2269 | Ivars.push_back(Iv); | |||
2270 | } | |||
2271 | } | |||
2272 | ||||
2273 | /// CollectInheritedProtocols - Collect all protocols in current class and | |||
2274 | /// those inherited by it. | |||
2275 | void ASTContext::CollectInheritedProtocols(const Decl *CDecl, | |||
2276 | llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols) { | |||
2277 | if (const auto *OI = dyn_cast<ObjCInterfaceDecl>(CDecl)) { | |||
2278 | // We can use protocol_iterator here instead of | |||
2279 | // all_referenced_protocol_iterator since we are walking all categories. | |||
2280 | for (auto *Proto : OI->all_referenced_protocols()) { | |||
2281 | CollectInheritedProtocols(Proto, Protocols); | |||
2282 | } | |||
2283 | ||||
2284 | // Categories of this Interface. | |||
2285 | for (const auto *Cat : OI->visible_categories()) | |||
2286 | CollectInheritedProtocols(Cat, Protocols); | |||
2287 | ||||
2288 | if (ObjCInterfaceDecl *SD = OI->getSuperClass()) | |||
2289 | while (SD) { | |||
2290 | CollectInheritedProtocols(SD, Protocols); | |||
2291 | SD = SD->getSuperClass(); | |||
2292 | } | |||
2293 | } else if (const auto *OC = dyn_cast<ObjCCategoryDecl>(CDecl)) { | |||
2294 | for (auto *Proto : OC->protocols()) { | |||
2295 | CollectInheritedProtocols(Proto, Protocols); | |||
2296 | } | |||
2297 | } else if (const auto *OP = dyn_cast<ObjCProtocolDecl>(CDecl)) { | |||
2298 | // Insert the protocol. | |||
2299 | if (!Protocols.insert( | |||
2300 | const_cast<ObjCProtocolDecl *>(OP->getCanonicalDecl())).second) | |||
2301 | return; | |||
2302 | ||||
2303 | for (auto *Proto : OP->protocols()) | |||
2304 | CollectInheritedProtocols(Proto, Protocols); | |||
2305 | } | |||
2306 | } | |||
2307 | ||||
2308 | static bool unionHasUniqueObjectRepresentations(const ASTContext &Context, | |||
2309 | const RecordDecl *RD) { | |||
2310 | assert(RD->isUnion() && "Must be union type")((RD->isUnion() && "Must be union type") ? static_cast <void> (0) : __assert_fail ("RD->isUnion() && \"Must be union type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2310, __PRETTY_FUNCTION__)); | |||
2311 | CharUnits UnionSize = Context.getTypeSizeInChars(RD->getTypeForDecl()); | |||
2312 | ||||
2313 | for (const auto *Field : RD->fields()) { | |||
2314 | if (!Context.hasUniqueObjectRepresentations(Field->getType())) | |||
2315 | return false; | |||
2316 | CharUnits FieldSize = Context.getTypeSizeInChars(Field->getType()); | |||
2317 | if (FieldSize != UnionSize) | |||
2318 | return false; | |||
2319 | } | |||
2320 | return !RD->field_empty(); | |||
2321 | } | |||
2322 | ||||
2323 | static bool isStructEmpty(QualType Ty) { | |||
2324 | const RecordDecl *RD = Ty->castAs<RecordType>()->getDecl(); | |||
2325 | ||||
2326 | if (!RD->field_empty()) | |||
2327 | return false; | |||
2328 | ||||
2329 | if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RD)) | |||
2330 | return ClassDecl->isEmpty(); | |||
2331 | ||||
2332 | return true; | |||
2333 | } | |||
2334 | ||||
2335 | static llvm::Optional<int64_t> | |||
2336 | structHasUniqueObjectRepresentations(const ASTContext &Context, | |||
2337 | const RecordDecl *RD) { | |||
2338 | assert(!RD->isUnion() && "Must be struct/class type")((!RD->isUnion() && "Must be struct/class type") ? static_cast<void> (0) : __assert_fail ("!RD->isUnion() && \"Must be struct/class type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2338, __PRETTY_FUNCTION__)); | |||
2339 | const auto &Layout = Context.getASTRecordLayout(RD); | |||
2340 | ||||
2341 | int64_t CurOffsetInBits = 0; | |||
2342 | if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RD)) { | |||
2343 | if (ClassDecl->isDynamicClass()) | |||
2344 | return llvm::None; | |||
2345 | ||||
2346 | SmallVector<std::pair<QualType, int64_t>, 4> Bases; | |||
2347 | for (const auto Base : ClassDecl->bases()) { | |||
2348 | // Empty types can be inherited from, and non-empty types can potentially | |||
2349 | // have tail padding, so just make sure there isn't an error. | |||
2350 | if (!isStructEmpty(Base.getType())) { | |||
2351 | llvm::Optional<int64_t> Size = structHasUniqueObjectRepresentations( | |||
2352 | Context, Base.getType()->getAs<RecordType>()->getDecl()); | |||
2353 | if (!Size) | |||
2354 | return llvm::None; | |||
2355 | Bases.emplace_back(Base.getType(), Size.getValue()); | |||
2356 | } | |||
2357 | } | |||
2358 | ||||
2359 | llvm::sort(Bases, [&](const std::pair<QualType, int64_t> &L, | |||
2360 | const std::pair<QualType, int64_t> &R) { | |||
2361 | return Layout.getBaseClassOffset(L.first->getAsCXXRecordDecl()) < | |||
2362 | Layout.getBaseClassOffset(R.first->getAsCXXRecordDecl()); | |||
2363 | }); | |||
2364 | ||||
2365 | for (const auto Base : Bases) { | |||
2366 | int64_t BaseOffset = Context.toBits( | |||
2367 | Layout.getBaseClassOffset(Base.first->getAsCXXRecordDecl())); | |||
2368 | int64_t BaseSize = Base.second; | |||
2369 | if (BaseOffset != CurOffsetInBits) | |||
2370 | return llvm::None; | |||
2371 | CurOffsetInBits = BaseOffset + BaseSize; | |||
2372 | } | |||
2373 | } | |||
2374 | ||||
2375 | for (const auto *Field : RD->fields()) { | |||
2376 | if (!Field->getType()->isReferenceType() && | |||
2377 | !Context.hasUniqueObjectRepresentations(Field->getType())) | |||
2378 | return llvm::None; | |||
2379 | ||||
2380 | int64_t FieldSizeInBits = | |||
2381 | Context.toBits(Context.getTypeSizeInChars(Field->getType())); | |||
2382 | if (Field->isBitField()) { | |||
2383 | int64_t BitfieldSize = Field->getBitWidthValue(Context); | |||
2384 | ||||
2385 | if (BitfieldSize > FieldSizeInBits) | |||
2386 | return llvm::None; | |||
2387 | FieldSizeInBits = BitfieldSize; | |||
2388 | } | |||
2389 | ||||
2390 | int64_t FieldOffsetInBits = Context.getFieldOffset(Field); | |||
2391 | ||||
2392 | if (FieldOffsetInBits != CurOffsetInBits) | |||
2393 | return llvm::None; | |||
2394 | ||||
2395 | CurOffsetInBits = FieldSizeInBits + FieldOffsetInBits; | |||
2396 | } | |||
2397 | ||||
2398 | return CurOffsetInBits; | |||
2399 | } | |||
2400 | ||||
2401 | bool ASTContext::hasUniqueObjectRepresentations(QualType Ty) const { | |||
2402 | // C++17 [meta.unary.prop]: | |||
2403 | // The predicate condition for a template specialization | |||
2404 | // has_unique_object_representations<T> shall be | |||
2405 | // satisfied if and only if: | |||
2406 | // (9.1) - T is trivially copyable, and | |||
2407 | // (9.2) - any two objects of type T with the same value have the same | |||
2408 | // object representation, where two objects | |||
2409 | // of array or non-union class type are considered to have the same value | |||
2410 | // if their respective sequences of | |||
2411 | // direct subobjects have the same values, and two objects of union type | |||
2412 | // are considered to have the same | |||
2413 | // value if they have the same active member and the corresponding members | |||
2414 | // have the same value. | |||
2415 | // The set of scalar types for which this condition holds is | |||
2416 | // implementation-defined. [ Note: If a type has padding | |||
2417 | // bits, the condition does not hold; otherwise, the condition holds true | |||
2418 | // for unsigned integral types. -- end note ] | |||
2419 | assert(!Ty.isNull() && "Null QualType sent to unique object rep check")((!Ty.isNull() && "Null QualType sent to unique object rep check" ) ? static_cast<void> (0) : __assert_fail ("!Ty.isNull() && \"Null QualType sent to unique object rep check\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2419, __PRETTY_FUNCTION__)); | |||
2420 | ||||
2421 | // Arrays are unique only if their element type is unique. | |||
2422 | if (Ty->isArrayType()) | |||
2423 | return hasUniqueObjectRepresentations(getBaseElementType(Ty)); | |||
2424 | ||||
2425 | // (9.1) - T is trivially copyable... | |||
2426 | if (!Ty.isTriviallyCopyableType(*this)) | |||
2427 | return false; | |||
2428 | ||||
2429 | // All integrals and enums are unique. | |||
2430 | if (Ty->isIntegralOrEnumerationType()) | |||
2431 | return true; | |||
2432 | ||||
2433 | // All other pointers are unique. | |||
2434 | if (Ty->isPointerType()) | |||
2435 | return true; | |||
2436 | ||||
2437 | if (Ty->isMemberPointerType()) { | |||
2438 | const auto *MPT = Ty->getAs<MemberPointerType>(); | |||
2439 | return !ABI->getMemberPointerInfo(MPT).HasPadding; | |||
2440 | } | |||
2441 | ||||
2442 | if (Ty->isRecordType()) { | |||
2443 | const RecordDecl *Record = Ty->getAs<RecordType>()->getDecl(); | |||
2444 | ||||
2445 | if (Record->isInvalidDecl()) | |||
2446 | return false; | |||
2447 | ||||
2448 | if (Record->isUnion()) | |||
2449 | return unionHasUniqueObjectRepresentations(*this, Record); | |||
2450 | ||||
2451 | Optional<int64_t> StructSize = | |||
2452 | structHasUniqueObjectRepresentations(*this, Record); | |||
2453 | ||||
2454 | return StructSize && | |||
2455 | StructSize.getValue() == static_cast<int64_t>(getTypeSize(Ty)); | |||
2456 | } | |||
2457 | ||||
2458 | // FIXME: More cases to handle here (list by rsmith): | |||
2459 | // vectors (careful about, eg, vector of 3 foo) | |||
2460 | // _Complex int and friends | |||
2461 | // _Atomic T | |||
2462 | // Obj-C block pointers | |||
2463 | // Obj-C object pointers | |||
2464 | // and perhaps OpenCL's various builtin types (pipe, sampler_t, event_t, | |||
2465 | // clk_event_t, queue_t, reserve_id_t) | |||
2466 | // There're also Obj-C class types and the Obj-C selector type, but I think it | |||
2467 | // makes sense for those to return false here. | |||
2468 | ||||
2469 | return false; | |||
2470 | } | |||
2471 | ||||
2472 | unsigned ASTContext::CountNonClassIvars(const ObjCInterfaceDecl *OI) const { | |||
2473 | unsigned count = 0; | |||
2474 | // Count ivars declared in class extension. | |||
2475 | for (const auto *Ext : OI->known_extensions()) | |||
2476 | count += Ext->ivar_size(); | |||
2477 | ||||
2478 | // Count ivar defined in this class's implementation. This | |||
2479 | // includes synthesized ivars. | |||
2480 | if (ObjCImplementationDecl *ImplDecl = OI->getImplementation()) | |||
2481 | count += ImplDecl->ivar_size(); | |||
2482 | ||||
2483 | return count; | |||
2484 | } | |||
2485 | ||||
2486 | bool ASTContext::isSentinelNullExpr(const Expr *E) { | |||
2487 | if (!E) | |||
2488 | return false; | |||
2489 | ||||
2490 | // nullptr_t is always treated as null. | |||
2491 | if (E->getType()->isNullPtrType()) return true; | |||
2492 | ||||
2493 | if (E->getType()->isAnyPointerType() && | |||
2494 | E->IgnoreParenCasts()->isNullPointerConstant(*this, | |||
2495 | Expr::NPC_ValueDependentIsNull)) | |||
2496 | return true; | |||
2497 | ||||
2498 | // Unfortunately, __null has type 'int'. | |||
2499 | if (isa<GNUNullExpr>(E)) return true; | |||
2500 | ||||
2501 | return false; | |||
2502 | } | |||
2503 | ||||
2504 | /// Get the implementation of ObjCInterfaceDecl, or nullptr if none | |||
2505 | /// exists. | |||
2506 | ObjCImplementationDecl *ASTContext::getObjCImplementation(ObjCInterfaceDecl *D) { | |||
2507 | llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator | |||
2508 | I = ObjCImpls.find(D); | |||
2509 | if (I != ObjCImpls.end()) | |||
2510 | return cast<ObjCImplementationDecl>(I->second); | |||
2511 | return nullptr; | |||
2512 | } | |||
2513 | ||||
2514 | /// Get the implementation of ObjCCategoryDecl, or nullptr if none | |||
2515 | /// exists. | |||
2516 | ObjCCategoryImplDecl *ASTContext::getObjCImplementation(ObjCCategoryDecl *D) { | |||
2517 | llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator | |||
2518 | I = ObjCImpls.find(D); | |||
2519 | if (I != ObjCImpls.end()) | |||
2520 | return cast<ObjCCategoryImplDecl>(I->second); | |||
2521 | return nullptr; | |||
2522 | } | |||
2523 | ||||
2524 | /// Set the implementation of ObjCInterfaceDecl. | |||
2525 | void ASTContext::setObjCImplementation(ObjCInterfaceDecl *IFaceD, | |||
2526 | ObjCImplementationDecl *ImplD) { | |||
2527 | assert(IFaceD && ImplD && "Passed null params")((IFaceD && ImplD && "Passed null params") ? static_cast <void> (0) : __assert_fail ("IFaceD && ImplD && \"Passed null params\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2527, __PRETTY_FUNCTION__)); | |||
2528 | ObjCImpls[IFaceD] = ImplD; | |||
2529 | } | |||
2530 | ||||
2531 | /// Set the implementation of ObjCCategoryDecl. | |||
2532 | void ASTContext::setObjCImplementation(ObjCCategoryDecl *CatD, | |||
2533 | ObjCCategoryImplDecl *ImplD) { | |||
2534 | assert(CatD && ImplD && "Passed null params")((CatD && ImplD && "Passed null params") ? static_cast <void> (0) : __assert_fail ("CatD && ImplD && \"Passed null params\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2534, __PRETTY_FUNCTION__)); | |||
2535 | ObjCImpls[CatD] = ImplD; | |||
2536 | } | |||
2537 | ||||
2538 | const ObjCMethodDecl * | |||
2539 | ASTContext::getObjCMethodRedeclaration(const ObjCMethodDecl *MD) const { | |||
2540 | return ObjCMethodRedecls.lookup(MD); | |||
2541 | } | |||
2542 | ||||
2543 | void ASTContext::setObjCMethodRedeclaration(const ObjCMethodDecl *MD, | |||
2544 | const ObjCMethodDecl *Redecl) { | |||
2545 | assert(!getObjCMethodRedeclaration(MD) && "MD already has a redeclaration")((!getObjCMethodRedeclaration(MD) && "MD already has a redeclaration" ) ? static_cast<void> (0) : __assert_fail ("!getObjCMethodRedeclaration(MD) && \"MD already has a redeclaration\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2545, __PRETTY_FUNCTION__)); | |||
2546 | ObjCMethodRedecls[MD] = Redecl; | |||
2547 | } | |||
2548 | ||||
2549 | const ObjCInterfaceDecl *ASTContext::getObjContainingInterface( | |||
2550 | const NamedDecl *ND) const { | |||
2551 | if (const auto *ID = dyn_cast<ObjCInterfaceDecl>(ND->getDeclContext())) | |||
2552 | return ID; | |||
2553 | if (const auto *CD = dyn_cast<ObjCCategoryDecl>(ND->getDeclContext())) | |||
2554 | return CD->getClassInterface(); | |||
2555 | if (const auto *IMD = dyn_cast<ObjCImplDecl>(ND->getDeclContext())) | |||
2556 | return IMD->getClassInterface(); | |||
2557 | ||||
2558 | return nullptr; | |||
2559 | } | |||
2560 | ||||
2561 | /// Get the copy initialization expression of VarDecl, or nullptr if | |||
2562 | /// none exists. | |||
2563 | ASTContext::BlockVarCopyInit | |||
2564 | ASTContext::getBlockVarCopyInit(const VarDecl*VD) const { | |||
2565 | assert(VD && "Passed null params")((VD && "Passed null params") ? static_cast<void> (0) : __assert_fail ("VD && \"Passed null params\"", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2565, __PRETTY_FUNCTION__)); | |||
2566 | assert(VD->hasAttr<BlocksAttr>() &&((VD->hasAttr<BlocksAttr>() && "getBlockVarCopyInits - not __block var" ) ? static_cast<void> (0) : __assert_fail ("VD->hasAttr<BlocksAttr>() && \"getBlockVarCopyInits - not __block var\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2567, __PRETTY_FUNCTION__)) | |||
2567 | "getBlockVarCopyInits - not __block var")((VD->hasAttr<BlocksAttr>() && "getBlockVarCopyInits - not __block var" ) ? static_cast<void> (0) : __assert_fail ("VD->hasAttr<BlocksAttr>() && \"getBlockVarCopyInits - not __block var\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2567, __PRETTY_FUNCTION__)); | |||
2568 | auto I = BlockVarCopyInits.find(VD); | |||
2569 | if (I != BlockVarCopyInits.end()) | |||
2570 | return I->second; | |||
2571 | return {nullptr, false}; | |||
2572 | } | |||
2573 | ||||
2574 | /// Set the copy initialization expression of a block var decl. | |||
2575 | void ASTContext::setBlockVarCopyInit(const VarDecl*VD, Expr *CopyExpr, | |||
2576 | bool CanThrow) { | |||
2577 | assert(VD && CopyExpr && "Passed null params")((VD && CopyExpr && "Passed null params") ? static_cast <void> (0) : __assert_fail ("VD && CopyExpr && \"Passed null params\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2577, __PRETTY_FUNCTION__)); | |||
2578 | assert(VD->hasAttr<BlocksAttr>() &&((VD->hasAttr<BlocksAttr>() && "setBlockVarCopyInits - not __block var" ) ? static_cast<void> (0) : __assert_fail ("VD->hasAttr<BlocksAttr>() && \"setBlockVarCopyInits - not __block var\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2579, __PRETTY_FUNCTION__)) | |||
2579 | "setBlockVarCopyInits - not __block var")((VD->hasAttr<BlocksAttr>() && "setBlockVarCopyInits - not __block var" ) ? static_cast<void> (0) : __assert_fail ("VD->hasAttr<BlocksAttr>() && \"setBlockVarCopyInits - not __block var\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2579, __PRETTY_FUNCTION__)); | |||
2580 | BlockVarCopyInits[VD].setExprAndFlag(CopyExpr, CanThrow); | |||
2581 | } | |||
2582 | ||||
2583 | TypeSourceInfo *ASTContext::CreateTypeSourceInfo(QualType T, | |||
2584 | unsigned DataSize) const { | |||
2585 | if (!DataSize) | |||
2586 | DataSize = TypeLoc::getFullDataSizeForType(T); | |||
2587 | else | |||
2588 | assert(DataSize == TypeLoc::getFullDataSizeForType(T) &&((DataSize == TypeLoc::getFullDataSizeForType(T) && "incorrect data size provided to CreateTypeSourceInfo!" ) ? static_cast<void> (0) : __assert_fail ("DataSize == TypeLoc::getFullDataSizeForType(T) && \"incorrect data size provided to CreateTypeSourceInfo!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2589, __PRETTY_FUNCTION__)) | |||
2589 | "incorrect data size provided to CreateTypeSourceInfo!")((DataSize == TypeLoc::getFullDataSizeForType(T) && "incorrect data size provided to CreateTypeSourceInfo!" ) ? static_cast<void> (0) : __assert_fail ("DataSize == TypeLoc::getFullDataSizeForType(T) && \"incorrect data size provided to CreateTypeSourceInfo!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2589, __PRETTY_FUNCTION__)); | |||
2590 | ||||
2591 | auto *TInfo = | |||
2592 | (TypeSourceInfo*)BumpAlloc.Allocate(sizeof(TypeSourceInfo) + DataSize, 8); | |||
2593 | new (TInfo) TypeSourceInfo(T); | |||
2594 | return TInfo; | |||
2595 | } | |||
2596 | ||||
2597 | TypeSourceInfo *ASTContext::getTrivialTypeSourceInfo(QualType T, | |||
2598 | SourceLocation L) const { | |||
2599 | TypeSourceInfo *DI = CreateTypeSourceInfo(T); | |||
2600 | DI->getTypeLoc().initialize(const_cast<ASTContext &>(*this), L); | |||
2601 | return DI; | |||
2602 | } | |||
2603 | ||||
2604 | const ASTRecordLayout & | |||
2605 | ASTContext::getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) const { | |||
2606 | return getObjCLayout(D, nullptr); | |||
2607 | } | |||
2608 | ||||
2609 | const ASTRecordLayout & | |||
2610 | ASTContext::getASTObjCImplementationLayout( | |||
2611 | const ObjCImplementationDecl *D) const { | |||
2612 | return getObjCLayout(D->getClassInterface(), D); | |||
2613 | } | |||
2614 | ||||
2615 | //===----------------------------------------------------------------------===// | |||
2616 | // Type creation/memoization methods | |||
2617 | //===----------------------------------------------------------------------===// | |||
2618 | ||||
2619 | QualType | |||
2620 | ASTContext::getExtQualType(const Type *baseType, Qualifiers quals) const { | |||
2621 | unsigned fastQuals = quals.getFastQualifiers(); | |||
2622 | quals.removeFastQualifiers(); | |||
2623 | ||||
2624 | // Check if we've already instantiated this type. | |||
2625 | llvm::FoldingSetNodeID ID; | |||
2626 | ExtQuals::Profile(ID, baseType, quals); | |||
2627 | void *insertPos = nullptr; | |||
2628 | if (ExtQuals *eq = ExtQualNodes.FindNodeOrInsertPos(ID, insertPos)) { | |||
2629 | assert(eq->getQualifiers() == quals)((eq->getQualifiers() == quals) ? static_cast<void> ( 0) : __assert_fail ("eq->getQualifiers() == quals", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2629, __PRETTY_FUNCTION__)); | |||
2630 | return QualType(eq, fastQuals); | |||
2631 | } | |||
2632 | ||||
2633 | // If the base type is not canonical, make the appropriate canonical type. | |||
2634 | QualType canon; | |||
2635 | if (!baseType->isCanonicalUnqualified()) { | |||
2636 | SplitQualType canonSplit = baseType->getCanonicalTypeInternal().split(); | |||
2637 | canonSplit.Quals.addConsistentQualifiers(quals); | |||
2638 | canon = getExtQualType(canonSplit.Ty, canonSplit.Quals); | |||
2639 | ||||
2640 | // Re-find the insert position. | |||
2641 | (void) ExtQualNodes.FindNodeOrInsertPos(ID, insertPos); | |||
2642 | } | |||
2643 | ||||
2644 | auto *eq = new (*this, TypeAlignment) ExtQuals(baseType, canon, quals); | |||
2645 | ExtQualNodes.InsertNode(eq, insertPos); | |||
2646 | return QualType(eq, fastQuals); | |||
2647 | } | |||
2648 | ||||
2649 | QualType ASTContext::getAddrSpaceQualType(QualType T, | |||
2650 | LangAS AddressSpace) const { | |||
2651 | QualType CanT = getCanonicalType(T); | |||
2652 | if (CanT.getAddressSpace() == AddressSpace) | |||
2653 | return T; | |||
2654 | ||||
2655 | // If we are composing extended qualifiers together, merge together | |||
2656 | // into one ExtQuals node. | |||
2657 | QualifierCollector Quals; | |||
2658 | const Type *TypeNode = Quals.strip(T); | |||
2659 | ||||
2660 | // If this type already has an address space specified, it cannot get | |||
2661 | // another one. | |||
2662 | assert(!Quals.hasAddressSpace() &&((!Quals.hasAddressSpace() && "Type cannot be in multiple addr spaces!" ) ? static_cast<void> (0) : __assert_fail ("!Quals.hasAddressSpace() && \"Type cannot be in multiple addr spaces!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2663, __PRETTY_FUNCTION__)) | |||
2663 | "Type cannot be in multiple addr spaces!")((!Quals.hasAddressSpace() && "Type cannot be in multiple addr spaces!" ) ? static_cast<void> (0) : __assert_fail ("!Quals.hasAddressSpace() && \"Type cannot be in multiple addr spaces!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2663, __PRETTY_FUNCTION__)); | |||
2664 | Quals.addAddressSpace(AddressSpace); | |||
2665 | ||||
2666 | return getExtQualType(TypeNode, Quals); | |||
2667 | } | |||
2668 | ||||
2669 | QualType ASTContext::removeAddrSpaceQualType(QualType T) const { | |||
2670 | // If we are composing extended qualifiers together, merge together | |||
2671 | // into one ExtQuals node. | |||
2672 | QualifierCollector Quals; | |||
2673 | const Type *TypeNode = Quals.strip(T); | |||
2674 | ||||
2675 | // If the qualifier doesn't have an address space just return it. | |||
2676 | if (!Quals.hasAddressSpace()) | |||
2677 | return T; | |||
2678 | ||||
2679 | Quals.removeAddressSpace(); | |||
2680 | ||||
2681 | // Removal of the address space can mean there are no longer any | |||
2682 | // non-fast qualifiers, so creating an ExtQualType isn't possible (asserts) | |||
2683 | // or required. | |||
2684 | if (Quals.hasNonFastQualifiers()) | |||
2685 | return getExtQualType(TypeNode, Quals); | |||
2686 | else | |||
2687 | return QualType(TypeNode, Quals.getFastQualifiers()); | |||
2688 | } | |||
2689 | ||||
2690 | QualType ASTContext::getObjCGCQualType(QualType T, | |||
2691 | Qualifiers::GC GCAttr) const { | |||
2692 | QualType CanT = getCanonicalType(T); | |||
2693 | if (CanT.getObjCGCAttr() == GCAttr) | |||
2694 | return T; | |||
2695 | ||||
2696 | if (const auto *ptr = T->getAs<PointerType>()) { | |||
2697 | QualType Pointee = ptr->getPointeeType(); | |||
2698 | if (Pointee->isAnyPointerType()) { | |||
2699 | QualType ResultType = getObjCGCQualType(Pointee, GCAttr); | |||
2700 | return getPointerType(ResultType); | |||
2701 | } | |||
2702 | } | |||
2703 | ||||
2704 | // If we are composing extended qualifiers together, merge together | |||
2705 | // into one ExtQuals node. | |||
2706 | QualifierCollector Quals; | |||
2707 | const Type *TypeNode = Quals.strip(T); | |||
2708 | ||||
2709 | // If this type already has an ObjCGC specified, it cannot get | |||
2710 | // another one. | |||
2711 | assert(!Quals.hasObjCGCAttr() &&((!Quals.hasObjCGCAttr() && "Type cannot have multiple ObjCGCs!" ) ? static_cast<void> (0) : __assert_fail ("!Quals.hasObjCGCAttr() && \"Type cannot have multiple ObjCGCs!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2712, __PRETTY_FUNCTION__)) | |||
2712 | "Type cannot have multiple ObjCGCs!")((!Quals.hasObjCGCAttr() && "Type cannot have multiple ObjCGCs!" ) ? static_cast<void> (0) : __assert_fail ("!Quals.hasObjCGCAttr() && \"Type cannot have multiple ObjCGCs!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2712, __PRETTY_FUNCTION__)); | |||
2713 | Quals.addObjCGCAttr(GCAttr); | |||
2714 | ||||
2715 | return getExtQualType(TypeNode, Quals); | |||
2716 | } | |||
2717 | ||||
2718 | const FunctionType *ASTContext::adjustFunctionType(const FunctionType *T, | |||
2719 | FunctionType::ExtInfo Info) { | |||
2720 | if (T->getExtInfo() == Info) | |||
2721 | return T; | |||
2722 | ||||
2723 | QualType Result; | |||
2724 | if (const auto *FNPT = dyn_cast<FunctionNoProtoType>(T)) { | |||
2725 | Result = getFunctionNoProtoType(FNPT->getReturnType(), Info); | |||
2726 | } else { | |||
2727 | const auto *FPT = cast<FunctionProtoType>(T); | |||
2728 | FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); | |||
2729 | EPI.ExtInfo = Info; | |||
2730 | Result = getFunctionType(FPT->getReturnType(), FPT->getParamTypes(), EPI); | |||
2731 | } | |||
2732 | ||||
2733 | return cast<FunctionType>(Result.getTypePtr()); | |||
2734 | } | |||
2735 | ||||
2736 | void ASTContext::adjustDeducedFunctionResultType(FunctionDecl *FD, | |||
2737 | QualType ResultType) { | |||
2738 | FD = FD->getMostRecentDecl(); | |||
2739 | while (true) { | |||
2740 | const auto *FPT = FD->getType()->castAs<FunctionProtoType>(); | |||
2741 | FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); | |||
2742 | FD->setType(getFunctionType(ResultType, FPT->getParamTypes(), EPI)); | |||
2743 | if (FunctionDecl *Next = FD->getPreviousDecl()) | |||
2744 | FD = Next; | |||
2745 | else | |||
2746 | break; | |||
2747 | } | |||
2748 | if (ASTMutationListener *L = getASTMutationListener()) | |||
2749 | L->DeducedReturnType(FD, ResultType); | |||
2750 | } | |||
2751 | ||||
2752 | /// Get a function type and produce the equivalent function type with the | |||
2753 | /// specified exception specification. Type sugar that can be present on a | |||
2754 | /// declaration of a function with an exception specification is permitted | |||
2755 | /// and preserved. Other type sugar (for instance, typedefs) is not. | |||
2756 | QualType ASTContext::getFunctionTypeWithExceptionSpec( | |||
2757 | QualType Orig, const FunctionProtoType::ExceptionSpecInfo &ESI) { | |||
2758 | // Might have some parens. | |||
2759 | if (const auto *PT = dyn_cast<ParenType>(Orig)) | |||
2760 | return getParenType( | |||
2761 | getFunctionTypeWithExceptionSpec(PT->getInnerType(), ESI)); | |||
2762 | ||||
2763 | // Might be wrapped in a macro qualified type. | |||
2764 | if (const auto *MQT = dyn_cast<MacroQualifiedType>(Orig)) | |||
2765 | return getMacroQualifiedType( | |||
2766 | getFunctionTypeWithExceptionSpec(MQT->getUnderlyingType(), ESI), | |||
2767 | MQT->getMacroIdentifier()); | |||
2768 | ||||
2769 | // Might have a calling-convention attribute. | |||
2770 | if (const auto *AT = dyn_cast<AttributedType>(Orig)) | |||
2771 | return getAttributedType( | |||
2772 | AT->getAttrKind(), | |||
2773 | getFunctionTypeWithExceptionSpec(AT->getModifiedType(), ESI), | |||
2774 | getFunctionTypeWithExceptionSpec(AT->getEquivalentType(), ESI)); | |||
2775 | ||||
2776 | // Anything else must be a function type. Rebuild it with the new exception | |||
2777 | // specification. | |||
2778 | const auto *Proto = Orig->getAs<FunctionProtoType>(); | |||
2779 | return getFunctionType( | |||
2780 | Proto->getReturnType(), Proto->getParamTypes(), | |||
2781 | Proto->getExtProtoInfo().withExceptionSpec(ESI)); | |||
2782 | } | |||
2783 | ||||
2784 | bool ASTContext::hasSameFunctionTypeIgnoringExceptionSpec(QualType T, | |||
2785 | QualType U) { | |||
2786 | return hasSameType(T, U) || | |||
2787 | (getLangOpts().CPlusPlus17 && | |||
2788 | hasSameType(getFunctionTypeWithExceptionSpec(T, EST_None), | |||
2789 | getFunctionTypeWithExceptionSpec(U, EST_None))); | |||
2790 | } | |||
2791 | ||||
2792 | void ASTContext::adjustExceptionSpec( | |||
2793 | FunctionDecl *FD, const FunctionProtoType::ExceptionSpecInfo &ESI, | |||
2794 | bool AsWritten) { | |||
2795 | // Update the type. | |||
2796 | QualType Updated = | |||
2797 | getFunctionTypeWithExceptionSpec(FD->getType(), ESI); | |||
2798 | FD->setType(Updated); | |||
2799 | ||||
2800 | if (!AsWritten) | |||
2801 | return; | |||
2802 | ||||
2803 | // Update the type in the type source information too. | |||
2804 | if (TypeSourceInfo *TSInfo = FD->getTypeSourceInfo()) { | |||
2805 | // If the type and the type-as-written differ, we may need to update | |||
2806 | // the type-as-written too. | |||
2807 | if (TSInfo->getType() != FD->getType()) | |||
2808 | Updated = getFunctionTypeWithExceptionSpec(TSInfo->getType(), ESI); | |||
2809 | ||||
2810 | // FIXME: When we get proper type location information for exceptions, | |||
2811 | // we'll also have to rebuild the TypeSourceInfo. For now, we just patch | |||
2812 | // up the TypeSourceInfo; | |||
2813 | assert(TypeLoc::getFullDataSizeForType(Updated) ==((TypeLoc::getFullDataSizeForType(Updated) == TypeLoc::getFullDataSizeForType (TSInfo->getType()) && "TypeLoc size mismatch from updating exception specification" ) ? static_cast<void> (0) : __assert_fail ("TypeLoc::getFullDataSizeForType(Updated) == TypeLoc::getFullDataSizeForType(TSInfo->getType()) && \"TypeLoc size mismatch from updating exception specification\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2815, __PRETTY_FUNCTION__)) | |||
2814 | TypeLoc::getFullDataSizeForType(TSInfo->getType()) &&((TypeLoc::getFullDataSizeForType(Updated) == TypeLoc::getFullDataSizeForType (TSInfo->getType()) && "TypeLoc size mismatch from updating exception specification" ) ? static_cast<void> (0) : __assert_fail ("TypeLoc::getFullDataSizeForType(Updated) == TypeLoc::getFullDataSizeForType(TSInfo->getType()) && \"TypeLoc size mismatch from updating exception specification\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2815, __PRETTY_FUNCTION__)) | |||
2815 | "TypeLoc size mismatch from updating exception specification")((TypeLoc::getFullDataSizeForType(Updated) == TypeLoc::getFullDataSizeForType (TSInfo->getType()) && "TypeLoc size mismatch from updating exception specification" ) ? static_cast<void> (0) : __assert_fail ("TypeLoc::getFullDataSizeForType(Updated) == TypeLoc::getFullDataSizeForType(TSInfo->getType()) && \"TypeLoc size mismatch from updating exception specification\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2815, __PRETTY_FUNCTION__)); | |||
2816 | TSInfo->overrideType(Updated); | |||
2817 | } | |||
2818 | } | |||
2819 | ||||
2820 | /// getComplexType - Return the uniqued reference to the type for a complex | |||
2821 | /// number with the specified element type. | |||
2822 | QualType ASTContext::getComplexType(QualType T) const { | |||
2823 | // Unique pointers, to guarantee there is only one pointer of a particular | |||
2824 | // structure. | |||
2825 | llvm::FoldingSetNodeID ID; | |||
2826 | ComplexType::Profile(ID, T); | |||
2827 | ||||
2828 | void *InsertPos = nullptr; | |||
2829 | if (ComplexType *CT = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos)) | |||
2830 | return QualType(CT, 0); | |||
2831 | ||||
2832 | // If the pointee type isn't canonical, this won't be a canonical type either, | |||
2833 | // so fill in the canonical type field. | |||
2834 | QualType Canonical; | |||
2835 | if (!T.isCanonical()) { | |||
2836 | Canonical = getComplexType(getCanonicalType(T)); | |||
2837 | ||||
2838 | // Get the new insert position for the node we care about. | |||
2839 | ComplexType *NewIP = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
2840 | assert(!NewIP && "Shouldn't be in the map!")((!NewIP && "Shouldn't be in the map!") ? static_cast <void> (0) : __assert_fail ("!NewIP && \"Shouldn't be in the map!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2840, __PRETTY_FUNCTION__)); (void)NewIP; | |||
2841 | } | |||
2842 | auto *New = new (*this, TypeAlignment) ComplexType(T, Canonical); | |||
2843 | Types.push_back(New); | |||
2844 | ComplexTypes.InsertNode(New, InsertPos); | |||
2845 | return QualType(New, 0); | |||
2846 | } | |||
2847 | ||||
2848 | /// getPointerType - Return the uniqued reference to the type for a pointer to | |||
2849 | /// the specified type. | |||
2850 | QualType ASTContext::getPointerType(QualType T) const { | |||
2851 | // Unique pointers, to guarantee there is only one pointer of a particular | |||
2852 | // structure. | |||
2853 | llvm::FoldingSetNodeID ID; | |||
2854 | PointerType::Profile(ID, T); | |||
2855 | ||||
2856 | void *InsertPos = nullptr; | |||
2857 | if (PointerType *PT = PointerTypes.FindNodeOrInsertPos(ID, InsertPos)) | |||
2858 | return QualType(PT, 0); | |||
2859 | ||||
2860 | // If the pointee type isn't canonical, this won't be a canonical type either, | |||
2861 | // so fill in the canonical type field. | |||
2862 | QualType Canonical; | |||
2863 | if (!T.isCanonical()) { | |||
2864 | Canonical = getPointerType(getCanonicalType(T)); | |||
2865 | ||||
2866 | // Get the new insert position for the node we care about. | |||
2867 | PointerType *NewIP = PointerTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
2868 | assert(!NewIP && "Shouldn't be in the map!")((!NewIP && "Shouldn't be in the map!") ? static_cast <void> (0) : __assert_fail ("!NewIP && \"Shouldn't be in the map!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2868, __PRETTY_FUNCTION__)); (void)NewIP; | |||
2869 | } | |||
2870 | auto *New = new (*this, TypeAlignment) PointerType(T, Canonical); | |||
2871 | Types.push_back(New); | |||
2872 | PointerTypes.InsertNode(New, InsertPos); | |||
2873 | return QualType(New, 0); | |||
2874 | } | |||
2875 | ||||
2876 | QualType ASTContext::getAdjustedType(QualType Orig, QualType New) const { | |||
2877 | llvm::FoldingSetNodeID ID; | |||
2878 | AdjustedType::Profile(ID, Orig, New); | |||
2879 | void *InsertPos = nullptr; | |||
2880 | AdjustedType *AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
2881 | if (AT) | |||
2882 | return QualType(AT, 0); | |||
2883 | ||||
2884 | QualType Canonical = getCanonicalType(New); | |||
2885 | ||||
2886 | // Get the new insert position for the node we care about. | |||
2887 | AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
2888 | assert(!AT && "Shouldn't be in the map!")((!AT && "Shouldn't be in the map!") ? static_cast< void> (0) : __assert_fail ("!AT && \"Shouldn't be in the map!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2888, __PRETTY_FUNCTION__)); | |||
2889 | ||||
2890 | AT = new (*this, TypeAlignment) | |||
2891 | AdjustedType(Type::Adjusted, Orig, New, Canonical); | |||
2892 | Types.push_back(AT); | |||
2893 | AdjustedTypes.InsertNode(AT, InsertPos); | |||
2894 | return QualType(AT, 0); | |||
2895 | } | |||
2896 | ||||
2897 | QualType ASTContext::getDecayedType(QualType T) const { | |||
2898 | assert((T->isArrayType() || T->isFunctionType()) && "T does not decay")(((T->isArrayType() || T->isFunctionType()) && "T does not decay" ) ? static_cast<void> (0) : __assert_fail ("(T->isArrayType() || T->isFunctionType()) && \"T does not decay\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2898, __PRETTY_FUNCTION__)); | |||
2899 | ||||
2900 | QualType Decayed; | |||
2901 | ||||
2902 | // C99 6.7.5.3p7: | |||
2903 | // A declaration of a parameter as "array of type" shall be | |||
2904 | // adjusted to "qualified pointer to type", where the type | |||
2905 | // qualifiers (if any) are those specified within the [ and ] of | |||
2906 | // the array type derivation. | |||
2907 | if (T->isArrayType()) | |||
2908 | Decayed = getArrayDecayedType(T); | |||
2909 | ||||
2910 | // C99 6.7.5.3p8: | |||
2911 | // A declaration of a parameter as "function returning type" | |||
2912 | // shall be adjusted to "pointer to function returning type", as | |||
2913 | // in 6.3.2.1. | |||
2914 | if (T->isFunctionType()) | |||
2915 | Decayed = getPointerType(T); | |||
2916 | ||||
2917 | llvm::FoldingSetNodeID ID; | |||
2918 | AdjustedType::Profile(ID, T, Decayed); | |||
2919 | void *InsertPos = nullptr; | |||
2920 | AdjustedType *AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
2921 | if (AT) | |||
2922 | return QualType(AT, 0); | |||
2923 | ||||
2924 | QualType Canonical = getCanonicalType(Decayed); | |||
2925 | ||||
2926 | // Get the new insert position for the node we care about. | |||
2927 | AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
2928 | assert(!AT && "Shouldn't be in the map!")((!AT && "Shouldn't be in the map!") ? static_cast< void> (0) : __assert_fail ("!AT && \"Shouldn't be in the map!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2928, __PRETTY_FUNCTION__)); | |||
2929 | ||||
2930 | AT = new (*this, TypeAlignment) DecayedType(T, Decayed, Canonical); | |||
2931 | Types.push_back(AT); | |||
2932 | AdjustedTypes.InsertNode(AT, InsertPos); | |||
2933 | return QualType(AT, 0); | |||
2934 | } | |||
2935 | ||||
2936 | /// getBlockPointerType - Return the uniqued reference to the type for | |||
2937 | /// a pointer to the specified block. | |||
2938 | QualType ASTContext::getBlockPointerType(QualType T) const { | |||
2939 | assert(T->isFunctionType() && "block of function types only")((T->isFunctionType() && "block of function types only" ) ? static_cast<void> (0) : __assert_fail ("T->isFunctionType() && \"block of function types only\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2939, __PRETTY_FUNCTION__)); | |||
2940 | // Unique pointers, to guarantee there is only one block of a particular | |||
2941 | // structure. | |||
2942 | llvm::FoldingSetNodeID ID; | |||
2943 | BlockPointerType::Profile(ID, T); | |||
2944 | ||||
2945 | void *InsertPos = nullptr; | |||
2946 | if (BlockPointerType *PT = | |||
2947 | BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) | |||
2948 | return QualType(PT, 0); | |||
2949 | ||||
2950 | // If the block pointee type isn't canonical, this won't be a canonical | |||
2951 | // type either so fill in the canonical type field. | |||
2952 | QualType Canonical; | |||
2953 | if (!T.isCanonical()) { | |||
2954 | Canonical = getBlockPointerType(getCanonicalType(T)); | |||
2955 | ||||
2956 | // Get the new insert position for the node we care about. | |||
2957 | BlockPointerType *NewIP = | |||
2958 | BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
2959 | assert(!NewIP && "Shouldn't be in the map!")((!NewIP && "Shouldn't be in the map!") ? static_cast <void> (0) : __assert_fail ("!NewIP && \"Shouldn't be in the map!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2959, __PRETTY_FUNCTION__)); (void)NewIP; | |||
2960 | } | |||
2961 | auto *New = new (*this, TypeAlignment) BlockPointerType(T, Canonical); | |||
2962 | Types.push_back(New); | |||
2963 | BlockPointerTypes.InsertNode(New, InsertPos); | |||
2964 | return QualType(New, 0); | |||
2965 | } | |||
2966 | ||||
2967 | /// getLValueReferenceType - Return the uniqued reference to the type for an | |||
2968 | /// lvalue reference to the specified type. | |||
2969 | QualType | |||
2970 | ASTContext::getLValueReferenceType(QualType T, bool SpelledAsLValue) const { | |||
2971 | assert(getCanonicalType(T) != OverloadTy &&((getCanonicalType(T) != OverloadTy && "Unresolved overloaded function type" ) ? static_cast<void> (0) : __assert_fail ("getCanonicalType(T) != OverloadTy && \"Unresolved overloaded function type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2972, __PRETTY_FUNCTION__)) | |||
2972 | "Unresolved overloaded function type")((getCanonicalType(T) != OverloadTy && "Unresolved overloaded function type" ) ? static_cast<void> (0) : __assert_fail ("getCanonicalType(T) != OverloadTy && \"Unresolved overloaded function type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2972, __PRETTY_FUNCTION__)); | |||
2973 | ||||
2974 | // Unique pointers, to guarantee there is only one pointer of a particular | |||
2975 | // structure. | |||
2976 | llvm::FoldingSetNodeID ID; | |||
2977 | ReferenceType::Profile(ID, T, SpelledAsLValue); | |||
2978 | ||||
2979 | void *InsertPos = nullptr; | |||
2980 | if (LValueReferenceType *RT = | |||
2981 | LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos)) | |||
2982 | return QualType(RT, 0); | |||
2983 | ||||
2984 | const auto *InnerRef = T->getAs<ReferenceType>(); | |||
2985 | ||||
2986 | // If the referencee type isn't canonical, this won't be a canonical type | |||
2987 | // either, so fill in the canonical type field. | |||
2988 | QualType Canonical; | |||
2989 | if (!SpelledAsLValue || InnerRef || !T.isCanonical()) { | |||
2990 | QualType PointeeType = (InnerRef ? InnerRef->getPointeeType() : T); | |||
2991 | Canonical = getLValueReferenceType(getCanonicalType(PointeeType)); | |||
2992 | ||||
2993 | // Get the new insert position for the node we care about. | |||
2994 | LValueReferenceType *NewIP = | |||
2995 | LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
2996 | assert(!NewIP && "Shouldn't be in the map!")((!NewIP && "Shouldn't be in the map!") ? static_cast <void> (0) : __assert_fail ("!NewIP && \"Shouldn't be in the map!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 2996, __PRETTY_FUNCTION__)); (void)NewIP; | |||
2997 | } | |||
2998 | ||||
2999 | auto *New = new (*this, TypeAlignment) LValueReferenceType(T, Canonical, | |||
3000 | SpelledAsLValue); | |||
3001 | Types.push_back(New); | |||
3002 | LValueReferenceTypes.InsertNode(New, InsertPos); | |||
3003 | ||||
3004 | return QualType(New, 0); | |||
3005 | } | |||
3006 | ||||
3007 | /// getRValueReferenceType - Return the uniqued reference to the type for an | |||
3008 | /// rvalue reference to the specified type. | |||
3009 | QualType ASTContext::getRValueReferenceType(QualType T) const { | |||
3010 | // Unique pointers, to guarantee there is only one pointer of a particular | |||
3011 | // structure. | |||
3012 | llvm::FoldingSetNodeID ID; | |||
3013 | ReferenceType::Profile(ID, T, false); | |||
3014 | ||||
3015 | void *InsertPos = nullptr; | |||
3016 | if (RValueReferenceType *RT = | |||
3017 | RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos)) | |||
3018 | return QualType(RT, 0); | |||
3019 | ||||
3020 | const auto *InnerRef = T->getAs<ReferenceType>(); | |||
3021 | ||||
3022 | // If the referencee type isn't canonical, this won't be a canonical type | |||
3023 | // either, so fill in the canonical type field. | |||
3024 | QualType Canonical; | |||
3025 | if (InnerRef || !T.isCanonical()) { | |||
3026 | QualType PointeeType = (InnerRef ? InnerRef->getPointeeType() : T); | |||
3027 | Canonical = getRValueReferenceType(getCanonicalType(PointeeType)); | |||
3028 | ||||
3029 | // Get the new insert position for the node we care about. | |||
3030 | RValueReferenceType *NewIP = | |||
3031 | RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
3032 | assert(!NewIP && "Shouldn't be in the map!")((!NewIP && "Shouldn't be in the map!") ? static_cast <void> (0) : __assert_fail ("!NewIP && \"Shouldn't be in the map!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3032, __PRETTY_FUNCTION__)); (void)NewIP; | |||
3033 | } | |||
3034 | ||||
3035 | auto *New = new (*this, TypeAlignment) RValueReferenceType(T, Canonical); | |||
3036 | Types.push_back(New); | |||
3037 | RValueReferenceTypes.InsertNode(New, InsertPos); | |||
3038 | return QualType(New, 0); | |||
3039 | } | |||
3040 | ||||
3041 | /// getMemberPointerType - Return the uniqued reference to the type for a | |||
3042 | /// member pointer to the specified type, in the specified class. | |||
3043 | QualType ASTContext::getMemberPointerType(QualType T, const Type *Cls) const { | |||
3044 | // Unique pointers, to guarantee there is only one pointer of a particular | |||
3045 | // structure. | |||
3046 | llvm::FoldingSetNodeID ID; | |||
3047 | MemberPointerType::Profile(ID, T, Cls); | |||
3048 | ||||
3049 | void *InsertPos = nullptr; | |||
3050 | if (MemberPointerType *PT = | |||
3051 | MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) | |||
3052 | return QualType(PT, 0); | |||
3053 | ||||
3054 | // If the pointee or class type isn't canonical, this won't be a canonical | |||
3055 | // type either, so fill in the canonical type field. | |||
3056 | QualType Canonical; | |||
3057 | if (!T.isCanonical() || !Cls->isCanonicalUnqualified()) { | |||
3058 | Canonical = getMemberPointerType(getCanonicalType(T),getCanonicalType(Cls)); | |||
3059 | ||||
3060 | // Get the new insert position for the node we care about. | |||
3061 | MemberPointerType *NewIP = | |||
3062 | MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
3063 | assert(!NewIP && "Shouldn't be in the map!")((!NewIP && "Shouldn't be in the map!") ? static_cast <void> (0) : __assert_fail ("!NewIP && \"Shouldn't be in the map!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3063, __PRETTY_FUNCTION__)); (void)NewIP; | |||
3064 | } | |||
3065 | auto *New = new (*this, TypeAlignment) MemberPointerType(T, Cls, Canonical); | |||
3066 | Types.push_back(New); | |||
3067 | MemberPointerTypes.InsertNode(New, InsertPos); | |||
3068 | return QualType(New, 0); | |||
3069 | } | |||
3070 | ||||
3071 | /// getConstantArrayType - Return the unique reference to the type for an | |||
3072 | /// array of the specified element type. | |||
3073 | QualType ASTContext::getConstantArrayType(QualType EltTy, | |||
3074 | const llvm::APInt &ArySizeIn, | |||
3075 | ArrayType::ArraySizeModifier ASM, | |||
3076 | unsigned IndexTypeQuals) const { | |||
3077 | assert((EltTy->isDependentType() ||(((EltTy->isDependentType() || EltTy->isIncompleteType( ) || EltTy->isConstantSizeType()) && "Constant array of VLAs is illegal!" ) ? static_cast<void> (0) : __assert_fail ("(EltTy->isDependentType() || EltTy->isIncompleteType() || EltTy->isConstantSizeType()) && \"Constant array of VLAs is illegal!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3079, __PRETTY_FUNCTION__)) | |||
3078 | EltTy->isIncompleteType() || EltTy->isConstantSizeType()) &&(((EltTy->isDependentType() || EltTy->isIncompleteType( ) || EltTy->isConstantSizeType()) && "Constant array of VLAs is illegal!" ) ? static_cast<void> (0) : __assert_fail ("(EltTy->isDependentType() || EltTy->isIncompleteType() || EltTy->isConstantSizeType()) && \"Constant array of VLAs is illegal!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3079, __PRETTY_FUNCTION__)) | |||
3079 | "Constant array of VLAs is illegal!")(((EltTy->isDependentType() || EltTy->isIncompleteType( ) || EltTy->isConstantSizeType()) && "Constant array of VLAs is illegal!" ) ? static_cast<void> (0) : __assert_fail ("(EltTy->isDependentType() || EltTy->isIncompleteType() || EltTy->isConstantSizeType()) && \"Constant array of VLAs is illegal!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3079, __PRETTY_FUNCTION__)); | |||
3080 | ||||
3081 | // Convert the array size into a canonical width matching the pointer size for | |||
3082 | // the target. | |||
3083 | llvm::APInt ArySize(ArySizeIn); | |||
3084 | ArySize = ArySize.zextOrTrunc(Target->getMaxPointerWidth()); | |||
3085 | ||||
3086 | llvm::FoldingSetNodeID ID; | |||
3087 | ConstantArrayType::Profile(ID, EltTy, ArySize, ASM, IndexTypeQuals); | |||
3088 | ||||
3089 | void *InsertPos = nullptr; | |||
3090 | if (ConstantArrayType *ATP = | |||
3091 | ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos)) | |||
3092 | return QualType(ATP, 0); | |||
3093 | ||||
3094 | // If the element type isn't canonical or has qualifiers, this won't | |||
3095 | // be a canonical type either, so fill in the canonical type field. | |||
3096 | QualType Canon; | |||
3097 | if (!EltTy.isCanonical() || EltTy.hasLocalQualifiers()) { | |||
3098 | SplitQualType canonSplit = getCanonicalType(EltTy).split(); | |||
3099 | Canon = getConstantArrayType(QualType(canonSplit.Ty, 0), ArySize, | |||
3100 | ASM, IndexTypeQuals); | |||
3101 | Canon = getQualifiedType(Canon, canonSplit.Quals); | |||
3102 | ||||
3103 | // Get the new insert position for the node we care about. | |||
3104 | ConstantArrayType *NewIP = | |||
3105 | ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
3106 | assert(!NewIP && "Shouldn't be in the map!")((!NewIP && "Shouldn't be in the map!") ? static_cast <void> (0) : __assert_fail ("!NewIP && \"Shouldn't be in the map!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3106, __PRETTY_FUNCTION__)); (void)NewIP; | |||
3107 | } | |||
3108 | ||||
3109 | auto *New = new (*this,TypeAlignment) | |||
3110 | ConstantArrayType(EltTy, Canon, ArySize, ASM, IndexTypeQuals); | |||
3111 | ConstantArrayTypes.InsertNode(New, InsertPos); | |||
3112 | Types.push_back(New); | |||
3113 | return QualType(New, 0); | |||
3114 | } | |||
3115 | ||||
3116 | /// getVariableArrayDecayedType - Turns the given type, which may be | |||
3117 | /// variably-modified, into the corresponding type with all the known | |||
3118 | /// sizes replaced with [*]. | |||
3119 | QualType ASTContext::getVariableArrayDecayedType(QualType type) const { | |||
3120 | // Vastly most common case. | |||
3121 | if (!type->isVariablyModifiedType()) return type; | |||
3122 | ||||
3123 | QualType result; | |||
3124 | ||||
3125 | SplitQualType split = type.getSplitDesugaredType(); | |||
3126 | const Type *ty = split.Ty; | |||
3127 | switch (ty->getTypeClass()) { | |||
3128 | #define TYPE(Class, Base) | |||
3129 | #define ABSTRACT_TYPE(Class, Base) | |||
3130 | #define NON_CANONICAL_TYPE(Class, Base) case Type::Class: | |||
3131 | #include "clang/AST/TypeNodes.def" | |||
3132 | llvm_unreachable("didn't desugar past all non-canonical types?")::llvm::llvm_unreachable_internal("didn't desugar past all non-canonical types?" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3132); | |||
3133 | ||||
3134 | // These types should never be variably-modified. | |||
3135 | case Type::Builtin: | |||
3136 | case Type::Complex: | |||
3137 | case Type::Vector: | |||
3138 | case Type::DependentVector: | |||
3139 | case Type::ExtVector: | |||
3140 | case Type::DependentSizedExtVector: | |||
3141 | case Type::DependentAddressSpace: | |||
3142 | case Type::ObjCObject: | |||
3143 | case Type::ObjCInterface: | |||
3144 | case Type::ObjCObjectPointer: | |||
3145 | case Type::Record: | |||
3146 | case Type::Enum: | |||
3147 | case Type::UnresolvedUsing: | |||
3148 | case Type::TypeOfExpr: | |||
3149 | case Type::TypeOf: | |||
3150 | case Type::Decltype: | |||
3151 | case Type::UnaryTransform: | |||
3152 | case Type::DependentName: | |||
3153 | case Type::InjectedClassName: | |||
3154 | case Type::TemplateSpecialization: | |||
3155 | case Type::DependentTemplateSpecialization: | |||
3156 | case Type::TemplateTypeParm: | |||
3157 | case Type::SubstTemplateTypeParmPack: | |||
3158 | case Type::Auto: | |||
3159 | case Type::DeducedTemplateSpecialization: | |||
3160 | case Type::PackExpansion: | |||
3161 | llvm_unreachable("type should never be variably-modified")::llvm::llvm_unreachable_internal("type should never be variably-modified" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3161); | |||
3162 | ||||
3163 | // These types can be variably-modified but should never need to | |||
3164 | // further decay. | |||
3165 | case Type::FunctionNoProto: | |||
3166 | case Type::FunctionProto: | |||
3167 | case Type::BlockPointer: | |||
3168 | case Type::MemberPointer: | |||
3169 | case Type::Pipe: | |||
3170 | return type; | |||
3171 | ||||
3172 | // These types can be variably-modified. All these modifications | |||
3173 | // preserve structure except as noted by comments. | |||
3174 | // TODO: if we ever care about optimizing VLAs, there are no-op | |||
3175 | // optimizations available here. | |||
3176 | case Type::Pointer: | |||
3177 | result = getPointerType(getVariableArrayDecayedType( | |||
3178 | cast<PointerType>(ty)->getPointeeType())); | |||
3179 | break; | |||
3180 | ||||
3181 | case Type::LValueReference: { | |||
3182 | const auto *lv = cast<LValueReferenceType>(ty); | |||
3183 | result = getLValueReferenceType( | |||
3184 | getVariableArrayDecayedType(lv->getPointeeType()), | |||
3185 | lv->isSpelledAsLValue()); | |||
3186 | break; | |||
3187 | } | |||
3188 | ||||
3189 | case Type::RValueReference: { | |||
3190 | const auto *lv = cast<RValueReferenceType>(ty); | |||
3191 | result = getRValueReferenceType( | |||
3192 | getVariableArrayDecayedType(lv->getPointeeType())); | |||
3193 | break; | |||
3194 | } | |||
3195 | ||||
3196 | case Type::Atomic: { | |||
3197 | const auto *at = cast<AtomicType>(ty); | |||
3198 | result = getAtomicType(getVariableArrayDecayedType(at->getValueType())); | |||
3199 | break; | |||
3200 | } | |||
3201 | ||||
3202 | case Type::ConstantArray: { | |||
3203 | const auto *cat = cast<ConstantArrayType>(ty); | |||
3204 | result = getConstantArrayType( | |||
3205 | getVariableArrayDecayedType(cat->getElementType()), | |||
3206 | cat->getSize(), | |||
3207 | cat->getSizeModifier(), | |||
3208 | cat->getIndexTypeCVRQualifiers()); | |||
3209 | break; | |||
3210 | } | |||
3211 | ||||
3212 | case Type::DependentSizedArray: { | |||
3213 | const auto *dat = cast<DependentSizedArrayType>(ty); | |||
3214 | result = getDependentSizedArrayType( | |||
3215 | getVariableArrayDecayedType(dat->getElementType()), | |||
3216 | dat->getSizeExpr(), | |||
3217 | dat->getSizeModifier(), | |||
3218 | dat->getIndexTypeCVRQualifiers(), | |||
3219 | dat->getBracketsRange()); | |||
3220 | break; | |||
3221 | } | |||
3222 | ||||
3223 | // Turn incomplete types into [*] types. | |||
3224 | case Type::IncompleteArray: { | |||
3225 | const auto *iat = cast<IncompleteArrayType>(ty); | |||
3226 | result = getVariableArrayType( | |||
3227 | getVariableArrayDecayedType(iat->getElementType()), | |||
3228 | /*size*/ nullptr, | |||
3229 | ArrayType::Normal, | |||
3230 | iat->getIndexTypeCVRQualifiers(), | |||
3231 | SourceRange()); | |||
3232 | break; | |||
3233 | } | |||
3234 | ||||
3235 | // Turn VLA types into [*] types. | |||
3236 | case Type::VariableArray: { | |||
3237 | const auto *vat = cast<VariableArrayType>(ty); | |||
3238 | result = getVariableArrayType( | |||
3239 | getVariableArrayDecayedType(vat->getElementType()), | |||
3240 | /*size*/ nullptr, | |||
3241 | ArrayType::Star, | |||
3242 | vat->getIndexTypeCVRQualifiers(), | |||
3243 | vat->getBracketsRange()); | |||
3244 | break; | |||
3245 | } | |||
3246 | } | |||
3247 | ||||
3248 | // Apply the top-level qualifiers from the original. | |||
3249 | return getQualifiedType(result, split.Quals); | |||
3250 | } | |||
3251 | ||||
3252 | /// getVariableArrayType - Returns a non-unique reference to the type for a | |||
3253 | /// variable array of the specified element type. | |||
3254 | QualType ASTContext::getVariableArrayType(QualType EltTy, | |||
3255 | Expr *NumElts, | |||
3256 | ArrayType::ArraySizeModifier ASM, | |||
3257 | unsigned IndexTypeQuals, | |||
3258 | SourceRange Brackets) const { | |||
3259 | // Since we don't unique expressions, it isn't possible to unique VLA's | |||
3260 | // that have an expression provided for their size. | |||
3261 | QualType Canon; | |||
3262 | ||||
3263 | // Be sure to pull qualifiers off the element type. | |||
3264 | if (!EltTy.isCanonical() || EltTy.hasLocalQualifiers()) { | |||
3265 | SplitQualType canonSplit = getCanonicalType(EltTy).split(); | |||
3266 | Canon = getVariableArrayType(QualType(canonSplit.Ty, 0), NumElts, ASM, | |||
3267 | IndexTypeQuals, Brackets); | |||
3268 | Canon = getQualifiedType(Canon, canonSplit.Quals); | |||
3269 | } | |||
3270 | ||||
3271 | auto *New = new (*this, TypeAlignment) | |||
3272 | VariableArrayType(EltTy, Canon, NumElts, ASM, IndexTypeQuals, Brackets); | |||
3273 | ||||
3274 | VariableArrayTypes.push_back(New); | |||
3275 | Types.push_back(New); | |||
3276 | return QualType(New, 0); | |||
3277 | } | |||
3278 | ||||
3279 | /// getDependentSizedArrayType - Returns a non-unique reference to | |||
3280 | /// the type for a dependently-sized array of the specified element | |||
3281 | /// type. | |||
3282 | QualType ASTContext::getDependentSizedArrayType(QualType elementType, | |||
3283 | Expr *numElements, | |||
3284 | ArrayType::ArraySizeModifier ASM, | |||
3285 | unsigned elementTypeQuals, | |||
3286 | SourceRange brackets) const { | |||
3287 | assert((!numElements || numElements->isTypeDependent() ||(((!numElements || numElements->isTypeDependent() || numElements ->isValueDependent()) && "Size must be type- or value-dependent!" ) ? static_cast<void> (0) : __assert_fail ("(!numElements || numElements->isTypeDependent() || numElements->isValueDependent()) && \"Size must be type- or value-dependent!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3289, __PRETTY_FUNCTION__)) | |||
3288 | numElements->isValueDependent()) &&(((!numElements || numElements->isTypeDependent() || numElements ->isValueDependent()) && "Size must be type- or value-dependent!" ) ? static_cast<void> (0) : __assert_fail ("(!numElements || numElements->isTypeDependent() || numElements->isValueDependent()) && \"Size must be type- or value-dependent!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3289, __PRETTY_FUNCTION__)) | |||
3289 | "Size must be type- or value-dependent!")(((!numElements || numElements->isTypeDependent() || numElements ->isValueDependent()) && "Size must be type- or value-dependent!" ) ? static_cast<void> (0) : __assert_fail ("(!numElements || numElements->isTypeDependent() || numElements->isValueDependent()) && \"Size must be type- or value-dependent!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3289, __PRETTY_FUNCTION__)); | |||
3290 | ||||
3291 | // Dependently-sized array types that do not have a specified number | |||
3292 | // of elements will have their sizes deduced from a dependent | |||
3293 | // initializer. We do no canonicalization here at all, which is okay | |||
3294 | // because they can't be used in most locations. | |||
3295 | if (!numElements) { | |||
3296 | auto *newType | |||
3297 | = new (*this, TypeAlignment) | |||
3298 | DependentSizedArrayType(*this, elementType, QualType(), | |||
3299 | numElements, ASM, elementTypeQuals, | |||
3300 | brackets); | |||
3301 | Types.push_back(newType); | |||
3302 | return QualType(newType, 0); | |||
3303 | } | |||
3304 | ||||
3305 | // Otherwise, we actually build a new type every time, but we | |||
3306 | // also build a canonical type. | |||
3307 | ||||
3308 | SplitQualType canonElementType = getCanonicalType(elementType).split(); | |||
3309 | ||||
3310 | void *insertPos = nullptr; | |||
3311 | llvm::FoldingSetNodeID ID; | |||
3312 | DependentSizedArrayType::Profile(ID, *this, | |||
3313 | QualType(canonElementType.Ty, 0), | |||
3314 | ASM, elementTypeQuals, numElements); | |||
3315 | ||||
3316 | // Look for an existing type with these properties. | |||
3317 | DependentSizedArrayType *canonTy = | |||
3318 | DependentSizedArrayTypes.FindNodeOrInsertPos(ID, insertPos); | |||
3319 | ||||
3320 | // If we don't have one, build one. | |||
3321 | if (!canonTy) { | |||
3322 | canonTy = new (*this, TypeAlignment) | |||
3323 | DependentSizedArrayType(*this, QualType(canonElementType.Ty, 0), | |||
3324 | QualType(), numElements, ASM, elementTypeQuals, | |||
3325 | brackets); | |||
3326 | DependentSizedArrayTypes.InsertNode(canonTy, insertPos); | |||
3327 | Types.push_back(canonTy); | |||
3328 | } | |||
3329 | ||||
3330 | // Apply qualifiers from the element type to the array. | |||
3331 | QualType canon = getQualifiedType(QualType(canonTy,0), | |||
3332 | canonElementType.Quals); | |||
3333 | ||||
3334 | // If we didn't need extra canonicalization for the element type or the size | |||
3335 | // expression, then just use that as our result. | |||
3336 | if (QualType(canonElementType.Ty, 0) == elementType && | |||
3337 | canonTy->getSizeExpr() == numElements) | |||
3338 | return canon; | |||
3339 | ||||
3340 | // Otherwise, we need to build a type which follows the spelling | |||
3341 | // of the element type. | |||
3342 | auto *sugaredType | |||
3343 | = new (*this, TypeAlignment) | |||
3344 | DependentSizedArrayType(*this, elementType, canon, numElements, | |||
3345 | ASM, elementTypeQuals, brackets); | |||
3346 | Types.push_back(sugaredType); | |||
3347 | return QualType(sugaredType, 0); | |||
3348 | } | |||
3349 | ||||
3350 | QualType ASTContext::getIncompleteArrayType(QualType elementType, | |||
3351 | ArrayType::ArraySizeModifier ASM, | |||
3352 | unsigned elementTypeQuals) const { | |||
3353 | llvm::FoldingSetNodeID ID; | |||
3354 | IncompleteArrayType::Profile(ID, elementType, ASM, elementTypeQuals); | |||
3355 | ||||
3356 | void *insertPos = nullptr; | |||
3357 | if (IncompleteArrayType *iat = | |||
3358 | IncompleteArrayTypes.FindNodeOrInsertPos(ID, insertPos)) | |||
3359 | return QualType(iat, 0); | |||
3360 | ||||
3361 | // If the element type isn't canonical, this won't be a canonical type | |||
3362 | // either, so fill in the canonical type field. We also have to pull | |||
3363 | // qualifiers off the element type. | |||
3364 | QualType canon; | |||
3365 | ||||
3366 | if (!elementType.isCanonical() || elementType.hasLocalQualifiers()) { | |||
3367 | SplitQualType canonSplit = getCanonicalType(elementType).split(); | |||
3368 | canon = getIncompleteArrayType(QualType(canonSplit.Ty, 0), | |||
3369 | ASM, elementTypeQuals); | |||
3370 | canon = getQualifiedType(canon, canonSplit.Quals); | |||
3371 | ||||
3372 | // Get the new insert position for the node we care about. | |||
3373 | IncompleteArrayType *existing = | |||
3374 | IncompleteArrayTypes.FindNodeOrInsertPos(ID, insertPos); | |||
3375 | assert(!existing && "Shouldn't be in the map!")((!existing && "Shouldn't be in the map!") ? static_cast <void> (0) : __assert_fail ("!existing && \"Shouldn't be in the map!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3375, __PRETTY_FUNCTION__)); (void) existing; | |||
3376 | } | |||
3377 | ||||
3378 | auto *newType = new (*this, TypeAlignment) | |||
3379 | IncompleteArrayType(elementType, canon, ASM, elementTypeQuals); | |||
3380 | ||||
3381 | IncompleteArrayTypes.InsertNode(newType, insertPos); | |||
3382 | Types.push_back(newType); | |||
3383 | return QualType(newType, 0); | |||
3384 | } | |||
3385 | ||||
3386 | /// getVectorType - Return the unique reference to a vector type of | |||
3387 | /// the specified element type and size. VectorType must be a built-in type. | |||
3388 | QualType ASTContext::getVectorType(QualType vecType, unsigned NumElts, | |||
3389 | VectorType::VectorKind VecKind) const { | |||
3390 | assert(vecType->isBuiltinType())((vecType->isBuiltinType()) ? static_cast<void> (0) : __assert_fail ("vecType->isBuiltinType()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3390, __PRETTY_FUNCTION__)); | |||
3391 | ||||
3392 | // Check if we've already instantiated a vector of this type. | |||
3393 | llvm::FoldingSetNodeID ID; | |||
3394 | VectorType::Profile(ID, vecType, NumElts, Type::Vector, VecKind); | |||
3395 | ||||
3396 | void *InsertPos = nullptr; | |||
3397 | if (VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos)) | |||
3398 | return QualType(VTP, 0); | |||
3399 | ||||
3400 | // If the element type isn't canonical, this won't be a canonical type either, | |||
3401 | // so fill in the canonical type field. | |||
3402 | QualType Canonical; | |||
3403 | if (!vecType.isCanonical()) { | |||
3404 | Canonical = getVectorType(getCanonicalType(vecType), NumElts, VecKind); | |||
3405 | ||||
3406 | // Get the new insert position for the node we care about. | |||
3407 | VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
3408 | assert(!NewIP && "Shouldn't be in the map!")((!NewIP && "Shouldn't be in the map!") ? static_cast <void> (0) : __assert_fail ("!NewIP && \"Shouldn't be in the map!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3408, __PRETTY_FUNCTION__)); (void)NewIP; | |||
3409 | } | |||
3410 | auto *New = new (*this, TypeAlignment) | |||
3411 | VectorType(vecType, NumElts, Canonical, VecKind); | |||
3412 | VectorTypes.InsertNode(New, InsertPos); | |||
3413 | Types.push_back(New); | |||
3414 | return QualType(New, 0); | |||
3415 | } | |||
3416 | ||||
3417 | QualType | |||
3418 | ASTContext::getDependentVectorType(QualType VecType, Expr *SizeExpr, | |||
3419 | SourceLocation AttrLoc, | |||
3420 | VectorType::VectorKind VecKind) const { | |||
3421 | llvm::FoldingSetNodeID ID; | |||
3422 | DependentVectorType::Profile(ID, *this, getCanonicalType(VecType), SizeExpr, | |||
3423 | VecKind); | |||
3424 | void *InsertPos = nullptr; | |||
3425 | DependentVectorType *Canon = | |||
3426 | DependentVectorTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
3427 | DependentVectorType *New; | |||
3428 | ||||
3429 | if (Canon) { | |||
3430 | New = new (*this, TypeAlignment) DependentVectorType( | |||
3431 | *this, VecType, QualType(Canon, 0), SizeExpr, AttrLoc, VecKind); | |||
3432 | } else { | |||
3433 | QualType CanonVecTy = getCanonicalType(VecType); | |||
3434 | if (CanonVecTy == VecType) { | |||
3435 | New = new (*this, TypeAlignment) DependentVectorType( | |||
3436 | *this, VecType, QualType(), SizeExpr, AttrLoc, VecKind); | |||
3437 | ||||
3438 | DependentVectorType *CanonCheck = | |||
3439 | DependentVectorTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
3440 | assert(!CanonCheck &&((!CanonCheck && "Dependent-sized vector_size canonical type broken" ) ? static_cast<void> (0) : __assert_fail ("!CanonCheck && \"Dependent-sized vector_size canonical type broken\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3441, __PRETTY_FUNCTION__)) | |||
3441 | "Dependent-sized vector_size canonical type broken")((!CanonCheck && "Dependent-sized vector_size canonical type broken" ) ? static_cast<void> (0) : __assert_fail ("!CanonCheck && \"Dependent-sized vector_size canonical type broken\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3441, __PRETTY_FUNCTION__)); | |||
3442 | (void)CanonCheck; | |||
3443 | DependentVectorTypes.InsertNode(New, InsertPos); | |||
3444 | } else { | |||
3445 | QualType Canon = getDependentSizedExtVectorType(CanonVecTy, SizeExpr, | |||
3446 | SourceLocation()); | |||
3447 | New = new (*this, TypeAlignment) DependentVectorType( | |||
3448 | *this, VecType, Canon, SizeExpr, AttrLoc, VecKind); | |||
3449 | } | |||
3450 | } | |||
3451 | ||||
3452 | Types.push_back(New); | |||
3453 | return QualType(New, 0); | |||
3454 | } | |||
3455 | ||||
3456 | /// getExtVectorType - Return the unique reference to an extended vector type of | |||
3457 | /// the specified element type and size. VectorType must be a built-in type. | |||
3458 | QualType | |||
3459 | ASTContext::getExtVectorType(QualType vecType, unsigned NumElts) const { | |||
3460 | assert(vecType->isBuiltinType() || vecType->isDependentType())((vecType->isBuiltinType() || vecType->isDependentType( )) ? static_cast<void> (0) : __assert_fail ("vecType->isBuiltinType() || vecType->isDependentType()" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3460, __PRETTY_FUNCTION__)); | |||
3461 | ||||
3462 | // Check if we've already instantiated a vector of this type. | |||
3463 | llvm::FoldingSetNodeID ID; | |||
3464 | VectorType::Profile(ID, vecType, NumElts, Type::ExtVector, | |||
3465 | VectorType::GenericVector); | |||
3466 | void *InsertPos = nullptr; | |||
3467 | if (VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos)) | |||
3468 | return QualType(VTP, 0); | |||
3469 | ||||
3470 | // If the element type isn't canonical, this won't be a canonical type either, | |||
3471 | // so fill in the canonical type field. | |||
3472 | QualType Canonical; | |||
3473 | if (!vecType.isCanonical()) { | |||
3474 | Canonical = getExtVectorType(getCanonicalType(vecType), NumElts); | |||
3475 | ||||
3476 | // Get the new insert position for the node we care about. | |||
3477 | VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
3478 | assert(!NewIP && "Shouldn't be in the map!")((!NewIP && "Shouldn't be in the map!") ? static_cast <void> (0) : __assert_fail ("!NewIP && \"Shouldn't be in the map!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3478, __PRETTY_FUNCTION__)); (void)NewIP; | |||
3479 | } | |||
3480 | auto *New = new (*this, TypeAlignment) | |||
3481 | ExtVectorType(vecType, NumElts, Canonical); | |||
3482 | VectorTypes.InsertNode(New, InsertPos); | |||
3483 | Types.push_back(New); | |||
3484 | return QualType(New, 0); | |||
3485 | } | |||
3486 | ||||
3487 | QualType | |||
3488 | ASTContext::getDependentSizedExtVectorType(QualType vecType, | |||
3489 | Expr *SizeExpr, | |||
3490 | SourceLocation AttrLoc) const { | |||
3491 | llvm::FoldingSetNodeID ID; | |||
3492 | DependentSizedExtVectorType::Profile(ID, *this, getCanonicalType(vecType), | |||
3493 | SizeExpr); | |||
3494 | ||||
3495 | void *InsertPos = nullptr; | |||
3496 | DependentSizedExtVectorType *Canon | |||
3497 | = DependentSizedExtVectorTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
3498 | DependentSizedExtVectorType *New; | |||
3499 | if (Canon) { | |||
3500 | // We already have a canonical version of this array type; use it as | |||
3501 | // the canonical type for a newly-built type. | |||
3502 | New = new (*this, TypeAlignment) | |||
3503 | DependentSizedExtVectorType(*this, vecType, QualType(Canon, 0), | |||
3504 | SizeExpr, AttrLoc); | |||
3505 | } else { | |||
3506 | QualType CanonVecTy = getCanonicalType(vecType); | |||
3507 | if (CanonVecTy == vecType) { | |||
3508 | New = new (*this, TypeAlignment) | |||
3509 | DependentSizedExtVectorType(*this, vecType, QualType(), SizeExpr, | |||
3510 | AttrLoc); | |||
3511 | ||||
3512 | DependentSizedExtVectorType *CanonCheck | |||
3513 | = DependentSizedExtVectorTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
3514 | assert(!CanonCheck && "Dependent-sized ext_vector canonical type broken")((!CanonCheck && "Dependent-sized ext_vector canonical type broken" ) ? static_cast<void> (0) : __assert_fail ("!CanonCheck && \"Dependent-sized ext_vector canonical type broken\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3514, __PRETTY_FUNCTION__)); | |||
3515 | (void)CanonCheck; | |||
3516 | DependentSizedExtVectorTypes.InsertNode(New, InsertPos); | |||
3517 | } else { | |||
3518 | QualType Canon = getDependentSizedExtVectorType(CanonVecTy, SizeExpr, | |||
3519 | SourceLocation()); | |||
3520 | New = new (*this, TypeAlignment) | |||
3521 | DependentSizedExtVectorType(*this, vecType, Canon, SizeExpr, AttrLoc); | |||
3522 | } | |||
3523 | } | |||
3524 | ||||
3525 | Types.push_back(New); | |||
3526 | return QualType(New, 0); | |||
3527 | } | |||
3528 | ||||
3529 | QualType ASTContext::getDependentAddressSpaceType(QualType PointeeType, | |||
3530 | Expr *AddrSpaceExpr, | |||
3531 | SourceLocation AttrLoc) const { | |||
3532 | assert(AddrSpaceExpr->isInstantiationDependent())((AddrSpaceExpr->isInstantiationDependent()) ? static_cast <void> (0) : __assert_fail ("AddrSpaceExpr->isInstantiationDependent()" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3532, __PRETTY_FUNCTION__)); | |||
3533 | ||||
3534 | QualType canonPointeeType = getCanonicalType(PointeeType); | |||
3535 | ||||
3536 | void *insertPos = nullptr; | |||
3537 | llvm::FoldingSetNodeID ID; | |||
3538 | DependentAddressSpaceType::Profile(ID, *this, canonPointeeType, | |||
3539 | AddrSpaceExpr); | |||
3540 | ||||
3541 | DependentAddressSpaceType *canonTy = | |||
3542 | DependentAddressSpaceTypes.FindNodeOrInsertPos(ID, insertPos); | |||
3543 | ||||
3544 | if (!canonTy) { | |||
3545 | canonTy = new (*this, TypeAlignment) | |||
3546 | DependentAddressSpaceType(*this, canonPointeeType, | |||
3547 | QualType(), AddrSpaceExpr, AttrLoc); | |||
3548 | DependentAddressSpaceTypes.InsertNode(canonTy, insertPos); | |||
3549 | Types.push_back(canonTy); | |||
3550 | } | |||
3551 | ||||
3552 | if (canonPointeeType == PointeeType && | |||
3553 | canonTy->getAddrSpaceExpr() == AddrSpaceExpr) | |||
3554 | return QualType(canonTy, 0); | |||
3555 | ||||
3556 | auto *sugaredType | |||
3557 | = new (*this, TypeAlignment) | |||
3558 | DependentAddressSpaceType(*this, PointeeType, QualType(canonTy, 0), | |||
3559 | AddrSpaceExpr, AttrLoc); | |||
3560 | Types.push_back(sugaredType); | |||
3561 | return QualType(sugaredType, 0); | |||
3562 | } | |||
3563 | ||||
3564 | /// Determine whether \p T is canonical as the result type of a function. | |||
3565 | static bool isCanonicalResultType(QualType T) { | |||
3566 | return T.isCanonical() && | |||
3567 | (T.getObjCLifetime() == Qualifiers::OCL_None || | |||
3568 | T.getObjCLifetime() == Qualifiers::OCL_ExplicitNone); | |||
3569 | } | |||
3570 | ||||
3571 | /// getFunctionNoProtoType - Return a K&R style C function type like 'int()'. | |||
3572 | QualType | |||
3573 | ASTContext::getFunctionNoProtoType(QualType ResultTy, | |||
3574 | const FunctionType::ExtInfo &Info) const { | |||
3575 | // Unique functions, to guarantee there is only one function of a particular | |||
3576 | // structure. | |||
3577 | llvm::FoldingSetNodeID ID; | |||
3578 | FunctionNoProtoType::Profile(ID, ResultTy, Info); | |||
3579 | ||||
3580 | void *InsertPos = nullptr; | |||
3581 | if (FunctionNoProtoType *FT = | |||
3582 | FunctionNoProtoTypes.FindNodeOrInsertPos(ID, InsertPos)) | |||
3583 | return QualType(FT, 0); | |||
3584 | ||||
3585 | QualType Canonical; | |||
3586 | if (!isCanonicalResultType(ResultTy)) { | |||
3587 | Canonical = | |||
3588 | getFunctionNoProtoType(getCanonicalFunctionResultType(ResultTy), Info); | |||
3589 | ||||
3590 | // Get the new insert position for the node we care about. | |||
3591 | FunctionNoProtoType *NewIP = | |||
3592 | FunctionNoProtoTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
3593 | assert(!NewIP && "Shouldn't be in the map!")((!NewIP && "Shouldn't be in the map!") ? static_cast <void> (0) : __assert_fail ("!NewIP && \"Shouldn't be in the map!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3593, __PRETTY_FUNCTION__)); (void)NewIP; | |||
3594 | } | |||
3595 | ||||
3596 | auto *New = new (*this, TypeAlignment) | |||
3597 | FunctionNoProtoType(ResultTy, Canonical, Info); | |||
3598 | Types.push_back(New); | |||
3599 | FunctionNoProtoTypes.InsertNode(New, InsertPos); | |||
3600 | return QualType(New, 0); | |||
3601 | } | |||
3602 | ||||
3603 | CanQualType | |||
3604 | ASTContext::getCanonicalFunctionResultType(QualType ResultType) const { | |||
3605 | CanQualType CanResultType = getCanonicalType(ResultType); | |||
3606 | ||||
3607 | // Canonical result types do not have ARC lifetime qualifiers. | |||
3608 | if (CanResultType.getQualifiers().hasObjCLifetime()) { | |||
3609 | Qualifiers Qs = CanResultType.getQualifiers(); | |||
3610 | Qs.removeObjCLifetime(); | |||
3611 | return CanQualType::CreateUnsafe( | |||
3612 | getQualifiedType(CanResultType.getUnqualifiedType(), Qs)); | |||
3613 | } | |||
3614 | ||||
3615 | return CanResultType; | |||
3616 | } | |||
3617 | ||||
3618 | static bool isCanonicalExceptionSpecification( | |||
3619 | const FunctionProtoType::ExceptionSpecInfo &ESI, bool NoexceptInType) { | |||
3620 | if (ESI.Type == EST_None) | |||
3621 | return true; | |||
3622 | if (!NoexceptInType) | |||
3623 | return false; | |||
3624 | ||||
3625 | // C++17 onwards: exception specification is part of the type, as a simple | |||
3626 | // boolean "can this function type throw". | |||
3627 | if (ESI.Type == EST_BasicNoexcept) | |||
3628 | return true; | |||
3629 | ||||
3630 | // A noexcept(expr) specification is (possibly) canonical if expr is | |||
3631 | // value-dependent. | |||
3632 | if (ESI.Type == EST_DependentNoexcept) | |||
3633 | return true; | |||
3634 | ||||
3635 | // A dynamic exception specification is canonical if it only contains pack | |||
3636 | // expansions (so we can't tell whether it's non-throwing) and all its | |||
3637 | // contained types are canonical. | |||
3638 | if (ESI.Type == EST_Dynamic) { | |||
3639 | bool AnyPackExpansions = false; | |||
3640 | for (QualType ET : ESI.Exceptions) { | |||
3641 | if (!ET.isCanonical()) | |||
3642 | return false; | |||
3643 | if (ET->getAs<PackExpansionType>()) | |||
3644 | AnyPackExpansions = true; | |||
3645 | } | |||
3646 | return AnyPackExpansions; | |||
3647 | } | |||
3648 | ||||
3649 | return false; | |||
3650 | } | |||
3651 | ||||
3652 | QualType ASTContext::getFunctionTypeInternal( | |||
3653 | QualType ResultTy, ArrayRef<QualType> ArgArray, | |||
3654 | const FunctionProtoType::ExtProtoInfo &EPI, bool OnlyWantCanonical) const { | |||
3655 | size_t NumArgs = ArgArray.size(); | |||
3656 | ||||
3657 | // Unique functions, to guarantee there is only one function of a particular | |||
3658 | // structure. | |||
3659 | llvm::FoldingSetNodeID ID; | |||
3660 | FunctionProtoType::Profile(ID, ResultTy, ArgArray.begin(), NumArgs, EPI, | |||
3661 | *this, true); | |||
3662 | ||||
3663 | QualType Canonical; | |||
3664 | bool Unique = false; | |||
3665 | ||||
3666 | void *InsertPos = nullptr; | |||
3667 | if (FunctionProtoType *FPT = | |||
3668 | FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos)) { | |||
3669 | QualType Existing = QualType(FPT, 0); | |||
3670 | ||||
3671 | // If we find a pre-existing equivalent FunctionProtoType, we can just reuse | |||
3672 | // it so long as our exception specification doesn't contain a dependent | |||
3673 | // noexcept expression, or we're just looking for a canonical type. | |||
3674 | // Otherwise, we're going to need to create a type | |||
3675 | // sugar node to hold the concrete expression. | |||
3676 | if (OnlyWantCanonical || !isComputedNoexcept(EPI.ExceptionSpec.Type) || | |||
3677 | EPI.ExceptionSpec.NoexceptExpr == FPT->getNoexceptExpr()) | |||
3678 | return Existing; | |||
3679 | ||||
3680 | // We need a new type sugar node for this one, to hold the new noexcept | |||
3681 | // expression. We do no canonicalization here, but that's OK since we don't | |||
3682 | // expect to see the same noexcept expression much more than once. | |||
3683 | Canonical = getCanonicalType(Existing); | |||
3684 | Unique = true; | |||
3685 | } | |||
3686 | ||||
3687 | bool NoexceptInType = getLangOpts().CPlusPlus17; | |||
3688 | bool IsCanonicalExceptionSpec = | |||
3689 | isCanonicalExceptionSpecification(EPI.ExceptionSpec, NoexceptInType); | |||
3690 | ||||
3691 | // Determine whether the type being created is already canonical or not. | |||
3692 | bool isCanonical = !Unique && IsCanonicalExceptionSpec && | |||
3693 | isCanonicalResultType(ResultTy) && !EPI.HasTrailingReturn; | |||
3694 | for (unsigned i = 0; i != NumArgs && isCanonical; ++i) | |||
3695 | if (!ArgArray[i].isCanonicalAsParam()) | |||
3696 | isCanonical = false; | |||
3697 | ||||
3698 | if (OnlyWantCanonical) | |||
3699 | assert(isCanonical &&((isCanonical && "given non-canonical parameters constructing canonical type" ) ? static_cast<void> (0) : __assert_fail ("isCanonical && \"given non-canonical parameters constructing canonical type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3700, __PRETTY_FUNCTION__)) | |||
3700 | "given non-canonical parameters constructing canonical type")((isCanonical && "given non-canonical parameters constructing canonical type" ) ? static_cast<void> (0) : __assert_fail ("isCanonical && \"given non-canonical parameters constructing canonical type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3700, __PRETTY_FUNCTION__)); | |||
3701 | ||||
3702 | // If this type isn't canonical, get the canonical version of it if we don't | |||
3703 | // already have it. The exception spec is only partially part of the | |||
3704 | // canonical type, and only in C++17 onwards. | |||
3705 | if (!isCanonical && Canonical.isNull()) { | |||
3706 | SmallVector<QualType, 16> CanonicalArgs; | |||
3707 | CanonicalArgs.reserve(NumArgs); | |||
3708 | for (unsigned i = 0; i != NumArgs; ++i) | |||
3709 | CanonicalArgs.push_back(getCanonicalParamType(ArgArray[i])); | |||
3710 | ||||
3711 | llvm::SmallVector<QualType, 8> ExceptionTypeStorage; | |||
3712 | FunctionProtoType::ExtProtoInfo CanonicalEPI = EPI; | |||
3713 | CanonicalEPI.HasTrailingReturn = false; | |||
3714 | ||||
3715 | if (IsCanonicalExceptionSpec) { | |||
3716 | // Exception spec is already OK. | |||
3717 | } else if (NoexceptInType) { | |||
3718 | switch (EPI.ExceptionSpec.Type) { | |||
3719 | case EST_Unparsed: case EST_Unevaluated: case EST_Uninstantiated: | |||
3720 | // We don't know yet. It shouldn't matter what we pick here; no-one | |||
3721 | // should ever look at this. | |||
3722 | LLVM_FALLTHROUGH[[clang::fallthrough]]; | |||
3723 | case EST_None: case EST_MSAny: case EST_NoexceptFalse: | |||
3724 | CanonicalEPI.ExceptionSpec.Type = EST_None; | |||
3725 | break; | |||
3726 | ||||
3727 | // A dynamic exception specification is almost always "not noexcept", | |||
3728 | // with the exception that a pack expansion might expand to no types. | |||
3729 | case EST_Dynamic: { | |||
3730 | bool AnyPacks = false; | |||
3731 | for (QualType ET : EPI.ExceptionSpec.Exceptions) { | |||
3732 | if (ET->getAs<PackExpansionType>()) | |||
3733 | AnyPacks = true; | |||
3734 | ExceptionTypeStorage.push_back(getCanonicalType(ET)); | |||
3735 | } | |||
3736 | if (!AnyPacks) | |||
3737 | CanonicalEPI.ExceptionSpec.Type = EST_None; | |||
3738 | else { | |||
3739 | CanonicalEPI.ExceptionSpec.Type = EST_Dynamic; | |||
3740 | CanonicalEPI.ExceptionSpec.Exceptions = ExceptionTypeStorage; | |||
3741 | } | |||
3742 | break; | |||
3743 | } | |||
3744 | ||||
3745 | case EST_DynamicNone: | |||
3746 | case EST_BasicNoexcept: | |||
3747 | case EST_NoexceptTrue: | |||
3748 | case EST_NoThrow: | |||
3749 | CanonicalEPI.ExceptionSpec.Type = EST_BasicNoexcept; | |||
3750 | break; | |||
3751 | ||||
3752 | case EST_DependentNoexcept: | |||
3753 | llvm_unreachable("dependent noexcept is already canonical")::llvm::llvm_unreachable_internal("dependent noexcept is already canonical" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3753); | |||
3754 | } | |||
3755 | } else { | |||
3756 | CanonicalEPI.ExceptionSpec = FunctionProtoType::ExceptionSpecInfo(); | |||
3757 | } | |||
3758 | ||||
3759 | // Adjust the canonical function result type. | |||
3760 | CanQualType CanResultTy = getCanonicalFunctionResultType(ResultTy); | |||
3761 | Canonical = | |||
3762 | getFunctionTypeInternal(CanResultTy, CanonicalArgs, CanonicalEPI, true); | |||
3763 | ||||
3764 | // Get the new insert position for the node we care about. | |||
3765 | FunctionProtoType *NewIP = | |||
3766 | FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
3767 | assert(!NewIP && "Shouldn't be in the map!")((!NewIP && "Shouldn't be in the map!") ? static_cast <void> (0) : __assert_fail ("!NewIP && \"Shouldn't be in the map!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3767, __PRETTY_FUNCTION__)); (void)NewIP; | |||
3768 | } | |||
3769 | ||||
3770 | // Compute the needed size to hold this FunctionProtoType and the | |||
3771 | // various trailing objects. | |||
3772 | auto ESH = FunctionProtoType::getExceptionSpecSize( | |||
3773 | EPI.ExceptionSpec.Type, EPI.ExceptionSpec.Exceptions.size()); | |||
3774 | size_t Size = FunctionProtoType::totalSizeToAlloc< | |||
3775 | QualType, FunctionType::FunctionTypeExtraBitfields, | |||
3776 | FunctionType::ExceptionType, Expr *, FunctionDecl *, | |||
3777 | FunctionProtoType::ExtParameterInfo, Qualifiers>( | |||
3778 | NumArgs, FunctionProtoType::hasExtraBitfields(EPI.ExceptionSpec.Type), | |||
3779 | ESH.NumExceptionType, ESH.NumExprPtr, ESH.NumFunctionDeclPtr, | |||
3780 | EPI.ExtParameterInfos ? NumArgs : 0, | |||
3781 | EPI.TypeQuals.hasNonFastQualifiers() ? 1 : 0); | |||
3782 | ||||
3783 | auto *FTP = (FunctionProtoType *)Allocate(Size, TypeAlignment); | |||
3784 | FunctionProtoType::ExtProtoInfo newEPI = EPI; | |||
3785 | new (FTP) FunctionProtoType(ResultTy, ArgArray, Canonical, newEPI); | |||
3786 | Types.push_back(FTP); | |||
3787 | if (!Unique) | |||
3788 | FunctionProtoTypes.InsertNode(FTP, InsertPos); | |||
3789 | return QualType(FTP, 0); | |||
3790 | } | |||
3791 | ||||
3792 | QualType ASTContext::getPipeType(QualType T, bool ReadOnly) const { | |||
3793 | llvm::FoldingSetNodeID ID; | |||
3794 | PipeType::Profile(ID, T, ReadOnly); | |||
3795 | ||||
3796 | void *InsertPos = nullptr; | |||
3797 | if (PipeType *PT = PipeTypes.FindNodeOrInsertPos(ID, InsertPos)) | |||
3798 | return QualType(PT, 0); | |||
3799 | ||||
3800 | // If the pipe element type isn't canonical, this won't be a canonical type | |||
3801 | // either, so fill in the canonical type field. | |||
3802 | QualType Canonical; | |||
3803 | if (!T.isCanonical()) { | |||
3804 | Canonical = getPipeType(getCanonicalType(T), ReadOnly); | |||
3805 | ||||
3806 | // Get the new insert position for the node we care about. | |||
3807 | PipeType *NewIP = PipeTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
3808 | assert(!NewIP && "Shouldn't be in the map!")((!NewIP && "Shouldn't be in the map!") ? static_cast <void> (0) : __assert_fail ("!NewIP && \"Shouldn't be in the map!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3808, __PRETTY_FUNCTION__)); | |||
3809 | (void)NewIP; | |||
3810 | } | |||
3811 | auto *New = new (*this, TypeAlignment) PipeType(T, Canonical, ReadOnly); | |||
3812 | Types.push_back(New); | |||
3813 | PipeTypes.InsertNode(New, InsertPos); | |||
3814 | return QualType(New, 0); | |||
3815 | } | |||
3816 | ||||
3817 | QualType ASTContext::adjustStringLiteralBaseType(QualType Ty) const { | |||
3818 | // OpenCL v1.1 s6.5.3: a string literal is in the constant address space. | |||
3819 | return LangOpts.OpenCL ? getAddrSpaceQualType(Ty, LangAS::opencl_constant) | |||
3820 | : Ty; | |||
3821 | } | |||
3822 | ||||
3823 | QualType ASTContext::getReadPipeType(QualType T) const { | |||
3824 | return getPipeType(T, true); | |||
3825 | } | |||
3826 | ||||
3827 | QualType ASTContext::getWritePipeType(QualType T) const { | |||
3828 | return getPipeType(T, false); | |||
3829 | } | |||
3830 | ||||
3831 | #ifndef NDEBUG | |||
3832 | static bool NeedsInjectedClassNameType(const RecordDecl *D) { | |||
3833 | if (!isa<CXXRecordDecl>(D)) return false; | |||
3834 | const auto *RD = cast<CXXRecordDecl>(D); | |||
3835 | if (isa<ClassTemplatePartialSpecializationDecl>(RD)) | |||
3836 | return true; | |||
3837 | if (RD->getDescribedClassTemplate() && | |||
3838 | !isa<ClassTemplateSpecializationDecl>(RD)) | |||
3839 | return true; | |||
3840 | return false; | |||
3841 | } | |||
3842 | #endif | |||
3843 | ||||
3844 | /// getInjectedClassNameType - Return the unique reference to the | |||
3845 | /// injected class name type for the specified templated declaration. | |||
3846 | QualType ASTContext::getInjectedClassNameType(CXXRecordDecl *Decl, | |||
3847 | QualType TST) const { | |||
3848 | assert(NeedsInjectedClassNameType(Decl))((NeedsInjectedClassNameType(Decl)) ? static_cast<void> (0) : __assert_fail ("NeedsInjectedClassNameType(Decl)", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3848, __PRETTY_FUNCTION__)); | |||
3849 | if (Decl->TypeForDecl) { | |||
3850 | assert(isa<InjectedClassNameType>(Decl->TypeForDecl))((isa<InjectedClassNameType>(Decl->TypeForDecl)) ? static_cast <void> (0) : __assert_fail ("isa<InjectedClassNameType>(Decl->TypeForDecl)" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3850, __PRETTY_FUNCTION__)); | |||
3851 | } else if (CXXRecordDecl *PrevDecl = Decl->getPreviousDecl()) { | |||
3852 | assert(PrevDecl->TypeForDecl && "previous declaration has no type")((PrevDecl->TypeForDecl && "previous declaration has no type" ) ? static_cast<void> (0) : __assert_fail ("PrevDecl->TypeForDecl && \"previous declaration has no type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3852, __PRETTY_FUNCTION__)); | |||
3853 | Decl->TypeForDecl = PrevDecl->TypeForDecl; | |||
3854 | assert(isa<InjectedClassNameType>(Decl->TypeForDecl))((isa<InjectedClassNameType>(Decl->TypeForDecl)) ? static_cast <void> (0) : __assert_fail ("isa<InjectedClassNameType>(Decl->TypeForDecl)" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3854, __PRETTY_FUNCTION__)); | |||
3855 | } else { | |||
3856 | Type *newType = | |||
3857 | new (*this, TypeAlignment) InjectedClassNameType(Decl, TST); | |||
3858 | Decl->TypeForDecl = newType; | |||
3859 | Types.push_back(newType); | |||
3860 | } | |||
3861 | return QualType(Decl->TypeForDecl, 0); | |||
3862 | } | |||
3863 | ||||
3864 | /// getTypeDeclType - Return the unique reference to the type for the | |||
3865 | /// specified type declaration. | |||
3866 | QualType ASTContext::getTypeDeclTypeSlow(const TypeDecl *Decl) const { | |||
3867 | assert(Decl && "Passed null for Decl param")((Decl && "Passed null for Decl param") ? static_cast <void> (0) : __assert_fail ("Decl && \"Passed null for Decl param\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3867, __PRETTY_FUNCTION__)); | |||
3868 | assert(!Decl->TypeForDecl && "TypeForDecl present in slow case")((!Decl->TypeForDecl && "TypeForDecl present in slow case" ) ? static_cast<void> (0) : __assert_fail ("!Decl->TypeForDecl && \"TypeForDecl present in slow case\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3868, __PRETTY_FUNCTION__)); | |||
3869 | ||||
3870 | if (const auto *Typedef = dyn_cast<TypedefNameDecl>(Decl)) | |||
3871 | return getTypedefType(Typedef); | |||
3872 | ||||
3873 | assert(!isa<TemplateTypeParmDecl>(Decl) &&((!isa<TemplateTypeParmDecl>(Decl) && "Template type parameter types are always available." ) ? static_cast<void> (0) : __assert_fail ("!isa<TemplateTypeParmDecl>(Decl) && \"Template type parameter types are always available.\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3874, __PRETTY_FUNCTION__)) | |||
3874 | "Template type parameter types are always available.")((!isa<TemplateTypeParmDecl>(Decl) && "Template type parameter types are always available." ) ? static_cast<void> (0) : __assert_fail ("!isa<TemplateTypeParmDecl>(Decl) && \"Template type parameter types are always available.\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3874, __PRETTY_FUNCTION__)); | |||
3875 | ||||
3876 | if (const auto *Record = dyn_cast<RecordDecl>(Decl)) { | |||
3877 | assert(Record->isFirstDecl() && "struct/union has previous declaration")((Record->isFirstDecl() && "struct/union has previous declaration" ) ? static_cast<void> (0) : __assert_fail ("Record->isFirstDecl() && \"struct/union has previous declaration\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3877, __PRETTY_FUNCTION__)); | |||
3878 | assert(!NeedsInjectedClassNameType(Record))((!NeedsInjectedClassNameType(Record)) ? static_cast<void> (0) : __assert_fail ("!NeedsInjectedClassNameType(Record)", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3878, __PRETTY_FUNCTION__)); | |||
3879 | return getRecordType(Record); | |||
3880 | } else if (const auto *Enum = dyn_cast<EnumDecl>(Decl)) { | |||
3881 | assert(Enum->isFirstDecl() && "enum has previous declaration")((Enum->isFirstDecl() && "enum has previous declaration" ) ? static_cast<void> (0) : __assert_fail ("Enum->isFirstDecl() && \"enum has previous declaration\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3881, __PRETTY_FUNCTION__)); | |||
3882 | return getEnumType(Enum); | |||
3883 | } else if (const auto *Using = dyn_cast<UnresolvedUsingTypenameDecl>(Decl)) { | |||
3884 | Type *newType = new (*this, TypeAlignment) UnresolvedUsingType(Using); | |||
3885 | Decl->TypeForDecl = newType; | |||
3886 | Types.push_back(newType); | |||
3887 | } else | |||
3888 | llvm_unreachable("TypeDecl without a type?")::llvm::llvm_unreachable_internal("TypeDecl without a type?", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3888); | |||
3889 | ||||
3890 | return QualType(Decl->TypeForDecl, 0); | |||
3891 | } | |||
3892 | ||||
3893 | /// getTypedefType - Return the unique reference to the type for the | |||
3894 | /// specified typedef name decl. | |||
3895 | QualType | |||
3896 | ASTContext::getTypedefType(const TypedefNameDecl *Decl, | |||
3897 | QualType Canonical) const { | |||
3898 | if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); | |||
3899 | ||||
3900 | if (Canonical.isNull()) | |||
3901 | Canonical = getCanonicalType(Decl->getUnderlyingType()); | |||
3902 | auto *newType = new (*this, TypeAlignment) | |||
3903 | TypedefType(Type::Typedef, Decl, Canonical); | |||
3904 | Decl->TypeForDecl = newType; | |||
3905 | Types.push_back(newType); | |||
3906 | return QualType(newType, 0); | |||
3907 | } | |||
3908 | ||||
3909 | QualType ASTContext::getRecordType(const RecordDecl *Decl) const { | |||
3910 | if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); | |||
3911 | ||||
3912 | if (const RecordDecl *PrevDecl = Decl->getPreviousDecl()) | |||
3913 | if (PrevDecl->TypeForDecl) | |||
3914 | return QualType(Decl->TypeForDecl = PrevDecl->TypeForDecl, 0); | |||
3915 | ||||
3916 | auto *newType = new (*this, TypeAlignment) RecordType(Decl); | |||
3917 | Decl->TypeForDecl = newType; | |||
3918 | Types.push_back(newType); | |||
3919 | return QualType(newType, 0); | |||
3920 | } | |||
3921 | ||||
3922 | QualType ASTContext::getEnumType(const EnumDecl *Decl) const { | |||
3923 | if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); | |||
3924 | ||||
3925 | if (const EnumDecl *PrevDecl = Decl->getPreviousDecl()) | |||
3926 | if (PrevDecl->TypeForDecl) | |||
3927 | return QualType(Decl->TypeForDecl = PrevDecl->TypeForDecl, 0); | |||
3928 | ||||
3929 | auto *newType = new (*this, TypeAlignment) EnumType(Decl); | |||
3930 | Decl->TypeForDecl = newType; | |||
3931 | Types.push_back(newType); | |||
3932 | return QualType(newType, 0); | |||
3933 | } | |||
3934 | ||||
3935 | QualType ASTContext::getAttributedType(attr::Kind attrKind, | |||
3936 | QualType modifiedType, | |||
3937 | QualType equivalentType) { | |||
3938 | llvm::FoldingSetNodeID id; | |||
3939 | AttributedType::Profile(id, attrKind, modifiedType, equivalentType); | |||
3940 | ||||
3941 | void *insertPos = nullptr; | |||
3942 | AttributedType *type = AttributedTypes.FindNodeOrInsertPos(id, insertPos); | |||
3943 | if (type) return QualType(type, 0); | |||
3944 | ||||
3945 | QualType canon = getCanonicalType(equivalentType); | |||
3946 | type = new (*this, TypeAlignment) | |||
3947 | AttributedType(canon, attrKind, modifiedType, equivalentType); | |||
3948 | ||||
3949 | Types.push_back(type); | |||
3950 | AttributedTypes.InsertNode(type, insertPos); | |||
3951 | ||||
3952 | return QualType(type, 0); | |||
3953 | } | |||
3954 | ||||
3955 | /// Retrieve a substitution-result type. | |||
3956 | QualType | |||
3957 | ASTContext::getSubstTemplateTypeParmType(const TemplateTypeParmType *Parm, | |||
3958 | QualType Replacement) const { | |||
3959 | assert(Replacement.isCanonical()((Replacement.isCanonical() && "replacement types must always be canonical" ) ? static_cast<void> (0) : __assert_fail ("Replacement.isCanonical() && \"replacement types must always be canonical\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3960, __PRETTY_FUNCTION__)) | |||
3960 | && "replacement types must always be canonical")((Replacement.isCanonical() && "replacement types must always be canonical" ) ? static_cast<void> (0) : __assert_fail ("Replacement.isCanonical() && \"replacement types must always be canonical\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3960, __PRETTY_FUNCTION__)); | |||
3961 | ||||
3962 | llvm::FoldingSetNodeID ID; | |||
3963 | SubstTemplateTypeParmType::Profile(ID, Parm, Replacement); | |||
3964 | void *InsertPos = nullptr; | |||
3965 | SubstTemplateTypeParmType *SubstParm | |||
3966 | = SubstTemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
3967 | ||||
3968 | if (!SubstParm) { | |||
3969 | SubstParm = new (*this, TypeAlignment) | |||
3970 | SubstTemplateTypeParmType(Parm, Replacement); | |||
3971 | Types.push_back(SubstParm); | |||
3972 | SubstTemplateTypeParmTypes.InsertNode(SubstParm, InsertPos); | |||
3973 | } | |||
3974 | ||||
3975 | return QualType(SubstParm, 0); | |||
3976 | } | |||
3977 | ||||
3978 | /// Retrieve a | |||
3979 | QualType ASTContext::getSubstTemplateTypeParmPackType( | |||
3980 | const TemplateTypeParmType *Parm, | |||
3981 | const TemplateArgument &ArgPack) { | |||
3982 | #ifndef NDEBUG | |||
3983 | for (const auto &P : ArgPack.pack_elements()) { | |||
3984 | assert(P.getKind() == TemplateArgument::Type &&"Pack contains a non-type")((P.getKind() == TemplateArgument::Type &&"Pack contains a non-type" ) ? static_cast<void> (0) : __assert_fail ("P.getKind() == TemplateArgument::Type &&\"Pack contains a non-type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3984, __PRETTY_FUNCTION__)); | |||
3985 | assert(P.getAsType().isCanonical() && "Pack contains non-canonical type")((P.getAsType().isCanonical() && "Pack contains non-canonical type" ) ? static_cast<void> (0) : __assert_fail ("P.getAsType().isCanonical() && \"Pack contains non-canonical type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 3985, __PRETTY_FUNCTION__)); | |||
3986 | } | |||
3987 | #endif | |||
3988 | ||||
3989 | llvm::FoldingSetNodeID ID; | |||
3990 | SubstTemplateTypeParmPackType::Profile(ID, Parm, ArgPack); | |||
3991 | void *InsertPos = nullptr; | |||
3992 | if (SubstTemplateTypeParmPackType *SubstParm | |||
3993 | = SubstTemplateTypeParmPackTypes.FindNodeOrInsertPos(ID, InsertPos)) | |||
3994 | return QualType(SubstParm, 0); | |||
3995 | ||||
3996 | QualType Canon; | |||
3997 | if (!Parm->isCanonicalUnqualified()) { | |||
3998 | Canon = getCanonicalType(QualType(Parm, 0)); | |||
3999 | Canon = getSubstTemplateTypeParmPackType(cast<TemplateTypeParmType>(Canon), | |||
4000 | ArgPack); | |||
4001 | SubstTemplateTypeParmPackTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4002 | } | |||
4003 | ||||
4004 | auto *SubstParm | |||
4005 | = new (*this, TypeAlignment) SubstTemplateTypeParmPackType(Parm, Canon, | |||
4006 | ArgPack); | |||
4007 | Types.push_back(SubstParm); | |||
4008 | SubstTemplateTypeParmPackTypes.InsertNode(SubstParm, InsertPos); | |||
4009 | return QualType(SubstParm, 0); | |||
4010 | } | |||
4011 | ||||
4012 | /// Retrieve the template type parameter type for a template | |||
4013 | /// parameter or parameter pack with the given depth, index, and (optionally) | |||
4014 | /// name. | |||
4015 | QualType ASTContext::getTemplateTypeParmType(unsigned Depth, unsigned Index, | |||
4016 | bool ParameterPack, | |||
4017 | TemplateTypeParmDecl *TTPDecl) const { | |||
4018 | llvm::FoldingSetNodeID ID; | |||
4019 | TemplateTypeParmType::Profile(ID, Depth, Index, ParameterPack, TTPDecl); | |||
4020 | void *InsertPos = nullptr; | |||
4021 | TemplateTypeParmType *TypeParm | |||
4022 | = TemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4023 | ||||
4024 | if (TypeParm) | |||
4025 | return QualType(TypeParm, 0); | |||
4026 | ||||
4027 | if (TTPDecl) { | |||
4028 | QualType Canon = getTemplateTypeParmType(Depth, Index, ParameterPack); | |||
4029 | TypeParm = new (*this, TypeAlignment) TemplateTypeParmType(TTPDecl, Canon); | |||
4030 | ||||
4031 | TemplateTypeParmType *TypeCheck | |||
4032 | = TemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4033 | assert(!TypeCheck && "Template type parameter canonical type broken")((!TypeCheck && "Template type parameter canonical type broken" ) ? static_cast<void> (0) : __assert_fail ("!TypeCheck && \"Template type parameter canonical type broken\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4033, __PRETTY_FUNCTION__)); | |||
4034 | (void)TypeCheck; | |||
4035 | } else | |||
4036 | TypeParm = new (*this, TypeAlignment) | |||
4037 | TemplateTypeParmType(Depth, Index, ParameterPack); | |||
4038 | ||||
4039 | Types.push_back(TypeParm); | |||
4040 | TemplateTypeParmTypes.InsertNode(TypeParm, InsertPos); | |||
4041 | ||||
4042 | return QualType(TypeParm, 0); | |||
4043 | } | |||
4044 | ||||
4045 | TypeSourceInfo * | |||
4046 | ASTContext::getTemplateSpecializationTypeInfo(TemplateName Name, | |||
4047 | SourceLocation NameLoc, | |||
4048 | const TemplateArgumentListInfo &Args, | |||
4049 | QualType Underlying) const { | |||
4050 | assert(!Name.getAsDependentTemplateName() &&((!Name.getAsDependentTemplateName() && "No dependent template names here!" ) ? static_cast<void> (0) : __assert_fail ("!Name.getAsDependentTemplateName() && \"No dependent template names here!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4051, __PRETTY_FUNCTION__)) | |||
4051 | "No dependent template names here!")((!Name.getAsDependentTemplateName() && "No dependent template names here!" ) ? static_cast<void> (0) : __assert_fail ("!Name.getAsDependentTemplateName() && \"No dependent template names here!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4051, __PRETTY_FUNCTION__)); | |||
4052 | QualType TST = getTemplateSpecializationType(Name, Args, Underlying); | |||
4053 | ||||
4054 | TypeSourceInfo *DI = CreateTypeSourceInfo(TST); | |||
4055 | TemplateSpecializationTypeLoc TL = | |||
4056 | DI->getTypeLoc().castAs<TemplateSpecializationTypeLoc>(); | |||
4057 | TL.setTemplateKeywordLoc(SourceLocation()); | |||
4058 | TL.setTemplateNameLoc(NameLoc); | |||
4059 | TL.setLAngleLoc(Args.getLAngleLoc()); | |||
4060 | TL.setRAngleLoc(Args.getRAngleLoc()); | |||
4061 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) | |||
4062 | TL.setArgLocInfo(i, Args[i].getLocInfo()); | |||
4063 | return DI; | |||
4064 | } | |||
4065 | ||||
4066 | QualType | |||
4067 | ASTContext::getTemplateSpecializationType(TemplateName Template, | |||
4068 | const TemplateArgumentListInfo &Args, | |||
4069 | QualType Underlying) const { | |||
4070 | assert(!Template.getAsDependentTemplateName() &&((!Template.getAsDependentTemplateName() && "No dependent template names here!" ) ? static_cast<void> (0) : __assert_fail ("!Template.getAsDependentTemplateName() && \"No dependent template names here!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4071, __PRETTY_FUNCTION__)) | |||
4071 | "No dependent template names here!")((!Template.getAsDependentTemplateName() && "No dependent template names here!" ) ? static_cast<void> (0) : __assert_fail ("!Template.getAsDependentTemplateName() && \"No dependent template names here!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4071, __PRETTY_FUNCTION__)); | |||
4072 | ||||
4073 | SmallVector<TemplateArgument, 4> ArgVec; | |||
4074 | ArgVec.reserve(Args.size()); | |||
4075 | for (const TemplateArgumentLoc &Arg : Args.arguments()) | |||
4076 | ArgVec.push_back(Arg.getArgument()); | |||
4077 | ||||
4078 | return getTemplateSpecializationType(Template, ArgVec, Underlying); | |||
4079 | } | |||
4080 | ||||
4081 | #ifndef NDEBUG | |||
4082 | static bool hasAnyPackExpansions(ArrayRef<TemplateArgument> Args) { | |||
4083 | for (const TemplateArgument &Arg : Args) | |||
4084 | if (Arg.isPackExpansion()) | |||
4085 | return true; | |||
4086 | ||||
4087 | return true; | |||
4088 | } | |||
4089 | #endif | |||
4090 | ||||
4091 | QualType | |||
4092 | ASTContext::getTemplateSpecializationType(TemplateName Template, | |||
4093 | ArrayRef<TemplateArgument> Args, | |||
4094 | QualType Underlying) const { | |||
4095 | assert(!Template.getAsDependentTemplateName() &&((!Template.getAsDependentTemplateName() && "No dependent template names here!" ) ? static_cast<void> (0) : __assert_fail ("!Template.getAsDependentTemplateName() && \"No dependent template names here!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4096, __PRETTY_FUNCTION__)) | |||
4096 | "No dependent template names here!")((!Template.getAsDependentTemplateName() && "No dependent template names here!" ) ? static_cast<void> (0) : __assert_fail ("!Template.getAsDependentTemplateName() && \"No dependent template names here!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4096, __PRETTY_FUNCTION__)); | |||
4097 | // Look through qualified template names. | |||
4098 | if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) | |||
4099 | Template = TemplateName(QTN->getTemplateDecl()); | |||
4100 | ||||
4101 | bool IsTypeAlias = | |||
4102 | Template.getAsTemplateDecl() && | |||
4103 | isa<TypeAliasTemplateDecl>(Template.getAsTemplateDecl()); | |||
4104 | QualType CanonType; | |||
4105 | if (!Underlying.isNull()) | |||
4106 | CanonType = getCanonicalType(Underlying); | |||
4107 | else { | |||
4108 | // We can get here with an alias template when the specialization contains | |||
4109 | // a pack expansion that does not match up with a parameter pack. | |||
4110 | assert((!IsTypeAlias || hasAnyPackExpansions(Args)) &&(((!IsTypeAlias || hasAnyPackExpansions(Args)) && "Caller must compute aliased type" ) ? static_cast<void> (0) : __assert_fail ("(!IsTypeAlias || hasAnyPackExpansions(Args)) && \"Caller must compute aliased type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4111, __PRETTY_FUNCTION__)) | |||
4111 | "Caller must compute aliased type")(((!IsTypeAlias || hasAnyPackExpansions(Args)) && "Caller must compute aliased type" ) ? static_cast<void> (0) : __assert_fail ("(!IsTypeAlias || hasAnyPackExpansions(Args)) && \"Caller must compute aliased type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4111, __PRETTY_FUNCTION__)); | |||
4112 | IsTypeAlias = false; | |||
4113 | CanonType = getCanonicalTemplateSpecializationType(Template, Args); | |||
4114 | } | |||
4115 | ||||
4116 | // Allocate the (non-canonical) template specialization type, but don't | |||
4117 | // try to unique it: these types typically have location information that | |||
4118 | // we don't unique and don't want to lose. | |||
4119 | void *Mem = Allocate(sizeof(TemplateSpecializationType) + | |||
4120 | sizeof(TemplateArgument) * Args.size() + | |||
4121 | (IsTypeAlias? sizeof(QualType) : 0), | |||
4122 | TypeAlignment); | |||
4123 | auto *Spec | |||
4124 | = new (Mem) TemplateSpecializationType(Template, Args, CanonType, | |||
4125 | IsTypeAlias ? Underlying : QualType()); | |||
4126 | ||||
4127 | Types.push_back(Spec); | |||
4128 | return QualType(Spec, 0); | |||
4129 | } | |||
4130 | ||||
4131 | QualType ASTContext::getCanonicalTemplateSpecializationType( | |||
4132 | TemplateName Template, ArrayRef<TemplateArgument> Args) const { | |||
4133 | assert(!Template.getAsDependentTemplateName() &&((!Template.getAsDependentTemplateName() && "No dependent template names here!" ) ? static_cast<void> (0) : __assert_fail ("!Template.getAsDependentTemplateName() && \"No dependent template names here!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4134, __PRETTY_FUNCTION__)) | |||
4134 | "No dependent template names here!")((!Template.getAsDependentTemplateName() && "No dependent template names here!" ) ? static_cast<void> (0) : __assert_fail ("!Template.getAsDependentTemplateName() && \"No dependent template names here!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4134, __PRETTY_FUNCTION__)); | |||
4135 | ||||
4136 | // Look through qualified template names. | |||
4137 | if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) | |||
4138 | Template = TemplateName(QTN->getTemplateDecl()); | |||
4139 | ||||
4140 | // Build the canonical template specialization type. | |||
4141 | TemplateName CanonTemplate = getCanonicalTemplateName(Template); | |||
4142 | SmallVector<TemplateArgument, 4> CanonArgs; | |||
4143 | unsigned NumArgs = Args.size(); | |||
4144 | CanonArgs.reserve(NumArgs); | |||
4145 | for (const TemplateArgument &Arg : Args) | |||
4146 | CanonArgs.push_back(getCanonicalTemplateArgument(Arg)); | |||
4147 | ||||
4148 | // Determine whether this canonical template specialization type already | |||
4149 | // exists. | |||
4150 | llvm::FoldingSetNodeID ID; | |||
4151 | TemplateSpecializationType::Profile(ID, CanonTemplate, | |||
4152 | CanonArgs, *this); | |||
4153 | ||||
4154 | void *InsertPos = nullptr; | |||
4155 | TemplateSpecializationType *Spec | |||
4156 | = TemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4157 | ||||
4158 | if (!Spec) { | |||
4159 | // Allocate a new canonical template specialization type. | |||
4160 | void *Mem = Allocate((sizeof(TemplateSpecializationType) + | |||
4161 | sizeof(TemplateArgument) * NumArgs), | |||
4162 | TypeAlignment); | |||
4163 | Spec = new (Mem) TemplateSpecializationType(CanonTemplate, | |||
4164 | CanonArgs, | |||
4165 | QualType(), QualType()); | |||
4166 | Types.push_back(Spec); | |||
4167 | TemplateSpecializationTypes.InsertNode(Spec, InsertPos); | |||
4168 | } | |||
4169 | ||||
4170 | assert(Spec->isDependentType() &&((Spec->isDependentType() && "Non-dependent template-id type must have a canonical type" ) ? static_cast<void> (0) : __assert_fail ("Spec->isDependentType() && \"Non-dependent template-id type must have a canonical type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4171, __PRETTY_FUNCTION__)) | |||
4171 | "Non-dependent template-id type must have a canonical type")((Spec->isDependentType() && "Non-dependent template-id type must have a canonical type" ) ? static_cast<void> (0) : __assert_fail ("Spec->isDependentType() && \"Non-dependent template-id type must have a canonical type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4171, __PRETTY_FUNCTION__)); | |||
4172 | return QualType(Spec, 0); | |||
4173 | } | |||
4174 | ||||
4175 | QualType ASTContext::getElaboratedType(ElaboratedTypeKeyword Keyword, | |||
4176 | NestedNameSpecifier *NNS, | |||
4177 | QualType NamedType, | |||
4178 | TagDecl *OwnedTagDecl) const { | |||
4179 | llvm::FoldingSetNodeID ID; | |||
4180 | ElaboratedType::Profile(ID, Keyword, NNS, NamedType, OwnedTagDecl); | |||
4181 | ||||
4182 | void *InsertPos = nullptr; | |||
4183 | ElaboratedType *T = ElaboratedTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4184 | if (T) | |||
4185 | return QualType(T, 0); | |||
4186 | ||||
4187 | QualType Canon = NamedType; | |||
4188 | if (!Canon.isCanonical()) { | |||
4189 | Canon = getCanonicalType(NamedType); | |||
4190 | ElaboratedType *CheckT = ElaboratedTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4191 | assert(!CheckT && "Elaborated canonical type broken")((!CheckT && "Elaborated canonical type broken") ? static_cast <void> (0) : __assert_fail ("!CheckT && \"Elaborated canonical type broken\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4191, __PRETTY_FUNCTION__)); | |||
4192 | (void)CheckT; | |||
4193 | } | |||
4194 | ||||
4195 | void *Mem = Allocate(ElaboratedType::totalSizeToAlloc<TagDecl *>(!!OwnedTagDecl), | |||
4196 | TypeAlignment); | |||
4197 | T = new (Mem) ElaboratedType(Keyword, NNS, NamedType, Canon, OwnedTagDecl); | |||
4198 | ||||
4199 | Types.push_back(T); | |||
4200 | ElaboratedTypes.InsertNode(T, InsertPos); | |||
4201 | return QualType(T, 0); | |||
4202 | } | |||
4203 | ||||
4204 | QualType | |||
4205 | ASTContext::getParenType(QualType InnerType) const { | |||
4206 | llvm::FoldingSetNodeID ID; | |||
4207 | ParenType::Profile(ID, InnerType); | |||
4208 | ||||
4209 | void *InsertPos = nullptr; | |||
4210 | ParenType *T = ParenTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4211 | if (T) | |||
4212 | return QualType(T, 0); | |||
4213 | ||||
4214 | QualType Canon = InnerType; | |||
4215 | if (!Canon.isCanonical()) { | |||
4216 | Canon = getCanonicalType(InnerType); | |||
4217 | ParenType *CheckT = ParenTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4218 | assert(!CheckT && "Paren canonical type broken")((!CheckT && "Paren canonical type broken") ? static_cast <void> (0) : __assert_fail ("!CheckT && \"Paren canonical type broken\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4218, __PRETTY_FUNCTION__)); | |||
4219 | (void)CheckT; | |||
4220 | } | |||
4221 | ||||
4222 | T = new (*this, TypeAlignment) ParenType(InnerType, Canon); | |||
4223 | Types.push_back(T); | |||
4224 | ParenTypes.InsertNode(T, InsertPos); | |||
4225 | return QualType(T, 0); | |||
4226 | } | |||
4227 | ||||
4228 | QualType | |||
4229 | ASTContext::getMacroQualifiedType(QualType UnderlyingTy, | |||
4230 | const IdentifierInfo *MacroII) const { | |||
4231 | QualType Canon = UnderlyingTy; | |||
4232 | if (!Canon.isCanonical()) | |||
4233 | Canon = getCanonicalType(UnderlyingTy); | |||
4234 | ||||
4235 | auto *newType = new (*this, TypeAlignment) | |||
4236 | MacroQualifiedType(UnderlyingTy, Canon, MacroII); | |||
4237 | Types.push_back(newType); | |||
4238 | return QualType(newType, 0); | |||
4239 | } | |||
4240 | ||||
4241 | QualType ASTContext::getDependentNameType(ElaboratedTypeKeyword Keyword, | |||
4242 | NestedNameSpecifier *NNS, | |||
4243 | const IdentifierInfo *Name, | |||
4244 | QualType Canon) const { | |||
4245 | if (Canon.isNull()) { | |||
4246 | NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); | |||
4247 | if (CanonNNS != NNS) | |||
4248 | Canon = getDependentNameType(Keyword, CanonNNS, Name); | |||
4249 | } | |||
4250 | ||||
4251 | llvm::FoldingSetNodeID ID; | |||
4252 | DependentNameType::Profile(ID, Keyword, NNS, Name); | |||
4253 | ||||
4254 | void *InsertPos = nullptr; | |||
4255 | DependentNameType *T | |||
4256 | = DependentNameTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4257 | if (T) | |||
4258 | return QualType(T, 0); | |||
4259 | ||||
4260 | T = new (*this, TypeAlignment) DependentNameType(Keyword, NNS, Name, Canon); | |||
4261 | Types.push_back(T); | |||
4262 | DependentNameTypes.InsertNode(T, InsertPos); | |||
4263 | return QualType(T, 0); | |||
4264 | } | |||
4265 | ||||
4266 | QualType | |||
4267 | ASTContext::getDependentTemplateSpecializationType( | |||
4268 | ElaboratedTypeKeyword Keyword, | |||
4269 | NestedNameSpecifier *NNS, | |||
4270 | const IdentifierInfo *Name, | |||
4271 | const TemplateArgumentListInfo &Args) const { | |||
4272 | // TODO: avoid this copy | |||
4273 | SmallVector<TemplateArgument, 16> ArgCopy; | |||
4274 | for (unsigned I = 0, E = Args.size(); I != E; ++I) | |||
4275 | ArgCopy.push_back(Args[I].getArgument()); | |||
4276 | return getDependentTemplateSpecializationType(Keyword, NNS, Name, ArgCopy); | |||
4277 | } | |||
4278 | ||||
4279 | QualType | |||
4280 | ASTContext::getDependentTemplateSpecializationType( | |||
4281 | ElaboratedTypeKeyword Keyword, | |||
4282 | NestedNameSpecifier *NNS, | |||
4283 | const IdentifierInfo *Name, | |||
4284 | ArrayRef<TemplateArgument> Args) const { | |||
4285 | assert((!NNS || NNS->isDependent()) &&(((!NNS || NNS->isDependent()) && "nested-name-specifier must be dependent" ) ? static_cast<void> (0) : __assert_fail ("(!NNS || NNS->isDependent()) && \"nested-name-specifier must be dependent\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4286, __PRETTY_FUNCTION__)) | |||
4286 | "nested-name-specifier must be dependent")(((!NNS || NNS->isDependent()) && "nested-name-specifier must be dependent" ) ? static_cast<void> (0) : __assert_fail ("(!NNS || NNS->isDependent()) && \"nested-name-specifier must be dependent\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4286, __PRETTY_FUNCTION__)); | |||
4287 | ||||
4288 | llvm::FoldingSetNodeID ID; | |||
4289 | DependentTemplateSpecializationType::Profile(ID, *this, Keyword, NNS, | |||
4290 | Name, Args); | |||
4291 | ||||
4292 | void *InsertPos = nullptr; | |||
4293 | DependentTemplateSpecializationType *T | |||
4294 | = DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4295 | if (T) | |||
4296 | return QualType(T, 0); | |||
4297 | ||||
4298 | NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); | |||
4299 | ||||
4300 | ElaboratedTypeKeyword CanonKeyword = Keyword; | |||
4301 | if (Keyword == ETK_None) CanonKeyword = ETK_Typename; | |||
4302 | ||||
4303 | bool AnyNonCanonArgs = false; | |||
4304 | unsigned NumArgs = Args.size(); | |||
4305 | SmallVector<TemplateArgument, 16> CanonArgs(NumArgs); | |||
4306 | for (unsigned I = 0; I != NumArgs; ++I) { | |||
4307 | CanonArgs[I] = getCanonicalTemplateArgument(Args[I]); | |||
4308 | if (!CanonArgs[I].structurallyEquals(Args[I])) | |||
4309 | AnyNonCanonArgs = true; | |||
4310 | } | |||
4311 | ||||
4312 | QualType Canon; | |||
4313 | if (AnyNonCanonArgs || CanonNNS != NNS || CanonKeyword != Keyword) { | |||
4314 | Canon = getDependentTemplateSpecializationType(CanonKeyword, CanonNNS, | |||
4315 | Name, | |||
4316 | CanonArgs); | |||
4317 | ||||
4318 | // Find the insert position again. | |||
4319 | DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4320 | } | |||
4321 | ||||
4322 | void *Mem = Allocate((sizeof(DependentTemplateSpecializationType) + | |||
4323 | sizeof(TemplateArgument) * NumArgs), | |||
4324 | TypeAlignment); | |||
4325 | T = new (Mem) DependentTemplateSpecializationType(Keyword, NNS, | |||
4326 | Name, Args, Canon); | |||
4327 | Types.push_back(T); | |||
4328 | DependentTemplateSpecializationTypes.InsertNode(T, InsertPos); | |||
4329 | return QualType(T, 0); | |||
4330 | } | |||
4331 | ||||
4332 | TemplateArgument ASTContext::getInjectedTemplateArg(NamedDecl *Param) { | |||
4333 | TemplateArgument Arg; | |||
4334 | if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) { | |||
4335 | QualType ArgType = getTypeDeclType(TTP); | |||
4336 | if (TTP->isParameterPack()) | |||
4337 | ArgType = getPackExpansionType(ArgType, None); | |||
4338 | ||||
4339 | Arg = TemplateArgument(ArgType); | |||
4340 | } else if (auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) { | |||
4341 | Expr *E = new (*this) DeclRefExpr( | |||
4342 | *this, NTTP, /*enclosing*/ false, | |||
4343 | NTTP->getType().getNonLValueExprType(*this), | |||
4344 | Expr::getValueKindForType(NTTP->getType()), NTTP->getLocation()); | |||
4345 | ||||
4346 | if (NTTP->isParameterPack()) | |||
4347 | E = new (*this) PackExpansionExpr(DependentTy, E, NTTP->getLocation(), | |||
4348 | None); | |||
4349 | Arg = TemplateArgument(E); | |||
4350 | } else { | |||
4351 | auto *TTP = cast<TemplateTemplateParmDecl>(Param); | |||
4352 | if (TTP->isParameterPack()) | |||
4353 | Arg = TemplateArgument(TemplateName(TTP), Optional<unsigned>()); | |||
4354 | else | |||
4355 | Arg = TemplateArgument(TemplateName(TTP)); | |||
4356 | } | |||
4357 | ||||
4358 | if (Param->isTemplateParameterPack()) | |||
4359 | Arg = TemplateArgument::CreatePackCopy(*this, Arg); | |||
4360 | ||||
4361 | return Arg; | |||
4362 | } | |||
4363 | ||||
4364 | void | |||
4365 | ASTContext::getInjectedTemplateArgs(const TemplateParameterList *Params, | |||
4366 | SmallVectorImpl<TemplateArgument> &Args) { | |||
4367 | Args.reserve(Args.size() + Params->size()); | |||
4368 | ||||
4369 | for (NamedDecl *Param : *Params) | |||
4370 | Args.push_back(getInjectedTemplateArg(Param)); | |||
4371 | } | |||
4372 | ||||
4373 | QualType ASTContext::getPackExpansionType(QualType Pattern, | |||
4374 | Optional<unsigned> NumExpansions) { | |||
4375 | llvm::FoldingSetNodeID ID; | |||
4376 | PackExpansionType::Profile(ID, Pattern, NumExpansions); | |||
4377 | ||||
4378 | // A deduced type can deduce to a pack, eg | |||
4379 | // auto ...x = some_pack; | |||
4380 | // That declaration isn't (yet) valid, but is created as part of building an | |||
4381 | // init-capture pack: | |||
4382 | // [...x = some_pack] {} | |||
4383 | assert((Pattern->containsUnexpandedParameterPack() ||(((Pattern->containsUnexpandedParameterPack() || Pattern-> getContainedDeducedType()) && "Pack expansions must expand one or more parameter packs" ) ? static_cast<void> (0) : __assert_fail ("(Pattern->containsUnexpandedParameterPack() || Pattern->getContainedDeducedType()) && \"Pack expansions must expand one or more parameter packs\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4385, __PRETTY_FUNCTION__)) | |||
4384 | Pattern->getContainedDeducedType()) &&(((Pattern->containsUnexpandedParameterPack() || Pattern-> getContainedDeducedType()) && "Pack expansions must expand one or more parameter packs" ) ? static_cast<void> (0) : __assert_fail ("(Pattern->containsUnexpandedParameterPack() || Pattern->getContainedDeducedType()) && \"Pack expansions must expand one or more parameter packs\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4385, __PRETTY_FUNCTION__)) | |||
4385 | "Pack expansions must expand one or more parameter packs")(((Pattern->containsUnexpandedParameterPack() || Pattern-> getContainedDeducedType()) && "Pack expansions must expand one or more parameter packs" ) ? static_cast<void> (0) : __assert_fail ("(Pattern->containsUnexpandedParameterPack() || Pattern->getContainedDeducedType()) && \"Pack expansions must expand one or more parameter packs\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4385, __PRETTY_FUNCTION__)); | |||
4386 | void *InsertPos = nullptr; | |||
4387 | PackExpansionType *T | |||
4388 | = PackExpansionTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4389 | if (T) | |||
4390 | return QualType(T, 0); | |||
4391 | ||||
4392 | QualType Canon; | |||
4393 | if (!Pattern.isCanonical()) { | |||
4394 | Canon = getCanonicalType(Pattern); | |||
4395 | // The canonical type might not contain an unexpanded parameter pack, if it | |||
4396 | // contains an alias template specialization which ignores one of its | |||
4397 | // parameters. | |||
4398 | if (Canon->containsUnexpandedParameterPack()) { | |||
4399 | Canon = getPackExpansionType(Canon, NumExpansions); | |||
4400 | ||||
4401 | // Find the insert position again, in case we inserted an element into | |||
4402 | // PackExpansionTypes and invalidated our insert position. | |||
4403 | PackExpansionTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4404 | } | |||
4405 | } | |||
4406 | ||||
4407 | T = new (*this, TypeAlignment) | |||
4408 | PackExpansionType(Pattern, Canon, NumExpansions); | |||
4409 | Types.push_back(T); | |||
4410 | PackExpansionTypes.InsertNode(T, InsertPos); | |||
4411 | return QualType(T, 0); | |||
4412 | } | |||
4413 | ||||
4414 | /// CmpProtocolNames - Comparison predicate for sorting protocols | |||
4415 | /// alphabetically. | |||
4416 | static int CmpProtocolNames(ObjCProtocolDecl *const *LHS, | |||
4417 | ObjCProtocolDecl *const *RHS) { | |||
4418 | return DeclarationName::compare((*LHS)->getDeclName(), (*RHS)->getDeclName()); | |||
4419 | } | |||
4420 | ||||
4421 | static bool areSortedAndUniqued(ArrayRef<ObjCProtocolDecl *> Protocols) { | |||
4422 | if (Protocols.empty()) return true; | |||
4423 | ||||
4424 | if (Protocols[0]->getCanonicalDecl() != Protocols[0]) | |||
4425 | return false; | |||
4426 | ||||
4427 | for (unsigned i = 1; i != Protocols.size(); ++i) | |||
4428 | if (CmpProtocolNames(&Protocols[i - 1], &Protocols[i]) >= 0 || | |||
4429 | Protocols[i]->getCanonicalDecl() != Protocols[i]) | |||
4430 | return false; | |||
4431 | return true; | |||
4432 | } | |||
4433 | ||||
4434 | static void | |||
4435 | SortAndUniqueProtocols(SmallVectorImpl<ObjCProtocolDecl *> &Protocols) { | |||
4436 | // Sort protocols, keyed by name. | |||
4437 | llvm::array_pod_sort(Protocols.begin(), Protocols.end(), CmpProtocolNames); | |||
4438 | ||||
4439 | // Canonicalize. | |||
4440 | for (ObjCProtocolDecl *&P : Protocols) | |||
4441 | P = P->getCanonicalDecl(); | |||
4442 | ||||
4443 | // Remove duplicates. | |||
4444 | auto ProtocolsEnd = std::unique(Protocols.begin(), Protocols.end()); | |||
4445 | Protocols.erase(ProtocolsEnd, Protocols.end()); | |||
4446 | } | |||
4447 | ||||
4448 | QualType ASTContext::getObjCObjectType(QualType BaseType, | |||
4449 | ObjCProtocolDecl * const *Protocols, | |||
4450 | unsigned NumProtocols) const { | |||
4451 | return getObjCObjectType(BaseType, {}, | |||
4452 | llvm::makeArrayRef(Protocols, NumProtocols), | |||
4453 | /*isKindOf=*/false); | |||
4454 | } | |||
4455 | ||||
4456 | QualType ASTContext::getObjCObjectType( | |||
4457 | QualType baseType, | |||
4458 | ArrayRef<QualType> typeArgs, | |||
4459 | ArrayRef<ObjCProtocolDecl *> protocols, | |||
4460 | bool isKindOf) const { | |||
4461 | // If the base type is an interface and there aren't any protocols or | |||
4462 | // type arguments to add, then the interface type will do just fine. | |||
4463 | if (typeArgs.empty() && protocols.empty() && !isKindOf && | |||
4464 | isa<ObjCInterfaceType>(baseType)) | |||
4465 | return baseType; | |||
4466 | ||||
4467 | // Look in the folding set for an existing type. | |||
4468 | llvm::FoldingSetNodeID ID; | |||
4469 | ObjCObjectTypeImpl::Profile(ID, baseType, typeArgs, protocols, isKindOf); | |||
4470 | void *InsertPos = nullptr; | |||
4471 | if (ObjCObjectType *QT = ObjCObjectTypes.FindNodeOrInsertPos(ID, InsertPos)) | |||
4472 | return QualType(QT, 0); | |||
4473 | ||||
4474 | // Determine the type arguments to be used for canonicalization, | |||
4475 | // which may be explicitly specified here or written on the base | |||
4476 | // type. | |||
4477 | ArrayRef<QualType> effectiveTypeArgs = typeArgs; | |||
4478 | if (effectiveTypeArgs.empty()) { | |||
4479 | if (const auto *baseObject = baseType->getAs<ObjCObjectType>()) | |||
4480 | effectiveTypeArgs = baseObject->getTypeArgs(); | |||
4481 | } | |||
4482 | ||||
4483 | // Build the canonical type, which has the canonical base type and a | |||
4484 | // sorted-and-uniqued list of protocols and the type arguments | |||
4485 | // canonicalized. | |||
4486 | QualType canonical; | |||
4487 | bool typeArgsAreCanonical = std::all_of(effectiveTypeArgs.begin(), | |||
4488 | effectiveTypeArgs.end(), | |||
4489 | [&](QualType type) { | |||
4490 | return type.isCanonical(); | |||
4491 | }); | |||
4492 | bool protocolsSorted = areSortedAndUniqued(protocols); | |||
4493 | if (!typeArgsAreCanonical || !protocolsSorted || !baseType.isCanonical()) { | |||
4494 | // Determine the canonical type arguments. | |||
4495 | ArrayRef<QualType> canonTypeArgs; | |||
4496 | SmallVector<QualType, 4> canonTypeArgsVec; | |||
4497 | if (!typeArgsAreCanonical) { | |||
4498 | canonTypeArgsVec.reserve(effectiveTypeArgs.size()); | |||
4499 | for (auto typeArg : effectiveTypeArgs) | |||
4500 | canonTypeArgsVec.push_back(getCanonicalType(typeArg)); | |||
4501 | canonTypeArgs = canonTypeArgsVec; | |||
4502 | } else { | |||
4503 | canonTypeArgs = effectiveTypeArgs; | |||
4504 | } | |||
4505 | ||||
4506 | ArrayRef<ObjCProtocolDecl *> canonProtocols; | |||
4507 | SmallVector<ObjCProtocolDecl*, 8> canonProtocolsVec; | |||
4508 | if (!protocolsSorted) { | |||
4509 | canonProtocolsVec.append(protocols.begin(), protocols.end()); | |||
4510 | SortAndUniqueProtocols(canonProtocolsVec); | |||
4511 | canonProtocols = canonProtocolsVec; | |||
4512 | } else { | |||
4513 | canonProtocols = protocols; | |||
4514 | } | |||
4515 | ||||
4516 | canonical = getObjCObjectType(getCanonicalType(baseType), canonTypeArgs, | |||
4517 | canonProtocols, isKindOf); | |||
4518 | ||||
4519 | // Regenerate InsertPos. | |||
4520 | ObjCObjectTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4521 | } | |||
4522 | ||||
4523 | unsigned size = sizeof(ObjCObjectTypeImpl); | |||
4524 | size += typeArgs.size() * sizeof(QualType); | |||
4525 | size += protocols.size() * sizeof(ObjCProtocolDecl *); | |||
4526 | void *mem = Allocate(size, TypeAlignment); | |||
4527 | auto *T = | |||
4528 | new (mem) ObjCObjectTypeImpl(canonical, baseType, typeArgs, protocols, | |||
4529 | isKindOf); | |||
4530 | ||||
4531 | Types.push_back(T); | |||
4532 | ObjCObjectTypes.InsertNode(T, InsertPos); | |||
4533 | return QualType(T, 0); | |||
4534 | } | |||
4535 | ||||
4536 | /// Apply Objective-C protocol qualifiers to the given type. | |||
4537 | /// If this is for the canonical type of a type parameter, we can apply | |||
4538 | /// protocol qualifiers on the ObjCObjectPointerType. | |||
4539 | QualType | |||
4540 | ASTContext::applyObjCProtocolQualifiers(QualType type, | |||
4541 | ArrayRef<ObjCProtocolDecl *> protocols, bool &hasError, | |||
4542 | bool allowOnPointerType) const { | |||
4543 | hasError = false; | |||
4544 | ||||
4545 | if (const auto *objT = dyn_cast<ObjCTypeParamType>(type.getTypePtr())) { | |||
4546 | return getObjCTypeParamType(objT->getDecl(), protocols); | |||
4547 | } | |||
4548 | ||||
4549 | // Apply protocol qualifiers to ObjCObjectPointerType. | |||
4550 | if (allowOnPointerType) { | |||
4551 | if (const auto *objPtr = | |||
4552 | dyn_cast<ObjCObjectPointerType>(type.getTypePtr())) { | |||
4553 | const ObjCObjectType *objT = objPtr->getObjectType(); | |||
4554 | // Merge protocol lists and construct ObjCObjectType. | |||
4555 | SmallVector<ObjCProtocolDecl*, 8> protocolsVec; | |||
4556 | protocolsVec.append(objT->qual_begin(), | |||
4557 | objT->qual_end()); | |||
4558 | protocolsVec.append(protocols.begin(), protocols.end()); | |||
4559 | ArrayRef<ObjCProtocolDecl *> protocols = protocolsVec; | |||
4560 | type = getObjCObjectType( | |||
4561 | objT->getBaseType(), | |||
4562 | objT->getTypeArgsAsWritten(), | |||
4563 | protocols, | |||
4564 | objT->isKindOfTypeAsWritten()); | |||
4565 | return getObjCObjectPointerType(type); | |||
4566 | } | |||
4567 | } | |||
4568 | ||||
4569 | // Apply protocol qualifiers to ObjCObjectType. | |||
4570 | if (const auto *objT = dyn_cast<ObjCObjectType>(type.getTypePtr())){ | |||
4571 | // FIXME: Check for protocols to which the class type is already | |||
4572 | // known to conform. | |||
4573 | ||||
4574 | return getObjCObjectType(objT->getBaseType(), | |||
4575 | objT->getTypeArgsAsWritten(), | |||
4576 | protocols, | |||
4577 | objT->isKindOfTypeAsWritten()); | |||
4578 | } | |||
4579 | ||||
4580 | // If the canonical type is ObjCObjectType, ... | |||
4581 | if (type->isObjCObjectType()) { | |||
4582 | // Silently overwrite any existing protocol qualifiers. | |||
4583 | // TODO: determine whether that's the right thing to do. | |||
4584 | ||||
4585 | // FIXME: Check for protocols to which the class type is already | |||
4586 | // known to conform. | |||
4587 | return getObjCObjectType(type, {}, protocols, false); | |||
4588 | } | |||
4589 | ||||
4590 | // id<protocol-list> | |||
4591 | if (type->isObjCIdType()) { | |||
4592 | const auto *objPtr = type->castAs<ObjCObjectPointerType>(); | |||
4593 | type = getObjCObjectType(ObjCBuiltinIdTy, {}, protocols, | |||
4594 | objPtr->isKindOfType()); | |||
4595 | return getObjCObjectPointerType(type); | |||
4596 | } | |||
4597 | ||||
4598 | // Class<protocol-list> | |||
4599 | if (type->isObjCClassType()) { | |||
4600 | const auto *objPtr = type->castAs<ObjCObjectPointerType>(); | |||
4601 | type = getObjCObjectType(ObjCBuiltinClassTy, {}, protocols, | |||
4602 | objPtr->isKindOfType()); | |||
4603 | return getObjCObjectPointerType(type); | |||
4604 | } | |||
4605 | ||||
4606 | hasError = true; | |||
4607 | return type; | |||
4608 | } | |||
4609 | ||||
4610 | QualType | |||
4611 | ASTContext::getObjCTypeParamType(const ObjCTypeParamDecl *Decl, | |||
4612 | ArrayRef<ObjCProtocolDecl *> protocols, | |||
4613 | QualType Canonical) const { | |||
4614 | // Look in the folding set for an existing type. | |||
4615 | llvm::FoldingSetNodeID ID; | |||
4616 | ObjCTypeParamType::Profile(ID, Decl, protocols); | |||
4617 | void *InsertPos = nullptr; | |||
4618 | if (ObjCTypeParamType *TypeParam = | |||
4619 | ObjCTypeParamTypes.FindNodeOrInsertPos(ID, InsertPos)) | |||
4620 | return QualType(TypeParam, 0); | |||
4621 | ||||
4622 | if (Canonical.isNull()) { | |||
4623 | // We canonicalize to the underlying type. | |||
4624 | Canonical = getCanonicalType(Decl->getUnderlyingType()); | |||
4625 | if (!protocols.empty()) { | |||
4626 | // Apply the protocol qualifers. | |||
4627 | bool hasError; | |||
4628 | Canonical = getCanonicalType(applyObjCProtocolQualifiers( | |||
4629 | Canonical, protocols, hasError, true /*allowOnPointerType*/)); | |||
4630 | assert(!hasError && "Error when apply protocol qualifier to bound type")((!hasError && "Error when apply protocol qualifier to bound type" ) ? static_cast<void> (0) : __assert_fail ("!hasError && \"Error when apply protocol qualifier to bound type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4630, __PRETTY_FUNCTION__)); | |||
4631 | } | |||
4632 | } | |||
4633 | ||||
4634 | unsigned size = sizeof(ObjCTypeParamType); | |||
4635 | size += protocols.size() * sizeof(ObjCProtocolDecl *); | |||
4636 | void *mem = Allocate(size, TypeAlignment); | |||
4637 | auto *newType = new (mem) ObjCTypeParamType(Decl, Canonical, protocols); | |||
4638 | ||||
4639 | Types.push_back(newType); | |||
4640 | ObjCTypeParamTypes.InsertNode(newType, InsertPos); | |||
4641 | return QualType(newType, 0); | |||
4642 | } | |||
4643 | ||||
4644 | /// ObjCObjectAdoptsQTypeProtocols - Checks that protocols in IC's | |||
4645 | /// protocol list adopt all protocols in QT's qualified-id protocol | |||
4646 | /// list. | |||
4647 | bool ASTContext::ObjCObjectAdoptsQTypeProtocols(QualType QT, | |||
4648 | ObjCInterfaceDecl *IC) { | |||
4649 | if (!QT->isObjCQualifiedIdType()) | |||
4650 | return false; | |||
4651 | ||||
4652 | if (const auto *OPT = QT->getAs<ObjCObjectPointerType>()) { | |||
4653 | // If both the right and left sides have qualifiers. | |||
4654 | for (auto *Proto : OPT->quals()) { | |||
4655 | if (!IC->ClassImplementsProtocol(Proto, false)) | |||
4656 | return false; | |||
4657 | } | |||
4658 | return true; | |||
4659 | } | |||
4660 | return false; | |||
4661 | } | |||
4662 | ||||
4663 | /// QIdProtocolsAdoptObjCObjectProtocols - Checks that protocols in | |||
4664 | /// QT's qualified-id protocol list adopt all protocols in IDecl's list | |||
4665 | /// of protocols. | |||
4666 | bool ASTContext::QIdProtocolsAdoptObjCObjectProtocols(QualType QT, | |||
4667 | ObjCInterfaceDecl *IDecl) { | |||
4668 | if (!QT->isObjCQualifiedIdType()) | |||
4669 | return false; | |||
4670 | const auto *OPT = QT->getAs<ObjCObjectPointerType>(); | |||
4671 | if (!OPT) | |||
4672 | return false; | |||
4673 | if (!IDecl->hasDefinition()) | |||
4674 | return false; | |||
4675 | llvm::SmallPtrSet<ObjCProtocolDecl *, 8> InheritedProtocols; | |||
4676 | CollectInheritedProtocols(IDecl, InheritedProtocols); | |||
4677 | if (InheritedProtocols.empty()) | |||
4678 | return false; | |||
4679 | // Check that if every protocol in list of id<plist> conforms to a protocol | |||
4680 | // of IDecl's, then bridge casting is ok. | |||
4681 | bool Conforms = false; | |||
4682 | for (auto *Proto : OPT->quals()) { | |||
4683 | Conforms = false; | |||
4684 | for (auto *PI : InheritedProtocols) { | |||
4685 | if (ProtocolCompatibleWithProtocol(Proto, PI)) { | |||
4686 | Conforms = true; | |||
4687 | break; | |||
4688 | } | |||
4689 | } | |||
4690 | if (!Conforms) | |||
4691 | break; | |||
4692 | } | |||
4693 | if (Conforms) | |||
4694 | return true; | |||
4695 | ||||
4696 | for (auto *PI : InheritedProtocols) { | |||
4697 | // If both the right and left sides have qualifiers. | |||
4698 | bool Adopts = false; | |||
4699 | for (auto *Proto : OPT->quals()) { | |||
4700 | // return 'true' if 'PI' is in the inheritance hierarchy of Proto | |||
4701 | if ((Adopts = ProtocolCompatibleWithProtocol(PI, Proto))) | |||
4702 | break; | |||
4703 | } | |||
4704 | if (!Adopts) | |||
4705 | return false; | |||
4706 | } | |||
4707 | return true; | |||
4708 | } | |||
4709 | ||||
4710 | /// getObjCObjectPointerType - Return a ObjCObjectPointerType type for | |||
4711 | /// the given object type. | |||
4712 | QualType ASTContext::getObjCObjectPointerType(QualType ObjectT) const { | |||
4713 | llvm::FoldingSetNodeID ID; | |||
4714 | ObjCObjectPointerType::Profile(ID, ObjectT); | |||
4715 | ||||
4716 | void *InsertPos = nullptr; | |||
4717 | if (ObjCObjectPointerType *QT = | |||
4718 | ObjCObjectPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) | |||
4719 | return QualType(QT, 0); | |||
4720 | ||||
4721 | // Find the canonical object type. | |||
4722 | QualType Canonical; | |||
4723 | if (!ObjectT.isCanonical()) { | |||
4724 | Canonical = getObjCObjectPointerType(getCanonicalType(ObjectT)); | |||
4725 | ||||
4726 | // Regenerate InsertPos. | |||
4727 | ObjCObjectPointerTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4728 | } | |||
4729 | ||||
4730 | // No match. | |||
4731 | void *Mem = Allocate(sizeof(ObjCObjectPointerType), TypeAlignment); | |||
4732 | auto *QType = | |||
4733 | new (Mem) ObjCObjectPointerType(Canonical, ObjectT); | |||
4734 | ||||
4735 | Types.push_back(QType); | |||
4736 | ObjCObjectPointerTypes.InsertNode(QType, InsertPos); | |||
4737 | return QualType(QType, 0); | |||
4738 | } | |||
4739 | ||||
4740 | /// getObjCInterfaceType - Return the unique reference to the type for the | |||
4741 | /// specified ObjC interface decl. The list of protocols is optional. | |||
4742 | QualType ASTContext::getObjCInterfaceType(const ObjCInterfaceDecl *Decl, | |||
4743 | ObjCInterfaceDecl *PrevDecl) const { | |||
4744 | if (Decl->TypeForDecl) | |||
4745 | return QualType(Decl->TypeForDecl, 0); | |||
4746 | ||||
4747 | if (PrevDecl) { | |||
4748 | assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl")((PrevDecl->TypeForDecl && "previous decl has no TypeForDecl" ) ? static_cast<void> (0) : __assert_fail ("PrevDecl->TypeForDecl && \"previous decl has no TypeForDecl\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4748, __PRETTY_FUNCTION__)); | |||
4749 | Decl->TypeForDecl = PrevDecl->TypeForDecl; | |||
4750 | return QualType(PrevDecl->TypeForDecl, 0); | |||
4751 | } | |||
4752 | ||||
4753 | // Prefer the definition, if there is one. | |||
4754 | if (const ObjCInterfaceDecl *Def = Decl->getDefinition()) | |||
4755 | Decl = Def; | |||
4756 | ||||
4757 | void *Mem = Allocate(sizeof(ObjCInterfaceType), TypeAlignment); | |||
4758 | auto *T = new (Mem) ObjCInterfaceType(Decl); | |||
4759 | Decl->TypeForDecl = T; | |||
4760 | Types.push_back(T); | |||
4761 | return QualType(T, 0); | |||
4762 | } | |||
4763 | ||||
4764 | /// getTypeOfExprType - Unlike many "get<Type>" functions, we can't unique | |||
4765 | /// TypeOfExprType AST's (since expression's are never shared). For example, | |||
4766 | /// multiple declarations that refer to "typeof(x)" all contain different | |||
4767 | /// DeclRefExpr's. This doesn't effect the type checker, since it operates | |||
4768 | /// on canonical type's (which are always unique). | |||
4769 | QualType ASTContext::getTypeOfExprType(Expr *tofExpr) const { | |||
4770 | TypeOfExprType *toe; | |||
4771 | if (tofExpr->isTypeDependent()) { | |||
4772 | llvm::FoldingSetNodeID ID; | |||
4773 | DependentTypeOfExprType::Profile(ID, *this, tofExpr); | |||
4774 | ||||
4775 | void *InsertPos = nullptr; | |||
4776 | DependentTypeOfExprType *Canon | |||
4777 | = DependentTypeOfExprTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4778 | if (Canon) { | |||
4779 | // We already have a "canonical" version of an identical, dependent | |||
4780 | // typeof(expr) type. Use that as our canonical type. | |||
4781 | toe = new (*this, TypeAlignment) TypeOfExprType(tofExpr, | |||
4782 | QualType((TypeOfExprType*)Canon, 0)); | |||
4783 | } else { | |||
4784 | // Build a new, canonical typeof(expr) type. | |||
4785 | Canon | |||
4786 | = new (*this, TypeAlignment) DependentTypeOfExprType(*this, tofExpr); | |||
4787 | DependentTypeOfExprTypes.InsertNode(Canon, InsertPos); | |||
4788 | toe = Canon; | |||
4789 | } | |||
4790 | } else { | |||
4791 | QualType Canonical = getCanonicalType(tofExpr->getType()); | |||
4792 | toe = new (*this, TypeAlignment) TypeOfExprType(tofExpr, Canonical); | |||
4793 | } | |||
4794 | Types.push_back(toe); | |||
4795 | return QualType(toe, 0); | |||
4796 | } | |||
4797 | ||||
4798 | /// getTypeOfType - Unlike many "get<Type>" functions, we don't unique | |||
4799 | /// TypeOfType nodes. The only motivation to unique these nodes would be | |||
4800 | /// memory savings. Since typeof(t) is fairly uncommon, space shouldn't be | |||
4801 | /// an issue. This doesn't affect the type checker, since it operates | |||
4802 | /// on canonical types (which are always unique). | |||
4803 | QualType ASTContext::getTypeOfType(QualType tofType) const { | |||
4804 | QualType Canonical = getCanonicalType(tofType); | |||
4805 | auto *tot = new (*this, TypeAlignment) TypeOfType(tofType, Canonical); | |||
4806 | Types.push_back(tot); | |||
4807 | return QualType(tot, 0); | |||
4808 | } | |||
4809 | ||||
4810 | /// Unlike many "get<Type>" functions, we don't unique DecltypeType | |||
4811 | /// nodes. This would never be helpful, since each such type has its own | |||
4812 | /// expression, and would not give a significant memory saving, since there | |||
4813 | /// is an Expr tree under each such type. | |||
4814 | QualType ASTContext::getDecltypeType(Expr *e, QualType UnderlyingType) const { | |||
4815 | DecltypeType *dt; | |||
4816 | ||||
4817 | // C++11 [temp.type]p2: | |||
4818 | // If an expression e involves a template parameter, decltype(e) denotes a | |||
4819 | // unique dependent type. Two such decltype-specifiers refer to the same | |||
4820 | // type only if their expressions are equivalent (14.5.6.1). | |||
4821 | if (e->isInstantiationDependent()) { | |||
4822 | llvm::FoldingSetNodeID ID; | |||
4823 | DependentDecltypeType::Profile(ID, *this, e); | |||
4824 | ||||
4825 | void *InsertPos = nullptr; | |||
4826 | DependentDecltypeType *Canon | |||
4827 | = DependentDecltypeTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4828 | if (!Canon) { | |||
4829 | // Build a new, canonical decltype(expr) type. | |||
4830 | Canon = new (*this, TypeAlignment) DependentDecltypeType(*this, e); | |||
4831 | DependentDecltypeTypes.InsertNode(Canon, InsertPos); | |||
4832 | } | |||
4833 | dt = new (*this, TypeAlignment) | |||
4834 | DecltypeType(e, UnderlyingType, QualType((DecltypeType *)Canon, 0)); | |||
4835 | } else { | |||
4836 | dt = new (*this, TypeAlignment) | |||
4837 | DecltypeType(e, UnderlyingType, getCanonicalType(UnderlyingType)); | |||
4838 | } | |||
4839 | Types.push_back(dt); | |||
4840 | return QualType(dt, 0); | |||
4841 | } | |||
4842 | ||||
4843 | /// getUnaryTransformationType - We don't unique these, since the memory | |||
4844 | /// savings are minimal and these are rare. | |||
4845 | QualType ASTContext::getUnaryTransformType(QualType BaseType, | |||
4846 | QualType UnderlyingType, | |||
4847 | UnaryTransformType::UTTKind Kind) | |||
4848 | const { | |||
4849 | UnaryTransformType *ut = nullptr; | |||
4850 | ||||
4851 | if (BaseType->isDependentType()) { | |||
4852 | // Look in the folding set for an existing type. | |||
4853 | llvm::FoldingSetNodeID ID; | |||
4854 | DependentUnaryTransformType::Profile(ID, getCanonicalType(BaseType), Kind); | |||
4855 | ||||
4856 | void *InsertPos = nullptr; | |||
4857 | DependentUnaryTransformType *Canon | |||
4858 | = DependentUnaryTransformTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4859 | ||||
4860 | if (!Canon) { | |||
4861 | // Build a new, canonical __underlying_type(type) type. | |||
4862 | Canon = new (*this, TypeAlignment) | |||
4863 | DependentUnaryTransformType(*this, getCanonicalType(BaseType), | |||
4864 | Kind); | |||
4865 | DependentUnaryTransformTypes.InsertNode(Canon, InsertPos); | |||
4866 | } | |||
4867 | ut = new (*this, TypeAlignment) UnaryTransformType (BaseType, | |||
4868 | QualType(), Kind, | |||
4869 | QualType(Canon, 0)); | |||
4870 | } else { | |||
4871 | QualType CanonType = getCanonicalType(UnderlyingType); | |||
4872 | ut = new (*this, TypeAlignment) UnaryTransformType (BaseType, | |||
4873 | UnderlyingType, Kind, | |||
4874 | CanonType); | |||
4875 | } | |||
4876 | Types.push_back(ut); | |||
4877 | return QualType(ut, 0); | |||
4878 | } | |||
4879 | ||||
4880 | /// getAutoType - Return the uniqued reference to the 'auto' type which has been | |||
4881 | /// deduced to the given type, or to the canonical undeduced 'auto' type, or the | |||
4882 | /// canonical deduced-but-dependent 'auto' type. | |||
4883 | QualType ASTContext::getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, | |||
4884 | bool IsDependent, bool IsPack) const { | |||
4885 | assert((!IsPack || IsDependent) && "only use IsPack for a dependent pack")(((!IsPack || IsDependent) && "only use IsPack for a dependent pack" ) ? static_cast<void> (0) : __assert_fail ("(!IsPack || IsDependent) && \"only use IsPack for a dependent pack\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4885, __PRETTY_FUNCTION__)); | |||
4886 | if (DeducedType.isNull() && Keyword == AutoTypeKeyword::Auto && !IsDependent) | |||
4887 | return getAutoDeductType(); | |||
4888 | ||||
4889 | // Look in the folding set for an existing type. | |||
4890 | void *InsertPos = nullptr; | |||
4891 | llvm::FoldingSetNodeID ID; | |||
4892 | AutoType::Profile(ID, DeducedType, Keyword, IsDependent, IsPack); | |||
4893 | if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos)) | |||
4894 | return QualType(AT, 0); | |||
4895 | ||||
4896 | auto *AT = new (*this, TypeAlignment) | |||
4897 | AutoType(DeducedType, Keyword, IsDependent, IsPack); | |||
4898 | Types.push_back(AT); | |||
4899 | if (InsertPos) | |||
4900 | AutoTypes.InsertNode(AT, InsertPos); | |||
4901 | return QualType(AT, 0); | |||
4902 | } | |||
4903 | ||||
4904 | /// Return the uniqued reference to the deduced template specialization type | |||
4905 | /// which has been deduced to the given type, or to the canonical undeduced | |||
4906 | /// such type, or the canonical deduced-but-dependent such type. | |||
4907 | QualType ASTContext::getDeducedTemplateSpecializationType( | |||
4908 | TemplateName Template, QualType DeducedType, bool IsDependent) const { | |||
4909 | // Look in the folding set for an existing type. | |||
4910 | void *InsertPos = nullptr; | |||
4911 | llvm::FoldingSetNodeID ID; | |||
4912 | DeducedTemplateSpecializationType::Profile(ID, Template, DeducedType, | |||
4913 | IsDependent); | |||
4914 | if (DeducedTemplateSpecializationType *DTST = | |||
4915 | DeducedTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos)) | |||
4916 | return QualType(DTST, 0); | |||
4917 | ||||
4918 | auto *DTST = new (*this, TypeAlignment) | |||
4919 | DeducedTemplateSpecializationType(Template, DeducedType, IsDependent); | |||
4920 | Types.push_back(DTST); | |||
4921 | if (InsertPos) | |||
4922 | DeducedTemplateSpecializationTypes.InsertNode(DTST, InsertPos); | |||
4923 | return QualType(DTST, 0); | |||
4924 | } | |||
4925 | ||||
4926 | /// getAtomicType - Return the uniqued reference to the atomic type for | |||
4927 | /// the given value type. | |||
4928 | QualType ASTContext::getAtomicType(QualType T) const { | |||
4929 | // Unique pointers, to guarantee there is only one pointer of a particular | |||
4930 | // structure. | |||
4931 | llvm::FoldingSetNodeID ID; | |||
4932 | AtomicType::Profile(ID, T); | |||
4933 | ||||
4934 | void *InsertPos = nullptr; | |||
4935 | if (AtomicType *AT = AtomicTypes.FindNodeOrInsertPos(ID, InsertPos)) | |||
4936 | return QualType(AT, 0); | |||
4937 | ||||
4938 | // If the atomic value type isn't canonical, this won't be a canonical type | |||
4939 | // either, so fill in the canonical type field. | |||
4940 | QualType Canonical; | |||
4941 | if (!T.isCanonical()) { | |||
4942 | Canonical = getAtomicType(getCanonicalType(T)); | |||
4943 | ||||
4944 | // Get the new insert position for the node we care about. | |||
4945 | AtomicType *NewIP = AtomicTypes.FindNodeOrInsertPos(ID, InsertPos); | |||
4946 | assert(!NewIP && "Shouldn't be in the map!")((!NewIP && "Shouldn't be in the map!") ? static_cast <void> (0) : __assert_fail ("!NewIP && \"Shouldn't be in the map!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4946, __PRETTY_FUNCTION__)); (void)NewIP; | |||
4947 | } | |||
4948 | auto *New = new (*this, TypeAlignment) AtomicType(T, Canonical); | |||
4949 | Types.push_back(New); | |||
4950 | AtomicTypes.InsertNode(New, InsertPos); | |||
4951 | return QualType(New, 0); | |||
4952 | } | |||
4953 | ||||
4954 | /// getAutoDeductType - Get type pattern for deducing against 'auto'. | |||
4955 | QualType ASTContext::getAutoDeductType() const { | |||
4956 | if (AutoDeductTy.isNull()) | |||
4957 | AutoDeductTy = QualType( | |||
4958 | new (*this, TypeAlignment) AutoType(QualType(), AutoTypeKeyword::Auto, | |||
4959 | /*dependent*/false, /*pack*/false), | |||
4960 | 0); | |||
4961 | return AutoDeductTy; | |||
4962 | } | |||
4963 | ||||
4964 | /// getAutoRRefDeductType - Get type pattern for deducing against 'auto &&'. | |||
4965 | QualType ASTContext::getAutoRRefDeductType() const { | |||
4966 | if (AutoRRefDeductTy.isNull()) | |||
4967 | AutoRRefDeductTy = getRValueReferenceType(getAutoDeductType()); | |||
4968 | assert(!AutoRRefDeductTy.isNull() && "can't build 'auto &&' pattern")((!AutoRRefDeductTy.isNull() && "can't build 'auto &&' pattern" ) ? static_cast<void> (0) : __assert_fail ("!AutoRRefDeductTy.isNull() && \"can't build 'auto &&' pattern\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4968, __PRETTY_FUNCTION__)); | |||
4969 | return AutoRRefDeductTy; | |||
4970 | } | |||
4971 | ||||
4972 | /// getTagDeclType - Return the unique reference to the type for the | |||
4973 | /// specified TagDecl (struct/union/class/enum) decl. | |||
4974 | QualType ASTContext::getTagDeclType(const TagDecl *Decl) const { | |||
4975 | assert(Decl)((Decl) ? static_cast<void> (0) : __assert_fail ("Decl" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 4975, __PRETTY_FUNCTION__)); | |||
4976 | // FIXME: What is the design on getTagDeclType when it requires casting | |||
4977 | // away const? mutable? | |||
4978 | return getTypeDeclType(const_cast<TagDecl*>(Decl)); | |||
4979 | } | |||
4980 | ||||
4981 | /// getSizeType - Return the unique type for "size_t" (C99 7.17), the result | |||
4982 | /// of the sizeof operator (C99 6.5.3.4p4). The value is target dependent and | |||
4983 | /// needs to agree with the definition in <stddef.h>. | |||
4984 | CanQualType ASTContext::getSizeType() const { | |||
4985 | return getFromTargetType(Target->getSizeType()); | |||
4986 | } | |||
4987 | ||||
4988 | /// Return the unique signed counterpart of the integer type | |||
4989 | /// corresponding to size_t. | |||
4990 | CanQualType ASTContext::getSignedSizeType() const { | |||
4991 | return getFromTargetType(Target->getSignedSizeType()); | |||
4992 | } | |||
4993 | ||||
4994 | /// getIntMaxType - Return the unique type for "intmax_t" (C99 7.18.1.5). | |||
4995 | CanQualType ASTContext::getIntMaxType() const { | |||
4996 | return getFromTargetType(Target->getIntMaxType()); | |||
4997 | } | |||
4998 | ||||
4999 | /// getUIntMaxType - Return the unique type for "uintmax_t" (C99 7.18.1.5). | |||
5000 | CanQualType ASTContext::getUIntMaxType() const { | |||
5001 | return getFromTargetType(Target->getUIntMaxType()); | |||
5002 | } | |||
5003 | ||||
5004 | /// getSignedWCharType - Return the type of "signed wchar_t". | |||
5005 | /// Used when in C++, as a GCC extension. | |||
5006 | QualType ASTContext::getSignedWCharType() const { | |||
5007 | // FIXME: derive from "Target" ? | |||
5008 | return WCharTy; | |||
5009 | } | |||
5010 | ||||
5011 | /// getUnsignedWCharType - Return the type of "unsigned wchar_t". | |||
5012 | /// Used when in C++, as a GCC extension. | |||
5013 | QualType ASTContext::getUnsignedWCharType() const { | |||
5014 | // FIXME: derive from "Target" ? | |||
5015 | return UnsignedIntTy; | |||
5016 | } | |||
5017 | ||||
5018 | QualType ASTContext::getIntPtrType() const { | |||
5019 | return getFromTargetType(Target->getIntPtrType()); | |||
5020 | } | |||
5021 | ||||
5022 | QualType ASTContext::getUIntPtrType() const { | |||
5023 | return getCorrespondingUnsignedType(getIntPtrType()); | |||
5024 | } | |||
5025 | ||||
5026 | /// getPointerDiffType - Return the unique type for "ptrdiff_t" (C99 7.17) | |||
5027 | /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9). | |||
5028 | QualType ASTContext::getPointerDiffType() const { | |||
5029 | return getFromTargetType(Target->getPtrDiffType(0)); | |||
5030 | } | |||
5031 | ||||
5032 | /// Return the unique unsigned counterpart of "ptrdiff_t" | |||
5033 | /// integer type. The standard (C11 7.21.6.1p7) refers to this type | |||
5034 | /// in the definition of %tu format specifier. | |||
5035 | QualType ASTContext::getUnsignedPointerDiffType() const { | |||
5036 | return getFromTargetType(Target->getUnsignedPtrDiffType(0)); | |||
5037 | } | |||
5038 | ||||
5039 | /// Return the unique type for "pid_t" defined in | |||
5040 | /// <sys/types.h>. We need this to compute the correct type for vfork(). | |||
5041 | QualType ASTContext::getProcessIDType() const { | |||
5042 | return getFromTargetType(Target->getProcessIDType()); | |||
5043 | } | |||
5044 | ||||
5045 | //===----------------------------------------------------------------------===// | |||
5046 | // Type Operators | |||
5047 | //===----------------------------------------------------------------------===// | |||
5048 | ||||
5049 | CanQualType ASTContext::getCanonicalParamType(QualType T) const { | |||
5050 | // Push qualifiers into arrays, and then discard any remaining | |||
5051 | // qualifiers. | |||
5052 | T = getCanonicalType(T); | |||
5053 | T = getVariableArrayDecayedType(T); | |||
5054 | const Type *Ty = T.getTypePtr(); | |||
5055 | QualType Result; | |||
5056 | if (isa<ArrayType>(Ty)) { | |||
5057 | Result = getArrayDecayedType(QualType(Ty,0)); | |||
5058 | } else if (isa<FunctionType>(Ty)) { | |||
5059 | Result = getPointerType(QualType(Ty, 0)); | |||
5060 | } else { | |||
5061 | Result = QualType(Ty, 0); | |||
5062 | } | |||
5063 | ||||
5064 | return CanQualType::CreateUnsafe(Result); | |||
5065 | } | |||
5066 | ||||
5067 | QualType ASTContext::getUnqualifiedArrayType(QualType type, | |||
5068 | Qualifiers &quals) { | |||
5069 | SplitQualType splitType = type.getSplitUnqualifiedType(); | |||
5070 | ||||
5071 | // FIXME: getSplitUnqualifiedType() actually walks all the way to | |||
5072 | // the unqualified desugared type and then drops it on the floor. | |||
5073 | // We then have to strip that sugar back off with | |||
5074 | // getUnqualifiedDesugaredType(), which is silly. | |||
5075 | const auto *AT = | |||
5076 | dyn_cast<ArrayType>(splitType.Ty->getUnqualifiedDesugaredType()); | |||
5077 | ||||
5078 | // If we don't have an array, just use the results in splitType. | |||
5079 | if (!AT) { | |||
5080 | quals = splitType.Quals; | |||
5081 | return QualType(splitType.Ty, 0); | |||
5082 | } | |||
5083 | ||||
5084 | // Otherwise, recurse on the array's element type. | |||
5085 | QualType elementType = AT->getElementType(); | |||
5086 | QualType unqualElementType = getUnqualifiedArrayType(elementType, quals); | |||
5087 | ||||
5088 | // If that didn't change the element type, AT has no qualifiers, so we | |||
5089 | // can just use the results in splitType. | |||
5090 | if (elementType == unqualElementType) { | |||
5091 | assert(quals.empty())((quals.empty()) ? static_cast<void> (0) : __assert_fail ("quals.empty()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5091, __PRETTY_FUNCTION__)); // from the recursive call | |||
5092 | quals = splitType.Quals; | |||
5093 | return QualType(splitType.Ty, 0); | |||
5094 | } | |||
5095 | ||||
5096 | // Otherwise, add in the qualifiers from the outermost type, then | |||
5097 | // build the type back up. | |||
5098 | quals.addConsistentQualifiers(splitType.Quals); | |||
5099 | ||||
5100 | if (const auto *CAT = dyn_cast<ConstantArrayType>(AT)) { | |||
5101 | return getConstantArrayType(unqualElementType, CAT->getSize(), | |||
5102 | CAT->getSizeModifier(), 0); | |||
5103 | } | |||
5104 | ||||
5105 | if (const auto *IAT = dyn_cast<IncompleteArrayType>(AT)) { | |||
5106 | return getIncompleteArrayType(unqualElementType, IAT->getSizeModifier(), 0); | |||
5107 | } | |||
5108 | ||||
5109 | if (const auto *VAT = dyn_cast<VariableArrayType>(AT)) { | |||
5110 | return getVariableArrayType(unqualElementType, | |||
5111 | VAT->getSizeExpr(), | |||
5112 | VAT->getSizeModifier(), | |||
5113 | VAT->getIndexTypeCVRQualifiers(), | |||
5114 | VAT->getBracketsRange()); | |||
5115 | } | |||
5116 | ||||
5117 | const auto *DSAT = cast<DependentSizedArrayType>(AT); | |||
5118 | return getDependentSizedArrayType(unqualElementType, DSAT->getSizeExpr(), | |||
5119 | DSAT->getSizeModifier(), 0, | |||
5120 | SourceRange()); | |||
5121 | } | |||
5122 | ||||
5123 | /// Attempt to unwrap two types that may both be array types with the same bound | |||
5124 | /// (or both be array types of unknown bound) for the purpose of comparing the | |||
5125 | /// cv-decomposition of two types per C++ [conv.qual]. | |||
5126 | bool ASTContext::UnwrapSimilarArrayTypes(QualType &T1, QualType &T2) { | |||
5127 | bool UnwrappedAny = false; | |||
5128 | while (true) { | |||
5129 | auto *AT1 = getAsArrayType(T1); | |||
5130 | if (!AT1) return UnwrappedAny; | |||
5131 | ||||
5132 | auto *AT2 = getAsArrayType(T2); | |||
5133 | if (!AT2) return UnwrappedAny; | |||
5134 | ||||
5135 | // If we don't have two array types with the same constant bound nor two | |||
5136 | // incomplete array types, we've unwrapped everything we can. | |||
5137 | if (auto *CAT1 = dyn_cast<ConstantArrayType>(AT1)) { | |||
5138 | auto *CAT2 = dyn_cast<ConstantArrayType>(AT2); | |||
5139 | if (!CAT2 || CAT1->getSize() != CAT2->getSize()) | |||
5140 | return UnwrappedAny; | |||
5141 | } else if (!isa<IncompleteArrayType>(AT1) || | |||
5142 | !isa<IncompleteArrayType>(AT2)) { | |||
5143 | return UnwrappedAny; | |||
5144 | } | |||
5145 | ||||
5146 | T1 = AT1->getElementType(); | |||
5147 | T2 = AT2->getElementType(); | |||
5148 | UnwrappedAny = true; | |||
5149 | } | |||
5150 | } | |||
5151 | ||||
5152 | /// Attempt to unwrap two types that may be similar (C++ [conv.qual]). | |||
5153 | /// | |||
5154 | /// If T1 and T2 are both pointer types of the same kind, or both array types | |||
5155 | /// with the same bound, unwraps layers from T1 and T2 until a pointer type is | |||
5156 | /// unwrapped. Top-level qualifiers on T1 and T2 are ignored. | |||
5157 | /// | |||
5158 | /// This function will typically be called in a loop that successively | |||
5159 | /// "unwraps" pointer and pointer-to-member types to compare them at each | |||
5160 | /// level. | |||
5161 | /// | |||
5162 | /// \return \c true if a pointer type was unwrapped, \c false if we reached a | |||
5163 | /// pair of types that can't be unwrapped further. | |||
5164 | bool ASTContext::UnwrapSimilarTypes(QualType &T1, QualType &T2) { | |||
5165 | UnwrapSimilarArrayTypes(T1, T2); | |||
5166 | ||||
5167 | const auto *T1PtrType = T1->getAs<PointerType>(); | |||
5168 | const auto *T2PtrType = T2->getAs<PointerType>(); | |||
5169 | if (T1PtrType && T2PtrType) { | |||
5170 | T1 = T1PtrType->getPointeeType(); | |||
5171 | T2 = T2PtrType->getPointeeType(); | |||
5172 | return true; | |||
5173 | } | |||
5174 | ||||
5175 | const auto *T1MPType = T1->getAs<MemberPointerType>(); | |||
5176 | const auto *T2MPType = T2->getAs<MemberPointerType>(); | |||
5177 | if (T1MPType && T2MPType && | |||
5178 | hasSameUnqualifiedType(QualType(T1MPType->getClass(), 0), | |||
5179 | QualType(T2MPType->getClass(), 0))) { | |||
5180 | T1 = T1MPType->getPointeeType(); | |||
5181 | T2 = T2MPType->getPointeeType(); | |||
5182 | return true; | |||
5183 | } | |||
5184 | ||||
5185 | if (getLangOpts().ObjC) { | |||
5186 | const auto *T1OPType = T1->getAs<ObjCObjectPointerType>(); | |||
5187 | const auto *T2OPType = T2->getAs<ObjCObjectPointerType>(); | |||
5188 | if (T1OPType && T2OPType) { | |||
5189 | T1 = T1OPType->getPointeeType(); | |||
5190 | T2 = T2OPType->getPointeeType(); | |||
5191 | return true; | |||
5192 | } | |||
5193 | } | |||
5194 | ||||
5195 | // FIXME: Block pointers, too? | |||
5196 | ||||
5197 | return false; | |||
5198 | } | |||
5199 | ||||
5200 | bool ASTContext::hasSimilarType(QualType T1, QualType T2) { | |||
5201 | while (true) { | |||
5202 | Qualifiers Quals; | |||
5203 | T1 = getUnqualifiedArrayType(T1, Quals); | |||
5204 | T2 = getUnqualifiedArrayType(T2, Quals); | |||
5205 | if (hasSameType(T1, T2)) | |||
5206 | return true; | |||
5207 | if (!UnwrapSimilarTypes(T1, T2)) | |||
5208 | return false; | |||
5209 | } | |||
5210 | } | |||
5211 | ||||
5212 | bool ASTContext::hasCvrSimilarType(QualType T1, QualType T2) { | |||
5213 | while (true) { | |||
5214 | Qualifiers Quals1, Quals2; | |||
5215 | T1 = getUnqualifiedArrayType(T1, Quals1); | |||
5216 | T2 = getUnqualifiedArrayType(T2, Quals2); | |||
5217 | ||||
5218 | Quals1.removeCVRQualifiers(); | |||
5219 | Quals2.removeCVRQualifiers(); | |||
5220 | if (Quals1 != Quals2) | |||
5221 | return false; | |||
5222 | ||||
5223 | if (hasSameType(T1, T2)) | |||
5224 | return true; | |||
5225 | ||||
5226 | if (!UnwrapSimilarTypes(T1, T2)) | |||
5227 | return false; | |||
5228 | } | |||
5229 | } | |||
5230 | ||||
5231 | DeclarationNameInfo | |||
5232 | ASTContext::getNameForTemplate(TemplateName Name, | |||
5233 | SourceLocation NameLoc) const { | |||
5234 | switch (Name.getKind()) { | |||
5235 | case TemplateName::QualifiedTemplate: | |||
5236 | case TemplateName::Template: | |||
5237 | // DNInfo work in progress: CHECKME: what about DNLoc? | |||
5238 | return DeclarationNameInfo(Name.getAsTemplateDecl()->getDeclName(), | |||
5239 | NameLoc); | |||
5240 | ||||
5241 | case TemplateName::OverloadedTemplate: { | |||
5242 | OverloadedTemplateStorage *Storage = Name.getAsOverloadedTemplate(); | |||
5243 | // DNInfo work in progress: CHECKME: what about DNLoc? | |||
5244 | return DeclarationNameInfo((*Storage->begin())->getDeclName(), NameLoc); | |||
5245 | } | |||
5246 | ||||
5247 | case TemplateName::AssumedTemplate: { | |||
5248 | AssumedTemplateStorage *Storage = Name.getAsAssumedTemplateName(); | |||
5249 | return DeclarationNameInfo(Storage->getDeclName(), NameLoc); | |||
5250 | } | |||
5251 | ||||
5252 | case TemplateName::DependentTemplate: { | |||
5253 | DependentTemplateName *DTN = Name.getAsDependentTemplateName(); | |||
5254 | DeclarationName DName; | |||
5255 | if (DTN->isIdentifier()) { | |||
5256 | DName = DeclarationNames.getIdentifier(DTN->getIdentifier()); | |||
5257 | return DeclarationNameInfo(DName, NameLoc); | |||
5258 | } else { | |||
5259 | DName = DeclarationNames.getCXXOperatorName(DTN->getOperator()); | |||
5260 | // DNInfo work in progress: FIXME: source locations? | |||
5261 | DeclarationNameLoc DNLoc; | |||
5262 | DNLoc.CXXOperatorName.BeginOpNameLoc = SourceLocation().getRawEncoding(); | |||
5263 | DNLoc.CXXOperatorName.EndOpNameLoc = SourceLocation().getRawEncoding(); | |||
5264 | return DeclarationNameInfo(DName, NameLoc, DNLoc); | |||
5265 | } | |||
5266 | } | |||
5267 | ||||
5268 | case TemplateName::SubstTemplateTemplateParm: { | |||
5269 | SubstTemplateTemplateParmStorage *subst | |||
5270 | = Name.getAsSubstTemplateTemplateParm(); | |||
5271 | return DeclarationNameInfo(subst->getParameter()->getDeclName(), | |||
5272 | NameLoc); | |||
5273 | } | |||
5274 | ||||
5275 | case TemplateName::SubstTemplateTemplateParmPack: { | |||
5276 | SubstTemplateTemplateParmPackStorage *subst | |||
5277 | = Name.getAsSubstTemplateTemplateParmPack(); | |||
5278 | return DeclarationNameInfo(subst->getParameterPack()->getDeclName(), | |||
5279 | NameLoc); | |||
5280 | } | |||
5281 | } | |||
5282 | ||||
5283 | llvm_unreachable("bad template name kind!")::llvm::llvm_unreachable_internal("bad template name kind!", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5283); | |||
5284 | } | |||
5285 | ||||
5286 | TemplateName ASTContext::getCanonicalTemplateName(TemplateName Name) const { | |||
5287 | switch (Name.getKind()) { | |||
5288 | case TemplateName::QualifiedTemplate: | |||
5289 | case TemplateName::Template: { | |||
5290 | TemplateDecl *Template = Name.getAsTemplateDecl(); | |||
5291 | if (auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Template)) | |||
5292 | Template = getCanonicalTemplateTemplateParmDecl(TTP); | |||
5293 | ||||
5294 | // The canonical template name is the canonical template declaration. | |||
5295 | return TemplateName(cast<TemplateDecl>(Template->getCanonicalDecl())); | |||
5296 | } | |||
5297 | ||||
5298 | case TemplateName::OverloadedTemplate: | |||
5299 | case TemplateName::AssumedTemplate: | |||
5300 | llvm_unreachable("cannot canonicalize unresolved template")::llvm::llvm_unreachable_internal("cannot canonicalize unresolved template" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5300); | |||
5301 | ||||
5302 | case TemplateName::DependentTemplate: { | |||
5303 | DependentTemplateName *DTN = Name.getAsDependentTemplateName(); | |||
5304 | assert(DTN && "Non-dependent template names must refer to template decls.")((DTN && "Non-dependent template names must refer to template decls." ) ? static_cast<void> (0) : __assert_fail ("DTN && \"Non-dependent template names must refer to template decls.\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5304, __PRETTY_FUNCTION__)); | |||
5305 | return DTN->CanonicalTemplateName; | |||
5306 | } | |||
5307 | ||||
5308 | case TemplateName::SubstTemplateTemplateParm: { | |||
5309 | SubstTemplateTemplateParmStorage *subst | |||
5310 | = Name.getAsSubstTemplateTemplateParm(); | |||
5311 | return getCanonicalTemplateName(subst->getReplacement()); | |||
5312 | } | |||
5313 | ||||
5314 | case TemplateName::SubstTemplateTemplateParmPack: { | |||
5315 | SubstTemplateTemplateParmPackStorage *subst | |||
5316 | = Name.getAsSubstTemplateTemplateParmPack(); | |||
5317 | TemplateTemplateParmDecl *canonParameter | |||
5318 | = getCanonicalTemplateTemplateParmDecl(subst->getParameterPack()); | |||
5319 | TemplateArgument canonArgPack | |||
5320 | = getCanonicalTemplateArgument(subst->getArgumentPack()); | |||
5321 | return getSubstTemplateTemplateParmPack(canonParameter, canonArgPack); | |||
5322 | } | |||
5323 | } | |||
5324 | ||||
5325 | llvm_unreachable("bad template name!")::llvm::llvm_unreachable_internal("bad template name!", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5325); | |||
5326 | } | |||
5327 | ||||
5328 | bool ASTContext::hasSameTemplateName(TemplateName X, TemplateName Y) { | |||
5329 | X = getCanonicalTemplateName(X); | |||
5330 | Y = getCanonicalTemplateName(Y); | |||
5331 | return X.getAsVoidPointer() == Y.getAsVoidPointer(); | |||
5332 | } | |||
5333 | ||||
5334 | TemplateArgument | |||
5335 | ASTContext::getCanonicalTemplateArgument(const TemplateArgument &Arg) const { | |||
5336 | switch (Arg.getKind()) { | |||
5337 | case TemplateArgument::Null: | |||
5338 | return Arg; | |||
5339 | ||||
5340 | case TemplateArgument::Expression: | |||
5341 | return Arg; | |||
5342 | ||||
5343 | case TemplateArgument::Declaration: { | |||
5344 | auto *D = cast<ValueDecl>(Arg.getAsDecl()->getCanonicalDecl()); | |||
5345 | return TemplateArgument(D, Arg.getParamTypeForDecl()); | |||
5346 | } | |||
5347 | ||||
5348 | case TemplateArgument::NullPtr: | |||
5349 | return TemplateArgument(getCanonicalType(Arg.getNullPtrType()), | |||
5350 | /*isNullPtr*/true); | |||
5351 | ||||
5352 | case TemplateArgument::Template: | |||
5353 | return TemplateArgument(getCanonicalTemplateName(Arg.getAsTemplate())); | |||
5354 | ||||
5355 | case TemplateArgument::TemplateExpansion: | |||
5356 | return TemplateArgument(getCanonicalTemplateName( | |||
5357 | Arg.getAsTemplateOrTemplatePattern()), | |||
5358 | Arg.getNumTemplateExpansions()); | |||
5359 | ||||
5360 | case TemplateArgument::Integral: | |||
5361 | return TemplateArgument(Arg, getCanonicalType(Arg.getIntegralType())); | |||
5362 | ||||
5363 | case TemplateArgument::Type: | |||
5364 | return TemplateArgument(getCanonicalType(Arg.getAsType())); | |||
5365 | ||||
5366 | case TemplateArgument::Pack: { | |||
5367 | if (Arg.pack_size() == 0) | |||
5368 | return Arg; | |||
5369 | ||||
5370 | auto *CanonArgs = new (*this) TemplateArgument[Arg.pack_size()]; | |||
5371 | unsigned Idx = 0; | |||
5372 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), | |||
5373 | AEnd = Arg.pack_end(); | |||
5374 | A != AEnd; (void)++A, ++Idx) | |||
5375 | CanonArgs[Idx] = getCanonicalTemplateArgument(*A); | |||
5376 | ||||
5377 | return TemplateArgument(llvm::makeArrayRef(CanonArgs, Arg.pack_size())); | |||
5378 | } | |||
5379 | } | |||
5380 | ||||
5381 | // Silence GCC warning | |||
5382 | llvm_unreachable("Unhandled template argument kind")::llvm::llvm_unreachable_internal("Unhandled template argument kind" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5382); | |||
5383 | } | |||
5384 | ||||
5385 | NestedNameSpecifier * | |||
5386 | ASTContext::getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const { | |||
5387 | if (!NNS) | |||
5388 | return nullptr; | |||
5389 | ||||
5390 | switch (NNS->getKind()) { | |||
5391 | case NestedNameSpecifier::Identifier: | |||
5392 | // Canonicalize the prefix but keep the identifier the same. | |||
5393 | return NestedNameSpecifier::Create(*this, | |||
5394 | getCanonicalNestedNameSpecifier(NNS->getPrefix()), | |||
5395 | NNS->getAsIdentifier()); | |||
5396 | ||||
5397 | case NestedNameSpecifier::Namespace: | |||
5398 | // A namespace is canonical; build a nested-name-specifier with | |||
5399 | // this namespace and no prefix. | |||
5400 | return NestedNameSpecifier::Create(*this, nullptr, | |||
5401 | NNS->getAsNamespace()->getOriginalNamespace()); | |||
5402 | ||||
5403 | case NestedNameSpecifier::NamespaceAlias: | |||
5404 | // A namespace is canonical; build a nested-name-specifier with | |||
5405 | // this namespace and no prefix. | |||
5406 | return NestedNameSpecifier::Create(*this, nullptr, | |||
5407 | NNS->getAsNamespaceAlias()->getNamespace() | |||
5408 | ->getOriginalNamespace()); | |||
5409 | ||||
5410 | case NestedNameSpecifier::TypeSpec: | |||
5411 | case NestedNameSpecifier::TypeSpecWithTemplate: { | |||
5412 | QualType T = getCanonicalType(QualType(NNS->getAsType(), 0)); | |||
5413 | ||||
5414 | // If we have some kind of dependent-named type (e.g., "typename T::type"), | |||
5415 | // break it apart into its prefix and identifier, then reconsititute those | |||
5416 | // as the canonical nested-name-specifier. This is required to canonicalize | |||
5417 | // a dependent nested-name-specifier involving typedefs of dependent-name | |||
5418 | // types, e.g., | |||
5419 | // typedef typename T::type T1; | |||
5420 | // typedef typename T1::type T2; | |||
5421 | if (const auto *DNT = T->getAs<DependentNameType>()) | |||
5422 | return NestedNameSpecifier::Create(*this, DNT->getQualifier(), | |||
5423 | const_cast<IdentifierInfo *>(DNT->getIdentifier())); | |||
5424 | ||||
5425 | // Otherwise, just canonicalize the type, and force it to be a TypeSpec. | |||
5426 | // FIXME: Why are TypeSpec and TypeSpecWithTemplate distinct in the | |||
5427 | // first place? | |||
5428 | return NestedNameSpecifier::Create(*this, nullptr, false, | |||
5429 | const_cast<Type *>(T.getTypePtr())); | |||
5430 | } | |||
5431 | ||||
5432 | case NestedNameSpecifier::Global: | |||
5433 | case NestedNameSpecifier::Super: | |||
5434 | // The global specifier and __super specifer are canonical and unique. | |||
5435 | return NNS; | |||
5436 | } | |||
5437 | ||||
5438 | llvm_unreachable("Invalid NestedNameSpecifier::Kind!")::llvm::llvm_unreachable_internal("Invalid NestedNameSpecifier::Kind!" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5438); | |||
5439 | } | |||
5440 | ||||
5441 | const ArrayType *ASTContext::getAsArrayType(QualType T) const { | |||
5442 | // Handle the non-qualified case efficiently. | |||
5443 | if (!T.hasLocalQualifiers()) { | |||
5444 | // Handle the common positive case fast. | |||
5445 | if (const auto *AT = dyn_cast<ArrayType>(T)) | |||
5446 | return AT; | |||
5447 | } | |||
5448 | ||||
5449 | // Handle the common negative case fast. | |||
5450 | if (!isa<ArrayType>(T.getCanonicalType())) | |||
5451 | return nullptr; | |||
5452 | ||||
5453 | // Apply any qualifiers from the array type to the element type. This | |||
5454 | // implements C99 6.7.3p8: "If the specification of an array type includes | |||
5455 | // any type qualifiers, the element type is so qualified, not the array type." | |||
5456 | ||||
5457 | // If we get here, we either have type qualifiers on the type, or we have | |||
5458 | // sugar such as a typedef in the way. If we have type qualifiers on the type | |||
5459 | // we must propagate them down into the element type. | |||
5460 | ||||
5461 | SplitQualType split = T.getSplitDesugaredType(); | |||
5462 | Qualifiers qs = split.Quals; | |||
5463 | ||||
5464 | // If we have a simple case, just return now. | |||
5465 | const auto *ATy = dyn_cast<ArrayType>(split.Ty); | |||
5466 | if (!ATy || qs.empty()) | |||
5467 | return ATy; | |||
5468 | ||||
5469 | // Otherwise, we have an array and we have qualifiers on it. Push the | |||
5470 | // qualifiers into the array element type and return a new array type. | |||
5471 | QualType NewEltTy = getQualifiedType(ATy->getElementType(), qs); | |||
5472 | ||||
5473 | if (const auto *CAT = dyn_cast<ConstantArrayType>(ATy)) | |||
5474 | return cast<ArrayType>(getConstantArrayType(NewEltTy, CAT->getSize(), | |||
5475 | CAT->getSizeModifier(), | |||
5476 | CAT->getIndexTypeCVRQualifiers())); | |||
5477 | if (const auto *IAT = dyn_cast<IncompleteArrayType>(ATy)) | |||
5478 | return cast<ArrayType>(getIncompleteArrayType(NewEltTy, | |||
5479 | IAT->getSizeModifier(), | |||
5480 | IAT->getIndexTypeCVRQualifiers())); | |||
5481 | ||||
5482 | if (const auto *DSAT = dyn_cast<DependentSizedArrayType>(ATy)) | |||
5483 | return cast<ArrayType>( | |||
5484 | getDependentSizedArrayType(NewEltTy, | |||
5485 | DSAT->getSizeExpr(), | |||
5486 | DSAT->getSizeModifier(), | |||
5487 | DSAT->getIndexTypeCVRQualifiers(), | |||
5488 | DSAT->getBracketsRange())); | |||
5489 | ||||
5490 | const auto *VAT = cast<VariableArrayType>(ATy); | |||
5491 | return cast<ArrayType>(getVariableArrayType(NewEltTy, | |||
5492 | VAT->getSizeExpr(), | |||
5493 | VAT->getSizeModifier(), | |||
5494 | VAT->getIndexTypeCVRQualifiers(), | |||
5495 | VAT->getBracketsRange())); | |||
5496 | } | |||
5497 | ||||
5498 | QualType ASTContext::getAdjustedParameterType(QualType T) const { | |||
5499 | if (T->isArrayType() || T->isFunctionType()) | |||
5500 | return getDecayedType(T); | |||
5501 | return T; | |||
5502 | } | |||
5503 | ||||
5504 | QualType ASTContext::getSignatureParameterType(QualType T) const { | |||
5505 | T = getVariableArrayDecayedType(T); | |||
5506 | T = getAdjustedParameterType(T); | |||
5507 | return T.getUnqualifiedType(); | |||
5508 | } | |||
5509 | ||||
5510 | QualType ASTContext::getExceptionObjectType(QualType T) const { | |||
5511 | // C++ [except.throw]p3: | |||
5512 | // A throw-expression initializes a temporary object, called the exception | |||
5513 | // object, the type of which is determined by removing any top-level | |||
5514 | // cv-qualifiers from the static type of the operand of throw and adjusting | |||
5515 | // the type from "array of T" or "function returning T" to "pointer to T" | |||
5516 | // or "pointer to function returning T", [...] | |||
5517 | T = getVariableArrayDecayedType(T); | |||
5518 | if (T->isArrayType() || T->isFunctionType()) | |||
5519 | T = getDecayedType(T); | |||
5520 | return T.getUnqualifiedType(); | |||
5521 | } | |||
5522 | ||||
5523 | /// getArrayDecayedType - Return the properly qualified result of decaying the | |||
5524 | /// specified array type to a pointer. This operation is non-trivial when | |||
5525 | /// handling typedefs etc. The canonical type of "T" must be an array type, | |||
5526 | /// this returns a pointer to a properly qualified element of the array. | |||
5527 | /// | |||
5528 | /// See C99 6.7.5.3p7 and C99 6.3.2.1p3. | |||
5529 | QualType ASTContext::getArrayDecayedType(QualType Ty) const { | |||
5530 | // Get the element type with 'getAsArrayType' so that we don't lose any | |||
5531 | // typedefs in the element type of the array. This also handles propagation | |||
5532 | // of type qualifiers from the array type into the element type if present | |||
5533 | // (C99 6.7.3p8). | |||
5534 | const ArrayType *PrettyArrayType = getAsArrayType(Ty); | |||
5535 | assert(PrettyArrayType && "Not an array type!")((PrettyArrayType && "Not an array type!") ? static_cast <void> (0) : __assert_fail ("PrettyArrayType && \"Not an array type!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5535, __PRETTY_FUNCTION__)); | |||
5536 | ||||
5537 | QualType PtrTy = getPointerType(PrettyArrayType->getElementType()); | |||
5538 | ||||
5539 | // int x[restrict 4] -> int *restrict | |||
5540 | QualType Result = getQualifiedType(PtrTy, | |||
5541 | PrettyArrayType->getIndexTypeQualifiers()); | |||
5542 | ||||
5543 | // int x[_Nullable] -> int * _Nullable | |||
5544 | if (auto Nullability = Ty->getNullability(*this)) { | |||
5545 | Result = const_cast<ASTContext *>(this)->getAttributedType( | |||
5546 | AttributedType::getNullabilityAttrKind(*Nullability), Result, Result); | |||
5547 | } | |||
5548 | return Result; | |||
5549 | } | |||
5550 | ||||
5551 | QualType ASTContext::getBaseElementType(const ArrayType *array) const { | |||
5552 | return getBaseElementType(array->getElementType()); | |||
5553 | } | |||
5554 | ||||
5555 | QualType ASTContext::getBaseElementType(QualType type) const { | |||
5556 | Qualifiers qs; | |||
5557 | while (true) { | |||
5558 | SplitQualType split = type.getSplitDesugaredType(); | |||
5559 | const ArrayType *array = split.Ty->getAsArrayTypeUnsafe(); | |||
5560 | if (!array) break; | |||
5561 | ||||
5562 | type = array->getElementType(); | |||
5563 | qs.addConsistentQualifiers(split.Quals); | |||
5564 | } | |||
5565 | ||||
5566 | return getQualifiedType(type, qs); | |||
5567 | } | |||
5568 | ||||
5569 | /// getConstantArrayElementCount - Returns number of constant array elements. | |||
5570 | uint64_t | |||
5571 | ASTContext::getConstantArrayElementCount(const ConstantArrayType *CA) const { | |||
5572 | uint64_t ElementCount = 1; | |||
5573 | do { | |||
5574 | ElementCount *= CA->getSize().getZExtValue(); | |||
5575 | CA = dyn_cast_or_null<ConstantArrayType>( | |||
5576 | CA->getElementType()->getAsArrayTypeUnsafe()); | |||
5577 | } while (CA); | |||
5578 | return ElementCount; | |||
5579 | } | |||
5580 | ||||
5581 | /// getFloatingRank - Return a relative rank for floating point types. | |||
5582 | /// This routine will assert if passed a built-in type that isn't a float. | |||
5583 | static FloatingRank getFloatingRank(QualType T) { | |||
5584 | if (const auto *CT = T->getAs<ComplexType>()) | |||
5585 | return getFloatingRank(CT->getElementType()); | |||
5586 | ||||
5587 | assert(T->getAs<BuiltinType>() && "getFloatingRank(): not a floating type")((T->getAs<BuiltinType>() && "getFloatingRank(): not a floating type" ) ? static_cast<void> (0) : __assert_fail ("T->getAs<BuiltinType>() && \"getFloatingRank(): not a floating type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5587, __PRETTY_FUNCTION__)); | |||
5588 | switch (T->getAs<BuiltinType>()->getKind()) { | |||
5589 | default: llvm_unreachable("getFloatingRank(): not a floating type")::llvm::llvm_unreachable_internal("getFloatingRank(): not a floating type" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5589); | |||
5590 | case BuiltinType::Float16: return Float16Rank; | |||
5591 | case BuiltinType::Half: return HalfRank; | |||
5592 | case BuiltinType::Float: return FloatRank; | |||
5593 | case BuiltinType::Double: return DoubleRank; | |||
5594 | case BuiltinType::LongDouble: return LongDoubleRank; | |||
5595 | case BuiltinType::Float128: return Float128Rank; | |||
5596 | } | |||
5597 | } | |||
5598 | ||||
5599 | /// getFloatingTypeOfSizeWithinDomain - Returns a real floating | |||
5600 | /// point or a complex type (based on typeDomain/typeSize). | |||
5601 | /// 'typeDomain' is a real floating point or complex type. | |||
5602 | /// 'typeSize' is a real floating point or complex type. | |||
5603 | QualType ASTContext::getFloatingTypeOfSizeWithinDomain(QualType Size, | |||
5604 | QualType Domain) const { | |||
5605 | FloatingRank EltRank = getFloatingRank(Size); | |||
5606 | if (Domain->isComplexType()) { | |||
5607 | switch (EltRank) { | |||
5608 | case Float16Rank: | |||
5609 | case HalfRank: llvm_unreachable("Complex half is not supported")::llvm::llvm_unreachable_internal("Complex half is not supported" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5609); | |||
5610 | case FloatRank: return FloatComplexTy; | |||
5611 | case DoubleRank: return DoubleComplexTy; | |||
5612 | case LongDoubleRank: return LongDoubleComplexTy; | |||
5613 | case Float128Rank: return Float128ComplexTy; | |||
5614 | } | |||
5615 | } | |||
5616 | ||||
5617 | assert(Domain->isRealFloatingType() && "Unknown domain!")((Domain->isRealFloatingType() && "Unknown domain!" ) ? static_cast<void> (0) : __assert_fail ("Domain->isRealFloatingType() && \"Unknown domain!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5617, __PRETTY_FUNCTION__)); | |||
5618 | switch (EltRank) { | |||
5619 | case Float16Rank: return HalfTy; | |||
5620 | case HalfRank: return HalfTy; | |||
5621 | case FloatRank: return FloatTy; | |||
5622 | case DoubleRank: return DoubleTy; | |||
5623 | case LongDoubleRank: return LongDoubleTy; | |||
5624 | case Float128Rank: return Float128Ty; | |||
5625 | } | |||
5626 | llvm_unreachable("getFloatingRank(): illegal value for rank")::llvm::llvm_unreachable_internal("getFloatingRank(): illegal value for rank" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5626); | |||
5627 | } | |||
5628 | ||||
5629 | /// getFloatingTypeOrder - Compare the rank of the two specified floating | |||
5630 | /// point types, ignoring the domain of the type (i.e. 'double' == | |||
5631 | /// '_Complex double'). If LHS > RHS, return 1. If LHS == RHS, return 0. If | |||
5632 | /// LHS < RHS, return -1. | |||
5633 | int ASTContext::getFloatingTypeOrder(QualType LHS, QualType RHS) const { | |||
5634 | FloatingRank LHSR = getFloatingRank(LHS); | |||
5635 | FloatingRank RHSR = getFloatingRank(RHS); | |||
5636 | ||||
5637 | if (LHSR == RHSR) | |||
5638 | return 0; | |||
5639 | if (LHSR > RHSR) | |||
5640 | return 1; | |||
5641 | return -1; | |||
5642 | } | |||
5643 | ||||
5644 | int ASTContext::getFloatingTypeSemanticOrder(QualType LHS, QualType RHS) const { | |||
5645 | if (&getFloatTypeSemantics(LHS) == &getFloatTypeSemantics(RHS)) | |||
5646 | return 0; | |||
5647 | return getFloatingTypeOrder(LHS, RHS); | |||
5648 | } | |||
5649 | ||||
5650 | /// getIntegerRank - Return an integer conversion rank (C99 6.3.1.1p1). This | |||
5651 | /// routine will assert if passed a built-in type that isn't an integer or enum, | |||
5652 | /// or if it is not canonicalized. | |||
5653 | unsigned ASTContext::getIntegerRank(const Type *T) const { | |||
5654 | assert(T->isCanonicalUnqualified() && "T should be canonicalized")((T->isCanonicalUnqualified() && "T should be canonicalized" ) ? static_cast<void> (0) : __assert_fail ("T->isCanonicalUnqualified() && \"T should be canonicalized\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5654, __PRETTY_FUNCTION__)); | |||
5655 | ||||
5656 | switch (cast<BuiltinType>(T)->getKind()) { | |||
5657 | default: llvm_unreachable("getIntegerRank(): not a built-in integer")::llvm::llvm_unreachable_internal("getIntegerRank(): not a built-in integer" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5657); | |||
5658 | case BuiltinType::Bool: | |||
5659 | return 1 + (getIntWidth(BoolTy) << 3); | |||
5660 | case BuiltinType::Char_S: | |||
5661 | case BuiltinType::Char_U: | |||
5662 | case BuiltinType::SChar: | |||
5663 | case BuiltinType::UChar: | |||
5664 | return 2 + (getIntWidth(CharTy) << 3); | |||
5665 | case BuiltinType::Short: | |||
5666 | case BuiltinType::UShort: | |||
5667 | return 3 + (getIntWidth(ShortTy) << 3); | |||
5668 | case BuiltinType::Int: | |||
5669 | case BuiltinType::UInt: | |||
5670 | return 4 + (getIntWidth(IntTy) << 3); | |||
5671 | case BuiltinType::Long: | |||
5672 | case BuiltinType::ULong: | |||
5673 | return 5 + (getIntWidth(LongTy) << 3); | |||
5674 | case BuiltinType::LongLong: | |||
5675 | case BuiltinType::ULongLong: | |||
5676 | return 6 + (getIntWidth(LongLongTy) << 3); | |||
5677 | case BuiltinType::Int128: | |||
5678 | case BuiltinType::UInt128: | |||
5679 | return 7 + (getIntWidth(Int128Ty) << 3); | |||
5680 | } | |||
5681 | } | |||
5682 | ||||
5683 | /// Whether this is a promotable bitfield reference according | |||
5684 | /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions). | |||
5685 | /// | |||
5686 | /// \returns the type this bit-field will promote to, or NULL if no | |||
5687 | /// promotion occurs. | |||
5688 | QualType ASTContext::isPromotableBitField(Expr *E) const { | |||
5689 | if (E->isTypeDependent() || E->isValueDependent()) | |||
5690 | return {}; | |||
5691 | ||||
5692 | // C++ [conv.prom]p5: | |||
5693 | // If the bit-field has an enumerated type, it is treated as any other | |||
5694 | // value of that type for promotion purposes. | |||
5695 | if (getLangOpts().CPlusPlus && E->getType()->isEnumeralType()) | |||
5696 | return {}; | |||
5697 | ||||
5698 | // FIXME: We should not do this unless E->refersToBitField() is true. This | |||
5699 | // matters in C where getSourceBitField() will find bit-fields for various | |||
5700 | // cases where the source expression is not a bit-field designator. | |||
5701 | ||||
5702 | FieldDecl *Field = E->getSourceBitField(); // FIXME: conditional bit-fields? | |||
5703 | if (!Field) | |||
5704 | return {}; | |||
5705 | ||||
5706 | QualType FT = Field->getType(); | |||
5707 | ||||
5708 | uint64_t BitWidth = Field->getBitWidthValue(*this); | |||
5709 | uint64_t IntSize = getTypeSize(IntTy); | |||
5710 | // C++ [conv.prom]p5: | |||
5711 | // A prvalue for an integral bit-field can be converted to a prvalue of type | |||
5712 | // int if int can represent all the values of the bit-field; otherwise, it | |||
5713 | // can be converted to unsigned int if unsigned int can represent all the | |||
5714 | // values of the bit-field. If the bit-field is larger yet, no integral | |||
5715 | // promotion applies to it. | |||
5716 | // C11 6.3.1.1/2: | |||
5717 | // [For a bit-field of type _Bool, int, signed int, or unsigned int:] | |||
5718 | // If an int can represent all values of the original type (as restricted by | |||
5719 | // the width, for a bit-field), the value is converted to an int; otherwise, | |||
5720 | // it is converted to an unsigned int. | |||
5721 | // | |||
5722 | // FIXME: C does not permit promotion of a 'long : 3' bitfield to int. | |||
5723 | // We perform that promotion here to match GCC and C++. | |||
5724 | // FIXME: C does not permit promotion of an enum bit-field whose rank is | |||
5725 | // greater than that of 'int'. We perform that promotion to match GCC. | |||
5726 | if (BitWidth < IntSize) | |||
5727 | return IntTy; | |||
5728 | ||||
5729 | if (BitWidth == IntSize) | |||
5730 | return FT->isSignedIntegerType() ? IntTy : UnsignedIntTy; | |||
5731 | ||||
5732 | // Bit-fields wider than int are not subject to promotions, and therefore act | |||
5733 | // like the base type. GCC has some weird bugs in this area that we | |||
5734 | // deliberately do not follow (GCC follows a pre-standard resolution to | |||
5735 | // C's DR315 which treats bit-width as being part of the type, and this leaks | |||
5736 | // into their semantics in some cases). | |||
5737 | return {}; | |||
5738 | } | |||
5739 | ||||
5740 | /// getPromotedIntegerType - Returns the type that Promotable will | |||
5741 | /// promote to: C99 6.3.1.1p2, assuming that Promotable is a promotable | |||
5742 | /// integer type. | |||
5743 | QualType ASTContext::getPromotedIntegerType(QualType Promotable) const { | |||
5744 | assert(!Promotable.isNull())((!Promotable.isNull()) ? static_cast<void> (0) : __assert_fail ("!Promotable.isNull()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5744, __PRETTY_FUNCTION__)); | |||
5745 | assert(Promotable->isPromotableIntegerType())((Promotable->isPromotableIntegerType()) ? static_cast< void> (0) : __assert_fail ("Promotable->isPromotableIntegerType()" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5745, __PRETTY_FUNCTION__)); | |||
5746 | if (const auto *ET = Promotable->getAs<EnumType>()) | |||
5747 | return ET->getDecl()->getPromotionType(); | |||
5748 | ||||
5749 | if (const auto *BT = Promotable->getAs<BuiltinType>()) { | |||
5750 | // C++ [conv.prom]: A prvalue of type char16_t, char32_t, or wchar_t | |||
5751 | // (3.9.1) can be converted to a prvalue of the first of the following | |||
5752 | // types that can represent all the values of its underlying type: | |||
5753 | // int, unsigned int, long int, unsigned long int, long long int, or | |||
5754 | // unsigned long long int [...] | |||
5755 | // FIXME: Is there some better way to compute this? | |||
5756 | if (BT->getKind() == BuiltinType::WChar_S || | |||
5757 | BT->getKind() == BuiltinType::WChar_U || | |||
5758 | BT->getKind() == BuiltinType::Char8 || | |||
5759 | BT->getKind() == BuiltinType::Char16 || | |||
5760 | BT->getKind() == BuiltinType::Char32) { | |||
5761 | bool FromIsSigned = BT->getKind() == BuiltinType::WChar_S; | |||
5762 | uint64_t FromSize = getTypeSize(BT); | |||
5763 | QualType PromoteTypes[] = { IntTy, UnsignedIntTy, LongTy, UnsignedLongTy, | |||
5764 | LongLongTy, UnsignedLongLongTy }; | |||
5765 | for (size_t Idx = 0; Idx < llvm::array_lengthof(PromoteTypes); ++Idx) { | |||
5766 | uint64_t ToSize = getTypeSize(PromoteTypes[Idx]); | |||
5767 | if (FromSize < ToSize || | |||
5768 | (FromSize == ToSize && | |||
5769 | FromIsSigned == PromoteTypes[Idx]->isSignedIntegerType())) | |||
5770 | return PromoteTypes[Idx]; | |||
5771 | } | |||
5772 | llvm_unreachable("char type should fit into long long")::llvm::llvm_unreachable_internal("char type should fit into long long" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5772); | |||
5773 | } | |||
5774 | } | |||
5775 | ||||
5776 | // At this point, we should have a signed or unsigned integer type. | |||
5777 | if (Promotable->isSignedIntegerType()) | |||
5778 | return IntTy; | |||
5779 | uint64_t PromotableSize = getIntWidth(Promotable); | |||
5780 | uint64_t IntSize = getIntWidth(IntTy); | |||
5781 | assert(Promotable->isUnsignedIntegerType() && PromotableSize <= IntSize)((Promotable->isUnsignedIntegerType() && PromotableSize <= IntSize) ? static_cast<void> (0) : __assert_fail ("Promotable->isUnsignedIntegerType() && PromotableSize <= IntSize" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5781, __PRETTY_FUNCTION__)); | |||
5782 | return (PromotableSize != IntSize) ? IntTy : UnsignedIntTy; | |||
5783 | } | |||
5784 | ||||
5785 | /// Recurses in pointer/array types until it finds an objc retainable | |||
5786 | /// type and returns its ownership. | |||
5787 | Qualifiers::ObjCLifetime ASTContext::getInnerObjCOwnership(QualType T) const { | |||
5788 | while (!T.isNull()) { | |||
5789 | if (T.getObjCLifetime() != Qualifiers::OCL_None) | |||
5790 | return T.getObjCLifetime(); | |||
5791 | if (T->isArrayType()) | |||
5792 | T = getBaseElementType(T); | |||
5793 | else if (const auto *PT = T->getAs<PointerType>()) | |||
5794 | T = PT->getPointeeType(); | |||
5795 | else if (const auto *RT = T->getAs<ReferenceType>()) | |||
5796 | T = RT->getPointeeType(); | |||
5797 | else | |||
5798 | break; | |||
5799 | } | |||
5800 | ||||
5801 | return Qualifiers::OCL_None; | |||
5802 | } | |||
5803 | ||||
5804 | static const Type *getIntegerTypeForEnum(const EnumType *ET) { | |||
5805 | // Incomplete enum types are not treated as integer types. | |||
5806 | // FIXME: In C++, enum types are never integer types. | |||
5807 | if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped()) | |||
5808 | return ET->getDecl()->getIntegerType().getTypePtr(); | |||
5809 | return nullptr; | |||
5810 | } | |||
5811 | ||||
5812 | /// getIntegerTypeOrder - Returns the highest ranked integer type: | |||
5813 | /// C99 6.3.1.8p1. If LHS > RHS, return 1. If LHS == RHS, return 0. If | |||
5814 | /// LHS < RHS, return -1. | |||
5815 | int ASTContext::getIntegerTypeOrder(QualType LHS, QualType RHS) const { | |||
5816 | const Type *LHSC = getCanonicalType(LHS).getTypePtr(); | |||
5817 | const Type *RHSC = getCanonicalType(RHS).getTypePtr(); | |||
5818 | ||||
5819 | // Unwrap enums to their underlying type. | |||
5820 | if (const auto *ET = dyn_cast<EnumType>(LHSC)) | |||
5821 | LHSC = getIntegerTypeForEnum(ET); | |||
5822 | if (const auto *ET = dyn_cast<EnumType>(RHSC)) | |||
5823 | RHSC = getIntegerTypeForEnum(ET); | |||
5824 | ||||
5825 | if (LHSC == RHSC) return 0; | |||
5826 | ||||
5827 | bool LHSUnsigned = LHSC->isUnsignedIntegerType(); | |||
5828 | bool RHSUnsigned = RHSC->isUnsignedIntegerType(); | |||
5829 | ||||
5830 | unsigned LHSRank = getIntegerRank(LHSC); | |||
5831 | unsigned RHSRank = getIntegerRank(RHSC); | |||
5832 | ||||
5833 | if (LHSUnsigned == RHSUnsigned) { // Both signed or both unsigned. | |||
5834 | if (LHSRank == RHSRank) return 0; | |||
5835 | return LHSRank > RHSRank ? 1 : -1; | |||
5836 | } | |||
5837 | ||||
5838 | // Otherwise, the LHS is signed and the RHS is unsigned or visa versa. | |||
5839 | if (LHSUnsigned) { | |||
5840 | // If the unsigned [LHS] type is larger, return it. | |||
5841 | if (LHSRank >= RHSRank) | |||
5842 | return 1; | |||
5843 | ||||
5844 | // If the signed type can represent all values of the unsigned type, it | |||
5845 | // wins. Because we are dealing with 2's complement and types that are | |||
5846 | // powers of two larger than each other, this is always safe. | |||
5847 | return -1; | |||
5848 | } | |||
5849 | ||||
5850 | // If the unsigned [RHS] type is larger, return it. | |||
5851 | if (RHSRank >= LHSRank) | |||
5852 | return -1; | |||
5853 | ||||
5854 | // If the signed type can represent all values of the unsigned type, it | |||
5855 | // wins. Because we are dealing with 2's complement and types that are | |||
5856 | // powers of two larger than each other, this is always safe. | |||
5857 | return 1; | |||
5858 | } | |||
5859 | ||||
5860 | TypedefDecl *ASTContext::getCFConstantStringDecl() const { | |||
5861 | if (CFConstantStringTypeDecl) | |||
5862 | return CFConstantStringTypeDecl; | |||
5863 | ||||
5864 | assert(!CFConstantStringTagDecl &&((!CFConstantStringTagDecl && "tag and typedef should be initialized together" ) ? static_cast<void> (0) : __assert_fail ("!CFConstantStringTagDecl && \"tag and typedef should be initialized together\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5865, __PRETTY_FUNCTION__)) | |||
5865 | "tag and typedef should be initialized together")((!CFConstantStringTagDecl && "tag and typedef should be initialized together" ) ? static_cast<void> (0) : __assert_fail ("!CFConstantStringTagDecl && \"tag and typedef should be initialized together\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5865, __PRETTY_FUNCTION__)); | |||
5866 | CFConstantStringTagDecl = buildImplicitRecord("__NSConstantString_tag"); | |||
5867 | CFConstantStringTagDecl->startDefinition(); | |||
5868 | ||||
5869 | struct { | |||
5870 | QualType Type; | |||
5871 | const char *Name; | |||
5872 | } Fields[5]; | |||
5873 | unsigned Count = 0; | |||
5874 | ||||
5875 | /// Objective-C ABI | |||
5876 | /// | |||
5877 | /// typedef struct __NSConstantString_tag { | |||
5878 | /// const int *isa; | |||
5879 | /// int flags; | |||
5880 | /// const char *str; | |||
5881 | /// long length; | |||
5882 | /// } __NSConstantString; | |||
5883 | /// | |||
5884 | /// Swift ABI (4.1, 4.2) | |||
5885 | /// | |||
5886 | /// typedef struct __NSConstantString_tag { | |||
5887 | /// uintptr_t _cfisa; | |||
5888 | /// uintptr_t _swift_rc; | |||
5889 | /// _Atomic(uint64_t) _cfinfoa; | |||
5890 | /// const char *_ptr; | |||
5891 | /// uint32_t _length; | |||
5892 | /// } __NSConstantString; | |||
5893 | /// | |||
5894 | /// Swift ABI (5.0) | |||
5895 | /// | |||
5896 | /// typedef struct __NSConstantString_tag { | |||
5897 | /// uintptr_t _cfisa; | |||
5898 | /// uintptr_t _swift_rc; | |||
5899 | /// _Atomic(uint64_t) _cfinfoa; | |||
5900 | /// const char *_ptr; | |||
5901 | /// uintptr_t _length; | |||
5902 | /// } __NSConstantString; | |||
5903 | ||||
5904 | const auto CFRuntime = getLangOpts().CFRuntime; | |||
5905 | if (static_cast<unsigned>(CFRuntime) < | |||
5906 | static_cast<unsigned>(LangOptions::CoreFoundationABI::Swift)) { | |||
5907 | Fields[Count++] = { getPointerType(IntTy.withConst()), "isa" }; | |||
5908 | Fields[Count++] = { IntTy, "flags" }; | |||
5909 | Fields[Count++] = { getPointerType(CharTy.withConst()), "str" }; | |||
5910 | Fields[Count++] = { LongTy, "length" }; | |||
5911 | } else { | |||
5912 | Fields[Count++] = { getUIntPtrType(), "_cfisa" }; | |||
5913 | Fields[Count++] = { getUIntPtrType(), "_swift_rc" }; | |||
5914 | Fields[Count++] = { getFromTargetType(Target->getUInt64Type()), "_swift_rc" }; | |||
5915 | Fields[Count++] = { getPointerType(CharTy.withConst()), "_ptr" }; | |||
5916 | if (CFRuntime == LangOptions::CoreFoundationABI::Swift4_1 || | |||
5917 | CFRuntime == LangOptions::CoreFoundationABI::Swift4_2) | |||
5918 | Fields[Count++] = { IntTy, "_ptr" }; | |||
5919 | else | |||
5920 | Fields[Count++] = { getUIntPtrType(), "_ptr" }; | |||
5921 | } | |||
5922 | ||||
5923 | // Create fields | |||
5924 | for (unsigned i = 0; i < Count; ++i) { | |||
5925 | FieldDecl *Field = | |||
5926 | FieldDecl::Create(*this, CFConstantStringTagDecl, SourceLocation(), | |||
5927 | SourceLocation(), &Idents.get(Fields[i].Name), | |||
5928 | Fields[i].Type, /*TInfo=*/nullptr, | |||
5929 | /*BitWidth=*/nullptr, /*Mutable=*/false, ICIS_NoInit); | |||
5930 | Field->setAccess(AS_public); | |||
5931 | CFConstantStringTagDecl->addDecl(Field); | |||
5932 | } | |||
5933 | ||||
5934 | CFConstantStringTagDecl->completeDefinition(); | |||
5935 | // This type is designed to be compatible with NSConstantString, but cannot | |||
5936 | // use the same name, since NSConstantString is an interface. | |||
5937 | auto tagType = getTagDeclType(CFConstantStringTagDecl); | |||
5938 | CFConstantStringTypeDecl = | |||
5939 | buildImplicitTypedef(tagType, "__NSConstantString"); | |||
5940 | ||||
5941 | return CFConstantStringTypeDecl; | |||
5942 | } | |||
5943 | ||||
5944 | RecordDecl *ASTContext::getCFConstantStringTagDecl() const { | |||
5945 | if (!CFConstantStringTagDecl) | |||
5946 | getCFConstantStringDecl(); // Build the tag and the typedef. | |||
5947 | return CFConstantStringTagDecl; | |||
5948 | } | |||
5949 | ||||
5950 | // getCFConstantStringType - Return the type used for constant CFStrings. | |||
5951 | QualType ASTContext::getCFConstantStringType() const { | |||
5952 | return getTypedefType(getCFConstantStringDecl()); | |||
5953 | } | |||
5954 | ||||
5955 | QualType ASTContext::getObjCSuperType() const { | |||
5956 | if (ObjCSuperType.isNull()) { | |||
5957 | RecordDecl *ObjCSuperTypeDecl = buildImplicitRecord("objc_super"); | |||
5958 | TUDecl->addDecl(ObjCSuperTypeDecl); | |||
5959 | ObjCSuperType = getTagDeclType(ObjCSuperTypeDecl); | |||
5960 | } | |||
5961 | return ObjCSuperType; | |||
5962 | } | |||
5963 | ||||
5964 | void ASTContext::setCFConstantStringType(QualType T) { | |||
5965 | const auto *TD = T->getAs<TypedefType>(); | |||
5966 | assert(TD && "Invalid CFConstantStringType")((TD && "Invalid CFConstantStringType") ? static_cast <void> (0) : __assert_fail ("TD && \"Invalid CFConstantStringType\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5966, __PRETTY_FUNCTION__)); | |||
5967 | CFConstantStringTypeDecl = cast<TypedefDecl>(TD->getDecl()); | |||
5968 | const auto *TagType = | |||
5969 | CFConstantStringTypeDecl->getUnderlyingType()->getAs<RecordType>(); | |||
5970 | assert(TagType && "Invalid CFConstantStringType")((TagType && "Invalid CFConstantStringType") ? static_cast <void> (0) : __assert_fail ("TagType && \"Invalid CFConstantStringType\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 5970, __PRETTY_FUNCTION__)); | |||
5971 | CFConstantStringTagDecl = TagType->getDecl(); | |||
5972 | } | |||
5973 | ||||
5974 | QualType ASTContext::getBlockDescriptorType() const { | |||
5975 | if (BlockDescriptorType) | |||
5976 | return getTagDeclType(BlockDescriptorType); | |||
5977 | ||||
5978 | RecordDecl *RD; | |||
5979 | // FIXME: Needs the FlagAppleBlock bit. | |||
5980 | RD = buildImplicitRecord("__block_descriptor"); | |||
5981 | RD->startDefinition(); | |||
5982 | ||||
5983 | QualType FieldTypes[] = { | |||
5984 | UnsignedLongTy, | |||
5985 | UnsignedLongTy, | |||
5986 | }; | |||
5987 | ||||
5988 | static const char *const FieldNames[] = { | |||
5989 | "reserved", | |||
5990 | "Size" | |||
5991 | }; | |||
5992 | ||||
5993 | for (size_t i = 0; i < 2; ++i) { | |||
5994 | FieldDecl *Field = FieldDecl::Create( | |||
5995 | *this, RD, SourceLocation(), SourceLocation(), | |||
5996 | &Idents.get(FieldNames[i]), FieldTypes[i], /*TInfo=*/nullptr, | |||
5997 | /*BitWidth=*/nullptr, /*Mutable=*/false, ICIS_NoInit); | |||
5998 | Field->setAccess(AS_public); | |||
5999 | RD->addDecl(Field); | |||
6000 | } | |||
6001 | ||||
6002 | RD->completeDefinition(); | |||
6003 | ||||
6004 | BlockDescriptorType = RD; | |||
6005 | ||||
6006 | return getTagDeclType(BlockDescriptorType); | |||
6007 | } | |||
6008 | ||||
6009 | QualType ASTContext::getBlockDescriptorExtendedType() const { | |||
6010 | if (BlockDescriptorExtendedType) | |||
6011 | return getTagDeclType(BlockDescriptorExtendedType); | |||
6012 | ||||
6013 | RecordDecl *RD; | |||
6014 | // FIXME: Needs the FlagAppleBlock bit. | |||
6015 | RD = buildImplicitRecord("__block_descriptor_withcopydispose"); | |||
6016 | RD->startDefinition(); | |||
6017 | ||||
6018 | QualType FieldTypes[] = { | |||
6019 | UnsignedLongTy, | |||
6020 | UnsignedLongTy, | |||
6021 | getPointerType(VoidPtrTy), | |||
6022 | getPointerType(VoidPtrTy) | |||
6023 | }; | |||
6024 | ||||
6025 | static const char *const FieldNames[] = { | |||
6026 | "reserved", | |||
6027 | "Size", | |||
6028 | "CopyFuncPtr", | |||
6029 | "DestroyFuncPtr" | |||
6030 | }; | |||
6031 | ||||
6032 | for (size_t i = 0; i < 4; ++i) { | |||
6033 | FieldDecl *Field = FieldDecl::Create( | |||
6034 | *this, RD, SourceLocation(), SourceLocation(), | |||
6035 | &Idents.get(FieldNames[i]), FieldTypes[i], /*TInfo=*/nullptr, | |||
6036 | /*BitWidth=*/nullptr, | |||
6037 | /*Mutable=*/false, ICIS_NoInit); | |||
6038 | Field->setAccess(AS_public); | |||
6039 | RD->addDecl(Field); | |||
6040 | } | |||
6041 | ||||
6042 | RD->completeDefinition(); | |||
6043 | ||||
6044 | BlockDescriptorExtendedType = RD; | |||
6045 | return getTagDeclType(BlockDescriptorExtendedType); | |||
6046 | } | |||
6047 | ||||
6048 | TargetInfo::OpenCLTypeKind ASTContext::getOpenCLTypeKind(const Type *T) const { | |||
6049 | const auto *BT = dyn_cast<BuiltinType>(T); | |||
6050 | ||||
6051 | if (!BT) { | |||
6052 | if (isa<PipeType>(T)) | |||
6053 | return TargetInfo::OCLTK_Pipe; | |||
6054 | ||||
6055 | return TargetInfo::OCLTK_Default; | |||
6056 | } | |||
6057 | ||||
6058 | switch (BT->getKind()) { | |||
6059 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ | |||
6060 | case BuiltinType::Id: \ | |||
6061 | return TargetInfo::OCLTK_Image; | |||
6062 | #include "clang/Basic/OpenCLImageTypes.def" | |||
6063 | ||||
6064 | case BuiltinType::OCLClkEvent: | |||
6065 | return TargetInfo::OCLTK_ClkEvent; | |||
6066 | ||||
6067 | case BuiltinType::OCLEvent: | |||
6068 | return TargetInfo::OCLTK_Event; | |||
6069 | ||||
6070 | case BuiltinType::OCLQueue: | |||
6071 | return TargetInfo::OCLTK_Queue; | |||
6072 | ||||
6073 | case BuiltinType::OCLReserveID: | |||
6074 | return TargetInfo::OCLTK_ReserveID; | |||
6075 | ||||
6076 | case BuiltinType::OCLSampler: | |||
6077 | return TargetInfo::OCLTK_Sampler; | |||
6078 | ||||
6079 | default: | |||
6080 | return TargetInfo::OCLTK_Default; | |||
6081 | } | |||
6082 | } | |||
6083 | ||||
6084 | LangAS ASTContext::getOpenCLTypeAddrSpace(const Type *T) const { | |||
6085 | return Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T)); | |||
6086 | } | |||
6087 | ||||
6088 | /// BlockRequiresCopying - Returns true if byref variable "D" of type "Ty" | |||
6089 | /// requires copy/dispose. Note that this must match the logic | |||
6090 | /// in buildByrefHelpers. | |||
6091 | bool ASTContext::BlockRequiresCopying(QualType Ty, | |||
6092 | const VarDecl *D) { | |||
6093 | if (const CXXRecordDecl *record = Ty->getAsCXXRecordDecl()) { | |||
6094 | const Expr *copyExpr = getBlockVarCopyInit(D).getCopyExpr(); | |||
6095 | if (!copyExpr && record->hasTrivialDestructor()) return false; | |||
6096 | ||||
6097 | return true; | |||
6098 | } | |||
6099 | ||||
6100 | // The block needs copy/destroy helpers if Ty is non-trivial to destructively | |||
6101 | // move or destroy. | |||
6102 | if (Ty.isNonTrivialToPrimitiveDestructiveMove() || Ty.isDestructedType()) | |||
6103 | return true; | |||
6104 | ||||
6105 | if (!Ty->isObjCRetainableType()) return false; | |||
6106 | ||||
6107 | Qualifiers qs = Ty.getQualifiers(); | |||
6108 | ||||
6109 | // If we have lifetime, that dominates. | |||
6110 | if (Qualifiers::ObjCLifetime lifetime = qs.getObjCLifetime()) { | |||
6111 | switch (lifetime) { | |||
6112 | case Qualifiers::OCL_None: llvm_unreachable("impossible")::llvm::llvm_unreachable_internal("impossible", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 6112); | |||
6113 | ||||
6114 | // These are just bits as far as the runtime is concerned. | |||
6115 | case Qualifiers::OCL_ExplicitNone: | |||
6116 | case Qualifiers::OCL_Autoreleasing: | |||
6117 | return false; | |||
6118 | ||||
6119 | // These cases should have been taken care of when checking the type's | |||
6120 | // non-triviality. | |||
6121 | case Qualifiers::OCL_Weak: | |||
6122 | case Qualifiers::OCL_Strong: | |||
6123 | llvm_unreachable("impossible")::llvm::llvm_unreachable_internal("impossible", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 6123); | |||
6124 | } | |||
6125 | llvm_unreachable("fell out of lifetime switch!")::llvm::llvm_unreachable_internal("fell out of lifetime switch!" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 6125); | |||
6126 | } | |||
6127 | return (Ty->isBlockPointerType() || isObjCNSObjectType(Ty) || | |||
6128 | Ty->isObjCObjectPointerType()); | |||
6129 | } | |||
6130 | ||||
6131 | bool ASTContext::getByrefLifetime(QualType Ty, | |||
6132 | Qualifiers::ObjCLifetime &LifeTime, | |||
6133 | bool &HasByrefExtendedLayout) const { | |||
6134 | if (!getLangOpts().ObjC || | |||
6135 | getLangOpts().getGC() != LangOptions::NonGC) | |||
6136 | return false; | |||
6137 | ||||
6138 | HasByrefExtendedLayout = false; | |||
6139 | if (Ty->isRecordType()) { | |||
6140 | HasByrefExtendedLayout = true; | |||
6141 | LifeTime = Qualifiers::OCL_None; | |||
6142 | } else if ((LifeTime = Ty.getObjCLifetime())) { | |||
6143 | // Honor the ARC qualifiers. | |||
6144 | } else if (Ty->isObjCObjectPointerType() || Ty->isBlockPointerType()) { | |||
6145 | // The MRR rule. | |||
6146 | LifeTime = Qualifiers::OCL_ExplicitNone; | |||
6147 | } else { | |||
6148 | LifeTime = Qualifiers::OCL_None; | |||
6149 | } | |||
6150 | return true; | |||
6151 | } | |||
6152 | ||||
6153 | TypedefDecl *ASTContext::getObjCInstanceTypeDecl() { | |||
6154 | if (!ObjCInstanceTypeDecl) | |||
6155 | ObjCInstanceTypeDecl = | |||
6156 | buildImplicitTypedef(getObjCIdType(), "instancetype"); | |||
6157 | return ObjCInstanceTypeDecl; | |||
6158 | } | |||
6159 | ||||
6160 | // This returns true if a type has been typedefed to BOOL: | |||
6161 | // typedef <type> BOOL; | |||
6162 | static bool isTypeTypedefedAsBOOL(QualType T) { | |||
6163 | if (const auto *TT = dyn_cast<TypedefType>(T)) | |||
6164 | if (IdentifierInfo *II = TT->getDecl()->getIdentifier()) | |||
6165 | return II->isStr("BOOL"); | |||
6166 | ||||
6167 | return false; | |||
6168 | } | |||
6169 | ||||
6170 | /// getObjCEncodingTypeSize returns size of type for objective-c encoding | |||
6171 | /// purpose. | |||
6172 | CharUnits ASTContext::getObjCEncodingTypeSize(QualType type) const { | |||
6173 | if (!type->isIncompleteArrayType() && type->isIncompleteType()) | |||
6174 | return CharUnits::Zero(); | |||
6175 | ||||
6176 | CharUnits sz = getTypeSizeInChars(type); | |||
6177 | ||||
6178 | // Make all integer and enum types at least as large as an int | |||
6179 | if (sz.isPositive() && type->isIntegralOrEnumerationType()) | |||
6180 | sz = std::max(sz, getTypeSizeInChars(IntTy)); | |||
6181 | // Treat arrays as pointers, since that's how they're passed in. | |||
6182 | else if (type->isArrayType()) | |||
6183 | sz = getTypeSizeInChars(VoidPtrTy); | |||
6184 | return sz; | |||
6185 | } | |||
6186 | ||||
6187 | bool ASTContext::isMSStaticDataMemberInlineDefinition(const VarDecl *VD) const { | |||
6188 | return getTargetInfo().getCXXABI().isMicrosoft() && | |||
6189 | VD->isStaticDataMember() && | |||
6190 | VD->getType()->isIntegralOrEnumerationType() && | |||
6191 | !VD->getFirstDecl()->isOutOfLine() && VD->getFirstDecl()->hasInit(); | |||
6192 | } | |||
6193 | ||||
6194 | ASTContext::InlineVariableDefinitionKind | |||
6195 | ASTContext::getInlineVariableDefinitionKind(const VarDecl *VD) const { | |||
6196 | if (!VD->isInline()) | |||
6197 | return InlineVariableDefinitionKind::None; | |||
6198 | ||||
6199 | // In almost all cases, it's a weak definition. | |||
6200 | auto *First = VD->getFirstDecl(); | |||
6201 | if (First->isInlineSpecified() || !First->isStaticDataMember()) | |||
6202 | return InlineVariableDefinitionKind::Weak; | |||
6203 | ||||
6204 | // If there's a file-context declaration in this translation unit, it's a | |||
6205 | // non-discardable definition. | |||
6206 | for (auto *D : VD->redecls()) | |||
6207 | if (D->getLexicalDeclContext()->isFileContext() && | |||
6208 | !D->isInlineSpecified() && (D->isConstexpr() || First->isConstexpr())) | |||
6209 | return InlineVariableDefinitionKind::Strong; | |||
6210 | ||||
6211 | // If we've not seen one yet, we don't know. | |||
6212 | return InlineVariableDefinitionKind::WeakUnknown; | |||
6213 | } | |||
6214 | ||||
6215 | static std::string charUnitsToString(const CharUnits &CU) { | |||
6216 | return llvm::itostr(CU.getQuantity()); | |||
6217 | } | |||
6218 | ||||
6219 | /// getObjCEncodingForBlock - Return the encoded type for this block | |||
6220 | /// declaration. | |||
6221 | std::string ASTContext::getObjCEncodingForBlock(const BlockExpr *Expr) const { | |||
6222 | std::string S; | |||
6223 | ||||
6224 | const BlockDecl *Decl = Expr->getBlockDecl(); | |||
6225 | QualType BlockTy = | |||
6226 | Expr->getType()->getAs<BlockPointerType>()->getPointeeType(); | |||
6227 | // Encode result type. | |||
6228 | if (getLangOpts().EncodeExtendedBlockSig) | |||
6229 | getObjCEncodingForMethodParameter( | |||
6230 | Decl::OBJC_TQ_None, BlockTy->getAs<FunctionType>()->getReturnType(), S, | |||
6231 | true /*Extended*/); | |||
6232 | else | |||
6233 | getObjCEncodingForType(BlockTy->getAs<FunctionType>()->getReturnType(), S); | |||
6234 | // Compute size of all parameters. | |||
6235 | // Start with computing size of a pointer in number of bytes. | |||
6236 | // FIXME: There might(should) be a better way of doing this computation! | |||
6237 | CharUnits PtrSize = getTypeSizeInChars(VoidPtrTy); | |||
6238 | CharUnits ParmOffset = PtrSize; | |||
6239 | for (auto PI : Decl->parameters()) { | |||
6240 | QualType PType = PI->getType(); | |||
6241 | CharUnits sz = getObjCEncodingTypeSize(PType); | |||
6242 | if (sz.isZero()) | |||
6243 | continue; | |||
6244 | assert(sz.isPositive() && "BlockExpr - Incomplete param type")((sz.isPositive() && "BlockExpr - Incomplete param type" ) ? static_cast<void> (0) : __assert_fail ("sz.isPositive() && \"BlockExpr - Incomplete param type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 6244, __PRETTY_FUNCTION__)); | |||
6245 | ParmOffset += sz; | |||
6246 | } | |||
6247 | // Size of the argument frame | |||
6248 | S += charUnitsToString(ParmOffset); | |||
6249 | // Block pointer and offset. | |||
6250 | S += "@?0"; | |||
6251 | ||||
6252 | // Argument types. | |||
6253 | ParmOffset = PtrSize; | |||
6254 | for (auto PVDecl : Decl->parameters()) { | |||
6255 | QualType PType = PVDecl->getOriginalType(); | |||
6256 | if (const auto *AT = | |||
6257 | dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) { | |||
6258 | // Use array's original type only if it has known number of | |||
6259 | // elements. | |||
6260 | if (!isa<ConstantArrayType>(AT)) | |||
6261 | PType = PVDecl->getType(); | |||
6262 | } else if (PType->isFunctionType()) | |||
6263 | PType = PVDecl->getType(); | |||
6264 | if (getLangOpts().EncodeExtendedBlockSig) | |||
6265 | getObjCEncodingForMethodParameter(Decl::OBJC_TQ_None, PType, | |||
6266 | S, true /*Extended*/); | |||
6267 | else | |||
6268 | getObjCEncodingForType(PType, S); | |||
6269 | S += charUnitsToString(ParmOffset); | |||
6270 | ParmOffset += getObjCEncodingTypeSize(PType); | |||
6271 | } | |||
6272 | ||||
6273 | return S; | |||
6274 | } | |||
6275 | ||||
6276 | std::string | |||
6277 | ASTContext::getObjCEncodingForFunctionDecl(const FunctionDecl *Decl) const { | |||
6278 | std::string S; | |||
6279 | // Encode result type. | |||
6280 | getObjCEncodingForType(Decl->getReturnType(), S); | |||
6281 | CharUnits ParmOffset; | |||
6282 | // Compute size of all parameters. | |||
6283 | for (auto PI : Decl->parameters()) { | |||
6284 | QualType PType = PI->getType(); | |||
6285 | CharUnits sz = getObjCEncodingTypeSize(PType); | |||
6286 | if (sz.isZero()) | |||
6287 | continue; | |||
6288 | ||||
6289 | assert(sz.isPositive() &&((sz.isPositive() && "getObjCEncodingForFunctionDecl - Incomplete param type" ) ? static_cast<void> (0) : __assert_fail ("sz.isPositive() && \"getObjCEncodingForFunctionDecl - Incomplete param type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 6290, __PRETTY_FUNCTION__)) | |||
6290 | "getObjCEncodingForFunctionDecl - Incomplete param type")((sz.isPositive() && "getObjCEncodingForFunctionDecl - Incomplete param type" ) ? static_cast<void> (0) : __assert_fail ("sz.isPositive() && \"getObjCEncodingForFunctionDecl - Incomplete param type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 6290, __PRETTY_FUNCTION__)); | |||
6291 | ParmOffset += sz; | |||
6292 | } | |||
6293 | S += charUnitsToString(ParmOffset); | |||
6294 | ParmOffset = CharUnits::Zero(); | |||
6295 | ||||
6296 | // Argument types. | |||
6297 | for (auto PVDecl : Decl->parameters()) { | |||
6298 | QualType PType = PVDecl->getOriginalType(); | |||
6299 | if (const auto *AT = | |||
6300 | dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) { | |||
6301 | // Use array's original type only if it has known number of | |||
6302 | // elements. | |||
6303 | if (!isa<ConstantArrayType>(AT)) | |||
6304 | PType = PVDecl->getType(); | |||
6305 | } else if (PType->isFunctionType()) | |||
6306 | PType = PVDecl->getType(); | |||
6307 | getObjCEncodingForType(PType, S); | |||
6308 | S += charUnitsToString(ParmOffset); | |||
6309 | ParmOffset += getObjCEncodingTypeSize(PType); | |||
6310 | } | |||
6311 | ||||
6312 | return S; | |||
6313 | } | |||
6314 | ||||
6315 | /// getObjCEncodingForMethodParameter - Return the encoded type for a single | |||
6316 | /// method parameter or return type. If Extended, include class names and | |||
6317 | /// block object types. | |||
6318 | void ASTContext::getObjCEncodingForMethodParameter(Decl::ObjCDeclQualifier QT, | |||
6319 | QualType T, std::string& S, | |||
6320 | bool Extended) const { | |||
6321 | // Encode type qualifer, 'in', 'inout', etc. for the parameter. | |||
6322 | getObjCEncodingForTypeQualifier(QT, S); | |||
6323 | // Encode parameter type. | |||
6324 | ObjCEncOptions Options = ObjCEncOptions() | |||
6325 | .setExpandPointedToStructures() | |||
6326 | .setExpandStructures() | |||
6327 | .setIsOutermostType(); | |||
6328 | if (Extended) | |||
6329 | Options.setEncodeBlockParameters().setEncodeClassNames(); | |||
6330 | getObjCEncodingForTypeImpl(T, S, Options, /*Field=*/nullptr); | |||
6331 | } | |||
6332 | ||||
6333 | /// getObjCEncodingForMethodDecl - Return the encoded type for this method | |||
6334 | /// declaration. | |||
6335 | std::string ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, | |||
6336 | bool Extended) const { | |||
6337 | // FIXME: This is not very efficient. | |||
6338 | // Encode return type. | |||
6339 | std::string S; | |||
6340 | getObjCEncodingForMethodParameter(Decl->getObjCDeclQualifier(), | |||
6341 | Decl->getReturnType(), S, Extended); | |||
6342 | // Compute size of all parameters. | |||
6343 | // Start with computing size of a pointer in number of bytes. | |||
6344 | // FIXME: There might(should) be a better way of doing this computation! | |||
6345 | CharUnits PtrSize = getTypeSizeInChars(VoidPtrTy); | |||
6346 | // The first two arguments (self and _cmd) are pointers; account for | |||
6347 | // their size. | |||
6348 | CharUnits ParmOffset = 2 * PtrSize; | |||
6349 | for (ObjCMethodDecl::param_const_iterator PI = Decl->param_begin(), | |||
6350 | E = Decl->sel_param_end(); PI != E; ++PI) { | |||
6351 | QualType PType = (*PI)->getType(); | |||
6352 | CharUnits sz = getObjCEncodingTypeSize(PType); | |||
6353 | if (sz.isZero()) | |||
6354 | continue; | |||
6355 | ||||
6356 | assert(sz.isPositive() &&((sz.isPositive() && "getObjCEncodingForMethodDecl - Incomplete param type" ) ? static_cast<void> (0) : __assert_fail ("sz.isPositive() && \"getObjCEncodingForMethodDecl - Incomplete param type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 6357, __PRETTY_FUNCTION__)) | |||
6357 | "getObjCEncodingForMethodDecl - Incomplete param type")((sz.isPositive() && "getObjCEncodingForMethodDecl - Incomplete param type" ) ? static_cast<void> (0) : __assert_fail ("sz.isPositive() && \"getObjCEncodingForMethodDecl - Incomplete param type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 6357, __PRETTY_FUNCTION__)); | |||
6358 | ParmOffset += sz; | |||
6359 | } | |||
6360 | S += charUnitsToString(ParmOffset); | |||
6361 | S += "@0:"; | |||
6362 | S += charUnitsToString(PtrSize); | |||
6363 | ||||
6364 | // Argument types. | |||
6365 | ParmOffset = 2 * PtrSize; | |||
6366 | for (ObjCMethodDecl::param_const_iterator PI = Decl->param_begin(), | |||
6367 | E = Decl->sel_param_end(); PI != E; ++PI) { | |||
6368 | const ParmVarDecl *PVDecl = *PI; | |||
6369 | QualType PType = PVDecl->getOriginalType(); | |||
6370 | if (const auto *AT = | |||
6371 | dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) { | |||
6372 | // Use array's original type only if it has known number of | |||
6373 | // elements. | |||
6374 | if (!isa<ConstantArrayType>(AT)) | |||
6375 | PType = PVDecl->getType(); | |||
6376 | } else if (PType->isFunctionType()) | |||
6377 | PType = PVDecl->getType(); | |||
6378 | getObjCEncodingForMethodParameter(PVDecl->getObjCDeclQualifier(), | |||
6379 | PType, S, Extended); | |||
6380 | S += charUnitsToString(ParmOffset); | |||
6381 | ParmOffset += getObjCEncodingTypeSize(PType); | |||
6382 | } | |||
6383 | ||||
6384 | return S; | |||
6385 | } | |||
6386 | ||||
6387 | ObjCPropertyImplDecl * | |||
6388 | ASTContext::getObjCPropertyImplDeclForPropertyDecl( | |||
6389 | const ObjCPropertyDecl *PD, | |||
6390 | const Decl *Container) const { | |||
6391 | if (!Container) | |||
6392 | return nullptr; | |||
6393 | if (const auto *CID = dyn_cast<ObjCCategoryImplDecl>(Container)) { | |||
6394 | for (auto *PID : CID->property_impls()) | |||
6395 | if (PID->getPropertyDecl() == PD) | |||
6396 | return PID; | |||
6397 | } else { | |||
6398 | const auto *OID = cast<ObjCImplementationDecl>(Container); | |||
6399 | for (auto *PID : OID->property_impls()) | |||
6400 | if (PID->getPropertyDecl() == PD) | |||
6401 | return PID; | |||
6402 | } | |||
6403 | return nullptr; | |||
6404 | } | |||
6405 | ||||
6406 | /// getObjCEncodingForPropertyDecl - Return the encoded type for this | |||
6407 | /// property declaration. If non-NULL, Container must be either an | |||
6408 | /// ObjCCategoryImplDecl or ObjCImplementationDecl; it should only be | |||
6409 | /// NULL when getting encodings for protocol properties. | |||
6410 | /// Property attributes are stored as a comma-delimited C string. The simple | |||
6411 | /// attributes readonly and bycopy are encoded as single characters. The | |||
6412 | /// parametrized attributes, getter=name, setter=name, and ivar=name, are | |||
6413 | /// encoded as single characters, followed by an identifier. Property types | |||
6414 | /// are also encoded as a parametrized attribute. The characters used to encode | |||
6415 | /// these attributes are defined by the following enumeration: | |||
6416 | /// @code | |||
6417 | /// enum PropertyAttributes { | |||
6418 | /// kPropertyReadOnly = 'R', // property is read-only. | |||
6419 | /// kPropertyBycopy = 'C', // property is a copy of the value last assigned | |||
6420 | /// kPropertyByref = '&', // property is a reference to the value last assigned | |||
6421 | /// kPropertyDynamic = 'D', // property is dynamic | |||
6422 | /// kPropertyGetter = 'G', // followed by getter selector name | |||
6423 | /// kPropertySetter = 'S', // followed by setter selector name | |||
6424 | /// kPropertyInstanceVariable = 'V' // followed by instance variable name | |||
6425 | /// kPropertyType = 'T' // followed by old-style type encoding. | |||
6426 | /// kPropertyWeak = 'W' // 'weak' property | |||
6427 | /// kPropertyStrong = 'P' // property GC'able | |||
6428 | /// kPropertyNonAtomic = 'N' // property non-atomic | |||
6429 | /// }; | |||
6430 | /// @endcode | |||
6431 | std::string | |||
6432 | ASTContext::getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD, | |||
6433 | const Decl *Container) const { | |||
6434 | // Collect information from the property implementation decl(s). | |||
6435 | bool Dynamic = false; | |||
6436 | ObjCPropertyImplDecl *SynthesizePID = nullptr; | |||
6437 | ||||
6438 | if (ObjCPropertyImplDecl *PropertyImpDecl = | |||
6439 | getObjCPropertyImplDeclForPropertyDecl(PD, Container)) { | |||
6440 | if (PropertyImpDecl->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic) | |||
6441 | Dynamic = true; | |||
6442 | else | |||
6443 | SynthesizePID = PropertyImpDecl; | |||
6444 | } | |||
6445 | ||||
6446 | // FIXME: This is not very efficient. | |||
6447 | std::string S = "T"; | |||
6448 | ||||
6449 | // Encode result type. | |||
6450 | // GCC has some special rules regarding encoding of properties which | |||
6451 | // closely resembles encoding of ivars. | |||
6452 | getObjCEncodingForPropertyType(PD->getType(), S); | |||
6453 | ||||
6454 | if (PD->isReadOnly()) { | |||
6455 | S += ",R"; | |||
6456 | if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) | |||
6457 | S += ",C"; | |||
6458 | if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) | |||
6459 | S += ",&"; | |||
6460 | if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_weak) | |||
6461 | S += ",W"; | |||
6462 | } else { | |||
6463 | switch (PD->getSetterKind()) { | |||
6464 | case ObjCPropertyDecl::Assign: break; | |||
6465 | case ObjCPropertyDecl::Copy: S += ",C"; break; | |||
6466 | case ObjCPropertyDecl::Retain: S += ",&"; break; | |||
6467 | case ObjCPropertyDecl::Weak: S += ",W"; break; | |||
6468 | } | |||
6469 | } | |||
6470 | ||||
6471 | // It really isn't clear at all what this means, since properties | |||
6472 | // are "dynamic by default". | |||
6473 | if (Dynamic) | |||
6474 | S += ",D"; | |||
6475 | ||||
6476 | if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_nonatomic) | |||
6477 | S += ",N"; | |||
6478 | ||||
6479 | if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) { | |||
6480 | S += ",G"; | |||
6481 | S += PD->getGetterName().getAsString(); | |||
6482 | } | |||
6483 | ||||
6484 | if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) { | |||
6485 | S += ",S"; | |||
6486 | S += PD->getSetterName().getAsString(); | |||
6487 | } | |||
6488 | ||||
6489 | if (SynthesizePID) { | |||
6490 | const ObjCIvarDecl *OID = SynthesizePID->getPropertyIvarDecl(); | |||
6491 | S += ",V"; | |||
6492 | S += OID->getNameAsString(); | |||
6493 | } | |||
6494 | ||||
6495 | // FIXME: OBJCGC: weak & strong | |||
6496 | return S; | |||
6497 | } | |||
6498 | ||||
6499 | /// getLegacyIntegralTypeEncoding - | |||
6500 | /// Another legacy compatibility encoding: 32-bit longs are encoded as | |||
6501 | /// 'l' or 'L' , but not always. For typedefs, we need to use | |||
6502 | /// 'i' or 'I' instead if encoding a struct field, or a pointer! | |||
6503 | void ASTContext::getLegacyIntegralTypeEncoding (QualType &PointeeTy) const { | |||
6504 | if (isa<TypedefType>(PointeeTy.getTypePtr())) { | |||
6505 | if (const auto *BT = PointeeTy->getAs<BuiltinType>()) { | |||
6506 | if (BT->getKind() == BuiltinType::ULong && getIntWidth(PointeeTy) == 32) | |||
6507 | PointeeTy = UnsignedIntTy; | |||
6508 | else | |||
6509 | if (BT->getKind() == BuiltinType::Long && getIntWidth(PointeeTy) == 32) | |||
6510 | PointeeTy = IntTy; | |||
6511 | } | |||
6512 | } | |||
6513 | } | |||
6514 | ||||
6515 | void ASTContext::getObjCEncodingForType(QualType T, std::string& S, | |||
6516 | const FieldDecl *Field, | |||
6517 | QualType *NotEncodedT) const { | |||
6518 | // We follow the behavior of gcc, expanding structures which are | |||
6519 | // directly pointed to, and expanding embedded structures. Note that | |||
6520 | // these rules are sufficient to prevent recursive encoding of the | |||
6521 | // same type. | |||
6522 | getObjCEncodingForTypeImpl(T, S, | |||
6523 | ObjCEncOptions() | |||
6524 | .setExpandPointedToStructures() | |||
6525 | .setExpandStructures() | |||
6526 | .setIsOutermostType(), | |||
6527 | Field, NotEncodedT); | |||
6528 | } | |||
6529 | ||||
6530 | void ASTContext::getObjCEncodingForPropertyType(QualType T, | |||
6531 | std::string& S) const { | |||
6532 | // Encode result type. | |||
6533 | // GCC has some special rules regarding encoding of properties which | |||
6534 | // closely resembles encoding of ivars. | |||
6535 | getObjCEncodingForTypeImpl(T, S, | |||
6536 | ObjCEncOptions() | |||
6537 | .setExpandPointedToStructures() | |||
6538 | .setExpandStructures() | |||
6539 | .setIsOutermostType() | |||
6540 | .setEncodingProperty(), | |||
6541 | /*Field=*/nullptr); | |||
6542 | } | |||
6543 | ||||
6544 | static char getObjCEncodingForPrimitiveKind(const ASTContext *C, | |||
6545 | BuiltinType::Kind kind) { | |||
6546 | switch (kind) { | |||
6547 | case BuiltinType::Void: return 'v'; | |||
6548 | case BuiltinType::Bool: return 'B'; | |||
6549 | case BuiltinType::Char8: | |||
6550 | case BuiltinType::Char_U: | |||
6551 | case BuiltinType::UChar: return 'C'; | |||
6552 | case BuiltinType::Char16: | |||
6553 | case BuiltinType::UShort: return 'S'; | |||
6554 | case BuiltinType::Char32: | |||
6555 | case BuiltinType::UInt: return 'I'; | |||
6556 | case BuiltinType::ULong: | |||
6557 | return C->getTargetInfo().getLongWidth() == 32 ? 'L' : 'Q'; | |||
6558 | case BuiltinType::UInt128: return 'T'; | |||
6559 | case BuiltinType::ULongLong: return 'Q'; | |||
6560 | case BuiltinType::Char_S: | |||
6561 | case BuiltinType::SChar: return 'c'; | |||
6562 | case BuiltinType::Short: return 's'; | |||
6563 | case BuiltinType::WChar_S: | |||
6564 | case BuiltinType::WChar_U: | |||
6565 | case BuiltinType::Int: return 'i'; | |||
6566 | case BuiltinType::Long: | |||
6567 | return C->getTargetInfo().getLongWidth() == 32 ? 'l' : 'q'; | |||
6568 | case BuiltinType::LongLong: return 'q'; | |||
6569 | case BuiltinType::Int128: return 't'; | |||
6570 | case BuiltinType::Float: return 'f'; | |||
6571 | case BuiltinType::Double: return 'd'; | |||
6572 | case BuiltinType::LongDouble: return 'D'; | |||
6573 | case BuiltinType::NullPtr: return '*'; // like char* | |||
6574 | ||||
6575 | case BuiltinType::Float16: | |||
6576 | case BuiltinType::Float128: | |||
6577 | case BuiltinType::Half: | |||
6578 | case BuiltinType::ShortAccum: | |||
6579 | case BuiltinType::Accum: | |||
6580 | case BuiltinType::LongAccum: | |||
6581 | case BuiltinType::UShortAccum: | |||
6582 | case BuiltinType::UAccum: | |||
6583 | case BuiltinType::ULongAccum: | |||
6584 | case BuiltinType::ShortFract: | |||
6585 | case BuiltinType::Fract: | |||
6586 | case BuiltinType::LongFract: | |||
6587 | case BuiltinType::UShortFract: | |||
6588 | case BuiltinType::UFract: | |||
6589 | case BuiltinType::ULongFract: | |||
6590 | case BuiltinType::SatShortAccum: | |||
6591 | case BuiltinType::SatAccum: | |||
6592 | case BuiltinType::SatLongAccum: | |||
6593 | case BuiltinType::SatUShortAccum: | |||
6594 | case BuiltinType::SatUAccum: | |||
6595 | case BuiltinType::SatULongAccum: | |||
6596 | case BuiltinType::SatShortFract: | |||
6597 | case BuiltinType::SatFract: | |||
6598 | case BuiltinType::SatLongFract: | |||
6599 | case BuiltinType::SatUShortFract: | |||
6600 | case BuiltinType::SatUFract: | |||
6601 | case BuiltinType::SatULongFract: | |||
6602 | // FIXME: potentially need @encodes for these! | |||
6603 | return ' '; | |||
6604 | ||||
6605 | case BuiltinType::ObjCId: | |||
6606 | case BuiltinType::ObjCClass: | |||
6607 | case BuiltinType::ObjCSel: | |||
6608 | llvm_unreachable("@encoding ObjC primitive type")::llvm::llvm_unreachable_internal("@encoding ObjC primitive type" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 6608); | |||
6609 | ||||
6610 | // OpenCL and placeholder types don't need @encodings. | |||
6611 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ | |||
6612 | case BuiltinType::Id: | |||
6613 | #include "clang/Basic/OpenCLImageTypes.def" | |||
6614 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ | |||
6615 | case BuiltinType::Id: | |||
6616 | #include "clang/Basic/OpenCLExtensionTypes.def" | |||
6617 | case BuiltinType::OCLEvent: | |||
6618 | case BuiltinType::OCLClkEvent: | |||
6619 | case BuiltinType::OCLQueue: | |||
6620 | case BuiltinType::OCLReserveID: | |||
6621 | case BuiltinType::OCLSampler: | |||
6622 | case BuiltinType::Dependent: | |||
6623 | #define BUILTIN_TYPE(KIND, ID) | |||
6624 | #define PLACEHOLDER_TYPE(KIND, ID) \ | |||
6625 | case BuiltinType::KIND: | |||
6626 | #include "clang/AST/BuiltinTypes.def" | |||
6627 | llvm_unreachable("invalid builtin type for @encode")::llvm::llvm_unreachable_internal("invalid builtin type for @encode" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 6627); | |||
6628 | } | |||
6629 | llvm_unreachable("invalid BuiltinType::Kind value")::llvm::llvm_unreachable_internal("invalid BuiltinType::Kind value" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 6629); | |||
6630 | } | |||
6631 | ||||
6632 | static char ObjCEncodingForEnumType(const ASTContext *C, const EnumType *ET) { | |||
6633 | EnumDecl *Enum = ET->getDecl(); | |||
6634 | ||||
6635 | // The encoding of an non-fixed enum type is always 'i', regardless of size. | |||
6636 | if (!Enum->isFixed()) | |||
6637 | return 'i'; | |||
6638 | ||||
6639 | // The encoding of a fixed enum type matches its fixed underlying type. | |||
6640 | const auto *BT = Enum->getIntegerType()->castAs<BuiltinType>(); | |||
6641 | return getObjCEncodingForPrimitiveKind(C, BT->getKind()); | |||
6642 | } | |||
6643 | ||||
6644 | static void EncodeBitField(const ASTContext *Ctx, std::string& S, | |||
6645 | QualType T, const FieldDecl *FD) { | |||
6646 | assert(FD->isBitField() && "not a bitfield - getObjCEncodingForTypeImpl")((FD->isBitField() && "not a bitfield - getObjCEncodingForTypeImpl" ) ? static_cast<void> (0) : __assert_fail ("FD->isBitField() && \"not a bitfield - getObjCEncodingForTypeImpl\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 6646, __PRETTY_FUNCTION__)); | |||
6647 | S += 'b'; | |||
6648 | // The NeXT runtime encodes bit fields as b followed by the number of bits. | |||
6649 | // The GNU runtime requires more information; bitfields are encoded as b, | |||
6650 | // then the offset (in bits) of the first element, then the type of the | |||
6651 | // bitfield, then the size in bits. For example, in this structure: | |||
6652 | // | |||
6653 | // struct | |||
6654 | // { | |||
6655 | // int integer; | |||
6656 | // int flags:2; | |||
6657 | // }; | |||
6658 | // On a 32-bit system, the encoding for flags would be b2 for the NeXT | |||
6659 | // runtime, but b32i2 for the GNU runtime. The reason for this extra | |||
6660 | // information is not especially sensible, but we're stuck with it for | |||
6661 | // compatibility with GCC, although providing it breaks anything that | |||
6662 | // actually uses runtime introspection and wants to work on both runtimes... | |||
6663 | if (Ctx->getLangOpts().ObjCRuntime.isGNUFamily()) { | |||
6664 | uint64_t Offset; | |||
6665 | ||||
6666 | if (const auto *IVD = dyn_cast<ObjCIvarDecl>(FD)) { | |||
6667 | Offset = Ctx->lookupFieldBitOffset(IVD->getContainingInterface(), nullptr, | |||
6668 | IVD); | |||
6669 | } else { | |||
6670 | const RecordDecl *RD = FD->getParent(); | |||
6671 | const ASTRecordLayout &RL = Ctx->getASTRecordLayout(RD); | |||
6672 | Offset = RL.getFieldOffset(FD->getFieldIndex()); | |||
6673 | } | |||
6674 | ||||
6675 | S += llvm::utostr(Offset); | |||
6676 | ||||
6677 | if (const auto *ET = T->getAs<EnumType>()) | |||
6678 | S += ObjCEncodingForEnumType(Ctx, ET); | |||
6679 | else { | |||
6680 | const auto *BT = T->castAs<BuiltinType>(); | |||
6681 | S += getObjCEncodingForPrimitiveKind(Ctx, BT->getKind()); | |||
6682 | } | |||
6683 | } | |||
6684 | S += llvm::utostr(FD->getBitWidthValue(*Ctx)); | |||
6685 | } | |||
6686 | ||||
6687 | // FIXME: Use SmallString for accumulating string. | |||
6688 | void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string &S, | |||
6689 | const ObjCEncOptions Options, | |||
6690 | const FieldDecl *FD, | |||
6691 | QualType *NotEncodedT) const { | |||
6692 | CanQualType CT = getCanonicalType(T); | |||
6693 | switch (CT->getTypeClass()) { | |||
6694 | case Type::Builtin: | |||
6695 | case Type::Enum: | |||
6696 | if (FD && FD->isBitField()) | |||
6697 | return EncodeBitField(this, S, T, FD); | |||
6698 | if (const auto *BT = dyn_cast<BuiltinType>(CT)) | |||
6699 | S += getObjCEncodingForPrimitiveKind(this, BT->getKind()); | |||
6700 | else | |||
6701 | S += ObjCEncodingForEnumType(this, cast<EnumType>(CT)); | |||
6702 | return; | |||
6703 | ||||
6704 | case Type::Complex: { | |||
6705 | const auto *CT = T->castAs<ComplexType>(); | |||
6706 | S += 'j'; | |||
6707 | getObjCEncodingForTypeImpl(CT->getElementType(), S, ObjCEncOptions(), | |||
6708 | /*Field=*/nullptr); | |||
6709 | return; | |||
6710 | } | |||
6711 | ||||
6712 | case Type::Atomic: { | |||
6713 | const auto *AT = T->castAs<AtomicType>(); | |||
6714 | S += 'A'; | |||
6715 | getObjCEncodingForTypeImpl(AT->getValueType(), S, ObjCEncOptions(), | |||
6716 | /*Field=*/nullptr); | |||
6717 | return; | |||
6718 | } | |||
6719 | ||||
6720 | // encoding for pointer or reference types. | |||
6721 | case Type::Pointer: | |||
6722 | case Type::LValueReference: | |||
6723 | case Type::RValueReference: { | |||
6724 | QualType PointeeTy; | |||
6725 | if (isa<PointerType>(CT)) { | |||
6726 | const auto *PT = T->castAs<PointerType>(); | |||
6727 | if (PT->isObjCSelType()) { | |||
6728 | S += ':'; | |||
6729 | return; | |||
6730 | } | |||
6731 | PointeeTy = PT->getPointeeType(); | |||
6732 | } else { | |||
6733 | PointeeTy = T->castAs<ReferenceType>()->getPointeeType(); | |||
6734 | } | |||
6735 | ||||
6736 | bool isReadOnly = false; | |||
6737 | // For historical/compatibility reasons, the read-only qualifier of the | |||
6738 | // pointee gets emitted _before_ the '^'. The read-only qualifier of | |||
6739 | // the pointer itself gets ignored, _unless_ we are looking at a typedef! | |||
6740 | // Also, do not emit the 'r' for anything but the outermost type! | |||
6741 | if (isa<TypedefType>(T.getTypePtr())) { | |||
6742 | if (Options.IsOutermostType() && T.isConstQualified()) { | |||
6743 | isReadOnly = true; | |||
6744 | S += 'r'; | |||
6745 | } | |||
6746 | } else if (Options.IsOutermostType()) { | |||
6747 | QualType P = PointeeTy; | |||
6748 | while (P->getAs<PointerType>()) | |||
6749 | P = P->getAs<PointerType>()->getPointeeType(); | |||
6750 | if (P.isConstQualified()) { | |||
6751 | isReadOnly = true; | |||
6752 | S += 'r'; | |||
6753 | } | |||
6754 | } | |||
6755 | if (isReadOnly) { | |||
6756 | // Another legacy compatibility encoding. Some ObjC qualifier and type | |||
6757 | // combinations need to be rearranged. | |||
6758 | // Rewrite "in const" from "nr" to "rn" | |||
6759 | if (StringRef(S).endswith("nr")) | |||
6760 | S.replace(S.end()-2, S.end(), "rn"); | |||
6761 | } | |||
6762 | ||||
6763 | if (PointeeTy->isCharType()) { | |||
6764 | // char pointer types should be encoded as '*' unless it is a | |||
6765 | // type that has been typedef'd to 'BOOL'. | |||
6766 | if (!isTypeTypedefedAsBOOL(PointeeTy)) { | |||
6767 | S += '*'; | |||
6768 | return; | |||
6769 | } | |||
6770 | } else if (const auto *RTy = PointeeTy->getAs<RecordType>()) { | |||
6771 | // GCC binary compat: Need to convert "struct objc_class *" to "#". | |||
6772 | if (RTy->getDecl()->getIdentifier() == &Idents.get("objc_class")) { | |||
6773 | S += '#'; | |||
6774 | return; | |||
6775 | } | |||
6776 | // GCC binary compat: Need to convert "struct objc_object *" to "@". | |||
6777 | if (RTy->getDecl()->getIdentifier() == &Idents.get("objc_object")) { | |||
6778 | S += '@'; | |||
6779 | return; | |||
6780 | } | |||
6781 | // fall through... | |||
6782 | } | |||
6783 | S += '^'; | |||
6784 | getLegacyIntegralTypeEncoding(PointeeTy); | |||
6785 | ||||
6786 | ObjCEncOptions NewOptions; | |||
6787 | if (Options.ExpandPointedToStructures()) | |||
6788 | NewOptions.setExpandStructures(); | |||
6789 | getObjCEncodingForTypeImpl(PointeeTy, S, NewOptions, | |||
6790 | /*Field=*/nullptr, NotEncodedT); | |||
6791 | return; | |||
6792 | } | |||
6793 | ||||
6794 | case Type::ConstantArray: | |||
6795 | case Type::IncompleteArray: | |||
6796 | case Type::VariableArray: { | |||
6797 | const auto *AT = cast<ArrayType>(CT); | |||
6798 | ||||
6799 | if (isa<IncompleteArrayType>(AT) && !Options.IsStructField()) { | |||
6800 | // Incomplete arrays are encoded as a pointer to the array element. | |||
6801 | S += '^'; | |||
6802 | ||||
6803 | getObjCEncodingForTypeImpl( | |||
6804 | AT->getElementType(), S, | |||
6805 | Options.keepingOnly(ObjCEncOptions().setExpandStructures()), FD); | |||
6806 | } else { | |||
6807 | S += '['; | |||
6808 | ||||
6809 | if (const auto *CAT = dyn_cast<ConstantArrayType>(AT)) | |||
6810 | S += llvm::utostr(CAT->getSize().getZExtValue()); | |||
6811 | else { | |||
6812 | //Variable length arrays are encoded as a regular array with 0 elements. | |||
6813 | assert((isa<VariableArrayType>(AT) || isa<IncompleteArrayType>(AT)) &&(((isa<VariableArrayType>(AT) || isa<IncompleteArrayType >(AT)) && "Unknown array type!") ? static_cast< void> (0) : __assert_fail ("(isa<VariableArrayType>(AT) || isa<IncompleteArrayType>(AT)) && \"Unknown array type!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 6814, __PRETTY_FUNCTION__)) | |||
6814 | "Unknown array type!")(((isa<VariableArrayType>(AT) || isa<IncompleteArrayType >(AT)) && "Unknown array type!") ? static_cast< void> (0) : __assert_fail ("(isa<VariableArrayType>(AT) || isa<IncompleteArrayType>(AT)) && \"Unknown array type!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 6814, __PRETTY_FUNCTION__)); | |||
6815 | S += '0'; | |||
6816 | } | |||
6817 | ||||
6818 | getObjCEncodingForTypeImpl( | |||
6819 | AT->getElementType(), S, | |||
6820 | Options.keepingOnly(ObjCEncOptions().setExpandStructures()), FD, | |||
6821 | NotEncodedT); | |||
6822 | S += ']'; | |||
6823 | } | |||
6824 | return; | |||
6825 | } | |||
6826 | ||||
6827 | case Type::FunctionNoProto: | |||
6828 | case Type::FunctionProto: | |||
6829 | S += '?'; | |||
6830 | return; | |||
6831 | ||||
6832 | case Type::Record: { | |||
6833 | RecordDecl *RDecl = cast<RecordType>(CT)->getDecl(); | |||
6834 | S += RDecl->isUnion() ? '(' : '{'; | |||
6835 | // Anonymous structures print as '?' | |||
6836 | if (const IdentifierInfo *II = RDecl->getIdentifier()) { | |||
6837 | S += II->getName(); | |||
6838 | if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(RDecl)) { | |||
6839 | const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); | |||
6840 | llvm::raw_string_ostream OS(S); | |||
6841 | printTemplateArgumentList(OS, TemplateArgs.asArray(), | |||
6842 | getPrintingPolicy()); | |||
6843 | } | |||
6844 | } else { | |||
6845 | S += '?'; | |||
6846 | } | |||
6847 | if (Options.ExpandStructures()) { | |||
6848 | S += '='; | |||
6849 | if (!RDecl->isUnion()) { | |||
6850 | getObjCEncodingForStructureImpl(RDecl, S, FD, true, NotEncodedT); | |||
6851 | } else { | |||
6852 | for (const auto *Field : RDecl->fields()) { | |||
6853 | if (FD) { | |||
6854 | S += '"'; | |||
6855 | S += Field->getNameAsString(); | |||
6856 | S += '"'; | |||
6857 | } | |||
6858 | ||||
6859 | // Special case bit-fields. | |||
6860 | if (Field->isBitField()) { | |||
6861 | getObjCEncodingForTypeImpl(Field->getType(), S, | |||
6862 | ObjCEncOptions().setExpandStructures(), | |||
6863 | Field); | |||
6864 | } else { | |||
6865 | QualType qt = Field->getType(); | |||
6866 | getLegacyIntegralTypeEncoding(qt); | |||
6867 | getObjCEncodingForTypeImpl( | |||
6868 | qt, S, | |||
6869 | ObjCEncOptions().setExpandStructures().setIsStructField(), FD, | |||
6870 | NotEncodedT); | |||
6871 | } | |||
6872 | } | |||
6873 | } | |||
6874 | } | |||
6875 | S += RDecl->isUnion() ? ')' : '}'; | |||
6876 | return; | |||
6877 | } | |||
6878 | ||||
6879 | case Type::BlockPointer: { | |||
6880 | const auto *BT = T->castAs<BlockPointerType>(); | |||
6881 | S += "@?"; // Unlike a pointer-to-function, which is "^?". | |||
6882 | if (Options.EncodeBlockParameters()) { | |||
6883 | const auto *FT = BT->getPointeeType()->castAs<FunctionType>(); | |||
6884 | ||||
6885 | S += '<'; | |||
6886 | // Block return type | |||
6887 | getObjCEncodingForTypeImpl(FT->getReturnType(), S, | |||
6888 | Options.forComponentType(), FD, NotEncodedT); | |||
6889 | // Block self | |||
6890 | S += "@?"; | |||
6891 | // Block parameters | |||
6892 | if (const auto *FPT = dyn_cast<FunctionProtoType>(FT)) { | |||
6893 | for (const auto &I : FPT->param_types()) | |||
6894 | getObjCEncodingForTypeImpl(I, S, Options.forComponentType(), FD, | |||
6895 | NotEncodedT); | |||
6896 | } | |||
6897 | S += '>'; | |||
6898 | } | |||
6899 | return; | |||
6900 | } | |||
6901 | ||||
6902 | case Type::ObjCObject: { | |||
6903 | // hack to match legacy encoding of *id and *Class | |||
6904 | QualType Ty = getObjCObjectPointerType(CT); | |||
6905 | if (Ty->isObjCIdType()) { | |||
6906 | S += "{objc_object=}"; | |||
6907 | return; | |||
6908 | } | |||
6909 | else if (Ty->isObjCClassType()) { | |||
6910 | S += "{objc_class=}"; | |||
6911 | return; | |||
6912 | } | |||
6913 | // TODO: Double check to make sure this intentionally falls through. | |||
6914 | LLVM_FALLTHROUGH[[clang::fallthrough]]; | |||
6915 | } | |||
6916 | ||||
6917 | case Type::ObjCInterface: { | |||
6918 | // Ignore protocol qualifiers when mangling at this level. | |||
6919 | // @encode(class_name) | |||
6920 | ObjCInterfaceDecl *OI = T->castAs<ObjCObjectType>()->getInterface(); | |||
6921 | S += '{'; | |||
6922 | S += OI->getObjCRuntimeNameAsString(); | |||
6923 | if (Options.ExpandStructures()) { | |||
6924 | S += '='; | |||
6925 | SmallVector<const ObjCIvarDecl*, 32> Ivars; | |||
6926 | DeepCollectObjCIvars(OI, true, Ivars); | |||
6927 | for (unsigned i = 0, e = Ivars.size(); i != e; ++i) { | |||
6928 | const FieldDecl *Field = Ivars[i]; | |||
6929 | if (Field->isBitField()) | |||
6930 | getObjCEncodingForTypeImpl(Field->getType(), S, | |||
6931 | ObjCEncOptions().setExpandStructures(), | |||
6932 | Field); | |||
6933 | else | |||
6934 | getObjCEncodingForTypeImpl(Field->getType(), S, | |||
6935 | ObjCEncOptions().setExpandStructures(), FD, | |||
6936 | NotEncodedT); | |||
6937 | } | |||
6938 | } | |||
6939 | S += '}'; | |||
6940 | return; | |||
6941 | } | |||
6942 | ||||
6943 | case Type::ObjCObjectPointer: { | |||
6944 | const auto *OPT = T->castAs<ObjCObjectPointerType>(); | |||
6945 | if (OPT->isObjCIdType()) { | |||
6946 | S += '@'; | |||
6947 | return; | |||
6948 | } | |||
6949 | ||||
6950 | if (OPT->isObjCClassType() || OPT->isObjCQualifiedClassType()) { | |||
6951 | // FIXME: Consider if we need to output qualifiers for 'Class<p>'. | |||
6952 | // Since this is a binary compatibility issue, need to consult with | |||
6953 | // runtime folks. Fortunately, this is a *very* obscure construct. | |||
6954 | S += '#'; | |||
6955 | return; | |||
6956 | } | |||
6957 | ||||
6958 | if (OPT->isObjCQualifiedIdType()) { | |||
6959 | getObjCEncodingForTypeImpl( | |||
6960 | getObjCIdType(), S, | |||
6961 | Options.keepingOnly(ObjCEncOptions() | |||
6962 | .setExpandPointedToStructures() | |||
6963 | .setExpandStructures()), | |||
6964 | FD); | |||
6965 | if (FD || Options.EncodingProperty() || Options.EncodeClassNames()) { | |||
6966 | // Note that we do extended encoding of protocol qualifer list | |||
6967 | // Only when doing ivar or property encoding. | |||
6968 | S += '"'; | |||
6969 | for (const auto *I : OPT->quals()) { | |||
6970 | S += '<'; | |||
6971 | S += I->getObjCRuntimeNameAsString(); | |||
6972 | S += '>'; | |||
6973 | } | |||
6974 | S += '"'; | |||
6975 | } | |||
6976 | return; | |||
6977 | } | |||
6978 | ||||
6979 | S += '@'; | |||
6980 | if (OPT->getInterfaceDecl() && | |||
6981 | (FD || Options.EncodingProperty() || Options.EncodeClassNames())) { | |||
6982 | S += '"'; | |||
6983 | S += OPT->getInterfaceDecl()->getObjCRuntimeNameAsString(); | |||
6984 | for (const auto *I : OPT->quals()) { | |||
6985 | S += '<'; | |||
6986 | S += I->getObjCRuntimeNameAsString(); | |||
6987 | S += '>'; | |||
6988 | } | |||
6989 | S += '"'; | |||
6990 | } | |||
6991 | return; | |||
6992 | } | |||
6993 | ||||
6994 | // gcc just blithely ignores member pointers. | |||
6995 | // FIXME: we should do better than that. 'M' is available. | |||
6996 | case Type::MemberPointer: | |||
6997 | // This matches gcc's encoding, even though technically it is insufficient. | |||
6998 | //FIXME. We should do a better job than gcc. | |||
6999 | case Type::Vector: | |||
7000 | case Type::ExtVector: | |||
7001 | // Until we have a coherent encoding of these three types, issue warning. | |||
7002 | if (NotEncodedT) | |||
7003 | *NotEncodedT = T; | |||
7004 | return; | |||
7005 | ||||
7006 | // We could see an undeduced auto type here during error recovery. | |||
7007 | // Just ignore it. | |||
7008 | case Type::Auto: | |||
7009 | case Type::DeducedTemplateSpecialization: | |||
7010 | return; | |||
7011 | ||||
7012 | case Type::Pipe: | |||
7013 | #define ABSTRACT_TYPE(KIND, BASE) | |||
7014 | #define TYPE(KIND, BASE) | |||
7015 | #define DEPENDENT_TYPE(KIND, BASE) \ | |||
7016 | case Type::KIND: | |||
7017 | #define NON_CANONICAL_TYPE(KIND, BASE) \ | |||
7018 | case Type::KIND: | |||
7019 | #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(KIND, BASE) \ | |||
7020 | case Type::KIND: | |||
7021 | #include "clang/AST/TypeNodes.def" | |||
7022 | llvm_unreachable("@encode for dependent type!")::llvm::llvm_unreachable_internal("@encode for dependent type!" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7022); | |||
7023 | } | |||
7024 | llvm_unreachable("bad type kind!")::llvm::llvm_unreachable_internal("bad type kind!", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7024); | |||
7025 | } | |||
7026 | ||||
7027 | void ASTContext::getObjCEncodingForStructureImpl(RecordDecl *RDecl, | |||
7028 | std::string &S, | |||
7029 | const FieldDecl *FD, | |||
7030 | bool includeVBases, | |||
7031 | QualType *NotEncodedT) const { | |||
7032 | assert(RDecl && "Expected non-null RecordDecl")((RDecl && "Expected non-null RecordDecl") ? static_cast <void> (0) : __assert_fail ("RDecl && \"Expected non-null RecordDecl\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7032, __PRETTY_FUNCTION__)); | |||
7033 | assert(!RDecl->isUnion() && "Should not be called for unions")((!RDecl->isUnion() && "Should not be called for unions" ) ? static_cast<void> (0) : __assert_fail ("!RDecl->isUnion() && \"Should not be called for unions\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7033, __PRETTY_FUNCTION__)); | |||
7034 | if (!RDecl->getDefinition() || RDecl->getDefinition()->isInvalidDecl()) | |||
7035 | return; | |||
7036 | ||||
7037 | const auto *CXXRec = dyn_cast<CXXRecordDecl>(RDecl); | |||
7038 | std::multimap<uint64_t, NamedDecl *> FieldOrBaseOffsets; | |||
7039 | const ASTRecordLayout &layout = getASTRecordLayout(RDecl); | |||
7040 | ||||
7041 | if (CXXRec) { | |||
7042 | for (const auto &BI : CXXRec->bases()) { | |||
7043 | if (!BI.isVirtual()) { | |||
7044 | CXXRecordDecl *base = BI.getType()->getAsCXXRecordDecl(); | |||
7045 | if (base->isEmpty()) | |||
7046 | continue; | |||
7047 | uint64_t offs = toBits(layout.getBaseClassOffset(base)); | |||
7048 | FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs), | |||
7049 | std::make_pair(offs, base)); | |||
7050 | } | |||
7051 | } | |||
7052 | } | |||
7053 | ||||
7054 | unsigned i = 0; | |||
7055 | for (auto *Field : RDecl->fields()) { | |||
7056 | uint64_t offs = layout.getFieldOffset(i); | |||
7057 | FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs), | |||
7058 | std::make_pair(offs, Field)); | |||
7059 | ++i; | |||
7060 | } | |||
7061 | ||||
7062 | if (CXXRec && includeVBases) { | |||
7063 | for (const auto &BI : CXXRec->vbases()) { | |||
7064 | CXXRecordDecl *base = BI.getType()->getAsCXXRecordDecl(); | |||
7065 | if (base->isEmpty()) | |||
7066 | continue; | |||
7067 | uint64_t offs = toBits(layout.getVBaseClassOffset(base)); | |||
7068 | if (offs >= uint64_t(toBits(layout.getNonVirtualSize())) && | |||
7069 | FieldOrBaseOffsets.find(offs) == FieldOrBaseOffsets.end()) | |||
7070 | FieldOrBaseOffsets.insert(FieldOrBaseOffsets.end(), | |||
7071 | std::make_pair(offs, base)); | |||
7072 | } | |||
7073 | } | |||
7074 | ||||
7075 | CharUnits size; | |||
7076 | if (CXXRec) { | |||
7077 | size = includeVBases ? layout.getSize() : layout.getNonVirtualSize(); | |||
7078 | } else { | |||
7079 | size = layout.getSize(); | |||
7080 | } | |||
7081 | ||||
7082 | #ifndef NDEBUG | |||
7083 | uint64_t CurOffs = 0; | |||
7084 | #endif | |||
7085 | std::multimap<uint64_t, NamedDecl *>::iterator | |||
7086 | CurLayObj = FieldOrBaseOffsets.begin(); | |||
7087 | ||||
7088 | if (CXXRec && CXXRec->isDynamicClass() && | |||
7089 | (CurLayObj == FieldOrBaseOffsets.end() || CurLayObj->first != 0)) { | |||
7090 | if (FD) { | |||
7091 | S += "\"_vptr$"; | |||
7092 | std::string recname = CXXRec->getNameAsString(); | |||
7093 | if (recname.empty()) recname = "?"; | |||
7094 | S += recname; | |||
7095 | S += '"'; | |||
7096 | } | |||
7097 | S += "^^?"; | |||
7098 | #ifndef NDEBUG | |||
7099 | CurOffs += getTypeSize(VoidPtrTy); | |||
7100 | #endif | |||
7101 | } | |||
7102 | ||||
7103 | if (!RDecl->hasFlexibleArrayMember()) { | |||
7104 | // Mark the end of the structure. | |||
7105 | uint64_t offs = toBits(size); | |||
7106 | FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs), | |||
7107 | std::make_pair(offs, nullptr)); | |||
7108 | } | |||
7109 | ||||
7110 | for (; CurLayObj != FieldOrBaseOffsets.end(); ++CurLayObj) { | |||
7111 | #ifndef NDEBUG | |||
7112 | assert(CurOffs <= CurLayObj->first)((CurOffs <= CurLayObj->first) ? static_cast<void> (0) : __assert_fail ("CurOffs <= CurLayObj->first", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7112, __PRETTY_FUNCTION__)); | |||
7113 | if (CurOffs < CurLayObj->first) { | |||
7114 | uint64_t padding = CurLayObj->first - CurOffs; | |||
7115 | // FIXME: There doesn't seem to be a way to indicate in the encoding that | |||
7116 | // packing/alignment of members is different that normal, in which case | |||
7117 | // the encoding will be out-of-sync with the real layout. | |||
7118 | // If the runtime switches to just consider the size of types without | |||
7119 | // taking into account alignment, we could make padding explicit in the | |||
7120 | // encoding (e.g. using arrays of chars). The encoding strings would be | |||
7121 | // longer then though. | |||
7122 | CurOffs += padding; | |||
7123 | } | |||
7124 | #endif | |||
7125 | ||||
7126 | NamedDecl *dcl = CurLayObj->second; | |||
7127 | if (!dcl) | |||
7128 | break; // reached end of structure. | |||
7129 | ||||
7130 | if (auto *base = dyn_cast<CXXRecordDecl>(dcl)) { | |||
7131 | // We expand the bases without their virtual bases since those are going | |||
7132 | // in the initial structure. Note that this differs from gcc which | |||
7133 | // expands virtual bases each time one is encountered in the hierarchy, | |||
7134 | // making the encoding type bigger than it really is. | |||
7135 | getObjCEncodingForStructureImpl(base, S, FD, /*includeVBases*/false, | |||
7136 | NotEncodedT); | |||
7137 | assert(!base->isEmpty())((!base->isEmpty()) ? static_cast<void> (0) : __assert_fail ("!base->isEmpty()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7137, __PRETTY_FUNCTION__)); | |||
7138 | #ifndef NDEBUG | |||
7139 | CurOffs += toBits(getASTRecordLayout(base).getNonVirtualSize()); | |||
7140 | #endif | |||
7141 | } else { | |||
7142 | const auto *field = cast<FieldDecl>(dcl); | |||
7143 | if (FD) { | |||
7144 | S += '"'; | |||
7145 | S += field->getNameAsString(); | |||
7146 | S += '"'; | |||
7147 | } | |||
7148 | ||||
7149 | if (field->isBitField()) { | |||
7150 | EncodeBitField(this, S, field->getType(), field); | |||
7151 | #ifndef NDEBUG | |||
7152 | CurOffs += field->getBitWidthValue(*this); | |||
7153 | #endif | |||
7154 | } else { | |||
7155 | QualType qt = field->getType(); | |||
7156 | getLegacyIntegralTypeEncoding(qt); | |||
7157 | getObjCEncodingForTypeImpl( | |||
7158 | qt, S, ObjCEncOptions().setExpandStructures().setIsStructField(), | |||
7159 | FD, NotEncodedT); | |||
7160 | #ifndef NDEBUG | |||
7161 | CurOffs += getTypeSize(field->getType()); | |||
7162 | #endif | |||
7163 | } | |||
7164 | } | |||
7165 | } | |||
7166 | } | |||
7167 | ||||
7168 | void ASTContext::getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT, | |||
7169 | std::string& S) const { | |||
7170 | if (QT & Decl::OBJC_TQ_In) | |||
7171 | S += 'n'; | |||
7172 | if (QT & Decl::OBJC_TQ_Inout) | |||
7173 | S += 'N'; | |||
7174 | if (QT & Decl::OBJC_TQ_Out) | |||
7175 | S += 'o'; | |||
7176 | if (QT & Decl::OBJC_TQ_Bycopy) | |||
7177 | S += 'O'; | |||
7178 | if (QT & Decl::OBJC_TQ_Byref) | |||
7179 | S += 'R'; | |||
7180 | if (QT & Decl::OBJC_TQ_Oneway) | |||
7181 | S += 'V'; | |||
7182 | } | |||
7183 | ||||
7184 | TypedefDecl *ASTContext::getObjCIdDecl() const { | |||
7185 | if (!ObjCIdDecl) { | |||
7186 | QualType T = getObjCObjectType(ObjCBuiltinIdTy, {}, {}); | |||
7187 | T = getObjCObjectPointerType(T); | |||
7188 | ObjCIdDecl = buildImplicitTypedef(T, "id"); | |||
7189 | } | |||
7190 | return ObjCIdDecl; | |||
7191 | } | |||
7192 | ||||
7193 | TypedefDecl *ASTContext::getObjCSelDecl() const { | |||
7194 | if (!ObjCSelDecl) { | |||
7195 | QualType T = getPointerType(ObjCBuiltinSelTy); | |||
7196 | ObjCSelDecl = buildImplicitTypedef(T, "SEL"); | |||
7197 | } | |||
7198 | return ObjCSelDecl; | |||
7199 | } | |||
7200 | ||||
7201 | TypedefDecl *ASTContext::getObjCClassDecl() const { | |||
7202 | if (!ObjCClassDecl) { | |||
7203 | QualType T = getObjCObjectType(ObjCBuiltinClassTy, {}, {}); | |||
7204 | T = getObjCObjectPointerType(T); | |||
7205 | ObjCClassDecl = buildImplicitTypedef(T, "Class"); | |||
7206 | } | |||
7207 | return ObjCClassDecl; | |||
7208 | } | |||
7209 | ||||
7210 | ObjCInterfaceDecl *ASTContext::getObjCProtocolDecl() const { | |||
7211 | if (!ObjCProtocolClassDecl) { | |||
7212 | ObjCProtocolClassDecl | |||
7213 | = ObjCInterfaceDecl::Create(*this, getTranslationUnitDecl(), | |||
7214 | SourceLocation(), | |||
7215 | &Idents.get("Protocol"), | |||
7216 | /*typeParamList=*/nullptr, | |||
7217 | /*PrevDecl=*/nullptr, | |||
7218 | SourceLocation(), true); | |||
7219 | } | |||
7220 | ||||
7221 | return ObjCProtocolClassDecl; | |||
7222 | } | |||
7223 | ||||
7224 | //===----------------------------------------------------------------------===// | |||
7225 | // __builtin_va_list Construction Functions | |||
7226 | //===----------------------------------------------------------------------===// | |||
7227 | ||||
7228 | static TypedefDecl *CreateCharPtrNamedVaListDecl(const ASTContext *Context, | |||
7229 | StringRef Name) { | |||
7230 | // typedef char* __builtin[_ms]_va_list; | |||
7231 | QualType T = Context->getPointerType(Context->CharTy); | |||
7232 | return Context->buildImplicitTypedef(T, Name); | |||
7233 | } | |||
7234 | ||||
7235 | static TypedefDecl *CreateMSVaListDecl(const ASTContext *Context) { | |||
7236 | return CreateCharPtrNamedVaListDecl(Context, "__builtin_ms_va_list"); | |||
7237 | } | |||
7238 | ||||
7239 | static TypedefDecl *CreateCharPtrBuiltinVaListDecl(const ASTContext *Context) { | |||
7240 | return CreateCharPtrNamedVaListDecl(Context, "__builtin_va_list"); | |||
7241 | } | |||
7242 | ||||
7243 | static TypedefDecl *CreateVoidPtrBuiltinVaListDecl(const ASTContext *Context) { | |||
7244 | // typedef void* __builtin_va_list; | |||
7245 | QualType T = Context->getPointerType(Context->VoidTy); | |||
7246 | return Context->buildImplicitTypedef(T, "__builtin_va_list"); | |||
7247 | } | |||
7248 | ||||
7249 | static TypedefDecl * | |||
7250 | CreateAArch64ABIBuiltinVaListDecl(const ASTContext *Context) { | |||
7251 | // struct __va_list | |||
7252 | RecordDecl *VaListTagDecl = Context->buildImplicitRecord("__va_list"); | |||
7253 | if (Context->getLangOpts().CPlusPlus) { | |||
7254 | // namespace std { struct __va_list { | |||
7255 | NamespaceDecl *NS; | |||
7256 | NS = NamespaceDecl::Create(const_cast<ASTContext &>(*Context), | |||
7257 | Context->getTranslationUnitDecl(), | |||
7258 | /*Inline*/ false, SourceLocation(), | |||
7259 | SourceLocation(), &Context->Idents.get("std"), | |||
7260 | /*PrevDecl*/ nullptr); | |||
7261 | NS->setImplicit(); | |||
7262 | VaListTagDecl->setDeclContext(NS); | |||
7263 | } | |||
7264 | ||||
7265 | VaListTagDecl->startDefinition(); | |||
7266 | ||||
7267 | const size_t NumFields = 5; | |||
7268 | QualType FieldTypes[NumFields]; | |||
7269 | const char *FieldNames[NumFields]; | |||
7270 | ||||
7271 | // void *__stack; | |||
7272 | FieldTypes[0] = Context->getPointerType(Context->VoidTy); | |||
7273 | FieldNames[0] = "__stack"; | |||
7274 | ||||
7275 | // void *__gr_top; | |||
7276 | FieldTypes[1] = Context->getPointerType(Context->VoidTy); | |||
7277 | FieldNames[1] = "__gr_top"; | |||
7278 | ||||
7279 | // void *__vr_top; | |||
7280 | FieldTypes[2] = Context->getPointerType(Context->VoidTy); | |||
7281 | FieldNames[2] = "__vr_top"; | |||
7282 | ||||
7283 | // int __gr_offs; | |||
7284 | FieldTypes[3] = Context->IntTy; | |||
7285 | FieldNames[3] = "__gr_offs"; | |||
7286 | ||||
7287 | // int __vr_offs; | |||
7288 | FieldTypes[4] = Context->IntTy; | |||
7289 | FieldNames[4] = "__vr_offs"; | |||
7290 | ||||
7291 | // Create fields | |||
7292 | for (unsigned i = 0; i < NumFields; ++i) { | |||
7293 | FieldDecl *Field = FieldDecl::Create(const_cast<ASTContext &>(*Context), | |||
7294 | VaListTagDecl, | |||
7295 | SourceLocation(), | |||
7296 | SourceLocation(), | |||
7297 | &Context->Idents.get(FieldNames[i]), | |||
7298 | FieldTypes[i], /*TInfo=*/nullptr, | |||
7299 | /*BitWidth=*/nullptr, | |||
7300 | /*Mutable=*/false, | |||
7301 | ICIS_NoInit); | |||
7302 | Field->setAccess(AS_public); | |||
7303 | VaListTagDecl->addDecl(Field); | |||
7304 | } | |||
7305 | VaListTagDecl->completeDefinition(); | |||
7306 | Context->VaListTagDecl = VaListTagDecl; | |||
7307 | QualType VaListTagType = Context->getRecordType(VaListTagDecl); | |||
7308 | ||||
7309 | // } __builtin_va_list; | |||
7310 | return Context->buildImplicitTypedef(VaListTagType, "__builtin_va_list"); | |||
7311 | } | |||
7312 | ||||
7313 | static TypedefDecl *CreatePowerABIBuiltinVaListDecl(const ASTContext *Context) { | |||
7314 | // typedef struct __va_list_tag { | |||
7315 | RecordDecl *VaListTagDecl; | |||
7316 | ||||
7317 | VaListTagDecl = Context->buildImplicitRecord("__va_list_tag"); | |||
7318 | VaListTagDecl->startDefinition(); | |||
7319 | ||||
7320 | const size_t NumFields = 5; | |||
7321 | QualType FieldTypes[NumFields]; | |||
7322 | const char *FieldNames[NumFields]; | |||
7323 | ||||
7324 | // unsigned char gpr; | |||
7325 | FieldTypes[0] = Context->UnsignedCharTy; | |||
7326 | FieldNames[0] = "gpr"; | |||
7327 | ||||
7328 | // unsigned char fpr; | |||
7329 | FieldTypes[1] = Context->UnsignedCharTy; | |||
7330 | FieldNames[1] = "fpr"; | |||
7331 | ||||
7332 | // unsigned short reserved; | |||
7333 | FieldTypes[2] = Context->UnsignedShortTy; | |||
7334 | FieldNames[2] = "reserved"; | |||
7335 | ||||
7336 | // void* overflow_arg_area; | |||
7337 | FieldTypes[3] = Context->getPointerType(Context->VoidTy); | |||
7338 | FieldNames[3] = "overflow_arg_area"; | |||
7339 | ||||
7340 | // void* reg_save_area; | |||
7341 | FieldTypes[4] = Context->getPointerType(Context->VoidTy); | |||
7342 | FieldNames[4] = "reg_save_area"; | |||
7343 | ||||
7344 | // Create fields | |||
7345 | for (unsigned i = 0; i < NumFields; ++i) { | |||
7346 | FieldDecl *Field = FieldDecl::Create(*Context, VaListTagDecl, | |||
7347 | SourceLocation(), | |||
7348 | SourceLocation(), | |||
7349 | &Context->Idents.get(FieldNames[i]), | |||
7350 | FieldTypes[i], /*TInfo=*/nullptr, | |||
7351 | /*BitWidth=*/nullptr, | |||
7352 | /*Mutable=*/false, | |||
7353 | ICIS_NoInit); | |||
7354 | Field->setAccess(AS_public); | |||
7355 | VaListTagDecl->addDecl(Field); | |||
7356 | } | |||
7357 | VaListTagDecl->completeDefinition(); | |||
7358 | Context->VaListTagDecl = VaListTagDecl; | |||
7359 | QualType VaListTagType = Context->getRecordType(VaListTagDecl); | |||
7360 | ||||
7361 | // } __va_list_tag; | |||
7362 | TypedefDecl *VaListTagTypedefDecl = | |||
7363 | Context->buildImplicitTypedef(VaListTagType, "__va_list_tag"); | |||
7364 | ||||
7365 | QualType VaListTagTypedefType = | |||
7366 | Context->getTypedefType(VaListTagTypedefDecl); | |||
7367 | ||||
7368 | // typedef __va_list_tag __builtin_va_list[1]; | |||
7369 | llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 1); | |||
7370 | QualType VaListTagArrayType | |||
7371 | = Context->getConstantArrayType(VaListTagTypedefType, | |||
7372 | Size, ArrayType::Normal, 0); | |||
7373 | return Context->buildImplicitTypedef(VaListTagArrayType, "__builtin_va_list"); | |||
7374 | } | |||
7375 | ||||
7376 | static TypedefDecl * | |||
7377 | CreateX86_64ABIBuiltinVaListDecl(const ASTContext *Context) { | |||
7378 | // struct __va_list_tag { | |||
7379 | RecordDecl *VaListTagDecl; | |||
7380 | VaListTagDecl = Context->buildImplicitRecord("__va_list_tag"); | |||
7381 | VaListTagDecl->startDefinition(); | |||
7382 | ||||
7383 | const size_t NumFields = 4; | |||
7384 | QualType FieldTypes[NumFields]; | |||
7385 | const char *FieldNames[NumFields]; | |||
7386 | ||||
7387 | // unsigned gp_offset; | |||
7388 | FieldTypes[0] = Context->UnsignedIntTy; | |||
7389 | FieldNames[0] = "gp_offset"; | |||
7390 | ||||
7391 | // unsigned fp_offset; | |||
7392 | FieldTypes[1] = Context->UnsignedIntTy; | |||
7393 | FieldNames[1] = "fp_offset"; | |||
7394 | ||||
7395 | // void* overflow_arg_area; | |||
7396 | FieldTypes[2] = Context->getPointerType(Context->VoidTy); | |||
7397 | FieldNames[2] = "overflow_arg_area"; | |||
7398 | ||||
7399 | // void* reg_save_area; | |||
7400 | FieldTypes[3] = Context->getPointerType(Context->VoidTy); | |||
7401 | FieldNames[3] = "reg_save_area"; | |||
7402 | ||||
7403 | // Create fields | |||
7404 | for (unsigned i = 0; i < NumFields; ++i) { | |||
7405 | FieldDecl *Field = FieldDecl::Create(const_cast<ASTContext &>(*Context), | |||
7406 | VaListTagDecl, | |||
7407 | SourceLocation(), | |||
7408 | SourceLocation(), | |||
7409 | &Context->Idents.get(FieldNames[i]), | |||
7410 | FieldTypes[i], /*TInfo=*/nullptr, | |||
7411 | /*BitWidth=*/nullptr, | |||
7412 | /*Mutable=*/false, | |||
7413 | ICIS_NoInit); | |||
7414 | Field->setAccess(AS_public); | |||
7415 | VaListTagDecl->addDecl(Field); | |||
7416 | } | |||
7417 | VaListTagDecl->completeDefinition(); | |||
7418 | Context->VaListTagDecl = VaListTagDecl; | |||
7419 | QualType VaListTagType = Context->getRecordType(VaListTagDecl); | |||
7420 | ||||
7421 | // }; | |||
7422 | ||||
7423 | // typedef struct __va_list_tag __builtin_va_list[1]; | |||
7424 | llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 1); | |||
7425 | QualType VaListTagArrayType = | |||
7426 | Context->getConstantArrayType(VaListTagType, Size, ArrayType::Normal, 0); | |||
7427 | return Context->buildImplicitTypedef(VaListTagArrayType, "__builtin_va_list"); | |||
7428 | } | |||
7429 | ||||
7430 | static TypedefDecl *CreatePNaClABIBuiltinVaListDecl(const ASTContext *Context) { | |||
7431 | // typedef int __builtin_va_list[4]; | |||
7432 | llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 4); | |||
7433 | QualType IntArrayType = | |||
7434 | Context->getConstantArrayType(Context->IntTy, Size, ArrayType::Normal, 0); | |||
7435 | return Context->buildImplicitTypedef(IntArrayType, "__builtin_va_list"); | |||
7436 | } | |||
7437 | ||||
7438 | static TypedefDecl * | |||
7439 | CreateAAPCSABIBuiltinVaListDecl(const ASTContext *Context) { | |||
7440 | // struct __va_list | |||
7441 | RecordDecl *VaListDecl = Context->buildImplicitRecord("__va_list"); | |||
7442 | if (Context->getLangOpts().CPlusPlus) { | |||
7443 | // namespace std { struct __va_list { | |||
7444 | NamespaceDecl *NS; | |||
7445 | NS = NamespaceDecl::Create(const_cast<ASTContext &>(*Context), | |||
7446 | Context->getTranslationUnitDecl(), | |||
7447 | /*Inline*/false, SourceLocation(), | |||
7448 | SourceLocation(), &Context->Idents.get("std"), | |||
7449 | /*PrevDecl*/ nullptr); | |||
7450 | NS->setImplicit(); | |||
7451 | VaListDecl->setDeclContext(NS); | |||
7452 | } | |||
7453 | ||||
7454 | VaListDecl->startDefinition(); | |||
7455 | ||||
7456 | // void * __ap; | |||
7457 | FieldDecl *Field = FieldDecl::Create(const_cast<ASTContext &>(*Context), | |||
7458 | VaListDecl, | |||
7459 | SourceLocation(), | |||
7460 | SourceLocation(), | |||
7461 | &Context->Idents.get("__ap"), | |||
7462 | Context->getPointerType(Context->VoidTy), | |||
7463 | /*TInfo=*/nullptr, | |||
7464 | /*BitWidth=*/nullptr, | |||
7465 | /*Mutable=*/false, | |||
7466 | ICIS_NoInit); | |||
7467 | Field->setAccess(AS_public); | |||
7468 | VaListDecl->addDecl(Field); | |||
7469 | ||||
7470 | // }; | |||
7471 | VaListDecl->completeDefinition(); | |||
7472 | Context->VaListTagDecl = VaListDecl; | |||
7473 | ||||
7474 | // typedef struct __va_list __builtin_va_list; | |||
7475 | QualType T = Context->getRecordType(VaListDecl); | |||
7476 | return Context->buildImplicitTypedef(T, "__builtin_va_list"); | |||
7477 | } | |||
7478 | ||||
7479 | static TypedefDecl * | |||
7480 | CreateSystemZBuiltinVaListDecl(const ASTContext *Context) { | |||
7481 | // struct __va_list_tag { | |||
7482 | RecordDecl *VaListTagDecl; | |||
7483 | VaListTagDecl = Context->buildImplicitRecord("__va_list_tag"); | |||
7484 | VaListTagDecl->startDefinition(); | |||
7485 | ||||
7486 | const size_t NumFields = 4; | |||
7487 | QualType FieldTypes[NumFields]; | |||
7488 | const char *FieldNames[NumFields]; | |||
7489 | ||||
7490 | // long __gpr; | |||
7491 | FieldTypes[0] = Context->LongTy; | |||
7492 | FieldNames[0] = "__gpr"; | |||
7493 | ||||
7494 | // long __fpr; | |||
7495 | FieldTypes[1] = Context->LongTy; | |||
7496 | FieldNames[1] = "__fpr"; | |||
7497 | ||||
7498 | // void *__overflow_arg_area; | |||
7499 | FieldTypes[2] = Context->getPointerType(Context->VoidTy); | |||
7500 | FieldNames[2] = "__overflow_arg_area"; | |||
7501 | ||||
7502 | // void *__reg_save_area; | |||
7503 | FieldTypes[3] = Context->getPointerType(Context->VoidTy); | |||
7504 | FieldNames[3] = "__reg_save_area"; | |||
7505 | ||||
7506 | // Create fields | |||
7507 | for (unsigned i = 0; i < NumFields; ++i) { | |||
7508 | FieldDecl *Field = FieldDecl::Create(const_cast<ASTContext &>(*Context), | |||
7509 | VaListTagDecl, | |||
7510 | SourceLocation(), | |||
7511 | SourceLocation(), | |||
7512 | &Context->Idents.get(FieldNames[i]), | |||
7513 | FieldTypes[i], /*TInfo=*/nullptr, | |||
7514 | /*BitWidth=*/nullptr, | |||
7515 | /*Mutable=*/false, | |||
7516 | ICIS_NoInit); | |||
7517 | Field->setAccess(AS_public); | |||
7518 | VaListTagDecl->addDecl(Field); | |||
7519 | } | |||
7520 | VaListTagDecl->completeDefinition(); | |||
7521 | Context->VaListTagDecl = VaListTagDecl; | |||
7522 | QualType VaListTagType = Context->getRecordType(VaListTagDecl); | |||
7523 | ||||
7524 | // }; | |||
7525 | ||||
7526 | // typedef __va_list_tag __builtin_va_list[1]; | |||
7527 | llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 1); | |||
7528 | QualType VaListTagArrayType = | |||
7529 | Context->getConstantArrayType(VaListTagType, Size, ArrayType::Normal, 0); | |||
7530 | ||||
7531 | return Context->buildImplicitTypedef(VaListTagArrayType, "__builtin_va_list"); | |||
7532 | } | |||
7533 | ||||
7534 | static TypedefDecl *CreateVaListDecl(const ASTContext *Context, | |||
7535 | TargetInfo::BuiltinVaListKind Kind) { | |||
7536 | switch (Kind) { | |||
7537 | case TargetInfo::CharPtrBuiltinVaList: | |||
7538 | return CreateCharPtrBuiltinVaListDecl(Context); | |||
7539 | case TargetInfo::VoidPtrBuiltinVaList: | |||
7540 | return CreateVoidPtrBuiltinVaListDecl(Context); | |||
7541 | case TargetInfo::AArch64ABIBuiltinVaList: | |||
7542 | return CreateAArch64ABIBuiltinVaListDecl(Context); | |||
7543 | case TargetInfo::PowerABIBuiltinVaList: | |||
7544 | return CreatePowerABIBuiltinVaListDecl(Context); | |||
7545 | case TargetInfo::X86_64ABIBuiltinVaList: | |||
7546 | return CreateX86_64ABIBuiltinVaListDecl(Context); | |||
7547 | case TargetInfo::PNaClABIBuiltinVaList: | |||
7548 | return CreatePNaClABIBuiltinVaListDecl(Context); | |||
7549 | case TargetInfo::AAPCSABIBuiltinVaList: | |||
7550 | return CreateAAPCSABIBuiltinVaListDecl(Context); | |||
7551 | case TargetInfo::SystemZBuiltinVaList: | |||
7552 | return CreateSystemZBuiltinVaListDecl(Context); | |||
7553 | } | |||
7554 | ||||
7555 | llvm_unreachable("Unhandled __builtin_va_list type kind")::llvm::llvm_unreachable_internal("Unhandled __builtin_va_list type kind" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7555); | |||
7556 | } | |||
7557 | ||||
7558 | TypedefDecl *ASTContext::getBuiltinVaListDecl() const { | |||
7559 | if (!BuiltinVaListDecl) { | |||
7560 | BuiltinVaListDecl = CreateVaListDecl(this, Target->getBuiltinVaListKind()); | |||
7561 | assert(BuiltinVaListDecl->isImplicit())((BuiltinVaListDecl->isImplicit()) ? static_cast<void> (0) : __assert_fail ("BuiltinVaListDecl->isImplicit()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7561, __PRETTY_FUNCTION__)); | |||
7562 | } | |||
7563 | ||||
7564 | return BuiltinVaListDecl; | |||
7565 | } | |||
7566 | ||||
7567 | Decl *ASTContext::getVaListTagDecl() const { | |||
7568 | // Force the creation of VaListTagDecl by building the __builtin_va_list | |||
7569 | // declaration. | |||
7570 | if (!VaListTagDecl) | |||
7571 | (void)getBuiltinVaListDecl(); | |||
7572 | ||||
7573 | return VaListTagDecl; | |||
7574 | } | |||
7575 | ||||
7576 | TypedefDecl *ASTContext::getBuiltinMSVaListDecl() const { | |||
7577 | if (!BuiltinMSVaListDecl) | |||
7578 | BuiltinMSVaListDecl = CreateMSVaListDecl(this); | |||
7579 | ||||
7580 | return BuiltinMSVaListDecl; | |||
7581 | } | |||
7582 | ||||
7583 | bool ASTContext::canBuiltinBeRedeclared(const FunctionDecl *FD) const { | |||
7584 | return BuiltinInfo.canBeRedeclared(FD->getBuiltinID()); | |||
7585 | } | |||
7586 | ||||
7587 | void ASTContext::setObjCConstantStringInterface(ObjCInterfaceDecl *Decl) { | |||
7588 | assert(ObjCConstantStringType.isNull() &&((ObjCConstantStringType.isNull() && "'NSConstantString' type already set!" ) ? static_cast<void> (0) : __assert_fail ("ObjCConstantStringType.isNull() && \"'NSConstantString' type already set!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7589, __PRETTY_FUNCTION__)) | |||
7589 | "'NSConstantString' type already set!")((ObjCConstantStringType.isNull() && "'NSConstantString' type already set!" ) ? static_cast<void> (0) : __assert_fail ("ObjCConstantStringType.isNull() && \"'NSConstantString' type already set!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7589, __PRETTY_FUNCTION__)); | |||
7590 | ||||
7591 | ObjCConstantStringType = getObjCInterfaceType(Decl); | |||
7592 | } | |||
7593 | ||||
7594 | /// Retrieve the template name that corresponds to a non-empty | |||
7595 | /// lookup. | |||
7596 | TemplateName | |||
7597 | ASTContext::getOverloadedTemplateName(UnresolvedSetIterator Begin, | |||
7598 | UnresolvedSetIterator End) const { | |||
7599 | unsigned size = End - Begin; | |||
7600 | assert(size > 1 && "set is not overloaded!")((size > 1 && "set is not overloaded!") ? static_cast <void> (0) : __assert_fail ("size > 1 && \"set is not overloaded!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7600, __PRETTY_FUNCTION__)); | |||
7601 | ||||
7602 | void *memory = Allocate(sizeof(OverloadedTemplateStorage) + | |||
7603 | size * sizeof(FunctionTemplateDecl*)); | |||
7604 | auto *OT = new (memory) OverloadedTemplateStorage(size); | |||
7605 | ||||
7606 | NamedDecl **Storage = OT->getStorage(); | |||
7607 | for (UnresolvedSetIterator I = Begin; I != End; ++I) { | |||
7608 | NamedDecl *D = *I; | |||
7609 | assert(isa<FunctionTemplateDecl>(D) ||((isa<FunctionTemplateDecl>(D) || isa<UnresolvedUsingValueDecl >(D) || (isa<UsingShadowDecl>(D) && isa<FunctionTemplateDecl >(D->getUnderlyingDecl()))) ? static_cast<void> ( 0) : __assert_fail ("isa<FunctionTemplateDecl>(D) || isa<UnresolvedUsingValueDecl>(D) || (isa<UsingShadowDecl>(D) && isa<FunctionTemplateDecl>(D->getUnderlyingDecl()))" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7612, __PRETTY_FUNCTION__)) | |||
7610 | isa<UnresolvedUsingValueDecl>(D) ||((isa<FunctionTemplateDecl>(D) || isa<UnresolvedUsingValueDecl >(D) || (isa<UsingShadowDecl>(D) && isa<FunctionTemplateDecl >(D->getUnderlyingDecl()))) ? static_cast<void> ( 0) : __assert_fail ("isa<FunctionTemplateDecl>(D) || isa<UnresolvedUsingValueDecl>(D) || (isa<UsingShadowDecl>(D) && isa<FunctionTemplateDecl>(D->getUnderlyingDecl()))" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7612, __PRETTY_FUNCTION__)) | |||
7611 | (isa<UsingShadowDecl>(D) &&((isa<FunctionTemplateDecl>(D) || isa<UnresolvedUsingValueDecl >(D) || (isa<UsingShadowDecl>(D) && isa<FunctionTemplateDecl >(D->getUnderlyingDecl()))) ? static_cast<void> ( 0) : __assert_fail ("isa<FunctionTemplateDecl>(D) || isa<UnresolvedUsingValueDecl>(D) || (isa<UsingShadowDecl>(D) && isa<FunctionTemplateDecl>(D->getUnderlyingDecl()))" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7612, __PRETTY_FUNCTION__)) | |||
7612 | isa<FunctionTemplateDecl>(D->getUnderlyingDecl())))((isa<FunctionTemplateDecl>(D) || isa<UnresolvedUsingValueDecl >(D) || (isa<UsingShadowDecl>(D) && isa<FunctionTemplateDecl >(D->getUnderlyingDecl()))) ? static_cast<void> ( 0) : __assert_fail ("isa<FunctionTemplateDecl>(D) || isa<UnresolvedUsingValueDecl>(D) || (isa<UsingShadowDecl>(D) && isa<FunctionTemplateDecl>(D->getUnderlyingDecl()))" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7612, __PRETTY_FUNCTION__)); | |||
7613 | *Storage++ = D; | |||
7614 | } | |||
7615 | ||||
7616 | return TemplateName(OT); | |||
7617 | } | |||
7618 | ||||
7619 | /// Retrieve a template name representing an unqualified-id that has been | |||
7620 | /// assumed to name a template for ADL purposes. | |||
7621 | TemplateName ASTContext::getAssumedTemplateName(DeclarationName Name) const { | |||
7622 | auto *OT = new (*this) AssumedTemplateStorage(Name); | |||
7623 | return TemplateName(OT); | |||
7624 | } | |||
7625 | ||||
7626 | /// Retrieve the template name that represents a qualified | |||
7627 | /// template name such as \c std::vector. | |||
7628 | TemplateName | |||
7629 | ASTContext::getQualifiedTemplateName(NestedNameSpecifier *NNS, | |||
7630 | bool TemplateKeyword, | |||
7631 | TemplateDecl *Template) const { | |||
7632 | assert(NNS && "Missing nested-name-specifier in qualified template name")((NNS && "Missing nested-name-specifier in qualified template name" ) ? static_cast<void> (0) : __assert_fail ("NNS && \"Missing nested-name-specifier in qualified template name\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7632, __PRETTY_FUNCTION__)); | |||
7633 | ||||
7634 | // FIXME: Canonicalization? | |||
7635 | llvm::FoldingSetNodeID ID; | |||
7636 | QualifiedTemplateName::Profile(ID, NNS, TemplateKeyword, Template); | |||
7637 | ||||
7638 | void *InsertPos = nullptr; | |||
7639 | QualifiedTemplateName *QTN = | |||
7640 | QualifiedTemplateNames.FindNodeOrInsertPos(ID, InsertPos); | |||
7641 | if (!QTN) { | |||
7642 | QTN = new (*this, alignof(QualifiedTemplateName)) | |||
7643 | QualifiedTemplateName(NNS, TemplateKeyword, Template); | |||
7644 | QualifiedTemplateNames.InsertNode(QTN, InsertPos); | |||
7645 | } | |||
7646 | ||||
7647 | return TemplateName(QTN); | |||
7648 | } | |||
7649 | ||||
7650 | /// Retrieve the template name that represents a dependent | |||
7651 | /// template name such as \c MetaFun::template apply. | |||
7652 | TemplateName | |||
7653 | ASTContext::getDependentTemplateName(NestedNameSpecifier *NNS, | |||
7654 | const IdentifierInfo *Name) const { | |||
7655 | assert((!NNS || NNS->isDependent()) &&(((!NNS || NNS->isDependent()) && "Nested name specifier must be dependent" ) ? static_cast<void> (0) : __assert_fail ("(!NNS || NNS->isDependent()) && \"Nested name specifier must be dependent\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7656, __PRETTY_FUNCTION__)) | |||
7656 | "Nested name specifier must be dependent")(((!NNS || NNS->isDependent()) && "Nested name specifier must be dependent" ) ? static_cast<void> (0) : __assert_fail ("(!NNS || NNS->isDependent()) && \"Nested name specifier must be dependent\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7656, __PRETTY_FUNCTION__)); | |||
7657 | ||||
7658 | llvm::FoldingSetNodeID ID; | |||
7659 | DependentTemplateName::Profile(ID, NNS, Name); | |||
7660 | ||||
7661 | void *InsertPos = nullptr; | |||
7662 | DependentTemplateName *QTN = | |||
7663 | DependentTemplateNames.FindNodeOrInsertPos(ID, InsertPos); | |||
7664 | ||||
7665 | if (QTN) | |||
7666 | return TemplateName(QTN); | |||
7667 | ||||
7668 | NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); | |||
7669 | if (CanonNNS == NNS) { | |||
7670 | QTN = new (*this, alignof(DependentTemplateName)) | |||
7671 | DependentTemplateName(NNS, Name); | |||
7672 | } else { | |||
7673 | TemplateName Canon = getDependentTemplateName(CanonNNS, Name); | |||
7674 | QTN = new (*this, alignof(DependentTemplateName)) | |||
7675 | DependentTemplateName(NNS, Name, Canon); | |||
7676 | DependentTemplateName *CheckQTN = | |||
7677 | DependentTemplateNames.FindNodeOrInsertPos(ID, InsertPos); | |||
7678 | assert(!CheckQTN && "Dependent type name canonicalization broken")((!CheckQTN && "Dependent type name canonicalization broken" ) ? static_cast<void> (0) : __assert_fail ("!CheckQTN && \"Dependent type name canonicalization broken\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7678, __PRETTY_FUNCTION__)); | |||
7679 | (void)CheckQTN; | |||
7680 | } | |||
7681 | ||||
7682 | DependentTemplateNames.InsertNode(QTN, InsertPos); | |||
7683 | return TemplateName(QTN); | |||
7684 | } | |||
7685 | ||||
7686 | /// Retrieve the template name that represents a dependent | |||
7687 | /// template name such as \c MetaFun::template operator+. | |||
7688 | TemplateName | |||
7689 | ASTContext::getDependentTemplateName(NestedNameSpecifier *NNS, | |||
7690 | OverloadedOperatorKind Operator) const { | |||
7691 | assert((!NNS || NNS->isDependent()) &&(((!NNS || NNS->isDependent()) && "Nested name specifier must be dependent" ) ? static_cast<void> (0) : __assert_fail ("(!NNS || NNS->isDependent()) && \"Nested name specifier must be dependent\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7692, __PRETTY_FUNCTION__)) | |||
7692 | "Nested name specifier must be dependent")(((!NNS || NNS->isDependent()) && "Nested name specifier must be dependent" ) ? static_cast<void> (0) : __assert_fail ("(!NNS || NNS->isDependent()) && \"Nested name specifier must be dependent\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7692, __PRETTY_FUNCTION__)); | |||
7693 | ||||
7694 | llvm::FoldingSetNodeID ID; | |||
7695 | DependentTemplateName::Profile(ID, NNS, Operator); | |||
7696 | ||||
7697 | void *InsertPos = nullptr; | |||
7698 | DependentTemplateName *QTN | |||
7699 | = DependentTemplateNames.FindNodeOrInsertPos(ID, InsertPos); | |||
7700 | ||||
7701 | if (QTN) | |||
7702 | return TemplateName(QTN); | |||
7703 | ||||
7704 | NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); | |||
7705 | if (CanonNNS == NNS) { | |||
7706 | QTN = new (*this, alignof(DependentTemplateName)) | |||
7707 | DependentTemplateName(NNS, Operator); | |||
7708 | } else { | |||
7709 | TemplateName Canon = getDependentTemplateName(CanonNNS, Operator); | |||
7710 | QTN = new (*this, alignof(DependentTemplateName)) | |||
7711 | DependentTemplateName(NNS, Operator, Canon); | |||
7712 | ||||
7713 | DependentTemplateName *CheckQTN | |||
7714 | = DependentTemplateNames.FindNodeOrInsertPos(ID, InsertPos); | |||
7715 | assert(!CheckQTN && "Dependent template name canonicalization broken")((!CheckQTN && "Dependent template name canonicalization broken" ) ? static_cast<void> (0) : __assert_fail ("!CheckQTN && \"Dependent template name canonicalization broken\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7715, __PRETTY_FUNCTION__)); | |||
7716 | (void)CheckQTN; | |||
7717 | } | |||
7718 | ||||
7719 | DependentTemplateNames.InsertNode(QTN, InsertPos); | |||
7720 | return TemplateName(QTN); | |||
7721 | } | |||
7722 | ||||
7723 | TemplateName | |||
7724 | ASTContext::getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param, | |||
7725 | TemplateName replacement) const { | |||
7726 | llvm::FoldingSetNodeID ID; | |||
7727 | SubstTemplateTemplateParmStorage::Profile(ID, param, replacement); | |||
7728 | ||||
7729 | void *insertPos = nullptr; | |||
7730 | SubstTemplateTemplateParmStorage *subst | |||
7731 | = SubstTemplateTemplateParms.FindNodeOrInsertPos(ID, insertPos); | |||
7732 | ||||
7733 | if (!subst) { | |||
7734 | subst = new (*this) SubstTemplateTemplateParmStorage(param, replacement); | |||
7735 | SubstTemplateTemplateParms.InsertNode(subst, insertPos); | |||
7736 | } | |||
7737 | ||||
7738 | return TemplateName(subst); | |||
7739 | } | |||
7740 | ||||
7741 | TemplateName | |||
7742 | ASTContext::getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param, | |||
7743 | const TemplateArgument &ArgPack) const { | |||
7744 | auto &Self = const_cast<ASTContext &>(*this); | |||
7745 | llvm::FoldingSetNodeID ID; | |||
7746 | SubstTemplateTemplateParmPackStorage::Profile(ID, Self, Param, ArgPack); | |||
7747 | ||||
7748 | void *InsertPos = nullptr; | |||
7749 | SubstTemplateTemplateParmPackStorage *Subst | |||
7750 | = SubstTemplateTemplateParmPacks.FindNodeOrInsertPos(ID, InsertPos); | |||
7751 | ||||
7752 | if (!Subst) { | |||
7753 | Subst = new (*this) SubstTemplateTemplateParmPackStorage(Param, | |||
7754 | ArgPack.pack_size(), | |||
7755 | ArgPack.pack_begin()); | |||
7756 | SubstTemplateTemplateParmPacks.InsertNode(Subst, InsertPos); | |||
7757 | } | |||
7758 | ||||
7759 | return TemplateName(Subst); | |||
7760 | } | |||
7761 | ||||
7762 | /// getFromTargetType - Given one of the integer types provided by | |||
7763 | /// TargetInfo, produce the corresponding type. The unsigned @p Type | |||
7764 | /// is actually a value of type @c TargetInfo::IntType. | |||
7765 | CanQualType ASTContext::getFromTargetType(unsigned Type) const { | |||
7766 | switch (Type) { | |||
7767 | case TargetInfo::NoInt: return {}; | |||
7768 | case TargetInfo::SignedChar: return SignedCharTy; | |||
7769 | case TargetInfo::UnsignedChar: return UnsignedCharTy; | |||
7770 | case TargetInfo::SignedShort: return ShortTy; | |||
7771 | case TargetInfo::UnsignedShort: return UnsignedShortTy; | |||
7772 | case TargetInfo::SignedInt: return IntTy; | |||
7773 | case TargetInfo::UnsignedInt: return UnsignedIntTy; | |||
7774 | case TargetInfo::SignedLong: return LongTy; | |||
7775 | case TargetInfo::UnsignedLong: return UnsignedLongTy; | |||
7776 | case TargetInfo::SignedLongLong: return LongLongTy; | |||
7777 | case TargetInfo::UnsignedLongLong: return UnsignedLongLongTy; | |||
7778 | } | |||
7779 | ||||
7780 | llvm_unreachable("Unhandled TargetInfo::IntType value")::llvm::llvm_unreachable_internal("Unhandled TargetInfo::IntType value" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7780); | |||
7781 | } | |||
7782 | ||||
7783 | //===----------------------------------------------------------------------===// | |||
7784 | // Type Predicates. | |||
7785 | //===----------------------------------------------------------------------===// | |||
7786 | ||||
7787 | /// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's | |||
7788 | /// garbage collection attribute. | |||
7789 | /// | |||
7790 | Qualifiers::GC ASTContext::getObjCGCAttrKind(QualType Ty) const { | |||
7791 | if (getLangOpts().getGC() == LangOptions::NonGC) | |||
7792 | return Qualifiers::GCNone; | |||
7793 | ||||
7794 | assert(getLangOpts().ObjC)((getLangOpts().ObjC) ? static_cast<void> (0) : __assert_fail ("getLangOpts().ObjC", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7794, __PRETTY_FUNCTION__)); | |||
7795 | Qualifiers::GC GCAttrs = Ty.getObjCGCAttr(); | |||
7796 | ||||
7797 | // Default behaviour under objective-C's gc is for ObjC pointers | |||
7798 | // (or pointers to them) be treated as though they were declared | |||
7799 | // as __strong. | |||
7800 | if (GCAttrs == Qualifiers::GCNone) { | |||
7801 | if (Ty->isObjCObjectPointerType() || Ty->isBlockPointerType()) | |||
7802 | return Qualifiers::Strong; | |||
7803 | else if (Ty->isPointerType()) | |||
7804 | return getObjCGCAttrKind(Ty->getAs<PointerType>()->getPointeeType()); | |||
7805 | } else { | |||
7806 | // It's not valid to set GC attributes on anything that isn't a | |||
7807 | // pointer. | |||
7808 | #ifndef NDEBUG | |||
7809 | QualType CT = Ty->getCanonicalTypeInternal(); | |||
7810 | while (const auto *AT = dyn_cast<ArrayType>(CT)) | |||
7811 | CT = AT->getElementType(); | |||
7812 | assert(CT->isAnyPointerType() || CT->isBlockPointerType())((CT->isAnyPointerType() || CT->isBlockPointerType()) ? static_cast<void> (0) : __assert_fail ("CT->isAnyPointerType() || CT->isBlockPointerType()" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7812, __PRETTY_FUNCTION__)); | |||
7813 | #endif | |||
7814 | } | |||
7815 | return GCAttrs; | |||
7816 | } | |||
7817 | ||||
7818 | //===----------------------------------------------------------------------===// | |||
7819 | // Type Compatibility Testing | |||
7820 | //===----------------------------------------------------------------------===// | |||
7821 | ||||
7822 | /// areCompatVectorTypes - Return true if the two specified vector types are | |||
7823 | /// compatible. | |||
7824 | static bool areCompatVectorTypes(const VectorType *LHS, | |||
7825 | const VectorType *RHS) { | |||
7826 | assert(LHS->isCanonicalUnqualified() && RHS->isCanonicalUnqualified())((LHS->isCanonicalUnqualified() && RHS->isCanonicalUnqualified ()) ? static_cast<void> (0) : __assert_fail ("LHS->isCanonicalUnqualified() && RHS->isCanonicalUnqualified()" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7826, __PRETTY_FUNCTION__)); | |||
7827 | return LHS->getElementType() == RHS->getElementType() && | |||
7828 | LHS->getNumElements() == RHS->getNumElements(); | |||
7829 | } | |||
7830 | ||||
7831 | bool ASTContext::areCompatibleVectorTypes(QualType FirstVec, | |||
7832 | QualType SecondVec) { | |||
7833 | assert(FirstVec->isVectorType() && "FirstVec should be a vector type")((FirstVec->isVectorType() && "FirstVec should be a vector type" ) ? static_cast<void> (0) : __assert_fail ("FirstVec->isVectorType() && \"FirstVec should be a vector type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7833, __PRETTY_FUNCTION__)); | |||
7834 | assert(SecondVec->isVectorType() && "SecondVec should be a vector type")((SecondVec->isVectorType() && "SecondVec should be a vector type" ) ? static_cast<void> (0) : __assert_fail ("SecondVec->isVectorType() && \"SecondVec should be a vector type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7834, __PRETTY_FUNCTION__)); | |||
7835 | ||||
7836 | if (hasSameUnqualifiedType(FirstVec, SecondVec)) | |||
7837 | return true; | |||
7838 | ||||
7839 | // Treat Neon vector types and most AltiVec vector types as if they are the | |||
7840 | // equivalent GCC vector types. | |||
7841 | const auto *First = FirstVec->getAs<VectorType>(); | |||
7842 | const auto *Second = SecondVec->getAs<VectorType>(); | |||
7843 | if (First->getNumElements() == Second->getNumElements() && | |||
7844 | hasSameType(First->getElementType(), Second->getElementType()) && | |||
7845 | First->getVectorKind() != VectorType::AltiVecPixel && | |||
7846 | First->getVectorKind() != VectorType::AltiVecBool && | |||
7847 | Second->getVectorKind() != VectorType::AltiVecPixel && | |||
7848 | Second->getVectorKind() != VectorType::AltiVecBool) | |||
7849 | return true; | |||
7850 | ||||
7851 | return false; | |||
7852 | } | |||
7853 | ||||
7854 | //===----------------------------------------------------------------------===// | |||
7855 | // ObjCQualifiedIdTypesAreCompatible - Compatibility testing for qualified id's. | |||
7856 | //===----------------------------------------------------------------------===// | |||
7857 | ||||
7858 | /// ProtocolCompatibleWithProtocol - return 'true' if 'lProto' is in the | |||
7859 | /// inheritance hierarchy of 'rProto'. | |||
7860 | bool | |||
7861 | ASTContext::ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto, | |||
7862 | ObjCProtocolDecl *rProto) const { | |||
7863 | if (declaresSameEntity(lProto, rProto)) | |||
7864 | return true; | |||
7865 | for (auto *PI : rProto->protocols()) | |||
7866 | if (ProtocolCompatibleWithProtocol(lProto, PI)) | |||
7867 | return true; | |||
7868 | return false; | |||
7869 | } | |||
7870 | ||||
7871 | /// ObjCQualifiedClassTypesAreCompatible - compare Class<pr,...> and | |||
7872 | /// Class<pr1, ...>. | |||
7873 | bool ASTContext::ObjCQualifiedClassTypesAreCompatible(QualType lhs, | |||
7874 | QualType rhs) { | |||
7875 | const auto *lhsQID = lhs->getAs<ObjCObjectPointerType>(); | |||
7876 | const auto *rhsOPT = rhs->getAs<ObjCObjectPointerType>(); | |||
7877 | assert((lhsQID && rhsOPT) && "ObjCQualifiedClassTypesAreCompatible")(((lhsQID && rhsOPT) && "ObjCQualifiedClassTypesAreCompatible" ) ? static_cast<void> (0) : __assert_fail ("(lhsQID && rhsOPT) && \"ObjCQualifiedClassTypesAreCompatible\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7877, __PRETTY_FUNCTION__)); | |||
7878 | ||||
7879 | for (auto *lhsProto : lhsQID->quals()) { | |||
7880 | bool match = false; | |||
7881 | for (auto *rhsProto : rhsOPT->quals()) { | |||
7882 | if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto)) { | |||
7883 | match = true; | |||
7884 | break; | |||
7885 | } | |||
7886 | } | |||
7887 | if (!match) | |||
7888 | return false; | |||
7889 | } | |||
7890 | return true; | |||
7891 | } | |||
7892 | ||||
7893 | /// ObjCQualifiedIdTypesAreCompatible - We know that one of lhs/rhs is an | |||
7894 | /// ObjCQualifiedIDType. | |||
7895 | bool ASTContext::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs, | |||
7896 | bool compare) { | |||
7897 | // Allow id<P..> and an 'id' or void* type in all cases. | |||
7898 | if (lhs->isVoidPointerType() || | |||
7899 | lhs->isObjCIdType() || lhs->isObjCClassType()) | |||
7900 | return true; | |||
7901 | else if (rhs->isVoidPointerType() || | |||
7902 | rhs->isObjCIdType() || rhs->isObjCClassType()) | |||
7903 | return true; | |||
7904 | ||||
7905 | if (const ObjCObjectPointerType *lhsQID = lhs->getAsObjCQualifiedIdType()) { | |||
7906 | const auto *rhsOPT = rhs->getAs<ObjCObjectPointerType>(); | |||
7907 | ||||
7908 | if (!rhsOPT) return false; | |||
7909 | ||||
7910 | if (rhsOPT->qual_empty()) { | |||
7911 | // If the RHS is a unqualified interface pointer "NSString*", | |||
7912 | // make sure we check the class hierarchy. | |||
7913 | if (ObjCInterfaceDecl *rhsID = rhsOPT->getInterfaceDecl()) { | |||
7914 | for (auto *I : lhsQID->quals()) { | |||
7915 | // when comparing an id<P> on lhs with a static type on rhs, | |||
7916 | // see if static class implements all of id's protocols, directly or | |||
7917 | // through its super class and categories. | |||
7918 | if (!rhsID->ClassImplementsProtocol(I, true)) | |||
7919 | return false; | |||
7920 | } | |||
7921 | } | |||
7922 | // If there are no qualifiers and no interface, we have an 'id'. | |||
7923 | return true; | |||
7924 | } | |||
7925 | // Both the right and left sides have qualifiers. | |||
7926 | for (auto *lhsProto : lhsQID->quals()) { | |||
7927 | bool match = false; | |||
7928 | ||||
7929 | // when comparing an id<P> on lhs with a static type on rhs, | |||
7930 | // see if static class implements all of id's protocols, directly or | |||
7931 | // through its super class and categories. | |||
7932 | for (auto *rhsProto : rhsOPT->quals()) { | |||
7933 | if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || | |||
7934 | (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { | |||
7935 | match = true; | |||
7936 | break; | |||
7937 | } | |||
7938 | } | |||
7939 | // If the RHS is a qualified interface pointer "NSString<P>*", | |||
7940 | // make sure we check the class hierarchy. | |||
7941 | if (ObjCInterfaceDecl *rhsID = rhsOPT->getInterfaceDecl()) { | |||
7942 | for (auto *I : lhsQID->quals()) { | |||
7943 | // when comparing an id<P> on lhs with a static type on rhs, | |||
7944 | // see if static class implements all of id's protocols, directly or | |||
7945 | // through its super class and categories. | |||
7946 | if (rhsID->ClassImplementsProtocol(I, true)) { | |||
7947 | match = true; | |||
7948 | break; | |||
7949 | } | |||
7950 | } | |||
7951 | } | |||
7952 | if (!match) | |||
7953 | return false; | |||
7954 | } | |||
7955 | ||||
7956 | return true; | |||
7957 | } | |||
7958 | ||||
7959 | const ObjCObjectPointerType *rhsQID = rhs->getAsObjCQualifiedIdType(); | |||
7960 | assert(rhsQID && "One of the LHS/RHS should be id<x>")((rhsQID && "One of the LHS/RHS should be id<x>" ) ? static_cast<void> (0) : __assert_fail ("rhsQID && \"One of the LHS/RHS should be id<x>\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 7960, __PRETTY_FUNCTION__)); | |||
7961 | ||||
7962 | if (const ObjCObjectPointerType *lhsOPT = | |||
7963 | lhs->getAsObjCInterfacePointerType()) { | |||
7964 | // If both the right and left sides have qualifiers. | |||
7965 | for (auto *lhsProto : lhsOPT->quals()) { | |||
7966 | bool match = false; | |||
7967 | ||||
7968 | // when comparing an id<P> on rhs with a static type on lhs, | |||
7969 | // see if static class implements all of id's protocols, directly or | |||
7970 | // through its super class and categories. | |||
7971 | // First, lhs protocols in the qualifier list must be found, direct | |||
7972 | // or indirect in rhs's qualifier list or it is a mismatch. | |||
7973 | for (auto *rhsProto : rhsQID->quals()) { | |||
7974 | if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || | |||
7975 | (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { | |||
7976 | match = true; | |||
7977 | break; | |||
7978 | } | |||
7979 | } | |||
7980 | if (!match) | |||
7981 | return false; | |||
7982 | } | |||
7983 | ||||
7984 | // Static class's protocols, or its super class or category protocols | |||
7985 | // must be found, direct or indirect in rhs's qualifier list or it is a mismatch. | |||
7986 | if (ObjCInterfaceDecl *lhsID = lhsOPT->getInterfaceDecl()) { | |||
7987 | llvm::SmallPtrSet<ObjCProtocolDecl *, 8> LHSInheritedProtocols; | |||
7988 | CollectInheritedProtocols(lhsID, LHSInheritedProtocols); | |||
7989 | // This is rather dubious but matches gcc's behavior. If lhs has | |||
7990 | // no type qualifier and its class has no static protocol(s) | |||
7991 | // assume that it is mismatch. | |||
7992 | if (LHSInheritedProtocols.empty() && lhsOPT->qual_empty()) | |||
7993 | return false; | |||
7994 | for (auto *lhsProto : LHSInheritedProtocols) { | |||
7995 | bool match = false; | |||
7996 | for (auto *rhsProto : rhsQID->quals()) { | |||
7997 | if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || | |||
7998 | (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { | |||
7999 | match = true; | |||
8000 | break; | |||
8001 | } | |||
8002 | } | |||
8003 | if (!match) | |||
8004 | return false; | |||
8005 | } | |||
8006 | } | |||
8007 | return true; | |||
8008 | } | |||
8009 | return false; | |||
8010 | } | |||
8011 | ||||
8012 | /// canAssignObjCInterfaces - Return true if the two interface types are | |||
8013 | /// compatible for assignment from RHS to LHS. This handles validation of any | |||
8014 | /// protocol qualifiers on the LHS or RHS. | |||
8015 | bool ASTContext::canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT, | |||
8016 | const ObjCObjectPointerType *RHSOPT) { | |||
8017 | const ObjCObjectType* LHS = LHSOPT->getObjectType(); | |||
8018 | const ObjCObjectType* RHS = RHSOPT->getObjectType(); | |||
8019 | ||||
8020 | // If either type represents the built-in 'id' or 'Class' types, return true. | |||
8021 | if (LHS->isObjCUnqualifiedIdOrClass() || | |||
8022 | RHS->isObjCUnqualifiedIdOrClass()) | |||
8023 | return true; | |||
8024 | ||||
8025 | // Function object that propagates a successful result or handles | |||
8026 | // __kindof types. | |||
8027 | auto finish = [&](bool succeeded) -> bool { | |||
8028 | if (succeeded) | |||
8029 | return true; | |||
8030 | ||||
8031 | if (!RHS->isKindOfType()) | |||
8032 | return false; | |||
8033 | ||||
8034 | // Strip off __kindof and protocol qualifiers, then check whether | |||
8035 | // we can assign the other way. | |||
8036 | return canAssignObjCInterfaces(RHSOPT->stripObjCKindOfTypeAndQuals(*this), | |||
8037 | LHSOPT->stripObjCKindOfTypeAndQuals(*this)); | |||
8038 | }; | |||
8039 | ||||
8040 | if (LHS->isObjCQualifiedId() || RHS->isObjCQualifiedId()) { | |||
8041 | return finish(ObjCQualifiedIdTypesAreCompatible(QualType(LHSOPT,0), | |||
8042 | QualType(RHSOPT,0), | |||
8043 | false)); | |||
8044 | } | |||
8045 | ||||
8046 | if (LHS->isObjCQualifiedClass() && RHS->isObjCQualifiedClass()) { | |||
8047 | return finish(ObjCQualifiedClassTypesAreCompatible(QualType(LHSOPT,0), | |||
8048 | QualType(RHSOPT,0))); | |||
8049 | } | |||
8050 | ||||
8051 | // If we have 2 user-defined types, fall into that path. | |||
8052 | if (LHS->getInterface() && RHS->getInterface()) { | |||
8053 | return finish(canAssignObjCInterfaces(LHS, RHS)); | |||
8054 | } | |||
8055 | ||||
8056 | return false; | |||
8057 | } | |||
8058 | ||||
8059 | /// canAssignObjCInterfacesInBlockPointer - This routine is specifically written | |||
8060 | /// for providing type-safety for objective-c pointers used to pass/return | |||
8061 | /// arguments in block literals. When passed as arguments, passing 'A*' where | |||
8062 | /// 'id' is expected is not OK. Passing 'Sub *" where 'Super *" is expected is | |||
8063 | /// not OK. For the return type, the opposite is not OK. | |||
8064 | bool ASTContext::canAssignObjCInterfacesInBlockPointer( | |||
8065 | const ObjCObjectPointerType *LHSOPT, | |||
8066 | const ObjCObjectPointerType *RHSOPT, | |||
8067 | bool BlockReturnType) { | |||
8068 | ||||
8069 | // Function object that propagates a successful result or handles | |||
8070 | // __kindof types. | |||
8071 | auto finish = [&](bool succeeded) -> bool { | |||
8072 | if (succeeded) | |||
8073 | return true; | |||
8074 | ||||
8075 | const ObjCObjectPointerType *Expected = BlockReturnType ? RHSOPT : LHSOPT; | |||
8076 | if (!Expected->isKindOfType()) | |||
8077 | return false; | |||
8078 | ||||
8079 | // Strip off __kindof and protocol qualifiers, then check whether | |||
8080 | // we can assign the other way. | |||
8081 | return canAssignObjCInterfacesInBlockPointer( | |||
8082 | RHSOPT->stripObjCKindOfTypeAndQuals(*this), | |||
8083 | LHSOPT->stripObjCKindOfTypeAndQuals(*this), | |||
8084 | BlockReturnType); | |||
8085 | }; | |||
8086 | ||||
8087 | if (RHSOPT->isObjCBuiltinType() || LHSOPT->isObjCIdType()) | |||
8088 | return true; | |||
8089 | ||||
8090 | if (LHSOPT->isObjCBuiltinType()) { | |||
8091 | return finish(RHSOPT->isObjCBuiltinType() || | |||
8092 | RHSOPT->isObjCQualifiedIdType()); | |||
8093 | } | |||
8094 | ||||
8095 | if (LHSOPT->isObjCQualifiedIdType() || RHSOPT->isObjCQualifiedIdType()) | |||
8096 | return finish(ObjCQualifiedIdTypesAreCompatible(QualType(LHSOPT,0), | |||
8097 | QualType(RHSOPT,0), | |||
8098 | false)); | |||
8099 | ||||
8100 | const ObjCInterfaceType* LHS = LHSOPT->getInterfaceType(); | |||
8101 | const ObjCInterfaceType* RHS = RHSOPT->getInterfaceType(); | |||
8102 | if (LHS && RHS) { // We have 2 user-defined types. | |||
8103 | if (LHS != RHS) { | |||
8104 | if (LHS->getDecl()->isSuperClassOf(RHS->getDecl())) | |||
8105 | return finish(BlockReturnType); | |||
8106 | if (RHS->getDecl()->isSuperClassOf(LHS->getDecl())) | |||
8107 | return finish(!BlockReturnType); | |||
8108 | } | |||
8109 | else | |||
8110 | return true; | |||
8111 | } | |||
8112 | return false; | |||
8113 | } | |||
8114 | ||||
8115 | /// Comparison routine for Objective-C protocols to be used with | |||
8116 | /// llvm::array_pod_sort. | |||
8117 | static int compareObjCProtocolsByName(ObjCProtocolDecl * const *lhs, | |||
8118 | ObjCProtocolDecl * const *rhs) { | |||
8119 | return (*lhs)->getName().compare((*rhs)->getName()); | |||
8120 | } | |||
8121 | ||||
8122 | /// getIntersectionOfProtocols - This routine finds the intersection of set | |||
8123 | /// of protocols inherited from two distinct objective-c pointer objects with | |||
8124 | /// the given common base. | |||
8125 | /// It is used to build composite qualifier list of the composite type of | |||
8126 | /// the conditional expression involving two objective-c pointer objects. | |||
8127 | static | |||
8128 | void getIntersectionOfProtocols(ASTContext &Context, | |||
8129 | const ObjCInterfaceDecl *CommonBase, | |||
8130 | const ObjCObjectPointerType *LHSOPT, | |||
8131 | const ObjCObjectPointerType *RHSOPT, | |||
8132 | SmallVectorImpl<ObjCProtocolDecl *> &IntersectionSet) { | |||
8133 | ||||
8134 | const ObjCObjectType* LHS = LHSOPT->getObjectType(); | |||
8135 | const ObjCObjectType* RHS = RHSOPT->getObjectType(); | |||
8136 | assert(LHS->getInterface() && "LHS must have an interface base")((LHS->getInterface() && "LHS must have an interface base" ) ? static_cast<void> (0) : __assert_fail ("LHS->getInterface() && \"LHS must have an interface base\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 8136, __PRETTY_FUNCTION__)); | |||
8137 | assert(RHS->getInterface() && "RHS must have an interface base")((RHS->getInterface() && "RHS must have an interface base" ) ? static_cast<void> (0) : __assert_fail ("RHS->getInterface() && \"RHS must have an interface base\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 8137, __PRETTY_FUNCTION__)); | |||
8138 | ||||
8139 | // Add all of the protocols for the LHS. | |||
8140 | llvm::SmallPtrSet<ObjCProtocolDecl *, 8> LHSProtocolSet; | |||
8141 | ||||
8142 | // Start with the protocol qualifiers. | |||
8143 | for (auto proto : LHS->quals()) { | |||
8144 | Context.CollectInheritedProtocols(proto, LHSProtocolSet); | |||
8145 | } | |||
8146 | ||||
8147 | // Also add the protocols associated with the LHS interface. | |||
8148 | Context.CollectInheritedProtocols(LHS->getInterface(), LHSProtocolSet); | |||
8149 | ||||
8150 | // Add all of the protocols for the RHS. | |||
8151 | llvm::SmallPtrSet<ObjCProtocolDecl *, 8> RHSProtocolSet; | |||
8152 | ||||
8153 | // Start with the protocol qualifiers. | |||
8154 | for (auto proto : RHS->quals()) { | |||
8155 | Context.CollectInheritedProtocols(proto, RHSProtocolSet); | |||
8156 | } | |||
8157 | ||||
8158 | // Also add the protocols associated with the RHS interface. | |||
8159 | Context.CollectInheritedProtocols(RHS->getInterface(), RHSProtocolSet); | |||
8160 | ||||
8161 | // Compute the intersection of the collected protocol sets. | |||
8162 | for (auto proto : LHSProtocolSet) { | |||
8163 | if (RHSProtocolSet.count(proto)) | |||
8164 | IntersectionSet.push_back(proto); | |||
8165 | } | |||
8166 | ||||
8167 | // Compute the set of protocols that is implied by either the common type or | |||
8168 | // the protocols within the intersection. | |||
8169 | llvm::SmallPtrSet<ObjCProtocolDecl *, 8> ImpliedProtocols; | |||
8170 | Context.CollectInheritedProtocols(CommonBase, ImpliedProtocols); | |||
8171 | ||||
8172 | // Remove any implied protocols from the list of inherited protocols. | |||
8173 | if (!ImpliedProtocols.empty()) { | |||
8174 | IntersectionSet.erase( | |||
8175 | std::remove_if(IntersectionSet.begin(), | |||
8176 | IntersectionSet.end(), | |||
8177 | [&](ObjCProtocolDecl *proto) -> bool { | |||
8178 | return ImpliedProtocols.count(proto) > 0; | |||
8179 | }), | |||
8180 | IntersectionSet.end()); | |||
8181 | } | |||
8182 | ||||
8183 | // Sort the remaining protocols by name. | |||
8184 | llvm::array_pod_sort(IntersectionSet.begin(), IntersectionSet.end(), | |||
8185 | compareObjCProtocolsByName); | |||
8186 | } | |||
8187 | ||||
8188 | /// Determine whether the first type is a subtype of the second. | |||
8189 | static bool canAssignObjCObjectTypes(ASTContext &ctx, QualType lhs, | |||
8190 | QualType rhs) { | |||
8191 | // Common case: two object pointers. | |||
8192 | const auto *lhsOPT = lhs->getAs<ObjCObjectPointerType>(); | |||
8193 | const auto *rhsOPT = rhs->getAs<ObjCObjectPointerType>(); | |||
8194 | if (lhsOPT && rhsOPT) | |||
8195 | return ctx.canAssignObjCInterfaces(lhsOPT, rhsOPT); | |||
8196 | ||||
8197 | // Two block pointers. | |||
8198 | const auto *lhsBlock = lhs->getAs<BlockPointerType>(); | |||
8199 | const auto *rhsBlock = rhs->getAs<BlockPointerType>(); | |||
8200 | if (lhsBlock && rhsBlock) | |||
8201 | return ctx.typesAreBlockPointerCompatible(lhs, rhs); | |||
8202 | ||||
8203 | // If either is an unqualified 'id' and the other is a block, it's | |||
8204 | // acceptable. | |||
8205 | if ((lhsOPT && lhsOPT->isObjCIdType() && rhsBlock) || | |||
8206 | (rhsOPT && rhsOPT->isObjCIdType() && lhsBlock)) | |||
8207 | return true; | |||
8208 | ||||
8209 | return false; | |||
8210 | } | |||
8211 | ||||
8212 | // Check that the given Objective-C type argument lists are equivalent. | |||
8213 | static bool sameObjCTypeArgs(ASTContext &ctx, | |||
8214 | const ObjCInterfaceDecl *iface, | |||
8215 | ArrayRef<QualType> lhsArgs, | |||
8216 | ArrayRef<QualType> rhsArgs, | |||
8217 | bool stripKindOf) { | |||
8218 | if (lhsArgs.size() != rhsArgs.size()) | |||
8219 | return false; | |||
8220 | ||||
8221 | ObjCTypeParamList *typeParams = iface->getTypeParamList(); | |||
8222 | for (unsigned i = 0, n = lhsArgs.size(); i != n; ++i) { | |||
8223 | if (ctx.hasSameType(lhsArgs[i], rhsArgs[i])) | |||
8224 | continue; | |||
8225 | ||||
8226 | switch (typeParams->begin()[i]->getVariance()) { | |||
8227 | case ObjCTypeParamVariance::Invariant: | |||
8228 | if (!stripKindOf || | |||
8229 | !ctx.hasSameType(lhsArgs[i].stripObjCKindOfType(ctx), | |||
8230 | rhsArgs[i].stripObjCKindOfType(ctx))) { | |||
8231 | return false; | |||
8232 | } | |||
8233 | break; | |||
8234 | ||||
8235 | case ObjCTypeParamVariance::Covariant: | |||
8236 | if (!canAssignObjCObjectTypes(ctx, lhsArgs[i], rhsArgs[i])) | |||
8237 | return false; | |||
8238 | break; | |||
8239 | ||||
8240 | case ObjCTypeParamVariance::Contravariant: | |||
8241 | if (!canAssignObjCObjectTypes(ctx, rhsArgs[i], lhsArgs[i])) | |||
8242 | return false; | |||
8243 | break; | |||
8244 | } | |||
8245 | } | |||
8246 | ||||
8247 | return true; | |||
8248 | } | |||
8249 | ||||
8250 | QualType ASTContext::areCommonBaseCompatible( | |||
8251 | const ObjCObjectPointerType *Lptr, | |||
8252 | const ObjCObjectPointerType *Rptr) { | |||
8253 | const ObjCObjectType *LHS = Lptr->getObjectType(); | |||
8254 | const ObjCObjectType *RHS = Rptr->getObjectType(); | |||
8255 | const ObjCInterfaceDecl* LDecl = LHS->getInterface(); | |||
8256 | const ObjCInterfaceDecl* RDecl = RHS->getInterface(); | |||
8257 | ||||
8258 | if (!LDecl || !RDecl) | |||
8259 | return {}; | |||
8260 | ||||
8261 | // When either LHS or RHS is a kindof type, we should return a kindof type. | |||
8262 | // For example, for common base of kindof(ASub1) and kindof(ASub2), we return | |||
8263 | // kindof(A). | |||
8264 | bool anyKindOf = LHS->isKindOfType() || RHS->isKindOfType(); | |||
8265 | ||||
8266 | // Follow the left-hand side up the class hierarchy until we either hit a | |||
8267 | // root or find the RHS. Record the ancestors in case we don't find it. | |||
8268 | llvm::SmallDenseMap<const ObjCInterfaceDecl *, const ObjCObjectType *, 4> | |||
8269 | LHSAncestors; | |||
8270 | while (true) { | |||
8271 | // Record this ancestor. We'll need this if the common type isn't in the | |||
8272 | // path from the LHS to the root. | |||
8273 | LHSAncestors[LHS->getInterface()->getCanonicalDecl()] = LHS; | |||
8274 | ||||
8275 | if (declaresSameEntity(LHS->getInterface(), RDecl)) { | |||
8276 | // Get the type arguments. | |||
8277 | ArrayRef<QualType> LHSTypeArgs = LHS->getTypeArgsAsWritten(); | |||
8278 | bool anyChanges = false; | |||
8279 | if (LHS->isSpecialized() && RHS->isSpecialized()) { | |||
8280 | // Both have type arguments, compare them. | |||
8281 | if (!sameObjCTypeArgs(*this, LHS->getInterface(), | |||
8282 | LHS->getTypeArgs(), RHS->getTypeArgs(), | |||
8283 | /*stripKindOf=*/true)) | |||
8284 | return {}; | |||
8285 | } else if (LHS->isSpecialized() != RHS->isSpecialized()) { | |||
8286 | // If only one has type arguments, the result will not have type | |||
8287 | // arguments. | |||
8288 | LHSTypeArgs = {}; | |||
8289 | anyChanges = true; | |||
8290 | } | |||
8291 | ||||
8292 | // Compute the intersection of protocols. | |||
8293 | SmallVector<ObjCProtocolDecl *, 8> Protocols; | |||
8294 | getIntersectionOfProtocols(*this, LHS->getInterface(), Lptr, Rptr, | |||
8295 | Protocols); | |||
8296 | if (!Protocols.empty()) | |||
8297 | anyChanges = true; | |||
8298 | ||||
8299 | // If anything in the LHS will have changed, build a new result type. | |||
8300 | // If we need to return a kindof type but LHS is not a kindof type, we | |||
8301 | // build a new result type. | |||
8302 | if (anyChanges || LHS->isKindOfType() != anyKindOf) { | |||
8303 | QualType Result = getObjCInterfaceType(LHS->getInterface()); | |||
8304 | Result = getObjCObjectType(Result, LHSTypeArgs, Protocols, | |||
8305 | anyKindOf || LHS->isKindOfType()); | |||
8306 | return getObjCObjectPointerType(Result); | |||
8307 | } | |||
8308 | ||||
8309 | return getObjCObjectPointerType(QualType(LHS, 0)); | |||
8310 | } | |||
8311 | ||||
8312 | // Find the superclass. | |||
8313 | QualType LHSSuperType = LHS->getSuperClassType(); | |||
8314 | if (LHSSuperType.isNull()) | |||
8315 | break; | |||
8316 | ||||
8317 | LHS = LHSSuperType->castAs<ObjCObjectType>(); | |||
8318 | } | |||
8319 | ||||
8320 | // We didn't find anything by following the LHS to its root; now check | |||
8321 | // the RHS against the cached set of ancestors. | |||
8322 | while (true) { | |||
8323 | auto KnownLHS = LHSAncestors.find(RHS->getInterface()->getCanonicalDecl()); | |||
8324 | if (KnownLHS != LHSAncestors.end()) { | |||
8325 | LHS = KnownLHS->second; | |||
8326 | ||||
8327 | // Get the type arguments. | |||
8328 | ArrayRef<QualType> RHSTypeArgs = RHS->getTypeArgsAsWritten(); | |||
8329 | bool anyChanges = false; | |||
8330 | if (LHS->isSpecialized() && RHS->isSpecialized()) { | |||
8331 | // Both have type arguments, compare them. | |||
8332 | if (!sameObjCTypeArgs(*this, LHS->getInterface(), | |||
8333 | LHS->getTypeArgs(), RHS->getTypeArgs(), | |||
8334 | /*stripKindOf=*/true)) | |||
8335 | return {}; | |||
8336 | } else if (LHS->isSpecialized() != RHS->isSpecialized()) { | |||
8337 | // If only one has type arguments, the result will not have type | |||
8338 | // arguments. | |||
8339 | RHSTypeArgs = {}; | |||
8340 | anyChanges = true; | |||
8341 | } | |||
8342 | ||||
8343 | // Compute the intersection of protocols. | |||
8344 | SmallVector<ObjCProtocolDecl *, 8> Protocols; | |||
8345 | getIntersectionOfProtocols(*this, RHS->getInterface(), Lptr, Rptr, | |||
8346 | Protocols); | |||
8347 | if (!Protocols.empty()) | |||
8348 | anyChanges = true; | |||
8349 | ||||
8350 | // If we need to return a kindof type but RHS is not a kindof type, we | |||
8351 | // build a new result type. | |||
8352 | if (anyChanges || RHS->isKindOfType() != anyKindOf) { | |||
8353 | QualType Result = getObjCInterfaceType(RHS->getInterface()); | |||
8354 | Result = getObjCObjectType(Result, RHSTypeArgs, Protocols, | |||
8355 | anyKindOf || RHS->isKindOfType()); | |||
8356 | return getObjCObjectPointerType(Result); | |||
8357 | } | |||
8358 | ||||
8359 | return getObjCObjectPointerType(QualType(RHS, 0)); | |||
8360 | } | |||
8361 | ||||
8362 | // Find the superclass of the RHS. | |||
8363 | QualType RHSSuperType = RHS->getSuperClassType(); | |||
8364 | if (RHSSuperType.isNull()) | |||
8365 | break; | |||
8366 | ||||
8367 | RHS = RHSSuperType->castAs<ObjCObjectType>(); | |||
8368 | } | |||
8369 | ||||
8370 | return {}; | |||
8371 | } | |||
8372 | ||||
8373 | bool ASTContext::canAssignObjCInterfaces(const ObjCObjectType *LHS, | |||
8374 | const ObjCObjectType *RHS) { | |||
8375 | assert(LHS->getInterface() && "LHS is not an interface type")((LHS->getInterface() && "LHS is not an interface type" ) ? static_cast<void> (0) : __assert_fail ("LHS->getInterface() && \"LHS is not an interface type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 8375, __PRETTY_FUNCTION__)); | |||
8376 | assert(RHS->getInterface() && "RHS is not an interface type")((RHS->getInterface() && "RHS is not an interface type" ) ? static_cast<void> (0) : __assert_fail ("RHS->getInterface() && \"RHS is not an interface type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 8376, __PRETTY_FUNCTION__)); | |||
8377 | ||||
8378 | // Verify that the base decls are compatible: the RHS must be a subclass of | |||
8379 | // the LHS. | |||
8380 | ObjCInterfaceDecl *LHSInterface = LHS->getInterface(); | |||
8381 | bool IsSuperClass = LHSInterface->isSuperClassOf(RHS->getInterface()); | |||
8382 | if (!IsSuperClass) | |||
8383 | return false; | |||
8384 | ||||
8385 | // If the LHS has protocol qualifiers, determine whether all of them are | |||
8386 | // satisfied by the RHS (i.e., the RHS has a superset of the protocols in the | |||
8387 | // LHS). | |||
8388 | if (LHS->getNumProtocols() > 0) { | |||
8389 | // OK if conversion of LHS to SuperClass results in narrowing of types | |||
8390 | // ; i.e., SuperClass may implement at least one of the protocols | |||
8391 | // in LHS's protocol list. Example, SuperObj<P1> = lhs<P1,P2> is ok. | |||
8392 | // But not SuperObj<P1,P2,P3> = lhs<P1,P2>. | |||
8393 | llvm::SmallPtrSet<ObjCProtocolDecl *, 8> SuperClassInheritedProtocols; | |||
8394 | CollectInheritedProtocols(RHS->getInterface(), SuperClassInheritedProtocols); | |||
8395 | // Also, if RHS has explicit quelifiers, include them for comparing with LHS's | |||
8396 | // qualifiers. | |||
8397 | for (auto *RHSPI : RHS->quals()) | |||
8398 | CollectInheritedProtocols(RHSPI, SuperClassInheritedProtocols); | |||
8399 | // If there is no protocols associated with RHS, it is not a match. | |||
8400 | if (SuperClassInheritedProtocols.empty()) | |||
8401 | return false; | |||
8402 | ||||
8403 | for (const auto *LHSProto : LHS->quals()) { | |||
8404 | bool SuperImplementsProtocol = false; | |||
8405 | for (auto *SuperClassProto : SuperClassInheritedProtocols) | |||
8406 | if (SuperClassProto->lookupProtocolNamed(LHSProto->getIdentifier())) { | |||
8407 | SuperImplementsProtocol = true; | |||
8408 | break; | |||
8409 | } | |||
8410 | if (!SuperImplementsProtocol) | |||
8411 | return false; | |||
8412 | } | |||
8413 | } | |||
8414 | ||||
8415 | // If the LHS is specialized, we may need to check type arguments. | |||
8416 | if (LHS->isSpecialized()) { | |||
8417 | // Follow the superclass chain until we've matched the LHS class in the | |||
8418 | // hierarchy. This substitutes type arguments through. | |||
8419 | const ObjCObjectType *RHSSuper = RHS; | |||
8420 | while (!declaresSameEntity(RHSSuper->getInterface(), LHSInterface)) | |||
8421 | RHSSuper = RHSSuper->getSuperClassType()->castAs<ObjCObjectType>(); | |||
8422 | ||||
8423 | // If the RHS is specializd, compare type arguments. | |||
8424 | if (RHSSuper->isSpecialized() && | |||
8425 | !sameObjCTypeArgs(*this, LHS->getInterface(), | |||
8426 | LHS->getTypeArgs(), RHSSuper->getTypeArgs(), | |||
8427 | /*stripKindOf=*/true)) { | |||
8428 | return false; | |||
8429 | } | |||
8430 | } | |||
8431 | ||||
8432 | return true; | |||
8433 | } | |||
8434 | ||||
8435 | bool ASTContext::areComparableObjCPointerTypes(QualType LHS, QualType RHS) { | |||
8436 | // get the "pointed to" types | |||
8437 | const auto *LHSOPT = LHS->getAs<ObjCObjectPointerType>(); | |||
8438 | const auto *RHSOPT = RHS->getAs<ObjCObjectPointerType>(); | |||
8439 | ||||
8440 | if (!LHSOPT || !RHSOPT) | |||
8441 | return false; | |||
8442 | ||||
8443 | return canAssignObjCInterfaces(LHSOPT, RHSOPT) || | |||
8444 | canAssignObjCInterfaces(RHSOPT, LHSOPT); | |||
8445 | } | |||
8446 | ||||
8447 | bool ASTContext::canBindObjCObjectType(QualType To, QualType From) { | |||
8448 | return canAssignObjCInterfaces( | |||
8449 | getObjCObjectPointerType(To)->getAs<ObjCObjectPointerType>(), | |||
8450 | getObjCObjectPointerType(From)->getAs<ObjCObjectPointerType>()); | |||
8451 | } | |||
8452 | ||||
8453 | /// typesAreCompatible - C99 6.7.3p9: For two qualified types to be compatible, | |||
8454 | /// both shall have the identically qualified version of a compatible type. | |||
8455 | /// C99 6.2.7p1: Two types have compatible types if their types are the | |||
8456 | /// same. See 6.7.[2,3,5] for additional rules. | |||
8457 | bool ASTContext::typesAreCompatible(QualType LHS, QualType RHS, | |||
8458 | bool CompareUnqualified) { | |||
8459 | if (getLangOpts().CPlusPlus) | |||
8460 | return hasSameType(LHS, RHS); | |||
8461 | ||||
8462 | return !mergeTypes(LHS, RHS, false, CompareUnqualified).isNull(); | |||
8463 | } | |||
8464 | ||||
8465 | bool ASTContext::propertyTypesAreCompatible(QualType LHS, QualType RHS) { | |||
8466 | return typesAreCompatible(LHS, RHS); | |||
8467 | } | |||
8468 | ||||
8469 | bool ASTContext::typesAreBlockPointerCompatible(QualType LHS, QualType RHS) { | |||
8470 | return !mergeTypes(LHS, RHS, true).isNull(); | |||
8471 | } | |||
8472 | ||||
8473 | /// mergeTransparentUnionType - if T is a transparent union type and a member | |||
8474 | /// of T is compatible with SubType, return the merged type, else return | |||
8475 | /// QualType() | |||
8476 | QualType ASTContext::mergeTransparentUnionType(QualType T, QualType SubType, | |||
8477 | bool OfBlockPointer, | |||
8478 | bool Unqualified) { | |||
8479 | if (const RecordType *UT = T->getAsUnionType()) { | |||
8480 | RecordDecl *UD = UT->getDecl(); | |||
8481 | if (UD->hasAttr<TransparentUnionAttr>()) { | |||
8482 | for (const auto *I : UD->fields()) { | |||
8483 | QualType ET = I->getType().getUnqualifiedType(); | |||
8484 | QualType MT = mergeTypes(ET, SubType, OfBlockPointer, Unqualified); | |||
8485 | if (!MT.isNull()) | |||
8486 | return MT; | |||
8487 | } | |||
8488 | } | |||
8489 | } | |||
8490 | ||||
8491 | return {}; | |||
8492 | } | |||
8493 | ||||
8494 | /// mergeFunctionParameterTypes - merge two types which appear as function | |||
8495 | /// parameter types | |||
8496 | QualType ASTContext::mergeFunctionParameterTypes(QualType lhs, QualType rhs, | |||
8497 | bool OfBlockPointer, | |||
8498 | bool Unqualified) { | |||
8499 | // GNU extension: two types are compatible if they appear as a function | |||
8500 | // argument, one of the types is a transparent union type and the other | |||
8501 | // type is compatible with a union member | |||
8502 | QualType lmerge = mergeTransparentUnionType(lhs, rhs, OfBlockPointer, | |||
8503 | Unqualified); | |||
8504 | if (!lmerge.isNull()) | |||
8505 | return lmerge; | |||
8506 | ||||
8507 | QualType rmerge = mergeTransparentUnionType(rhs, lhs, OfBlockPointer, | |||
8508 | Unqualified); | |||
8509 | if (!rmerge.isNull()) | |||
8510 | return rmerge; | |||
8511 | ||||
8512 | return mergeTypes(lhs, rhs, OfBlockPointer, Unqualified); | |||
8513 | } | |||
8514 | ||||
8515 | QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs, | |||
8516 | bool OfBlockPointer, | |||
8517 | bool Unqualified) { | |||
8518 | const auto *lbase = lhs->getAs<FunctionType>(); | |||
8519 | const auto *rbase = rhs->getAs<FunctionType>(); | |||
8520 | const auto *lproto = dyn_cast<FunctionProtoType>(lbase); | |||
8521 | const auto *rproto = dyn_cast<FunctionProtoType>(rbase); | |||
8522 | bool allLTypes = true; | |||
8523 | bool allRTypes = true; | |||
8524 | ||||
8525 | // Check return type | |||
8526 | QualType retType; | |||
8527 | if (OfBlockPointer) { | |||
8528 | QualType RHS = rbase->getReturnType(); | |||
8529 | QualType LHS = lbase->getReturnType(); | |||
8530 | bool UnqualifiedResult = Unqualified; | |||
8531 | if (!UnqualifiedResult) | |||
8532 | UnqualifiedResult = (!RHS.hasQualifiers() && LHS.hasQualifiers()); | |||
8533 | retType = mergeTypes(LHS, RHS, true, UnqualifiedResult, true); | |||
8534 | } | |||
8535 | else | |||
8536 | retType = mergeTypes(lbase->getReturnType(), rbase->getReturnType(), false, | |||
8537 | Unqualified); | |||
8538 | if (retType.isNull()) | |||
8539 | return {}; | |||
8540 | ||||
8541 | if (Unqualified) | |||
8542 | retType = retType.getUnqualifiedType(); | |||
8543 | ||||
8544 | CanQualType LRetType = getCanonicalType(lbase->getReturnType()); | |||
8545 | CanQualType RRetType = getCanonicalType(rbase->getReturnType()); | |||
8546 | if (Unqualified) { | |||
8547 | LRetType = LRetType.getUnqualifiedType(); | |||
8548 | RRetType = RRetType.getUnqualifiedType(); | |||
8549 | } | |||
8550 | ||||
8551 | if (getCanonicalType(retType) != LRetType) | |||
8552 | allLTypes = false; | |||
8553 | if (getCanonicalType(retType) != RRetType) | |||
8554 | allRTypes = false; | |||
8555 | ||||
8556 | // FIXME: double check this | |||
8557 | // FIXME: should we error if lbase->getRegParmAttr() != 0 && | |||
8558 | // rbase->getRegParmAttr() != 0 && | |||
8559 | // lbase->getRegParmAttr() != rbase->getRegParmAttr()? | |||
8560 | FunctionType::ExtInfo lbaseInfo = lbase->getExtInfo(); | |||
8561 | FunctionType::ExtInfo rbaseInfo = rbase->getExtInfo(); | |||
8562 | ||||
8563 | // Compatible functions must have compatible calling conventions | |||
8564 | if (lbaseInfo.getCC() != rbaseInfo.getCC()) | |||
8565 | return {}; | |||
8566 | ||||
8567 | // Regparm is part of the calling convention. | |||
8568 | if (lbaseInfo.getHasRegParm() != rbaseInfo.getHasRegParm()) | |||
8569 | return {}; | |||
8570 | if (lbaseInfo.getRegParm() != rbaseInfo.getRegParm()) | |||
8571 | return {}; | |||
8572 | ||||
8573 | if (lbaseInfo.getProducesResult() != rbaseInfo.getProducesResult()) | |||
8574 | return {}; | |||
8575 | if (lbaseInfo.getNoCallerSavedRegs() != rbaseInfo.getNoCallerSavedRegs()) | |||
8576 | return {}; | |||
8577 | if (lbaseInfo.getNoCfCheck() != rbaseInfo.getNoCfCheck()) | |||
8578 | return {}; | |||
8579 | ||||
8580 | // FIXME: some uses, e.g. conditional exprs, really want this to be 'both'. | |||
8581 | bool NoReturn = lbaseInfo.getNoReturn() || rbaseInfo.getNoReturn(); | |||
8582 | ||||
8583 | if (lbaseInfo.getNoReturn() != NoReturn) | |||
8584 | allLTypes = false; | |||
8585 | if (rbaseInfo.getNoReturn() != NoReturn) | |||
8586 | allRTypes = false; | |||
8587 | ||||
8588 | FunctionType::ExtInfo einfo = lbaseInfo.withNoReturn(NoReturn); | |||
8589 | ||||
8590 | if (lproto && rproto) { // two C99 style function prototypes | |||
8591 | assert(!lproto->hasExceptionSpec() && !rproto->hasExceptionSpec() &&((!lproto->hasExceptionSpec() && !rproto->hasExceptionSpec () && "C++ shouldn't be here") ? static_cast<void> (0) : __assert_fail ("!lproto->hasExceptionSpec() && !rproto->hasExceptionSpec() && \"C++ shouldn't be here\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 8592, __PRETTY_FUNCTION__)) | |||
8592 | "C++ shouldn't be here")((!lproto->hasExceptionSpec() && !rproto->hasExceptionSpec () && "C++ shouldn't be here") ? static_cast<void> (0) : __assert_fail ("!lproto->hasExceptionSpec() && !rproto->hasExceptionSpec() && \"C++ shouldn't be here\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 8592, __PRETTY_FUNCTION__)); | |||
8593 | // Compatible functions must have the same number of parameters | |||
8594 | if (lproto->getNumParams() != rproto->getNumParams()) | |||
8595 | return {}; | |||
8596 | ||||
8597 | // Variadic and non-variadic functions aren't compatible | |||
8598 | if (lproto->isVariadic() != rproto->isVariadic()) | |||
8599 | return {}; | |||
8600 | ||||
8601 | if (lproto->getMethodQuals() != rproto->getMethodQuals()) | |||
8602 | return {}; | |||
8603 | ||||
8604 | SmallVector<FunctionProtoType::ExtParameterInfo, 4> newParamInfos; | |||
8605 | bool canUseLeft, canUseRight; | |||
8606 | if (!mergeExtParameterInfo(lproto, rproto, canUseLeft, canUseRight, | |||
8607 | newParamInfos)) | |||
8608 | return {}; | |||
8609 | ||||
8610 | if (!canUseLeft) | |||
8611 | allLTypes = false; | |||
8612 | if (!canUseRight) | |||
8613 | allRTypes = false; | |||
8614 | ||||
8615 | // Check parameter type compatibility | |||
8616 | SmallVector<QualType, 10> types; | |||
8617 | for (unsigned i = 0, n = lproto->getNumParams(); i < n; i++) { | |||
8618 | QualType lParamType = lproto->getParamType(i).getUnqualifiedType(); | |||
8619 | QualType rParamType = rproto->getParamType(i).getUnqualifiedType(); | |||
8620 | QualType paramType = mergeFunctionParameterTypes( | |||
8621 | lParamType, rParamType, OfBlockPointer, Unqualified); | |||
8622 | if (paramType.isNull()) | |||
8623 | return {}; | |||
8624 | ||||
8625 | if (Unqualified) | |||
8626 | paramType = paramType.getUnqualifiedType(); | |||
8627 | ||||
8628 | types.push_back(paramType); | |||
8629 | if (Unqualified) { | |||
8630 | lParamType = lParamType.getUnqualifiedType(); | |||
8631 | rParamType = rParamType.getUnqualifiedType(); | |||
8632 | } | |||
8633 | ||||
8634 | if (getCanonicalType(paramType) != getCanonicalType(lParamType)) | |||
8635 | allLTypes = false; | |||
8636 | if (getCanonicalType(paramType) != getCanonicalType(rParamType)) | |||
8637 | allRTypes = false; | |||
8638 | } | |||
8639 | ||||
8640 | if (allLTypes) return lhs; | |||
8641 | if (allRTypes) return rhs; | |||
8642 | ||||
8643 | FunctionProtoType::ExtProtoInfo EPI = lproto->getExtProtoInfo(); | |||
8644 | EPI.ExtInfo = einfo; | |||
8645 | EPI.ExtParameterInfos = | |||
8646 | newParamInfos.empty() ? nullptr : newParamInfos.data(); | |||
8647 | return getFunctionType(retType, types, EPI); | |||
8648 | } | |||
8649 | ||||
8650 | if (lproto) allRTypes = false; | |||
8651 | if (rproto) allLTypes = false; | |||
8652 | ||||
8653 | const FunctionProtoType *proto = lproto ? lproto : rproto; | |||
8654 | if (proto) { | |||
8655 | assert(!proto->hasExceptionSpec() && "C++ shouldn't be here")((!proto->hasExceptionSpec() && "C++ shouldn't be here" ) ? static_cast<void> (0) : __assert_fail ("!proto->hasExceptionSpec() && \"C++ shouldn't be here\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 8655, __PRETTY_FUNCTION__)); | |||
8656 | if (proto->isVariadic()) | |||
8657 | return {}; | |||
8658 | // Check that the types are compatible with the types that | |||
8659 | // would result from default argument promotions (C99 6.7.5.3p15). | |||
8660 | // The only types actually affected are promotable integer | |||
8661 | // types and floats, which would be passed as a different | |||
8662 | // type depending on whether the prototype is visible. | |||
8663 | for (unsigned i = 0, n = proto->getNumParams(); i < n; ++i) { | |||
8664 | QualType paramTy = proto->getParamType(i); | |||
8665 | ||||
8666 | // Look at the converted type of enum types, since that is the type used | |||
8667 | // to pass enum values. | |||
8668 | if (const auto *Enum = paramTy->getAs<EnumType>()) { | |||
8669 | paramTy = Enum->getDecl()->getIntegerType(); | |||
8670 | if (paramTy.isNull()) | |||
8671 | return {}; | |||
8672 | } | |||
8673 | ||||
8674 | if (paramTy->isPromotableIntegerType() || | |||
8675 | getCanonicalType(paramTy).getUnqualifiedType() == FloatTy) | |||
8676 | return {}; | |||
8677 | } | |||
8678 | ||||
8679 | if (allLTypes) return lhs; | |||
8680 | if (allRTypes) return rhs; | |||
8681 | ||||
8682 | FunctionProtoType::ExtProtoInfo EPI = proto->getExtProtoInfo(); | |||
8683 | EPI.ExtInfo = einfo; | |||
8684 | return getFunctionType(retType, proto->getParamTypes(), EPI); | |||
8685 | } | |||
8686 | ||||
8687 | if (allLTypes) return lhs; | |||
8688 | if (allRTypes) return rhs; | |||
8689 | return getFunctionNoProtoType(retType, einfo); | |||
8690 | } | |||
8691 | ||||
8692 | /// Given that we have an enum type and a non-enum type, try to merge them. | |||
8693 | static QualType mergeEnumWithInteger(ASTContext &Context, const EnumType *ET, | |||
8694 | QualType other, bool isBlockReturnType) { | |||
8695 | // C99 6.7.2.2p4: Each enumerated type shall be compatible with char, | |||
8696 | // a signed integer type, or an unsigned integer type. | |||
8697 | // Compatibility is based on the underlying type, not the promotion | |||
8698 | // type. | |||
8699 | QualType underlyingType = ET->getDecl()->getIntegerType(); | |||
8700 | if (underlyingType.isNull()) | |||
8701 | return {}; | |||
8702 | if (Context.hasSameType(underlyingType, other)) | |||
8703 | return other; | |||
8704 | ||||
8705 | // In block return types, we're more permissive and accept any | |||
8706 | // integral type of the same size. | |||
8707 | if (isBlockReturnType && other->isIntegerType() && | |||
8708 | Context.getTypeSize(underlyingType) == Context.getTypeSize(other)) | |||
8709 | return other; | |||
8710 | ||||
8711 | return {}; | |||
8712 | } | |||
8713 | ||||
8714 | QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, | |||
8715 | bool OfBlockPointer, | |||
8716 | bool Unqualified, bool BlockReturnType) { | |||
8717 | // C++ [expr]: If an expression initially has the type "reference to T", the | |||
8718 | // type is adjusted to "T" prior to any further analysis, the expression | |||
8719 | // designates the object or function denoted by the reference, and the | |||
8720 | // expression is an lvalue unless the reference is an rvalue reference and | |||
8721 | // the expression is a function call (possibly inside parentheses). | |||
8722 | assert(!LHS->getAs<ReferenceType>() && "LHS is a reference type?")((!LHS->getAs<ReferenceType>() && "LHS is a reference type?" ) ? static_cast<void> (0) : __assert_fail ("!LHS->getAs<ReferenceType>() && \"LHS is a reference type?\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 8722, __PRETTY_FUNCTION__)); | |||
8723 | assert(!RHS->getAs<ReferenceType>() && "RHS is a reference type?")((!RHS->getAs<ReferenceType>() && "RHS is a reference type?" ) ? static_cast<void> (0) : __assert_fail ("!RHS->getAs<ReferenceType>() && \"RHS is a reference type?\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 8723, __PRETTY_FUNCTION__)); | |||
8724 | ||||
8725 | if (Unqualified) { | |||
8726 | LHS = LHS.getUnqualifiedType(); | |||
8727 | RHS = RHS.getUnqualifiedType(); | |||
8728 | } | |||
8729 | ||||
8730 | QualType LHSCan = getCanonicalType(LHS), | |||
8731 | RHSCan = getCanonicalType(RHS); | |||
8732 | ||||
8733 | // If two types are identical, they are compatible. | |||
8734 | if (LHSCan == RHSCan) | |||
8735 | return LHS; | |||
8736 | ||||
8737 | // If the qualifiers are different, the types aren't compatible... mostly. | |||
8738 | Qualifiers LQuals = LHSCan.getLocalQualifiers(); | |||
8739 | Qualifiers RQuals = RHSCan.getLocalQualifiers(); | |||
8740 | if (LQuals != RQuals) { | |||
8741 | // If any of these qualifiers are different, we have a type | |||
8742 | // mismatch. | |||
8743 | if (LQuals.getCVRQualifiers() != RQuals.getCVRQualifiers() || | |||
8744 | LQuals.getAddressSpace() != RQuals.getAddressSpace() || | |||
8745 | LQuals.getObjCLifetime() != RQuals.getObjCLifetime() || | |||
8746 | LQuals.hasUnaligned() != RQuals.hasUnaligned()) | |||
8747 | return {}; | |||
8748 | ||||
8749 | // Exactly one GC qualifier difference is allowed: __strong is | |||
8750 | // okay if the other type has no GC qualifier but is an Objective | |||
8751 | // C object pointer (i.e. implicitly strong by default). We fix | |||
8752 | // this by pretending that the unqualified type was actually | |||
8753 | // qualified __strong. | |||
8754 | Qualifiers::GC GC_L = LQuals.getObjCGCAttr(); | |||
8755 | Qualifiers::GC GC_R = RQuals.getObjCGCAttr(); | |||
8756 | assert((GC_L != GC_R) && "unequal qualifier sets had only equal elements")(((GC_L != GC_R) && "unequal qualifier sets had only equal elements" ) ? static_cast<void> (0) : __assert_fail ("(GC_L != GC_R) && \"unequal qualifier sets had only equal elements\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 8756, __PRETTY_FUNCTION__)); | |||
8757 | ||||
8758 | if (GC_L == Qualifiers::Weak || GC_R == Qualifiers::Weak) | |||
8759 | return {}; | |||
8760 | ||||
8761 | if (GC_L == Qualifiers::Strong && RHSCan->isObjCObjectPointerType()) { | |||
8762 | return mergeTypes(LHS, getObjCGCQualType(RHS, Qualifiers::Strong)); | |||
8763 | } | |||
8764 | if (GC_R == Qualifiers::Strong && LHSCan->isObjCObjectPointerType()) { | |||
8765 | return mergeTypes(getObjCGCQualType(LHS, Qualifiers::Strong), RHS); | |||
8766 | } | |||
8767 | return {}; | |||
8768 | } | |||
8769 | ||||
8770 | // Okay, qualifiers are equal. | |||
8771 | ||||
8772 | Type::TypeClass LHSClass = LHSCan->getTypeClass(); | |||
8773 | Type::TypeClass RHSClass = RHSCan->getTypeClass(); | |||
8774 | ||||
8775 | // We want to consider the two function types to be the same for these | |||
8776 | // comparisons, just force one to the other. | |||
8777 | if (LHSClass == Type::FunctionProto) LHSClass = Type::FunctionNoProto; | |||
8778 | if (RHSClass == Type::FunctionProto) RHSClass = Type::FunctionNoProto; | |||
8779 | ||||
8780 | // Same as above for arrays | |||
8781 | if (LHSClass == Type::VariableArray || LHSClass == Type::IncompleteArray) | |||
8782 | LHSClass = Type::ConstantArray; | |||
8783 | if (RHSClass == Type::VariableArray || RHSClass == Type::IncompleteArray) | |||
8784 | RHSClass = Type::ConstantArray; | |||
8785 | ||||
8786 | // ObjCInterfaces are just specialized ObjCObjects. | |||
8787 | if (LHSClass == Type::ObjCInterface) LHSClass = Type::ObjCObject; | |||
8788 | if (RHSClass == Type::ObjCInterface) RHSClass = Type::ObjCObject; | |||
8789 | ||||
8790 | // Canonicalize ExtVector -> Vector. | |||
8791 | if (LHSClass == Type::ExtVector) LHSClass = Type::Vector; | |||
8792 | if (RHSClass == Type::ExtVector) RHSClass = Type::Vector; | |||
8793 | ||||
8794 | // If the canonical type classes don't match. | |||
8795 | if (LHSClass != RHSClass) { | |||
8796 | // Note that we only have special rules for turning block enum | |||
8797 | // returns into block int returns, not vice-versa. | |||
8798 | if (const auto *ETy = LHS->getAs<EnumType>()) { | |||
8799 | return mergeEnumWithInteger(*this, ETy, RHS, false); | |||
8800 | } | |||
8801 | if (const EnumType* ETy = RHS->getAs<EnumType>()) { | |||
8802 | return mergeEnumWithInteger(*this, ETy, LHS, BlockReturnType); | |||
8803 | } | |||
8804 | // allow block pointer type to match an 'id' type. | |||
8805 | if (OfBlockPointer && !BlockReturnType) { | |||
8806 | if (LHS->isObjCIdType() && RHS->isBlockPointerType()) | |||
8807 | return LHS; | |||
8808 | if (RHS->isObjCIdType() && LHS->isBlockPointerType()) | |||
8809 | return RHS; | |||
8810 | } | |||
8811 | ||||
8812 | return {}; | |||
8813 | } | |||
8814 | ||||
8815 | // The canonical type classes match. | |||
8816 | switch (LHSClass) { | |||
8817 | #define TYPE(Class, Base) | |||
8818 | #define ABSTRACT_TYPE(Class, Base) | |||
8819 | #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class: | |||
8820 | #define NON_CANONICAL_TYPE(Class, Base) case Type::Class: | |||
8821 | #define DEPENDENT_TYPE(Class, Base) case Type::Class: | |||
8822 | #include "clang/AST/TypeNodes.def" | |||
8823 | llvm_unreachable("Non-canonical and dependent types shouldn't get here")::llvm::llvm_unreachable_internal("Non-canonical and dependent types shouldn't get here" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 8823); | |||
8824 | ||||
8825 | case Type::Auto: | |||
8826 | case Type::DeducedTemplateSpecialization: | |||
8827 | case Type::LValueReference: | |||
8828 | case Type::RValueReference: | |||
8829 | case Type::MemberPointer: | |||
8830 | llvm_unreachable("C++ should never be in mergeTypes")::llvm::llvm_unreachable_internal("C++ should never be in mergeTypes" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 8830); | |||
8831 | ||||
8832 | case Type::ObjCInterface: | |||
8833 | case Type::IncompleteArray: | |||
8834 | case Type::VariableArray: | |||
8835 | case Type::FunctionProto: | |||
8836 | case Type::ExtVector: | |||
8837 | llvm_unreachable("Types are eliminated above")::llvm::llvm_unreachable_internal("Types are eliminated above" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 8837); | |||
8838 | ||||
8839 | case Type::Pointer: | |||
8840 | { | |||
8841 | // Merge two pointer types, while trying to preserve typedef info | |||
8842 | QualType LHSPointee = LHS->getAs<PointerType>()->getPointeeType(); | |||
8843 | QualType RHSPointee = RHS->getAs<PointerType>()->getPointeeType(); | |||
8844 | if (Unqualified) { | |||
8845 | LHSPointee = LHSPointee.getUnqualifiedType(); | |||
8846 | RHSPointee = RHSPointee.getUnqualifiedType(); | |||
8847 | } | |||
8848 | QualType ResultType = mergeTypes(LHSPointee, RHSPointee, false, | |||
8849 | Unqualified); | |||
8850 | if (ResultType.isNull()) | |||
8851 | return {}; | |||
8852 | if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) | |||
8853 | return LHS; | |||
8854 | if (getCanonicalType(RHSPointee) == getCanonicalType(ResultType)) | |||
8855 | return RHS; | |||
8856 | return getPointerType(ResultType); | |||
8857 | } | |||
8858 | case Type::BlockPointer: | |||
8859 | { | |||
8860 | // Merge two block pointer types, while trying to preserve typedef info | |||
8861 | QualType LHSPointee = LHS->getAs<BlockPointerType>()->getPointeeType(); | |||
8862 | QualType RHSPointee = RHS->getAs<BlockPointerType>()->getPointeeType(); | |||
8863 | if (Unqualified) { | |||
8864 | LHSPointee = LHSPointee.getUnqualifiedType(); | |||
8865 | RHSPointee = RHSPointee.getUnqualifiedType(); | |||
8866 | } | |||
8867 | if (getLangOpts().OpenCL) { | |||
8868 | Qualifiers LHSPteeQual = LHSPointee.getQualifiers(); | |||
8869 | Qualifiers RHSPteeQual = RHSPointee.getQualifiers(); | |||
8870 | // Blocks can't be an expression in a ternary operator (OpenCL v2.0 | |||
8871 | // 6.12.5) thus the following check is asymmetric. | |||
8872 | if (!LHSPteeQual.isAddressSpaceSupersetOf(RHSPteeQual)) | |||
8873 | return {}; | |||
8874 | LHSPteeQual.removeAddressSpace(); | |||
8875 | RHSPteeQual.removeAddressSpace(); | |||
8876 | LHSPointee = | |||
8877 | QualType(LHSPointee.getTypePtr(), LHSPteeQual.getAsOpaqueValue()); | |||
8878 | RHSPointee = | |||
8879 | QualType(RHSPointee.getTypePtr(), RHSPteeQual.getAsOpaqueValue()); | |||
8880 | } | |||
8881 | QualType ResultType = mergeTypes(LHSPointee, RHSPointee, OfBlockPointer, | |||
8882 | Unqualified); | |||
8883 | if (ResultType.isNull()) | |||
8884 | return {}; | |||
8885 | if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) | |||
8886 | return LHS; | |||
8887 | if (getCanonicalType(RHSPointee) == getCanonicalType(ResultType)) | |||
8888 | return RHS; | |||
8889 | return getBlockPointerType(ResultType); | |||
8890 | } | |||
8891 | case Type::Atomic: | |||
8892 | { | |||
8893 | // Merge two pointer types, while trying to preserve typedef info | |||
8894 | QualType LHSValue = LHS->getAs<AtomicType>()->getValueType(); | |||
8895 | QualType RHSValue = RHS->getAs<AtomicType>()->getValueType(); | |||
8896 | if (Unqualified) { | |||
8897 | LHSValue = LHSValue.getUnqualifiedType(); | |||
8898 | RHSValue = RHSValue.getUnqualifiedType(); | |||
8899 | } | |||
8900 | QualType ResultType = mergeTypes(LHSValue, RHSValue, false, | |||
8901 | Unqualified); | |||
8902 | if (ResultType.isNull()) | |||
8903 | return {}; | |||
8904 | if (getCanonicalType(LHSValue) == getCanonicalType(ResultType)) | |||
8905 | return LHS; | |||
8906 | if (getCanonicalType(RHSValue) == getCanonicalType(ResultType)) | |||
8907 | return RHS; | |||
8908 | return getAtomicType(ResultType); | |||
8909 | } | |||
8910 | case Type::ConstantArray: | |||
8911 | { | |||
8912 | const ConstantArrayType* LCAT = getAsConstantArrayType(LHS); | |||
8913 | const ConstantArrayType* RCAT = getAsConstantArrayType(RHS); | |||
8914 | if (LCAT && RCAT && RCAT->getSize() != LCAT->getSize()) | |||
8915 | return {}; | |||
8916 | ||||
8917 | QualType LHSElem = getAsArrayType(LHS)->getElementType(); | |||
8918 | QualType RHSElem = getAsArrayType(RHS)->getElementType(); | |||
8919 | if (Unqualified) { | |||
8920 | LHSElem = LHSElem.getUnqualifiedType(); | |||
8921 | RHSElem = RHSElem.getUnqualifiedType(); | |||
8922 | } | |||
8923 | ||||
8924 | QualType ResultType = mergeTypes(LHSElem, RHSElem, false, Unqualified); | |||
8925 | if (ResultType.isNull()) | |||
8926 | return {}; | |||
8927 | ||||
8928 | const VariableArrayType* LVAT = getAsVariableArrayType(LHS); | |||
8929 | const VariableArrayType* RVAT = getAsVariableArrayType(RHS); | |||
8930 | ||||
8931 | // If either side is a variable array, and both are complete, check whether | |||
8932 | // the current dimension is definite. | |||
8933 | if (LVAT || RVAT) { | |||
8934 | auto SizeFetch = [this](const VariableArrayType* VAT, | |||
8935 | const ConstantArrayType* CAT) | |||
8936 | -> std::pair<bool,llvm::APInt> { | |||
8937 | if (VAT) { | |||
8938 | llvm::APSInt TheInt; | |||
8939 | Expr *E = VAT->getSizeExpr(); | |||
8940 | if (E && E->isIntegerConstantExpr(TheInt, *this)) | |||
8941 | return std::make_pair(true, TheInt); | |||
8942 | else | |||
8943 | return std::make_pair(false, TheInt); | |||
8944 | } else if (CAT) { | |||
8945 | return std::make_pair(true, CAT->getSize()); | |||
8946 | } else { | |||
8947 | return std::make_pair(false, llvm::APInt()); | |||
8948 | } | |||
8949 | }; | |||
8950 | ||||
8951 | bool HaveLSize, HaveRSize; | |||
8952 | llvm::APInt LSize, RSize; | |||
8953 | std::tie(HaveLSize, LSize) = SizeFetch(LVAT, LCAT); | |||
8954 | std::tie(HaveRSize, RSize) = SizeFetch(RVAT, RCAT); | |||
8955 | if (HaveLSize && HaveRSize && !llvm::APInt::isSameValue(LSize, RSize)) | |||
8956 | return {}; // Definite, but unequal, array dimension | |||
8957 | } | |||
8958 | ||||
8959 | if (LCAT && getCanonicalType(LHSElem) == getCanonicalType(ResultType)) | |||
8960 | return LHS; | |||
8961 | if (RCAT && getCanonicalType(RHSElem) == getCanonicalType(ResultType)) | |||
8962 | return RHS; | |||
8963 | if (LCAT) return getConstantArrayType(ResultType, LCAT->getSize(), | |||
8964 | ArrayType::ArraySizeModifier(), 0); | |||
8965 | if (RCAT) return getConstantArrayType(ResultType, RCAT->getSize(), | |||
8966 | ArrayType::ArraySizeModifier(), 0); | |||
8967 | if (LVAT && getCanonicalType(LHSElem) == getCanonicalType(ResultType)) | |||
8968 | return LHS; | |||
8969 | if (RVAT && getCanonicalType(RHSElem) == getCanonicalType(ResultType)) | |||
8970 | return RHS; | |||
8971 | if (LVAT) { | |||
8972 | // FIXME: This isn't correct! But tricky to implement because | |||
8973 | // the array's size has to be the size of LHS, but the type | |||
8974 | // has to be different. | |||
8975 | return LHS; | |||
8976 | } | |||
8977 | if (RVAT) { | |||
8978 | // FIXME: This isn't correct! But tricky to implement because | |||
8979 | // the array's size has to be the size of RHS, but the type | |||
8980 | // has to be different. | |||
8981 | return RHS; | |||
8982 | } | |||
8983 | if (getCanonicalType(LHSElem) == getCanonicalType(ResultType)) return LHS; | |||
8984 | if (getCanonicalType(RHSElem) == getCanonicalType(ResultType)) return RHS; | |||
8985 | return getIncompleteArrayType(ResultType, | |||
8986 | ArrayType::ArraySizeModifier(), 0); | |||
8987 | } | |||
8988 | case Type::FunctionNoProto: | |||
8989 | return mergeFunctionTypes(LHS, RHS, OfBlockPointer, Unqualified); | |||
8990 | case Type::Record: | |||
8991 | case Type::Enum: | |||
8992 | return {}; | |||
8993 | case Type::Builtin: | |||
8994 | // Only exactly equal builtin types are compatible, which is tested above. | |||
8995 | return {}; | |||
8996 | case Type::Complex: | |||
8997 | // Distinct complex types are incompatible. | |||
8998 | return {}; | |||
8999 | case Type::Vector: | |||
9000 | // FIXME: The merged type should be an ExtVector! | |||
9001 | if (areCompatVectorTypes(LHSCan->getAs<VectorType>(), | |||
9002 | RHSCan->getAs<VectorType>())) | |||
9003 | return LHS; | |||
9004 | return {}; | |||
9005 | case Type::ObjCObject: { | |||
9006 | // Check if the types are assignment compatible. | |||
9007 | // FIXME: This should be type compatibility, e.g. whether | |||
9008 | // "LHS x; RHS x;" at global scope is legal. | |||
9009 | const auto *LHSIface = LHS->getAs<ObjCObjectType>(); | |||
9010 | const auto *RHSIface = RHS->getAs<ObjCObjectType>(); | |||
9011 | if (canAssignObjCInterfaces(LHSIface, RHSIface)) | |||
9012 | return LHS; | |||
9013 | ||||
9014 | return {}; | |||
9015 | } | |||
9016 | case Type::ObjCObjectPointer: | |||
9017 | if (OfBlockPointer) { | |||
9018 | if (canAssignObjCInterfacesInBlockPointer( | |||
9019 | LHS->getAs<ObjCObjectPointerType>(), | |||
9020 | RHS->getAs<ObjCObjectPointerType>(), | |||
9021 | BlockReturnType)) | |||
9022 | return LHS; | |||
9023 | return {}; | |||
9024 | } | |||
9025 | if (canAssignObjCInterfaces(LHS->getAs<ObjCObjectPointerType>(), | |||
9026 | RHS->getAs<ObjCObjectPointerType>())) | |||
9027 | return LHS; | |||
9028 | ||||
9029 | return {}; | |||
9030 | case Type::Pipe: | |||
9031 | assert(LHS != RHS &&((LHS != RHS && "Equivalent pipe types should have already been handled!" ) ? static_cast<void> (0) : __assert_fail ("LHS != RHS && \"Equivalent pipe types should have already been handled!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9032, __PRETTY_FUNCTION__)) | |||
9032 | "Equivalent pipe types should have already been handled!")((LHS != RHS && "Equivalent pipe types should have already been handled!" ) ? static_cast<void> (0) : __assert_fail ("LHS != RHS && \"Equivalent pipe types should have already been handled!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9032, __PRETTY_FUNCTION__)); | |||
9033 | return {}; | |||
9034 | } | |||
9035 | ||||
9036 | llvm_unreachable("Invalid Type::Class!")::llvm::llvm_unreachable_internal("Invalid Type::Class!", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9036); | |||
9037 | } | |||
9038 | ||||
9039 | bool ASTContext::mergeExtParameterInfo( | |||
9040 | const FunctionProtoType *FirstFnType, const FunctionProtoType *SecondFnType, | |||
9041 | bool &CanUseFirst, bool &CanUseSecond, | |||
9042 | SmallVectorImpl<FunctionProtoType::ExtParameterInfo> &NewParamInfos) { | |||
9043 | assert(NewParamInfos.empty() && "param info list not empty")((NewParamInfos.empty() && "param info list not empty" ) ? static_cast<void> (0) : __assert_fail ("NewParamInfos.empty() && \"param info list not empty\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9043, __PRETTY_FUNCTION__)); | |||
9044 | CanUseFirst = CanUseSecond = true; | |||
9045 | bool FirstHasInfo = FirstFnType->hasExtParameterInfos(); | |||
9046 | bool SecondHasInfo = SecondFnType->hasExtParameterInfos(); | |||
9047 | ||||
9048 | // Fast path: if the first type doesn't have ext parameter infos, | |||
9049 | // we match if and only if the second type also doesn't have them. | |||
9050 | if (!FirstHasInfo && !SecondHasInfo) | |||
9051 | return true; | |||
9052 | ||||
9053 | bool NeedParamInfo = false; | |||
9054 | size_t E = FirstHasInfo ? FirstFnType->getExtParameterInfos().size() | |||
9055 | : SecondFnType->getExtParameterInfos().size(); | |||
9056 | ||||
9057 | for (size_t I = 0; I < E; ++I) { | |||
9058 | FunctionProtoType::ExtParameterInfo FirstParam, SecondParam; | |||
9059 | if (FirstHasInfo) | |||
9060 | FirstParam = FirstFnType->getExtParameterInfo(I); | |||
9061 | if (SecondHasInfo) | |||
9062 | SecondParam = SecondFnType->getExtParameterInfo(I); | |||
9063 | ||||
9064 | // Cannot merge unless everything except the noescape flag matches. | |||
9065 | if (FirstParam.withIsNoEscape(false) != SecondParam.withIsNoEscape(false)) | |||
9066 | return false; | |||
9067 | ||||
9068 | bool FirstNoEscape = FirstParam.isNoEscape(); | |||
9069 | bool SecondNoEscape = SecondParam.isNoEscape(); | |||
9070 | bool IsNoEscape = FirstNoEscape && SecondNoEscape; | |||
9071 | NewParamInfos.push_back(FirstParam.withIsNoEscape(IsNoEscape)); | |||
9072 | if (NewParamInfos.back().getOpaqueValue()) | |||
9073 | NeedParamInfo = true; | |||
9074 | if (FirstNoEscape != IsNoEscape) | |||
9075 | CanUseFirst = false; | |||
9076 | if (SecondNoEscape != IsNoEscape) | |||
9077 | CanUseSecond = false; | |||
9078 | } | |||
9079 | ||||
9080 | if (!NeedParamInfo) | |||
9081 | NewParamInfos.clear(); | |||
9082 | ||||
9083 | return true; | |||
9084 | } | |||
9085 | ||||
9086 | void ASTContext::ResetObjCLayout(const ObjCContainerDecl *CD) { | |||
9087 | ObjCLayouts[CD] = nullptr; | |||
9088 | } | |||
9089 | ||||
9090 | /// mergeObjCGCQualifiers - This routine merges ObjC's GC attribute of 'LHS' and | |||
9091 | /// 'RHS' attributes and returns the merged version; including for function | |||
9092 | /// return types. | |||
9093 | QualType ASTContext::mergeObjCGCQualifiers(QualType LHS, QualType RHS) { | |||
9094 | QualType LHSCan = getCanonicalType(LHS), | |||
9095 | RHSCan = getCanonicalType(RHS); | |||
9096 | // If two types are identical, they are compatible. | |||
9097 | if (LHSCan == RHSCan) | |||
9098 | return LHS; | |||
9099 | if (RHSCan->isFunctionType()) { | |||
9100 | if (!LHSCan->isFunctionType()) | |||
9101 | return {}; | |||
9102 | QualType OldReturnType = | |||
9103 | cast<FunctionType>(RHSCan.getTypePtr())->getReturnType(); | |||
9104 | QualType NewReturnType = | |||
9105 | cast<FunctionType>(LHSCan.getTypePtr())->getReturnType(); | |||
9106 | QualType ResReturnType = | |||
9107 | mergeObjCGCQualifiers(NewReturnType, OldReturnType); | |||
9108 | if (ResReturnType.isNull()) | |||
9109 | return {}; | |||
9110 | if (ResReturnType == NewReturnType || ResReturnType == OldReturnType) { | |||
9111 | // id foo(); ... __strong id foo(); or: __strong id foo(); ... id foo(); | |||
9112 | // In either case, use OldReturnType to build the new function type. | |||
9113 | const auto *F = LHS->getAs<FunctionType>(); | |||
9114 | if (const auto *FPT = cast<FunctionProtoType>(F)) { | |||
9115 | FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); | |||
9116 | EPI.ExtInfo = getFunctionExtInfo(LHS); | |||
9117 | QualType ResultType = | |||
9118 | getFunctionType(OldReturnType, FPT->getParamTypes(), EPI); | |||
9119 | return ResultType; | |||
9120 | } | |||
9121 | } | |||
9122 | return {}; | |||
9123 | } | |||
9124 | ||||
9125 | // If the qualifiers are different, the types can still be merged. | |||
9126 | Qualifiers LQuals = LHSCan.getLocalQualifiers(); | |||
9127 | Qualifiers RQuals = RHSCan.getLocalQualifiers(); | |||
9128 | if (LQuals != RQuals) { | |||
9129 | // If any of these qualifiers are different, we have a type mismatch. | |||
9130 | if (LQuals.getCVRQualifiers() != RQuals.getCVRQualifiers() || | |||
9131 | LQuals.getAddressSpace() != RQuals.getAddressSpace()) | |||
9132 | return {}; | |||
9133 | ||||
9134 | // Exactly one GC qualifier difference is allowed: __strong is | |||
9135 | // okay if the other type has no GC qualifier but is an Objective | |||
9136 | // C object pointer (i.e. implicitly strong by default). We fix | |||
9137 | // this by pretending that the unqualified type was actually | |||
9138 | // qualified __strong. | |||
9139 | Qualifiers::GC GC_L = LQuals.getObjCGCAttr(); | |||
9140 | Qualifiers::GC GC_R = RQuals.getObjCGCAttr(); | |||
9141 | assert((GC_L != GC_R) && "unequal qualifier sets had only equal elements")(((GC_L != GC_R) && "unequal qualifier sets had only equal elements" ) ? static_cast<void> (0) : __assert_fail ("(GC_L != GC_R) && \"unequal qualifier sets had only equal elements\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9141, __PRETTY_FUNCTION__)); | |||
9142 | ||||
9143 | if (GC_L == Qualifiers::Weak || GC_R == Qualifiers::Weak) | |||
9144 | return {}; | |||
9145 | ||||
9146 | if (GC_L == Qualifiers::Strong) | |||
9147 | return LHS; | |||
9148 | if (GC_R == Qualifiers::Strong) | |||
9149 | return RHS; | |||
9150 | return {}; | |||
9151 | } | |||
9152 | ||||
9153 | if (LHSCan->isObjCObjectPointerType() && RHSCan->isObjCObjectPointerType()) { | |||
9154 | QualType LHSBaseQT = LHS->getAs<ObjCObjectPointerType>()->getPointeeType(); | |||
9155 | QualType RHSBaseQT = RHS->getAs<ObjCObjectPointerType>()->getPointeeType(); | |||
9156 | QualType ResQT = mergeObjCGCQualifiers(LHSBaseQT, RHSBaseQT); | |||
9157 | if (ResQT == LHSBaseQT) | |||
9158 | return LHS; | |||
9159 | if (ResQT == RHSBaseQT) | |||
9160 | return RHS; | |||
9161 | } | |||
9162 | return {}; | |||
9163 | } | |||
9164 | ||||
9165 | //===----------------------------------------------------------------------===// | |||
9166 | // Integer Predicates | |||
9167 | //===----------------------------------------------------------------------===// | |||
9168 | ||||
9169 | unsigned ASTContext::getIntWidth(QualType T) const { | |||
9170 | if (const auto *ET = T->getAs<EnumType>()) | |||
9171 | T = ET->getDecl()->getIntegerType(); | |||
9172 | if (T->isBooleanType()) | |||
9173 | return 1; | |||
9174 | // For builtin types, just use the standard type sizing method | |||
9175 | return (unsigned)getTypeSize(T); | |||
9176 | } | |||
9177 | ||||
9178 | QualType ASTContext::getCorrespondingUnsignedType(QualType T) const { | |||
9179 | assert((T->hasSignedIntegerRepresentation() || T->isSignedFixedPointType()) &&(((T->hasSignedIntegerRepresentation() || T->isSignedFixedPointType ()) && "Unexpected type") ? static_cast<void> ( 0) : __assert_fail ("(T->hasSignedIntegerRepresentation() || T->isSignedFixedPointType()) && \"Unexpected type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9180, __PRETTY_FUNCTION__)) | |||
9180 | "Unexpected type")(((T->hasSignedIntegerRepresentation() || T->isSignedFixedPointType ()) && "Unexpected type") ? static_cast<void> ( 0) : __assert_fail ("(T->hasSignedIntegerRepresentation() || T->isSignedFixedPointType()) && \"Unexpected type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9180, __PRETTY_FUNCTION__)); | |||
9181 | ||||
9182 | // Turn <4 x signed int> -> <4 x unsigned int> | |||
9183 | if (const auto *VTy = T->getAs<VectorType>()) | |||
9184 | return getVectorType(getCorrespondingUnsignedType(VTy->getElementType()), | |||
9185 | VTy->getNumElements(), VTy->getVectorKind()); | |||
9186 | ||||
9187 | // For enums, we return the unsigned version of the base type. | |||
9188 | if (const auto *ETy = T->getAs<EnumType>()) | |||
9189 | T = ETy->getDecl()->getIntegerType(); | |||
9190 | ||||
9191 | const auto *BTy = T->getAs<BuiltinType>(); | |||
9192 | assert(BTy && "Unexpected signed integer or fixed point type")((BTy && "Unexpected signed integer or fixed point type" ) ? static_cast<void> (0) : __assert_fail ("BTy && \"Unexpected signed integer or fixed point type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9192, __PRETTY_FUNCTION__)); | |||
9193 | switch (BTy->getKind()) { | |||
9194 | case BuiltinType::Char_S: | |||
9195 | case BuiltinType::SChar: | |||
9196 | return UnsignedCharTy; | |||
9197 | case BuiltinType::Short: | |||
9198 | return UnsignedShortTy; | |||
9199 | case BuiltinType::Int: | |||
9200 | return UnsignedIntTy; | |||
9201 | case BuiltinType::Long: | |||
9202 | return UnsignedLongTy; | |||
9203 | case BuiltinType::LongLong: | |||
9204 | return UnsignedLongLongTy; | |||
9205 | case BuiltinType::Int128: | |||
9206 | return UnsignedInt128Ty; | |||
9207 | ||||
9208 | case BuiltinType::ShortAccum: | |||
9209 | return UnsignedShortAccumTy; | |||
9210 | case BuiltinType::Accum: | |||
9211 | return UnsignedAccumTy; | |||
9212 | case BuiltinType::LongAccum: | |||
9213 | return UnsignedLongAccumTy; | |||
9214 | case BuiltinType::SatShortAccum: | |||
9215 | return SatUnsignedShortAccumTy; | |||
9216 | case BuiltinType::SatAccum: | |||
9217 | return SatUnsignedAccumTy; | |||
9218 | case BuiltinType::SatLongAccum: | |||
9219 | return SatUnsignedLongAccumTy; | |||
9220 | case BuiltinType::ShortFract: | |||
9221 | return UnsignedShortFractTy; | |||
9222 | case BuiltinType::Fract: | |||
9223 | return UnsignedFractTy; | |||
9224 | case BuiltinType::LongFract: | |||
9225 | return UnsignedLongFractTy; | |||
9226 | case BuiltinType::SatShortFract: | |||
9227 | return SatUnsignedShortFractTy; | |||
9228 | case BuiltinType::SatFract: | |||
9229 | return SatUnsignedFractTy; | |||
9230 | case BuiltinType::SatLongFract: | |||
9231 | return SatUnsignedLongFractTy; | |||
9232 | default: | |||
9233 | llvm_unreachable("Unexpected signed integer or fixed point type")::llvm::llvm_unreachable_internal("Unexpected signed integer or fixed point type" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9233); | |||
9234 | } | |||
9235 | } | |||
9236 | ||||
9237 | ASTMutationListener::~ASTMutationListener() = default; | |||
9238 | ||||
9239 | void ASTMutationListener::DeducedReturnType(const FunctionDecl *FD, | |||
9240 | QualType ReturnType) {} | |||
9241 | ||||
9242 | //===----------------------------------------------------------------------===// | |||
9243 | // Builtin Type Computation | |||
9244 | //===----------------------------------------------------------------------===// | |||
9245 | ||||
9246 | /// DecodeTypeFromStr - This decodes one type descriptor from Str, advancing the | |||
9247 | /// pointer over the consumed characters. This returns the resultant type. If | |||
9248 | /// AllowTypeModifiers is false then modifier like * are not parsed, just basic | |||
9249 | /// types. This allows "v2i*" to be parsed as a pointer to a v2i instead of | |||
9250 | /// a vector of "i*". | |||
9251 | /// | |||
9252 | /// RequiresICE is filled in on return to indicate whether the value is required | |||
9253 | /// to be an Integer Constant Expression. | |||
9254 | static QualType DecodeTypeFromStr(const char *&Str, const ASTContext &Context, | |||
9255 | ASTContext::GetBuiltinTypeError &Error, | |||
9256 | bool &RequiresICE, | |||
9257 | bool AllowTypeModifiers) { | |||
9258 | // Modifiers. | |||
9259 | int HowLong = 0; | |||
9260 | bool Signed = false, Unsigned = false; | |||
9261 | RequiresICE = false; | |||
9262 | ||||
9263 | // Read the prefixed modifiers first. | |||
9264 | bool Done = false; | |||
9265 | #ifndef NDEBUG | |||
9266 | bool IsSpecial = false; | |||
9267 | #endif | |||
9268 | while (!Done) { | |||
9269 | switch (*Str++) { | |||
9270 | default: Done = true; --Str; break; | |||
9271 | case 'I': | |||
9272 | RequiresICE = true; | |||
9273 | break; | |||
9274 | case 'S': | |||
9275 | assert(!Unsigned && "Can't use both 'S' and 'U' modifiers!")((!Unsigned && "Can't use both 'S' and 'U' modifiers!" ) ? static_cast<void> (0) : __assert_fail ("!Unsigned && \"Can't use both 'S' and 'U' modifiers!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9275, __PRETTY_FUNCTION__)); | |||
9276 | assert(!Signed && "Can't use 'S' modifier multiple times!")((!Signed && "Can't use 'S' modifier multiple times!" ) ? static_cast<void> (0) : __assert_fail ("!Signed && \"Can't use 'S' modifier multiple times!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9276, __PRETTY_FUNCTION__)); | |||
9277 | Signed = true; | |||
9278 | break; | |||
9279 | case 'U': | |||
9280 | assert(!Signed && "Can't use both 'S' and 'U' modifiers!")((!Signed && "Can't use both 'S' and 'U' modifiers!") ? static_cast<void> (0) : __assert_fail ("!Signed && \"Can't use both 'S' and 'U' modifiers!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9280, __PRETTY_FUNCTION__)); | |||
9281 | assert(!Unsigned && "Can't use 'U' modifier multiple times!")((!Unsigned && "Can't use 'U' modifier multiple times!" ) ? static_cast<void> (0) : __assert_fail ("!Unsigned && \"Can't use 'U' modifier multiple times!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9281, __PRETTY_FUNCTION__)); | |||
9282 | Unsigned = true; | |||
9283 | break; | |||
9284 | case 'L': | |||
9285 | assert(!IsSpecial && "Can't use 'L' with 'W', 'N', 'Z' or 'O' modifiers")((!IsSpecial && "Can't use 'L' with 'W', 'N', 'Z' or 'O' modifiers" ) ? static_cast<void> (0) : __assert_fail ("!IsSpecial && \"Can't use 'L' with 'W', 'N', 'Z' or 'O' modifiers\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9285, __PRETTY_FUNCTION__)); | |||
9286 | assert(HowLong <= 2 && "Can't have LLLL modifier")((HowLong <= 2 && "Can't have LLLL modifier") ? static_cast <void> (0) : __assert_fail ("HowLong <= 2 && \"Can't have LLLL modifier\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9286, __PRETTY_FUNCTION__)); | |||
9287 | ++HowLong; | |||
9288 | break; | |||
9289 | case 'N': | |||
9290 | // 'N' behaves like 'L' for all non LP64 targets and 'int' otherwise. | |||
9291 | assert(!IsSpecial && "Can't use two 'N', 'W', 'Z' or 'O' modifiers!")((!IsSpecial && "Can't use two 'N', 'W', 'Z' or 'O' modifiers!" ) ? static_cast<void> (0) : __assert_fail ("!IsSpecial && \"Can't use two 'N', 'W', 'Z' or 'O' modifiers!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9291, __PRETTY_FUNCTION__)); | |||
9292 | assert(HowLong == 0 && "Can't use both 'L' and 'N' modifiers!")((HowLong == 0 && "Can't use both 'L' and 'N' modifiers!" ) ? static_cast<void> (0) : __assert_fail ("HowLong == 0 && \"Can't use both 'L' and 'N' modifiers!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9292, __PRETTY_FUNCTION__)); | |||
9293 | #ifndef NDEBUG | |||
9294 | IsSpecial = true; | |||
9295 | #endif | |||
9296 | if (Context.getTargetInfo().getLongWidth() == 32) | |||
9297 | ++HowLong; | |||
9298 | break; | |||
9299 | case 'W': | |||
9300 | // This modifier represents int64 type. | |||
9301 | assert(!IsSpecial && "Can't use two 'N', 'W', 'Z' or 'O' modifiers!")((!IsSpecial && "Can't use two 'N', 'W', 'Z' or 'O' modifiers!" ) ? static_cast<void> (0) : __assert_fail ("!IsSpecial && \"Can't use two 'N', 'W', 'Z' or 'O' modifiers!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9301, __PRETTY_FUNCTION__)); | |||
9302 | assert(HowLong == 0 && "Can't use both 'L' and 'W' modifiers!")((HowLong == 0 && "Can't use both 'L' and 'W' modifiers!" ) ? static_cast<void> (0) : __assert_fail ("HowLong == 0 && \"Can't use both 'L' and 'W' modifiers!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9302, __PRETTY_FUNCTION__)); | |||
9303 | #ifndef NDEBUG | |||
9304 | IsSpecial = true; | |||
9305 | #endif | |||
9306 | switch (Context.getTargetInfo().getInt64Type()) { | |||
9307 | default: | |||
9308 | llvm_unreachable("Unexpected integer type")::llvm::llvm_unreachable_internal("Unexpected integer type", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9308); | |||
9309 | case TargetInfo::SignedLong: | |||
9310 | HowLong = 1; | |||
9311 | break; | |||
9312 | case TargetInfo::SignedLongLong: | |||
9313 | HowLong = 2; | |||
9314 | break; | |||
9315 | } | |||
9316 | break; | |||
9317 | case 'Z': | |||
9318 | // This modifier represents int32 type. | |||
9319 | assert(!IsSpecial && "Can't use two 'N', 'W', 'Z' or 'O' modifiers!")((!IsSpecial && "Can't use two 'N', 'W', 'Z' or 'O' modifiers!" ) ? static_cast<void> (0) : __assert_fail ("!IsSpecial && \"Can't use two 'N', 'W', 'Z' or 'O' modifiers!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9319, __PRETTY_FUNCTION__)); | |||
9320 | assert(HowLong == 0 && "Can't use both 'L' and 'Z' modifiers!")((HowLong == 0 && "Can't use both 'L' and 'Z' modifiers!" ) ? static_cast<void> (0) : __assert_fail ("HowLong == 0 && \"Can't use both 'L' and 'Z' modifiers!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9320, __PRETTY_FUNCTION__)); | |||
9321 | #ifndef NDEBUG | |||
9322 | IsSpecial = true; | |||
9323 | #endif | |||
9324 | switch (Context.getTargetInfo().getIntTypeByWidth(32, true)) { | |||
9325 | default: | |||
9326 | llvm_unreachable("Unexpected integer type")::llvm::llvm_unreachable_internal("Unexpected integer type", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9326); | |||
9327 | case TargetInfo::SignedInt: | |||
9328 | HowLong = 0; | |||
9329 | break; | |||
9330 | case TargetInfo::SignedLong: | |||
9331 | HowLong = 1; | |||
9332 | break; | |||
9333 | case TargetInfo::SignedLongLong: | |||
9334 | HowLong = 2; | |||
9335 | break; | |||
9336 | } | |||
9337 | break; | |||
9338 | case 'O': | |||
9339 | assert(!IsSpecial && "Can't use two 'N', 'W', 'Z' or 'O' modifiers!")((!IsSpecial && "Can't use two 'N', 'W', 'Z' or 'O' modifiers!" ) ? static_cast<void> (0) : __assert_fail ("!IsSpecial && \"Can't use two 'N', 'W', 'Z' or 'O' modifiers!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9339, __PRETTY_FUNCTION__)); | |||
9340 | assert(HowLong == 0 && "Can't use both 'L' and 'O' modifiers!")((HowLong == 0 && "Can't use both 'L' and 'O' modifiers!" ) ? static_cast<void> (0) : __assert_fail ("HowLong == 0 && \"Can't use both 'L' and 'O' modifiers!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9340, __PRETTY_FUNCTION__)); | |||
9341 | #ifndef NDEBUG | |||
9342 | IsSpecial = true; | |||
9343 | #endif | |||
9344 | if (Context.getLangOpts().OpenCL) | |||
9345 | HowLong = 1; | |||
9346 | else | |||
9347 | HowLong = 2; | |||
9348 | break; | |||
9349 | } | |||
9350 | } | |||
9351 | ||||
9352 | QualType Type; | |||
9353 | ||||
9354 | // Read the base type. | |||
9355 | switch (*Str++) { | |||
9356 | default: llvm_unreachable("Unknown builtin type letter!")::llvm::llvm_unreachable_internal("Unknown builtin type letter!" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9356); | |||
9357 | case 'v': | |||
9358 | assert(HowLong == 0 && !Signed && !Unsigned &&((HowLong == 0 && !Signed && !Unsigned && "Bad modifiers used with 'v'!") ? static_cast<void> (0 ) : __assert_fail ("HowLong == 0 && !Signed && !Unsigned && \"Bad modifiers used with 'v'!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9359, __PRETTY_FUNCTION__)) | |||
9359 | "Bad modifiers used with 'v'!")((HowLong == 0 && !Signed && !Unsigned && "Bad modifiers used with 'v'!") ? static_cast<void> (0 ) : __assert_fail ("HowLong == 0 && !Signed && !Unsigned && \"Bad modifiers used with 'v'!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9359, __PRETTY_FUNCTION__)); | |||
9360 | Type = Context.VoidTy; | |||
9361 | break; | |||
9362 | case 'h': | |||
9363 | assert(HowLong == 0 && !Signed && !Unsigned &&((HowLong == 0 && !Signed && !Unsigned && "Bad modifiers used with 'h'!") ? static_cast<void> (0 ) : __assert_fail ("HowLong == 0 && !Signed && !Unsigned && \"Bad modifiers used with 'h'!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9364, __PRETTY_FUNCTION__)) | |||
9364 | "Bad modifiers used with 'h'!")((HowLong == 0 && !Signed && !Unsigned && "Bad modifiers used with 'h'!") ? static_cast<void> (0 ) : __assert_fail ("HowLong == 0 && !Signed && !Unsigned && \"Bad modifiers used with 'h'!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9364, __PRETTY_FUNCTION__)); | |||
9365 | Type = Context.HalfTy; | |||
9366 | break; | |||
9367 | case 'f': | |||
9368 | assert(HowLong == 0 && !Signed && !Unsigned &&((HowLong == 0 && !Signed && !Unsigned && "Bad modifiers used with 'f'!") ? static_cast<void> (0 ) : __assert_fail ("HowLong == 0 && !Signed && !Unsigned && \"Bad modifiers used with 'f'!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9369, __PRETTY_FUNCTION__)) | |||
9369 | "Bad modifiers used with 'f'!")((HowLong == 0 && !Signed && !Unsigned && "Bad modifiers used with 'f'!") ? static_cast<void> (0 ) : __assert_fail ("HowLong == 0 && !Signed && !Unsigned && \"Bad modifiers used with 'f'!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9369, __PRETTY_FUNCTION__)); | |||
9370 | Type = Context.FloatTy; | |||
9371 | break; | |||
9372 | case 'd': | |||
9373 | assert(HowLong < 3 && !Signed && !Unsigned &&((HowLong < 3 && !Signed && !Unsigned && "Bad modifiers used with 'd'!") ? static_cast<void> (0 ) : __assert_fail ("HowLong < 3 && !Signed && !Unsigned && \"Bad modifiers used with 'd'!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9374, __PRETTY_FUNCTION__)) | |||
9374 | "Bad modifiers used with 'd'!")((HowLong < 3 && !Signed && !Unsigned && "Bad modifiers used with 'd'!") ? static_cast<void> (0 ) : __assert_fail ("HowLong < 3 && !Signed && !Unsigned && \"Bad modifiers used with 'd'!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9374, __PRETTY_FUNCTION__)); | |||
9375 | if (HowLong == 1) | |||
9376 | Type = Context.LongDoubleTy; | |||
9377 | else if (HowLong == 2) | |||
9378 | Type = Context.Float128Ty; | |||
9379 | else | |||
9380 | Type = Context.DoubleTy; | |||
9381 | break; | |||
9382 | case 's': | |||
9383 | assert(HowLong == 0 && "Bad modifiers used with 's'!")((HowLong == 0 && "Bad modifiers used with 's'!") ? static_cast <void> (0) : __assert_fail ("HowLong == 0 && \"Bad modifiers used with 's'!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9383, __PRETTY_FUNCTION__)); | |||
9384 | if (Unsigned) | |||
9385 | Type = Context.UnsignedShortTy; | |||
9386 | else | |||
9387 | Type = Context.ShortTy; | |||
9388 | break; | |||
9389 | case 'i': | |||
9390 | if (HowLong == 3) | |||
9391 | Type = Unsigned ? Context.UnsignedInt128Ty : Context.Int128Ty; | |||
9392 | else if (HowLong == 2) | |||
9393 | Type = Unsigned ? Context.UnsignedLongLongTy : Context.LongLongTy; | |||
9394 | else if (HowLong == 1) | |||
9395 | Type = Unsigned ? Context.UnsignedLongTy : Context.LongTy; | |||
9396 | else | |||
9397 | Type = Unsigned ? Context.UnsignedIntTy : Context.IntTy; | |||
9398 | break; | |||
9399 | case 'c': | |||
9400 | assert(HowLong == 0 && "Bad modifiers used with 'c'!")((HowLong == 0 && "Bad modifiers used with 'c'!") ? static_cast <void> (0) : __assert_fail ("HowLong == 0 && \"Bad modifiers used with 'c'!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9400, __PRETTY_FUNCTION__)); | |||
9401 | if (Signed) | |||
9402 | Type = Context.SignedCharTy; | |||
9403 | else if (Unsigned) | |||
9404 | Type = Context.UnsignedCharTy; | |||
9405 | else | |||
9406 | Type = Context.CharTy; | |||
9407 | break; | |||
9408 | case 'b': // boolean | |||
9409 | assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'b'!")((HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'b'!") ? static_cast<void> (0) : __assert_fail ("HowLong == 0 && !Signed && !Unsigned && \"Bad modifiers for 'b'!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9409, __PRETTY_FUNCTION__)); | |||
9410 | Type = Context.BoolTy; | |||
9411 | break; | |||
9412 | case 'z': // size_t. | |||
9413 | assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'z'!")((HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'z'!") ? static_cast<void> (0) : __assert_fail ("HowLong == 0 && !Signed && !Unsigned && \"Bad modifiers for 'z'!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9413, __PRETTY_FUNCTION__)); | |||
9414 | Type = Context.getSizeType(); | |||
9415 | break; | |||
9416 | case 'w': // wchar_t. | |||
9417 | assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'w'!")((HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'w'!") ? static_cast<void> (0) : __assert_fail ("HowLong == 0 && !Signed && !Unsigned && \"Bad modifiers for 'w'!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9417, __PRETTY_FUNCTION__)); | |||
9418 | Type = Context.getWideCharType(); | |||
9419 | break; | |||
9420 | case 'F': | |||
9421 | Type = Context.getCFConstantStringType(); | |||
9422 | break; | |||
9423 | case 'G': | |||
9424 | Type = Context.getObjCIdType(); | |||
9425 | break; | |||
9426 | case 'H': | |||
9427 | Type = Context.getObjCSelType(); | |||
9428 | break; | |||
9429 | case 'M': | |||
9430 | Type = Context.getObjCSuperType(); | |||
9431 | break; | |||
9432 | case 'a': | |||
9433 | Type = Context.getBuiltinVaListType(); | |||
9434 | assert(!Type.isNull() && "builtin va list type not initialized!")((!Type.isNull() && "builtin va list type not initialized!" ) ? static_cast<void> (0) : __assert_fail ("!Type.isNull() && \"builtin va list type not initialized!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9434, __PRETTY_FUNCTION__)); | |||
9435 | break; | |||
9436 | case 'A': | |||
9437 | // This is a "reference" to a va_list; however, what exactly | |||
9438 | // this means depends on how va_list is defined. There are two | |||
9439 | // different kinds of va_list: ones passed by value, and ones | |||
9440 | // passed by reference. An example of a by-value va_list is | |||
9441 | // x86, where va_list is a char*. An example of by-ref va_list | |||
9442 | // is x86-64, where va_list is a __va_list_tag[1]. For x86, | |||
9443 | // we want this argument to be a char*&; for x86-64, we want | |||
9444 | // it to be a __va_list_tag*. | |||
9445 | Type = Context.getBuiltinVaListType(); | |||
9446 | assert(!Type.isNull() && "builtin va list type not initialized!")((!Type.isNull() && "builtin va list type not initialized!" ) ? static_cast<void> (0) : __assert_fail ("!Type.isNull() && \"builtin va list type not initialized!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9446, __PRETTY_FUNCTION__)); | |||
9447 | if (Type->isArrayType()) | |||
9448 | Type = Context.getArrayDecayedType(Type); | |||
9449 | else | |||
9450 | Type = Context.getLValueReferenceType(Type); | |||
9451 | break; | |||
9452 | case 'V': { | |||
9453 | char *End; | |||
9454 | unsigned NumElements = strtoul(Str, &End, 10); | |||
9455 | assert(End != Str && "Missing vector size")((End != Str && "Missing vector size") ? static_cast< void> (0) : __assert_fail ("End != Str && \"Missing vector size\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9455, __PRETTY_FUNCTION__)); | |||
9456 | Str = End; | |||
9457 | ||||
9458 | QualType ElementType = DecodeTypeFromStr(Str, Context, Error, | |||
9459 | RequiresICE, false); | |||
9460 | assert(!RequiresICE && "Can't require vector ICE")((!RequiresICE && "Can't require vector ICE") ? static_cast <void> (0) : __assert_fail ("!RequiresICE && \"Can't require vector ICE\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9460, __PRETTY_FUNCTION__)); | |||
9461 | ||||
9462 | // TODO: No way to make AltiVec vectors in builtins yet. | |||
9463 | Type = Context.getVectorType(ElementType, NumElements, | |||
9464 | VectorType::GenericVector); | |||
9465 | break; | |||
9466 | } | |||
9467 | case 'E': { | |||
9468 | char *End; | |||
9469 | ||||
9470 | unsigned NumElements = strtoul(Str, &End, 10); | |||
9471 | assert(End != Str && "Missing vector size")((End != Str && "Missing vector size") ? static_cast< void> (0) : __assert_fail ("End != Str && \"Missing vector size\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9471, __PRETTY_FUNCTION__)); | |||
9472 | ||||
9473 | Str = End; | |||
9474 | ||||
9475 | QualType ElementType = DecodeTypeFromStr(Str, Context, Error, RequiresICE, | |||
9476 | false); | |||
9477 | Type = Context.getExtVectorType(ElementType, NumElements); | |||
9478 | break; | |||
9479 | } | |||
9480 | case 'X': { | |||
9481 | QualType ElementType = DecodeTypeFromStr(Str, Context, Error, RequiresICE, | |||
9482 | false); | |||
9483 | assert(!RequiresICE && "Can't require complex ICE")((!RequiresICE && "Can't require complex ICE") ? static_cast <void> (0) : __assert_fail ("!RequiresICE && \"Can't require complex ICE\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9483, __PRETTY_FUNCTION__)); | |||
9484 | Type = Context.getComplexType(ElementType); | |||
9485 | break; | |||
9486 | } | |||
9487 | case 'Y': | |||
9488 | Type = Context.getPointerDiffType(); | |||
9489 | break; | |||
9490 | case 'P': | |||
9491 | Type = Context.getFILEType(); | |||
9492 | if (Type.isNull()) { | |||
9493 | Error = ASTContext::GE_Missing_stdio; | |||
9494 | return {}; | |||
9495 | } | |||
9496 | break; | |||
9497 | case 'J': | |||
9498 | if (Signed) | |||
9499 | Type = Context.getsigjmp_bufType(); | |||
9500 | else | |||
9501 | Type = Context.getjmp_bufType(); | |||
9502 | ||||
9503 | if (Type.isNull()) { | |||
9504 | Error = ASTContext::GE_Missing_setjmp; | |||
9505 | return {}; | |||
9506 | } | |||
9507 | break; | |||
9508 | case 'K': | |||
9509 | assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'K'!")((HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'K'!") ? static_cast<void> (0) : __assert_fail ("HowLong == 0 && !Signed && !Unsigned && \"Bad modifiers for 'K'!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9509, __PRETTY_FUNCTION__)); | |||
9510 | Type = Context.getucontext_tType(); | |||
9511 | ||||
9512 | if (Type.isNull()) { | |||
9513 | Error = ASTContext::GE_Missing_ucontext; | |||
9514 | return {}; | |||
9515 | } | |||
9516 | break; | |||
9517 | case 'p': | |||
9518 | Type = Context.getProcessIDType(); | |||
9519 | break; | |||
9520 | } | |||
9521 | ||||
9522 | // If there are modifiers and if we're allowed to parse them, go for it. | |||
9523 | Done = !AllowTypeModifiers; | |||
9524 | while (!Done) { | |||
9525 | switch (char c = *Str++) { | |||
9526 | default: Done = true; --Str; break; | |||
9527 | case '*': | |||
9528 | case '&': { | |||
9529 | // Both pointers and references can have their pointee types | |||
9530 | // qualified with an address space. | |||
9531 | char *End; | |||
9532 | unsigned AddrSpace = strtoul(Str, &End, 10); | |||
9533 | if (End != Str) { | |||
9534 | // Note AddrSpace == 0 is not the same as an unspecified address space. | |||
9535 | Type = Context.getAddrSpaceQualType( | |||
9536 | Type, | |||
9537 | Context.getLangASForBuiltinAddressSpace(AddrSpace)); | |||
9538 | Str = End; | |||
9539 | } | |||
9540 | if (c == '*') | |||
9541 | Type = Context.getPointerType(Type); | |||
9542 | else | |||
9543 | Type = Context.getLValueReferenceType(Type); | |||
9544 | break; | |||
9545 | } | |||
9546 | // FIXME: There's no way to have a built-in with an rvalue ref arg. | |||
9547 | case 'C': | |||
9548 | Type = Type.withConst(); | |||
9549 | break; | |||
9550 | case 'D': | |||
9551 | Type = Context.getVolatileType(Type); | |||
9552 | break; | |||
9553 | case 'R': | |||
9554 | Type = Type.withRestrict(); | |||
9555 | break; | |||
9556 | } | |||
9557 | } | |||
9558 | ||||
9559 | assert((!RequiresICE || Type->isIntegralOrEnumerationType()) &&(((!RequiresICE || Type->isIntegralOrEnumerationType()) && "Integer constant 'I' type must be an integer") ? static_cast <void> (0) : __assert_fail ("(!RequiresICE || Type->isIntegralOrEnumerationType()) && \"Integer constant 'I' type must be an integer\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9560, __PRETTY_FUNCTION__)) | |||
9560 | "Integer constant 'I' type must be an integer")(((!RequiresICE || Type->isIntegralOrEnumerationType()) && "Integer constant 'I' type must be an integer") ? static_cast <void> (0) : __assert_fail ("(!RequiresICE || Type->isIntegralOrEnumerationType()) && \"Integer constant 'I' type must be an integer\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9560, __PRETTY_FUNCTION__)); | |||
9561 | ||||
9562 | return Type; | |||
9563 | } | |||
9564 | ||||
9565 | /// GetBuiltinType - Return the type for the specified builtin. | |||
9566 | QualType ASTContext::GetBuiltinType(unsigned Id, | |||
9567 | GetBuiltinTypeError &Error, | |||
9568 | unsigned *IntegerConstantArgs) const { | |||
9569 | const char *TypeStr = BuiltinInfo.getTypeString(Id); | |||
9570 | if (TypeStr[0] == '\0') { | |||
9571 | Error = GE_Missing_type; | |||
9572 | return {}; | |||
9573 | } | |||
9574 | ||||
9575 | SmallVector<QualType, 8> ArgTypes; | |||
9576 | ||||
9577 | bool RequiresICE = false; | |||
9578 | Error = GE_None; | |||
9579 | QualType ResType = DecodeTypeFromStr(TypeStr, *this, Error, | |||
9580 | RequiresICE, true); | |||
9581 | if (Error != GE_None) | |||
9582 | return {}; | |||
9583 | ||||
9584 | assert(!RequiresICE && "Result of intrinsic cannot be required to be an ICE")((!RequiresICE && "Result of intrinsic cannot be required to be an ICE" ) ? static_cast<void> (0) : __assert_fail ("!RequiresICE && \"Result of intrinsic cannot be required to be an ICE\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9584, __PRETTY_FUNCTION__)); | |||
9585 | ||||
9586 | while (TypeStr[0] && TypeStr[0] != '.') { | |||
9587 | QualType Ty = DecodeTypeFromStr(TypeStr, *this, Error, RequiresICE, true); | |||
9588 | if (Error != GE_None) | |||
9589 | return {}; | |||
9590 | ||||
9591 | // If this argument is required to be an IntegerConstantExpression and the | |||
9592 | // caller cares, fill in the bitmask we return. | |||
9593 | if (RequiresICE && IntegerConstantArgs) | |||
9594 | *IntegerConstantArgs |= 1 << ArgTypes.size(); | |||
9595 | ||||
9596 | // Do array -> pointer decay. The builtin should use the decayed type. | |||
9597 | if (Ty->isArrayType()) | |||
9598 | Ty = getArrayDecayedType(Ty); | |||
9599 | ||||
9600 | ArgTypes.push_back(Ty); | |||
9601 | } | |||
9602 | ||||
9603 | if (Id == Builtin::BI__GetExceptionInfo) | |||
9604 | return {}; | |||
9605 | ||||
9606 | assert((TypeStr[0] != '.' || TypeStr[1] == 0) &&(((TypeStr[0] != '.' || TypeStr[1] == 0) && "'.' should only occur at end of builtin type list!" ) ? static_cast<void> (0) : __assert_fail ("(TypeStr[0] != '.' || TypeStr[1] == 0) && \"'.' should only occur at end of builtin type list!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9607, __PRETTY_FUNCTION__)) | |||
9607 | "'.' should only occur at end of builtin type list!")(((TypeStr[0] != '.' || TypeStr[1] == 0) && "'.' should only occur at end of builtin type list!" ) ? static_cast<void> (0) : __assert_fail ("(TypeStr[0] != '.' || TypeStr[1] == 0) && \"'.' should only occur at end of builtin type list!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9607, __PRETTY_FUNCTION__)); | |||
9608 | ||||
9609 | bool Variadic = (TypeStr[0] == '.'); | |||
9610 | ||||
9611 | FunctionType::ExtInfo EI(getDefaultCallingConvention( | |||
9612 | Variadic, /*IsCXXMethod=*/false, /*IsBuiltin=*/true)); | |||
9613 | if (BuiltinInfo.isNoReturn(Id)) EI = EI.withNoReturn(true); | |||
9614 | ||||
9615 | ||||
9616 | // We really shouldn't be making a no-proto type here. | |||
9617 | if (ArgTypes.empty() && Variadic && !getLangOpts().CPlusPlus) | |||
9618 | return getFunctionNoProtoType(ResType, EI); | |||
9619 | ||||
9620 | FunctionProtoType::ExtProtoInfo EPI; | |||
9621 | EPI.ExtInfo = EI; | |||
9622 | EPI.Variadic = Variadic; | |||
9623 | if (getLangOpts().CPlusPlus && BuiltinInfo.isNoThrow(Id)) | |||
9624 | EPI.ExceptionSpec.Type = | |||
9625 | getLangOpts().CPlusPlus11 ? EST_BasicNoexcept : EST_DynamicNone; | |||
9626 | ||||
9627 | return getFunctionType(ResType, ArgTypes, EPI); | |||
9628 | } | |||
9629 | ||||
9630 | static GVALinkage basicGVALinkageForFunction(const ASTContext &Context, | |||
9631 | const FunctionDecl *FD) { | |||
9632 | if (!FD->isExternallyVisible()) | |||
9633 | return GVA_Internal; | |||
9634 | ||||
9635 | // Non-user-provided functions get emitted as weak definitions with every | |||
9636 | // use, no matter whether they've been explicitly instantiated etc. | |||
9637 | if (const auto *MD = dyn_cast<CXXMethodDecl>(FD)) | |||
9638 | if (!MD->isUserProvided()) | |||
9639 | return GVA_DiscardableODR; | |||
9640 | ||||
9641 | GVALinkage External; | |||
9642 | switch (FD->getTemplateSpecializationKind()) { | |||
9643 | case TSK_Undeclared: | |||
9644 | case TSK_ExplicitSpecialization: | |||
9645 | External = GVA_StrongExternal; | |||
9646 | break; | |||
9647 | ||||
9648 | case TSK_ExplicitInstantiationDefinition: | |||
9649 | return GVA_StrongODR; | |||
9650 | ||||
9651 | // C++11 [temp.explicit]p10: | |||
9652 | // [ Note: The intent is that an inline function that is the subject of | |||
9653 | // an explicit instantiation declaration will still be implicitly | |||
9654 | // instantiated when used so that the body can be considered for | |||
9655 | // inlining, but that no out-of-line copy of the inline function would be | |||
9656 | // generated in the translation unit. -- end note ] | |||
9657 | case TSK_ExplicitInstantiationDeclaration: | |||
9658 | return GVA_AvailableExternally; | |||
9659 | ||||
9660 | case TSK_ImplicitInstantiation: | |||
9661 | External = GVA_DiscardableODR; | |||
9662 | break; | |||
9663 | } | |||
9664 | ||||
9665 | if (!FD->isInlined()) | |||
9666 | return External; | |||
9667 | ||||
9668 | if ((!Context.getLangOpts().CPlusPlus && | |||
9669 | !Context.getTargetInfo().getCXXABI().isMicrosoft() && | |||
9670 | !FD->hasAttr<DLLExportAttr>()) || | |||
9671 | FD->hasAttr<GNUInlineAttr>()) { | |||
9672 | // FIXME: This doesn't match gcc's behavior for dllexport inline functions. | |||
9673 | ||||
9674 | // GNU or C99 inline semantics. Determine whether this symbol should be | |||
9675 | // externally visible. | |||
9676 | if (FD->isInlineDefinitionExternallyVisible()) | |||
9677 | return External; | |||
9678 | ||||
9679 | // C99 inline semantics, where the symbol is not externally visible. | |||
9680 | return GVA_AvailableExternally; | |||
9681 | } | |||
9682 | ||||
9683 | // Functions specified with extern and inline in -fms-compatibility mode | |||
9684 | // forcibly get emitted. While the body of the function cannot be later | |||
9685 | // replaced, the function definition cannot be discarded. | |||
9686 | if (FD->isMSExternInline()) | |||
9687 | return GVA_StrongODR; | |||
9688 | ||||
9689 | return GVA_DiscardableODR; | |||
9690 | } | |||
9691 | ||||
9692 | static GVALinkage adjustGVALinkageForAttributes(const ASTContext &Context, | |||
9693 | const Decl *D, GVALinkage L) { | |||
9694 | // See http://msdn.microsoft.com/en-us/library/xa0d9ste.aspx | |||
9695 | // dllexport/dllimport on inline functions. | |||
9696 | if (D->hasAttr<DLLImportAttr>()) { | |||
9697 | if (L == GVA_DiscardableODR || L == GVA_StrongODR) | |||
9698 | return GVA_AvailableExternally; | |||
9699 | } else if (D->hasAttr<DLLExportAttr>()) { | |||
9700 | if (L == GVA_DiscardableODR) | |||
9701 | return GVA_StrongODR; | |||
9702 | } else if (Context.getLangOpts().CUDA && Context.getLangOpts().CUDAIsDevice && | |||
9703 | D->hasAttr<CUDAGlobalAttr>()) { | |||
9704 | // Device-side functions with __global__ attribute must always be | |||
9705 | // visible externally so they can be launched from host. | |||
9706 | if (L == GVA_DiscardableODR || L == GVA_Internal) | |||
9707 | return GVA_StrongODR; | |||
9708 | } | |||
9709 | return L; | |||
9710 | } | |||
9711 | ||||
9712 | /// Adjust the GVALinkage for a declaration based on what an external AST source | |||
9713 | /// knows about whether there can be other definitions of this declaration. | |||
9714 | static GVALinkage | |||
9715 | adjustGVALinkageForExternalDefinitionKind(const ASTContext &Ctx, const Decl *D, | |||
9716 | GVALinkage L) { | |||
9717 | ExternalASTSource *Source = Ctx.getExternalSource(); | |||
9718 | if (!Source) | |||
9719 | return L; | |||
9720 | ||||
9721 | switch (Source->hasExternalDefinitions(D)) { | |||
9722 | case ExternalASTSource::EK_Never: | |||
9723 | // Other translation units rely on us to provide the definition. | |||
9724 | if (L == GVA_DiscardableODR) | |||
9725 | return GVA_StrongODR; | |||
9726 | break; | |||
9727 | ||||
9728 | case ExternalASTSource::EK_Always: | |||
9729 | return GVA_AvailableExternally; | |||
9730 | ||||
9731 | case ExternalASTSource::EK_ReplyHazy: | |||
9732 | break; | |||
9733 | } | |||
9734 | return L; | |||
9735 | } | |||
9736 | ||||
9737 | GVALinkage ASTContext::GetGVALinkageForFunction(const FunctionDecl *FD) const { | |||
9738 | return adjustGVALinkageForExternalDefinitionKind(*this, FD, | |||
9739 | adjustGVALinkageForAttributes(*this, FD, | |||
9740 | basicGVALinkageForFunction(*this, FD))); | |||
9741 | } | |||
9742 | ||||
9743 | static GVALinkage basicGVALinkageForVariable(const ASTContext &Context, | |||
9744 | const VarDecl *VD) { | |||
9745 | if (!VD->isExternallyVisible()) | |||
9746 | return GVA_Internal; | |||
9747 | ||||
9748 | if (VD->isStaticLocal()) { | |||
9749 | const DeclContext *LexicalContext = VD->getParentFunctionOrMethod(); | |||
9750 | while (LexicalContext && !isa<FunctionDecl>(LexicalContext)) | |||
9751 | LexicalContext = LexicalContext->getLexicalParent(); | |||
9752 | ||||
9753 | // ObjC Blocks can create local variables that don't have a FunctionDecl | |||
9754 | // LexicalContext. | |||
9755 | if (!LexicalContext) | |||
9756 | return GVA_DiscardableODR; | |||
9757 | ||||
9758 | // Otherwise, let the static local variable inherit its linkage from the | |||
9759 | // nearest enclosing function. | |||
9760 | auto StaticLocalLinkage = | |||
9761 | Context.GetGVALinkageForFunction(cast<FunctionDecl>(LexicalContext)); | |||
9762 | ||||
9763 | // Itanium ABI 5.2.2: "Each COMDAT group [for a static local variable] must | |||
9764 | // be emitted in any object with references to the symbol for the object it | |||
9765 | // contains, whether inline or out-of-line." | |||
9766 | // Similar behavior is observed with MSVC. An alternative ABI could use | |||
9767 | // StrongODR/AvailableExternally to match the function, but none are | |||
9768 | // known/supported currently. | |||
9769 | if (StaticLocalLinkage == GVA_StrongODR || | |||
9770 | StaticLocalLinkage == GVA_AvailableExternally) | |||
9771 | return GVA_DiscardableODR; | |||
9772 | return StaticLocalLinkage; | |||
9773 | } | |||
9774 | ||||
9775 | // MSVC treats in-class initialized static data members as definitions. | |||
9776 | // By giving them non-strong linkage, out-of-line definitions won't | |||
9777 | // cause link errors. | |||
9778 | if (Context.isMSStaticDataMemberInlineDefinition(VD)) | |||
9779 | return GVA_DiscardableODR; | |||
9780 | ||||
9781 | // Most non-template variables have strong linkage; inline variables are | |||
9782 | // linkonce_odr or (occasionally, for compatibility) weak_odr. | |||
9783 | GVALinkage StrongLinkage; | |||
9784 | switch (Context.getInlineVariableDefinitionKind(VD)) { | |||
9785 | case ASTContext::InlineVariableDefinitionKind::None: | |||
9786 | StrongLinkage = GVA_StrongExternal; | |||
9787 | break; | |||
9788 | case ASTContext::InlineVariableDefinitionKind::Weak: | |||
9789 | case ASTContext::InlineVariableDefinitionKind::WeakUnknown: | |||
9790 | StrongLinkage = GVA_DiscardableODR; | |||
9791 | break; | |||
9792 | case ASTContext::InlineVariableDefinitionKind::Strong: | |||
9793 | StrongLinkage = GVA_StrongODR; | |||
9794 | break; | |||
9795 | } | |||
9796 | ||||
9797 | switch (VD->getTemplateSpecializationKind()) { | |||
9798 | case TSK_Undeclared: | |||
9799 | return StrongLinkage; | |||
9800 | ||||
9801 | case TSK_ExplicitSpecialization: | |||
9802 | return Context.getTargetInfo().getCXXABI().isMicrosoft() && | |||
9803 | VD->isStaticDataMember() | |||
9804 | ? GVA_StrongODR | |||
9805 | : StrongLinkage; | |||
9806 | ||||
9807 | case TSK_ExplicitInstantiationDefinition: | |||
9808 | return GVA_StrongODR; | |||
9809 | ||||
9810 | case TSK_ExplicitInstantiationDeclaration: | |||
9811 | return GVA_AvailableExternally; | |||
9812 | ||||
9813 | case TSK_ImplicitInstantiation: | |||
9814 | return GVA_DiscardableODR; | |||
9815 | } | |||
9816 | ||||
9817 | llvm_unreachable("Invalid Linkage!")::llvm::llvm_unreachable_internal("Invalid Linkage!", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9817); | |||
9818 | } | |||
9819 | ||||
9820 | GVALinkage ASTContext::GetGVALinkageForVariable(const VarDecl *VD) { | |||
9821 | return adjustGVALinkageForExternalDefinitionKind(*this, VD, | |||
9822 | adjustGVALinkageForAttributes(*this, VD, | |||
9823 | basicGVALinkageForVariable(*this, VD))); | |||
9824 | } | |||
9825 | ||||
9826 | bool ASTContext::DeclMustBeEmitted(const Decl *D) { | |||
9827 | if (const auto *VD = dyn_cast<VarDecl>(D)) { | |||
9828 | if (!VD->isFileVarDecl()) | |||
9829 | return false; | |||
9830 | // Global named register variables (GNU extension) are never emitted. | |||
9831 | if (VD->getStorageClass() == SC_Register) | |||
9832 | return false; | |||
9833 | if (VD->getDescribedVarTemplate() || | |||
9834 | isa<VarTemplatePartialSpecializationDecl>(VD)) | |||
9835 | return false; | |||
9836 | } else if (const auto *FD = dyn_cast<FunctionDecl>(D)) { | |||
9837 | // We never need to emit an uninstantiated function template. | |||
9838 | if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate) | |||
9839 | return false; | |||
9840 | } else if (isa<PragmaCommentDecl>(D)) | |||
9841 | return true; | |||
9842 | else if (isa<PragmaDetectMismatchDecl>(D)) | |||
9843 | return true; | |||
9844 | else if (isa<OMPThreadPrivateDecl>(D)) | |||
9845 | return !D->getDeclContext()->isDependentContext(); | |||
9846 | else if (isa<OMPAllocateDecl>(D)) | |||
9847 | return !D->getDeclContext()->isDependentContext(); | |||
9848 | else if (isa<OMPDeclareReductionDecl>(D)) | |||
9849 | return !D->getDeclContext()->isDependentContext(); | |||
9850 | else if (isa<ImportDecl>(D)) | |||
9851 | return true; | |||
9852 | else | |||
9853 | return false; | |||
9854 | ||||
9855 | if (D->isFromASTFile() && !LangOpts.BuildingPCHWithObjectFile) { | |||
9856 | assert(getExternalSource() && "It's from an AST file; must have a source.")((getExternalSource() && "It's from an AST file; must have a source." ) ? static_cast<void> (0) : __assert_fail ("getExternalSource() && \"It's from an AST file; must have a source.\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9856, __PRETTY_FUNCTION__)); | |||
9857 | // On Windows, PCH files are built together with an object file. If this | |||
9858 | // declaration comes from such a PCH and DeclMustBeEmitted would return | |||
9859 | // true, it would have returned true and the decl would have been emitted | |||
9860 | // into that object file, so it doesn't need to be emitted here. | |||
9861 | // Note that decls are still emitted if they're referenced, as usual; | |||
9862 | // DeclMustBeEmitted is used to decide whether a decl must be emitted even | |||
9863 | // if it's not referenced. | |||
9864 | // | |||
9865 | // Explicit template instantiation definitions are tricky. If there was an | |||
9866 | // explicit template instantiation decl in the PCH before, it will look like | |||
9867 | // the definition comes from there, even if that was just the declaration. | |||
9868 | // (Explicit instantiation defs of variable templates always get emitted.) | |||
9869 | bool IsExpInstDef = | |||
9870 | isa<FunctionDecl>(D) && | |||
9871 | cast<FunctionDecl>(D)->getTemplateSpecializationKind() == | |||
9872 | TSK_ExplicitInstantiationDefinition; | |||
9873 | ||||
9874 | // Implicit member function definitions, such as operator= might not be | |||
9875 | // marked as template specializations, since they're not coming from a | |||
9876 | // template but synthesized directly on the class. | |||
9877 | IsExpInstDef |= | |||
9878 | isa<CXXMethodDecl>(D) && | |||
9879 | cast<CXXMethodDecl>(D)->getParent()->getTemplateSpecializationKind() == | |||
9880 | TSK_ExplicitInstantiationDefinition; | |||
9881 | ||||
9882 | if (getExternalSource()->DeclIsFromPCHWithObjectFile(D) && !IsExpInstDef) | |||
9883 | return false; | |||
9884 | } | |||
9885 | ||||
9886 | // If this is a member of a class template, we do not need to emit it. | |||
9887 | if (D->getDeclContext()->isDependentContext()) | |||
9888 | return false; | |||
9889 | ||||
9890 | // Weak references don't produce any output by themselves. | |||
9891 | if (D->hasAttr<WeakRefAttr>()) | |||
9892 | return false; | |||
9893 | ||||
9894 | // Aliases and used decls are required. | |||
9895 | if (D->hasAttr<AliasAttr>() || D->hasAttr<UsedAttr>()) | |||
9896 | return true; | |||
9897 | ||||
9898 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) { | |||
9899 | // Forward declarations aren't required. | |||
9900 | if (!FD->doesThisDeclarationHaveABody()) | |||
9901 | return FD->doesDeclarationForceExternallyVisibleDefinition(); | |||
9902 | ||||
9903 | // Constructors and destructors are required. | |||
9904 | if (FD->hasAttr<ConstructorAttr>() || FD->hasAttr<DestructorAttr>()) | |||
9905 | return true; | |||
9906 | ||||
9907 | // The key function for a class is required. This rule only comes | |||
9908 | // into play when inline functions can be key functions, though. | |||
9909 | if (getTargetInfo().getCXXABI().canKeyFunctionBeInline()) { | |||
9910 | if (const auto *MD = dyn_cast<CXXMethodDecl>(FD)) { | |||
9911 | const CXXRecordDecl *RD = MD->getParent(); | |||
9912 | if (MD->isOutOfLine() && RD->isDynamicClass()) { | |||
9913 | const CXXMethodDecl *KeyFunc = getCurrentKeyFunction(RD); | |||
9914 | if (KeyFunc && KeyFunc->getCanonicalDecl() == MD->getCanonicalDecl()) | |||
9915 | return true; | |||
9916 | } | |||
9917 | } | |||
9918 | } | |||
9919 | ||||
9920 | GVALinkage Linkage = GetGVALinkageForFunction(FD); | |||
9921 | ||||
9922 | // static, static inline, always_inline, and extern inline functions can | |||
9923 | // always be deferred. Normal inline functions can be deferred in C99/C++. | |||
9924 | // Implicit template instantiations can also be deferred in C++. | |||
9925 | return !isDiscardableGVALinkage(Linkage); | |||
9926 | } | |||
9927 | ||||
9928 | const auto *VD = cast<VarDecl>(D); | |||
9929 | assert(VD->isFileVarDecl() && "Expected file scoped var")((VD->isFileVarDecl() && "Expected file scoped var" ) ? static_cast<void> (0) : __assert_fail ("VD->isFileVarDecl() && \"Expected file scoped var\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9929, __PRETTY_FUNCTION__)); | |||
9930 | ||||
9931 | // If the decl is marked as `declare target to`, it should be emitted for the | |||
9932 | // host and for the device. | |||
9933 | if (LangOpts.OpenMP && | |||
9934 | OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) | |||
9935 | return true; | |||
9936 | ||||
9937 | if (VD->isThisDeclarationADefinition() == VarDecl::DeclarationOnly && | |||
9938 | !isMSStaticDataMemberInlineDefinition(VD)) | |||
9939 | return false; | |||
9940 | ||||
9941 | // Variables that can be needed in other TUs are required. | |||
9942 | auto Linkage = GetGVALinkageForVariable(VD); | |||
9943 | if (!isDiscardableGVALinkage(Linkage)) | |||
9944 | return true; | |||
9945 | ||||
9946 | // We never need to emit a variable that is available in another TU. | |||
9947 | if (Linkage == GVA_AvailableExternally) | |||
9948 | return false; | |||
9949 | ||||
9950 | // Variables that have destruction with side-effects are required. | |||
9951 | if (VD->getType().isDestructedType()) | |||
9952 | return true; | |||
9953 | ||||
9954 | // Variables that have initialization with side-effects are required. | |||
9955 | if (VD->getInit() && VD->getInit()->HasSideEffects(*this) && | |||
9956 | // We can get a value-dependent initializer during error recovery. | |||
9957 | (VD->getInit()->isValueDependent() || !VD->evaluateValue())) | |||
9958 | return true; | |||
9959 | ||||
9960 | // Likewise, variables with tuple-like bindings are required if their | |||
9961 | // bindings have side-effects. | |||
9962 | if (const auto *DD = dyn_cast<DecompositionDecl>(VD)) | |||
9963 | for (const auto *BD : DD->bindings()) | |||
9964 | if (const auto *BindingVD = BD->getHoldingVar()) | |||
9965 | if (DeclMustBeEmitted(BindingVD)) | |||
9966 | return true; | |||
9967 | ||||
9968 | return false; | |||
9969 | } | |||
9970 | ||||
9971 | void ASTContext::forEachMultiversionedFunctionVersion( | |||
9972 | const FunctionDecl *FD, | |||
9973 | llvm::function_ref<void(FunctionDecl *)> Pred) const { | |||
9974 | assert(FD->isMultiVersion() && "Only valid for multiversioned functions")((FD->isMultiVersion() && "Only valid for multiversioned functions" ) ? static_cast<void> (0) : __assert_fail ("FD->isMultiVersion() && \"Only valid for multiversioned functions\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 9974, __PRETTY_FUNCTION__)); | |||
9975 | llvm::SmallDenseSet<const FunctionDecl*, 4> SeenDecls; | |||
9976 | FD = FD->getMostRecentDecl(); | |||
9977 | for (auto *CurDecl : | |||
9978 | FD->getDeclContext()->getRedeclContext()->lookup(FD->getDeclName())) { | |||
9979 | FunctionDecl *CurFD = CurDecl->getAsFunction()->getMostRecentDecl(); | |||
9980 | if (CurFD && hasSameType(CurFD->getType(), FD->getType()) && | |||
9981 | std::end(SeenDecls) == llvm::find(SeenDecls, CurFD)) { | |||
9982 | SeenDecls.insert(CurFD); | |||
9983 | Pred(CurFD); | |||
9984 | } | |||
9985 | } | |||
9986 | } | |||
9987 | ||||
9988 | CallingConv ASTContext::getDefaultCallingConvention(bool IsVariadic, | |||
9989 | bool IsCXXMethod, | |||
9990 | bool IsBuiltin) const { | |||
9991 | // Pass through to the C++ ABI object | |||
9992 | if (IsCXXMethod) | |||
9993 | return ABI->getDefaultMethodCallConv(IsVariadic); | |||
9994 | ||||
9995 | // Builtins ignore user-specified default calling convention and remain the | |||
9996 | // Target's default calling convention. | |||
9997 | if (!IsBuiltin) { | |||
9998 | switch (LangOpts.getDefaultCallingConv()) { | |||
9999 | case LangOptions::DCC_None: | |||
10000 | break; | |||
10001 | case LangOptions::DCC_CDecl: | |||
10002 | return CC_C; | |||
10003 | case LangOptions::DCC_FastCall: | |||
10004 | if (getTargetInfo().hasFeature("sse2") && !IsVariadic) | |||
10005 | return CC_X86FastCall; | |||
10006 | break; | |||
10007 | case LangOptions::DCC_StdCall: | |||
10008 | if (!IsVariadic) | |||
10009 | return CC_X86StdCall; | |||
10010 | break; | |||
10011 | case LangOptions::DCC_VectorCall: | |||
10012 | // __vectorcall cannot be applied to variadic functions. | |||
10013 | if (!IsVariadic) | |||
10014 | return CC_X86VectorCall; | |||
10015 | break; | |||
10016 | case LangOptions::DCC_RegCall: | |||
10017 | // __regcall cannot be applied to variadic functions. | |||
10018 | if (!IsVariadic) | |||
10019 | return CC_X86RegCall; | |||
10020 | break; | |||
10021 | } | |||
10022 | } | |||
10023 | return Target->getDefaultCallingConv(TargetInfo::CCMT_Unknown); | |||
10024 | } | |||
10025 | ||||
10026 | bool ASTContext::isNearlyEmpty(const CXXRecordDecl *RD) const { | |||
10027 | // Pass through to the C++ ABI object | |||
10028 | return ABI->isNearlyEmpty(RD); | |||
10029 | } | |||
10030 | ||||
10031 | VTableContextBase *ASTContext::getVTableContext() { | |||
10032 | if (!VTContext.get()) { | |||
10033 | if (Target->getCXXABI().isMicrosoft()) | |||
10034 | VTContext.reset(new MicrosoftVTableContext(*this)); | |||
10035 | else | |||
10036 | VTContext.reset(new ItaniumVTableContext(*this)); | |||
10037 | } | |||
10038 | return VTContext.get(); | |||
10039 | } | |||
10040 | ||||
10041 | MangleContext *ASTContext::createMangleContext(const TargetInfo *T) { | |||
10042 | if (!T) | |||
10043 | T = Target; | |||
10044 | switch (T->getCXXABI().getKind()) { | |||
10045 | case TargetCXXABI::GenericAArch64: | |||
10046 | case TargetCXXABI::GenericItanium: | |||
10047 | case TargetCXXABI::GenericARM: | |||
10048 | case TargetCXXABI::GenericMIPS: | |||
10049 | case TargetCXXABI::iOS: | |||
10050 | case TargetCXXABI::iOS64: | |||
10051 | case TargetCXXABI::WebAssembly: | |||
10052 | case TargetCXXABI::WatchOS: | |||
10053 | return ItaniumMangleContext::create(*this, getDiagnostics()); | |||
10054 | case TargetCXXABI::Microsoft: | |||
10055 | return MicrosoftMangleContext::create(*this, getDiagnostics()); | |||
10056 | } | |||
10057 | llvm_unreachable("Unsupported ABI")::llvm::llvm_unreachable_internal("Unsupported ABI", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10057); | |||
10058 | } | |||
10059 | ||||
10060 | CXXABI::~CXXABI() = default; | |||
10061 | ||||
10062 | size_t ASTContext::getSideTableAllocatedMemory() const { | |||
10063 | return ASTRecordLayouts.getMemorySize() + | |||
10064 | llvm::capacity_in_bytes(ObjCLayouts) + | |||
10065 | llvm::capacity_in_bytes(KeyFunctions) + | |||
10066 | llvm::capacity_in_bytes(ObjCImpls) + | |||
10067 | llvm::capacity_in_bytes(BlockVarCopyInits) + | |||
10068 | llvm::capacity_in_bytes(DeclAttrs) + | |||
10069 | llvm::capacity_in_bytes(TemplateOrInstantiation) + | |||
10070 | llvm::capacity_in_bytes(InstantiatedFromUsingDecl) + | |||
10071 | llvm::capacity_in_bytes(InstantiatedFromUsingShadowDecl) + | |||
10072 | llvm::capacity_in_bytes(InstantiatedFromUnnamedFieldDecl) + | |||
10073 | llvm::capacity_in_bytes(OverriddenMethods) + | |||
10074 | llvm::capacity_in_bytes(Types) + | |||
10075 | llvm::capacity_in_bytes(VariableArrayTypes); | |||
10076 | } | |||
10077 | ||||
10078 | /// getIntTypeForBitwidth - | |||
10079 | /// sets integer QualTy according to specified details: | |||
10080 | /// bitwidth, signed/unsigned. | |||
10081 | /// Returns empty type if there is no appropriate target types. | |||
10082 | QualType ASTContext::getIntTypeForBitwidth(unsigned DestWidth, | |||
10083 | unsigned Signed) const { | |||
10084 | TargetInfo::IntType Ty = getTargetInfo().getIntTypeByWidth(DestWidth, Signed); | |||
10085 | CanQualType QualTy = getFromTargetType(Ty); | |||
10086 | if (!QualTy && DestWidth == 128) | |||
10087 | return Signed ? Int128Ty : UnsignedInt128Ty; | |||
10088 | return QualTy; | |||
10089 | } | |||
10090 | ||||
10091 | /// getRealTypeForBitwidth - | |||
10092 | /// sets floating point QualTy according to specified bitwidth. | |||
10093 | /// Returns empty type if there is no appropriate target types. | |||
10094 | QualType ASTContext::getRealTypeForBitwidth(unsigned DestWidth) const { | |||
10095 | TargetInfo::RealType Ty = getTargetInfo().getRealTypeByWidth(DestWidth); | |||
10096 | switch (Ty) { | |||
10097 | case TargetInfo::Float: | |||
10098 | return FloatTy; | |||
10099 | case TargetInfo::Double: | |||
10100 | return DoubleTy; | |||
10101 | case TargetInfo::LongDouble: | |||
10102 | return LongDoubleTy; | |||
10103 | case TargetInfo::Float128: | |||
10104 | return Float128Ty; | |||
10105 | case TargetInfo::NoFloat: | |||
10106 | return {}; | |||
10107 | } | |||
10108 | ||||
10109 | llvm_unreachable("Unhandled TargetInfo::RealType value")::llvm::llvm_unreachable_internal("Unhandled TargetInfo::RealType value" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10109); | |||
10110 | } | |||
10111 | ||||
10112 | void ASTContext::setManglingNumber(const NamedDecl *ND, unsigned Number) { | |||
10113 | if (Number > 1) | |||
10114 | MangleNumbers[ND] = Number; | |||
10115 | } | |||
10116 | ||||
10117 | unsigned ASTContext::getManglingNumber(const NamedDecl *ND) const { | |||
10118 | auto I = MangleNumbers.find(ND); | |||
10119 | return I != MangleNumbers.end() ? I->second : 1; | |||
10120 | } | |||
10121 | ||||
10122 | void ASTContext::setStaticLocalNumber(const VarDecl *VD, unsigned Number) { | |||
10123 | if (Number > 1) | |||
10124 | StaticLocalNumbers[VD] = Number; | |||
10125 | } | |||
10126 | ||||
10127 | unsigned ASTContext::getStaticLocalNumber(const VarDecl *VD) const { | |||
10128 | auto I = StaticLocalNumbers.find(VD); | |||
10129 | return I != StaticLocalNumbers.end() ? I->second : 1; | |||
10130 | } | |||
10131 | ||||
10132 | MangleNumberingContext & | |||
10133 | ASTContext::getManglingNumberContext(const DeclContext *DC) { | |||
10134 | assert(LangOpts.CPlusPlus)((LangOpts.CPlusPlus) ? static_cast<void> (0) : __assert_fail ("LangOpts.CPlusPlus", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10134, __PRETTY_FUNCTION__)); // We don't need mangling numbers for plain C. | |||
10135 | std::unique_ptr<MangleNumberingContext> &MCtx = MangleNumberingContexts[DC]; | |||
10136 | if (!MCtx) | |||
10137 | MCtx = createMangleNumberingContext(); | |||
10138 | return *MCtx; | |||
10139 | } | |||
10140 | ||||
10141 | std::unique_ptr<MangleNumberingContext> | |||
10142 | ASTContext::createMangleNumberingContext() const { | |||
10143 | return ABI->createMangleNumberingContext(); | |||
10144 | } | |||
10145 | ||||
10146 | const CXXConstructorDecl * | |||
10147 | ASTContext::getCopyConstructorForExceptionObject(CXXRecordDecl *RD) { | |||
10148 | return ABI->getCopyConstructorForExceptionObject( | |||
10149 | cast<CXXRecordDecl>(RD->getFirstDecl())); | |||
10150 | } | |||
10151 | ||||
10152 | void ASTContext::addCopyConstructorForExceptionObject(CXXRecordDecl *RD, | |||
10153 | CXXConstructorDecl *CD) { | |||
10154 | return ABI->addCopyConstructorForExceptionObject( | |||
10155 | cast<CXXRecordDecl>(RD->getFirstDecl()), | |||
10156 | cast<CXXConstructorDecl>(CD->getFirstDecl())); | |||
10157 | } | |||
10158 | ||||
10159 | void ASTContext::addTypedefNameForUnnamedTagDecl(TagDecl *TD, | |||
10160 | TypedefNameDecl *DD) { | |||
10161 | return ABI->addTypedefNameForUnnamedTagDecl(TD, DD); | |||
10162 | } | |||
10163 | ||||
10164 | TypedefNameDecl * | |||
10165 | ASTContext::getTypedefNameForUnnamedTagDecl(const TagDecl *TD) { | |||
10166 | return ABI->getTypedefNameForUnnamedTagDecl(TD); | |||
10167 | } | |||
10168 | ||||
10169 | void ASTContext::addDeclaratorForUnnamedTagDecl(TagDecl *TD, | |||
10170 | DeclaratorDecl *DD) { | |||
10171 | return ABI->addDeclaratorForUnnamedTagDecl(TD, DD); | |||
10172 | } | |||
10173 | ||||
10174 | DeclaratorDecl *ASTContext::getDeclaratorForUnnamedTagDecl(const TagDecl *TD) { | |||
10175 | return ABI->getDeclaratorForUnnamedTagDecl(TD); | |||
10176 | } | |||
10177 | ||||
10178 | void ASTContext::setParameterIndex(const ParmVarDecl *D, unsigned int index) { | |||
10179 | ParamIndices[D] = index; | |||
10180 | } | |||
10181 | ||||
10182 | unsigned ASTContext::getParameterIndex(const ParmVarDecl *D) const { | |||
10183 | ParameterIndexTable::const_iterator I = ParamIndices.find(D); | |||
10184 | assert(I != ParamIndices.end() &&((I != ParamIndices.end() && "ParmIndices lacks entry set by ParmVarDecl" ) ? static_cast<void> (0) : __assert_fail ("I != ParamIndices.end() && \"ParmIndices lacks entry set by ParmVarDecl\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10185, __PRETTY_FUNCTION__)) | |||
10185 | "ParmIndices lacks entry set by ParmVarDecl")((I != ParamIndices.end() && "ParmIndices lacks entry set by ParmVarDecl" ) ? static_cast<void> (0) : __assert_fail ("I != ParamIndices.end() && \"ParmIndices lacks entry set by ParmVarDecl\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10185, __PRETTY_FUNCTION__)); | |||
10186 | return I->second; | |||
10187 | } | |||
10188 | ||||
10189 | APValue * | |||
10190 | ASTContext::getMaterializedTemporaryValue(const MaterializeTemporaryExpr *E, | |||
10191 | bool MayCreate) { | |||
10192 | assert(E && E->getStorageDuration() == SD_Static &&((E && E->getStorageDuration() == SD_Static && "don't need to cache the computed value for this temporary") ? static_cast<void> (0) : __assert_fail ("E && E->getStorageDuration() == SD_Static && \"don't need to cache the computed value for this temporary\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10193, __PRETTY_FUNCTION__)) | |||
10193 | "don't need to cache the computed value for this temporary")((E && E->getStorageDuration() == SD_Static && "don't need to cache the computed value for this temporary") ? static_cast<void> (0) : __assert_fail ("E && E->getStorageDuration() == SD_Static && \"don't need to cache the computed value for this temporary\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10193, __PRETTY_FUNCTION__)); | |||
10194 | if (MayCreate) { | |||
10195 | APValue *&MTVI = MaterializedTemporaryValues[E]; | |||
10196 | if (!MTVI) | |||
10197 | MTVI = new (*this) APValue; | |||
10198 | return MTVI; | |||
10199 | } | |||
10200 | ||||
10201 | return MaterializedTemporaryValues.lookup(E); | |||
10202 | } | |||
10203 | ||||
10204 | QualType ASTContext::getStringLiteralArrayType(QualType EltTy, | |||
10205 | unsigned Length) const { | |||
10206 | // A C++ string literal has a const-qualified element type (C++ 2.13.4p1). | |||
10207 | if (getLangOpts().CPlusPlus || getLangOpts().ConstStrings) | |||
10208 | EltTy = EltTy.withConst(); | |||
10209 | ||||
10210 | EltTy = adjustStringLiteralBaseType(EltTy); | |||
10211 | ||||
10212 | // Get an array type for the string, according to C99 6.4.5. This includes | |||
10213 | // the null terminator character. | |||
10214 | return getConstantArrayType(EltTy, llvm::APInt(32, Length + 1), | |||
10215 | ArrayType::Normal, /*IndexTypeQuals*/ 0); | |||
10216 | } | |||
10217 | ||||
10218 | StringLiteral * | |||
10219 | ASTContext::getPredefinedStringLiteralFromCache(StringRef Key) const { | |||
10220 | StringLiteral *&Result = StringLiteralCache[Key]; | |||
10221 | if (!Result) | |||
10222 | Result = StringLiteral::Create( | |||
10223 | *this, Key, StringLiteral::Ascii, | |||
10224 | /*Pascal*/ false, getStringLiteralArrayType(CharTy, Key.size()), | |||
10225 | SourceLocation()); | |||
10226 | return Result; | |||
10227 | } | |||
10228 | ||||
10229 | bool ASTContext::AtomicUsesUnsupportedLibcall(const AtomicExpr *E) const { | |||
10230 | const llvm::Triple &T = getTargetInfo().getTriple(); | |||
10231 | if (!T.isOSDarwin()) | |||
10232 | return false; | |||
10233 | ||||
10234 | if (!(T.isiOS() && T.isOSVersionLT(7)) && | |||
10235 | !(T.isMacOSX() && T.isOSVersionLT(10, 9))) | |||
10236 | return false; | |||
10237 | ||||
10238 | QualType AtomicTy = E->getPtr()->getType()->getPointeeType(); | |||
10239 | CharUnits sizeChars = getTypeSizeInChars(AtomicTy); | |||
10240 | uint64_t Size = sizeChars.getQuantity(); | |||
10241 | CharUnits alignChars = getTypeAlignInChars(AtomicTy); | |||
10242 | unsigned Align = alignChars.getQuantity(); | |||
10243 | unsigned MaxInlineWidthInBits = getTargetInfo().getMaxAtomicInlineWidth(); | |||
10244 | return (Size != Align || toBits(sizeChars) > MaxInlineWidthInBits); | |||
10245 | } | |||
10246 | ||||
10247 | /// Template specializations to abstract away from pointers and TypeLocs. | |||
10248 | /// @{ | |||
10249 | template <typename T> | |||
10250 | static ast_type_traits::DynTypedNode createDynTypedNode(const T &Node) { | |||
10251 | return ast_type_traits::DynTypedNode::create(*Node); | |||
10252 | } | |||
10253 | template <> | |||
10254 | ast_type_traits::DynTypedNode createDynTypedNode(const TypeLoc &Node) { | |||
10255 | return ast_type_traits::DynTypedNode::create(Node); | |||
10256 | } | |||
10257 | template <> | |||
10258 | ast_type_traits::DynTypedNode | |||
10259 | createDynTypedNode(const NestedNameSpecifierLoc &Node) { | |||
10260 | return ast_type_traits::DynTypedNode::create(Node); | |||
10261 | } | |||
10262 | /// @} | |||
10263 | ||||
10264 | /// A \c RecursiveASTVisitor that builds a map from nodes to their | |||
10265 | /// parents as defined by the \c RecursiveASTVisitor. | |||
10266 | /// | |||
10267 | /// Note that the relationship described here is purely in terms of AST | |||
10268 | /// traversal - there are other relationships (for example declaration context) | |||
10269 | /// in the AST that are better modeled by special matchers. | |||
10270 | /// | |||
10271 | /// FIXME: Currently only builds up the map using \c Stmt and \c Decl nodes. | |||
10272 | class ASTContext::ParentMap::ASTVisitor | |||
10273 | : public RecursiveASTVisitor<ASTVisitor> { | |||
10274 | public: | |||
10275 | ASTVisitor(ParentMap &Map) : Map(Map) {} | |||
10276 | ||||
10277 | private: | |||
10278 | friend class RecursiveASTVisitor<ASTVisitor>; | |||
10279 | ||||
10280 | using VisitorBase = RecursiveASTVisitor<ASTVisitor>; | |||
10281 | ||||
10282 | bool shouldVisitTemplateInstantiations() const { return true; } | |||
10283 | ||||
10284 | bool shouldVisitImplicitCode() const { return true; } | |||
10285 | ||||
10286 | template <typename T, typename MapNodeTy, typename BaseTraverseFn, | |||
10287 | typename MapTy> | |||
10288 | bool TraverseNode(T Node, MapNodeTy MapNode, BaseTraverseFn BaseTraverse, | |||
10289 | MapTy *Parents) { | |||
10290 | if (!Node) | |||
10291 | return true; | |||
10292 | if (ParentStack.size() > 0) { | |||
10293 | // FIXME: Currently we add the same parent multiple times, but only | |||
10294 | // when no memoization data is available for the type. | |||
10295 | // For example when we visit all subexpressions of template | |||
10296 | // instantiations; this is suboptimal, but benign: the only way to | |||
10297 | // visit those is with hasAncestor / hasParent, and those do not create | |||
10298 | // new matches. | |||
10299 | // The plan is to enable DynTypedNode to be storable in a map or hash | |||
10300 | // map. The main problem there is to implement hash functions / | |||
10301 | // comparison operators for all types that DynTypedNode supports that | |||
10302 | // do not have pointer identity. | |||
10303 | auto &NodeOrVector = (*Parents)[MapNode]; | |||
10304 | if (NodeOrVector.isNull()) { | |||
10305 | if (const auto *D = ParentStack.back().get<Decl>()) | |||
10306 | NodeOrVector = D; | |||
10307 | else if (const auto *S = ParentStack.back().get<Stmt>()) | |||
10308 | NodeOrVector = S; | |||
10309 | else | |||
10310 | NodeOrVector = new ast_type_traits::DynTypedNode(ParentStack.back()); | |||
10311 | } else { | |||
10312 | if (!NodeOrVector.template is<ParentVector *>()) { | |||
10313 | auto *Vector = new ParentVector( | |||
10314 | 1, getSingleDynTypedNodeFromParentMap(NodeOrVector)); | |||
10315 | delete NodeOrVector | |||
10316 | .template dyn_cast<ast_type_traits::DynTypedNode *>(); | |||
10317 | NodeOrVector = Vector; | |||
10318 | } | |||
10319 | ||||
10320 | auto *Vector = NodeOrVector.template get<ParentVector *>(); | |||
| ||||
10321 | // Skip duplicates for types that have memoization data. | |||
10322 | // We must check that the type has memoization data before calling | |||
10323 | // std::find() because DynTypedNode::operator== can't compare all | |||
10324 | // types. | |||
10325 | bool Found = ParentStack.back().getMemoizationData() && | |||
10326 | std::find(Vector->begin(), Vector->end(), | |||
10327 | ParentStack.back()) != Vector->end(); | |||
10328 | if (!Found) | |||
10329 | Vector->push_back(ParentStack.back()); | |||
10330 | } | |||
10331 | } | |||
10332 | ParentStack.push_back(createDynTypedNode(Node)); | |||
10333 | bool Result = BaseTraverse(); | |||
10334 | ParentStack.pop_back(); | |||
10335 | return Result; | |||
10336 | } | |||
10337 | ||||
10338 | bool TraverseDecl(Decl *DeclNode) { | |||
10339 | return TraverseNode( | |||
10340 | DeclNode, DeclNode, [&] { return VisitorBase::TraverseDecl(DeclNode); }, | |||
10341 | &Map.PointerParents); | |||
10342 | } | |||
10343 | ||||
10344 | bool TraverseStmt(Stmt *StmtNode) { | |||
10345 | return TraverseNode( | |||
10346 | StmtNode, StmtNode, [&] { return VisitorBase::TraverseStmt(StmtNode); }, | |||
10347 | &Map.PointerParents); | |||
10348 | } | |||
10349 | ||||
10350 | bool TraverseTypeLoc(TypeLoc TypeLocNode) { | |||
10351 | return TraverseNode( | |||
| ||||
10352 | TypeLocNode, ast_type_traits::DynTypedNode::create(TypeLocNode), | |||
10353 | [&] { return VisitorBase::TraverseTypeLoc(TypeLocNode); }, | |||
10354 | &Map.OtherParents); | |||
10355 | } | |||
10356 | ||||
10357 | bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNSLocNode) { | |||
10358 | return TraverseNode( | |||
10359 | NNSLocNode, ast_type_traits::DynTypedNode::create(NNSLocNode), | |||
10360 | [&] { return VisitorBase::TraverseNestedNameSpecifierLoc(NNSLocNode); }, | |||
10361 | &Map.OtherParents); | |||
10362 | } | |||
10363 | ||||
10364 | ParentMap ⤅ | |||
10365 | llvm::SmallVector<ast_type_traits::DynTypedNode, 16> ParentStack; | |||
10366 | }; | |||
10367 | ||||
10368 | ASTContext::ParentMap::ParentMap(ASTContext &Ctx) { | |||
10369 | ASTVisitor(*this).TraverseAST(Ctx); | |||
10370 | } | |||
10371 | ||||
10372 | ASTContext::DynTypedNodeList | |||
10373 | ASTContext::getParents(const ast_type_traits::DynTypedNode &Node) { | |||
10374 | if (!Parents) | |||
10375 | // We build the parent map for the traversal scope (usually whole TU), as | |||
10376 | // hasAncestor can escape any subtree. | |||
10377 | Parents = llvm::make_unique<ParentMap>(*this); | |||
10378 | return Parents->getParents(Node); | |||
10379 | } | |||
10380 | ||||
10381 | bool | |||
10382 | ASTContext::ObjCMethodsAreEqual(const ObjCMethodDecl *MethodDecl, | |||
10383 | const ObjCMethodDecl *MethodImpl) { | |||
10384 | // No point trying to match an unavailable/deprecated mothod. | |||
10385 | if (MethodDecl->hasAttr<UnavailableAttr>() | |||
10386 | || MethodDecl->hasAttr<DeprecatedAttr>()) | |||
10387 | return false; | |||
10388 | if (MethodDecl->getObjCDeclQualifier() != | |||
10389 | MethodImpl->getObjCDeclQualifier()) | |||
10390 | return false; | |||
10391 | if (!hasSameType(MethodDecl->getReturnType(), MethodImpl->getReturnType())) | |||
10392 | return false; | |||
10393 | ||||
10394 | if (MethodDecl->param_size() != MethodImpl->param_size()) | |||
10395 | return false; | |||
10396 | ||||
10397 | for (ObjCMethodDecl::param_const_iterator IM = MethodImpl->param_begin(), | |||
10398 | IF = MethodDecl->param_begin(), EM = MethodImpl->param_end(), | |||
10399 | EF = MethodDecl->param_end(); | |||
10400 | IM != EM && IF != EF; ++IM, ++IF) { | |||
10401 | const ParmVarDecl *DeclVar = (*IF); | |||
10402 | const ParmVarDecl *ImplVar = (*IM); | |||
10403 | if (ImplVar->getObjCDeclQualifier() != DeclVar->getObjCDeclQualifier()) | |||
10404 | return false; | |||
10405 | if (!hasSameType(DeclVar->getType(), ImplVar->getType())) | |||
10406 | return false; | |||
10407 | } | |||
10408 | ||||
10409 | return (MethodDecl->isVariadic() == MethodImpl->isVariadic()); | |||
10410 | } | |||
10411 | ||||
10412 | uint64_t ASTContext::getTargetNullPointerValue(QualType QT) const { | |||
10413 | LangAS AS; | |||
10414 | if (QT->getUnqualifiedDesugaredType()->isNullPtrType()) | |||
10415 | AS = LangAS::Default; | |||
10416 | else | |||
10417 | AS = QT->getPointeeType().getAddressSpace(); | |||
10418 | ||||
10419 | return getTargetInfo().getNullPointerValue(AS); | |||
10420 | } | |||
10421 | ||||
10422 | unsigned ASTContext::getTargetAddressSpace(LangAS AS) const { | |||
10423 | if (isTargetAddressSpace(AS)) | |||
10424 | return toTargetAddressSpace(AS); | |||
10425 | else | |||
10426 | return (*AddrSpaceMap)[(unsigned)AS]; | |||
10427 | } | |||
10428 | ||||
10429 | QualType ASTContext::getCorrespondingSaturatedType(QualType Ty) const { | |||
10430 | assert(Ty->isFixedPointType())((Ty->isFixedPointType()) ? static_cast<void> (0) : __assert_fail ("Ty->isFixedPointType()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10430, __PRETTY_FUNCTION__)); | |||
10431 | ||||
10432 | if (Ty->isSaturatedFixedPointType()) return Ty; | |||
10433 | ||||
10434 | const auto &BT = Ty->getAs<BuiltinType>(); | |||
10435 | switch (BT->getKind()) { | |||
10436 | default: | |||
10437 | llvm_unreachable("Not a fixed point type!")::llvm::llvm_unreachable_internal("Not a fixed point type!", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10437); | |||
10438 | case BuiltinType::ShortAccum: | |||
10439 | return SatShortAccumTy; | |||
10440 | case BuiltinType::Accum: | |||
10441 | return SatAccumTy; | |||
10442 | case BuiltinType::LongAccum: | |||
10443 | return SatLongAccumTy; | |||
10444 | case BuiltinType::UShortAccum: | |||
10445 | return SatUnsignedShortAccumTy; | |||
10446 | case BuiltinType::UAccum: | |||
10447 | return SatUnsignedAccumTy; | |||
10448 | case BuiltinType::ULongAccum: | |||
10449 | return SatUnsignedLongAccumTy; | |||
10450 | case BuiltinType::ShortFract: | |||
10451 | return SatShortFractTy; | |||
10452 | case BuiltinType::Fract: | |||
10453 | return SatFractTy; | |||
10454 | case BuiltinType::LongFract: | |||
10455 | return SatLongFractTy; | |||
10456 | case BuiltinType::UShortFract: | |||
10457 | return SatUnsignedShortFractTy; | |||
10458 | case BuiltinType::UFract: | |||
10459 | return SatUnsignedFractTy; | |||
10460 | case BuiltinType::ULongFract: | |||
10461 | return SatUnsignedLongFractTy; | |||
10462 | } | |||
10463 | } | |||
10464 | ||||
10465 | LangAS ASTContext::getLangASForBuiltinAddressSpace(unsigned AS) const { | |||
10466 | if (LangOpts.OpenCL) | |||
10467 | return getTargetInfo().getOpenCLBuiltinAddressSpace(AS); | |||
10468 | ||||
10469 | if (LangOpts.CUDA) | |||
10470 | return getTargetInfo().getCUDABuiltinAddressSpace(AS); | |||
10471 | ||||
10472 | return getLangASFromTargetAS(AS); | |||
10473 | } | |||
10474 | ||||
10475 | // Explicitly instantiate this in case a Redeclarable<T> is used from a TU that | |||
10476 | // doesn't include ASTContext.h | |||
10477 | template | |||
10478 | clang::LazyGenerationalUpdatePtr< | |||
10479 | const Decl *, Decl *, &ExternalASTSource::CompleteRedeclChain>::ValueType | |||
10480 | clang::LazyGenerationalUpdatePtr< | |||
10481 | const Decl *, Decl *, &ExternalASTSource::CompleteRedeclChain>::makeValue( | |||
10482 | const clang::ASTContext &Ctx, Decl *Value); | |||
10483 | ||||
10484 | unsigned char ASTContext::getFixedPointScale(QualType Ty) const { | |||
10485 | assert(Ty->isFixedPointType())((Ty->isFixedPointType()) ? static_cast<void> (0) : __assert_fail ("Ty->isFixedPointType()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10485, __PRETTY_FUNCTION__)); | |||
10486 | ||||
10487 | const auto *BT = Ty->getAs<BuiltinType>(); | |||
10488 | const TargetInfo &Target = getTargetInfo(); | |||
10489 | switch (BT->getKind()) { | |||
10490 | default: | |||
10491 | llvm_unreachable("Not a fixed point type!")::llvm::llvm_unreachable_internal("Not a fixed point type!", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10491); | |||
10492 | case BuiltinType::ShortAccum: | |||
10493 | case BuiltinType::SatShortAccum: | |||
10494 | return Target.getShortAccumScale(); | |||
10495 | case BuiltinType::Accum: | |||
10496 | case BuiltinType::SatAccum: | |||
10497 | return Target.getAccumScale(); | |||
10498 | case BuiltinType::LongAccum: | |||
10499 | case BuiltinType::SatLongAccum: | |||
10500 | return Target.getLongAccumScale(); | |||
10501 | case BuiltinType::UShortAccum: | |||
10502 | case BuiltinType::SatUShortAccum: | |||
10503 | return Target.getUnsignedShortAccumScale(); | |||
10504 | case BuiltinType::UAccum: | |||
10505 | case BuiltinType::SatUAccum: | |||
10506 | return Target.getUnsignedAccumScale(); | |||
10507 | case BuiltinType::ULongAccum: | |||
10508 | case BuiltinType::SatULongAccum: | |||
10509 | return Target.getUnsignedLongAccumScale(); | |||
10510 | case BuiltinType::ShortFract: | |||
10511 | case BuiltinType::SatShortFract: | |||
10512 | return Target.getShortFractScale(); | |||
10513 | case BuiltinType::Fract: | |||
10514 | case BuiltinType::SatFract: | |||
10515 | return Target.getFractScale(); | |||
10516 | case BuiltinType::LongFract: | |||
10517 | case BuiltinType::SatLongFract: | |||
10518 | return Target.getLongFractScale(); | |||
10519 | case BuiltinType::UShortFract: | |||
10520 | case BuiltinType::SatUShortFract: | |||
10521 | return Target.getUnsignedShortFractScale(); | |||
10522 | case BuiltinType::UFract: | |||
10523 | case BuiltinType::SatUFract: | |||
10524 | return Target.getUnsignedFractScale(); | |||
10525 | case BuiltinType::ULongFract: | |||
10526 | case BuiltinType::SatULongFract: | |||
10527 | return Target.getUnsignedLongFractScale(); | |||
10528 | } | |||
10529 | } | |||
10530 | ||||
10531 | unsigned char ASTContext::getFixedPointIBits(QualType Ty) const { | |||
10532 | assert(Ty->isFixedPointType())((Ty->isFixedPointType()) ? static_cast<void> (0) : __assert_fail ("Ty->isFixedPointType()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10532, __PRETTY_FUNCTION__)); | |||
10533 | ||||
10534 | const auto *BT = Ty->getAs<BuiltinType>(); | |||
10535 | const TargetInfo &Target = getTargetInfo(); | |||
10536 | switch (BT->getKind()) { | |||
10537 | default: | |||
10538 | llvm_unreachable("Not a fixed point type!")::llvm::llvm_unreachable_internal("Not a fixed point type!", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10538); | |||
10539 | case BuiltinType::ShortAccum: | |||
10540 | case BuiltinType::SatShortAccum: | |||
10541 | return Target.getShortAccumIBits(); | |||
10542 | case BuiltinType::Accum: | |||
10543 | case BuiltinType::SatAccum: | |||
10544 | return Target.getAccumIBits(); | |||
10545 | case BuiltinType::LongAccum: | |||
10546 | case BuiltinType::SatLongAccum: | |||
10547 | return Target.getLongAccumIBits(); | |||
10548 | case BuiltinType::UShortAccum: | |||
10549 | case BuiltinType::SatUShortAccum: | |||
10550 | return Target.getUnsignedShortAccumIBits(); | |||
10551 | case BuiltinType::UAccum: | |||
10552 | case BuiltinType::SatUAccum: | |||
10553 | return Target.getUnsignedAccumIBits(); | |||
10554 | case BuiltinType::ULongAccum: | |||
10555 | case BuiltinType::SatULongAccum: | |||
10556 | return Target.getUnsignedLongAccumIBits(); | |||
10557 | case BuiltinType::ShortFract: | |||
10558 | case BuiltinType::SatShortFract: | |||
10559 | case BuiltinType::Fract: | |||
10560 | case BuiltinType::SatFract: | |||
10561 | case BuiltinType::LongFract: | |||
10562 | case BuiltinType::SatLongFract: | |||
10563 | case BuiltinType::UShortFract: | |||
10564 | case BuiltinType::SatUShortFract: | |||
10565 | case BuiltinType::UFract: | |||
10566 | case BuiltinType::SatUFract: | |||
10567 | case BuiltinType::ULongFract: | |||
10568 | case BuiltinType::SatULongFract: | |||
10569 | return 0; | |||
10570 | } | |||
10571 | } | |||
10572 | ||||
10573 | FixedPointSemantics ASTContext::getFixedPointSemantics(QualType Ty) const { | |||
10574 | assert((Ty->isFixedPointType() || Ty->isIntegerType()) &&(((Ty->isFixedPointType() || Ty->isIntegerType()) && "Can only get the fixed point semantics for a " "fixed point or integer type." ) ? static_cast<void> (0) : __assert_fail ("(Ty->isFixedPointType() || Ty->isIntegerType()) && \"Can only get the fixed point semantics for a \" \"fixed point or integer type.\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10576, __PRETTY_FUNCTION__)) | |||
10575 | "Can only get the fixed point semantics for a "(((Ty->isFixedPointType() || Ty->isIntegerType()) && "Can only get the fixed point semantics for a " "fixed point or integer type." ) ? static_cast<void> (0) : __assert_fail ("(Ty->isFixedPointType() || Ty->isIntegerType()) && \"Can only get the fixed point semantics for a \" \"fixed point or integer type.\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10576, __PRETTY_FUNCTION__)) | |||
10576 | "fixed point or integer type.")(((Ty->isFixedPointType() || Ty->isIntegerType()) && "Can only get the fixed point semantics for a " "fixed point or integer type." ) ? static_cast<void> (0) : __assert_fail ("(Ty->isFixedPointType() || Ty->isIntegerType()) && \"Can only get the fixed point semantics for a \" \"fixed point or integer type.\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10576, __PRETTY_FUNCTION__)); | |||
10577 | if (Ty->isIntegerType()) | |||
10578 | return FixedPointSemantics::GetIntegerSemantics(getIntWidth(Ty), | |||
10579 | Ty->isSignedIntegerType()); | |||
10580 | ||||
10581 | bool isSigned = Ty->isSignedFixedPointType(); | |||
10582 | return FixedPointSemantics( | |||
10583 | static_cast<unsigned>(getTypeSize(Ty)), getFixedPointScale(Ty), isSigned, | |||
10584 | Ty->isSaturatedFixedPointType(), | |||
10585 | !isSigned && getTargetInfo().doUnsignedFixedPointTypesHavePadding()); | |||
10586 | } | |||
10587 | ||||
10588 | APFixedPoint ASTContext::getFixedPointMax(QualType Ty) const { | |||
10589 | assert(Ty->isFixedPointType())((Ty->isFixedPointType()) ? static_cast<void> (0) : __assert_fail ("Ty->isFixedPointType()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10589, __PRETTY_FUNCTION__)); | |||
10590 | return APFixedPoint::getMax(getFixedPointSemantics(Ty)); | |||
10591 | } | |||
10592 | ||||
10593 | APFixedPoint ASTContext::getFixedPointMin(QualType Ty) const { | |||
10594 | assert(Ty->isFixedPointType())((Ty->isFixedPointType()) ? static_cast<void> (0) : __assert_fail ("Ty->isFixedPointType()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10594, __PRETTY_FUNCTION__)); | |||
10595 | return APFixedPoint::getMin(getFixedPointSemantics(Ty)); | |||
10596 | } | |||
10597 | ||||
10598 | QualType ASTContext::getCorrespondingSignedFixedPointType(QualType Ty) const { | |||
10599 | assert(Ty->isUnsignedFixedPointType() &&((Ty->isUnsignedFixedPointType() && "Expected unsigned fixed point type" ) ? static_cast<void> (0) : __assert_fail ("Ty->isUnsignedFixedPointType() && \"Expected unsigned fixed point type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10600, __PRETTY_FUNCTION__)) | |||
10600 | "Expected unsigned fixed point type")((Ty->isUnsignedFixedPointType() && "Expected unsigned fixed point type" ) ? static_cast<void> (0) : __assert_fail ("Ty->isUnsignedFixedPointType() && \"Expected unsigned fixed point type\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10600, __PRETTY_FUNCTION__)); | |||
10601 | const auto *BTy = Ty->getAs<BuiltinType>(); | |||
10602 | ||||
10603 | switch (BTy->getKind()) { | |||
10604 | case BuiltinType::UShortAccum: | |||
10605 | return ShortAccumTy; | |||
10606 | case BuiltinType::UAccum: | |||
10607 | return AccumTy; | |||
10608 | case BuiltinType::ULongAccum: | |||
10609 | return LongAccumTy; | |||
10610 | case BuiltinType::SatUShortAccum: | |||
10611 | return SatShortAccumTy; | |||
10612 | case BuiltinType::SatUAccum: | |||
10613 | return SatAccumTy; | |||
10614 | case BuiltinType::SatULongAccum: | |||
10615 | return SatLongAccumTy; | |||
10616 | case BuiltinType::UShortFract: | |||
10617 | return ShortFractTy; | |||
10618 | case BuiltinType::UFract: | |||
10619 | return FractTy; | |||
10620 | case BuiltinType::ULongFract: | |||
10621 | return LongFractTy; | |||
10622 | case BuiltinType::SatUShortFract: | |||
10623 | return SatShortFractTy; | |||
10624 | case BuiltinType::SatUFract: | |||
10625 | return SatFractTy; | |||
10626 | case BuiltinType::SatULongFract: | |||
10627 | return SatLongFractTy; | |||
10628 | default: | |||
10629 | llvm_unreachable("Unexpected unsigned fixed point type")::llvm::llvm_unreachable_internal("Unexpected unsigned fixed point type" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/ASTContext.cpp" , 10629); | |||
10630 | } | |||
10631 | } |