зеркало из https://github.com/microsoft/clang-1.git
Mangle static variables with an extra name to distinguish them from non-static variables in the same TU.
Fixes PR5966 for real this time; also reverts r92911, which had a incorrect fix. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94352 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
1efcf3d137
Коммит
31455256ae
|
@ -171,14 +171,15 @@ bool MangleContext::shouldMangleDeclName(const NamedDecl *D) {
|
|||
isInExternCSystemHeader(D->getLocation()))
|
||||
return false;
|
||||
|
||||
// Variables at global scope are not mangled.
|
||||
// Variables at global scope with non-internal linkage are not mangled
|
||||
if (!FD) {
|
||||
const DeclContext *DC = D->getDeclContext();
|
||||
// Check for extern variable declared locally.
|
||||
if (isa<FunctionDecl>(DC) && D->hasLinkage())
|
||||
while (!DC->isNamespace() && !DC->isTranslationUnit())
|
||||
DC = DC->getParent();
|
||||
if (DC->isTranslationUnit())
|
||||
if (DC->isTranslationUnit() &&
|
||||
D->getLinkage() != NamedDecl::InternalLinkage)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -199,13 +200,10 @@ void CXXNameMangler::mangle(const NamedDecl *D, llvm::StringRef Prefix) {
|
|||
return;
|
||||
}
|
||||
|
||||
// <mangled-name> ::= _Z [L] <encoding>
|
||||
// <mangled-name> ::= _Z <encoding>
|
||||
// ::= <data name>
|
||||
// ::= <special-name>
|
||||
Out << Prefix;
|
||||
if (D->getLinkage() == NamedDecl::InternalLinkage) // match gcc behavior
|
||||
Out << 'L';
|
||||
|
||||
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
|
||||
mangleFunctionEncoding(FD);
|
||||
else
|
||||
|
@ -419,6 +417,13 @@ void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND) {
|
|||
}
|
||||
|
||||
if (const IdentifierInfo *II = Name.getAsIdentifierInfo()) {
|
||||
// We must avoid conflicts between internally- and externally-
|
||||
// linked names in the same TU. This naming convention is the
|
||||
// same as that followed by GCC, though it shouldn't actually matter.
|
||||
if (ND->getLinkage() == NamedDecl::InternalLinkage &&
|
||||
ND->getDeclContext()->isFileContext())
|
||||
Out << 'L';
|
||||
|
||||
mangleSourceName(II);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
const int x = 10;
|
||||
const int y = 20;
|
||||
// CHECK-NOT: @x
|
||||
// CHECK: @y = internal constant i32 20
|
||||
// CHECK: @_ZL1y = internal constant i32 20
|
||||
const int& b() { return y; }
|
||||
|
||||
const char z1[] = "asdf";
|
||||
const char z2[] = "zxcv";
|
||||
// CHECK-NOT: @z1
|
||||
// CHECK: @z2 = internal constant
|
||||
// CHECK: @_ZL2z2 = internal constant
|
||||
const char* b2() { return z2; }
|
||||
|
|
|
@ -5,7 +5,7 @@ extern void* foo;
|
|||
static void* const a = foo;
|
||||
void* bar() { return a; }
|
||||
|
||||
// CHECK: @a = internal global i8* null
|
||||
// CHECK: @_ZL1a = internal global i8* null
|
||||
|
||||
// CHECK: define internal void @__cxx_global_var_init
|
||||
// CHECK: load i8** @foo
|
||||
|
|
|
@ -7,4 +7,4 @@ struct A {
|
|||
|
||||
const A x;
|
||||
|
||||
// CHECK: @x = internal global
|
||||
// CHECK: @_ZL1x = internal global
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -fblocks | FileCheck %s
|
||||
|
||||
struct X { };
|
||||
struct Y { };
|
||||
|
||||
|
@ -9,6 +8,9 @@ struct Y { };
|
|||
// CHECK: @_ZZN1N1gEvE1a = internal global
|
||||
// CHECK: @_ZGVZN1N1gEvE1a = internal global
|
||||
|
||||
//CHECK: @pr5966_i = external global
|
||||
//CHECK: @_ZL8pr5966_i = internal global
|
||||
|
||||
// CHECK: define zeroext i1 @_ZplRK1YRA100_P1X
|
||||
bool operator+(const Y&, X* (&xs)[100]) { return false; }
|
||||
|
||||
|
@ -310,7 +312,13 @@ template class Alloc<char>;
|
|||
// CHECK: define void @_Z1fU13block_pointerFiiiE
|
||||
void f(int (^)(int, int)) { }
|
||||
|
||||
// PR5869
|
||||
// CHECK: define internal void @_ZL2f2v
|
||||
static void f2() {}
|
||||
void f3() { f2(); }
|
||||
void pr5966_foo() {
|
||||
extern int pr5966_i;
|
||||
pr5966_i = 0;
|
||||
}
|
||||
|
||||
static int pr5966_i;
|
||||
|
||||
void pr5966_bar() {
|
||||
pr5966_i = 0;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче