diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-02-14 01:47:04 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-02-14 01:47:04 +0000 |
commit | d2fdd4256a2efc41365ccdd27a210d1d99a1fe3a (patch) | |
tree | 806a23fc44c70cd99e6316463c8e25362d3abdbd /lib/AST/ItaniumMangle.cpp | |
parent | 950fee2555f7a6bd193e588d6b6a941fd182391a (diff) |
merge hasCLanguageLinkage and isExternC. Keep the shorter name.
I added hasCLanguageLinkage while fixing some language linkage bugs some
time ago so that I wouldn't have to check all users of isExternC. It turned
out to be a much longer detour than expected, but this patch finally
merges the two again. The isExternC function now implements just the
standard notion of having C language linkage.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175119 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ItaniumMangle.cpp')
-rw-r--r-- | lib/AST/ItaniumMangle.cpp | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/lib/AST/ItaniumMangle.cpp b/lib/AST/ItaniumMangle.cpp index a7fc16aae3..e9a3b03483 100644 --- a/lib/AST/ItaniumMangle.cpp +++ b/lib/AST/ItaniumMangle.cpp @@ -366,20 +366,34 @@ bool ItaniumMangleContext::shouldMangleDeclName(const NamedDecl *D) { if (D->hasAttr<AsmLabelAttr>()) return true; - // Clang's "overloadable" attribute extension to C/C++ implies name mangling - // (always) as does passing a C++ member function and a function - // whose name is not a simple identifier. const FunctionDecl *FD = dyn_cast<FunctionDecl>(D); - if (FD && (FD->hasAttr<OverloadableAttr>() || isa<CXXMethodDecl>(FD) || - !FD->getDeclName().isIdentifier())) - return true; + if (FD) { + LanguageLinkage L = FD->getLanguageLinkage(); + // Overloadable functions need mangling. + if (FD->hasAttr<OverloadableAttr>()) + return true; + + // C functions and "main" are not mangled. + if (FD->isMain() || L == CLanguageLinkage) + return false; + + // C++ functions and those whose names are not a simple identifier need + // mangling. + if (!FD->getDeclName().isIdentifier() || L == CXXLanguageLinkage) + return true; + } // Otherwise, no mangling is done outside C++ mode. if (!getASTContext().getLangOpts().CPlusPlus) return false; - // Variables at global scope with non-internal linkage are not mangled - if (!FD) { + const VarDecl *VD = dyn_cast<VarDecl>(D); + if (VD) { + // C variables are not mangled. + if (VD->isExternC()) + return false; + + // Variables at global scope with non-internal linkage are not mangled const DeclContext *DC = getEffectiveDeclContext(D); // Check for extern variable declared locally. if (DC->isFunctionOrMethod() && D->hasLinkage()) @@ -389,18 +403,6 @@ bool ItaniumMangleContext::shouldMangleDeclName(const NamedDecl *D) { return false; } - // Class members are always mangled. - if (getEffectiveDeclContext(D)->isRecord()) - return true; - - // C functions and "main" are not mangled. - if (FD) - return !FD->isMain() && !FD->hasCLanguageLinkage(); - - // C variables are not mangled. - if (const VarDecl *VD = dyn_cast<VarDecl>(D)) - return !VD->hasCLanguageLinkage(); - return true; } |