https://bugs.llvm.org/show_bug.cgi?id=41885

            Bug ID: 41885
           Summary: Variable with end part that is optimized out is
                    printed incorrectly
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: DebugInfo
          Assignee: unassignedb...@nondot.org
          Reporter: david.stenb...@ericsson.com
                CC: jdevliegh...@apple.com, keith.wal...@arm.com,
                    llvm-bugs@lists.llvm.org,
                    paul_robin...@playstation.sony.com

When compiling the following example:

  extern int ext;
  volatile int global;

  int main() {
    int arr[32] = {123};
    global = arr[0];
    arr[0] = ext;
    return 0;
  }

with Clang (trunk) respectively GCC (8.3.0), you get different location
information about the optimized out elements at the end of arr:

  $ clang -O3 -g opt-end.c -o clang.out
  $ llvm-dwarfdump clang.out | grep -B2 -P "DW_AT_name.*arr"
                  DW_AT_location        (0x00000000
                     [0x0000000000400480,  0x000000000040048a): DW_OP_constu
0x7b, DW_OP_stack_value, DW_OP_piece 0x4)
                  DW_AT_name    ("arr")

 $ gcc-8 -O3 -g -gstrict-dwarf opt-end.c -o gcc.out
 $ llvm-dwarfdump gcc.out | grep -A5 -P "DW_AT_name.*arr" | grep -vP
"DW_AT_decl|DW_AT_type"
                  DW_AT_name    ("arr")
                  DW_AT_location        (0x00000000
                     [0x00000000000004f0,  0x00000000000004fa): DW_OP_const1u
0x7b, DW_OP_stack_value, DW_OP_piece 0x4, DW_OP_piece 0x7c)

As seen, GCC emits an explicit empty location description piece which covers
the optimized out elements at the end of the array, whereas Clang does not emit
that.

This results in the elements being printed out with garbage data when debugging
the Clang binary in LLDB (7.0):

  $ lldb-7 clang.out
  (lldb) target create "clang.out"
  Current executable set to 'clang.out' (x86_64).
  (lldb) b main
  Breakpoint 1: where = clang.out`main at opt-end.c:6, address =
0x0000000000400480
  (lldb) run
  Process 22244 launched: '/home/edasten/upstream/master/clang.out' (x86_64)
  Process 22244 stopped
  * thread #1, name = 'clang.out', stop reason = breakpoint 1.1
      frame #0: 0x0000000000400480 clang.out`main at opt-end.c:6
     3          
     4          int main() {
     5            int arr[32] = {123};
  -> 6            global = arr[0];
     7            arr[0] = ext;
     8            return 0;
     9          }
  (lldb) print arr
  (int [32]) $0 = {
    [0] = 123
    [1] = 0
    [2] = -1579873760
    [3] = 32657
    [4] = 32
    [and so on...]

Also, in GDB (8.2.1) the elements are printed as <synthetic pointer> instead of
<optimized out>:

 (gdb) print arr
 $1 = {123, <synthetic pointer> <repeats 31 times>}

It is unclear to me if the producer must cover the whole variable when emitting
composite location descriptions, or if the consumers should be able to handle
that, assuming that parts that are not explicitly covered are implicitly
covered by empty location descriptions. I did not manage to find anything in
the DWARF 4 and 5 standards that mandate the former (but I may of course have
missed it).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to