| File: | build/source/clang/lib/AST/ItaniumMangle.cpp |
| Warning: | line 303, column 28 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | //===--- ItaniumMangle.cpp - Itanium C++ Name Mangling ----------*- 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 | // Implements C++ name mangling according to the Itanium C++ ABI, | |||
| 10 | // which is used in GCC 3.2 and newer (and many compilers that are | |||
| 11 | // ABI-compatible with GCC): | |||
| 12 | // | |||
| 13 | // http://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling | |||
| 14 | // | |||
| 15 | //===----------------------------------------------------------------------===// | |||
| 16 | ||||
| 17 | #include "clang/AST/ASTContext.h" | |||
| 18 | #include "clang/AST/Attr.h" | |||
| 19 | #include "clang/AST/Decl.h" | |||
| 20 | #include "clang/AST/DeclCXX.h" | |||
| 21 | #include "clang/AST/DeclObjC.h" | |||
| 22 | #include "clang/AST/DeclOpenMP.h" | |||
| 23 | #include "clang/AST/DeclTemplate.h" | |||
| 24 | #include "clang/AST/Expr.h" | |||
| 25 | #include "clang/AST/ExprCXX.h" | |||
| 26 | #include "clang/AST/ExprConcepts.h" | |||
| 27 | #include "clang/AST/ExprObjC.h" | |||
| 28 | #include "clang/AST/Mangle.h" | |||
| 29 | #include "clang/AST/TypeLoc.h" | |||
| 30 | #include "clang/Basic/ABI.h" | |||
| 31 | #include "clang/Basic/Module.h" | |||
| 32 | #include "clang/Basic/SourceManager.h" | |||
| 33 | #include "clang/Basic/TargetInfo.h" | |||
| 34 | #include "clang/Basic/Thunk.h" | |||
| 35 | #include "llvm/ADT/StringExtras.h" | |||
| 36 | #include "llvm/Support/ErrorHandling.h" | |||
| 37 | #include "llvm/Support/raw_ostream.h" | |||
| 38 | #include <optional> | |||
| 39 | ||||
| 40 | using namespace clang; | |||
| 41 | ||||
| 42 | namespace { | |||
| 43 | ||||
| 44 | static bool isLocalContainerContext(const DeclContext *DC) { | |||
| 45 | return isa<FunctionDecl>(DC) || isa<ObjCMethodDecl>(DC) || isa<BlockDecl>(DC); | |||
| 46 | } | |||
| 47 | ||||
| 48 | static const FunctionDecl *getStructor(const FunctionDecl *fn) { | |||
| 49 | if (const FunctionTemplateDecl *ftd = fn->getPrimaryTemplate()) | |||
| 50 | return ftd->getTemplatedDecl(); | |||
| 51 | ||||
| 52 | return fn; | |||
| 53 | } | |||
| 54 | ||||
| 55 | static const NamedDecl *getStructor(const NamedDecl *decl) { | |||
| 56 | const FunctionDecl *fn = dyn_cast_or_null<FunctionDecl>(decl); | |||
| 57 | return (fn ? getStructor(fn) : decl); | |||
| 58 | } | |||
| 59 | ||||
| 60 | static bool isLambda(const NamedDecl *ND) { | |||
| 61 | const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(ND); | |||
| 62 | if (!Record) | |||
| 63 | return false; | |||
| 64 | ||||
| 65 | return Record->isLambda(); | |||
| 66 | } | |||
| 67 | ||||
| 68 | static const unsigned UnknownArity = ~0U; | |||
| 69 | ||||
| 70 | class ItaniumMangleContextImpl : public ItaniumMangleContext { | |||
| 71 | typedef std::pair<const DeclContext*, IdentifierInfo*> DiscriminatorKeyTy; | |||
| 72 | llvm::DenseMap<DiscriminatorKeyTy, unsigned> Discriminator; | |||
| 73 | llvm::DenseMap<const NamedDecl*, unsigned> Uniquifier; | |||
| 74 | const DiscriminatorOverrideTy DiscriminatorOverride = nullptr; | |||
| 75 | NamespaceDecl *StdNamespace = nullptr; | |||
| 76 | ||||
| 77 | bool NeedsUniqueInternalLinkageNames = false; | |||
| 78 | ||||
| 79 | public: | |||
| 80 | explicit ItaniumMangleContextImpl( | |||
| 81 | ASTContext &Context, DiagnosticsEngine &Diags, | |||
| 82 | DiscriminatorOverrideTy DiscriminatorOverride, bool IsAux = false) | |||
| 83 | : ItaniumMangleContext(Context, Diags, IsAux), | |||
| 84 | DiscriminatorOverride(DiscriminatorOverride) {} | |||
| 85 | ||||
| 86 | /// @name Mangler Entry Points | |||
| 87 | /// @{ | |||
| 88 | ||||
| 89 | bool shouldMangleCXXName(const NamedDecl *D) override; | |||
| 90 | bool shouldMangleStringLiteral(const StringLiteral *) override { | |||
| 91 | return false; | |||
| 92 | } | |||
| 93 | ||||
| 94 | bool isUniqueInternalLinkageDecl(const NamedDecl *ND) override; | |||
| 95 | void needsUniqueInternalLinkageNames() override { | |||
| 96 | NeedsUniqueInternalLinkageNames = true; | |||
| 97 | } | |||
| 98 | ||||
| 99 | void mangleCXXName(GlobalDecl GD, raw_ostream &) override; | |||
| 100 | void mangleThunk(const CXXMethodDecl *MD, const ThunkInfo &Thunk, | |||
| 101 | raw_ostream &) override; | |||
| 102 | void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type, | |||
| 103 | const ThisAdjustment &ThisAdjustment, | |||
| 104 | raw_ostream &) override; | |||
| 105 | void mangleReferenceTemporary(const VarDecl *D, unsigned ManglingNumber, | |||
| 106 | raw_ostream &) override; | |||
| 107 | void mangleCXXVTable(const CXXRecordDecl *RD, raw_ostream &) override; | |||
| 108 | void mangleCXXVTT(const CXXRecordDecl *RD, raw_ostream &) override; | |||
| 109 | void mangleCXXCtorVTable(const CXXRecordDecl *RD, int64_t Offset, | |||
| 110 | const CXXRecordDecl *Type, raw_ostream &) override; | |||
| 111 | void mangleCXXRTTI(QualType T, raw_ostream &) override; | |||
| 112 | void mangleCXXRTTIName(QualType T, raw_ostream &, | |||
| 113 | bool NormalizeIntegers) override; | |||
| 114 | void mangleTypeName(QualType T, raw_ostream &, | |||
| 115 | bool NormalizeIntegers) override; | |||
| 116 | ||||
| 117 | void mangleCXXCtorComdat(const CXXConstructorDecl *D, raw_ostream &) override; | |||
| 118 | void mangleCXXDtorComdat(const CXXDestructorDecl *D, raw_ostream &) override; | |||
| 119 | void mangleStaticGuardVariable(const VarDecl *D, raw_ostream &) override; | |||
| 120 | void mangleDynamicInitializer(const VarDecl *D, raw_ostream &Out) override; | |||
| 121 | void mangleDynamicAtExitDestructor(const VarDecl *D, | |||
| 122 | raw_ostream &Out) override; | |||
| 123 | void mangleDynamicStermFinalizer(const VarDecl *D, raw_ostream &Out) override; | |||
| 124 | void mangleSEHFilterExpression(GlobalDecl EnclosingDecl, | |||
| 125 | raw_ostream &Out) override; | |||
| 126 | void mangleSEHFinallyBlock(GlobalDecl EnclosingDecl, | |||
| 127 | raw_ostream &Out) override; | |||
| 128 | void mangleItaniumThreadLocalInit(const VarDecl *D, raw_ostream &) override; | |||
| 129 | void mangleItaniumThreadLocalWrapper(const VarDecl *D, | |||
| 130 | raw_ostream &) override; | |||
| 131 | ||||
| 132 | void mangleStringLiteral(const StringLiteral *, raw_ostream &) override; | |||
| 133 | ||||
| 134 | void mangleLambdaSig(const CXXRecordDecl *Lambda, raw_ostream &) override; | |||
| 135 | ||||
| 136 | void mangleModuleInitializer(const Module *Module, raw_ostream &) override; | |||
| 137 | ||||
| 138 | bool getNextDiscriminator(const NamedDecl *ND, unsigned &disc) { | |||
| 139 | // Lambda closure types are already numbered. | |||
| 140 | if (isLambda(ND)) | |||
| 141 | return false; | |||
| 142 | ||||
| 143 | // Anonymous tags are already numbered. | |||
| 144 | if (const TagDecl *Tag = dyn_cast<TagDecl>(ND)) { | |||
| 145 | if (Tag->getName().empty() && !Tag->getTypedefNameForAnonDecl()) | |||
| 146 | return false; | |||
| 147 | } | |||
| 148 | ||||
| 149 | // Use the canonical number for externally visible decls. | |||
| 150 | if (ND->isExternallyVisible()) { | |||
| 151 | unsigned discriminator = getASTContext().getManglingNumber(ND, isAux()); | |||
| 152 | if (discriminator == 1) | |||
| 153 | return false; | |||
| 154 | disc = discriminator - 2; | |||
| 155 | return true; | |||
| 156 | } | |||
| 157 | ||||
| 158 | // Make up a reasonable number for internal decls. | |||
| 159 | unsigned &discriminator = Uniquifier[ND]; | |||
| 160 | if (!discriminator) { | |||
| 161 | const DeclContext *DC = getEffectiveDeclContext(ND); | |||
| 162 | discriminator = ++Discriminator[std::make_pair(DC, ND->getIdentifier())]; | |||
| 163 | } | |||
| 164 | if (discriminator == 1) | |||
| 165 | return false; | |||
| 166 | disc = discriminator-2; | |||
| 167 | return true; | |||
| 168 | } | |||
| 169 | ||||
| 170 | std::string getLambdaString(const CXXRecordDecl *Lambda) override { | |||
| 171 | // This function matches the one in MicrosoftMangle, which returns | |||
| 172 | // the string that is used in lambda mangled names. | |||
| 173 | assert(Lambda->isLambda() && "RD must be a lambda!")(static_cast <bool> (Lambda->isLambda() && "RD must be a lambda!" ) ? void (0) : __assert_fail ("Lambda->isLambda() && \"RD must be a lambda!\"" , "clang/lib/AST/ItaniumMangle.cpp", 173, __extension__ __PRETTY_FUNCTION__ )); | |||
| 174 | std::string Name("<lambda"); | |||
| 175 | Decl *LambdaContextDecl = Lambda->getLambdaContextDecl(); | |||
| 176 | unsigned LambdaManglingNumber = Lambda->getLambdaManglingNumber(); | |||
| 177 | unsigned LambdaId; | |||
| 178 | const ParmVarDecl *Parm = dyn_cast_or_null<ParmVarDecl>(LambdaContextDecl); | |||
| 179 | const FunctionDecl *Func = | |||
| 180 | Parm ? dyn_cast<FunctionDecl>(Parm->getDeclContext()) : nullptr; | |||
| 181 | ||||
| 182 | if (Func) { | |||
| 183 | unsigned DefaultArgNo = | |||
| 184 | Func->getNumParams() - Parm->getFunctionScopeIndex(); | |||
| 185 | Name += llvm::utostr(DefaultArgNo); | |||
| 186 | Name += "_"; | |||
| 187 | } | |||
| 188 | ||||
| 189 | if (LambdaManglingNumber) | |||
| 190 | LambdaId = LambdaManglingNumber; | |||
| 191 | else | |||
| 192 | LambdaId = getAnonymousStructIdForDebugInfo(Lambda); | |||
| 193 | ||||
| 194 | Name += llvm::utostr(LambdaId); | |||
| 195 | Name += '>'; | |||
| 196 | return Name; | |||
| 197 | } | |||
| 198 | ||||
| 199 | DiscriminatorOverrideTy getDiscriminatorOverride() const override { | |||
| 200 | return DiscriminatorOverride; | |||
| 201 | } | |||
| 202 | ||||
| 203 | NamespaceDecl *getStdNamespace(); | |||
| 204 | ||||
| 205 | const DeclContext *getEffectiveDeclContext(const Decl *D); | |||
| 206 | const DeclContext *getEffectiveParentContext(const DeclContext *DC) { | |||
| 207 | return getEffectiveDeclContext(cast<Decl>(DC)); | |||
| 208 | } | |||
| 209 | ||||
| 210 | bool isInternalLinkageDecl(const NamedDecl *ND); | |||
| 211 | const DeclContext *IgnoreLinkageSpecDecls(const DeclContext *DC); | |||
| 212 | ||||
| 213 | /// @} | |||
| 214 | }; | |||
| 215 | ||||
| 216 | /// Manage the mangling of a single name. | |||
| 217 | class CXXNameMangler { | |||
| 218 | ItaniumMangleContextImpl &Context; | |||
| 219 | raw_ostream &Out; | |||
| 220 | /// Normalize integer types for cross-language CFI support with other | |||
| 221 | /// languages that can't represent and encode C/C++ integer types. | |||
| 222 | bool NormalizeIntegers = false; | |||
| 223 | ||||
| 224 | bool NullOut = false; | |||
| 225 | /// In the "DisableDerivedAbiTags" mode derived ABI tags are not calculated. | |||
| 226 | /// This mode is used when mangler creates another mangler recursively to | |||
| 227 | /// calculate ABI tags for the function return value or the variable type. | |||
| 228 | /// Also it is required to avoid infinite recursion in some cases. | |||
| 229 | bool DisableDerivedAbiTags = false; | |||
| 230 | ||||
| 231 | /// The "structor" is the top-level declaration being mangled, if | |||
| 232 | /// that's not a template specialization; otherwise it's the pattern | |||
| 233 | /// for that specialization. | |||
| 234 | const NamedDecl *Structor; | |||
| 235 | unsigned StructorType = 0; | |||
| 236 | ||||
| 237 | /// The next substitution sequence number. | |||
| 238 | unsigned SeqID = 0; | |||
| 239 | ||||
| 240 | class FunctionTypeDepthState { | |||
| 241 | unsigned Bits; | |||
| 242 | ||||
| 243 | enum { InResultTypeMask = 1 }; | |||
| 244 | ||||
| 245 | public: | |||
| 246 | FunctionTypeDepthState() : Bits(0) {} | |||
| 247 | ||||
| 248 | /// The number of function types we're inside. | |||
| 249 | unsigned getDepth() const { | |||
| 250 | return Bits >> 1; | |||
| 251 | } | |||
| 252 | ||||
| 253 | /// True if we're in the return type of the innermost function type. | |||
| 254 | bool isInResultType() const { | |||
| 255 | return Bits & InResultTypeMask; | |||
| 256 | } | |||
| 257 | ||||
| 258 | FunctionTypeDepthState push() { | |||
| 259 | FunctionTypeDepthState tmp = *this; | |||
| 260 | Bits = (Bits & ~InResultTypeMask) + 2; | |||
| 261 | return tmp; | |||
| 262 | } | |||
| 263 | ||||
| 264 | void enterResultType() { | |||
| 265 | Bits |= InResultTypeMask; | |||
| 266 | } | |||
| 267 | ||||
| 268 | void leaveResultType() { | |||
| 269 | Bits &= ~InResultTypeMask; | |||
| 270 | } | |||
| 271 | ||||
| 272 | void pop(FunctionTypeDepthState saved) { | |||
| 273 | assert(getDepth() == saved.getDepth() + 1)(static_cast <bool> (getDepth() == saved.getDepth() + 1 ) ? void (0) : __assert_fail ("getDepth() == saved.getDepth() + 1" , "clang/lib/AST/ItaniumMangle.cpp", 273, __extension__ __PRETTY_FUNCTION__ )); | |||
| 274 | Bits = saved.Bits; | |||
| 275 | } | |||
| 276 | ||||
| 277 | } FunctionTypeDepth; | |||
| 278 | ||||
| 279 | // abi_tag is a gcc attribute, taking one or more strings called "tags". | |||
| 280 | // The goal is to annotate against which version of a library an object was | |||
| 281 | // built and to be able to provide backwards compatibility ("dual abi"). | |||
| 282 | // For more information see docs/ItaniumMangleAbiTags.rst. | |||
| 283 | typedef SmallVector<StringRef, 4> AbiTagList; | |||
| 284 | ||||
| 285 | // State to gather all implicit and explicit tags used in a mangled name. | |||
| 286 | // Must always have an instance of this while emitting any name to keep | |||
| 287 | // track. | |||
| 288 | class AbiTagState final { | |||
| 289 | public: | |||
| 290 | explicit AbiTagState(AbiTagState *&Head) : LinkHead(Head) { | |||
| 291 | Parent = LinkHead; | |||
| 292 | LinkHead = this; | |||
| 293 | } | |||
| 294 | ||||
| 295 | // No copy, no move. | |||
| 296 | AbiTagState(const AbiTagState &) = delete; | |||
| 297 | AbiTagState &operator=(const AbiTagState &) = delete; | |||
| 298 | ||||
| 299 | ~AbiTagState() { pop(); } | |||
| 300 | ||||
| 301 | void write(raw_ostream &Out, const NamedDecl *ND, | |||
| 302 | const AbiTagList *AdditionalAbiTags) { | |||
| 303 | ND = cast<NamedDecl>(ND->getCanonicalDecl()); | |||
| ||||
| 304 | if (!isa<FunctionDecl>(ND) && !isa<VarDecl>(ND)) { | |||
| 305 | assert((static_cast <bool> (!AdditionalAbiTags && "only function and variables need a list of additional abi tags" ) ? void (0) : __assert_fail ("!AdditionalAbiTags && \"only function and variables need a list of additional abi tags\"" , "clang/lib/AST/ItaniumMangle.cpp", 307, __extension__ __PRETTY_FUNCTION__ )) | |||
| 306 | !AdditionalAbiTags &&(static_cast <bool> (!AdditionalAbiTags && "only function and variables need a list of additional abi tags" ) ? void (0) : __assert_fail ("!AdditionalAbiTags && \"only function and variables need a list of additional abi tags\"" , "clang/lib/AST/ItaniumMangle.cpp", 307, __extension__ __PRETTY_FUNCTION__ )) | |||
| 307 | "only function and variables need a list of additional abi tags")(static_cast <bool> (!AdditionalAbiTags && "only function and variables need a list of additional abi tags" ) ? void (0) : __assert_fail ("!AdditionalAbiTags && \"only function and variables need a list of additional abi tags\"" , "clang/lib/AST/ItaniumMangle.cpp", 307, __extension__ __PRETTY_FUNCTION__ )); | |||
| 308 | if (const auto *NS = dyn_cast<NamespaceDecl>(ND)) { | |||
| 309 | if (const auto *AbiTag = NS->getAttr<AbiTagAttr>()) { | |||
| 310 | UsedAbiTags.insert(UsedAbiTags.end(), AbiTag->tags().begin(), | |||
| 311 | AbiTag->tags().end()); | |||
| 312 | } | |||
| 313 | // Don't emit abi tags for namespaces. | |||
| 314 | return; | |||
| 315 | } | |||
| 316 | } | |||
| 317 | ||||
| 318 | AbiTagList TagList; | |||
| 319 | if (const auto *AbiTag = ND->getAttr<AbiTagAttr>()) { | |||
| 320 | UsedAbiTags.insert(UsedAbiTags.end(), AbiTag->tags().begin(), | |||
| 321 | AbiTag->tags().end()); | |||
| 322 | TagList.insert(TagList.end(), AbiTag->tags().begin(), | |||
| 323 | AbiTag->tags().end()); | |||
| 324 | } | |||
| 325 | ||||
| 326 | if (AdditionalAbiTags) { | |||
| 327 | UsedAbiTags.insert(UsedAbiTags.end(), AdditionalAbiTags->begin(), | |||
| 328 | AdditionalAbiTags->end()); | |||
| 329 | TagList.insert(TagList.end(), AdditionalAbiTags->begin(), | |||
| 330 | AdditionalAbiTags->end()); | |||
| 331 | } | |||
| 332 | ||||
| 333 | llvm::sort(TagList); | |||
| 334 | TagList.erase(std::unique(TagList.begin(), TagList.end()), TagList.end()); | |||
| 335 | ||||
| 336 | writeSortedUniqueAbiTags(Out, TagList); | |||
| 337 | } | |||
| 338 | ||||
| 339 | const AbiTagList &getUsedAbiTags() const { return UsedAbiTags; } | |||
| 340 | void setUsedAbiTags(const AbiTagList &AbiTags) { | |||
| 341 | UsedAbiTags = AbiTags; | |||
| 342 | } | |||
| 343 | ||||
| 344 | const AbiTagList &getEmittedAbiTags() const { | |||
| 345 | return EmittedAbiTags; | |||
| 346 | } | |||
| 347 | ||||
| 348 | const AbiTagList &getSortedUniqueUsedAbiTags() { | |||
| 349 | llvm::sort(UsedAbiTags); | |||
| 350 | UsedAbiTags.erase(std::unique(UsedAbiTags.begin(), UsedAbiTags.end()), | |||
| 351 | UsedAbiTags.end()); | |||
| 352 | return UsedAbiTags; | |||
| 353 | } | |||
| 354 | ||||
| 355 | private: | |||
| 356 | //! All abi tags used implicitly or explicitly. | |||
| 357 | AbiTagList UsedAbiTags; | |||
| 358 | //! All explicit abi tags (i.e. not from namespace). | |||
| 359 | AbiTagList EmittedAbiTags; | |||
| 360 | ||||
| 361 | AbiTagState *&LinkHead; | |||
| 362 | AbiTagState *Parent = nullptr; | |||
| 363 | ||||
| 364 | void pop() { | |||
| 365 | assert(LinkHead == this &&(static_cast <bool> (LinkHead == this && "abi tag link head must point to us on destruction" ) ? void (0) : __assert_fail ("LinkHead == this && \"abi tag link head must point to us on destruction\"" , "clang/lib/AST/ItaniumMangle.cpp", 366, __extension__ __PRETTY_FUNCTION__ )) | |||
| 366 | "abi tag link head must point to us on destruction")(static_cast <bool> (LinkHead == this && "abi tag link head must point to us on destruction" ) ? void (0) : __assert_fail ("LinkHead == this && \"abi tag link head must point to us on destruction\"" , "clang/lib/AST/ItaniumMangle.cpp", 366, __extension__ __PRETTY_FUNCTION__ )); | |||
| 367 | if (Parent) { | |||
| 368 | Parent->UsedAbiTags.insert(Parent->UsedAbiTags.end(), | |||
| 369 | UsedAbiTags.begin(), UsedAbiTags.end()); | |||
| 370 | Parent->EmittedAbiTags.insert(Parent->EmittedAbiTags.end(), | |||
| 371 | EmittedAbiTags.begin(), | |||
| 372 | EmittedAbiTags.end()); | |||
| 373 | } | |||
| 374 | LinkHead = Parent; | |||
| 375 | } | |||
| 376 | ||||
| 377 | void writeSortedUniqueAbiTags(raw_ostream &Out, const AbiTagList &AbiTags) { | |||
| 378 | for (const auto &Tag : AbiTags) { | |||
| 379 | EmittedAbiTags.push_back(Tag); | |||
| 380 | Out << "B"; | |||
| 381 | Out << Tag.size(); | |||
| 382 | Out << Tag; | |||
| 383 | } | |||
| 384 | } | |||
| 385 | }; | |||
| 386 | ||||
| 387 | AbiTagState *AbiTags = nullptr; | |||
| 388 | AbiTagState AbiTagsRoot; | |||
| 389 | ||||
| 390 | llvm::DenseMap<uintptr_t, unsigned> Substitutions; | |||
| 391 | llvm::DenseMap<StringRef, unsigned> ModuleSubstitutions; | |||
| 392 | ||||
| 393 | ASTContext &getASTContext() const { return Context.getASTContext(); } | |||
| 394 | ||||
| 395 | bool isStd(const NamespaceDecl *NS); | |||
| 396 | bool isStdNamespace(const DeclContext *DC); | |||
| 397 | ||||
| 398 | const RecordDecl *GetLocalClassDecl(const Decl *D); | |||
| 399 | const DeclContext *IgnoreLinkageSpecDecls(const DeclContext *DC); | |||
| 400 | bool isSpecializedAs(QualType S, llvm::StringRef Name, QualType A); | |||
| 401 | bool isStdCharSpecialization(const ClassTemplateSpecializationDecl *SD, | |||
| 402 | llvm::StringRef Name, bool HasAllocator); | |||
| 403 | ||||
| 404 | public: | |||
| 405 | CXXNameMangler(ItaniumMangleContextImpl &C, raw_ostream &Out_, | |||
| 406 | const NamedDecl *D = nullptr, bool NullOut_ = false) | |||
| 407 | : Context(C), Out(Out_), NullOut(NullOut_), Structor(getStructor(D)), | |||
| 408 | AbiTagsRoot(AbiTags) { | |||
| 409 | // These can't be mangled without a ctor type or dtor type. | |||
| 410 | assert(!D || (!isa<CXXDestructorDecl>(D) &&(static_cast <bool> (!D || (!isa<CXXDestructorDecl> (D) && !isa<CXXConstructorDecl>(D))) ? void (0) : __assert_fail ("!D || (!isa<CXXDestructorDecl>(D) && !isa<CXXConstructorDecl>(D))" , "clang/lib/AST/ItaniumMangle.cpp", 411, __extension__ __PRETTY_FUNCTION__ )) | |||
| 411 | !isa<CXXConstructorDecl>(D)))(static_cast <bool> (!D || (!isa<CXXDestructorDecl> (D) && !isa<CXXConstructorDecl>(D))) ? void (0) : __assert_fail ("!D || (!isa<CXXDestructorDecl>(D) && !isa<CXXConstructorDecl>(D))" , "clang/lib/AST/ItaniumMangle.cpp", 411, __extension__ __PRETTY_FUNCTION__ )); | |||
| 412 | } | |||
| 413 | CXXNameMangler(ItaniumMangleContextImpl &C, raw_ostream &Out_, | |||
| 414 | const CXXConstructorDecl *D, CXXCtorType Type) | |||
| 415 | : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type), | |||
| 416 | AbiTagsRoot(AbiTags) {} | |||
| 417 | CXXNameMangler(ItaniumMangleContextImpl &C, raw_ostream &Out_, | |||
| 418 | const CXXDestructorDecl *D, CXXDtorType Type) | |||
| 419 | : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type), | |||
| 420 | AbiTagsRoot(AbiTags) {} | |||
| 421 | ||||
| 422 | CXXNameMangler(ItaniumMangleContextImpl &C, raw_ostream &Out_, | |||
| 423 | bool NormalizeIntegers_) | |||
| 424 | : Context(C), Out(Out_), NormalizeIntegers(NormalizeIntegers_), | |||
| 425 | NullOut(false), Structor(nullptr), AbiTagsRoot(AbiTags) {} | |||
| 426 | CXXNameMangler(CXXNameMangler &Outer, raw_ostream &Out_) | |||
| 427 | : Context(Outer.Context), Out(Out_), Structor(Outer.Structor), | |||
| 428 | StructorType(Outer.StructorType), SeqID(Outer.SeqID), | |||
| 429 | FunctionTypeDepth(Outer.FunctionTypeDepth), AbiTagsRoot(AbiTags), | |||
| 430 | Substitutions(Outer.Substitutions), | |||
| 431 | ModuleSubstitutions(Outer.ModuleSubstitutions) {} | |||
| 432 | ||||
| 433 | CXXNameMangler(CXXNameMangler &Outer, llvm::raw_null_ostream &Out_) | |||
| 434 | : CXXNameMangler(Outer, (raw_ostream &)Out_) { | |||
| 435 | NullOut = true; | |||
| 436 | } | |||
| 437 | ||||
| 438 | raw_ostream &getStream() { return Out; } | |||
| 439 | ||||
| 440 | void disableDerivedAbiTags() { DisableDerivedAbiTags = true; } | |||
| 441 | static bool shouldHaveAbiTags(ItaniumMangleContextImpl &C, const VarDecl *VD); | |||
| 442 | ||||
| 443 | void mangle(GlobalDecl GD); | |||
| 444 | void mangleCallOffset(int64_t NonVirtual, int64_t Virtual); | |||
| 445 | void mangleNumber(const llvm::APSInt &I); | |||
| 446 | void mangleNumber(int64_t Number); | |||
| 447 | void mangleFloat(const llvm::APFloat &F); | |||
| 448 | void mangleFunctionEncoding(GlobalDecl GD); | |||
| 449 | void mangleSeqID(unsigned SeqID); | |||
| 450 | void mangleName(GlobalDecl GD); | |||
| 451 | void mangleType(QualType T); | |||
| 452 | void mangleNameOrStandardSubstitution(const NamedDecl *ND); | |||
| 453 | void mangleLambdaSig(const CXXRecordDecl *Lambda); | |||
| 454 | void mangleModuleNamePrefix(StringRef Name, bool IsPartition = false); | |||
| 455 | ||||
| 456 | private: | |||
| 457 | ||||
| 458 | bool mangleSubstitution(const NamedDecl *ND); | |||
| 459 | bool mangleSubstitution(NestedNameSpecifier *NNS); | |||
| 460 | bool mangleSubstitution(QualType T); | |||
| 461 | bool mangleSubstitution(TemplateName Template); | |||
| 462 | bool mangleSubstitution(uintptr_t Ptr); | |||
| 463 | ||||
| 464 | void mangleExistingSubstitution(TemplateName name); | |||
| 465 | ||||
| 466 | bool mangleStandardSubstitution(const NamedDecl *ND); | |||
| 467 | ||||
| 468 | void addSubstitution(const NamedDecl *ND) { | |||
| 469 | ND = cast<NamedDecl>(ND->getCanonicalDecl()); | |||
| 470 | ||||
| 471 | addSubstitution(reinterpret_cast<uintptr_t>(ND)); | |||
| 472 | } | |||
| 473 | void addSubstitution(NestedNameSpecifier *NNS) { | |||
| 474 | NNS = Context.getASTContext().getCanonicalNestedNameSpecifier(NNS); | |||
| 475 | ||||
| 476 | addSubstitution(reinterpret_cast<uintptr_t>(NNS)); | |||
| 477 | } | |||
| 478 | void addSubstitution(QualType T); | |||
| 479 | void addSubstitution(TemplateName Template); | |||
| 480 | void addSubstitution(uintptr_t Ptr); | |||
| 481 | // Destructive copy substitutions from other mangler. | |||
| 482 | void extendSubstitutions(CXXNameMangler* Other); | |||
| 483 | ||||
| 484 | void mangleUnresolvedPrefix(NestedNameSpecifier *qualifier, | |||
| 485 | bool recursive = false); | |||
| 486 | void mangleUnresolvedName(NestedNameSpecifier *qualifier, | |||
| 487 | DeclarationName name, | |||
| 488 | const TemplateArgumentLoc *TemplateArgs, | |||
| 489 | unsigned NumTemplateArgs, | |||
| 490 | unsigned KnownArity = UnknownArity); | |||
| 491 | ||||
| 492 | void mangleFunctionEncodingBareType(const FunctionDecl *FD); | |||
| 493 | ||||
| 494 | void mangleNameWithAbiTags(GlobalDecl GD, | |||
| 495 | const AbiTagList *AdditionalAbiTags); | |||
| 496 | void mangleModuleName(const NamedDecl *ND); | |||
| 497 | void mangleTemplateName(const TemplateDecl *TD, | |||
| 498 | ArrayRef<TemplateArgument> Args); | |||
| 499 | void mangleUnqualifiedName(GlobalDecl GD, const DeclContext *DC, | |||
| 500 | const AbiTagList *AdditionalAbiTags) { | |||
| 501 | mangleUnqualifiedName(GD, cast<NamedDecl>(GD.getDecl())->getDeclName(), DC, | |||
| 502 | UnknownArity, AdditionalAbiTags); | |||
| 503 | } | |||
| 504 | void mangleUnqualifiedName(GlobalDecl GD, DeclarationName Name, | |||
| 505 | const DeclContext *DC, unsigned KnownArity, | |||
| 506 | const AbiTagList *AdditionalAbiTags); | |||
| 507 | void mangleUnscopedName(GlobalDecl GD, const DeclContext *DC, | |||
| 508 | const AbiTagList *AdditionalAbiTags); | |||
| 509 | void mangleUnscopedTemplateName(GlobalDecl GD, const DeclContext *DC, | |||
| 510 | const AbiTagList *AdditionalAbiTags); | |||
| 511 | void mangleSourceName(const IdentifierInfo *II); | |||
| 512 | void mangleRegCallName(const IdentifierInfo *II); | |||
| 513 | void mangleDeviceStubName(const IdentifierInfo *II); | |||
| 514 | void mangleSourceNameWithAbiTags( | |||
| 515 | const NamedDecl *ND, const AbiTagList *AdditionalAbiTags = nullptr); | |||
| 516 | void mangleLocalName(GlobalDecl GD, | |||
| 517 | const AbiTagList *AdditionalAbiTags); | |||
| 518 | void mangleBlockForPrefix(const BlockDecl *Block); | |||
| 519 | void mangleUnqualifiedBlock(const BlockDecl *Block); | |||
| 520 | void mangleTemplateParamDecl(const NamedDecl *Decl); | |||
| 521 | void mangleLambda(const CXXRecordDecl *Lambda); | |||
| 522 | void mangleNestedName(GlobalDecl GD, const DeclContext *DC, | |||
| 523 | const AbiTagList *AdditionalAbiTags, | |||
| 524 | bool NoFunction=false); | |||
| 525 | void mangleNestedName(const TemplateDecl *TD, | |||
| 526 | ArrayRef<TemplateArgument> Args); | |||
| 527 | void mangleNestedNameWithClosurePrefix(GlobalDecl GD, | |||
| 528 | const NamedDecl *PrefixND, | |||
| 529 | const AbiTagList *AdditionalAbiTags); | |||
| 530 | void manglePrefix(NestedNameSpecifier *qualifier); | |||
| 531 | void manglePrefix(const DeclContext *DC, bool NoFunction=false); | |||
| 532 | void manglePrefix(QualType type); | |||
| 533 | void mangleTemplatePrefix(GlobalDecl GD, bool NoFunction=false); | |||
| 534 | void mangleTemplatePrefix(TemplateName Template); | |||
| 535 | const NamedDecl *getClosurePrefix(const Decl *ND); | |||
| 536 | void mangleClosurePrefix(const NamedDecl *ND, bool NoFunction = false); | |||
| 537 | bool mangleUnresolvedTypeOrSimpleId(QualType DestroyedType, | |||
| 538 | StringRef Prefix = ""); | |||
| 539 | void mangleOperatorName(DeclarationName Name, unsigned Arity); | |||
| 540 | void mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity); | |||
| 541 | void mangleVendorQualifier(StringRef qualifier); | |||
| 542 | void mangleQualifiers(Qualifiers Quals, const DependentAddressSpaceType *DAST = nullptr); | |||
| 543 | void mangleRefQualifier(RefQualifierKind RefQualifier); | |||
| 544 | ||||
| 545 | void mangleObjCMethodName(const ObjCMethodDecl *MD); | |||
| 546 | ||||
| 547 | // Declare manglers for every type class. | |||
| 548 | #define ABSTRACT_TYPE(CLASS, PARENT) | |||
| 549 | #define NON_CANONICAL_TYPE(CLASS, PARENT) | |||
| 550 | #define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T); | |||
| 551 | #include "clang/AST/TypeNodes.inc" | |||
| 552 | ||||
| 553 | void mangleType(const TagType*); | |||
| 554 | void mangleType(TemplateName); | |||
| 555 | static StringRef getCallingConvQualifierName(CallingConv CC); | |||
| 556 | void mangleExtParameterInfo(FunctionProtoType::ExtParameterInfo info); | |||
| 557 | void mangleExtFunctionInfo(const FunctionType *T); | |||
| 558 | void mangleBareFunctionType(const FunctionProtoType *T, bool MangleReturnType, | |||
| 559 | const FunctionDecl *FD = nullptr); | |||
| 560 | void mangleNeonVectorType(const VectorType *T); | |||
| 561 | void mangleNeonVectorType(const DependentVectorType *T); | |||
| 562 | void mangleAArch64NeonVectorType(const VectorType *T); | |||
| 563 | void mangleAArch64NeonVectorType(const DependentVectorType *T); | |||
| 564 | void mangleAArch64FixedSveVectorType(const VectorType *T); | |||
| 565 | void mangleAArch64FixedSveVectorType(const DependentVectorType *T); | |||
| 566 | void mangleRISCVFixedRVVVectorType(const VectorType *T); | |||
| 567 | void mangleRISCVFixedRVVVectorType(const DependentVectorType *T); | |||
| 568 | ||||
| 569 | void mangleIntegerLiteral(QualType T, const llvm::APSInt &Value); | |||
| 570 | void mangleFloatLiteral(QualType T, const llvm::APFloat &V); | |||
| 571 | void mangleFixedPointLiteral(); | |||
| 572 | void mangleNullPointer(QualType T); | |||
| 573 | ||||
| 574 | void mangleMemberExprBase(const Expr *base, bool isArrow); | |||
| 575 | void mangleMemberExpr(const Expr *base, bool isArrow, | |||
| 576 | NestedNameSpecifier *qualifier, | |||
| 577 | NamedDecl *firstQualifierLookup, | |||
| 578 | DeclarationName name, | |||
| 579 | const TemplateArgumentLoc *TemplateArgs, | |||
| 580 | unsigned NumTemplateArgs, | |||
| 581 | unsigned knownArity); | |||
| 582 | void mangleCastExpression(const Expr *E, StringRef CastEncoding); | |||
| 583 | void mangleInitListElements(const InitListExpr *InitList); | |||
| 584 | void mangleExpression(const Expr *E, unsigned Arity = UnknownArity, | |||
| 585 | bool AsTemplateArg = false); | |||
| 586 | void mangleCXXCtorType(CXXCtorType T, const CXXRecordDecl *InheritedFrom); | |||
| 587 | void mangleCXXDtorType(CXXDtorType T); | |||
| 588 | ||||
| 589 | void mangleTemplateArgs(TemplateName TN, | |||
| 590 | const TemplateArgumentLoc *TemplateArgs, | |||
| 591 | unsigned NumTemplateArgs); | |||
| 592 | void mangleTemplateArgs(TemplateName TN, ArrayRef<TemplateArgument> Args); | |||
| 593 | void mangleTemplateArgs(TemplateName TN, const TemplateArgumentList &AL); | |||
| 594 | void mangleTemplateArg(TemplateArgument A, bool NeedExactType); | |||
| 595 | void mangleTemplateArgExpr(const Expr *E); | |||
| 596 | void mangleValueInTemplateArg(QualType T, const APValue &V, bool TopLevel, | |||
| 597 | bool NeedExactType = false); | |||
| 598 | ||||
| 599 | void mangleTemplateParameter(unsigned Depth, unsigned Index); | |||
| 600 | ||||
| 601 | void mangleFunctionParam(const ParmVarDecl *parm); | |||
| 602 | ||||
| 603 | void writeAbiTags(const NamedDecl *ND, | |||
| 604 | const AbiTagList *AdditionalAbiTags); | |||
| 605 | ||||
| 606 | // Returns sorted unique list of ABI tags. | |||
| 607 | AbiTagList makeFunctionReturnTypeTags(const FunctionDecl *FD); | |||
| 608 | // Returns sorted unique list of ABI tags. | |||
| 609 | AbiTagList makeVariableTypeTags(const VarDecl *VD); | |||
| 610 | }; | |||
| 611 | ||||
| 612 | } | |||
| 613 | ||||
| 614 | NamespaceDecl *ItaniumMangleContextImpl::getStdNamespace() { | |||
| 615 | if (!StdNamespace) { | |||
| 616 | StdNamespace = NamespaceDecl::Create( | |||
| 617 | getASTContext(), getASTContext().getTranslationUnitDecl(), | |||
| 618 | /*Inline=*/false, SourceLocation(), SourceLocation(), | |||
| 619 | &getASTContext().Idents.get("std"), | |||
| 620 | /*PrevDecl=*/nullptr, /*Nested=*/false); | |||
| 621 | StdNamespace->setImplicit(); | |||
| 622 | } | |||
| 623 | return StdNamespace; | |||
| 624 | } | |||
| 625 | ||||
| 626 | /// Retrieve the declaration context that should be used when mangling the given | |||
| 627 | /// declaration. | |||
| 628 | const DeclContext * | |||
| 629 | ItaniumMangleContextImpl::getEffectiveDeclContext(const Decl *D) { | |||
| 630 | // The ABI assumes that lambda closure types that occur within | |||
| 631 | // default arguments live in the context of the function. However, due to | |||
| 632 | // the way in which Clang parses and creates function declarations, this is | |||
| 633 | // not the case: the lambda closure type ends up living in the context | |||
| 634 | // where the function itself resides, because the function declaration itself | |||
| 635 | // had not yet been created. Fix the context here. | |||
| 636 | if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { | |||
| 637 | if (RD->isLambda()) | |||
| 638 | if (ParmVarDecl *ContextParam = | |||
| 639 | dyn_cast_or_null<ParmVarDecl>(RD->getLambdaContextDecl())) | |||
| 640 | return ContextParam->getDeclContext(); | |||
| 641 | } | |||
| 642 | ||||
| 643 | // Perform the same check for block literals. | |||
| 644 | if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) { | |||
| 645 | if (ParmVarDecl *ContextParam = | |||
| 646 | dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl())) | |||
| 647 | return ContextParam->getDeclContext(); | |||
| 648 | } | |||
| 649 | ||||
| 650 | // On ARM and AArch64, the va_list tag is always mangled as if in the std | |||
| 651 | // namespace. We do not represent va_list as actually being in the std | |||
| 652 | // namespace in C because this would result in incorrect debug info in C, | |||
| 653 | // among other things. It is important for both languages to have the same | |||
| 654 | // mangling in order for -fsanitize=cfi-icall to work. | |||
| 655 | if (D == getASTContext().getVaListTagDecl()) { | |||
| 656 | const llvm::Triple &T = getASTContext().getTargetInfo().getTriple(); | |||
| 657 | if (T.isARM() || T.isThumb() || T.isAArch64()) | |||
| 658 | return getStdNamespace(); | |||
| 659 | } | |||
| 660 | ||||
| 661 | const DeclContext *DC = D->getDeclContext(); | |||
| 662 | if (isa<CapturedDecl>(DC) || isa<OMPDeclareReductionDecl>(DC) || | |||
| 663 | isa<OMPDeclareMapperDecl>(DC)) { | |||
| 664 | return getEffectiveDeclContext(cast<Decl>(DC)); | |||
| 665 | } | |||
| 666 | ||||
| 667 | if (const auto *VD = dyn_cast<VarDecl>(D)) | |||
| 668 | if (VD->isExternC()) | |||
| 669 | return getASTContext().getTranslationUnitDecl(); | |||
| 670 | ||||
| 671 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) | |||
| 672 | if (FD->isExternC()) | |||
| 673 | return getASTContext().getTranslationUnitDecl(); | |||
| 674 | ||||
| 675 | return DC->getRedeclContext(); | |||
| 676 | } | |||
| 677 | ||||
| 678 | bool ItaniumMangleContextImpl::isInternalLinkageDecl(const NamedDecl *ND) { | |||
| 679 | if (ND && ND->getFormalLinkage() == InternalLinkage && | |||
| 680 | !ND->isExternallyVisible() && | |||
| 681 | getEffectiveDeclContext(ND)->isFileContext() && | |||
| 682 | !ND->isInAnonymousNamespace()) | |||
| 683 | return true; | |||
| 684 | return false; | |||
| 685 | } | |||
| 686 | ||||
| 687 | // Check if this Function Decl needs a unique internal linkage name. | |||
| 688 | bool ItaniumMangleContextImpl::isUniqueInternalLinkageDecl( | |||
| 689 | const NamedDecl *ND) { | |||
| 690 | if (!NeedsUniqueInternalLinkageNames || !ND) | |||
| 691 | return false; | |||
| 692 | ||||
| 693 | const auto *FD = dyn_cast<FunctionDecl>(ND); | |||
| 694 | if (!FD) | |||
| 695 | return false; | |||
| 696 | ||||
| 697 | // For C functions without prototypes, return false as their | |||
| 698 | // names should not be mangled. | |||
| 699 | if (!FD->getType()->getAs<FunctionProtoType>()) | |||
| 700 | return false; | |||
| 701 | ||||
| 702 | if (isInternalLinkageDecl(ND)) | |||
| 703 | return true; | |||
| 704 | ||||
| 705 | return false; | |||
| 706 | } | |||
| 707 | ||||
| 708 | bool ItaniumMangleContextImpl::shouldMangleCXXName(const NamedDecl *D) { | |||
| 709 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) { | |||
| 710 | LanguageLinkage L = FD->getLanguageLinkage(); | |||
| 711 | // Overloadable functions need mangling. | |||
| 712 | if (FD->hasAttr<OverloadableAttr>()) | |||
| 713 | return true; | |||
| 714 | ||||
| 715 | // "main" is not mangled. | |||
| 716 | if (FD->isMain()) | |||
| 717 | return false; | |||
| 718 | ||||
| 719 | // The Windows ABI expects that we would never mangle "typical" | |||
| 720 | // user-defined entry points regardless of visibility or freestanding-ness. | |||
| 721 | // | |||
| 722 | // N.B. This is distinct from asking about "main". "main" has a lot of | |||
| 723 | // special rules associated with it in the standard while these | |||
| 724 | // user-defined entry points are outside of the purview of the standard. | |||
| 725 | // For example, there can be only one definition for "main" in a standards | |||
| 726 | // compliant program; however nothing forbids the existence of wmain and | |||
| 727 | // WinMain in the same translation unit. | |||
| 728 | if (FD->isMSVCRTEntryPoint()) | |||
| 729 | return false; | |||
| 730 | ||||
| 731 | // C++ functions and those whose names are not a simple identifier need | |||
| 732 | // mangling. | |||
| 733 | if (!FD->getDeclName().isIdentifier() || L == CXXLanguageLinkage) | |||
| 734 | return true; | |||
| 735 | ||||
| 736 | // C functions are not mangled. | |||
| 737 | if (L == CLanguageLinkage) | |||
| 738 | return false; | |||
| 739 | } | |||
| 740 | ||||
| 741 | // Otherwise, no mangling is done outside C++ mode. | |||
| 742 | if (!getASTContext().getLangOpts().CPlusPlus) | |||
| 743 | return false; | |||
| 744 | ||||
| 745 | if (const auto *VD = dyn_cast<VarDecl>(D)) { | |||
| 746 | // Decompositions are mangled. | |||
| 747 | if (isa<DecompositionDecl>(VD)) | |||
| 748 | return true; | |||
| 749 | ||||
| 750 | // C variables are not mangled. | |||
| 751 | if (VD->isExternC()) | |||
| 752 | return false; | |||
| 753 | ||||
| 754 | // Variables at global scope are not mangled unless they have internal | |||
| 755 | // linkage or are specializations or are attached to a named module. | |||
| 756 | const DeclContext *DC = getEffectiveDeclContext(D); | |||
| 757 | // Check for extern variable declared locally. | |||
| 758 | if (DC->isFunctionOrMethod() && D->hasLinkage()) | |||
| 759 | while (!DC->isFileContext()) | |||
| 760 | DC = getEffectiveParentContext(DC); | |||
| 761 | if (DC->isTranslationUnit() && D->getFormalLinkage() != InternalLinkage && | |||
| 762 | !CXXNameMangler::shouldHaveAbiTags(*this, VD) && | |||
| 763 | !isa<VarTemplateSpecializationDecl>(VD) && | |||
| 764 | !VD->getOwningModuleForLinkage()) | |||
| 765 | return false; | |||
| 766 | } | |||
| 767 | ||||
| 768 | return true; | |||
| 769 | } | |||
| 770 | ||||
| 771 | void CXXNameMangler::writeAbiTags(const NamedDecl *ND, | |||
| 772 | const AbiTagList *AdditionalAbiTags) { | |||
| 773 | assert(AbiTags && "require AbiTagState")(static_cast <bool> (AbiTags && "require AbiTagState" ) ? void (0) : __assert_fail ("AbiTags && \"require AbiTagState\"" , "clang/lib/AST/ItaniumMangle.cpp", 773, __extension__ __PRETTY_FUNCTION__ )); | |||
| 774 | AbiTags->write(Out, ND, DisableDerivedAbiTags ? nullptr : AdditionalAbiTags); | |||
| 775 | } | |||
| 776 | ||||
| 777 | void CXXNameMangler::mangleSourceNameWithAbiTags( | |||
| 778 | const NamedDecl *ND, const AbiTagList *AdditionalAbiTags) { | |||
| 779 | mangleSourceName(ND->getIdentifier()); | |||
| 780 | writeAbiTags(ND, AdditionalAbiTags); | |||
| 781 | } | |||
| 782 | ||||
| 783 | void CXXNameMangler::mangle(GlobalDecl GD) { | |||
| 784 | // <mangled-name> ::= _Z <encoding> | |||
| 785 | // ::= <data name> | |||
| 786 | // ::= <special-name> | |||
| 787 | Out << "_Z"; | |||
| 788 | if (isa<FunctionDecl>(GD.getDecl())) | |||
| 789 | mangleFunctionEncoding(GD); | |||
| 790 | else if (isa<VarDecl, FieldDecl, MSGuidDecl, TemplateParamObjectDecl, | |||
| 791 | BindingDecl>(GD.getDecl())) | |||
| 792 | mangleName(GD); | |||
| 793 | else if (const IndirectFieldDecl *IFD = | |||
| 794 | dyn_cast<IndirectFieldDecl>(GD.getDecl())) | |||
| 795 | mangleName(IFD->getAnonField()); | |||
| 796 | else | |||
| 797 | llvm_unreachable("unexpected kind of global decl")::llvm::llvm_unreachable_internal("unexpected kind of global decl" , "clang/lib/AST/ItaniumMangle.cpp", 797); | |||
| 798 | } | |||
| 799 | ||||
| 800 | void CXXNameMangler::mangleFunctionEncoding(GlobalDecl GD) { | |||
| 801 | const FunctionDecl *FD = cast<FunctionDecl>(GD.getDecl()); | |||
| 802 | // <encoding> ::= <function name> <bare-function-type> | |||
| 803 | ||||
| 804 | // Don't mangle in the type if this isn't a decl we should typically mangle. | |||
| 805 | if (!Context.shouldMangleDeclName(FD)) { | |||
| 806 | mangleName(GD); | |||
| 807 | return; | |||
| 808 | } | |||
| 809 | ||||
| 810 | AbiTagList ReturnTypeAbiTags = makeFunctionReturnTypeTags(FD); | |||
| 811 | if (ReturnTypeAbiTags.empty()) { | |||
| 812 | // There are no tags for return type, the simplest case. | |||
| 813 | mangleName(GD); | |||
| 814 | mangleFunctionEncodingBareType(FD); | |||
| 815 | return; | |||
| 816 | } | |||
| 817 | ||||
| 818 | // Mangle function name and encoding to temporary buffer. | |||
| 819 | // We have to output name and encoding to the same mangler to get the same | |||
| 820 | // substitution as it will be in final mangling. | |||
| 821 | SmallString<256> FunctionEncodingBuf; | |||
| 822 | llvm::raw_svector_ostream FunctionEncodingStream(FunctionEncodingBuf); | |||
| 823 | CXXNameMangler FunctionEncodingMangler(*this, FunctionEncodingStream); | |||
| 824 | // Output name of the function. | |||
| 825 | FunctionEncodingMangler.disableDerivedAbiTags(); | |||
| 826 | FunctionEncodingMangler.mangleNameWithAbiTags(FD, nullptr); | |||
| 827 | ||||
| 828 | // Remember length of the function name in the buffer. | |||
| 829 | size_t EncodingPositionStart = FunctionEncodingStream.str().size(); | |||
| 830 | FunctionEncodingMangler.mangleFunctionEncodingBareType(FD); | |||
| 831 | ||||
| 832 | // Get tags from return type that are not present in function name or | |||
| 833 | // encoding. | |||
| 834 | const AbiTagList &UsedAbiTags = | |||
| 835 | FunctionEncodingMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags(); | |||
| 836 | AbiTagList AdditionalAbiTags(ReturnTypeAbiTags.size()); | |||
| 837 | AdditionalAbiTags.erase( | |||
| 838 | std::set_difference(ReturnTypeAbiTags.begin(), ReturnTypeAbiTags.end(), | |||
| 839 | UsedAbiTags.begin(), UsedAbiTags.end(), | |||
| 840 | AdditionalAbiTags.begin()), | |||
| 841 | AdditionalAbiTags.end()); | |||
| 842 | ||||
| 843 | // Output name with implicit tags and function encoding from temporary buffer. | |||
| 844 | mangleNameWithAbiTags(FD, &AdditionalAbiTags); | |||
| 845 | Out << FunctionEncodingStream.str().substr(EncodingPositionStart); | |||
| 846 | ||||
| 847 | // Function encoding could create new substitutions so we have to add | |||
| 848 | // temp mangled substitutions to main mangler. | |||
| 849 | extendSubstitutions(&FunctionEncodingMangler); | |||
| 850 | } | |||
| 851 | ||||
| 852 | void CXXNameMangler::mangleFunctionEncodingBareType(const FunctionDecl *FD) { | |||
| 853 | if (FD->hasAttr<EnableIfAttr>()) { | |||
| 854 | FunctionTypeDepthState Saved = FunctionTypeDepth.push(); | |||
| 855 | Out << "Ua9enable_ifI"; | |||
| 856 | for (AttrVec::const_iterator I = FD->getAttrs().begin(), | |||
| 857 | E = FD->getAttrs().end(); | |||
| 858 | I != E; ++I) { | |||
| 859 | EnableIfAttr *EIA = dyn_cast<EnableIfAttr>(*I); | |||
| 860 | if (!EIA) | |||
| 861 | continue; | |||
| 862 | if (Context.getASTContext().getLangOpts().getClangABICompat() > | |||
| 863 | LangOptions::ClangABI::Ver11) { | |||
| 864 | mangleTemplateArgExpr(EIA->getCond()); | |||
| 865 | } else { | |||
| 866 | // Prior to Clang 12, we hardcoded the X/E around enable-if's argument, | |||
| 867 | // even though <template-arg> should not include an X/E around | |||
| 868 | // <expr-primary>. | |||
| 869 | Out << 'X'; | |||
| 870 | mangleExpression(EIA->getCond()); | |||
| 871 | Out << 'E'; | |||
| 872 | } | |||
| 873 | } | |||
| 874 | Out << 'E'; | |||
| 875 | FunctionTypeDepth.pop(Saved); | |||
| 876 | } | |||
| 877 | ||||
| 878 | // When mangling an inheriting constructor, the bare function type used is | |||
| 879 | // that of the inherited constructor. | |||
| 880 | if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) | |||
| 881 | if (auto Inherited = CD->getInheritedConstructor()) | |||
| 882 | FD = Inherited.getConstructor(); | |||
| 883 | ||||
| 884 | // Whether the mangling of a function type includes the return type depends on | |||
| 885 | // the context and the nature of the function. The rules for deciding whether | |||
| 886 | // the return type is included are: | |||
| 887 | // | |||
| 888 | // 1. Template functions (names or types) have return types encoded, with | |||
| 889 | // the exceptions listed below. | |||
| 890 | // 2. Function types not appearing as part of a function name mangling, | |||
| 891 | // e.g. parameters, pointer types, etc., have return type encoded, with the | |||
| 892 | // exceptions listed below. | |||
| 893 | // 3. Non-template function names do not have return types encoded. | |||
| 894 | // | |||
| 895 | // The exceptions mentioned in (1) and (2) above, for which the return type is | |||
| 896 | // never included, are | |||
| 897 | // 1. Constructors. | |||
| 898 | // 2. Destructors. | |||
| 899 | // 3. Conversion operator functions, e.g. operator int. | |||
| 900 | bool MangleReturnType = false; | |||
| 901 | if (FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate()) { | |||
| 902 | if (!(isa<CXXConstructorDecl>(FD) || isa<CXXDestructorDecl>(FD) || | |||
| 903 | isa<CXXConversionDecl>(FD))) | |||
| 904 | MangleReturnType = true; | |||
| 905 | ||||
| 906 | // Mangle the type of the primary template. | |||
| 907 | FD = PrimaryTemplate->getTemplatedDecl(); | |||
| 908 | } | |||
| 909 | ||||
| 910 | mangleBareFunctionType(FD->getType()->castAs<FunctionProtoType>(), | |||
| 911 | MangleReturnType, FD); | |||
| 912 | } | |||
| 913 | ||||
| 914 | /// Return whether a given namespace is the 'std' namespace. | |||
| 915 | bool CXXNameMangler::isStd(const NamespaceDecl *NS) { | |||
| 916 | if (!Context.getEffectiveParentContext(NS)->isTranslationUnit()) | |||
| 917 | return false; | |||
| 918 | ||||
| 919 | const IdentifierInfo *II = NS->getOriginalNamespace()->getIdentifier(); | |||
| 920 | return II && II->isStr("std"); | |||
| 921 | } | |||
| 922 | ||||
| 923 | // isStdNamespace - Return whether a given decl context is a toplevel 'std' | |||
| 924 | // namespace. | |||
| 925 | bool CXXNameMangler::isStdNamespace(const DeclContext *DC) { | |||
| 926 | if (!DC->isNamespace()) | |||
| 927 | return false; | |||
| 928 | ||||
| 929 | return isStd(cast<NamespaceDecl>(DC)); | |||
| 930 | } | |||
| 931 | ||||
| 932 | static const GlobalDecl | |||
| 933 | isTemplate(GlobalDecl GD, const TemplateArgumentList *&TemplateArgs) { | |||
| 934 | const NamedDecl *ND = cast<NamedDecl>(GD.getDecl()); | |||
| 935 | // Check if we have a function template. | |||
| 936 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) { | |||
| 937 | if (const TemplateDecl *TD = FD->getPrimaryTemplate()) { | |||
| 938 | TemplateArgs = FD->getTemplateSpecializationArgs(); | |||
| 939 | return GD.getWithDecl(TD); | |||
| 940 | } | |||
| 941 | } | |||
| 942 | ||||
| 943 | // Check if we have a class template. | |||
| 944 | if (const ClassTemplateSpecializationDecl *Spec = | |||
| 945 | dyn_cast<ClassTemplateSpecializationDecl>(ND)) { | |||
| 946 | TemplateArgs = &Spec->getTemplateArgs(); | |||
| 947 | return GD.getWithDecl(Spec->getSpecializedTemplate()); | |||
| 948 | } | |||
| 949 | ||||
| 950 | // Check if we have a variable template. | |||
| 951 | if (const VarTemplateSpecializationDecl *Spec = | |||
| 952 | dyn_cast<VarTemplateSpecializationDecl>(ND)) { | |||
| 953 | TemplateArgs = &Spec->getTemplateArgs(); | |||
| 954 | return GD.getWithDecl(Spec->getSpecializedTemplate()); | |||
| 955 | } | |||
| 956 | ||||
| 957 | return GlobalDecl(); | |||
| 958 | } | |||
| 959 | ||||
| 960 | static TemplateName asTemplateName(GlobalDecl GD) { | |||
| 961 | const TemplateDecl *TD = dyn_cast_or_null<TemplateDecl>(GD.getDecl()); | |||
| 962 | return TemplateName(const_cast<TemplateDecl*>(TD)); | |||
| 963 | } | |||
| 964 | ||||
| 965 | void CXXNameMangler::mangleName(GlobalDecl GD) { | |||
| 966 | const NamedDecl *ND = cast<NamedDecl>(GD.getDecl()); | |||
| 967 | if (const VarDecl *VD = dyn_cast<VarDecl>(ND)) { | |||
| 968 | // Variables should have implicit tags from its type. | |||
| 969 | AbiTagList VariableTypeAbiTags = makeVariableTypeTags(VD); | |||
| 970 | if (VariableTypeAbiTags.empty()) { | |||
| 971 | // Simple case no variable type tags. | |||
| 972 | mangleNameWithAbiTags(VD, nullptr); | |||
| 973 | return; | |||
| 974 | } | |||
| 975 | ||||
| 976 | // Mangle variable name to null stream to collect tags. | |||
| 977 | llvm::raw_null_ostream NullOutStream; | |||
| 978 | CXXNameMangler VariableNameMangler(*this, NullOutStream); | |||
| 979 | VariableNameMangler.disableDerivedAbiTags(); | |||
| 980 | VariableNameMangler.mangleNameWithAbiTags(VD, nullptr); | |||
| 981 | ||||
| 982 | // Get tags from variable type that are not present in its name. | |||
| 983 | const AbiTagList &UsedAbiTags = | |||
| 984 | VariableNameMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags(); | |||
| 985 | AbiTagList AdditionalAbiTags(VariableTypeAbiTags.size()); | |||
| 986 | AdditionalAbiTags.erase( | |||
| 987 | std::set_difference(VariableTypeAbiTags.begin(), | |||
| 988 | VariableTypeAbiTags.end(), UsedAbiTags.begin(), | |||
| 989 | UsedAbiTags.end(), AdditionalAbiTags.begin()), | |||
| 990 | AdditionalAbiTags.end()); | |||
| 991 | ||||
| 992 | // Output name with implicit tags. | |||
| 993 | mangleNameWithAbiTags(VD, &AdditionalAbiTags); | |||
| 994 | } else { | |||
| 995 | mangleNameWithAbiTags(GD, nullptr); | |||
| 996 | } | |||
| 997 | } | |||
| 998 | ||||
| 999 | const RecordDecl *CXXNameMangler::GetLocalClassDecl(const Decl *D) { | |||
| 1000 | const DeclContext *DC = Context.getEffectiveDeclContext(D); | |||
| 1001 | while (!DC->isNamespace() && !DC->isTranslationUnit()) { | |||
| 1002 | if (isLocalContainerContext(DC)) | |||
| 1003 | return dyn_cast<RecordDecl>(D); | |||
| 1004 | D = cast<Decl>(DC); | |||
| 1005 | DC = Context.getEffectiveDeclContext(D); | |||
| 1006 | } | |||
| 1007 | return nullptr; | |||
| 1008 | } | |||
| 1009 | ||||
| 1010 | void CXXNameMangler::mangleNameWithAbiTags(GlobalDecl GD, | |||
| 1011 | const AbiTagList *AdditionalAbiTags) { | |||
| 1012 | const NamedDecl *ND = cast<NamedDecl>(GD.getDecl()); | |||
| 1013 | // <name> ::= [<module-name>] <nested-name> | |||
| 1014 | // ::= [<module-name>] <unscoped-name> | |||
| 1015 | // ::= [<module-name>] <unscoped-template-name> <template-args> | |||
| 1016 | // ::= <local-name> | |||
| 1017 | // | |||
| 1018 | const DeclContext *DC = Context.getEffectiveDeclContext(ND); | |||
| 1019 | ||||
| 1020 | // If this is an extern variable declared locally, the relevant DeclContext | |||
| 1021 | // is that of the containing namespace, or the translation unit. | |||
| 1022 | // FIXME: This is a hack; extern variables declared locally should have | |||
| 1023 | // a proper semantic declaration context! | |||
| 1024 | if (isLocalContainerContext(DC) && ND->hasLinkage() && !isLambda(ND)) | |||
| 1025 | while (!DC->isNamespace() && !DC->isTranslationUnit()) | |||
| 1026 | DC = Context.getEffectiveParentContext(DC); | |||
| 1027 | else if (GetLocalClassDecl(ND)) { | |||
| 1028 | mangleLocalName(GD, AdditionalAbiTags); | |||
| 1029 | return; | |||
| 1030 | } | |||
| 1031 | ||||
| 1032 | assert(!isa<LinkageSpecDecl>(DC) && "context cannot be LinkageSpecDecl")(static_cast <bool> (!isa<LinkageSpecDecl>(DC) && "context cannot be LinkageSpecDecl") ? void (0) : __assert_fail ("!isa<LinkageSpecDecl>(DC) && \"context cannot be LinkageSpecDecl\"" , "clang/lib/AST/ItaniumMangle.cpp", 1032, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1033 | ||||
| 1034 | if (isLocalContainerContext(DC)) { | |||
| 1035 | mangleLocalName(GD, AdditionalAbiTags); | |||
| 1036 | return; | |||
| 1037 | } | |||
| 1038 | ||||
| 1039 | // Closures can require a nested-name mangling even if they're semantically | |||
| 1040 | // in the global namespace. | |||
| 1041 | if (const NamedDecl *PrefixND = getClosurePrefix(ND)) { | |||
| 1042 | mangleNestedNameWithClosurePrefix(GD, PrefixND, AdditionalAbiTags); | |||
| 1043 | return; | |||
| 1044 | } | |||
| 1045 | ||||
| 1046 | if (DC->isTranslationUnit() || isStdNamespace(DC)) { | |||
| 1047 | // Check if we have a template. | |||
| 1048 | const TemplateArgumentList *TemplateArgs = nullptr; | |||
| 1049 | if (GlobalDecl TD = isTemplate(GD, TemplateArgs)) { | |||
| 1050 | mangleUnscopedTemplateName(TD, DC, AdditionalAbiTags); | |||
| 1051 | mangleTemplateArgs(asTemplateName(TD), *TemplateArgs); | |||
| 1052 | return; | |||
| 1053 | } | |||
| 1054 | ||||
| 1055 | mangleUnscopedName(GD, DC, AdditionalAbiTags); | |||
| 1056 | return; | |||
| 1057 | } | |||
| 1058 | ||||
| 1059 | mangleNestedName(GD, DC, AdditionalAbiTags); | |||
| 1060 | } | |||
| 1061 | ||||
| 1062 | void CXXNameMangler::mangleModuleName(const NamedDecl *ND) { | |||
| 1063 | if (ND->isExternallyVisible()) | |||
| 1064 | if (Module *M = ND->getOwningModuleForLinkage()) | |||
| 1065 | mangleModuleNamePrefix(M->getPrimaryModuleInterfaceName()); | |||
| 1066 | } | |||
| 1067 | ||||
| 1068 | // <module-name> ::= <module-subname> | |||
| 1069 | // ::= <module-name> <module-subname> | |||
| 1070 | // ::= <substitution> | |||
| 1071 | // <module-subname> ::= W <source-name> | |||
| 1072 | // ::= W P <source-name> | |||
| 1073 | void CXXNameMangler::mangleModuleNamePrefix(StringRef Name, bool IsPartition) { | |||
| 1074 | // <substitution> ::= S <seq-id> _ | |||
| 1075 | auto It = ModuleSubstitutions.find(Name); | |||
| 1076 | if (It != ModuleSubstitutions.end()) { | |||
| 1077 | Out << 'S'; | |||
| 1078 | mangleSeqID(It->second); | |||
| 1079 | return; | |||
| 1080 | } | |||
| 1081 | ||||
| 1082 | // FIXME: Preserve hierarchy in module names rather than flattening | |||
| 1083 | // them to strings; use Module*s as substitution keys. | |||
| 1084 | auto Parts = Name.rsplit('.'); | |||
| 1085 | if (Parts.second.empty()) | |||
| 1086 | Parts.second = Parts.first; | |||
| 1087 | else { | |||
| 1088 | mangleModuleNamePrefix(Parts.first, IsPartition); | |||
| 1089 | IsPartition = false; | |||
| 1090 | } | |||
| 1091 | ||||
| 1092 | Out << 'W'; | |||
| 1093 | if (IsPartition) | |||
| 1094 | Out << 'P'; | |||
| 1095 | Out << Parts.second.size() << Parts.second; | |||
| 1096 | ModuleSubstitutions.insert({Name, SeqID++}); | |||
| 1097 | } | |||
| 1098 | ||||
| 1099 | void CXXNameMangler::mangleTemplateName(const TemplateDecl *TD, | |||
| 1100 | ArrayRef<TemplateArgument> Args) { | |||
| 1101 | const DeclContext *DC = Context.getEffectiveDeclContext(TD); | |||
| 1102 | ||||
| 1103 | if (DC->isTranslationUnit() || isStdNamespace(DC)) { | |||
| 1104 | mangleUnscopedTemplateName(TD, DC, nullptr); | |||
| 1105 | mangleTemplateArgs(asTemplateName(TD), Args); | |||
| 1106 | } else { | |||
| 1107 | mangleNestedName(TD, Args); | |||
| 1108 | } | |||
| 1109 | } | |||
| 1110 | ||||
| 1111 | void CXXNameMangler::mangleUnscopedName(GlobalDecl GD, const DeclContext *DC, | |||
| 1112 | const AbiTagList *AdditionalAbiTags) { | |||
| 1113 | // <unscoped-name> ::= <unqualified-name> | |||
| 1114 | // ::= St <unqualified-name> # ::std:: | |||
| 1115 | ||||
| 1116 | assert(!isa<LinkageSpecDecl>(DC) && "unskipped LinkageSpecDecl")(static_cast <bool> (!isa<LinkageSpecDecl>(DC) && "unskipped LinkageSpecDecl") ? void (0) : __assert_fail ("!isa<LinkageSpecDecl>(DC) && \"unskipped LinkageSpecDecl\"" , "clang/lib/AST/ItaniumMangle.cpp", 1116, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1117 | if (isStdNamespace(DC)) | |||
| 1118 | Out << "St"; | |||
| 1119 | ||||
| 1120 | mangleUnqualifiedName(GD, DC, AdditionalAbiTags); | |||
| 1121 | } | |||
| 1122 | ||||
| 1123 | void CXXNameMangler::mangleUnscopedTemplateName( | |||
| 1124 | GlobalDecl GD, const DeclContext *DC, const AbiTagList *AdditionalAbiTags) { | |||
| 1125 | const TemplateDecl *ND = cast<TemplateDecl>(GD.getDecl()); | |||
| 1126 | // <unscoped-template-name> ::= <unscoped-name> | |||
| 1127 | // ::= <substitution> | |||
| 1128 | if (mangleSubstitution(ND)) | |||
| 1129 | return; | |||
| 1130 | ||||
| 1131 | // <template-template-param> ::= <template-param> | |||
| 1132 | if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) { | |||
| 1133 | assert(!AdditionalAbiTags &&(static_cast <bool> (!AdditionalAbiTags && "template template param cannot have abi tags" ) ? void (0) : __assert_fail ("!AdditionalAbiTags && \"template template param cannot have abi tags\"" , "clang/lib/AST/ItaniumMangle.cpp", 1134, __extension__ __PRETTY_FUNCTION__ )) | |||
| 1134 | "template template param cannot have abi tags")(static_cast <bool> (!AdditionalAbiTags && "template template param cannot have abi tags" ) ? void (0) : __assert_fail ("!AdditionalAbiTags && \"template template param cannot have abi tags\"" , "clang/lib/AST/ItaniumMangle.cpp", 1134, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1135 | mangleTemplateParameter(TTP->getDepth(), TTP->getIndex()); | |||
| 1136 | } else if (isa<BuiltinTemplateDecl>(ND) || isa<ConceptDecl>(ND)) { | |||
| 1137 | mangleUnscopedName(GD, DC, AdditionalAbiTags); | |||
| 1138 | } else { | |||
| 1139 | mangleUnscopedName(GD.getWithDecl(ND->getTemplatedDecl()), DC, | |||
| 1140 | AdditionalAbiTags); | |||
| 1141 | } | |||
| 1142 | ||||
| 1143 | addSubstitution(ND); | |||
| 1144 | } | |||
| 1145 | ||||
| 1146 | void CXXNameMangler::mangleFloat(const llvm::APFloat &f) { | |||
| 1147 | // ABI: | |||
| 1148 | // Floating-point literals are encoded using a fixed-length | |||
| 1149 | // lowercase hexadecimal string corresponding to the internal | |||
| 1150 | // representation (IEEE on Itanium), high-order bytes first, | |||
| 1151 | // without leading zeroes. For example: "Lf bf800000 E" is -1.0f | |||
| 1152 | // on Itanium. | |||
| 1153 | // The 'without leading zeroes' thing seems to be an editorial | |||
| 1154 | // mistake; see the discussion on cxx-abi-dev beginning on | |||
| 1155 | // 2012-01-16. | |||
| 1156 | ||||
| 1157 | // Our requirements here are just barely weird enough to justify | |||
| 1158 | // using a custom algorithm instead of post-processing APInt::toString(). | |||
| 1159 | ||||
| 1160 | llvm::APInt valueBits = f.bitcastToAPInt(); | |||
| 1161 | unsigned numCharacters = (valueBits.getBitWidth() + 3) / 4; | |||
| 1162 | assert(numCharacters != 0)(static_cast <bool> (numCharacters != 0) ? void (0) : __assert_fail ("numCharacters != 0", "clang/lib/AST/ItaniumMangle.cpp", 1162 , __extension__ __PRETTY_FUNCTION__)); | |||
| 1163 | ||||
| 1164 | // Allocate a buffer of the right number of characters. | |||
| 1165 | SmallVector<char, 20> buffer(numCharacters); | |||
| 1166 | ||||
| 1167 | // Fill the buffer left-to-right. | |||
| 1168 | for (unsigned stringIndex = 0; stringIndex != numCharacters; ++stringIndex) { | |||
| 1169 | // The bit-index of the next hex digit. | |||
| 1170 | unsigned digitBitIndex = 4 * (numCharacters - stringIndex - 1); | |||
| 1171 | ||||
| 1172 | // Project out 4 bits starting at 'digitIndex'. | |||
| 1173 | uint64_t hexDigit = valueBits.getRawData()[digitBitIndex / 64]; | |||
| 1174 | hexDigit >>= (digitBitIndex % 64); | |||
| 1175 | hexDigit &= 0xF; | |||
| 1176 | ||||
| 1177 | // Map that over to a lowercase hex digit. | |||
| 1178 | static const char charForHex[16] = { | |||
| 1179 | '0', '1', '2', '3', '4', '5', '6', '7', | |||
| 1180 | '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' | |||
| 1181 | }; | |||
| 1182 | buffer[stringIndex] = charForHex[hexDigit]; | |||
| 1183 | } | |||
| 1184 | ||||
| 1185 | Out.write(buffer.data(), numCharacters); | |||
| 1186 | } | |||
| 1187 | ||||
| 1188 | void CXXNameMangler::mangleFloatLiteral(QualType T, const llvm::APFloat &V) { | |||
| 1189 | Out << 'L'; | |||
| 1190 | mangleType(T); | |||
| 1191 | mangleFloat(V); | |||
| 1192 | Out << 'E'; | |||
| 1193 | } | |||
| 1194 | ||||
| 1195 | void CXXNameMangler::mangleFixedPointLiteral() { | |||
| 1196 | DiagnosticsEngine &Diags = Context.getDiags(); | |||
| 1197 | unsigned DiagID = Diags.getCustomDiagID( | |||
| 1198 | DiagnosticsEngine::Error, "cannot mangle fixed point literals yet"); | |||
| 1199 | Diags.Report(DiagID); | |||
| 1200 | } | |||
| 1201 | ||||
| 1202 | void CXXNameMangler::mangleNullPointer(QualType T) { | |||
| 1203 | // <expr-primary> ::= L <type> 0 E | |||
| 1204 | Out << 'L'; | |||
| 1205 | mangleType(T); | |||
| 1206 | Out << "0E"; | |||
| 1207 | } | |||
| 1208 | ||||
| 1209 | void CXXNameMangler::mangleNumber(const llvm::APSInt &Value) { | |||
| 1210 | if (Value.isSigned() && Value.isNegative()) { | |||
| 1211 | Out << 'n'; | |||
| 1212 | Value.abs().print(Out, /*signed*/ false); | |||
| 1213 | } else { | |||
| 1214 | Value.print(Out, /*signed*/ false); | |||
| 1215 | } | |||
| 1216 | } | |||
| 1217 | ||||
| 1218 | void CXXNameMangler::mangleNumber(int64_t Number) { | |||
| 1219 | // <number> ::= [n] <non-negative decimal integer> | |||
| 1220 | if (Number < 0) { | |||
| 1221 | Out << 'n'; | |||
| 1222 | Number = -Number; | |||
| 1223 | } | |||
| 1224 | ||||
| 1225 | Out << Number; | |||
| 1226 | } | |||
| 1227 | ||||
| 1228 | void CXXNameMangler::mangleCallOffset(int64_t NonVirtual, int64_t Virtual) { | |||
| 1229 | // <call-offset> ::= h <nv-offset> _ | |||
| 1230 | // ::= v <v-offset> _ | |||
| 1231 | // <nv-offset> ::= <offset number> # non-virtual base override | |||
| 1232 | // <v-offset> ::= <offset number> _ <virtual offset number> | |||
| 1233 | // # virtual base override, with vcall offset | |||
| 1234 | if (!Virtual) { | |||
| 1235 | Out << 'h'; | |||
| 1236 | mangleNumber(NonVirtual); | |||
| 1237 | Out << '_'; | |||
| 1238 | return; | |||
| 1239 | } | |||
| 1240 | ||||
| 1241 | Out << 'v'; | |||
| 1242 | mangleNumber(NonVirtual); | |||
| 1243 | Out << '_'; | |||
| 1244 | mangleNumber(Virtual); | |||
| 1245 | Out << '_'; | |||
| 1246 | } | |||
| 1247 | ||||
| 1248 | void CXXNameMangler::manglePrefix(QualType type) { | |||
| 1249 | if (const auto *TST = type->getAs<TemplateSpecializationType>()) { | |||
| 1250 | if (!mangleSubstitution(QualType(TST, 0))) { | |||
| 1251 | mangleTemplatePrefix(TST->getTemplateName()); | |||
| 1252 | ||||
| 1253 | // FIXME: GCC does not appear to mangle the template arguments when | |||
| 1254 | // the template in question is a dependent template name. Should we | |||
| 1255 | // emulate that badness? | |||
| 1256 | mangleTemplateArgs(TST->getTemplateName(), TST->template_arguments()); | |||
| 1257 | addSubstitution(QualType(TST, 0)); | |||
| 1258 | } | |||
| 1259 | } else if (const auto *DTST = | |||
| 1260 | type->getAs<DependentTemplateSpecializationType>()) { | |||
| 1261 | if (!mangleSubstitution(QualType(DTST, 0))) { | |||
| 1262 | TemplateName Template = getASTContext().getDependentTemplateName( | |||
| 1263 | DTST->getQualifier(), DTST->getIdentifier()); | |||
| 1264 | mangleTemplatePrefix(Template); | |||
| 1265 | ||||
| 1266 | // FIXME: GCC does not appear to mangle the template arguments when | |||
| 1267 | // the template in question is a dependent template name. Should we | |||
| 1268 | // emulate that badness? | |||
| 1269 | mangleTemplateArgs(Template, DTST->template_arguments()); | |||
| 1270 | addSubstitution(QualType(DTST, 0)); | |||
| 1271 | } | |||
| 1272 | } else { | |||
| 1273 | // We use the QualType mangle type variant here because it handles | |||
| 1274 | // substitutions. | |||
| 1275 | mangleType(type); | |||
| 1276 | } | |||
| 1277 | } | |||
| 1278 | ||||
| 1279 | /// Mangle everything prior to the base-unresolved-name in an unresolved-name. | |||
| 1280 | /// | |||
| 1281 | /// \param recursive - true if this is being called recursively, | |||
| 1282 | /// i.e. if there is more prefix "to the right". | |||
| 1283 | void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier *qualifier, | |||
| 1284 | bool recursive) { | |||
| 1285 | ||||
| 1286 | // x, ::x | |||
| 1287 | // <unresolved-name> ::= [gs] <base-unresolved-name> | |||
| 1288 | ||||
| 1289 | // T::x / decltype(p)::x | |||
| 1290 | // <unresolved-name> ::= sr <unresolved-type> <base-unresolved-name> | |||
| 1291 | ||||
| 1292 | // T::N::x /decltype(p)::N::x | |||
| 1293 | // <unresolved-name> ::= srN <unresolved-type> <unresolved-qualifier-level>+ E | |||
| 1294 | // <base-unresolved-name> | |||
| 1295 | ||||
| 1296 | // A::x, N::y, A<T>::z; "gs" means leading "::" | |||
| 1297 | // <unresolved-name> ::= [gs] sr <unresolved-qualifier-level>+ E | |||
| 1298 | // <base-unresolved-name> | |||
| 1299 | ||||
| 1300 | switch (qualifier->getKind()) { | |||
| 1301 | case NestedNameSpecifier::Global: | |||
| 1302 | Out << "gs"; | |||
| 1303 | ||||
| 1304 | // We want an 'sr' unless this is the entire NNS. | |||
| 1305 | if (recursive) | |||
| 1306 | Out << "sr"; | |||
| 1307 | ||||
| 1308 | // We never want an 'E' here. | |||
| 1309 | return; | |||
| 1310 | ||||
| 1311 | case NestedNameSpecifier::Super: | |||
| 1312 | llvm_unreachable("Can't mangle __super specifier")::llvm::llvm_unreachable_internal("Can't mangle __super specifier" , "clang/lib/AST/ItaniumMangle.cpp", 1312); | |||
| 1313 | ||||
| 1314 | case NestedNameSpecifier::Namespace: | |||
| 1315 | if (qualifier->getPrefix()) | |||
| 1316 | mangleUnresolvedPrefix(qualifier->getPrefix(), | |||
| 1317 | /*recursive*/ true); | |||
| 1318 | else | |||
| 1319 | Out << "sr"; | |||
| 1320 | mangleSourceNameWithAbiTags(qualifier->getAsNamespace()); | |||
| 1321 | break; | |||
| 1322 | case NestedNameSpecifier::NamespaceAlias: | |||
| 1323 | if (qualifier->getPrefix()) | |||
| 1324 | mangleUnresolvedPrefix(qualifier->getPrefix(), | |||
| 1325 | /*recursive*/ true); | |||
| 1326 | else | |||
| 1327 | Out << "sr"; | |||
| 1328 | mangleSourceNameWithAbiTags(qualifier->getAsNamespaceAlias()); | |||
| 1329 | break; | |||
| 1330 | ||||
| 1331 | case NestedNameSpecifier::TypeSpec: | |||
| 1332 | case NestedNameSpecifier::TypeSpecWithTemplate: { | |||
| 1333 | const Type *type = qualifier->getAsType(); | |||
| 1334 | ||||
| 1335 | // We only want to use an unresolved-type encoding if this is one of: | |||
| 1336 | // - a decltype | |||
| 1337 | // - a template type parameter | |||
| 1338 | // - a template template parameter with arguments | |||
| 1339 | // In all of these cases, we should have no prefix. | |||
| 1340 | if (qualifier->getPrefix()) { | |||
| 1341 | mangleUnresolvedPrefix(qualifier->getPrefix(), | |||
| 1342 | /*recursive*/ true); | |||
| 1343 | } else { | |||
| 1344 | // Otherwise, all the cases want this. | |||
| 1345 | Out << "sr"; | |||
| 1346 | } | |||
| 1347 | ||||
| 1348 | if (mangleUnresolvedTypeOrSimpleId(QualType(type, 0), recursive ? "N" : "")) | |||
| 1349 | return; | |||
| 1350 | ||||
| 1351 | break; | |||
| 1352 | } | |||
| 1353 | ||||
| 1354 | case NestedNameSpecifier::Identifier: | |||
| 1355 | // Member expressions can have these without prefixes. | |||
| 1356 | if (qualifier->getPrefix()) | |||
| 1357 | mangleUnresolvedPrefix(qualifier->getPrefix(), | |||
| 1358 | /*recursive*/ true); | |||
| 1359 | else | |||
| 1360 | Out << "sr"; | |||
| 1361 | ||||
| 1362 | mangleSourceName(qualifier->getAsIdentifier()); | |||
| 1363 | // An Identifier has no type information, so we can't emit abi tags for it. | |||
| 1364 | break; | |||
| 1365 | } | |||
| 1366 | ||||
| 1367 | // If this was the innermost part of the NNS, and we fell out to | |||
| 1368 | // here, append an 'E'. | |||
| 1369 | if (!recursive) | |||
| 1370 | Out << 'E'; | |||
| 1371 | } | |||
| 1372 | ||||
| 1373 | /// Mangle an unresolved-name, which is generally used for names which | |||
| 1374 | /// weren't resolved to specific entities. | |||
| 1375 | void CXXNameMangler::mangleUnresolvedName( | |||
| 1376 | NestedNameSpecifier *qualifier, DeclarationName name, | |||
| 1377 | const TemplateArgumentLoc *TemplateArgs, unsigned NumTemplateArgs, | |||
| 1378 | unsigned knownArity) { | |||
| 1379 | if (qualifier) mangleUnresolvedPrefix(qualifier); | |||
| 1380 | switch (name.getNameKind()) { | |||
| 1381 | // <base-unresolved-name> ::= <simple-id> | |||
| 1382 | case DeclarationName::Identifier: | |||
| 1383 | mangleSourceName(name.getAsIdentifierInfo()); | |||
| 1384 | break; | |||
| 1385 | // <base-unresolved-name> ::= dn <destructor-name> | |||
| 1386 | case DeclarationName::CXXDestructorName: | |||
| 1387 | Out << "dn"; | |||
| 1388 | mangleUnresolvedTypeOrSimpleId(name.getCXXNameType()); | |||
| 1389 | break; | |||
| 1390 | // <base-unresolved-name> ::= on <operator-name> | |||
| 1391 | case DeclarationName::CXXConversionFunctionName: | |||
| 1392 | case DeclarationName::CXXLiteralOperatorName: | |||
| 1393 | case DeclarationName::CXXOperatorName: | |||
| 1394 | Out << "on"; | |||
| 1395 | mangleOperatorName(name, knownArity); | |||
| 1396 | break; | |||
| 1397 | case DeclarationName::CXXConstructorName: | |||
| 1398 | llvm_unreachable("Can't mangle a constructor name!")::llvm::llvm_unreachable_internal("Can't mangle a constructor name!" , "clang/lib/AST/ItaniumMangle.cpp", 1398); | |||
| 1399 | case DeclarationName::CXXUsingDirective: | |||
| 1400 | llvm_unreachable("Can't mangle a using directive name!")::llvm::llvm_unreachable_internal("Can't mangle a using directive name!" , "clang/lib/AST/ItaniumMangle.cpp", 1400); | |||
| 1401 | case DeclarationName::CXXDeductionGuideName: | |||
| 1402 | llvm_unreachable("Can't mangle a deduction guide name!")::llvm::llvm_unreachable_internal("Can't mangle a deduction guide name!" , "clang/lib/AST/ItaniumMangle.cpp", 1402); | |||
| 1403 | case DeclarationName::ObjCMultiArgSelector: | |||
| 1404 | case DeclarationName::ObjCOneArgSelector: | |||
| 1405 | case DeclarationName::ObjCZeroArgSelector: | |||
| 1406 | llvm_unreachable("Can't mangle Objective-C selector names here!")::llvm::llvm_unreachable_internal("Can't mangle Objective-C selector names here!" , "clang/lib/AST/ItaniumMangle.cpp", 1406); | |||
| 1407 | } | |||
| 1408 | ||||
| 1409 | // The <simple-id> and on <operator-name> productions end in an optional | |||
| 1410 | // <template-args>. | |||
| 1411 | if (TemplateArgs) | |||
| 1412 | mangleTemplateArgs(TemplateName(), TemplateArgs, NumTemplateArgs); | |||
| 1413 | } | |||
| 1414 | ||||
| 1415 | void CXXNameMangler::mangleUnqualifiedName( | |||
| 1416 | GlobalDecl GD, DeclarationName Name, const DeclContext *DC, | |||
| 1417 | unsigned KnownArity, const AbiTagList *AdditionalAbiTags) { | |||
| 1418 | const NamedDecl *ND = cast_or_null<NamedDecl>(GD.getDecl()); | |||
| ||||
| 1419 | // <unqualified-name> ::= [<module-name>] <operator-name> | |||
| 1420 | // ::= <ctor-dtor-name> | |||
| 1421 | // ::= [<module-name>] <source-name> | |||
| 1422 | // ::= [<module-name>] DC <source-name>* E | |||
| 1423 | ||||
| 1424 | if (ND
| |||
| 1425 | mangleModuleName(ND); | |||
| 1426 | ||||
| 1427 | unsigned Arity = KnownArity; | |||
| 1428 | switch (Name.getNameKind()) { | |||
| 1429 | case DeclarationName::Identifier: { | |||
| 1430 | const IdentifierInfo *II = Name.getAsIdentifierInfo(); | |||
| 1431 | ||||
| 1432 | // We mangle decomposition declarations as the names of their bindings. | |||
| 1433 | if (auto *DD = dyn_cast<DecompositionDecl>(ND)) { | |||
| 1434 | // FIXME: Non-standard mangling for decomposition declarations: | |||
| 1435 | // | |||
| 1436 | // <unqualified-name> ::= DC <source-name>* E | |||
| 1437 | // | |||
| 1438 | // Proposed on cxx-abi-dev on 2016-08-12 | |||
| 1439 | Out << "DC"; | |||
| 1440 | for (auto *BD : DD->bindings()) | |||
| 1441 | mangleSourceName(BD->getDeclName().getAsIdentifierInfo()); | |||
| 1442 | Out << 'E'; | |||
| 1443 | writeAbiTags(ND, AdditionalAbiTags); | |||
| 1444 | break; | |||
| 1445 | } | |||
| 1446 | ||||
| 1447 | if (auto *GD = dyn_cast<MSGuidDecl>(ND)) { | |||
| 1448 | // We follow MSVC in mangling GUID declarations as if they were variables | |||
| 1449 | // with a particular reserved name. Continue the pretense here. | |||
| 1450 | SmallString<sizeof("_GUID_12345678_1234_1234_1234_1234567890ab")> GUID; | |||
| 1451 | llvm::raw_svector_ostream GUIDOS(GUID); | |||
| 1452 | Context.mangleMSGuidDecl(GD, GUIDOS); | |||
| 1453 | Out << GUID.size() << GUID; | |||
| 1454 | break; | |||
| 1455 | } | |||
| 1456 | ||||
| 1457 | if (auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) { | |||
| 1458 | // Proposed in https://github.com/itanium-cxx-abi/cxx-abi/issues/63. | |||
| 1459 | Out << "TA"; | |||
| 1460 | mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(), | |||
| 1461 | TPO->getValue(), /*TopLevel=*/true); | |||
| 1462 | break; | |||
| 1463 | } | |||
| 1464 | ||||
| 1465 | if (II) { | |||
| 1466 | // Match GCC's naming convention for internal linkage symbols, for | |||
| 1467 | // symbols that are not actually visible outside of this TU. GCC | |||
| 1468 | // distinguishes between internal and external linkage symbols in | |||
| 1469 | // its mangling, to support cases like this that were valid C++ prior | |||
| 1470 | // to DR426: | |||
| 1471 | // | |||
| 1472 | // void test() { extern void foo(); } | |||
| 1473 | // static void foo(); | |||
| 1474 | // | |||
| 1475 | // Don't bother with the L marker for names in anonymous namespaces; the | |||
| 1476 | // 12_GLOBAL__N_1 mangling is quite sufficient there, and this better | |||
| 1477 | // matches GCC anyway, because GCC does not treat anonymous namespaces as | |||
| 1478 | // implying internal linkage. | |||
| 1479 | if (Context.isInternalLinkageDecl(ND)) | |||
| 1480 | Out << 'L'; | |||
| 1481 | ||||
| 1482 | auto *FD = dyn_cast<FunctionDecl>(ND); | |||
| 1483 | bool IsRegCall = FD && | |||
| 1484 | FD->getType()->castAs<FunctionType>()->getCallConv() == | |||
| 1485 | clang::CC_X86RegCall; | |||
| 1486 | bool IsDeviceStub = | |||
| 1487 | FD && FD->hasAttr<CUDAGlobalAttr>() && | |||
| 1488 | GD.getKernelReferenceKind() == KernelReferenceKind::Stub; | |||
| 1489 | if (IsDeviceStub) | |||
| 1490 | mangleDeviceStubName(II); | |||
| 1491 | else if (IsRegCall) | |||
| 1492 | mangleRegCallName(II); | |||
| 1493 | else | |||
| 1494 | mangleSourceName(II); | |||
| 1495 | ||||
| 1496 | writeAbiTags(ND, AdditionalAbiTags); | |||
| 1497 | break; | |||
| 1498 | } | |||
| 1499 | ||||
| 1500 | // Otherwise, an anonymous entity. We must have a declaration. | |||
| 1501 | assert(ND && "mangling empty name without declaration")(static_cast <bool> (ND && "mangling empty name without declaration" ) ? void (0) : __assert_fail ("ND && \"mangling empty name without declaration\"" , "clang/lib/AST/ItaniumMangle.cpp", 1501, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1502 | ||||
| 1503 | if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) { | |||
| 1504 | if (NS->isAnonymousNamespace()) { | |||
| 1505 | // This is how gcc mangles these names. | |||
| 1506 | Out << "12_GLOBAL__N_1"; | |||
| 1507 | break; | |||
| 1508 | } | |||
| 1509 | } | |||
| 1510 | ||||
| 1511 | if (const VarDecl *VD = dyn_cast<VarDecl>(ND)) { | |||
| 1512 | // We must have an anonymous union or struct declaration. | |||
| 1513 | const RecordDecl *RD = VD->getType()->castAs<RecordType>()->getDecl(); | |||
| 1514 | ||||
| 1515 | // Itanium C++ ABI 5.1.2: | |||
| 1516 | // | |||
| 1517 | // For the purposes of mangling, the name of an anonymous union is | |||
| 1518 | // considered to be the name of the first named data member found by a | |||
| 1519 | // pre-order, depth-first, declaration-order walk of the data members of | |||
| 1520 | // the anonymous union. If there is no such data member (i.e., if all of | |||
| 1521 | // the data members in the union are unnamed), then there is no way for | |||
| 1522 | // a program to refer to the anonymous union, and there is therefore no | |||
| 1523 | // need to mangle its name. | |||
| 1524 | assert(RD->isAnonymousStructOrUnion()(static_cast <bool> (RD->isAnonymousStructOrUnion() && "Expected anonymous struct or union!") ? void (0) : __assert_fail ("RD->isAnonymousStructOrUnion() && \"Expected anonymous struct or union!\"" , "clang/lib/AST/ItaniumMangle.cpp", 1525, __extension__ __PRETTY_FUNCTION__ )) | |||
| 1525 | && "Expected anonymous struct or union!")(static_cast <bool> (RD->isAnonymousStructOrUnion() && "Expected anonymous struct or union!") ? void (0) : __assert_fail ("RD->isAnonymousStructOrUnion() && \"Expected anonymous struct or union!\"" , "clang/lib/AST/ItaniumMangle.cpp", 1525, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1526 | const FieldDecl *FD = RD->findFirstNamedDataMember(); | |||
| 1527 | ||||
| 1528 | // It's actually possible for various reasons for us to get here | |||
| 1529 | // with an empty anonymous struct / union. Fortunately, it | |||
| 1530 | // doesn't really matter what name we generate. | |||
| 1531 | if (!FD) break; | |||
| 1532 | assert(FD->getIdentifier() && "Data member name isn't an identifier!")(static_cast <bool> (FD->getIdentifier() && "Data member name isn't an identifier!" ) ? void (0) : __assert_fail ("FD->getIdentifier() && \"Data member name isn't an identifier!\"" , "clang/lib/AST/ItaniumMangle.cpp", 1532, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1533 | ||||
| 1534 | mangleSourceName(FD->getIdentifier()); | |||
| 1535 | // Not emitting abi tags: internal name anyway. | |||
| 1536 | break; | |||
| 1537 | } | |||
| 1538 | ||||
| 1539 | // Class extensions have no name as a category, and it's possible | |||
| 1540 | // for them to be the semantic parent of certain declarations | |||
| 1541 | // (primarily, tag decls defined within declarations). Such | |||
| 1542 | // declarations will always have internal linkage, so the name | |||
| 1543 | // doesn't really matter, but we shouldn't crash on them. For | |||
| 1544 | // safety, just handle all ObjC containers here. | |||
| 1545 | if (isa<ObjCContainerDecl>(ND)) | |||
| 1546 | break; | |||
| 1547 | ||||
| 1548 | // We must have an anonymous struct. | |||
| 1549 | const TagDecl *TD = cast<TagDecl>(ND); | |||
| 1550 | if (const TypedefNameDecl *D = TD->getTypedefNameForAnonDecl()) { | |||
| 1551 | assert(TD->getDeclContext() == D->getDeclContext() &&(static_cast <bool> (TD->getDeclContext() == D->getDeclContext () && "Typedef should not be in another decl context!" ) ? void (0) : __assert_fail ("TD->getDeclContext() == D->getDeclContext() && \"Typedef should not be in another decl context!\"" , "clang/lib/AST/ItaniumMangle.cpp", 1552, __extension__ __PRETTY_FUNCTION__ )) | |||
| 1552 | "Typedef should not be in another decl context!")(static_cast <bool> (TD->getDeclContext() == D->getDeclContext () && "Typedef should not be in another decl context!" ) ? void (0) : __assert_fail ("TD->getDeclContext() == D->getDeclContext() && \"Typedef should not be in another decl context!\"" , "clang/lib/AST/ItaniumMangle.cpp", 1552, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1553 | assert(D->getDeclName().getAsIdentifierInfo() &&(static_cast <bool> (D->getDeclName().getAsIdentifierInfo () && "Typedef was not named!") ? void (0) : __assert_fail ("D->getDeclName().getAsIdentifierInfo() && \"Typedef was not named!\"" , "clang/lib/AST/ItaniumMangle.cpp", 1554, __extension__ __PRETTY_FUNCTION__ )) | |||
| 1554 | "Typedef was not named!")(static_cast <bool> (D->getDeclName().getAsIdentifierInfo () && "Typedef was not named!") ? void (0) : __assert_fail ("D->getDeclName().getAsIdentifierInfo() && \"Typedef was not named!\"" , "clang/lib/AST/ItaniumMangle.cpp", 1554, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1555 | mangleSourceName(D->getDeclName().getAsIdentifierInfo()); | |||
| 1556 | assert(!AdditionalAbiTags && "Type cannot have additional abi tags")(static_cast <bool> (!AdditionalAbiTags && "Type cannot have additional abi tags" ) ? void (0) : __assert_fail ("!AdditionalAbiTags && \"Type cannot have additional abi tags\"" , "clang/lib/AST/ItaniumMangle.cpp", 1556, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1557 | // Explicit abi tags are still possible; take from underlying type, not | |||
| 1558 | // from typedef. | |||
| 1559 | writeAbiTags(TD, nullptr); | |||
| 1560 | break; | |||
| 1561 | } | |||
| 1562 | ||||
| 1563 | // <unnamed-type-name> ::= <closure-type-name> | |||
| 1564 | // | |||
| 1565 | // <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _ | |||
| 1566 | // <lambda-sig> ::= <template-param-decl>* <parameter-type>+ | |||
| 1567 | // # Parameter types or 'v' for 'void'. | |||
| 1568 | if (const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(TD)) { | |||
| 1569 | std::optional<unsigned> DeviceNumber = | |||
| 1570 | Context.getDiscriminatorOverride()(Context.getASTContext(), Record); | |||
| 1571 | ||||
| 1572 | // If we have a device-number via the discriminator, use that to mangle | |||
| 1573 | // the lambda, otherwise use the typical lambda-mangling-number. In either | |||
| 1574 | // case, a '0' should be mangled as a normal unnamed class instead of as a | |||
| 1575 | // lambda. | |||
| 1576 | if (Record->isLambda() && | |||
| 1577 | ((DeviceNumber && *DeviceNumber > 0) || | |||
| 1578 | (!DeviceNumber && Record->getLambdaManglingNumber() > 0))) { | |||
| 1579 | assert(!AdditionalAbiTags &&(static_cast <bool> (!AdditionalAbiTags && "Lambda type cannot have additional abi tags" ) ? void (0) : __assert_fail ("!AdditionalAbiTags && \"Lambda type cannot have additional abi tags\"" , "clang/lib/AST/ItaniumMangle.cpp", 1580, __extension__ __PRETTY_FUNCTION__ )) | |||
| 1580 | "Lambda type cannot have additional abi tags")(static_cast <bool> (!AdditionalAbiTags && "Lambda type cannot have additional abi tags" ) ? void (0) : __assert_fail ("!AdditionalAbiTags && \"Lambda type cannot have additional abi tags\"" , "clang/lib/AST/ItaniumMangle.cpp", 1580, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1581 | mangleLambda(Record); | |||
| 1582 | break; | |||
| 1583 | } | |||
| 1584 | } | |||
| 1585 | ||||
| 1586 | if (TD->isExternallyVisible()) { | |||
| 1587 | unsigned UnnamedMangle = | |||
| 1588 | getASTContext().getManglingNumber(TD, Context.isAux()); | |||
| 1589 | Out << "Ut"; | |||
| 1590 | if (UnnamedMangle > 1) | |||
| 1591 | Out << UnnamedMangle - 2; | |||
| 1592 | Out << '_'; | |||
| 1593 | writeAbiTags(TD, AdditionalAbiTags); | |||
| 1594 | break; | |||
| 1595 | } | |||
| 1596 | ||||
| 1597 | // Get a unique id for the anonymous struct. If it is not a real output | |||
| 1598 | // ID doesn't matter so use fake one. | |||
| 1599 | unsigned AnonStructId = | |||
| 1600 | NullOut ? 0 | |||
| 1601 | : Context.getAnonymousStructId(TD, dyn_cast<FunctionDecl>(DC)); | |||
| 1602 | ||||
| 1603 | // Mangle it as a source name in the form | |||
| 1604 | // [n] $_<id> | |||
| 1605 | // where n is the length of the string. | |||
| 1606 | SmallString<8> Str; | |||
| 1607 | Str += "$_"; | |||
| 1608 | Str += llvm::utostr(AnonStructId); | |||
| 1609 | ||||
| 1610 | Out << Str.size(); | |||
| 1611 | Out << Str; | |||
| 1612 | break; | |||
| 1613 | } | |||
| 1614 | ||||
| 1615 | case DeclarationName::ObjCZeroArgSelector: | |||
| 1616 | case DeclarationName::ObjCOneArgSelector: | |||
| 1617 | case DeclarationName::ObjCMultiArgSelector: | |||
| 1618 | llvm_unreachable("Can't mangle Objective-C selector names here!")::llvm::llvm_unreachable_internal("Can't mangle Objective-C selector names here!" , "clang/lib/AST/ItaniumMangle.cpp", 1618); | |||
| 1619 | ||||
| 1620 | case DeclarationName::CXXConstructorName: { | |||
| 1621 | const CXXRecordDecl *InheritedFrom = nullptr; | |||
| 1622 | TemplateName InheritedTemplateName; | |||
| 1623 | const TemplateArgumentList *InheritedTemplateArgs = nullptr; | |||
| 1624 | if (auto Inherited = | |||
| 1625 | cast<CXXConstructorDecl>(ND)->getInheritedConstructor()) { | |||
| 1626 | InheritedFrom = Inherited.getConstructor()->getParent(); | |||
| 1627 | InheritedTemplateName = | |||
| 1628 | TemplateName(Inherited.getConstructor()->getPrimaryTemplate()); | |||
| 1629 | InheritedTemplateArgs = | |||
| 1630 | Inherited.getConstructor()->getTemplateSpecializationArgs(); | |||
| 1631 | } | |||
| 1632 | ||||
| 1633 | if (ND == Structor) | |||
| 1634 | // If the named decl is the C++ constructor we're mangling, use the type | |||
| 1635 | // we were given. | |||
| 1636 | mangleCXXCtorType(static_cast<CXXCtorType>(StructorType), InheritedFrom); | |||
| 1637 | else | |||
| 1638 | // Otherwise, use the complete constructor name. This is relevant if a | |||
| 1639 | // class with a constructor is declared within a constructor. | |||
| 1640 | mangleCXXCtorType(Ctor_Complete, InheritedFrom); | |||
| 1641 | ||||
| 1642 | // FIXME: The template arguments are part of the enclosing prefix or | |||
| 1643 | // nested-name, but it's more convenient to mangle them here. | |||
| 1644 | if (InheritedTemplateArgs) | |||
| 1645 | mangleTemplateArgs(InheritedTemplateName, *InheritedTemplateArgs); | |||
| 1646 | ||||
| 1647 | writeAbiTags(ND, AdditionalAbiTags); | |||
| 1648 | break; | |||
| 1649 | } | |||
| 1650 | ||||
| 1651 | case DeclarationName::CXXDestructorName: | |||
| 1652 | if (ND == Structor) | |||
| 1653 | // If the named decl is the C++ destructor we're mangling, use the type we | |||
| 1654 | // were given. | |||
| 1655 | mangleCXXDtorType(static_cast<CXXDtorType>(StructorType)); | |||
| 1656 | else | |||
| 1657 | // Otherwise, use the complete destructor name. This is relevant if a | |||
| 1658 | // class with a destructor is declared within a destructor. | |||
| 1659 | mangleCXXDtorType(Dtor_Complete); | |||
| 1660 | writeAbiTags(ND, AdditionalAbiTags); | |||
| 1661 | break; | |||
| 1662 | ||||
| 1663 | case DeclarationName::CXXOperatorName: | |||
| 1664 | if (ND && Arity == UnknownArity) { | |||
| 1665 | Arity = cast<FunctionDecl>(ND)->getNumParams(); | |||
| 1666 | ||||
| 1667 | // If we have a member function, we need to include the 'this' pointer. | |||
| 1668 | if (const auto *MD = dyn_cast<CXXMethodDecl>(ND)) | |||
| 1669 | if (!MD->isStatic()) | |||
| 1670 | Arity++; | |||
| 1671 | } | |||
| 1672 | [[fallthrough]]; | |||
| 1673 | case DeclarationName::CXXConversionFunctionName: | |||
| 1674 | case DeclarationName::CXXLiteralOperatorName: | |||
| 1675 | mangleOperatorName(Name, Arity); | |||
| 1676 | writeAbiTags(ND, AdditionalAbiTags); | |||
| 1677 | break; | |||
| 1678 | ||||
| 1679 | case DeclarationName::CXXDeductionGuideName: | |||
| 1680 | llvm_unreachable("Can't mangle a deduction guide name!")::llvm::llvm_unreachable_internal("Can't mangle a deduction guide name!" , "clang/lib/AST/ItaniumMangle.cpp", 1680); | |||
| 1681 | ||||
| 1682 | case DeclarationName::CXXUsingDirective: | |||
| 1683 | llvm_unreachable("Can't mangle a using directive name!")::llvm::llvm_unreachable_internal("Can't mangle a using directive name!" , "clang/lib/AST/ItaniumMangle.cpp", 1683); | |||
| 1684 | } | |||
| 1685 | } | |||
| 1686 | ||||
| 1687 | void CXXNameMangler::mangleRegCallName(const IdentifierInfo *II) { | |||
| 1688 | // <source-name> ::= <positive length number> __regcall3__ <identifier> | |||
| 1689 | // <number> ::= [n] <non-negative decimal integer> | |||
| 1690 | // <identifier> ::= <unqualified source code identifier> | |||
| 1691 | Out << II->getLength() + sizeof("__regcall3__") - 1 << "__regcall3__" | |||
| 1692 | << II->getName(); | |||
| 1693 | } | |||
| 1694 | ||||
| 1695 | void CXXNameMangler::mangleDeviceStubName(const IdentifierInfo *II) { | |||
| 1696 | // <source-name> ::= <positive length number> __device_stub__ <identifier> | |||
| 1697 | // <number> ::= [n] <non-negative decimal integer> | |||
| 1698 | // <identifier> ::= <unqualified source code identifier> | |||
| 1699 | Out << II->getLength() + sizeof("__device_stub__") - 1 << "__device_stub__" | |||
| 1700 | << II->getName(); | |||
| 1701 | } | |||
| 1702 | ||||
| 1703 | void CXXNameMangler::mangleSourceName(const IdentifierInfo *II) { | |||
| 1704 | // <source-name> ::= <positive length number> <identifier> | |||
| 1705 | // <number> ::= [n] <non-negative decimal integer> | |||
| 1706 | // <identifier> ::= <unqualified source code identifier> | |||
| 1707 | Out << II->getLength() << II->getName(); | |||
| 1708 | } | |||
| 1709 | ||||
| 1710 | void CXXNameMangler::mangleNestedName(GlobalDecl GD, | |||
| 1711 | const DeclContext *DC, | |||
| 1712 | const AbiTagList *AdditionalAbiTags, | |||
| 1713 | bool NoFunction) { | |||
| 1714 | const NamedDecl *ND = cast<NamedDecl>(GD.getDecl()); | |||
| 1715 | // <nested-name> | |||
| 1716 | // ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E | |||
| 1717 | // ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> | |||
| 1718 | // <template-args> E | |||
| 1719 | ||||
| 1720 | Out << 'N'; | |||
| 1721 | if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(ND)) { | |||
| 1722 | Qualifiers MethodQuals = Method->getMethodQualifiers(); | |||
| 1723 | // We do not consider restrict a distinguishing attribute for overloading | |||
| 1724 | // purposes so we must not mangle it. | |||
| 1725 | MethodQuals.removeRestrict(); | |||
| 1726 | mangleQualifiers(MethodQuals); | |||
| 1727 | mangleRefQualifier(Method->getRefQualifier()); | |||
| 1728 | } | |||
| 1729 | ||||
| 1730 | // Check if we have a template. | |||
| 1731 | const TemplateArgumentList *TemplateArgs = nullptr; | |||
| 1732 | if (GlobalDecl TD = isTemplate(GD, TemplateArgs)) { | |||
| 1733 | mangleTemplatePrefix(TD, NoFunction); | |||
| 1734 | mangleTemplateArgs(asTemplateName(TD), *TemplateArgs); | |||
| 1735 | } else { | |||
| 1736 | manglePrefix(DC, NoFunction); | |||
| 1737 | mangleUnqualifiedName(GD, DC, AdditionalAbiTags); | |||
| 1738 | } | |||
| 1739 | ||||
| 1740 | Out << 'E'; | |||
| 1741 | } | |||
| 1742 | void CXXNameMangler::mangleNestedName(const TemplateDecl *TD, | |||
| 1743 | ArrayRef<TemplateArgument> Args) { | |||
| 1744 | // <nested-name> ::= N [<CV-qualifiers>] <template-prefix> <template-args> E | |||
| 1745 | ||||
| 1746 | Out << 'N'; | |||
| 1747 | ||||
| 1748 | mangleTemplatePrefix(TD); | |||
| 1749 | mangleTemplateArgs(asTemplateName(TD), Args); | |||
| 1750 | ||||
| 1751 | Out << 'E'; | |||
| 1752 | } | |||
| 1753 | ||||
| 1754 | void CXXNameMangler::mangleNestedNameWithClosurePrefix( | |||
| 1755 | GlobalDecl GD, const NamedDecl *PrefixND, | |||
| 1756 | const AbiTagList *AdditionalAbiTags) { | |||
| 1757 | // A <closure-prefix> represents a variable or field, not a regular | |||
| 1758 | // DeclContext, so needs special handling. In this case we're mangling a | |||
| 1759 | // limited form of <nested-name>: | |||
| 1760 | // | |||
| 1761 | // <nested-name> ::= N <closure-prefix> <closure-type-name> E | |||
| 1762 | ||||
| 1763 | Out << 'N'; | |||
| 1764 | ||||
| 1765 | mangleClosurePrefix(PrefixND); | |||
| 1766 | mangleUnqualifiedName(GD, nullptr, AdditionalAbiTags); | |||
| 1767 | ||||
| 1768 | Out << 'E'; | |||
| 1769 | } | |||
| 1770 | ||||
| 1771 | static GlobalDecl getParentOfLocalEntity(const DeclContext *DC) { | |||
| 1772 | GlobalDecl GD; | |||
| 1773 | // The Itanium spec says: | |||
| 1774 | // For entities in constructors and destructors, the mangling of the | |||
| 1775 | // complete object constructor or destructor is used as the base function | |||
| 1776 | // name, i.e. the C1 or D1 version. | |||
| 1777 | if (auto *CD = dyn_cast<CXXConstructorDecl>(DC)) | |||
| 1778 | GD = GlobalDecl(CD, Ctor_Complete); | |||
| 1779 | else if (auto *DD = dyn_cast<CXXDestructorDecl>(DC)) | |||
| 1780 | GD = GlobalDecl(DD, Dtor_Complete); | |||
| 1781 | else | |||
| 1782 | GD = GlobalDecl(cast<FunctionDecl>(DC)); | |||
| 1783 | return GD; | |||
| 1784 | } | |||
| 1785 | ||||
| 1786 | void CXXNameMangler::mangleLocalName(GlobalDecl GD, | |||
| 1787 | const AbiTagList *AdditionalAbiTags) { | |||
| 1788 | const Decl *D = GD.getDecl(); | |||
| 1789 | // <local-name> := Z <function encoding> E <entity name> [<discriminator>] | |||
| 1790 | // := Z <function encoding> E s [<discriminator>] | |||
| 1791 | // <local-name> := Z <function encoding> E d [ <parameter number> ] | |||
| 1792 | // _ <entity name> | |||
| 1793 | // <discriminator> := _ <non-negative number> | |||
| 1794 | assert(isa<NamedDecl>(D) || isa<BlockDecl>(D))(static_cast <bool> (isa<NamedDecl>(D) || isa< BlockDecl>(D)) ? void (0) : __assert_fail ("isa<NamedDecl>(D) || isa<BlockDecl>(D)" , "clang/lib/AST/ItaniumMangle.cpp", 1794, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1795 | const RecordDecl *RD = GetLocalClassDecl(D); | |||
| 1796 | const DeclContext *DC = Context.getEffectiveDeclContext(RD ? RD : D); | |||
| 1797 | ||||
| 1798 | Out << 'Z'; | |||
| 1799 | ||||
| 1800 | { | |||
| 1801 | AbiTagState LocalAbiTags(AbiTags); | |||
| 1802 | ||||
| 1803 | if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC)) | |||
| 1804 | mangleObjCMethodName(MD); | |||
| 1805 | else if (const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) | |||
| 1806 | mangleBlockForPrefix(BD); | |||
| 1807 | else | |||
| 1808 | mangleFunctionEncoding(getParentOfLocalEntity(DC)); | |||
| 1809 | ||||
| 1810 | // Implicit ABI tags (from namespace) are not available in the following | |||
| 1811 | // entity; reset to actually emitted tags, which are available. | |||
| 1812 | LocalAbiTags.setUsedAbiTags(LocalAbiTags.getEmittedAbiTags()); | |||
| 1813 | } | |||
| 1814 | ||||
| 1815 | Out << 'E'; | |||
| 1816 | ||||
| 1817 | // GCC 5.3.0 doesn't emit derived ABI tags for local names but that seems to | |||
| 1818 | // be a bug that is fixed in trunk. | |||
| 1819 | ||||
| 1820 | if (RD) { | |||
| 1821 | // The parameter number is omitted for the last parameter, 0 for the | |||
| 1822 | // second-to-last parameter, 1 for the third-to-last parameter, etc. The | |||
| 1823 | // <entity name> will of course contain a <closure-type-name>: Its | |||
| 1824 | // numbering will be local to the particular argument in which it appears | |||
| 1825 | // -- other default arguments do not affect its encoding. | |||
| 1826 | const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD); | |||
| 1827 | if (CXXRD && CXXRD->isLambda()) { | |||
| 1828 | if (const ParmVarDecl *Parm | |||
| 1829 | = dyn_cast_or_null<ParmVarDecl>(CXXRD->getLambdaContextDecl())) { | |||
| 1830 | if (const FunctionDecl *Func | |||
| 1831 | = dyn_cast<FunctionDecl>(Parm->getDeclContext())) { | |||
| 1832 | Out << 'd'; | |||
| 1833 | unsigned Num = Func->getNumParams() - Parm->getFunctionScopeIndex(); | |||
| 1834 | if (Num > 1) | |||
| 1835 | mangleNumber(Num - 2); | |||
| 1836 | Out << '_'; | |||
| 1837 | } | |||
| 1838 | } | |||
| 1839 | } | |||
| 1840 | ||||
| 1841 | // Mangle the name relative to the closest enclosing function. | |||
| 1842 | // equality ok because RD derived from ND above | |||
| 1843 | if (D == RD) { | |||
| 1844 | mangleUnqualifiedName(RD, DC, AdditionalAbiTags); | |||
| 1845 | } else if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) { | |||
| 1846 | if (const NamedDecl *PrefixND = getClosurePrefix(BD)) | |||
| 1847 | mangleClosurePrefix(PrefixND, true /*NoFunction*/); | |||
| 1848 | else | |||
| 1849 | manglePrefix(Context.getEffectiveDeclContext(BD), true /*NoFunction*/); | |||
| 1850 | assert(!AdditionalAbiTags && "Block cannot have additional abi tags")(static_cast <bool> (!AdditionalAbiTags && "Block cannot have additional abi tags" ) ? void (0) : __assert_fail ("!AdditionalAbiTags && \"Block cannot have additional abi tags\"" , "clang/lib/AST/ItaniumMangle.cpp", 1850, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1851 | mangleUnqualifiedBlock(BD); | |||
| 1852 | } else { | |||
| 1853 | const NamedDecl *ND = cast<NamedDecl>(D); | |||
| 1854 | mangleNestedName(GD, Context.getEffectiveDeclContext(ND), | |||
| 1855 | AdditionalAbiTags, true /*NoFunction*/); | |||
| 1856 | } | |||
| 1857 | } else if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) { | |||
| 1858 | // Mangle a block in a default parameter; see above explanation for | |||
| 1859 | // lambdas. | |||
| 1860 | if (const ParmVarDecl *Parm | |||
| 1861 | = dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl())) { | |||
| 1862 | if (const FunctionDecl *Func | |||
| 1863 | = dyn_cast<FunctionDecl>(Parm->getDeclContext())) { | |||
| 1864 | Out << 'd'; | |||
| 1865 | unsigned Num = Func->getNumParams() - Parm->getFunctionScopeIndex(); | |||
| 1866 | if (Num > 1) | |||
| 1867 | mangleNumber(Num - 2); | |||
| 1868 | Out << '_'; | |||
| 1869 | } | |||
| 1870 | } | |||
| 1871 | ||||
| 1872 | assert(!AdditionalAbiTags && "Block cannot have additional abi tags")(static_cast <bool> (!AdditionalAbiTags && "Block cannot have additional abi tags" ) ? void (0) : __assert_fail ("!AdditionalAbiTags && \"Block cannot have additional abi tags\"" , "clang/lib/AST/ItaniumMangle.cpp", 1872, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1873 | mangleUnqualifiedBlock(BD); | |||
| 1874 | } else { | |||
| 1875 | mangleUnqualifiedName(GD, DC, AdditionalAbiTags); | |||
| 1876 | } | |||
| 1877 | ||||
| 1878 | if (const NamedDecl *ND = dyn_cast<NamedDecl>(RD ? RD : D)) { | |||
| 1879 | unsigned disc; | |||
| 1880 | if (Context.getNextDiscriminator(ND, disc)) { | |||
| 1881 | if (disc < 10) | |||
| 1882 | Out << '_' << disc; | |||
| 1883 | else | |||
| 1884 | Out << "__" << disc << '_'; | |||
| 1885 | } | |||
| 1886 | } | |||
| 1887 | } | |||
| 1888 | ||||
| 1889 | void CXXNameMangler::mangleBlockForPrefix(const BlockDecl *Block) { | |||
| 1890 | if (GetLocalClassDecl(Block)) { | |||
| 1891 | mangleLocalName(Block, /* AdditionalAbiTags */ nullptr); | |||
| 1892 | return; | |||
| 1893 | } | |||
| 1894 | const DeclContext *DC = Context.getEffectiveDeclContext(Block); | |||
| 1895 | if (isLocalContainerContext(DC)) { | |||
| 1896 | mangleLocalName(Block, /* AdditionalAbiTags */ nullptr); | |||
| 1897 | return; | |||
| 1898 | } | |||
| 1899 | if (const NamedDecl *PrefixND = getClosurePrefix(Block)) | |||
| 1900 | mangleClosurePrefix(PrefixND); | |||
| 1901 | else | |||
| 1902 | manglePrefix(DC); | |||
| 1903 | mangleUnqualifiedBlock(Block); | |||
| 1904 | } | |||
| 1905 | ||||
| 1906 | void CXXNameMangler::mangleUnqualifiedBlock(const BlockDecl *Block) { | |||
| 1907 | // When trying to be ABI-compatibility with clang 12 and before, mangle a | |||
| 1908 | // <data-member-prefix> now, with no substitutions and no <template-args>. | |||
| 1909 | if (Decl *Context = Block->getBlockManglingContextDecl()) { | |||
| 1910 | if (getASTContext().getLangOpts().getClangABICompat() <= | |||
| 1911 | LangOptions::ClangABI::Ver12 && | |||
| 1912 | (isa<VarDecl>(Context) || isa<FieldDecl>(Context)) && | |||
| 1913 | Context->getDeclContext()->isRecord()) { | |||
| 1914 | const auto *ND = cast<NamedDecl>(Context); | |||
| 1915 | if (ND->getIdentifier()) { | |||
| 1916 | mangleSourceNameWithAbiTags(ND); | |||
| 1917 | Out << 'M'; | |||
| 1918 | } | |||
| 1919 | } | |||
| 1920 | } | |||
| 1921 | ||||
| 1922 | // If we have a block mangling number, use it. | |||
| 1923 | unsigned Number = Block->getBlockManglingNumber(); | |||
| 1924 | // Otherwise, just make up a number. It doesn't matter what it is because | |||
| 1925 | // the symbol in question isn't externally visible. | |||
| 1926 | if (!Number) | |||
| 1927 | Number = Context.getBlockId(Block, false); | |||
| 1928 | else { | |||
| 1929 | // Stored mangling numbers are 1-based. | |||
| 1930 | --Number; | |||
| 1931 | } | |||
| 1932 | Out << "Ub"; | |||
| 1933 | if (Number > 0) | |||
| 1934 | Out << Number - 1; | |||
| 1935 | Out << '_'; | |||
| 1936 | } | |||
| 1937 | ||||
| 1938 | // <template-param-decl> | |||
| 1939 | // ::= Ty # template type parameter | |||
| 1940 | // ::= Tn <type> # template non-type parameter | |||
| 1941 | // ::= Tt <template-param-decl>* E # template template parameter | |||
| 1942 | // ::= Tp <template-param-decl> # template parameter pack | |||
| 1943 | void CXXNameMangler::mangleTemplateParamDecl(const NamedDecl *Decl) { | |||
| 1944 | if (auto *Ty = dyn_cast<TemplateTypeParmDecl>(Decl)) { | |||
| 1945 | if (Ty->isParameterPack()) | |||
| 1946 | Out << "Tp"; | |||
| 1947 | Out << "Ty"; | |||
| 1948 | } else if (auto *Tn = dyn_cast<NonTypeTemplateParmDecl>(Decl)) { | |||
| 1949 | if (Tn->isExpandedParameterPack()) { | |||
| 1950 | for (unsigned I = 0, N = Tn->getNumExpansionTypes(); I != N; ++I) { | |||
| 1951 | Out << "Tn"; | |||
| 1952 | mangleType(Tn->getExpansionType(I)); | |||
| 1953 | } | |||
| 1954 | } else { | |||
| 1955 | QualType T = Tn->getType(); | |||
| 1956 | if (Tn->isParameterPack()) { | |||
| 1957 | Out << "Tp"; | |||
| 1958 | if (auto *PackExpansion = T->getAs<PackExpansionType>()) | |||
| 1959 | T = PackExpansion->getPattern(); | |||
| 1960 | } | |||
| 1961 | Out << "Tn"; | |||
| 1962 | mangleType(T); | |||
| 1963 | } | |||
| 1964 | } else if (auto *Tt = dyn_cast<TemplateTemplateParmDecl>(Decl)) { | |||
| 1965 | if (Tt->isExpandedParameterPack()) { | |||
| 1966 | for (unsigned I = 0, N = Tt->getNumExpansionTemplateParameters(); I != N; | |||
| 1967 | ++I) { | |||
| 1968 | Out << "Tt"; | |||
| 1969 | for (auto *Param : *Tt->getExpansionTemplateParameters(I)) | |||
| 1970 | mangleTemplateParamDecl(Param); | |||
| 1971 | Out << "E"; | |||
| 1972 | } | |||
| 1973 | } else { | |||
| 1974 | if (Tt->isParameterPack()) | |||
| 1975 | Out << "Tp"; | |||
| 1976 | Out << "Tt"; | |||
| 1977 | for (auto *Param : *Tt->getTemplateParameters()) | |||
| 1978 | mangleTemplateParamDecl(Param); | |||
| 1979 | Out << "E"; | |||
| 1980 | } | |||
| 1981 | } | |||
| 1982 | } | |||
| 1983 | ||||
| 1984 | void CXXNameMangler::mangleLambda(const CXXRecordDecl *Lambda) { | |||
| 1985 | // When trying to be ABI-compatibility with clang 12 and before, mangle a | |||
| 1986 | // <data-member-prefix> now, with no substitutions. | |||
| 1987 | if (Decl *Context = Lambda->getLambdaContextDecl()) { | |||
| 1988 | if (getASTContext().getLangOpts().getClangABICompat() <= | |||
| 1989 | LangOptions::ClangABI::Ver12 && | |||
| 1990 | (isa<VarDecl>(Context) || isa<FieldDecl>(Context)) && | |||
| 1991 | !isa<ParmVarDecl>(Context)) { | |||
| 1992 | if (const IdentifierInfo *Name | |||
| 1993 | = cast<NamedDecl>(Context)->getIdentifier()) { | |||
| 1994 | mangleSourceName(Name); | |||
| 1995 | const TemplateArgumentList *TemplateArgs = nullptr; | |||
| 1996 | if (GlobalDecl TD = isTemplate(cast<NamedDecl>(Context), TemplateArgs)) | |||
| 1997 | mangleTemplateArgs(asTemplateName(TD), *TemplateArgs); | |||
| 1998 | Out << 'M'; | |||
| 1999 | } | |||
| 2000 | } | |||
| 2001 | } | |||
| 2002 | ||||
| 2003 | Out << "Ul"; | |||
| 2004 | mangleLambdaSig(Lambda); | |||
| 2005 | Out << "E"; | |||
| 2006 | ||||
| 2007 | // The number is omitted for the first closure type with a given | |||
| 2008 | // <lambda-sig> in a given context; it is n-2 for the nth closure type | |||
| 2009 | // (in lexical order) with that same <lambda-sig> and context. | |||
| 2010 | // | |||
| 2011 | // The AST keeps track of the number for us. | |||
| 2012 | // | |||
| 2013 | // In CUDA/HIP, to ensure the consistent lamba numbering between the device- | |||
| 2014 | // and host-side compilations, an extra device mangle context may be created | |||
| 2015 | // if the host-side CXX ABI has different numbering for lambda. In such case, | |||
| 2016 | // if the mangle context is that device-side one, use the device-side lambda | |||
| 2017 | // mangling number for this lambda. | |||
| 2018 | std::optional<unsigned> DeviceNumber = | |||
| 2019 | Context.getDiscriminatorOverride()(Context.getASTContext(), Lambda); | |||
| 2020 | unsigned Number = | |||
| 2021 | DeviceNumber ? *DeviceNumber : Lambda->getLambdaManglingNumber(); | |||
| 2022 | ||||
| 2023 | assert(Number > 0 && "Lambda should be mangled as an unnamed class")(static_cast <bool> (Number > 0 && "Lambda should be mangled as an unnamed class" ) ? void (0) : __assert_fail ("Number > 0 && \"Lambda should be mangled as an unnamed class\"" , "clang/lib/AST/ItaniumMangle.cpp", 2023, __extension__ __PRETTY_FUNCTION__ )); | |||
| 2024 | if (Number > 1) | |||
| 2025 | mangleNumber(Number - 2); | |||
| 2026 | Out << '_'; | |||
| 2027 | } | |||
| 2028 | ||||
| 2029 | void CXXNameMangler::mangleLambdaSig(const CXXRecordDecl *Lambda) { | |||
| 2030 | for (auto *D : Lambda->getLambdaExplicitTemplateParameters()) | |||
| 2031 | mangleTemplateParamDecl(D); | |||
| 2032 | auto *Proto = | |||
| 2033 | Lambda->getLambdaTypeInfo()->getType()->castAs<FunctionProtoType>(); | |||
| 2034 | mangleBareFunctionType(Proto, /*MangleReturnType=*/false, | |||
| 2035 | Lambda->getLambdaStaticInvoker()); | |||
| 2036 | } | |||
| 2037 | ||||
| 2038 | void CXXNameMangler::manglePrefix(NestedNameSpecifier *qualifier) { | |||
| 2039 | switch (qualifier->getKind()) { | |||
| 2040 | case NestedNameSpecifier::Global: | |||
| 2041 | // nothing | |||
| 2042 | return; | |||
| 2043 | ||||
| 2044 | case NestedNameSpecifier::Super: | |||
| 2045 | llvm_unreachable("Can't mangle __super specifier")::llvm::llvm_unreachable_internal("Can't mangle __super specifier" , "clang/lib/AST/ItaniumMangle.cpp", 2045); | |||
| 2046 | ||||
| 2047 | case NestedNameSpecifier::Namespace: | |||
| 2048 | mangleName(qualifier->getAsNamespace()); | |||
| 2049 | return; | |||
| 2050 | ||||
| 2051 | case NestedNameSpecifier::NamespaceAlias: | |||
| 2052 | mangleName(qualifier->getAsNamespaceAlias()->getNamespace()); | |||
| 2053 | return; | |||
| 2054 | ||||
| 2055 | case NestedNameSpecifier::TypeSpec: | |||
| 2056 | case NestedNameSpecifier::TypeSpecWithTemplate: | |||
| 2057 | manglePrefix(QualType(qualifier->getAsType(), 0)); | |||
| 2058 | return; | |||
| 2059 | ||||
| 2060 | case NestedNameSpecifier::Identifier: | |||
| 2061 | // Clang 14 and before did not consider this substitutable. | |||
| 2062 | bool Clang14Compat = getASTContext().getLangOpts().getClangABICompat() <= | |||
| 2063 | LangOptions::ClangABI::Ver14; | |||
| 2064 | if (!Clang14Compat && mangleSubstitution(qualifier)) | |||
| 2065 | return; | |||
| 2066 | ||||
| 2067 | // Member expressions can have these without prefixes, but that | |||
| 2068 | // should end up in mangleUnresolvedPrefix instead. | |||
| 2069 | assert(qualifier->getPrefix())(static_cast <bool> (qualifier->getPrefix()) ? void ( 0) : __assert_fail ("qualifier->getPrefix()", "clang/lib/AST/ItaniumMangle.cpp" , 2069, __extension__ __PRETTY_FUNCTION__)); | |||
| 2070 | manglePrefix(qualifier->getPrefix()); | |||
| 2071 | ||||
| 2072 | mangleSourceName(qualifier->getAsIdentifier()); | |||
| 2073 | ||||
| 2074 | if (!Clang14Compat) | |||
| 2075 | addSubstitution(qualifier); | |||
| 2076 | return; | |||
| 2077 | } | |||
| 2078 | ||||
| 2079 | llvm_unreachable("unexpected nested name specifier")::llvm::llvm_unreachable_internal("unexpected nested name specifier" , "clang/lib/AST/ItaniumMangle.cpp", 2079); | |||
| 2080 | } | |||
| 2081 | ||||
| 2082 | void CXXNameMangler::manglePrefix(const DeclContext *DC, bool NoFunction) { | |||
| 2083 | // <prefix> ::= <prefix> <unqualified-name> | |||
| 2084 | // ::= <template-prefix> <template-args> | |||
| 2085 | // ::= <closure-prefix> | |||
| 2086 | // ::= <template-param> | |||
| 2087 | // ::= # empty | |||
| 2088 | // ::= <substitution> | |||
| 2089 | ||||
| 2090 | assert(!isa<LinkageSpecDecl>(DC) && "prefix cannot be LinkageSpecDecl")(static_cast <bool> (!isa<LinkageSpecDecl>(DC) && "prefix cannot be LinkageSpecDecl") ? void (0) : __assert_fail ("!isa<LinkageSpecDecl>(DC) && \"prefix cannot be LinkageSpecDecl\"" , "clang/lib/AST/ItaniumMangle.cpp", 2090, __extension__ __PRETTY_FUNCTION__ )); | |||
| 2091 | ||||
| 2092 | if (DC->isTranslationUnit()) | |||
| 2093 | return; | |||
| 2094 | ||||
| 2095 | if (NoFunction && isLocalContainerContext(DC)) | |||
| 2096 | return; | |||
| 2097 | ||||
| 2098 | assert(!isLocalContainerContext(DC))(static_cast <bool> (!isLocalContainerContext(DC)) ? void (0) : __assert_fail ("!isLocalContainerContext(DC)", "clang/lib/AST/ItaniumMangle.cpp" , 2098, __extension__ __PRETTY_FUNCTION__)); | |||
| 2099 | ||||
| 2100 | const NamedDecl *ND = cast<NamedDecl>(DC); | |||
| 2101 | if (mangleSubstitution(ND)) | |||
| 2102 | return; | |||
| 2103 | ||||
| 2104 | // Check if we have a template-prefix or a closure-prefix. | |||
| 2105 | const TemplateArgumentList *TemplateArgs = nullptr; | |||
| 2106 | if (GlobalDecl TD = isTemplate(ND, TemplateArgs)) { | |||
| 2107 | mangleTemplatePrefix(TD); | |||
| 2108 | mangleTemplateArgs(asTemplateName(TD), *TemplateArgs); | |||
| 2109 | } else if (const NamedDecl *PrefixND = getClosurePrefix(ND)) { | |||
| 2110 | mangleClosurePrefix(PrefixND, NoFunction); | |||
| 2111 | mangleUnqualifiedName(ND, nullptr, nullptr); | |||
| 2112 | } else { | |||
| 2113 | const DeclContext *DC = Context.getEffectiveDeclContext(ND); | |||
| 2114 | manglePrefix(DC, NoFunction); | |||
| 2115 | mangleUnqualifiedName(ND, DC, nullptr); | |||
| 2116 | } | |||
| 2117 | ||||
| 2118 | addSubstitution(ND); | |||
| 2119 | } | |||
| 2120 | ||||
| 2121 | void CXXNameMangler::mangleTemplatePrefix(TemplateName Template) { | |||
| 2122 | // <template-prefix> ::= <prefix> <template unqualified-name> | |||
| 2123 | // ::= <template-param> | |||
| 2124 | // ::= <substitution> | |||
| 2125 | if (TemplateDecl *TD = Template.getAsTemplateDecl()) | |||
| 2126 | return mangleTemplatePrefix(TD); | |||
| 2127 | ||||
| 2128 | DependentTemplateName *Dependent = Template.getAsDependentTemplateName(); | |||
| 2129 | assert(Dependent && "unexpected template name kind")(static_cast <bool> (Dependent && "unexpected template name kind" ) ? void (0) : __assert_fail ("Dependent && \"unexpected template name kind\"" , "clang/lib/AST/ItaniumMangle.cpp", 2129, __extension__ __PRETTY_FUNCTION__ )); | |||
| 2130 | ||||
| 2131 | // Clang 11 and before mangled the substitution for a dependent template name | |||
| 2132 | // after already having emitted (a substitution for) the prefix. | |||
| 2133 | bool Clang11Compat = getASTContext().getLangOpts().getClangABICompat() <= | |||
| 2134 | LangOptions::ClangABI::Ver11; | |||
| 2135 | if (!Clang11Compat && mangleSubstitution(Template)) | |||
| 2136 | return; | |||
| 2137 | ||||
| 2138 | if (NestedNameSpecifier *Qualifier = Dependent->getQualifier()) | |||
| 2139 | manglePrefix(Qualifier); | |||
| 2140 | ||||
| 2141 | if (Clang11Compat && mangleSubstitution(Template)) | |||
| 2142 | return; | |||
| 2143 | ||||
| 2144 | if (const IdentifierInfo *Id = Dependent->getIdentifier()) | |||
| 2145 | mangleSourceName(Id); | |||
| 2146 | else | |||
| 2147 | mangleOperatorName(Dependent->getOperator(), UnknownArity); | |||
| 2148 | ||||
| 2149 | addSubstitution(Template); | |||
| 2150 | } | |||
| 2151 | ||||
| 2152 | void CXXNameMangler::mangleTemplatePrefix(GlobalDecl GD, | |||
| 2153 | bool NoFunction) { | |||
| 2154 | const TemplateDecl *ND = cast<TemplateDecl>(GD.getDecl()); | |||
| 2155 | // <template-prefix> ::= <prefix> <template unqualified-name> | |||
| 2156 | // ::= <template-param> | |||
| 2157 | // ::= <substitution> | |||
| 2158 | // <template-template-param> ::= <template-param> | |||
| 2159 | // <substitution> | |||
| 2160 | ||||
| 2161 | if (mangleSubstitution(ND)) | |||
| 2162 | return; | |||
| 2163 | ||||
| 2164 | // <template-template-param> ::= <template-param> | |||
| 2165 | if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) { | |||
| 2166 | mangleTemplateParameter(TTP->getDepth(), TTP->getIndex()); | |||
| 2167 | } else { | |||
| 2168 | const DeclContext *DC = Context.getEffectiveDeclContext(ND); | |||
| 2169 | manglePrefix(DC, NoFunction); | |||
| 2170 | if (isa<BuiltinTemplateDecl>(ND) || isa<ConceptDecl>(ND)) | |||
| 2171 | mangleUnqualifiedName(GD, DC, nullptr); | |||
| 2172 | else | |||
| 2173 | mangleUnqualifiedName(GD.getWithDecl(ND->getTemplatedDecl()), DC, | |||
| 2174 | nullptr); | |||
| 2175 | } | |||
| 2176 | ||||
| 2177 | addSubstitution(ND); | |||
| 2178 | } | |||
| 2179 | ||||
| 2180 | const NamedDecl *CXXNameMangler::getClosurePrefix(const Decl *ND) { | |||
| 2181 | if (getASTContext().getLangOpts().getClangABICompat() <= | |||
| 2182 | LangOptions::ClangABI::Ver12) | |||
| 2183 | return nullptr; | |||
| 2184 | ||||
| 2185 | const NamedDecl *Context = nullptr; | |||
| 2186 | if (auto *Block = dyn_cast<BlockDecl>(ND)) { | |||
| 2187 | Context = dyn_cast_or_null<NamedDecl>(Block->getBlockManglingContextDecl()); | |||
| 2188 | } else if (auto *RD = dyn_cast<CXXRecordDecl>(ND)) { | |||
| 2189 | if (RD->isLambda()) | |||
| 2190 | Context = dyn_cast_or_null<NamedDecl>(RD->getLambdaContextDecl()); | |||
| 2191 | } | |||
| 2192 | if (!Context) | |||
| 2193 | return nullptr; | |||
| 2194 | ||||
| 2195 | // Only lambdas within the initializer of a non-local variable or non-static | |||
| 2196 | // data member get a <closure-prefix>. | |||
| 2197 | if ((isa<VarDecl>(Context) && cast<VarDecl>(Context)->hasGlobalStorage()) || | |||
| 2198 | isa<FieldDecl>(Context)) | |||
| 2199 | return Context; | |||
| 2200 | ||||
| 2201 | return nullptr; | |||
| 2202 | } | |||
| 2203 | ||||
| 2204 | void CXXNameMangler::mangleClosurePrefix(const NamedDecl *ND, bool NoFunction) { | |||
| 2205 | // <closure-prefix> ::= [ <prefix> ] <unqualified-name> M | |||
| 2206 | // ::= <template-prefix> <template-args> M | |||
| 2207 | if (mangleSubstitution(ND)) | |||
| 2208 | return; | |||
| 2209 | ||||
| 2210 | const TemplateArgumentList *TemplateArgs = nullptr; | |||
| 2211 | if (GlobalDecl TD = isTemplate(ND, TemplateArgs)) { | |||
| 2212 | mangleTemplatePrefix(TD, NoFunction); | |||
| 2213 | mangleTemplateArgs(asTemplateName(TD), *TemplateArgs); | |||
| 2214 | } else { | |||
| 2215 | const auto *DC = Context.getEffectiveDeclContext(ND); | |||
| 2216 | manglePrefix(DC, NoFunction); | |||
| 2217 | mangleUnqualifiedName(ND, DC, nullptr); | |||
| 2218 | } | |||
| 2219 | ||||
| 2220 | Out << 'M'; | |||
| 2221 | ||||
| 2222 | addSubstitution(ND); | |||
| 2223 | } | |||
| 2224 | ||||
| 2225 | /// Mangles a template name under the production <type>. Required for | |||
| 2226 | /// template template arguments. | |||
| 2227 | /// <type> ::= <class-enum-type> | |||
| 2228 | /// ::= <template-param> | |||
| 2229 | /// ::= <substitution> | |||
| 2230 | void CXXNameMangler::mangleType(TemplateName TN) { | |||
| 2231 | if (mangleSubstitution(TN)) | |||
| 2232 | return; | |||
| 2233 | ||||
| 2234 | TemplateDecl *TD = nullptr; | |||
| 2235 | ||||
| 2236 | switch (TN.getKind()) { | |||
| 2237 | case TemplateName::QualifiedTemplate: | |||
| 2238 | case TemplateName::UsingTemplate: | |||
| 2239 | case TemplateName::Template: | |||
| 2240 | TD = TN.getAsTemplateDecl(); | |||
| 2241 | goto HaveDecl; | |||
| 2242 | ||||
| 2243 | HaveDecl: | |||
| 2244 | if (auto *TTP = dyn_cast<TemplateTemplateParmDecl>(TD)) | |||
| 2245 | mangleTemplateParameter(TTP->getDepth(), TTP->getIndex()); | |||
| 2246 | else | |||
| 2247 | mangleName(TD); | |||
| 2248 | break; | |||
| 2249 | ||||
| 2250 | case TemplateName::OverloadedTemplate: | |||
| 2251 | case TemplateName::AssumedTemplate: | |||
| 2252 | llvm_unreachable("can't mangle an overloaded template name as a <type>")::llvm::llvm_unreachable_internal("can't mangle an overloaded template name as a <type>" , "clang/lib/AST/ItaniumMangle.cpp", 2252); | |||
| 2253 | ||||
| 2254 | case TemplateName::DependentTemplate: { | |||
| 2255 | const DependentTemplateName *Dependent = TN.getAsDependentTemplateName(); | |||
| 2256 | assert(Dependent->isIdentifier())(static_cast <bool> (Dependent->isIdentifier()) ? void (0) : __assert_fail ("Dependent->isIdentifier()", "clang/lib/AST/ItaniumMangle.cpp" , 2256, __extension__ __PRETTY_FUNCTION__)); | |||
| 2257 | ||||
| 2258 | // <class-enum-type> ::= <name> | |||
| 2259 | // <name> ::= <nested-name> | |||
| 2260 | mangleUnresolvedPrefix(Dependent->getQualifier()); | |||
| 2261 | mangleSourceName(Dependent->getIdentifier()); | |||
| 2262 | break; | |||
| 2263 | } | |||
| 2264 | ||||
| 2265 | case TemplateName::SubstTemplateTemplateParm: { | |||
| 2266 | // Substituted template parameters are mangled as the substituted | |||
| 2267 | // template. This will check for the substitution twice, which is | |||
| 2268 | // fine, but we have to return early so that we don't try to *add* | |||
| 2269 | // the substitution twice. | |||
| 2270 | SubstTemplateTemplateParmStorage *subst | |||
| 2271 | = TN.getAsSubstTemplateTemplateParm(); | |||
| 2272 | mangleType(subst->getReplacement()); | |||
| 2273 | return; | |||
| 2274 | } | |||
| 2275 | ||||
| 2276 | case TemplateName::SubstTemplateTemplateParmPack: { | |||
| 2277 | // FIXME: not clear how to mangle this! | |||
| 2278 | // template <template <class> class T...> class A { | |||
| 2279 | // template <template <class> class U...> void foo(B<T,U> x...); | |||
| 2280 | // }; | |||
| 2281 | Out << "_SUBSTPACK_"; | |||
| 2282 | break; | |||
| 2283 | } | |||
| 2284 | } | |||
| 2285 | ||||
| 2286 | addSubstitution(TN); | |||
| 2287 | } | |||
| 2288 | ||||
| 2289 | bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty, | |||
| 2290 | StringRef Prefix) { | |||
| 2291 | // Only certain other types are valid as prefixes; enumerate them. | |||
| 2292 | switch (Ty->getTypeClass()) { | |||
| 2293 | case Type::Builtin: | |||
| 2294 | case Type::Complex: | |||
| 2295 | case Type::Adjusted: | |||
| 2296 | case Type::Decayed: | |||
| 2297 | case Type::Pointer: | |||
| 2298 | case Type::BlockPointer: | |||
| 2299 | case Type::LValueReference: | |||
| 2300 | case Type::RValueReference: | |||
| 2301 | case Type::MemberPointer: | |||
| 2302 | case Type::ConstantArray: | |||
| 2303 | case Type::IncompleteArray: | |||
| 2304 | case Type::VariableArray: | |||
| 2305 | case Type::DependentSizedArray: | |||
| 2306 | case Type::DependentAddressSpace: | |||
| 2307 | case Type::DependentVector: | |||
| 2308 | case Type::DependentSizedExtVector: | |||
| 2309 | case Type::Vector: | |||
| 2310 | case Type::ExtVector: | |||
| 2311 | case Type::ConstantMatrix: | |||
| 2312 | case Type::DependentSizedMatrix: | |||
| 2313 | case Type::FunctionProto: | |||
| 2314 | case Type::FunctionNoProto: | |||
| 2315 | case Type::Paren: | |||
| 2316 | case Type::Attributed: | |||
| 2317 | case Type::BTFTagAttributed: | |||
| 2318 | case Type::Auto: | |||
| 2319 | case Type::DeducedTemplateSpecialization: | |||
| 2320 | case Type::PackExpansion: | |||
| 2321 | case Type::ObjCObject: | |||
| 2322 | case Type::ObjCInterface: | |||
| 2323 | case Type::ObjCObjectPointer: | |||
| 2324 | case Type::ObjCTypeParam: | |||
| 2325 | case Type::Atomic: | |||
| 2326 | case Type::Pipe: | |||
| 2327 | case Type::MacroQualified: | |||
| 2328 | case Type::BitInt: | |||
| 2329 | case Type::DependentBitInt: | |||
| 2330 | llvm_unreachable("type is illegal as a nested name specifier")::llvm::llvm_unreachable_internal("type is illegal as a nested name specifier" , "clang/lib/AST/ItaniumMangle.cpp", 2330); | |||
| 2331 | ||||
| 2332 | case Type::SubstTemplateTypeParmPack: | |||
| 2333 | // FIXME: not clear how to mangle this! | |||
| 2334 | // template <class T...> class A { | |||
| 2335 | // template <class U...> void foo(decltype(T::foo(U())) x...); | |||
| 2336 | // }; | |||
| 2337 | Out << "_SUBSTPACK_"; | |||
| 2338 | break; | |||
| 2339 | ||||
| 2340 | // <unresolved-type> ::= <template-param> | |||
| 2341 | // ::= <decltype> | |||
| 2342 | // ::= <template-template-param> <template-args> | |||
| 2343 | // (this last is not official yet) | |||
| 2344 | case Type::TypeOfExpr: | |||
| 2345 | case Type::TypeOf: | |||
| 2346 | case Type::Decltype: | |||
| 2347 | case Type::TemplateTypeParm: | |||
| 2348 | case Type::UnaryTransform: | |||
| 2349 | case Type::SubstTemplateTypeParm: | |||
| 2350 | unresolvedType: | |||
| 2351 | // Some callers want a prefix before the mangled type. | |||
| 2352 | Out << Prefix; | |||
| 2353 | ||||
| 2354 | // This seems to do everything we want. It's not really | |||
| 2355 | // sanctioned for a substituted template parameter, though. | |||
| 2356 | mangleType(Ty); | |||
| 2357 | ||||
| 2358 | // We never want to print 'E' directly after an unresolved-type, | |||
| 2359 | // so we return directly. | |||
| 2360 | return true; | |||
| 2361 | ||||
| 2362 | case Type::Typedef: | |||
| 2363 | mangleSourceNameWithAbiTags(cast<TypedefType>(Ty)->getDecl()); | |||
| 2364 | break; | |||
| 2365 | ||||
| 2366 | case Type::UnresolvedUsing: | |||
| 2367 | mangleSourceNameWithAbiTags( | |||
| 2368 | cast<UnresolvedUsingType>(Ty)->getDecl()); | |||
| 2369 | break; | |||
| 2370 | ||||
| 2371 | case Type::Enum: | |||
| 2372 | case Type::Record: | |||
| 2373 | mangleSourceNameWithAbiTags(cast<TagType>(Ty)->getDecl()); | |||
| 2374 | break; | |||
| 2375 | ||||
| 2376 | case Type::TemplateSpecialization: { | |||
| 2377 | const TemplateSpecializationType *TST = | |||
| 2378 | cast<TemplateSpecializationType>(Ty); | |||
| 2379 | TemplateName TN = TST->getTemplateName(); | |||
| 2380 | switch (TN.getKind()) { | |||
| 2381 | case TemplateName::Template: | |||
| 2382 | case TemplateName::QualifiedTemplate: { | |||
| 2383 | TemplateDecl *TD = TN.getAsTemplateDecl(); | |||
| 2384 | ||||
| 2385 | // If the base is a template template parameter, this is an | |||
| 2386 | // unresolved type. | |||
| 2387 | assert(TD && "no template for template specialization type")(static_cast <bool> (TD && "no template for template specialization type" ) ? void (0) : __assert_fail ("TD && \"no template for template specialization type\"" , "clang/lib/AST/ItaniumMangle.cpp", 2387, __extension__ __PRETTY_FUNCTION__ )); | |||
| 2388 | if (isa<TemplateTemplateParmDecl>(TD)) | |||
| 2389 | goto unresolvedType; | |||
| 2390 | ||||
| 2391 | mangleSourceNameWithAbiTags(TD); | |||
| 2392 | break; | |||
| 2393 | } | |||
| 2394 | ||||
| 2395 | case TemplateName::OverloadedTemplate: | |||
| 2396 | case TemplateName::AssumedTemplate: | |||
| 2397 | case TemplateName::DependentTemplate: | |||
| 2398 | llvm_unreachable("invalid base for a template specialization type")::llvm::llvm_unreachable_internal("invalid base for a template specialization type" , "clang/lib/AST/ItaniumMangle.cpp", 2398); | |||
| 2399 | ||||
| 2400 | case TemplateName::SubstTemplateTemplateParm: { | |||
| 2401 | SubstTemplateTemplateParmStorage *subst = | |||
| 2402 | TN.getAsSubstTemplateTemplateParm(); | |||
| 2403 | mangleExistingSubstitution(subst->getReplacement()); | |||
| 2404 | break; | |||
| 2405 | } | |||
| 2406 | ||||
| 2407 | case TemplateName::SubstTemplateTemplateParmPack: { | |||
| 2408 | // FIXME: not clear how to mangle this! | |||
| 2409 | // template <template <class U> class T...> class A { | |||
| 2410 | // template <class U...> void foo(decltype(T<U>::foo) x...); | |||
| 2411 | // }; | |||
| 2412 | Out << "_SUBSTPACK_"; | |||
| 2413 | break; | |||
| 2414 | } | |||
| 2415 | case TemplateName::UsingTemplate: { | |||
| 2416 | TemplateDecl *TD = TN.getAsTemplateDecl(); | |||
| 2417 | assert(TD && !isa<TemplateTemplateParmDecl>(TD))(static_cast <bool> (TD && !isa<TemplateTemplateParmDecl >(TD)) ? void (0) : __assert_fail ("TD && !isa<TemplateTemplateParmDecl>(TD)" , "clang/lib/AST/ItaniumMangle.cpp", 2417, __extension__ __PRETTY_FUNCTION__ )); | |||
| 2418 | mangleSourceNameWithAbiTags(TD); | |||
| 2419 | break; | |||
| 2420 | } | |||
| 2421 | } | |||
| 2422 | ||||
| 2423 | // Note: we don't pass in the template name here. We are mangling the | |||
| 2424 | // original source-level template arguments, so we shouldn't consider | |||
| 2425 | // conversions to the corresponding template parameter. | |||
| 2426 | // FIXME: Other compilers mangle partially-resolved template arguments in | |||
| 2427 | // unresolved-qualifier-levels. | |||
| 2428 | mangleTemplateArgs(TemplateName(), TST->template_arguments()); | |||
| 2429 | break; | |||
| 2430 | } | |||
| 2431 | ||||
| 2432 | case Type::InjectedClassName: | |||
| 2433 | mangleSourceNameWithAbiTags( | |||
| 2434 | cast<InjectedClassNameType>(Ty)->getDecl()); | |||
| 2435 | break; | |||
| 2436 | ||||
| 2437 | case Type::DependentName: | |||
| 2438 | mangleSourceName(cast<DependentNameType>(Ty)->getIdentifier()); | |||
| 2439 | break; | |||
| 2440 | ||||
| 2441 | case Type::DependentTemplateSpecialization: { | |||
| 2442 | const DependentTemplateSpecializationType *DTST = | |||
| 2443 | cast<DependentTemplateSpecializationType>(Ty); | |||
| 2444 | TemplateName Template = getASTContext().getDependentTemplateName( | |||
| 2445 | DTST->getQualifier(), DTST->getIdentifier()); | |||
| 2446 | mangleSourceName(DTST->getIdentifier()); | |||
| 2447 | mangleTemplateArgs(Template, DTST->template_arguments()); | |||
| 2448 | break; | |||
| 2449 | } | |||
| 2450 | ||||
| 2451 | case Type::Using: | |||
| 2452 | return mangleUnresolvedTypeOrSimpleId(cast<UsingType>(Ty)->desugar(), | |||
| 2453 | Prefix); | |||
| 2454 | case Type::Elaborated: | |||
| 2455 | return mangleUnresolvedTypeOrSimpleId( | |||
| 2456 | cast<ElaboratedType>(Ty)->getNamedType(), Prefix); | |||
| 2457 | } | |||
| 2458 | ||||
| 2459 | return false; | |||
| 2460 | } | |||
| 2461 | ||||
| 2462 | void CXXNameMangler::mangleOperatorName(DeclarationName Name, unsigned Arity) { | |||
| 2463 | switch (Name.getNameKind()) { | |||
| 2464 | case DeclarationName::CXXConstructorName: | |||
| 2465 | case DeclarationName::CXXDestructorName: | |||
| 2466 | case DeclarationName::CXXDeductionGuideName: | |||
| 2467 | case DeclarationName::CXXUsingDirective: | |||
| 2468 | case DeclarationName::Identifier: | |||
| 2469 | case DeclarationName::ObjCMultiArgSelector: | |||
| 2470 | case DeclarationName::ObjCOneArgSelector: | |||
| 2471 | case DeclarationName::ObjCZeroArgSelector: | |||
| 2472 | llvm_unreachable("Not an operator name")::llvm::llvm_unreachable_internal("Not an operator name", "clang/lib/AST/ItaniumMangle.cpp" , 2472); | |||
| 2473 | ||||
| 2474 | case DeclarationName::CXXConversionFunctionName: | |||
| 2475 | // <operator-name> ::= cv <type> # (cast) | |||
| 2476 | Out << "cv"; | |||
| 2477 | mangleType(Name.getCXXNameType()); | |||
| 2478 | break; | |||
| 2479 | ||||
| 2480 | case DeclarationName::CXXLiteralOperatorName: | |||
| 2481 | Out << "li"; | |||
| 2482 | mangleSourceName(Name.getCXXLiteralIdentifier()); | |||
| 2483 | return; | |||
| 2484 | ||||
| 2485 | case DeclarationName::CXXOperatorName: | |||
| 2486 | mangleOperatorName(Name.getCXXOverloadedOperator(), Arity); | |||
| 2487 | break; | |||
| 2488 | } | |||
| 2489 | } | |||
| 2490 | ||||
| 2491 | void | |||
| 2492 | CXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity) { | |||
| 2493 | switch (OO) { | |||
| 2494 | // <operator-name> ::= nw # new | |||
| 2495 | case OO_New: Out << "nw"; break; | |||
| 2496 | // ::= na # new[] | |||
| 2497 | case OO_Array_New: Out << "na"; break; | |||
| 2498 | // ::= dl # delete | |||
| 2499 | case OO_Delete: Out << "dl"; break; | |||
| 2500 | // ::= da # delete[] | |||
| 2501 | case OO_Array_Delete: Out << "da"; break; | |||
| 2502 | // ::= ps # + (unary) | |||
| 2503 | // ::= pl # + (binary or unknown) | |||
| 2504 | case OO_Plus: | |||
| 2505 | Out << (Arity == 1? "ps" : "pl"); break; | |||
| 2506 | // ::= ng # - (unary) | |||
| 2507 | // ::= mi # - (binary or unknown) | |||
| 2508 | case OO_Minus: | |||
| 2509 | Out << (Arity == 1? "ng" : "mi"); break; | |||
| 2510 | // ::= ad # & (unary) | |||
| 2511 | // ::= an # & (binary or unknown) | |||
| 2512 | case OO_Amp: | |||
| 2513 | Out << (Arity == 1? "ad" : "an"); break; | |||
| 2514 | // ::= de # * (unary) | |||
| 2515 | // ::= ml # * (binary or unknown) | |||
| 2516 | case OO_Star: | |||
| 2517 | // Use binary when unknown. | |||
| 2518 | Out << (Arity == 1? "de" : "ml"); break; | |||
| 2519 | // ::= co # ~ | |||
| 2520 | case OO_Tilde: Out << "co"; break; | |||
| 2521 | // ::= dv # / | |||
| 2522 | case OO_Slash: Out << "dv"; break; | |||
| 2523 | // ::= rm # % | |||
| 2524 | case OO_Percent: Out << "rm"; break; | |||
| 2525 | // ::= or # | | |||
| 2526 | case OO_Pipe: Out << "or"; break; | |||
| 2527 | // ::= eo # ^ | |||
| 2528 | case OO_Caret: Out << "eo"; break; | |||
| 2529 | // ::= aS # = | |||
| 2530 | case OO_Equal: Out << "aS"; break; | |||
| 2531 | // ::= pL # += | |||
| 2532 | case OO_PlusEqual: Out << "pL"; break; | |||
| 2533 | // ::= mI # -= | |||
| 2534 | case OO_MinusEqual: Out << "mI"; break; | |||
| 2535 | // ::= mL # *= | |||
| 2536 | case OO_StarEqual: Out << "mL"; break; | |||
| 2537 | // ::= dV # /= | |||
| 2538 | case OO_SlashEqual: Out << "dV"; break; | |||
| 2539 | // ::= rM # %= | |||
| 2540 | case OO_PercentEqual: Out << "rM"; break; | |||
| 2541 | // ::= aN # &= | |||
| 2542 | case OO_AmpEqual: Out << "aN"; break; | |||
| 2543 | // ::= oR # |= | |||
| 2544 | case OO_PipeEqual: Out << "oR"; break; | |||
| 2545 | // ::= eO # ^= | |||
| 2546 | case OO_CaretEqual: Out << "eO"; break; | |||
| 2547 | // ::= ls # << | |||
| 2548 | case OO_LessLess: Out << "ls"; break; | |||
| 2549 | // ::= rs # >> | |||
| 2550 | case OO_GreaterGreater: Out << "rs"; break; | |||
| 2551 | // ::= lS # <<= | |||
| 2552 | case OO_LessLessEqual: Out << "lS"; break; | |||
| 2553 | // ::= rS # >>= | |||
| 2554 | case OO_GreaterGreaterEqual: Out << "rS"; break; | |||
| 2555 | // ::= eq # == | |||
| 2556 | case OO_EqualEqual: Out << "eq"; break; | |||
| 2557 | // ::= ne # != | |||
| 2558 | case OO_ExclaimEqual: Out << "ne"; break; | |||
| 2559 | // ::= lt # < | |||
| 2560 | case OO_Less: Out << "lt"; break; | |||
| 2561 | // ::= gt # > | |||
| 2562 | case OO_Greater: Out << "gt"; break; | |||
| 2563 | // ::= le # <= | |||
| 2564 | case OO_LessEqual: Out << "le"; break; | |||
| 2565 | // ::= ge # >= | |||
| 2566 | case OO_GreaterEqual: Out << "ge"; break; | |||
| 2567 | // ::= nt # ! | |||
| 2568 | case OO_Exclaim: Out << "nt"; break; | |||
| 2569 | // ::= aa # && | |||
| 2570 | case OO_AmpAmp: Out << "aa"; break; | |||
| 2571 | // ::= oo # || | |||
| 2572 | case OO_PipePipe: Out << "oo"; break; | |||
| 2573 | // ::= pp # ++ | |||
| 2574 | case OO_PlusPlus: Out << "pp"; break; | |||
| 2575 | // ::= mm # -- | |||
| 2576 | case OO_MinusMinus: Out << "mm"; break; | |||
| 2577 | // ::= cm # , | |||
| 2578 | case OO_Comma: Out << "cm"; break; | |||
| 2579 | // ::= pm # ->* | |||
| 2580 | case OO_ArrowStar: Out << "pm"; break; | |||
| 2581 | // ::= pt # -> | |||
| 2582 | case OO_Arrow: Out << "pt"; break; | |||
| 2583 | // ::= cl # () | |||
| 2584 | case OO_Call: Out << "cl"; break; | |||
| 2585 | // ::= ix # [] | |||
| 2586 | case OO_Subscript: Out << "ix"; break; | |||
| 2587 | ||||
| 2588 | // ::= qu # ? | |||
| 2589 | // The conditional operator can't be overloaded, but we still handle it when | |||
| 2590 | // mangling expressions. | |||
| 2591 | case OO_Conditional: Out << "qu"; break; | |||
| 2592 | // Proposal on cxx-abi-dev, 2015-10-21. | |||
| 2593 | // ::= aw # co_await | |||
| 2594 | case OO_Coawait: Out << "aw"; break; | |||
| 2595 | // Proposed in cxx-abi github issue 43. | |||
| 2596 | // ::= ss # <=> | |||
| 2597 | case OO_Spaceship: Out << "ss"; break; | |||
| 2598 | ||||
| 2599 | case OO_None: | |||
| 2600 | case NUM_OVERLOADED_OPERATORS: | |||
| 2601 | llvm_unreachable("Not an overloaded operator")::llvm::llvm_unreachable_internal("Not an overloaded operator" , "clang/lib/AST/ItaniumMangle.cpp", 2601); | |||
| 2602 | } | |||
| 2603 | } | |||
| 2604 | ||||
| 2605 | void CXXNameMangler::mangleQualifiers(Qualifiers Quals, const DependentAddressSpaceType *DAST) { | |||
| 2606 | // Vendor qualifiers come first and if they are order-insensitive they must | |||
| 2607 | // be emitted in reversed alphabetical order, see Itanium ABI 5.1.5. | |||
| 2608 | ||||
| 2609 | // <type> ::= U <addrspace-expr> | |||
| 2610 | if (DAST) { | |||
| 2611 | Out << "U2ASI"; | |||
| 2612 | mangleExpression(DAST->getAddrSpaceExpr()); | |||
| 2613 | Out << "E"; | |||
| 2614 | } | |||
| 2615 | ||||
| 2616 | // Address space qualifiers start with an ordinary letter. | |||
| 2617 | if (Quals.hasAddressSpace()) { | |||
| 2618 | // Address space extension: | |||
| 2619 | // | |||
| 2620 | // <type> ::= U <target-addrspace> | |||
| 2621 | // <type> ::= U <OpenCL-addrspace> | |||
| 2622 | // <type> ::= U <CUDA-addrspace> | |||
| 2623 | ||||
| 2624 | SmallString<64> ASString; | |||
| 2625 | LangAS AS = Quals.getAddressSpace(); | |||
| 2626 | ||||
| 2627 | if (Context.getASTContext().addressSpaceMapManglingFor(AS)) { | |||
| 2628 | // <target-addrspace> ::= "AS" <address-space-number> | |||
| 2629 | unsigned TargetAS = Context.getASTContext().getTargetAddressSpace(AS); | |||
| 2630 | if (TargetAS != 0 || | |||
| 2631 | Context.getASTContext().getTargetAddressSpace(LangAS::Default) != 0) | |||
| 2632 | ASString = "AS" + llvm::utostr(TargetAS); | |||
| 2633 | } else { | |||
| 2634 | switch (AS) { | |||
| 2635 | default: llvm_unreachable("Not a language specific address space")::llvm::llvm_unreachable_internal("Not a language specific address space" , "clang/lib/AST/ItaniumMangle.cpp", 2635); | |||
| 2636 | // <OpenCL-addrspace> ::= "CL" [ "global" | "local" | "constant" | | |||
| 2637 | // "private"| "generic" | "device" | | |||
| 2638 | // "host" ] | |||
| 2639 | case LangAS::opencl_global: | |||
| 2640 | ASString = "CLglobal"; | |||
| 2641 | break; | |||
| 2642 | case LangAS::opencl_global_device: | |||
| 2643 | ASString = "CLdevice"; | |||
| 2644 | break; | |||
| 2645 | case LangAS::opencl_global_host: | |||
| 2646 | ASString = "CLhost"; | |||
| 2647 | break; | |||
| 2648 | case LangAS::opencl_local: | |||
| 2649 | ASString = "CLlocal"; | |||
| 2650 | break; | |||
| 2651 | case LangAS::opencl_constant: | |||
| 2652 | ASString = "CLconstant"; | |||
| 2653 | break; | |||
| 2654 | case LangAS::opencl_private: | |||
| 2655 | ASString = "CLprivate"; | |||
| 2656 | break; | |||
| 2657 | case LangAS::opencl_generic: | |||
| 2658 | ASString = "CLgeneric"; | |||
| 2659 | break; | |||
| 2660 | // <SYCL-addrspace> ::= "SY" [ "global" | "local" | "private" | | |||
| 2661 | // "device" | "host" ] | |||
| 2662 | case LangAS::sycl_global: | |||
| 2663 | ASString = "SYglobal"; | |||
| 2664 | break; | |||
| 2665 | case LangAS::sycl_global_device: | |||
| 2666 | ASString = "SYdevice"; | |||
| 2667 | break; | |||
| 2668 | case LangAS::sycl_global_host: | |||
| 2669 | ASString = "SYhost"; | |||
| 2670 | break; | |||
| 2671 | case LangAS::sycl_local: | |||
| 2672 | ASString = "SYlocal"; | |||
| 2673 | break; | |||
| 2674 | case LangAS::sycl_private: | |||
| 2675 | ASString = "SYprivate"; | |||
| 2676 | break; | |||
| 2677 | // <CUDA-addrspace> ::= "CU" [ "device" | "constant" | "shared" ] | |||
| 2678 | case LangAS::cuda_device: | |||
| 2679 | ASString = "CUdevice"; | |||
| 2680 | break; | |||
| 2681 | case LangAS::cuda_constant: | |||
| 2682 | ASString = "CUconstant"; | |||
| 2683 | break; | |||
| 2684 | case LangAS::cuda_shared: | |||
| 2685 | ASString = "CUshared"; | |||
| 2686 | break; | |||
| 2687 | // <ptrsize-addrspace> ::= [ "ptr32_sptr" | "ptr32_uptr" | "ptr64" ] | |||
| 2688 | case LangAS::ptr32_sptr: | |||
| 2689 | ASString = "ptr32_sptr"; | |||
| 2690 | break; | |||
| 2691 | case LangAS::ptr32_uptr: | |||
| 2692 | ASString = "ptr32_uptr"; | |||
| 2693 | break; | |||
| 2694 | case LangAS::ptr64: | |||
| 2695 | ASString = "ptr64"; | |||
| 2696 | break; | |||
| 2697 | } | |||
| 2698 | } | |||
| 2699 | if (!ASString.empty()) | |||
| 2700 | mangleVendorQualifier(ASString); | |||
| 2701 | } | |||
| 2702 | ||||
| 2703 | // The ARC ownership qualifiers start with underscores. | |||
| 2704 | // Objective-C ARC Extension: | |||
| 2705 | // | |||
| 2706 | // <type> ::= U "__strong" | |||
| 2707 | // <type> ::= U "__weak" | |||
| 2708 | // <type> ::= U "__autoreleasing" | |||
| 2709 | // | |||
| 2710 | // Note: we emit __weak first to preserve the order as | |||
| 2711 | // required by the Itanium ABI. | |||
| 2712 | if (Quals.getObjCLifetime() == Qualifiers::OCL_Weak) | |||
| 2713 | mangleVendorQualifier("__weak"); | |||
| 2714 | ||||
| 2715 | // __unaligned (from -fms-extensions) | |||
| 2716 | if (Quals.hasUnaligned()) | |||
| 2717 | mangleVendorQualifier("__unaligned"); | |||
| 2718 | ||||
| 2719 | // Remaining ARC ownership qualifiers. | |||
| 2720 | switch (Quals.getObjCLifetime()) { | |||
| 2721 | case Qualifiers::OCL_None: | |||
| 2722 | break; | |||
| 2723 | ||||
| 2724 | case Qualifiers::OCL_Weak: | |||
| 2725 | // Do nothing as we already handled this case above. | |||
| 2726 | break; | |||
| 2727 | ||||
| 2728 | case Qualifiers::OCL_Strong: | |||
| 2729 | mangleVendorQualifier("__strong"); | |||
| 2730 | break; | |||
| 2731 | ||||
| 2732 | case Qualifiers::OCL_Autoreleasing: | |||
| 2733 | mangleVendorQualifier("__autoreleasing"); | |||
| 2734 | break; | |||
| 2735 | ||||
| 2736 | case Qualifiers::OCL_ExplicitNone: | |||
| 2737 | // The __unsafe_unretained qualifier is *not* mangled, so that | |||
| 2738 | // __unsafe_unretained types in ARC produce the same manglings as the | |||
| 2739 | // equivalent (but, naturally, unqualified) types in non-ARC, providing | |||
| 2740 | // better ABI compatibility. | |||
| 2741 | // | |||
| 2742 | // It's safe to do this because unqualified 'id' won't show up | |||
| 2743 | // in any type signatures that need to be mangled. | |||
| 2744 | break; | |||
| 2745 | } | |||
| 2746 | ||||
| 2747 | // <CV-qualifiers> ::= [r] [V] [K] # restrict (C99), volatile, const | |||
| 2748 | if (Quals.hasRestrict()) | |||
| 2749 | Out << 'r'; | |||
| 2750 | if (Quals.hasVolatile()) | |||
| 2751 | Out << 'V'; | |||
| 2752 | if (Quals.hasConst()) | |||
| 2753 | Out << 'K'; | |||
| 2754 | } | |||
| 2755 | ||||
| 2756 | void CXXNameMangler::mangleVendorQualifier(StringRef name) { | |||
| 2757 | Out << 'U' << name.size() << name; | |||
| 2758 | } | |||
| 2759 | ||||
| 2760 | void CXXNameMangler::mangleRefQualifier(RefQualifierKind RefQualifier) { | |||
| 2761 | // <ref-qualifier> ::= R # lvalue reference | |||
| 2762 | // ::= O # rvalue-reference | |||
| 2763 | switch (RefQualifier) { | |||
| 2764 | case RQ_None: | |||
| 2765 | break; | |||
| 2766 | ||||
| 2767 | case RQ_LValue: | |||
| 2768 | Out << 'R'; | |||
| 2769 | break; | |||
| 2770 | ||||
| 2771 | case RQ_RValue: | |||
| 2772 | Out << 'O'; | |||
| 2773 | break; | |||
| 2774 | } | |||
| 2775 | } | |||
| 2776 | ||||
| 2777 | void CXXNameMangler::mangleObjCMethodName(const ObjCMethodDecl *MD) { | |||
| 2778 | Context.mangleObjCMethodNameAsSourceName(MD, Out); | |||
| 2779 | } | |||
| 2780 | ||||
| 2781 | static bool isTypeSubstitutable(Qualifiers Quals, const Type *Ty, | |||
| 2782 | ASTContext &Ctx) { | |||
| 2783 | if (Quals) | |||
| 2784 | return true; | |||
| 2785 | if (Ty->isSpecificBuiltinType(BuiltinType::ObjCSel)) | |||
| 2786 | return true; | |||
| 2787 | if (Ty->isOpenCLSpecificType()) | |||
| 2788 | return true; | |||
| 2789 | if (Ty->isBuiltinType()) | |||
| 2790 | return false; | |||
| 2791 | // Through to Clang 6.0, we accidentally treated undeduced auto types as | |||
| 2792 | // substitution candidates. | |||
| 2793 | if (Ctx.getLangOpts().getClangABICompat() > LangOptions::ClangABI::Ver6 && | |||
| 2794 | isa<AutoType>(Ty)) | |||
| 2795 | return false; | |||
| 2796 | // A placeholder type for class template deduction is substitutable with | |||
| 2797 | // its corresponding template name; this is handled specially when mangling | |||
| 2798 | // the type. | |||
| 2799 | if (auto *DeducedTST = Ty->getAs<DeducedTemplateSpecializationType>()) | |||
| 2800 | if (DeducedTST->getDeducedType().isNull()) | |||
| 2801 | return false; | |||
| 2802 | return true; | |||
| 2803 | } | |||
| 2804 | ||||
| 2805 | void CXXNameMangler::mangleType(QualType T) { | |||
| 2806 | // If our type is instantiation-dependent but not dependent, we mangle | |||
| 2807 | // it as it was written in the source, removing any top-level sugar. | |||
| 2808 | // Otherwise, use the canonical type. | |||
| 2809 | // | |||
| 2810 | // FIXME: This is an approximation of the instantiation-dependent name | |||
| 2811 | // mangling rules, since we should really be using the type as written and | |||
| 2812 | // augmented via semantic analysis (i.e., with implicit conversions and | |||
| 2813 | // default template arguments) for any instantiation-dependent type. | |||
| 2814 | // Unfortunately, that requires several changes to our AST: | |||
| 2815 | // - Instantiation-dependent TemplateSpecializationTypes will need to be | |||
| 2816 | // uniqued, so that we can handle substitutions properly | |||
| 2817 | // - Default template arguments will need to be represented in the | |||
| 2818 | // TemplateSpecializationType, since they need to be mangled even though | |||
| 2819 | // they aren't written. | |||
| 2820 | // - Conversions on non-type template arguments need to be expressed, since | |||
| 2821 | // they can affect the mangling of sizeof/alignof. | |||
| 2822 | // | |||
| 2823 | // FIXME: This is wrong when mapping to the canonical type for a dependent | |||
| 2824 | // type discards instantiation-dependent portions of the type, such as for: | |||
| 2825 | // | |||
| 2826 | // template<typename T, int N> void f(T (&)[sizeof(N)]); | |||
| 2827 | // template<typename T> void f(T() throw(typename T::type)); (pre-C++17) | |||
| 2828 | // | |||
| 2829 | // It's also wrong in the opposite direction when instantiation-dependent, | |||
| 2830 | // canonically-equivalent types differ in some irrelevant portion of inner | |||
| 2831 | // type sugar. In such cases, we fail to form correct substitutions, eg: | |||
| 2832 | // | |||
| 2833 | // template<int N> void f(A<sizeof(N)> *, A<sizeof(N)> (*)); | |||
| 2834 | // | |||
| 2835 | // We should instead canonicalize the non-instantiation-dependent parts, | |||
| 2836 | // regardless of whether the type as a whole is dependent or instantiation | |||
| 2837 | // dependent. | |||
| 2838 | if (!T->isInstantiationDependentType() || T->isDependentType()) | |||
| 2839 | T = T.getCanonicalType(); | |||
| 2840 | else { | |||
| 2841 | // Desugar any types that are purely sugar. | |||
| 2842 | do { | |||
| 2843 | // Don't desugar through template specialization types that aren't | |||
| 2844 | // type aliases. We need to mangle the template arguments as written. | |||
| 2845 | if (const TemplateSpecializationType *TST | |||
| 2846 | = dyn_cast<TemplateSpecializationType>(T)) | |||
| 2847 | if (!TST->isTypeAlias()) | |||
| 2848 | break; | |||
| 2849 | ||||
| 2850 | // FIXME: We presumably shouldn't strip off ElaboratedTypes with | |||
| 2851 | // instantation-dependent qualifiers. See | |||
| 2852 | // https://github.com/itanium-cxx-abi/cxx-abi/issues/114. | |||
| 2853 | ||||
| 2854 | QualType Desugared | |||
| 2855 | = T.getSingleStepDesugaredType(Context.getASTContext()); | |||
| 2856 | if (Desugared == T) | |||
| 2857 | break; | |||
| 2858 | ||||
| 2859 | T = Desugared; | |||
| 2860 | } while (true); | |||
| 2861 | } | |||
| 2862 | SplitQualType split = T.split(); | |||
| 2863 | Qualifiers quals = split.Quals; | |||
| 2864 | const Type *ty = split.Ty; | |||
| 2865 | ||||
| 2866 | bool isSubstitutable = | |||
| 2867 | isTypeSubstitutable(quals, ty, Context.getASTContext()); | |||
| 2868 | if (isSubstitutable && mangleSubstitution(T)) | |||
| 2869 | return; | |||
| 2870 | ||||
| 2871 | // If we're mangling a qualified array type, push the qualifiers to | |||
| 2872 | // the element type. | |||
| 2873 | if (quals && isa<ArrayType>(T)) { | |||
| 2874 | ty = Context.getASTContext().getAsArrayType(T); | |||
| 2875 | quals = Qualifiers(); | |||
| 2876 | ||||
| 2877 | // Note that we don't update T: we want to add the | |||
| 2878 | // substitution at the original type. | |||
| 2879 | } | |||
| 2880 | ||||
| 2881 | if (quals || ty->isDependentAddressSpaceType()) { | |||
| 2882 | if (const DependentAddressSpaceType *DAST = | |||
| 2883 | dyn_cast<DependentAddressSpaceType>(ty)) { | |||
| 2884 | SplitQualType splitDAST = DAST->getPointeeType().split(); | |||
| 2885 | mangleQualifiers(splitDAST.Quals, DAST); | |||
| 2886 | mangleType(QualType(splitDAST.Ty, 0)); | |||
| 2887 | } else { | |||
| 2888 | mangleQualifiers(quals); | |||
| 2889 | ||||
| 2890 | // Recurse: even if the qualified type isn't yet substitutable, | |||
| 2891 | // the unqualified type might be. | |||
| 2892 | mangleType(QualType(ty, 0)); | |||
| 2893 | } | |||
| 2894 | } else { | |||
| 2895 | switch (ty->getTypeClass()) { | |||
| 2896 | #define ABSTRACT_TYPE(CLASS, PARENT) | |||
| 2897 | #define NON_CANONICAL_TYPE(CLASS, PARENT) \ | |||
| 2898 | case Type::CLASS: \ | |||
| 2899 | llvm_unreachable("can't mangle non-canonical type " #CLASS "Type")::llvm::llvm_unreachable_internal("can't mangle non-canonical type " #CLASS "Type", "clang/lib/AST/ItaniumMangle.cpp", 2899); \ | |||
| 2900 | return; | |||
| 2901 | #define TYPE(CLASS, PARENT) \ | |||
| 2902 | case Type::CLASS: \ | |||
| 2903 | mangleType(static_cast<const CLASS##Type*>(ty)); \ | |||
| 2904 | break; | |||
| 2905 | #include "clang/AST/TypeNodes.inc" | |||
| 2906 | } | |||
| 2907 | } | |||
| 2908 | ||||
| 2909 | // Add the substitution. | |||
| 2910 | if (isSubstitutable) | |||
| 2911 | addSubstitution(T); | |||
| 2912 | } | |||
| 2913 | ||||
| 2914 | void CXXNameMangler::mangleNameOrStandardSubstitution(const NamedDecl *ND) { | |||
| 2915 | if (!mangleStandardSubstitution(ND)) | |||
| 2916 | mangleName(ND); | |||
| 2917 | } | |||
| 2918 | ||||
| 2919 | void CXXNameMangler::mangleType(const BuiltinType *T) { | |||
| 2920 | // <type> ::= <builtin-type> | |||
| 2921 | // <builtin-type> ::= v # void | |||
| 2922 | // ::= w # wchar_t | |||
| 2923 | // ::= b # bool | |||
| 2924 | // ::= c # char | |||
| 2925 | // ::= a # signed char | |||
| 2926 | // ::= h # unsigned char | |||
| 2927 | // ::= s # short | |||
| 2928 | // ::= t # unsigned short | |||
| 2929 | // ::= i # int | |||
| 2930 | // ::= j # unsigned int | |||
| 2931 | // ::= l # long | |||
| 2932 | // ::= m # unsigned long | |||
| 2933 | // ::= x # long long, __int64 | |||
| 2934 | // ::= y # unsigned long long, __int64 | |||
| 2935 | // ::= n # __int128 | |||
| 2936 | // ::= o # unsigned __int128 | |||
| 2937 | // ::= f # float | |||
| 2938 | // ::= d # double | |||
| 2939 | // ::= e # long double, __float80 | |||
| 2940 | // ::= g # __float128 | |||
| 2941 | // ::= g # __ibm128 | |||
| 2942 | // UNSUPPORTED: ::= Dd # IEEE 754r decimal floating point (64 bits) | |||
| 2943 | // UNSUPPORTED: ::= De # IEEE 754r decimal floating point (128 bits) | |||
| 2944 | // UNSUPPORTED: ::= Df # IEEE 754r decimal floating point (32 bits) | |||
| 2945 | // ::= Dh # IEEE 754r half-precision floating point (16 bits) | |||
| 2946 | // ::= DF <number> _ # ISO/IEC TS 18661 binary floating point type _FloatN (N bits); | |||
| 2947 | // ::= Di # char32_t | |||
| 2948 | // ::= Ds # char16_t | |||
| 2949 | // ::= Dn # std::nullptr_t (i.e., decltype(nullptr)) | |||
| 2950 | // ::= u <source-name> # vendor extended type | |||
| 2951 | std::string type_name; | |||
| 2952 | // Normalize integer types as vendor extended types: | |||
| 2953 | // u<length>i<type size> | |||
| 2954 | // u<length>u<type size> | |||
| 2955 | if (NormalizeIntegers && T->isInteger()) { | |||
| 2956 | if (T->isSignedInteger()) { | |||
| 2957 | switch (getASTContext().getTypeSize(T)) { | |||
| 2958 | case 8: | |||
| 2959 | // Pick a representative for each integer size in the substitution | |||
| 2960 | // dictionary. (Its actual defined size is not relevant.) | |||
| 2961 | if (mangleSubstitution(BuiltinType::SChar)) | |||
| 2962 | break; | |||
| 2963 | Out << "u2i8"; | |||
| 2964 | addSubstitution(BuiltinType::SChar); | |||
| 2965 | break; | |||
| 2966 | case 16: | |||
| 2967 | if (mangleSubstitution(BuiltinType::Short)) | |||
| 2968 | break; | |||
| 2969 | Out << "u3i16"; | |||
| 2970 | addSubstitution(BuiltinType::Short); | |||
| 2971 | break; | |||
| 2972 | case 32: | |||
| 2973 | if (mangleSubstitution(BuiltinType::Int)) | |||
| 2974 | break; | |||
| 2975 | Out << "u3i32"; | |||
| 2976 | addSubstitution(BuiltinType::Int); | |||
| 2977 | break; | |||
| 2978 | case 64: | |||
| 2979 | if (mangleSubstitution(BuiltinType::Long)) | |||
| 2980 | break; | |||
| 2981 | Out << "u3i64"; | |||
| 2982 | addSubstitution(BuiltinType::Long); | |||
| 2983 | break; | |||
| 2984 | case 128: | |||
| 2985 | if (mangleSubstitution(BuiltinType::Int128)) | |||
| 2986 | break; | |||
| 2987 | Out << "u4i128"; | |||
| 2988 | addSubstitution(BuiltinType::Int128); | |||
| 2989 | break; | |||
| 2990 | default: | |||
| 2991 | llvm_unreachable("Unknown integer size for normalization")::llvm::llvm_unreachable_internal("Unknown integer size for normalization" , "clang/lib/AST/ItaniumMangle.cpp", 2991); | |||
| 2992 | } | |||
| 2993 | } else { | |||
| 2994 | switch (getASTContext().getTypeSize(T)) { | |||
| 2995 | case 8: | |||
| 2996 | if (mangleSubstitution(BuiltinType::UChar)) | |||
| 2997 | break; | |||
| 2998 | Out << "u2u8"; | |||
| 2999 | addSubstitution(BuiltinType::UChar); | |||
| 3000 | break; | |||
| 3001 | case 16: | |||
| 3002 | if (mangleSubstitution(BuiltinType::UShort)) | |||
| 3003 | break; | |||
| 3004 | Out << "u3u16"; | |||
| 3005 | addSubstitution(BuiltinType::UShort); | |||
| 3006 | break; | |||
| 3007 | case 32: | |||
| 3008 | if (mangleSubstitution(BuiltinType::UInt)) | |||
| 3009 | break; | |||
| 3010 | Out << "u3u32"; | |||
| 3011 | addSubstitution(BuiltinType::UInt); | |||
| 3012 | break; | |||
| 3013 | case 64: | |||
| 3014 | if (mangleSubstitution(BuiltinType::ULong)) | |||
| 3015 | break; | |||
| 3016 | Out << "u3u64"; | |||
| 3017 | addSubstitution(BuiltinType::ULong); | |||
| 3018 | break; | |||
| 3019 | case 128: | |||
| 3020 | if (mangleSubstitution(BuiltinType::UInt128)) | |||
| 3021 | break; | |||
| 3022 | Out << "u4u128"; | |||
| 3023 | addSubstitution(BuiltinType::UInt128); | |||
| 3024 | break; | |||
| 3025 | default: | |||
| 3026 | llvm_unreachable("Unknown integer size for normalization")::llvm::llvm_unreachable_internal("Unknown integer size for normalization" , "clang/lib/AST/ItaniumMangle.cpp", 3026); | |||
| 3027 | } | |||
| 3028 | } | |||
| 3029 | return; | |||
| 3030 | } | |||
| 3031 | switch (T->getKind()) { | |||
| 3032 | case BuiltinType::Void: | |||
| 3033 | Out << 'v'; | |||
| 3034 | break; | |||
| 3035 | case BuiltinType::Bool: | |||
| 3036 | Out << 'b'; | |||
| 3037 | break; | |||
| 3038 | case BuiltinType::Char_U: | |||
| 3039 | case BuiltinType::Char_S: | |||
| 3040 | Out << 'c'; | |||
| 3041 | break; | |||
| 3042 | case BuiltinType::UChar: | |||
| 3043 | Out << 'h'; | |||
| 3044 | break; | |||
| 3045 | case BuiltinType::UShort: | |||
| 3046 | Out << 't'; | |||
| 3047 | break; | |||
| 3048 | case BuiltinType::UInt: | |||
| 3049 | Out << 'j'; | |||
| 3050 | break; | |||
| 3051 | case BuiltinType::ULong: | |||
| 3052 | Out << 'm'; | |||
| 3053 | break; | |||
| 3054 | case BuiltinType::ULongLong: | |||
| 3055 | Out << 'y'; | |||
| 3056 | break; | |||
| 3057 | case BuiltinType::UInt128: | |||
| 3058 | Out << 'o'; | |||
| 3059 | break; | |||
| 3060 | case BuiltinType::SChar: | |||
| 3061 | Out << 'a'; | |||
| 3062 | break; | |||
| 3063 | case BuiltinType::WChar_S: | |||
| 3064 | case BuiltinType::WChar_U: | |||
| 3065 | Out << 'w'; | |||
| 3066 | break; | |||
| 3067 | case BuiltinType::Char8: | |||
| 3068 | Out << "Du"; | |||
| 3069 | break; | |||
| 3070 | case BuiltinType::Char16: | |||
| 3071 | Out << "Ds"; | |||
| 3072 | break; | |||
| 3073 | case BuiltinType::Char32: | |||
| 3074 | Out << "Di"; | |||
| 3075 | break; | |||
| 3076 | case BuiltinType::Short: | |||
| 3077 | Out << 's'; | |||
| 3078 | break; | |||
| 3079 | case BuiltinType::Int: | |||
| 3080 | Out << 'i'; | |||
| 3081 | break; | |||
| 3082 | case BuiltinType::Long: | |||
| 3083 | Out << 'l'; | |||
| 3084 | break; | |||
| 3085 | case BuiltinType::LongLong: | |||
| 3086 | Out << 'x'; | |||
| 3087 | break; | |||
| 3088 | case BuiltinType::Int128: | |||
| 3089 | Out << 'n'; | |||
| 3090 | break; | |||
| 3091 | case BuiltinType::Float16: | |||
| 3092 | Out << "DF16_"; | |||
| 3093 | break; | |||
| 3094 | case BuiltinType::ShortAccum: | |||
| 3095 | case BuiltinType::Accum: | |||
| 3096 | case BuiltinType::LongAccum: | |||
| 3097 | case BuiltinType::UShortAccum: | |||
| 3098 | case BuiltinType::UAccum: | |||
| 3099 | case BuiltinType::ULongAccum: | |||
| 3100 | case BuiltinType::ShortFract: | |||
| 3101 | case BuiltinType::Fract: | |||
| 3102 | case BuiltinType::LongFract: | |||
| 3103 | case BuiltinType::UShortFract: | |||
| 3104 | case BuiltinType::UFract: | |||
| 3105 | case BuiltinType::ULongFract: | |||
| 3106 | case BuiltinType::SatShortAccum: | |||
| 3107 | case BuiltinType::SatAccum: | |||
| 3108 | case BuiltinType::SatLongAccum: | |||
| 3109 | case BuiltinType::SatUShortAccum: | |||
| 3110 | case BuiltinType::SatUAccum: | |||
| 3111 | case BuiltinType::SatULongAccum: | |||
| 3112 | case BuiltinType::SatShortFract: | |||
| 3113 | case BuiltinType::SatFract: | |||
| 3114 | case BuiltinType::SatLongFract: | |||
| 3115 | case BuiltinType::SatUShortFract: | |||
| 3116 | case BuiltinType::SatUFract: | |||
| 3117 | case BuiltinType::SatULongFract: | |||
| 3118 | llvm_unreachable("Fixed point types are disabled for c++")::llvm::llvm_unreachable_internal("Fixed point types are disabled for c++" , "clang/lib/AST/ItaniumMangle.cpp", 3118); | |||
| 3119 | case BuiltinType::Half: | |||
| 3120 | Out << "Dh"; | |||
| 3121 | break; | |||
| 3122 | case BuiltinType::Float: | |||
| 3123 | Out << 'f'; | |||
| 3124 | break; | |||
| 3125 | case BuiltinType::Double: | |||
| 3126 | Out << 'd'; | |||
| 3127 | break; | |||
| 3128 | case BuiltinType::LongDouble: { | |||
| 3129 | const TargetInfo *TI = getASTContext().getLangOpts().OpenMP && | |||
| 3130 | getASTContext().getLangOpts().OpenMPIsDevice | |||
| 3131 | ? getASTContext().getAuxTargetInfo() | |||
| 3132 | : &getASTContext().getTargetInfo(); | |||
| 3133 | Out << TI->getLongDoubleMangling(); | |||
| 3134 | break; | |||
| 3135 | } | |||
| 3136 | case BuiltinType::Float128: { | |||
| 3137 | const TargetInfo *TI = getASTContext().getLangOpts().OpenMP && | |||
| 3138 | getASTContext().getLangOpts().OpenMPIsDevice | |||
| 3139 | ? getASTContext().getAuxTargetInfo() | |||
| 3140 | : &getASTContext().getTargetInfo(); | |||
| 3141 | Out << TI->getFloat128Mangling(); | |||
| 3142 | break; | |||
| 3143 | } | |||
| 3144 | case BuiltinType::BFloat16: { | |||
| 3145 | const TargetInfo *TI = ((getASTContext().getLangOpts().OpenMP && | |||
| 3146 | getASTContext().getLangOpts().OpenMPIsDevice) || | |||
| 3147 | getASTContext().getLangOpts().SYCLIsDevice) | |||
| 3148 | ? getASTContext().getAuxTargetInfo() | |||
| 3149 | : &getASTContext().getTargetInfo(); | |||
| 3150 | Out << TI->getBFloat16Mangling(); | |||
| 3151 | break; | |||
| 3152 | } | |||
| 3153 | case BuiltinType::Ibm128: { | |||
| 3154 | const TargetInfo *TI = &getASTContext().getTargetInfo(); | |||
| 3155 | Out << TI->getIbm128Mangling(); | |||
| 3156 | break; | |||
| 3157 | } | |||
| 3158 | case BuiltinType::NullPtr: | |||
| 3159 | Out << "Dn"; | |||
| 3160 | break; | |||
| 3161 | ||||
| 3162 | #define BUILTIN_TYPE(Id, SingletonId) | |||
| 3163 | #define PLACEHOLDER_TYPE(Id, SingletonId) \ | |||
| 3164 | case BuiltinType::Id: | |||
| 3165 | #include "clang/AST/BuiltinTypes.def" | |||
| 3166 | case BuiltinType::Dependent: | |||
| 3167 | if (!NullOut) | |||
| 3168 | llvm_unreachable("mangling a placeholder type")::llvm::llvm_unreachable_internal("mangling a placeholder type" , "clang/lib/AST/ItaniumMangle.cpp", 3168); | |||
| 3169 | break; | |||
| 3170 | case BuiltinType::ObjCId: | |||
| 3171 | Out << "11objc_object"; | |||
| 3172 | break; | |||
| 3173 | case BuiltinType::ObjCClass: | |||
| 3174 | Out << "10objc_class"; | |||
| 3175 | break; | |||
| 3176 | case BuiltinType::ObjCSel: | |||
| 3177 | Out << "13objc_selector"; | |||
| 3178 | break; | |||
| 3179 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ | |||
| 3180 | case BuiltinType::Id: \ | |||
| 3181 | type_name = "ocl_" #ImgType "_" #Suffix; \ | |||
| 3182 | Out << type_name.size() << type_name; \ | |||
| 3183 | break; | |||
| 3184 | #include "clang/Basic/OpenCLImageTypes.def" | |||
| 3185 | case BuiltinType::OCLSampler: | |||
| 3186 | Out << "11ocl_sampler"; | |||
| 3187 | break; | |||
| 3188 | case BuiltinType::OCLEvent: | |||
| 3189 | Out << "9ocl_event"; | |||
| 3190 | break; | |||
| 3191 | case BuiltinType::OCLClkEvent: | |||
| 3192 | Out << "12ocl_clkevent"; | |||
| 3193 | break; | |||
| 3194 | case BuiltinType::OCLQueue: | |||
| 3195 | Out << "9ocl_queue"; | |||
| 3196 | break; | |||
| 3197 | case BuiltinType::OCLReserveID: | |||
| 3198 | Out << "13ocl_reserveid"; | |||
| 3199 | break; | |||
| 3200 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ | |||
| 3201 | case BuiltinType::Id: \ | |||
| 3202 | type_name = "ocl_" #ExtType; \ | |||
| 3203 | Out << type_name.size() << type_name; \ | |||
| 3204 | break; | |||
| 3205 | #include "clang/Basic/OpenCLExtensionTypes.def" | |||
| 3206 | // The SVE types are effectively target-specific. The mangling scheme | |||
| 3207 | // is defined in the appendices to the Procedure Call Standard for the | |||
| 3208 | // Arm Architecture. | |||
| 3209 | #define SVE_VECTOR_TYPE(InternalName, MangledName, Id, SingletonId, NumEls, \ | |||
| 3210 | ElBits, IsSigned, IsFP, IsBF) \ | |||
| 3211 | case BuiltinType::Id: \ | |||
| 3212 | type_name = MangledName; \ | |||
| 3213 | Out << (type_name == InternalName ? "u" : "") << type_name.size() \ | |||
| 3214 | << type_name; \ | |||
| 3215 | break; | |||
| 3216 | #define SVE_PREDICATE_TYPE(InternalName, MangledName, Id, SingletonId, NumEls) \ | |||
| 3217 | case BuiltinType::Id: \ | |||
| 3218 | type_name = MangledName; \ | |||
| 3219 | Out << (type_name == InternalName ? "u" : "") << type_name.size() \ | |||
| 3220 | << type_name; \ | |||
| 3221 | break; | |||
| 3222 | #define SVE_OPAQUE_TYPE(InternalName, MangledName, Id, SingletonId) \ | |||
| 3223 | case BuiltinType::Id: \ | |||
| 3224 | type_name = MangledName; \ | |||
| 3225 | Out << (type_name == InternalName ? "u" : "") << type_name.size() \ | |||
| 3226 | << type_name; \ | |||
| 3227 | break; | |||
| 3228 | #include "clang/Basic/AArch64SVEACLETypes.def" | |||
| 3229 | #define PPC_VECTOR_TYPE(Name, Id, Size) \ | |||
| 3230 | case BuiltinType::Id: \ | |||
| 3231 | type_name = #Name; \ | |||
| 3232 | Out << 'u' << type_name.size() << type_name; \ | |||
| 3233 | break; | |||
| 3234 | #include "clang/Basic/PPCTypes.def" | |||
| 3235 | // TODO: Check the mangling scheme for RISC-V V. | |||
| 3236 | #define RVV_TYPE(Name, Id, SingletonId) \ | |||
| 3237 | case BuiltinType::Id: \ | |||
| 3238 | type_name = Name; \ | |||
| 3239 | Out << 'u' << type_name.size() << type_name; \ | |||
| 3240 | break; | |||
| 3241 | #include "clang/Basic/RISCVVTypes.def" | |||
| 3242 | #define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS) \ | |||
| 3243 | case BuiltinType::Id: \ | |||
| 3244 | type_name = MangledName; \ | |||
| 3245 | Out << 'u' << type_name.size() << type_name; \ | |||
| 3246 | break; | |||
| 3247 | #include "clang/Basic/WebAssemblyReferenceTypes.def" | |||
| 3248 | } | |||
| 3249 | } | |||
| 3250 | ||||
| 3251 | StringRef CXXNameMangler::getCallingConvQualifierName(CallingConv CC) { | |||
| 3252 | switch (CC) { | |||
| 3253 | case CC_C: | |||
| 3254 | return ""; | |||
| 3255 | ||||
| 3256 | case CC_X86VectorCall: | |||
| 3257 | case CC_X86Pascal: | |||
| 3258 | case CC_X86RegCall: | |||
| 3259 | case CC_AAPCS: | |||
| 3260 | case CC_AAPCS_VFP: | |||
| 3261 | case CC_AArch64VectorCall: | |||
| 3262 | case CC_AArch64SVEPCS: | |||
| 3263 | case CC_AMDGPUKernelCall: | |||
| 3264 | case CC_IntelOclBicc: | |||
| 3265 | case CC_SpirFunction: | |||
| 3266 | case CC_OpenCLKernel: | |||
| 3267 | case CC_PreserveMost: | |||
| 3268 | case CC_PreserveAll: | |||
| 3269 | // FIXME: we should be mangling all of the above. | |||
| 3270 | return ""; | |||
| 3271 | ||||
| 3272 | case CC_X86ThisCall: | |||
| 3273 | // FIXME: To match mingw GCC, thiscall should only be mangled in when it is | |||
| 3274 | // used explicitly. At this point, we don't have that much information in | |||
| 3275 | // the AST, since clang tends to bake the convention into the canonical | |||
| 3276 | // function type. thiscall only rarely used explicitly, so don't mangle it | |||
| 3277 | // for now. | |||
| 3278 | return ""; | |||
| 3279 | ||||
| 3280 | case CC_X86StdCall: | |||
| 3281 | return "stdcall"; | |||
| 3282 | case CC_X86FastCall: | |||
| 3283 | return "fastcall"; | |||
| 3284 | case CC_X86_64SysV: | |||
| 3285 | return "sysv_abi"; | |||
| 3286 | case CC_Win64: | |||
| 3287 | return "ms_abi"; | |||
| 3288 | case CC_Swift: | |||
| 3289 | return "swiftcall"; | |||
| 3290 | case CC_SwiftAsync: | |||
| 3291 | return "swiftasynccall"; | |||
| 3292 | } | |||
| 3293 | llvm_unreachable("bad calling convention")::llvm::llvm_unreachable_internal("bad calling convention", "clang/lib/AST/ItaniumMangle.cpp" , 3293); | |||
| 3294 | } | |||
| 3295 | ||||
| 3296 | void CXXNameMangler::mangleExtFunctionInfo(const FunctionType *T) { | |||
| 3297 | // Fast path. | |||
| 3298 | if (T->getExtInfo() == FunctionType::ExtInfo()) | |||
| 3299 | return; | |||
| 3300 | ||||
| 3301 | // Vendor-specific qualifiers are emitted in reverse alphabetical order. | |||
| 3302 | // This will get more complicated in the future if we mangle other | |||
| 3303 | // things here; but for now, since we mangle ns_returns_retained as | |||
| 3304 | // a qualifier on the result type, we can get away with this: | |||
| 3305 | StringRef CCQualifier = getCallingConvQualifierName(T->getExtInfo().getCC()); | |||
| 3306 | if (!CCQualifier.empty()) | |||
| 3307 | mangleVendorQualifier(CCQualifier); | |||
| 3308 | ||||
| 3309 | // FIXME: regparm | |||
| 3310 | // FIXME: noreturn | |||
| 3311 | } | |||
| 3312 | ||||
| 3313 | void | |||
| 3314 | CXXNameMangler::mangleExtParameterInfo(FunctionProtoType::ExtParameterInfo PI) { | |||
| 3315 | // Vendor-specific qualifiers are emitted in reverse alphabetical order. | |||
| 3316 | ||||
| 3317 | // Note that these are *not* substitution candidates. Demanglers might | |||
| 3318 | // have trouble with this if the parameter type is fully substituted. | |||
| 3319 | ||||
| 3320 | switch (PI.getABI()) { | |||
| 3321 | case ParameterABI::Ordinary: | |||
| 3322 | break; | |||
| 3323 | ||||
| 3324 | // All of these start with "swift", so they come before "ns_consumed". | |||
| 3325 | case ParameterABI::SwiftContext: | |||
| 3326 | case ParameterABI::SwiftAsyncContext: | |||
| 3327 | case ParameterABI::SwiftErrorResult: | |||
| 3328 | case ParameterABI::SwiftIndirectResult: | |||
| 3329 | mangleVendorQualifier(getParameterABISpelling(PI.getABI())); | |||
| 3330 | break; | |||
| 3331 | } | |||
| 3332 | ||||
| 3333 | if (PI.isConsumed()) | |||
| 3334 | mangleVendorQualifier("ns_consumed"); | |||
| 3335 | ||||
| 3336 | if (PI.isNoEscape()) | |||
| 3337 | mangleVendorQualifier("noescape"); | |||
| 3338 | } | |||
| 3339 | ||||
| 3340 | // <type> ::= <function-type> | |||
| 3341 | // <function-type> ::= [<CV-qualifiers>] F [Y] | |||
| 3342 | // <bare-function-type> [<ref-qualifier>] E | |||
| 3343 | void CXXNameMangler::mangleType(const FunctionProtoType *T) { | |||
| 3344 | mangleExtFunctionInfo(T); | |||
| 3345 | ||||
| 3346 | // Mangle CV-qualifiers, if present. These are 'this' qualifiers, | |||
| 3347 | // e.g. "const" in "int (A::*)() const". | |||
| 3348 | mangleQualifiers(T->getMethodQuals()); | |||
| 3349 | ||||
| 3350 | // Mangle instantiation-dependent exception-specification, if present, | |||
| 3351 | // per cxx-abi-dev proposal on 2016-10-11. | |||
| 3352 | if (T->hasInstantiationDependentExceptionSpec()) { | |||
| 3353 | if (isComputedNoexcept(T->getExceptionSpecType())) { | |||
| 3354 | Out << "DO"; | |||
| 3355 | mangleExpression(T->getNoexceptExpr()); | |||
| 3356 | Out << "E"; | |||
| 3357 | } else { | |||
| 3358 | assert(T->getExceptionSpecType() == EST_Dynamic)(static_cast <bool> (T->getExceptionSpecType() == EST_Dynamic ) ? void (0) : __assert_fail ("T->getExceptionSpecType() == EST_Dynamic" , "clang/lib/AST/ItaniumMangle.cpp", 3358, __extension__ __PRETTY_FUNCTION__ )); | |||
| 3359 | Out << "Dw"; | |||
| 3360 | for (auto ExceptTy : T->exceptions()) | |||
| 3361 | mangleType(ExceptTy); | |||
| 3362 | Out << "E"; | |||
| 3363 | } | |||
| 3364 | } else if (T->isNothrow()) { | |||
| 3365 | Out << "Do"; | |||
| 3366 | } | |||
| 3367 | ||||
| 3368 | Out << 'F'; | |||
| 3369 | ||||
| 3370 | // FIXME: We don't have enough information in the AST to produce the 'Y' | |||
| 3371 | // encoding for extern "C" function types. | |||
| 3372 | mangleBareFunctionType(T, /*MangleReturnType=*/true); | |||
| 3373 | ||||
| 3374 | // Mangle the ref-qualifier, if present. | |||
| 3375 | mangleRefQualifier(T->getRefQualifier()); | |||
| 3376 | ||||
| 3377 | Out << 'E'; | |||
| 3378 | } | |||
| 3379 | ||||
| 3380 | void CXXNameMangler::mangleType(const FunctionNoProtoType *T) { | |||
| 3381 | // Function types without prototypes can arise when mangling a function type | |||
| 3382 | // within an overloadable function in C. We mangle these as the absence of any | |||
| 3383 | // parameter types (not even an empty parameter list). | |||
| 3384 | Out << 'F'; | |||
| 3385 | ||||
| 3386 | FunctionTypeDepthState saved = FunctionTypeDepth.push(); | |||
| 3387 | ||||
| 3388 | FunctionTypeDepth.enterResultType(); | |||
| 3389 | mangleType(T->getReturnType()); | |||
| 3390 | FunctionTypeDepth.leaveResultType(); | |||
| 3391 | ||||
| 3392 | FunctionTypeDepth.pop(saved); | |||
| 3393 | Out << 'E'; | |||
| 3394 | } | |||
| 3395 | ||||
| 3396 | void CXXNameMangler::mangleBareFunctionType(const FunctionProtoType *Proto, | |||
| 3397 | bool MangleReturnType, | |||
| 3398 | const FunctionDecl *FD) { | |||
| 3399 | // Record that we're in a function type. See mangleFunctionParam | |||
| 3400 | // for details on what we're trying to achieve here. | |||
| 3401 | FunctionTypeDepthState saved = FunctionTypeDepth.push(); | |||
| 3402 | ||||
| 3403 | // <bare-function-type> ::= <signature type>+ | |||
| 3404 | if (MangleReturnType) { | |||
| 3405 | FunctionTypeDepth.enterResultType(); | |||
| 3406 | ||||
| 3407 | // Mangle ns_returns_retained as an order-sensitive qualifier here. | |||
| 3408 | if (Proto->getExtInfo().getProducesResult() && FD == nullptr) | |||
| 3409 | mangleVendorQualifier("ns_returns_retained"); | |||
| 3410 | ||||
| 3411 | // Mangle the return type without any direct ARC ownership qualifiers. | |||
| 3412 | QualType ReturnTy = Proto->getReturnType(); | |||
| 3413 | if (ReturnTy.getObjCLifetime()) { | |||
| 3414 | auto SplitReturnTy = ReturnTy.split(); | |||
| 3415 | SplitReturnTy.Quals.removeObjCLifetime(); | |||
| 3416 | ReturnTy = getASTContext().getQualifiedType(SplitReturnTy); | |||
| 3417 | } | |||
| 3418 | mangleType(ReturnTy); | |||
| 3419 | ||||
| 3420 | FunctionTypeDepth.leaveResultType(); | |||
| 3421 | } | |||
| 3422 | ||||
| 3423 | if (Proto->getNumParams() == 0 && !Proto->isVariadic()) { | |||
| 3424 | // <builtin-type> ::= v # void | |||
| 3425 | Out << 'v'; | |||
| 3426 | ||||
| 3427 | FunctionTypeDepth.pop(saved); | |||
| 3428 | return; | |||
| 3429 | } | |||
| 3430 | ||||
| 3431 | assert(!FD || FD->getNumParams() == Proto->getNumParams())(static_cast <bool> (!FD || FD->getNumParams() == Proto ->getNumParams()) ? void (0) : __assert_fail ("!FD || FD->getNumParams() == Proto->getNumParams()" , "clang/lib/AST/ItaniumMangle.cpp", 3431, __extension__ __PRETTY_FUNCTION__ )); | |||
| 3432 | for (unsigned I = 0, E = Proto->getNumParams(); I != E; ++I) { | |||
| 3433 | // Mangle extended parameter info as order-sensitive qualifiers here. | |||
| 3434 | if (Proto->hasExtParameterInfos() && FD == nullptr) { | |||
| 3435 | mangleExtParameterInfo(Proto->getExtParameterInfo(I)); | |||
| 3436 | } | |||
| 3437 | ||||
| 3438 | // Mangle the type. | |||
| 3439 | QualType ParamTy = Proto->getParamType(I); | |||
| 3440 | mangleType(Context.getASTContext().getSignatureParameterType(ParamTy)); | |||
| 3441 | ||||
| 3442 | if (FD) { | |||
| 3443 | if (auto *Attr = FD->getParamDecl(I)->getAttr<PassObjectSizeAttr>()) { | |||
| 3444 | // Attr can only take 1 character, so we can hardcode the length below. | |||
| 3445 | assert(Attr->getType() <= 9 && Attr->getType() >= 0)(static_cast <bool> (Attr->getType() <= 9 && Attr->getType() >= 0) ? void (0) : __assert_fail ("Attr->getType() <= 9 && Attr->getType() >= 0" , "clang/lib/AST/ItaniumMangle.cpp", 3445, __extension__ __PRETTY_FUNCTION__ )); | |||
| 3446 | if (Attr->isDynamic()) | |||
| 3447 | Out << "U25pass_dynamic_object_size" << Attr->getType(); | |||
| 3448 | else | |||
| 3449 | Out << "U17pass_object_size" << Attr->getType(); | |||
| 3450 | } | |||
| 3451 | } | |||
| 3452 | } | |||
| 3453 | ||||
| 3454 | FunctionTypeDepth.pop(saved); | |||
| 3455 | ||||
| 3456 | // <builtin-type> ::= z # ellipsis | |||
| 3457 | if (Proto->isVariadic()) | |||
| 3458 | Out << 'z'; | |||
| 3459 | } | |||
| 3460 | ||||
| 3461 | // <type> ::= <class-enum-type> | |||
| 3462 | // <class-enum-type> ::= <name> | |||
| 3463 | void CXXNameMangler::mangleType(const UnresolvedUsingType *T) { | |||
| 3464 | mangleName(T->getDecl()); | |||
| 3465 | } | |||
| 3466 | ||||
| 3467 | // <type> ::= <class-enum-type> | |||
| 3468 | // <class-enum-type> ::= <name> | |||
| 3469 | void CXXNameMangler::mangleType(const EnumType *T) { | |||
| 3470 | mangleType(static_cast<const TagType*>(T)); | |||
| 3471 | } | |||
| 3472 | void CXXNameMangler::mangleType(const RecordType *T) { | |||
| 3473 | mangleType(static_cast<const TagType*>(T)); | |||
| 3474 | } | |||
| 3475 | void CXXNameMangler::mangleType(const TagType *T) { | |||
| 3476 | mangleName(T->getDecl()); | |||
| 3477 | } | |||
| 3478 | ||||
| 3479 | // <type> ::= <array-type> | |||
| 3480 | // <array-type> ::= A <positive dimension number> _ <element type> | |||
| 3481 | // ::= A [<dimension expression>] _ <element type> | |||
| 3482 | void CXXNameMangler::mangleType(const ConstantArrayType *T) { | |||
| 3483 | Out << 'A' << T->getSize() << '_'; | |||
| 3484 | mangleType(T->getElementType()); | |||
| 3485 | } | |||
| 3486 | void CXXNameMangler::mangleType(const VariableArrayType *T) { | |||
| 3487 | Out << 'A'; | |||
| 3488 | // decayed vla types (size 0) will just be skipped. | |||
| 3489 | if (T->getSizeExpr()) | |||
| 3490 | mangleExpression(T->getSizeExpr()); | |||
| 3491 | Out << '_'; | |||
| 3492 | mangleType(T->getElementType()); | |||
| 3493 | } | |||
| 3494 | void CXXNameMangler::mangleType(const DependentSizedArrayType *T) { | |||
| 3495 | Out << 'A'; | |||
| 3496 | // A DependentSizedArrayType might not have size expression as below | |||
| 3497 | // | |||
| 3498 | // template<int ...N> int arr[] = {N...}; | |||
| 3499 | if (T->getSizeExpr()) | |||
| 3500 | mangleExpression(T->getSizeExpr()); | |||
| 3501 | Out << '_'; | |||
| 3502 | mangleType(T->getElementType()); | |||
| 3503 | } | |||
| 3504 | void CXXNameMangler::mangleType(const IncompleteArrayType *T) { | |||
| 3505 | Out << "A_"; | |||
| 3506 | mangleType(T->getElementType()); | |||
| 3507 | } | |||
| 3508 | ||||
| 3509 | // <type> ::= <pointer-to-member-type> | |||
| 3510 | // <pointer-to-member-type> ::= M <class type> <member type> | |||
| 3511 | void CXXNameMangler::mangleType(const MemberPointerType *T) { | |||
| 3512 | Out << 'M'; | |||
| 3513 | mangleType(QualType(T->getClass(), 0)); | |||
| 3514 | QualType PointeeType = T->getPointeeType(); | |||
| 3515 | if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) { | |||
| 3516 | mangleType(FPT); | |||
| 3517 | ||||
| 3518 | // Itanium C++ ABI 5.1.8: | |||
| 3519 | // | |||
| 3520 | // The type of a non-static member function is considered to be different, | |||
| 3521 | // for the purposes of substitution, from the type of a namespace-scope or | |||
| 3522 | // static member function whose type appears similar. The types of two | |||
| 3523 | // non-static member functions are considered to be different, for the | |||
| 3524 | // purposes of substitution, if the functions are members of different | |||
| 3525 | // classes. In other words, for the purposes of substitution, the class of | |||
| 3526 | // which the function is a member is considered part of the type of | |||
| 3527 | // function. | |||
| 3528 | ||||
| 3529 | // Given that we already substitute member function pointers as a | |||
| 3530 | // whole, the net effect of this rule is just to unconditionally | |||
| 3531 | // suppress substitution on the function type in a member pointer. | |||
| 3532 | // We increment the SeqID here to emulate adding an entry to the | |||
| 3533 | // substitution table. | |||
| 3534 | ++SeqID; | |||
| 3535 | } else | |||
| 3536 | mangleType(PointeeType); | |||
| 3537 | } | |||
| 3538 | ||||
| 3539 | // <type> ::= <template-param> | |||
| 3540 | void CXXNameMangler::mangleType(const TemplateTypeParmType *T) { | |||
| 3541 | mangleTemplateParameter(T->getDepth(), T->getIndex()); | |||
| 3542 | } | |||
| 3543 | ||||
| 3544 | // <type> ::= <template-param> | |||
| 3545 | void CXXNameMangler::mangleType(const SubstTemplateTypeParmPackType *T) { | |||
| 3546 | // FIXME: not clear how to mangle this! | |||
| 3547 | // template <class T...> class A { | |||
| 3548 | // template <class U...> void foo(T(*)(U) x...); | |||
| 3549 | // }; | |||
| 3550 | Out << "_SUBSTPACK_"; | |||
| 3551 | } | |||
| 3552 | ||||
| 3553 | // <type> ::= P <type> # pointer-to | |||
| 3554 | void CXXNameMangler::mangleType(const PointerType *T) { | |||
| 3555 | Out << 'P'; | |||
| 3556 | mangleType(T->getPointeeType()); | |||
| 3557 | } | |||
| 3558 | void CXXNameMangler::mangleType(const ObjCObjectPointerType *T) { | |||
| 3559 | Out << 'P'; | |||
| 3560 | mangleType(T->getPointeeType()); | |||
| 3561 | } | |||
| 3562 | ||||
| 3563 | // <type> ::= R <type> # reference-to | |||
| 3564 | void CXXNameMangler::mangleType(const LValueReferenceType *T) { | |||
| 3565 | Out << 'R'; | |||
| 3566 | mangleType(T->getPointeeType()); | |||
| 3567 | } | |||
| 3568 | ||||
| 3569 | // <type> ::= O <type> # rvalue reference-to (C++0x) | |||
| 3570 | void CXXNameMangler::mangleType(const RValueReferenceType *T) { | |||
| 3571 | Out << 'O'; | |||
| 3572 | mangleType(T->getPointeeType()); | |||
| 3573 | } | |||
| 3574 | ||||
| 3575 | // <type> ::= C <type> # complex pair (C 2000) | |||
| 3576 | void CXXNameMangler::mangleType(const ComplexType *T) { | |||
| 3577 | Out << 'C'; | |||
| 3578 | mangleType(T->getElementType()); | |||
| 3579 | } | |||
| 3580 | ||||
| 3581 | // ARM's ABI for Neon vector types specifies that they should be mangled as | |||
| 3582 | // if they are structs (to match ARM's initial implementation). The | |||
| 3583 | // vector type must be one of the special types predefined by ARM. | |||
| 3584 | void CXXNameMangler::mangleNeonVectorType(const VectorType *T) { | |||
| 3585 | QualType EltType = T->getElementType(); | |||
| 3586 | assert(EltType->isBuiltinType() && "Neon vector element not a BuiltinType")(static_cast <bool> (EltType->isBuiltinType() && "Neon vector element not a BuiltinType") ? void (0) : __assert_fail ("EltType->isBuiltinType() && \"Neon vector element not a BuiltinType\"" , "clang/lib/AST/ItaniumMangle.cpp", 3586, __extension__ __PRETTY_FUNCTION__ )); | |||
| 3587 | const char *EltName = nullptr; | |||
| 3588 | if (T->getVectorKind() == VectorType::NeonPolyVector) { | |||
| 3589 | switch (cast<BuiltinType>(EltType)->getKind()) { | |||
| 3590 | case BuiltinType::SChar: | |||
| 3591 | case BuiltinType::UChar: | |||
| 3592 | EltName = "poly8_t"; | |||
| 3593 | break; | |||
| 3594 | case BuiltinType::Short: | |||
| 3595 | case BuiltinType::UShort: | |||
| 3596 | EltName = "poly16_t"; | |||
| 3597 | break; | |||
| 3598 | case BuiltinType::LongLong: | |||
| 3599 | case BuiltinType::ULongLong: | |||
| 3600 | EltName = "poly64_t"; | |||
| 3601 | break; | |||
| 3602 | default: llvm_unreachable("unexpected Neon polynomial vector element type")::llvm::llvm_unreachable_internal("unexpected Neon polynomial vector element type" , "clang/lib/AST/ItaniumMangle.cpp", 3602); | |||
| 3603 | } | |||
| 3604 | } else { | |||
| 3605 | switch (cast<BuiltinType>(EltType)->getKind()) { | |||
| 3606 | case BuiltinType::SChar: EltName = "int8_t"; break; | |||
| 3607 | case BuiltinType::UChar: EltName = "uint8_t"; break; | |||
| 3608 | case BuiltinType::Short: EltName = "int16_t"; break; | |||
| 3609 | case BuiltinType::UShort: EltName = "uint16_t"; break; | |||
| 3610 | case BuiltinType::Int: EltName = "int32_t"; break; | |||
| 3611 | case BuiltinType::UInt: EltName = "uint32_t"; break; | |||
| 3612 | case BuiltinType::LongLong: EltName = "int64_t"; break; | |||
| 3613 | case BuiltinType::ULongLong: EltName = "uint64_t"; break; | |||
| 3614 | case BuiltinType::Double: EltName = "float64_t"; break; | |||
| 3615 | case BuiltinType::Float: EltName = "float32_t"; break; | |||
| 3616 | case BuiltinType::Half: EltName = "float16_t"; break; | |||
| 3617 | case BuiltinType::BFloat16: EltName = "bfloat16_t"; break; | |||
| 3618 | default: | |||
| 3619 | llvm_unreachable("unexpected Neon vector element type")::llvm::llvm_unreachable_internal("unexpected Neon vector element type" , "clang/lib/AST/ItaniumMangle.cpp", 3619); | |||
| 3620 | } | |||
| 3621 | } | |||
| 3622 | const char *BaseName = nullptr; | |||
| 3623 | unsigned BitSize = (T->getNumElements() * | |||
| 3624 | getASTContext().getTypeSize(EltType)); | |||
| 3625 | if (BitSize == 64) | |||
| 3626 | BaseName = "__simd64_"; | |||
| 3627 | else { | |||
| 3628 | assert(BitSize == 128 && "Neon vector type not 64 or 128 bits")(static_cast <bool> (BitSize == 128 && "Neon vector type not 64 or 128 bits" ) ? void (0) : __assert_fail ("BitSize == 128 && \"Neon vector type not 64 or 128 bits\"" , "clang/lib/AST/ItaniumMangle.cpp", 3628, __extension__ __PRETTY_FUNCTION__ )); | |||
| 3629 | BaseName = "__simd128_"; | |||
| 3630 | } | |||
| 3631 | Out << strlen(BaseName) + strlen(EltName); | |||
| 3632 | Out << BaseName << EltName; | |||
| 3633 | } | |||
| 3634 | ||||
| 3635 | void CXXNameMangler::mangleNeonVectorType(const DependentVectorType *T) { | |||
| 3636 | DiagnosticsEngine &Diags = Context.getDiags(); | |||
| 3637 | unsigned DiagID = Diags.getCustomDiagID( | |||
| 3638 | DiagnosticsEngine::Error, | |||
| 3639 | "cannot mangle this dependent neon vector type yet"); | |||
| 3640 | Diags.Report(T->getAttributeLoc(), DiagID); | |||
| 3641 | } | |||
| 3642 | ||||
| 3643 | static StringRef mangleAArch64VectorBase(const BuiltinType *EltType) { | |||
| 3644 | switch (EltType->getKind()) { | |||
| 3645 | case BuiltinType::SChar: | |||
| 3646 | return "Int8"; | |||
| 3647 | case BuiltinType::Short: | |||
| 3648 | return "Int16"; | |||
| 3649 | case BuiltinType::Int: | |||
| 3650 | return "Int32"; | |||
| 3651 | case BuiltinType::Long: | |||
| 3652 | case BuiltinType::LongLong: | |||
| 3653 | return "Int64"; | |||
| 3654 | case BuiltinType::UChar: | |||
| 3655 | return "Uint8"; | |||
| 3656 | case BuiltinType::UShort: | |||
| 3657 | return "Uint16"; | |||
| 3658 | case BuiltinType::UInt: | |||
| 3659 | return "Uint32"; | |||
| 3660 | case BuiltinType::ULong: | |||
| 3661 | case BuiltinType::ULongLong: | |||
| 3662 | return "Uint64"; | |||
| 3663 | case BuiltinType::Half: | |||
| 3664 | return "Float16"; | |||
| 3665 | case BuiltinType::Float: | |||
| 3666 | return "Float32"; | |||
| 3667 | case BuiltinType::Double: | |||
| 3668 | return "Float64"; | |||
| 3669 | case BuiltinType::BFloat16: | |||
| 3670 | return "Bfloat16"; | |||
| 3671 | default: | |||
| 3672 | llvm_unreachable("Unexpected vector element base type")::llvm::llvm_unreachable_internal("Unexpected vector element base type" , "clang/lib/AST/ItaniumMangle.cpp", 3672); | |||
| 3673 | } | |||
| 3674 | } | |||
| 3675 | ||||
| 3676 | // AArch64's ABI for Neon vector types specifies that they should be mangled as | |||
| 3677 | // the equivalent internal name. The vector type must be one of the special | |||
| 3678 | // types predefined by ARM. | |||
| 3679 | void CXXNameMangler::mangleAArch64NeonVectorType(const VectorType *T) { | |||
| 3680 | QualType EltType = T->getElementType(); | |||
| 3681 | assert(EltType->isBuiltinType() && "Neon vector element not a BuiltinType")(static_cast <bool> (EltType->isBuiltinType() && "Neon vector element not a BuiltinType") ? void (0) : __assert_fail ("EltType->isBuiltinType() && \"Neon vector element not a BuiltinType\"" , "clang/lib/AST/ItaniumMangle.cpp", 3681, __extension__ __PRETTY_FUNCTION__ )); | |||
| 3682 | unsigned BitSize = | |||
| 3683 | (T->getNumElements() * getASTContext().getTypeSize(EltType)); | |||
| 3684 | (void)BitSize; // Silence warning. | |||
| 3685 | ||||
| 3686 | assert((BitSize == 64 || BitSize == 128) &&(static_cast <bool> ((BitSize == 64 || BitSize == 128) && "Neon vector type not 64 or 128 bits") ? void (0) : __assert_fail ("(BitSize == 64 || BitSize == 128) && \"Neon vector type not 64 or 128 bits\"" , "clang/lib/AST/ItaniumMangle.cpp", 3687, __extension__ __PRETTY_FUNCTION__ )) | |||
| 3687 | "Neon vector type not 64 or 128 bits")(static_cast <bool> ((BitSize == 64 || BitSize == 128) && "Neon vector type not 64 or 128 bits") ? void (0) : __assert_fail ("(BitSize == 64 || BitSize == 128) && \"Neon vector type not 64 or 128 bits\"" , "clang/lib/AST/ItaniumMangle.cpp", 3687, __extension__ __PRETTY_FUNCTION__ )); | |||
| 3688 | ||||
| 3689 | StringRef EltName; | |||
| 3690 | if (T->getVectorKind() == VectorType::NeonPolyVector) { | |||
| 3691 | switch (cast<BuiltinType>(EltType)->getKind()) { | |||
| 3692 | case BuiltinType::UChar: | |||
| 3693 | EltName = "Poly8"; | |||
| 3694 | break; | |||
| 3695 | case BuiltinType::UShort: | |||
| 3696 | EltName = "Poly16"; | |||
| 3697 | break; | |||
| 3698 | case BuiltinType::ULong: | |||
| 3699 | case BuiltinType::ULongLong: | |||
| 3700 | EltName = "Poly64"; | |||
| 3701 | break; | |||
| 3702 | default: | |||
| 3703 | llvm_unreachable("unexpected Neon polynomial vector element type")::llvm::llvm_unreachable_internal("unexpected Neon polynomial vector element type" , "clang/lib/AST/ItaniumMangle.cpp", 3703); | |||
| 3704 | } | |||
| 3705 | } else | |||
| 3706 | EltName = mangleAArch64VectorBase(cast<BuiltinType>(EltType)); | |||
| 3707 | ||||
| 3708 | std::string TypeName = | |||
| 3709 | ("__" + EltName + "x" + Twine(T->getNumElements()) + "_t").str(); | |||
| 3710 | Out << TypeName.length() << TypeName; | |||
| 3711 | } | |||
| 3712 | void CXXNameMangler::mangleAArch64NeonVectorType(const DependentVectorType *T) { | |||
| 3713 | DiagnosticsEngine &Diags = Context.getDiags(); | |||
| 3714 | unsigned DiagID = Diags.getCustomDiagID( | |||
| 3715 | DiagnosticsEngine::Error, | |||
| 3716 | "cannot mangle this dependent neon vector type yet"); | |||
| 3717 | Diags.Report(T->getAttributeLoc(), DiagID); | |||
| 3718 | } | |||
| 3719 | ||||
| 3720 | // The AArch64 ACLE specifies that fixed-length SVE vector and predicate types | |||
| 3721 | // defined with the 'arm_sve_vector_bits' attribute map to the same AAPCS64 | |||
| 3722 | // type as the sizeless variants. | |||
| 3723 | // | |||
| 3724 | // The mangling scheme for VLS types is implemented as a "pseudo" template: | |||
| 3725 | // | |||
| 3726 | // '__SVE_VLS<<type>, <vector length>>' | |||
| 3727 | // | |||
| 3728 | // Combining the existing SVE type and a specific vector length (in bits). | |||
| 3729 | // For example: | |||
| 3730 | // | |||
| 3731 | // typedef __SVInt32_t foo __attribute__((arm_sve_vector_bits(512))); | |||
| 3732 | // | |||
| 3733 | // is described as '__SVE_VLS<__SVInt32_t, 512u>' and mangled as: | |||
| 3734 | // | |||
| 3735 | // "9__SVE_VLSI" + base type mangling + "Lj" + __ARM_FEATURE_SVE_BITS + "EE" | |||
| 3736 | // | |||
| 3737 | // i.e. 9__SVE_VLSIu11__SVInt32_tLj512EE | |||
| 3738 | // | |||
| 3739 | // The latest ACLE specification (00bet5) does not contain details of this | |||
| 3740 | // mangling scheme, it will be specified in the next revision. The mangling | |||
| 3741 | // scheme is otherwise defined in the appendices to the Procedure Call Standard | |||
| 3742 | // for the Arm Architecture, see | |||
| 3743 | // https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#appendix-c-mangling | |||
| 3744 | void CXXNameMangler::mangleAArch64FixedSveVectorType(const VectorType *T) { | |||
| 3745 | assert((T->getVectorKind() == VectorType::SveFixedLengthDataVector ||(static_cast <bool> ((T->getVectorKind() == VectorType ::SveFixedLengthDataVector || T->getVectorKind() == VectorType ::SveFixedLengthPredicateVector) && "expected fixed-length SVE vector!" ) ? void (0) : __assert_fail ("(T->getVectorKind() == VectorType::SveFixedLengthDataVector || T->getVectorKind() == VectorType::SveFixedLengthPredicateVector) && \"expected fixed-length SVE vector!\"" , "clang/lib/AST/ItaniumMangle.cpp", 3747, __extension__ __PRETTY_FUNCTION__ )) | |||
| 3746 | T->getVectorKind() == VectorType::SveFixedLengthPredicateVector) &&(static_cast <bool> ((T->getVectorKind() == VectorType ::SveFixedLengthDataVector || T->getVectorKind() == VectorType ::SveFixedLengthPredicateVector) && "expected fixed-length SVE vector!" ) ? void (0) : __assert_fail ("(T->getVectorKind() == VectorType::SveFixedLengthDataVector || T->getVectorKind() == VectorType::SveFixedLengthPredicateVector) && \"expected fixed-length SVE vector!\"" , "clang/lib/AST/ItaniumMangle.cpp", 3747, __extension__ __PRETTY_FUNCTION__ )) | |||
| 3747 | "expected fixed-length SVE vector!")(static_cast <bool> ((T->getVectorKind() == VectorType ::SveFixedLengthDataVector || T->getVectorKind() == VectorType ::SveFixedLengthPredicateVector) && "expected fixed-length SVE vector!" ) ? void (0) : __assert_fail ("(T->getVectorKind() == VectorType::SveFixedLengthDataVector || T->getVectorKind() == VectorType::SveFixedLengthPredicateVector) && \"expected fixed-length SVE vector!\"" , "clang/lib/AST/ItaniumMangle.cpp", 3747, __extension__ __PRETTY_FUNCTION__ )); | |||
| 3748 | ||||
| 3749 | QualType EltType = T->getElementType(); | |||
| 3750 | assert(EltType->isBuiltinType() &&(static_cast <bool> (EltType->isBuiltinType() && "expected builtin type for fixed-length SVE vector!") ? void (0) : __assert_fail ("EltType->isBuiltinType() && \"expected builtin type for fixed-length SVE vector!\"" , "clang/lib/AST/ItaniumMangle.cpp", 3751, __extension__ __PRETTY_FUNCTION__ )) | |||
| 3751 | "expected builtin type for fixed-length SVE vector!")(static_cast <bool> (EltType->isBuiltinType() && "expected builtin type for fixed-length SVE vector!") ? void (0) : __assert_fail ("EltType->isBuiltinType() && \"expected builtin type for fixed-length SVE vector!\"" , "clang/lib/AST/ItaniumMangle.cpp", 3751, __extension__ __PRETTY_FUNCTION__ )); | |||
| 3752 | ||||
| 3753 | StringRef TypeName; | |||
| 3754 | switch (cast<BuiltinType>(EltType)->getKind()) { | |||
| 3755 | case BuiltinType::SChar: | |||
| 3756 | TypeName = "__SVInt8_t"; | |||
| 3757 | break; | |||
| 3758 | case BuiltinType::UChar: { | |||
| 3759 | if (T->getVectorKind() == VectorType::SveFixedLengthDataVector) | |||
| 3760 | TypeName = "__SVUint8_t"; | |||
| 3761 | else | |||
| 3762 | TypeName = "__SVBool_t"; | |||
| 3763 | break; | |||
| 3764 | } | |||
| 3765 | case BuiltinType::Short: | |||
| 3766 | TypeName = "__SVInt16_t"; | |||
| 3767 | break; | |||
| 3768 | case BuiltinType::UShort: | |||
| 3769 | TypeName = "__SVUint16_t"; | |||
| 3770 | break; | |||
| 3771 | case BuiltinType::Int: | |||
| 3772 | TypeName = "__SVInt32_t"; | |||
| 3773 | break; | |||
| 3774 | case BuiltinType::UInt: | |||
| 3775 | TypeName = "__SVUint32_t"; | |||
| 3776 | break; | |||
| 3777 | case BuiltinType::Long: | |||
| 3778 | TypeName = "__SVInt64_t"; | |||
| 3779 | break; | |||
| 3780 | case BuiltinType::ULong: | |||
| 3781 | TypeName = "__SVUint64_t"; | |||
| 3782 | break; | |||
| 3783 | case BuiltinType::Half: | |||
| 3784 | TypeName = "__SVFloat16_t"; | |||
| 3785 | break; | |||
| 3786 | case BuiltinType::Float: | |||
| 3787 | TypeName = "__SVFloat32_t"; | |||
| 3788 | break; | |||
| 3789 | case BuiltinType::Double: | |||
| 3790 | TypeName = "__SVFloat64_t"; | |||
| 3791 | break; | |||
| 3792 | case BuiltinType::BFloat16: | |||
| 3793 | TypeName = "__SVBfloat16_t"; | |||
| 3794 | break; | |||
| 3795 | default: | |||
| 3796 | llvm_unreachable("unexpected element type for fixed-length SVE vector!")::llvm::llvm_unreachable_internal("unexpected element type for fixed-length SVE vector!" , "clang/lib/AST/ItaniumMangle.cpp", 3796); | |||
| 3797 | } | |||
| 3798 | ||||
| 3799 | unsigned VecSizeInBits = getASTContext().getTypeInfo(T).Width; | |||
| 3800 | ||||
| 3801 | if (T->getVectorKind() == VectorType::SveFixedLengthPredicateVector) | |||
| 3802 | VecSizeInBits *= 8; | |||
| 3803 | ||||
| 3804 | Out << "9__SVE_VLSI" << 'u' << TypeName.size() << TypeName << "Lj" | |||
| 3805 | << VecSizeInBits << "EE"; | |||
| 3806 | } | |||
| 3807 | ||||
| 3808 | void CXXNameMangler::mangleAArch64FixedSveVectorType( | |||
| 3809 | const DependentVectorType *T) { | |||
| 3810 | DiagnosticsEngine &Diags = Context.getDiags(); | |||
| 3811 | unsigned DiagID = Diags.getCustomDiagID( | |||
| 3812 | DiagnosticsEngine::Error, | |||
| 3813 | "cannot mangle this dependent fixed-length SVE vector type yet"); | |||
| 3814 | Diags.Report(T->getAttributeLoc(), DiagID); | |||
| 3815 | } | |||
| 3816 | ||||
| 3817 | void CXXNameMangler::mangleRISCVFixedRVVVectorType(const VectorType *T) { | |||
| 3818 | assert(T->getVectorKind() == VectorType::RVVFixedLengthDataVector &&(static_cast <bool> (T->getVectorKind() == VectorType ::RVVFixedLengthDataVector && "expected fixed-length RVV vector!" ) ? void (0) : __assert_fail ("T->getVectorKind() == VectorType::RVVFixedLengthDataVector && \"expected fixed-length RVV vector!\"" , "clang/lib/AST/ItaniumMangle.cpp", 3819, __extension__ __PRETTY_FUNCTION__ )) | |||
| 3819 | "expected fixed-length RVV vector!")(static_cast <bool> (T->getVectorKind() == VectorType ::RVVFixedLengthDataVector && "expected fixed-length RVV vector!" ) ? void (0) : __assert_fail ("T->getVectorKind() == VectorType::RVVFixedLengthDataVector && \"expected fixed-length RVV vector!\"" , "clang/lib/AST/ItaniumMangle.cpp", 3819, __extension__ __PRETTY_FUNCTION__ )); | |||
| 3820 | ||||
| 3821 | QualType EltType = T->getElementType(); | |||
| 3822 | assert(EltType->isBuiltinType() &&(static_cast <bool> (EltType->isBuiltinType() && "expected builtin type for fixed-length RVV vector!") ? void (0) : __assert_fail ("EltType->isBuiltinType() && \"expected builtin type for fixed-length RVV vector!\"" , "clang/lib/AST/ItaniumMangle.cpp", 3823, __extension__ __PRETTY_FUNCTION__ )) | |||
| 3823 | "expected builtin type for fixed-length RVV vector!")(static_cast <bool> (EltType->isBuiltinType() && "expected builtin type for fixed-length RVV vector!") ? void (0) : __assert_fail ("EltType->isBuiltinType() && \"expected builtin type for fixed-length RVV vector!\"" , "clang/lib/AST/ItaniumMangle.cpp", 3823, __extension__ __PRETTY_FUNCTION__ )); | |||
| 3824 | ||||
| 3825 | StringRef TypeName; | |||
| 3826 | switch (cast<BuiltinType>(EltType)->getKind()) { | |||
| 3827 | case BuiltinType::SChar: | |||
| 3828 | TypeName = "__rvv_int8m1_t"; | |||
| 3829 | break; | |||
| 3830 | case BuiltinType::UChar: | |||
| 3831 | TypeName = "__rvv_uint8m1_t"; | |||
| 3832 | break; | |||
| 3833 | case BuiltinType::Short: | |||
| 3834 | TypeName = "__rvv_int16m1_t"; | |||
| 3835 | break; | |||
| 3836 | case BuiltinType::UShort: | |||
| 3837 | TypeName = "__rvv_uint16m1_t"; | |||
| 3838 | break; | |||
| 3839 | case BuiltinType::Int: | |||
| 3840 | TypeName = "__rvv_int32m1_t"; | |||
| 3841 | break; | |||
| 3842 | case BuiltinType::UInt: | |||
| 3843 | TypeName = "__rvv_uint32m1_t"; | |||
| 3844 | break; | |||
| 3845 | case BuiltinType::Long: | |||
| 3846 | TypeName = "__rvv_int64m1_t"; | |||
| 3847 | break; | |||
| 3848 | case BuiltinType::ULong: | |||
| 3849 | TypeName = "__rvv_uint64m1_t"; | |||
| 3850 | break; | |||
| 3851 | case BuiltinType::Half: | |||
| 3852 | TypeName = "__rvv_float16m1_t"; | |||
| 3853 | break; | |||
| 3854 | case BuiltinType::Float: | |||
| 3855 | TypeName = "__rvv_float32m1_t"; | |||
| 3856 | break; | |||
| 3857 | case BuiltinType::Double: | |||
| 3858 | TypeName = "__rvv_float64m1_t"; | |||
| 3859 | break; | |||
| 3860 | default: | |||
| 3861 | llvm_unreachable("unexpected element type for fixed-length RVV vector!")::llvm::llvm_unreachable_internal("unexpected element type for fixed-length RVV vector!" , "clang/lib/AST/ItaniumMangle.cpp", 3861); | |||
| 3862 | } | |||
| 3863 | ||||
| 3864 | unsigned VecSizeInBits = getASTContext().getTypeInfo(T).Width; | |||
| 3865 | ||||
| 3866 | Out << "9__RVV_VLSI" << 'u' << TypeName.size() << TypeName << "Lj" | |||
| 3867 | << VecSizeInBits << "EE"; | |||
| 3868 | } | |||
| 3869 | ||||
| 3870 | void CXXNameMangler::mangleRISCVFixedRVVVectorType( | |||
| 3871 | const DependentVectorType *T) { | |||
| 3872 | DiagnosticsEngine &Diags = Context.getDiags(); | |||
| 3873 | unsigned DiagID = Diags.getCustomDiagID( | |||
| 3874 | DiagnosticsEngine::Error, | |||
| 3875 | "cannot mangle this dependent fixed-length RVV vector type yet"); | |||
| 3876 | Diags.Report(T->getAttributeLoc(), DiagID); | |||
| 3877 | } | |||
| 3878 | ||||
| 3879 | // GNU extension: vector types | |||
| 3880 | // <type> ::= <vector-type> | |||
| 3881 | // <vector-type> ::= Dv <positive dimension number> _ | |||
| 3882 | // <extended element type> | |||
| 3883 | // ::= Dv [<dimension expression>] _ <element type> | |||
| 3884 | // <extended element type> ::= <element type> | |||
| 3885 | // ::= p # AltiVec vector pixel | |||
| 3886 | // ::= b # Altivec vector bool | |||
| 3887 | void CXXNameMangler::mangleType(const VectorType *T) { | |||
| 3888 | if ((T->getVectorKind() == VectorType::NeonVector || | |||
| 3889 | T->getVectorKind() == VectorType::NeonPolyVector)) { | |||
| 3890 | llvm::Triple Target = getASTContext().getTargetInfo().getTriple(); | |||
| 3891 | llvm::Triple::ArchType Arch = | |||
| 3892 | getASTContext().getTargetInfo().getTriple().getArch(); | |||
| 3893 | if ((Arch == llvm::Triple::aarch64 || | |||
| 3894 | Arch == llvm::Triple::aarch64_be) && !Target.isOSDarwin()) | |||
| 3895 | mangleAArch64NeonVectorType(T); | |||
| 3896 | else | |||
| 3897 | mangleNeonVectorType(T); | |||
| 3898 | return; | |||
| 3899 | } else if (T->getVectorKind() == VectorType::SveFixedLengthDataVector || | |||
| 3900 | T->getVectorKind() == VectorType::SveFixedLengthPredicateVector) { | |||
| 3901 | mangleAArch64FixedSveVectorType(T); | |||
| 3902 | return; | |||
| 3903 | } else if (T->getVectorKind() == VectorType::RVVFixedLengthDataVector) { | |||
| 3904 | mangleRISCVFixedRVVVectorType(T); | |||
| 3905 | return; | |||
| 3906 | } | |||
| 3907 | Out << "Dv" << T->getNumElements() << '_'; | |||
| 3908 | if (T->getVectorKind() == VectorType::AltiVecPixel) | |||
| 3909 | Out << 'p'; | |||
| 3910 | else if (T->getVectorKind() == VectorType::AltiVecBool) | |||
| 3911 | Out << 'b'; | |||
| 3912 | else | |||
| 3913 | mangleType(T->getElementType()); | |||
| 3914 | } | |||
| 3915 | ||||
| 3916 | void CXXNameMangler::mangleType(const DependentVectorType *T) { | |||
| 3917 | if ((T->getVectorKind() == VectorType::NeonVector || | |||
| 3918 | T->getVectorKind() == VectorType::NeonPolyVector)) { | |||
| 3919 | llvm::Triple Target = getASTContext().getTargetInfo().getTriple(); | |||
| 3920 | llvm::Triple::ArchType Arch = | |||
| 3921 | getASTContext().getTargetInfo().getTriple().getArch(); | |||
| 3922 | if ((Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::aarch64_be) && | |||
| 3923 | !Target.isOSDarwin()) | |||
| 3924 | mangleAArch64NeonVectorType(T); | |||
| 3925 | else | |||
| 3926 | mangleNeonVectorType(T); | |||
| 3927 | return; | |||
| 3928 | } else if (T->getVectorKind() == VectorType::SveFixedLengthDataVector || | |||
| 3929 | T->getVectorKind() == VectorType::SveFixedLengthPredicateVector) { | |||
| 3930 | mangleAArch64FixedSveVectorType(T); | |||
| 3931 | return; | |||
| 3932 | } else if (T->getVectorKind() == VectorType::RVVFixedLengthDataVector) { | |||
| 3933 | mangleRISCVFixedRVVVectorType(T); | |||
| 3934 | return; | |||
| 3935 | } | |||
| 3936 | ||||
| 3937 | Out << "Dv"; | |||
| 3938 | mangleExpression(T->getSizeExpr()); | |||
| 3939 | Out << '_'; | |||
| 3940 | if (T->getVectorKind() == VectorType::AltiVecPixel) | |||
| 3941 | Out << 'p'; | |||
| 3942 | else if (T->getVectorKind() == VectorType::AltiVecBool) | |||
| 3943 | Out << 'b'; | |||
| 3944 | else | |||
| 3945 | mangleType(T->getElementType()); | |||
| 3946 | } | |||
| 3947 | ||||
| 3948 | void CXXNameMangler::mangleType(const ExtVectorType *T) { | |||
| 3949 | mangleType(static_cast<const VectorType*>(T)); | |||
| 3950 | } | |||
| 3951 | void CXXNameMangler::mangleType(const DependentSizedExtVectorType *T) { | |||
| 3952 | Out << "Dv"; | |||
| 3953 | mangleExpression(T->getSizeExpr()); | |||
| 3954 | Out << '_'; | |||
| 3955 | mangleType(T->getElementType()); | |||
| 3956 | } | |||
| 3957 | ||||
| 3958 | void CXXNameMangler::mangleType(const ConstantMatrixType *T) { | |||
| 3959 | // Mangle matrix types as a vendor extended type: | |||
| 3960 | // u<Len>matrix_typeI<Rows><Columns><element type>E | |||
| 3961 | ||||
| 3962 | StringRef VendorQualifier = "matrix_type"; | |||
| 3963 | Out << "u" << VendorQualifier.size() << VendorQualifier; | |||
| 3964 | ||||
| 3965 | Out << "I"; | |||
| 3966 | auto &ASTCtx = getASTContext(); | |||
| 3967 | unsigned BitWidth = ASTCtx.getTypeSize(ASTCtx.getSizeType()); | |||
| 3968 | llvm::APSInt Rows(BitWidth); | |||
| 3969 | Rows = T->getNumRows(); | |||
| 3970 | mangleIntegerLiteral(ASTCtx.getSizeType(), Rows); | |||
| 3971 | llvm::APSInt Columns(BitWidth); | |||
| 3972 | Columns = T->getNumColumns(); | |||
| 3973 | mangleIntegerLiteral(ASTCtx.getSizeType(), Columns); | |||
| 3974 | mangleType(T->getElementType()); | |||
| 3975 | Out << "E"; | |||
| 3976 | } | |||
| 3977 | ||||
| 3978 | void CXXNameMangler::mangleType(const DependentSizedMatrixType *T) { | |||
| 3979 | // Mangle matrix types as a vendor extended type: | |||
| 3980 | // u<Len>matrix_typeI<row expr><column expr><element type>E | |||
| 3981 | StringRef VendorQualifier = "matrix_type"; | |||
| 3982 | Out << "u" << VendorQualifier.size() << VendorQualifier; | |||
| 3983 | ||||
| 3984 | Out << "I"; | |||
| 3985 | mangleTemplateArgExpr(T->getRowExpr()); | |||
| 3986 | mangleTemplateArgExpr(T->getColumnExpr()); | |||
| 3987 | mangleType(T->getElementType()); | |||
| 3988 | Out << "E"; | |||
| 3989 | } | |||
| 3990 | ||||
| 3991 | void CXXNameMangler::mangleType(const DependentAddressSpaceType *T) { | |||
| 3992 | SplitQualType split = T->getPointeeType().split(); | |||
| 3993 | mangleQualifiers(split.Quals, T); | |||
| 3994 | mangleType(QualType(split.Ty, 0)); | |||
| 3995 | } | |||
| 3996 | ||||
| 3997 | void CXXNameMangler::mangleType(const PackExpansionType *T) { | |||
| 3998 | // <type> ::= Dp <type> # pack expansion (C++0x) | |||
| 3999 | Out << "Dp"; | |||
| 4000 | mangleType(T->getPattern()); | |||
| 4001 | } | |||
| 4002 | ||||
| 4003 | void CXXNameMangler::mangleType(const ObjCInterfaceType *T) { | |||
| 4004 | mangleSourceName(T->getDecl()->getIdentifier()); | |||
| 4005 | } | |||
| 4006 | ||||
| 4007 | void CXXNameMangler::mangleType(const ObjCObjectType *T) { | |||
| 4008 | // Treat __kindof as a vendor extended type qualifier. | |||
| 4009 | if (T->isKindOfType()) | |||
| 4010 | Out << "U8__kindof"; | |||
| 4011 | ||||
| 4012 | if (!T->qual_empty()) { | |||
| 4013 | // Mangle protocol qualifiers. | |||
| 4014 | SmallString<64> QualStr; | |||
| 4015 | llvm::raw_svector_ostream QualOS(QualStr); | |||
| 4016 | QualOS << "objcproto"; | |||
| 4017 | for (const auto *I : T->quals()) { | |||
| 4018 | StringRef name = I->getName(); | |||
| 4019 | QualOS << name.size() << name; | |||
| 4020 | } | |||
| 4021 | Out << 'U' << QualStr.size() << QualStr; | |||
| 4022 | } | |||
| 4023 | ||||
| 4024 | mangleType(T->getBaseType()); | |||
| 4025 | ||||
| 4026 | if (T->isSpecialized()) { | |||
| 4027 | // Mangle type arguments as I <type>+ E | |||
| 4028 | Out << 'I'; | |||
| 4029 | for (auto typeArg : T->getTypeArgs()) | |||
| 4030 | mangleType(typeArg); | |||
| 4031 | Out << 'E'; | |||
| 4032 | } | |||
| 4033 | } | |||
| 4034 | ||||
| 4035 | void CXXNameMangler::mangleType(const BlockPointerType *T) { | |||
| 4036 | Out << "U13block_pointer"; | |||
| 4037 | mangleType(T->getPointeeType()); | |||
| 4038 | } | |||
| 4039 | ||||
| 4040 | void CXXNameMangler::mangleType(const InjectedClassNameType *T) { | |||
| 4041 | // Mangle injected class name types as if the user had written the | |||
| 4042 | // specialization out fully. It may not actually be possible to see | |||
| 4043 | // this mangling, though. | |||
| 4044 | mangleType(T->getInjectedSpecializationType()); | |||
| 4045 | } | |||
| 4046 | ||||
| 4047 | void CXXNameMangler::mangleType(const TemplateSpecializationType *T) { | |||
| 4048 | if (TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl()) { | |||
| 4049 | mangleTemplateName(TD, T->template_arguments()); | |||
| 4050 | } else { | |||
| 4051 | if (mangleSubstitution(QualType(T, 0))) | |||
| 4052 | return; | |||
| 4053 | ||||
| 4054 | mangleTemplatePrefix(T->getTemplateName()); | |||
| 4055 | ||||
| 4056 | // FIXME: GCC does not appear to mangle the template arguments when | |||
| 4057 | // the template in question is a dependent template name. Should we | |||
| 4058 | // emulate that badness? | |||
| 4059 | mangleTemplateArgs(T->getTemplateName(), T->template_arguments()); | |||
| 4060 | addSubstitution(QualType(T, 0)); | |||
| 4061 | } | |||
| 4062 | } | |||
| 4063 | ||||
| 4064 | void CXXNameMangler::mangleType(const DependentNameType *T) { | |||
| 4065 | // Proposal by cxx-abi-dev, 2014-03-26 | |||
| 4066 | // <class-enum-type> ::= <name> # non-dependent or dependent type name or | |||
| 4067 | // # dependent elaborated type specifier using | |||
| 4068 | // # 'typename' | |||
| 4069 | // ::= Ts <name> # dependent elaborated type specifier using | |||
| 4070 | // # 'struct' or 'class' | |||
| 4071 | // ::= Tu <name> # dependent elaborated type specifier using | |||
| 4072 | // # 'union' | |||
| 4073 | // ::= Te <name> # dependent elaborated type specifier using | |||
| 4074 | // # 'enum' | |||
| 4075 | switch (T->getKeyword()) { | |||
| 4076 | case ETK_None: | |||
| 4077 | case ETK_Typename: | |||
| 4078 | break; | |||
| 4079 | case ETK_Struct: | |||
| 4080 | case ETK_Class: | |||
| 4081 | case ETK_Interface: | |||
| 4082 | Out << "Ts"; | |||
| 4083 | break; | |||
| 4084 | case ETK_Union: | |||
| 4085 | Out << "Tu"; | |||
| 4086 | break; | |||
| 4087 | case ETK_Enum: | |||
| 4088 | Out << "Te"; | |||
| 4089 | break; | |||
| 4090 | } | |||
| 4091 | // Typename types are always nested | |||
| 4092 | Out << 'N'; | |||
| 4093 | manglePrefix(T->getQualifier()); | |||
| 4094 | mangleSourceName(T->getIdentifier()); | |||
| 4095 | Out << 'E'; | |||
| 4096 | } | |||
| 4097 | ||||
| 4098 | void CXXNameMangler::mangleType(const DependentTemplateSpecializationType *T) { | |||
| 4099 | // Dependently-scoped template types are nested if they have a prefix. | |||
| 4100 | Out << 'N'; | |||
| 4101 | ||||
| 4102 | // TODO: avoid making this TemplateName. | |||
| 4103 | TemplateName Prefix = | |||
| 4104 | getASTContext().getDependentTemplateName(T->getQualifier(), | |||
| 4105 | T->getIdentifier()); | |||
| 4106 | mangleTemplatePrefix(Prefix); | |||
| 4107 | ||||
| 4108 | // FIXME: GCC does not appear to mangle the template arguments when | |||
| 4109 | // the template in question is a dependent template name. Should we | |||
| 4110 | // emulate that badness? | |||
| 4111 | mangleTemplateArgs(Prefix, T->template_arguments()); | |||
| 4112 | Out << 'E'; | |||
| 4113 | } | |||
| 4114 | ||||
| 4115 | void CXXNameMangler::mangleType(const TypeOfType *T) { | |||
| 4116 | // FIXME: this is pretty unsatisfactory, but there isn't an obvious | |||
| 4117 | // "extension with parameters" mangling. | |||
| 4118 | Out << "u6typeof"; | |||
| 4119 | } | |||
| 4120 | ||||
| 4121 | void CXXNameMangler::mangleType(const TypeOfExprType *T) { | |||
| 4122 | // FIXME: this is pretty unsatisfactory, but there isn't an obvious | |||
| 4123 | // "extension with parameters" mangling. | |||
| 4124 | Out << "u6typeof"; | |||
| 4125 | } | |||
| 4126 | ||||
| 4127 | void CXXNameMangler::mangleType(const DecltypeType *T) { | |||
| 4128 | Expr *E = T->getUnderlyingExpr(); | |||
| 4129 | ||||
| 4130 | // type ::= Dt <expression> E # decltype of an id-expression | |||
| 4131 | // # or class member access | |||
| 4132 | // ::= DT <expression> E # decltype of an expression | |||
| 4133 | ||||
| 4134 | // This purports to be an exhaustive list of id-expressions and | |||
| 4135 | // class member accesses. Note that we do not ignore parentheses; | |||
| 4136 | // parentheses change the semantics of decltype for these | |||
| 4137 | // expressions (and cause the mangler to use the other form). | |||
| 4138 | if (isa<DeclRefExpr>(E) || | |||
| 4139 | isa<MemberExpr>(E) || | |||
| 4140 | isa<UnresolvedLookupExpr>(E) || | |||
| 4141 | isa<DependentScopeDeclRefExpr>(E) || | |||
| 4142 | isa<CXXDependentScopeMemberExpr>(E) || | |||
| 4143 | isa<UnresolvedMemberExpr>(E)) | |||
| 4144 | Out << "Dt"; | |||
| 4145 | else | |||
| 4146 | Out << "DT"; | |||
| 4147 | mangleExpression(E); | |||
| 4148 | Out << 'E'; | |||
| 4149 | } | |||
| 4150 | ||||
| 4151 | void CXXNameMangler::mangleType(const UnaryTransformType *T) { | |||
| 4152 | // If this is dependent, we need to record that. If not, we simply | |||
| 4153 | // mangle it as the underlying type since they are equivalent. | |||
| 4154 | if (T->isDependentType()) { | |||
| 4155 | Out << "u"; | |||
| 4156 | ||||
| 4157 | StringRef BuiltinName; | |||
| 4158 | switch (T->getUTTKind()) { | |||
| 4159 | #define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \ | |||
| 4160 | case UnaryTransformType::Enum: \ | |||
| 4161 | BuiltinName = "__" #Trait; \ | |||
| 4162 | break; | |||
| 4163 | #include "clang/Basic/TransformTypeTraits.def" | |||
| 4164 | } | |||
| 4165 | Out << BuiltinName.size() << BuiltinName; | |||
| 4166 | } | |||
| 4167 | ||||
| 4168 | Out << "I"; | |||
| 4169 | mangleType(T->getBaseType()); | |||
| 4170 | Out << "E"; | |||
| 4171 | } | |||
| 4172 | ||||
| 4173 | void CXXNameMangler::mangleType(const AutoType *T) { | |||
| 4174 | assert(T->getDeducedType().isNull() &&(static_cast <bool> (T->getDeducedType().isNull() && "Deduced AutoType shouldn't be handled here!") ? void (0) : __assert_fail ("T->getDeducedType().isNull() && \"Deduced AutoType shouldn't be handled here!\"" , "clang/lib/AST/ItaniumMangle.cpp", 4175, __extension__ __PRETTY_FUNCTION__ )) | |||
| 4175 | "Deduced AutoType shouldn't be handled here!")(static_cast <bool> (T->getDeducedType().isNull() && "Deduced AutoType shouldn't be handled here!") ? void (0) : __assert_fail ("T->getDeducedType().isNull() && \"Deduced AutoType shouldn't be handled here!\"" , "clang/lib/AST/ItaniumMangle.cpp", 4175, __extension__ __PRETTY_FUNCTION__ )); | |||
| 4176 | assert(T->getKeyword() != AutoTypeKeyword::GNUAutoType &&(static_cast <bool> (T->getKeyword() != AutoTypeKeyword ::GNUAutoType && "shouldn't need to mangle __auto_type!" ) ? void (0) : __assert_fail ("T->getKeyword() != AutoTypeKeyword::GNUAutoType && \"shouldn't need to mangle __auto_type!\"" , "clang/lib/AST/ItaniumMangle.cpp", 4177, __extension__ __PRETTY_FUNCTION__ )) | |||
| 4177 | "shouldn't need to mangle __auto_type!")(static_cast <bool> (T->getKeyword() != AutoTypeKeyword ::GNUAutoType && "shouldn't need to mangle __auto_type!" ) ? void (0) : __assert_fail ("T->getKeyword() != AutoTypeKeyword::GNUAutoType && \"shouldn't need to mangle __auto_type!\"" , "clang/lib/AST/ItaniumMangle.cpp", 4177, __extension__ __PRETTY_FUNCTION__ )); | |||
| 4178 | // <builtin-type> ::= Da # auto | |||
| 4179 | // ::= Dc # decltype(auto) | |||
| 4180 | Out << (T->isDecltypeAuto() ? "Dc" : "Da"); | |||
| 4181 | } | |||
| 4182 | ||||
| 4183 | void CXXNameMangler::mangleType(const DeducedTemplateSpecializationType *T) { | |||
| 4184 | QualType Deduced = T->getDeducedType(); | |||
| 4185 | if (!Deduced.isNull()) | |||
| 4186 | return mangleType(Deduced); | |||
| 4187 | ||||
| 4188 | TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl(); | |||
| 4189 | assert(TD && "shouldn't form deduced TST unless we know we have a template")(static_cast <bool> (TD && "shouldn't form deduced TST unless we know we have a template" ) ? void (0) : __assert_fail ("TD && \"shouldn't form deduced TST unless we know we have a template\"" , "clang/lib/AST/ItaniumMangle.cpp", 4189, __extension__ __PRETTY_FUNCTION__ )); | |||
| 4190 | ||||
| 4191 | if (mangleSubstitution(TD)) | |||
| 4192 | return; | |||
| 4193 | ||||
| 4194 | mangleName(GlobalDecl(TD)); | |||
| 4195 | addSubstitution(TD); | |||
| 4196 | } | |||
| 4197 | ||||
| 4198 | void CXXNameMangler::mangleType(const AtomicType *T) { | |||
| 4199 | // <type> ::= U <source-name> <type> # vendor extended type qualifier | |||
| 4200 | // (Until there's a standardized mangling...) | |||
| 4201 | Out << "U7_Atomic"; | |||
| 4202 | mangleType(T->getValueType()); | |||
| 4203 | } | |||
| 4204 | ||||
| 4205 | void CXXNameMangler::mangleType(const PipeType *T) { | |||
| 4206 | // Pipe type mangling rules are described in SPIR 2.0 specification | |||
| 4207 | // A.1 Data types and A.3 Summary of changes | |||
| 4208 | // <type> ::= 8ocl_pipe | |||
| 4209 | Out << "8ocl_pipe"; | |||
| 4210 | } | |||
| 4211 | ||||
| 4212 | void CXXNameMangler::mangleType(const BitIntType *T) { | |||
| 4213 | // 5.1.5.2 Builtin types | |||
| 4214 | // <type> ::= DB <number | instantiation-dependent expression> _ | |||
| 4215 | // ::= DU <number | instantiation-dependent expression> _ | |||
| 4216 | Out << "D" << (T->isUnsigned() ? "U" : "B") << T->getNumBits() << "_"; | |||
| 4217 | } | |||
| 4218 | ||||
| 4219 | void CXXNameMangler::mangleType(const DependentBitIntType *T) { | |||
| 4220 | // 5.1.5.2 Builtin types | |||
| 4221 | // <type> ::= DB <number | instantiation-dependent expression> _ | |||
| 4222 | // ::= DU <number | instantiation-dependent expression> _ | |||
| 4223 | Out << "D" << (T->isUnsigned() ? "U" : "B"); | |||
| 4224 | mangleExpression(T->getNumBitsExpr()); | |||
| 4225 | Out << "_"; | |||
| 4226 | } | |||
| 4227 | ||||
| 4228 | void CXXNameMangler::mangleIntegerLiteral(QualType T, | |||
| 4229 | const llvm::APSInt &Value) { | |||
| 4230 | // <expr-primary> ::= L <type> <value number> E # integer literal | |||
| 4231 | Out << 'L'; | |||
| 4232 | ||||
| 4233 | mangleType(T); | |||
| 4234 | if (T->isBooleanType()) { | |||
| 4235 | // Boolean values are encoded as 0/1. | |||
| 4236 | Out << (Value.getBoolValue() ? '1' : '0'); | |||
| 4237 | } else { | |||
| 4238 | mangleNumber(Value); | |||
| 4239 | } | |||
| 4240 | Out << 'E'; | |||
| 4241 | ||||
| 4242 | } | |||
| 4243 | ||||
| 4244 | void CXXNameMangler::mangleMemberExprBase(const Expr *Base, bool IsArrow) { | |||
| 4245 | // Ignore member expressions involving anonymous unions. | |||
| 4246 | while (const auto *RT = Base->getType()->getAs<RecordType>()) { | |||
| 4247 | if (!RT->getDecl()->isAnonymousStructOrUnion()) | |||
| 4248 | break; | |||
| 4249 | const auto *ME = dyn_cast<MemberExpr>(Base); | |||
| 4250 | if (!ME) | |||
| 4251 | break; | |||
| 4252 | Base = ME->getBase(); | |||
| 4253 | IsArrow = ME->isArrow(); | |||
| 4254 | } | |||
| 4255 | ||||
| 4256 | if (Base->isImplicitCXXThis()) { | |||
| 4257 | // Note: GCC mangles member expressions to the implicit 'this' as | |||
| 4258 | // *this., whereas we represent them as this->. The Itanium C++ ABI | |||
| 4259 | // does not specify anything here, so we follow GCC. | |||
| 4260 | Out << "dtdefpT"; | |||
| 4261 | } else { | |||
| 4262 | Out << (IsArrow ? "pt" : "dt"); | |||
| 4263 | mangleExpression(Base); | |||
| 4264 | } | |||
| 4265 | } | |||
| 4266 | ||||
| 4267 | /// Mangles a member expression. | |||
| 4268 | void CXXNameMangler::mangleMemberExpr(const Expr *base, | |||
| 4269 | bool isArrow, | |||
| 4270 | NestedNameSpecifier *qualifier, | |||
| 4271 | NamedDecl *firstQualifierLookup, | |||
| 4272 | DeclarationName member, | |||
| 4273 | const TemplateArgumentLoc *TemplateArgs, | |||
| 4274 | unsigned NumTemplateArgs, | |||
| 4275 | unsigned arity) { | |||
| 4276 | // <expression> ::= dt <expression> <unresolved-name> | |||
| 4277 | // ::= pt <expression> <unresolved-name> | |||
| 4278 | if (base) | |||
| 4279 | mangleMemberExprBase(base, isArrow); | |||
| 4280 | mangleUnresolvedName(qualifier, member, TemplateArgs, NumTemplateArgs, arity); | |||
| 4281 | } | |||
| 4282 | ||||
| 4283 | /// Look at the callee of the given call expression and determine if | |||
| 4284 | /// it's a parenthesized id-expression which would have triggered ADL | |||
| 4285 | /// otherwise. | |||
| 4286 | static bool isParenthesizedADLCallee(const CallExpr *call) { | |||
| 4287 | const Expr *callee = call->getCallee(); | |||
| 4288 | const Expr *fn = callee->IgnoreParens(); | |||
| 4289 | ||||
| 4290 | // Must be parenthesized. IgnoreParens() skips __extension__ nodes, | |||
| 4291 | // too, but for those to appear in the callee, it would have to be | |||
| 4292 | // parenthesized. | |||
| 4293 | if (callee == fn) return false; | |||
| 4294 | ||||
| 4295 | // Must be an unresolved lookup. | |||
| 4296 | const UnresolvedLookupExpr *lookup = dyn_cast<UnresolvedLookupExpr>(fn); | |||
| 4297 | if (!lookup) return false; | |||
| 4298 | ||||
| 4299 | assert(!lookup->requiresADL())(static_cast <bool> (!lookup->requiresADL()) ? void ( 0) : __assert_fail ("!lookup->requiresADL()", "clang/lib/AST/ItaniumMangle.cpp" , 4299, __extension__ __PRETTY_FUNCTION__)); | |||
| 4300 | ||||
| 4301 | // Must be an unqualified lookup. | |||
| 4302 | if (lookup->getQualifier()) return false; | |||
| 4303 | ||||
| 4304 | // Must not have found a class member. Note that if one is a class | |||
| 4305 | // member, they're all class members. | |||
| 4306 | if (lookup->getNumDecls() > 0 && | |||
| 4307 | (*lookup->decls_begin())->isCXXClassMember()) | |||
| 4308 | return false; | |||
| 4309 | ||||
| 4310 | // Otherwise, ADL would have been triggered. | |||
| 4311 | return true; | |||
| 4312 | } | |||
| 4313 | ||||
| 4314 | void CXXNameMangler::mangleCastExpression(const Expr *E, StringRef CastEncoding) { | |||
| 4315 | const ExplicitCastExpr *ECE = cast<ExplicitCastExpr>(E); | |||
| 4316 | Out << CastEncoding; | |||
| 4317 | mangleType(ECE->getType()); | |||
| 4318 | mangleExpression(ECE->getSubExpr()); | |||
| 4319 | } | |||
| 4320 | ||||
| 4321 | void CXXNameMangler::mangleInitListElements(const InitListExpr *InitList) { | |||
| 4322 | if (auto *Syntactic = InitList->getSyntacticForm()) | |||
| 4323 | InitList = Syntactic; | |||
| 4324 | for (unsigned i = 0, e = InitList->getNumInits(); i != e; ++i) | |||
| 4325 | mangleExpression(InitList->getInit(i)); | |||
| 4326 | } | |||
| 4327 | ||||
| 4328 | void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity, | |||
| 4329 | bool AsTemplateArg) { | |||
| 4330 | // <expression> ::= <unary operator-name> <expression> | |||
| 4331 | // ::= <binary operator-name> <expression> <expression> | |||
| 4332 | // ::= <trinary operator-name> <expression> <expression> <expression> | |||
| 4333 | // ::= cv <type> expression # conversion with one argument | |||
| 4334 | // ::= cv <type> _ <expression>* E # conversion with a different number of arguments | |||
| 4335 | // ::= dc <type> <expression> # dynamic_cast<type> (expression) | |||
| 4336 | // ::= sc <type> <expression> # static_cast<type> (expression) | |||
| 4337 | // ::= cc <type> <expression> # const_cast<type> (expression) | |||
| 4338 | // ::= rc <type> <expression> # reinterpret_cast<type> (expression) | |||
| 4339 | // ::= st <type> # sizeof (a type) | |||
| 4340 | // ::= at <type> # alignof (a type) | |||
| 4341 | // ::= <template-param> | |||
| 4342 | // ::= <function-param> | |||
| 4343 | // ::= fpT # 'this' expression (part of <function-param>) | |||
| 4344 | // ::= sr <type> <unqualified-name> # dependent name | |||
| 4345 | // ::= sr <type> <unqualified-name> <template-args> # dependent template-id | |||
| 4346 | // ::= ds <expression> <expression> # expr.*expr | |||
| 4347 | // ::= sZ <template-param> # size of a parameter pack | |||
| 4348 | // ::= sZ <function-param> # size of a function parameter pack | |||
| 4349 | // ::= u <source-name> <template-arg>* E # vendor extended expression | |||
| 4350 | // ::= <expr-primary> | |||
| 4351 | // <expr-primary> ::= L <type> <value number> E # integer literal | |||
| 4352 | // ::= L <type> <value float> E # floating literal | |||
| 4353 | // ::= L <type> <string type> E # string literal | |||
| 4354 | // ::= L <nullptr type> E # nullptr literal "LDnE" | |||
| 4355 | // ::= L <pointer type> 0 E # null pointer template argument | |||
| 4356 | // ::= L <type> <real-part float> _ <imag-part float> E # complex floating point literal (C99); not used by clang | |||
| 4357 | // ::= L <mangled-name> E # external name | |||
| 4358 | QualType ImplicitlyConvertedToType; | |||
| 4359 | ||||
| 4360 | // A top-level expression that's not <expr-primary> needs to be wrapped in | |||
| 4361 | // X...E in a template arg. | |||
| 4362 | bool IsPrimaryExpr = true; | |||
| 4363 | auto NotPrimaryExpr = [&] { | |||
| 4364 | if (AsTemplateArg && IsPrimaryExpr) | |||
| 4365 | Out << 'X'; | |||
| 4366 | IsPrimaryExpr = false; | |||
| 4367 | }; | |||
| 4368 | ||||
| 4369 | auto MangleDeclRefExpr = [&](const NamedDecl *D) { | |||
| 4370 | switch (D->getKind()) { | |||
| 4371 | default: | |||
| 4372 | // <expr-primary> ::= L <mangled-name> E # external name | |||
| 4373 | Out << 'L'; | |||
| 4374 | mangle(D); | |||
| 4375 | Out << 'E'; | |||
| 4376 | break; | |||
| 4377 | ||||
| 4378 | case Decl::ParmVar: | |||
| 4379 | NotPrimaryExpr(); | |||
| 4380 | mangleFunctionParam(cast<ParmVarDecl>(D)); | |||
| 4381 | break; | |||
| 4382 | ||||
| 4383 | case Decl::EnumConstant: { | |||
| 4384 | // <expr-primary> | |||
| 4385 | const EnumConstantDecl *ED = cast<EnumConstantDecl>(D); | |||
| 4386 | mangleIntegerLiteral(ED->getType(), ED->getInitVal()); | |||
| 4387 | break; | |||
| 4388 | } | |||
| 4389 | ||||
| 4390 | case Decl::NonTypeTemplateParm: | |||
| 4391 | NotPrimaryExpr(); | |||
| 4392 | const NonTypeTemplateParmDecl *PD = cast<NonTypeTemplateParmDecl>(D); | |||
| 4393 | mangleTemplateParameter(PD->getDepth(), PD->getIndex()); | |||
| 4394 | break; | |||
| 4395 | } | |||
| 4396 | }; | |||
| 4397 | ||||
| 4398 | // 'goto recurse' is used when handling a simple "unwrapping" node which | |||
| 4399 | // produces no output, where ImplicitlyConvertedToType and AsTemplateArg need | |||
| 4400 | // to be preserved. | |||
| 4401 | recurse: | |||
| 4402 | switch (E->getStmtClass()) { | |||
| 4403 | case Expr::NoStmtClass: | |||
| 4404 | #define ABSTRACT_STMT(Type) | |||
| 4405 | #define EXPR(Type, Base) | |||
| 4406 | #define STMT(Type, Base) \ | |||
| 4407 | case Expr::Type##Class: | |||
| 4408 | #include "clang/AST/StmtNodes.inc" | |||
| 4409 | // fallthrough | |||
| 4410 | ||||
| 4411 | // These all can only appear in local or variable-initialization | |||
| 4412 | // contexts and so should never appear in a mangling. | |||
| 4413 | case Expr::AddrLabelExprClass: | |||
| 4414 | case Expr::DesignatedInitUpdateExprClass: | |||
| 4415 | case Expr::ImplicitValueInitExprClass: | |||
| 4416 | case Expr::ArrayInitLoopExprClass: | |||
| 4417 | case Expr::ArrayInitIndexExprClass: | |||
| 4418 | case Expr::NoInitExprClass: | |||
| 4419 | case Expr::ParenListExprClass: | |||
| 4420 | case Expr::MSPropertyRefExprClass: | |||
| 4421 | case Expr::MSPropertySubscriptExprClass: | |||
| 4422 | case Expr::TypoExprClass: // This should no longer exist in the AST by now. | |||
| 4423 | case Expr::RecoveryExprClass: | |||
| 4424 | case Expr::OMPArraySectionExprClass: | |||
| 4425 | case Expr::OMPArrayShapingExprClass: | |||
| 4426 | case Expr::OMPIteratorExprClass: | |||
| 4427 | case Expr::CXXInheritedCtorInitExprClass: | |||
| 4428 | case Expr::CXXParenListInitExprClass: | |||
| 4429 | llvm_unreachable("unexpected statement kind")::llvm::llvm_unreachable_internal("unexpected statement kind" , "clang/lib/AST/ItaniumMangle.cpp", 4429); | |||
| 4430 | ||||
| 4431 | case Expr::ConstantExprClass: | |||
| 4432 | E = cast<ConstantExpr>(E)->getSubExpr(); | |||
| 4433 | goto recurse; | |||
| 4434 | ||||
| 4435 | // FIXME: invent manglings for all these. | |||
| 4436 | case Expr::BlockExprClass: | |||
| 4437 | case Expr::ChooseExprClass: | |||
| 4438 | case Expr::CompoundLiteralExprClass: | |||
| 4439 | case Expr::ExtVectorElementExprClass: | |||
| 4440 | case Expr::GenericSelectionExprClass: | |||
| 4441 | case Expr::ObjCEncodeExprClass: | |||
| 4442 | case Expr::ObjCIsaExprClass: | |||
| 4443 | case Expr::ObjCIvarRefExprClass: | |||
| 4444 | case Expr::ObjCMessageExprClass: | |||
| 4445 | case Expr::ObjCPropertyRefExprClass: | |||
| 4446 | case Expr::ObjCProtocolExprClass: | |||
| 4447 | case Expr::ObjCSelectorExprClass: | |||
| 4448 | case Expr::ObjCStringLiteralClass: | |||
| 4449 | case Expr::ObjCBoxedExprClass: | |||
| 4450 | case Expr::ObjCArrayLiteralClass: | |||
| 4451 | case Expr::ObjCDictionaryLiteralClass: | |||
| 4452 | case Expr::ObjCSubscriptRefExprClass: | |||
| 4453 | case Expr::ObjCIndirectCopyRestoreExprClass: | |||
| 4454 | case Expr::ObjCAvailabilityCheckExprClass: | |||
| 4455 | case Expr::OffsetOfExprClass: | |||
| 4456 | case Expr::PredefinedExprClass: | |||
| 4457 | case Expr::ShuffleVectorExprClass: | |||
| 4458 | case Expr::ConvertVectorExprClass: | |||
| 4459 | case Expr::StmtExprClass: | |||
| 4460 | case Expr::TypeTraitExprClass: | |||
| 4461 | case Expr::RequiresExprClass: | |||
| 4462 | case Expr::ArrayTypeTraitExprClass: | |||
| 4463 | case Expr::ExpressionTraitExprClass: | |||
| 4464 | case Expr::VAArgExprClass: | |||
| 4465 | case Expr::CUDAKernelCallExprClass: | |||
| 4466 | case Expr::AsTypeExprClass: | |||
| 4467 | case Expr::PseudoObjectExprClass: | |||
| 4468 | case Expr::AtomicExprClass: | |||
| 4469 | case Expr::SourceLocExprClass: | |||
| 4470 | case Expr::BuiltinBitCastExprClass: | |||
| 4471 | { | |||
| 4472 | NotPrimaryExpr(); | |||
| 4473 | if (!NullOut) { | |||
| 4474 | // As bad as this diagnostic is, it's better than crashing. | |||
| 4475 | DiagnosticsEngine &Diags = Context.getDiags(); | |||
| 4476 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | |||
| 4477 | "cannot yet mangle expression type %0"); | |||
| 4478 | Diags.Report(E->getExprLoc(), DiagID) | |||
| 4479 | << E->getStmtClassName() << E->getSourceRange(); | |||
| 4480 | return; | |||
| 4481 | } | |||
| 4482 | break; | |||
| 4483 | } | |||
| 4484 | ||||
| 4485 | case Expr::CXXUuidofExprClass: { | |||
| 4486 | NotPrimaryExpr(); | |||
| 4487 | const CXXUuidofExpr *UE = cast<CXXUuidofExpr>(E); | |||
| 4488 | // As of clang 12, uuidof uses the vendor extended expression | |||
| 4489 | // mangling. Previously, it used a special-cased nonstandard extension. | |||
| 4490 | if (Context.getASTContext().getLangOpts().getClangABICompat() > | |||
| 4491 | LangOptions::ClangABI::Ver11) { | |||
| 4492 | Out << "u8__uuidof"; | |||
| 4493 | if (UE->isTypeOperand()) | |||
| 4494 | mangleType(UE->getTypeOperand(Context.getASTContext())); | |||
| 4495 | else | |||
| 4496 | mangleTemplateArgExpr(UE->getExprOperand()); | |||
| 4497 | Out << 'E'; | |||
| 4498 | } else { | |||
| 4499 | if (UE->isTypeOperand()) { | |||
| 4500 | QualType UuidT = UE->getTypeOperand(Context.getASTContext()); | |||
| 4501 | Out << "u8__uuidoft"; | |||
| 4502 | mangleType(UuidT); | |||
| 4503 | } else { | |||
| 4504 | Expr *UuidExp = UE->getExprOperand(); | |||
| 4505 | Out << "u8__uuidofz"; | |||
| 4506 | mangleExpression(UuidExp); | |||
| 4507 | } | |||
| 4508 | } | |||
| 4509 | break; | |||
| 4510 | } | |||
| 4511 | ||||
| 4512 | // Even gcc-4.5 doesn't mangle this. | |||
| 4513 | case Expr::BinaryConditionalOperatorClass: { | |||
| 4514 | NotPrimaryExpr(); | |||
| 4515 | DiagnosticsEngine &Diags = Context.getDiags(); | |||
| 4516 | unsigned DiagID = | |||
| 4517 | Diags.getCustomDiagID(DiagnosticsEngine::Error, | |||
| 4518 | "?: operator with omitted middle operand cannot be mangled"); | |||
| 4519 | Diags.Report(E->getExprLoc(), DiagID) | |||
| 4520 | << E->getStmtClassName() << E->getSourceRange(); | |||
| 4521 | return; | |||
| 4522 | } | |||
| 4523 | ||||
| 4524 | // These are used for internal purposes and cannot be meaningfully mangled. | |||
| 4525 | case Expr::OpaqueValueExprClass: | |||
| 4526 | llvm_unreachable("cannot mangle opaque value; mangling wrong thing?")::llvm::llvm_unreachable_internal("cannot mangle opaque value; mangling wrong thing?" , "clang/lib/AST/ItaniumMangle.cpp", 4526); | |||
| 4527 | ||||
| 4528 | case Expr::InitListExprClass: { | |||
| 4529 | NotPrimaryExpr(); | |||
| 4530 | Out << "il"; | |||
| 4531 | mangleInitListElements(cast<InitListExpr>(E)); | |||
| 4532 | Out << "E"; | |||
| 4533 | break; | |||
| 4534 | } | |||
| 4535 | ||||
| 4536 | case Expr::DesignatedInitExprClass: { | |||
| 4537 | NotPrimaryExpr(); | |||
| 4538 | auto *DIE = cast<DesignatedInitExpr>(E); | |||
| 4539 | for (const auto &Designator : DIE->designators()) { | |||
| 4540 | if (Designator.isFieldDesignator()) { | |||
| 4541 | Out << "di"; | |||
| 4542 | mangleSourceName(Designator.getFieldName()); | |||
| 4543 | } else if (Designator.isArrayDesignator()) { | |||
| 4544 | Out << "dx"; | |||
| 4545 | mangleExpression(DIE->getArrayIndex(Designator)); | |||
| 4546 | } else { | |||
| 4547 | assert(Designator.isArrayRangeDesignator() &&(static_cast <bool> (Designator.isArrayRangeDesignator( ) && "unknown designator kind") ? void (0) : __assert_fail ("Designator.isArrayRangeDesignator() && \"unknown designator kind\"" , "clang/lib/AST/ItaniumMangle.cpp", 4548, __extension__ __PRETTY_FUNCTION__ )) | |||
| 4548 | "unknown designator kind")(static_cast <bool> (Designator.isArrayRangeDesignator( ) && "unknown designator kind") ? void (0) : __assert_fail ("Designator.isArrayRangeDesignator() && \"unknown designator kind\"" , "clang/lib/AST/ItaniumMangle.cpp", 4548, __extension__ __PRETTY_FUNCTION__ )); | |||
| 4549 | Out << "dX"; | |||
| 4550 | mangleExpression(DIE->getArrayRangeStart(Designator)); | |||
| 4551 | mangleExpression(DIE->getArrayRangeEnd(Designator)); | |||
| 4552 | } | |||
| 4553 | } | |||
| 4554 | mangleExpression(DIE->getInit()); | |||
| 4555 | break; | |||
| 4556 | } | |||
| 4557 | ||||
| 4558 | case Expr::CXXDefaultArgExprClass: | |||
| 4559 | E = cast<CXXDefaultArgExpr>(E)->getExpr(); | |||
| 4560 | goto recurse; | |||
| 4561 | ||||
| 4562 | case Expr::CXXDefaultInitExprClass: | |||
| 4563 | E = cast<CXXDefaultInitExpr>(E)->getExpr(); | |||
| 4564 | goto recurse; | |||
| 4565 | ||||
| 4566 | case Expr::CXXStdInitializerListExprClass: | |||
| 4567 | E = cast<CXXStdInitializerListExpr>(E)->getSubExpr(); | |||
| 4568 | goto recurse; | |||
| 4569 | ||||
| 4570 | case Expr::SubstNonTypeTemplateParmExprClass: | |||
| 4571 | E = cast<SubstNonTypeTemplateParmExpr>(E)->getReplacement(); | |||
| 4572 | goto recurse; | |||
| 4573 | ||||
| 4574 | case Expr::UserDefinedLiteralClass: | |||
| 4575 | // We follow g++'s approach of mangling a UDL as a call to the literal | |||
| 4576 | // operator. | |||
| 4577 | case Expr::CXXMemberCallExprClass: // fallthrough | |||
| 4578 | case Expr::CallExprClass: { | |||
| 4579 | NotPrimaryExpr(); | |||
| 4580 | const CallExpr *CE = cast<CallExpr>(E); | |||
| 4581 | ||||
| 4582 | // <expression> ::= cp <simple-id> <expression>* E | |||
| 4583 | // We use this mangling only when the call would use ADL except | |||
| 4584 | // for being parenthesized. Per discussion with David | |||
| 4585 | // Vandervoorde, 2011.04.25. | |||
| 4586 | if (isParenthesizedADLCallee(CE)) { | |||
| 4587 | Out << "cp"; | |||
| 4588 | // The callee here is a parenthesized UnresolvedLookupExpr with | |||
| 4589 | // no qualifier and should always get mangled as a <simple-id> | |||
| 4590 | // anyway. | |||
| 4591 | ||||
| 4592 | // <expression> ::= cl <expression>* E | |||
| 4593 | } else { | |||
| 4594 | Out << "cl"; | |||
| 4595 | } | |||
| 4596 | ||||
| 4597 | unsigned CallArity = CE->getNumArgs(); | |||
| 4598 | for (const Expr *Arg : CE->arguments()) | |||
| 4599 | if (isa<PackExpansionExpr>(Arg)) | |||
| 4600 | CallArity = UnknownArity; | |||
| 4601 | ||||
| 4602 | mangleExpression(CE->getCallee(), CallArity); | |||
| 4603 | for (const Expr *Arg : CE->arguments()) | |||
| 4604 | mangleExpression(Arg); | |||
| 4605 | Out << 'E'; | |||
| 4606 | break; | |||
| 4607 | } | |||
| 4608 | ||||
| 4609 | case Expr::CXXNewExprClass: { | |||
| 4610 | NotPrimaryExpr(); | |||
| 4611 | const CXXNewExpr *New = cast<CXXNewExpr>(E); | |||
| 4612 | if (New->isGlobalNew()) Out << "gs"; | |||
| 4613 | Out << (New->isArray() ? "na" : "nw"); | |||
| 4614 | for (CXXNewExpr::const_arg_iterator I = New->placement_arg_begin(), | |||
| 4615 | E = New->placement_arg_end(); I != E; ++I) | |||
| 4616 | mangleExpression(*I); | |||
| 4617 | Out << '_'; | |||
| 4618 | mangleType(New->getAllocatedType()); | |||
| 4619 | if (New->hasInitializer()) { | |||
| 4620 | if (New->getInitializationStyle() == CXXNewExpr::ListInit) | |||
| 4621 | Out << "il"; | |||
| 4622 | else | |||
| 4623 | Out << "pi"; | |||
| 4624 | const Expr *Init = New->getInitializer(); | |||
| 4625 | if (const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(Init)) { | |||
| 4626 | // Directly inline the initializers. | |||
| 4627 | for (CXXConstructExpr::const_arg_iterator I = CCE->arg_begin(), | |||
| 4628 | E = CCE->arg_end(); | |||
| 4629 | I != E; ++I) | |||
| 4630 | mangleExpression(*I); | |||
| 4631 | } else if (const ParenListExpr *PLE = dyn_cast<ParenListExpr>(Init)) { | |||
| 4632 | for (unsigned i = 0, e = PLE->getNumExprs(); i != e; ++i) | |||
| 4633 | mangleExpression(PLE->getExpr(i)); | |||
| 4634 | } else if (New->getInitializationStyle() == CXXNewExpr::ListInit && | |||
| 4635 | isa<InitListExpr>(Init)) { | |||
| 4636 | // Only take InitListExprs apart for list-initialization. | |||
| 4637 | mangleInitListElements(cast<InitListExpr>(Init)); | |||
| 4638 | } else | |||
| 4639 | mangleExpression(Init); | |||
| 4640 | } | |||
| 4641 | Out << 'E'; | |||
| 4642 | break; | |||
| 4643 | } | |||
| 4644 | ||||
| 4645 | case Expr::CXXPseudoDestructorExprClass: { | |||
| 4646 | NotPrimaryExpr(); | |||
| 4647 | const auto *PDE = cast<CXXPseudoDestructorExpr>(E); | |||
| 4648 | if (const Expr *Base = PDE->getBase()) | |||
| 4649 | mangleMemberExprBase(Base, PDE->isArrow()); | |||
| 4650 | NestedNameSpecifier *Qualifier = PDE->getQualifier(); | |||
| 4651 | if (TypeSourceInfo *ScopeInfo = PDE->getScopeTypeInfo()) { | |||
| 4652 | if (Qualifier) { | |||
| 4653 | mangleUnresolvedPrefix(Qualifier, | |||
| 4654 | /*recursive=*/true); | |||
| 4655 | mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType()); | |||
| 4656 | Out << 'E'; | |||
| 4657 | } else { | |||
| 4658 | Out << "sr"; | |||
| 4659 | if (!mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType())) | |||
| 4660 | Out << 'E'; | |||
| 4661 | } | |||
| 4662 | } else if (Qualifier) { | |||
| 4663 | mangleUnresolvedPrefix(Qualifier); | |||
| 4664 | } | |||
| 4665 | // <base-unresolved-name> ::= dn <destructor-name> | |||
| 4666 | Out << "dn"; | |||
| 4667 | QualType DestroyedType = PDE->getDestroyedType(); | |||
| 4668 | mangleUnresolvedTypeOrSimpleId(DestroyedType); | |||
| 4669 | break; | |||
| 4670 | } | |||
| 4671 | ||||
| 4672 | case Expr::MemberExprClass: { | |||
| 4673 | NotPrimaryExpr(); | |||
| 4674 | const MemberExpr *ME = cast<MemberExpr>(E); | |||
| 4675 | mangleMemberExpr(ME->getBase(), ME->isArrow(), | |||
| 4676 | ME->getQualifier(), nullptr, | |||
| 4677 | ME->getMemberDecl()->getDeclName(), | |||
| 4678 | ME->getTemplateArgs(), ME->getNumTemplateArgs(), | |||
| 4679 | Arity); | |||
| 4680 | break; | |||
| 4681 | } | |||
| 4682 | ||||
| 4683 | case Expr::UnresolvedMemberExprClass: { | |||
| 4684 | NotPrimaryExpr(); | |||
| 4685 | const UnresolvedMemberExpr *ME = cast<UnresolvedMemberExpr>(E); | |||
| 4686 | mangleMemberExpr(ME->isImplicitAccess() ? nullptr : ME->getBase(), | |||
| 4687 | ME->isArrow(), ME->getQualifier(), nullptr, | |||
| 4688 | ME->getMemberName(), | |||
| 4689 | ME->getTemplateArgs(), ME->getNumTemplateArgs(), | |||
| 4690 | Arity); | |||
| 4691 | break; | |||
| 4692 | } | |||
| 4693 | ||||
| 4694 | case Expr::CXXDependentScopeMemberExprClass: { | |||
| 4695 | NotPrimaryExpr(); | |||
| 4696 | const CXXDependentScopeMemberExpr *ME | |||
| 4697 | = cast<CXXDependentScopeMemberExpr>(E); | |||
| 4698 | mangleMemberExpr(ME->isImplicitAccess() ? nullptr : ME->getBase(), | |||
| 4699 | ME->isArrow(), ME->getQualifier(), | |||
| 4700 | ME->getFirstQualifierFoundInScope(), | |||
| 4701 | ME->getMember(), | |||
| 4702 | ME->getTemplateArgs(), ME->getNumTemplateArgs(), | |||
| 4703 | Arity); | |||
| 4704 | break; | |||
| 4705 | } | |||
| 4706 | ||||
| 4707 | case Expr::UnresolvedLookupExprClass: { | |||
| 4708 | NotPrimaryExpr(); | |||
| 4709 | const UnresolvedLookupExpr *ULE = cast<UnresolvedLookupExpr>(E); | |||
| 4710 | mangleUnresolvedName(ULE->getQualifier(), ULE->getName(), | |||
| 4711 | ULE->getTemplateArgs(), ULE->getNumTemplateArgs(), | |||
| 4712 | Arity); | |||
| 4713 | break; | |||
| 4714 | } | |||
| 4715 | ||||
| 4716 | case Expr::CXXUnresolvedConstructExprClass: { | |||
| 4717 | NotPrimaryExpr(); | |||
| 4718 | const CXXUnresolvedConstructExpr *CE = cast<CXXUnresolvedConstructExpr>(E); | |||
| 4719 | unsigned N = CE->getNumArgs(); | |||
| 4720 | ||||
| 4721 | if (CE->isListInitialization()) { | |||
| 4722 | assert(N == 1 && "unexpected form for list initialization")(static_cast <bool> (N == 1 && "unexpected form for list initialization" ) ? void (0) : __assert_fail ("N == 1 && \"unexpected form for list initialization\"" , "clang/lib/AST/ItaniumMangle.cpp", 4722, __extension__ __PRETTY_FUNCTION__ )); | |||
| 4723 | auto *IL = cast<InitListExpr>(CE->getArg(0)); | |||
| 4724 | Out << "tl"; | |||
| 4725 | mangleType(CE->getType()); | |||
| 4726 | mangleInitListElements(IL); | |||
| 4727 | Out << "E"; | |||
| 4728 | break; | |||
| 4729 | } | |||
| 4730 | ||||
| 4731 | Out << "cv"; | |||
| 4732 | mangleType(CE->getType()); | |||
| 4733 | if (N != 1) Out << '_'; | |||
| 4734 | for (unsigned I = 0; I != N; ++I) mangleExpression(CE->getArg(I)); | |||
| 4735 | if (N != 1) Out << 'E'; | |||
| 4736 | break; | |||
| 4737 | } | |||
| 4738 | ||||
| 4739 | case Expr::CXXConstructExprClass: { | |||
| 4740 | // An implicit cast is silent, thus may contain <expr-primary>. | |||
| 4741 | const auto *CE = cast<CXXConstructExpr>(E); | |||
| 4742 | if (!CE->isListInitialization() || CE->isStdInitListInitialization()) { | |||
| 4743 | assert((static_cast <bool> (CE->getNumArgs() >= 1 && (CE->getNumArgs() == 1 || isa<CXXDefaultArgExpr>(CE ->getArg(1))) && "implicit CXXConstructExpr must have one argument" ) ? void (0) : __assert_fail ("CE->getNumArgs() >= 1 && (CE->getNumArgs() == 1 || isa<CXXDefaultArgExpr>(CE->getArg(1))) && \"implicit CXXConstructExpr must have one argument\"" , "clang/lib/AST/ItaniumMangle.cpp", 4746, __extension__ __PRETTY_FUNCTION__ )) | |||
| 4744 | CE->getNumArgs() >= 1 &&(static_cast <bool> (CE->getNumArgs() >= 1 && (CE->getNumArgs() == 1 || isa<CXXDefaultArgExpr>(CE ->getArg(1))) && "implicit CXXConstructExpr must have one argument" ) ? void (0) : __assert_fail ("CE->getNumArgs() >= 1 && (CE->getNumArgs() == 1 || isa<CXXDefaultArgExpr>(CE->getArg(1))) && \"implicit CXXConstructExpr must have one argument\"" , "clang/lib/AST/ItaniumMangle.cpp", 4746, __extension__ __PRETTY_FUNCTION__ )) | |||
| 4745 | (CE->getNumArgs() == 1 || isa<CXXDefaultArgExpr>(CE->getArg(1))) &&(static_cast <bool> (CE->getNumArgs() >= 1 && (CE->getNumArgs() == 1 || isa<CXXDefaultArgExpr>(CE ->getArg(1))) && "implicit CXXConstructExpr must have one argument" ) ? void (0) : __assert_fail ("CE->getNumArgs() >= 1 && (CE->getNumArgs() == 1 || isa<CXXDefaultArgExpr>(CE->getArg(1))) && \"implicit CXXConstructExpr must have one argument\"" , "clang/lib/AST/ItaniumMangle.cpp", 4746, __extension__ __PRETTY_FUNCTION__ )) | |||
| 4746 | "implicit CXXConstructExpr must have one argument")(static_cast <bool> (CE->getNumArgs() >= 1 && (CE->getNumArgs() == 1 || isa<CXXDefaultArgExpr>(CE ->getArg(1))) && "implicit CXXConstructExpr must have one argument" ) ? void (0) : __assert_fail ("CE->getNumArgs() >= 1 && (CE->getNumArgs() == 1 || isa<CXXDefaultArgExpr>(CE->getArg(1))) && \"implicit CXXConstructExpr must have one argument\"" , "clang/lib/AST/ItaniumMangle.cpp", 4746, __extension__ __PRETTY_FUNCTION__ )); | |||
| 4747 | E = cast<CXXConstructExpr>(E)->getArg(0); | |||
| 4748 | goto recurse; | |||
| 4749 | } | |||
| 4750 | NotPrimaryExpr(); | |||
| 4751 | Out << "il"; | |||
| 4752 | for (auto *E : CE->arguments()) | |||
| 4753 | mangleExpression(E); | |||
| 4754 | Out << "E"; | |||
| 4755 | break; | |||
| 4756 | } | |||
| 4757 | ||||
| 4758 | case Expr::CXXTemporaryObjectExprClass: { | |||
| 4759 | NotPrimaryExpr(); | |||
| 4760 | const auto *CE = cast<CXXTemporaryObjectExpr>(E); | |||
| 4761 | unsigned N = CE->getNumArgs(); | |||
| 4762 | bool List = CE->isListInitialization(); | |||
| 4763 | ||||
| 4764 | if (List) | |||
| 4765 | Out << "tl"; | |||
| 4766 | else | |||
| 4767 | Out << "cv"; | |||
| 4768 | mangleType(CE->getType()); | |||
| 4769 | if (!List && N != 1) | |||
| 4770 | Out << '_'; | |||
| 4771 | if (CE->isStdInitListInitialization()) { | |||
| 4772 | // We implicitly created a std::initializer_list<T> for the first argument | |||
| 4773 | // of a constructor of type U in an expression of the form U{a, b, c}. | |||
| 4774 | // Strip all the semantic gunk off the initializer list. | |||
| 4775 | auto *SILE = | |||
| 4776 | cast<CXXStdInitializerListExpr>(CE->getArg(0)->IgnoreImplicit()); | |||
| 4777 | auto *ILE = cast<InitListExpr>(SILE->getSubExpr()->IgnoreImplicit()); | |||
| 4778 | mangleInitListElements(ILE); | |||
| 4779 | } else { | |||
| 4780 | for (auto *E : CE->arguments()) | |||
| 4781 | mangleExpression(E); | |||
| 4782 | } | |||
| 4783 | if (List || N != 1) | |||
| 4784 | Out << 'E'; | |||
| 4785 | break; | |||
| 4786 | } | |||
| 4787 | ||||
| 4788 | case Expr::CXXScalarValueInitExprClass: | |||
| 4789 | NotPrimaryExpr(); | |||
| 4790 | Out << "cv"; | |||
| 4791 | mangleType(E->getType()); | |||
| 4792 | Out << "_E"; | |||
| 4793 | break; | |||
| 4794 | ||||
| 4795 | case Expr::CXXNoexceptExprClass: | |||
| 4796 | NotPrimaryExpr(); | |||
| 4797 | Out << "nx"; | |||
| 4798 | mangleExpression(cast<CXXNoexceptExpr>(E)->getOperand()); | |||
| 4799 | break; | |||
| 4800 | ||||
| 4801 | case Expr::UnaryExprOrTypeTraitExprClass: { | |||
| 4802 | // Non-instantiation-dependent traits are an <expr-primary> integer literal. | |||
| 4803 | const UnaryExprOrTypeTraitExpr *SAE = cast<UnaryExprOrTypeTraitExpr>(E); | |||
| 4804 | ||||
| 4805 | if (!SAE->isInstantiationDependent()) { | |||
| 4806 | // Itanium C++ ABI: | |||
| 4807 | // If the operand of a sizeof or alignof operator is not | |||
| 4808 | // instantiation-dependent it is encoded as an integer literal | |||
| 4809 | // reflecting the result of the operator. | |||
| 4810 | // | |||
| 4811 | // If the result of the operator is implicitly converted to a known | |||
| 4812 | // integer type, that type is used for the literal; otherwise, the type | |||
| 4813 | // of std::size_t or std::ptrdiff_t is used. | |||
| 4814 | QualType T = (ImplicitlyConvertedToType.isNull() || | |||
| 4815 | !ImplicitlyConvertedToType->isIntegerType())? SAE->getType() | |||
| 4816 | : ImplicitlyConvertedToType; | |||
| 4817 | llvm::APSInt V = SAE->EvaluateKnownConstInt(Context.getASTContext()); | |||
| 4818 | mangleIntegerLiteral(T, V); | |||
| 4819 | break; | |||
| 4820 | } | |||
| 4821 | ||||
| 4822 | NotPrimaryExpr(); // But otherwise, they are not. | |||
| 4823 | ||||
| 4824 | auto MangleAlignofSizeofArg = [&] { | |||
| 4825 | if (SAE->isArgumentType()) { | |||
| 4826 | Out << 't'; | |||
| 4827 | mangleType(SAE->getArgumentType()); | |||
| 4828 | } else { | |||
| 4829 | Out << 'z'; | |||
| 4830 | mangleExpression(SAE->getArgumentExpr()); | |||
| 4831 | } | |||
| 4832 | }; | |||
| 4833 | ||||
| 4834 | switch(SAE->getKind()) { | |||
| 4835 | case UETT_SizeOf: | |||
| 4836 | Out << 's'; | |||
| 4837 | MangleAlignofSizeofArg(); | |||
| 4838 | break; | |||
| 4839 | case UETT_PreferredAlignOf: | |||
| 4840 | // As of clang 12, we mangle __alignof__ differently than alignof. (They | |||
| 4841 | // have acted differently since Clang 8, but were previously mangled the | |||
| 4842 | // same.) | |||
| 4843 | if (Context.getASTContext().getLangOpts().getClangABICompat() > | |||
| 4844 | LangOptions::ClangABI::Ver11) { | |||
| 4845 | Out << "u11__alignof__"; | |||
| 4846 | if (SAE->isArgumentType()) | |||
| 4847 | mangleType(SAE->getArgumentType()); | |||
| 4848 | else | |||
| 4849 | mangleTemplateArgExpr(SAE->getArgumentExpr()); | |||
| 4850 | Out << 'E'; | |||
| 4851 | break; | |||
| 4852 | } | |||
| 4853 | [[fallthrough]]; | |||
| 4854 | case UETT_AlignOf: | |||
| 4855 | Out << 'a'; | |||
| 4856 | MangleAlignofSizeofArg(); | |||
| 4857 | break; | |||
| 4858 | case UETT_VecStep: { | |||
| 4859 | DiagnosticsEngine &Diags = Context.getDiags(); | |||
| 4860 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, | |||
| 4861 | "cannot yet mangle vec_step expression"); | |||
| 4862 | Diags.Report(DiagID); | |||
| 4863 | return; | |||
| 4864 | } | |||
| 4865 | case UETT_OpenMPRequiredSimdAlign: { | |||
| 4866 | DiagnosticsEngine &Diags = Context.getDiags(); | |||
| 4867 | unsigned DiagID = Diags.getCustomDiagID( | |||
| 4868 | DiagnosticsEngine::Error, | |||
| 4869 | "cannot yet mangle __builtin_omp_required_simd_align expression"); | |||
| 4870 | Diags.Report(DiagID); | |||
| 4871 | return; | |||
| 4872 | } | |||
| 4873 | } | |||
| 4874 | break; | |||
| 4875 | } | |||
| 4876 | ||||
| 4877 | case Expr::CXXThrowExprClass: { | |||
| 4878 | NotPrimaryExpr(); | |||
| 4879 | const CXXThrowExpr *TE = cast<CXXThrowExpr>(E); | |||
| 4880 | // <expression> ::= tw <expression> # throw expression | |||
| 4881 | // ::= tr # rethrow | |||
| 4882 | if (TE->getSubExpr()) { | |||
| 4883 | Out << "tw"; | |||
| 4884 | mangleExpression(TE->getSubExpr()); | |||
| 4885 | } else { | |||
| 4886 | Out << "tr"; | |||
| 4887 | } | |||
| 4888 | break; | |||
| 4889 | } | |||
| 4890 | ||||
| 4891 | case Expr::CXXTypeidExprClass: { | |||
| 4892 | NotPrimaryExpr(); | |||
| 4893 | const CXXTypeidExpr *TIE = cast<CXXTypeidExpr>(E); | |||
| 4894 | // <expression> ::= ti <type> # typeid (type) | |||
| 4895 | // ::= te <expression> # typeid (expression) | |||
| 4896 | if (TIE->isTypeOperand()) { | |||
| 4897 | Out << "ti"; | |||
| 4898 | mangleType(TIE->getTypeOperand(Context.getASTContext())); | |||
| 4899 | } else { | |||
| 4900 | Out << "te"; | |||
| 4901 | mangleExpression(TIE->getExprOperand()); | |||
| 4902 | } | |||
| 4903 | break; | |||
| 4904 | } | |||
| 4905 | ||||
| 4906 | case Expr::CXXDeleteExprClass: { | |||
| 4907 | NotPrimaryExpr(); | |||
| 4908 | const CXXDeleteExpr *DE = cast<CXXDeleteExpr>(E); | |||
| 4909 | // <expression> ::= [gs] dl <expression> # [::] delete expr | |||
| 4910 | // ::= [gs] da <expression> # [::] delete [] expr | |||
| 4911 | if (DE->isGlobalDelete()) Out << "gs"; | |||
| 4912 | Out << (DE->isArrayForm() ? "da" : "dl"); | |||
| 4913 | mangleExpression(DE->getArgument()); | |||
| 4914 | break; | |||
| 4915 | } | |||
| 4916 | ||||
| 4917 | case Expr::UnaryOperatorClass: { | |||
| 4918 | NotPrimaryExpr(); | |||
| 4919 | const UnaryOperator *UO = cast<UnaryOperator>(E); | |||
| 4920 | mangleOperatorName(UnaryOperator::getOverloadedOperator(UO->getOpcode()), | |||
| 4921 | /*Arity=*/1); | |||
| 4922 | mangleExpression(UO->getSubExpr()); | |||
| 4923 | break; | |||
| 4924 | } | |||
| 4925 | ||||
| 4926 | case Expr::ArraySubscriptExprClass: { | |||
| 4927 | NotPrimaryExpr(); | |||
| 4928 | const ArraySubscriptExpr *AE = cast<ArraySubscriptExpr>(E); | |||
| 4929 | ||||
| 4930 | // Array subscript is treated as a syntactically weird form of | |||
| 4931 | // binary operator. | |||
| 4932 | Out << "ix"; | |||
| 4933 | mangleExpression(AE->getLHS()); | |||
| 4934 | mangleExpression(AE->getRHS()); | |||
| 4935 | break; | |||
| 4936 | } | |||
| 4937 | ||||
| 4938 | case Expr::MatrixSubscriptExprClass: { | |||
| 4939 | NotPrimaryExpr(); | |||
| 4940 | const MatrixSubscriptExpr *ME = cast<MatrixSubscriptExpr>(E); | |||
| 4941 | Out << "ixix"; | |||
| 4942 | mangleExpression(ME->getBase()); | |||
| 4943 | mangleExpression(ME->getRowIdx()); | |||
| 4944 | mangleExpression(ME->getColumnIdx()); | |||
| 4945 | break; | |||
| 4946 | } | |||
| 4947 | ||||
| 4948 | case Expr::CompoundAssignOperatorClass: // fallthrough | |||
| 4949 | case Expr::BinaryOperatorClass: { | |||
| 4950 | NotPrimaryExpr(); | |||
| 4951 | const BinaryOperator *BO = cast<BinaryOperator>(E); | |||
| 4952 | if (BO->getOpcode() == BO_PtrMemD) | |||
| 4953 | Out << "ds"; | |||
| 4954 | else | |||
| 4955 | mangleOperatorName(BinaryOperator::getOverloadedOperator(BO->getOpcode()), | |||
| 4956 | /*Arity=*/2); | |||
| 4957 | mangleExpression(BO->getLHS()); | |||
| 4958 | mangleExpression(BO->getRHS()); | |||
| 4959 | break; | |||
| 4960 | } | |||
| 4961 | ||||
| 4962 | case Expr::CXXRewrittenBinaryOperatorClass: { | |||
| 4963 | NotPrimaryExpr(); | |||
| 4964 | // The mangled form represents the original syntax. | |||
| 4965 | CXXRewrittenBinaryOperator::DecomposedForm Decomposed = | |||
| 4966 | cast<CXXRewrittenBinaryOperator>(E)->getDecomposedForm(); | |||
| 4967 | mangleOperatorName(BinaryOperator::getOverloadedOperator(Decomposed.Opcode), | |||
| 4968 | /*Arity=*/2); | |||
| 4969 | mangleExpression(Decomposed.LHS); | |||
| 4970 | mangleExpression(Decomposed.RHS); | |||
| 4971 | break; | |||
| 4972 | } | |||
| 4973 | ||||
| 4974 | case Expr::ConditionalOperatorClass: { | |||
| 4975 | NotPrimaryExpr(); | |||
| 4976 | const ConditionalOperator *CO = cast<ConditionalOperator>(E); | |||
| 4977 | mangleOperatorName(OO_Conditional, /*Arity=*/3); | |||
| 4978 | mangleExpression(CO->getCond()); | |||
| 4979 | mangleExpression(CO->getLHS(), Arity); | |||
| 4980 | mangleExpression(CO->getRHS(), Arity); | |||
| 4981 | break; | |||
| 4982 | } | |||
| 4983 | ||||
| 4984 | case Expr::ImplicitCastExprClass: { | |||
| 4985 | ImplicitlyConvertedToType = E->getType(); | |||
| 4986 | E = cast<ImplicitCastExpr>(E)->getSubExpr(); | |||
| 4987 | goto recurse; | |||
| 4988 | } | |||
| 4989 | ||||
| 4990 | case Expr::ObjCBridgedCastExprClass: { | |||
| 4991 | NotPrimaryExpr(); | |||
| 4992 | // Mangle ownership casts as a vendor extended operator __bridge, | |||
| 4993 | // __bridge_transfer, or __bridge_retain. | |||
| 4994 | StringRef Kind = cast<ObjCBridgedCastExpr>(E)->getBridgeKindName(); | |||
| 4995 | Out << "v1U" << Kind.size() << Kind; | |||
| 4996 | mangleCastExpression(E, "cv"); | |||
| 4997 | break; | |||
| 4998 | } | |||
| 4999 | ||||
| 5000 | case Expr::CStyleCastExprClass: | |||
| 5001 | NotPrimaryExpr(); | |||
| 5002 | mangleCastExpression(E, "cv"); | |||
| 5003 | break; | |||
| 5004 | ||||
| 5005 | case Expr::CXXFunctionalCastExprClass: { | |||
| 5006 | NotPrimaryExpr(); | |||
| 5007 | auto *Sub = cast<ExplicitCastExpr>(E)->getSubExpr()->IgnoreImplicit(); | |||
| 5008 | // FIXME: Add isImplicit to CXXConstructExpr. | |||
| 5009 | if (auto *CCE = dyn_cast<CXXConstructExpr>(Sub)) | |||
| 5010 | if (CCE->getParenOrBraceRange().isInvalid()) | |||
| 5011 | Sub = CCE->getArg(0)->IgnoreImplicit(); | |||
| 5012 | if (auto *StdInitList = dyn_cast<CXXStdInitializerListExpr>(Sub)) | |||
| 5013 | Sub = StdInitList->getSubExpr()->IgnoreImplicit(); | |||
| 5014 | if (auto *IL = dyn_cast<InitListExpr>(Sub)) { | |||
| 5015 | Out << "tl"; | |||
| 5016 | mangleType(E->getType()); | |||
| 5017 | mangleInitListElements(IL); | |||
| 5018 | Out << "E"; | |||
| 5019 | } else { | |||
| 5020 | mangleCastExpression(E, "cv"); | |||
| 5021 | } | |||
| 5022 | break; | |||
| 5023 | } | |||
| 5024 | ||||
| 5025 | case Expr::CXXStaticCastExprClass: | |||
| 5026 | NotPrimaryExpr(); | |||
| 5027 | mangleCastExpression(E, "sc"); | |||
| 5028 | break; | |||
| 5029 | case Expr::CXXDynamicCastExprClass: | |||
| 5030 | NotPrimaryExpr(); | |||
| 5031 | mangleCastExpression(E, "dc"); | |||
| 5032 | break; | |||
| 5033 | case Expr::CXXReinterpretCastExprClass: | |||
| 5034 | NotPrimaryExpr(); | |||
| 5035 | mangleCastExpression(E, "rc"); | |||
| 5036 | break; | |||
| 5037 | case Expr::CXXConstCastExprClass: | |||
| 5038 | NotPrimaryExpr(); | |||
| 5039 | mangleCastExpression(E, "cc"); | |||
| 5040 | break; | |||
| 5041 | case Expr::CXXAddrspaceCastExprClass: | |||
| 5042 | NotPrimaryExpr(); | |||
| 5043 | mangleCastExpression(E, "ac"); | |||
| 5044 | break; | |||
| 5045 | ||||
| 5046 | case Expr::CXXOperatorCallExprClass: { | |||
| 5047 | NotPrimaryExpr(); | |||
| 5048 | const CXXOperatorCallExpr *CE = cast<CXXOperatorCallExpr>(E); | |||
| 5049 | unsigned NumArgs = CE->getNumArgs(); | |||
| 5050 | // A CXXOperatorCallExpr for OO_Arrow models only semantics, not syntax | |||
| 5051 | // (the enclosing MemberExpr covers the syntactic portion). | |||
| 5052 | if (CE->getOperator() != OO_Arrow) | |||
| 5053 | mangleOperatorName(CE->getOperator(), /*Arity=*/NumArgs); | |||
| 5054 | // Mangle the arguments. | |||
| 5055 | for (unsigned i = 0; i != NumArgs; ++i) | |||
| 5056 | mangleExpression(CE->getArg(i)); | |||
| 5057 | break; | |||
| 5058 | } | |||
| 5059 | ||||
| 5060 | case Expr::ParenExprClass: | |||
| 5061 | E = cast<ParenExpr>(E)->getSubExpr(); | |||
| 5062 | goto recurse; | |||
| 5063 | ||||
| 5064 | case Expr::ConceptSpecializationExprClass: { | |||
| 5065 | // <expr-primary> ::= L <mangled-name> E # external name | |||
| 5066 | Out << "L_Z"; | |||
| 5067 | auto *CSE = cast<ConceptSpecializationExpr>(E); | |||
| 5068 | mangleTemplateName(CSE->getNamedConcept(), CSE->getTemplateArguments()); | |||
| 5069 | Out << 'E'; | |||
| 5070 | break; | |||
| 5071 | } | |||
| 5072 | ||||
| 5073 | case Expr::DeclRefExprClass: | |||
| 5074 | // MangleDeclRefExpr helper handles primary-vs-nonprimary | |||
| 5075 | MangleDeclRefExpr(cast<DeclRefExpr>(E)->getDecl()); | |||
| 5076 | break; | |||
| 5077 | ||||
| 5078 | case Expr::SubstNonTypeTemplateParmPackExprClass: | |||
| 5079 | NotPrimaryExpr(); | |||
| 5080 | // FIXME: not clear how to mangle this! | |||
| 5081 | // template <unsigned N...> class A { | |||
| 5082 | // template <class U...> void foo(U (&x)[N]...); | |||
| 5083 | // }; | |||
| 5084 | Out << "_SUBSTPACK_"; | |||
| 5085 | break; | |||
| 5086 | ||||
| 5087 | case Expr::FunctionParmPackExprClass: { | |||
| 5088 | NotPrimaryExpr(); | |||
| 5089 | // FIXME: not clear how to mangle this! | |||
| 5090 | const FunctionParmPackExpr *FPPE = cast<FunctionParmPackExpr>(E); | |||
| 5091 | Out << "v110_SUBSTPACK"; | |||
| 5092 | MangleDeclRefExpr(FPPE->getParameterPack()); | |||
| 5093 | break; | |||
| 5094 | } | |||
| 5095 | ||||
| 5096 | case Expr::DependentScopeDeclRefExprClass: { | |||
| 5097 | NotPrimaryExpr(); | |||
| 5098 | const DependentScopeDeclRefExpr *DRE = cast<DependentScopeDeclRefExpr>(E); | |||
| 5099 | mangleUnresolvedName(DRE->getQualifier(), DRE->getDeclName(), | |||
| 5100 | DRE->getTemplateArgs(), DRE->getNumTemplateArgs(), | |||
| 5101 | Arity); | |||
| 5102 | break; | |||
| 5103 | } | |||
| 5104 | ||||
| 5105 | case Expr::CXXBindTemporaryExprClass: | |||
| 5106 | E = cast<CXXBindTemporaryExpr>(E)->getSubExpr(); | |||
| 5107 | goto recurse; | |||
| 5108 | ||||
| 5109 | case Expr::ExprWithCleanupsClass: | |||
| 5110 | E = cast<ExprWithCleanups>(E)->getSubExpr(); | |||
| 5111 | goto recurse; | |||
| 5112 | ||||
| 5113 | case Expr::FloatingLiteralClass: { | |||
| 5114 | // <expr-primary> | |||
| 5115 | const FloatingLiteral *FL = cast<FloatingLiteral>(E); | |||
| 5116 | mangleFloatLiteral(FL->getType(), FL->getValue()); | |||
| 5117 | break; | |||
| 5118 | } | |||
| 5119 | ||||
| 5120 | case Expr::FixedPointLiteralClass: | |||
| 5121 | // Currently unimplemented -- might be <expr-primary> in future? | |||
| 5122 | mangleFixedPointLiteral(); | |||
| 5123 | break; | |||
| 5124 | ||||
| 5125 | case Expr::CharacterLiteralClass: | |||
| 5126 | // <expr-primary> | |||
| 5127 | Out << 'L'; | |||
| 5128 | mangleType(E->getType()); | |||
| 5129 | Out << cast<CharacterLiteral>(E)->getValue(); | |||
| 5130 | Out << 'E'; | |||
| 5131 | break; | |||
| 5132 | ||||
| 5133 | // FIXME. __objc_yes/__objc_no are mangled same as true/false | |||
| 5134 | case Expr::ObjCBoolLiteralExprClass: | |||
| 5135 | // <expr-primary> | |||
| 5136 | Out << "Lb"; | |||
| 5137 | Out << (cast<ObjCBoolLiteralExpr>(E)->getValue() ? '1' : '0'); | |||
| 5138 | Out << 'E'; | |||
| 5139 | break; | |||
| 5140 | ||||
| 5141 | case Expr::CXXBoolLiteralExprClass: | |||
| 5142 | // <expr-primary> | |||
| 5143 | Out << "Lb"; | |||
| 5144 | Out << (cast<CXXBoolLiteralExpr>(E)->getValue() ? '1' : '0'); | |||
| 5145 | Out << 'E'; | |||
| 5146 | break; | |||
| 5147 | ||||
| 5148 | case Expr::IntegerLiteralClass: { | |||
| 5149 | // <expr-primary> | |||
| 5150 | llvm::APSInt Value(cast<IntegerLiteral>(E)->getValue()); | |||
| 5151 | if (E->getType()->isSignedIntegerType()) | |||
| 5152 | Value.setIsSigned(true); | |||
| 5153 | mangleIntegerLiteral(E->getType(), Value); | |||
| 5154 | break; | |||
| 5155 | } | |||
| 5156 | ||||
| 5157 | case Expr::ImaginaryLiteralClass: { | |||
| 5158 | // <expr-primary> | |||
| 5159 | const ImaginaryLiteral *IE = cast<ImaginaryLiteral>(E); | |||
| 5160 | // Mangle as if a complex literal. | |||
| 5161 | // Proposal from David Vandevoorde, 2010.06.30. | |||
| 5162 | Out << 'L'; | |||
| 5163 | mangleType(E->getType()); | |||
| 5164 | if (const FloatingLiteral *Imag = | |||
| 5165 | dyn_cast<FloatingLiteral>(IE->getSubExpr())) { | |||
| 5166 | // Mangle a floating-point zero of the appropriate type. | |||
| 5167 | mangleFloat(llvm::APFloat(Imag->getValue().getSemantics())); | |||
| 5168 | Out << '_'; | |||
| 5169 | mangleFloat(Imag->getValue()); | |||
| 5170 | } else { | |||
| 5171 | Out << "0_"; | |||
| 5172 | llvm::APSInt Value(cast<IntegerLiteral>(IE->getSubExpr())->getValue()); | |||
| 5173 | if (IE->getSubExpr()->getType()->isSignedIntegerType()) | |||
| 5174 | Value.setIsSigned(true); | |||
| 5175 | mangleNumber(Value); | |||
| 5176 | } | |||
| 5177 | Out << 'E'; | |||
| 5178 | break; | |||
| 5179 | } | |||
| 5180 | ||||
| 5181 | case Expr::StringLiteralClass: { | |||
| 5182 | // <expr-primary> | |||
| 5183 | // Revised proposal from David Vandervoorde, 2010.07.15. | |||
| 5184 | Out << 'L'; | |||
| 5185 | assert(isa<ConstantArrayType>(E->getType()))(static_cast <bool> (isa<ConstantArrayType>(E-> getType())) ? void (0) : __assert_fail ("isa<ConstantArrayType>(E->getType())" , "clang/lib/AST/ItaniumMangle.cpp", 5185, __extension__ __PRETTY_FUNCTION__ )); | |||
| 5186 | mangleType(E->getType()); | |||
| 5187 | Out << 'E'; | |||
| 5188 | break; | |||
| 5189 | } | |||
| 5190 | ||||
| 5191 | case Expr::GNUNullExprClass: | |||
| 5192 | // <expr-primary> | |||
| 5193 | // Mangle as if an integer literal 0. | |||
| 5194 | mangleIntegerLiteral(E->getType(), llvm::APSInt(32)); | |||
| 5195 | break; | |||
| 5196 | ||||
| 5197 | case Expr::CXXNullPtrLiteralExprClass: { | |||
| 5198 | // <expr-primary> | |||
| 5199 | Out << "LDnE"; | |||
| 5200 | break; | |||
| 5201 | } | |||
| 5202 | ||||
| 5203 | case Expr::LambdaExprClass: { | |||
| 5204 | // A lambda-expression can't appear in the signature of an | |||
| 5205 | // externally-visible declaration, so there's no standard mangling for | |||
| 5206 | // this, but mangling as a literal of the closure type seems reasonable. | |||
| 5207 | Out << "L"; | |||
| 5208 | mangleType(Context.getASTContext().getRecordType(cast<LambdaExpr>(E)->getLambdaClass())); | |||
| 5209 | Out << "E"; | |||
| 5210 | break; | |||
| 5211 | } | |||
| 5212 | ||||
| 5213 | case Expr::PackExpansionExprClass: | |||
| 5214 | NotPrimaryExpr(); | |||
| 5215 | Out << "sp"; | |||
| 5216 | mangleExpression(cast<PackExpansionExpr>(E)->getPattern()); | |||
| 5217 | break; | |||
| 5218 | ||||
| 5219 | case Expr::SizeOfPackExprClass: { | |||
| 5220 | NotPrimaryExpr(); | |||
| 5221 | auto *SPE = cast<SizeOfPackExpr>(E); | |||
| 5222 | if (SPE->isPartiallySubstituted()) { | |||
| 5223 | Out << "sP"; | |||
| 5224 | for (const auto &A : SPE->getPartialArguments()) | |||
| 5225 | mangleTemplateArg(A, false); | |||
| 5226 | Out << "E"; | |||
| 5227 | break; | |||
| 5228 | } | |||
| 5229 | ||||
| 5230 | Out << "sZ"; | |||
| 5231 | const NamedDecl *Pack = SPE->getPack(); | |||
| 5232 | if (const TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(Pack)) | |||
| 5233 | mangleTemplateParameter(TTP->getDepth(), TTP->getIndex()); | |||
| 5234 | else if (const NonTypeTemplateParmDecl *NTTP | |||
| 5235 | = dyn_cast<NonTypeTemplateParmDecl>(Pack)) | |||
| 5236 | mangleTemplateParameter(NTTP->getDepth(), NTTP->getIndex()); | |||
| 5237 | else if (const TemplateTemplateParmDecl *TempTP | |||
| 5238 | = dyn_cast<TemplateTemplateParmDecl>(Pack)) | |||
| 5239 | mangleTemplateParameter(TempTP->getDepth(), TempTP->getIndex()); | |||
| 5240 | else | |||
| 5241 | mangleFunctionParam(cast<ParmVarDecl>(Pack)); | |||
| 5242 | break; | |||
| 5243 | } | |||
| 5244 | ||||
| 5245 | case Expr::MaterializeTemporaryExprClass: | |||
| 5246 | E = cast<MaterializeTemporaryExpr>(E)->getSubExpr(); | |||
| 5247 | goto recurse; | |||
| 5248 | ||||
| 5249 | case Expr::CXXFoldExprClass: { | |||
| 5250 | NotPrimaryExpr(); | |||
| 5251 | auto *FE = cast<CXXFoldExpr>(E); | |||
| 5252 | if (FE->isLeftFold()) | |||
| 5253 | Out << (FE->getInit() ? "fL" : "fl"); | |||
| 5254 | else | |||
| 5255 | Out << (FE->getInit() ? "fR" : "fr"); | |||
| 5256 | ||||
| 5257 | if (FE->getOperator() == BO_PtrMemD) | |||
| 5258 | Out << "ds"; | |||
| 5259 | else | |||
| 5260 | mangleOperatorName( | |||
| 5261 | BinaryOperator::getOverloadedOperator(FE->getOperator()), | |||
| 5262 | /*Arity=*/2); | |||
| 5263 | ||||
| 5264 | if (FE->getLHS()) | |||
| 5265 | mangleExpression(FE->getLHS()); | |||
| 5266 | if (FE->getRHS()) | |||
| 5267 | mangleExpression(FE->getRHS()); | |||
| 5268 | break; | |||
| 5269 | } | |||
| 5270 | ||||
| 5271 | case Expr::CXXThisExprClass: | |||
| 5272 | NotPrimaryExpr(); | |||
| 5273 | Out << "fpT"; | |||
| 5274 | break; | |||
| 5275 | ||||
| 5276 | case Expr::CoawaitExprClass: | |||
| 5277 | // FIXME: Propose a non-vendor mangling. | |||
| 5278 | NotPrimaryExpr(); | |||
| 5279 | Out << "v18co_await"; | |||
| 5280 | mangleExpression(cast<CoawaitExpr>(E)->getOperand()); | |||
| 5281 | break; | |||
| 5282 | ||||
| 5283 | case Expr::DependentCoawaitExprClass: | |||
| 5284 | // FIXME: Propose a non-vendor mangling. | |||
| 5285 | NotPrimaryExpr(); | |||
| 5286 | Out << "v18co_await"; | |||
| 5287 | mangleExpression(cast<DependentCoawaitExpr>(E)->getOperand()); | |||
| 5288 | break; | |||
| 5289 | ||||
| 5290 | case Expr::CoyieldExprClass: | |||
| 5291 | // FIXME: Propose a non-vendor mangling. | |||
| 5292 | NotPrimaryExpr(); | |||
| 5293 | Out << "v18co_yield"; | |||
| 5294 | mangleExpression(cast<CoawaitExpr>(E)->getOperand()); | |||
| 5295 | break; | |||
| 5296 | case Expr::SYCLUniqueStableNameExprClass: { | |||
| 5297 | const auto *USN = cast<SYCLUniqueStableNameExpr>(E); | |||
| 5298 | NotPrimaryExpr(); | |||
| 5299 | ||||
| 5300 | Out << "u33__builtin_sycl_unique_stable_name"; | |||
| 5301 | mangleType(USN->getTypeSourceInfo()->getType()); | |||
| 5302 | ||||
| 5303 | Out << "E"; | |||
| 5304 | break; | |||
| 5305 | } | |||
| 5306 | } | |||
| 5307 | ||||
| 5308 | if (AsTemplateArg && !IsPrimaryExpr) | |||
| 5309 | Out << 'E'; | |||
| 5310 | } | |||
| 5311 | ||||
| 5312 | /// Mangle an expression which refers to a parameter variable. | |||
| 5313 | /// | |||
| 5314 | /// <expression> ::= <function-param> | |||
| 5315 | /// <function-param> ::= fp <top-level CV-qualifiers> _ # L == 0, I == 0 | |||
| 5316 | /// <function-param> ::= fp <top-level CV-qualifiers> | |||
| 5317 | /// <parameter-2 non-negative number> _ # L == 0, I > 0 | |||
| 5318 | /// <function-param> ::= fL <L-1 non-negative number> | |||
| 5319 | /// p <top-level CV-qualifiers> _ # L > 0, I == 0 | |||
| 5320 | /// <function-param> ::= fL <L-1 non-negative number> | |||
| 5321 | /// p <top-level CV-qualifiers> | |||
| 5322 | /// <I-1 non-negative number> _ # L > 0, I > 0 | |||
| 5323 | /// | |||
| 5324 | /// L is the nesting depth of the parameter, defined as 1 if the | |||
| 5325 | /// parameter comes from the innermost function prototype scope | |||
| 5326 | /// enclosing the current context, 2 if from the next enclosing | |||
| 5327 | /// function prototype scope, and so on, with one special case: if | |||
| 5328 | /// we've processed the full parameter clause for the innermost | |||
| 5329 | /// function type, then L is one less. This definition conveniently | |||
| 5330 | /// makes it irrelevant whether a function's result type was written | |||
| 5331 | /// trailing or leading, but is otherwise overly complicated; the | |||
| 5332 | /// numbering was first designed without considering references to | |||
| 5333 | /// parameter in locations other than return types, and then the | |||
| 5334 | /// mangling had to be generalized without changing the existing | |||
| 5335 | /// manglings. | |||
| 5336 | /// | |||
| 5337 | /// I is the zero-based index of the parameter within its parameter | |||
| 5338 | /// declaration clause. Note that the original ABI document describes | |||
| 5339 | /// this using 1-based ordinals. | |||
| 5340 | void CXXNameMangler::mangleFunctionParam(const ParmVarDecl *parm) { | |||
| 5341 | unsigned parmDepth = parm->getFunctionScopeDepth(); | |||
| 5342 | unsigned parmIndex = parm->getFunctionScopeIndex(); | |||
| 5343 | ||||
| 5344 | // Compute 'L'. | |||
| 5345 | // parmDepth does not include the declaring function prototype. | |||
| 5346 | // FunctionTypeDepth does account for that. | |||
| 5347 | assert(parmDepth < FunctionTypeDepth.getDepth())(static_cast <bool> (parmDepth < FunctionTypeDepth.getDepth ()) ? void (0) : __assert_fail ("parmDepth < FunctionTypeDepth.getDepth()" , "clang/lib/AST/ItaniumMangle.cpp", 5347, __extension__ __PRETTY_FUNCTION__ )); | |||
| 5348 | unsigned nestingDepth = FunctionTypeDepth.getDepth() - parmDepth; | |||
| 5349 | if (FunctionTypeDepth.isInResultType()) | |||
| 5350 | nestingDepth--; | |||
| 5351 | ||||
| 5352 | if (nestingDepth == 0) { | |||
| 5353 | Out << "fp"; | |||
| 5354 | } else { | |||
| 5355 | Out << "fL" << (nestingDepth - 1) << 'p'; | |||
| 5356 | } | |||
| 5357 | ||||
| 5358 | // Top-level qualifiers. We don't have to worry about arrays here, | |||
| 5359 | // because parameters declared as arrays should already have been | |||
| 5360 | // transformed to have pointer type. FIXME: apparently these don't | |||
| 5361 | // get mangled if used as an rvalue of a known non-class type? | |||
| 5362 | assert(!parm->getType()->isArrayType()(static_cast <bool> (!parm->getType()->isArrayType () && "parameter's type is still an array type?") ? void (0) : __assert_fail ("!parm->getType()->isArrayType() && \"parameter's type is still an array type?\"" , "clang/lib/AST/ItaniumMangle.cpp", 5363, __extension__ __PRETTY_FUNCTION__ )) | |||
| 5363 | && "parameter's type is still an array type?")(static_cast <bool> (!parm->getType()->isArrayType () && "parameter's type is still an array type?") ? void (0) : __assert_fail ("!parm->getType()->isArrayType() && \"parameter's type is still an array type?\"" , "clang/lib/AST/ItaniumMangle.cpp", 5363, __extension__ __PRETTY_FUNCTION__ )); | |||
| 5364 | ||||
| 5365 | if (const DependentAddressSpaceType *DAST = | |||
| 5366 | dyn_cast<DependentAddressSpaceType>(parm->getType())) { | |||
| 5367 | mangleQualifiers(DAST->getPointeeType().getQualifiers(), DAST); | |||
| 5368 | } else { | |||
| 5369 | mangleQualifiers(parm->getType().getQualifiers()); | |||
| 5370 | } | |||
| 5371 | ||||
| 5372 | // Parameter index. | |||
| 5373 | if (parmIndex != 0) { | |||
| 5374 | Out << (parmIndex - 1); | |||
| 5375 | } | |||
| 5376 | Out << '_'; | |||
| 5377 | } | |||
| 5378 | ||||
| 5379 | void CXXNameMangler::mangleCXXCtorType(CXXCtorType T, | |||
| 5380 | const CXXRecordDecl *InheritedFrom) { | |||
| 5381 | // <ctor-dtor-name> ::= C1 # complete object constructor | |||
| 5382 | // ::= C2 # base object constructor | |||
| 5383 | // ::= CI1 <type> # complete inheriting constructor | |||
| 5384 | // ::= CI2 <type> # base inheriting constructor | |||
| 5385 | // | |||
| 5386 | // In addition, C5 is a comdat name with C1 and C2 in it. | |||
| 5387 | Out << 'C'; | |||
| 5388 | if (InheritedFrom) | |||
| 5389 | Out << 'I'; | |||
| 5390 | switch (T) { | |||
| 5391 | case Ctor_Complete: | |||
| 5392 | Out << '1'; | |||
| 5393 | break; | |||
| 5394 | case Ctor_Base: | |||
| 5395 | Out << '2'; | |||
| 5396 | break; | |||
| 5397 | case Ctor_Comdat: | |||
| 5398 | Out << '5'; | |||
| 5399 | break; | |||
| 5400 | case Ctor_DefaultClosure: | |||
| 5401 | case Ctor_CopyingClosure: | |||
| 5402 | llvm_unreachable("closure constructors don't exist for the Itanium ABI!")::llvm::llvm_unreachable_internal("closure constructors don't exist for the Itanium ABI!" , "clang/lib/AST/ItaniumMangle.cpp", 5402); | |||
| 5403 | } | |||
| 5404 | if (InheritedFrom) | |||
| 5405 | mangleName(InheritedFrom); | |||
| 5406 | } | |||
| 5407 | ||||
| 5408 | void CXXNameMangler::mangleCXXDtorType(CXXDtorType T) { | |||
| 5409 | // <ctor-dtor-name> ::= D0 # deleting destructor | |||
| 5410 | // ::= D1 # complete object destructor | |||
| 5411 | // ::= D2 # base object destructor | |||
| 5412 | // | |||
| 5413 | // In addition, D5 is a comdat name with D1, D2 and, if virtual, D0 in it. | |||
| 5414 | switch (T) { | |||
| 5415 | case Dtor_Deleting: | |||
| 5416 | Out << "D0"; | |||
| 5417 | break; | |||
| 5418 | case Dtor_Complete: | |||
| 5419 | Out << "D1"; | |||
| 5420 | break; | |||
| 5421 | case Dtor_Base: | |||
| 5422 | Out << "D2"; | |||
| 5423 | break; | |||
| 5424 | case Dtor_Comdat: | |||
| 5425 | Out << "D5"; | |||
| 5426 | break; | |||
| 5427 | } | |||
| 5428 | } | |||
| 5429 | ||||
| 5430 | namespace { | |||
| 5431 | // Helper to provide ancillary information on a template used to mangle its | |||
| 5432 | // arguments. | |||
| 5433 | struct TemplateArgManglingInfo { | |||
| 5434 | TemplateDecl *ResolvedTemplate = nullptr; | |||
| 5435 | bool SeenPackExpansionIntoNonPack = false; | |||
| 5436 | const NamedDecl *UnresolvedExpandedPack = nullptr; | |||
| 5437 | ||||
| 5438 | TemplateArgManglingInfo(TemplateName TN) { | |||
| 5439 | if (TemplateDecl *TD = TN.getAsTemplateDecl()) | |||
| 5440 | ResolvedTemplate = TD; | |||
| 5441 | } | |||
| 5442 | ||||
| 5443 | /// Do we need to mangle template arguments with exactly correct types? | |||
| 5444 | /// | |||
| 5445 | /// This should be called exactly once for each parameter / argument pair, in | |||
| 5446 | /// order. | |||
| 5447 | bool needExactType(unsigned ParamIdx, const TemplateArgument &Arg) { | |||
| 5448 | // We need correct types when the template-name is unresolved or when it | |||
| 5449 | // names a template that is able to be overloaded. | |||
| 5450 | if (!ResolvedTemplate || SeenPackExpansionIntoNonPack) | |||
| 5451 | return true; | |||
| 5452 | ||||
| 5453 | // Move to the next parameter. | |||
| 5454 | const NamedDecl *Param = UnresolvedExpandedPack; | |||
| 5455 | if (!Param) { | |||
| 5456 | assert(ParamIdx < ResolvedTemplate->getTemplateParameters()->size() &&(static_cast <bool> (ParamIdx < ResolvedTemplate-> getTemplateParameters()->size() && "no parameter for argument" ) ? void (0) : __assert_fail ("ParamIdx < ResolvedTemplate->getTemplateParameters()->size() && \"no parameter for argument\"" , "clang/lib/AST/ItaniumMangle.cpp", 5457, __extension__ __PRETTY_FUNCTION__ )) | |||
| 5457 | "no parameter for argument")(static_cast <bool> (ParamIdx < ResolvedTemplate-> getTemplateParameters()->size() && "no parameter for argument" ) ? void (0) : __assert_fail ("ParamIdx < ResolvedTemplate->getTemplateParameters()->size() && \"no parameter for argument\"" , "clang/lib/AST/ItaniumMangle.cpp", 5457, __extension__ __PRETTY_FUNCTION__ )); | |||
| 5458 | Param = ResolvedTemplate->getTemplateParameters()->getParam(ParamIdx); | |||
| 5459 | ||||
| 5460 | // If we reach an expanded parameter pack whose argument isn't in pack | |||
| 5461 | // form, that means Sema couldn't figure out which arguments belonged to | |||
| 5462 | // it, because it contains a pack expansion. Track the expanded pack for | |||
| 5463 | // all further template arguments until we hit that pack expansion. | |||
| 5464 | if (Param->isParameterPack() && Arg.getKind() != TemplateArgument::Pack) { | |||
| 5465 | assert(getExpandedPackSize(Param) &&(static_cast <bool> (getExpandedPackSize(Param) && "failed to form pack argument for parameter pack") ? void (0 ) : __assert_fail ("getExpandedPackSize(Param) && \"failed to form pack argument for parameter pack\"" , "clang/lib/AST/ItaniumMangle.cpp", 5466, __extension__ __PRETTY_FUNCTION__ )) | |||
| 5466 | "failed to form pack argument for parameter pack")(static_cast <bool> (getExpandedPackSize(Param) && "failed to form pack argument for parameter pack") ? void (0 ) : __assert_fail ("getExpandedPackSize(Param) && \"failed to form pack argument for parameter pack\"" , "clang/lib/AST/ItaniumMangle.cpp", 5466, __extension__ __PRETTY_FUNCTION__ )); | |||
| 5467 | UnresolvedExpandedPack = Param; | |||
| 5468 | } | |||
| 5469 | } | |||
| 5470 | ||||
| 5471 | // If we encounter a pack argument that is expanded into a non-pack | |||
| 5472 | // parameter, we can no longer track parameter / argument correspondence, | |||
| 5473 | // and need to use exact types from this point onwards. | |||
| 5474 | if (Arg.isPackExpansion() && | |||
| 5475 | (!Param->isParameterPack() || UnresolvedExpandedPack)) { | |||
| 5476 | SeenPackExpansionIntoNonPack = true; | |||
| 5477 | return true; | |||
| 5478 | } | |||
| 5479 | ||||
| 5480 | // We need exact types for function template arguments because they might be | |||
| 5481 | // overloaded on template parameter type. As a special case, a member | |||
| 5482 | // function template of a generic lambda is not overloadable. | |||
| 5483 | if (auto *FTD = dyn_cast<FunctionTemplateDecl>(ResolvedTemplate)) { | |||
| 5484 | auto *RD = dyn_cast<CXXRecordDecl>(FTD->getDeclContext()); | |||
| 5485 | if (!RD || !RD->isGenericLambda()) | |||
| 5486 | return true; | |||
| 5487 | } | |||
| 5488 | ||||
| 5489 | // Otherwise, we only need a correct type if the parameter has a deduced | |||
| 5490 | // type. | |||
| 5491 | // | |||
| 5492 | // Note: for an expanded parameter pack, getType() returns the type prior | |||
| 5493 | // to expansion. We could ask for the expanded type with getExpansionType(), | |||
| 5494 | // but it doesn't matter because substitution and expansion don't affect | |||
| 5495 | // whether a deduced type appears in the type. | |||
| 5496 | auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param); | |||
| 5497 | return NTTP && NTTP->getType()->getContainedDeducedType(); | |||
| 5498 | } | |||
| 5499 | }; | |||
| 5500 | } | |||
| 5501 | ||||
| 5502 | void CXXNameMangler::mangleTemplateArgs(TemplateName TN, | |||
| 5503 | const TemplateArgumentLoc *TemplateArgs, | |||
| 5504 | unsigned NumTemplateArgs) { | |||
| 5505 | // <template-args> ::= I <template-arg>+ E | |||
| 5506 | Out << 'I'; | |||
| 5507 | TemplateArgManglingInfo Info(TN); | |||
| 5508 | for (unsigned i = 0; i != NumTemplateArgs; ++i) | |||
| 5509 | mangleTemplateArg(TemplateArgs[i].getArgument(), | |||
| 5510 | Info.needExactType(i, TemplateArgs[i].getArgument())); | |||
| 5511 | Out << 'E'; | |||
| 5512 | } | |||
| 5513 | ||||
| 5514 | void CXXNameMangler::mangleTemplateArgs(TemplateName TN, | |||
| 5515 | const TemplateArgumentList &AL) { | |||
| 5516 | // <template-args> ::= I <template-arg>+ E | |||
| 5517 | Out << 'I'; | |||
| 5518 | TemplateArgManglingInfo Info(TN); | |||
| 5519 | for (unsigned i = 0, e = AL.size(); i != e; ++i) | |||
| 5520 | mangleTemplateArg(AL[i], Info.needExactType(i, AL[i])); | |||
| 5521 | Out << 'E'; | |||
| 5522 | } | |||
| 5523 | ||||
| 5524 | void CXXNameMangler::mangleTemplateArgs(TemplateName TN, | |||
| 5525 | ArrayRef<TemplateArgument> Args) { | |||
| 5526 | // <template-args> ::= I <template-arg>+ E | |||
| 5527 | Out << 'I'; | |||
| 5528 | TemplateArgManglingInfo Info(TN); | |||
| 5529 | for (unsigned i = 0; i != Args.size(); ++i) | |||
| 5530 | mangleTemplateArg(Args[i], Info.needExactType(i, Args[i])); | |||
| 5531 | Out << 'E'; | |||
| 5532 | } | |||
| 5533 | ||||
| 5534 | void CXXNameMangler::mangleTemplateArg(TemplateArgument A, bool NeedExactType) { | |||
| 5535 | // <template-arg> ::= <type> # type or template | |||
| 5536 | // ::= X <expression> E # expression | |||
| 5537 | // ::= <expr-primary> # simple expressions | |||
| 5538 | // ::= J <template-arg>* E # argument pack | |||
| 5539 | if (!A.isInstantiationDependent() || A.isDependent()) | |||
| 5540 | A = Context.getASTContext().getCanonicalTemplateArgument(A); | |||
| 5541 | ||||
| 5542 | switch (A.getKind()) { | |||
| 5543 | case TemplateArgument::Null: | |||
| 5544 | llvm_unreachable("Cannot mangle NULL template argument")::llvm::llvm_unreachable_internal("Cannot mangle NULL template argument" , "clang/lib/AST/ItaniumMangle.cpp", 5544); | |||
| 5545 | ||||
| 5546 | case TemplateArgument::Type: | |||
| 5547 | mangleType(A.getAsType()); | |||
| 5548 | break; | |||
| 5549 | case TemplateArgument::Template: | |||
| 5550 | // This is mangled as <type>. | |||
| 5551 | mangleType(A.getAsTemplate()); | |||
| 5552 | break; | |||
| 5553 | case TemplateArgument::TemplateExpansion: | |||
| 5554 | // <type> ::= Dp <type> # pack expansion (C++0x) | |||
| 5555 | Out << "Dp"; | |||
| 5556 | mangleType(A.getAsTemplateOrTemplatePattern()); | |||
| 5557 | break; | |||
| 5558 | case TemplateArgument::Expression: | |||
| 5559 | mangleTemplateArgExpr(A.getAsExpr()); | |||
| 5560 | break; | |||
| 5561 | case TemplateArgument::Integral: | |||
| 5562 | mangleIntegerLiteral(A.getIntegralType(), A.getAsIntegral()); | |||
| 5563 | break; | |||
| 5564 | case TemplateArgument::Declaration: { | |||
| 5565 | // <expr-primary> ::= L <mangled-name> E # external name | |||
| 5566 | ValueDecl *D = A.getAsDecl(); | |||
| 5567 | ||||
| 5568 | // Template parameter objects are modeled by reproducing a source form | |||
| 5569 | // produced as if by aggregate initialization. | |||
| 5570 | if (A.getParamTypeForDecl()->isRecordType()) { | |||
| 5571 | auto *TPO = cast<TemplateParamObjectDecl>(D); | |||
| 5572 | mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(), | |||
| 5573 | TPO->getValue(), /*TopLevel=*/true, | |||
| 5574 | NeedExactType); | |||
| 5575 | break; | |||
| 5576 | } | |||
| 5577 | ||||
| 5578 | ASTContext &Ctx = Context.getASTContext(); | |||
| 5579 | APValue Value; | |||
| 5580 | if (D->isCXXInstanceMember()) | |||
| 5581 | // Simple pointer-to-member with no conversion. | |||
| 5582 | Value = APValue(D, /*IsDerivedMember=*/false, /*Path=*/{}); | |||
| 5583 | else if (D->getType()->isArrayType() && | |||
| 5584 | Ctx.hasSimilarType(Ctx.getDecayedType(D->getType()), | |||
| 5585 | A.getParamTypeForDecl()) && | |||
| 5586 | Ctx.getLangOpts().getClangABICompat() > | |||
| 5587 | LangOptions::ClangABI::Ver11) | |||
| 5588 | // Build a value corresponding to this implicit array-to-pointer decay. | |||
| 5589 | Value = APValue(APValue::LValueBase(D), CharUnits::Zero(), | |||
| 5590 | {APValue::LValuePathEntry::ArrayIndex(0)}, | |||
| 5591 | /*OnePastTheEnd=*/false); | |||
| 5592 | else | |||
| 5593 | // Regular pointer or reference to a declaration. | |||
| 5594 | Value = APValue(APValue::LValueBase(D), CharUnits::Zero(), | |||
| 5595 | ArrayRef<APValue::LValuePathEntry>(), | |||
| 5596 | /*OnePastTheEnd=*/false); | |||
| 5597 | mangleValueInTemplateArg(A.getParamTypeForDecl(), Value, /*TopLevel=*/true, | |||
| 5598 | NeedExactType); | |||
| 5599 | break; | |||
| 5600 | } | |||
| 5601 | case TemplateArgument::NullPtr: { | |||
| 5602 | mangleNullPointer(A.getNullPtrType()); | |||
| 5603 | break; | |||
| 5604 | } | |||
| 5605 | case TemplateArgument::Pack: { | |||
| 5606 | // <template-arg> ::= J <template-arg>* E | |||
| 5607 | Out << 'J'; | |||
| 5608 | for (const auto &P : A.pack_elements()) | |||
| 5609 | mangleTemplateArg(P, NeedExactType); | |||
| 5610 | Out << 'E'; | |||
| 5611 | } | |||
| 5612 | } | |||
| 5613 | } | |||
| 5614 | ||||
| 5615 | void CXXNameMangler::mangleTemplateArgExpr(const Expr *E) { | |||
| 5616 | ASTContext &Ctx = Context.getASTContext(); | |||
| 5617 | if (Ctx.getLangOpts().getClangABICompat() > LangOptions::ClangABI::Ver11) { | |||
| 5618 | mangleExpression(E, UnknownArity, /*AsTemplateArg=*/true); | |||
| 5619 | return; | |||
| 5620 | } | |||
| 5621 | ||||
| 5622 | // Prior to Clang 12, we didn't omit the X .. E around <expr-primary> | |||
| 5623 | // correctly in cases where the template argument was | |||
| 5624 | // constructed from an expression rather than an already-evaluated | |||
| 5625 | // literal. In such a case, we would then e.g. emit 'XLi0EE' instead of | |||
| 5626 | // 'Li0E'. | |||
| 5627 | // | |||
| 5628 | // We did special-case DeclRefExpr to attempt to DTRT for that one | |||
| 5629 | // expression-kind, but while doing so, unfortunately handled ParmVarDecl | |||
| 5630 | // (subtype of VarDecl) _incorrectly_, and emitted 'L_Z .. E' instead of | |||
| 5631 | // the proper 'Xfp_E'. | |||
| 5632 | E = E->IgnoreParenImpCasts(); | |||
| 5633 | if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) { | |||
| 5634 | const ValueDecl *D = DRE->getDecl(); | |||
| 5635 | if (isa<VarDecl>(D) || isa<FunctionDecl>(D)) { | |||
| 5636 | Out << 'L'; | |||
| 5637 | mangle(D); | |||
| 5638 | Out << 'E'; | |||
| 5639 | return; | |||
| 5640 | } | |||
| 5641 | } | |||
| 5642 | Out << 'X'; | |||
| 5643 | mangleExpression(E); | |||
| 5644 | Out << 'E'; | |||
| 5645 | } | |||
| 5646 | ||||
| 5647 | /// Determine whether a given value is equivalent to zero-initialization for | |||
| 5648 | /// the purpose of discarding a trailing portion of a 'tl' mangling. | |||
| 5649 | /// | |||
| 5650 | /// Note that this is not in general equivalent to determining whether the | |||
| 5651 | /// value has an all-zeroes bit pattern. | |||
| 5652 | static bool isZeroInitialized(QualType T, const APValue &V) { | |||
| 5653 | // FIXME: mangleValueInTemplateArg has quadratic time complexity in | |||
| 5654 | // pathological cases due to using this, but it's a little awkward | |||
| 5655 | // to do this in linear time in general. | |||
| 5656 | switch (V.getKind()) { | |||
| 5657 | case APValue::None: | |||
| 5658 | case APValue::Indeterminate: | |||
| 5659 | case APValue::AddrLabelDiff: | |||
| 5660 | return false; | |||
| 5661 | ||||
| 5662 | case APValue::Struct: { | |||
| 5663 | const CXXRecordDecl *RD = T->getAsCXXRecordDecl(); | |||
| 5664 | assert(RD && "unexpected type for record value")(static_cast <bool> (RD && "unexpected type for record value" ) ? void (0) : __assert_fail ("RD && \"unexpected type for record value\"" , "clang/lib/AST/ItaniumMangle.cpp", 5664, __extension__ __PRETTY_FUNCTION__ )); | |||
| 5665 | unsigned I = 0; | |||
| 5666 | for (const CXXBaseSpecifier &BS : RD->bases()) { | |||
| 5667 | if (!isZeroInitialized(BS.getType(), V.getStructBase(I))) | |||
| 5668 | return false; | |||
| 5669 | ++I; | |||
| 5670 | } | |||
| 5671 | I = 0; | |||
| 5672 | for (const FieldDecl *FD : RD->fields()) { | |||
| 5673 | if (!FD->isUnnamedBitfield() && | |||
| 5674 | !isZeroInitialized(FD->getType(), V.getStructField(I))) | |||
| 5675 | return false; | |||
| 5676 | ++I; | |||
| 5677 | } | |||
| 5678 | return true; | |||
| 5679 | } | |||
| 5680 | ||||
| 5681 | case APValue::Union: { | |||
| 5682 | const CXXRecordDecl *RD = T->getAsCXXRecordDecl(); | |||
| 5683 | assert(RD && "unexpected type for union value")(static_cast <bool> (RD && "unexpected type for union value" ) ? void (0) : __assert_fail ("RD && \"unexpected type for union value\"" , "clang/lib/AST/ItaniumMangle.cpp", 5683, __extension__ __PRETTY_FUNCTION__ )); | |||
| 5684 | // Zero-initialization zeroes the first non-unnamed-bitfield field, if any. | |||
| 5685 | for (const FieldDecl *FD : RD->fields()) { | |||
| 5686 | if (!FD->isUnnamedBitfield()) | |||
| 5687 | return V.getUnionField() && declaresSameEntity(FD, V.getUnionField()) && | |||
| 5688 | isZeroInitialized(FD->getType(), V.getUnionValue()); | |||
| 5689 | } | |||
| 5690 | // If there are no fields (other than unnamed bitfields), the value is | |||
| 5691 | // necessarily zero-initialized. | |||
| 5692 | return true; | |||
| 5693 | } | |||
| 5694 | ||||
| 5695 | case APValue::Array: { | |||
| 5696 | QualType ElemT(T->getArrayElementTypeNoTypeQual(), 0); | |||
| 5697 | for (unsigned I = 0, N = V.getArrayInitializedElts(); I != N; ++I) | |||
| 5698 | if (!isZeroInitialized(ElemT, V.getArrayInitializedElt(I))) | |||
| 5699 | return false; | |||
| 5700 | return !V.hasArrayFiller() || isZeroInitialized(ElemT, V.getArrayFiller()); | |||
| 5701 | } | |||
| 5702 | ||||
| 5703 | case APValue::Vector: { | |||
| 5704 | const VectorType *VT = T->castAs<VectorType>(); | |||
| 5705 | for (unsigned I = 0, N = V.getVectorLength(); I != N; ++I) | |||
| 5706 | if (!isZeroInitialized(VT->getElementType(), V.getVectorElt(I))) | |||
| 5707 | return false; | |||
| 5708 | return true; | |||
| 5709 | } | |||
| 5710 | ||||
| 5711 | case APValue::Int: | |||
| 5712 | return !V.getInt(); | |||
| 5713 | ||||
| 5714 | case APValue::Float: | |||
| 5715 | return V.getFloat().isPosZero(); | |||
| 5716 | ||||
| 5717 | case APValue::FixedPoint: | |||
| 5718 | return !V.getFixedPoint().getValue(); | |||
| 5719 | ||||
| 5720 | case APValue::ComplexFloat: | |||
| 5721 | return V.getComplexFloatReal().isPosZero() && | |||
| 5722 | V.getComplexFloatImag().isPosZero(); | |||
| 5723 | ||||
| 5724 | case APValue::ComplexInt: | |||
| 5725 | return !V.getComplexIntReal() && !V.getComplexIntImag(); | |||
| 5726 | ||||
| 5727 | case APValue::LValue: | |||
| 5728 | return V.isNullPointer(); | |||
| 5729 | ||||
| 5730 | case APValue::MemberPointer: | |||
| 5731 | return !V.getMemberPointerDecl(); | |||
| 5732 | } | |||
| 5733 | ||||
| 5734 | llvm_unreachable("Unhandled APValue::ValueKind enum")::llvm::llvm_unreachable_internal("Unhandled APValue::ValueKind enum" , "clang/lib/AST/ItaniumMangle.cpp", 5734); | |||
| 5735 | } | |||
| 5736 | ||||
| 5737 | static QualType getLValueType(ASTContext &Ctx, const APValue &LV) { | |||
| 5738 | QualType T = LV.getLValueBase().getType(); | |||
| 5739 | for (APValue::LValuePathEntry E : LV.getLValuePath()) { | |||
| 5740 | if (const ArrayType *AT = Ctx.getAsArrayType(T)) | |||
| 5741 | T = AT->getElementType(); | |||
| 5742 | else if (const FieldDecl *FD = | |||
| 5743 | dyn_cast<FieldDecl>(E.getAsBaseOrMember().getPointer())) | |||
| 5744 | T = FD->getType(); | |||
| 5745 | else | |||
| 5746 | T = Ctx.getRecordType( | |||
| 5747 | cast<CXXRecordDecl>(E.getAsBaseOrMember().getPointer())); | |||
| 5748 | } | |||
| 5749 | return T; | |||
| 5750 | } | |||
| 5751 | ||||
| 5752 | static IdentifierInfo *getUnionInitName(SourceLocation UnionLoc, | |||
| 5753 | DiagnosticsEngine &Diags, | |||
| 5754 | const FieldDecl *FD) { | |||
| 5755 | // According to: | |||
| 5756 | // http://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling.anonymous | |||
| 5757 | // For the purposes of mangling, the name of an anonymous union is considered | |||
| 5758 | // to be the name of the first named data member found by a pre-order, | |||
| 5759 | // depth-first, declaration-order walk of the data members of the anonymous | |||
| 5760 | // union. | |||
| 5761 | ||||
| 5762 | if (FD->getIdentifier()) | |||
| 5763 | return FD->getIdentifier(); | |||
| 5764 | ||||
| 5765 | // The only cases where the identifer of a FieldDecl would be blank is if the | |||
| 5766 | // field represents an anonymous record type or if it is an unnamed bitfield. | |||
| 5767 | // There is no type to descend into in the case of a bitfield, so we can just | |||
| 5768 | // return nullptr in that case. | |||
| 5769 | if (FD->isBitField()) | |||
| 5770 | return nullptr; | |||
| 5771 | const CXXRecordDecl *RD = FD->getType()->getAsCXXRecordDecl(); | |||
| 5772 | ||||
| 5773 | // Consider only the fields in declaration order, searched depth-first. We | |||
| 5774 | // don't care about the active member of the union, as all we are doing is | |||
| 5775 | // looking for a valid name. We also don't check bases, due to guidance from | |||
| 5776 | // the Itanium ABI folks. | |||
| 5777 | for (const FieldDecl *RDField : RD->fields()) { | |||
| 5778 | if (IdentifierInfo *II = getUnionInitName(UnionLoc, Diags, RDField)) | |||
| 5779 | return II; | |||
| 5780 | } | |||
| 5781 | ||||
| 5782 | // According to the Itanium ABI: If there is no such data member (i.e., if all | |||
| 5783 | // of the data members in the union are unnamed), then there is no way for a | |||
| 5784 | // program to refer to the anonymous union, and there is therefore no need to | |||
| 5785 | // mangle its name. However, we should diagnose this anyway. | |||
| 5786 | unsigned DiagID = Diags.getCustomDiagID( | |||
| 5787 | DiagnosticsEngine::Error, "cannot mangle this unnamed union NTTP yet"); | |||
| 5788 | Diags.Report(UnionLoc, DiagID); | |||
| 5789 | ||||
| 5790 | return nullptr; | |||
| 5791 | } | |||
| 5792 | ||||
| 5793 | void CXXNameMangler::mangleValueInTemplateArg(QualType T, const APValue &V, | |||
| 5794 | bool TopLevel, | |||
| 5795 | bool NeedExactType) { | |||
| 5796 | // Ignore all top-level cv-qualifiers, to match GCC. | |||
| 5797 | Qualifiers Quals; | |||
| 5798 | T = getASTContext().getUnqualifiedArrayType(T, Quals); | |||
| 5799 | ||||
| 5800 | // A top-level expression that's not a primary expression is wrapped in X...E. | |||
| 5801 | bool IsPrimaryExpr = true; | |||
| 5802 | auto NotPrimaryExpr = [&] { | |||
| 5803 | if (TopLevel && IsPrimaryExpr) | |||
| 5804 | Out << 'X'; | |||
| 5805 | IsPrimaryExpr = false; | |||
| 5806 | }; | |||
| 5807 | ||||
| 5808 | // Proposed in https://github.com/itanium-cxx-abi/cxx-abi/issues/63. | |||
| 5809 | switch (V.getKind()) { | |||
| 5810 | case APValue::None: | |||
| 5811 | case APValue::Indeterminate: | |||
| 5812 | Out << 'L'; | |||
| 5813 | mangleType(T); | |||
| 5814 | Out << 'E'; | |||
| 5815 | break; | |||
| 5816 | ||||
| 5817 | case APValue::AddrLabelDiff: | |||
| 5818 | llvm_unreachable("unexpected value kind in template argument")::llvm::llvm_unreachable_internal("unexpected value kind in template argument" , "clang/lib/AST/ItaniumMangle.cpp", 5818); | |||
| 5819 | ||||
| 5820 | case APValue::Struct: { | |||
| 5821 | const CXXRecordDecl *RD = T->getAsCXXRecordDecl(); | |||
| 5822 | assert(RD && "unexpected type for record value")(static_cast <bool> (RD && "unexpected type for record value" ) ? void (0) : __assert_fail ("RD && \"unexpected type for record value\"" , "clang/lib/AST/ItaniumMangle.cpp", 5822, __extension__ __PRETTY_FUNCTION__ )); | |||
| 5823 | ||||
| 5824 | // Drop trailing zero-initialized elements. | |||
| 5825 | llvm::SmallVector<const FieldDecl *, 16> Fields(RD->fields()); | |||
| 5826 | while ( | |||
| 5827 | !Fields.empty() && | |||
| 5828 | (Fields.back()->isUnnamedBitfield() || | |||
| 5829 | isZeroInitialized(Fields.back()->getType(), | |||
| 5830 | V.getStructField(Fields.back()->getFieldIndex())))) { | |||
| 5831 | Fields.pop_back(); | |||
| 5832 | } | |||
| 5833 | llvm::ArrayRef<CXXBaseSpecifier> Bases(RD->bases_begin(), RD->bases_end()); | |||
| 5834 | if (Fields.empty()) { | |||
| 5835 | while (!Bases.empty() && | |||
| 5836 | isZeroInitialized(Bases.back().getType(), | |||
| 5837 | V.getStructBase(Bases.size() - 1))) | |||
| 5838 | Bases = Bases.drop_back(); | |||
| 5839 | } | |||
| 5840 | ||||
| 5841 | // <expression> ::= tl <type> <braced-expression>* E | |||
| 5842 | NotPrimaryExpr(); | |||
| 5843 | Out << "tl"; | |||
| 5844 | mangleType(T); | |||
| 5845 | for (unsigned I = 0, N = Bases.size(); I != N; ++I) | |||
| 5846 | mangleValueInTemplateArg(Bases[I].getType(), V.getStructBase(I), false); | |||
| 5847 | for (unsigned I = 0, N = Fields.size(); I != N; ++I) { | |||
| 5848 | if (Fields[I]->isUnnamedBitfield()) | |||
| 5849 | continue; | |||
| 5850 | mangleValueInTemplateArg(Fields[I]->getType(), | |||
| 5851 | V.getStructField(Fields[I]->getFieldIndex()), | |||
| 5852 | false); | |||
| 5853 | } | |||
| 5854 | Out << 'E'; | |||
| 5855 | break; | |||
| 5856 | } | |||
| 5857 | ||||
| 5858 | case APValue::Union: { | |||
| 5859 | assert(T->getAsCXXRecordDecl() && "unexpected type for union value")(static_cast <bool> (T->getAsCXXRecordDecl() && "unexpected type for union value") ? void (0) : __assert_fail ("T->getAsCXXRecordDecl() && \"unexpected type for union value\"" , "clang/lib/AST/ItaniumMangle.cpp", 5859, __extension__ __PRETTY_FUNCTION__ )); | |||
| 5860 | const FieldDecl *FD = V.getUnionField(); | |||
| 5861 | ||||
| 5862 | if (!FD) { | |||
| 5863 | Out << 'L'; | |||
| 5864 | mangleType(T); | |||
| 5865 | Out << 'E'; | |||
| 5866 | break; | |||
| 5867 | } | |||
| 5868 | ||||
| 5869 | // <braced-expression> ::= di <field source-name> <braced-expression> | |||
| 5870 | NotPrimaryExpr(); | |||
| 5871 | Out << "tl"; | |||
| 5872 | mangleType(T); | |||
| 5873 | if (!isZeroInitialized(T, V)) { | |||
| 5874 | Out << "di"; | |||
| 5875 | IdentifierInfo *II = (getUnionInitName( | |||
| 5876 | T->getAsCXXRecordDecl()->getLocation(), Context.getDiags(), FD)); | |||
| 5877 | if (II) | |||
| 5878 | mangleSourceName(II); | |||
| 5879 | mangleValueInTemplateArg(FD->getType(), V.getUnionValue(), false); | |||
| 5880 | } | |||
| 5881 | Out << 'E'; | |||
| 5882 | break; | |||
| 5883 | } | |||
| 5884 | ||||
| 5885 | case APValue::Array: { | |||
| 5886 | QualType ElemT(T->getArrayElementTypeNoTypeQual(), 0); | |||
| 5887 | ||||
| 5888 | NotPrimaryExpr(); | |||
| 5889 | Out << "tl"; | |||
| 5890 | mangleType(T); | |||
| 5891 | ||||
| 5892 | // Drop trailing zero-initialized elements. | |||
| 5893 | unsigned N = V.getArraySize(); | |||
| 5894 | if (!V.hasArrayFiller() || isZeroInitialized(ElemT, V.getArrayFiller())) { | |||
| 5895 | N = V.getArrayInitializedElts(); | |||
| 5896 | while (N && isZeroInitialized(ElemT, V.getArrayInitializedElt(N - 1))) | |||
| 5897 | --N; | |||
| 5898 | } | |||
| 5899 | ||||
| 5900 | for (unsigned I = 0; I != N; ++I) { | |||
| 5901 | const APValue &Elem = I < V.getArrayInitializedElts() | |||
| 5902 | ? V.getArrayInitializedElt(I) | |||
| 5903 | : V.getArrayFiller(); | |||
| 5904 | mangleValueInTemplateArg(ElemT, Elem, false); | |||
| 5905 | } | |||
| 5906 | Out << 'E'; | |||
| 5907 | break; | |||
| 5908 | } | |||
| 5909 | ||||
| 5910 | case APValue::Vector: { | |||
| 5911 | const VectorType *VT = T->castAs<VectorType>(); | |||
| 5912 | ||||
| 5913 | NotPrimaryExpr(); | |||
| 5914 | Out << "tl"; | |||
| 5915 | mangleType(T); | |||
| 5916 | unsigned N = V.getVectorLength(); | |||
| 5917 | while (N && isZeroInitialized(VT->getElementType(), V.getVectorElt(N - 1))) | |||
| 5918 | --N; | |||
| 5919 | for (unsigned I = 0; I != N; ++I) | |||
| 5920 | mangleValueInTemplateArg(VT->getElementType(), V.getVectorElt(I), false); | |||
| 5921 | Out << 'E'; | |||
| 5922 | break; | |||
| 5923 | } | |||
| 5924 | ||||
| 5925 | case APValue::Int: | |||
| 5926 | mangleIntegerLiteral(T, V.getInt()); | |||
| 5927 | break; | |||
| 5928 | ||||
| 5929 | case APValue::Float: | |||
| 5930 | mangleFloatLiteral(T, V.getFloat()); | |||
| 5931 | break; | |||
| 5932 | ||||
| 5933 | case APValue::FixedPoint: | |||
| 5934 | mangleFixedPointLiteral(); | |||
| 5935 | break; | |||
| 5936 | ||||
| 5937 | case APValue::ComplexFloat: { | |||
| 5938 | const ComplexType *CT = T->castAs<ComplexType>(); | |||
| 5939 | NotPrimaryExpr(); | |||
| 5940 | Out << "tl"; | |||
| 5941 | mangleType(T); | |||
| 5942 | if (!V.getComplexFloatReal().isPosZero() || | |||
| 5943 | !V.getComplexFloatImag().isPosZero()) | |||
| 5944 | mangleFloatLiteral(CT->getElementType(), V.getComplexFloatReal()); | |||
| 5945 | if (!V.getComplexFloatImag().isPosZero()) | |||
| 5946 | mangleFloatLiteral(CT->getElementType(), V.getComplexFloatImag()); | |||
| 5947 | Out << 'E'; | |||
| 5948 | break; | |||
| 5949 | } | |||
| 5950 | ||||
| 5951 | case APValue::ComplexInt: { | |||
| 5952 | const ComplexType *CT = T->castAs<ComplexType>(); | |||
| 5953 | NotPrimaryExpr(); | |||
| 5954 | Out << "tl"; | |||
| 5955 | mangleType(T); | |||
| 5956 | if (V.getComplexIntReal().getBoolValue() || | |||
| 5957 | V.getComplexIntImag().getBoolValue()) | |||
| 5958 | mangleIntegerLiteral(CT->getElementType(), V.getComplexIntReal()); | |||
| 5959 | if (V.getComplexIntImag().getBoolValue()) | |||
| 5960 | mangleIntegerLiteral(CT->getElementType(), V.getComplexIntImag()); | |||
| 5961 | Out << 'E'; | |||
| 5962 | break; | |||
| 5963 | } | |||
| 5964 | ||||
| 5965 | case APValue::LValue: { | |||
| 5966 | // Proposed in https://github.com/itanium-cxx-abi/cxx-abi/issues/47. | |||
| 5967 | assert((T->isPointerType() || T->isReferenceType()) &&(static_cast <bool> ((T->isPointerType() || T->isReferenceType ()) && "unexpected type for LValue template arg") ? void (0) : __assert_fail ("(T->isPointerType() || T->isReferenceType()) && \"unexpected type for LValue template arg\"" , "clang/lib/AST/ItaniumMangle.cpp", 5968, __extension__ __PRETTY_FUNCTION__ )) | |||
| 5968 | "unexpected type for LValue template arg")(static_cast <bool> ((T->isPointerType() || T->isReferenceType ()) && "unexpected type for LValue template arg") ? void (0) : __assert_fail ("(T->isPointerType() || T->isReferenceType()) && \"unexpected type for LValue template arg\"" , "clang/lib/AST/ItaniumMangle.cpp", 5968, __extension__ __PRETTY_FUNCTION__ )); | |||
| 5969 | ||||
| 5970 | if (V.isNullPointer()) { | |||
| 5971 | mangleNullPointer(T); | |||
| 5972 | break; | |||
| 5973 | } | |||
| 5974 | ||||
| 5975 | APValue::LValueBase B = V.getLValueBase(); | |||
| 5976 | if (!B) { | |||
| 5977 | // Non-standard mangling for integer cast to a pointer; this can only | |||
| 5978 | // occur as an extension. | |||
| 5979 | CharUnits Offset = V.getLValueOffset(); | |||
| 5980 | if (Offset.isZero()) { | |||
| 5981 | // This is reinterpret_cast<T*>(0), not a null pointer. Mangle this as | |||
| 5982 | // a cast, because L <type> 0 E means something else. | |||
| 5983 | NotPrimaryExpr(); | |||
| 5984 | Out << "rc"; | |||
| 5985 | mangleType(T); | |||
| 5986 | Out << "Li0E"; | |||
| 5987 | if (TopLevel) | |||
| 5988 | Out << 'E'; | |||
| 5989 | } else { | |||
| 5990 | Out << "L"; | |||
| 5991 | mangleType(T); | |||
| 5992 | Out << Offset.getQuantity() << 'E'; | |||
| 5993 | } | |||
| 5994 | break; | |||
| 5995 | } | |||
| 5996 | ||||
| 5997 | ASTContext &Ctx = Context.getASTContext(); | |||
| 5998 | ||||
| 5999 | enum { Base, Offset, Path } Kind; | |||
| 6000 | if (!V.hasLValuePath()) { | |||
| 6001 | // Mangle as (T*)((char*)&base + N). | |||
| 6002 | if (T->isReferenceType()) { | |||
| 6003 | NotPrimaryExpr(); | |||
| 6004 | Out << "decvP"; | |||
| 6005 | mangleType(T->getPointeeType()); | |||
| 6006 | } else { | |||
| 6007 | NotPrimaryExpr(); | |||
| 6008 | Out << "cv"; | |||
| 6009 | mangleType(T); | |||
| 6010 | } | |||
| 6011 | Out << "plcvPcad"; | |||
| 6012 | Kind = Offset; | |||
| 6013 | } else { | |||
| 6014 | if (!V.getLValuePath().empty() || V.isLValueOnePastTheEnd()) { | |||
| 6015 | NotPrimaryExpr(); | |||
| 6016 | // A final conversion to the template parameter's type is usually | |||
| 6017 | // folded into the 'so' mangling, but we can't do that for 'void*' | |||
| 6018 | // parameters without introducing collisions. | |||
| 6019 | if (NeedExactType && T->isVoidPointerType()) { | |||
| 6020 | Out << "cv"; | |||
| 6021 | mangleType(T); | |||
| 6022 | } | |||
| 6023 | if (T->isPointerType()) | |||
| 6024 | Out << "ad"; | |||
| 6025 | Out << "so"; | |||
| 6026 | mangleType(T->isVoidPointerType() | |||
| 6027 | ? getLValueType(Ctx, V).getUnqualifiedType() | |||
| 6028 | : T->getPointeeType()); | |||
| 6029 | Kind = Path; | |||
| 6030 | } else { | |||
| 6031 | if (NeedExactType && | |||
| 6032 | !Ctx.hasSameType(T->getPointeeType(), getLValueType(Ctx, V)) && | |||
| 6033 | Ctx.getLangOpts().getClangABICompat() > | |||
| 6034 | LangOptions::ClangABI::Ver11) { | |||
| 6035 | NotPrimaryExpr(); | |||
| 6036 | Out << "cv"; | |||
| 6037 | mangleType(T); | |||
| 6038 | } | |||
| 6039 | if (T->isPointerType()) { | |||
| 6040 | NotPrimaryExpr(); | |||
| 6041 | Out << "ad"; | |||
| 6042 | } | |||
| 6043 | Kind = Base; | |||
| 6044 | } | |||
| 6045 | } | |||
| 6046 | ||||
| 6047 | QualType TypeSoFar = B.getType(); | |||
| 6048 | if (auto *VD = B.dyn_cast<const ValueDecl*>()) { | |||
| 6049 | Out << 'L'; | |||
| 6050 | mangle(VD); | |||
| 6051 | Out << 'E'; | |||
| 6052 | } else if (auto *E = B.dyn_cast<const Expr*>()) { | |||
| 6053 | NotPrimaryExpr(); | |||
| 6054 | mangleExpression(E); | |||
| 6055 | } else if (auto TI = B.dyn_cast<TypeInfoLValue>()) { | |||
| 6056 | NotPrimaryExpr(); | |||
| 6057 | Out << "ti"; | |||
| 6058 | mangleType(QualType(TI.getType(), 0)); | |||
| 6059 | } else { | |||
| 6060 | // We should never see dynamic allocations here. | |||
| 6061 | llvm_unreachable("unexpected lvalue base kind in template argument")::llvm::llvm_unreachable_internal("unexpected lvalue base kind in template argument" , "clang/lib/AST/ItaniumMangle.cpp", 6061); | |||
| 6062 | } | |||
| 6063 | ||||
| 6064 | switch (Kind) { | |||
| 6065 | case Base: | |||
| 6066 | break; | |||
| 6067 | ||||
| 6068 | case Offset: | |||
| 6069 | Out << 'L'; | |||
| 6070 | mangleType(Ctx.getPointerDiffType()); | |||
| 6071 | mangleNumber(V.getLValueOffset().getQuantity()); | |||
| 6072 | Out << 'E'; | |||
| 6073 | break; | |||
| 6074 | ||||
| 6075 | case Path: | |||
| 6076 | // <expression> ::= so <referent type> <expr> [<offset number>] | |||
| 6077 | // <union-selector>* [p] E | |||
| 6078 | if (!V.getLValueOffset().isZero()) | |||
| 6079 | mangleNumber(V.getLValueOffset().getQuantity()); | |||
| 6080 | ||||
| 6081 | // We model a past-the-end array pointer as array indexing with index N, | |||
| 6082 | // not with the "past the end" flag. Compensate for that. | |||
| 6083 | bool OnePastTheEnd = V.isLValueOnePastTheEnd(); | |||
| 6084 | ||||
| 6085 | for (APValue::LValuePathEntry E : V.getLValuePath()) { | |||
| 6086 | if (auto *AT = TypeSoFar->getAsArrayTypeUnsafe()) { | |||
| 6087 | if (auto *CAT = dyn_cast<ConstantArrayType>(AT)) | |||
| 6088 | OnePastTheEnd |= CAT->getSize() == E.getAsArrayIndex(); | |||
| 6089 | TypeSoFar = AT->getElementType(); | |||
| 6090 | } else { | |||
| 6091 | const Decl *D = E.getAsBaseOrMember().getPointer(); | |||
| 6092 | if (auto *FD = dyn_cast<FieldDecl>(D)) { | |||
| 6093 | // <union-selector> ::= _ <number> | |||
| 6094 | if (FD->getParent()->isUnion()) { | |||
| 6095 | Out << '_'; | |||
| 6096 | if (FD->getFieldIndex()) | |||
| 6097 | Out << (FD->getFieldIndex() - 1); | |||
| 6098 | } | |||
| 6099 | TypeSoFar = FD->getType(); | |||
| 6100 | } else { | |||
| 6101 | TypeSoFar = Ctx.getRecordType(cast<CXXRecordDecl>(D)); | |||
| 6102 | } | |||
| 6103 | } | |||
| 6104 | } | |||
| 6105 | ||||
| 6106 | if (OnePastTheEnd) | |||
| 6107 | Out << 'p'; | |||
| 6108 | Out << 'E'; | |||
| 6109 | break; | |||
| 6110 | } | |||
| 6111 | ||||
| 6112 | break; | |||
| 6113 | } | |||
| 6114 | ||||
| 6115 | case APValue::MemberPointer: | |||
| 6116 | // Proposed in https://github.com/itanium-cxx-abi/cxx-abi/issues/47. | |||
| 6117 | if (!V.getMemberPointerDecl()) { | |||
| 6118 | mangleNullPointer(T); | |||
| 6119 | break; | |||
| 6120 | } | |||
| 6121 | ||||
| 6122 | ASTContext &Ctx = Context.getASTContext(); | |||
| 6123 | ||||
| 6124 | NotPrimaryExpr(); | |||
| 6125 | if (!V.getMemberPointerPath().empty()) { | |||
| 6126 | Out << "mc"; | |||
| 6127 | mangleType(T); | |||
| 6128 | } else if (NeedExactType && | |||
| 6129 | !Ctx.hasSameType( | |||
| 6130 | T->castAs<MemberPointerType>()->getPointeeType(), | |||
| 6131 | V.getMemberPointerDecl()->getType()) && | |||
| 6132 | Ctx.getLangOpts().getClangABICompat() > | |||
| 6133 | LangOptions::ClangABI::Ver11) { | |||
| 6134 | Out << "cv"; | |||
| 6135 | mangleType(T); | |||
| 6136 | } | |||
| 6137 | Out << "adL"; | |||
| 6138 | mangle(V.getMemberPointerDecl()); | |||
| 6139 | Out << 'E'; | |||
| 6140 | if (!V.getMemberPointerPath().empty()) { | |||
| 6141 | CharUnits Offset = | |||
| 6142 | Context.getASTContext().getMemberPointerPathAdjustment(V); | |||
| 6143 | if (!Offset.isZero()) | |||
| 6144 | mangleNumber(Offset.getQuantity()); | |||
| 6145 | Out << 'E'; | |||
| 6146 | } | |||
| 6147 | break; | |||
| 6148 | } | |||
| 6149 | ||||
| 6150 | if (TopLevel && !IsPrimaryExpr) | |||
| 6151 | Out << 'E'; | |||
| 6152 | } | |||
| 6153 | ||||
| 6154 | void CXXNameMangler::mangleTemplateParameter(unsigned Depth, unsigned Index) { | |||
| 6155 | // <template-param> ::= T_ # first template parameter | |||
| 6156 | // ::= T <parameter-2 non-negative number> _ | |||
| 6157 | // ::= TL <L-1 non-negative number> __ | |||
| 6158 | // ::= TL <L-1 non-negative number> _ | |||
| 6159 | // <parameter-2 non-negative number> _ | |||
| 6160 | // | |||
| 6161 | // The latter two manglings are from a proposal here: | |||
| 6162 | // https://github.com/itanium-cxx-abi/cxx-abi/issues/31#issuecomment-528122117 | |||
| 6163 | Out << 'T'; | |||
| 6164 | if (Depth != 0) | |||
| 6165 | Out << 'L' << (Depth - 1) << '_'; | |||
| 6166 | if (Index != 0) | |||
| 6167 | Out << (Index - 1); | |||
| 6168 | Out << '_'; | |||
| 6169 | } | |||
| 6170 | ||||
| 6171 | void CXXNameMangler::mangleSeqID(unsigned SeqID) { | |||
| 6172 | if (SeqID == 0) { | |||
| 6173 | // Nothing. | |||
| 6174 | } else if (SeqID == 1) { | |||
| 6175 | Out << '0'; | |||
| 6176 | } else { | |||
| 6177 | SeqID--; | |||
| 6178 | ||||
| 6179 | // <seq-id> is encoded in base-36, using digits and upper case letters. | |||
| 6180 | char Buffer[7]; // log(2**32) / log(36) ~= 7 | |||
| 6181 | MutableArrayRef<char> BufferRef(Buffer); | |||
| 6182 | MutableArrayRef<char>::reverse_iterator I = BufferRef.rbegin(); | |||
| 6183 | ||||
| 6184 | for (; SeqID != 0; SeqID /= 36) { | |||
| 6185 | unsigned C = SeqID % 36; | |||
| 6186 | *I++ = (C < 10 ? '0' + C : 'A' + C - 10); | |||
| 6187 | } | |||
| 6188 | ||||
| 6189 | Out.write(I.base(), I - BufferRef.rbegin()); | |||
| 6190 | } | |||
| 6191 | Out << '_'; | |||
| 6192 | } | |||
| 6193 | ||||
| 6194 | void CXXNameMangler::mangleExistingSubstitution(TemplateName tname) { | |||
| 6195 | bool result = mangleSubstitution(tname); | |||
| 6196 | assert(result && "no existing substitution for template name")(static_cast <bool> (result && "no existing substitution for template name" ) ? void (0) : __assert_fail ("result && \"no existing substitution for template name\"" , "clang/lib/AST/ItaniumMangle.cpp", 6196, __extension__ __PRETTY_FUNCTION__ )); | |||
| 6197 | (void) result; | |||
| 6198 | } | |||
| 6199 | ||||
| 6200 | // <substitution> ::= S <seq-id> _ | |||
| 6201 | // ::= S_ | |||
| 6202 | bool CXXNameMangler::mangleSubstitution(const NamedDecl *ND) { | |||
| 6203 | // Try one of the standard substitutions first. | |||
| 6204 | if (mangleStandardSubstitution(ND)) | |||
| 6205 | return true; | |||
| 6206 | ||||
| 6207 | ND = cast<NamedDecl>(ND->getCanonicalDecl()); | |||
| 6208 | return mangleSubstitution(reinterpret_cast<uintptr_t>(ND)); | |||
| 6209 | } | |||
| 6210 | ||||
| 6211 | bool CXXNameMangler::mangleSubstitution(NestedNameSpecifier *NNS) { | |||
| 6212 | assert(NNS->getKind() == NestedNameSpecifier::Identifier &&(static_cast <bool> (NNS->getKind() == NestedNameSpecifier ::Identifier && "mangleSubstitution(NestedNameSpecifier *) is only used for " "identifier nested name specifiers.") ? void (0) : __assert_fail ("NNS->getKind() == NestedNameSpecifier::Identifier && \"mangleSubstitution(NestedNameSpecifier *) is only used for \" \"identifier nested name specifiers.\"" , "clang/lib/AST/ItaniumMangle.cpp", 6214, __extension__ __PRETTY_FUNCTION__ )) | |||
| 6213 | "mangleSubstitution(NestedNameSpecifier *) is only used for "(static_cast <bool> (NNS->getKind() == NestedNameSpecifier ::Identifier && "mangleSubstitution(NestedNameSpecifier *) is only used for " "identifier nested name specifiers.") ? void (0) : __assert_fail ("NNS->getKind() == NestedNameSpecifier::Identifier && \"mangleSubstitution(NestedNameSpecifier *) is only used for \" \"identifier nested name specifiers.\"" , "clang/lib/AST/ItaniumMangle.cpp", 6214, __extension__ __PRETTY_FUNCTION__ )) | |||
| 6214 | "identifier nested name specifiers.")(static_cast <bool> (NNS->getKind() == NestedNameSpecifier ::Identifier && "mangleSubstitution(NestedNameSpecifier *) is only used for " "identifier nested name specifiers.") ? void (0) : __assert_fail ("NNS->getKind() == NestedNameSpecifier::Identifier && \"mangleSubstitution(NestedNameSpecifier *) is only used for \" \"identifier nested name specifiers.\"" , "clang/lib/AST/ItaniumMangle.cpp", 6214, __extension__ __PRETTY_FUNCTION__ )); | |||
| 6215 | NNS = Context.getASTContext().getCanonicalNestedNameSpecifier(NNS); | |||
| 6216 | return mangleSubstitution(reinterpret_cast<uintptr_t>(NNS)); | |||
| 6217 | } | |||
| 6218 | ||||
| 6219 | /// Determine whether the given type has any qualifiers that are relevant for | |||
| 6220 | /// substitutions. | |||
| 6221 | static bool hasMangledSubstitutionQualifiers(QualType T) { | |||
| 6222 | Qualifiers Qs = T.getQualifiers(); | |||
| 6223 | return Qs.getCVRQualifiers() || Qs.hasAddressSpace() || Qs.hasUnaligned(); | |||
| 6224 | } | |||
| 6225 | ||||
| 6226 | bool CXXNameMangler::mangleSubstitution(QualType T) { | |||
| 6227 | if (!hasMangledSubstitutionQualifiers(T)) { | |||
| 6228 | if (const RecordType *RT = T->getAs<RecordType>()) | |||
| 6229 | return mangleSubstitution(RT->getDecl()); | |||
| 6230 | } | |||
| 6231 | ||||
| 6232 | uintptr_t TypePtr = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr()); | |||
| 6233 | ||||
| 6234 | return mangleSubstitution(TypePtr); | |||
| 6235 | } | |||
| 6236 | ||||
| 6237 | bool CXXNameMangler::mangleSubstitution(TemplateName Template) { | |||
| 6238 | if (TemplateDecl *TD = Template.getAsTemplateDecl()) | |||
| 6239 | return mangleSubstitution(TD); | |||
| 6240 | ||||
| 6241 | Template = Context.getASTContext().getCanonicalTemplateName(Template); | |||
| 6242 | return mangleSubstitution( | |||
| 6243 | reinterpret_cast<uintptr_t>(Template.getAsVoidPointer())); | |||
| 6244 | } | |||
| 6245 | ||||
| 6246 | bool CXXNameMangler::mangleSubstitution(uintptr_t Ptr) { | |||
| 6247 | llvm::DenseMap<uintptr_t, unsigned>::iterator I = Substitutions.find(Ptr); | |||
| 6248 | if (I == Substitutions.end()) | |||
| 6249 | return false; | |||
| 6250 | ||||
| 6251 | unsigned SeqID = I->second; | |||
| 6252 | Out << 'S'; | |||
| 6253 | mangleSeqID(SeqID); | |||
| 6254 | ||||
| 6255 | return true; | |||
| 6256 | } | |||
| 6257 | ||||
| 6258 | /// Returns whether S is a template specialization of std::Name with a single | |||
| 6259 | /// argument of type A. | |||
| 6260 | bool CXXNameMangler::isSpecializedAs(QualType S, llvm::StringRef Name, | |||
| 6261 | QualType A) { | |||
| 6262 | if (S.isNull()) | |||
| 6263 | return false; | |||
| 6264 | ||||
| 6265 | const RecordType *RT = S->getAs<RecordType>(); | |||
| 6266 | if (!RT) | |||
| 6267 | return false; | |||
| 6268 | ||||
| 6269 | const ClassTemplateSpecializationDecl *SD = | |||
| 6270 | dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl()); | |||
| 6271 | if (!SD || !SD->getIdentifier()->isStr(Name)) | |||
| 6272 | return false; | |||
| 6273 | ||||
| 6274 | if (!isStdNamespace(Context.getEffectiveDeclContext(SD))) | |||
| 6275 | return false; | |||
| 6276 | ||||
| 6277 | const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs(); | |||
| 6278 | if (TemplateArgs.size() != 1) | |||
| 6279 | return false; | |||
| 6280 | ||||
| 6281 | if (TemplateArgs[0].getAsType() != A) | |||
| 6282 | return false; | |||
| 6283 | ||||
| 6284 | if (SD->getSpecializedTemplate()->getOwningModuleForLinkage()) | |||
| 6285 | return false; | |||
| 6286 | ||||
| 6287 | return true; | |||
| 6288 | } | |||
| 6289 | ||||
| 6290 | /// Returns whether SD is a template specialization std::Name<char, | |||
| 6291 | /// std::char_traits<char> [, std::allocator<char>]> | |||
| 6292 | /// HasAllocator controls whether the 3rd template argument is needed. | |||
| 6293 | bool CXXNameMangler::isStdCharSpecialization( | |||
| 6294 | const ClassTemplateSpecializationDecl *SD, llvm::StringRef Name, | |||
| 6295 | bool HasAllocator) { | |||
| 6296 | if (!SD->getIdentifier()->isStr(Name)) | |||
| 6297 | return false; | |||
| 6298 | ||||
| 6299 | const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs(); | |||
| 6300 | if (TemplateArgs.size() != (HasAllocator ? 3 : 2)) | |||
| 6301 | return false; | |||
| 6302 | ||||
| 6303 | QualType A = TemplateArgs[0].getAsType(); | |||
| 6304 | if (A.isNull()) | |||
| 6305 | return false; | |||
| 6306 | // Plain 'char' is named Char_S or Char_U depending on the target ABI. | |||
| 6307 | if (!A->isSpecificBuiltinType(BuiltinType::Char_S) && | |||
| 6308 | !A->isSpecificBuiltinType(BuiltinType::Char_U)) | |||
| 6309 | return false; | |||
| 6310 | ||||
| 6311 | if (!isSpecializedAs(TemplateArgs[1].getAsType(), "char_traits", A)) | |||
| 6312 | return false; | |||
| 6313 | ||||
| 6314 | if (HasAllocator && | |||
| 6315 | !isSpecializedAs(TemplateArgs[2].getAsType(), "allocator", A)) | |||
| 6316 | return false; | |||
| 6317 | ||||
| 6318 | if (SD->getSpecializedTemplate()->getOwningModuleForLinkage()) | |||
| 6319 | return false; | |||
| 6320 | ||||
| 6321 | return true; | |||
| 6322 | } | |||
| 6323 | ||||
| 6324 | bool CXXNameMangler::mangleStandardSubstitution(const NamedDecl *ND) { | |||
| 6325 | // <substitution> ::= St # ::std:: | |||
| 6326 | if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) { | |||
| 6327 | if (isStd(NS)) { | |||
| 6328 | Out << "St"; | |||
| 6329 | return true; | |||
| 6330 | } | |||
| 6331 | return false; | |||
| 6332 | } | |||
| 6333 | ||||
| 6334 | if (const ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(ND)) { | |||
| 6335 | if (!isStdNamespace(Context.getEffectiveDeclContext(TD))) | |||
| 6336 | return false; | |||
| 6337 | ||||
| 6338 | if (TD->getOwningModuleForLinkage()) | |||
| 6339 | return false; | |||
| 6340 | ||||
| 6341 | // <substitution> ::= Sa # ::std::allocator | |||
| 6342 | if (TD->getIdentifier()->isStr("allocator")) { | |||
| 6343 | Out << "Sa"; | |||
| 6344 | return true; | |||
| 6345 | } | |||
| 6346 | ||||
| 6347 | // <<substitution> ::= Sb # ::std::basic_string | |||
| 6348 | if (TD->getIdentifier()->isStr("basic_string")) { | |||
| 6349 | Out << "Sb"; | |||
| 6350 | return true; | |||
| 6351 | } | |||
| 6352 | return false; | |||
| 6353 | } | |||
| 6354 | ||||
| 6355 | if (const ClassTemplateSpecializationDecl *SD = | |||
| 6356 | dyn_cast<ClassTemplateSpecializationDecl>(ND)) { | |||
| 6357 | if (!isStdNamespace(Context.getEffectiveDeclContext(SD))) | |||
| 6358 | return false; | |||
| 6359 | ||||
| 6360 | if (SD->getSpecializedTemplate()->getOwningModuleForLinkage()) | |||
| 6361 | return false; | |||
| 6362 | ||||
| 6363 | // <substitution> ::= Ss # ::std::basic_string<char, | |||
| 6364 | // ::std::char_traits<char>, | |||
| 6365 | // ::std::allocator<char> > | |||
| 6366 | if (isStdCharSpecialization(SD, "basic_string", /*HasAllocator=*/true)) { | |||
| 6367 | Out << "Ss"; | |||
| 6368 | return true; | |||
| 6369 | } | |||
| 6370 | ||||
| 6371 | // <substitution> ::= Si # ::std::basic_istream<char, | |||
| 6372 | // ::std::char_traits<char> > | |||
| 6373 | if (isStdCharSpecialization(SD, "basic_istream", /*HasAllocator=*/false)) { | |||
| 6374 | Out << "Si"; | |||
| 6375 | return true; | |||
| 6376 | } | |||
| 6377 | ||||
| 6378 | // <substitution> ::= So # ::std::basic_ostream<char, | |||
| 6379 | // ::std::char_traits<char> > | |||
| 6380 | if (isStdCharSpecialization(SD, "basic_ostream", /*HasAllocator=*/false)) { | |||
| 6381 | Out << "So"; | |||
| 6382 | return true; | |||
| 6383 | } | |||
| 6384 | ||||
| 6385 | // <substitution> ::= Sd # ::std::basic_iostream<char, | |||
| 6386 | // ::std::char_traits<char> > | |||
| 6387 | if (isStdCharSpecialization(SD, "basic_iostream", /*HasAllocator=*/false)) { | |||
| 6388 | Out << "Sd"; | |||
| 6389 | return true; | |||
| 6390 | } | |||
| 6391 | return false; | |||
| 6392 | } | |||
| 6393 | ||||
| 6394 | return false; | |||
| 6395 | } | |||
| 6396 | ||||
| 6397 | void CXXNameMangler::addSubstitution(QualType T) { | |||
| 6398 | if (!hasMangledSubstitutionQualifiers(T)) { | |||
| 6399 | if (const RecordType *RT = T->getAs<RecordType>()) { | |||
| 6400 | addSubstitution(RT->getDecl()); | |||
| 6401 | return; | |||
| 6402 | } | |||
| 6403 | } | |||
| 6404 | ||||
| 6405 | uintptr_t TypePtr = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr()); | |||
| 6406 | addSubstitution(TypePtr); | |||
| 6407 | } | |||
| 6408 | ||||
| 6409 | void CXXNameMangler::addSubstitution(TemplateName Template) { | |||
| 6410 | if (TemplateDecl *TD = Template.getAsTemplateDecl()) | |||
| 6411 | return addSubstitution(TD); | |||
| 6412 | ||||
| 6413 | Template = Context.getASTContext().getCanonicalTemplateName(Template); | |||
| 6414 | addSubstitution(reinterpret_cast<uintptr_t>(Template.getAsVoidPointer())); | |||
| 6415 | } | |||
| 6416 | ||||
| 6417 | void CXXNameMangler::addSubstitution(uintptr_t Ptr) { | |||
| 6418 | assert(!Substitutions.count(Ptr) && "Substitution already exists!")(static_cast <bool> (!Substitutions.count(Ptr) && "Substitution already exists!") ? void (0) : __assert_fail ( "!Substitutions.count(Ptr) && \"Substitution already exists!\"" , "clang/lib/AST/ItaniumMangle.cpp", 6418, __extension__ __PRETTY_FUNCTION__ )); | |||
| 6419 | Substitutions[Ptr] = SeqID++; | |||
| 6420 | } | |||
| 6421 | ||||
| 6422 | void CXXNameMangler::extendSubstitutions(CXXNameMangler* Other) { | |||
| 6423 | assert(Other->SeqID >= SeqID && "Must be superset of substitutions!")(static_cast <bool> (Other->SeqID >= SeqID && "Must be superset of substitutions!") ? void (0) : __assert_fail ("Other->SeqID >= SeqID && \"Must be superset of substitutions!\"" , "clang/lib/AST/ItaniumMangle.cpp", 6423, __extension__ __PRETTY_FUNCTION__ )); | |||
| 6424 | if (Other->SeqID > SeqID) { | |||
| 6425 | Substitutions.swap(Other->Substitutions); | |||
| 6426 | SeqID = Other->SeqID; | |||
| 6427 | } | |||
| 6428 | } | |||
| 6429 | ||||
| 6430 | CXXNameMangler::AbiTagList | |||
| 6431 | CXXNameMangler::makeFunctionReturnTypeTags(const FunctionDecl *FD) { | |||
| 6432 | // When derived abi tags are disabled there is no need to make any list. | |||
| 6433 | if (DisableDerivedAbiTags) | |||
| 6434 | return AbiTagList(); | |||
| 6435 | ||||
| 6436 | llvm::raw_null_ostream NullOutStream; | |||
| 6437 | CXXNameMangler TrackReturnTypeTags(*this, NullOutStream); | |||
| 6438 | TrackReturnTypeTags.disableDerivedAbiTags(); | |||
| 6439 | ||||
| 6440 | const FunctionProtoType *Proto = | |||
| 6441 | cast<FunctionProtoType>(FD->getType()->getAs<FunctionType>()); | |||
| 6442 | FunctionTypeDepthState saved = TrackReturnTypeTags.FunctionTypeDepth.push(); | |||
| 6443 | TrackReturnTypeTags.FunctionTypeDepth.enterResultType(); | |||
| 6444 | TrackReturnTypeTags.mangleType(Proto->getReturnType()); | |||
| 6445 | TrackReturnTypeTags.FunctionTypeDepth.leaveResultType(); | |||
| 6446 | TrackReturnTypeTags.FunctionTypeDepth.pop(saved); | |||
| 6447 | ||||
| 6448 | return TrackReturnTypeTags.AbiTagsRoot.getSortedUniqueUsedAbiTags(); | |||
| 6449 | } | |||
| 6450 | ||||
| 6451 | CXXNameMangler::AbiTagList | |||
| 6452 | CXXNameMangler::makeVariableTypeTags(const VarDecl *VD) { | |||
| 6453 | // When derived abi tags are disabled there is no need to make any list. | |||
| 6454 | if (DisableDerivedAbiTags) | |||
| 6455 | return AbiTagList(); | |||
| 6456 | ||||
| 6457 | llvm::raw_null_ostream NullOutStream; | |||
| 6458 | CXXNameMangler TrackVariableType(*this, NullOutStream); | |||
| 6459 | TrackVariableType.disableDerivedAbiTags(); | |||
| 6460 | ||||
| 6461 | TrackVariableType.mangleType(VD->getType()); | |||
| 6462 | ||||
| 6463 | return TrackVariableType.AbiTagsRoot.getSortedUniqueUsedAbiTags(); | |||
| 6464 | } | |||
| 6465 | ||||
| 6466 | bool CXXNameMangler::shouldHaveAbiTags(ItaniumMangleContextImpl &C, | |||
| 6467 | const VarDecl *VD) { | |||
| 6468 | llvm::raw_null_ostream NullOutStream; | |||
| 6469 | CXXNameMangler TrackAbiTags(C, NullOutStream, nullptr, true); | |||
| 6470 | TrackAbiTags.mangle(VD); | |||
| 6471 | return TrackAbiTags.AbiTagsRoot.getUsedAbiTags().size(); | |||
| 6472 | } | |||
| 6473 | ||||
| 6474 | // | |||
| 6475 | ||||
| 6476 | /// Mangles the name of the declaration D and emits that name to the given | |||
| 6477 | /// output stream. | |||
| 6478 | /// | |||
| 6479 | /// If the declaration D requires a mangled name, this routine will emit that | |||
| 6480 | /// mangled name to \p os and return true. Otherwise, \p os will be unchanged | |||
| 6481 | /// and this routine will return false. In this case, the caller should just | |||
| 6482 | /// emit the identifier of the declaration (\c D->getIdentifier()) as its | |||
| 6483 | /// name. | |||
| 6484 | void ItaniumMangleContextImpl::mangleCXXName(GlobalDecl GD, | |||
| 6485 | raw_ostream &Out) { | |||
| 6486 | const NamedDecl *D = cast<NamedDecl>(GD.getDecl()); | |||
| 6487 | assert((isa<FunctionDecl, VarDecl, TemplateParamObjectDecl>(D)) &&(static_cast <bool> ((isa<FunctionDecl, VarDecl, TemplateParamObjectDecl >(D)) && "Invalid mangleName() call, argument is not a variable or function!" ) ? void (0) : __assert_fail ("(isa<FunctionDecl, VarDecl, TemplateParamObjectDecl>(D)) && \"Invalid mangleName() call, argument is not a variable or function!\"" , "clang/lib/AST/ItaniumMangle.cpp", 6488, __extension__ __PRETTY_FUNCTION__ )) | |||
| 6488 | "Invalid mangleName() call, argument is not a variable or function!")(static_cast <bool> ((isa<FunctionDecl, VarDecl, TemplateParamObjectDecl >(D)) && "Invalid mangleName() call, argument is not a variable or function!" ) ? void (0) : __assert_fail ("(isa<FunctionDecl, VarDecl, TemplateParamObjectDecl>(D)) && \"Invalid mangleName() call, argument is not a variable or function!\"" , "clang/lib/AST/ItaniumMangle.cpp", 6488, __extension__ __PRETTY_FUNCTION__ )); | |||
| 6489 | ||||
| 6490 | PrettyStackTraceDecl CrashInfo(D, SourceLocation(), | |||
| 6491 | getASTContext().getSourceManager(), | |||
| 6492 | "Mangling declaration"); | |||
| 6493 | ||||
| 6494 | if (auto *CD = dyn_cast<CXXConstructorDecl>(D)) { | |||
| 6495 | auto Type = GD.getCtorType(); | |||
| 6496 | CXXNameMangler Mangler(*this, Out, CD, Type); | |||
| 6497 | return Mangler.mangle(GlobalDecl(CD, Type)); | |||
| 6498 | } | |||
| 6499 | ||||
| 6500 | if (auto *DD = dyn_cast<CXXDestructorDecl>(D)) { | |||
| 6501 | auto Type = GD.getDtorType(); | |||
| 6502 | CXXNameMangler Mangler(*this, Out, DD, Type); | |||
| 6503 | return Mangler.mangle(GlobalDecl(DD, Type)); | |||
| 6504 | } | |||
| 6505 | ||||
| 6506 | CXXNameMangler Mangler(*this, Out, D); | |||
| 6507 | Mangler.mangle(GD); | |||
| 6508 | } | |||
| 6509 | ||||
| 6510 | void ItaniumMangleContextImpl::mangleCXXCtorComdat(const CXXConstructorDecl *D, | |||
| 6511 | raw_ostream &Out) { | |||
| 6512 | CXXNameMangler Mangler(*this, Out, D, Ctor_Comdat); | |||
| 6513 | Mangler.mangle(GlobalDecl(D, Ctor_Comdat)); | |||
| 6514 | } | |||
| 6515 | ||||
| 6516 | void ItaniumMangleContextImpl::mangleCXXDtorComdat(const CXXDestructorDecl *D, | |||
| 6517 | raw_ostream &Out) { | |||
| 6518 | CXXNameMangler Mangler(*this, Out, D, Dtor_Comdat); | |||
| 6519 | Mangler.mangle(GlobalDecl(D, Dtor_Comdat)); | |||
| 6520 | } | |||
| 6521 | ||||
| 6522 | void ItaniumMangleContextImpl::mangleThunk(const CXXMethodDecl *MD, | |||
| 6523 | const ThunkInfo &Thunk, | |||
| 6524 | raw_ostream &Out) { | |||
| 6525 | // <special-name> ::= T <call-offset> <base encoding> | |||
| 6526 | // # base is the nominal target function of thunk | |||
| 6527 | // <special-name> ::= Tc <call-offset> <call-offset> <base encoding> | |||
| 6528 | // # base is the nominal target function of thunk | |||
| 6529 | // # first call-offset is 'this' adjustment | |||
| 6530 | // # second call-offset is result adjustment | |||
| 6531 | ||||
| 6532 | assert(!isa<CXXDestructorDecl>(MD) &&(static_cast <bool> (!isa<CXXDestructorDecl>(MD) && "Use mangleCXXDtor for destructor decls!") ? void (0) : __assert_fail ("!isa<CXXDestructorDecl>(MD) && \"Use mangleCXXDtor for destructor decls!\"" , "clang/lib/AST/ItaniumMangle.cpp", 6533, __extension__ __PRETTY_FUNCTION__ )) | |||
| 6533 | "Use mangleCXXDtor for destructor decls!")(static_cast <bool> (!isa<CXXDestructorDecl>(MD) && "Use mangleCXXDtor for destructor decls!") ? void (0) : __assert_fail ("!isa<CXXDestructorDecl>(MD) && \"Use mangleCXXDtor for destructor decls!\"" , "clang/lib/AST/ItaniumMangle.cpp", 6533, __extension__ __PRETTY_FUNCTION__ )); | |||
| 6534 | CXXNameMangler Mangler(*this, Out); | |||
| 6535 | Mangler.getStream() << "_ZT"; | |||
| 6536 | if (!Thunk.Return.isEmpty()) | |||
| 6537 | Mangler.getStream() << 'c'; | |||
| 6538 | ||||
| 6539 | // Mangle the 'this' pointer adjustment. | |||
| 6540 | Mangler.mangleCallOffset(Thunk.This.NonVirtual, | |||
| 6541 | Thunk.This.Virtual.Itanium.VCallOffsetOffset); | |||
| 6542 | ||||
| 6543 | // Mangle the return pointer adjustment if there is one. | |||
| 6544 | if (!Thunk.Return.isEmpty()) | |||
| 6545 | Mangler.mangleCallOffset(Thunk.Return.NonVirtual, | |||
| 6546 | Thunk.Return.Virtual.Itanium.VBaseOffsetOffset); | |||
| 6547 | ||||
| 6548 | Mangler.mangleFunctionEncoding(MD); | |||
| 6549 | } | |||
| 6550 | ||||
| 6551 | void ItaniumMangleContextImpl::mangleCXXDtorThunk( | |||
| 6552 | const CXXDestructorDecl *DD, CXXDtorType Type, | |||
| 6553 | const ThisAdjustment &ThisAdjustment, raw_ostream &Out) { | |||
| 6554 | // <special-name> ::= T <call-offset> <base encoding> | |||
| 6555 | // # base is the nominal target function of thunk | |||
| 6556 | CXXNameMangler Mangler(*this, Out, DD, Type); | |||
| 6557 | Mangler.getStream() << "_ZT"; | |||
| 6558 | ||||
| 6559 | // Mangle the 'this' pointer adjustment. | |||
| 6560 | Mangler.mangleCallOffset(ThisAdjustment.NonVirtual, | |||
| 6561 | ThisAdjustment.Virtual.Itanium.VCallOffsetOffset); | |||
| 6562 | ||||
| 6563 | Mangler.mangleFunctionEncoding(GlobalDecl(DD, Type)); | |||
| 6564 | } | |||
| 6565 | ||||
| 6566 | /// Returns the mangled name for a guard variable for the passed in VarDecl. | |||
| 6567 | void ItaniumMangleContextImpl::mangleStaticGuardVariable(const VarDecl *D, | |||
| 6568 | raw_ostream &Out) { | |||
| 6569 | // <special-name> ::= GV <object name> # Guard variable for one-time | |||
| 6570 | // # initialization | |||
| 6571 | CXXNameMangler Mangler(*this, Out); | |||
| 6572 | // GCC 5.3.0 doesn't emit derived ABI tags for local names but that seems to | |||
| 6573 | // be a bug that is fixed in trunk. | |||
| 6574 | Mangler.getStream() << "_ZGV"; | |||
| 6575 | Mangler.mangleName(D); | |||
| 6576 | } | |||
| 6577 | ||||
| 6578 | void ItaniumMangleContextImpl::mangleDynamicInitializer(const VarDecl *MD, | |||
| 6579 | raw_ostream &Out) { | |||
| 6580 | // These symbols are internal in the Itanium ABI, so the names don't matter. | |||
| 6581 | // Clang has traditionally used this symbol and allowed LLVM to adjust it to | |||
| 6582 | // avoid duplicate symbols. | |||
| 6583 | Out << "__cxx_global_var_init"; | |||
| 6584 | } | |||
| 6585 | ||||
| 6586 | void ItaniumMangleContextImpl::mangleDynamicAtExitDestructor(const VarDecl *D, | |||
| 6587 | raw_ostream &Out) { | |||
| 6588 | // Prefix the mangling of D with __dtor_. | |||
| 6589 | CXXNameMangler Mangler(*this, Out); | |||
| 6590 | Mangler.getStream() << "__dtor_"; | |||
| 6591 | if (shouldMangleDeclName(D)) | |||
| 6592 | Mangler.mangle(D); | |||
| 6593 | else | |||
| 6594 | Mangler.getStream() << D->getName(); | |||
| 6595 | } | |||
| 6596 | ||||
| 6597 | void ItaniumMangleContextImpl::mangleDynamicStermFinalizer(const VarDecl *D, | |||
| 6598 | raw_ostream &Out) { | |||
| 6599 | // Clang generates these internal-linkage functions as part of its | |||
| 6600 | // implementation of the XL ABI. | |||
| 6601 | CXXNameMangler Mangler(*this, Out); | |||
| 6602 | Mangler.getStream() << "__finalize_"; | |||
| 6603 | if (shouldMangleDeclName(D)) | |||
| 6604 | Mangler.mangle(D); | |||
| 6605 | else | |||
| 6606 | Mangler.getStream() << D->getName(); | |||
| 6607 | } | |||
| 6608 | ||||
| 6609 | void ItaniumMangleContextImpl::mangleSEHFilterExpression( | |||
| 6610 | GlobalDecl EnclosingDecl, raw_ostream &Out) { | |||
| 6611 | CXXNameMangler Mangler(*this, Out); | |||
| 6612 | Mangler.getStream() << "__filt_"; | |||
| 6613 | auto *EnclosingFD = cast<FunctionDecl>(EnclosingDecl.getDecl()); | |||
| 6614 | if (shouldMangleDeclName(EnclosingFD)) | |||
| 6615 | Mangler.mangle(EnclosingDecl); | |||
| 6616 | else | |||
| 6617 | Mangler.getStream() << EnclosingFD->getName(); | |||
| 6618 | } | |||
| 6619 | ||||
| 6620 | void ItaniumMangleContextImpl::mangleSEHFinallyBlock( | |||
| 6621 | GlobalDecl EnclosingDecl, raw_ostream &Out) { | |||
| 6622 | CXXNameMangler Mangler(*this, Out); | |||
| 6623 | Mangler.getStream() << "__fin_"; | |||
| 6624 | auto *EnclosingFD = cast<FunctionDecl>(EnclosingDecl.getDecl()); | |||
| 6625 | if (shouldMangleDeclName(EnclosingFD)) | |||
| 6626 | Mangler.mangle(EnclosingDecl); | |||
| 6627 | else | |||
| 6628 | Mangler.getStream() << EnclosingFD->getName(); | |||
| 6629 | } | |||
| 6630 | ||||
| 6631 | void ItaniumMangleContextImpl::mangleItaniumThreadLocalInit(const VarDecl *D, | |||
| 6632 | raw_ostream &Out) { | |||
| 6633 | // <special-name> ::= TH <object name> | |||
| 6634 | CXXNameMangler Mangler(*this, Out); | |||
| 6635 | Mangler.getStream() << "_ZTH"; | |||
| 6636 | Mangler.mangleName(D); | |||
| 6637 | } | |||
| 6638 | ||||
| 6639 | void | |||
| 6640 | ItaniumMangleContextImpl::mangleItaniumThreadLocalWrapper(const VarDecl *D, | |||
| 6641 | raw_ostream &Out) { | |||
| 6642 | // <special-name> ::= TW <object name> | |||
| 6643 | CXXNameMangler Mangler(*this, Out); | |||
| 6644 | Mangler.getStream() << "_ZTW"; | |||
| 6645 | Mangler.mangleName(D); | |||
| 6646 | } | |||
| 6647 | ||||
| 6648 | void ItaniumMangleContextImpl::mangleReferenceTemporary(const VarDecl *D, | |||
| 6649 | unsigned ManglingNumber, | |||
| 6650 | raw_ostream &Out) { | |||
| 6651 | // We match the GCC mangling here. | |||
| 6652 | // <special-name> ::= GR <object name> | |||
| 6653 | CXXNameMangler Mangler(*this, Out); | |||
| 6654 | Mangler.getStream() << "_ZGR"; | |||
| 6655 | Mangler.mangleName(D); | |||
| 6656 | assert(ManglingNumber > 0 && "Reference temporary mangling number is zero!")(static_cast <bool> (ManglingNumber > 0 && "Reference temporary mangling number is zero!" ) ? void (0) : __assert_fail ("ManglingNumber > 0 && \"Reference temporary mangling number is zero!\"" , "clang/lib/AST/ItaniumMangle.cpp", 6656, __extension__ __PRETTY_FUNCTION__ )); | |||
| 6657 | Mangler.mangleSeqID(ManglingNumber - 1); | |||
| 6658 | } | |||
| 6659 | ||||
| 6660 | void ItaniumMangleContextImpl::mangleCXXVTable(const CXXRecordDecl *RD, | |||
| 6661 | raw_ostream &Out) { | |||
| 6662 | // <special-name> ::= TV <type> # virtual table | |||
| 6663 | CXXNameMangler Mangler(*this, Out); | |||
| 6664 | Mangler.getStream() << "_ZTV"; | |||
| 6665 | Mangler.mangleNameOrStandardSubstitution(RD); | |||
| 6666 | } | |||
| 6667 | ||||
| 6668 | void ItaniumMangleContextImpl::mangleCXXVTT(const CXXRecordDecl *RD, | |||
| 6669 | raw_ostream &Out) { | |||
| 6670 | // <special-name> ::= TT <type> # VTT structure | |||
| 6671 | CXXNameMangler Mangler(*this, Out); | |||
| 6672 | Mangler.getStream() << "_ZTT"; | |||
| 6673 | Mangler.mangleNameOrStandardSubstitution(RD); | |||
| 6674 | } | |||
| 6675 | ||||
| 6676 | void ItaniumMangleContextImpl::mangleCXXCtorVTable(const CXXRecordDecl *RD, | |||
| 6677 | int64_t Offset, | |||
| 6678 | const CXXRecordDecl *Type, | |||
| 6679 | raw_ostream &Out) { | |||
| 6680 | // <special-name> ::= TC <type> <offset number> _ <base type> | |||
| 6681 | CXXNameMangler Mangler(*this, Out); | |||
| 6682 | Mangler.getStream() << "_ZTC"; | |||
| 6683 | Mangler.mangleNameOrStandardSubstitution(RD); | |||
| 6684 | Mangler.getStream() << Offset; | |||
| 6685 | Mangler.getStream() << '_'; | |||
| 6686 | Mangler.mangleNameOrStandardSubstitution(Type); | |||
| 6687 | } | |||
| 6688 | ||||
| 6689 | void ItaniumMangleContextImpl::mangleCXXRTTI(QualType Ty, raw_ostream &Out) { | |||
| 6690 | // <special-name> ::= TI <type> # typeinfo structure | |||
| 6691 | assert(!Ty.hasQualifiers() && "RTTI info cannot have top-level qualifiers")(static_cast <bool> (!Ty.hasQualifiers() && "RTTI info cannot have top-level qualifiers" ) ? void (0) : __assert_fail ("!Ty.hasQualifiers() && \"RTTI info cannot have top-level qualifiers\"" , "clang/lib/AST/ItaniumMangle.cpp", 6691, __extension__ __PRETTY_FUNCTION__ )); | |||
| 6692 | CXXNameMangler Mangler(*this, Out); | |||
| 6693 | Mangler.getStream() << "_ZTI"; | |||
| 6694 | Mangler.mangleType(Ty); | |||
| 6695 | } | |||
| 6696 | ||||
| 6697 | void ItaniumMangleContextImpl::mangleCXXRTTIName( | |||
| 6698 | QualType Ty, raw_ostream &Out, bool NormalizeIntegers = false) { | |||
| 6699 | // <special-name> ::= TS <type> # typeinfo name (null terminated byte string) | |||
| 6700 | CXXNameMangler Mangler(*this, Out, NormalizeIntegers); | |||
| 6701 | Mangler.getStream() << "_ZTS"; | |||
| 6702 | Mangler.mangleType(Ty); | |||
| 6703 | } | |||
| 6704 | ||||
| 6705 | void ItaniumMangleContextImpl::mangleTypeName(QualType Ty, raw_ostream &Out, | |||
| 6706 | bool NormalizeIntegers = false) { | |||
| 6707 | mangleCXXRTTIName(Ty, Out, NormalizeIntegers); | |||
| 6708 | } | |||
| 6709 | ||||
| 6710 | void ItaniumMangleContextImpl::mangleStringLiteral(const StringLiteral *, raw_ostream &) { | |||
| 6711 | llvm_unreachable("Can't mangle string literals")::llvm::llvm_unreachable_internal("Can't mangle string literals" , "clang/lib/AST/ItaniumMangle.cpp", 6711); | |||
| 6712 | } | |||
| 6713 | ||||
| 6714 | void ItaniumMangleContextImpl::mangleLambdaSig(const CXXRecordDecl *Lambda, | |||
| 6715 | raw_ostream &Out) { | |||
| 6716 | CXXNameMangler Mangler(*this, Out); | |||
| 6717 | Mangler.mangleLambdaSig(Lambda); | |||
| 6718 | } | |||
| 6719 | ||||
| 6720 | void ItaniumMangleContextImpl::mangleModuleInitializer(const Module *M, | |||
| 6721 | raw_ostream &Out) { | |||
| 6722 | // <special-name> ::= GI <module-name> # module initializer function | |||
| 6723 | CXXNameMangler Mangler(*this, Out); | |||
| 6724 | Mangler.getStream() << "_ZGI"; | |||
| 6725 | Mangler.mangleModuleNamePrefix(M->getPrimaryModuleInterfaceName()); | |||
| 6726 | if (M->isModulePartition()) { | |||
| 6727 | // The partition needs including, as partitions can have them too. | |||
| 6728 | auto Partition = M->Name.find(':'); | |||
| 6729 | Mangler.mangleModuleNamePrefix( | |||
| 6730 | StringRef(&M->Name[Partition + 1], M->Name.size() - Partition - 1), | |||
| 6731 | /*IsPartition*/ true); | |||
| 6732 | } | |||
| 6733 | } | |||
| 6734 | ||||
| 6735 | ItaniumMangleContext *ItaniumMangleContext::create(ASTContext &Context, | |||
| 6736 | DiagnosticsEngine &Diags, | |||
| 6737 | bool IsAux) { | |||
| 6738 | return new ItaniumMangleContextImpl( | |||
| 6739 | Context, Diags, | |||
| 6740 | [](ASTContext &, const NamedDecl *) -> std::optional<unsigned> { | |||
| 6741 | return std::nullopt; | |||
| 6742 | }, | |||
| 6743 | IsAux); | |||
| 6744 | } | |||
| 6745 | ||||
| 6746 | ItaniumMangleContext * | |||
| 6747 | ItaniumMangleContext::create(ASTContext &Context, DiagnosticsEngine &Diags, | |||
| 6748 | DiscriminatorOverrideTy DiscriminatorOverride, | |||
| 6749 | bool IsAux) { | |||
| 6750 | return new ItaniumMangleContextImpl(Context, Diags, DiscriminatorOverride, | |||
| 6751 | IsAux); | |||
| 6752 | } |