<div dir="ltr">The CompileUnit is not supposed to be duplicated on master: <a href="https://github.com/llvm-mirror/llvm/blob/e3e43d9d574cf0a829e9a58525372ba0868a3292/lib/Transforms/Utils/CloneFunction.cpp#L129-L141">https://github.com/llvm-mirror/llvm/blob/e3e43d9d574cf0a829e9a58525372ba0868a3292/lib/Transforms/Utils/CloneFunction.cpp#L129-L141</a>. Is there no subprogram attached to your function, but somehow the CU is referenced anyway?</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 15, 2017 at 6:24 PM, Adrian Prantl <span dir="ltr"><<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Can you send me a patch with instructions to reproduce? I can take a look.<span class="HOEnZb"><font color="#888888"><div><br></div></font></span><div><span class="HOEnZb"><font color="#888888">-- adrian</font></span><div><div class="h5"><br><div><blockquote type="cite"><div>On Jun 15, 2017, at 2:23 PM, Sergei Larin <<a href="mailto:slarin@codeaurora.org" target="_blank">slarin@codeaurora.org</a>> wrote:</div><br class="m_-2106187463680274044Apple-interchange-newline"><div><div class="m_-2106187463680274044WordSection1" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif">Yes, it does for us. My tree is couple days off the tip, and I see it there.<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif">Sergei<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><b><span style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span style="font-size:11pt;font-family:Calibri,sans-serif"><span class="m_-2106187463680274044Apple-converted-space"> </span>llvm-dev [<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">mailto:llvm-dev-bounces@<wbr>lists.llvm.org</a>]<span class="m_-2106187463680274044Apple-converted-space"> </span><b>On Behalf Of<span class="m_-2106187463680274044Apple-converted-space"> </span></b>Keno Fischer via llvm-dev<br><b>Sent:</b><span class="m_-2106187463680274044Apple-converted-space"> </span>Thursday, June 15, 2017 1:25 PM<br><b>To:</b><span class="m_-2106187463680274044Apple-converted-space"> </span>Adrian Prantl <<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>><br><b>Cc:</b><span class="m_-2106187463680274044Apple-converted-space"> </span>llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br><b>Subject:</b><span class="m_-2106187463680274044Apple-converted-space"> </span>Re: [llvm-dev] CloneFunctionInto produces invalid debug info<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">This all looks very similar to a bug in the cloning stuff I fixed recently, so would be indeed good to know if this is still happening on master.<u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">On Thu, Jun 15, 2017 at 2:23 PM, Adrian Prantl via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" style="color:purple;text-decoration:underline" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></div><blockquote style="border-style:none none none solid;border-left-width:1pt;border-left-color:rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in" type="cite"><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">If you are doing this work based off LLVM trunk, could you send me your patch to reproduce the problem?<u></u><u></u></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">-- adrian<u></u><u></u></div><div><blockquote style="margin-top:5pt;margin-bottom:5pt" type="cite"><div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">On Jun 15, 2017, at 8:31 AM, Matthias Bernad via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" style="color:purple;text-decoration:underline" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></div></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div></div><div><div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">Hi!<u></u><u></u></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">We are currently working on a science project and implemented a FunctionPass that clones a function (more precisely a constructor of a struct/class) and adds a parameter.<u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">First, we create a new function with a new function type, which includes the newly added parameter:<u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><blockquote style="margin-left:30pt;margin-right:0in" type="cite"><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">Function *NF = Function::Create(NewFTy, F.getLinkage(), F.getName() + "Cloned", F.getParent());<u></u><u></u></div></div></blockquote><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">and after setting up the ValueToValueMapTy, we use the CloneFunctionInto method to clone the function body<u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><blockquote style="margin-left:30pt;margin-right:0in" type="cite"><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">CloneFunctionInto(NF, &F, Map, true, Returns, "Cloned");<u></u><u></u></div></div></div></blockquote><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><div><p class="MsoNormal" style="margin:0in 0in 12pt;font-size:12pt;font-family:'Times New Roman',serif">The code seems to work as intended, but when we try to emit debug symbols (clang -g flag) the pass fails with following message:<u></u><u></u></p></div><blockquote style="margin-left:30pt;margin-right:0in" type="cite"><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">"All DICompileUnits must be listed in<span class="m_-2106187463680274044Apple-converted-space"> </span><a href="http://llvm.dbg.cu/" style="color:purple;text-decoration:underline" target="_blank">llvm.dbg.cu</a>"<u></u><u></u></div></div></blockquote><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">Nevertheless, we can dump the Module and therefore can print out the annotated IR.<u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">This is what the function to be cloned looks like:<u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><blockquote style="margin-left:30pt;margin-right:0in" type="cite"><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">; Function Attrs: noinline nounwind uwtable<u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">define linkonce_odr void @_ZN12MyFunnyClassC2Ev(%<wbr>struct.MyFunnyClass* %this) unnamed_addr #4 comdat align 2 !dbg !46 {<u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">entry:<u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">  %this.addr = alloca %struct.MyFunnyClass*, align 8<u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">  store %struct.MyFunnyClass* %this, %struct.MyFunnyClass** %this.addr, align 8<u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">  call void @llvm.dbg.declare(metadata %struct.MyFunnyClass** %this.addr, metadata !49, metadata !31), !dbg !50<u></u><u></u></div></div></div></blockquote><blockquote style="margin-left:30pt;margin-right:0in" type="cite"><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">... rest of function code<u></u><u></u></div></div></div></blockquote><blockquote style="margin-left:30pt;margin-right:0in" type="cite"><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">}<u></u><u></u></div></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">!46 = distinct !DISubprogram(name: "MyFunnyClass", linkageName: "_ZN12MyFunnyClassC2Ev", scope: !15, file: !1, line: 1, type: !25, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagArtificial | DIFlagPrototyped, isOptimized: false, unit: !0, declaration: !47, variables: !2)<u></u><u></u></div></div></div></blockquote><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">and the cloned function:<u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><blockquote style="margin-left:30pt;margin-right:0in" type="cite"><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">; Function Attrs: noinline nounwind uwtable<u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">define linkonce_odr void @_ZN12MyFunnyClassC2EvCloned(%<wbr>struct.MyFunnyClass* %this, { [6 x i8*] }* %newparam) unnamed_addr #4 align 2 !dbg !73 {<u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">entry:<u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">  %this.addr = alloca %struct.MyFunnyClass*, align 8<u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">  store %struct.MyFunnyClass* %this, %struct.MyFunnyClass** %this.addr, align 8<u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">  call void @llvm.dbg.declare(metadata %struct.MyFunnyClass** %this.addr, metadata !89, metadata !31), !dbg !91<u></u><u></u></div></div></div></blockquote><blockquote style="margin-left:30pt;margin-right:0in" type="cite"><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">... rest of function code<u></u><u></u></div></div></div></blockquote><blockquote style="margin-left:30pt;margin-right:0in" type="cite"><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">}<u></u><u></u></div></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">!73 = distinct !DISubprogram(name: "MyFunnyClass", linkageName: "_ZN12MyFunnyClassC2Ev", scope: !74, file: !1, line: 1, type: !81, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagArtificial | DIFlagPrototyped, isOptimized: false, unit: !87, declaration: !88, variables: !2)<u></u><u></u></div></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div></blockquote><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">So the cloned function gets annotated with debug symbols as expected. We noticed that the linkageName of the cloned function is the same as the original one's. Could that cause the error mentioned above? If so, how can we fix that error?<u></u><u></u></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">Best regards and thanks in advance,<u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">Matthias<u></u><u></u></div></div></div></div></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">______________________________<wbr>_________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" style="color:purple;text-decoration:underline" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" style="color:purple;text-decoration:underline" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><u></u><u></u></div></div></blockquote></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div></div><p class="MsoNormal" style="margin:0in 0in 12pt;font-size:12pt;font-family:'Times New Roman',serif"><br>______________________________<wbr>_________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" style="color:purple;text-decoration:underline" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" style="color:purple;text-decoration:underline" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a></p></blockquote></div></div></div></div></blockquote></div><br></div></div></div></div></blockquote></div><br></div>