diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-02-15 18:11:42 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-02-15 18:11:42 +0000 |
commit | f552c20b3dd21855054010e29882e563fdcccff6 (patch) | |
tree | e11d5beeffe69d1a6ffcf07f0903727d3ff1b8e0 | |
parent | 8e3df4d0864f0a966c20088ca1a29c3398b7639d (diff) |
Emit in-class member function definitions that are marked
"used". Fixes <rdar://problem/8684363>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125579 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/ModuleBuilder.cpp | 12 | ||||
-rw-r--r-- | test/CodeGenCXX/attr-used.cpp | 9 |
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/CodeGen/ModuleBuilder.cpp b/lib/CodeGen/ModuleBuilder.cpp index 6d9d2770c7..d41d3ac268 100644 --- a/lib/CodeGen/ModuleBuilder.cpp +++ b/lib/CodeGen/ModuleBuilder.cpp @@ -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 index 0000000000..26109e7c63 --- /dev/null +++ b/test/CodeGenCXX/attr-used.cpp @@ -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() {} +}; |