Don't skip lambdas when mangling local vars.

This commit rearranges the logic in CXXNameMangler::mangleLocalName and
GetLocalClassDecl so that it doesn't accidentally skip over lambdas.  It
also reduces code duplication a bit.

llvm-svn: 185402
This commit is contained in:
Eli Friedman 2013-07-02 02:01:18 +00:00
parent 686df32216
commit 92821745bf
3 changed files with 22 additions and 22 deletions

View File

@ -64,15 +64,13 @@ static const DeclContext *getEffectiveParentContext(const DeclContext *DC) {
return getEffectiveDeclContext(cast<Decl>(DC));
}
static const CXXRecordDecl *GetLocalClassDecl(const NamedDecl *ND) {
const DeclContext *DC = dyn_cast<DeclContext>(ND);
if (!DC)
DC = getEffectiveDeclContext(ND);
static const CXXRecordDecl *GetLocalClassDecl(const Decl *D) {
const DeclContext *DC = getEffectiveDeclContext(D);
while (!DC->isNamespace() && !DC->isTranslationUnit()) {
const DeclContext *Parent = getEffectiveDeclContext(cast<Decl>(DC));
if (isa<FunctionDecl>(Parent))
return dyn_cast<CXXRecordDecl>(DC);
DC = Parent;
if (isa<FunctionDecl>(DC) || isa<ObjCMethodDecl>(DC) || isa<BlockDecl>(DC))
return dyn_cast<CXXRecordDecl>(D);
D = cast<Decl>(DC);
DC = getEffectiveDeclContext(D);
}
return 0;
}
@ -1272,16 +1270,21 @@ void CXXNameMangler::mangleLocalName(const NamedDecl *ND) {
// <local-name> := Z <function encoding> E d [ <parameter number> ]
// _ <entity name>
// <discriminator> := _ <non-negative number>
const DeclContext *DC = getEffectiveDeclContext(ND);
const CXXRecordDecl *RD = GetLocalClassDecl(ND);
const DeclContext *DC = getEffectiveDeclContext(RD ? RD : ND);
Out << 'Z';
if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC)) {
mangleObjCMethodName(MD);
} else if (const CXXRecordDecl *RD = GetLocalClassDecl(ND)) {
mangleFunctionEncoding(cast<FunctionDecl>(getEffectiveDeclContext(RD)));
Out << 'E';
if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC))
mangleObjCMethodName(MD);
else if (const BlockDecl *BD = dyn_cast<BlockDecl>(DC))
manglePrefix(BD); // FIXME: This isn't right.
else
mangleFunctionEncoding(cast<FunctionDecl>(DC));
Out << 'E';
if (RD) {
// The parameter number is omitted for the last parameter, 0 for the
// second-to-last parameter, 1 for the third-to-last parameter, etc. The
// <entity name> will of course contain a <closure-type-name>: Its
@ -1307,7 +1310,7 @@ void CXXNameMangler::mangleLocalName(const NamedDecl *ND) {
if (ND == RD) // equality ok because RD derived from ND above
mangleUnqualifiedName(ND);
else
mangleNestedName(ND, DC, true /*NoFunction*/);
mangleNestedName(ND, getEffectiveDeclContext(ND), true /*NoFunction*/);
if (!SkipDiscriminator) {
unsigned disc;
@ -1321,10 +1324,7 @@ void CXXNameMangler::mangleLocalName(const NamedDecl *ND) {
return;
}
else
mangleFunctionEncoding(cast<FunctionDecl>(DC));
Out << 'E';
mangleUnqualifiedName(ND);
}

View File

@ -14,7 +14,7 @@ namespace PR12746 {
}
// CHECK: define internal zeroext i1 @___ZN7PR127462f1EPi_block_invoke
// CHECK: call zeroext i1 @"_ZNK7PR127462f1Ub_3$_0clEv"
// CHECK: call zeroext i1 @"_ZZ7PR127462f1Ub_ENK3$_0clEv"
bool f2(int *x) {
auto outer = [&]() -> bool {

View File

@ -1,9 +1,9 @@
// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-macosx10.7.0 -emit-llvm -o - %s | FileCheck %s
// CHECK: @_ZZNK7PR12917IJiiEE1nMUlvE_clEvE1n = linkonce_odr global i32 0
// CHECK: @_ZZN7PR12917IJicdEEC1EicdEd_N1nE = linkonce_odr global i32 0
// CHECK: @_ZZN7PR12917IJicdEEC1EicdEd0_N1nE = linkonce_odr global i32 0
// CHECK: @_ZZN7PR12917IJicdEEC1EicdEd1_N1nE = linkonce_odr global i32 0
// CHECK: @_ZZZN7PR12917IJicdEEC1EicdEd_NKUlvE_clEvE1n = linkonce_odr global i32 0
// CHECK: @_ZZZN7PR12917IJicdEEC1EicdEd0_NKUlvE_clEvE1n = linkonce_odr global i32 0
// CHECK: @_ZZZN7PR12917IJicdEEC1EicdEd1_NKUlvE_clEvE1n = linkonce_odr global i32 0
// CHECK: define linkonce_odr void @_Z11inline_funci
inline void inline_func(int n) {