]> granicus.if.org Git - clang/commitdiff
Use new getLinkage() method to correctly compute whether a variable has
authorEli Friedman <eli.friedman@gmail.com>
Thu, 26 Nov 2009 02:52:12 +0000 (02:52 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Thu, 26 Nov 2009 02:52:12 +0000 (02:52 +0000)
internal linkage.  Fixes PR5433.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89931 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/CodeGenCXX/const-global-linkage.cpp [new file with mode: 0644]

index 7cd9e9f81be33843f54f3d59b426dd07cba2db79..6aff0e7476bc31cc72be54fa0bfcce7a05a35965 100644 (file)
@@ -549,7 +549,7 @@ bool CodeGenModule::MayDeferGeneration(const ValueDecl *Global) {
   // cannot be.
   if (VD->isInAnonymousNamespace())
     return true;
-  if (VD->getStorageClass() == VarDecl::Static) {
+  if (VD->getLinkage() == VarDecl::InternalLinkage) {
     // Initializer has side effects?
     if (VD->getInit() && VD->getInit()->HasSideEffects(Context))
       return false;
@@ -982,9 +982,8 @@ GetLinkageForVariable(ASTContext &Context, const VarDecl *VD) {
       return CodeGenModule::GVA_TemplateInstantiation;
     }
   }
-  
-  // Static variables get internal linkage.
-  if (VD->getStorageClass() == VarDecl::Static)
+
+  if (VD->getLinkage() == VarDecl::InternalLinkage)
     return CodeGenModule::GVA_Internal;
 
   return CodeGenModule::GVA_StrongExternal;
diff --git a/test/CodeGenCXX/const-global-linkage.cpp b/test/CodeGenCXX/const-global-linkage.cpp
new file mode 100644 (file)
index 0000000..ddf4358
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: clang-cc -emit-llvm -o - %s | FileCheck %s
+
+const int x = 10;
+const int y = 20;
+// CHECK-NOT: @x
+// CHECK: @y = internal constant i32 20
+const int& b() { return y; }
+