]> granicus.if.org Git - clang/commitdiff
Revert r236879, "Do not emit thunks with available_externally linkage in comdats"
authorNAKAMURA Takumi <geek4civic@gmail.com>
Sat, 9 May 2015 21:10:07 +0000 (21:10 +0000)
committerNAKAMURA Takumi <geek4civic@gmail.com>
Sat, 9 May 2015 21:10:07 +0000 (21:10 +0000)
It broke pecoff, at least i686-cygwin.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236937 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDecl.cpp
lib/CodeGen/CGVTT.cpp
lib/CodeGen/CGVTables.cpp
lib/CodeGen/CodeGenModule.cpp
lib/CodeGen/CodeGenModule.h
lib/CodeGen/ItaniumCXXABI.cpp
test/CodeGenCXX/thunks.cpp

index eb9e2e28a985639c8927a70d2d1ab7f95f48f0ff..fdbf1f62d7c90f8dca7eeb356114c11b5fc90982 100644 (file)
@@ -210,7 +210,8 @@ llvm::Constant *CodeGenModule::getOrCreateStaticVarDecl(
   GV->setAlignment(getContext().getDeclAlign(&D).getQuantity());
   setGlobalVisibility(GV, &D);
 
-  maybeSetTrivialComdat(*GV);
+  if (supportsCOMDAT() && GV->isWeakForLinker())
+    GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
 
   if (D.getTLSKind())
     setTLSMode(GV, D);
index aca9e7a3e629fb0793efdbe3070233878764788e..895afd75afc44daf624aaa243ab3140922a19301 100644 (file)
@@ -94,7 +94,8 @@ CodeGenVTables::EmitVTTDefinition(llvm::GlobalVariable *VTT,
   // Set the correct linkage.
   VTT->setLinkage(Linkage);
 
-  CGM.maybeSetTrivialComdat(*VTT);
+  if (CGM.supportsCOMDAT() && VTT->isWeakForLinker())
+    VTT->setComdat(CGM.getModule().getOrInsertComdat(VTT->getName()));
 
   // Set the right visibility.
   CGM.setGlobalVisibility(VTT, RD);
@@ -176,3 +177,4 @@ CodeGenVTables::getSecondaryVirtualPointerIndex(const CXXRecordDecl *RD,
   
   return I->second;
 }
+
index 7359bf42145d4d161bc23672d0c23968982aad9f..57370a6faa2c0817affeaf4629e275404ab560b9 100644 (file)
@@ -378,6 +378,9 @@ 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);
@@ -458,7 +461,6 @@ 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,
index b3d7b5d4f6d67f34a27df4fcfc59855bf9644c5f..d75dcd2213433a1ab9c4d8c887d1da0e77c20681 100644 (file)
@@ -1298,7 +1298,8 @@ llvm::Constant *CodeGenModule::GetAddrOfUuidDescriptor(
   auto *GV = new llvm::GlobalVariable(
       getModule(), Init->getType(),
       /*isConstant=*/true, llvm::GlobalValue::LinkOnceODRLinkage, Init, Name);
-  maybeSetTrivialComdat(*GV);
+  if (supportsCOMDAT())
+    GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
   return GV;
 }
 
@@ -1849,7 +1850,9 @@ CodeGenModule::CreateOrReplaceCXXRuntimeVariable(StringRef Name,
     OldGV->eraseFromParent();
   }
 
-  maybeSetTrivialComdat(*GV);
+  if (supportsCOMDAT() && GV->isWeakForLinker() &&
+      !GV->hasAvailableExternallyLinkage())
+    GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
 
   return GV;
 }
@@ -1982,14 +1985,6 @@ 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();
@@ -2929,7 +2924,10 @@ GenerateStringLiteral(llvm::Constant *C, llvm::GlobalValue::LinkageTypes LT,
       nullptr, llvm::GlobalVariable::NotThreadLocal, AddrSpace);
   GV->setAlignment(Alignment);
   GV->setUnnamedAddr(true);
-  CGM.maybeSetTrivialComdat(*GV);
+  if (GV->isWeakForLinker()) {
+    assert(CGM.supportsCOMDAT() && "Only COFF uses weak string literals");
+    GV->setComdat(M.getOrInsertComdat(GV->getName()));
+  }
 
   return GV;
 }
@@ -3111,7 +3109,8 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalTemporary(
   setGlobalVisibility(GV, VD);
   GV->setAlignment(
       getContext().getTypeAlignInChars(MaterializedType).getQuantity());
-  maybeSetTrivialComdat(*GV);
+  if (supportsCOMDAT() && GV->isWeakForLinker())
+    GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
   if (VD->getTLSKind())
     setTLSMode(GV, *VD);
   Slot = GV;
index 6ce5c31cee9752a0d5cea19a458d56cdbb2e85e4..feef6c2583ec38cd5c1bafc5985dc951d9ce855f 100644 (file)
@@ -608,7 +608,6 @@ 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; }
index 58786fe2ce0ef6d58ff7454de54f93c9318f8e89..e8c28c1265dd493e37cca04b485a116fa90ae454 100644 (file)
@@ -1328,7 +1328,8 @@ void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables &CGVT,
   // Set the correct linkage.
   VTable->setLinkage(Linkage);
 
-  CGM.maybeSetTrivialComdat(*VTable);
+  if (CGM.supportsCOMDAT() && VTable->isWeakForLinker())
+    VTable->setComdat(CGM.getModule().getOrInsertComdat(VTable->getName()));
 
   // Set the right visibility.
   CGM.setGlobalVisibility(VTable, RD);
@@ -1795,8 +1796,8 @@ void ItaniumCXXABI::EmitGuardedInit(CodeGenFunction &CGF,
     if (!D.isLocalVarDecl() && C) {
       guard->setComdat(C);
       CGF.CurFn->setComdat(C);
-    } else {
-      CGM.maybeSetTrivialComdat(*guard);
+    } else if (CGM.supportsCOMDAT() && guard->isWeakForLinker()) {
+      guard->setComdat(CGM.getModule().getOrInsertComdat(guard->getName()));
     }
 
     CGM.setStaticLocalDeclGuardAddress(&D, guard);
@@ -2802,7 +2803,8 @@ llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo(QualType Ty, bool Force) {
       new llvm::GlobalVariable(M, Init->getType(),
                                /*Constant=*/true, Linkage, Init, Name);
 
-  CGM.maybeSetTrivialComdat(*GV);
+  if (CGM.supportsCOMDAT() && GV->isWeakForLinker())
+    GV->setComdat(M.getOrInsertComdat(GV->getName()));
 
   // If there's already an old global variable, replace it with the new one.
   if (OldGV) {
@@ -3596,7 +3598,8 @@ 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);
-    CGM.maybeSetTrivialComdat(*fn);
+    if (CGM.supportsCOMDAT())
+      fn->setComdat(CGM.getModule().getOrInsertComdat(fn->getName()));
 
     // Set up the function.
     llvm::BasicBlock *entry =
index 255017057ca2258fa577214a494e7cee9643ad56..2287d65a286d5977f83a6ecbe94e562a001c35b2 100644 (file)
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -munwind-tables -emit-llvm -o - | FileCheck %s
-// RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -munwind-tables -emit-llvm -o - -O1 -disable-llvm-optzns | FileCheck %s --check-prefix=CHECK --check-prefix=CHECKOPT
+// RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -munwind-tables -emit-llvm -o - -O1 -disable-llvm-optzns | FileCheck %s
 
 namespace Test1 {
 
@@ -361,28 +361,6 @@ namespace Test15 {
   // CHECK: declare void @_ZThn8_N6Test151C1fEiz
 }
 
-namespace Test16 {
-
-// Check that the thunk for 'B::f' has available_externally linkage
-// and is not in a comdat.
-
-template <class C>
-struct A {
-  virtual void f();
-};
-
-template <class D>
-struct B : virtual A<D> {
-  virtual void f() { }
-};
-
-extern template struct B<int>;
-
-void f(B<int> b) {
-  b.f();
-}
-}
-
 /**** The following has to go at the end of the file ****/
 
 // This is from Test5:
@@ -393,7 +371,4 @@ void f(B<int> b) {
 // CHECK-LABEL: define linkonce_odr void @_ZN6Test101C3fooEv
 // CHECK-LABEL: define linkonce_odr void @_ZThn8_N6Test101C3fooEv
 
-// CHECKOPT-LABEL: define available_externally void @_ZTv0_n24_N6Test161BIiE1fEv
-// CHECKOPT-NOT: comdat
-
 // CHECK: attributes [[NUW]] = { nounwind uwtable{{.*}} }