diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-02-13 22:08:43 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-02-13 22:08:43 +0000 |
commit | 5c61d97ad442b2c0bbecb617c8f21857ce1fff6d (patch) | |
tree | 3bc1e1cdf7efbcc53a69fe846418e8c821c00ab5 /lib/CodeGen/CodeGenModule.cpp | |
parent | 56cd21bd52aed7a32f3ff11b7e480f664d0b4262 (diff) |
IRgen support for attribute used.
- PR3566
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64492 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index ecfd8c98c3..e60edce213 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -238,11 +238,11 @@ void CodeGenModule::EmitAnnotations() { gv->setSection("llvm.metadata"); } -static void SetGlobalValueAttributes(const Decl *D, - bool IsInternal, - bool IsInline, - llvm::GlobalValue *GV, - bool ForDefinition) { +void CodeGenModule::SetGlobalValueAttributes(const Decl *D, + bool IsInternal, + bool IsInline, + llvm::GlobalValue *GV, + bool ForDefinition) { // FIXME: Set up linkage and many other things. Note, this is a simple // approximation of what we really want. if (!ForDefinition) { @@ -290,6 +290,14 @@ static void SetGlobalValueAttributes(const Decl *D, if (const SectionAttr *SA = D->getAttr<SectionAttr>()) GV->setSection(SA->getName()); + + // Only add to llvm.used when we see a definition, otherwise we + // might add multiple times or risk the value being replaced by a + // subsequent RAUW. + if (ForDefinition) { + if (D->getAttr<UsedAttr>()) + AddUsedGlobal(GV); + } } void CodeGenModule::SetFunctionAttributes(const Decl *D, @@ -492,8 +500,9 @@ llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV, } bool CodeGenModule::MayDeferGeneration(const ValueDecl *Global) { - // Never defer when EmitAllDecls is specified. - if (Features.EmitAllDecls) + // Never defer when EmitAllDecls is specified or the decl has + // attribute used. + if (Features.EmitAllDecls || Global->getAttr<UsedAttr>()) return false; if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Global)) { @@ -728,6 +737,9 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) { if (const SectionAttr *SA = D->getAttr<SectionAttr>()) GV->setSection(SA->getName()); + if (D->getAttr<UsedAttr>()) + AddUsedGlobal(GV); + // Emit global variable debug information. CGDebugInfo *DI = getDebugInfo(); if(DI) { |