diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2015-06-09 19:08:19 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2015-06-09 19:08:19 +0000 | 
| commit | 798321d8eb5630cd4a8f490a4f25e32ef195fb07 (patch) | |
| tree | a59f5569ef36d00388c0428426abef26aa9105b6 /lib/CodeGen/CodeGenModule.cpp | |
| parent | 5e20cdd81c44a443562a09007668ffdf76c455af (diff) | |
Notes
Diffstat (limited to 'lib/CodeGen/CodeGenModule.cpp')
| -rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 39 | 
1 files changed, 23 insertions, 16 deletions
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 400506129e64..9496831ea8c8 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -676,6 +676,25 @@ CodeGenModule::getFunctionLinkage(GlobalDecl GD) {    return getLLVMLinkageForDeclarator(D, Linkage, /*isConstantVariable=*/false);  } +void CodeGenModule::setFunctionDLLStorageClass(GlobalDecl GD, llvm::Function *F) { +  const auto *FD = cast<FunctionDecl>(GD.getDecl()); + +  if (const auto *Dtor = dyn_cast_or_null<CXXDestructorDecl>(FD)) { +    if (getCXXABI().useThunkForDtorVariant(Dtor, GD.getDtorType())) { +      // Don't dllexport/import destructor thunks. +      F->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass); +      return; +    } +  } + +  if (FD->hasAttr<DLLImportAttr>()) +    F->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass); +  else if (FD->hasAttr<DLLExportAttr>()) +    F->setDLLStorageClass(llvm::GlobalVariable::DLLExportStorageClass); +  else +    F->setDLLStorageClass(llvm::GlobalVariable::DefaultStorageClass); +} +  void CodeGenModule::setFunctionDefinitionAttributes(const FunctionDecl *D,                                                      llvm::Function *F) {    setNonAliasAttributes(D, F); @@ -817,7 +836,7 @@ void CodeGenModule::setNonAliasAttributes(const Decl *D,    if (const SectionAttr *SA = D->getAttr<SectionAttr>())      GO->setSection(SA->getName()); -  getTargetCodeGenInfo().SetTargetAttributes(D, GO, *this); +  getTargetCodeGenInfo().setTargetAttributes(D, GO, *this);  }  void CodeGenModule::SetInternalFunctionAttributes(const Decl *D, @@ -889,13 +908,6 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,    setLinkageAndVisibilityForGV(F, FD); -  if (const auto *Dtor = dyn_cast_or_null<CXXDestructorDecl>(FD)) { -    if (getCXXABI().useThunkForDtorVariant(Dtor, GD.getDtorType())) { -      // Don't dllexport/import destructor thunks. -      F->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass); -    } -  } -    if (const SectionAttr *SA = FD->getAttr<SectionAttr>())      F->setSection(SA->getName()); @@ -909,13 +921,13 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,  void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) {    assert(!GV->isDeclaration() &&           "Only globals with definition can force usage."); -  LLVMUsed.push_back(GV); +  LLVMUsed.emplace_back(GV);  }  void CodeGenModule::addCompilerUsedGlobal(llvm::GlobalValue *GV) {    assert(!GV->isDeclaration() &&           "Only globals with definition can force usage."); -  LLVMCompilerUsed.push_back(GV); +  LLVMCompilerUsed.emplace_back(GV);  }  static void emitUsed(CodeGenModule &CGM, StringRef Name, @@ -2455,12 +2467,7 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD,    // declarations).    auto *Fn = cast<llvm::Function>(GV);    setFunctionLinkage(GD, Fn); -  if (D->hasAttr<DLLImportAttr>()) -    GV->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass); -  else if (D->hasAttr<DLLExportAttr>()) -    GV->setDLLStorageClass(llvm::GlobalVariable::DLLExportStorageClass); -  else -    GV->setDLLStorageClass(llvm::GlobalVariable::DefaultStorageClass); +  setFunctionDLLStorageClass(GD, Fn);    // FIXME: this is redundant with part of setFunctionDefinitionAttributes    setGlobalVisibility(Fn, D);  | 
