File: | clang/lib/AST/MicrosoftMangle.cpp |
Warning: | line 2535, column 24 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===--- MicrosoftMangle.cpp - Microsoft Visual C++ Name Mangling ---------===// | ||||
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 provides C++ name mangling targeting the Microsoft Visual C++ ABI. | ||||
10 | // | ||||
11 | //===----------------------------------------------------------------------===// | ||||
12 | |||||
13 | #include "clang/AST/ASTContext.h" | ||||
14 | #include "clang/AST/Attr.h" | ||||
15 | #include "clang/AST/CXXInheritance.h" | ||||
16 | #include "clang/AST/CharUnits.h" | ||||
17 | #include "clang/AST/Decl.h" | ||||
18 | #include "clang/AST/DeclCXX.h" | ||||
19 | #include "clang/AST/DeclObjC.h" | ||||
20 | #include "clang/AST/DeclOpenMP.h" | ||||
21 | #include "clang/AST/DeclTemplate.h" | ||||
22 | #include "clang/AST/Expr.h" | ||||
23 | #include "clang/AST/ExprCXX.h" | ||||
24 | #include "clang/AST/Mangle.h" | ||||
25 | #include "clang/AST/VTableBuilder.h" | ||||
26 | #include "clang/Basic/ABI.h" | ||||
27 | #include "clang/Basic/DiagnosticOptions.h" | ||||
28 | #include "clang/Basic/FileManager.h" | ||||
29 | #include "clang/Basic/SourceManager.h" | ||||
30 | #include "clang/Basic/TargetInfo.h" | ||||
31 | #include "llvm/ADT/StringExtras.h" | ||||
32 | #include "llvm/Support/CRC.h" | ||||
33 | #include "llvm/Support/MD5.h" | ||||
34 | #include "llvm/Support/MathExtras.h" | ||||
35 | #include "llvm/Support/StringSaver.h" | ||||
36 | #include "llvm/Support/xxhash.h" | ||||
37 | |||||
38 | using namespace clang; | ||||
39 | |||||
40 | namespace { | ||||
41 | |||||
42 | struct msvc_hashing_ostream : public llvm::raw_svector_ostream { | ||||
43 | raw_ostream &OS; | ||||
44 | llvm::SmallString<64> Buffer; | ||||
45 | |||||
46 | msvc_hashing_ostream(raw_ostream &OS) | ||||
47 | : llvm::raw_svector_ostream(Buffer), OS(OS) {} | ||||
48 | ~msvc_hashing_ostream() override { | ||||
49 | StringRef MangledName = str(); | ||||
50 | bool StartsWithEscape = MangledName.startswith("\01"); | ||||
51 | if (StartsWithEscape) | ||||
52 | MangledName = MangledName.drop_front(1); | ||||
53 | if (MangledName.size() < 4096) { | ||||
54 | OS << str(); | ||||
55 | return; | ||||
56 | } | ||||
57 | |||||
58 | llvm::MD5 Hasher; | ||||
59 | llvm::MD5::MD5Result Hash; | ||||
60 | Hasher.update(MangledName); | ||||
61 | Hasher.final(Hash); | ||||
62 | |||||
63 | SmallString<32> HexString; | ||||
64 | llvm::MD5::stringifyResult(Hash, HexString); | ||||
65 | |||||
66 | if (StartsWithEscape) | ||||
67 | OS << '\01'; | ||||
68 | OS << "??@" << HexString << '@'; | ||||
69 | } | ||||
70 | }; | ||||
71 | |||||
72 | static const DeclContext * | ||||
73 | getLambdaDefaultArgumentDeclContext(const Decl *D) { | ||||
74 | if (const auto *RD = dyn_cast<CXXRecordDecl>(D)) | ||||
75 | if (RD->isLambda()) | ||||
76 | if (const auto *Parm = | ||||
77 | dyn_cast_or_null<ParmVarDecl>(RD->getLambdaContextDecl())) | ||||
78 | return Parm->getDeclContext(); | ||||
79 | return nullptr; | ||||
80 | } | ||||
81 | |||||
82 | /// Retrieve the declaration context that should be used when mangling | ||||
83 | /// the given declaration. | ||||
84 | static const DeclContext *getEffectiveDeclContext(const Decl *D) { | ||||
85 | // The ABI assumes that lambda closure types that occur within | ||||
86 | // default arguments live in the context of the function. However, due to | ||||
87 | // the way in which Clang parses and creates function declarations, this is | ||||
88 | // not the case: the lambda closure type ends up living in the context | ||||
89 | // where the function itself resides, because the function declaration itself | ||||
90 | // had not yet been created. Fix the context here. | ||||
91 | if (const auto *LDADC = getLambdaDefaultArgumentDeclContext(D)) | ||||
92 | return LDADC; | ||||
93 | |||||
94 | // Perform the same check for block literals. | ||||
95 | if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) { | ||||
96 | if (ParmVarDecl *ContextParam = | ||||
97 | dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl())) | ||||
98 | return ContextParam->getDeclContext(); | ||||
99 | } | ||||
100 | |||||
101 | const DeclContext *DC = D->getDeclContext(); | ||||
102 | if (isa<CapturedDecl>(DC) || isa<OMPDeclareReductionDecl>(DC) || | ||||
103 | isa<OMPDeclareMapperDecl>(DC)) { | ||||
104 | return getEffectiveDeclContext(cast<Decl>(DC)); | ||||
105 | } | ||||
106 | |||||
107 | return DC->getRedeclContext(); | ||||
108 | } | ||||
109 | |||||
110 | static const DeclContext *getEffectiveParentContext(const DeclContext *DC) { | ||||
111 | return getEffectiveDeclContext(cast<Decl>(DC)); | ||||
112 | } | ||||
113 | |||||
114 | static const FunctionDecl *getStructor(const NamedDecl *ND) { | ||||
115 | if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(ND)) | ||||
116 | return FTD->getTemplatedDecl()->getCanonicalDecl(); | ||||
117 | |||||
118 | const auto *FD = cast<FunctionDecl>(ND); | ||||
119 | if (const auto *FTD = FD->getPrimaryTemplate()) | ||||
120 | return FTD->getTemplatedDecl()->getCanonicalDecl(); | ||||
121 | |||||
122 | return FD->getCanonicalDecl(); | ||||
123 | } | ||||
124 | |||||
125 | /// MicrosoftMangleContextImpl - Overrides the default MangleContext for the | ||||
126 | /// Microsoft Visual C++ ABI. | ||||
127 | class MicrosoftMangleContextImpl : public MicrosoftMangleContext { | ||||
128 | typedef std::pair<const DeclContext *, IdentifierInfo *> DiscriminatorKeyTy; | ||||
129 | llvm::DenseMap<DiscriminatorKeyTy, unsigned> Discriminator; | ||||
130 | llvm::DenseMap<const NamedDecl *, unsigned> Uniquifier; | ||||
131 | llvm::DenseMap<const CXXRecordDecl *, unsigned> LambdaIds; | ||||
132 | llvm::DenseMap<const NamedDecl *, unsigned> SEHFilterIds; | ||||
133 | llvm::DenseMap<const NamedDecl *, unsigned> SEHFinallyIds; | ||||
134 | SmallString<16> AnonymousNamespaceHash; | ||||
135 | |||||
136 | public: | ||||
137 | MicrosoftMangleContextImpl(ASTContext &Context, DiagnosticsEngine &Diags); | ||||
138 | bool shouldMangleCXXName(const NamedDecl *D) override; | ||||
139 | bool shouldMangleStringLiteral(const StringLiteral *SL) override; | ||||
140 | void mangleCXXName(GlobalDecl GD, raw_ostream &Out) override; | ||||
141 | void mangleVirtualMemPtrThunk(const CXXMethodDecl *MD, | ||||
142 | const MethodVFTableLocation &ML, | ||||
143 | raw_ostream &Out) override; | ||||
144 | void mangleThunk(const CXXMethodDecl *MD, const ThunkInfo &Thunk, | ||||
145 | raw_ostream &) override; | ||||
146 | void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type, | ||||
147 | const ThisAdjustment &ThisAdjustment, | ||||
148 | raw_ostream &) override; | ||||
149 | void mangleCXXVFTable(const CXXRecordDecl *Derived, | ||||
150 | ArrayRef<const CXXRecordDecl *> BasePath, | ||||
151 | raw_ostream &Out) override; | ||||
152 | void mangleCXXVBTable(const CXXRecordDecl *Derived, | ||||
153 | ArrayRef<const CXXRecordDecl *> BasePath, | ||||
154 | raw_ostream &Out) override; | ||||
155 | void mangleCXXVirtualDisplacementMap(const CXXRecordDecl *SrcRD, | ||||
156 | const CXXRecordDecl *DstRD, | ||||
157 | raw_ostream &Out) override; | ||||
158 | void mangleCXXThrowInfo(QualType T, bool IsConst, bool IsVolatile, | ||||
159 | bool IsUnaligned, uint32_t NumEntries, | ||||
160 | raw_ostream &Out) override; | ||||
161 | void mangleCXXCatchableTypeArray(QualType T, uint32_t NumEntries, | ||||
162 | raw_ostream &Out) override; | ||||
163 | void mangleCXXCatchableType(QualType T, const CXXConstructorDecl *CD, | ||||
164 | CXXCtorType CT, uint32_t Size, uint32_t NVOffset, | ||||
165 | int32_t VBPtrOffset, uint32_t VBIndex, | ||||
166 | raw_ostream &Out) override; | ||||
167 | void mangleCXXRTTI(QualType T, raw_ostream &Out) override; | ||||
168 | void mangleCXXRTTIName(QualType T, raw_ostream &Out) override; | ||||
169 | void mangleCXXRTTIBaseClassDescriptor(const CXXRecordDecl *Derived, | ||||
170 | uint32_t NVOffset, int32_t VBPtrOffset, | ||||
171 | uint32_t VBTableOffset, uint32_t Flags, | ||||
172 | raw_ostream &Out) override; | ||||
173 | void mangleCXXRTTIBaseClassArray(const CXXRecordDecl *Derived, | ||||
174 | raw_ostream &Out) override; | ||||
175 | void mangleCXXRTTIClassHierarchyDescriptor(const CXXRecordDecl *Derived, | ||||
176 | raw_ostream &Out) override; | ||||
177 | void | ||||
178 | mangleCXXRTTICompleteObjectLocator(const CXXRecordDecl *Derived, | ||||
179 | ArrayRef<const CXXRecordDecl *> BasePath, | ||||
180 | raw_ostream &Out) override; | ||||
181 | void mangleTypeName(QualType T, raw_ostream &) override; | ||||
182 | void mangleReferenceTemporary(const VarDecl *, unsigned ManglingNumber, | ||||
183 | raw_ostream &) override; | ||||
184 | void mangleStaticGuardVariable(const VarDecl *D, raw_ostream &Out) override; | ||||
185 | void mangleThreadSafeStaticGuardVariable(const VarDecl *D, unsigned GuardNum, | ||||
186 | raw_ostream &Out) override; | ||||
187 | void mangleDynamicInitializer(const VarDecl *D, raw_ostream &Out) override; | ||||
188 | void mangleDynamicAtExitDestructor(const VarDecl *D, | ||||
189 | raw_ostream &Out) override; | ||||
190 | void mangleSEHFilterExpression(const NamedDecl *EnclosingDecl, | ||||
191 | raw_ostream &Out) override; | ||||
192 | void mangleSEHFinallyBlock(const NamedDecl *EnclosingDecl, | ||||
193 | raw_ostream &Out) override; | ||||
194 | void mangleStringLiteral(const StringLiteral *SL, raw_ostream &Out) override; | ||||
195 | bool getNextDiscriminator(const NamedDecl *ND, unsigned &disc) { | ||||
196 | const DeclContext *DC = getEffectiveDeclContext(ND); | ||||
197 | if (!DC->isFunctionOrMethod()) | ||||
198 | return false; | ||||
199 | |||||
200 | // Lambda closure types are already numbered, give out a phony number so | ||||
201 | // that they demangle nicely. | ||||
202 | if (const auto *RD = dyn_cast<CXXRecordDecl>(ND)) { | ||||
203 | if (RD->isLambda()) { | ||||
204 | disc = 1; | ||||
205 | return true; | ||||
206 | } | ||||
207 | } | ||||
208 | |||||
209 | // Use the canonical number for externally visible decls. | ||||
210 | if (ND->isExternallyVisible()) { | ||||
211 | disc = getASTContext().getManglingNumber(ND); | ||||
212 | return true; | ||||
213 | } | ||||
214 | |||||
215 | // Anonymous tags are already numbered. | ||||
216 | if (const TagDecl *Tag = dyn_cast<TagDecl>(ND)) { | ||||
217 | if (!Tag->hasNameForLinkage() && | ||||
218 | !getASTContext().getDeclaratorForUnnamedTagDecl(Tag) && | ||||
219 | !getASTContext().getTypedefNameForUnnamedTagDecl(Tag)) | ||||
220 | return false; | ||||
221 | } | ||||
222 | |||||
223 | // Make up a reasonable number for internal decls. | ||||
224 | unsigned &discriminator = Uniquifier[ND]; | ||||
225 | if (!discriminator) | ||||
226 | discriminator = ++Discriminator[std::make_pair(DC, ND->getIdentifier())]; | ||||
227 | disc = discriminator + 1; | ||||
228 | return true; | ||||
229 | } | ||||
230 | |||||
231 | std::string getLambdaString(const CXXRecordDecl *Lambda) override { | ||||
232 | assert(Lambda->isLambda() && "RD must be a lambda!")((Lambda->isLambda() && "RD must be a lambda!") ? static_cast <void> (0) : __assert_fail ("Lambda->isLambda() && \"RD must be a lambda!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 232, __PRETTY_FUNCTION__)); | ||||
233 | std::string Name("<lambda_"); | ||||
234 | |||||
235 | Decl *LambdaContextDecl = Lambda->getLambdaContextDecl(); | ||||
236 | unsigned LambdaManglingNumber = Lambda->getLambdaManglingNumber(); | ||||
237 | unsigned LambdaId; | ||||
238 | const ParmVarDecl *Parm = dyn_cast_or_null<ParmVarDecl>(LambdaContextDecl); | ||||
239 | const FunctionDecl *Func = | ||||
240 | Parm ? dyn_cast<FunctionDecl>(Parm->getDeclContext()) : nullptr; | ||||
241 | |||||
242 | if (Func) { | ||||
243 | unsigned DefaultArgNo = | ||||
244 | Func->getNumParams() - Parm->getFunctionScopeIndex(); | ||||
245 | Name += llvm::utostr(DefaultArgNo); | ||||
246 | Name += "_"; | ||||
247 | } | ||||
248 | |||||
249 | if (LambdaManglingNumber) | ||||
250 | LambdaId = LambdaManglingNumber; | ||||
251 | else | ||||
252 | LambdaId = getLambdaIdForDebugInfo(Lambda); | ||||
253 | |||||
254 | Name += llvm::utostr(LambdaId); | ||||
255 | Name += ">"; | ||||
256 | return Name; | ||||
257 | } | ||||
258 | |||||
259 | unsigned getLambdaId(const CXXRecordDecl *RD) { | ||||
260 | assert(RD->isLambda() && "RD must be a lambda!")((RD->isLambda() && "RD must be a lambda!") ? static_cast <void> (0) : __assert_fail ("RD->isLambda() && \"RD must be a lambda!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 260, __PRETTY_FUNCTION__)); | ||||
261 | assert(!RD->isExternallyVisible() && "RD must not be visible!")((!RD->isExternallyVisible() && "RD must not be visible!" ) ? static_cast<void> (0) : __assert_fail ("!RD->isExternallyVisible() && \"RD must not be visible!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 261, __PRETTY_FUNCTION__)); | ||||
262 | assert(RD->getLambdaManglingNumber() == 0 &&((RD->getLambdaManglingNumber() == 0 && "RD must not have a mangling number!" ) ? static_cast<void> (0) : __assert_fail ("RD->getLambdaManglingNumber() == 0 && \"RD must not have a mangling number!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 263, __PRETTY_FUNCTION__)) | ||||
263 | "RD must not have a mangling number!")((RD->getLambdaManglingNumber() == 0 && "RD must not have a mangling number!" ) ? static_cast<void> (0) : __assert_fail ("RD->getLambdaManglingNumber() == 0 && \"RD must not have a mangling number!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 263, __PRETTY_FUNCTION__)); | ||||
264 | std::pair<llvm::DenseMap<const CXXRecordDecl *, unsigned>::iterator, bool> | ||||
265 | Result = LambdaIds.insert(std::make_pair(RD, LambdaIds.size())); | ||||
266 | return Result.first->second; | ||||
267 | } | ||||
268 | |||||
269 | unsigned getLambdaIdForDebugInfo(const CXXRecordDecl *RD) { | ||||
270 | assert(RD->isLambda() && "RD must be a lambda!")((RD->isLambda() && "RD must be a lambda!") ? static_cast <void> (0) : __assert_fail ("RD->isLambda() && \"RD must be a lambda!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 270, __PRETTY_FUNCTION__)); | ||||
271 | assert(!RD->isExternallyVisible() && "RD must not be visible!")((!RD->isExternallyVisible() && "RD must not be visible!" ) ? static_cast<void> (0) : __assert_fail ("!RD->isExternallyVisible() && \"RD must not be visible!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 271, __PRETTY_FUNCTION__)); | ||||
272 | assert(RD->getLambdaManglingNumber() == 0 &&((RD->getLambdaManglingNumber() == 0 && "RD must not have a mangling number!" ) ? static_cast<void> (0) : __assert_fail ("RD->getLambdaManglingNumber() == 0 && \"RD must not have a mangling number!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 273, __PRETTY_FUNCTION__)) | ||||
273 | "RD must not have a mangling number!")((RD->getLambdaManglingNumber() == 0 && "RD must not have a mangling number!" ) ? static_cast<void> (0) : __assert_fail ("RD->getLambdaManglingNumber() == 0 && \"RD must not have a mangling number!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 273, __PRETTY_FUNCTION__)); | ||||
274 | llvm::DenseMap<const CXXRecordDecl *, unsigned>::iterator Result = | ||||
275 | LambdaIds.find(RD); | ||||
276 | // The lambda should exist, but return 0 in case it doesn't. | ||||
277 | if (Result == LambdaIds.end()) | ||||
278 | return 0; | ||||
279 | return Result->second; | ||||
280 | } | ||||
281 | |||||
282 | /// Return a character sequence that is (somewhat) unique to the TU suitable | ||||
283 | /// for mangling anonymous namespaces. | ||||
284 | StringRef getAnonymousNamespaceHash() const { | ||||
285 | return AnonymousNamespaceHash; | ||||
286 | } | ||||
287 | |||||
288 | private: | ||||
289 | void mangleInitFiniStub(const VarDecl *D, char CharCode, raw_ostream &Out); | ||||
290 | }; | ||||
291 | |||||
292 | /// MicrosoftCXXNameMangler - Manage the mangling of a single name for the | ||||
293 | /// Microsoft Visual C++ ABI. | ||||
294 | class MicrosoftCXXNameMangler { | ||||
295 | MicrosoftMangleContextImpl &Context; | ||||
296 | raw_ostream &Out; | ||||
297 | |||||
298 | /// The "structor" is the top-level declaration being mangled, if | ||||
299 | /// that's not a template specialization; otherwise it's the pattern | ||||
300 | /// for that specialization. | ||||
301 | const NamedDecl *Structor; | ||||
302 | unsigned StructorType; | ||||
303 | |||||
304 | typedef llvm::SmallVector<std::string, 10> BackRefVec; | ||||
305 | BackRefVec NameBackReferences; | ||||
306 | |||||
307 | typedef llvm::DenseMap<const void *, unsigned> ArgBackRefMap; | ||||
308 | ArgBackRefMap FunArgBackReferences; | ||||
309 | ArgBackRefMap TemplateArgBackReferences; | ||||
310 | |||||
311 | typedef llvm::DenseMap<const void *, StringRef> TemplateArgStringMap; | ||||
312 | TemplateArgStringMap TemplateArgStrings; | ||||
313 | llvm::StringSaver TemplateArgStringStorage; | ||||
314 | llvm::BumpPtrAllocator TemplateArgStringStorageAlloc; | ||||
315 | |||||
316 | typedef std::set<std::pair<int, bool>> PassObjectSizeArgsSet; | ||||
317 | PassObjectSizeArgsSet PassObjectSizeArgs; | ||||
318 | |||||
319 | ASTContext &getASTContext() const { return Context.getASTContext(); } | ||||
320 | |||||
321 | const bool PointersAre64Bit; | ||||
322 | |||||
323 | public: | ||||
324 | enum QualifierMangleMode { QMM_Drop, QMM_Mangle, QMM_Escape, QMM_Result }; | ||||
325 | |||||
326 | MicrosoftCXXNameMangler(MicrosoftMangleContextImpl &C, raw_ostream &Out_) | ||||
327 | : Context(C), Out(Out_), Structor(nullptr), StructorType(-1), | ||||
328 | TemplateArgStringStorage(TemplateArgStringStorageAlloc), | ||||
329 | PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth(0) == | ||||
330 | 64) {} | ||||
331 | |||||
332 | MicrosoftCXXNameMangler(MicrosoftMangleContextImpl &C, raw_ostream &Out_, | ||||
333 | const CXXConstructorDecl *D, CXXCtorType Type) | ||||
334 | : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type), | ||||
335 | TemplateArgStringStorage(TemplateArgStringStorageAlloc), | ||||
336 | PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth(0) == | ||||
337 | 64) {} | ||||
338 | |||||
339 | MicrosoftCXXNameMangler(MicrosoftMangleContextImpl &C, raw_ostream &Out_, | ||||
340 | const CXXDestructorDecl *D, CXXDtorType Type) | ||||
341 | : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type), | ||||
342 | TemplateArgStringStorage(TemplateArgStringStorageAlloc), | ||||
343 | PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth(0) == | ||||
344 | 64) {} | ||||
345 | |||||
346 | raw_ostream &getStream() const { return Out; } | ||||
347 | |||||
348 | void mangle(const NamedDecl *D, StringRef Prefix = "?"); | ||||
349 | void mangleName(const NamedDecl *ND); | ||||
350 | void mangleFunctionEncoding(const FunctionDecl *FD, bool ShouldMangle); | ||||
351 | void mangleVariableEncoding(const VarDecl *VD); | ||||
352 | void mangleMemberDataPointer(const CXXRecordDecl *RD, const ValueDecl *VD, | ||||
353 | StringRef Prefix = "$"); | ||||
354 | void mangleMemberFunctionPointer(const CXXRecordDecl *RD, | ||||
355 | const CXXMethodDecl *MD, | ||||
356 | StringRef Prefix = "$"); | ||||
357 | void mangleVirtualMemPtrThunk(const CXXMethodDecl *MD, | ||||
358 | const MethodVFTableLocation &ML); | ||||
359 | void mangleNumber(int64_t Number); | ||||
360 | void mangleNumber(llvm::APSInt Number); | ||||
361 | void mangleFloat(llvm::APFloat Number); | ||||
362 | void mangleBits(llvm::APInt Number); | ||||
363 | void mangleTagTypeKind(TagTypeKind TK); | ||||
364 | void mangleArtificialTagType(TagTypeKind TK, StringRef UnqualifiedName, | ||||
365 | ArrayRef<StringRef> NestedNames = None); | ||||
366 | void mangleAddressSpaceType(QualType T, Qualifiers Quals, SourceRange Range); | ||||
367 | void mangleType(QualType T, SourceRange Range, | ||||
368 | QualifierMangleMode QMM = QMM_Mangle); | ||||
369 | void mangleFunctionType(const FunctionType *T, | ||||
370 | const FunctionDecl *D = nullptr, | ||||
371 | bool ForceThisQuals = false, | ||||
372 | bool MangleExceptionSpec = true); | ||||
373 | void mangleNestedName(const NamedDecl *ND); | ||||
374 | |||||
375 | private: | ||||
376 | bool isStructorDecl(const NamedDecl *ND) const { | ||||
377 | return ND == Structor || getStructor(ND) == Structor; | ||||
378 | } | ||||
379 | |||||
380 | bool is64BitPointer(Qualifiers Quals) const { | ||||
381 | LangAS AddrSpace = Quals.getAddressSpace(); | ||||
382 | return AddrSpace == LangAS::ptr64 || | ||||
383 | (PointersAre64Bit && !(AddrSpace == LangAS::ptr32_sptr || | ||||
384 | AddrSpace == LangAS::ptr32_uptr)); | ||||
385 | } | ||||
386 | |||||
387 | void mangleUnqualifiedName(const NamedDecl *ND) { | ||||
388 | mangleUnqualifiedName(ND, ND->getDeclName()); | ||||
389 | } | ||||
390 | void mangleUnqualifiedName(const NamedDecl *ND, DeclarationName Name); | ||||
391 | void mangleSourceName(StringRef Name); | ||||
392 | void mangleOperatorName(OverloadedOperatorKind OO, SourceLocation Loc); | ||||
393 | void mangleCXXDtorType(CXXDtorType T); | ||||
394 | void mangleQualifiers(Qualifiers Quals, bool IsMember); | ||||
395 | void mangleRefQualifier(RefQualifierKind RefQualifier); | ||||
396 | void manglePointerCVQualifiers(Qualifiers Quals); | ||||
397 | void manglePointerExtQualifiers(Qualifiers Quals, QualType PointeeType); | ||||
398 | |||||
399 | void mangleUnscopedTemplateName(const TemplateDecl *ND); | ||||
400 | void | ||||
401 | mangleTemplateInstantiationName(const TemplateDecl *TD, | ||||
402 | const TemplateArgumentList &TemplateArgs); | ||||
403 | void mangleObjCMethodName(const ObjCMethodDecl *MD); | ||||
404 | |||||
405 | void mangleFunctionArgumentType(QualType T, SourceRange Range); | ||||
406 | void manglePassObjectSizeArg(const PassObjectSizeAttr *POSA); | ||||
407 | |||||
408 | bool isArtificialTagType(QualType T) const; | ||||
409 | |||||
410 | // Declare manglers for every type class. | ||||
411 | #define ABSTRACT_TYPE(CLASS, PARENT) | ||||
412 | #define NON_CANONICAL_TYPE(CLASS, PARENT) | ||||
413 | #define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T, \ | ||||
414 | Qualifiers Quals, \ | ||||
415 | SourceRange Range); | ||||
416 | #include "clang/AST/TypeNodes.inc" | ||||
417 | #undef ABSTRACT_TYPE | ||||
418 | #undef NON_CANONICAL_TYPE | ||||
419 | #undef TYPE | ||||
420 | |||||
421 | void mangleType(const TagDecl *TD); | ||||
422 | void mangleDecayedArrayType(const ArrayType *T); | ||||
423 | void mangleArrayType(const ArrayType *T); | ||||
424 | void mangleFunctionClass(const FunctionDecl *FD); | ||||
425 | void mangleCallingConvention(CallingConv CC); | ||||
426 | void mangleCallingConvention(const FunctionType *T); | ||||
427 | void mangleIntegerLiteral(const llvm::APSInt &Number, | ||||
428 | const NonTypeTemplateParmDecl *PD = nullptr, | ||||
429 | QualType TemplateArgType = QualType()); | ||||
430 | void mangleExpression(const Expr *E, const NonTypeTemplateParmDecl *PD); | ||||
431 | void mangleThrowSpecification(const FunctionProtoType *T); | ||||
432 | |||||
433 | void mangleTemplateArgs(const TemplateDecl *TD, | ||||
434 | const TemplateArgumentList &TemplateArgs); | ||||
435 | void mangleTemplateArg(const TemplateDecl *TD, const TemplateArgument &TA, | ||||
436 | const NamedDecl *Parm); | ||||
437 | void mangleTemplateArgValue(QualType T, const APValue &V, | ||||
438 | bool WithScalarType = false); | ||||
439 | |||||
440 | void mangleObjCProtocol(const ObjCProtocolDecl *PD); | ||||
441 | void mangleObjCLifetime(const QualType T, Qualifiers Quals, | ||||
442 | SourceRange Range); | ||||
443 | void mangleObjCKindOfType(const ObjCObjectType *T, Qualifiers Quals, | ||||
444 | SourceRange Range); | ||||
445 | }; | ||||
446 | } | ||||
447 | |||||
448 | MicrosoftMangleContextImpl::MicrosoftMangleContextImpl(ASTContext &Context, | ||||
449 | DiagnosticsEngine &Diags) | ||||
450 | : MicrosoftMangleContext(Context, Diags) { | ||||
451 | // To mangle anonymous namespaces, hash the path to the main source file. The | ||||
452 | // path should be whatever (probably relative) path was passed on the command | ||||
453 | // line. The goal is for the compiler to produce the same output regardless of | ||||
454 | // working directory, so use the uncanonicalized relative path. | ||||
455 | // | ||||
456 | // It's important to make the mangled names unique because, when CodeView | ||||
457 | // debug info is in use, the debugger uses mangled type names to distinguish | ||||
458 | // between otherwise identically named types in anonymous namespaces. | ||||
459 | // | ||||
460 | // These symbols are always internal, so there is no need for the hash to | ||||
461 | // match what MSVC produces. For the same reason, clang is free to change the | ||||
462 | // hash at any time without breaking compatibility with old versions of clang. | ||||
463 | // The generated names are intended to look similar to what MSVC generates, | ||||
464 | // which are something like "?A0x01234567@". | ||||
465 | SourceManager &SM = Context.getSourceManager(); | ||||
466 | if (const FileEntry *FE = SM.getFileEntryForID(SM.getMainFileID())) { | ||||
467 | // Truncate the hash so we get 8 characters of hexadecimal. | ||||
468 | uint32_t TruncatedHash = uint32_t(xxHash64(FE->getName())); | ||||
469 | AnonymousNamespaceHash = llvm::utohexstr(TruncatedHash); | ||||
470 | } else { | ||||
471 | // If we don't have a path to the main file, we'll just use 0. | ||||
472 | AnonymousNamespaceHash = "0"; | ||||
473 | } | ||||
474 | } | ||||
475 | |||||
476 | bool MicrosoftMangleContextImpl::shouldMangleCXXName(const NamedDecl *D) { | ||||
477 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { | ||||
478 | LanguageLinkage L = FD->getLanguageLinkage(); | ||||
479 | // Overloadable functions need mangling. | ||||
480 | if (FD->hasAttr<OverloadableAttr>()) | ||||
481 | return true; | ||||
482 | |||||
483 | // The ABI expects that we would never mangle "typical" user-defined entry | ||||
484 | // points regardless of visibility or freestanding-ness. | ||||
485 | // | ||||
486 | // N.B. This is distinct from asking about "main". "main" has a lot of | ||||
487 | // special rules associated with it in the standard while these | ||||
488 | // user-defined entry points are outside of the purview of the standard. | ||||
489 | // For example, there can be only one definition for "main" in a standards | ||||
490 | // compliant program; however nothing forbids the existence of wmain and | ||||
491 | // WinMain in the same translation unit. | ||||
492 | if (FD->isMSVCRTEntryPoint()) | ||||
493 | return false; | ||||
494 | |||||
495 | // C++ functions and those whose names are not a simple identifier need | ||||
496 | // mangling. | ||||
497 | if (!FD->getDeclName().isIdentifier() || L == CXXLanguageLinkage) | ||||
498 | return true; | ||||
499 | |||||
500 | // C functions are not mangled. | ||||
501 | if (L == CLanguageLinkage) | ||||
502 | return false; | ||||
503 | } | ||||
504 | |||||
505 | // Otherwise, no mangling is done outside C++ mode. | ||||
506 | if (!getASTContext().getLangOpts().CPlusPlus) | ||||
507 | return false; | ||||
508 | |||||
509 | const VarDecl *VD = dyn_cast<VarDecl>(D); | ||||
510 | if (VD && !isa<DecompositionDecl>(D)) { | ||||
511 | // C variables are not mangled. | ||||
512 | if (VD->isExternC()) | ||||
513 | return false; | ||||
514 | |||||
515 | // Variables at global scope with internal linkage are not mangled. | ||||
516 | const DeclContext *DC = getEffectiveDeclContext(D); | ||||
517 | // Check for extern variable declared locally. | ||||
518 | if (DC->isFunctionOrMethod() && D->hasLinkage()) | ||||
519 | while (!DC->isNamespace() && !DC->isTranslationUnit()) | ||||
520 | DC = getEffectiveParentContext(DC); | ||||
521 | |||||
522 | if (DC->isTranslationUnit() && D->getFormalLinkage() == InternalLinkage && | ||||
523 | !isa<VarTemplateSpecializationDecl>(D) && | ||||
524 | D->getIdentifier() != nullptr) | ||||
525 | return false; | ||||
526 | } | ||||
527 | |||||
528 | return true; | ||||
529 | } | ||||
530 | |||||
531 | bool | ||||
532 | MicrosoftMangleContextImpl::shouldMangleStringLiteral(const StringLiteral *SL) { | ||||
533 | return true; | ||||
534 | } | ||||
535 | |||||
536 | void MicrosoftCXXNameMangler::mangle(const NamedDecl *D, StringRef Prefix) { | ||||
537 | // MSVC doesn't mangle C++ names the same way it mangles extern "C" names. | ||||
538 | // Therefore it's really important that we don't decorate the | ||||
539 | // name with leading underscores or leading/trailing at signs. So, by | ||||
540 | // default, we emit an asm marker at the start so we get the name right. | ||||
541 | // Callers can override this with a custom prefix. | ||||
542 | |||||
543 | // <mangled-name> ::= ? <name> <type-encoding> | ||||
544 | Out << Prefix; | ||||
545 | mangleName(D); | ||||
546 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) | ||||
547 | mangleFunctionEncoding(FD, Context.shouldMangleDeclName(FD)); | ||||
548 | else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) | ||||
549 | mangleVariableEncoding(VD); | ||||
550 | else if (isa<MSGuidDecl>(D)) | ||||
551 | // MSVC appears to mangle GUIDs as if they were variables of type | ||||
552 | // 'const struct __s_GUID'. | ||||
553 | Out << "3U__s_GUID@@B"; | ||||
554 | else if (isa<TemplateParamObjectDecl>(D)) { | ||||
555 | // Template parameter objects don't get a <type-encoding>; their type is | ||||
556 | // specified as part of their value. | ||||
557 | } else | ||||
558 | llvm_unreachable("Tried to mangle unexpected NamedDecl!")::llvm::llvm_unreachable_internal("Tried to mangle unexpected NamedDecl!" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 558); | ||||
559 | } | ||||
560 | |||||
561 | void MicrosoftCXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD, | ||||
562 | bool ShouldMangle) { | ||||
563 | // <type-encoding> ::= <function-class> <function-type> | ||||
564 | |||||
565 | // Since MSVC operates on the type as written and not the canonical type, it | ||||
566 | // actually matters which decl we have here. MSVC appears to choose the | ||||
567 | // first, since it is most likely to be the declaration in a header file. | ||||
568 | FD = FD->getFirstDecl(); | ||||
569 | |||||
570 | // We should never ever see a FunctionNoProtoType at this point. | ||||
571 | // We don't even know how to mangle their types anyway :). | ||||
572 | const FunctionProtoType *FT = FD->getType()->castAs<FunctionProtoType>(); | ||||
573 | |||||
574 | // extern "C" functions can hold entities that must be mangled. | ||||
575 | // As it stands, these functions still need to get expressed in the full | ||||
576 | // external name. They have their class and type omitted, replaced with '9'. | ||||
577 | if (ShouldMangle) { | ||||
578 | // We would like to mangle all extern "C" functions using this additional | ||||
579 | // component but this would break compatibility with MSVC's behavior. | ||||
580 | // Instead, do this when we know that compatibility isn't important (in | ||||
581 | // other words, when it is an overloaded extern "C" function). | ||||
582 | if (FD->isExternC() && FD->hasAttr<OverloadableAttr>()) | ||||
583 | Out << "$$J0"; | ||||
584 | |||||
585 | mangleFunctionClass(FD); | ||||
586 | |||||
587 | mangleFunctionType(FT, FD, false, false); | ||||
588 | } else { | ||||
589 | Out << '9'; | ||||
590 | } | ||||
591 | } | ||||
592 | |||||
593 | void MicrosoftCXXNameMangler::mangleVariableEncoding(const VarDecl *VD) { | ||||
594 | // <type-encoding> ::= <storage-class> <variable-type> | ||||
595 | // <storage-class> ::= 0 # private static member | ||||
596 | // ::= 1 # protected static member | ||||
597 | // ::= 2 # public static member | ||||
598 | // ::= 3 # global | ||||
599 | // ::= 4 # static local | ||||
600 | |||||
601 | // The first character in the encoding (after the name) is the storage class. | ||||
602 | if (VD->isStaticDataMember()) { | ||||
603 | // If it's a static member, it also encodes the access level. | ||||
604 | switch (VD->getAccess()) { | ||||
605 | default: | ||||
606 | case AS_private: Out << '0'; break; | ||||
607 | case AS_protected: Out << '1'; break; | ||||
608 | case AS_public: Out << '2'; break; | ||||
609 | } | ||||
610 | } | ||||
611 | else if (!VD->isStaticLocal()) | ||||
612 | Out << '3'; | ||||
613 | else | ||||
614 | Out << '4'; | ||||
615 | // Now mangle the type. | ||||
616 | // <variable-type> ::= <type> <cvr-qualifiers> | ||||
617 | // ::= <type> <pointee-cvr-qualifiers> # pointers, references | ||||
618 | // Pointers and references are odd. The type of 'int * const foo;' gets | ||||
619 | // mangled as 'QAHA' instead of 'PAHB', for example. | ||||
620 | SourceRange SR = VD->getSourceRange(); | ||||
621 | QualType Ty = VD->getType(); | ||||
622 | if (Ty->isPointerType() || Ty->isReferenceType() || | ||||
623 | Ty->isMemberPointerType()) { | ||||
624 | mangleType(Ty, SR, QMM_Drop); | ||||
625 | manglePointerExtQualifiers( | ||||
626 | Ty.getDesugaredType(getASTContext()).getLocalQualifiers(), QualType()); | ||||
627 | if (const MemberPointerType *MPT = Ty->getAs<MemberPointerType>()) { | ||||
628 | mangleQualifiers(MPT->getPointeeType().getQualifiers(), true); | ||||
629 | // Member pointers are suffixed with a back reference to the member | ||||
630 | // pointer's class name. | ||||
631 | mangleName(MPT->getClass()->getAsCXXRecordDecl()); | ||||
632 | } else | ||||
633 | mangleQualifiers(Ty->getPointeeType().getQualifiers(), false); | ||||
634 | } else if (const ArrayType *AT = getASTContext().getAsArrayType(Ty)) { | ||||
635 | // Global arrays are funny, too. | ||||
636 | mangleDecayedArrayType(AT); | ||||
637 | if (AT->getElementType()->isArrayType()) | ||||
638 | Out << 'A'; | ||||
639 | else | ||||
640 | mangleQualifiers(Ty.getQualifiers(), false); | ||||
641 | } else { | ||||
642 | mangleType(Ty, SR, QMM_Drop); | ||||
643 | mangleQualifiers(Ty.getQualifiers(), false); | ||||
644 | } | ||||
645 | } | ||||
646 | |||||
647 | void MicrosoftCXXNameMangler::mangleMemberDataPointer(const CXXRecordDecl *RD, | ||||
648 | const ValueDecl *VD, | ||||
649 | StringRef Prefix) { | ||||
650 | // <member-data-pointer> ::= <integer-literal> | ||||
651 | // ::= $F <number> <number> | ||||
652 | // ::= $G <number> <number> <number> | ||||
653 | |||||
654 | int64_t FieldOffset; | ||||
655 | int64_t VBTableOffset; | ||||
656 | MSInheritanceModel IM = RD->getMSInheritanceModel(); | ||||
657 | if (VD) { | ||||
658 | FieldOffset = getASTContext().getFieldOffset(VD); | ||||
659 | assert(FieldOffset % getASTContext().getCharWidth() == 0 &&((FieldOffset % getASTContext().getCharWidth() == 0 && "cannot take address of bitfield") ? static_cast<void> (0) : __assert_fail ("FieldOffset % getASTContext().getCharWidth() == 0 && \"cannot take address of bitfield\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 660, __PRETTY_FUNCTION__)) | ||||
660 | "cannot take address of bitfield")((FieldOffset % getASTContext().getCharWidth() == 0 && "cannot take address of bitfield") ? static_cast<void> (0) : __assert_fail ("FieldOffset % getASTContext().getCharWidth() == 0 && \"cannot take address of bitfield\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 660, __PRETTY_FUNCTION__)); | ||||
661 | FieldOffset /= getASTContext().getCharWidth(); | ||||
662 | |||||
663 | VBTableOffset = 0; | ||||
664 | |||||
665 | if (IM == MSInheritanceModel::Virtual) | ||||
666 | FieldOffset -= getASTContext().getOffsetOfBaseWithVBPtr(RD).getQuantity(); | ||||
667 | } else { | ||||
668 | FieldOffset = RD->nullFieldOffsetIsZero() ? 0 : -1; | ||||
669 | |||||
670 | VBTableOffset = -1; | ||||
671 | } | ||||
672 | |||||
673 | char Code = '\0'; | ||||
674 | switch (IM) { | ||||
675 | case MSInheritanceModel::Single: Code = '0'; break; | ||||
676 | case MSInheritanceModel::Multiple: Code = '0'; break; | ||||
677 | case MSInheritanceModel::Virtual: Code = 'F'; break; | ||||
678 | case MSInheritanceModel::Unspecified: Code = 'G'; break; | ||||
679 | } | ||||
680 | |||||
681 | Out << Prefix << Code; | ||||
682 | |||||
683 | mangleNumber(FieldOffset); | ||||
684 | |||||
685 | // The C++ standard doesn't allow base-to-derived member pointer conversions | ||||
686 | // in template parameter contexts, so the vbptr offset of data member pointers | ||||
687 | // is always zero. | ||||
688 | if (inheritanceModelHasVBPtrOffsetField(IM)) | ||||
689 | mangleNumber(0); | ||||
690 | if (inheritanceModelHasVBTableOffsetField(IM)) | ||||
691 | mangleNumber(VBTableOffset); | ||||
692 | } | ||||
693 | |||||
694 | void | ||||
695 | MicrosoftCXXNameMangler::mangleMemberFunctionPointer(const CXXRecordDecl *RD, | ||||
696 | const CXXMethodDecl *MD, | ||||
697 | StringRef Prefix) { | ||||
698 | // <member-function-pointer> ::= $1? <name> | ||||
699 | // ::= $H? <name> <number> | ||||
700 | // ::= $I? <name> <number> <number> | ||||
701 | // ::= $J? <name> <number> <number> <number> | ||||
702 | |||||
703 | MSInheritanceModel IM = RD->getMSInheritanceModel(); | ||||
704 | |||||
705 | char Code = '\0'; | ||||
706 | switch (IM) { | ||||
707 | case MSInheritanceModel::Single: Code = '1'; break; | ||||
708 | case MSInheritanceModel::Multiple: Code = 'H'; break; | ||||
709 | case MSInheritanceModel::Virtual: Code = 'I'; break; | ||||
710 | case MSInheritanceModel::Unspecified: Code = 'J'; break; | ||||
711 | } | ||||
712 | |||||
713 | // If non-virtual, mangle the name. If virtual, mangle as a virtual memptr | ||||
714 | // thunk. | ||||
715 | uint64_t NVOffset = 0; | ||||
716 | uint64_t VBTableOffset = 0; | ||||
717 | uint64_t VBPtrOffset = 0; | ||||
718 | if (MD) { | ||||
719 | Out << Prefix << Code << '?'; | ||||
720 | if (MD->isVirtual()) { | ||||
721 | MicrosoftVTableContext *VTContext = | ||||
722 | cast<MicrosoftVTableContext>(getASTContext().getVTableContext()); | ||||
723 | MethodVFTableLocation ML = | ||||
724 | VTContext->getMethodVFTableLocation(GlobalDecl(MD)); | ||||
725 | mangleVirtualMemPtrThunk(MD, ML); | ||||
726 | NVOffset = ML.VFPtrOffset.getQuantity(); | ||||
727 | VBTableOffset = ML.VBTableIndex * 4; | ||||
728 | if (ML.VBase) { | ||||
729 | const ASTRecordLayout &Layout = getASTContext().getASTRecordLayout(RD); | ||||
730 | VBPtrOffset = Layout.getVBPtrOffset().getQuantity(); | ||||
731 | } | ||||
732 | } else { | ||||
733 | mangleName(MD); | ||||
734 | mangleFunctionEncoding(MD, /*ShouldMangle=*/true); | ||||
735 | } | ||||
736 | |||||
737 | if (VBTableOffset == 0 && IM == MSInheritanceModel::Virtual) | ||||
738 | NVOffset -= getASTContext().getOffsetOfBaseWithVBPtr(RD).getQuantity(); | ||||
739 | } else { | ||||
740 | // Null single inheritance member functions are encoded as a simple nullptr. | ||||
741 | if (IM == MSInheritanceModel::Single) { | ||||
742 | Out << Prefix << "0A@"; | ||||
743 | return; | ||||
744 | } | ||||
745 | if (IM == MSInheritanceModel::Unspecified) | ||||
746 | VBTableOffset = -1; | ||||
747 | Out << Prefix << Code; | ||||
748 | } | ||||
749 | |||||
750 | if (inheritanceModelHasNVOffsetField(/*IsMemberFunction=*/true, IM)) | ||||
751 | mangleNumber(static_cast<uint32_t>(NVOffset)); | ||||
752 | if (inheritanceModelHasVBPtrOffsetField(IM)) | ||||
753 | mangleNumber(VBPtrOffset); | ||||
754 | if (inheritanceModelHasVBTableOffsetField(IM)) | ||||
755 | mangleNumber(VBTableOffset); | ||||
756 | } | ||||
757 | |||||
758 | void MicrosoftCXXNameMangler::mangleVirtualMemPtrThunk( | ||||
759 | const CXXMethodDecl *MD, const MethodVFTableLocation &ML) { | ||||
760 | // Get the vftable offset. | ||||
761 | CharUnits PointerWidth = getASTContext().toCharUnitsFromBits( | ||||
762 | getASTContext().getTargetInfo().getPointerWidth(0)); | ||||
763 | uint64_t OffsetInVFTable = ML.Index * PointerWidth.getQuantity(); | ||||
764 | |||||
765 | Out << "?_9"; | ||||
766 | mangleName(MD->getParent()); | ||||
767 | Out << "$B"; | ||||
768 | mangleNumber(OffsetInVFTable); | ||||
769 | Out << 'A'; | ||||
770 | mangleCallingConvention(MD->getType()->castAs<FunctionProtoType>()); | ||||
771 | } | ||||
772 | |||||
773 | void MicrosoftCXXNameMangler::mangleName(const NamedDecl *ND) { | ||||
774 | // <name> ::= <unscoped-name> {[<named-scope>]+ | [<nested-name>]}? @ | ||||
775 | |||||
776 | // Always start with the unqualified name. | ||||
777 | mangleUnqualifiedName(ND); | ||||
778 | |||||
779 | mangleNestedName(ND); | ||||
780 | |||||
781 | // Terminate the whole name with an '@'. | ||||
782 | Out << '@'; | ||||
783 | } | ||||
784 | |||||
785 | void MicrosoftCXXNameMangler::mangleNumber(int64_t Number) { | ||||
786 | mangleNumber(llvm::APSInt(llvm::APInt(64, Number), /*IsUnsigned*/false)); | ||||
787 | } | ||||
788 | |||||
789 | void MicrosoftCXXNameMangler::mangleNumber(llvm::APSInt Number) { | ||||
790 | // MSVC never mangles any integer wider than 64 bits. In general it appears | ||||
791 | // to convert every integer to signed 64 bit before mangling (including | ||||
792 | // unsigned 64 bit values). Do the same, but preserve bits beyond the bottom | ||||
793 | // 64. | ||||
794 | llvm::APInt Value = | ||||
795 | Number.isSigned() ? Number.sextOrSelf(64) : Number.zextOrSelf(64); | ||||
796 | |||||
797 | // <non-negative integer> ::= A@ # when Number == 0 | ||||
798 | // ::= <decimal digit> # when 1 <= Number <= 10 | ||||
799 | // ::= <hex digit>+ @ # when Number >= 10 | ||||
800 | // | ||||
801 | // <number> ::= [?] <non-negative integer> | ||||
802 | |||||
803 | if (Value.isNegative()) { | ||||
804 | Value = -Value; | ||||
805 | Out << '?'; | ||||
806 | } | ||||
807 | mangleBits(Value); | ||||
808 | } | ||||
809 | |||||
810 | void MicrosoftCXXNameMangler::mangleFloat(llvm::APFloat Number) { | ||||
811 | using llvm::APFloat; | ||||
812 | |||||
813 | switch (APFloat::SemanticsToEnum(Number.getSemantics())) { | ||||
814 | case APFloat::S_IEEEsingle: Out << 'A'; break; | ||||
815 | case APFloat::S_IEEEdouble: Out << 'B'; break; | ||||
816 | |||||
817 | // The following are all Clang extensions. We try to pick manglings that are | ||||
818 | // unlikely to conflict with MSVC's scheme. | ||||
819 | case APFloat::S_IEEEhalf: Out << 'V'; break; | ||||
820 | case APFloat::S_BFloat: Out << 'W'; break; | ||||
821 | case APFloat::S_x87DoubleExtended: Out << 'X'; break; | ||||
822 | case APFloat::S_IEEEquad: Out << 'Y'; break; | ||||
823 | case APFloat::S_PPCDoubleDouble: Out << 'Z'; break; | ||||
824 | } | ||||
825 | |||||
826 | mangleBits(Number.bitcastToAPInt()); | ||||
827 | } | ||||
828 | |||||
829 | void MicrosoftCXXNameMangler::mangleBits(llvm::APInt Value) { | ||||
830 | if (Value == 0) | ||||
831 | Out << "A@"; | ||||
832 | else if (Value.uge(1) && Value.ule(10)) | ||||
833 | Out << (Value - 1); | ||||
834 | else { | ||||
835 | // Numbers that are not encoded as decimal digits are represented as nibbles | ||||
836 | // in the range of ASCII characters 'A' to 'P'. | ||||
837 | // The number 0x123450 would be encoded as 'BCDEFA' | ||||
838 | llvm::SmallString<32> EncodedNumberBuffer; | ||||
839 | for (; Value != 0; Value.lshrInPlace(4)) | ||||
840 | EncodedNumberBuffer.push_back('A' + (Value & 0xf).getZExtValue()); | ||||
841 | std::reverse(EncodedNumberBuffer.begin(), EncodedNumberBuffer.end()); | ||||
842 | Out.write(EncodedNumberBuffer.data(), EncodedNumberBuffer.size()); | ||||
843 | Out << '@'; | ||||
844 | } | ||||
845 | } | ||||
846 | |||||
847 | static const TemplateDecl * | ||||
848 | isTemplate(const NamedDecl *ND, const TemplateArgumentList *&TemplateArgs) { | ||||
849 | // Check if we have a function template. | ||||
850 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) { | ||||
851 | if (const TemplateDecl *TD = FD->getPrimaryTemplate()) { | ||||
852 | TemplateArgs = FD->getTemplateSpecializationArgs(); | ||||
853 | return TD; | ||||
854 | } | ||||
855 | } | ||||
856 | |||||
857 | // Check if we have a class template. | ||||
858 | if (const ClassTemplateSpecializationDecl *Spec = | ||||
859 | dyn_cast<ClassTemplateSpecializationDecl>(ND)) { | ||||
860 | TemplateArgs = &Spec->getTemplateArgs(); | ||||
861 | return Spec->getSpecializedTemplate(); | ||||
862 | } | ||||
863 | |||||
864 | // Check if we have a variable template. | ||||
865 | if (const VarTemplateSpecializationDecl *Spec = | ||||
866 | dyn_cast<VarTemplateSpecializationDecl>(ND)) { | ||||
867 | TemplateArgs = &Spec->getTemplateArgs(); | ||||
868 | return Spec->getSpecializedTemplate(); | ||||
869 | } | ||||
870 | |||||
871 | return nullptr; | ||||
872 | } | ||||
873 | |||||
874 | void MicrosoftCXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, | ||||
875 | DeclarationName Name) { | ||||
876 | // <unqualified-name> ::= <operator-name> | ||||
877 | // ::= <ctor-dtor-name> | ||||
878 | // ::= <source-name> | ||||
879 | // ::= <template-name> | ||||
880 | |||||
881 | // Check if we have a template. | ||||
882 | const TemplateArgumentList *TemplateArgs = nullptr; | ||||
883 | if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { | ||||
884 | // Function templates aren't considered for name back referencing. This | ||||
885 | // makes sense since function templates aren't likely to occur multiple | ||||
886 | // times in a symbol. | ||||
887 | if (isa<FunctionTemplateDecl>(TD)) { | ||||
888 | mangleTemplateInstantiationName(TD, *TemplateArgs); | ||||
889 | Out << '@'; | ||||
890 | return; | ||||
891 | } | ||||
892 | |||||
893 | // Here comes the tricky thing: if we need to mangle something like | ||||
894 | // void foo(A::X<Y>, B::X<Y>), | ||||
895 | // the X<Y> part is aliased. However, if you need to mangle | ||||
896 | // void foo(A::X<A::Y>, A::X<B::Y>), | ||||
897 | // the A::X<> part is not aliased. | ||||
898 | // That is, from the mangler's perspective we have a structure like this: | ||||
899 | // namespace[s] -> type[ -> template-parameters] | ||||
900 | // but from the Clang perspective we have | ||||
901 | // type [ -> template-parameters] | ||||
902 | // \-> namespace[s] | ||||
903 | // What we do is we create a new mangler, mangle the same type (without | ||||
904 | // a namespace suffix) to a string using the extra mangler and then use | ||||
905 | // the mangled type name as a key to check the mangling of different types | ||||
906 | // for aliasing. | ||||
907 | |||||
908 | // It's important to key cache reads off ND, not TD -- the same TD can | ||||
909 | // be used with different TemplateArgs, but ND uniquely identifies | ||||
910 | // TD / TemplateArg pairs. | ||||
911 | ArgBackRefMap::iterator Found = TemplateArgBackReferences.find(ND); | ||||
912 | if (Found == TemplateArgBackReferences.end()) { | ||||
913 | |||||
914 | TemplateArgStringMap::iterator Found = TemplateArgStrings.find(ND); | ||||
915 | if (Found == TemplateArgStrings.end()) { | ||||
916 | // Mangle full template name into temporary buffer. | ||||
917 | llvm::SmallString<64> TemplateMangling; | ||||
918 | llvm::raw_svector_ostream Stream(TemplateMangling); | ||||
919 | MicrosoftCXXNameMangler Extra(Context, Stream); | ||||
920 | Extra.mangleTemplateInstantiationName(TD, *TemplateArgs); | ||||
921 | |||||
922 | // Use the string backref vector to possibly get a back reference. | ||||
923 | mangleSourceName(TemplateMangling); | ||||
924 | |||||
925 | // Memoize back reference for this type if one exist, else memoize | ||||
926 | // the mangling itself. | ||||
927 | BackRefVec::iterator StringFound = | ||||
928 | llvm::find(NameBackReferences, TemplateMangling); | ||||
929 | if (StringFound != NameBackReferences.end()) { | ||||
930 | TemplateArgBackReferences[ND] = | ||||
931 | StringFound - NameBackReferences.begin(); | ||||
932 | } else { | ||||
933 | TemplateArgStrings[ND] = | ||||
934 | TemplateArgStringStorage.save(TemplateMangling.str()); | ||||
935 | } | ||||
936 | } else { | ||||
937 | Out << Found->second << '@'; // Outputs a StringRef. | ||||
938 | } | ||||
939 | } else { | ||||
940 | Out << Found->second; // Outputs a back reference (an int). | ||||
941 | } | ||||
942 | return; | ||||
943 | } | ||||
944 | |||||
945 | switch (Name.getNameKind()) { | ||||
946 | case DeclarationName::Identifier: { | ||||
947 | if (const IdentifierInfo *II = Name.getAsIdentifierInfo()) { | ||||
948 | mangleSourceName(II->getName()); | ||||
949 | break; | ||||
950 | } | ||||
951 | |||||
952 | // Otherwise, an anonymous entity. We must have a declaration. | ||||
953 | assert(ND && "mangling empty name without declaration")((ND && "mangling empty name without declaration") ? static_cast <void> (0) : __assert_fail ("ND && \"mangling empty name without declaration\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 953, __PRETTY_FUNCTION__)); | ||||
954 | |||||
955 | if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) { | ||||
956 | if (NS->isAnonymousNamespace()) { | ||||
957 | Out << "?A0x" << Context.getAnonymousNamespaceHash() << '@'; | ||||
958 | break; | ||||
959 | } | ||||
960 | } | ||||
961 | |||||
962 | if (const DecompositionDecl *DD = dyn_cast<DecompositionDecl>(ND)) { | ||||
963 | // Decomposition declarations are considered anonymous, and get | ||||
964 | // numbered with a $S prefix. | ||||
965 | llvm::SmallString<64> Name("$S"); | ||||
966 | // Get a unique id for the anonymous struct. | ||||
967 | Name += llvm::utostr(Context.getAnonymousStructId(DD) + 1); | ||||
968 | mangleSourceName(Name); | ||||
969 | break; | ||||
970 | } | ||||
971 | |||||
972 | if (const VarDecl *VD = dyn_cast<VarDecl>(ND)) { | ||||
973 | // We must have an anonymous union or struct declaration. | ||||
974 | const CXXRecordDecl *RD = VD->getType()->getAsCXXRecordDecl(); | ||||
975 | assert(RD && "expected variable decl to have a record type")((RD && "expected variable decl to have a record type" ) ? static_cast<void> (0) : __assert_fail ("RD && \"expected variable decl to have a record type\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 975, __PRETTY_FUNCTION__)); | ||||
976 | // Anonymous types with no tag or typedef get the name of their | ||||
977 | // declarator mangled in. If they have no declarator, number them with | ||||
978 | // a $S prefix. | ||||
979 | llvm::SmallString<64> Name("$S"); | ||||
980 | // Get a unique id for the anonymous struct. | ||||
981 | Name += llvm::utostr(Context.getAnonymousStructId(RD) + 1); | ||||
982 | mangleSourceName(Name.str()); | ||||
983 | break; | ||||
984 | } | ||||
985 | |||||
986 | if (const MSGuidDecl *GD = dyn_cast<MSGuidDecl>(ND)) { | ||||
987 | // Mangle a GUID object as if it were a variable with the corresponding | ||||
988 | // mangled name. | ||||
989 | SmallString<sizeof("_GUID_12345678_1234_1234_1234_1234567890ab")> GUID; | ||||
990 | llvm::raw_svector_ostream GUIDOS(GUID); | ||||
991 | Context.mangleMSGuidDecl(GD, GUIDOS); | ||||
992 | mangleSourceName(GUID); | ||||
993 | break; | ||||
994 | } | ||||
995 | |||||
996 | if (const auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) { | ||||
997 | Out << "?__N"; | ||||
998 | mangleTemplateArgValue(TPO->getType().getUnqualifiedType(), | ||||
999 | TPO->getValue()); | ||||
1000 | break; | ||||
1001 | } | ||||
1002 | |||||
1003 | // We must have an anonymous struct. | ||||
1004 | const TagDecl *TD = cast<TagDecl>(ND); | ||||
1005 | if (const TypedefNameDecl *D = TD->getTypedefNameForAnonDecl()) { | ||||
1006 | assert(TD->getDeclContext() == D->getDeclContext() &&((TD->getDeclContext() == D->getDeclContext() && "Typedef should not be in another decl context!") ? static_cast <void> (0) : __assert_fail ("TD->getDeclContext() == D->getDeclContext() && \"Typedef should not be in another decl context!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 1007, __PRETTY_FUNCTION__)) | ||||
1007 | "Typedef should not be in another decl context!")((TD->getDeclContext() == D->getDeclContext() && "Typedef should not be in another decl context!") ? static_cast <void> (0) : __assert_fail ("TD->getDeclContext() == D->getDeclContext() && \"Typedef should not be in another decl context!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 1007, __PRETTY_FUNCTION__)); | ||||
1008 | assert(D->getDeclName().getAsIdentifierInfo() &&((D->getDeclName().getAsIdentifierInfo() && "Typedef was not named!" ) ? static_cast<void> (0) : __assert_fail ("D->getDeclName().getAsIdentifierInfo() && \"Typedef was not named!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 1009, __PRETTY_FUNCTION__)) | ||||
1009 | "Typedef was not named!")((D->getDeclName().getAsIdentifierInfo() && "Typedef was not named!" ) ? static_cast<void> (0) : __assert_fail ("D->getDeclName().getAsIdentifierInfo() && \"Typedef was not named!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 1009, __PRETTY_FUNCTION__)); | ||||
1010 | mangleSourceName(D->getDeclName().getAsIdentifierInfo()->getName()); | ||||
1011 | break; | ||||
1012 | } | ||||
1013 | |||||
1014 | if (const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(TD)) { | ||||
1015 | if (Record->isLambda()) { | ||||
1016 | llvm::SmallString<10> Name("<lambda_"); | ||||
1017 | |||||
1018 | Decl *LambdaContextDecl = Record->getLambdaContextDecl(); | ||||
1019 | unsigned LambdaManglingNumber = Record->getLambdaManglingNumber(); | ||||
1020 | unsigned LambdaId; | ||||
1021 | const ParmVarDecl *Parm = | ||||
1022 | dyn_cast_or_null<ParmVarDecl>(LambdaContextDecl); | ||||
1023 | const FunctionDecl *Func = | ||||
1024 | Parm ? dyn_cast<FunctionDecl>(Parm->getDeclContext()) : nullptr; | ||||
1025 | |||||
1026 | if (Func) { | ||||
1027 | unsigned DefaultArgNo = | ||||
1028 | Func->getNumParams() - Parm->getFunctionScopeIndex(); | ||||
1029 | Name += llvm::utostr(DefaultArgNo); | ||||
1030 | Name += "_"; | ||||
1031 | } | ||||
1032 | |||||
1033 | if (LambdaManglingNumber) | ||||
1034 | LambdaId = LambdaManglingNumber; | ||||
1035 | else | ||||
1036 | LambdaId = Context.getLambdaId(Record); | ||||
1037 | |||||
1038 | Name += llvm::utostr(LambdaId); | ||||
1039 | Name += ">"; | ||||
1040 | |||||
1041 | mangleSourceName(Name); | ||||
1042 | |||||
1043 | // If the context is a variable or a class member and not a parameter, | ||||
1044 | // it is encoded in a qualified name. | ||||
1045 | if (LambdaManglingNumber && LambdaContextDecl) { | ||||
1046 | if ((isa<VarDecl>(LambdaContextDecl) || | ||||
1047 | isa<FieldDecl>(LambdaContextDecl)) && | ||||
1048 | !isa<ParmVarDecl>(LambdaContextDecl)) { | ||||
1049 | mangleUnqualifiedName(cast<NamedDecl>(LambdaContextDecl)); | ||||
1050 | } | ||||
1051 | } | ||||
1052 | break; | ||||
1053 | } | ||||
1054 | } | ||||
1055 | |||||
1056 | llvm::SmallString<64> Name; | ||||
1057 | if (DeclaratorDecl *DD = | ||||
1058 | Context.getASTContext().getDeclaratorForUnnamedTagDecl(TD)) { | ||||
1059 | // Anonymous types without a name for linkage purposes have their | ||||
1060 | // declarator mangled in if they have one. | ||||
1061 | Name += "<unnamed-type-"; | ||||
1062 | Name += DD->getName(); | ||||
1063 | } else if (TypedefNameDecl *TND = | ||||
1064 | Context.getASTContext().getTypedefNameForUnnamedTagDecl( | ||||
1065 | TD)) { | ||||
1066 | // Anonymous types without a name for linkage purposes have their | ||||
1067 | // associate typedef mangled in if they have one. | ||||
1068 | Name += "<unnamed-type-"; | ||||
1069 | Name += TND->getName(); | ||||
1070 | } else if (isa<EnumDecl>(TD) && | ||||
1071 | cast<EnumDecl>(TD)->enumerator_begin() != | ||||
1072 | cast<EnumDecl>(TD)->enumerator_end()) { | ||||
1073 | // Anonymous non-empty enums mangle in the first enumerator. | ||||
1074 | auto *ED = cast<EnumDecl>(TD); | ||||
1075 | Name += "<unnamed-enum-"; | ||||
1076 | Name += ED->enumerator_begin()->getName(); | ||||
1077 | } else { | ||||
1078 | // Otherwise, number the types using a $S prefix. | ||||
1079 | Name += "<unnamed-type-$S"; | ||||
1080 | Name += llvm::utostr(Context.getAnonymousStructId(TD) + 1); | ||||
1081 | } | ||||
1082 | Name += ">"; | ||||
1083 | mangleSourceName(Name.str()); | ||||
1084 | break; | ||||
1085 | } | ||||
1086 | |||||
1087 | case DeclarationName::ObjCZeroArgSelector: | ||||
1088 | case DeclarationName::ObjCOneArgSelector: | ||||
1089 | case DeclarationName::ObjCMultiArgSelector: { | ||||
1090 | // This is reachable only when constructing an outlined SEH finally | ||||
1091 | // block. Nothing depends on this mangling and it's used only with | ||||
1092 | // functinos with internal linkage. | ||||
1093 | llvm::SmallString<64> Name; | ||||
1094 | mangleSourceName(Name.str()); | ||||
1095 | break; | ||||
1096 | } | ||||
1097 | |||||
1098 | case DeclarationName::CXXConstructorName: | ||||
1099 | if (isStructorDecl(ND)) { | ||||
1100 | if (StructorType == Ctor_CopyingClosure) { | ||||
1101 | Out << "?_O"; | ||||
1102 | return; | ||||
1103 | } | ||||
1104 | if (StructorType == Ctor_DefaultClosure) { | ||||
1105 | Out << "?_F"; | ||||
1106 | return; | ||||
1107 | } | ||||
1108 | } | ||||
1109 | Out << "?0"; | ||||
1110 | return; | ||||
1111 | |||||
1112 | case DeclarationName::CXXDestructorName: | ||||
1113 | if (isStructorDecl(ND)) | ||||
1114 | // If the named decl is the C++ destructor we're mangling, | ||||
1115 | // use the type we were given. | ||||
1116 | mangleCXXDtorType(static_cast<CXXDtorType>(StructorType)); | ||||
1117 | else | ||||
1118 | // Otherwise, use the base destructor name. This is relevant if a | ||||
1119 | // class with a destructor is declared within a destructor. | ||||
1120 | mangleCXXDtorType(Dtor_Base); | ||||
1121 | break; | ||||
1122 | |||||
1123 | case DeclarationName::CXXConversionFunctionName: | ||||
1124 | // <operator-name> ::= ?B # (cast) | ||||
1125 | // The target type is encoded as the return type. | ||||
1126 | Out << "?B"; | ||||
1127 | break; | ||||
1128 | |||||
1129 | case DeclarationName::CXXOperatorName: | ||||
1130 | mangleOperatorName(Name.getCXXOverloadedOperator(), ND->getLocation()); | ||||
1131 | break; | ||||
1132 | |||||
1133 | case DeclarationName::CXXLiteralOperatorName: { | ||||
1134 | Out << "?__K"; | ||||
1135 | mangleSourceName(Name.getCXXLiteralIdentifier()->getName()); | ||||
1136 | break; | ||||
1137 | } | ||||
1138 | |||||
1139 | case DeclarationName::CXXDeductionGuideName: | ||||
1140 | llvm_unreachable("Can't mangle a deduction guide name!")::llvm::llvm_unreachable_internal("Can't mangle a deduction guide name!" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 1140); | ||||
1141 | |||||
1142 | case DeclarationName::CXXUsingDirective: | ||||
1143 | llvm_unreachable("Can't mangle a using directive name!")::llvm::llvm_unreachable_internal("Can't mangle a using directive name!" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 1143); | ||||
1144 | } | ||||
1145 | } | ||||
1146 | |||||
1147 | // <postfix> ::= <unqualified-name> [<postfix>] | ||||
1148 | // ::= <substitution> [<postfix>] | ||||
1149 | void MicrosoftCXXNameMangler::mangleNestedName(const NamedDecl *ND) { | ||||
1150 | const DeclContext *DC = getEffectiveDeclContext(ND); | ||||
1151 | while (!DC->isTranslationUnit()) { | ||||
1152 | if (isa<TagDecl>(ND) || isa<VarDecl>(ND)) { | ||||
1153 | unsigned Disc; | ||||
1154 | if (Context.getNextDiscriminator(ND, Disc)) { | ||||
1155 | Out << '?'; | ||||
1156 | mangleNumber(Disc); | ||||
1157 | Out << '?'; | ||||
1158 | } | ||||
1159 | } | ||||
1160 | |||||
1161 | if (const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) { | ||||
1162 | auto Discriminate = | ||||
1163 | [](StringRef Name, const unsigned Discriminator, | ||||
1164 | const unsigned ParameterDiscriminator) -> std::string { | ||||
1165 | std::string Buffer; | ||||
1166 | llvm::raw_string_ostream Stream(Buffer); | ||||
1167 | Stream << Name; | ||||
1168 | if (Discriminator) | ||||
1169 | Stream << '_' << Discriminator; | ||||
1170 | if (ParameterDiscriminator) | ||||
1171 | Stream << '_' << ParameterDiscriminator; | ||||
1172 | return Stream.str(); | ||||
1173 | }; | ||||
1174 | |||||
1175 | unsigned Discriminator = BD->getBlockManglingNumber(); | ||||
1176 | if (!Discriminator) | ||||
1177 | Discriminator = Context.getBlockId(BD, /*Local=*/false); | ||||
1178 | |||||
1179 | // Mangle the parameter position as a discriminator to deal with unnamed | ||||
1180 | // parameters. Rather than mangling the unqualified parameter name, | ||||
1181 | // always use the position to give a uniform mangling. | ||||
1182 | unsigned ParameterDiscriminator = 0; | ||||
1183 | if (const auto *MC = BD->getBlockManglingContextDecl()) | ||||
1184 | if (const auto *P = dyn_cast<ParmVarDecl>(MC)) | ||||
1185 | if (const auto *F = dyn_cast<FunctionDecl>(P->getDeclContext())) | ||||
1186 | ParameterDiscriminator = | ||||
1187 | F->getNumParams() - P->getFunctionScopeIndex(); | ||||
1188 | |||||
1189 | DC = getEffectiveDeclContext(BD); | ||||
1190 | |||||
1191 | Out << '?'; | ||||
1192 | mangleSourceName(Discriminate("_block_invoke", Discriminator, | ||||
1193 | ParameterDiscriminator)); | ||||
1194 | // If we have a block mangling context, encode that now. This allows us | ||||
1195 | // to discriminate between named static data initializers in the same | ||||
1196 | // scope. This is handled differently from parameters, which use | ||||
1197 | // positions to discriminate between multiple instances. | ||||
1198 | if (const auto *MC = BD->getBlockManglingContextDecl()) | ||||
1199 | if (!isa<ParmVarDecl>(MC)) | ||||
1200 | if (const auto *ND = dyn_cast<NamedDecl>(MC)) | ||||
1201 | mangleUnqualifiedName(ND); | ||||
1202 | // MS ABI and Itanium manglings are in inverted scopes. In the case of a | ||||
1203 | // RecordDecl, mangle the entire scope hierarchy at this point rather than | ||||
1204 | // just the unqualified name to get the ordering correct. | ||||
1205 | if (const auto *RD = dyn_cast<RecordDecl>(DC)) | ||||
1206 | mangleName(RD); | ||||
1207 | else | ||||
1208 | Out << '@'; | ||||
1209 | // void __cdecl | ||||
1210 | Out << "YAX"; | ||||
1211 | // struct __block_literal * | ||||
1212 | Out << 'P'; | ||||
1213 | // __ptr64 | ||||
1214 | if (PointersAre64Bit) | ||||
1215 | Out << 'E'; | ||||
1216 | Out << 'A'; | ||||
1217 | mangleArtificialTagType(TTK_Struct, | ||||
1218 | Discriminate("__block_literal", Discriminator, | ||||
1219 | ParameterDiscriminator)); | ||||
1220 | Out << "@Z"; | ||||
1221 | |||||
1222 | // If the effective context was a Record, we have fully mangled the | ||||
1223 | // qualified name and do not need to continue. | ||||
1224 | if (isa<RecordDecl>(DC)) | ||||
1225 | break; | ||||
1226 | continue; | ||||
1227 | } else if (const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(DC)) { | ||||
1228 | mangleObjCMethodName(Method); | ||||
1229 | } else if (isa<NamedDecl>(DC)) { | ||||
1230 | ND = cast<NamedDecl>(DC); | ||||
1231 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) { | ||||
1232 | mangle(FD, "?"); | ||||
1233 | break; | ||||
1234 | } else { | ||||
1235 | mangleUnqualifiedName(ND); | ||||
1236 | // Lambdas in default arguments conceptually belong to the function the | ||||
1237 | // parameter corresponds to. | ||||
1238 | if (const auto *LDADC = getLambdaDefaultArgumentDeclContext(ND)) { | ||||
1239 | DC = LDADC; | ||||
1240 | continue; | ||||
1241 | } | ||||
1242 | } | ||||
1243 | } | ||||
1244 | DC = DC->getParent(); | ||||
1245 | } | ||||
1246 | } | ||||
1247 | |||||
1248 | void MicrosoftCXXNameMangler::mangleCXXDtorType(CXXDtorType T) { | ||||
1249 | // Microsoft uses the names on the case labels for these dtor variants. Clang | ||||
1250 | // uses the Itanium terminology internally. Everything in this ABI delegates | ||||
1251 | // towards the base dtor. | ||||
1252 | switch (T) { | ||||
1253 | // <operator-name> ::= ?1 # destructor | ||||
1254 | case Dtor_Base: Out << "?1"; return; | ||||
1255 | // <operator-name> ::= ?_D # vbase destructor | ||||
1256 | case Dtor_Complete: Out << "?_D"; return; | ||||
1257 | // <operator-name> ::= ?_G # scalar deleting destructor | ||||
1258 | case Dtor_Deleting: Out << "?_G"; return; | ||||
1259 | // <operator-name> ::= ?_E # vector deleting destructor | ||||
1260 | // FIXME: Add a vector deleting dtor type. It goes in the vtable, so we need | ||||
1261 | // it. | ||||
1262 | case Dtor_Comdat: | ||||
1263 | llvm_unreachable("not expecting a COMDAT")::llvm::llvm_unreachable_internal("not expecting a COMDAT", "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 1263); | ||||
1264 | } | ||||
1265 | llvm_unreachable("Unsupported dtor type?")::llvm::llvm_unreachable_internal("Unsupported dtor type?", "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 1265); | ||||
1266 | } | ||||
1267 | |||||
1268 | void MicrosoftCXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO, | ||||
1269 | SourceLocation Loc) { | ||||
1270 | switch (OO) { | ||||
1271 | // ?0 # constructor | ||||
1272 | // ?1 # destructor | ||||
1273 | // <operator-name> ::= ?2 # new | ||||
1274 | case OO_New: Out << "?2"; break; | ||||
1275 | // <operator-name> ::= ?3 # delete | ||||
1276 | case OO_Delete: Out << "?3"; break; | ||||
1277 | // <operator-name> ::= ?4 # = | ||||
1278 | case OO_Equal: Out << "?4"; break; | ||||
1279 | // <operator-name> ::= ?5 # >> | ||||
1280 | case OO_GreaterGreater: Out << "?5"; break; | ||||
1281 | // <operator-name> ::= ?6 # << | ||||
1282 | case OO_LessLess: Out << "?6"; break; | ||||
1283 | // <operator-name> ::= ?7 # ! | ||||
1284 | case OO_Exclaim: Out << "?7"; break; | ||||
1285 | // <operator-name> ::= ?8 # == | ||||
1286 | case OO_EqualEqual: Out << "?8"; break; | ||||
1287 | // <operator-name> ::= ?9 # != | ||||
1288 | case OO_ExclaimEqual: Out << "?9"; break; | ||||
1289 | // <operator-name> ::= ?A # [] | ||||
1290 | case OO_Subscript: Out << "?A"; break; | ||||
1291 | // ?B # conversion | ||||
1292 | // <operator-name> ::= ?C # -> | ||||
1293 | case OO_Arrow: Out << "?C"; break; | ||||
1294 | // <operator-name> ::= ?D # * | ||||
1295 | case OO_Star: Out << "?D"; break; | ||||
1296 | // <operator-name> ::= ?E # ++ | ||||
1297 | case OO_PlusPlus: Out << "?E"; break; | ||||
1298 | // <operator-name> ::= ?F # -- | ||||
1299 | case OO_MinusMinus: Out << "?F"; break; | ||||
1300 | // <operator-name> ::= ?G # - | ||||
1301 | case OO_Minus: Out << "?G"; break; | ||||
1302 | // <operator-name> ::= ?H # + | ||||
1303 | case OO_Plus: Out << "?H"; break; | ||||
1304 | // <operator-name> ::= ?I # & | ||||
1305 | case OO_Amp: Out << "?I"; break; | ||||
1306 | // <operator-name> ::= ?J # ->* | ||||
1307 | case OO_ArrowStar: Out << "?J"; break; | ||||
1308 | // <operator-name> ::= ?K # / | ||||
1309 | case OO_Slash: Out << "?K"; break; | ||||
1310 | // <operator-name> ::= ?L # % | ||||
1311 | case OO_Percent: Out << "?L"; break; | ||||
1312 | // <operator-name> ::= ?M # < | ||||
1313 | case OO_Less: Out << "?M"; break; | ||||
1314 | // <operator-name> ::= ?N # <= | ||||
1315 | case OO_LessEqual: Out << "?N"; break; | ||||
1316 | // <operator-name> ::= ?O # > | ||||
1317 | case OO_Greater: Out << "?O"; break; | ||||
1318 | // <operator-name> ::= ?P # >= | ||||
1319 | case OO_GreaterEqual: Out << "?P"; break; | ||||
1320 | // <operator-name> ::= ?Q # , | ||||
1321 | case OO_Comma: Out << "?Q"; break; | ||||
1322 | // <operator-name> ::= ?R # () | ||||
1323 | case OO_Call: Out << "?R"; break; | ||||
1324 | // <operator-name> ::= ?S # ~ | ||||
1325 | case OO_Tilde: Out << "?S"; break; | ||||
1326 | // <operator-name> ::= ?T # ^ | ||||
1327 | case OO_Caret: Out << "?T"; break; | ||||
1328 | // <operator-name> ::= ?U # | | ||||
1329 | case OO_Pipe: Out << "?U"; break; | ||||
1330 | // <operator-name> ::= ?V # && | ||||
1331 | case OO_AmpAmp: Out << "?V"; break; | ||||
1332 | // <operator-name> ::= ?W # || | ||||
1333 | case OO_PipePipe: Out << "?W"; break; | ||||
1334 | // <operator-name> ::= ?X # *= | ||||
1335 | case OO_StarEqual: Out << "?X"; break; | ||||
1336 | // <operator-name> ::= ?Y # += | ||||
1337 | case OO_PlusEqual: Out << "?Y"; break; | ||||
1338 | // <operator-name> ::= ?Z # -= | ||||
1339 | case OO_MinusEqual: Out << "?Z"; break; | ||||
1340 | // <operator-name> ::= ?_0 # /= | ||||
1341 | case OO_SlashEqual: Out << "?_0"; break; | ||||
1342 | // <operator-name> ::= ?_1 # %= | ||||
1343 | case OO_PercentEqual: Out << "?_1"; break; | ||||
1344 | // <operator-name> ::= ?_2 # >>= | ||||
1345 | case OO_GreaterGreaterEqual: Out << "?_2"; break; | ||||
1346 | // <operator-name> ::= ?_3 # <<= | ||||
1347 | case OO_LessLessEqual: Out << "?_3"; break; | ||||
1348 | // <operator-name> ::= ?_4 # &= | ||||
1349 | case OO_AmpEqual: Out << "?_4"; break; | ||||
1350 | // <operator-name> ::= ?_5 # |= | ||||
1351 | case OO_PipeEqual: Out << "?_5"; break; | ||||
1352 | // <operator-name> ::= ?_6 # ^= | ||||
1353 | case OO_CaretEqual: Out << "?_6"; break; | ||||
1354 | // ?_7 # vftable | ||||
1355 | // ?_8 # vbtable | ||||
1356 | // ?_9 # vcall | ||||
1357 | // ?_A # typeof | ||||
1358 | // ?_B # local static guard | ||||
1359 | // ?_C # string | ||||
1360 | // ?_D # vbase destructor | ||||
1361 | // ?_E # vector deleting destructor | ||||
1362 | // ?_F # default constructor closure | ||||
1363 | // ?_G # scalar deleting destructor | ||||
1364 | // ?_H # vector constructor iterator | ||||
1365 | // ?_I # vector destructor iterator | ||||
1366 | // ?_J # vector vbase constructor iterator | ||||
1367 | // ?_K # virtual displacement map | ||||
1368 | // ?_L # eh vector constructor iterator | ||||
1369 | // ?_M # eh vector destructor iterator | ||||
1370 | // ?_N # eh vector vbase constructor iterator | ||||
1371 | // ?_O # copy constructor closure | ||||
1372 | // ?_P<name> # udt returning <name> | ||||
1373 | // ?_Q # <unknown> | ||||
1374 | // ?_R0 # RTTI Type Descriptor | ||||
1375 | // ?_R1 # RTTI Base Class Descriptor at (a,b,c,d) | ||||
1376 | // ?_R2 # RTTI Base Class Array | ||||
1377 | // ?_R3 # RTTI Class Hierarchy Descriptor | ||||
1378 | // ?_R4 # RTTI Complete Object Locator | ||||
1379 | // ?_S # local vftable | ||||
1380 | // ?_T # local vftable constructor closure | ||||
1381 | // <operator-name> ::= ?_U # new[] | ||||
1382 | case OO_Array_New: Out << "?_U"; break; | ||||
1383 | // <operator-name> ::= ?_V # delete[] | ||||
1384 | case OO_Array_Delete: Out << "?_V"; break; | ||||
1385 | // <operator-name> ::= ?__L # co_await | ||||
1386 | case OO_Coawait: Out << "?__L"; break; | ||||
1387 | // <operator-name> ::= ?__M # <=> | ||||
1388 | case OO_Spaceship: Out << "?__M"; break; | ||||
1389 | |||||
1390 | case OO_Conditional: { | ||||
1391 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
1392 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | ||||
1393 | "cannot mangle this conditional operator yet"); | ||||
1394 | Diags.Report(Loc, DiagID); | ||||
1395 | break; | ||||
1396 | } | ||||
1397 | |||||
1398 | case OO_None: | ||||
1399 | case NUM_OVERLOADED_OPERATORS: | ||||
1400 | llvm_unreachable("Not an overloaded operator")::llvm::llvm_unreachable_internal("Not an overloaded operator" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 1400); | ||||
1401 | } | ||||
1402 | } | ||||
1403 | |||||
1404 | void MicrosoftCXXNameMangler::mangleSourceName(StringRef Name) { | ||||
1405 | // <source name> ::= <identifier> @ | ||||
1406 | BackRefVec::iterator Found = llvm::find(NameBackReferences, Name); | ||||
1407 | if (Found == NameBackReferences.end()) { | ||||
1408 | if (NameBackReferences.size() < 10) | ||||
1409 | NameBackReferences.push_back(std::string(Name)); | ||||
1410 | Out << Name << '@'; | ||||
1411 | } else { | ||||
1412 | Out << (Found - NameBackReferences.begin()); | ||||
1413 | } | ||||
1414 | } | ||||
1415 | |||||
1416 | void MicrosoftCXXNameMangler::mangleObjCMethodName(const ObjCMethodDecl *MD) { | ||||
1417 | Context.mangleObjCMethodNameAsSourceName(MD, Out); | ||||
1418 | } | ||||
1419 | |||||
1420 | void MicrosoftCXXNameMangler::mangleTemplateInstantiationName( | ||||
1421 | const TemplateDecl *TD, const TemplateArgumentList &TemplateArgs) { | ||||
1422 | // <template-name> ::= <unscoped-template-name> <template-args> | ||||
1423 | // ::= <substitution> | ||||
1424 | // Always start with the unqualified name. | ||||
1425 | |||||
1426 | // Templates have their own context for back references. | ||||
1427 | ArgBackRefMap OuterFunArgsContext; | ||||
1428 | ArgBackRefMap OuterTemplateArgsContext; | ||||
1429 | BackRefVec OuterTemplateContext; | ||||
1430 | PassObjectSizeArgsSet OuterPassObjectSizeArgs; | ||||
1431 | NameBackReferences.swap(OuterTemplateContext); | ||||
1432 | FunArgBackReferences.swap(OuterFunArgsContext); | ||||
1433 | TemplateArgBackReferences.swap(OuterTemplateArgsContext); | ||||
1434 | PassObjectSizeArgs.swap(OuterPassObjectSizeArgs); | ||||
1435 | |||||
1436 | mangleUnscopedTemplateName(TD); | ||||
1437 | mangleTemplateArgs(TD, TemplateArgs); | ||||
1438 | |||||
1439 | // Restore the previous back reference contexts. | ||||
1440 | NameBackReferences.swap(OuterTemplateContext); | ||||
1441 | FunArgBackReferences.swap(OuterFunArgsContext); | ||||
1442 | TemplateArgBackReferences.swap(OuterTemplateArgsContext); | ||||
1443 | PassObjectSizeArgs.swap(OuterPassObjectSizeArgs); | ||||
1444 | } | ||||
1445 | |||||
1446 | void | ||||
1447 | MicrosoftCXXNameMangler::mangleUnscopedTemplateName(const TemplateDecl *TD) { | ||||
1448 | // <unscoped-template-name> ::= ?$ <unqualified-name> | ||||
1449 | Out << "?$"; | ||||
1450 | mangleUnqualifiedName(TD); | ||||
1451 | } | ||||
1452 | |||||
1453 | void MicrosoftCXXNameMangler::mangleIntegerLiteral( | ||||
1454 | const llvm::APSInt &Value, const NonTypeTemplateParmDecl *PD, | ||||
1455 | QualType TemplateArgType) { | ||||
1456 | // <integer-literal> ::= $0 <number> | ||||
1457 | Out << "$"; | ||||
1458 | |||||
1459 | // Since MSVC 2019, add 'M[<type>]' after '$' for auto template parameter when | ||||
1460 | // argument is integer. | ||||
1461 | if (getASTContext().getLangOpts().isCompatibleWithMSVC( | ||||
1462 | LangOptions::MSVC2019) && | ||||
1463 | PD && PD->getType()->getTypeClass() == Type::Auto && | ||||
1464 | !TemplateArgType.isNull()) { | ||||
1465 | Out << "M"; | ||||
1466 | mangleType(TemplateArgType, SourceRange(), QMM_Drop); | ||||
1467 | } | ||||
1468 | |||||
1469 | Out << "0"; | ||||
1470 | |||||
1471 | mangleNumber(Value); | ||||
1472 | } | ||||
1473 | |||||
1474 | void MicrosoftCXXNameMangler::mangleExpression( | ||||
1475 | const Expr *E, const NonTypeTemplateParmDecl *PD) { | ||||
1476 | // See if this is a constant expression. | ||||
1477 | if (Optional<llvm::APSInt> Value = | ||||
1478 | E->getIntegerConstantExpr(Context.getASTContext())) { | ||||
1479 | mangleIntegerLiteral(*Value, PD, E->getType()); | ||||
1480 | return; | ||||
1481 | } | ||||
1482 | |||||
1483 | // As bad as this diagnostic is, it's better than crashing. | ||||
1484 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
1485 | unsigned DiagID = Diags.getCustomDiagID( | ||||
1486 | DiagnosticsEngine::Error, "cannot yet mangle expression type %0"); | ||||
1487 | Diags.Report(E->getExprLoc(), DiagID) << E->getStmtClassName() | ||||
1488 | << E->getSourceRange(); | ||||
1489 | } | ||||
1490 | |||||
1491 | void MicrosoftCXXNameMangler::mangleTemplateArgs( | ||||
1492 | const TemplateDecl *TD, const TemplateArgumentList &TemplateArgs) { | ||||
1493 | // <template-args> ::= <template-arg>+ | ||||
1494 | const TemplateParameterList *TPL = TD->getTemplateParameters(); | ||||
1495 | assert(TPL->size() == TemplateArgs.size() &&((TPL->size() == TemplateArgs.size() && "size mismatch between args and parms!" ) ? static_cast<void> (0) : __assert_fail ("TPL->size() == TemplateArgs.size() && \"size mismatch between args and parms!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 1496, __PRETTY_FUNCTION__)) | ||||
1496 | "size mismatch between args and parms!")((TPL->size() == TemplateArgs.size() && "size mismatch between args and parms!" ) ? static_cast<void> (0) : __assert_fail ("TPL->size() == TemplateArgs.size() && \"size mismatch between args and parms!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 1496, __PRETTY_FUNCTION__)); | ||||
1497 | |||||
1498 | for (size_t i = 0; i < TemplateArgs.size(); ++i) { | ||||
1499 | const TemplateArgument &TA = TemplateArgs[i]; | ||||
1500 | |||||
1501 | // Separate consecutive packs by $$Z. | ||||
1502 | if (i > 0 && TA.getKind() == TemplateArgument::Pack && | ||||
1503 | TemplateArgs[i - 1].getKind() == TemplateArgument::Pack) | ||||
1504 | Out << "$$Z"; | ||||
1505 | |||||
1506 | mangleTemplateArg(TD, TA, TPL->getParam(i)); | ||||
1507 | } | ||||
1508 | } | ||||
1509 | |||||
1510 | void MicrosoftCXXNameMangler::mangleTemplateArg(const TemplateDecl *TD, | ||||
1511 | const TemplateArgument &TA, | ||||
1512 | const NamedDecl *Parm) { | ||||
1513 | // <template-arg> ::= <type> | ||||
1514 | // ::= <integer-literal> | ||||
1515 | // ::= <member-data-pointer> | ||||
1516 | // ::= <member-function-pointer> | ||||
1517 | // ::= $ <constant-value> | ||||
1518 | // ::= <template-args> | ||||
1519 | // | ||||
1520 | // <constant-value> ::= 0 <number> # integer | ||||
1521 | // ::= 1 <mangled-name> # address of D | ||||
1522 | // ::= 2 <type> <typed-constant-value>* @ # struct | ||||
1523 | // ::= 3 <type> <constant-value>* @ # array | ||||
1524 | // ::= 4 ??? # string | ||||
1525 | // ::= 5 <constant-value> @ # address of subobject | ||||
1526 | // ::= 6 <constant-value> <unqualified-name> @ # a.b | ||||
1527 | // ::= 7 <type> [<unqualified-name> <constant-value>] @ | ||||
1528 | // # union, with or without an active member | ||||
1529 | // # pointer to member, symbolically | ||||
1530 | // ::= 8 <class> <unqualified-name> @ | ||||
1531 | // ::= A <type> <non-negative integer> # float | ||||
1532 | // ::= B <type> <non-negative integer> # double | ||||
1533 | // ::= E <mangled-name> # reference to D | ||||
1534 | // # pointer to member, by component value | ||||
1535 | // ::= F <number> <number> | ||||
1536 | // ::= G <number> <number> <number> | ||||
1537 | // ::= H <mangled-name> <number> | ||||
1538 | // ::= I <mangled-name> <number> <number> | ||||
1539 | // ::= J <mangled-name> <number> <number> <number> | ||||
1540 | // | ||||
1541 | // <typed-constant-value> ::= [<type>] <constant-value> | ||||
1542 | // | ||||
1543 | // The <type> appears to be included in a <typed-constant-value> only in the | ||||
1544 | // '0', '1', '8', 'A', 'B', and 'E' cases. | ||||
1545 | |||||
1546 | switch (TA.getKind()) { | ||||
1547 | case TemplateArgument::Null: | ||||
1548 | llvm_unreachable("Can't mangle null template arguments!")::llvm::llvm_unreachable_internal("Can't mangle null template arguments!" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 1548); | ||||
1549 | case TemplateArgument::TemplateExpansion: | ||||
1550 | llvm_unreachable("Can't mangle template expansion arguments!")::llvm::llvm_unreachable_internal("Can't mangle template expansion arguments!" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 1550); | ||||
1551 | case TemplateArgument::Type: { | ||||
1552 | QualType T = TA.getAsType(); | ||||
1553 | mangleType(T, SourceRange(), QMM_Escape); | ||||
1554 | break; | ||||
1555 | } | ||||
1556 | case TemplateArgument::Declaration: { | ||||
1557 | const NamedDecl *ND = TA.getAsDecl(); | ||||
1558 | if (isa<FieldDecl>(ND) || isa<IndirectFieldDecl>(ND)) { | ||||
1559 | mangleMemberDataPointer(cast<CXXRecordDecl>(ND->getDeclContext()) | ||||
1560 | ->getMostRecentNonInjectedDecl(), | ||||
1561 | cast<ValueDecl>(ND)); | ||||
1562 | } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) { | ||||
1563 | const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD); | ||||
1564 | if (MD && MD->isInstance()) { | ||||
1565 | mangleMemberFunctionPointer( | ||||
1566 | MD->getParent()->getMostRecentNonInjectedDecl(), MD); | ||||
1567 | } else { | ||||
1568 | Out << "$1?"; | ||||
1569 | mangleName(FD); | ||||
1570 | mangleFunctionEncoding(FD, /*ShouldMangle=*/true); | ||||
1571 | } | ||||
1572 | } else if (TA.getParamTypeForDecl()->isRecordType()) { | ||||
1573 | Out << "$"; | ||||
1574 | auto *TPO = cast<TemplateParamObjectDecl>(ND); | ||||
1575 | mangleTemplateArgValue(TPO->getType().getUnqualifiedType(), | ||||
1576 | TPO->getValue()); | ||||
1577 | } else { | ||||
1578 | mangle(ND, TA.getParamTypeForDecl()->isReferenceType() ? "$E?" : "$1?"); | ||||
1579 | } | ||||
1580 | break; | ||||
1581 | } | ||||
1582 | case TemplateArgument::Integral: { | ||||
1583 | QualType T = TA.getIntegralType(); | ||||
1584 | mangleIntegerLiteral(TA.getAsIntegral(), | ||||
1585 | cast<NonTypeTemplateParmDecl>(Parm), T); | ||||
1586 | break; | ||||
1587 | } | ||||
1588 | case TemplateArgument::NullPtr: { | ||||
1589 | QualType T = TA.getNullPtrType(); | ||||
1590 | if (const MemberPointerType *MPT = T->getAs<MemberPointerType>()) { | ||||
1591 | const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl(); | ||||
1592 | if (MPT->isMemberFunctionPointerType() && | ||||
1593 | !isa<FunctionTemplateDecl>(TD)) { | ||||
1594 | mangleMemberFunctionPointer(RD, nullptr); | ||||
1595 | return; | ||||
1596 | } | ||||
1597 | if (MPT->isMemberDataPointer()) { | ||||
1598 | if (!isa<FunctionTemplateDecl>(TD)) { | ||||
1599 | mangleMemberDataPointer(RD, nullptr); | ||||
1600 | return; | ||||
1601 | } | ||||
1602 | // nullptr data pointers are always represented with a single field | ||||
1603 | // which is initialized with either 0 or -1. Why -1? Well, we need to | ||||
1604 | // distinguish the case where the data member is at offset zero in the | ||||
1605 | // record. | ||||
1606 | // However, we are free to use 0 *if* we would use multiple fields for | ||||
1607 | // non-nullptr member pointers. | ||||
1608 | if (!RD->nullFieldOffsetIsZero()) { | ||||
1609 | mangleIntegerLiteral(llvm::APSInt::get(-1), | ||||
1610 | cast<NonTypeTemplateParmDecl>(Parm), T); | ||||
1611 | return; | ||||
1612 | } | ||||
1613 | } | ||||
1614 | } | ||||
1615 | mangleIntegerLiteral(llvm::APSInt::getUnsigned(0), | ||||
1616 | cast<NonTypeTemplateParmDecl>(Parm), T); | ||||
1617 | break; | ||||
1618 | } | ||||
1619 | case TemplateArgument::Expression: | ||||
1620 | mangleExpression(TA.getAsExpr(), cast<NonTypeTemplateParmDecl>(Parm)); | ||||
1621 | break; | ||||
1622 | case TemplateArgument::Pack: { | ||||
1623 | ArrayRef<TemplateArgument> TemplateArgs = TA.getPackAsArray(); | ||||
1624 | if (TemplateArgs.empty()) { | ||||
1625 | if (isa<TemplateTypeParmDecl>(Parm) || | ||||
1626 | isa<TemplateTemplateParmDecl>(Parm)) | ||||
1627 | // MSVC 2015 changed the mangling for empty expanded template packs, | ||||
1628 | // use the old mangling for link compatibility for old versions. | ||||
1629 | Out << (Context.getASTContext().getLangOpts().isCompatibleWithMSVC( | ||||
1630 | LangOptions::MSVC2015) | ||||
1631 | ? "$$V" | ||||
1632 | : "$$$V"); | ||||
1633 | else if (isa<NonTypeTemplateParmDecl>(Parm)) | ||||
1634 | Out << "$S"; | ||||
1635 | else | ||||
1636 | llvm_unreachable("unexpected template parameter decl!")::llvm::llvm_unreachable_internal("unexpected template parameter decl!" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 1636); | ||||
1637 | } else { | ||||
1638 | for (const TemplateArgument &PA : TemplateArgs) | ||||
1639 | mangleTemplateArg(TD, PA, Parm); | ||||
1640 | } | ||||
1641 | break; | ||||
1642 | } | ||||
1643 | case TemplateArgument::Template: { | ||||
1644 | const NamedDecl *ND = | ||||
1645 | TA.getAsTemplate().getAsTemplateDecl()->getTemplatedDecl(); | ||||
1646 | if (const auto *TD = dyn_cast<TagDecl>(ND)) { | ||||
1647 | mangleType(TD); | ||||
1648 | } else if (isa<TypeAliasDecl>(ND)) { | ||||
1649 | Out << "$$Y"; | ||||
1650 | mangleName(ND); | ||||
1651 | } else { | ||||
1652 | llvm_unreachable("unexpected template template NamedDecl!")::llvm::llvm_unreachable_internal("unexpected template template NamedDecl!" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 1652); | ||||
1653 | } | ||||
1654 | break; | ||||
1655 | } | ||||
1656 | } | ||||
1657 | } | ||||
1658 | |||||
1659 | void MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T, | ||||
1660 | const APValue &V, | ||||
1661 | bool WithScalarType) { | ||||
1662 | switch (V.getKind()) { | ||||
1663 | case APValue::None: | ||||
1664 | case APValue::Indeterminate: | ||||
1665 | // FIXME: MSVC doesn't allow this, so we can't be sure how it should be | ||||
1666 | // mangled. | ||||
1667 | if (WithScalarType) | ||||
1668 | mangleType(T, SourceRange(), QMM_Escape); | ||||
1669 | Out << '@'; | ||||
1670 | return; | ||||
1671 | |||||
1672 | case APValue::Int: | ||||
1673 | if (WithScalarType) | ||||
1674 | mangleType(T, SourceRange(), QMM_Escape); | ||||
1675 | Out << '0'; | ||||
1676 | mangleNumber(V.getInt()); | ||||
1677 | return; | ||||
1678 | |||||
1679 | case APValue::Float: | ||||
1680 | if (WithScalarType) | ||||
1681 | mangleType(T, SourceRange(), QMM_Escape); | ||||
1682 | mangleFloat(V.getFloat()); | ||||
1683 | return; | ||||
1684 | |||||
1685 | case APValue::LValue: { | ||||
1686 | if (WithScalarType) | ||||
1687 | mangleType(T, SourceRange(), QMM_Escape); | ||||
1688 | |||||
1689 | // We don't know how to mangle past-the-end pointers yet. | ||||
1690 | if (V.isLValueOnePastTheEnd()) | ||||
1691 | break; | ||||
1692 | |||||
1693 | APValue::LValueBase Base = V.getLValueBase(); | ||||
1694 | if (!V.hasLValuePath() || V.getLValuePath().empty()) { | ||||
1695 | // Taking the address of a complete object has a special-case mangling. | ||||
1696 | if (Base.isNull()) { | ||||
1697 | // MSVC emits 0A@ for null pointers. Generalize this for arbitrary | ||||
1698 | // integers cast to pointers. | ||||
1699 | // FIXME: This mangles 0 cast to a pointer the same as a null pointer, | ||||
1700 | // even in cases where the two are different values. | ||||
1701 | Out << "0"; | ||||
1702 | mangleNumber(V.getLValueOffset().getQuantity()); | ||||
1703 | } else if (!V.hasLValuePath()) { | ||||
1704 | // FIXME: This can only happen as an extension. Invent a mangling. | ||||
1705 | break; | ||||
1706 | } else if (auto *VD = Base.dyn_cast<const ValueDecl*>()) { | ||||
1707 | Out << (T->isReferenceType() ? "E" : "1"); | ||||
1708 | mangle(VD); | ||||
1709 | } else { | ||||
1710 | break; | ||||
1711 | } | ||||
1712 | } else { | ||||
1713 | unsigned NumAts = 0; | ||||
1714 | if (T->isPointerType()) { | ||||
1715 | Out << "5"; | ||||
1716 | ++NumAts; | ||||
1717 | } | ||||
1718 | |||||
1719 | QualType T = Base.getType(); | ||||
1720 | for (APValue::LValuePathEntry E : V.getLValuePath()) { | ||||
1721 | // We don't know how to mangle array subscripting yet. | ||||
1722 | if (T->isArrayType()) | ||||
1723 | goto mangling_unknown; | ||||
1724 | |||||
1725 | const Decl *D = E.getAsBaseOrMember().getPointer(); | ||||
1726 | auto *FD = dyn_cast<FieldDecl>(D); | ||||
1727 | // We don't know how to mangle derived-to-base conversions yet. | ||||
1728 | if (!FD) | ||||
1729 | goto mangling_unknown; | ||||
1730 | |||||
1731 | Out << "6"; | ||||
1732 | ++NumAts; | ||||
1733 | T = FD->getType(); | ||||
1734 | } | ||||
1735 | |||||
1736 | auto *VD = Base.dyn_cast<const ValueDecl*>(); | ||||
1737 | if (!VD) | ||||
1738 | break; | ||||
1739 | Out << "E"; | ||||
1740 | mangle(VD); | ||||
1741 | |||||
1742 | for (APValue::LValuePathEntry E : V.getLValuePath()) { | ||||
1743 | const Decl *D = E.getAsBaseOrMember().getPointer(); | ||||
1744 | mangleUnqualifiedName(cast<FieldDecl>(D)); | ||||
1745 | } | ||||
1746 | for (unsigned I = 0; I != NumAts; ++I) | ||||
1747 | Out << '@'; | ||||
1748 | } | ||||
1749 | |||||
1750 | return; | ||||
1751 | } | ||||
1752 | |||||
1753 | case APValue::MemberPointer: { | ||||
1754 | if (WithScalarType) | ||||
1755 | mangleType(T, SourceRange(), QMM_Escape); | ||||
1756 | |||||
1757 | // FIXME: The below manglings don't include a conversion, so bail if there | ||||
1758 | // would be one. MSVC mangles the (possibly converted) value of the | ||||
1759 | // pointer-to-member object as if it were a struct, leading to collisions | ||||
1760 | // in some cases. | ||||
1761 | if (!V.getMemberPointerPath().empty()) | ||||
1762 | break; | ||||
1763 | |||||
1764 | const CXXRecordDecl *RD = | ||||
1765 | T->castAs<MemberPointerType>()->getMostRecentCXXRecordDecl(); | ||||
1766 | const ValueDecl *D = V.getMemberPointerDecl(); | ||||
1767 | if (T->isMemberDataPointerType()) | ||||
1768 | mangleMemberDataPointer(RD, D, ""); | ||||
1769 | else | ||||
1770 | mangleMemberFunctionPointer(RD, cast_or_null<CXXMethodDecl>(D), ""); | ||||
1771 | return; | ||||
1772 | } | ||||
1773 | |||||
1774 | case APValue::Struct: { | ||||
1775 | Out << '2'; | ||||
1776 | mangleType(T, SourceRange(), QMM_Escape); | ||||
1777 | const CXXRecordDecl *RD = T->getAsCXXRecordDecl(); | ||||
1778 | assert(RD && "unexpected type for record value")((RD && "unexpected type for record value") ? static_cast <void> (0) : __assert_fail ("RD && \"unexpected type for record value\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 1778, __PRETTY_FUNCTION__)); | ||||
1779 | |||||
1780 | unsigned BaseIndex = 0; | ||||
1781 | for (const CXXBaseSpecifier &B : RD->bases()) | ||||
1782 | mangleTemplateArgValue(B.getType(), V.getStructBase(BaseIndex++)); | ||||
1783 | for (const FieldDecl *FD : RD->fields()) | ||||
1784 | if (!FD->isUnnamedBitfield()) | ||||
1785 | mangleTemplateArgValue(FD->getType(), | ||||
1786 | V.getStructField(FD->getFieldIndex()), | ||||
1787 | /*WithScalarType*/ true); | ||||
1788 | Out << '@'; | ||||
1789 | return; | ||||
1790 | } | ||||
1791 | |||||
1792 | case APValue::Union: | ||||
1793 | Out << '7'; | ||||
1794 | mangleType(T, SourceRange(), QMM_Escape); | ||||
1795 | if (const FieldDecl *FD = V.getUnionField()) { | ||||
1796 | mangleUnqualifiedName(FD); | ||||
1797 | mangleTemplateArgValue(FD->getType(), V.getUnionValue()); | ||||
1798 | } | ||||
1799 | Out << '@'; | ||||
1800 | return; | ||||
1801 | |||||
1802 | case APValue::ComplexInt: | ||||
1803 | // We mangle complex types as structs, so mangle the value as a struct too. | ||||
1804 | Out << '2'; | ||||
1805 | mangleType(T, SourceRange(), QMM_Escape); | ||||
1806 | Out << '0'; | ||||
1807 | mangleNumber(V.getComplexIntReal()); | ||||
1808 | Out << '0'; | ||||
1809 | mangleNumber(V.getComplexIntImag()); | ||||
1810 | Out << '@'; | ||||
1811 | return; | ||||
1812 | |||||
1813 | case APValue::ComplexFloat: | ||||
1814 | Out << '2'; | ||||
1815 | mangleType(T, SourceRange(), QMM_Escape); | ||||
1816 | mangleFloat(V.getComplexFloatReal()); | ||||
1817 | mangleFloat(V.getComplexFloatImag()); | ||||
1818 | Out << '@'; | ||||
1819 | return; | ||||
1820 | |||||
1821 | case APValue::Array: { | ||||
1822 | Out << '3'; | ||||
1823 | QualType ElemT = getASTContext().getAsArrayType(T)->getElementType(); | ||||
1824 | mangleType(ElemT, SourceRange(), QMM_Escape); | ||||
1825 | for (unsigned I = 0, N = V.getArraySize(); I != N; ++I) { | ||||
1826 | const APValue &ElemV = I < V.getArrayInitializedElts() | ||||
1827 | ? V.getArrayInitializedElt(I) | ||||
1828 | : V.getArrayFiller(); | ||||
1829 | mangleTemplateArgValue(ElemT, ElemV); | ||||
1830 | Out << '@'; | ||||
1831 | } | ||||
1832 | Out << '@'; | ||||
1833 | return; | ||||
1834 | } | ||||
1835 | |||||
1836 | case APValue::Vector: { | ||||
1837 | // __m128 is mangled as a struct containing an array. We follow this | ||||
1838 | // approach for all vector types. | ||||
1839 | Out << '2'; | ||||
1840 | mangleType(T, SourceRange(), QMM_Escape); | ||||
1841 | Out << '3'; | ||||
1842 | QualType ElemT = T->castAs<VectorType>()->getElementType(); | ||||
1843 | mangleType(ElemT, SourceRange(), QMM_Escape); | ||||
1844 | for (unsigned I = 0, N = V.getVectorLength(); I != N; ++I) { | ||||
1845 | const APValue &ElemV = V.getVectorElt(I); | ||||
1846 | mangleTemplateArgValue(ElemT, ElemV); | ||||
1847 | Out << '@'; | ||||
1848 | } | ||||
1849 | Out << "@@"; | ||||
1850 | return; | ||||
1851 | } | ||||
1852 | |||||
1853 | case APValue::AddrLabelDiff: | ||||
1854 | case APValue::FixedPoint: | ||||
1855 | break; | ||||
1856 | } | ||||
1857 | |||||
1858 | mangling_unknown: | ||||
1859 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
1860 | unsigned DiagID = Diags.getCustomDiagID( | ||||
1861 | DiagnosticsEngine::Error, "cannot mangle this template argument yet"); | ||||
1862 | Diags.Report(DiagID); | ||||
1863 | } | ||||
1864 | |||||
1865 | void MicrosoftCXXNameMangler::mangleObjCProtocol(const ObjCProtocolDecl *PD) { | ||||
1866 | llvm::SmallString<64> TemplateMangling; | ||||
1867 | llvm::raw_svector_ostream Stream(TemplateMangling); | ||||
1868 | MicrosoftCXXNameMangler Extra(Context, Stream); | ||||
1869 | |||||
1870 | Stream << "?$"; | ||||
1871 | Extra.mangleSourceName("Protocol"); | ||||
1872 | Extra.mangleArtificialTagType(TTK_Struct, PD->getName()); | ||||
1873 | |||||
1874 | mangleArtificialTagType(TTK_Struct, TemplateMangling, {"__ObjC"}); | ||||
1875 | } | ||||
1876 | |||||
1877 | void MicrosoftCXXNameMangler::mangleObjCLifetime(const QualType Type, | ||||
1878 | Qualifiers Quals, | ||||
1879 | SourceRange Range) { | ||||
1880 | llvm::SmallString<64> TemplateMangling; | ||||
1881 | llvm::raw_svector_ostream Stream(TemplateMangling); | ||||
1882 | MicrosoftCXXNameMangler Extra(Context, Stream); | ||||
1883 | |||||
1884 | Stream << "?$"; | ||||
1885 | switch (Quals.getObjCLifetime()) { | ||||
1886 | case Qualifiers::OCL_None: | ||||
1887 | case Qualifiers::OCL_ExplicitNone: | ||||
1888 | break; | ||||
1889 | case Qualifiers::OCL_Autoreleasing: | ||||
1890 | Extra.mangleSourceName("Autoreleasing"); | ||||
1891 | break; | ||||
1892 | case Qualifiers::OCL_Strong: | ||||
1893 | Extra.mangleSourceName("Strong"); | ||||
1894 | break; | ||||
1895 | case Qualifiers::OCL_Weak: | ||||
1896 | Extra.mangleSourceName("Weak"); | ||||
1897 | break; | ||||
1898 | } | ||||
1899 | Extra.manglePointerCVQualifiers(Quals); | ||||
1900 | Extra.manglePointerExtQualifiers(Quals, Type); | ||||
1901 | Extra.mangleType(Type, Range); | ||||
1902 | |||||
1903 | mangleArtificialTagType(TTK_Struct, TemplateMangling, {"__ObjC"}); | ||||
1904 | } | ||||
1905 | |||||
1906 | void MicrosoftCXXNameMangler::mangleObjCKindOfType(const ObjCObjectType *T, | ||||
1907 | Qualifiers Quals, | ||||
1908 | SourceRange Range) { | ||||
1909 | llvm::SmallString<64> TemplateMangling; | ||||
1910 | llvm::raw_svector_ostream Stream(TemplateMangling); | ||||
1911 | MicrosoftCXXNameMangler Extra(Context, Stream); | ||||
1912 | |||||
1913 | Stream << "?$"; | ||||
1914 | Extra.mangleSourceName("KindOf"); | ||||
1915 | Extra.mangleType(QualType(T, 0) | ||||
1916 | .stripObjCKindOfType(getASTContext()) | ||||
1917 | ->getAs<ObjCObjectType>(), | ||||
1918 | Quals, Range); | ||||
1919 | |||||
1920 | mangleArtificialTagType(TTK_Struct, TemplateMangling, {"__ObjC"}); | ||||
1921 | } | ||||
1922 | |||||
1923 | void MicrosoftCXXNameMangler::mangleQualifiers(Qualifiers Quals, | ||||
1924 | bool IsMember) { | ||||
1925 | // <cvr-qualifiers> ::= [E] [F] [I] <base-cvr-qualifiers> | ||||
1926 | // 'E' means __ptr64 (32-bit only); 'F' means __unaligned (32/64-bit only); | ||||
1927 | // 'I' means __restrict (32/64-bit). | ||||
1928 | // Note that the MSVC __restrict keyword isn't the same as the C99 restrict | ||||
1929 | // keyword! | ||||
1930 | // <base-cvr-qualifiers> ::= A # near | ||||
1931 | // ::= B # near const | ||||
1932 | // ::= C # near volatile | ||||
1933 | // ::= D # near const volatile | ||||
1934 | // ::= E # far (16-bit) | ||||
1935 | // ::= F # far const (16-bit) | ||||
1936 | // ::= G # far volatile (16-bit) | ||||
1937 | // ::= H # far const volatile (16-bit) | ||||
1938 | // ::= I # huge (16-bit) | ||||
1939 | // ::= J # huge const (16-bit) | ||||
1940 | // ::= K # huge volatile (16-bit) | ||||
1941 | // ::= L # huge const volatile (16-bit) | ||||
1942 | // ::= M <basis> # based | ||||
1943 | // ::= N <basis> # based const | ||||
1944 | // ::= O <basis> # based volatile | ||||
1945 | // ::= P <basis> # based const volatile | ||||
1946 | // ::= Q # near member | ||||
1947 | // ::= R # near const member | ||||
1948 | // ::= S # near volatile member | ||||
1949 | // ::= T # near const volatile member | ||||
1950 | // ::= U # far member (16-bit) | ||||
1951 | // ::= V # far const member (16-bit) | ||||
1952 | // ::= W # far volatile member (16-bit) | ||||
1953 | // ::= X # far const volatile member (16-bit) | ||||
1954 | // ::= Y # huge member (16-bit) | ||||
1955 | // ::= Z # huge const member (16-bit) | ||||
1956 | // ::= 0 # huge volatile member (16-bit) | ||||
1957 | // ::= 1 # huge const volatile member (16-bit) | ||||
1958 | // ::= 2 <basis> # based member | ||||
1959 | // ::= 3 <basis> # based const member | ||||
1960 | // ::= 4 <basis> # based volatile member | ||||
1961 | // ::= 5 <basis> # based const volatile member | ||||
1962 | // ::= 6 # near function (pointers only) | ||||
1963 | // ::= 7 # far function (pointers only) | ||||
1964 | // ::= 8 # near method (pointers only) | ||||
1965 | // ::= 9 # far method (pointers only) | ||||
1966 | // ::= _A <basis> # based function (pointers only) | ||||
1967 | // ::= _B <basis> # based function (far?) (pointers only) | ||||
1968 | // ::= _C <basis> # based method (pointers only) | ||||
1969 | // ::= _D <basis> # based method (far?) (pointers only) | ||||
1970 | // ::= _E # block (Clang) | ||||
1971 | // <basis> ::= 0 # __based(void) | ||||
1972 | // ::= 1 # __based(segment)? | ||||
1973 | // ::= 2 <name> # __based(name) | ||||
1974 | // ::= 3 # ? | ||||
1975 | // ::= 4 # ? | ||||
1976 | // ::= 5 # not really based | ||||
1977 | bool HasConst = Quals.hasConst(), | ||||
1978 | HasVolatile = Quals.hasVolatile(); | ||||
1979 | |||||
1980 | if (!IsMember) { | ||||
1981 | if (HasConst && HasVolatile) { | ||||
1982 | Out << 'D'; | ||||
1983 | } else if (HasVolatile) { | ||||
1984 | Out << 'C'; | ||||
1985 | } else if (HasConst) { | ||||
1986 | Out << 'B'; | ||||
1987 | } else { | ||||
1988 | Out << 'A'; | ||||
1989 | } | ||||
1990 | } else { | ||||
1991 | if (HasConst && HasVolatile) { | ||||
1992 | Out << 'T'; | ||||
1993 | } else if (HasVolatile) { | ||||
1994 | Out << 'S'; | ||||
1995 | } else if (HasConst) { | ||||
1996 | Out << 'R'; | ||||
1997 | } else { | ||||
1998 | Out << 'Q'; | ||||
1999 | } | ||||
2000 | } | ||||
2001 | |||||
2002 | // FIXME: For now, just drop all extension qualifiers on the floor. | ||||
2003 | } | ||||
2004 | |||||
2005 | void | ||||
2006 | MicrosoftCXXNameMangler::mangleRefQualifier(RefQualifierKind RefQualifier) { | ||||
2007 | // <ref-qualifier> ::= G # lvalue reference | ||||
2008 | // ::= H # rvalue-reference | ||||
2009 | switch (RefQualifier) { | ||||
2010 | case RQ_None: | ||||
2011 | break; | ||||
2012 | |||||
2013 | case RQ_LValue: | ||||
2014 | Out << 'G'; | ||||
2015 | break; | ||||
2016 | |||||
2017 | case RQ_RValue: | ||||
2018 | Out << 'H'; | ||||
2019 | break; | ||||
2020 | } | ||||
2021 | } | ||||
2022 | |||||
2023 | void MicrosoftCXXNameMangler::manglePointerExtQualifiers(Qualifiers Quals, | ||||
2024 | QualType PointeeType) { | ||||
2025 | // Check if this is a default 64-bit pointer or has __ptr64 qualifier. | ||||
2026 | bool is64Bit = PointeeType.isNull() ? PointersAre64Bit : | ||||
2027 | is64BitPointer(PointeeType.getQualifiers()); | ||||
2028 | if (is64Bit && (PointeeType.isNull() || !PointeeType->isFunctionType())) | ||||
2029 | Out << 'E'; | ||||
2030 | |||||
2031 | if (Quals.hasRestrict()) | ||||
2032 | Out << 'I'; | ||||
2033 | |||||
2034 | if (Quals.hasUnaligned() || | ||||
2035 | (!PointeeType.isNull() && PointeeType.getLocalQualifiers().hasUnaligned())) | ||||
2036 | Out << 'F'; | ||||
2037 | } | ||||
2038 | |||||
2039 | void MicrosoftCXXNameMangler::manglePointerCVQualifiers(Qualifiers Quals) { | ||||
2040 | // <pointer-cv-qualifiers> ::= P # no qualifiers | ||||
2041 | // ::= Q # const | ||||
2042 | // ::= R # volatile | ||||
2043 | // ::= S # const volatile | ||||
2044 | bool HasConst = Quals.hasConst(), | ||||
2045 | HasVolatile = Quals.hasVolatile(); | ||||
2046 | |||||
2047 | if (HasConst && HasVolatile) { | ||||
2048 | Out << 'S'; | ||||
2049 | } else if (HasVolatile) { | ||||
2050 | Out << 'R'; | ||||
2051 | } else if (HasConst) { | ||||
2052 | Out << 'Q'; | ||||
2053 | } else { | ||||
2054 | Out << 'P'; | ||||
2055 | } | ||||
2056 | } | ||||
2057 | |||||
2058 | void MicrosoftCXXNameMangler::mangleFunctionArgumentType(QualType T, | ||||
2059 | SourceRange Range) { | ||||
2060 | // MSVC will backreference two canonically equivalent types that have slightly | ||||
2061 | // different manglings when mangled alone. | ||||
2062 | |||||
2063 | // Decayed types do not match up with non-decayed versions of the same type. | ||||
2064 | // | ||||
2065 | // e.g. | ||||
2066 | // void (*x)(void) will not form a backreference with void x(void) | ||||
2067 | void *TypePtr; | ||||
2068 | if (const auto *DT = T->getAs<DecayedType>()) { | ||||
2069 | QualType OriginalType = DT->getOriginalType(); | ||||
2070 | // All decayed ArrayTypes should be treated identically; as-if they were | ||||
2071 | // a decayed IncompleteArrayType. | ||||
2072 | if (const auto *AT = getASTContext().getAsArrayType(OriginalType)) | ||||
2073 | OriginalType = getASTContext().getIncompleteArrayType( | ||||
2074 | AT->getElementType(), AT->getSizeModifier(), | ||||
2075 | AT->getIndexTypeCVRQualifiers()); | ||||
2076 | |||||
2077 | TypePtr = OriginalType.getCanonicalType().getAsOpaquePtr(); | ||||
2078 | // If the original parameter was textually written as an array, | ||||
2079 | // instead treat the decayed parameter like it's const. | ||||
2080 | // | ||||
2081 | // e.g. | ||||
2082 | // int [] -> int * const | ||||
2083 | if (OriginalType->isArrayType()) | ||||
2084 | T = T.withConst(); | ||||
2085 | } else { | ||||
2086 | TypePtr = T.getCanonicalType().getAsOpaquePtr(); | ||||
2087 | } | ||||
2088 | |||||
2089 | ArgBackRefMap::iterator Found = FunArgBackReferences.find(TypePtr); | ||||
2090 | |||||
2091 | if (Found == FunArgBackReferences.end()) { | ||||
2092 | size_t OutSizeBefore = Out.tell(); | ||||
2093 | |||||
2094 | mangleType(T, Range, QMM_Drop); | ||||
2095 | |||||
2096 | // See if it's worth creating a back reference. | ||||
2097 | // Only types longer than 1 character are considered | ||||
2098 | // and only 10 back references slots are available: | ||||
2099 | bool LongerThanOneChar = (Out.tell() - OutSizeBefore > 1); | ||||
2100 | if (LongerThanOneChar && FunArgBackReferences.size() < 10) { | ||||
2101 | size_t Size = FunArgBackReferences.size(); | ||||
2102 | FunArgBackReferences[TypePtr] = Size; | ||||
2103 | } | ||||
2104 | } else { | ||||
2105 | Out << Found->second; | ||||
2106 | } | ||||
2107 | } | ||||
2108 | |||||
2109 | void MicrosoftCXXNameMangler::manglePassObjectSizeArg( | ||||
2110 | const PassObjectSizeAttr *POSA) { | ||||
2111 | int Type = POSA->getType(); | ||||
2112 | bool Dynamic = POSA->isDynamic(); | ||||
2113 | |||||
2114 | auto Iter = PassObjectSizeArgs.insert({Type, Dynamic}).first; | ||||
2115 | auto *TypePtr = (const void *)&*Iter; | ||||
2116 | ArgBackRefMap::iterator Found = FunArgBackReferences.find(TypePtr); | ||||
2117 | |||||
2118 | if (Found == FunArgBackReferences.end()) { | ||||
2119 | std::string Name = | ||||
2120 | Dynamic ? "__pass_dynamic_object_size" : "__pass_object_size"; | ||||
2121 | mangleArtificialTagType(TTK_Enum, Name + llvm::utostr(Type), {"__clang"}); | ||||
2122 | |||||
2123 | if (FunArgBackReferences.size() < 10) { | ||||
2124 | size_t Size = FunArgBackReferences.size(); | ||||
2125 | FunArgBackReferences[TypePtr] = Size; | ||||
2126 | } | ||||
2127 | } else { | ||||
2128 | Out << Found->second; | ||||
2129 | } | ||||
2130 | } | ||||
2131 | |||||
2132 | void MicrosoftCXXNameMangler::mangleAddressSpaceType(QualType T, | ||||
2133 | Qualifiers Quals, | ||||
2134 | SourceRange Range) { | ||||
2135 | // Address space is mangled as an unqualified templated type in the __clang | ||||
2136 | // namespace. The demangled version of this is: | ||||
2137 | // In the case of a language specific address space: | ||||
2138 | // __clang::struct _AS[language_addr_space]<Type> | ||||
2139 | // where: | ||||
2140 | // <language_addr_space> ::= <OpenCL-addrspace> | <CUDA-addrspace> | ||||
2141 | // <OpenCL-addrspace> ::= "CL" [ "global" | "local" | "constant" | | ||||
2142 | // "private"| "generic" | "device" | "host" ] | ||||
2143 | // <CUDA-addrspace> ::= "CU" [ "device" | "constant" | "shared" ] | ||||
2144 | // Note that the above were chosen to match the Itanium mangling for this. | ||||
2145 | // | ||||
2146 | // In the case of a non-language specific address space: | ||||
2147 | // __clang::struct _AS<TargetAS, Type> | ||||
2148 | assert(Quals.hasAddressSpace() && "Not valid without address space")((Quals.hasAddressSpace() && "Not valid without address space" ) ? static_cast<void> (0) : __assert_fail ("Quals.hasAddressSpace() && \"Not valid without address space\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 2148, __PRETTY_FUNCTION__)); | ||||
2149 | llvm::SmallString<32> ASMangling; | ||||
2150 | llvm::raw_svector_ostream Stream(ASMangling); | ||||
2151 | MicrosoftCXXNameMangler Extra(Context, Stream); | ||||
2152 | Stream << "?$"; | ||||
2153 | |||||
2154 | LangAS AS = Quals.getAddressSpace(); | ||||
2155 | if (Context.getASTContext().addressSpaceMapManglingFor(AS)) { | ||||
2156 | unsigned TargetAS = Context.getASTContext().getTargetAddressSpace(AS); | ||||
2157 | Extra.mangleSourceName("_AS"); | ||||
2158 | Extra.mangleIntegerLiteral(llvm::APSInt::getUnsigned(TargetAS)); | ||||
2159 | } else { | ||||
2160 | switch (AS) { | ||||
2161 | default: | ||||
2162 | llvm_unreachable("Not a language specific address space")::llvm::llvm_unreachable_internal("Not a language specific address space" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 2162); | ||||
2163 | case LangAS::opencl_global: | ||||
2164 | Extra.mangleSourceName("_ASCLglobal"); | ||||
2165 | break; | ||||
2166 | case LangAS::opencl_global_device: | ||||
2167 | Extra.mangleSourceName("_ASCLdevice"); | ||||
2168 | break; | ||||
2169 | case LangAS::opencl_global_host: | ||||
2170 | Extra.mangleSourceName("_ASCLhost"); | ||||
2171 | break; | ||||
2172 | case LangAS::opencl_local: | ||||
2173 | Extra.mangleSourceName("_ASCLlocal"); | ||||
2174 | break; | ||||
2175 | case LangAS::opencl_constant: | ||||
2176 | Extra.mangleSourceName("_ASCLconstant"); | ||||
2177 | break; | ||||
2178 | case LangAS::opencl_private: | ||||
2179 | Extra.mangleSourceName("_ASCLprivate"); | ||||
2180 | break; | ||||
2181 | case LangAS::opencl_generic: | ||||
2182 | Extra.mangleSourceName("_ASCLgeneric"); | ||||
2183 | break; | ||||
2184 | case LangAS::cuda_device: | ||||
2185 | Extra.mangleSourceName("_ASCUdevice"); | ||||
2186 | break; | ||||
2187 | case LangAS::cuda_constant: | ||||
2188 | Extra.mangleSourceName("_ASCUconstant"); | ||||
2189 | break; | ||||
2190 | case LangAS::cuda_shared: | ||||
2191 | Extra.mangleSourceName("_ASCUshared"); | ||||
2192 | break; | ||||
2193 | case LangAS::ptr32_sptr: | ||||
2194 | case LangAS::ptr32_uptr: | ||||
2195 | case LangAS::ptr64: | ||||
2196 | llvm_unreachable("don't mangle ptr address spaces with _AS")::llvm::llvm_unreachable_internal("don't mangle ptr address spaces with _AS" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 2196); | ||||
2197 | } | ||||
2198 | } | ||||
2199 | |||||
2200 | Extra.mangleType(T, Range, QMM_Escape); | ||||
2201 | mangleQualifiers(Qualifiers(), false); | ||||
2202 | mangleArtificialTagType(TTK_Struct, ASMangling, {"__clang"}); | ||||
2203 | } | ||||
2204 | |||||
2205 | void MicrosoftCXXNameMangler::mangleType(QualType T, SourceRange Range, | ||||
2206 | QualifierMangleMode QMM) { | ||||
2207 | // Don't use the canonical types. MSVC includes things like 'const' on | ||||
2208 | // pointer arguments to function pointers that canonicalization strips away. | ||||
2209 | T = T.getDesugaredType(getASTContext()); | ||||
2210 | Qualifiers Quals = T.getLocalQualifiers(); | ||||
2211 | |||||
2212 | if (const ArrayType *AT = getASTContext().getAsArrayType(T)) { | ||||
2213 | // If there were any Quals, getAsArrayType() pushed them onto the array | ||||
2214 | // element type. | ||||
2215 | if (QMM == QMM_Mangle) | ||||
2216 | Out << 'A'; | ||||
2217 | else if (QMM == QMM_Escape || QMM == QMM_Result) | ||||
2218 | Out << "$$B"; | ||||
2219 | mangleArrayType(AT); | ||||
2220 | return; | ||||
2221 | } | ||||
2222 | |||||
2223 | bool IsPointer = T->isAnyPointerType() || T->isMemberPointerType() || | ||||
2224 | T->isReferenceType() || T->isBlockPointerType(); | ||||
2225 | |||||
2226 | switch (QMM) { | ||||
2227 | case QMM_Drop: | ||||
2228 | if (Quals.hasObjCLifetime()) | ||||
2229 | Quals = Quals.withoutObjCLifetime(); | ||||
2230 | break; | ||||
2231 | case QMM_Mangle: | ||||
2232 | if (const FunctionType *FT = dyn_cast<FunctionType>(T)) { | ||||
2233 | Out << '6'; | ||||
2234 | mangleFunctionType(FT); | ||||
2235 | return; | ||||
2236 | } | ||||
2237 | mangleQualifiers(Quals, false); | ||||
2238 | break; | ||||
2239 | case QMM_Escape: | ||||
2240 | if (!IsPointer && Quals) { | ||||
2241 | Out << "$$C"; | ||||
2242 | mangleQualifiers(Quals, false); | ||||
2243 | } | ||||
2244 | break; | ||||
2245 | case QMM_Result: | ||||
2246 | // Presence of __unaligned qualifier shouldn't affect mangling here. | ||||
2247 | Quals.removeUnaligned(); | ||||
2248 | if (Quals.hasObjCLifetime()) | ||||
2249 | Quals = Quals.withoutObjCLifetime(); | ||||
2250 | if ((!IsPointer && Quals) || isa<TagType>(T) || isArtificialTagType(T)) { | ||||
2251 | Out << '?'; | ||||
2252 | mangleQualifiers(Quals, false); | ||||
2253 | } | ||||
2254 | break; | ||||
2255 | } | ||||
2256 | |||||
2257 | const Type *ty = T.getTypePtr(); | ||||
2258 | |||||
2259 | switch (ty->getTypeClass()) { | ||||
2260 | #define ABSTRACT_TYPE(CLASS, PARENT) | ||||
2261 | #define NON_CANONICAL_TYPE(CLASS, PARENT) \ | ||||
2262 | case Type::CLASS: \ | ||||
2263 | llvm_unreachable("can't mangle non-canonical type " #CLASS "Type")::llvm::llvm_unreachable_internal("can't mangle non-canonical type " #CLASS "Type", "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 2263); \ | ||||
2264 | return; | ||||
2265 | #define TYPE(CLASS, PARENT) \ | ||||
2266 | case Type::CLASS: \ | ||||
2267 | mangleType(cast<CLASS##Type>(ty), Quals, Range); \ | ||||
2268 | break; | ||||
2269 | #include "clang/AST/TypeNodes.inc" | ||||
2270 | #undef ABSTRACT_TYPE | ||||
2271 | #undef NON_CANONICAL_TYPE | ||||
2272 | #undef TYPE | ||||
2273 | } | ||||
2274 | } | ||||
2275 | |||||
2276 | void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers, | ||||
2277 | SourceRange Range) { | ||||
2278 | // <type> ::= <builtin-type> | ||||
2279 | // <builtin-type> ::= X # void | ||||
2280 | // ::= C # signed char | ||||
2281 | // ::= D # char | ||||
2282 | // ::= E # unsigned char | ||||
2283 | // ::= F # short | ||||
2284 | // ::= G # unsigned short (or wchar_t if it's not a builtin) | ||||
2285 | // ::= H # int | ||||
2286 | // ::= I # unsigned int | ||||
2287 | // ::= J # long | ||||
2288 | // ::= K # unsigned long | ||||
2289 | // L # <none> | ||||
2290 | // ::= M # float | ||||
2291 | // ::= N # double | ||||
2292 | // ::= O # long double (__float80 is mangled differently) | ||||
2293 | // ::= _J # long long, __int64 | ||||
2294 | // ::= _K # unsigned long long, __int64 | ||||
2295 | // ::= _L # __int128 | ||||
2296 | // ::= _M # unsigned __int128 | ||||
2297 | // ::= _N # bool | ||||
2298 | // _O # <array in parameter> | ||||
2299 | // ::= _Q # char8_t | ||||
2300 | // ::= _S # char16_t | ||||
2301 | // ::= _T # __float80 (Intel) | ||||
2302 | // ::= _U # char32_t | ||||
2303 | // ::= _W # wchar_t | ||||
2304 | // ::= _Z # __float80 (Digital Mars) | ||||
2305 | switch (T->getKind()) { | ||||
2306 | case BuiltinType::Void: | ||||
2307 | Out << 'X'; | ||||
2308 | break; | ||||
2309 | case BuiltinType::SChar: | ||||
2310 | Out << 'C'; | ||||
2311 | break; | ||||
2312 | case BuiltinType::Char_U: | ||||
2313 | case BuiltinType::Char_S: | ||||
2314 | Out << 'D'; | ||||
2315 | break; | ||||
2316 | case BuiltinType::UChar: | ||||
2317 | Out << 'E'; | ||||
2318 | break; | ||||
2319 | case BuiltinType::Short: | ||||
2320 | Out << 'F'; | ||||
2321 | break; | ||||
2322 | case BuiltinType::UShort: | ||||
2323 | Out << 'G'; | ||||
2324 | break; | ||||
2325 | case BuiltinType::Int: | ||||
2326 | Out << 'H'; | ||||
2327 | break; | ||||
2328 | case BuiltinType::UInt: | ||||
2329 | Out << 'I'; | ||||
2330 | break; | ||||
2331 | case BuiltinType::Long: | ||||
2332 | Out << 'J'; | ||||
2333 | break; | ||||
2334 | case BuiltinType::ULong: | ||||
2335 | Out << 'K'; | ||||
2336 | break; | ||||
2337 | case BuiltinType::Float: | ||||
2338 | Out << 'M'; | ||||
2339 | break; | ||||
2340 | case BuiltinType::Double: | ||||
2341 | Out << 'N'; | ||||
2342 | break; | ||||
2343 | // TODO: Determine size and mangle accordingly | ||||
2344 | case BuiltinType::LongDouble: | ||||
2345 | Out << 'O'; | ||||
2346 | break; | ||||
2347 | case BuiltinType::LongLong: | ||||
2348 | Out << "_J"; | ||||
2349 | break; | ||||
2350 | case BuiltinType::ULongLong: | ||||
2351 | Out << "_K"; | ||||
2352 | break; | ||||
2353 | case BuiltinType::Int128: | ||||
2354 | Out << "_L"; | ||||
2355 | break; | ||||
2356 | case BuiltinType::UInt128: | ||||
2357 | Out << "_M"; | ||||
2358 | break; | ||||
2359 | case BuiltinType::Bool: | ||||
2360 | Out << "_N"; | ||||
2361 | break; | ||||
2362 | case BuiltinType::Char8: | ||||
2363 | Out << "_Q"; | ||||
2364 | break; | ||||
2365 | case BuiltinType::Char16: | ||||
2366 | Out << "_S"; | ||||
2367 | break; | ||||
2368 | case BuiltinType::Char32: | ||||
2369 | Out << "_U"; | ||||
2370 | break; | ||||
2371 | case BuiltinType::WChar_S: | ||||
2372 | case BuiltinType::WChar_U: | ||||
2373 | Out << "_W"; | ||||
2374 | break; | ||||
2375 | |||||
2376 | #define BUILTIN_TYPE(Id, SingletonId) | ||||
2377 | #define PLACEHOLDER_TYPE(Id, SingletonId) \ | ||||
2378 | case BuiltinType::Id: | ||||
2379 | #include "clang/AST/BuiltinTypes.def" | ||||
2380 | case BuiltinType::Dependent: | ||||
2381 | llvm_unreachable("placeholder types shouldn't get to name mangling")::llvm::llvm_unreachable_internal("placeholder types shouldn't get to name mangling" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 2381); | ||||
2382 | |||||
2383 | case BuiltinType::ObjCId: | ||||
2384 | mangleArtificialTagType(TTK_Struct, "objc_object"); | ||||
2385 | break; | ||||
2386 | case BuiltinType::ObjCClass: | ||||
2387 | mangleArtificialTagType(TTK_Struct, "objc_class"); | ||||
2388 | break; | ||||
2389 | case BuiltinType::ObjCSel: | ||||
2390 | mangleArtificialTagType(TTK_Struct, "objc_selector"); | ||||
2391 | break; | ||||
2392 | |||||
2393 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ | ||||
2394 | case BuiltinType::Id: \ | ||||
2395 | Out << "PAUocl_" #ImgType "_" #Suffix "@@"; \ | ||||
2396 | break; | ||||
2397 | #include "clang/Basic/OpenCLImageTypes.def" | ||||
2398 | case BuiltinType::OCLSampler: | ||||
2399 | Out << "PA"; | ||||
2400 | mangleArtificialTagType(TTK_Struct, "ocl_sampler"); | ||||
2401 | break; | ||||
2402 | case BuiltinType::OCLEvent: | ||||
2403 | Out << "PA"; | ||||
2404 | mangleArtificialTagType(TTK_Struct, "ocl_event"); | ||||
2405 | break; | ||||
2406 | case BuiltinType::OCLClkEvent: | ||||
2407 | Out << "PA"; | ||||
2408 | mangleArtificialTagType(TTK_Struct, "ocl_clkevent"); | ||||
2409 | break; | ||||
2410 | case BuiltinType::OCLQueue: | ||||
2411 | Out << "PA"; | ||||
2412 | mangleArtificialTagType(TTK_Struct, "ocl_queue"); | ||||
2413 | break; | ||||
2414 | case BuiltinType::OCLReserveID: | ||||
2415 | Out << "PA"; | ||||
2416 | mangleArtificialTagType(TTK_Struct, "ocl_reserveid"); | ||||
2417 | break; | ||||
2418 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ | ||||
2419 | case BuiltinType::Id: \ | ||||
2420 | mangleArtificialTagType(TTK_Struct, "ocl_" #ExtType); \ | ||||
2421 | break; | ||||
2422 | #include "clang/Basic/OpenCLExtensionTypes.def" | ||||
2423 | |||||
2424 | case BuiltinType::NullPtr: | ||||
2425 | Out << "$$T"; | ||||
2426 | break; | ||||
2427 | |||||
2428 | case BuiltinType::Float16: | ||||
2429 | mangleArtificialTagType(TTK_Struct, "_Float16", {"__clang"}); | ||||
2430 | break; | ||||
2431 | |||||
2432 | case BuiltinType::Half: | ||||
2433 | mangleArtificialTagType(TTK_Struct, "_Half", {"__clang"}); | ||||
2434 | break; | ||||
2435 | |||||
2436 | #define SVE_TYPE(Name, Id, SingletonId) \ | ||||
2437 | case BuiltinType::Id: | ||||
2438 | #include "clang/Basic/AArch64SVEACLETypes.def" | ||||
2439 | #define PPC_VECTOR_TYPE(Name, Id, Size) \ | ||||
2440 | case BuiltinType::Id: | ||||
2441 | #include "clang/Basic/PPCTypes.def" | ||||
2442 | #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id: | ||||
2443 | #include "clang/Basic/RISCVVTypes.def" | ||||
2444 | case BuiltinType::ShortAccum: | ||||
2445 | case BuiltinType::Accum: | ||||
2446 | case BuiltinType::LongAccum: | ||||
2447 | case BuiltinType::UShortAccum: | ||||
2448 | case BuiltinType::UAccum: | ||||
2449 | case BuiltinType::ULongAccum: | ||||
2450 | case BuiltinType::ShortFract: | ||||
2451 | case BuiltinType::Fract: | ||||
2452 | case BuiltinType::LongFract: | ||||
2453 | case BuiltinType::UShortFract: | ||||
2454 | case BuiltinType::UFract: | ||||
2455 | case BuiltinType::ULongFract: | ||||
2456 | case BuiltinType::SatShortAccum: | ||||
2457 | case BuiltinType::SatAccum: | ||||
2458 | case BuiltinType::SatLongAccum: | ||||
2459 | case BuiltinType::SatUShortAccum: | ||||
2460 | case BuiltinType::SatUAccum: | ||||
2461 | case BuiltinType::SatULongAccum: | ||||
2462 | case BuiltinType::SatShortFract: | ||||
2463 | case BuiltinType::SatFract: | ||||
2464 | case BuiltinType::SatLongFract: | ||||
2465 | case BuiltinType::SatUShortFract: | ||||
2466 | case BuiltinType::SatUFract: | ||||
2467 | case BuiltinType::SatULongFract: | ||||
2468 | case BuiltinType::BFloat16: | ||||
2469 | case BuiltinType::Float128: { | ||||
2470 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
2471 | unsigned DiagID = Diags.getCustomDiagID( | ||||
2472 | DiagnosticsEngine::Error, "cannot mangle this built-in %0 type yet"); | ||||
2473 | Diags.Report(Range.getBegin(), DiagID) | ||||
2474 | << T->getName(Context.getASTContext().getPrintingPolicy()) << Range; | ||||
2475 | break; | ||||
2476 | } | ||||
2477 | } | ||||
2478 | } | ||||
2479 | |||||
2480 | // <type> ::= <function-type> | ||||
2481 | void MicrosoftCXXNameMangler::mangleType(const FunctionProtoType *T, Qualifiers, | ||||
2482 | SourceRange) { | ||||
2483 | // Structors only appear in decls, so at this point we know it's not a | ||||
2484 | // structor type. | ||||
2485 | // FIXME: This may not be lambda-friendly. | ||||
2486 | if (T->getMethodQuals() || T->getRefQualifier() != RQ_None) { | ||||
2487 | Out << "$$A8@@"; | ||||
2488 | mangleFunctionType(T, /*D=*/nullptr, /*ForceThisQuals=*/true); | ||||
2489 | } else { | ||||
2490 | Out << "$$A6"; | ||||
2491 | mangleFunctionType(T); | ||||
2492 | } | ||||
2493 | } | ||||
2494 | void MicrosoftCXXNameMangler::mangleType(const FunctionNoProtoType *T, | ||||
2495 | Qualifiers, SourceRange) { | ||||
2496 | Out << "$$A6"; | ||||
2497 | mangleFunctionType(T); | ||||
2498 | } | ||||
2499 | |||||
2500 | void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T, | ||||
2501 | const FunctionDecl *D, | ||||
2502 | bool ForceThisQuals, | ||||
2503 | bool MangleExceptionSpec) { | ||||
2504 | // <function-type> ::= <this-cvr-qualifiers> <calling-convention> | ||||
2505 | // <return-type> <argument-list> <throw-spec> | ||||
2506 | const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(T); | ||||
2507 | |||||
2508 | SourceRange Range; | ||||
2509 | if (D
| ||||
2510 | |||||
2511 | bool IsInLambda = false; | ||||
2512 | bool IsStructor = false, HasThisQuals = ForceThisQuals, IsCtorClosure = false; | ||||
2513 | CallingConv CC = T->getCallConv(); | ||||
2514 | if (const CXXMethodDecl *MD
| ||||
2515 | if (MD->getParent()->isLambda()) | ||||
2516 | IsInLambda = true; | ||||
2517 | if (MD->isInstance()) | ||||
2518 | HasThisQuals = true; | ||||
2519 | if (isa<CXXDestructorDecl>(MD)) { | ||||
2520 | IsStructor = true; | ||||
2521 | } else if (isa<CXXConstructorDecl>(MD)) { | ||||
2522 | IsStructor = true; | ||||
2523 | IsCtorClosure = (StructorType == Ctor_CopyingClosure || | ||||
2524 | StructorType == Ctor_DefaultClosure) && | ||||
2525 | isStructorDecl(MD); | ||||
2526 | if (IsCtorClosure) | ||||
2527 | CC = getASTContext().getDefaultCallingConvention( | ||||
2528 | /*IsVariadic=*/false, /*IsCXXMethod=*/true); | ||||
2529 | } | ||||
2530 | } | ||||
2531 | |||||
2532 | // If this is a C++ instance method, mangle the CVR qualifiers for the | ||||
2533 | // this pointer. | ||||
2534 | if (HasThisQuals
| ||||
2535 | Qualifiers Quals = Proto->getMethodQuals(); | ||||
| |||||
2536 | manglePointerExtQualifiers(Quals, /*PointeeType=*/QualType()); | ||||
2537 | mangleRefQualifier(Proto->getRefQualifier()); | ||||
2538 | mangleQualifiers(Quals, /*IsMember=*/false); | ||||
2539 | } | ||||
2540 | |||||
2541 | mangleCallingConvention(CC); | ||||
2542 | |||||
2543 | // <return-type> ::= <type> | ||||
2544 | // ::= @ # structors (they have no declared return type) | ||||
2545 | if (IsStructor) { | ||||
2546 | if (isa<CXXDestructorDecl>(D) && isStructorDecl(D)) { | ||||
2547 | // The scalar deleting destructor takes an extra int argument which is not | ||||
2548 | // reflected in the AST. | ||||
2549 | if (StructorType == Dtor_Deleting) { | ||||
2550 | Out << (PointersAre64Bit ? "PEAXI@Z" : "PAXI@Z"); | ||||
2551 | return; | ||||
2552 | } | ||||
2553 | // The vbase destructor returns void which is not reflected in the AST. | ||||
2554 | if (StructorType == Dtor_Complete) { | ||||
2555 | Out << "XXZ"; | ||||
2556 | return; | ||||
2557 | } | ||||
2558 | } | ||||
2559 | if (IsCtorClosure) { | ||||
2560 | // Default constructor closure and copy constructor closure both return | ||||
2561 | // void. | ||||
2562 | Out << 'X'; | ||||
2563 | |||||
2564 | if (StructorType == Ctor_DefaultClosure) { | ||||
2565 | // Default constructor closure always has no arguments. | ||||
2566 | Out << 'X'; | ||||
2567 | } else if (StructorType == Ctor_CopyingClosure) { | ||||
2568 | // Copy constructor closure always takes an unqualified reference. | ||||
2569 | mangleFunctionArgumentType(getASTContext().getLValueReferenceType( | ||||
2570 | Proto->getParamType(0) | ||||
2571 | ->getAs<LValueReferenceType>() | ||||
2572 | ->getPointeeType(), | ||||
2573 | /*SpelledAsLValue=*/true), | ||||
2574 | Range); | ||||
2575 | Out << '@'; | ||||
2576 | } else { | ||||
2577 | llvm_unreachable("unexpected constructor closure!")::llvm::llvm_unreachable_internal("unexpected constructor closure!" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 2577); | ||||
2578 | } | ||||
2579 | Out << 'Z'; | ||||
2580 | return; | ||||
2581 | } | ||||
2582 | Out << '@'; | ||||
2583 | } else if (IsInLambda && D && isa<CXXConversionDecl>(D)) { | ||||
2584 | // The only lambda conversion operators are to function pointers, which | ||||
2585 | // can differ by their calling convention and are typically deduced. So | ||||
2586 | // we make sure that this type gets mangled properly. | ||||
2587 | mangleType(T->getReturnType(), Range, QMM_Result); | ||||
2588 | } else { | ||||
2589 | QualType ResultType = T->getReturnType(); | ||||
2590 | if (IsInLambda && isa<CXXConversionDecl>(D)) { | ||||
2591 | // The only lambda conversion operators are to function pointers, which | ||||
2592 | // can differ by their calling convention and are typically deduced. So | ||||
2593 | // we make sure that this type gets mangled properly. | ||||
2594 | mangleType(ResultType, Range, QMM_Result); | ||||
2595 | } else if (const auto *AT = dyn_cast_or_null<AutoType>( | ||||
2596 | ResultType->getContainedAutoType())) { | ||||
2597 | Out << '?'; | ||||
2598 | mangleQualifiers(ResultType.getLocalQualifiers(), /*IsMember=*/false); | ||||
2599 | Out << '?'; | ||||
2600 | assert(AT->getKeyword() != AutoTypeKeyword::GNUAutoType &&((AT->getKeyword() != AutoTypeKeyword::GNUAutoType && "shouldn't need to mangle __auto_type!") ? static_cast<void > (0) : __assert_fail ("AT->getKeyword() != AutoTypeKeyword::GNUAutoType && \"shouldn't need to mangle __auto_type!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 2601, __PRETTY_FUNCTION__)) | ||||
2601 | "shouldn't need to mangle __auto_type!")((AT->getKeyword() != AutoTypeKeyword::GNUAutoType && "shouldn't need to mangle __auto_type!") ? static_cast<void > (0) : __assert_fail ("AT->getKeyword() != AutoTypeKeyword::GNUAutoType && \"shouldn't need to mangle __auto_type!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 2601, __PRETTY_FUNCTION__)); | ||||
2602 | mangleSourceName(AT->isDecltypeAuto() ? "<decltype-auto>" : "<auto>"); | ||||
2603 | Out << '@'; | ||||
2604 | } else if (IsInLambda) { | ||||
2605 | Out << '@'; | ||||
2606 | } else { | ||||
2607 | if (ResultType->isVoidType()) | ||||
2608 | ResultType = ResultType.getUnqualifiedType(); | ||||
2609 | mangleType(ResultType, Range, QMM_Result); | ||||
2610 | } | ||||
2611 | } | ||||
2612 | |||||
2613 | // <argument-list> ::= X # void | ||||
2614 | // ::= <type>+ @ | ||||
2615 | // ::= <type>* Z # varargs | ||||
2616 | if (!Proto) { | ||||
2617 | // Function types without prototypes can arise when mangling a function type | ||||
2618 | // within an overloadable function in C. We mangle these as the absence of | ||||
2619 | // any parameter types (not even an empty parameter list). | ||||
2620 | Out << '@'; | ||||
2621 | } else if (Proto->getNumParams() == 0 && !Proto->isVariadic()) { | ||||
2622 | Out << 'X'; | ||||
2623 | } else { | ||||
2624 | // Happens for function pointer type arguments for example. | ||||
2625 | for (unsigned I = 0, E = Proto->getNumParams(); I != E; ++I) { | ||||
2626 | mangleFunctionArgumentType(Proto->getParamType(I), Range); | ||||
2627 | // Mangle each pass_object_size parameter as if it's a parameter of enum | ||||
2628 | // type passed directly after the parameter with the pass_object_size | ||||
2629 | // attribute. The aforementioned enum's name is __pass_object_size, and we | ||||
2630 | // pretend it resides in a top-level namespace called __clang. | ||||
2631 | // | ||||
2632 | // FIXME: Is there a defined extension notation for the MS ABI, or is it | ||||
2633 | // necessary to just cross our fingers and hope this type+namespace | ||||
2634 | // combination doesn't conflict with anything? | ||||
2635 | if (D) | ||||
2636 | if (const auto *P = D->getParamDecl(I)->getAttr<PassObjectSizeAttr>()) | ||||
2637 | manglePassObjectSizeArg(P); | ||||
2638 | } | ||||
2639 | // <builtin-type> ::= Z # ellipsis | ||||
2640 | if (Proto->isVariadic()) | ||||
2641 | Out << 'Z'; | ||||
2642 | else | ||||
2643 | Out << '@'; | ||||
2644 | } | ||||
2645 | |||||
2646 | if (MangleExceptionSpec && getASTContext().getLangOpts().CPlusPlus17 && | ||||
2647 | getASTContext().getLangOpts().isCompatibleWithMSVC( | ||||
2648 | LangOptions::MSVC2017_5)) | ||||
2649 | mangleThrowSpecification(Proto); | ||||
2650 | else | ||||
2651 | Out << 'Z'; | ||||
2652 | } | ||||
2653 | |||||
2654 | void MicrosoftCXXNameMangler::mangleFunctionClass(const FunctionDecl *FD) { | ||||
2655 | // <function-class> ::= <member-function> E? # E designates a 64-bit 'this' | ||||
2656 | // # pointer. in 64-bit mode *all* | ||||
2657 | // # 'this' pointers are 64-bit. | ||||
2658 | // ::= <global-function> | ||||
2659 | // <member-function> ::= A # private: near | ||||
2660 | // ::= B # private: far | ||||
2661 | // ::= C # private: static near | ||||
2662 | // ::= D # private: static far | ||||
2663 | // ::= E # private: virtual near | ||||
2664 | // ::= F # private: virtual far | ||||
2665 | // ::= I # protected: near | ||||
2666 | // ::= J # protected: far | ||||
2667 | // ::= K # protected: static near | ||||
2668 | // ::= L # protected: static far | ||||
2669 | // ::= M # protected: virtual near | ||||
2670 | // ::= N # protected: virtual far | ||||
2671 | // ::= Q # public: near | ||||
2672 | // ::= R # public: far | ||||
2673 | // ::= S # public: static near | ||||
2674 | // ::= T # public: static far | ||||
2675 | // ::= U # public: virtual near | ||||
2676 | // ::= V # public: virtual far | ||||
2677 | // <global-function> ::= Y # global near | ||||
2678 | // ::= Z # global far | ||||
2679 | if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { | ||||
2680 | bool IsVirtual = MD->isVirtual(); | ||||
2681 | // When mangling vbase destructor variants, ignore whether or not the | ||||
2682 | // underlying destructor was defined to be virtual. | ||||
2683 | if (isa<CXXDestructorDecl>(MD) && isStructorDecl(MD) && | ||||
2684 | StructorType == Dtor_Complete) { | ||||
2685 | IsVirtual = false; | ||||
2686 | } | ||||
2687 | switch (MD->getAccess()) { | ||||
2688 | case AS_none: | ||||
2689 | llvm_unreachable("Unsupported access specifier")::llvm::llvm_unreachable_internal("Unsupported access specifier" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 2689); | ||||
2690 | case AS_private: | ||||
2691 | if (MD->isStatic()) | ||||
2692 | Out << 'C'; | ||||
2693 | else if (IsVirtual) | ||||
2694 | Out << 'E'; | ||||
2695 | else | ||||
2696 | Out << 'A'; | ||||
2697 | break; | ||||
2698 | case AS_protected: | ||||
2699 | if (MD->isStatic()) | ||||
2700 | Out << 'K'; | ||||
2701 | else if (IsVirtual) | ||||
2702 | Out << 'M'; | ||||
2703 | else | ||||
2704 | Out << 'I'; | ||||
2705 | break; | ||||
2706 | case AS_public: | ||||
2707 | if (MD->isStatic()) | ||||
2708 | Out << 'S'; | ||||
2709 | else if (IsVirtual) | ||||
2710 | Out << 'U'; | ||||
2711 | else | ||||
2712 | Out << 'Q'; | ||||
2713 | } | ||||
2714 | } else { | ||||
2715 | Out << 'Y'; | ||||
2716 | } | ||||
2717 | } | ||||
2718 | void MicrosoftCXXNameMangler::mangleCallingConvention(CallingConv CC) { | ||||
2719 | // <calling-convention> ::= A # __cdecl | ||||
2720 | // ::= B # __export __cdecl | ||||
2721 | // ::= C # __pascal | ||||
2722 | // ::= D # __export __pascal | ||||
2723 | // ::= E # __thiscall | ||||
2724 | // ::= F # __export __thiscall | ||||
2725 | // ::= G # __stdcall | ||||
2726 | // ::= H # __export __stdcall | ||||
2727 | // ::= I # __fastcall | ||||
2728 | // ::= J # __export __fastcall | ||||
2729 | // ::= Q # __vectorcall | ||||
2730 | // ::= S # __attribute__((__swiftcall__)) // Clang-only | ||||
2731 | // ::= w # __regcall | ||||
2732 | // The 'export' calling conventions are from a bygone era | ||||
2733 | // (*cough*Win16*cough*) when functions were declared for export with | ||||
2734 | // that keyword. (It didn't actually export them, it just made them so | ||||
2735 | // that they could be in a DLL and somebody from another module could call | ||||
2736 | // them.) | ||||
2737 | |||||
2738 | switch (CC) { | ||||
2739 | default: | ||||
2740 | llvm_unreachable("Unsupported CC for mangling")::llvm::llvm_unreachable_internal("Unsupported CC for mangling" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 2740); | ||||
2741 | case CC_Win64: | ||||
2742 | case CC_X86_64SysV: | ||||
2743 | case CC_C: Out << 'A'; break; | ||||
2744 | case CC_X86Pascal: Out << 'C'; break; | ||||
2745 | case CC_X86ThisCall: Out << 'E'; break; | ||||
2746 | case CC_X86StdCall: Out << 'G'; break; | ||||
2747 | case CC_X86FastCall: Out << 'I'; break; | ||||
2748 | case CC_X86VectorCall: Out << 'Q'; break; | ||||
2749 | case CC_Swift: Out << 'S'; break; | ||||
2750 | case CC_PreserveMost: Out << 'U'; break; | ||||
2751 | case CC_X86RegCall: Out << 'w'; break; | ||||
2752 | } | ||||
2753 | } | ||||
2754 | void MicrosoftCXXNameMangler::mangleCallingConvention(const FunctionType *T) { | ||||
2755 | mangleCallingConvention(T->getCallConv()); | ||||
2756 | } | ||||
2757 | |||||
2758 | void MicrosoftCXXNameMangler::mangleThrowSpecification( | ||||
2759 | const FunctionProtoType *FT) { | ||||
2760 | // <throw-spec> ::= Z # (default) | ||||
2761 | // ::= _E # noexcept | ||||
2762 | if (FT->canThrow()) | ||||
2763 | Out << 'Z'; | ||||
2764 | else | ||||
2765 | Out << "_E"; | ||||
2766 | } | ||||
2767 | |||||
2768 | void MicrosoftCXXNameMangler::mangleType(const UnresolvedUsingType *T, | ||||
2769 | Qualifiers, SourceRange Range) { | ||||
2770 | // Probably should be mangled as a template instantiation; need to see what | ||||
2771 | // VC does first. | ||||
2772 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
2773 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | ||||
2774 | "cannot mangle this unresolved dependent type yet"); | ||||
2775 | Diags.Report(Range.getBegin(), DiagID) | ||||
2776 | << Range; | ||||
2777 | } | ||||
2778 | |||||
2779 | // <type> ::= <union-type> | <struct-type> | <class-type> | <enum-type> | ||||
2780 | // <union-type> ::= T <name> | ||||
2781 | // <struct-type> ::= U <name> | ||||
2782 | // <class-type> ::= V <name> | ||||
2783 | // <enum-type> ::= W4 <name> | ||||
2784 | void MicrosoftCXXNameMangler::mangleTagTypeKind(TagTypeKind TTK) { | ||||
2785 | switch (TTK) { | ||||
2786 | case TTK_Union: | ||||
2787 | Out << 'T'; | ||||
2788 | break; | ||||
2789 | case TTK_Struct: | ||||
2790 | case TTK_Interface: | ||||
2791 | Out << 'U'; | ||||
2792 | break; | ||||
2793 | case TTK_Class: | ||||
2794 | Out << 'V'; | ||||
2795 | break; | ||||
2796 | case TTK_Enum: | ||||
2797 | Out << "W4"; | ||||
2798 | break; | ||||
2799 | } | ||||
2800 | } | ||||
2801 | void MicrosoftCXXNameMangler::mangleType(const EnumType *T, Qualifiers, | ||||
2802 | SourceRange) { | ||||
2803 | mangleType(cast<TagType>(T)->getDecl()); | ||||
2804 | } | ||||
2805 | void MicrosoftCXXNameMangler::mangleType(const RecordType *T, Qualifiers, | ||||
2806 | SourceRange) { | ||||
2807 | mangleType(cast<TagType>(T)->getDecl()); | ||||
2808 | } | ||||
2809 | void MicrosoftCXXNameMangler::mangleType(const TagDecl *TD) { | ||||
2810 | mangleTagTypeKind(TD->getTagKind()); | ||||
2811 | mangleName(TD); | ||||
2812 | } | ||||
2813 | |||||
2814 | // If you add a call to this, consider updating isArtificialTagType() too. | ||||
2815 | void MicrosoftCXXNameMangler::mangleArtificialTagType( | ||||
2816 | TagTypeKind TK, StringRef UnqualifiedName, | ||||
2817 | ArrayRef<StringRef> NestedNames) { | ||||
2818 | // <name> ::= <unscoped-name> {[<named-scope>]+ | [<nested-name>]}? @ | ||||
2819 | mangleTagTypeKind(TK); | ||||
2820 | |||||
2821 | // Always start with the unqualified name. | ||||
2822 | mangleSourceName(UnqualifiedName); | ||||
2823 | |||||
2824 | for (auto I = NestedNames.rbegin(), E = NestedNames.rend(); I != E; ++I) | ||||
2825 | mangleSourceName(*I); | ||||
2826 | |||||
2827 | // Terminate the whole name with an '@'. | ||||
2828 | Out << '@'; | ||||
2829 | } | ||||
2830 | |||||
2831 | // <type> ::= <array-type> | ||||
2832 | // <array-type> ::= <pointer-cvr-qualifiers> <cvr-qualifiers> | ||||
2833 | // [Y <dimension-count> <dimension>+] | ||||
2834 | // <element-type> # as global, E is never required | ||||
2835 | // It's supposed to be the other way around, but for some strange reason, it | ||||
2836 | // isn't. Today this behavior is retained for the sole purpose of backwards | ||||
2837 | // compatibility. | ||||
2838 | void MicrosoftCXXNameMangler::mangleDecayedArrayType(const ArrayType *T) { | ||||
2839 | // This isn't a recursive mangling, so now we have to do it all in this | ||||
2840 | // one call. | ||||
2841 | manglePointerCVQualifiers(T->getElementType().getQualifiers()); | ||||
2842 | mangleType(T->getElementType(), SourceRange()); | ||||
2843 | } | ||||
2844 | void MicrosoftCXXNameMangler::mangleType(const ConstantArrayType *T, Qualifiers, | ||||
2845 | SourceRange) { | ||||
2846 | llvm_unreachable("Should have been special cased")::llvm::llvm_unreachable_internal("Should have been special cased" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 2846); | ||||
2847 | } | ||||
2848 | void MicrosoftCXXNameMangler::mangleType(const VariableArrayType *T, Qualifiers, | ||||
2849 | SourceRange) { | ||||
2850 | llvm_unreachable("Should have been special cased")::llvm::llvm_unreachable_internal("Should have been special cased" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 2850); | ||||
2851 | } | ||||
2852 | void MicrosoftCXXNameMangler::mangleType(const DependentSizedArrayType *T, | ||||
2853 | Qualifiers, SourceRange) { | ||||
2854 | llvm_unreachable("Should have been special cased")::llvm::llvm_unreachable_internal("Should have been special cased" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 2854); | ||||
2855 | } | ||||
2856 | void MicrosoftCXXNameMangler::mangleType(const IncompleteArrayType *T, | ||||
2857 | Qualifiers, SourceRange) { | ||||
2858 | llvm_unreachable("Should have been special cased")::llvm::llvm_unreachable_internal("Should have been special cased" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 2858); | ||||
2859 | } | ||||
2860 | void MicrosoftCXXNameMangler::mangleArrayType(const ArrayType *T) { | ||||
2861 | QualType ElementTy(T, 0); | ||||
2862 | SmallVector<llvm::APInt, 3> Dimensions; | ||||
2863 | for (;;) { | ||||
2864 | if (ElementTy->isConstantArrayType()) { | ||||
2865 | const ConstantArrayType *CAT = | ||||
2866 | getASTContext().getAsConstantArrayType(ElementTy); | ||||
2867 | Dimensions.push_back(CAT->getSize()); | ||||
2868 | ElementTy = CAT->getElementType(); | ||||
2869 | } else if (ElementTy->isIncompleteArrayType()) { | ||||
2870 | const IncompleteArrayType *IAT = | ||||
2871 | getASTContext().getAsIncompleteArrayType(ElementTy); | ||||
2872 | Dimensions.push_back(llvm::APInt(32, 0)); | ||||
2873 | ElementTy = IAT->getElementType(); | ||||
2874 | } else if (ElementTy->isVariableArrayType()) { | ||||
2875 | const VariableArrayType *VAT = | ||||
2876 | getASTContext().getAsVariableArrayType(ElementTy); | ||||
2877 | Dimensions.push_back(llvm::APInt(32, 0)); | ||||
2878 | ElementTy = VAT->getElementType(); | ||||
2879 | } else if (ElementTy->isDependentSizedArrayType()) { | ||||
2880 | // The dependent expression has to be folded into a constant (TODO). | ||||
2881 | const DependentSizedArrayType *DSAT = | ||||
2882 | getASTContext().getAsDependentSizedArrayType(ElementTy); | ||||
2883 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
2884 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | ||||
2885 | "cannot mangle this dependent-length array yet"); | ||||
2886 | Diags.Report(DSAT->getSizeExpr()->getExprLoc(), DiagID) | ||||
2887 | << DSAT->getBracketsRange(); | ||||
2888 | return; | ||||
2889 | } else { | ||||
2890 | break; | ||||
2891 | } | ||||
2892 | } | ||||
2893 | Out << 'Y'; | ||||
2894 | // <dimension-count> ::= <number> # number of extra dimensions | ||||
2895 | mangleNumber(Dimensions.size()); | ||||
2896 | for (const llvm::APInt &Dimension : Dimensions) | ||||
2897 | mangleNumber(Dimension.getLimitedValue()); | ||||
2898 | mangleType(ElementTy, SourceRange(), QMM_Escape); | ||||
2899 | } | ||||
2900 | |||||
2901 | // <type> ::= <pointer-to-member-type> | ||||
2902 | // <pointer-to-member-type> ::= <pointer-cvr-qualifiers> <cvr-qualifiers> | ||||
2903 | // <class name> <type> | ||||
2904 | void MicrosoftCXXNameMangler::mangleType(const MemberPointerType *T, | ||||
2905 | Qualifiers Quals, SourceRange Range) { | ||||
2906 | QualType PointeeType = T->getPointeeType(); | ||||
2907 | manglePointerCVQualifiers(Quals); | ||||
2908 | manglePointerExtQualifiers(Quals, PointeeType); | ||||
2909 | if (const FunctionProtoType *FPT = PointeeType->getAs<FunctionProtoType>()) { | ||||
2910 | Out << '8'; | ||||
2911 | mangleName(T->getClass()->castAs<RecordType>()->getDecl()); | ||||
2912 | mangleFunctionType(FPT, nullptr, true); | ||||
2913 | } else { | ||||
2914 | mangleQualifiers(PointeeType.getQualifiers(), true); | ||||
2915 | mangleName(T->getClass()->castAs<RecordType>()->getDecl()); | ||||
2916 | mangleType(PointeeType, Range, QMM_Drop); | ||||
2917 | } | ||||
2918 | } | ||||
2919 | |||||
2920 | void MicrosoftCXXNameMangler::mangleType(const TemplateTypeParmType *T, | ||||
2921 | Qualifiers, SourceRange Range) { | ||||
2922 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
2923 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | ||||
2924 | "cannot mangle this template type parameter type yet"); | ||||
2925 | Diags.Report(Range.getBegin(), DiagID) | ||||
2926 | << Range; | ||||
2927 | } | ||||
2928 | |||||
2929 | void MicrosoftCXXNameMangler::mangleType(const SubstTemplateTypeParmPackType *T, | ||||
2930 | Qualifiers, SourceRange Range) { | ||||
2931 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
2932 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | ||||
2933 | "cannot mangle this substituted parameter pack yet"); | ||||
2934 | Diags.Report(Range.getBegin(), DiagID) | ||||
2935 | << Range; | ||||
2936 | } | ||||
2937 | |||||
2938 | // <type> ::= <pointer-type> | ||||
2939 | // <pointer-type> ::= E? <pointer-cvr-qualifiers> <cvr-qualifiers> <type> | ||||
2940 | // # the E is required for 64-bit non-static pointers | ||||
2941 | void MicrosoftCXXNameMangler::mangleType(const PointerType *T, Qualifiers Quals, | ||||
2942 | SourceRange Range) { | ||||
2943 | QualType PointeeType = T->getPointeeType(); | ||||
2944 | manglePointerCVQualifiers(Quals); | ||||
2945 | manglePointerExtQualifiers(Quals, PointeeType); | ||||
2946 | |||||
2947 | // For pointer size address spaces, go down the same type mangling path as | ||||
2948 | // non address space types. | ||||
2949 | LangAS AddrSpace = PointeeType.getQualifiers().getAddressSpace(); | ||||
2950 | if (isPtrSizeAddressSpace(AddrSpace) || AddrSpace == LangAS::Default) | ||||
2951 | mangleType(PointeeType, Range); | ||||
2952 | else | ||||
2953 | mangleAddressSpaceType(PointeeType, PointeeType.getQualifiers(), Range); | ||||
2954 | } | ||||
2955 | |||||
2956 | void MicrosoftCXXNameMangler::mangleType(const ObjCObjectPointerType *T, | ||||
2957 | Qualifiers Quals, SourceRange Range) { | ||||
2958 | QualType PointeeType = T->getPointeeType(); | ||||
2959 | switch (Quals.getObjCLifetime()) { | ||||
2960 | case Qualifiers::OCL_None: | ||||
2961 | case Qualifiers::OCL_ExplicitNone: | ||||
2962 | break; | ||||
2963 | case Qualifiers::OCL_Autoreleasing: | ||||
2964 | case Qualifiers::OCL_Strong: | ||||
2965 | case Qualifiers::OCL_Weak: | ||||
2966 | return mangleObjCLifetime(PointeeType, Quals, Range); | ||||
2967 | } | ||||
2968 | manglePointerCVQualifiers(Quals); | ||||
2969 | manglePointerExtQualifiers(Quals, PointeeType); | ||||
2970 | mangleType(PointeeType, Range); | ||||
2971 | } | ||||
2972 | |||||
2973 | // <type> ::= <reference-type> | ||||
2974 | // <reference-type> ::= A E? <cvr-qualifiers> <type> | ||||
2975 | // # the E is required for 64-bit non-static lvalue references | ||||
2976 | void MicrosoftCXXNameMangler::mangleType(const LValueReferenceType *T, | ||||
2977 | Qualifiers Quals, SourceRange Range) { | ||||
2978 | QualType PointeeType = T->getPointeeType(); | ||||
2979 | assert(!Quals.hasConst() && !Quals.hasVolatile() && "unexpected qualifier!")((!Quals.hasConst() && !Quals.hasVolatile() && "unexpected qualifier!") ? static_cast<void> (0) : __assert_fail ("!Quals.hasConst() && !Quals.hasVolatile() && \"unexpected qualifier!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 2979, __PRETTY_FUNCTION__)); | ||||
2980 | Out << 'A'; | ||||
2981 | manglePointerExtQualifiers(Quals, PointeeType); | ||||
2982 | mangleType(PointeeType, Range); | ||||
2983 | } | ||||
2984 | |||||
2985 | // <type> ::= <r-value-reference-type> | ||||
2986 | // <r-value-reference-type> ::= $$Q E? <cvr-qualifiers> <type> | ||||
2987 | // # the E is required for 64-bit non-static rvalue references | ||||
2988 | void MicrosoftCXXNameMangler::mangleType(const RValueReferenceType *T, | ||||
2989 | Qualifiers Quals, SourceRange Range) { | ||||
2990 | QualType PointeeType = T->getPointeeType(); | ||||
2991 | assert(!Quals.hasConst() && !Quals.hasVolatile() && "unexpected qualifier!")((!Quals.hasConst() && !Quals.hasVolatile() && "unexpected qualifier!") ? static_cast<void> (0) : __assert_fail ("!Quals.hasConst() && !Quals.hasVolatile() && \"unexpected qualifier!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 2991, __PRETTY_FUNCTION__)); | ||||
2992 | Out << "$$Q"; | ||||
2993 | manglePointerExtQualifiers(Quals, PointeeType); | ||||
2994 | mangleType(PointeeType, Range); | ||||
2995 | } | ||||
2996 | |||||
2997 | void MicrosoftCXXNameMangler::mangleType(const ComplexType *T, Qualifiers, | ||||
2998 | SourceRange Range) { | ||||
2999 | QualType ElementType = T->getElementType(); | ||||
3000 | |||||
3001 | llvm::SmallString<64> TemplateMangling; | ||||
3002 | llvm::raw_svector_ostream Stream(TemplateMangling); | ||||
3003 | MicrosoftCXXNameMangler Extra(Context, Stream); | ||||
3004 | Stream << "?$"; | ||||
3005 | Extra.mangleSourceName("_Complex"); | ||||
3006 | Extra.mangleType(ElementType, Range, QMM_Escape); | ||||
3007 | |||||
3008 | mangleArtificialTagType(TTK_Struct, TemplateMangling, {"__clang"}); | ||||
3009 | } | ||||
3010 | |||||
3011 | // Returns true for types that mangleArtificialTagType() gets called for with | ||||
3012 | // TTK_Union, TTK_Struct, TTK_Class and where compatibility with MSVC's | ||||
3013 | // mangling matters. | ||||
3014 | // (It doesn't matter for Objective-C types and the like that cl.exe doesn't | ||||
3015 | // support.) | ||||
3016 | bool MicrosoftCXXNameMangler::isArtificialTagType(QualType T) const { | ||||
3017 | const Type *ty = T.getTypePtr(); | ||||
3018 | switch (ty->getTypeClass()) { | ||||
3019 | default: | ||||
3020 | return false; | ||||
3021 | |||||
3022 | case Type::Vector: { | ||||
3023 | // For ABI compatibility only __m64, __m128(id), and __m256(id) matter, | ||||
3024 | // but since mangleType(VectorType*) always calls mangleArtificialTagType() | ||||
3025 | // just always return true (the other vector types are clang-only). | ||||
3026 | return true; | ||||
3027 | } | ||||
3028 | } | ||||
3029 | } | ||||
3030 | |||||
3031 | void MicrosoftCXXNameMangler::mangleType(const VectorType *T, Qualifiers Quals, | ||||
3032 | SourceRange Range) { | ||||
3033 | const BuiltinType *ET = T->getElementType()->getAs<BuiltinType>(); | ||||
3034 | assert(ET && "vectors with non-builtin elements are unsupported")((ET && "vectors with non-builtin elements are unsupported" ) ? static_cast<void> (0) : __assert_fail ("ET && \"vectors with non-builtin elements are unsupported\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 3034, __PRETTY_FUNCTION__)); | ||||
3035 | uint64_t Width = getASTContext().getTypeSize(T); | ||||
3036 | // Pattern match exactly the typedefs in our intrinsic headers. Anything that | ||||
3037 | // doesn't match the Intel types uses a custom mangling below. | ||||
3038 | size_t OutSizeBefore = Out.tell(); | ||||
3039 | if (!isa<ExtVectorType>(T)) { | ||||
3040 | if (getASTContext().getTargetInfo().getTriple().isX86()) { | ||||
3041 | if (Width == 64 && ET->getKind() == BuiltinType::LongLong) { | ||||
3042 | mangleArtificialTagType(TTK_Union, "__m64"); | ||||
3043 | } else if (Width >= 128) { | ||||
3044 | if (ET->getKind() == BuiltinType::Float) | ||||
3045 | mangleArtificialTagType(TTK_Union, "__m" + llvm::utostr(Width)); | ||||
3046 | else if (ET->getKind() == BuiltinType::LongLong) | ||||
3047 | mangleArtificialTagType(TTK_Union, "__m" + llvm::utostr(Width) + 'i'); | ||||
3048 | else if (ET->getKind() == BuiltinType::Double) | ||||
3049 | mangleArtificialTagType(TTK_Struct, "__m" + llvm::utostr(Width) + 'd'); | ||||
3050 | } | ||||
3051 | } | ||||
3052 | } | ||||
3053 | |||||
3054 | bool IsBuiltin = Out.tell() != OutSizeBefore; | ||||
3055 | if (!IsBuiltin) { | ||||
3056 | // The MS ABI doesn't have a special mangling for vector types, so we define | ||||
3057 | // our own mangling to handle uses of __vector_size__ on user-specified | ||||
3058 | // types, and for extensions like __v4sf. | ||||
3059 | |||||
3060 | llvm::SmallString<64> TemplateMangling; | ||||
3061 | llvm::raw_svector_ostream Stream(TemplateMangling); | ||||
3062 | MicrosoftCXXNameMangler Extra(Context, Stream); | ||||
3063 | Stream << "?$"; | ||||
3064 | Extra.mangleSourceName("__vector"); | ||||
3065 | Extra.mangleType(QualType(ET, 0), Range, QMM_Escape); | ||||
3066 | Extra.mangleIntegerLiteral(llvm::APSInt::getUnsigned(T->getNumElements())); | ||||
3067 | |||||
3068 | mangleArtificialTagType(TTK_Union, TemplateMangling, {"__clang"}); | ||||
3069 | } | ||||
3070 | } | ||||
3071 | |||||
3072 | void MicrosoftCXXNameMangler::mangleType(const ExtVectorType *T, | ||||
3073 | Qualifiers Quals, SourceRange Range) { | ||||
3074 | mangleType(static_cast<const VectorType *>(T), Quals, Range); | ||||
3075 | } | ||||
3076 | |||||
3077 | void MicrosoftCXXNameMangler::mangleType(const DependentVectorType *T, | ||||
3078 | Qualifiers, SourceRange Range) { | ||||
3079 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
3080 | unsigned DiagID = Diags.getCustomDiagID( | ||||
3081 | DiagnosticsEngine::Error, | ||||
3082 | "cannot mangle this dependent-sized vector type yet"); | ||||
3083 | Diags.Report(Range.getBegin(), DiagID) << Range; | ||||
3084 | } | ||||
3085 | |||||
3086 | void MicrosoftCXXNameMangler::mangleType(const DependentSizedExtVectorType *T, | ||||
3087 | Qualifiers, SourceRange Range) { | ||||
3088 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
3089 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | ||||
3090 | "cannot mangle this dependent-sized extended vector type yet"); | ||||
3091 | Diags.Report(Range.getBegin(), DiagID) | ||||
3092 | << Range; | ||||
3093 | } | ||||
3094 | |||||
3095 | void MicrosoftCXXNameMangler::mangleType(const ConstantMatrixType *T, | ||||
3096 | Qualifiers quals, SourceRange Range) { | ||||
3097 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
3098 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | ||||
3099 | "Cannot mangle this matrix type yet"); | ||||
3100 | Diags.Report(Range.getBegin(), DiagID) << Range; | ||||
3101 | } | ||||
3102 | |||||
3103 | void MicrosoftCXXNameMangler::mangleType(const DependentSizedMatrixType *T, | ||||
3104 | Qualifiers quals, SourceRange Range) { | ||||
3105 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
3106 | unsigned DiagID = Diags.getCustomDiagID( | ||||
3107 | DiagnosticsEngine::Error, | ||||
3108 | "Cannot mangle this dependent-sized matrix type yet"); | ||||
3109 | Diags.Report(Range.getBegin(), DiagID) << Range; | ||||
3110 | } | ||||
3111 | |||||
3112 | void MicrosoftCXXNameMangler::mangleType(const DependentAddressSpaceType *T, | ||||
3113 | Qualifiers, SourceRange Range) { | ||||
3114 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
3115 | unsigned DiagID = Diags.getCustomDiagID( | ||||
3116 | DiagnosticsEngine::Error, | ||||
3117 | "cannot mangle this dependent address space type yet"); | ||||
3118 | Diags.Report(Range.getBegin(), DiagID) << Range; | ||||
3119 | } | ||||
3120 | |||||
3121 | void MicrosoftCXXNameMangler::mangleType(const ObjCInterfaceType *T, Qualifiers, | ||||
3122 | SourceRange) { | ||||
3123 | // ObjC interfaces have structs underlying them. | ||||
3124 | mangleTagTypeKind(TTK_Struct); | ||||
3125 | mangleName(T->getDecl()); | ||||
3126 | } | ||||
3127 | |||||
3128 | void MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *T, | ||||
3129 | Qualifiers Quals, SourceRange Range) { | ||||
3130 | if (T->isKindOfType()) | ||||
3131 | return mangleObjCKindOfType(T, Quals, Range); | ||||
3132 | |||||
3133 | if (T->qual_empty() && !T->isSpecialized()) | ||||
3134 | return mangleType(T->getBaseType(), Range, QMM_Drop); | ||||
3135 | |||||
3136 | ArgBackRefMap OuterFunArgsContext; | ||||
3137 | ArgBackRefMap OuterTemplateArgsContext; | ||||
3138 | BackRefVec OuterTemplateContext; | ||||
3139 | |||||
3140 | FunArgBackReferences.swap(OuterFunArgsContext); | ||||
3141 | TemplateArgBackReferences.swap(OuterTemplateArgsContext); | ||||
3142 | NameBackReferences.swap(OuterTemplateContext); | ||||
3143 | |||||
3144 | mangleTagTypeKind(TTK_Struct); | ||||
3145 | |||||
3146 | Out << "?$"; | ||||
3147 | if (T->isObjCId()) | ||||
3148 | mangleSourceName("objc_object"); | ||||
3149 | else if (T->isObjCClass()) | ||||
3150 | mangleSourceName("objc_class"); | ||||
3151 | else | ||||
3152 | mangleSourceName(T->getInterface()->getName()); | ||||
3153 | |||||
3154 | for (const auto &Q : T->quals()) | ||||
3155 | mangleObjCProtocol(Q); | ||||
3156 | |||||
3157 | if (T->isSpecialized()) | ||||
3158 | for (const auto &TA : T->getTypeArgs()) | ||||
3159 | mangleType(TA, Range, QMM_Drop); | ||||
3160 | |||||
3161 | Out << '@'; | ||||
3162 | |||||
3163 | Out << '@'; | ||||
3164 | |||||
3165 | FunArgBackReferences.swap(OuterFunArgsContext); | ||||
3166 | TemplateArgBackReferences.swap(OuterTemplateArgsContext); | ||||
3167 | NameBackReferences.swap(OuterTemplateContext); | ||||
3168 | } | ||||
3169 | |||||
3170 | void MicrosoftCXXNameMangler::mangleType(const BlockPointerType *T, | ||||
3171 | Qualifiers Quals, SourceRange Range) { | ||||
3172 | QualType PointeeType = T->getPointeeType(); | ||||
3173 | manglePointerCVQualifiers(Quals); | ||||
3174 | manglePointerExtQualifiers(Quals, PointeeType); | ||||
3175 | |||||
3176 | Out << "_E"; | ||||
3177 | |||||
3178 | mangleFunctionType(PointeeType->castAs<FunctionProtoType>()); | ||||
3179 | } | ||||
3180 | |||||
3181 | void MicrosoftCXXNameMangler::mangleType(const InjectedClassNameType *, | ||||
3182 | Qualifiers, SourceRange) { | ||||
3183 | llvm_unreachable("Cannot mangle injected class name type.")::llvm::llvm_unreachable_internal("Cannot mangle injected class name type." , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 3183); | ||||
3184 | } | ||||
3185 | |||||
3186 | void MicrosoftCXXNameMangler::mangleType(const TemplateSpecializationType *T, | ||||
3187 | Qualifiers, SourceRange Range) { | ||||
3188 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
3189 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | ||||
3190 | "cannot mangle this template specialization type yet"); | ||||
3191 | Diags.Report(Range.getBegin(), DiagID) | ||||
3192 | << Range; | ||||
3193 | } | ||||
3194 | |||||
3195 | void MicrosoftCXXNameMangler::mangleType(const DependentNameType *T, Qualifiers, | ||||
3196 | SourceRange Range) { | ||||
3197 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
3198 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | ||||
3199 | "cannot mangle this dependent name type yet"); | ||||
3200 | Diags.Report(Range.getBegin(), DiagID) | ||||
3201 | << Range; | ||||
3202 | } | ||||
3203 | |||||
3204 | void MicrosoftCXXNameMangler::mangleType( | ||||
3205 | const DependentTemplateSpecializationType *T, Qualifiers, | ||||
3206 | SourceRange Range) { | ||||
3207 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
3208 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | ||||
3209 | "cannot mangle this dependent template specialization type yet"); | ||||
3210 | Diags.Report(Range.getBegin(), DiagID) | ||||
3211 | << Range; | ||||
3212 | } | ||||
3213 | |||||
3214 | void MicrosoftCXXNameMangler::mangleType(const PackExpansionType *T, Qualifiers, | ||||
3215 | SourceRange Range) { | ||||
3216 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
3217 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | ||||
3218 | "cannot mangle this pack expansion yet"); | ||||
3219 | Diags.Report(Range.getBegin(), DiagID) | ||||
3220 | << Range; | ||||
3221 | } | ||||
3222 | |||||
3223 | void MicrosoftCXXNameMangler::mangleType(const TypeOfType *T, Qualifiers, | ||||
3224 | SourceRange Range) { | ||||
3225 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
3226 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | ||||
3227 | "cannot mangle this typeof(type) yet"); | ||||
3228 | Diags.Report(Range.getBegin(), DiagID) | ||||
3229 | << Range; | ||||
3230 | } | ||||
3231 | |||||
3232 | void MicrosoftCXXNameMangler::mangleType(const TypeOfExprType *T, Qualifiers, | ||||
3233 | SourceRange Range) { | ||||
3234 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
3235 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | ||||
3236 | "cannot mangle this typeof(expression) yet"); | ||||
3237 | Diags.Report(Range.getBegin(), DiagID) | ||||
3238 | << Range; | ||||
3239 | } | ||||
3240 | |||||
3241 | void MicrosoftCXXNameMangler::mangleType(const DecltypeType *T, Qualifiers, | ||||
3242 | SourceRange Range) { | ||||
3243 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
3244 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | ||||
3245 | "cannot mangle this decltype() yet"); | ||||
3246 | Diags.Report(Range.getBegin(), DiagID) | ||||
3247 | << Range; | ||||
3248 | } | ||||
3249 | |||||
3250 | void MicrosoftCXXNameMangler::mangleType(const UnaryTransformType *T, | ||||
3251 | Qualifiers, SourceRange Range) { | ||||
3252 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
3253 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | ||||
3254 | "cannot mangle this unary transform type yet"); | ||||
3255 | Diags.Report(Range.getBegin(), DiagID) | ||||
3256 | << Range; | ||||
3257 | } | ||||
3258 | |||||
3259 | void MicrosoftCXXNameMangler::mangleType(const AutoType *T, Qualifiers, | ||||
3260 | SourceRange Range) { | ||||
3261 | assert(T->getDeducedType().isNull() && "expecting a dependent type!")((T->getDeducedType().isNull() && "expecting a dependent type!" ) ? static_cast<void> (0) : __assert_fail ("T->getDeducedType().isNull() && \"expecting a dependent type!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 3261, __PRETTY_FUNCTION__)); | ||||
3262 | |||||
3263 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
3264 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | ||||
3265 | "cannot mangle this 'auto' type yet"); | ||||
3266 | Diags.Report(Range.getBegin(), DiagID) | ||||
3267 | << Range; | ||||
3268 | } | ||||
3269 | |||||
3270 | void MicrosoftCXXNameMangler::mangleType( | ||||
3271 | const DeducedTemplateSpecializationType *T, Qualifiers, SourceRange Range) { | ||||
3272 | assert(T->getDeducedType().isNull() && "expecting a dependent type!")((T->getDeducedType().isNull() && "expecting a dependent type!" ) ? static_cast<void> (0) : __assert_fail ("T->getDeducedType().isNull() && \"expecting a dependent type!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 3272, __PRETTY_FUNCTION__)); | ||||
3273 | |||||
3274 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
3275 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | ||||
3276 | "cannot mangle this deduced class template specialization type yet"); | ||||
3277 | Diags.Report(Range.getBegin(), DiagID) | ||||
3278 | << Range; | ||||
3279 | } | ||||
3280 | |||||
3281 | void MicrosoftCXXNameMangler::mangleType(const AtomicType *T, Qualifiers, | ||||
3282 | SourceRange Range) { | ||||
3283 | QualType ValueType = T->getValueType(); | ||||
3284 | |||||
3285 | llvm::SmallString<64> TemplateMangling; | ||||
3286 | llvm::raw_svector_ostream Stream(TemplateMangling); | ||||
3287 | MicrosoftCXXNameMangler Extra(Context, Stream); | ||||
3288 | Stream << "?$"; | ||||
3289 | Extra.mangleSourceName("_Atomic"); | ||||
3290 | Extra.mangleType(ValueType, Range, QMM_Escape); | ||||
3291 | |||||
3292 | mangleArtificialTagType(TTK_Struct, TemplateMangling, {"__clang"}); | ||||
3293 | } | ||||
3294 | |||||
3295 | void MicrosoftCXXNameMangler::mangleType(const PipeType *T, Qualifiers, | ||||
3296 | SourceRange Range) { | ||||
3297 | QualType ElementType = T->getElementType(); | ||||
3298 | |||||
3299 | llvm::SmallString<64> TemplateMangling; | ||||
3300 | llvm::raw_svector_ostream Stream(TemplateMangling); | ||||
3301 | MicrosoftCXXNameMangler Extra(Context, Stream); | ||||
3302 | Stream << "?$"; | ||||
3303 | Extra.mangleSourceName("ocl_pipe"); | ||||
3304 | Extra.mangleType(ElementType, Range, QMM_Escape); | ||||
3305 | Extra.mangleIntegerLiteral(llvm::APSInt::get(T->isReadOnly())); | ||||
3306 | |||||
3307 | mangleArtificialTagType(TTK_Struct, TemplateMangling, {"__clang"}); | ||||
3308 | } | ||||
3309 | |||||
3310 | void MicrosoftMangleContextImpl::mangleCXXName(GlobalDecl GD, | ||||
3311 | raw_ostream &Out) { | ||||
3312 | const NamedDecl *D = cast<NamedDecl>(GD.getDecl()); | ||||
3313 | PrettyStackTraceDecl CrashInfo(D, SourceLocation(), | ||||
3314 | getASTContext().getSourceManager(), | ||||
3315 | "Mangling declaration"); | ||||
3316 | |||||
3317 | msvc_hashing_ostream MHO(Out); | ||||
3318 | |||||
3319 | if (auto *CD = dyn_cast<CXXConstructorDecl>(D)) { | ||||
3320 | auto Type = GD.getCtorType(); | ||||
3321 | MicrosoftCXXNameMangler mangler(*this, MHO, CD, Type); | ||||
3322 | return mangler.mangle(D); | ||||
3323 | } | ||||
3324 | |||||
3325 | if (auto *DD = dyn_cast<CXXDestructorDecl>(D)) { | ||||
3326 | auto Type = GD.getDtorType(); | ||||
3327 | MicrosoftCXXNameMangler mangler(*this, MHO, DD, Type); | ||||
3328 | return mangler.mangle(D); | ||||
3329 | } | ||||
3330 | |||||
3331 | MicrosoftCXXNameMangler Mangler(*this, MHO); | ||||
3332 | return Mangler.mangle(D); | ||||
3333 | } | ||||
3334 | |||||
3335 | void MicrosoftCXXNameMangler::mangleType(const ExtIntType *T, Qualifiers, | ||||
3336 | SourceRange Range) { | ||||
3337 | llvm::SmallString<64> TemplateMangling; | ||||
3338 | llvm::raw_svector_ostream Stream(TemplateMangling); | ||||
3339 | MicrosoftCXXNameMangler Extra(Context, Stream); | ||||
3340 | Stream << "?$"; | ||||
3341 | if (T->isUnsigned()) | ||||
3342 | Extra.mangleSourceName("_UExtInt"); | ||||
3343 | else | ||||
3344 | Extra.mangleSourceName("_ExtInt"); | ||||
3345 | Extra.mangleIntegerLiteral(llvm::APSInt::getUnsigned(T->getNumBits())); | ||||
3346 | |||||
3347 | mangleArtificialTagType(TTK_Struct, TemplateMangling, {"__clang"}); | ||||
3348 | } | ||||
3349 | |||||
3350 | void MicrosoftCXXNameMangler::mangleType(const DependentExtIntType *T, | ||||
3351 | Qualifiers, SourceRange Range) { | ||||
3352 | DiagnosticsEngine &Diags = Context.getDiags(); | ||||
3353 | unsigned DiagID = Diags.getCustomDiagID( | ||||
3354 | DiagnosticsEngine::Error, "cannot mangle this DependentExtInt type yet"); | ||||
3355 | Diags.Report(Range.getBegin(), DiagID) << Range; | ||||
3356 | } | ||||
3357 | |||||
3358 | // <this-adjustment> ::= <no-adjustment> | <static-adjustment> | | ||||
3359 | // <virtual-adjustment> | ||||
3360 | // <no-adjustment> ::= A # private near | ||||
3361 | // ::= B # private far | ||||
3362 | // ::= I # protected near | ||||
3363 | // ::= J # protected far | ||||
3364 | // ::= Q # public near | ||||
3365 | // ::= R # public far | ||||
3366 | // <static-adjustment> ::= G <static-offset> # private near | ||||
3367 | // ::= H <static-offset> # private far | ||||
3368 | // ::= O <static-offset> # protected near | ||||
3369 | // ::= P <static-offset> # protected far | ||||
3370 | // ::= W <static-offset> # public near | ||||
3371 | // ::= X <static-offset> # public far | ||||
3372 | // <virtual-adjustment> ::= $0 <virtual-shift> <static-offset> # private near | ||||
3373 | // ::= $1 <virtual-shift> <static-offset> # private far | ||||
3374 | // ::= $2 <virtual-shift> <static-offset> # protected near | ||||
3375 | // ::= $3 <virtual-shift> <static-offset> # protected far | ||||
3376 | // ::= $4 <virtual-shift> <static-offset> # public near | ||||
3377 | // ::= $5 <virtual-shift> <static-offset> # public far | ||||
3378 | // <virtual-shift> ::= <vtordisp-shift> | <vtordispex-shift> | ||||
3379 | // <vtordisp-shift> ::= <offset-to-vtordisp> | ||||
3380 | // <vtordispex-shift> ::= <offset-to-vbptr> <vbase-offset-offset> | ||||
3381 | // <offset-to-vtordisp> | ||||
3382 | static void mangleThunkThisAdjustment(AccessSpecifier AS, | ||||
3383 | const ThisAdjustment &Adjustment, | ||||
3384 | MicrosoftCXXNameMangler &Mangler, | ||||
3385 | raw_ostream &Out) { | ||||
3386 | if (!Adjustment.Virtual.isEmpty()) { | ||||
3387 | Out << '$'; | ||||
3388 | char AccessSpec; | ||||
3389 | switch (AS) { | ||||
3390 | case AS_none: | ||||
3391 | llvm_unreachable("Unsupported access specifier")::llvm::llvm_unreachable_internal("Unsupported access specifier" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 3391); | ||||
3392 | case AS_private: | ||||
3393 | AccessSpec = '0'; | ||||
3394 | break; | ||||
3395 | case AS_protected: | ||||
3396 | AccessSpec = '2'; | ||||
3397 | break; | ||||
3398 | case AS_public: | ||||
3399 | AccessSpec = '4'; | ||||
3400 | } | ||||
3401 | if (Adjustment.Virtual.Microsoft.VBPtrOffset) { | ||||
3402 | Out << 'R' << AccessSpec; | ||||
3403 | Mangler.mangleNumber( | ||||
3404 | static_cast<uint32_t>(Adjustment.Virtual.Microsoft.VBPtrOffset)); | ||||
3405 | Mangler.mangleNumber( | ||||
3406 | static_cast<uint32_t>(Adjustment.Virtual.Microsoft.VBOffsetOffset)); | ||||
3407 | Mangler.mangleNumber( | ||||
3408 | static_cast<uint32_t>(Adjustment.Virtual.Microsoft.VtordispOffset)); | ||||
3409 | Mangler.mangleNumber(static_cast<uint32_t>(Adjustment.NonVirtual)); | ||||
3410 | } else { | ||||
3411 | Out << AccessSpec; | ||||
3412 | Mangler.mangleNumber( | ||||
3413 | static_cast<uint32_t>(Adjustment.Virtual.Microsoft.VtordispOffset)); | ||||
3414 | Mangler.mangleNumber(-static_cast<uint32_t>(Adjustment.NonVirtual)); | ||||
3415 | } | ||||
3416 | } else if (Adjustment.NonVirtual != 0) { | ||||
3417 | switch (AS) { | ||||
3418 | case AS_none: | ||||
3419 | llvm_unreachable("Unsupported access specifier")::llvm::llvm_unreachable_internal("Unsupported access specifier" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 3419); | ||||
3420 | case AS_private: | ||||
3421 | Out << 'G'; | ||||
3422 | break; | ||||
3423 | case AS_protected: | ||||
3424 | Out << 'O'; | ||||
3425 | break; | ||||
3426 | case AS_public: | ||||
3427 | Out << 'W'; | ||||
3428 | } | ||||
3429 | Mangler.mangleNumber(-static_cast<uint32_t>(Adjustment.NonVirtual)); | ||||
3430 | } else { | ||||
3431 | switch (AS) { | ||||
3432 | case AS_none: | ||||
3433 | llvm_unreachable("Unsupported access specifier")::llvm::llvm_unreachable_internal("Unsupported access specifier" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 3433); | ||||
3434 | case AS_private: | ||||
3435 | Out << 'A'; | ||||
3436 | break; | ||||
3437 | case AS_protected: | ||||
3438 | Out << 'I'; | ||||
3439 | break; | ||||
3440 | case AS_public: | ||||
3441 | Out << 'Q'; | ||||
3442 | } | ||||
3443 | } | ||||
3444 | } | ||||
3445 | |||||
3446 | void MicrosoftMangleContextImpl::mangleVirtualMemPtrThunk( | ||||
3447 | const CXXMethodDecl *MD, const MethodVFTableLocation &ML, | ||||
3448 | raw_ostream &Out) { | ||||
3449 | msvc_hashing_ostream MHO(Out); | ||||
3450 | MicrosoftCXXNameMangler Mangler(*this, MHO); | ||||
3451 | Mangler.getStream() << '?'; | ||||
3452 | Mangler.mangleVirtualMemPtrThunk(MD, ML); | ||||
3453 | } | ||||
3454 | |||||
3455 | void MicrosoftMangleContextImpl::mangleThunk(const CXXMethodDecl *MD, | ||||
3456 | const ThunkInfo &Thunk, | ||||
3457 | raw_ostream &Out) { | ||||
3458 | msvc_hashing_ostream MHO(Out); | ||||
3459 | MicrosoftCXXNameMangler Mangler(*this, MHO); | ||||
3460 | Mangler.getStream() << '?'; | ||||
3461 | Mangler.mangleName(MD); | ||||
3462 | |||||
3463 | // Usually the thunk uses the access specifier of the new method, but if this | ||||
3464 | // is a covariant return thunk, then MSVC always uses the public access | ||||
3465 | // specifier, and we do the same. | ||||
3466 | AccessSpecifier AS = Thunk.Return.isEmpty() ? MD->getAccess() : AS_public; | ||||
3467 | mangleThunkThisAdjustment(AS, Thunk.This, Mangler, MHO); | ||||
3468 | |||||
3469 | if (!Thunk.Return.isEmpty()) | ||||
3470 | assert(Thunk.Method != nullptr &&((Thunk.Method != nullptr && "Thunk info should hold the overridee decl" ) ? static_cast<void> (0) : __assert_fail ("Thunk.Method != nullptr && \"Thunk info should hold the overridee decl\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 3471, __PRETTY_FUNCTION__)) | ||||
3471 | "Thunk info should hold the overridee decl")((Thunk.Method != nullptr && "Thunk info should hold the overridee decl" ) ? static_cast<void> (0) : __assert_fail ("Thunk.Method != nullptr && \"Thunk info should hold the overridee decl\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 3471, __PRETTY_FUNCTION__)); | ||||
3472 | |||||
3473 | const CXXMethodDecl *DeclForFPT = Thunk.Method ? Thunk.Method : MD; | ||||
3474 | Mangler.mangleFunctionType( | ||||
3475 | DeclForFPT->getType()->castAs<FunctionProtoType>(), MD); | ||||
3476 | } | ||||
3477 | |||||
3478 | void MicrosoftMangleContextImpl::mangleCXXDtorThunk( | ||||
3479 | const CXXDestructorDecl *DD, CXXDtorType Type, | ||||
3480 | const ThisAdjustment &Adjustment, raw_ostream &Out) { | ||||
3481 | // FIXME: Actually, the dtor thunk should be emitted for vector deleting | ||||
3482 | // dtors rather than scalar deleting dtors. Just use the vector deleting dtor | ||||
3483 | // mangling manually until we support both deleting dtor types. | ||||
3484 | assert(Type == Dtor_Deleting)((Type == Dtor_Deleting) ? static_cast<void> (0) : __assert_fail ("Type == Dtor_Deleting", "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 3484, __PRETTY_FUNCTION__)); | ||||
| |||||
3485 | msvc_hashing_ostream MHO(Out); | ||||
3486 | MicrosoftCXXNameMangler Mangler(*this, MHO, DD, Type); | ||||
3487 | Mangler.getStream() << "??_E"; | ||||
3488 | Mangler.mangleName(DD->getParent()); | ||||
3489 | mangleThunkThisAdjustment(DD->getAccess(), Adjustment, Mangler, MHO); | ||||
3490 | Mangler.mangleFunctionType(DD->getType()->castAs<FunctionProtoType>(), DD); | ||||
3491 | } | ||||
3492 | |||||
3493 | void MicrosoftMangleContextImpl::mangleCXXVFTable( | ||||
3494 | const CXXRecordDecl *Derived, ArrayRef<const CXXRecordDecl *> BasePath, | ||||
3495 | raw_ostream &Out) { | ||||
3496 | // <mangled-name> ::= ?_7 <class-name> <storage-class> | ||||
3497 | // <cvr-qualifiers> [<name>] @ | ||||
3498 | // NOTE: <cvr-qualifiers> here is always 'B' (const). <storage-class> | ||||
3499 | // is always '6' for vftables. | ||||
3500 | msvc_hashing_ostream MHO(Out); | ||||
3501 | MicrosoftCXXNameMangler Mangler(*this, MHO); | ||||
3502 | if (Derived->hasAttr<DLLImportAttr>()) | ||||
3503 | Mangler.getStream() << "??_S"; | ||||
3504 | else | ||||
3505 | Mangler.getStream() << "??_7"; | ||||
3506 | Mangler.mangleName(Derived); | ||||
3507 | Mangler.getStream() << "6B"; // '6' for vftable, 'B' for const. | ||||
3508 | for (const CXXRecordDecl *RD : BasePath) | ||||
3509 | Mangler.mangleName(RD); | ||||
3510 | Mangler.getStream() << '@'; | ||||
3511 | } | ||||
3512 | |||||
3513 | void MicrosoftMangleContextImpl::mangleCXXVBTable( | ||||
3514 | const CXXRecordDecl *Derived, ArrayRef<const CXXRecordDecl *> BasePath, | ||||
3515 | raw_ostream &Out) { | ||||
3516 | // <mangled-name> ::= ?_8 <class-name> <storage-class> | ||||
3517 | // <cvr-qualifiers> [<name>] @ | ||||
3518 | // NOTE: <cvr-qualifiers> here is always 'B' (const). <storage-class> | ||||
3519 | // is always '7' for vbtables. | ||||
3520 | msvc_hashing_ostream MHO(Out); | ||||
3521 | MicrosoftCXXNameMangler Mangler(*this, MHO); | ||||
3522 | Mangler.getStream() << "??_8"; | ||||
3523 | Mangler.mangleName(Derived); | ||||
3524 | Mangler.getStream() << "7B"; // '7' for vbtable, 'B' for const. | ||||
3525 | for (const CXXRecordDecl *RD : BasePath) | ||||
3526 | Mangler.mangleName(RD); | ||||
3527 | Mangler.getStream() << '@'; | ||||
3528 | } | ||||
3529 | |||||
3530 | void MicrosoftMangleContextImpl::mangleCXXRTTI(QualType T, raw_ostream &Out) { | ||||
3531 | msvc_hashing_ostream MHO(Out); | ||||
3532 | MicrosoftCXXNameMangler Mangler(*this, MHO); | ||||
3533 | Mangler.getStream() << "??_R0"; | ||||
3534 | Mangler.mangleType(T, SourceRange(), MicrosoftCXXNameMangler::QMM_Result); | ||||
3535 | Mangler.getStream() << "@8"; | ||||
3536 | } | ||||
3537 | |||||
3538 | void MicrosoftMangleContextImpl::mangleCXXRTTIName(QualType T, | ||||
3539 | raw_ostream &Out) { | ||||
3540 | MicrosoftCXXNameMangler Mangler(*this, Out); | ||||
3541 | Mangler.getStream() << '.'; | ||||
3542 | Mangler.mangleType(T, SourceRange(), MicrosoftCXXNameMangler::QMM_Result); | ||||
3543 | } | ||||
3544 | |||||
3545 | void MicrosoftMangleContextImpl::mangleCXXVirtualDisplacementMap( | ||||
3546 | const CXXRecordDecl *SrcRD, const CXXRecordDecl *DstRD, raw_ostream &Out) { | ||||
3547 | msvc_hashing_ostream MHO(Out); | ||||
3548 | MicrosoftCXXNameMangler Mangler(*this, MHO); | ||||
3549 | Mangler.getStream() << "??_K"; | ||||
3550 | Mangler.mangleName(SrcRD); | ||||
3551 | Mangler.getStream() << "$C"; | ||||
3552 | Mangler.mangleName(DstRD); | ||||
3553 | } | ||||
3554 | |||||
3555 | void MicrosoftMangleContextImpl::mangleCXXThrowInfo(QualType T, bool IsConst, | ||||
3556 | bool IsVolatile, | ||||
3557 | bool IsUnaligned, | ||||
3558 | uint32_t NumEntries, | ||||
3559 | raw_ostream &Out) { | ||||
3560 | msvc_hashing_ostream MHO(Out); | ||||
3561 | MicrosoftCXXNameMangler Mangler(*this, MHO); | ||||
3562 | Mangler.getStream() << "_TI"; | ||||
3563 | if (IsConst) | ||||
3564 | Mangler.getStream() << 'C'; | ||||
3565 | if (IsVolatile) | ||||
3566 | Mangler.getStream() << 'V'; | ||||
3567 | if (IsUnaligned) | ||||
3568 | Mangler.getStream() << 'U'; | ||||
3569 | Mangler.getStream() << NumEntries; | ||||
3570 | Mangler.mangleType(T, SourceRange(), MicrosoftCXXNameMangler::QMM_Result); | ||||
3571 | } | ||||
3572 | |||||
3573 | void MicrosoftMangleContextImpl::mangleCXXCatchableTypeArray( | ||||
3574 | QualType T, uint32_t NumEntries, raw_ostream &Out) { | ||||
3575 | msvc_hashing_ostream MHO(Out); | ||||
3576 | MicrosoftCXXNameMangler Mangler(*this, MHO); | ||||
3577 | Mangler.getStream() << "_CTA"; | ||||
3578 | Mangler.getStream() << NumEntries; | ||||
3579 | Mangler.mangleType(T, SourceRange(), MicrosoftCXXNameMangler::QMM_Result); | ||||
3580 | } | ||||
3581 | |||||
3582 | void MicrosoftMangleContextImpl::mangleCXXCatchableType( | ||||
3583 | QualType T, const CXXConstructorDecl *CD, CXXCtorType CT, uint32_t Size, | ||||
3584 | uint32_t NVOffset, int32_t VBPtrOffset, uint32_t VBIndex, | ||||
3585 | raw_ostream &Out) { | ||||
3586 | MicrosoftCXXNameMangler Mangler(*this, Out); | ||||
3587 | Mangler.getStream() << "_CT"; | ||||
3588 | |||||
3589 | llvm::SmallString<64> RTTIMangling; | ||||
3590 | { | ||||
3591 | llvm::raw_svector_ostream Stream(RTTIMangling); | ||||
3592 | msvc_hashing_ostream MHO(Stream); | ||||
3593 | mangleCXXRTTI(T, MHO); | ||||
3594 | } | ||||
3595 | Mangler.getStream() << RTTIMangling; | ||||
3596 | |||||
3597 | // VS2015 and VS2017.1 omit the copy-constructor in the mangled name but | ||||
3598 | // both older and newer versions include it. | ||||
3599 | // FIXME: It is known that the Ctor is present in 2013, and in 2017.7 | ||||
3600 | // (_MSC_VER 1914) and newer, and that it's omitted in 2015 and 2017.4 | ||||
3601 | // (_MSC_VER 1911), but it's unknown when exactly it reappeared (1914? | ||||
3602 | // Or 1912, 1913 aleady?). | ||||
3603 | bool OmitCopyCtor = getASTContext().getLangOpts().isCompatibleWithMSVC( | ||||
3604 | LangOptions::MSVC2015) && | ||||
3605 | !getASTContext().getLangOpts().isCompatibleWithMSVC( | ||||
3606 | LangOptions::MSVC2017_7); | ||||
3607 | llvm::SmallString<64> CopyCtorMangling; | ||||
3608 | if (!OmitCopyCtor && CD) { | ||||
3609 | llvm::raw_svector_ostream Stream(CopyCtorMangling); | ||||
3610 | msvc_hashing_ostream MHO(Stream); | ||||
3611 | mangleCXXName(GlobalDecl(CD, CT), MHO); | ||||
3612 | } | ||||
3613 | Mangler.getStream() << CopyCtorMangling; | ||||
3614 | |||||
3615 | Mangler.getStream() << Size; | ||||
3616 | if (VBPtrOffset == -1) { | ||||
3617 | if (NVOffset) { | ||||
3618 | Mangler.getStream() << NVOffset; | ||||
3619 | } | ||||
3620 | } else { | ||||
3621 | Mangler.getStream() << NVOffset; | ||||
3622 | Mangler.getStream() << VBPtrOffset; | ||||
3623 | Mangler.getStream() << VBIndex; | ||||
3624 | } | ||||
3625 | } | ||||
3626 | |||||
3627 | void MicrosoftMangleContextImpl::mangleCXXRTTIBaseClassDescriptor( | ||||
3628 | const CXXRecordDecl *Derived, uint32_t NVOffset, int32_t VBPtrOffset, | ||||
3629 | uint32_t VBTableOffset, uint32_t Flags, raw_ostream &Out) { | ||||
3630 | msvc_hashing_ostream MHO(Out); | ||||
3631 | MicrosoftCXXNameMangler Mangler(*this, MHO); | ||||
3632 | Mangler.getStream() << "??_R1"; | ||||
3633 | Mangler.mangleNumber(NVOffset); | ||||
3634 | Mangler.mangleNumber(VBPtrOffset); | ||||
3635 | Mangler.mangleNumber(VBTableOffset); | ||||
3636 | Mangler.mangleNumber(Flags); | ||||
3637 | Mangler.mangleName(Derived); | ||||
3638 | Mangler.getStream() << "8"; | ||||
3639 | } | ||||
3640 | |||||
3641 | void MicrosoftMangleContextImpl::mangleCXXRTTIBaseClassArray( | ||||
3642 | const CXXRecordDecl *Derived, raw_ostream &Out) { | ||||
3643 | msvc_hashing_ostream MHO(Out); | ||||
3644 | MicrosoftCXXNameMangler Mangler(*this, MHO); | ||||
3645 | Mangler.getStream() << "??_R2"; | ||||
3646 | Mangler.mangleName(Derived); | ||||
3647 | Mangler.getStream() << "8"; | ||||
3648 | } | ||||
3649 | |||||
3650 | void MicrosoftMangleContextImpl::mangleCXXRTTIClassHierarchyDescriptor( | ||||
3651 | const CXXRecordDecl *Derived, raw_ostream &Out) { | ||||
3652 | msvc_hashing_ostream MHO(Out); | ||||
3653 | MicrosoftCXXNameMangler Mangler(*this, MHO); | ||||
3654 | Mangler.getStream() << "??_R3"; | ||||
3655 | Mangler.mangleName(Derived); | ||||
3656 | Mangler.getStream() << "8"; | ||||
3657 | } | ||||
3658 | |||||
3659 | void MicrosoftMangleContextImpl::mangleCXXRTTICompleteObjectLocator( | ||||
3660 | const CXXRecordDecl *Derived, ArrayRef<const CXXRecordDecl *> BasePath, | ||||
3661 | raw_ostream &Out) { | ||||
3662 | // <mangled-name> ::= ?_R4 <class-name> <storage-class> | ||||
3663 | // <cvr-qualifiers> [<name>] @ | ||||
3664 | // NOTE: <cvr-qualifiers> here is always 'B' (const). <storage-class> | ||||
3665 | // is always '6' for vftables. | ||||
3666 | llvm::SmallString<64> VFTableMangling; | ||||
3667 | llvm::raw_svector_ostream Stream(VFTableMangling); | ||||
3668 | mangleCXXVFTable(Derived, BasePath, Stream); | ||||
3669 | |||||
3670 | if (VFTableMangling.startswith("??@")) { | ||||
3671 | assert(VFTableMangling.endswith("@"))((VFTableMangling.endswith("@")) ? static_cast<void> (0 ) : __assert_fail ("VFTableMangling.endswith(\"@\")", "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 3671, __PRETTY_FUNCTION__)); | ||||
3672 | Out << VFTableMangling << "??_R4@"; | ||||
3673 | return; | ||||
3674 | } | ||||
3675 | |||||
3676 | assert(VFTableMangling.startswith("??_7") ||((VFTableMangling.startswith("??_7") || VFTableMangling.startswith ("??_S")) ? static_cast<void> (0) : __assert_fail ("VFTableMangling.startswith(\"??_7\") || VFTableMangling.startswith(\"??_S\")" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 3677, __PRETTY_FUNCTION__)) | ||||
3677 | VFTableMangling.startswith("??_S"))((VFTableMangling.startswith("??_7") || VFTableMangling.startswith ("??_S")) ? static_cast<void> (0) : __assert_fail ("VFTableMangling.startswith(\"??_7\") || VFTableMangling.startswith(\"??_S\")" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/lib/AST/MicrosoftMangle.cpp" , 3677, __PRETTY_FUNCTION__)); | ||||
3678 | |||||
3679 | Out << "??_R4" << StringRef(VFTableMangling).drop_front(4); | ||||
3680 | } | ||||
3681 | |||||
3682 | void MicrosoftMangleContextImpl::mangleSEHFilterExpression( | ||||
3683 | const NamedDecl *EnclosingDecl, raw_ostream &Out) { | ||||
3684 | msvc_hashing_ostream MHO(Out); | ||||
3685 | MicrosoftCXXNameMangler Mangler(*this, MHO); | ||||
3686 | // The function body is in the same comdat as the function with the handler, | ||||
3687 | // so the numbering here doesn't have to be the same across TUs. | ||||
3688 | // | ||||
3689 | // <mangled-name> ::= ?filt$ <filter-number> @0 | ||||
3690 | Mangler.getStream() << "?filt$" << SEHFilterIds[EnclosingDecl]++ << "@0@"; | ||||
3691 | Mangler.mangleName(EnclosingDecl); | ||||
3692 | } | ||||
3693 | |||||
3694 | void MicrosoftMangleContextImpl::mangleSEHFinallyBlock( | ||||
3695 | const NamedDecl *EnclosingDecl, raw_ostream &Out) { | ||||
3696 | msvc_hashing_ostream MHO(Out); | ||||
3697 | MicrosoftCXXNameMangler Mangler(*this, MHO); | ||||
3698 | // The function body is in the same comdat as the function with the handler, | ||||
3699 | // so the numbering here doesn't have to be the same across TUs. | ||||
3700 | // | ||||
3701 | // <mangled-name> ::= ?fin$ <filter-number> @0 | ||||
3702 | Mangler.getStream() << "?fin$" << SEHFinallyIds[EnclosingDecl]++ << "@0@"; | ||||
3703 | Mangler.mangleName(EnclosingDecl); | ||||
3704 | } | ||||
3705 | |||||
3706 | void MicrosoftMangleContextImpl::mangleTypeName(QualType T, raw_ostream &Out) { | ||||
3707 | // This is just a made up unique string for the purposes of tbaa. undname | ||||
3708 | // does *not* know how to demangle it. | ||||
3709 | MicrosoftCXXNameMangler Mangler(*this, Out); | ||||
3710 | Mangler.getStream() << '?'; | ||||
3711 | Mangler.mangleType(T, SourceRange()); | ||||
3712 | } | ||||
3713 | |||||
3714 | void MicrosoftMangleContextImpl::mangleReferenceTemporary( | ||||
3715 | const VarDecl *VD, unsigned ManglingNumber, raw_ostream &Out) { | ||||
3716 | msvc_hashing_ostream MHO(Out); | ||||
3717 | MicrosoftCXXNameMangler Mangler(*this, MHO); | ||||
3718 | |||||
3719 | Mangler.getStream() << "?$RT" << ManglingNumber << '@'; | ||||
3720 | Mangler.mangle(VD, ""); | ||||
3721 | } | ||||
3722 | |||||
3723 | void MicrosoftMangleContextImpl::mangleThreadSafeStaticGuardVariable( | ||||
3724 | const VarDecl *VD, unsigned GuardNum, raw_ostream &Out) { | ||||
3725 | msvc_hashing_ostream MHO(Out); | ||||
3726 | MicrosoftCXXNameMangler Mangler(*this, MHO); | ||||
3727 | |||||
3728 | Mangler.getStream() << "?$TSS" << GuardNum << '@'; | ||||
3729 | Mangler.mangleNestedName(VD); | ||||
3730 | Mangler.getStream() << "@4HA"; | ||||
3731 | } | ||||
3732 | |||||
3733 | void MicrosoftMangleContextImpl::mangleStaticGuardVariable(const VarDecl *VD, | ||||
3734 | raw_ostream &Out) { | ||||
3735 | // <guard-name> ::= ?_B <postfix> @5 <scope-depth> | ||||
3736 | // ::= ?__J <postfix> @5 <scope-depth> | ||||
3737 | // ::= ?$S <guard-num> @ <postfix> @4IA | ||||
3738 | |||||
3739 | // The first mangling is what MSVC uses to guard static locals in inline | ||||
3740 | // functions. It uses a different mangling in external functions to support | ||||
3741 | // guarding more than 32 variables. MSVC rejects inline functions with more | ||||
3742 | // than 32 static locals. We don't fully implement the second mangling | ||||
3743 | // because those guards are not externally visible, and instead use LLVM's | ||||
3744 | // default renaming when creating a new guard variable. | ||||
3745 | msvc_hashing_ostream MHO(Out); | ||||
3746 | MicrosoftCXXNameMangler Mangler(*this, MHO); | ||||
3747 | |||||
3748 | bool Visible = VD->isExternallyVisible(); | ||||
3749 | if (Visible) { | ||||
3750 | Mangler.getStream() << (VD->getTLSKind() ? "??__J" : "??_B"); | ||||
3751 | } else { | ||||
3752 | Mangler.getStream() << "?$S1@"; | ||||
3753 | } | ||||
3754 | unsigned ScopeDepth = 0; | ||||
3755 | if (Visible && !getNextDiscriminator(VD, ScopeDepth)) | ||||
3756 | // If we do not have a discriminator and are emitting a guard variable for | ||||
3757 | // use at global scope, then mangling the nested name will not be enough to | ||||
3758 | // remove ambiguities. | ||||
3759 | Mangler.mangle(VD, ""); | ||||
3760 | else | ||||
3761 | Mangler.mangleNestedName(VD); | ||||
3762 | Mangler.getStream() << (Visible ? "@5" : "@4IA"); | ||||
3763 | if (ScopeDepth) | ||||
3764 | Mangler.mangleNumber(ScopeDepth); | ||||
3765 | } | ||||
3766 | |||||
3767 | void MicrosoftMangleContextImpl::mangleInitFiniStub(const VarDecl *D, | ||||
3768 | char CharCode, | ||||
3769 | raw_ostream &Out) { | ||||
3770 | msvc_hashing_ostream MHO(Out); | ||||
3771 | MicrosoftCXXNameMangler Mangler(*this, MHO); | ||||
3772 | Mangler.getStream() << "??__" << CharCode; | ||||
3773 | if (D->isStaticDataMember()) { | ||||
3774 | Mangler.getStream() << '?'; | ||||
3775 | Mangler.mangleName(D); | ||||
3776 | Mangler.mangleVariableEncoding(D); | ||||
3777 | Mangler.getStream() << "@@"; | ||||
3778 | } else { | ||||
3779 | Mangler.mangleName(D); | ||||
3780 | } | ||||
3781 | // This is the function class mangling. These stubs are global, non-variadic, | ||||
3782 | // cdecl functions that return void and take no args. | ||||
3783 | Mangler.getStream() << "YAXXZ"; | ||||
3784 | } | ||||
3785 | |||||
3786 | void MicrosoftMangleContextImpl::mangleDynamicInitializer(const VarDecl *D, | ||||
3787 | raw_ostream &Out) { | ||||
3788 | // <initializer-name> ::= ?__E <name> YAXXZ | ||||
3789 | mangleInitFiniStub(D, 'E', Out); | ||||
3790 | } | ||||
3791 | |||||
3792 | void | ||||
3793 | MicrosoftMangleContextImpl::mangleDynamicAtExitDestructor(const VarDecl *D, | ||||
3794 | raw_ostream &Out) { | ||||
3795 | // <destructor-name> ::= ?__F <name> YAXXZ | ||||
3796 | mangleInitFiniStub(D, 'F', Out); | ||||
3797 | } | ||||
3798 | |||||
3799 | void MicrosoftMangleContextImpl::mangleStringLiteral(const StringLiteral *SL, | ||||
3800 | raw_ostream &Out) { | ||||
3801 | // <char-type> ::= 0 # char, char16_t, char32_t | ||||
3802 | // # (little endian char data in mangling) | ||||
3803 | // ::= 1 # wchar_t (big endian char data in mangling) | ||||
3804 | // | ||||
3805 | // <literal-length> ::= <non-negative integer> # the length of the literal | ||||
3806 | // | ||||
3807 | // <encoded-crc> ::= <hex digit>+ @ # crc of the literal including | ||||
3808 | // # trailing null bytes | ||||
3809 | // | ||||
3810 | // <encoded-string> ::= <simple character> # uninteresting character | ||||
3811 | // ::= '?$' <hex digit> <hex digit> # these two nibbles | ||||
3812 | // # encode the byte for the | ||||
3813 | // # character | ||||
3814 | // ::= '?' [a-z] # \xe1 - \xfa | ||||
3815 | // ::= '?' [A-Z] # \xc1 - \xda | ||||
3816 | // ::= '?' [0-9] # [,/\:. \n\t'-] | ||||
3817 | // | ||||
3818 | // <literal> ::= '??_C@_' <char-type> <literal-length> <encoded-crc> | ||||
3819 | // <encoded-string> '@' | ||||
3820 | MicrosoftCXXNameMangler Mangler(*this, Out); | ||||
3821 | Mangler.getStream() << "??_C@_"; | ||||
3822 | |||||
3823 | // The actual string length might be different from that of the string literal | ||||
3824 | // in cases like: | ||||
3825 | // char foo[3] = "foobar"; | ||||
3826 | // char bar[42] = "foobar"; | ||||
3827 | // Where it is truncated or zero-padded to fit the array. This is the length | ||||
3828 | // used for mangling, and any trailing null-bytes also need to be mangled. | ||||
3829 | unsigned StringLength = getASTContext() | ||||
3830 | .getAsConstantArrayType(SL->getType()) | ||||
3831 | ->getSize() | ||||
3832 | .getZExtValue(); | ||||
3833 | unsigned StringByteLength = StringLength * SL->getCharByteWidth(); | ||||
3834 | |||||
3835 | // <char-type>: The "kind" of string literal is encoded into the mangled name. | ||||
3836 | if (SL->isWide()) | ||||
3837 | Mangler.getStream() << '1'; | ||||
3838 | else | ||||
3839 | Mangler.getStream() << '0'; | ||||
3840 | |||||
3841 | // <literal-length>: The next part of the mangled name consists of the length | ||||
3842 | // of the string in bytes. | ||||
3843 | Mangler.mangleNumber(StringByteLength); | ||||
3844 | |||||
3845 | auto GetLittleEndianByte = [&SL](unsigned Index) { | ||||
3846 | unsigned CharByteWidth = SL->getCharByteWidth(); | ||||
3847 | if (Index / CharByteWidth >= SL->getLength()) | ||||
3848 | return static_cast<char>(0); | ||||
3849 | uint32_t CodeUnit = SL->getCodeUnit(Index / CharByteWidth); | ||||
3850 | unsigned OffsetInCodeUnit = Index % CharByteWidth; | ||||
3851 | return static_cast<char>((CodeUnit >> (8 * OffsetInCodeUnit)) & 0xff); | ||||
3852 | }; | ||||
3853 | |||||
3854 | auto GetBigEndianByte = [&SL](unsigned Index) { | ||||
3855 | unsigned CharByteWidth = SL->getCharByteWidth(); | ||||
3856 | if (Index / CharByteWidth >= SL->getLength()) | ||||
3857 | return static_cast<char>(0); | ||||
3858 | uint32_t CodeUnit = SL->getCodeUnit(Index / CharByteWidth); | ||||
3859 | unsigned OffsetInCodeUnit = (CharByteWidth - 1) - (Index % CharByteWidth); | ||||
3860 | return static_cast<char>((CodeUnit >> (8 * OffsetInCodeUnit)) & 0xff); | ||||
3861 | }; | ||||
3862 | |||||
3863 | // CRC all the bytes of the StringLiteral. | ||||
3864 | llvm::JamCRC JC; | ||||
3865 | for (unsigned I = 0, E = StringByteLength; I != E; ++I) | ||||
3866 | JC.update(GetLittleEndianByte(I)); | ||||
3867 | |||||
3868 | // <encoded-crc>: The CRC is encoded utilizing the standard number mangling | ||||
3869 | // scheme. | ||||
3870 | Mangler.mangleNumber(JC.getCRC()); | ||||
3871 | |||||
3872 | // <encoded-string>: The mangled name also contains the first 32 bytes | ||||
3873 | // (including null-terminator bytes) of the encoded StringLiteral. | ||||
3874 | // Each character is encoded by splitting them into bytes and then encoding | ||||
3875 | // the constituent bytes. | ||||
3876 | auto MangleByte = [&Mangler](char Byte) { | ||||
3877 | // There are five different manglings for characters: | ||||
3878 | // - [a-zA-Z0-9_$]: A one-to-one mapping. | ||||
3879 | // - ?[a-z]: The range from \xe1 to \xfa. | ||||
3880 | // - ?[A-Z]: The range from \xc1 to \xda. | ||||
3881 | // - ?[0-9]: The set of [,/\:. \n\t'-]. | ||||
3882 | // - ?$XX: A fallback which maps nibbles. | ||||
3883 | if (isIdentifierBody(Byte, /*AllowDollar=*/true)) { | ||||
3884 | Mangler.getStream() << Byte; | ||||
3885 | } else if (isLetter(Byte & 0x7f)) { | ||||
3886 | Mangler.getStream() << '?' << static_cast<char>(Byte & 0x7f); | ||||
3887 | } else { | ||||
3888 | const char SpecialChars[] = {',', '/', '\\', ':', '.', | ||||
3889 | ' ', '\n', '\t', '\'', '-'}; | ||||
3890 | const char *Pos = llvm::find(SpecialChars, Byte); | ||||
3891 | if (Pos != std::end(SpecialChars)) { | ||||
3892 | Mangler.getStream() << '?' << (Pos - std::begin(SpecialChars)); | ||||
3893 | } else { | ||||
3894 | Mangler.getStream() << "?$"; | ||||
3895 | Mangler.getStream() << static_cast<char>('A' + ((Byte >> 4) & 0xf)); | ||||
3896 | Mangler.getStream() << static_cast<char>('A' + (Byte & 0xf)); | ||||
3897 | } | ||||
3898 | } | ||||
3899 | }; | ||||
3900 | |||||
3901 | // Enforce our 32 bytes max, except wchar_t which gets 32 chars instead. | ||||
3902 | unsigned MaxBytesToMangle = SL->isWide() ? 64U : 32U; | ||||
3903 | unsigned NumBytesToMangle = std::min(MaxBytesToMangle, StringByteLength); | ||||
3904 | for (unsigned I = 0; I != NumBytesToMangle; ++I) { | ||||
3905 | if (SL->isWide()) | ||||
3906 | MangleByte(GetBigEndianByte(I)); | ||||
3907 | else | ||||
3908 | MangleByte(GetLittleEndianByte(I)); | ||||
3909 | } | ||||
3910 | |||||
3911 | Mangler.getStream() << '@'; | ||||
3912 | } | ||||
3913 | |||||
3914 | MicrosoftMangleContext * | ||||
3915 | MicrosoftMangleContext::create(ASTContext &Context, DiagnosticsEngine &Diags) { | ||||
3916 | return new MicrosoftMangleContextImpl(Context, Diags); | ||||
3917 | } |
1 | //===- DeclCXX.h - Classes for representing C++ declarations --*- C++ -*-=====// |
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 | /// \file |
10 | /// Defines the C++ Decl subclasses, other than those for templates |
11 | /// (found in DeclTemplate.h) and friends (in DeclFriend.h). |
12 | // |
13 | //===----------------------------------------------------------------------===// |
14 | |
15 | #ifndef LLVM_CLANG_AST_DECLCXX_H |
16 | #define LLVM_CLANG_AST_DECLCXX_H |
17 | |
18 | #include "clang/AST/ASTUnresolvedSet.h" |
19 | #include "clang/AST/Decl.h" |
20 | #include "clang/AST/DeclBase.h" |
21 | #include "clang/AST/DeclarationName.h" |
22 | #include "clang/AST/Expr.h" |
23 | #include "clang/AST/ExternalASTSource.h" |
24 | #include "clang/AST/LambdaCapture.h" |
25 | #include "clang/AST/NestedNameSpecifier.h" |
26 | #include "clang/AST/Redeclarable.h" |
27 | #include "clang/AST/Stmt.h" |
28 | #include "clang/AST/Type.h" |
29 | #include "clang/AST/TypeLoc.h" |
30 | #include "clang/AST/UnresolvedSet.h" |
31 | #include "clang/Basic/LLVM.h" |
32 | #include "clang/Basic/Lambda.h" |
33 | #include "clang/Basic/LangOptions.h" |
34 | #include "clang/Basic/OperatorKinds.h" |
35 | #include "clang/Basic/SourceLocation.h" |
36 | #include "clang/Basic/Specifiers.h" |
37 | #include "llvm/ADT/ArrayRef.h" |
38 | #include "llvm/ADT/DenseMap.h" |
39 | #include "llvm/ADT/PointerIntPair.h" |
40 | #include "llvm/ADT/PointerUnion.h" |
41 | #include "llvm/ADT/STLExtras.h" |
42 | #include "llvm/ADT/TinyPtrVector.h" |
43 | #include "llvm/ADT/iterator_range.h" |
44 | #include "llvm/Support/Casting.h" |
45 | #include "llvm/Support/Compiler.h" |
46 | #include "llvm/Support/PointerLikeTypeTraits.h" |
47 | #include "llvm/Support/TrailingObjects.h" |
48 | #include <cassert> |
49 | #include <cstddef> |
50 | #include <iterator> |
51 | #include <memory> |
52 | #include <vector> |
53 | |
54 | namespace clang { |
55 | |
56 | class ASTContext; |
57 | class ClassTemplateDecl; |
58 | class ConstructorUsingShadowDecl; |
59 | class CXXBasePath; |
60 | class CXXBasePaths; |
61 | class CXXConstructorDecl; |
62 | class CXXDestructorDecl; |
63 | class CXXFinalOverriderMap; |
64 | class CXXIndirectPrimaryBaseSet; |
65 | class CXXMethodDecl; |
66 | class DecompositionDecl; |
67 | class DiagnosticBuilder; |
68 | class FriendDecl; |
69 | class FunctionTemplateDecl; |
70 | class IdentifierInfo; |
71 | class MemberSpecializationInfo; |
72 | class TemplateDecl; |
73 | class TemplateParameterList; |
74 | class UsingDecl; |
75 | |
76 | /// Represents an access specifier followed by colon ':'. |
77 | /// |
78 | /// An objects of this class represents sugar for the syntactic occurrence |
79 | /// of an access specifier followed by a colon in the list of member |
80 | /// specifiers of a C++ class definition. |
81 | /// |
82 | /// Note that they do not represent other uses of access specifiers, |
83 | /// such as those occurring in a list of base specifiers. |
84 | /// Also note that this class has nothing to do with so-called |
85 | /// "access declarations" (C++98 11.3 [class.access.dcl]). |
86 | class AccessSpecDecl : public Decl { |
87 | /// The location of the ':'. |
88 | SourceLocation ColonLoc; |
89 | |
90 | AccessSpecDecl(AccessSpecifier AS, DeclContext *DC, |
91 | SourceLocation ASLoc, SourceLocation ColonLoc) |
92 | : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) { |
93 | setAccess(AS); |
94 | } |
95 | |
96 | AccessSpecDecl(EmptyShell Empty) : Decl(AccessSpec, Empty) {} |
97 | |
98 | virtual void anchor(); |
99 | |
100 | public: |
101 | /// The location of the access specifier. |
102 | SourceLocation getAccessSpecifierLoc() const { return getLocation(); } |
103 | |
104 | /// Sets the location of the access specifier. |
105 | void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); } |
106 | |
107 | /// The location of the colon following the access specifier. |
108 | SourceLocation getColonLoc() const { return ColonLoc; } |
109 | |
110 | /// Sets the location of the colon. |
111 | void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; } |
112 | |
113 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
114 | return SourceRange(getAccessSpecifierLoc(), getColonLoc()); |
115 | } |
116 | |
117 | static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS, |
118 | DeclContext *DC, SourceLocation ASLoc, |
119 | SourceLocation ColonLoc) { |
120 | return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc); |
121 | } |
122 | |
123 | static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
124 | |
125 | // Implement isa/cast/dyncast/etc. |
126 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
127 | static bool classofKind(Kind K) { return K == AccessSpec; } |
128 | }; |
129 | |
130 | /// Represents a base class of a C++ class. |
131 | /// |
132 | /// Each CXXBaseSpecifier represents a single, direct base class (or |
133 | /// struct) of a C++ class (or struct). It specifies the type of that |
134 | /// base class, whether it is a virtual or non-virtual base, and what |
135 | /// level of access (public, protected, private) is used for the |
136 | /// derivation. For example: |
137 | /// |
138 | /// \code |
139 | /// class A { }; |
140 | /// class B { }; |
141 | /// class C : public virtual A, protected B { }; |
142 | /// \endcode |
143 | /// |
144 | /// In this code, C will have two CXXBaseSpecifiers, one for "public |
145 | /// virtual A" and the other for "protected B". |
146 | class CXXBaseSpecifier { |
147 | /// The source code range that covers the full base |
148 | /// specifier, including the "virtual" (if present) and access |
149 | /// specifier (if present). |
150 | SourceRange Range; |
151 | |
152 | /// The source location of the ellipsis, if this is a pack |
153 | /// expansion. |
154 | SourceLocation EllipsisLoc; |
155 | |
156 | /// Whether this is a virtual base class or not. |
157 | unsigned Virtual : 1; |
158 | |
159 | /// Whether this is the base of a class (true) or of a struct (false). |
160 | /// |
161 | /// This determines the mapping from the access specifier as written in the |
162 | /// source code to the access specifier used for semantic analysis. |
163 | unsigned BaseOfClass : 1; |
164 | |
165 | /// Access specifier as written in the source code (may be AS_none). |
166 | /// |
167 | /// The actual type of data stored here is an AccessSpecifier, but we use |
168 | /// "unsigned" here to work around a VC++ bug. |
169 | unsigned Access : 2; |
170 | |
171 | /// Whether the class contains a using declaration |
172 | /// to inherit the named class's constructors. |
173 | unsigned InheritConstructors : 1; |
174 | |
175 | /// The type of the base class. |
176 | /// |
177 | /// This will be a class or struct (or a typedef of such). The source code |
178 | /// range does not include the \c virtual or the access specifier. |
179 | TypeSourceInfo *BaseTypeInfo; |
180 | |
181 | public: |
182 | CXXBaseSpecifier() = default; |
183 | CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, |
184 | TypeSourceInfo *TInfo, SourceLocation EllipsisLoc) |
185 | : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC), |
186 | Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) {} |
187 | |
188 | /// Retrieves the source range that contains the entire base specifier. |
189 | SourceRange getSourceRange() const LLVM_READONLY__attribute__((__pure__)) { return Range; } |
190 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { return Range.getBegin(); } |
191 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return Range.getEnd(); } |
192 | |
193 | /// Get the location at which the base class type was written. |
194 | SourceLocation getBaseTypeLoc() const LLVM_READONLY__attribute__((__pure__)) { |
195 | return BaseTypeInfo->getTypeLoc().getBeginLoc(); |
196 | } |
197 | |
198 | /// Determines whether the base class is a virtual base class (or not). |
199 | bool isVirtual() const { return Virtual; } |
200 | |
201 | /// Determine whether this base class is a base of a class declared |
202 | /// with the 'class' keyword (vs. one declared with the 'struct' keyword). |
203 | bool isBaseOfClass() const { return BaseOfClass; } |
204 | |
205 | /// Determine whether this base specifier is a pack expansion. |
206 | bool isPackExpansion() const { return EllipsisLoc.isValid(); } |
207 | |
208 | /// Determine whether this base class's constructors get inherited. |
209 | bool getInheritConstructors() const { return InheritConstructors; } |
210 | |
211 | /// Set that this base class's constructors should be inherited. |
212 | void setInheritConstructors(bool Inherit = true) { |
213 | InheritConstructors = Inherit; |
214 | } |
215 | |
216 | /// For a pack expansion, determine the location of the ellipsis. |
217 | SourceLocation getEllipsisLoc() const { |
218 | return EllipsisLoc; |
219 | } |
220 | |
221 | /// Returns the access specifier for this base specifier. |
222 | /// |
223 | /// This is the actual base specifier as used for semantic analysis, so |
224 | /// the result can never be AS_none. To retrieve the access specifier as |
225 | /// written in the source code, use getAccessSpecifierAsWritten(). |
226 | AccessSpecifier getAccessSpecifier() const { |
227 | if ((AccessSpecifier)Access == AS_none) |
228 | return BaseOfClass? AS_private : AS_public; |
229 | else |
230 | return (AccessSpecifier)Access; |
231 | } |
232 | |
233 | /// Retrieves the access specifier as written in the source code |
234 | /// (which may mean that no access specifier was explicitly written). |
235 | /// |
236 | /// Use getAccessSpecifier() to retrieve the access specifier for use in |
237 | /// semantic analysis. |
238 | AccessSpecifier getAccessSpecifierAsWritten() const { |
239 | return (AccessSpecifier)Access; |
240 | } |
241 | |
242 | /// Retrieves the type of the base class. |
243 | /// |
244 | /// This type will always be an unqualified class type. |
245 | QualType getType() const { |
246 | return BaseTypeInfo->getType().getUnqualifiedType(); |
247 | } |
248 | |
249 | /// Retrieves the type and source location of the base class. |
250 | TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; } |
251 | }; |
252 | |
253 | /// Represents a C++ struct/union/class. |
254 | class CXXRecordDecl : public RecordDecl { |
255 | friend class ASTDeclReader; |
256 | friend class ASTDeclWriter; |
257 | friend class ASTNodeImporter; |
258 | friend class ASTReader; |
259 | friend class ASTRecordWriter; |
260 | friend class ASTWriter; |
261 | friend class DeclContext; |
262 | friend class LambdaExpr; |
263 | |
264 | friend void FunctionDecl::setPure(bool); |
265 | friend void TagDecl::startDefinition(); |
266 | |
267 | /// Values used in DefinitionData fields to represent special members. |
268 | enum SpecialMemberFlags { |
269 | SMF_DefaultConstructor = 0x1, |
270 | SMF_CopyConstructor = 0x2, |
271 | SMF_MoveConstructor = 0x4, |
272 | SMF_CopyAssignment = 0x8, |
273 | SMF_MoveAssignment = 0x10, |
274 | SMF_Destructor = 0x20, |
275 | SMF_All = 0x3f |
276 | }; |
277 | |
278 | struct DefinitionData { |
279 | #define FIELD(Name, Width, Merge) \ |
280 | unsigned Name : Width; |
281 | #include "CXXRecordDeclDefinitionBits.def" |
282 | |
283 | /// Whether this class describes a C++ lambda. |
284 | unsigned IsLambda : 1; |
285 | |
286 | /// Whether we are currently parsing base specifiers. |
287 | unsigned IsParsingBaseSpecifiers : 1; |
288 | |
289 | /// True when visible conversion functions are already computed |
290 | /// and are available. |
291 | unsigned ComputedVisibleConversions : 1; |
292 | |
293 | unsigned HasODRHash : 1; |
294 | |
295 | /// A hash of parts of the class to help in ODR checking. |
296 | unsigned ODRHash = 0; |
297 | |
298 | /// The number of base class specifiers in Bases. |
299 | unsigned NumBases = 0; |
300 | |
301 | /// The number of virtual base class specifiers in VBases. |
302 | unsigned NumVBases = 0; |
303 | |
304 | /// Base classes of this class. |
305 | /// |
306 | /// FIXME: This is wasted space for a union. |
307 | LazyCXXBaseSpecifiersPtr Bases; |
308 | |
309 | /// direct and indirect virtual base classes of this class. |
310 | LazyCXXBaseSpecifiersPtr VBases; |
311 | |
312 | /// The conversion functions of this C++ class (but not its |
313 | /// inherited conversion functions). |
314 | /// |
315 | /// Each of the entries in this overload set is a CXXConversionDecl. |
316 | LazyASTUnresolvedSet Conversions; |
317 | |
318 | /// The conversion functions of this C++ class and all those |
319 | /// inherited conversion functions that are visible in this class. |
320 | /// |
321 | /// Each of the entries in this overload set is a CXXConversionDecl or a |
322 | /// FunctionTemplateDecl. |
323 | LazyASTUnresolvedSet VisibleConversions; |
324 | |
325 | /// The declaration which defines this record. |
326 | CXXRecordDecl *Definition; |
327 | |
328 | /// The first friend declaration in this class, or null if there |
329 | /// aren't any. |
330 | /// |
331 | /// This is actually currently stored in reverse order. |
332 | LazyDeclPtr FirstFriend; |
333 | |
334 | DefinitionData(CXXRecordDecl *D); |
335 | |
336 | /// Retrieve the set of direct base classes. |
337 | CXXBaseSpecifier *getBases() const { |
338 | if (!Bases.isOffset()) |
339 | return Bases.get(nullptr); |
340 | return getBasesSlowCase(); |
341 | } |
342 | |
343 | /// Retrieve the set of virtual base classes. |
344 | CXXBaseSpecifier *getVBases() const { |
345 | if (!VBases.isOffset()) |
346 | return VBases.get(nullptr); |
347 | return getVBasesSlowCase(); |
348 | } |
349 | |
350 | ArrayRef<CXXBaseSpecifier> bases() const { |
351 | return llvm::makeArrayRef(getBases(), NumBases); |
352 | } |
353 | |
354 | ArrayRef<CXXBaseSpecifier> vbases() const { |
355 | return llvm::makeArrayRef(getVBases(), NumVBases); |
356 | } |
357 | |
358 | private: |
359 | CXXBaseSpecifier *getBasesSlowCase() const; |
360 | CXXBaseSpecifier *getVBasesSlowCase() const; |
361 | }; |
362 | |
363 | struct DefinitionData *DefinitionData; |
364 | |
365 | /// Describes a C++ closure type (generated by a lambda expression). |
366 | struct LambdaDefinitionData : public DefinitionData { |
367 | using Capture = LambdaCapture; |
368 | |
369 | /// Whether this lambda is known to be dependent, even if its |
370 | /// context isn't dependent. |
371 | /// |
372 | /// A lambda with a non-dependent context can be dependent if it occurs |
373 | /// within the default argument of a function template, because the |
374 | /// lambda will have been created with the enclosing context as its |
375 | /// declaration context, rather than function. This is an unfortunate |
376 | /// artifact of having to parse the default arguments before. |
377 | unsigned Dependent : 1; |
378 | |
379 | /// Whether this lambda is a generic lambda. |
380 | unsigned IsGenericLambda : 1; |
381 | |
382 | /// The Default Capture. |
383 | unsigned CaptureDefault : 2; |
384 | |
385 | /// The number of captures in this lambda is limited 2^NumCaptures. |
386 | unsigned NumCaptures : 15; |
387 | |
388 | /// The number of explicit captures in this lambda. |
389 | unsigned NumExplicitCaptures : 13; |
390 | |
391 | /// Has known `internal` linkage. |
392 | unsigned HasKnownInternalLinkage : 1; |
393 | |
394 | /// The number used to indicate this lambda expression for name |
395 | /// mangling in the Itanium C++ ABI. |
396 | unsigned ManglingNumber : 31; |
397 | |
398 | /// The declaration that provides context for this lambda, if the |
399 | /// actual DeclContext does not suffice. This is used for lambdas that |
400 | /// occur within default arguments of function parameters within the class |
401 | /// or within a data member initializer. |
402 | LazyDeclPtr ContextDecl; |
403 | |
404 | /// The list of captures, both explicit and implicit, for this |
405 | /// lambda. |
406 | Capture *Captures = nullptr; |
407 | |
408 | /// The type of the call method. |
409 | TypeSourceInfo *MethodTyInfo; |
410 | |
411 | LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, bool Dependent, |
412 | bool IsGeneric, LambdaCaptureDefault CaptureDefault) |
413 | : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric), |
414 | CaptureDefault(CaptureDefault), NumCaptures(0), |
415 | NumExplicitCaptures(0), HasKnownInternalLinkage(0), ManglingNumber(0), |
416 | MethodTyInfo(Info) { |
417 | IsLambda = true; |
418 | |
419 | // C++1z [expr.prim.lambda]p4: |
420 | // This class type is not an aggregate type. |
421 | Aggregate = false; |
422 | PlainOldData = false; |
423 | } |
424 | }; |
425 | |
426 | struct DefinitionData *dataPtr() const { |
427 | // Complete the redecl chain (if necessary). |
428 | getMostRecentDecl(); |
429 | return DefinitionData; |
430 | } |
431 | |
432 | struct DefinitionData &data() const { |
433 | auto *DD = dataPtr(); |
434 | assert(DD && "queried property of class with no definition")((DD && "queried property of class with no definition" ) ? static_cast<void> (0) : __assert_fail ("DD && \"queried property of class with no definition\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 434, __PRETTY_FUNCTION__)); |
435 | return *DD; |
436 | } |
437 | |
438 | struct LambdaDefinitionData &getLambdaData() const { |
439 | // No update required: a merged definition cannot change any lambda |
440 | // properties. |
441 | auto *DD = DefinitionData; |
442 | assert(DD && DD->IsLambda && "queried lambda property of non-lambda class")((DD && DD->IsLambda && "queried lambda property of non-lambda class" ) ? static_cast<void> (0) : __assert_fail ("DD && DD->IsLambda && \"queried lambda property of non-lambda class\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 442, __PRETTY_FUNCTION__)); |
443 | return static_cast<LambdaDefinitionData&>(*DD); |
444 | } |
445 | |
446 | /// The template or declaration that this declaration |
447 | /// describes or was instantiated from, respectively. |
448 | /// |
449 | /// For non-templates, this value will be null. For record |
450 | /// declarations that describe a class template, this will be a |
451 | /// pointer to a ClassTemplateDecl. For member |
452 | /// classes of class template specializations, this will be the |
453 | /// MemberSpecializationInfo referring to the member class that was |
454 | /// instantiated or specialized. |
455 | llvm::PointerUnion<ClassTemplateDecl *, MemberSpecializationInfo *> |
456 | TemplateOrInstantiation; |
457 | |
458 | /// Called from setBases and addedMember to notify the class that a |
459 | /// direct or virtual base class or a member of class type has been added. |
460 | void addedClassSubobject(CXXRecordDecl *Base); |
461 | |
462 | /// Notify the class that member has been added. |
463 | /// |
464 | /// This routine helps maintain information about the class based on which |
465 | /// members have been added. It will be invoked by DeclContext::addDecl() |
466 | /// whenever a member is added to this record. |
467 | void addedMember(Decl *D); |
468 | |
469 | void markedVirtualFunctionPure(); |
470 | |
471 | /// Get the head of our list of friend declarations, possibly |
472 | /// deserializing the friends from an external AST source. |
473 | FriendDecl *getFirstFriend() const; |
474 | |
475 | /// Determine whether this class has an empty base class subobject of type X |
476 | /// or of one of the types that might be at offset 0 within X (per the C++ |
477 | /// "standard layout" rules). |
478 | bool hasSubobjectAtOffsetZeroOfEmptyBaseType(ASTContext &Ctx, |
479 | const CXXRecordDecl *X); |
480 | |
481 | protected: |
482 | CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC, |
483 | SourceLocation StartLoc, SourceLocation IdLoc, |
484 | IdentifierInfo *Id, CXXRecordDecl *PrevDecl); |
485 | |
486 | public: |
487 | /// Iterator that traverses the base classes of a class. |
488 | using base_class_iterator = CXXBaseSpecifier *; |
489 | |
490 | /// Iterator that traverses the base classes of a class. |
491 | using base_class_const_iterator = const CXXBaseSpecifier *; |
492 | |
493 | CXXRecordDecl *getCanonicalDecl() override { |
494 | return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); |
495 | } |
496 | |
497 | const CXXRecordDecl *getCanonicalDecl() const { |
498 | return const_cast<CXXRecordDecl*>(this)->getCanonicalDecl(); |
499 | } |
500 | |
501 | CXXRecordDecl *getPreviousDecl() { |
502 | return cast_or_null<CXXRecordDecl>( |
503 | static_cast<RecordDecl *>(this)->getPreviousDecl()); |
504 | } |
505 | |
506 | const CXXRecordDecl *getPreviousDecl() const { |
507 | return const_cast<CXXRecordDecl*>(this)->getPreviousDecl(); |
508 | } |
509 | |
510 | CXXRecordDecl *getMostRecentDecl() { |
511 | return cast<CXXRecordDecl>( |
512 | static_cast<RecordDecl *>(this)->getMostRecentDecl()); |
513 | } |
514 | |
515 | const CXXRecordDecl *getMostRecentDecl() const { |
516 | return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl(); |
517 | } |
518 | |
519 | CXXRecordDecl *getMostRecentNonInjectedDecl() { |
520 | CXXRecordDecl *Recent = |
521 | static_cast<CXXRecordDecl *>(this)->getMostRecentDecl(); |
522 | while (Recent->isInjectedClassName()) { |
523 | // FIXME: Does injected class name need to be in the redeclarations chain? |
524 | assert(Recent->getPreviousDecl())((Recent->getPreviousDecl()) ? static_cast<void> (0) : __assert_fail ("Recent->getPreviousDecl()", "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 524, __PRETTY_FUNCTION__)); |
525 | Recent = Recent->getPreviousDecl(); |
526 | } |
527 | return Recent; |
528 | } |
529 | |
530 | const CXXRecordDecl *getMostRecentNonInjectedDecl() const { |
531 | return const_cast<CXXRecordDecl*>(this)->getMostRecentNonInjectedDecl(); |
532 | } |
533 | |
534 | CXXRecordDecl *getDefinition() const { |
535 | // We only need an update if we don't already know which |
536 | // declaration is the definition. |
537 | auto *DD = DefinitionData ? DefinitionData : dataPtr(); |
538 | return DD ? DD->Definition : nullptr; |
539 | } |
540 | |
541 | bool hasDefinition() const { return DefinitionData || dataPtr(); } |
542 | |
543 | static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC, |
544 | SourceLocation StartLoc, SourceLocation IdLoc, |
545 | IdentifierInfo *Id, |
546 | CXXRecordDecl *PrevDecl = nullptr, |
547 | bool DelayTypeCreation = false); |
548 | static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC, |
549 | TypeSourceInfo *Info, SourceLocation Loc, |
550 | bool DependentLambda, bool IsGeneric, |
551 | LambdaCaptureDefault CaptureDefault); |
552 | static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID); |
553 | |
554 | bool isDynamicClass() const { |
555 | return data().Polymorphic || data().NumVBases != 0; |
556 | } |
557 | |
558 | /// @returns true if class is dynamic or might be dynamic because the |
559 | /// definition is incomplete of dependent. |
560 | bool mayBeDynamicClass() const { |
561 | return !hasDefinition() || isDynamicClass() || hasAnyDependentBases(); |
562 | } |
563 | |
564 | /// @returns true if class is non dynamic or might be non dynamic because the |
565 | /// definition is incomplete of dependent. |
566 | bool mayBeNonDynamicClass() const { |
567 | return !hasDefinition() || !isDynamicClass() || hasAnyDependentBases(); |
568 | } |
569 | |
570 | void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; } |
571 | |
572 | bool isParsingBaseSpecifiers() const { |
573 | return data().IsParsingBaseSpecifiers; |
574 | } |
575 | |
576 | unsigned getODRHash() const; |
577 | |
578 | /// Sets the base classes of this struct or class. |
579 | void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases); |
580 | |
581 | /// Retrieves the number of base classes of this class. |
582 | unsigned getNumBases() const { return data().NumBases; } |
583 | |
584 | using base_class_range = llvm::iterator_range<base_class_iterator>; |
585 | using base_class_const_range = |
586 | llvm::iterator_range<base_class_const_iterator>; |
587 | |
588 | base_class_range bases() { |
589 | return base_class_range(bases_begin(), bases_end()); |
590 | } |
591 | base_class_const_range bases() const { |
592 | return base_class_const_range(bases_begin(), bases_end()); |
593 | } |
594 | |
595 | base_class_iterator bases_begin() { return data().getBases(); } |
596 | base_class_const_iterator bases_begin() const { return data().getBases(); } |
597 | base_class_iterator bases_end() { return bases_begin() + data().NumBases; } |
598 | base_class_const_iterator bases_end() const { |
599 | return bases_begin() + data().NumBases; |
600 | } |
601 | |
602 | /// Retrieves the number of virtual base classes of this class. |
603 | unsigned getNumVBases() const { return data().NumVBases; } |
604 | |
605 | base_class_range vbases() { |
606 | return base_class_range(vbases_begin(), vbases_end()); |
607 | } |
608 | base_class_const_range vbases() const { |
609 | return base_class_const_range(vbases_begin(), vbases_end()); |
610 | } |
611 | |
612 | base_class_iterator vbases_begin() { return data().getVBases(); } |
613 | base_class_const_iterator vbases_begin() const { return data().getVBases(); } |
614 | base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; } |
615 | base_class_const_iterator vbases_end() const { |
616 | return vbases_begin() + data().NumVBases; |
617 | } |
618 | |
619 | /// Determine whether this class has any dependent base classes which |
620 | /// are not the current instantiation. |
621 | bool hasAnyDependentBases() const; |
622 | |
623 | /// Iterator access to method members. The method iterator visits |
624 | /// all method members of the class, including non-instance methods, |
625 | /// special methods, etc. |
626 | using method_iterator = specific_decl_iterator<CXXMethodDecl>; |
627 | using method_range = |
628 | llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>; |
629 | |
630 | method_range methods() const { |
631 | return method_range(method_begin(), method_end()); |
632 | } |
633 | |
634 | /// Method begin iterator. Iterates in the order the methods |
635 | /// were declared. |
636 | method_iterator method_begin() const { |
637 | return method_iterator(decls_begin()); |
638 | } |
639 | |
640 | /// Method past-the-end iterator. |
641 | method_iterator method_end() const { |
642 | return method_iterator(decls_end()); |
643 | } |
644 | |
645 | /// Iterator access to constructor members. |
646 | using ctor_iterator = specific_decl_iterator<CXXConstructorDecl>; |
647 | using ctor_range = |
648 | llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>; |
649 | |
650 | ctor_range ctors() const { return ctor_range(ctor_begin(), ctor_end()); } |
651 | |
652 | ctor_iterator ctor_begin() const { |
653 | return ctor_iterator(decls_begin()); |
654 | } |
655 | |
656 | ctor_iterator ctor_end() const { |
657 | return ctor_iterator(decls_end()); |
658 | } |
659 | |
660 | /// An iterator over friend declarations. All of these are defined |
661 | /// in DeclFriend.h. |
662 | class friend_iterator; |
663 | using friend_range = llvm::iterator_range<friend_iterator>; |
664 | |
665 | friend_range friends() const; |
666 | friend_iterator friend_begin() const; |
667 | friend_iterator friend_end() const; |
668 | void pushFriendDecl(FriendDecl *FD); |
669 | |
670 | /// Determines whether this record has any friends. |
671 | bool hasFriends() const { |
672 | return data().FirstFriend.isValid(); |
673 | } |
674 | |
675 | /// \c true if a defaulted copy constructor for this class would be |
676 | /// deleted. |
677 | bool defaultedCopyConstructorIsDeleted() const { |
678 | assert((!needsOverloadResolutionForCopyConstructor() ||(((!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 680, __PRETTY_FUNCTION__)) |
679 | (data().DeclaredSpecialMembers & SMF_CopyConstructor)) &&(((!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 680, __PRETTY_FUNCTION__)) |
680 | "this property has not yet been computed by Sema")(((!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 680, __PRETTY_FUNCTION__)); |
681 | return data().DefaultedCopyConstructorIsDeleted; |
682 | } |
683 | |
684 | /// \c true if a defaulted move constructor for this class would be |
685 | /// deleted. |
686 | bool defaultedMoveConstructorIsDeleted() const { |
687 | assert((!needsOverloadResolutionForMoveConstructor() ||(((!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 689, __PRETTY_FUNCTION__)) |
688 | (data().DeclaredSpecialMembers & SMF_MoveConstructor)) &&(((!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 689, __PRETTY_FUNCTION__)) |
689 | "this property has not yet been computed by Sema")(((!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 689, __PRETTY_FUNCTION__)); |
690 | return data().DefaultedMoveConstructorIsDeleted; |
691 | } |
692 | |
693 | /// \c true if a defaulted destructor for this class would be deleted. |
694 | bool defaultedDestructorIsDeleted() const { |
695 | assert((!needsOverloadResolutionForDestructor() ||(((!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 697, __PRETTY_FUNCTION__)) |
696 | (data().DeclaredSpecialMembers & SMF_Destructor)) &&(((!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 697, __PRETTY_FUNCTION__)) |
697 | "this property has not yet been computed by Sema")(((!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 697, __PRETTY_FUNCTION__)); |
698 | return data().DefaultedDestructorIsDeleted; |
699 | } |
700 | |
701 | /// \c true if we know for sure that this class has a single, |
702 | /// accessible, unambiguous copy constructor that is not deleted. |
703 | bool hasSimpleCopyConstructor() const { |
704 | return !hasUserDeclaredCopyConstructor() && |
705 | !data().DefaultedCopyConstructorIsDeleted; |
706 | } |
707 | |
708 | /// \c true if we know for sure that this class has a single, |
709 | /// accessible, unambiguous move constructor that is not deleted. |
710 | bool hasSimpleMoveConstructor() const { |
711 | return !hasUserDeclaredMoveConstructor() && hasMoveConstructor() && |
712 | !data().DefaultedMoveConstructorIsDeleted; |
713 | } |
714 | |
715 | /// \c true if we know for sure that this class has a single, |
716 | /// accessible, unambiguous copy assignment operator that is not deleted. |
717 | bool hasSimpleCopyAssignment() const { |
718 | return !hasUserDeclaredCopyAssignment() && |
719 | !data().DefaultedCopyAssignmentIsDeleted; |
720 | } |
721 | |
722 | /// \c true if we know for sure that this class has a single, |
723 | /// accessible, unambiguous move assignment operator that is not deleted. |
724 | bool hasSimpleMoveAssignment() const { |
725 | return !hasUserDeclaredMoveAssignment() && hasMoveAssignment() && |
726 | !data().DefaultedMoveAssignmentIsDeleted; |
727 | } |
728 | |
729 | /// \c true if we know for sure that this class has an accessible |
730 | /// destructor that is not deleted. |
731 | bool hasSimpleDestructor() const { |
732 | return !hasUserDeclaredDestructor() && |
733 | !data().DefaultedDestructorIsDeleted; |
734 | } |
735 | |
736 | /// Determine whether this class has any default constructors. |
737 | bool hasDefaultConstructor() const { |
738 | return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) || |
739 | needsImplicitDefaultConstructor(); |
740 | } |
741 | |
742 | /// Determine if we need to declare a default constructor for |
743 | /// this class. |
744 | /// |
745 | /// This value is used for lazy creation of default constructors. |
746 | bool needsImplicitDefaultConstructor() const { |
747 | return (!data().UserDeclaredConstructor && |
748 | !(data().DeclaredSpecialMembers & SMF_DefaultConstructor) && |
749 | (!isLambda() || lambdaIsDefaultConstructibleAndAssignable())) || |
750 | // FIXME: Proposed fix to core wording issue: if a class inherits |
751 | // a default constructor and doesn't explicitly declare one, one |
752 | // is declared implicitly. |
753 | (data().HasInheritedDefaultConstructor && |
754 | !(data().DeclaredSpecialMembers & SMF_DefaultConstructor)); |
755 | } |
756 | |
757 | /// Determine whether this class has any user-declared constructors. |
758 | /// |
759 | /// When true, a default constructor will not be implicitly declared. |
760 | bool hasUserDeclaredConstructor() const { |
761 | return data().UserDeclaredConstructor; |
762 | } |
763 | |
764 | /// Whether this class has a user-provided default constructor |
765 | /// per C++11. |
766 | bool hasUserProvidedDefaultConstructor() const { |
767 | return data().UserProvidedDefaultConstructor; |
768 | } |
769 | |
770 | /// Determine whether this class has a user-declared copy constructor. |
771 | /// |
772 | /// When false, a copy constructor will be implicitly declared. |
773 | bool hasUserDeclaredCopyConstructor() const { |
774 | return data().UserDeclaredSpecialMembers & SMF_CopyConstructor; |
775 | } |
776 | |
777 | /// Determine whether this class needs an implicit copy |
778 | /// constructor to be lazily declared. |
779 | bool needsImplicitCopyConstructor() const { |
780 | return !(data().DeclaredSpecialMembers & SMF_CopyConstructor); |
781 | } |
782 | |
783 | /// Determine whether we need to eagerly declare a defaulted copy |
784 | /// constructor for this class. |
785 | bool needsOverloadResolutionForCopyConstructor() const { |
786 | // C++17 [class.copy.ctor]p6: |
787 | // If the class definition declares a move constructor or move assignment |
788 | // operator, the implicitly declared copy constructor is defined as |
789 | // deleted. |
790 | // In MSVC mode, sometimes a declared move assignment does not delete an |
791 | // implicit copy constructor, so defer this choice to Sema. |
792 | if (data().UserDeclaredSpecialMembers & |
793 | (SMF_MoveConstructor | SMF_MoveAssignment)) |
794 | return true; |
795 | return data().NeedOverloadResolutionForCopyConstructor; |
796 | } |
797 | |
798 | /// Determine whether an implicit copy constructor for this type |
799 | /// would have a parameter with a const-qualified reference type. |
800 | bool implicitCopyConstructorHasConstParam() const { |
801 | return data().ImplicitCopyConstructorCanHaveConstParamForNonVBase && |
802 | (isAbstract() || |
803 | data().ImplicitCopyConstructorCanHaveConstParamForVBase); |
804 | } |
805 | |
806 | /// Determine whether this class has a copy constructor with |
807 | /// a parameter type which is a reference to a const-qualified type. |
808 | bool hasCopyConstructorWithConstParam() const { |
809 | return data().HasDeclaredCopyConstructorWithConstParam || |
810 | (needsImplicitCopyConstructor() && |
811 | implicitCopyConstructorHasConstParam()); |
812 | } |
813 | |
814 | /// Whether this class has a user-declared move constructor or |
815 | /// assignment operator. |
816 | /// |
817 | /// When false, a move constructor and assignment operator may be |
818 | /// implicitly declared. |
819 | bool hasUserDeclaredMoveOperation() const { |
820 | return data().UserDeclaredSpecialMembers & |
821 | (SMF_MoveConstructor | SMF_MoveAssignment); |
822 | } |
823 | |
824 | /// Determine whether this class has had a move constructor |
825 | /// declared by the user. |
826 | bool hasUserDeclaredMoveConstructor() const { |
827 | return data().UserDeclaredSpecialMembers & SMF_MoveConstructor; |
828 | } |
829 | |
830 | /// Determine whether this class has a move constructor. |
831 | bool hasMoveConstructor() const { |
832 | return (data().DeclaredSpecialMembers & SMF_MoveConstructor) || |
833 | needsImplicitMoveConstructor(); |
834 | } |
835 | |
836 | /// Set that we attempted to declare an implicit copy |
837 | /// constructor, but overload resolution failed so we deleted it. |
838 | void setImplicitCopyConstructorIsDeleted() { |
839 | assert((data().DefaultedCopyConstructorIsDeleted ||(((data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor ()) && "Copy constructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor()) && \"Copy constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 841, __PRETTY_FUNCTION__)) |
840 | needsOverloadResolutionForCopyConstructor()) &&(((data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor ()) && "Copy constructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor()) && \"Copy constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 841, __PRETTY_FUNCTION__)) |
841 | "Copy constructor should not be deleted")(((data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor ()) && "Copy constructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor()) && \"Copy constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 841, __PRETTY_FUNCTION__)); |
842 | data().DefaultedCopyConstructorIsDeleted = true; |
843 | } |
844 | |
845 | /// Set that we attempted to declare an implicit move |
846 | /// constructor, but overload resolution failed so we deleted it. |
847 | void setImplicitMoveConstructorIsDeleted() { |
848 | assert((data().DefaultedMoveConstructorIsDeleted ||(((data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor ()) && "move constructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor()) && \"move constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 850, __PRETTY_FUNCTION__)) |
849 | needsOverloadResolutionForMoveConstructor()) &&(((data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor ()) && "move constructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor()) && \"move constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 850, __PRETTY_FUNCTION__)) |
850 | "move constructor should not be deleted")(((data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor ()) && "move constructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor()) && \"move constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 850, __PRETTY_FUNCTION__)); |
851 | data().DefaultedMoveConstructorIsDeleted = true; |
852 | } |
853 | |
854 | /// Set that we attempted to declare an implicit destructor, |
855 | /// but overload resolution failed so we deleted it. |
856 | void setImplicitDestructorIsDeleted() { |
857 | assert((data().DefaultedDestructorIsDeleted ||(((data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor ()) && "destructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor()) && \"destructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 859, __PRETTY_FUNCTION__)) |
858 | needsOverloadResolutionForDestructor()) &&(((data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor ()) && "destructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor()) && \"destructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 859, __PRETTY_FUNCTION__)) |
859 | "destructor should not be deleted")(((data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor ()) && "destructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor()) && \"destructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 859, __PRETTY_FUNCTION__)); |
860 | data().DefaultedDestructorIsDeleted = true; |
861 | } |
862 | |
863 | /// Determine whether this class should get an implicit move |
864 | /// constructor or if any existing special member function inhibits this. |
865 | bool needsImplicitMoveConstructor() const { |
866 | return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) && |
867 | !hasUserDeclaredCopyConstructor() && |
868 | !hasUserDeclaredCopyAssignment() && |
869 | !hasUserDeclaredMoveAssignment() && |
870 | !hasUserDeclaredDestructor(); |
871 | } |
872 | |
873 | /// Determine whether we need to eagerly declare a defaulted move |
874 | /// constructor for this class. |
875 | bool needsOverloadResolutionForMoveConstructor() const { |
876 | return data().NeedOverloadResolutionForMoveConstructor; |
877 | } |
878 | |
879 | /// Determine whether this class has a user-declared copy assignment |
880 | /// operator. |
881 | /// |
882 | /// When false, a copy assignment operator will be implicitly declared. |
883 | bool hasUserDeclaredCopyAssignment() const { |
884 | return data().UserDeclaredSpecialMembers & SMF_CopyAssignment; |
885 | } |
886 | |
887 | /// Set that we attempted to declare an implicit copy assignment |
888 | /// operator, but overload resolution failed so we deleted it. |
889 | void setImplicitCopyAssignmentIsDeleted() { |
890 | assert((data().DefaultedCopyAssignmentIsDeleted ||(((data().DefaultedCopyAssignmentIsDeleted || needsOverloadResolutionForCopyAssignment ()) && "copy assignment should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedCopyAssignmentIsDeleted || needsOverloadResolutionForCopyAssignment()) && \"copy assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 892, __PRETTY_FUNCTION__)) |
891 | needsOverloadResolutionForCopyAssignment()) &&(((data().DefaultedCopyAssignmentIsDeleted || needsOverloadResolutionForCopyAssignment ()) && "copy assignment should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedCopyAssignmentIsDeleted || needsOverloadResolutionForCopyAssignment()) && \"copy assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 892, __PRETTY_FUNCTION__)) |
892 | "copy assignment should not be deleted")(((data().DefaultedCopyAssignmentIsDeleted || needsOverloadResolutionForCopyAssignment ()) && "copy assignment should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedCopyAssignmentIsDeleted || needsOverloadResolutionForCopyAssignment()) && \"copy assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 892, __PRETTY_FUNCTION__)); |
893 | data().DefaultedCopyAssignmentIsDeleted = true; |
894 | } |
895 | |
896 | /// Determine whether this class needs an implicit copy |
897 | /// assignment operator to be lazily declared. |
898 | bool needsImplicitCopyAssignment() const { |
899 | return !(data().DeclaredSpecialMembers & SMF_CopyAssignment); |
900 | } |
901 | |
902 | /// Determine whether we need to eagerly declare a defaulted copy |
903 | /// assignment operator for this class. |
904 | bool needsOverloadResolutionForCopyAssignment() const { |
905 | // C++20 [class.copy.assign]p2: |
906 | // If the class definition declares a move constructor or move assignment |
907 | // operator, the implicitly declared copy assignment operator is defined |
908 | // as deleted. |
909 | // In MSVC mode, sometimes a declared move constructor does not delete an |
910 | // implicit copy assignment, so defer this choice to Sema. |
911 | if (data().UserDeclaredSpecialMembers & |
912 | (SMF_MoveConstructor | SMF_MoveAssignment)) |
913 | return true; |
914 | return data().NeedOverloadResolutionForCopyAssignment; |
915 | } |
916 | |
917 | /// Determine whether an implicit copy assignment operator for this |
918 | /// type would have a parameter with a const-qualified reference type. |
919 | bool implicitCopyAssignmentHasConstParam() const { |
920 | return data().ImplicitCopyAssignmentHasConstParam; |
921 | } |
922 | |
923 | /// Determine whether this class has a copy assignment operator with |
924 | /// a parameter type which is a reference to a const-qualified type or is not |
925 | /// a reference. |
926 | bool hasCopyAssignmentWithConstParam() const { |
927 | return data().HasDeclaredCopyAssignmentWithConstParam || |
928 | (needsImplicitCopyAssignment() && |
929 | implicitCopyAssignmentHasConstParam()); |
930 | } |
931 | |
932 | /// Determine whether this class has had a move assignment |
933 | /// declared by the user. |
934 | bool hasUserDeclaredMoveAssignment() const { |
935 | return data().UserDeclaredSpecialMembers & SMF_MoveAssignment; |
936 | } |
937 | |
938 | /// Determine whether this class has a move assignment operator. |
939 | bool hasMoveAssignment() const { |
940 | return (data().DeclaredSpecialMembers & SMF_MoveAssignment) || |
941 | needsImplicitMoveAssignment(); |
942 | } |
943 | |
944 | /// Set that we attempted to declare an implicit move assignment |
945 | /// operator, but overload resolution failed so we deleted it. |
946 | void setImplicitMoveAssignmentIsDeleted() { |
947 | assert((data().DefaultedMoveAssignmentIsDeleted ||(((data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment ()) && "move assignment should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment()) && \"move assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 949, __PRETTY_FUNCTION__)) |
948 | needsOverloadResolutionForMoveAssignment()) &&(((data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment ()) && "move assignment should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment()) && \"move assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 949, __PRETTY_FUNCTION__)) |
949 | "move assignment should not be deleted")(((data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment ()) && "move assignment should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment()) && \"move assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 949, __PRETTY_FUNCTION__)); |
950 | data().DefaultedMoveAssignmentIsDeleted = true; |
951 | } |
952 | |
953 | /// Determine whether this class should get an implicit move |
954 | /// assignment operator or if any existing special member function inhibits |
955 | /// this. |
956 | bool needsImplicitMoveAssignment() const { |
957 | return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) && |
958 | !hasUserDeclaredCopyConstructor() && |
959 | !hasUserDeclaredCopyAssignment() && |
960 | !hasUserDeclaredMoveConstructor() && |
961 | !hasUserDeclaredDestructor() && |
962 | (!isLambda() || lambdaIsDefaultConstructibleAndAssignable()); |
963 | } |
964 | |
965 | /// Determine whether we need to eagerly declare a move assignment |
966 | /// operator for this class. |
967 | bool needsOverloadResolutionForMoveAssignment() const { |
968 | return data().NeedOverloadResolutionForMoveAssignment; |
969 | } |
970 | |
971 | /// Determine whether this class has a user-declared destructor. |
972 | /// |
973 | /// When false, a destructor will be implicitly declared. |
974 | bool hasUserDeclaredDestructor() const { |
975 | return data().UserDeclaredSpecialMembers & SMF_Destructor; |
976 | } |
977 | |
978 | /// Determine whether this class needs an implicit destructor to |
979 | /// be lazily declared. |
980 | bool needsImplicitDestructor() const { |
981 | return !(data().DeclaredSpecialMembers & SMF_Destructor); |
982 | } |
983 | |
984 | /// Determine whether we need to eagerly declare a destructor for this |
985 | /// class. |
986 | bool needsOverloadResolutionForDestructor() const { |
987 | return data().NeedOverloadResolutionForDestructor; |
988 | } |
989 | |
990 | /// Determine whether this class describes a lambda function object. |
991 | bool isLambda() const { |
992 | // An update record can't turn a non-lambda into a lambda. |
993 | auto *DD = DefinitionData; |
994 | return DD && DD->IsLambda; |
995 | } |
996 | |
997 | /// Determine whether this class describes a generic |
998 | /// lambda function object (i.e. function call operator is |
999 | /// a template). |
1000 | bool isGenericLambda() const; |
1001 | |
1002 | /// Determine whether this lambda should have an implicit default constructor |
1003 | /// and copy and move assignment operators. |
1004 | bool lambdaIsDefaultConstructibleAndAssignable() const; |
1005 | |
1006 | /// Retrieve the lambda call operator of the closure type |
1007 | /// if this is a closure type. |
1008 | CXXMethodDecl *getLambdaCallOperator() const; |
1009 | |
1010 | /// Retrieve the dependent lambda call operator of the closure type |
1011 | /// if this is a templated closure type. |
1012 | FunctionTemplateDecl *getDependentLambdaCallOperator() const; |
1013 | |
1014 | /// Retrieve the lambda static invoker, the address of which |
1015 | /// is returned by the conversion operator, and the body of which |
1016 | /// is forwarded to the lambda call operator. The version that does not |
1017 | /// take a calling convention uses the 'default' calling convention for free |
1018 | /// functions if the Lambda's calling convention was not modified via |
1019 | /// attribute. Otherwise, it will return the calling convention specified for |
1020 | /// the lambda. |
1021 | CXXMethodDecl *getLambdaStaticInvoker() const; |
1022 | CXXMethodDecl *getLambdaStaticInvoker(CallingConv CC) const; |
1023 | |
1024 | /// Retrieve the generic lambda's template parameter list. |
1025 | /// Returns null if the class does not represent a lambda or a generic |
1026 | /// lambda. |
1027 | TemplateParameterList *getGenericLambdaTemplateParameterList() const; |
1028 | |
1029 | /// Retrieve the lambda template parameters that were specified explicitly. |
1030 | ArrayRef<NamedDecl *> getLambdaExplicitTemplateParameters() const; |
1031 | |
1032 | LambdaCaptureDefault getLambdaCaptureDefault() const { |
1033 | assert(isLambda())((isLambda()) ? static_cast<void> (0) : __assert_fail ( "isLambda()", "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 1033, __PRETTY_FUNCTION__)); |
1034 | return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault); |
1035 | } |
1036 | |
1037 | /// Set the captures for this lambda closure type. |
1038 | void setCaptures(ASTContext &Context, ArrayRef<LambdaCapture> Captures); |
1039 | |
1040 | /// For a closure type, retrieve the mapping from captured |
1041 | /// variables and \c this to the non-static data members that store the |
1042 | /// values or references of the captures. |
1043 | /// |
1044 | /// \param Captures Will be populated with the mapping from captured |
1045 | /// variables to the corresponding fields. |
1046 | /// |
1047 | /// \param ThisCapture Will be set to the field declaration for the |
1048 | /// \c this capture. |
1049 | /// |
1050 | /// \note No entries will be added for init-captures, as they do not capture |
1051 | /// variables. |
1052 | void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures, |
1053 | FieldDecl *&ThisCapture) const; |
1054 | |
1055 | using capture_const_iterator = const LambdaCapture *; |
1056 | using capture_const_range = llvm::iterator_range<capture_const_iterator>; |
1057 | |
1058 | capture_const_range captures() const { |
1059 | return capture_const_range(captures_begin(), captures_end()); |
1060 | } |
1061 | |
1062 | capture_const_iterator captures_begin() const { |
1063 | return isLambda() ? getLambdaData().Captures : nullptr; |
1064 | } |
1065 | |
1066 | capture_const_iterator captures_end() const { |
1067 | return isLambda() ? captures_begin() + getLambdaData().NumCaptures |
1068 | : nullptr; |
1069 | } |
1070 | |
1071 | unsigned capture_size() const { return getLambdaData().NumCaptures; } |
1072 | |
1073 | using conversion_iterator = UnresolvedSetIterator; |
1074 | |
1075 | conversion_iterator conversion_begin() const { |
1076 | return data().Conversions.get(getASTContext()).begin(); |
1077 | } |
1078 | |
1079 | conversion_iterator conversion_end() const { |
1080 | return data().Conversions.get(getASTContext()).end(); |
1081 | } |
1082 | |
1083 | /// Removes a conversion function from this class. The conversion |
1084 | /// function must currently be a member of this class. Furthermore, |
1085 | /// this class must currently be in the process of being defined. |
1086 | void removeConversion(const NamedDecl *Old); |
1087 | |
1088 | /// Get all conversion functions visible in current class, |
1089 | /// including conversion function templates. |
1090 | llvm::iterator_range<conversion_iterator> |
1091 | getVisibleConversionFunctions() const; |
1092 | |
1093 | /// Determine whether this class is an aggregate (C++ [dcl.init.aggr]), |
1094 | /// which is a class with no user-declared constructors, no private |
1095 | /// or protected non-static data members, no base classes, and no virtual |
1096 | /// functions (C++ [dcl.init.aggr]p1). |
1097 | bool isAggregate() const { return data().Aggregate; } |
1098 | |
1099 | /// Whether this class has any in-class initializers |
1100 | /// for non-static data members (including those in anonymous unions or |
1101 | /// structs). |
1102 | bool hasInClassInitializer() const { return data().HasInClassInitializer; } |
1103 | |
1104 | /// Whether this class or any of its subobjects has any members of |
1105 | /// reference type which would make value-initialization ill-formed. |
1106 | /// |
1107 | /// Per C++03 [dcl.init]p5: |
1108 | /// - if T is a non-union class type without a user-declared constructor, |
1109 | /// then every non-static data member and base-class component of T is |
1110 | /// value-initialized [...] A program that calls for [...] |
1111 | /// value-initialization of an entity of reference type is ill-formed. |
1112 | bool hasUninitializedReferenceMember() const { |
1113 | return !isUnion() && !hasUserDeclaredConstructor() && |
1114 | data().HasUninitializedReferenceMember; |
1115 | } |
1116 | |
1117 | /// Whether this class is a POD-type (C++ [class]p4) |
1118 | /// |
1119 | /// For purposes of this function a class is POD if it is an aggregate |
1120 | /// that has no non-static non-POD data members, no reference data |
1121 | /// members, no user-defined copy assignment operator and no |
1122 | /// user-defined destructor. |
1123 | /// |
1124 | /// Note that this is the C++ TR1 definition of POD. |
1125 | bool isPOD() const { return data().PlainOldData; } |
1126 | |
1127 | /// True if this class is C-like, without C++-specific features, e.g. |
1128 | /// it contains only public fields, no bases, tag kind is not 'class', etc. |
1129 | bool isCLike() const; |
1130 | |
1131 | /// Determine whether this is an empty class in the sense of |
1132 | /// (C++11 [meta.unary.prop]). |
1133 | /// |
1134 | /// The CXXRecordDecl is a class type, but not a union type, |
1135 | /// with no non-static data members other than bit-fields of length 0, |
1136 | /// no virtual member functions, no virtual base classes, |
1137 | /// and no base class B for which is_empty<B>::value is false. |
1138 | /// |
1139 | /// \note This does NOT include a check for union-ness. |
1140 | bool isEmpty() const { return data().Empty; } |
1141 | |
1142 | bool hasPrivateFields() const { |
1143 | return data().HasPrivateFields; |
1144 | } |
1145 | |
1146 | bool hasProtectedFields() const { |
1147 | return data().HasProtectedFields; |
1148 | } |
1149 | |
1150 | /// Determine whether this class has direct non-static data members. |
1151 | bool hasDirectFields() const { |
1152 | auto &D = data(); |
1153 | return D.HasPublicFields || D.HasProtectedFields || D.HasPrivateFields; |
1154 | } |
1155 | |
1156 | /// Whether this class is polymorphic (C++ [class.virtual]), |
1157 | /// which means that the class contains or inherits a virtual function. |
1158 | bool isPolymorphic() const { return data().Polymorphic; } |
1159 | |
1160 | /// Determine whether this class has a pure virtual function. |
1161 | /// |
1162 | /// The class is is abstract per (C++ [class.abstract]p2) if it declares |
1163 | /// a pure virtual function or inherits a pure virtual function that is |
1164 | /// not overridden. |
1165 | bool isAbstract() const { return data().Abstract; } |
1166 | |
1167 | /// Determine whether this class is standard-layout per |
1168 | /// C++ [class]p7. |
1169 | bool isStandardLayout() const { return data().IsStandardLayout; } |
1170 | |
1171 | /// Determine whether this class was standard-layout per |
1172 | /// C++11 [class]p7, specifically using the C++11 rules without any DRs. |
1173 | bool isCXX11StandardLayout() const { return data().IsCXX11StandardLayout; } |
1174 | |
1175 | /// Determine whether this class, or any of its class subobjects, |
1176 | /// contains a mutable field. |
1177 | bool hasMutableFields() const { return data().HasMutableFields; } |
1178 | |
1179 | /// Determine whether this class has any variant members. |
1180 | bool hasVariantMembers() const { return data().HasVariantMembers; } |
1181 | |
1182 | /// Determine whether this class has a trivial default constructor |
1183 | /// (C++11 [class.ctor]p5). |
1184 | bool hasTrivialDefaultConstructor() const { |
1185 | return hasDefaultConstructor() && |
1186 | (data().HasTrivialSpecialMembers & SMF_DefaultConstructor); |
1187 | } |
1188 | |
1189 | /// Determine whether this class has a non-trivial default constructor |
1190 | /// (C++11 [class.ctor]p5). |
1191 | bool hasNonTrivialDefaultConstructor() const { |
1192 | return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) || |
1193 | (needsImplicitDefaultConstructor() && |
1194 | !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor)); |
1195 | } |
1196 | |
1197 | /// Determine whether this class has at least one constexpr constructor |
1198 | /// other than the copy or move constructors. |
1199 | bool hasConstexprNonCopyMoveConstructor() const { |
1200 | return data().HasConstexprNonCopyMoveConstructor || |
1201 | (needsImplicitDefaultConstructor() && |
1202 | defaultedDefaultConstructorIsConstexpr()); |
1203 | } |
1204 | |
1205 | /// Determine whether a defaulted default constructor for this class |
1206 | /// would be constexpr. |
1207 | bool defaultedDefaultConstructorIsConstexpr() const { |
1208 | return data().DefaultedDefaultConstructorIsConstexpr && |
1209 | (!isUnion() || hasInClassInitializer() || !hasVariantMembers() || |
1210 | getLangOpts().CPlusPlus20); |
1211 | } |
1212 | |
1213 | /// Determine whether this class has a constexpr default constructor. |
1214 | bool hasConstexprDefaultConstructor() const { |
1215 | return data().HasConstexprDefaultConstructor || |
1216 | (needsImplicitDefaultConstructor() && |
1217 | defaultedDefaultConstructorIsConstexpr()); |
1218 | } |
1219 | |
1220 | /// Determine whether this class has a trivial copy constructor |
1221 | /// (C++ [class.copy]p6, C++11 [class.copy]p12) |
1222 | bool hasTrivialCopyConstructor() const { |
1223 | return data().HasTrivialSpecialMembers & SMF_CopyConstructor; |
1224 | } |
1225 | |
1226 | bool hasTrivialCopyConstructorForCall() const { |
1227 | return data().HasTrivialSpecialMembersForCall & SMF_CopyConstructor; |
1228 | } |
1229 | |
1230 | /// Determine whether this class has a non-trivial copy constructor |
1231 | /// (C++ [class.copy]p6, C++11 [class.copy]p12) |
1232 | bool hasNonTrivialCopyConstructor() const { |
1233 | return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor || |
1234 | !hasTrivialCopyConstructor(); |
1235 | } |
1236 | |
1237 | bool hasNonTrivialCopyConstructorForCall() const { |
1238 | return (data().DeclaredNonTrivialSpecialMembersForCall & |
1239 | SMF_CopyConstructor) || |
1240 | !hasTrivialCopyConstructorForCall(); |
1241 | } |
1242 | |
1243 | /// Determine whether this class has a trivial move constructor |
1244 | /// (C++11 [class.copy]p12) |
1245 | bool hasTrivialMoveConstructor() const { |
1246 | return hasMoveConstructor() && |
1247 | (data().HasTrivialSpecialMembers & SMF_MoveConstructor); |
1248 | } |
1249 | |
1250 | bool hasTrivialMoveConstructorForCall() const { |
1251 | return hasMoveConstructor() && |
1252 | (data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor); |
1253 | } |
1254 | |
1255 | /// Determine whether this class has a non-trivial move constructor |
1256 | /// (C++11 [class.copy]p12) |
1257 | bool hasNonTrivialMoveConstructor() const { |
1258 | return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) || |
1259 | (needsImplicitMoveConstructor() && |
1260 | !(data().HasTrivialSpecialMembers & SMF_MoveConstructor)); |
1261 | } |
1262 | |
1263 | bool hasNonTrivialMoveConstructorForCall() const { |
1264 | return (data().DeclaredNonTrivialSpecialMembersForCall & |
1265 | SMF_MoveConstructor) || |
1266 | (needsImplicitMoveConstructor() && |
1267 | !(data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor)); |
1268 | } |
1269 | |
1270 | /// Determine whether this class has a trivial copy assignment operator |
1271 | /// (C++ [class.copy]p11, C++11 [class.copy]p25) |
1272 | bool hasTrivialCopyAssignment() const { |
1273 | return data().HasTrivialSpecialMembers & SMF_CopyAssignment; |
1274 | } |
1275 | |
1276 | /// Determine whether this class has a non-trivial copy assignment |
1277 | /// operator (C++ [class.copy]p11, C++11 [class.copy]p25) |
1278 | bool hasNonTrivialCopyAssignment() const { |
1279 | return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment || |
1280 | !hasTrivialCopyAssignment(); |
1281 | } |
1282 | |
1283 | /// Determine whether this class has a trivial move assignment operator |
1284 | /// (C++11 [class.copy]p25) |
1285 | bool hasTrivialMoveAssignment() const { |
1286 | return hasMoveAssignment() && |
1287 | (data().HasTrivialSpecialMembers & SMF_MoveAssignment); |
1288 | } |
1289 | |
1290 | /// Determine whether this class has a non-trivial move assignment |
1291 | /// operator (C++11 [class.copy]p25) |
1292 | bool hasNonTrivialMoveAssignment() const { |
1293 | return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) || |
1294 | (needsImplicitMoveAssignment() && |
1295 | !(data().HasTrivialSpecialMembers & SMF_MoveAssignment)); |
1296 | } |
1297 | |
1298 | /// Determine whether a defaulted default constructor for this class |
1299 | /// would be constexpr. |
1300 | bool defaultedDestructorIsConstexpr() const { |
1301 | return data().DefaultedDestructorIsConstexpr && |
1302 | getLangOpts().CPlusPlus20; |
1303 | } |
1304 | |
1305 | /// Determine whether this class has a constexpr destructor. |
1306 | bool hasConstexprDestructor() const; |
1307 | |
1308 | /// Determine whether this class has a trivial destructor |
1309 | /// (C++ [class.dtor]p3) |
1310 | bool hasTrivialDestructor() const { |
1311 | return data().HasTrivialSpecialMembers & SMF_Destructor; |
1312 | } |
1313 | |
1314 | bool hasTrivialDestructorForCall() const { |
1315 | return data().HasTrivialSpecialMembersForCall & SMF_Destructor; |
1316 | } |
1317 | |
1318 | /// Determine whether this class has a non-trivial destructor |
1319 | /// (C++ [class.dtor]p3) |
1320 | bool hasNonTrivialDestructor() const { |
1321 | return !(data().HasTrivialSpecialMembers & SMF_Destructor); |
1322 | } |
1323 | |
1324 | bool hasNonTrivialDestructorForCall() const { |
1325 | return !(data().HasTrivialSpecialMembersForCall & SMF_Destructor); |
1326 | } |
1327 | |
1328 | void setHasTrivialSpecialMemberForCall() { |
1329 | data().HasTrivialSpecialMembersForCall = |
1330 | (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor); |
1331 | } |
1332 | |
1333 | /// Determine whether declaring a const variable with this type is ok |
1334 | /// per core issue 253. |
1335 | bool allowConstDefaultInit() const { |
1336 | return !data().HasUninitializedFields || |
1337 | !(data().HasDefaultedDefaultConstructor || |
1338 | needsImplicitDefaultConstructor()); |
1339 | } |
1340 | |
1341 | /// Determine whether this class has a destructor which has no |
1342 | /// semantic effect. |
1343 | /// |
1344 | /// Any such destructor will be trivial, public, defaulted and not deleted, |
1345 | /// and will call only irrelevant destructors. |
1346 | bool hasIrrelevantDestructor() const { |
1347 | return data().HasIrrelevantDestructor; |
1348 | } |
1349 | |
1350 | /// Determine whether this class has a non-literal or/ volatile type |
1351 | /// non-static data member or base class. |
1352 | bool hasNonLiteralTypeFieldsOrBases() const { |
1353 | return data().HasNonLiteralTypeFieldsOrBases; |
1354 | } |
1355 | |
1356 | /// Determine whether this class has a using-declaration that names |
1357 | /// a user-declared base class constructor. |
1358 | bool hasInheritedConstructor() const { |
1359 | return data().HasInheritedConstructor; |
1360 | } |
1361 | |
1362 | /// Determine whether this class has a using-declaration that names |
1363 | /// a base class assignment operator. |
1364 | bool hasInheritedAssignment() const { |
1365 | return data().HasInheritedAssignment; |
1366 | } |
1367 | |
1368 | /// Determine whether this class is considered trivially copyable per |
1369 | /// (C++11 [class]p6). |
1370 | bool isTriviallyCopyable() const; |
1371 | |
1372 | /// Determine whether this class is considered trivial. |
1373 | /// |
1374 | /// C++11 [class]p6: |
1375 | /// "A trivial class is a class that has a trivial default constructor and |
1376 | /// is trivially copyable." |
1377 | bool isTrivial() const { |
1378 | return isTriviallyCopyable() && hasTrivialDefaultConstructor(); |
1379 | } |
1380 | |
1381 | /// Determine whether this class is a literal type. |
1382 | /// |
1383 | /// C++11 [basic.types]p10: |
1384 | /// A class type that has all the following properties: |
1385 | /// - it has a trivial destructor |
1386 | /// - every constructor call and full-expression in the |
1387 | /// brace-or-equal-intializers for non-static data members (if any) is |
1388 | /// a constant expression. |
1389 | /// - it is an aggregate type or has at least one constexpr constructor |
1390 | /// or constructor template that is not a copy or move constructor, and |
1391 | /// - all of its non-static data members and base classes are of literal |
1392 | /// types |
1393 | /// |
1394 | /// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by |
1395 | /// treating types with trivial default constructors as literal types. |
1396 | /// |
1397 | /// Only in C++17 and beyond, are lambdas literal types. |
1398 | bool isLiteral() const { |
1399 | const LangOptions &LangOpts = getLangOpts(); |
1400 | return (LangOpts.CPlusPlus20 ? hasConstexprDestructor() |
1401 | : hasTrivialDestructor()) && |
1402 | (!isLambda() || LangOpts.CPlusPlus17) && |
1403 | !hasNonLiteralTypeFieldsOrBases() && |
1404 | (isAggregate() || isLambda() || |
1405 | hasConstexprNonCopyMoveConstructor() || |
1406 | hasTrivialDefaultConstructor()); |
1407 | } |
1408 | |
1409 | /// Determine whether this is a structural type. |
1410 | bool isStructural() const { |
1411 | return isLiteral() && data().StructuralIfLiteral; |
1412 | } |
1413 | |
1414 | /// If this record is an instantiation of a member class, |
1415 | /// retrieves the member class from which it was instantiated. |
1416 | /// |
1417 | /// This routine will return non-null for (non-templated) member |
1418 | /// classes of class templates. For example, given: |
1419 | /// |
1420 | /// \code |
1421 | /// template<typename T> |
1422 | /// struct X { |
1423 | /// struct A { }; |
1424 | /// }; |
1425 | /// \endcode |
1426 | /// |
1427 | /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl |
1428 | /// whose parent is the class template specialization X<int>. For |
1429 | /// this declaration, getInstantiatedFromMemberClass() will return |
1430 | /// the CXXRecordDecl X<T>::A. When a complete definition of |
1431 | /// X<int>::A is required, it will be instantiated from the |
1432 | /// declaration returned by getInstantiatedFromMemberClass(). |
1433 | CXXRecordDecl *getInstantiatedFromMemberClass() const; |
1434 | |
1435 | /// If this class is an instantiation of a member class of a |
1436 | /// class template specialization, retrieves the member specialization |
1437 | /// information. |
1438 | MemberSpecializationInfo *getMemberSpecializationInfo() const; |
1439 | |
1440 | /// Specify that this record is an instantiation of the |
1441 | /// member class \p RD. |
1442 | void setInstantiationOfMemberClass(CXXRecordDecl *RD, |
1443 | TemplateSpecializationKind TSK); |
1444 | |
1445 | /// Retrieves the class template that is described by this |
1446 | /// class declaration. |
1447 | /// |
1448 | /// Every class template is represented as a ClassTemplateDecl and a |
1449 | /// CXXRecordDecl. The former contains template properties (such as |
1450 | /// the template parameter lists) while the latter contains the |
1451 | /// actual description of the template's |
1452 | /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the |
1453 | /// CXXRecordDecl that from a ClassTemplateDecl, while |
1454 | /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from |
1455 | /// a CXXRecordDecl. |
1456 | ClassTemplateDecl *getDescribedClassTemplate() const; |
1457 | |
1458 | void setDescribedClassTemplate(ClassTemplateDecl *Template); |
1459 | |
1460 | /// Determine whether this particular class is a specialization or |
1461 | /// instantiation of a class template or member class of a class template, |
1462 | /// and how it was instantiated or specialized. |
1463 | TemplateSpecializationKind getTemplateSpecializationKind() const; |
1464 | |
1465 | /// Set the kind of specialization or template instantiation this is. |
1466 | void setTemplateSpecializationKind(TemplateSpecializationKind TSK); |
1467 | |
1468 | /// Retrieve the record declaration from which this record could be |
1469 | /// instantiated. Returns null if this class is not a template instantiation. |
1470 | const CXXRecordDecl *getTemplateInstantiationPattern() const; |
1471 | |
1472 | CXXRecordDecl *getTemplateInstantiationPattern() { |
1473 | return const_cast<CXXRecordDecl *>(const_cast<const CXXRecordDecl *>(this) |
1474 | ->getTemplateInstantiationPattern()); |
1475 | } |
1476 | |
1477 | /// Returns the destructor decl for this class. |
1478 | CXXDestructorDecl *getDestructor() const; |
1479 | |
1480 | /// Returns true if the class destructor, or any implicitly invoked |
1481 | /// destructors are marked noreturn. |
1482 | bool isAnyDestructorNoReturn() const; |
1483 | |
1484 | /// If the class is a local class [class.local], returns |
1485 | /// the enclosing function declaration. |
1486 | const FunctionDecl *isLocalClass() const { |
1487 | if (const auto *RD = dyn_cast<CXXRecordDecl>(getDeclContext())) |
1488 | return RD->isLocalClass(); |
1489 | |
1490 | return dyn_cast<FunctionDecl>(getDeclContext()); |
1491 | } |
1492 | |
1493 | FunctionDecl *isLocalClass() { |
1494 | return const_cast<FunctionDecl*>( |
1495 | const_cast<const CXXRecordDecl*>(this)->isLocalClass()); |
1496 | } |
1497 | |
1498 | /// Determine whether this dependent class is a current instantiation, |
1499 | /// when viewed from within the given context. |
1500 | bool isCurrentInstantiation(const DeclContext *CurContext) const; |
1501 | |
1502 | /// Determine whether this class is derived from the class \p Base. |
1503 | /// |
1504 | /// This routine only determines whether this class is derived from \p Base, |
1505 | /// but does not account for factors that may make a Derived -> Base class |
1506 | /// ill-formed, such as private/protected inheritance or multiple, ambiguous |
1507 | /// base class subobjects. |
1508 | /// |
1509 | /// \param Base the base class we are searching for. |
1510 | /// |
1511 | /// \returns true if this class is derived from Base, false otherwise. |
1512 | bool isDerivedFrom(const CXXRecordDecl *Base) const; |
1513 | |
1514 | /// Determine whether this class is derived from the type \p Base. |
1515 | /// |
1516 | /// This routine only determines whether this class is derived from \p Base, |
1517 | /// but does not account for factors that may make a Derived -> Base class |
1518 | /// ill-formed, such as private/protected inheritance or multiple, ambiguous |
1519 | /// base class subobjects. |
1520 | /// |
1521 | /// \param Base the base class we are searching for. |
1522 | /// |
1523 | /// \param Paths will contain the paths taken from the current class to the |
1524 | /// given \p Base class. |
1525 | /// |
1526 | /// \returns true if this class is derived from \p Base, false otherwise. |
1527 | /// |
1528 | /// \todo add a separate parameter to configure IsDerivedFrom, rather than |
1529 | /// tangling input and output in \p Paths |
1530 | bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const; |
1531 | |
1532 | /// Determine whether this class is virtually derived from |
1533 | /// the class \p Base. |
1534 | /// |
1535 | /// This routine only determines whether this class is virtually |
1536 | /// derived from \p Base, but does not account for factors that may |
1537 | /// make a Derived -> Base class ill-formed, such as |
1538 | /// private/protected inheritance or multiple, ambiguous base class |
1539 | /// subobjects. |
1540 | /// |
1541 | /// \param Base the base class we are searching for. |
1542 | /// |
1543 | /// \returns true if this class is virtually derived from Base, |
1544 | /// false otherwise. |
1545 | bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const; |
1546 | |
1547 | /// Determine whether this class is provably not derived from |
1548 | /// the type \p Base. |
1549 | bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const; |
1550 | |
1551 | /// Function type used by forallBases() as a callback. |
1552 | /// |
1553 | /// \param BaseDefinition the definition of the base class |
1554 | /// |
1555 | /// \returns true if this base matched the search criteria |
1556 | using ForallBasesCallback = |
1557 | llvm::function_ref<bool(const CXXRecordDecl *BaseDefinition)>; |
1558 | |
1559 | /// Determines if the given callback holds for all the direct |
1560 | /// or indirect base classes of this type. |
1561 | /// |
1562 | /// The class itself does not count as a base class. This routine |
1563 | /// returns false if the class has non-computable base classes. |
1564 | /// |
1565 | /// \param BaseMatches Callback invoked for each (direct or indirect) base |
1566 | /// class of this type until a call returns false. |
1567 | bool forallBases(ForallBasesCallback BaseMatches) const; |
1568 | |
1569 | /// Function type used by lookupInBases() to determine whether a |
1570 | /// specific base class subobject matches the lookup criteria. |
1571 | /// |
1572 | /// \param Specifier the base-class specifier that describes the inheritance |
1573 | /// from the base class we are trying to match. |
1574 | /// |
1575 | /// \param Path the current path, from the most-derived class down to the |
1576 | /// base named by the \p Specifier. |
1577 | /// |
1578 | /// \returns true if this base matched the search criteria, false otherwise. |
1579 | using BaseMatchesCallback = |
1580 | llvm::function_ref<bool(const CXXBaseSpecifier *Specifier, |
1581 | CXXBasePath &Path)>; |
1582 | |
1583 | /// Look for entities within the base classes of this C++ class, |
1584 | /// transitively searching all base class subobjects. |
1585 | /// |
1586 | /// This routine uses the callback function \p BaseMatches to find base |
1587 | /// classes meeting some search criteria, walking all base class subobjects |
1588 | /// and populating the given \p Paths structure with the paths through the |
1589 | /// inheritance hierarchy that resulted in a match. On a successful search, |
1590 | /// the \p Paths structure can be queried to retrieve the matching paths and |
1591 | /// to determine if there were any ambiguities. |
1592 | /// |
1593 | /// \param BaseMatches callback function used to determine whether a given |
1594 | /// base matches the user-defined search criteria. |
1595 | /// |
1596 | /// \param Paths used to record the paths from this class to its base class |
1597 | /// subobjects that match the search criteria. |
1598 | /// |
1599 | /// \param LookupInDependent can be set to true to extend the search to |
1600 | /// dependent base classes. |
1601 | /// |
1602 | /// \returns true if there exists any path from this class to a base class |
1603 | /// subobject that matches the search criteria. |
1604 | bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths, |
1605 | bool LookupInDependent = false) const; |
1606 | |
1607 | /// Base-class lookup callback that determines whether the given |
1608 | /// base class specifier refers to a specific class declaration. |
1609 | /// |
1610 | /// This callback can be used with \c lookupInBases() to determine whether |
1611 | /// a given derived class has is a base class subobject of a particular type. |
1612 | /// The base record pointer should refer to the canonical CXXRecordDecl of the |
1613 | /// base class that we are searching for. |
1614 | static bool FindBaseClass(const CXXBaseSpecifier *Specifier, |
1615 | CXXBasePath &Path, const CXXRecordDecl *BaseRecord); |
1616 | |
1617 | /// Base-class lookup callback that determines whether the |
1618 | /// given base class specifier refers to a specific class |
1619 | /// declaration and describes virtual derivation. |
1620 | /// |
1621 | /// This callback can be used with \c lookupInBases() to determine |
1622 | /// whether a given derived class has is a virtual base class |
1623 | /// subobject of a particular type. The base record pointer should |
1624 | /// refer to the canonical CXXRecordDecl of the base class that we |
1625 | /// are searching for. |
1626 | static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier, |
1627 | CXXBasePath &Path, |
1628 | const CXXRecordDecl *BaseRecord); |
1629 | |
1630 | /// Retrieve the final overriders for each virtual member |
1631 | /// function in the class hierarchy where this class is the |
1632 | /// most-derived class in the class hierarchy. |
1633 | void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const; |
1634 | |
1635 | /// Get the indirect primary bases for this class. |
1636 | void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const; |
1637 | |
1638 | /// Determine whether this class has a member with the given name, possibly |
1639 | /// in a non-dependent base class. |
1640 | /// |
1641 | /// No check for ambiguity is performed, so this should never be used when |
1642 | /// implementing language semantics, but it may be appropriate for warnings, |
1643 | /// static analysis, or similar. |
1644 | bool hasMemberName(DeclarationName N) const; |
1645 | |
1646 | /// Performs an imprecise lookup of a dependent name in this class. |
1647 | /// |
1648 | /// This function does not follow strict semantic rules and should be used |
1649 | /// only when lookup rules can be relaxed, e.g. indexing. |
1650 | std::vector<const NamedDecl *> |
1651 | lookupDependentName(DeclarationName Name, |
1652 | llvm::function_ref<bool(const NamedDecl *ND)> Filter); |
1653 | |
1654 | /// Renders and displays an inheritance diagram |
1655 | /// for this C++ class and all of its base classes (transitively) using |
1656 | /// GraphViz. |
1657 | void viewInheritance(ASTContext& Context) const; |
1658 | |
1659 | /// Calculates the access of a decl that is reached |
1660 | /// along a path. |
1661 | static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, |
1662 | AccessSpecifier DeclAccess) { |
1663 | assert(DeclAccess != AS_none)((DeclAccess != AS_none) ? static_cast<void> (0) : __assert_fail ("DeclAccess != AS_none", "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 1663, __PRETTY_FUNCTION__)); |
1664 | if (DeclAccess == AS_private) return AS_none; |
1665 | return (PathAccess > DeclAccess ? PathAccess : DeclAccess); |
1666 | } |
1667 | |
1668 | /// Indicates that the declaration of a defaulted or deleted special |
1669 | /// member function is now complete. |
1670 | void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD); |
1671 | |
1672 | void setTrivialForCallFlags(CXXMethodDecl *MD); |
1673 | |
1674 | /// Indicates that the definition of this class is now complete. |
1675 | void completeDefinition() override; |
1676 | |
1677 | /// Indicates that the definition of this class is now complete, |
1678 | /// and provides a final overrider map to help determine |
1679 | /// |
1680 | /// \param FinalOverriders The final overrider map for this class, which can |
1681 | /// be provided as an optimization for abstract-class checking. If NULL, |
1682 | /// final overriders will be computed if they are needed to complete the |
1683 | /// definition. |
1684 | void completeDefinition(CXXFinalOverriderMap *FinalOverriders); |
1685 | |
1686 | /// Determine whether this class may end up being abstract, even though |
1687 | /// it is not yet known to be abstract. |
1688 | /// |
1689 | /// \returns true if this class is not known to be abstract but has any |
1690 | /// base classes that are abstract. In this case, \c completeDefinition() |
1691 | /// will need to compute final overriders to determine whether the class is |
1692 | /// actually abstract. |
1693 | bool mayBeAbstract() const; |
1694 | |
1695 | /// Determine whether it's impossible for a class to be derived from this |
1696 | /// class. This is best-effort, and may conservatively return false. |
1697 | bool isEffectivelyFinal() const; |
1698 | |
1699 | /// If this is the closure type of a lambda expression, retrieve the |
1700 | /// number to be used for name mangling in the Itanium C++ ABI. |
1701 | /// |
1702 | /// Zero indicates that this closure type has internal linkage, so the |
1703 | /// mangling number does not matter, while a non-zero value indicates which |
1704 | /// lambda expression this is in this particular context. |
1705 | unsigned getLambdaManglingNumber() const { |
1706 | assert(isLambda() && "Not a lambda closure type!")((isLambda() && "Not a lambda closure type!") ? static_cast <void> (0) : __assert_fail ("isLambda() && \"Not a lambda closure type!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 1706, __PRETTY_FUNCTION__)); |
1707 | return getLambdaData().ManglingNumber; |
1708 | } |
1709 | |
1710 | /// The lambda is known to has internal linkage no matter whether it has name |
1711 | /// mangling number. |
1712 | bool hasKnownLambdaInternalLinkage() const { |
1713 | assert(isLambda() && "Not a lambda closure type!")((isLambda() && "Not a lambda closure type!") ? static_cast <void> (0) : __assert_fail ("isLambda() && \"Not a lambda closure type!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 1713, __PRETTY_FUNCTION__)); |
1714 | return getLambdaData().HasKnownInternalLinkage; |
1715 | } |
1716 | |
1717 | /// Retrieve the declaration that provides additional context for a |
1718 | /// lambda, when the normal declaration context is not specific enough. |
1719 | /// |
1720 | /// Certain contexts (default arguments of in-class function parameters and |
1721 | /// the initializers of data members) have separate name mangling rules for |
1722 | /// lambdas within the Itanium C++ ABI. For these cases, this routine provides |
1723 | /// the declaration in which the lambda occurs, e.g., the function parameter |
1724 | /// or the non-static data member. Otherwise, it returns NULL to imply that |
1725 | /// the declaration context suffices. |
1726 | Decl *getLambdaContextDecl() const; |
1727 | |
1728 | /// Set the mangling number and context declaration for a lambda |
1729 | /// class. |
1730 | void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl, |
1731 | bool HasKnownInternalLinkage = false) { |
1732 | assert(isLambda() && "Not a lambda closure type!")((isLambda() && "Not a lambda closure type!") ? static_cast <void> (0) : __assert_fail ("isLambda() && \"Not a lambda closure type!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 1732, __PRETTY_FUNCTION__)); |
1733 | getLambdaData().ManglingNumber = ManglingNumber; |
1734 | getLambdaData().ContextDecl = ContextDecl; |
1735 | getLambdaData().HasKnownInternalLinkage = HasKnownInternalLinkage; |
1736 | } |
1737 | |
1738 | /// Set the device side mangling number. |
1739 | void setDeviceLambdaManglingNumber(unsigned Num) const; |
1740 | |
1741 | /// Retrieve the device side mangling number. |
1742 | unsigned getDeviceLambdaManglingNumber() const; |
1743 | |
1744 | /// Returns the inheritance model used for this record. |
1745 | MSInheritanceModel getMSInheritanceModel() const; |
1746 | |
1747 | /// Calculate what the inheritance model would be for this class. |
1748 | MSInheritanceModel calculateInheritanceModel() const; |
1749 | |
1750 | /// In the Microsoft C++ ABI, use zero for the field offset of a null data |
1751 | /// member pointer if we can guarantee that zero is not a valid field offset, |
1752 | /// or if the member pointer has multiple fields. Polymorphic classes have a |
1753 | /// vfptr at offset zero, so we can use zero for null. If there are multiple |
1754 | /// fields, we can use zero even if it is a valid field offset because |
1755 | /// null-ness testing will check the other fields. |
1756 | bool nullFieldOffsetIsZero() const; |
1757 | |
1758 | /// Controls when vtordisps will be emitted if this record is used as a |
1759 | /// virtual base. |
1760 | MSVtorDispMode getMSVtorDispMode() const; |
1761 | |
1762 | /// Determine whether this lambda expression was known to be dependent |
1763 | /// at the time it was created, even if its context does not appear to be |
1764 | /// dependent. |
1765 | /// |
1766 | /// This flag is a workaround for an issue with parsing, where default |
1767 | /// arguments are parsed before their enclosing function declarations have |
1768 | /// been created. This means that any lambda expressions within those |
1769 | /// default arguments will have as their DeclContext the context enclosing |
1770 | /// the function declaration, which may be non-dependent even when the |
1771 | /// function declaration itself is dependent. This flag indicates when we |
1772 | /// know that the lambda is dependent despite that. |
1773 | bool isDependentLambda() const { |
1774 | return isLambda() && getLambdaData().Dependent; |
1775 | } |
1776 | |
1777 | TypeSourceInfo *getLambdaTypeInfo() const { |
1778 | return getLambdaData().MethodTyInfo; |
1779 | } |
1780 | |
1781 | // Determine whether this type is an Interface Like type for |
1782 | // __interface inheritance purposes. |
1783 | bool isInterfaceLike() const; |
1784 | |
1785 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1786 | static bool classofKind(Kind K) { |
1787 | return K >= firstCXXRecord && K <= lastCXXRecord; |
1788 | } |
1789 | }; |
1790 | |
1791 | /// Store information needed for an explicit specifier. |
1792 | /// Used by CXXDeductionGuideDecl, CXXConstructorDecl and CXXConversionDecl. |
1793 | class ExplicitSpecifier { |
1794 | llvm::PointerIntPair<Expr *, 2, ExplicitSpecKind> ExplicitSpec{ |
1795 | nullptr, ExplicitSpecKind::ResolvedFalse}; |
1796 | |
1797 | public: |
1798 | ExplicitSpecifier() = default; |
1799 | ExplicitSpecifier(Expr *Expression, ExplicitSpecKind Kind) |
1800 | : ExplicitSpec(Expression, Kind) {} |
1801 | ExplicitSpecKind getKind() const { return ExplicitSpec.getInt(); } |
1802 | const Expr *getExpr() const { return ExplicitSpec.getPointer(); } |
1803 | Expr *getExpr() { return ExplicitSpec.getPointer(); } |
1804 | |
1805 | /// Determine if the declaration had an explicit specifier of any kind. |
1806 | bool isSpecified() const { |
1807 | return ExplicitSpec.getInt() != ExplicitSpecKind::ResolvedFalse || |
1808 | ExplicitSpec.getPointer(); |
1809 | } |
1810 | |
1811 | /// Check for equivalence of explicit specifiers. |
1812 | /// \return true if the explicit specifier are equivalent, false otherwise. |
1813 | bool isEquivalent(const ExplicitSpecifier Other) const; |
1814 | /// Determine whether this specifier is known to correspond to an explicit |
1815 | /// declaration. Returns false if the specifier is absent or has an |
1816 | /// expression that is value-dependent or evaluates to false. |
1817 | bool isExplicit() const { |
1818 | return ExplicitSpec.getInt() == ExplicitSpecKind::ResolvedTrue; |
1819 | } |
1820 | /// Determine if the explicit specifier is invalid. |
1821 | /// This state occurs after a substitution failures. |
1822 | bool isInvalid() const { |
1823 | return ExplicitSpec.getInt() == ExplicitSpecKind::Unresolved && |
1824 | !ExplicitSpec.getPointer(); |
1825 | } |
1826 | void setKind(ExplicitSpecKind Kind) { ExplicitSpec.setInt(Kind); } |
1827 | void setExpr(Expr *E) { ExplicitSpec.setPointer(E); } |
1828 | // Retrieve the explicit specifier in the given declaration, if any. |
1829 | static ExplicitSpecifier getFromDecl(FunctionDecl *Function); |
1830 | static const ExplicitSpecifier getFromDecl(const FunctionDecl *Function) { |
1831 | return getFromDecl(const_cast<FunctionDecl *>(Function)); |
1832 | } |
1833 | static ExplicitSpecifier Invalid() { |
1834 | return ExplicitSpecifier(nullptr, ExplicitSpecKind::Unresolved); |
1835 | } |
1836 | }; |
1837 | |
1838 | /// Represents a C++ deduction guide declaration. |
1839 | /// |
1840 | /// \code |
1841 | /// template<typename T> struct A { A(); A(T); }; |
1842 | /// A() -> A<int>; |
1843 | /// \endcode |
1844 | /// |
1845 | /// In this example, there will be an explicit deduction guide from the |
1846 | /// second line, and implicit deduction guide templates synthesized from |
1847 | /// the constructors of \c A. |
1848 | class CXXDeductionGuideDecl : public FunctionDecl { |
1849 | void anchor() override; |
1850 | |
1851 | private: |
1852 | CXXDeductionGuideDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
1853 | ExplicitSpecifier ES, |
1854 | const DeclarationNameInfo &NameInfo, QualType T, |
1855 | TypeSourceInfo *TInfo, SourceLocation EndLocation) |
1856 | : FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo, |
1857 | SC_None, false, ConstexprSpecKind::Unspecified), |
1858 | ExplicitSpec(ES) { |
1859 | if (EndLocation.isValid()) |
1860 | setRangeEnd(EndLocation); |
1861 | setIsCopyDeductionCandidate(false); |
1862 | } |
1863 | |
1864 | ExplicitSpecifier ExplicitSpec; |
1865 | void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; } |
1866 | |
1867 | public: |
1868 | friend class ASTDeclReader; |
1869 | friend class ASTDeclWriter; |
1870 | |
1871 | static CXXDeductionGuideDecl * |
1872 | Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
1873 | ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T, |
1874 | TypeSourceInfo *TInfo, SourceLocation EndLocation); |
1875 | |
1876 | static CXXDeductionGuideDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1877 | |
1878 | ExplicitSpecifier getExplicitSpecifier() { return ExplicitSpec; } |
1879 | const ExplicitSpecifier getExplicitSpecifier() const { return ExplicitSpec; } |
1880 | |
1881 | /// Return true if the declartion is already resolved to be explicit. |
1882 | bool isExplicit() const { return ExplicitSpec.isExplicit(); } |
1883 | |
1884 | /// Get the template for which this guide performs deduction. |
1885 | TemplateDecl *getDeducedTemplate() const { |
1886 | return getDeclName().getCXXDeductionGuideTemplate(); |
1887 | } |
1888 | |
1889 | void setIsCopyDeductionCandidate(bool isCDC = true) { |
1890 | FunctionDeclBits.IsCopyDeductionCandidate = isCDC; |
1891 | } |
1892 | |
1893 | bool isCopyDeductionCandidate() const { |
1894 | return FunctionDeclBits.IsCopyDeductionCandidate; |
1895 | } |
1896 | |
1897 | // Implement isa/cast/dyncast/etc. |
1898 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1899 | static bool classofKind(Kind K) { return K == CXXDeductionGuide; } |
1900 | }; |
1901 | |
1902 | /// \brief Represents the body of a requires-expression. |
1903 | /// |
1904 | /// This decl exists merely to serve as the DeclContext for the local |
1905 | /// parameters of the requires expression as well as other declarations inside |
1906 | /// it. |
1907 | /// |
1908 | /// \code |
1909 | /// template<typename T> requires requires (T t) { {t++} -> regular; } |
1910 | /// \endcode |
1911 | /// |
1912 | /// In this example, a RequiresExpr object will be generated for the expression, |
1913 | /// and a RequiresExprBodyDecl will be created to hold the parameter t and the |
1914 | /// template argument list imposed by the compound requirement. |
1915 | class RequiresExprBodyDecl : public Decl, public DeclContext { |
1916 | RequiresExprBodyDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc) |
1917 | : Decl(RequiresExprBody, DC, StartLoc), DeclContext(RequiresExprBody) {} |
1918 | |
1919 | public: |
1920 | friend class ASTDeclReader; |
1921 | friend class ASTDeclWriter; |
1922 | |
1923 | static RequiresExprBodyDecl *Create(ASTContext &C, DeclContext *DC, |
1924 | SourceLocation StartLoc); |
1925 | |
1926 | static RequiresExprBodyDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1927 | |
1928 | // Implement isa/cast/dyncast/etc. |
1929 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1930 | static bool classofKind(Kind K) { return K == RequiresExprBody; } |
1931 | }; |
1932 | |
1933 | /// Represents a static or instance method of a struct/union/class. |
1934 | /// |
1935 | /// In the terminology of the C++ Standard, these are the (static and |
1936 | /// non-static) member functions, whether virtual or not. |
1937 | class CXXMethodDecl : public FunctionDecl { |
1938 | void anchor() override; |
1939 | |
1940 | protected: |
1941 | CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD, |
1942 | SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, |
1943 | QualType T, TypeSourceInfo *TInfo, StorageClass SC, |
1944 | bool isInline, ConstexprSpecKind ConstexprKind, |
1945 | SourceLocation EndLocation, |
1946 | Expr *TrailingRequiresClause = nullptr) |
1947 | : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo, SC, isInline, |
1948 | ConstexprKind, TrailingRequiresClause) { |
1949 | if (EndLocation.isValid()) |
1950 | setRangeEnd(EndLocation); |
1951 | } |
1952 | |
1953 | public: |
1954 | static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, |
1955 | SourceLocation StartLoc, |
1956 | const DeclarationNameInfo &NameInfo, QualType T, |
1957 | TypeSourceInfo *TInfo, StorageClass SC, |
1958 | bool isInline, ConstexprSpecKind ConstexprKind, |
1959 | SourceLocation EndLocation, |
1960 | Expr *TrailingRequiresClause = nullptr); |
1961 | |
1962 | static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1963 | |
1964 | bool isStatic() const; |
1965 | bool isInstance() const { return !isStatic(); } |
1966 | |
1967 | /// Returns true if the given operator is implicitly static in a record |
1968 | /// context. |
1969 | static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) { |
1970 | // [class.free]p1: |
1971 | // Any allocation function for a class T is a static member |
1972 | // (even if not explicitly declared static). |
1973 | // [class.free]p6 Any deallocation function for a class X is a static member |
1974 | // (even if not explicitly declared static). |
1975 | return OOK == OO_New || OOK == OO_Array_New || OOK == OO_Delete || |
1976 | OOK == OO_Array_Delete; |
1977 | } |
1978 | |
1979 | bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); } |
1980 | bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); } |
1981 | |
1982 | bool isVirtual() const { |
1983 | CXXMethodDecl *CD = const_cast<CXXMethodDecl*>(this)->getCanonicalDecl(); |
1984 | |
1985 | // Member function is virtual if it is marked explicitly so, or if it is |
1986 | // declared in __interface -- then it is automatically pure virtual. |
1987 | if (CD->isVirtualAsWritten() || CD->isPure()) |
1988 | return true; |
1989 | |
1990 | return CD->size_overridden_methods() != 0; |
1991 | } |
1992 | |
1993 | /// If it's possible to devirtualize a call to this method, return the called |
1994 | /// function. Otherwise, return null. |
1995 | |
1996 | /// \param Base The object on which this virtual function is called. |
1997 | /// \param IsAppleKext True if we are compiling for Apple kext. |
1998 | CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, bool IsAppleKext); |
1999 | |
2000 | const CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, |
2001 | bool IsAppleKext) const { |
2002 | return const_cast<CXXMethodDecl *>(this)->getDevirtualizedMethod( |
2003 | Base, IsAppleKext); |
2004 | } |
2005 | |
2006 | /// Determine whether this is a usual deallocation function (C++ |
2007 | /// [basic.stc.dynamic.deallocation]p2), which is an overloaded delete or |
2008 | /// delete[] operator with a particular signature. Populates \p PreventedBy |
2009 | /// with the declarations of the functions of the same kind if they were the |
2010 | /// reason for this function returning false. This is used by |
2011 | /// Sema::isUsualDeallocationFunction to reconsider the answer based on the |
2012 | /// context. |
2013 | bool isUsualDeallocationFunction( |
2014 | SmallVectorImpl<const FunctionDecl *> &PreventedBy) const; |
2015 | |
2016 | /// Determine whether this is a copy-assignment operator, regardless |
2017 | /// of whether it was declared implicitly or explicitly. |
2018 | bool isCopyAssignmentOperator() const; |
2019 | |
2020 | /// Determine whether this is a move assignment operator. |
2021 | bool isMoveAssignmentOperator() const; |
2022 | |
2023 | CXXMethodDecl *getCanonicalDecl() override { |
2024 | return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); |
2025 | } |
2026 | const CXXMethodDecl *getCanonicalDecl() const { |
2027 | return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl(); |
2028 | } |
2029 | |
2030 | CXXMethodDecl *getMostRecentDecl() { |
2031 | return cast<CXXMethodDecl>( |
2032 | static_cast<FunctionDecl *>(this)->getMostRecentDecl()); |
2033 | } |
2034 | const CXXMethodDecl *getMostRecentDecl() const { |
2035 | return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl(); |
2036 | } |
2037 | |
2038 | void addOverriddenMethod(const CXXMethodDecl *MD); |
2039 | |
2040 | using method_iterator = const CXXMethodDecl *const *; |
2041 | |
2042 | method_iterator begin_overridden_methods() const; |
2043 | method_iterator end_overridden_methods() const; |
2044 | unsigned size_overridden_methods() const; |
2045 | |
2046 | using overridden_method_range = llvm::iterator_range< |
2047 | llvm::TinyPtrVector<const CXXMethodDecl *>::const_iterator>; |
2048 | |
2049 | overridden_method_range overridden_methods() const; |
2050 | |
2051 | /// Return the parent of this method declaration, which |
2052 | /// is the class in which this method is defined. |
2053 | const CXXRecordDecl *getParent() const { |
2054 | return cast<CXXRecordDecl>(FunctionDecl::getParent()); |
2055 | } |
2056 | |
2057 | /// Return the parent of this method declaration, which |
2058 | /// is the class in which this method is defined. |
2059 | CXXRecordDecl *getParent() { |
2060 | return const_cast<CXXRecordDecl *>( |
2061 | cast<CXXRecordDecl>(FunctionDecl::getParent())); |
2062 | } |
2063 | |
2064 | /// Return the type of the \c this pointer. |
2065 | /// |
2066 | /// Should only be called for instance (i.e., non-static) methods. Note |
2067 | /// that for the call operator of a lambda closure type, this returns the |
2068 | /// desugared 'this' type (a pointer to the closure type), not the captured |
2069 | /// 'this' type. |
2070 | QualType getThisType() const; |
2071 | |
2072 | /// Return the type of the object pointed by \c this. |
2073 | /// |
2074 | /// See getThisType() for usage restriction. |
2075 | QualType getThisObjectType() const; |
2076 | |
2077 | static QualType getThisType(const FunctionProtoType *FPT, |
2078 | const CXXRecordDecl *Decl); |
2079 | |
2080 | static QualType getThisObjectType(const FunctionProtoType *FPT, |
2081 | const CXXRecordDecl *Decl); |
2082 | |
2083 | Qualifiers getMethodQualifiers() const { |
2084 | return getType()->castAs<FunctionProtoType>()->getMethodQuals(); |
2085 | } |
2086 | |
2087 | /// Retrieve the ref-qualifier associated with this method. |
2088 | /// |
2089 | /// In the following example, \c f() has an lvalue ref-qualifier, \c g() |
2090 | /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier. |
2091 | /// @code |
2092 | /// struct X { |
2093 | /// void f() &; |
2094 | /// void g() &&; |
2095 | /// void h(); |
2096 | /// }; |
2097 | /// @endcode |
2098 | RefQualifierKind getRefQualifier() const { |
2099 | return getType()->castAs<FunctionProtoType>()->getRefQualifier(); |
2100 | } |
2101 | |
2102 | bool hasInlineBody() const; |
2103 | |
2104 | /// Determine whether this is a lambda closure type's static member |
2105 | /// function that is used for the result of the lambda's conversion to |
2106 | /// function pointer (for a lambda with no captures). |
2107 | /// |
2108 | /// The function itself, if used, will have a placeholder body that will be |
2109 | /// supplied by IR generation to either forward to the function call operator |
2110 | /// or clone the function call operator. |
2111 | bool isLambdaStaticInvoker() const; |
2112 | |
2113 | /// Find the method in \p RD that corresponds to this one. |
2114 | /// |
2115 | /// Find if \p RD or one of the classes it inherits from override this method. |
2116 | /// If so, return it. \p RD is assumed to be a subclass of the class defining |
2117 | /// this method (or be the class itself), unless \p MayBeBase is set to true. |
2118 | CXXMethodDecl * |
2119 | getCorrespondingMethodInClass(const CXXRecordDecl *RD, |
2120 | bool MayBeBase = false); |
2121 | |
2122 | const CXXMethodDecl * |
2123 | getCorrespondingMethodInClass(const CXXRecordDecl *RD, |
2124 | bool MayBeBase = false) const { |
2125 | return const_cast<CXXMethodDecl *>(this) |
2126 | ->getCorrespondingMethodInClass(RD, MayBeBase); |
2127 | } |
2128 | |
2129 | /// Find if \p RD declares a function that overrides this function, and if so, |
2130 | /// return it. Does not search base classes. |
2131 | CXXMethodDecl *getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, |
2132 | bool MayBeBase = false); |
2133 | const CXXMethodDecl * |
2134 | getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, |
2135 | bool MayBeBase = false) const { |
2136 | return const_cast<CXXMethodDecl *>(this) |
2137 | ->getCorrespondingMethodDeclaredInClass(RD, MayBeBase); |
2138 | } |
2139 | |
2140 | // Implement isa/cast/dyncast/etc. |
2141 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2142 | static bool classofKind(Kind K) { |
2143 | return K >= firstCXXMethod && K <= lastCXXMethod; |
2144 | } |
2145 | }; |
2146 | |
2147 | /// Represents a C++ base or member initializer. |
2148 | /// |
2149 | /// This is part of a constructor initializer that |
2150 | /// initializes one non-static member variable or one base class. For |
2151 | /// example, in the following, both 'A(a)' and 'f(3.14159)' are member |
2152 | /// initializers: |
2153 | /// |
2154 | /// \code |
2155 | /// class A { }; |
2156 | /// class B : public A { |
2157 | /// float f; |
2158 | /// public: |
2159 | /// B(A& a) : A(a), f(3.14159) { } |
2160 | /// }; |
2161 | /// \endcode |
2162 | class CXXCtorInitializer final { |
2163 | /// Either the base class name/delegating constructor type (stored as |
2164 | /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field |
2165 | /// (IndirectFieldDecl*) being initialized. |
2166 | llvm::PointerUnion<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *> |
2167 | Initializee; |
2168 | |
2169 | /// The argument used to initialize the base or member, which may |
2170 | /// end up constructing an object (when multiple arguments are involved). |
2171 | Stmt *Init; |
2172 | |
2173 | /// The source location for the field name or, for a base initializer |
2174 | /// pack expansion, the location of the ellipsis. |
2175 | /// |
2176 | /// In the case of a delegating |
2177 | /// constructor, it will still include the type's source location as the |
2178 | /// Initializee points to the CXXConstructorDecl (to allow loop detection). |
2179 | SourceLocation MemberOrEllipsisLocation; |
2180 | |
2181 | /// Location of the left paren of the ctor-initializer. |
2182 | SourceLocation LParenLoc; |
2183 | |
2184 | /// Location of the right paren of the ctor-initializer. |
2185 | SourceLocation RParenLoc; |
2186 | |
2187 | /// If the initializee is a type, whether that type makes this |
2188 | /// a delegating initialization. |
2189 | unsigned IsDelegating : 1; |
2190 | |
2191 | /// If the initializer is a base initializer, this keeps track |
2192 | /// of whether the base is virtual or not. |
2193 | unsigned IsVirtual : 1; |
2194 | |
2195 | /// Whether or not the initializer is explicitly written |
2196 | /// in the sources. |
2197 | unsigned IsWritten : 1; |
2198 | |
2199 | /// If IsWritten is true, then this number keeps track of the textual order |
2200 | /// of this initializer in the original sources, counting from 0. |
2201 | unsigned SourceOrder : 13; |
2202 | |
2203 | public: |
2204 | /// Creates a new base-class initializer. |
2205 | explicit |
2206 | CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual, |
2207 | SourceLocation L, Expr *Init, SourceLocation R, |
2208 | SourceLocation EllipsisLoc); |
2209 | |
2210 | /// Creates a new member initializer. |
2211 | explicit |
2212 | CXXCtorInitializer(ASTContext &Context, FieldDecl *Member, |
2213 | SourceLocation MemberLoc, SourceLocation L, Expr *Init, |
2214 | SourceLocation R); |
2215 | |
2216 | /// Creates a new anonymous field initializer. |
2217 | explicit |
2218 | CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member, |
2219 | SourceLocation MemberLoc, SourceLocation L, Expr *Init, |
2220 | SourceLocation R); |
2221 | |
2222 | /// Creates a new delegating initializer. |
2223 | explicit |
2224 | CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, |
2225 | SourceLocation L, Expr *Init, SourceLocation R); |
2226 | |
2227 | /// \return Unique reproducible object identifier. |
2228 | int64_t getID(const ASTContext &Context) const; |
2229 | |
2230 | /// Determine whether this initializer is initializing a base class. |
2231 | bool isBaseInitializer() const { |
2232 | return Initializee.is<TypeSourceInfo*>() && !IsDelegating; |
2233 | } |
2234 | |
2235 | /// Determine whether this initializer is initializing a non-static |
2236 | /// data member. |
2237 | bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); } |
2238 | |
2239 | bool isAnyMemberInitializer() const { |
2240 | return isMemberInitializer() || isIndirectMemberInitializer(); |
2241 | } |
2242 | |
2243 | bool isIndirectMemberInitializer() const { |
2244 | return Initializee.is<IndirectFieldDecl*>(); |
2245 | } |
2246 | |
2247 | /// Determine whether this initializer is an implicit initializer |
2248 | /// generated for a field with an initializer defined on the member |
2249 | /// declaration. |
2250 | /// |
2251 | /// In-class member initializers (also known as "non-static data member |
2252 | /// initializations", NSDMIs) were introduced in C++11. |
2253 | bool isInClassMemberInitializer() const { |
2254 | return Init->getStmtClass() == Stmt::CXXDefaultInitExprClass; |
2255 | } |
2256 | |
2257 | /// Determine whether this initializer is creating a delegating |
2258 | /// constructor. |
2259 | bool isDelegatingInitializer() const { |
2260 | return Initializee.is<TypeSourceInfo*>() && IsDelegating; |
2261 | } |
2262 | |
2263 | /// Determine whether this initializer is a pack expansion. |
2264 | bool isPackExpansion() const { |
2265 | return isBaseInitializer() && MemberOrEllipsisLocation.isValid(); |
2266 | } |
2267 | |
2268 | // For a pack expansion, returns the location of the ellipsis. |
2269 | SourceLocation getEllipsisLoc() const { |
2270 | assert(isPackExpansion() && "Initializer is not a pack expansion")((isPackExpansion() && "Initializer is not a pack expansion" ) ? static_cast<void> (0) : __assert_fail ("isPackExpansion() && \"Initializer is not a pack expansion\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 2270, __PRETTY_FUNCTION__)); |
2271 | return MemberOrEllipsisLocation; |
2272 | } |
2273 | |
2274 | /// If this is a base class initializer, returns the type of the |
2275 | /// base class with location information. Otherwise, returns an NULL |
2276 | /// type location. |
2277 | TypeLoc getBaseClassLoc() const; |
2278 | |
2279 | /// If this is a base class initializer, returns the type of the base class. |
2280 | /// Otherwise, returns null. |
2281 | const Type *getBaseClass() const; |
2282 | |
2283 | /// Returns whether the base is virtual or not. |
2284 | bool isBaseVirtual() const { |
2285 | assert(isBaseInitializer() && "Must call this on base initializer!")((isBaseInitializer() && "Must call this on base initializer!" ) ? static_cast<void> (0) : __assert_fail ("isBaseInitializer() && \"Must call this on base initializer!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 2285, __PRETTY_FUNCTION__)); |
2286 | |
2287 | return IsVirtual; |
2288 | } |
2289 | |
2290 | /// Returns the declarator information for a base class or delegating |
2291 | /// initializer. |
2292 | TypeSourceInfo *getTypeSourceInfo() const { |
2293 | return Initializee.dyn_cast<TypeSourceInfo *>(); |
2294 | } |
2295 | |
2296 | /// If this is a member initializer, returns the declaration of the |
2297 | /// non-static data member being initialized. Otherwise, returns null. |
2298 | FieldDecl *getMember() const { |
2299 | if (isMemberInitializer()) |
2300 | return Initializee.get<FieldDecl*>(); |
2301 | return nullptr; |
2302 | } |
2303 | |
2304 | FieldDecl *getAnyMember() const { |
2305 | if (isMemberInitializer()) |
2306 | return Initializee.get<FieldDecl*>(); |
2307 | if (isIndirectMemberInitializer()) |
2308 | return Initializee.get<IndirectFieldDecl*>()->getAnonField(); |
2309 | return nullptr; |
2310 | } |
2311 | |
2312 | IndirectFieldDecl *getIndirectMember() const { |
2313 | if (isIndirectMemberInitializer()) |
2314 | return Initializee.get<IndirectFieldDecl*>(); |
2315 | return nullptr; |
2316 | } |
2317 | |
2318 | SourceLocation getMemberLocation() const { |
2319 | return MemberOrEllipsisLocation; |
2320 | } |
2321 | |
2322 | /// Determine the source location of the initializer. |
2323 | SourceLocation getSourceLocation() const; |
2324 | |
2325 | /// Determine the source range covering the entire initializer. |
2326 | SourceRange getSourceRange() const LLVM_READONLY__attribute__((__pure__)); |
2327 | |
2328 | /// Determine whether this initializer is explicitly written |
2329 | /// in the source code. |
2330 | bool isWritten() const { return IsWritten; } |
2331 | |
2332 | /// Return the source position of the initializer, counting from 0. |
2333 | /// If the initializer was implicit, -1 is returned. |
2334 | int getSourceOrder() const { |
2335 | return IsWritten ? static_cast<int>(SourceOrder) : -1; |
2336 | } |
2337 | |
2338 | /// Set the source order of this initializer. |
2339 | /// |
2340 | /// This can only be called once for each initializer; it cannot be called |
2341 | /// on an initializer having a positive number of (implicit) array indices. |
2342 | /// |
2343 | /// This assumes that the initializer was written in the source code, and |
2344 | /// ensures that isWritten() returns true. |
2345 | void setSourceOrder(int Pos) { |
2346 | assert(!IsWritten &&((!IsWritten && "setSourceOrder() used on implicit initializer" ) ? static_cast<void> (0) : __assert_fail ("!IsWritten && \"setSourceOrder() used on implicit initializer\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 2347, __PRETTY_FUNCTION__)) |
2347 | "setSourceOrder() used on implicit initializer")((!IsWritten && "setSourceOrder() used on implicit initializer" ) ? static_cast<void> (0) : __assert_fail ("!IsWritten && \"setSourceOrder() used on implicit initializer\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 2347, __PRETTY_FUNCTION__)); |
2348 | assert(SourceOrder == 0 &&((SourceOrder == 0 && "calling twice setSourceOrder() on the same initializer" ) ? static_cast<void> (0) : __assert_fail ("SourceOrder == 0 && \"calling twice setSourceOrder() on the same initializer\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 2349, __PRETTY_FUNCTION__)) |
2349 | "calling twice setSourceOrder() on the same initializer")((SourceOrder == 0 && "calling twice setSourceOrder() on the same initializer" ) ? static_cast<void> (0) : __assert_fail ("SourceOrder == 0 && \"calling twice setSourceOrder() on the same initializer\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 2349, __PRETTY_FUNCTION__)); |
2350 | assert(Pos >= 0 &&((Pos >= 0 && "setSourceOrder() used to make an initializer implicit" ) ? static_cast<void> (0) : __assert_fail ("Pos >= 0 && \"setSourceOrder() used to make an initializer implicit\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 2351, __PRETTY_FUNCTION__)) |
2351 | "setSourceOrder() used to make an initializer implicit")((Pos >= 0 && "setSourceOrder() used to make an initializer implicit" ) ? static_cast<void> (0) : __assert_fail ("Pos >= 0 && \"setSourceOrder() used to make an initializer implicit\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 2351, __PRETTY_FUNCTION__)); |
2352 | IsWritten = true; |
2353 | SourceOrder = static_cast<unsigned>(Pos); |
2354 | } |
2355 | |
2356 | SourceLocation getLParenLoc() const { return LParenLoc; } |
2357 | SourceLocation getRParenLoc() const { return RParenLoc; } |
2358 | |
2359 | /// Get the initializer. |
2360 | Expr *getInit() const { return static_cast<Expr *>(Init); } |
2361 | }; |
2362 | |
2363 | /// Description of a constructor that was inherited from a base class. |
2364 | class InheritedConstructor { |
2365 | ConstructorUsingShadowDecl *Shadow = nullptr; |
2366 | CXXConstructorDecl *BaseCtor = nullptr; |
2367 | |
2368 | public: |
2369 | InheritedConstructor() = default; |
2370 | InheritedConstructor(ConstructorUsingShadowDecl *Shadow, |
2371 | CXXConstructorDecl *BaseCtor) |
2372 | : Shadow(Shadow), BaseCtor(BaseCtor) {} |
2373 | |
2374 | explicit operator bool() const { return Shadow; } |
2375 | |
2376 | ConstructorUsingShadowDecl *getShadowDecl() const { return Shadow; } |
2377 | CXXConstructorDecl *getConstructor() const { return BaseCtor; } |
2378 | }; |
2379 | |
2380 | /// Represents a C++ constructor within a class. |
2381 | /// |
2382 | /// For example: |
2383 | /// |
2384 | /// \code |
2385 | /// class X { |
2386 | /// public: |
2387 | /// explicit X(int); // represented by a CXXConstructorDecl. |
2388 | /// }; |
2389 | /// \endcode |
2390 | class CXXConstructorDecl final |
2391 | : public CXXMethodDecl, |
2392 | private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor, |
2393 | ExplicitSpecifier> { |
2394 | // This class stores some data in DeclContext::CXXConstructorDeclBits |
2395 | // to save some space. Use the provided accessors to access it. |
2396 | |
2397 | /// \name Support for base and member initializers. |
2398 | /// \{ |
2399 | /// The arguments used to initialize the base or member. |
2400 | LazyCXXCtorInitializersPtr CtorInitializers; |
2401 | |
2402 | CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2403 | const DeclarationNameInfo &NameInfo, QualType T, |
2404 | TypeSourceInfo *TInfo, ExplicitSpecifier ES, bool isInline, |
2405 | bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, |
2406 | InheritedConstructor Inherited, |
2407 | Expr *TrailingRequiresClause); |
2408 | |
2409 | void anchor() override; |
2410 | |
2411 | size_t numTrailingObjects(OverloadToken<InheritedConstructor>) const { |
2412 | return CXXConstructorDeclBits.IsInheritingConstructor; |
2413 | } |
2414 | size_t numTrailingObjects(OverloadToken<ExplicitSpecifier>) const { |
2415 | return CXXConstructorDeclBits.HasTrailingExplicitSpecifier; |
2416 | } |
2417 | |
2418 | ExplicitSpecifier getExplicitSpecifierInternal() const { |
2419 | if (CXXConstructorDeclBits.HasTrailingExplicitSpecifier) |
2420 | return *getTrailingObjects<ExplicitSpecifier>(); |
2421 | return ExplicitSpecifier( |
2422 | nullptr, CXXConstructorDeclBits.IsSimpleExplicit |
2423 | ? ExplicitSpecKind::ResolvedTrue |
2424 | : ExplicitSpecKind::ResolvedFalse); |
2425 | } |
2426 | |
2427 | enum TraillingAllocKind { |
2428 | TAKInheritsConstructor = 1, |
2429 | TAKHasTailExplicit = 1 << 1, |
2430 | }; |
2431 | |
2432 | uint64_t getTraillingAllocKind() const { |
2433 | return numTrailingObjects(OverloadToken<InheritedConstructor>()) | |
2434 | (numTrailingObjects(OverloadToken<ExplicitSpecifier>()) << 1); |
2435 | } |
2436 | |
2437 | public: |
2438 | friend class ASTDeclReader; |
2439 | friend class ASTDeclWriter; |
2440 | friend TrailingObjects; |
2441 | |
2442 | static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
2443 | uint64_t AllocKind); |
2444 | static CXXConstructorDecl * |
2445 | Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2446 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2447 | ExplicitSpecifier ES, bool isInline, bool isImplicitlyDeclared, |
2448 | ConstexprSpecKind ConstexprKind, |
2449 | InheritedConstructor Inherited = InheritedConstructor(), |
2450 | Expr *TrailingRequiresClause = nullptr); |
2451 | |
2452 | void setExplicitSpecifier(ExplicitSpecifier ES) { |
2453 | assert((!ES.getExpr() ||(((!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier ) && "cannot set this explicit specifier. no trail-allocated space for " "explicit") ? static_cast<void> (0) : __assert_fail ("(!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && \"cannot set this explicit specifier. no trail-allocated space for \" \"explicit\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 2456, __PRETTY_FUNCTION__)) |
2454 | CXXConstructorDeclBits.HasTrailingExplicitSpecifier) &&(((!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier ) && "cannot set this explicit specifier. no trail-allocated space for " "explicit") ? static_cast<void> (0) : __assert_fail ("(!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && \"cannot set this explicit specifier. no trail-allocated space for \" \"explicit\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 2456, __PRETTY_FUNCTION__)) |
2455 | "cannot set this explicit specifier. no trail-allocated space for "(((!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier ) && "cannot set this explicit specifier. no trail-allocated space for " "explicit") ? static_cast<void> (0) : __assert_fail ("(!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && \"cannot set this explicit specifier. no trail-allocated space for \" \"explicit\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 2456, __PRETTY_FUNCTION__)) |
2456 | "explicit")(((!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier ) && "cannot set this explicit specifier. no trail-allocated space for " "explicit") ? static_cast<void> (0) : __assert_fail ("(!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && \"cannot set this explicit specifier. no trail-allocated space for \" \"explicit\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 2456, __PRETTY_FUNCTION__)); |
2457 | if (ES.getExpr()) |
2458 | *getCanonicalDecl()->getTrailingObjects<ExplicitSpecifier>() = ES; |
2459 | else |
2460 | CXXConstructorDeclBits.IsSimpleExplicit = ES.isExplicit(); |
2461 | } |
2462 | |
2463 | ExplicitSpecifier getExplicitSpecifier() { |
2464 | return getCanonicalDecl()->getExplicitSpecifierInternal(); |
2465 | } |
2466 | const ExplicitSpecifier getExplicitSpecifier() const { |
2467 | return getCanonicalDecl()->getExplicitSpecifierInternal(); |
2468 | } |
2469 | |
2470 | /// Return true if the declartion is already resolved to be explicit. |
2471 | bool isExplicit() const { return getExplicitSpecifier().isExplicit(); } |
2472 | |
2473 | /// Iterates through the member/base initializer list. |
2474 | using init_iterator = CXXCtorInitializer **; |
2475 | |
2476 | /// Iterates through the member/base initializer list. |
2477 | using init_const_iterator = CXXCtorInitializer *const *; |
2478 | |
2479 | using init_range = llvm::iterator_range<init_iterator>; |
2480 | using init_const_range = llvm::iterator_range<init_const_iterator>; |
2481 | |
2482 | init_range inits() { return init_range(init_begin(), init_end()); } |
2483 | init_const_range inits() const { |
2484 | return init_const_range(init_begin(), init_end()); |
2485 | } |
2486 | |
2487 | /// Retrieve an iterator to the first initializer. |
2488 | init_iterator init_begin() { |
2489 | const auto *ConstThis = this; |
2490 | return const_cast<init_iterator>(ConstThis->init_begin()); |
2491 | } |
2492 | |
2493 | /// Retrieve an iterator to the first initializer. |
2494 | init_const_iterator init_begin() const; |
2495 | |
2496 | /// Retrieve an iterator past the last initializer. |
2497 | init_iterator init_end() { |
2498 | return init_begin() + getNumCtorInitializers(); |
2499 | } |
2500 | |
2501 | /// Retrieve an iterator past the last initializer. |
2502 | init_const_iterator init_end() const { |
2503 | return init_begin() + getNumCtorInitializers(); |
2504 | } |
2505 | |
2506 | using init_reverse_iterator = std::reverse_iterator<init_iterator>; |
2507 | using init_const_reverse_iterator = |
2508 | std::reverse_iterator<init_const_iterator>; |
2509 | |
2510 | init_reverse_iterator init_rbegin() { |
2511 | return init_reverse_iterator(init_end()); |
2512 | } |
2513 | init_const_reverse_iterator init_rbegin() const { |
2514 | return init_const_reverse_iterator(init_end()); |
2515 | } |
2516 | |
2517 | init_reverse_iterator init_rend() { |
2518 | return init_reverse_iterator(init_begin()); |
2519 | } |
2520 | init_const_reverse_iterator init_rend() const { |
2521 | return init_const_reverse_iterator(init_begin()); |
2522 | } |
2523 | |
2524 | /// Determine the number of arguments used to initialize the member |
2525 | /// or base. |
2526 | unsigned getNumCtorInitializers() const { |
2527 | return CXXConstructorDeclBits.NumCtorInitializers; |
2528 | } |
2529 | |
2530 | void setNumCtorInitializers(unsigned numCtorInitializers) { |
2531 | CXXConstructorDeclBits.NumCtorInitializers = numCtorInitializers; |
2532 | // This assert added because NumCtorInitializers is stored |
2533 | // in CXXConstructorDeclBits as a bitfield and its width has |
2534 | // been shrunk from 32 bits to fit into CXXConstructorDeclBitfields. |
2535 | assert(CXXConstructorDeclBits.NumCtorInitializers ==((CXXConstructorDeclBits.NumCtorInitializers == numCtorInitializers && "NumCtorInitializers overflow!") ? static_cast< void> (0) : __assert_fail ("CXXConstructorDeclBits.NumCtorInitializers == numCtorInitializers && \"NumCtorInitializers overflow!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 2536, __PRETTY_FUNCTION__)) |
2536 | numCtorInitializers && "NumCtorInitializers overflow!")((CXXConstructorDeclBits.NumCtorInitializers == numCtorInitializers && "NumCtorInitializers overflow!") ? static_cast< void> (0) : __assert_fail ("CXXConstructorDeclBits.NumCtorInitializers == numCtorInitializers && \"NumCtorInitializers overflow!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 2536, __PRETTY_FUNCTION__)); |
2537 | } |
2538 | |
2539 | void setCtorInitializers(CXXCtorInitializer **Initializers) { |
2540 | CtorInitializers = Initializers; |
2541 | } |
2542 | |
2543 | /// Determine whether this constructor is a delegating constructor. |
2544 | bool isDelegatingConstructor() const { |
2545 | return (getNumCtorInitializers() == 1) && |
2546 | init_begin()[0]->isDelegatingInitializer(); |
2547 | } |
2548 | |
2549 | /// When this constructor delegates to another, retrieve the target. |
2550 | CXXConstructorDecl *getTargetConstructor() const; |
2551 | |
2552 | /// Whether this constructor is a default |
2553 | /// constructor (C++ [class.ctor]p5), which can be used to |
2554 | /// default-initialize a class of this type. |
2555 | bool isDefaultConstructor() const; |
2556 | |
2557 | /// Whether this constructor is a copy constructor (C++ [class.copy]p2, |
2558 | /// which can be used to copy the class. |
2559 | /// |
2560 | /// \p TypeQuals will be set to the qualifiers on the |
2561 | /// argument type. For example, \p TypeQuals would be set to \c |
2562 | /// Qualifiers::Const for the following copy constructor: |
2563 | /// |
2564 | /// \code |
2565 | /// class X { |
2566 | /// public: |
2567 | /// X(const X&); |
2568 | /// }; |
2569 | /// \endcode |
2570 | bool isCopyConstructor(unsigned &TypeQuals) const; |
2571 | |
2572 | /// Whether this constructor is a copy |
2573 | /// constructor (C++ [class.copy]p2, which can be used to copy the |
2574 | /// class. |
2575 | bool isCopyConstructor() const { |
2576 | unsigned TypeQuals = 0; |
2577 | return isCopyConstructor(TypeQuals); |
2578 | } |
2579 | |
2580 | /// Determine whether this constructor is a move constructor |
2581 | /// (C++11 [class.copy]p3), which can be used to move values of the class. |
2582 | /// |
2583 | /// \param TypeQuals If this constructor is a move constructor, will be set |
2584 | /// to the type qualifiers on the referent of the first parameter's type. |
2585 | bool isMoveConstructor(unsigned &TypeQuals) const; |
2586 | |
2587 | /// Determine whether this constructor is a move constructor |
2588 | /// (C++11 [class.copy]p3), which can be used to move values of the class. |
2589 | bool isMoveConstructor() const { |
2590 | unsigned TypeQuals = 0; |
2591 | return isMoveConstructor(TypeQuals); |
2592 | } |
2593 | |
2594 | /// Determine whether this is a copy or move constructor. |
2595 | /// |
2596 | /// \param TypeQuals Will be set to the type qualifiers on the reference |
2597 | /// parameter, if in fact this is a copy or move constructor. |
2598 | bool isCopyOrMoveConstructor(unsigned &TypeQuals) const; |
2599 | |
2600 | /// Determine whether this a copy or move constructor. |
2601 | bool isCopyOrMoveConstructor() const { |
2602 | unsigned Quals; |
2603 | return isCopyOrMoveConstructor(Quals); |
2604 | } |
2605 | |
2606 | /// Whether this constructor is a |
2607 | /// converting constructor (C++ [class.conv.ctor]), which can be |
2608 | /// used for user-defined conversions. |
2609 | bool isConvertingConstructor(bool AllowExplicit) const; |
2610 | |
2611 | /// Determine whether this is a member template specialization that |
2612 | /// would copy the object to itself. Such constructors are never used to copy |
2613 | /// an object. |
2614 | bool isSpecializationCopyingObject() const; |
2615 | |
2616 | /// Determine whether this is an implicit constructor synthesized to |
2617 | /// model a call to a constructor inherited from a base class. |
2618 | bool isInheritingConstructor() const { |
2619 | return CXXConstructorDeclBits.IsInheritingConstructor; |
2620 | } |
2621 | |
2622 | /// State that this is an implicit constructor synthesized to |
2623 | /// model a call to a constructor inherited from a base class. |
2624 | void setInheritingConstructor(bool isIC = true) { |
2625 | CXXConstructorDeclBits.IsInheritingConstructor = isIC; |
2626 | } |
2627 | |
2628 | /// Get the constructor that this inheriting constructor is based on. |
2629 | InheritedConstructor getInheritedConstructor() const { |
2630 | return isInheritingConstructor() ? |
2631 | *getTrailingObjects<InheritedConstructor>() : InheritedConstructor(); |
2632 | } |
2633 | |
2634 | CXXConstructorDecl *getCanonicalDecl() override { |
2635 | return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl()); |
2636 | } |
2637 | const CXXConstructorDecl *getCanonicalDecl() const { |
2638 | return const_cast<CXXConstructorDecl*>(this)->getCanonicalDecl(); |
2639 | } |
2640 | |
2641 | // Implement isa/cast/dyncast/etc. |
2642 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2643 | static bool classofKind(Kind K) { return K == CXXConstructor; } |
2644 | }; |
2645 | |
2646 | /// Represents a C++ destructor within a class. |
2647 | /// |
2648 | /// For example: |
2649 | /// |
2650 | /// \code |
2651 | /// class X { |
2652 | /// public: |
2653 | /// ~X(); // represented by a CXXDestructorDecl. |
2654 | /// }; |
2655 | /// \endcode |
2656 | class CXXDestructorDecl : public CXXMethodDecl { |
2657 | friend class ASTDeclReader; |
2658 | friend class ASTDeclWriter; |
2659 | |
2660 | // FIXME: Don't allocate storage for these except in the first declaration |
2661 | // of a virtual destructor. |
2662 | FunctionDecl *OperatorDelete = nullptr; |
2663 | Expr *OperatorDeleteThisArg = nullptr; |
2664 | |
2665 | CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2666 | const DeclarationNameInfo &NameInfo, QualType T, |
2667 | TypeSourceInfo *TInfo, bool isInline, |
2668 | bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, |
2669 | Expr *TrailingRequiresClause = nullptr) |
2670 | : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo, |
2671 | SC_None, isInline, ConstexprKind, SourceLocation(), |
2672 | TrailingRequiresClause) { |
2673 | setImplicit(isImplicitlyDeclared); |
2674 | } |
2675 | |
2676 | void anchor() override; |
2677 | |
2678 | public: |
2679 | static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, |
2680 | SourceLocation StartLoc, |
2681 | const DeclarationNameInfo &NameInfo, |
2682 | QualType T, TypeSourceInfo *TInfo, |
2683 | bool isInline, bool isImplicitlyDeclared, |
2684 | ConstexprSpecKind ConstexprKind, |
2685 | Expr *TrailingRequiresClause = nullptr); |
2686 | static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID); |
2687 | |
2688 | void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg); |
2689 | |
2690 | const FunctionDecl *getOperatorDelete() const { |
2691 | return getCanonicalDecl()->OperatorDelete; |
2692 | } |
2693 | |
2694 | Expr *getOperatorDeleteThisArg() const { |
2695 | return getCanonicalDecl()->OperatorDeleteThisArg; |
2696 | } |
2697 | |
2698 | CXXDestructorDecl *getCanonicalDecl() override { |
2699 | return cast<CXXDestructorDecl>(FunctionDecl::getCanonicalDecl()); |
2700 | } |
2701 | const CXXDestructorDecl *getCanonicalDecl() const { |
2702 | return const_cast<CXXDestructorDecl*>(this)->getCanonicalDecl(); |
2703 | } |
2704 | |
2705 | // Implement isa/cast/dyncast/etc. |
2706 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2707 | static bool classofKind(Kind K) { return K == CXXDestructor; } |
2708 | }; |
2709 | |
2710 | /// Represents a C++ conversion function within a class. |
2711 | /// |
2712 | /// For example: |
2713 | /// |
2714 | /// \code |
2715 | /// class X { |
2716 | /// public: |
2717 | /// operator bool(); |
2718 | /// }; |
2719 | /// \endcode |
2720 | class CXXConversionDecl : public CXXMethodDecl { |
2721 | CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2722 | const DeclarationNameInfo &NameInfo, QualType T, |
2723 | TypeSourceInfo *TInfo, bool isInline, ExplicitSpecifier ES, |
2724 | ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, |
2725 | Expr *TrailingRequiresClause = nullptr) |
2726 | : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo, |
2727 | SC_None, isInline, ConstexprKind, EndLocation, |
2728 | TrailingRequiresClause), |
2729 | ExplicitSpec(ES) {} |
2730 | void anchor() override; |
2731 | |
2732 | ExplicitSpecifier ExplicitSpec; |
2733 | |
2734 | public: |
2735 | friend class ASTDeclReader; |
2736 | friend class ASTDeclWriter; |
2737 | |
2738 | static CXXConversionDecl * |
2739 | Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2740 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2741 | bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, |
2742 | SourceLocation EndLocation, Expr *TrailingRequiresClause = nullptr); |
2743 | static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2744 | |
2745 | ExplicitSpecifier getExplicitSpecifier() { |
2746 | return getCanonicalDecl()->ExplicitSpec; |
2747 | } |
2748 | |
2749 | const ExplicitSpecifier getExplicitSpecifier() const { |
2750 | return getCanonicalDecl()->ExplicitSpec; |
2751 | } |
2752 | |
2753 | /// Return true if the declartion is already resolved to be explicit. |
2754 | bool isExplicit() const { return getExplicitSpecifier().isExplicit(); } |
2755 | void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; } |
2756 | |
2757 | /// Returns the type that this conversion function is converting to. |
2758 | QualType getConversionType() const { |
2759 | return getType()->castAs<FunctionType>()->getReturnType(); |
2760 | } |
2761 | |
2762 | /// Determine whether this conversion function is a conversion from |
2763 | /// a lambda closure type to a block pointer. |
2764 | bool isLambdaToBlockPointerConversion() const; |
2765 | |
2766 | CXXConversionDecl *getCanonicalDecl() override { |
2767 | return cast<CXXConversionDecl>(FunctionDecl::getCanonicalDecl()); |
2768 | } |
2769 | const CXXConversionDecl *getCanonicalDecl() const { |
2770 | return const_cast<CXXConversionDecl*>(this)->getCanonicalDecl(); |
2771 | } |
2772 | |
2773 | // Implement isa/cast/dyncast/etc. |
2774 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2775 | static bool classofKind(Kind K) { return K == CXXConversion; } |
2776 | }; |
2777 | |
2778 | /// Represents a linkage specification. |
2779 | /// |
2780 | /// For example: |
2781 | /// \code |
2782 | /// extern "C" void foo(); |
2783 | /// \endcode |
2784 | class LinkageSpecDecl : public Decl, public DeclContext { |
2785 | virtual void anchor(); |
2786 | // This class stores some data in DeclContext::LinkageSpecDeclBits to save |
2787 | // some space. Use the provided accessors to access it. |
2788 | public: |
2789 | /// Represents the language in a linkage specification. |
2790 | /// |
2791 | /// The values are part of the serialization ABI for |
2792 | /// ASTs and cannot be changed without altering that ABI. |
2793 | enum LanguageIDs { lang_c = 1, lang_cxx = 2 }; |
2794 | |
2795 | private: |
2796 | /// The source location for the extern keyword. |
2797 | SourceLocation ExternLoc; |
2798 | |
2799 | /// The source location for the right brace (if valid). |
2800 | SourceLocation RBraceLoc; |
2801 | |
2802 | LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc, |
2803 | SourceLocation LangLoc, LanguageIDs lang, bool HasBraces); |
2804 | |
2805 | public: |
2806 | static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, |
2807 | SourceLocation ExternLoc, |
2808 | SourceLocation LangLoc, LanguageIDs Lang, |
2809 | bool HasBraces); |
2810 | static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2811 | |
2812 | /// Return the language specified by this linkage specification. |
2813 | LanguageIDs getLanguage() const { |
2814 | return static_cast<LanguageIDs>(LinkageSpecDeclBits.Language); |
2815 | } |
2816 | |
2817 | /// Set the language specified by this linkage specification. |
2818 | void setLanguage(LanguageIDs L) { LinkageSpecDeclBits.Language = L; } |
2819 | |
2820 | /// Determines whether this linkage specification had braces in |
2821 | /// its syntactic form. |
2822 | bool hasBraces() const { |
2823 | assert(!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces)((!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces) ? static_cast <void> (0) : __assert_fail ("!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 2823, __PRETTY_FUNCTION__)); |
2824 | return LinkageSpecDeclBits.HasBraces; |
2825 | } |
2826 | |
2827 | SourceLocation getExternLoc() const { return ExternLoc; } |
2828 | SourceLocation getRBraceLoc() const { return RBraceLoc; } |
2829 | void setExternLoc(SourceLocation L) { ExternLoc = L; } |
2830 | void setRBraceLoc(SourceLocation L) { |
2831 | RBraceLoc = L; |
2832 | LinkageSpecDeclBits.HasBraces = RBraceLoc.isValid(); |
2833 | } |
2834 | |
2835 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { |
2836 | if (hasBraces()) |
2837 | return getRBraceLoc(); |
2838 | // No braces: get the end location of the (only) declaration in context |
2839 | // (if present). |
2840 | return decls_empty() ? getLocation() : decls_begin()->getEndLoc(); |
2841 | } |
2842 | |
2843 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
2844 | return SourceRange(ExternLoc, getEndLoc()); |
2845 | } |
2846 | |
2847 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2848 | static bool classofKind(Kind K) { return K == LinkageSpec; } |
2849 | |
2850 | static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { |
2851 | return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); |
2852 | } |
2853 | |
2854 | static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { |
2855 | return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); |
2856 | } |
2857 | }; |
2858 | |
2859 | /// Represents C++ using-directive. |
2860 | /// |
2861 | /// For example: |
2862 | /// \code |
2863 | /// using namespace std; |
2864 | /// \endcode |
2865 | /// |
2866 | /// \note UsingDirectiveDecl should be Decl not NamedDecl, but we provide |
2867 | /// artificial names for all using-directives in order to store |
2868 | /// them in DeclContext effectively. |
2869 | class UsingDirectiveDecl : public NamedDecl { |
2870 | /// The location of the \c using keyword. |
2871 | SourceLocation UsingLoc; |
2872 | |
2873 | /// The location of the \c namespace keyword. |
2874 | SourceLocation NamespaceLoc; |
2875 | |
2876 | /// The nested-name-specifier that precedes the namespace. |
2877 | NestedNameSpecifierLoc QualifierLoc; |
2878 | |
2879 | /// The namespace nominated by this using-directive. |
2880 | NamedDecl *NominatedNamespace; |
2881 | |
2882 | /// Enclosing context containing both using-directive and nominated |
2883 | /// namespace. |
2884 | DeclContext *CommonAncestor; |
2885 | |
2886 | UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc, |
2887 | SourceLocation NamespcLoc, |
2888 | NestedNameSpecifierLoc QualifierLoc, |
2889 | SourceLocation IdentLoc, |
2890 | NamedDecl *Nominated, |
2891 | DeclContext *CommonAncestor) |
2892 | : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc), |
2893 | NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc), |
2894 | NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) {} |
2895 | |
2896 | /// Returns special DeclarationName used by using-directives. |
2897 | /// |
2898 | /// This is only used by DeclContext for storing UsingDirectiveDecls in |
2899 | /// its lookup structure. |
2900 | static DeclarationName getName() { |
2901 | return DeclarationName::getUsingDirectiveName(); |
2902 | } |
2903 | |
2904 | void anchor() override; |
2905 | |
2906 | public: |
2907 | friend class ASTDeclReader; |
2908 | |
2909 | // Friend for getUsingDirectiveName. |
2910 | friend class DeclContext; |
2911 | |
2912 | /// Retrieve the nested-name-specifier that qualifies the |
2913 | /// name of the namespace, with source-location information. |
2914 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
2915 | |
2916 | /// Retrieve the nested-name-specifier that qualifies the |
2917 | /// name of the namespace. |
2918 | NestedNameSpecifier *getQualifier() const { |
2919 | return QualifierLoc.getNestedNameSpecifier(); |
2920 | } |
2921 | |
2922 | NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; } |
2923 | const NamedDecl *getNominatedNamespaceAsWritten() const { |
2924 | return NominatedNamespace; |
2925 | } |
2926 | |
2927 | /// Returns the namespace nominated by this using-directive. |
2928 | NamespaceDecl *getNominatedNamespace(); |
2929 | |
2930 | const NamespaceDecl *getNominatedNamespace() const { |
2931 | return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); |
2932 | } |
2933 | |
2934 | /// Returns the common ancestor context of this using-directive and |
2935 | /// its nominated namespace. |
2936 | DeclContext *getCommonAncestor() { return CommonAncestor; } |
2937 | const DeclContext *getCommonAncestor() const { return CommonAncestor; } |
2938 | |
2939 | /// Return the location of the \c using keyword. |
2940 | SourceLocation getUsingLoc() const { return UsingLoc; } |
2941 | |
2942 | // FIXME: Could omit 'Key' in name. |
2943 | /// Returns the location of the \c namespace keyword. |
2944 | SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } |
2945 | |
2946 | /// Returns the location of this using declaration's identifier. |
2947 | SourceLocation getIdentLocation() const { return getLocation(); } |
2948 | |
2949 | static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, |
2950 | SourceLocation UsingLoc, |
2951 | SourceLocation NamespaceLoc, |
2952 | NestedNameSpecifierLoc QualifierLoc, |
2953 | SourceLocation IdentLoc, |
2954 | NamedDecl *Nominated, |
2955 | DeclContext *CommonAncestor); |
2956 | static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2957 | |
2958 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
2959 | return SourceRange(UsingLoc, getLocation()); |
2960 | } |
2961 | |
2962 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2963 | static bool classofKind(Kind K) { return K == UsingDirective; } |
2964 | }; |
2965 | |
2966 | /// Represents a C++ namespace alias. |
2967 | /// |
2968 | /// For example: |
2969 | /// |
2970 | /// \code |
2971 | /// namespace Foo = Bar; |
2972 | /// \endcode |
2973 | class NamespaceAliasDecl : public NamedDecl, |
2974 | public Redeclarable<NamespaceAliasDecl> { |
2975 | friend class ASTDeclReader; |
2976 | |
2977 | /// The location of the \c namespace keyword. |
2978 | SourceLocation NamespaceLoc; |
2979 | |
2980 | /// The location of the namespace's identifier. |
2981 | /// |
2982 | /// This is accessed by TargetNameLoc. |
2983 | SourceLocation IdentLoc; |
2984 | |
2985 | /// The nested-name-specifier that precedes the namespace. |
2986 | NestedNameSpecifierLoc QualifierLoc; |
2987 | |
2988 | /// The Decl that this alias points to, either a NamespaceDecl or |
2989 | /// a NamespaceAliasDecl. |
2990 | NamedDecl *Namespace; |
2991 | |
2992 | NamespaceAliasDecl(ASTContext &C, DeclContext *DC, |
2993 | SourceLocation NamespaceLoc, SourceLocation AliasLoc, |
2994 | IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc, |
2995 | SourceLocation IdentLoc, NamedDecl *Namespace) |
2996 | : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), redeclarable_base(C), |
2997 | NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc), |
2998 | QualifierLoc(QualifierLoc), Namespace(Namespace) {} |
2999 | |
3000 | void anchor() override; |
3001 | |
3002 | using redeclarable_base = Redeclarable<NamespaceAliasDecl>; |
3003 | |
3004 | NamespaceAliasDecl *getNextRedeclarationImpl() override; |
3005 | NamespaceAliasDecl *getPreviousDeclImpl() override; |
3006 | NamespaceAliasDecl *getMostRecentDeclImpl() override; |
3007 | |
3008 | public: |
3009 | static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, |
3010 | SourceLocation NamespaceLoc, |
3011 | SourceLocation AliasLoc, |
3012 | IdentifierInfo *Alias, |
3013 | NestedNameSpecifierLoc QualifierLoc, |
3014 | SourceLocation IdentLoc, |
3015 | NamedDecl *Namespace); |
3016 | |
3017 | static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3018 | |
3019 | using redecl_range = redeclarable_base::redecl_range; |
3020 | using redecl_iterator = redeclarable_base::redecl_iterator; |
3021 | |
3022 | using redeclarable_base::redecls_begin; |
3023 | using redeclarable_base::redecls_end; |
3024 | using redeclarable_base::redecls; |
3025 | using redeclarable_base::getPreviousDecl; |
3026 | using redeclarable_base::getMostRecentDecl; |
3027 | |
3028 | NamespaceAliasDecl *getCanonicalDecl() override { |
3029 | return getFirstDecl(); |
3030 | } |
3031 | const NamespaceAliasDecl *getCanonicalDecl() const { |
3032 | return getFirstDecl(); |
3033 | } |
3034 | |
3035 | /// Retrieve the nested-name-specifier that qualifies the |
3036 | /// name of the namespace, with source-location information. |
3037 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3038 | |
3039 | /// Retrieve the nested-name-specifier that qualifies the |
3040 | /// name of the namespace. |
3041 | NestedNameSpecifier *getQualifier() const { |
3042 | return QualifierLoc.getNestedNameSpecifier(); |
3043 | } |
3044 | |
3045 | /// Retrieve the namespace declaration aliased by this directive. |
3046 | NamespaceDecl *getNamespace() { |
3047 | if (auto *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) |
3048 | return AD->getNamespace(); |
3049 | |
3050 | return cast<NamespaceDecl>(Namespace); |
3051 | } |
3052 | |
3053 | const NamespaceDecl *getNamespace() const { |
3054 | return const_cast<NamespaceAliasDecl *>(this)->getNamespace(); |
3055 | } |
3056 | |
3057 | /// Returns the location of the alias name, i.e. 'foo' in |
3058 | /// "namespace foo = ns::bar;". |
3059 | SourceLocation getAliasLoc() const { return getLocation(); } |
3060 | |
3061 | /// Returns the location of the \c namespace keyword. |
3062 | SourceLocation getNamespaceLoc() const { return NamespaceLoc; } |
3063 | |
3064 | /// Returns the location of the identifier in the named namespace. |
3065 | SourceLocation getTargetNameLoc() const { return IdentLoc; } |
3066 | |
3067 | /// Retrieve the namespace that this alias refers to, which |
3068 | /// may either be a NamespaceDecl or a NamespaceAliasDecl. |
3069 | NamedDecl *getAliasedNamespace() const { return Namespace; } |
3070 | |
3071 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
3072 | return SourceRange(NamespaceLoc, IdentLoc); |
3073 | } |
3074 | |
3075 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3076 | static bool classofKind(Kind K) { return K == NamespaceAlias; } |
3077 | }; |
3078 | |
3079 | /// Implicit declaration of a temporary that was materialized by |
3080 | /// a MaterializeTemporaryExpr and lifetime-extended by a declaration |
3081 | class LifetimeExtendedTemporaryDecl final |
3082 | : public Decl, |
3083 | public Mergeable<LifetimeExtendedTemporaryDecl> { |
3084 | friend class MaterializeTemporaryExpr; |
3085 | friend class ASTDeclReader; |
3086 | |
3087 | Stmt *ExprWithTemporary = nullptr; |
3088 | |
3089 | /// The declaration which lifetime-extended this reference, if any. |
3090 | /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl. |
3091 | ValueDecl *ExtendingDecl = nullptr; |
3092 | unsigned ManglingNumber; |
3093 | |
3094 | mutable APValue *Value = nullptr; |
3095 | |
3096 | virtual void anchor(); |
3097 | |
3098 | LifetimeExtendedTemporaryDecl(Expr *Temp, ValueDecl *EDecl, unsigned Mangling) |
3099 | : Decl(Decl::LifetimeExtendedTemporary, EDecl->getDeclContext(), |
3100 | EDecl->getLocation()), |
3101 | ExprWithTemporary(Temp), ExtendingDecl(EDecl), |
3102 | ManglingNumber(Mangling) {} |
3103 | |
3104 | LifetimeExtendedTemporaryDecl(EmptyShell) |
3105 | : Decl(Decl::LifetimeExtendedTemporary, EmptyShell{}) {} |
3106 | |
3107 | public: |
3108 | static LifetimeExtendedTemporaryDecl *Create(Expr *Temp, ValueDecl *EDec, |
3109 | unsigned Mangling) { |
3110 | return new (EDec->getASTContext(), EDec->getDeclContext()) |
3111 | LifetimeExtendedTemporaryDecl(Temp, EDec, Mangling); |
3112 | } |
3113 | static LifetimeExtendedTemporaryDecl *CreateDeserialized(ASTContext &C, |
3114 | unsigned ID) { |
3115 | return new (C, ID) LifetimeExtendedTemporaryDecl(EmptyShell{}); |
3116 | } |
3117 | |
3118 | ValueDecl *getExtendingDecl() { return ExtendingDecl; } |
3119 | const ValueDecl *getExtendingDecl() const { return ExtendingDecl; } |
3120 | |
3121 | /// Retrieve the storage duration for the materialized temporary. |
3122 | StorageDuration getStorageDuration() const; |
3123 | |
3124 | /// Retrieve the expression to which the temporary materialization conversion |
3125 | /// was applied. This isn't necessarily the initializer of the temporary due |
3126 | /// to the C++98 delayed materialization rules, but |
3127 | /// skipRValueSubobjectAdjustments can be used to find said initializer within |
3128 | /// the subexpression. |
3129 | Expr *getTemporaryExpr() { return cast<Expr>(ExprWithTemporary); } |
3130 | const Expr *getTemporaryExpr() const { return cast<Expr>(ExprWithTemporary); } |
3131 | |
3132 | unsigned getManglingNumber() const { return ManglingNumber; } |
3133 | |
3134 | /// Get the storage for the constant value of a materialized temporary |
3135 | /// of static storage duration. |
3136 | APValue *getOrCreateValue(bool MayCreate) const; |
3137 | |
3138 | APValue *getValue() const { return Value; } |
3139 | |
3140 | // Iterators |
3141 | Stmt::child_range childrenExpr() { |
3142 | return Stmt::child_range(&ExprWithTemporary, &ExprWithTemporary + 1); |
3143 | } |
3144 | |
3145 | Stmt::const_child_range childrenExpr() const { |
3146 | return Stmt::const_child_range(&ExprWithTemporary, &ExprWithTemporary + 1); |
3147 | } |
3148 | |
3149 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3150 | static bool classofKind(Kind K) { |
3151 | return K == Decl::LifetimeExtendedTemporary; |
3152 | } |
3153 | }; |
3154 | |
3155 | /// Represents a shadow declaration introduced into a scope by a |
3156 | /// (resolved) using declaration. |
3157 | /// |
3158 | /// For example, |
3159 | /// \code |
3160 | /// namespace A { |
3161 | /// void foo(); |
3162 | /// } |
3163 | /// namespace B { |
3164 | /// using A::foo; // <- a UsingDecl |
3165 | /// // Also creates a UsingShadowDecl for A::foo() in B |
3166 | /// } |
3167 | /// \endcode |
3168 | class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> { |
3169 | friend class UsingDecl; |
3170 | |
3171 | /// The referenced declaration. |
3172 | NamedDecl *Underlying = nullptr; |
3173 | |
3174 | /// The using declaration which introduced this decl or the next using |
3175 | /// shadow declaration contained in the aforementioned using declaration. |
3176 | NamedDecl *UsingOrNextShadow = nullptr; |
3177 | |
3178 | void anchor() override; |
3179 | |
3180 | using redeclarable_base = Redeclarable<UsingShadowDecl>; |
3181 | |
3182 | UsingShadowDecl *getNextRedeclarationImpl() override { |
3183 | return getNextRedeclaration(); |
3184 | } |
3185 | |
3186 | UsingShadowDecl *getPreviousDeclImpl() override { |
3187 | return getPreviousDecl(); |
3188 | } |
3189 | |
3190 | UsingShadowDecl *getMostRecentDeclImpl() override { |
3191 | return getMostRecentDecl(); |
3192 | } |
3193 | |
3194 | protected: |
3195 | UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc, |
3196 | UsingDecl *Using, NamedDecl *Target); |
3197 | UsingShadowDecl(Kind K, ASTContext &C, EmptyShell); |
3198 | |
3199 | public: |
3200 | friend class ASTDeclReader; |
3201 | friend class ASTDeclWriter; |
3202 | |
3203 | static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC, |
3204 | SourceLocation Loc, UsingDecl *Using, |
3205 | NamedDecl *Target) { |
3206 | return new (C, DC) UsingShadowDecl(UsingShadow, C, DC, Loc, Using, Target); |
3207 | } |
3208 | |
3209 | static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3210 | |
3211 | using redecl_range = redeclarable_base::redecl_range; |
3212 | using redecl_iterator = redeclarable_base::redecl_iterator; |
3213 | |
3214 | using redeclarable_base::redecls_begin; |
3215 | using redeclarable_base::redecls_end; |
3216 | using redeclarable_base::redecls; |
3217 | using redeclarable_base::getPreviousDecl; |
3218 | using redeclarable_base::getMostRecentDecl; |
3219 | using redeclarable_base::isFirstDecl; |
3220 | |
3221 | UsingShadowDecl *getCanonicalDecl() override { |
3222 | return getFirstDecl(); |
3223 | } |
3224 | const UsingShadowDecl *getCanonicalDecl() const { |
3225 | return getFirstDecl(); |
3226 | } |
3227 | |
3228 | /// Gets the underlying declaration which has been brought into the |
3229 | /// local scope. |
3230 | NamedDecl *getTargetDecl() const { return Underlying; } |
3231 | |
3232 | /// Sets the underlying declaration which has been brought into the |
3233 | /// local scope. |
3234 | void setTargetDecl(NamedDecl *ND) { |
3235 | assert(ND && "Target decl is null!")((ND && "Target decl is null!") ? static_cast<void > (0) : __assert_fail ("ND && \"Target decl is null!\"" , "/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/clang/include/clang/AST/DeclCXX.h" , 3235, __PRETTY_FUNCTION__)); |
3236 | Underlying = ND; |
3237 | // A UsingShadowDecl is never a friend or local extern declaration, even |
3238 | // if it is a shadow declaration for one. |
3239 | IdentifierNamespace = |
3240 | ND->getIdentifierNamespace() & |
3241 | ~(IDNS_OrdinaryFriend | IDNS_TagFriend | IDNS_LocalExtern); |
3242 | } |
3243 | |
3244 | /// Gets the using declaration to which this declaration is tied. |
3245 | UsingDecl *getUsingDecl() const; |
3246 | |
3247 | /// The next using shadow declaration contained in the shadow decl |
3248 | /// chain of the using declaration which introduced this decl. |
3249 | UsingShadowDecl *getNextUsingShadowDecl() const { |
3250 | return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow); |
3251 | } |
3252 | |
3253 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3254 | static bool classofKind(Kind K) { |
3255 | return K == Decl::UsingShadow || K == Decl::ConstructorUsingShadow; |
3256 | } |
3257 | }; |
3258 | |
3259 | /// Represents a shadow constructor declaration introduced into a |
3260 | /// class by a C++11 using-declaration that names a constructor. |
3261 | /// |
3262 | /// For example: |
3263 | /// \code |
3264 | /// struct Base { Base(int); }; |
3265 | /// struct Derived { |
3266 | /// using Base::Base; // creates a UsingDecl and a ConstructorUsingShadowDecl |
3267 | /// }; |
3268 | /// \endcode |
3269 | class ConstructorUsingShadowDecl final : public UsingShadowDecl { |
3270 | /// If this constructor using declaration inherted the constructor |
3271 | /// from an indirect base class, this is the ConstructorUsingShadowDecl |
3272 | /// in the named direct base class from which the declaration was inherited. |
3273 | ConstructorUsingShadowDecl *NominatedBaseClassShadowDecl = nullptr; |
3274 | |
3275 | /// If this constructor using declaration inherted the constructor |
3276 | /// from an indirect base class, this is the ConstructorUsingShadowDecl |
3277 | /// that will be used to construct the unique direct or virtual base class |
3278 | /// that receives the constructor arguments. |
3279 | ConstructorUsingShadowDecl *ConstructedBaseClassShadowDecl = nullptr; |
3280 | |
3281 | /// \c true if the constructor ultimately named by this using shadow |
3282 | /// declaration is within a virtual base class subobject of the class that |
3283 | /// contains this declaration. |
3284 | unsigned IsVirtual : 1; |
3285 | |
3286 | ConstructorUsingShadowDecl(ASTContext &C, DeclContext *DC, SourceLocation Loc, |
3287 | UsingDecl *Using, NamedDecl *Target, |
3288 | bool TargetInVirtualBase) |
3289 | : UsingShadowDecl(ConstructorUsingShadow, C, DC, Loc, Using, |
3290 | Target->getUnderlyingDecl()), |
3291 | NominatedBaseClassShadowDecl( |
3292 | dyn_cast<ConstructorUsingShadowDecl>(Target)), |
3293 | ConstructedBaseClassShadowDecl(NominatedBaseClassShadowDecl), |
3294 | IsVirtual(TargetInVirtualBase) { |
3295 | // If we found a constructor that chains to a constructor for a virtual |
3296 | // base, we should directly call that virtual base constructor instead. |
3297 | // FIXME: This logic belongs in Sema. |
3298 | if (NominatedBaseClassShadowDecl && |
3299 | NominatedBaseClassShadowDecl->constructsVirtualBase()) { |
3300 | ConstructedBaseClassShadowDecl = |
3301 | NominatedBaseClassShadowDecl->ConstructedBaseClassShadowDecl; |
3302 | IsVirtual = true; |
3303 | } |
3304 | } |
3305 | |
3306 | ConstructorUsingShadowDecl(ASTContext &C, EmptyShell Empty) |
3307 | : UsingShadowDecl(ConstructorUsingShadow, C, Empty), IsVirtual(false) {} |
3308 | |
3309 | void anchor() override; |
3310 | |
3311 | public: |
3312 | friend class ASTDeclReader; |
3313 | friend class ASTDeclWriter; |
3314 | |
3315 | static ConstructorUsingShadowDecl *Create(ASTContext &C, DeclContext *DC, |
3316 | SourceLocation Loc, |
3317 | UsingDecl *Using, NamedDecl *Target, |
3318 | bool IsVirtual); |
3319 | static ConstructorUsingShadowDecl *CreateDeserialized(ASTContext &C, |
3320 | unsigned ID); |
3321 | |
3322 | /// Returns the parent of this using shadow declaration, which |
3323 | /// is the class in which this is declared. |
3324 | //@{ |
3325 | const CXXRecordDecl *getParent() const { |
3326 | return cast<CXXRecordDecl>(getDeclContext()); |
3327 | } |
3328 | CXXRecordDecl *getParent() { |
3329 | return cast<CXXRecordDecl>(getDeclContext()); |
3330 | } |
3331 | //@} |
3332 | |
3333 | /// Get the inheriting constructor declaration for the direct base |
3334 | /// class from which this using shadow declaration was inherited, if there is |
3335 | /// one. This can be different for each redeclaration of the same shadow decl. |
3336 | ConstructorUsingShadowDecl *getNominatedBaseClassShadowDecl() const { |
3337 | return NominatedBaseClassShadowDecl; |
3338 | } |
3339 | |
3340 | /// Get the inheriting constructor declaration for the base class |
3341 | /// for which we don't have an explicit initializer, if there is one. |
3342 | ConstructorUsingShadowDecl *getConstructedBaseClassShadowDecl() const { |
3343 | return ConstructedBaseClassShadowDecl; |
3344 | } |
3345 | |
3346 | /// Get the base class that was named in the using declaration. This |
3347 | /// can be different for each redeclaration of this same shadow decl. |
3348 | CXXRecordDecl *getNominatedBaseClass() const; |
3349 | |
3350 | /// Get the base class whose constructor or constructor shadow |
3351 | /// declaration is passed the constructor arguments. |
3352 | CXXRecordDecl *getConstructedBaseClass() const { |
3353 | return cast<CXXRecordDecl>((ConstructedBaseClassShadowDecl |
3354 | ? ConstructedBaseClassShadowDecl |
3355 | : getTargetDecl()) |
3356 | ->getDeclContext()); |
3357 | } |
3358 | |
3359 | /// Returns \c true if the constructed base class is a virtual base |
3360 | /// class subobject of this declaration's class. |
3361 | bool constructsVirtualBase() const { |
3362 | return IsVirtual; |
3363 | } |
3364 | |
3365 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3366 | static bool classofKind(Kind K) { return K == ConstructorUsingShadow; } |
3367 | }; |
3368 | |
3369 | /// Represents a C++ using-declaration. |
3370 | /// |
3371 | /// For example: |
3372 | /// \code |
3373 | /// using someNameSpace::someIdentifier; |
3374 | /// \endcode |
3375 | class UsingDecl : public NamedDecl, public Mergeable<UsingDecl> { |
3376 | /// The source location of the 'using' keyword itself. |
3377 | SourceLocation UsingLocation; |
3378 | |
3379 | /// The nested-name-specifier that precedes the name. |
3380 | NestedNameSpecifierLoc QualifierLoc; |
3381 | |
3382 | /// Provides source/type location info for the declaration name |
3383 | /// embedded in the ValueDecl base class. |
3384 | DeclarationNameLoc DNLoc; |
3385 | |
3386 | /// The first shadow declaration of the shadow decl chain associated |
3387 | /// with this using declaration. |
3388 | /// |
3389 | /// The bool member of the pair store whether this decl has the \c typename |
3390 | /// keyword. |
3391 | llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow; |
3392 | |
3393 | UsingDecl(DeclContext *DC, SourceLocation UL, |
3394 | NestedNameSpecifierLoc QualifierLoc, |
3395 | const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword) |
3396 | : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()), |
3397 | UsingLocation(UL), QualifierLoc(QualifierLoc), |
3398 | DNLoc(NameInfo.getInfo()), FirstUsingShadow(nullptr, HasTypenameKeyword) { |
3399 | } |
3400 | |
3401 | void anchor() override; |
3402 | |
3403 | public: |
3404 | friend class ASTDeclReader; |
3405 | friend class ASTDeclWriter; |
3406 | |
3407 | /// Return the source location of the 'using' keyword. |
3408 | SourceLocation getUsingLoc() const { return UsingLocation; } |
3409 | |
3410 | /// Set the source location of the 'using' keyword. |
3411 | void setUsingLoc(SourceLocation L) { UsingLocation = L; } |
3412 | |
3413 | /// Retrieve the nested-name-specifier that qualifies the name, |
3414 | /// with source-location information. |
3415 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3416 | |
3417 | /// Retrieve the nested-name-specifier that qualifies the name. |
3418 | NestedNameSpecifier *getQualifier() const { |
3419 | return QualifierLoc.getNestedNameSpecifier(); |
3420 | } |
3421 | |
3422 | DeclarationNameInfo getNameInfo() const { |
3423 | return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); |
3424 | } |
3425 | |
3426 | /// Return true if it is a C++03 access declaration (no 'using'). |
3427 | bool isAccessDeclaration() const { return UsingLocation.isInvalid(); } |
3428 | |
3429 | /// Return true if the using declaration has 'typename'. |
3430 | bool hasTypename() const { return FirstUsingShadow.getInt(); } |
3431 | |
3432 | /// Sets whether the using declaration has 'typename'. |
3433 | void setTypename(bool TN) { FirstUsingShadow.setInt(TN); } |
3434 | |
3435 | /// Iterates through the using shadow declarations associated with |
3436 | /// this using declaration. |
3437 | class shadow_iterator { |
3438 | /// The current using shadow declaration. |
3439 | UsingShadowDecl *Current = nullptr; |
3440 | |
3441 | public: |
3442 | using value_type = UsingShadowDecl *; |
3443 | using reference = UsingShadowDecl *; |
3444 | using pointer = UsingShadowDecl *; |
3445 | using iterator_category = std::forward_iterator_tag; |
3446 | using difference_type = std::ptrdiff_t; |
3447 | |
3448 | shadow_iterator() = default; |
3449 | explicit shadow_iterator(UsingShadowDecl *C) : Current(C) {} |
3450 | |
3451 | reference operator*() const { return Current; } |
3452 | pointer operator->() const { return Current; } |
3453 | |
3454 | shadow_iterator& operator++() { |
3455 | Current = Current->getNextUsingShadowDecl(); |
3456 | return *this; |
3457 | } |
3458 | |
3459 | shadow_iterator operator++(int) { |
3460 | shadow_iterator tmp(*this); |
3461 | ++(*this); |
3462 | return tmp; |
3463 | } |
3464 | |
3465 | friend bool operator==(shadow_iterator x, shadow_iterator y) { |
3466 | return x.Current == y.Current; |
3467 | } |
3468 | friend bool operator!=(shadow_iterator x, shadow_iterator y) { |
3469 | return x.Current != y.Current; |
3470 | } |
3471 | }; |
3472 | |
3473 | using shadow_range = llvm::iterator_range<shadow_iterator>; |
3474 | |
3475 | shadow_range shadows() const { |
3476 | return shadow_range(shadow_begin(), shadow_end()); |
3477 | } |
3478 | |
3479 | shadow_iterator shadow_begin() const { |
3480 | return shadow_iterator(FirstUsingShadow.getPointer()); |
3481 | } |
3482 | |
3483 | shadow_iterator shadow_end() const { return shadow_iterator(); } |
3484 | |
3485 | /// Return the number of shadowed declarations associated with this |
3486 | /// using declaration. |
3487 | unsigned shadow_size() const { |
3488 | return std::distance(shadow_begin(), shadow_end()); |
3489 | } |
3490 | |
3491 | void addShadowDecl(UsingShadowDecl *S); |
3492 | void removeShadowDecl(UsingShadowDecl *S); |
3493 | |
3494 | static UsingDecl *Create(ASTContext &C, DeclContext *DC, |
3495 | SourceLocation UsingL, |
3496 | NestedNameSpecifierLoc QualifierLoc, |
3497 | const DeclarationNameInfo &NameInfo, |
3498 | bool HasTypenameKeyword); |
3499 | |
3500 | static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3501 | |
3502 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)); |
3503 | |
3504 | /// Retrieves the canonical declaration of this declaration. |
3505 | UsingDecl *getCanonicalDecl() override { return getFirstDecl(); } |
3506 | const UsingDecl *getCanonicalDecl() const { return getFirstDecl(); } |
3507 | |
3508 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3509 | static bool classofKind(Kind K) { return K == Using; } |
3510 | }; |
3511 | |
3512 | /// Represents a pack of using declarations that a single |
3513 | /// using-declarator pack-expanded into. |
3514 | /// |
3515 | /// \code |
3516 | /// template<typename ...T> struct X : T... { |
3517 | /// using T::operator()...; |
3518 | /// using T::operator T...; |
3519 | /// }; |
3520 | /// \endcode |
3521 | /// |
3522 | /// In the second case above, the UsingPackDecl will have the name |
3523 | /// 'operator T' (which contains an unexpanded pack), but the individual |
3524 | /// UsingDecls and UsingShadowDecls will have more reasonable names. |
3525 | class UsingPackDecl final |
3526 | : public NamedDecl, public Mergeable<UsingPackDecl>, |
3527 | private llvm::TrailingObjects<UsingPackDecl, NamedDecl *> { |
3528 | /// The UnresolvedUsingValueDecl or UnresolvedUsingTypenameDecl from |
3529 | /// which this waas instantiated. |
3530 | NamedDecl *InstantiatedFrom; |
3531 | |
3532 | /// The number of using-declarations created by this pack expansion. |
3533 | unsigned NumExpansions; |
3534 | |
3535 | UsingPackDecl(DeclContext *DC, NamedDecl *InstantiatedFrom, |
3536 | ArrayRef<NamedDecl *> UsingDecls) |
3537 | : NamedDecl(UsingPack, DC, |
3538 | InstantiatedFrom ? InstantiatedFrom->getLocation() |
3539 | : SourceLocation(), |
3540 | InstantiatedFrom ? InstantiatedFrom->getDeclName() |
3541 | : DeclarationName()), |
3542 | InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) { |
3543 | std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(), |
3544 | getTrailingObjects<NamedDecl *>()); |
3545 | } |
3546 | |
3547 | void anchor() override; |
3548 | |
3549 | public: |
3550 | friend class ASTDeclReader; |
3551 | friend class ASTDeclWriter; |
3552 | friend TrailingObjects; |
3553 | |
3554 | /// Get the using declaration from which this was instantiated. This will |
3555 | /// always be an UnresolvedUsingValueDecl or an UnresolvedUsingTypenameDecl |
3556 | /// that is a pack expansion. |
3557 | NamedDecl *getInstantiatedFromUsingDecl() const { return InstantiatedFrom; } |
3558 | |
3559 | /// Get the set of using declarations that this pack expanded into. Note that |
3560 | /// some of these may still be unresolved. |
3561 | ArrayRef<NamedDecl *> expansions() const { |
3562 | return llvm::makeArrayRef(getTrailingObjects<NamedDecl *>(), NumExpansions); |
3563 | } |
3564 | |
3565 | static UsingPackDecl *Create(ASTContext &C, DeclContext *DC, |
3566 | NamedDecl *InstantiatedFrom, |
3567 | ArrayRef<NamedDecl *> UsingDecls); |
3568 | |
3569 | static UsingPackDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
3570 | unsigned NumExpansions); |
3571 | |
3572 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
3573 | return InstantiatedFrom->getSourceRange(); |
3574 | } |
3575 | |
3576 | UsingPackDecl *getCanonicalDecl() override { return getFirstDecl(); } |
3577 | const UsingPackDecl *getCanonicalDecl() const { return getFirstDecl(); } |
3578 | |
3579 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3580 | static bool classofKind(Kind K) { return K == UsingPack; } |
3581 | }; |
3582 | |
3583 | /// Represents a dependent using declaration which was not marked with |
3584 | /// \c typename. |
3585 | /// |
3586 | /// Unlike non-dependent using declarations, these *only* bring through |
3587 | /// non-types; otherwise they would break two-phase lookup. |
3588 | /// |
3589 | /// \code |
3590 | /// template \<class T> class A : public Base<T> { |
3591 | /// using Base<T>::foo; |
3592 | /// }; |
3593 | /// \endcode |
3594 | class UnresolvedUsingValueDecl : public ValueDecl, |
3595 | public Mergeable<UnresolvedUsingValueDecl> { |
3596 | /// The source location of the 'using' keyword |
3597 | SourceLocation UsingLocation; |
3598 | |
3599 | /// If this is a pack expansion, the location of the '...'. |
3600 | SourceLocation EllipsisLoc; |
3601 | |
3602 | /// The nested-name-specifier that precedes the name. |
3603 | NestedNameSpecifierLoc QualifierLoc; |
3604 | |
3605 | /// Provides source/type location info for the declaration name |
3606 | /// embedded in the ValueDecl base class. |
3607 | DeclarationNameLoc DNLoc; |
3608 | |
3609 | UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty, |
3610 | SourceLocation UsingLoc, |
3611 | NestedNameSpecifierLoc QualifierLoc, |
3612 | const DeclarationNameInfo &NameInfo, |
3613 | SourceLocation EllipsisLoc) |
3614 | : ValueDecl(UnresolvedUsingValue, DC, |
3615 | NameInfo.getLoc(), NameInfo.getName(), Ty), |
3616 | UsingLocation(UsingLoc), EllipsisLoc(EllipsisLoc), |
3617 | QualifierLoc(QualifierLoc), DNLoc(NameInfo.getInfo()) {} |
3618 | |
3619 | void anchor() override; |
3620 | |
3621 | public: |
3622 | friend class ASTDeclReader; |
3623 | friend class ASTDeclWriter; |
3624 | |
3625 | /// Returns the source location of the 'using' keyword. |
3626 | SourceLocation getUsingLoc() const { return UsingLocation; } |
3627 | |
3628 | /// Set the source location of the 'using' keyword. |
3629 | void setUsingLoc(SourceLocation L) { UsingLocation = L; } |
3630 | |
3631 | /// Return true if it is a C++03 access declaration (no 'using'). |
3632 | bool isAccessDeclaration() const { return UsingLocation.isInvalid(); } |
3633 | |
3634 | /// Retrieve the nested-name-specifier that qualifies the name, |
3635 | /// with source-location information. |
3636 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3637 | |
3638 | /// Retrieve the nested-name-specifier that qualifies the name. |
3639 | NestedNameSpecifier *getQualifier() const { |
3640 | return QualifierLoc.getNestedNameSpecifier(); |
3641 | } |
3642 | |
3643 | DeclarationNameInfo getNameInfo() const { |
3644 | return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); |
3645 | } |
3646 | |
3647 | /// Determine whether this is a pack expansion. |
3648 | bool isPackExpansion() const { |
3649 | return EllipsisLoc.isValid(); |
3650 | } |
3651 | |
3652 | /// Get the location of the ellipsis if this is a pack expansion. |
3653 | SourceLocation getEllipsisLoc() const { |
3654 | return EllipsisLoc; |
3655 | } |
3656 | |
3657 | static UnresolvedUsingValueDecl * |
3658 | Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, |
3659 | NestedNameSpecifierLoc QualifierLoc, |
3660 | const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc); |
3661 | |
3662 | static UnresolvedUsingValueDecl * |
3663 | CreateDeserialized(ASTContext &C, unsigned ID); |
3664 | |
3665 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)); |
3666 | |
3667 | /// Retrieves the canonical declaration of this declaration. |
3668 | UnresolvedUsingValueDecl *getCanonicalDecl() override { |
3669 | return getFirstDecl(); |
3670 | } |
3671 | const UnresolvedUsingValueDecl *getCanonicalDecl() const { |
3672 | return getFirstDecl(); |
3673 | } |
3674 | |
3675 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3676 | static bool classofKind(Kind K) { return K == UnresolvedUsingValue; } |
3677 | }; |
3678 | |
3679 | /// Represents a dependent using declaration which was marked with |
3680 | /// \c typename. |
3681 | /// |
3682 | /// \code |
3683 | /// template \<class T> class A : public Base<T> { |
3684 | /// using typename Base<T>::foo; |
3685 | /// }; |
3686 | /// \endcode |
3687 | /// |
3688 | /// The type associated with an unresolved using typename decl is |
3689 | /// currently always a typename type. |
3690 | class UnresolvedUsingTypenameDecl |
3691 | : public TypeDecl, |
3692 | public Mergeable<UnresolvedUsingTypenameDecl> { |
3693 | friend class ASTDeclReader; |
3694 | |
3695 | /// The source location of the 'typename' keyword |
3696 | SourceLocation TypenameLocation; |
3697 | |
3698 | /// If this is a pack expansion, the location of the '...'. |
3699 | SourceLocation EllipsisLoc; |
3700 | |
3701 | /// The nested-name-specifier that precedes the name. |
3702 | NestedNameSpecifierLoc QualifierLoc; |
3703 | |
3704 | UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc, |
3705 | SourceLocation TypenameLoc, |
3706 | NestedNameSpecifierLoc QualifierLoc, |
3707 | SourceLocation TargetNameLoc, |
3708 | IdentifierInfo *TargetName, |
3709 | SourceLocation EllipsisLoc) |
3710 | : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName, |
3711 | UsingLoc), |
3712 | TypenameLocation(TypenameLoc), EllipsisLoc(EllipsisLoc), |
3713 | QualifierLoc(QualifierLoc) {} |
3714 | |
3715 | void anchor() override; |
3716 | |
3717 | public: |
3718 | /// Returns the source location of the 'using' keyword. |
3719 | SourceLocation getUsingLoc() const { return getBeginLoc(); } |
3720 | |
3721 | /// Returns the source location of the 'typename' keyword. |
3722 | SourceLocation getTypenameLoc() const { return TypenameLocation; } |
3723 | |
3724 | /// Retrieve the nested-name-specifier that qualifies the name, |
3725 | /// with source-location information. |
3726 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3727 | |
3728 | /// Retrieve the nested-name-specifier that qualifies the name. |
3729 | NestedNameSpecifier *getQualifier() const { |
3730 | return QualifierLoc.getNestedNameSpecifier(); |
3731 | } |
3732 | |
3733 | DeclarationNameInfo getNameInfo() const { |
3734 | return DeclarationNameInfo(getDeclName(), getLocation()); |
3735 | } |
3736 | |
3737 | /// Determine whether this is a pack expansion. |
3738 | bool isPackExpansion() const { |
3739 | return EllipsisLoc.isValid(); |
3740 | } |
3741 | |
3742 | /// Get the location of the ellipsis if this is a pack expansion. |
3743 | SourceLocation getEllipsisLoc() const { |
3744 | return EllipsisLoc; |
3745 | } |
3746 | |
3747 | static UnresolvedUsingTypenameDecl * |
3748 | Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, |
3749 | SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc, |
3750 | SourceLocation TargetNameLoc, DeclarationName TargetName, |
3751 | SourceLocation EllipsisLoc); |
3752 | |
3753 | static UnresolvedUsingTypenameDecl * |
3754 | CreateDeserialized(ASTContext &C, unsigned ID); |
3755 | |
3756 | /// Retrieves the canonical declaration of this declaration. |
3757 | UnresolvedUsingTypenameDecl *getCanonicalDecl() override { |
3758 | return getFirstDecl(); |
3759 | } |
3760 | const UnresolvedUsingTypenameDecl *getCanonicalDecl() const { |
3761 | return getFirstDecl(); |
3762 | } |
3763 | |
3764 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3765 | static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; } |
3766 | }; |
3767 | |
3768 | /// Represents a C++11 static_assert declaration. |
3769 | class StaticAssertDecl : public Decl { |
3770 | llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed; |
3771 | StringLiteral *Message; |
3772 | SourceLocation RParenLoc; |
3773 | |
3774 | StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc, |
3775 | Expr *AssertExpr, StringLiteral *Message, |
3776 | SourceLocation RParenLoc, bool Failed) |
3777 | : Decl(StaticAssert, DC, StaticAssertLoc), |
3778 | AssertExprAndFailed(AssertExpr, Failed), Message(Message), |
3779 | RParenLoc(RParenLoc) {} |
3780 | |
3781 | virtual void anchor(); |
3782 | |
3783 | public: |
3784 | friend class ASTDeclReader; |
3785 | |
3786 | static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, |
3787 | SourceLocation StaticAssertLoc, |
3788 | Expr *AssertExpr, StringLiteral *Message, |
3789 | SourceLocation RParenLoc, bool Failed); |
3790 | static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3791 | |
3792 | Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); } |
3793 | const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); } |
3794 | |
3795 | StringLiteral *getMessage() { return Message; } |
3796 | const StringLiteral *getMessage() const { return Message; } |
3797 | |
3798 | bool isFailed() const { return AssertExprAndFailed.getInt(); } |
3799 | |
3800 | SourceLocation getRParenLoc() const { return RParenLoc; } |
3801 | |
3802 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
3803 | return SourceRange(getLocation(), getRParenLoc()); |
3804 | } |
3805 | |
3806 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3807 | static bool classofKind(Kind K) { return K == StaticAssert; } |
3808 | }; |
3809 | |
3810 | /// A binding in a decomposition declaration. For instance, given: |
3811 | /// |
3812 | /// int n[3]; |
3813 | /// auto &[a, b, c] = n; |
3814 | /// |
3815 | /// a, b, and c are BindingDecls, whose bindings are the expressions |
3816 | /// x[0], x[1], and x[2] respectively, where x is the implicit |
3817 | /// DecompositionDecl of type 'int (&)[3]'. |
3818 | class BindingDecl : public ValueDecl { |
3819 | /// The declaration that this binding binds to part of. |
3820 | LazyDeclPtr Decomp; |
3821 | /// The binding represented by this declaration. References to this |
3822 | /// declaration are effectively equivalent to this expression (except |
3823 | /// that it is only evaluated once at the point of declaration of the |
3824 | /// binding). |
3825 | Expr *Binding = nullptr; |
3826 | |
3827 | BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id) |
3828 | : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()) {} |
3829 | |
3830 | void anchor() override; |
3831 | |
3832 | public: |
3833 | friend class ASTDeclReader; |
3834 | |
3835 | static BindingDecl *Create(ASTContext &C, DeclContext *DC, |
3836 | SourceLocation IdLoc, IdentifierInfo *Id); |
3837 | static BindingDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3838 | |
3839 | /// Get the expression to which this declaration is bound. This may be null |
3840 | /// in two different cases: while parsing the initializer for the |
3841 | /// decomposition declaration, and when the initializer is type-dependent. |
3842 | Expr *getBinding() const { return Binding; } |
3843 | |
3844 | /// Get the decomposition declaration that this binding represents a |
3845 | /// decomposition of. |
3846 | ValueDecl *getDecomposedDecl() const; |
3847 | |
3848 | /// Get the variable (if any) that holds the value of evaluating the binding. |
3849 | /// Only present for user-defined bindings for tuple-like types. |
3850 | VarDecl *getHoldingVar() const; |
3851 | |
3852 | /// Set the binding for this BindingDecl, along with its declared type (which |
3853 | /// should be a possibly-cv-qualified form of the type of the binding, or a |
3854 | /// reference to such a type). |
3855 | void setBinding(QualType DeclaredType, Expr *Binding) { |
3856 | setType(DeclaredType); |
3857 | this->Binding = Binding; |
3858 | } |
3859 | |
3860 | /// Set the decomposed variable for this BindingDecl. |
3861 | void setDecomposedDecl(ValueDecl *Decomposed) { Decomp = Decomposed; } |
3862 | |
3863 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3864 | static bool classofKind(Kind K) { return K == Decl::Binding; } |
3865 | }; |
3866 | |
3867 | /// A decomposition declaration. For instance, given: |
3868 | /// |
3869 | /// int n[3]; |
3870 | /// auto &[a, b, c] = n; |
3871 | /// |
3872 | /// the second line declares a DecompositionDecl of type 'int (&)[3]', and |
3873 | /// three BindingDecls (named a, b, and c). An instance of this class is always |
3874 | /// unnamed, but behaves in almost all other respects like a VarDecl. |
3875 | class DecompositionDecl final |
3876 | : public VarDecl, |
3877 | private llvm::TrailingObjects<DecompositionDecl, BindingDecl *> { |
3878 | /// The number of BindingDecl*s following this object. |
3879 | unsigned NumBindings; |
3880 | |
3881 | DecompositionDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
3882 | SourceLocation LSquareLoc, QualType T, |
3883 | TypeSourceInfo *TInfo, StorageClass SC, |
3884 | ArrayRef<BindingDecl *> Bindings) |
3885 | : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo, |
3886 | SC), |
3887 | NumBindings(Bindings.size()) { |
3888 | std::uninitialized_copy(Bindings.begin(), Bindings.end(), |
3889 | getTrailingObjects<BindingDecl *>()); |
3890 | for (auto *B : Bindings) |
3891 | B->setDecomposedDecl(this); |
3892 | } |
3893 | |
3894 | void anchor() override; |
3895 | |
3896 | public: |
3897 | friend class ASTDeclReader; |
3898 | friend TrailingObjects; |
3899 | |
3900 | static DecompositionDecl *Create(ASTContext &C, DeclContext *DC, |
3901 | SourceLocation StartLoc, |
3902 | SourceLocation LSquareLoc, |
3903 | QualType T, TypeSourceInfo *TInfo, |
3904 | StorageClass S, |
3905 | ArrayRef<BindingDecl *> Bindings); |
3906 | static DecompositionDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
3907 | unsigned NumBindings); |
3908 | |
3909 | ArrayRef<BindingDecl *> bindings() const { |
3910 | return llvm::makeArrayRef(getTrailingObjects<BindingDecl *>(), NumBindings); |
3911 | } |
3912 | |
3913 | void printName(raw_ostream &os) const override; |
3914 | |
3915 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3916 | static bool classofKind(Kind K) { return K == Decomposition; } |
3917 | }; |
3918 | |
3919 | /// An instance of this class represents the declaration of a property |
3920 | /// member. This is a Microsoft extension to C++, first introduced in |
3921 | /// Visual Studio .NET 2003 as a parallel to similar features in C# |
3922 | /// and Managed C++. |
3923 | /// |
3924 | /// A property must always be a non-static class member. |
3925 | /// |
3926 | /// A property member superficially resembles a non-static data |
3927 | /// member, except preceded by a property attribute: |
3928 | /// __declspec(property(get=GetX, put=PutX)) int x; |
3929 | /// Either (but not both) of the 'get' and 'put' names may be omitted. |
3930 | /// |
3931 | /// A reference to a property is always an lvalue. If the lvalue |
3932 | /// undergoes lvalue-to-rvalue conversion, then a getter name is |
3933 | /// required, and that member is called with no arguments. |
3934 | /// If the lvalue is assigned into, then a setter name is required, |
3935 | /// and that member is called with one argument, the value assigned. |
3936 | /// Both operations are potentially overloaded. Compound assignments |
3937 | /// are permitted, as are the increment and decrement operators. |
3938 | /// |
3939 | /// The getter and putter methods are permitted to be overloaded, |
3940 | /// although their return and parameter types are subject to certain |
3941 | /// restrictions according to the type of the property. |
3942 | /// |
3943 | /// A property declared using an incomplete array type may |
3944 | /// additionally be subscripted, adding extra parameters to the getter |
3945 | /// and putter methods. |
3946 | class MSPropertyDecl : public DeclaratorDecl { |
3947 | IdentifierInfo *GetterId, *SetterId; |
3948 | |
3949 | MSPropertyDecl(DeclContext *DC, SourceLocation L, DeclarationName N, |
3950 | QualType T, TypeSourceInfo *TInfo, SourceLocation StartL, |
3951 | IdentifierInfo *Getter, IdentifierInfo *Setter) |
3952 | : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL), |
3953 | GetterId(Getter), SetterId(Setter) {} |
3954 | |
3955 | void anchor() override; |
3956 | public: |
3957 | friend class ASTDeclReader; |
3958 | |
3959 | static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC, |
3960 | SourceLocation L, DeclarationName N, QualType T, |
3961 | TypeSourceInfo *TInfo, SourceLocation StartL, |
3962 | IdentifierInfo *Getter, IdentifierInfo *Setter); |
3963 | static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3964 | |
3965 | static bool classof(const Decl *D) { return D->getKind() == MSProperty; } |
3966 | |
3967 | bool hasGetter() const { return GetterId != nullptr; } |
3968 | IdentifierInfo* getGetterId() const { return GetterId; } |
3969 | bool hasSetter() const { return SetterId != nullptr; } |
3970 | IdentifierInfo* getSetterId() const { return SetterId; } |
3971 | }; |
3972 | |
3973 | /// Parts of a decomposed MSGuidDecl. Factored out to avoid unnecessary |
3974 | /// dependencies on DeclCXX.h. |
3975 | struct MSGuidDeclParts { |
3976 | /// {01234567-... |
3977 | uint32_t Part1; |
3978 | /// ...-89ab-... |
3979 | uint16_t Part2; |
3980 | /// ...-cdef-... |
3981 | uint16_t Part3; |
3982 | /// ...-0123-456789abcdef} |
3983 | uint8_t Part4And5[8]; |
3984 | |
3985 | uint64_t getPart4And5AsUint64() const { |
3986 | uint64_t Val; |
3987 | memcpy(&Val, &Part4And5, sizeof(Part4And5)); |
3988 | return Val; |
3989 | } |
3990 | }; |
3991 | |
3992 | /// A global _GUID constant. These are implicitly created by UuidAttrs. |
3993 | /// |
3994 | /// struct _declspec(uuid("01234567-89ab-cdef-0123-456789abcdef")) X{}; |
3995 | /// |
3996 | /// X is a CXXRecordDecl that contains a UuidAttr that references the (unique) |
3997 | /// MSGuidDecl for the specified UUID. |
3998 | class MSGuidDecl : public ValueDecl, |
3999 | public Mergeable<MSGuidDecl>, |
4000 | public llvm::FoldingSetNode { |
4001 | public: |
4002 | using Parts = MSGuidDeclParts; |
4003 | |
4004 | private: |
4005 | /// The decomposed form of the UUID. |
4006 | Parts PartVal; |
4007 | |
4008 | /// The resolved value of the UUID as an APValue. Computed on demand and |
4009 | /// cached. |
4010 | mutable APValue APVal; |
4011 | |
4012 | void anchor() override; |
4013 | |
4014 | MSGuidDecl(DeclContext *DC, QualType T, Parts P); |
4015 | |
4016 | static MSGuidDecl *Create(const ASTContext &C, QualType T, Parts P); |
4017 | static MSGuidDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
4018 | |
4019 | // Only ASTContext::getMSGuidDecl and deserialization create these. |
4020 | friend class ASTContext; |
4021 | friend class ASTReader; |
4022 | friend class ASTDeclReader; |
4023 | |
4024 | public: |
4025 | /// Print this UUID in a human-readable format. |
4026 | void printName(llvm::raw_ostream &OS) const override; |
4027 | |
4028 | /// Get the decomposed parts of this declaration. |
4029 | Parts getParts() const { return PartVal; } |
4030 | |
4031 | /// Get the value of this MSGuidDecl as an APValue. This may fail and return |
4032 | /// an absent APValue if the type of the declaration is not of the expected |
4033 | /// shape. |
4034 | APValue &getAsAPValue() const; |
4035 | |
4036 | static void Profile(llvm::FoldingSetNodeID &ID, Parts P) { |
4037 | ID.AddInteger(P.Part1); |
4038 | ID.AddInteger(P.Part2); |
4039 | ID.AddInteger(P.Part3); |
4040 | ID.AddInteger(P.getPart4And5AsUint64()); |
4041 | } |
4042 | void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, PartVal); } |
4043 | |
4044 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
4045 | static bool classofKind(Kind K) { return K == Decl::MSGuid; } |
4046 | }; |
4047 | |
4048 | /// Insertion operator for diagnostics. This allows sending an AccessSpecifier |
4049 | /// into a diagnostic with <<. |
4050 | const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB, |
4051 | AccessSpecifier AS); |
4052 | |
4053 | } // namespace clang |
4054 | |
4055 | #endif // LLVM_CLANG_AST_DECLCXX_H |