diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-17 20:04:51 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-17 20:04:51 +0000 |
commit | a418418f63f9279e671f5038a97164628772e40c (patch) | |
tree | d9b4836afc48beceecba8da8f198dde35c4730ef /clang | |
parent | 3d4276e3cf037e3e4599ff34084cf6ba03793276 (diff) | |
download | bcm5719-llvm-a418418f63f9279e671f5038a97164628772e40c.tar.gz bcm5719-llvm-a418418f63f9279e671f5038a97164628772e40c.zip |
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.
llvm-svn: 184114
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/AST/Decl.cpp | 6 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGDecl.cpp | 8 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/linkage.cpp | 11 |
3 files changed, 19 insertions, 6 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index a36fcf2507b..c799161e9b7 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -1043,9 +1043,13 @@ static LinkageInfo getLVForLocalDecl(const NamedDecl *D, 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); diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index cb157486463..614eaab3f37 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -126,10 +126,8 @@ void CodeGenFunction::EmitVarDecl(const VarDecl &D) { // 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 VarDecl &D) { } } // 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)) diff --git a/clang/test/CodeGenCXX/linkage.cpp b/clang/test/CodeGenCXX/linkage.cpp index 7c670293996..c7feaefeb85 100644 --- a/clang/test/CodeGenCXX/linkage.cpp +++ b/clang/test/CodeGenCXX/linkage.cpp @@ -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>(); +} |