1;; Test mixed D0/D2 and D5 COMDATs. Reduced from: 2;; 3;; // a.cc 4;; template <typename T> 5;; struct A final { virtual ~A() {} }; 6;; extern "C" void aa() { A<int> a; } 7;; // b.cc 8;; template <typename T> 9;; struct A final { virtual ~A() {} }; 10;; template struct A<int>; 11;; extern "C" void bb(Aptr a) { delete a; } 12;; 13;; clang -c -fpic -O0 -flto=thin a.cc && ld.lld -shared a.o b.o 14;; 15;; The file matches lld/test/ELF/lto/ctor-dtor-alias2.ll 16 17; RUN: rm -rf %t && split-file %s %t && cd %t 18 19;; a.bc defines D0 in comdat D0 and D2 in comdat D2. b.bc defines D0/D1/D2 in comdat D5. 20; RUN: opt -module-summary a.ll -o a.bc 21; RUN: opt -module-summary b.ll -o b.bc 22; RUN: llvm-lto2 run a.bc b.bc -r=a.bc,aa,px -r=a.bc,_ZN1AIiED0Ev,px -r=a.bc,_ZN1AIiED2Ev,px -r=a.bc,_ZdlPv, \ 23; RUN: -r=b.bc,bb,px -r=b.bc,_ZN1AIiED0Ev, -r=b.bc,_ZN1AIiED1Ev,px -r=b.bc,_ZN1AIiED2Ev, -r=b.bc,_ZdlPv, -o out --save-temps 24; RUN: llvm-dis < out.2.1.promote.bc | FileCheck %s 25 26;; Although D0/D2 in b.bc is non-prevailing, keep D1/D2 as definitions, otherwise 27;; the output may have an undefined and unsatisfied D1. 28; CHECK: @_ZN1AIiED1Ev = weak_odr unnamed_addr alias void (ptr), ptr @_ZN1AIiED2Ev 29; CHECK: define weak_odr void @_ZN1AIiED2Ev(ptr noundef nonnull %this) unnamed_addr comdat($_ZN1AIiED5Ev) { 30; CHECK: define available_externally void @_ZN1AIiED0Ev(ptr noundef nonnull %this) unnamed_addr { 31 32;--- a.ll 33target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 34target triple = "x86_64-unknown-linux-gnu" 35 36$_ZN1AIiED2Ev = comdat any 37 38$_ZN1AIiED0Ev = comdat any 39 40define void @aa() { 41entry: 42 %a = alloca ptr, align 8 43 call void @_ZN1AIiED2Ev(ptr noundef nonnull %a) 44 ret void 45} 46 47define linkonce_odr void @_ZN1AIiED2Ev(ptr noundef nonnull %this) unnamed_addr comdat { 48 ret void 49} 50 51define linkonce_odr void @_ZN1AIiED0Ev(ptr noundef nonnull %this) unnamed_addr comdat { 52entry: 53 call void @_ZN1AIiED2Ev(ptr noundef nonnull %this) 54 call void @_ZdlPv(ptr noundef %this) 55 ret void 56} 57 58declare void @_ZdlPv(ptr noundef) 59 60;--- b.ll 61target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 62target triple = "x86_64-unknown-linux-gnu" 63 64$_ZN1AIiED5Ev = comdat any 65 66$_ZTV1AIiE = comdat any 67 68@_ZN1AIiED1Ev = weak_odr unnamed_addr alias void (ptr), ptr @_ZN1AIiED2Ev 69 70define weak_odr void @_ZN1AIiED2Ev(ptr noundef nonnull %this) unnamed_addr comdat($_ZN1AIiED5Ev) { 71 ret void 72} 73 74define weak_odr void @_ZN1AIiED0Ev(ptr noundef nonnull %this) unnamed_addr comdat($_ZN1AIiED5Ev) { 75entry: 76 call void @_ZN1AIiED1Ev(ptr noundef nonnull %this) 77 call void @_ZdlPv(ptr noundef %this) 78 ret void 79} 80 81declare void @_ZdlPv(ptr noundef) 82 83define void @bb(ptr noundef %a) { 84entry: 85 call void @_ZN1AIiED1Ev(ptr noundef nonnull %a) 86 call void @_ZdlPv(ptr noundef %a) 87 ret void 88} 89