diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/CodeGen/Mangle.cpp | 17 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/const-global-linkage.cpp | 4 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/deferred-global-init.cpp | 2 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/global-llvm-constant.cpp | 2 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/mangle.cpp | 18 |
5 files changed, 28 insertions, 15 deletions
diff --git a/clang/lib/CodeGen/Mangle.cpp b/clang/lib/CodeGen/Mangle.cpp index d873cfec1bd..b6bebd0247b 100644 --- a/clang/lib/CodeGen/Mangle.cpp +++ b/clang/lib/CodeGen/Mangle.cpp @@ -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; } diff --git a/clang/test/CodeGenCXX/const-global-linkage.cpp b/clang/test/CodeGenCXX/const-global-linkage.cpp index f88bc808a7c..d0a055b4949 100644 --- a/clang/test/CodeGenCXX/const-global-linkage.cpp +++ b/clang/test/CodeGenCXX/const-global-linkage.cpp @@ -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; } diff --git a/clang/test/CodeGenCXX/deferred-global-init.cpp b/clang/test/CodeGenCXX/deferred-global-init.cpp index 57014790554..802042dd8b9 100644 --- a/clang/test/CodeGenCXX/deferred-global-init.cpp +++ b/clang/test/CodeGenCXX/deferred-global-init.cpp @@ -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 diff --git a/clang/test/CodeGenCXX/global-llvm-constant.cpp b/clang/test/CodeGenCXX/global-llvm-constant.cpp index e799231ab74..ef1dcf0c59b 100644 --- a/clang/test/CodeGenCXX/global-llvm-constant.cpp +++ b/clang/test/CodeGenCXX/global-llvm-constant.cpp @@ -7,4 +7,4 @@ struct A { const A x; -// CHECK: @x = internal global +// CHECK: @_ZL1x = internal global diff --git a/clang/test/CodeGenCXX/mangle.cpp b/clang/test/CodeGenCXX/mangle.cpp index 5947587eec3..b4f2a3de442 100644 --- a/clang/test/CodeGenCXX/mangle.cpp +++ b/clang/test/CodeGenCXX/mangle.cpp @@ -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; +} |

