aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/Mangle.cpp
diff options
context:
space:
mode:
authorSean Hunt <rideau3@gmail.com>2010-01-24 03:04:27 +0000
committerSean Hunt <rideau3@gmail.com>2010-01-24 03:04:27 +0000
commit31455256ae26cc7069111643ec4429ea564377da (patch)
tree53431a5b13cc8470317d88666409862de7bd0452 /lib/CodeGen/Mangle.cpp
parent1efcf3d137c11fb6b21c385911e0d2ca59ca94c3 (diff)
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
Diffstat (limited to 'lib/CodeGen/Mangle.cpp')
-rw-r--r--lib/CodeGen/Mangle.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp
index d873cfec1b..b6bebd0247 100644
--- a/lib/CodeGen/Mangle.cpp
+++ b/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;
}