<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:"trebuchet ms",sans-serif">I am bit confused - `unit` must be present for definitions, and `<span style="font-family:Arial,Helvetica,sans-serif">optimized</span><span style="font-family:Arial,Helvetica,sans-serif"> ` is also a `definition`, so, `unit` must be present for </span><span style="font-family:Arial,Helvetica,sans-serif">`</span><span style="font-family:Arial,Helvetica,sans-serif">optimized</span><span style="font-family:Arial,Helvetica,sans-serif"> ` too. Am I right? </span></div><div class="gmail_default" style="font-family:"trebuchet ms",sans-serif"><span style="font-family:Arial,Helvetica,sans-serif"><br></span></div><div class="gmail_default" style="font-family:"trebuchet ms",sans-serif"><span style="font-family:Arial,Helvetica,sans-serif">Mahesha</span></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, May 31, 2020 at 10:14 PM David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">definition and optimized are orthogonal (a function could be both, or<br>
neither) - one says this DISubprogram describes a function definition<br>
(rather than a declaration) and the other says this function has been<br>
compiled (so I suppose it must be a definition - though we may not<br>
rely on/verify that/need that to be true at the moment).<br>
<br>
Sounds like you're saying the verifier does check the constraint<br>
you're interested in (ie: you only hit the assert in<br>
lib/CodeGen/LexicalScopes if the code is in violation of the<br>
verifier?) - and the verification check sounds correct/reasonable to<br>
me. (declarations are owned by the unit - whereas definitions are<br>
intentionally owned by the llvm::Function and refer to the unit they<br>
are within so they can be implicitly dropped if the Function is<br>
dropped - so, yes, the unit must be present for definitions and must<br>
not be present for non-definitions).<br>
<br>
On Sun, May 31, 2020 at 2:53 AM Mahesha S <<a href="mailto:mahesha.comp@gmail.com" target="_blank">mahesha.comp@gmail.com</a>> wrote:<br>
><br>
> Hi David<br>
><br>
> If you look at line <a href="https://github.com/llvm/llvm-project/blob/master/llvm/lib/IR/Verifier.cpp#L1160" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/blob/master/llvm/lib/IR/Verifier.cpp#L1160</a> there is IR verification which asserts that only in case of `spFlags = DISPFlagDefinition`, the compilation unit (`unit` field) should be present. Otherwise, it should *not* be present. In the crash case, `spFlags = DISPFlagOptimized`. So, I guess, `unit` field should *not* be present, though I do not know the difference between ` DISPFlagDefinition` and ` DISPFlagOptimized`. if that is expected, then we may need to check `nullity` of `DISubprogram::getUnit()` before accessing it at <a href="https://github.com/llvm/llvm-project/blob/master/llvm/lib/CodeGen/LexicalScopes.cpp#L53" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/blob/master/llvm/lib/CodeGen/LexicalScopes.cpp#L53</a><br>
><br>
> Thanks,<br>
> Mahesha<br>
><br>
> On Sun, May 31, 2020 at 11:26 AM David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br>
>><br>
>> In theory the LLVM IR verifier (llvm/lib/IR/Verifier.cpp) should catch<br>
>> this sort of thing. Maybe it isn't running in llc? It probably should<br>
>> be. It's also likely not exhaustive to completely arbitrary changes to<br>
>> the debug info IR - but could be improved if there are particular<br>
>> things folks come across/want to sure it up against.<br>
>><br>
>> On Sat, May 30, 2020 at 10:27 PM Mahesha S via llvm-dev<br>
>> <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
>> ><br>
>> > Hi-<br>
>> ><br>
>> > Here is the simple C++ function:<br>
>> ><br>
>> > -----------<br>
>> > void foo() {<br>
>> > }<br>
>> > -----------<br>
>> ><br>
>> > Let's say, above function is compiled to generate LLVM IR with -g flag<br>
>> > using the command line `clang++ -g -O0 -S -emit-llvm foo.cpp`, we get<br>
>> > below IR<br>
>> ><br>
>> > -----------<br>
>> > ; ModuleID = 'foo.cpp'<br>
>> > source_filename = "foo.cpp"<br>
>> > target datalayout =<br>
>> > "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"<br>
>> > target triple = "x86_64-unknown-linux-gnu"<br>
>> ><br>
>> > ; Function Attrs: noinline nounwind optnone uwtable<br>
>> > define dso_local void @_Z3foov() #0 !dbg !7 {<br>
>> > ret void, !dbg !10<br>
>> > }<br>
>> ><br>
>> > attributes #0 = { noinline nounwind optnone uwtable<br>
>> > "correctly-rounded-divide-sqrt-fp-math"="false"<br>
>> > "disable-tail-calls"="false" "frame-pointer"="all"<br>
>> > "less-precise-fpmad"="false" "min-legal-vector-width"="0"<br>
>> > "no-infs-fp-math"="false" "no-jump-tables"="false"<br>
>> > "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false"<br>
>> > "no-trapping-math"="false" "stack-protector-buffer-size"="8"<br>
>> > "target-cpu"="x86-64"<br>
>> > "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87"<br>
>> > "unsafe-fp-math"="false" "use-soft-float"="false" }<br>
>> ><br>
>> > !<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!0}<br>
>> > !llvm.module.flags = !{!3, !4, !5}<br>
>> > !llvm.ident = !{!6}<br>
>> ><br>
>> > !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file:<br>
>> > !1, producer: "clang version 11.0.0<br>
>> > (<a href="https://github.com/llvm/llvm-project" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project</a><br>
>> > 9e0b52e2e68412a9a2add18697f4246e5e5ee5e3)", isOptimized: false,<br>
>> > runtimeVersion: 0, emissionKind: FullDebug, enums: !2,<br>
>> > splitDebugInlining: false, nameTableKind: None)<br>
>> > !1 = !DIFile(filename: "foo.cpp", directory:<br>
>> > "/home/mahesha/ROCm/issues/hipclang/other/crash/foo")<br>
>> > !2 = !{}<br>
>> > !3 = !{i32 7, !"Dwarf Version", i32 4}<br>
>> > !4 = !{i32 2, !"Debug Info Version", i32 3}<br>
>> > !5 = !{i32 1, !"wchar_size", i32 4}<br>
>> > !6 = !{!"clang version 11.0.0 (<a href="https://github.com/llvm/llvm-project" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project</a><br>
>> > 9e0b52e2e68412a9a2add18697f4246e5e5ee5e3)"}<br>
>> > !7 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov",<br>
>> > scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags:<br>
>> > DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0,<br>
>> > retainedNodes: !2)<br>
>> > !8 = !DISubroutineType(types: !9)<br>
>> > !9 = !{null}<br>
>> > !10 = !DILocation(line: 2, column: 1, scope: !7)<br>
>> > -----------<br>
>> ><br>
>> > Now, let's say, in the above IR file, I intentionally make debug info<br>
>> > metadata, a kind of invalid, by removing the field 'unit` and by<br>
>> > changing the field `spFlags` from `DISPFlagDefinition` to<br>
>> > `DISPFlagOptimized` within metadata info !7 as shown below.<br>
>> ><br>
>> > -----------<br>
>> > ; ModuleID = 'foo.cpp'<br>
>> > source_filename = "foo.cpp"<br>
>> > target datalayout =<br>
>> > "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"<br>
>> > target triple = "x86_64-unknown-linux-gnu"<br>
>> ><br>
>> > ; Function Attrs: noinline nounwind optnone uwtable<br>
>> > define dso_local void @_Z3foov() #0 !dbg !7 {<br>
>> > ret void<br>
>> > }<br>
>> ><br>
>> > attributes #0 = { noinline nounwind optnone uwtable<br>
>> > "correctly-rounded-divide-sqrt-fp-math"="false"<br>
>> > "disable-tail-calls"="false" "frame-pointer"="all"<br>
>> > "less-precise-fpmad"="false" "min-legal-vector-width"="0"<br>
>> > "no-infs-fp-math"="false" "no-jump-tables"="false"<br>
>> > "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false"<br>
>> > "no-trapping-math"="false" "stack-protector-buffer-size"="8"<br>
>> > "target-cpu"="x86-64"<br>
>> > "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87"<br>
>> > "unsafe-fp-math"="false" "use-soft-float"="false" }<br>
>> ><br>
>> > !<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!0}<br>
>> > !llvm.module.flags = !{!3, !4, !5}<br>
>> > !llvm.ident = !{!6}<br>
>> ><br>
>> > !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file:<br>
>> > !1, producer: "clang version 11.0.0<br>
>> > (<a href="https://github.com/llvm/llvm-project" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project</a><br>
>> > 9e0b52e2e68412a9a2add18697f4246e5e5ee5e3)", isOptimized: false,<br>
>> > runtimeVersion: 0, emissionKind: FullDebug, enums: !2,<br>
>> > splitDebugInlining: false, nameTableKind: None)<br>
>> > !1 = !DIFile(filename: "foo.cpp", directory:<br>
>> > "/home/mahesha/ROCm/issues/hipclang/other/crash/foo")<br>
>> > !2 = !{}<br>
>> > !3 = !{i32 7, !"Dwarf Version", i32 4}<br>
>> > !4 = !{i32 2, !"Debug Info Version", i32 3}<br>
>> > !5 = !{i32 1, !"wchar_size", i32 4}<br>
>> > !6 = !{!"clang version 11.0.0 (<a href="https://github.com/llvm/llvm-project" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project</a><br>
>> > 9e0b52e2e68412a9a2add18697f4246e5e5ee5e3)"}<br>
>> > !7 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov",<br>
>> > scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags:<br>
>> > DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2)<br>
>> > !8 = !DISubroutineType(types: !9)<br>
>> > !9 = !{null}<br>
>> > !10 = !DILocation(line: 2, column: 1, scope: !7)<br>
>> > -----------<br>
>> ><br>
>> > Now, if I compile the above modified IR file using LLC, then LLC<br>
>> > crashes as below. The crash point is<br>
>> > <a href="https://github.com/llvm/llvm-project/blob/master/llvm/lib/CodeGen/LexicalScopes.cpp#L53" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/blob/master/llvm/lib/CodeGen/LexicalScopes.cpp#L53</a>.<br>
>> > Reason for crash is `NULL` pointer access. `DISubprogram::getUnit()`<br>
>> > returns `NULL` pointer since there is no `unit` field in the related<br>
>> > metadata info.<br>
>> ><br>
>> > -----------<br>
>> > PLEASE submit a bug report to <a href="https://bugs.llvm.org/" rel="noreferrer" target="_blank">https://bugs.llvm.org/</a> and include the<br>
>> > crash backtrace.<br>
>> > Stack dump:<br>
>> > 0. Program arguments: /opt/rocm/llvm/bin/llc foo.ll<br>
>> > 1. Running pass 'Function Pass Manager' on module 'foo.ll'.<br>
>> > 2. Running pass 'Debug Variable Analysis' on function '@_Z3foov'<br>
>> > #0 0x0000556017a2aa8a llvm::sys::PrintStackTrace(llvm::raw_ostream&)<br>
>> > (/opt/rocm/llvm/bin/llc+0x1883a8a)<br>
>> > #1 0x0000556017a28854 llvm::sys::RunSignalHandlers()<br>
>> > (/opt/rocm/llvm/bin/llc+0x1881854)<br>
>> > #2 0x0000556017a289a3 SignalHandler(int) (/opt/rocm/llvm/bin/llc+0x18819a3)<br>
>> > #3 0x00007fdb38654890 __restore_rt<br>
>> > (/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)<br>
>> > #4 0x0000556016f013ea<br>
>> > llvm::LexicalScopes::initialize(llvm::MachineFunction const&)<br>
>> > (/opt/rocm/llvm/bin/llc+0xd5a3ea)<br>
>> > #5 0x0000556016f224dd<br>
>> > llvm::LiveDebugVariables::runOnMachineFunction(llvm::MachineFunction&)<br>
>> > (/opt/rocm/llvm/bin/llc+0xd7b4dd)<br>
>> > #6 0x0000556016fcb2b0<br>
>> > llvm::MachineFunctionPass::runOnFunction(llvm::Function&)<br>
>> > (/opt/rocm/llvm/bin/llc+0xe242b0)<br>
>> > #7 0x0000556017375e8f<br>
>> > llvm::FPPassManager::runOnFunction(llvm::Function&)<br>
>> > (/opt/rocm/llvm/bin/llc+0x11cee8f)<br>
>> > #8 0x0000556017376581 llvm::FPPassManager::runOnModule(llvm::Module&)<br>
>> > (/opt/rocm/llvm/bin/llc+0x11cf581)<br>
>> > #9 0x0000556017376981<br>
>> > llvm::legacy::PassManagerImpl::run(llvm::Module&)<br>
>> > (/opt/rocm/llvm/bin/llc+0x11cf981)<br>
>> > #10 0x000055601662496a main (/opt/rocm/llvm/bin/llc+0x47d96a)<br>
>> > #11 0x00007fdb372e8b97 __libc_start_main<br>
>> > /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:344:0<br>
>> > #12 0x000055601668f2ea _start (/opt/rocm/llvm/bin/llc+0x4e82ea)<br>
>> > -----------<br>
>> ><br>
>> > QUESTION IS: Is this expected behavior? OR should LLC throw an error<br>
>> > and abort compilation? OR at the crash point, we are suppose to test<br>
>> > `nullity` of `DISubprogram::getUnit()` before accessing it?<br>
>> ><br>
>> > --<br>
>> > Thanks,<br>
>> > Mahesha<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
><br>
><br>
><br>
> --<br>
> Thanks,<br>
> Mahesha<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><font face="trebuchet ms, sans-serif">Thanks,</font><div><font face="trebuchet ms, sans-serif">Mahesha</font></div></div></div></div>