<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Lowering loses information about debug variable assignment."
   href="https://bugs.llvm.org/show_bug.cgi?id=39896">39896</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Lowering loses information about debug variable assignment.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Keywords</th>
          <td>wrong-debug
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>DebugInfo
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>davide@freebsd.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>carlos.alberto.enciso@gmail.com, greg.bedwell@sony.com, jdevlieghere@apple.com, jeremy.morse.llvm@gmail.com, keith.walker@arm.com, llvm-bugs@lists.llvm.org, paul_robinson@playstation.sony.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=21196" name="attach_21196" title="testcase">attachment 21196</a> <a href="attachment.cgi?id=21196&action=edit" title="testcase">[details]</a></span>
testcase

The following IR debug instruction/metadata (please see attachment for the full
file):

@a = global i8 25, align 1, !dbg !0

; Function Attrs: nounwind ssp uwtable
define signext i16 @b() #0 !dbg !12 {
entry:
  call void @llvm.dbg.value(metadata i16 23680, metadata !17, metadata
!DIExpression()), !dbg !18
  %0 = load i8, i8* @a, align 1, !dbg !19, !tbaa !20
  %conv = sext i8 %0 to i16, !dbg !19
  call void @llvm.dbg.value(metadata i16 %conv, metadata !17, metadata
!DIExpression()), !dbg !18
  %call = call i32 (...) @optimize_me_not(), !dbg !23
  %1 = load i8, i8* @a, align 1, !dbg !24, !tbaa !20
  %conv1 = sext i8 %1 to i16, !dbg !24
  ret i16 %conv1, !dbg !25
}


Gets lowered into:

$ ./llc -filetype=obj ./baciotto.ll -o Palatino
$ dwarfdump ./patatino

[…]

0x00000046:     TAG_subprogram [4] *
                 AT_low_pc( 0x0000000000000000 )
                 AT_high_pc( 0x00000014 )
                 AT_frame_base( rbp )
                Unknown DW_AT constant: 0x7a( true )
                 AT_name( "b" )
                 AT_decl_file( "/Users/dcci/work/llvm/build-debug/bin/run.c" )
                 AT_decl_line( 2 )
                 AT_type( {0x00000095} ( short ) )
                 AT_external( true )
                 AT_APPLE_optimized( true )

0x0000005f:         TAG_variable [5]  
                     AT_const_value( 0x0000000000005c80 )
                     AT_name( "i" )
                     AT_decl_file(
"/Users/dcci/work/llvm/build-debug/bin/run.c" )
                     AT_decl_line( 3 )
                     AT_type( {0x00000095} ( short ) )

0x0000006d:         NULL

Somehow, somewhere in the backend or in MC we loose track that the variable
gets reassigned to the value loaded from the global @a. This degrades the debug
info quality, printing the wrong value.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>