]> granicus.if.org Git - clang/commitdiff
In addition to in-class member functions marked with the "used"
authorDouglas Gregor <dgregor@apple.com>
Sat, 19 Feb 2011 21:54:50 +0000 (21:54 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 19 Feb 2011 21:54:50 +0000 (21:54 +0000)
attribute, we also care about those with the "constructor"
attribute. Fixes PR6521.

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

lib/CodeGen/ModuleBuilder.cpp
test/CodeGenCXX/constructor-attr.cpp [new file with mode: 0644]

index d41d3ac268a0657fd7baf79bb92d856b225040c6..894502864464c073451834d4884a00e4fa96e1d6 100644 (file)
@@ -80,7 +80,8 @@ namespace {
              M != MEnd; ++M)
           if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(*M))
             if (Method->isThisDeclarationADefinition() &&
-                Method->hasAttr<UsedAttr>())
+                (Method->hasAttr<UsedAttr>() || 
+                 Method->hasAttr<ConstructorAttr>()))
               Builder->EmitTopLevelDecl(Method);
       }
     }
diff --git a/test/CodeGenCXX/constructor-attr.cpp b/test/CodeGenCXX/constructor-attr.cpp
new file mode 100644 (file)
index 0000000..691795f
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: @llvm.global_ctors
+
+// PR6521
+void bar();
+struct Foo {
+  // CHECK: define linkonce_odr void @_ZN3Foo3fooEv
+  static void foo() __attribute__((constructor)) {
+    bar();
+  }
+};