r184114 - Cleanup linkage computation for static locals.
Rafael Espindola
rafael.espindola at gmail.com
Mon Jun 17 13:04:51 PDT 2013
Author: rafael
Date: Mon Jun 17 15:04:51 2013
New Revision: 184114
URL: http://llvm.org/viewvc/llvm-project?rev=184114&view=rev
Log:
Cleanup linkage computation for static locals.
With this patch we assign VisibleNoLinkage to static locals in inline functions.
This lets us simplify CodeGen a bit.
Modified:
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/test/CodeGenCXX/linkage.cpp
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=184114&r1=184113&r2=184114&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Mon Jun 17 15:04:51 2013
@@ -1043,9 +1043,13 @@ static LinkageInfo getLVForLocalDecl(con
return LV;
}
+
+ if (!Var->isStaticLocal())
+ return LinkageInfo::none();
}
- if (!isa<TagDecl>(D))
+ ASTContext &Context = D->getASTContext();
+ if (!Context.getLangOpts().CPlusPlus)
return LinkageInfo::none();
const FunctionDecl *FD = getOutermostFunctionContext(D);
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=184114&r1=184113&r2=184114&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Mon Jun 17 15:04:51 2013
@@ -126,10 +126,8 @@ void CodeGenFunction::EmitVarDecl(const
// If the function definition has some sort of weak linkage, its
// static variables should also be weak so that they get properly
- // uniqued. We can't do this in C, though, because there's no
- // standard way to agree on which variables are the same (i.e.
- // there's no mangling).
- if (getLangOpts().CPlusPlus) {
+ // uniqued.
+ if (D.isExternallyVisible()) {
const Decl *D = CurCodeDecl;
while (true) {
if (isa<BlockDecl>(D)) {
@@ -143,7 +141,7 @@ void CodeGenFunction::EmitVarDecl(const
}
}
// FIXME: Do we really only care about FunctionDecls here?
- if (D && isa<FunctionDecl>(D)) {
+ if (isa<FunctionDecl>(D)) {
llvm::GlobalValue::LinkageTypes ParentLinkage =
CGM.getFunctionLinkage(cast<FunctionDecl>(D));
if (llvm::GlobalValue::isWeakForLinker(ParentLinkage))
Modified: cfe/trunk/test/CodeGenCXX/linkage.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/linkage.cpp?rev=184114&r1=184113&r2=184114&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/linkage.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/linkage.cpp Mon Jun 17 15:04:51 2013
@@ -209,3 +209,14 @@ namespace test16 {
}
void *test() { return foo<int>::bar(); }
}
+
+namespace test17 {
+ // CHECK-DAG: @_ZZN6test173fooILi42EEEPivE3bar = weak_odr
+ // CHECK-DAG: define weak_odr i32* @_ZN6test173fooILi42EEEPiv(
+ template<int I>
+ int *foo() {
+ static int bar;
+ return &bar;
+ }
+ template int *foo<42>();
+}
More information about the cfe-commits
mailing list