}
static void ThunkGToF(Function *F, Function *G) {
- Function *NewG = Function::Create(G->getFunctionType(), G->getLinkage(),
- "", G->getParent());
+ Function *NewG = Function::Create(G->getFunctionType(), G->getLinkage(), "",
+ G->getParent());
BasicBlock *BB = BasicBlock::Create("", NewG);
std::vector<Value *> Args;
}
break;
- case ExternalWeak:
- return false;
+ case ExternalWeak: {
+ assert(catG == ExternalWeak);
+
+ // Make them both thunks to the same internal function.
+ F->setAlignment(std::max(F->getAlignment(), G->getAlignment()));
+ Function *H = Function::Create(F->getFunctionType(), F->getLinkage(), "",
+ F->getParent());
+ H->copyAttributesFrom(F);
+ H->takeName(F);
+
+ ThunkGToF(F, G);
+ ThunkGToF(F, H);
+
+ F->setLinkage(GlobalValue::InternalLinkage);
+ } break;
case Internal:
switch (catG) {
--- /dev/null
+; RUN: llvm-as < %s | opt -mergefunc | llvm-dis > %t
+; RUN: grep {define weak} %t | count 2
+; RUN: grep {call} %t | count 2
+
+define weak i32 @sum(i32 %x, i32 %y) {
+ %sum = add i32 %x, %y
+ ret i32 %sum
+}
+
+define weak i32 @add(i32 %x, i32 %y) {
+ %sum = add i32 %x, %y
+ ret i32 %sum
+}