summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGDecl.cpp3
-rw-r--r--clang/lib/CodeGen/CGVTT.cpp4
-rw-r--r--clang/lib/CodeGen/CGVTables.cpp4
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp23
-rw-r--r--clang/lib/CodeGen/CodeGenModule.h1
-rw-r--r--clang/lib/CodeGen/ItaniumCXXABI.cpp13
6 files changed, 21 insertions, 27 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index fdbf1f62d7c..eb9e2e28a98 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -210,8 +210,7 @@ llvm::Constant *CodeGenModule::getOrCreateStaticVarDecl(
GV->setAlignment(getContext().getDeclAlign(&D).getQuantity());
setGlobalVisibility(GV, &D);
- if (supportsCOMDAT() && GV->isWeakForLinker())
- GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
+ maybeSetTrivialComdat(*GV);
if (D.getTLSKind())
setTLSMode(GV, D);
diff --git a/clang/lib/CodeGen/CGVTT.cpp b/clang/lib/CodeGen/CGVTT.cpp
index 895afd75afc..aca9e7a3e62 100644
--- a/clang/lib/CodeGen/CGVTT.cpp
+++ b/clang/lib/CodeGen/CGVTT.cpp
@@ -94,8 +94,7 @@ CodeGenVTables::EmitVTTDefinition(llvm::GlobalVariable *VTT,
// Set the correct linkage.
VTT->setLinkage(Linkage);
- if (CGM.supportsCOMDAT() && VTT->isWeakForLinker())
- VTT->setComdat(CGM.getModule().getOrInsertComdat(VTT->getName()));
+ CGM.maybeSetTrivialComdat(*VTT);
// Set the right visibility.
CGM.setGlobalVisibility(VTT, RD);
@@ -177,4 +176,3 @@ CodeGenVTables::getSecondaryVirtualPointerIndex(const CXXRecordDecl *RD,
return I->second;
}
-
diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp
index 57370a6faa2..7359bf42145 100644
--- a/clang/lib/CodeGen/CGVTables.cpp
+++ b/clang/lib/CodeGen/CGVTables.cpp
@@ -378,9 +378,6 @@ void CodeGenFunction::GenerateThunk(llvm::Function *Fn,
// Set the right linkage.
CGM.setFunctionLinkage(GD, Fn);
- if (CGM.supportsCOMDAT() && Fn->isWeakForLinker())
- Fn->setComdat(CGM.getModule().getOrInsertComdat(Fn->getName()));
-
// Set the right visibility.
const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
setThunkVisibility(CGM, MD, Thunk, Fn);
@@ -461,6 +458,7 @@ void CodeGenVTables::emitThunk(GlobalDecl GD, const ThunkInfo &Thunk,
CGM.getCXXABI().setThunkLinkage(ThunkFn, ForVTable, GD,
!Thunk.Return.isEmpty());
}
+ CGM.maybeSetTrivialComdat(*ThunkFn);
}
void CodeGenVTables::maybeEmitThunkForVTable(GlobalDecl GD,
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index d75dcd22134..b3d7b5d4f6d 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1298,8 +1298,7 @@ llvm::Constant *CodeGenModule::GetAddrOfUuidDescriptor(
auto *GV = new llvm::GlobalVariable(
getModule(), Init->getType(),
/*isConstant=*/true, llvm::GlobalValue::LinkOnceODRLinkage, Init, Name);
- if (supportsCOMDAT())
- GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
+ maybeSetTrivialComdat(*GV);
return GV;
}
@@ -1850,9 +1849,7 @@ CodeGenModule::CreateOrReplaceCXXRuntimeVariable(StringRef Name,
OldGV->eraseFromParent();
}
- if (supportsCOMDAT() && GV->isWeakForLinker() &&
- !GV->hasAvailableExternallyLinkage())
- GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
+ maybeSetTrivialComdat(*GV);
return GV;
}
@@ -1985,6 +1982,14 @@ void CodeGenModule::maybeSetTrivialComdat(const Decl &D,
GO.setComdat(TheModule.getOrInsertComdat(GO.getName()));
}
+void CodeGenModule::maybeSetTrivialComdat(llvm::GlobalObject &GO) {
+ if (!supportsCOMDAT())
+ return;
+ if (GO.isWeakForLinker() && !GO.hasAvailableExternallyLinkage()) {
+ GO.setComdat(getModule().getOrInsertComdat(GO.getName()));
+ }
+}
+
void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
llvm::Constant *Init = nullptr;
QualType ASTTy = D->getType();
@@ -2924,10 +2929,7 @@ GenerateStringLiteral(llvm::Constant *C, llvm::GlobalValue::LinkageTypes LT,
nullptr, llvm::GlobalVariable::NotThreadLocal, AddrSpace);
GV->setAlignment(Alignment);
GV->setUnnamedAddr(true);
- if (GV->isWeakForLinker()) {
- assert(CGM.supportsCOMDAT() && "Only COFF uses weak string literals");
- GV->setComdat(M.getOrInsertComdat(GV->getName()));
- }
+ CGM.maybeSetTrivialComdat(*GV);
return GV;
}
@@ -3109,8 +3111,7 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalTemporary(
setGlobalVisibility(GV, VD);
GV->setAlignment(
getContext().getTypeAlignInChars(MaterializedType).getQuantity());
- if (supportsCOMDAT() && GV->isWeakForLinker())
- GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
+ maybeSetTrivialComdat(*GV);
if (VD->getTLSKind())
setTLSMode(GV, *VD);
Slot = GV;
diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h
index feef6c2583e..6ce5c31cee9 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -608,6 +608,7 @@ public:
const llvm::Triple &getTriple() const;
bool supportsCOMDAT() const;
void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO);
+ void maybeSetTrivialComdat(llvm::GlobalObject &GO);
CGCXXABI &getCXXABI() const { return *ABI; }
llvm::LLVMContext &getLLVMContext() { return VMContext; }
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index e8c28c1265d..58786fe2ce0 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1328,8 +1328,7 @@ void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables &CGVT,
// Set the correct linkage.
VTable->setLinkage(Linkage);
- if (CGM.supportsCOMDAT() && VTable->isWeakForLinker())
- VTable->setComdat(CGM.getModule().getOrInsertComdat(VTable->getName()));
+ CGM.maybeSetTrivialComdat(*VTable);
// Set the right visibility.
CGM.setGlobalVisibility(VTable, RD);
@@ -1796,8 +1795,8 @@ void ItaniumCXXABI::EmitGuardedInit(CodeGenFunction &CGF,
if (!D.isLocalVarDecl() && C) {
guard->setComdat(C);
CGF.CurFn->setComdat(C);
- } else if (CGM.supportsCOMDAT() && guard->isWeakForLinker()) {
- guard->setComdat(CGM.getModule().getOrInsertComdat(guard->getName()));
+ } else {
+ CGM.maybeSetTrivialComdat(*guard);
}
CGM.setStaticLocalDeclGuardAddress(&D, guard);
@@ -2803,8 +2802,7 @@ llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo(QualType Ty, bool Force) {
new llvm::GlobalVariable(M, Init->getType(),
/*Constant=*/true, Linkage, Init, Name);
- if (CGM.supportsCOMDAT() && GV->isWeakForLinker())
- GV->setComdat(M.getOrInsertComdat(GV->getName()));
+ CGM.maybeSetTrivialComdat(*GV);
// If there's already an old global variable, replace it with the new one.
if (OldGV) {
@@ -3598,8 +3596,7 @@ static llvm::Constant *getClangCallTerminateFn(CodeGenModule &CGM) {
// we don't want it to turn into an exported symbol.
fn->setLinkage(llvm::Function::LinkOnceODRLinkage);
fn->setVisibility(llvm::Function::HiddenVisibility);
- if (CGM.supportsCOMDAT())
- fn->setComdat(CGM.getModule().getOrInsertComdat(fn->getName()));
+ CGM.maybeSetTrivialComdat(*fn);
// Set up the function.
llvm::BasicBlock *entry =
OpenPOWER on IntegriCloud