]> granicus.if.org Git - clang/commitdiff
Switch CodeGen's "is this variable declaration a definition?" logic
authorDouglas Gregor <dgregor@apple.com>
Sat, 6 Feb 2010 05:15:45 +0000 (05:15 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 6 Feb 2010 05:15:45 +0000 (05:15 +0000)
over to VarDecl::isThisDeclarationADefinition(), which handles
variables declared with linkage specifications better (among other
things). CMake 2.9 (from CVS) now builds with clang++ and is somewhat
functional.

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

lib/CodeGen/CodeGenModule.cpp
test/CXX/dcl.dcl/dcl.link/p7.cpp [new file with mode: 0644]

index fc5989fa9a4b965d0a19dc4e70e76ff49a8a566d..644c5d0bf8ca2067ec2430ed691b03d6f4b52b67 100644 (file)
@@ -627,20 +627,7 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
     const VarDecl *VD = cast<VarDecl>(Global);
     assert(VD->isFileVarDecl() && "Cannot emit local var decl as global.");
 
-    if (getLangOptions().CPlusPlus && !VD->getInit()) {
-      // In C++, if this is marked "extern", defer code generation.
-      if (VD->getStorageClass() == VarDecl::Extern || VD->isExternC())
-        return;
-
-      // If this is a declaration of an explicit specialization of a static
-      // data member in a class template, don't emit it.
-      if (VD->isStaticDataMember() && 
-          VD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
-        return;
-    }
-
-    // In C, if this isn't a definition, defer code generation.
-    if (!getLangOptions().CPlusPlus && !VD->getInit())
+    if (VD->isThisDeclarationADefinition() != VarDecl::Definition)
       return;
   }
 
diff --git a/test/CXX/dcl.dcl/dcl.link/p7.cpp b/test/CXX/dcl.dcl/dcl.link/p7.cpp
new file mode 100644 (file)
index 0000000..bd9ff3c
--- /dev/null
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+
+struct X { };
+
+// CHECK: @x1 = global %struct.X zeroinitializer
+// CHECK: @x4 = global %struct.X zeroinitializer
+// CHECK: @x2 = external global %struct.X
+// CHECK: @x3 = external global %struct.X
+extern "C" {
+
+
+  X x1;
+}
+
+extern "C" X x2;
+
+extern X x3;
+
+X x4;
+
+X& get(int i) {
+  if (i == 1)
+    return x1;
+  else if (i == 2)
+    return x2;
+  else if (i == 3)
+    return x3;
+  else
+    return x4;
+}