Index: llvm/lib/Transforms/IPO/LowerTypeTests.cpp =================================================================== --- llvm/lib/Transforms/IPO/LowerTypeTests.cpp +++ llvm/lib/Transforms/IPO/LowerTypeTests.cpp @@ -1512,14 +1512,18 @@ FunctionType::get(Type::getVoidTy(M.getContext()), false), GlobalVariable::ExternalLinkage, FunctionName, &M); - if (Linkage == CFL_Definition) - F->eraseMetadata(LLVMContext::MD_type); + if (F->hasAvailableExternallyLinkage()) { + F->setLinkage(GlobalValue::ExternalLinkage); + F->deleteBody(); + F->setComdat(nullptr); + F->clearMetadata(); + } if (F->isDeclaration()) { if (Linkage == CFL_WeakDeclaration) F->setLinkage(GlobalValue::ExternalWeakLinkage); - SmallVector Types; + F->eraseMetadata(LLVMContext::MD_type); for (unsigned I = 2; I < FuncMD->getNumOperands(); ++I) F->addMetadata(LLVMContext::MD_type, *cast(FuncMD->getOperand(I).get())); Index: llvm/test/Transforms/LowerTypeTests/export-icall.ll =================================================================== --- llvm/test/Transforms/LowerTypeTests/export-icall.ll +++ llvm/test/Transforms/LowerTypeTests/export-icall.ll @@ -9,8 +9,11 @@ } declare !type !8 void @f(i32 %x) +define available_externally void @f2(i32 %x) !type !8 { + ret void +} -!cfi.functions = !{!0, !1, !3, !4, !5, !6} +!cfi.functions = !{!0, !1, !3, !9, !4, !5, !6} ; declaration of @h with a different type is ignored !0 = !{!"h", i8 1, !7} @@ -19,8 +22,9 @@ !1 = !{!"h", i8 2, !8} !2 = !{i64 0, !"typeid1"} -; definition of @f replaces types on the IR declaration above +; definitions of @f and @f2 replace types on the IR declarations above !3 = !{!"f", i8 0, !2} +!9 = !{!"f2", i8 0, !2} !4 = !{!"external", i8 1, !2} !5 = !{!"external_weak", i8 2, !2} !6 = !{!"g", i8 0, !7} @@ -30,10 +34,11 @@ ; CHECK-DAG: @__typeid_typeid1_global_addr = hidden alias i8, bitcast (void ()* [[JT1:.*]] to i8*) ; CHECK-DAG: @__typeid_typeid1_align = hidden alias i8, inttoptr (i8 3 to i8*) -; CHECK-DAG: @__typeid_typeid1_size_m1 = hidden alias i8, inttoptr (i64 3 to i8*) +; CHECK-DAG: @__typeid_typeid1_size_m1 = hidden alias i8, inttoptr (i64 4 to i8*) ; CHECK-DAG: @h = alias void (i8), bitcast (void ()* [[JT1]] to void (i8)*) ; CHECK-DAG: @f = alias void (i32), {{.*}}getelementptr {{.*}}void ()* [[JT1]] +; CHECK-DAG: @f2 = alias void (i32), {{.*}}getelementptr {{.*}}void ()* [[JT1]] ; CHECK-DAG: @external.cfi_jt = hidden alias void (), {{.*}}getelementptr {{.*}}void ()* [[JT1]] ; CHECK-DAG: @external_weak.cfi_jt = hidden alias void (), {{.*}}getelementptr {{.*}}void ()* [[JT1]] @@ -45,6 +50,7 @@ ; CHECK-DAG: declare !type !{{.*}} void @external() ; CHECK-DAG: declare !type !{{.*}} void @external_weak() ; CHECK-DAG: declare !type !{{.*}} void @f.cfi(i32) +; CHECK-DAG: declare !type !{{.*}} void @f2.cfi(i32) ; CHECK-DAG: declare !type !{{.*}} void @g.cfi() @@ -62,6 +68,7 @@ ; SUMMARY: CfiFunctionDefs: ; SUMMARY-NEXT: - f +; SUMMARY-NEXT: - f2 ; SUMMARY-NEXT: - g ; SUMMARY-NEXT: - h ; SUMMARY-NEXT: CfiFunctionDecls: