<div dir="ltr">Hi Teresa<div><br></div><div>I file a bug here. <a href="https://bugs.llvm.org/show_bug.cgi?id=38372">https://bugs.llvm.org/show_bug.cgi?id=38372</a></div><div><br></div><div>Thanks </div><div>-Xin</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jul 30, 2018 at 9:18 AM Teresa Johnson <<a href="mailto:tejohnson@google.com">tejohnson@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I took a quick look and it looks like the declare of @b is fine, but the call in @a is using a different type (the "type opaque"). I dumped the module at the point of the failure, shown below. This was with the change of !9 in a.ll to be a class type.<div><br></div><div>Xin - can you file a bug and cc me on it and also reply here with the bug number? I am traveling all this week and next and likely won't have a chance to look more until afterwards. Hopefully someone else can take a look in the meantime.</div><div><br></div><div>Teresa</div><div><br></div><div><div>; ModuleID = 'ld-temp.o'</div><div>source_filename = "ld-temp.o"</div><div>target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"</div><div>target triple = "x86_64-unknown-linux-gnu"</div><div><br></div><div>%0 = type opaque</div><div>%struct.TA = type {}</div><div><br></div><div>@gv = external dso_local global %struct.TA*</div><div><br></div><div>define i32 @c() !dbg !13 {</div><div>  %1 = bitcast %struct.TA** @gv to i8*</div><div>  unreachable</div><div>}</div><div><br></div><div>declare i1 @b(%struct.TA*)</div><div><br></div><div>define i1 @a(%struct.TA*) {</div><div>  %2 = call i1 bitcast (i1 (%struct.TA*)* @b to i1 (%0*)*)(%struct.TA* %0)</div><div>  unreachable</div><div>}</div><div><br></div><div>!<a href="http://llvm.dbg.cu" target="_blank">llvm.dbg.cu</a> = !{!0, !6}</div><div>!llvm.module.flags = !{!11, !12}</div><div><br></div><div>!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug, retainedTypes: !2)</div><div>!1 = !DIFile(filename: "f2", directory: "")</div><div>!2 = !{!3}</div><div>!3 = distinct !DICompositeType(tag: DW_TAG_class_type, scope: !5, file: !4, identifier: "SHARED")</div><div>!4 = !DIFile(filename: "f1", directory: "")</div><div>!5 = distinct !DISubprogram(scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !6)</div><div>!6 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !4, isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug, retainedTypes: !7)</div><div>!7 = !{!8, !3}</div><div>!8 = !DICompositeType(tag: DW_TAG_class_type, scope: !5, file: !4, templateParams: !9)</div><div>!9 = !{!10}</div><div>!10 = !DITemplateValueParameter(value: i1 (%0*)* bitcast (i1 (%struct.TA*)* @b to i1 (%0*)*))</div><div>!11 = !{i32 2, !"Debug Info Version", i32 3}</div><div>!12 = !{i32 1, !"ThinLTO", i32 0}</div><div>!13 = distinct !DISubprogram(scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !0)</div></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jul 30, 2018 at 7:06 AM Xin Tong via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, Jul 30, 2018 at 6:52 AM <<a href="mailto:paul.robinson@sony.com" target="_blank">paul.robinson@sony.com</a>> wrote:<br>
><br>
><br>
><br>
> > -----Original Message-----<br>
> > From: llvm-dev [mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>] On Behalf Of Xin<br>
> > Tong via llvm-dev<br>
> > Sent: Friday, July 27, 2018 9:33 PM<br>
> > To: llvm-dev<br>
> > Subject: [llvm-dev] ThinLTO Bug ?<br>
> ><br>
> > Hi<br>
> ><br>
> > I have encountered a module verification failure when running 2 files<br>
> > with thin-lto (I hit this bug in the link step in LTO on a really<br>
> > large program and I reduced to this test case).<br>
> ><br>
> ><br>
> > ~/llvmfb/build-debug/bin/llvm-lto2 run -o c a.o  b.o -r a.o,c,px  -r<br>
> > b.o,a,px -r b.o,b,px  -r a.o,gv -r b.o,gv<br>
> > Called function is not the same type as the call!<br>
> > %2 = call i1 bitcast (i1 (%struct.TA*)* @b to i1 (%0*)*)(%struct.TA* %0)<br>
> > in function a<br>
> > LLVM ERROR: Broken function found, compilation aborted!<br>
> ><br>
> ><br>
> > My understanding why this is happening is roughly as follow. I would<br>
> > like to check with people whether this is a real bug. And also would<br>
> > like to help fixing it with other people’s help if it’s a real bug. I<br>
> > am quite new to this part of LLVM.<br>
> ><br>
> > 1. DICompositeType “SHARED” in a.ll is ODRed with the one in b.ll at load<br>
> > time.<br>
><br>
> I know relatively little about LTO but I see that in a.ll, "SHARED" is<br>
> described as a DW_TAG_class_type while in b.ll it is DW_TAG_array_type.<br>
> This suggests that you have an ODR violation in your source code.<br>
><br>
Hi Paul<br>
<br>
Thanks for pointing it out.<br>
I fixed this by making in b.ll and the same failure persists.<br>
!9 = !DICompositeType(tag: DW_TAG_class_type, file: !3, identifier:<br>
"SHARED", scope: !8)<br>
<br>
-Xin<br>
<br>
<br>
> ODR violations in LTO tend to exhibit as a "broken module" or "broken<br>
> function" at link time.  It would be nice to diagnose these better,<br>
> admittedly.<br>
> --paulr<br>
><br>
> > 2. %struct.TA.0 (renamed from %struct.TA at load time) = type opaque<br>
> > and i1 (%struct.TA.0*)* @b  in b.ll gets pulled into the destination<br>
> > module when we are merging in a.ll.<br>
> > 3. We only found out that %struct.TA.0 maps to %struct.TA when we link<br>
> > in b.ll because of the @gv global variable.<br>
> > 4. Then we have a problem, because declare i1 @b(%struct.TA.0*) in<br>
> > a.ll should have been remapped due to what we found in #3, but was<br>
> > not.  This eventually leads to the IR verifier failure.<br>
> ><br>
> > Thanks<br>
> > -Xin<br>
> ><br>
> ><br>
> > Commands to reproduce with ToT LLVM:<br>
> > ===============================<br>
> ><br>
> > ~/llvm/build-debug/bin/opt -module-summary -o a.o a.ll<br>
> > ~/llvm/build-debug/bin/opt -module-summary -o b.o b.ll<br>
> > ~/llvm/build-debug/bin/llvm-lto2 run -o c a.o b.o -r a.o,c,px -r<br>
> > b.o,a,px -r b.o,b,px -r a.o,gv -r b.o,gv<br>
> ><br>
> ><br>
> ><br>
> > [~/thinltobug]$ cat a.ll<br>
> ><br>
> > target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"<br>
> ><br>
> > target triple = "x86_64-unknown-linux-gnu"<br>
> ><br>
> > %struct.TA = type {}<br>
> ><br>
> ><br>
> ><br>
> > @gv = dso_local global %struct.TA * zeroinitializer<br>
> ><br>
> > define i32 @c() !dbg !6 {<br>
> ><br>
> >   bitcast %struct.TA ** @gv to i8*<br>
> ><br>
> >   unreachable<br>
> ><br>
> > }<br>
> ><br>
> ><br>
> ><br>
> ><br>
> ><br>
> > !llvm.module.flags = !{!0, !1}<br>
> ><br>
> > !<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!2}<br>
> ><br>
> > !0 = !{i32 2, !"Debug Info Version", i32 3}<br>
> ><br>
> > !1 = !{i32 1, !"ThinLTO", i32 0}<br>
> ><br>
> > !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3,<br>
> > retainedTypes: !4)<br>
> ><br>
> > !3 = !DIFile(filename: "f2", directory: "")<br>
> ><br>
> > !4 = !{!5}<br>
> ><br>
> > !5 = !DICompositeType(tag: DW_TAG_class_type, file: !3, flags:<br>
> > DIFlagFwdDecl, identifier: "SHARED")<br>
> ><br>
> > !6 = distinct !DISubprogram(unit: !2)<br>
> ><br>
> ><br>
> ><br>
> > [~/thinltobug]$ cat b.ll<br>
> ><br>
> > target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"<br>
> ><br>
> > target triple = "x86_64-unknown-linux-gnu"<br>
> ><br>
> ><br>
> ><br>
> > %struct.TA = type opaque<br>
> ><br>
> ><br>
> ><br>
> > @gv = external dso_local global %struct.TA *<br>
> ><br>
> ><br>
> ><br>
> > define i1 @b(%struct.TA*) {<br>
> ><br>
> >   unreachable<br>
> ><br>
> > }<br>
> ><br>
> ><br>
> ><br>
> > define i1 @a(%struct.TA* %a) {<br>
> ><br>
> >   call i1 @b(%struct.TA* %a)<br>
> ><br>
> >   unreachable<br>
> ><br>
> > }<br>
> ><br>
> ><br>
> ><br>
> > !llvm.module.flags = !{!0, !1}<br>
> ><br>
> > !<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!2}<br>
> ><br>
> > !0 = !{i32 2, !"Debug Info Version", i32 3}<br>
> ><br>
> > !1 = !{i32 1, !"ThinLTO", i32 0}<br>
> ><br>
> > !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3,<br>
> > retainedTypes: !4)<br>
> ><br>
> > !3 = !DIFile(filename: "f1", directory: "")<br>
> ><br>
> > !4 = !{!5, !9}<br>
> ><br>
> > !5 = !DICompositeType(tag: DW_TAG_class_type, file: !3,<br>
> > templateParams: !6, scope: !8)<br>
> ><br>
> > !6 = !{!7}<br>
> ><br>
> ><br>
> ><br>
> > ; The reference to @b and struct.TA.0 (renamed)  that will be loaded in<br>
> > %a.o<br>
> ><br>
> ><br>
> ><br>
> > !7 = !DITemplateValueParameter(value: i1 (%struct.TA*)* @b)<br>
> ><br>
> > !8 = distinct !DISubprogram(unit: !2)<br>
> ><br>
> ><br>
> ><br>
> > !9 = !DICompositeType(tag: DW_TAG_array_type, identifier: "SHARED", scope:<br>
> > !8)<br>
> > _______________________________________________<br>
> > LLVM Developers mailing list<br>
> > <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
> > <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="m_-5769990478634412512gmail_signature" data-smartmail="gmail_signature"><span style="font-family:Times;font-size:medium"><table cellspacing="0" cellpadding="0"><tbody><tr style="color:rgb(85,85,85);font-family:sans-serif;font-size:small"><td style="border-top-style:solid;border-top-color:rgb(213,15,37);border-top-width:2px">Teresa Johnson |</td><td style="border-top-style:solid;border-top-color:rgb(51,105,232);border-top-width:2px"> Software Engineer |</td><td style="border-top-style:solid;border-top-color:rgb(0,153,57);border-top-width:2px"> <a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a> |</td><td style="border-top-style:solid;border-top-color:rgb(238,178,17);border-top-width:2px"> 408-460-2413</td></tr></tbody></table></span></div>
</blockquote></div>