]> granicus.if.org Git - clang/commitdiff
Emit in-class member function definitions that are marked
authorDouglas Gregor <dgregor@apple.com>
Tue, 15 Feb 2011 18:11:42 +0000 (18:11 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 15 Feb 2011 18:11:42 +0000 (18:11 +0000)
"used". Fixes <rdar://problem/8684363>.

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

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

index 6d9d2770c7c84d3744b32489fea1313ab6e469f4..d41d3ac268a0657fd7baf79bb92d856b225040c6 100644 (file)
@@ -71,6 +71,18 @@ namespace {
     /// (because these can be defined in declspecs).
     virtual void HandleTagDeclDefinition(TagDecl *D) {
       Builder->UpdateCompletedType(D);
+      
+      // In C++, we may have member functions that need to be emitted at this 
+      // point.
+      if (Ctx->getLangOptions().CPlusPlus && !D->isDependentContext()) {
+        for (DeclContext::decl_iterator M = D->decls_begin(), 
+                                     MEnd = D->decls_end();
+             M != MEnd; ++M)
+          if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(*M))
+            if (Method->isThisDeclarationADefinition() &&
+                Method->hasAttr<UsedAttr>())
+              Builder->EmitTopLevelDecl(Method);
+      }
     }
 
     virtual void HandleTranslationUnit(ASTContext &Ctx) {
diff --git a/test/CodeGenCXX/attr-used.cpp b/test/CodeGenCXX/attr-used.cpp
new file mode 100644 (file)
index 0000000..26109e7
--- /dev/null
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+
+// <rdar://problem/8684363>: clang++ not respecting __attribute__((used)) on destructors
+struct X0 {
+  // CHECK: define linkonce_odr void @_ZN2X0C1Ev
+  __attribute__((used)) X0() {}
+  // CHECK: define linkonce_odr void @_ZN2X0D1Ev
+  __attribute__((used)) ~X0() {}
+};