diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2012-06-26 16:06:38 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2012-06-26 16:06:38 +0000 |
commit | 4904bf4e84cfb48080270ebaa9005327f18ab0e5 (patch) | |
tree | 2887e79ad5a24c8ba5fa803cc98ac9ebb12a5c87 /lib/AST/Mangle.cpp | |
parent | b9d2b3b8edf7a0dc56e55acb1cf87338d5648daa (diff) |
block literal irgen: several improvements on naming block
literal helper functions. All helper functions (global
and locals) use block_invoke as their prefix. Local literal
helper names are prefixed by their enclosing mangled function
names. Blocks in non-local initializers (e.g. a global variable
or a C++11 field) are prefixed by their mangled variable name.
The descriminator number added to end of the name starts off
with blank (for first block) and _<N> (for the N+2-th block).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159206 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Mangle.cpp')
-rw-r--r-- | lib/AST/Mangle.cpp | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/lib/AST/Mangle.cpp b/lib/AST/Mangle.cpp index 73c9f5778f..d5f83719ec 100644 --- a/lib/AST/Mangle.cpp +++ b/lib/AST/Mangle.cpp @@ -40,7 +40,11 @@ static void mangleFunctionBlock(MangleContext &Context, StringRef Outer, const BlockDecl *BD, raw_ostream &Out) { - Out << "__" << Outer << "_block_invoke_" << Context.getBlockId(BD, true); + unsigned discriminator = Context.getBlockId(BD, true); + if (discriminator == 0) + Out << "__" << Outer << "_block_invoke"; + else + Out << "__" << Outer << "_block_invoke_" << discriminator+1; } static void checkMangleDC(const DeclContext *DC, const BlockDecl *BD) { @@ -62,8 +66,20 @@ static void checkMangleDC(const DeclContext *DC, const BlockDecl *BD) { void MangleContext::anchor() { } void MangleContext::mangleGlobalBlock(const BlockDecl *BD, + const NamedDecl *ID, raw_ostream &Out) { - Out << "__block_global_" << getBlockId(BD, false); + unsigned discriminator = getBlockId(BD, false); + if (ID) { + if (shouldMangleDeclName(ID)) + mangleName(ID, Out); + else { + Out << ID->getIdentifier()->getName(); + } + } + if (discriminator == 0) + Out << "_block_invoke"; + else + Out << "_block_invoke_" << discriminator+1; } void MangleContext::mangleCtorBlock(const CXXConstructorDecl *CD, @@ -99,8 +115,8 @@ void MangleContext::mangleBlock(const DeclContext *DC, const BlockDecl *BD, mangleObjCMethodName(Method, Stream); } else { const NamedDecl *ND = cast<NamedDecl>(DC); - if (IdentifierInfo *II = ND->getIdentifier()) - Stream << II->getName(); + if (!shouldMangleDeclName(ND) && ND->getIdentifier()) + Stream << ND->getIdentifier()->getName(); else { // FIXME: We were doing a mangleUnqualifiedName() before, but that's // a private member of a class that will soon itself be private to the @@ -131,12 +147,13 @@ void MangleContext::mangleObjCMethodName(const ObjCMethodDecl *MD, } void MangleContext::mangleBlock(const BlockDecl *BD, - raw_ostream &Out) { + raw_ostream &Out, + const NamedDecl *ID) { const DeclContext *DC = BD->getDeclContext(); while (isa<BlockDecl>(DC) || isa<EnumDecl>(DC)) DC = DC->getParent(); if (DC->isFunctionOrMethod()) mangleBlock(DC, BD, Out); else - mangleGlobalBlock(BD, Out); + mangleGlobalBlock(BD, ID, Out); } |