Commit ebfe2a27 authored by Hans Wennborg's avatar Hans Wennborg
Browse files

Merging r242293:

------------------------------------------------------------------------
r242293 | rafael | 2015-07-15 07:48:06 -0700 (Wed, 15 Jul 2015) | 3 lines

Set comdat when an available_externally thunk is converted to linkonce_odr.

Fixes pr24130.
------------------------------------------------------------------------

llvm-svn: 242333
parent 64d8956c
Loading
Loading
Loading
Loading
+17 −12
Original line number Diff line number Diff line
@@ -56,6 +56,21 @@ static void setThunkVisibility(CodeGenModule &CGM, const CXXMethodDecl *MD,
  CGM.setGlobalVisibility(Fn, MD);
}

static void setThunkProperties(CodeGenModule &CGM, const ThunkInfo &Thunk,
                               llvm::Function *ThunkFn, bool ForVTable,
                               GlobalDecl GD) {
  CGM.setFunctionLinkage(GD, ThunkFn);
  CGM.getCXXABI().setThunkLinkage(ThunkFn, ForVTable, GD,
                                  !Thunk.Return.isEmpty());

  // Set the right visibility.
  const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
  setThunkVisibility(CGM, MD, Thunk, ThunkFn);

  if (CGM.supportsCOMDAT() && ThunkFn->isWeakForLinker())
    ThunkFn->setComdat(CGM.getModule().getOrInsertComdat(ThunkFn->getName()));
}

#ifndef NDEBUG
static bool similar(const ABIArgInfo &infoL, CanQualType typeL,
                    const ABIArgInfo &infoR, CanQualType typeR) {
@@ -429,8 +444,7 @@ void CodeGenVTables::emitThunk(GlobalDecl GD, const ThunkInfo &Thunk,
      return;
    }

    // Change the linkage.
    CGM.setFunctionLinkage(GD, ThunkFn);
    setThunkProperties(CGM, Thunk, ThunkFn, ForVTable, GD);
    return;
  }

@@ -451,16 +465,7 @@ void CodeGenVTables::emitThunk(GlobalDecl GD, const ThunkInfo &Thunk,
    CodeGenFunction(CGM).generateThunk(ThunkFn, FnInfo, GD, Thunk);
  }

  CGM.setFunctionLinkage(GD, ThunkFn);
  CGM.getCXXABI().setThunkLinkage(ThunkFn, ForVTable, GD,
                                  !Thunk.Return.isEmpty());

  // Set the right visibility.
  const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
  setThunkVisibility(CGM, MD, Thunk, ThunkFn);

  if (CGM.supportsCOMDAT() && ThunkFn->isWeakForLinker())
    ThunkFn->setComdat(CGM.getModule().getOrInsertComdat(ThunkFn->getName()));
  setThunkProperties(CGM, Thunk, ThunkFn, ForVTable, GD);
}

void CodeGenVTables::maybeEmitThunkForVTable(GlobalDecl GD,
+17 −0
Original line number Diff line number Diff line
@@ -361,6 +361,23 @@ namespace Test15 {
  // CHECK: declare void @_ZThn8_N6Test151C1fEiz
}

namespace Test16 {
struct A {
  virtual ~A();
};
struct B {
  virtual void foo();
};
struct C : public A, public B {
  void foo() {}
};
struct D : public C {
  ~D();
};
D::~D() {}
// CHECK: define linkonce_odr void @_ZThn8_N6Test161C3fooEv({{.*}}) {{.*}} comdat
}

/**** The following has to go at the end of the file ****/

// This is from Test5: