diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2012-03-05 10:54:55 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2012-03-05 10:54:55 +0000 |
commit | 234fe654a3dd2888be42ae5db34db96c5c2c4ba3 (patch) | |
tree | 2e6ae67d1dfb3dbce908f2e7bb58a4acf08192ac /lib/CodeGen | |
parent | b3c312ce4d94a037a83ba6df6650b0317b15edd1 (diff) |
Fix a small difference in sema and codegen views of what needs to be output.
In the included testcase, soma thinks that we already have a definition after we
see the out of line decl. Codegen puts it in a deferred list, to be output if
a use is seen. This would break when we saw an explicit template instantiation
definition, since codegen would not be notified.
This patch adds a method to the consumer interface so that soma can notify
codegen that this decl is now required.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152024 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CodeGenAction.cpp | 4 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 3 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenModule.h | 5 | ||||
-rw-r--r-- | lib/CodeGen/ModuleBuilder.cpp | 4 |
4 files changed, 16 insertions, 0 deletions
diff --git a/lib/CodeGen/CodeGenAction.cpp b/lib/CodeGen/CodeGenAction.cpp index 02e0860292..b669d994ad 100644 --- a/lib/CodeGen/CodeGenAction.cpp +++ b/lib/CodeGen/CodeGenAction.cpp @@ -73,6 +73,10 @@ namespace clang { llvm::Module *takeModule() { return TheModule.take(); } llvm::Module *takeLinkModule() { return LinkModule.take(); } + virtual void MarkVarRequired(VarDecl *VD) { + Gen->MarkVarRequired(VD); + } + virtual void Initialize(ASTContext &Ctx) { Context = &Ctx; diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 922a5df344..b2bfab055b 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -1722,6 +1722,9 @@ static void ReplaceUsesOfNonProtoTypeWithRealFunction(llvm::GlobalValue *Old, } } +void CodeGenModule::MarkVarRequired(VarDecl *VD) { + GetAddrOfGlobalVar(VD); +} void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD) { const FunctionDecl *D = cast<FunctionDecl>(GD.getDecl()); diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index ba4887d057..93eee44431 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -658,6 +658,11 @@ public: /// EmitTopLevelDecl - Emit code for a single top level declaration. void EmitTopLevelDecl(Decl *D); + /// MarkVarRequired - Tell the consumer that this variable must be output. + /// This is needed when the definition is initially one that can be deferred, + /// but we then see an explicit template instantiation definition. + void MarkVarRequired(VarDecl *VD); + /// AddUsedGlobal - Add a global which should be forced to be /// present in the object file; these are emitted to the llvm.used /// metadata global. diff --git a/lib/CodeGen/ModuleBuilder.cpp b/lib/CodeGen/ModuleBuilder.cpp index ddbe27bc17..f81f6236d6 100644 --- a/lib/CodeGen/ModuleBuilder.cpp +++ b/lib/CodeGen/ModuleBuilder.cpp @@ -59,6 +59,10 @@ namespace { *M, *TD, Diags)); } + virtual void MarkVarRequired(VarDecl *VD) { + Builder->MarkVarRequired(VD); + } + virtual bool HandleTopLevelDecl(DeclGroupRef DG) { // Make sure to emit all elements of a Decl. for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) |