summaryrefslogtreecommitdiff
path: root/lib/CodeGen/ModuleBuilder.cpp
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2014-06-06 17:36:17 +0000
committerHans Wennborg <hans@hanshq.net>2014-06-06 17:36:17 +0000
commit8cf6d63a853e8f59df80b97c941b2162752d0c68 (patch)
tree96e45075c1268d5bb7e8750bc95d81ff890b5ff5 /lib/CodeGen/ModuleBuilder.cpp
parent150a4989ecf988595f80809abf84835c9625b33c (diff)
downloadclang-8cf6d63a853e8f59df80b97c941b2162752d0c68.tar.gz
clang-8cf6d63a853e8f59df80b97c941b2162752d0c68.tar.bz2
clang-8cf6d63a853e8f59df80b97c941b2162752d0c68.tar.xz
Defer codegen of inline method definitions to the end of current top level declaration
We would previously fail to emit a definition of bar() for the following code: struct __declspec(dllexport) S { void foo() { t->bar(); } struct T { void bar() {} }; T *t; }; Note that foo() is an exported method, but bar() is not. However, foo() refers to bar() so we need to emit its definition. We would previously fail to realise that bar() is used. By deferring the method definitions until the end of the top level declaration, we can simply call EmitTopLevelDecl on them and rely on the usual mechanisms to decide whether the method should be emitted or not. Differential Revision: http://reviews.llvm.org/D4038 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@210356 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/ModuleBuilder.cpp')
-rw-r--r--lib/CodeGen/ModuleBuilder.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/CodeGen/ModuleBuilder.cpp b/lib/CodeGen/ModuleBuilder.cpp
index e5bdae93fe..c4a0e5c063 100644
--- a/lib/CodeGen/ModuleBuilder.cpp
+++ b/lib/CodeGen/ModuleBuilder.cpp
@@ -93,6 +93,12 @@ namespace {
// Make sure to emit all elements of a Decl.
for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I)
Builder->EmitTopLevelDecl(*I);
+
+ // Emit any deferred inline method definitions.
+ for (CXXMethodDecl *MD : DeferredInlineMethodDefinitions)
+ Builder->EmitTopLevelDecl(MD);
+ DeferredInlineMethodDefinitions.clear();
+
return true;
}
@@ -102,12 +108,15 @@ namespace {
assert(D->doesThisDeclarationHaveABody());
- // We may have member functions that need to be emitted at this point.
- if (!D->isDependentContext() &&
- (D->hasAttr<UsedAttr>() || D->hasAttr<ConstructorAttr>() ||
- D->hasAttr<DLLExportAttr>())) {
- Builder->EmitTopLevelDecl(D);
- }
+ // We may want to emit this definition. However, that decision might be
+ // based on computing the linkage, and we have to defer that in case we
+ // are inside of something that will change the method's final linkage,
+ // e.g.
+ // typedef struct {
+ // void bar();
+ // void foo() { bar(); }
+ // } A;
+ DeferredInlineMethodDefinitions.push_back(D);
}
/// HandleTagDeclDefinition - This callback is invoked each time a TagDecl
@@ -168,6 +177,9 @@ namespace {
void HandleDependentLibrary(llvm::StringRef Lib) override {
Builder->AddDependentLib(Lib);
}
+
+ private:
+ std::vector<CXXMethodDecl *> DeferredInlineMethodDefinitions;
};
}