Issue 75460
Summary DWARF debug info for 32-bit variable has a 64-bit composite location description
Labels
Assignees
Reporter dstenb
    LLVM commit: https://github.com/llvm/llvm-project/commit/ef35da825f38a86e4621c13a2898d561da88991c

When compiling the following program:

```
volatile int a;
int b;
long c;
char d;
long long e;
void main() {
  int f = c < 6;
  long long g = f;
  d = g ^= e;
  b = 0;
  for (; b < 10; b++)
    for (; a;) // break here and print f
      for (;;)
 ;
}
```

for i386 using:

```
clang -m32 -O3 -g reduce30841.c
```

GDB 13.2 will emit an error when trying to print `f`:

```
(gdb) b 12
Breakpoint 1 at 0x11f6: file reduce30841.c, line 12.
(gdb) run
Starting program: reduce30841.out 

Breakpoint 1, main () at reduce30841.c:12
12          for (; a;)
(gdb) p f
access outside bounds of object referenced via synthetic pointer
```

The `DW_AT_location` in question looks like:

```
0x0000008a:     DW_TAG_variable
 DW_AT_location        (indexed (0x1) loclist = 0x00000025: 
 [0x000011e8, 0x000011ee): DW_OP_reg1 ECX, DW_OP_piece 0x4
 [0x000011f6, 0x00001204): DW_OP_piece 0x4, DW_OP_reg1 ECX, DW_OP_piece 0x4)
                  DW_AT_name    ("f")
 DW_AT_decl_file       ("reduce30841.c")
 DW_AT_decl_line       (7)
                  DW_AT_type    (0x00000037 "int")
```

As seen, a 64-bit composite location description is emitted for the range [0x000011f6, 0x00001204).

The llvm.dbg.value for the 32-bit variable is changed to a 64-bit value by InstCombine:

```
-; *** IR Dump Before InstCombinePass on main ***
+; *** IR Dump After InstCombinePass on main ***
 ; ModuleID = 'reduce30841.c'
 source_filename = "reduce30841.c"
 target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i128:128-f64:32:64-f80:32-n8:16:32-S128"
@@ -15,39 +15,37 @@
 entry:
   %0 = load i32, ptr @c, align 4, !dbg !33, !tbaa !34
   %cmp = icmp slt i32 %0, 6, !dbg !38
-  %conv = zext i1 %cmp to i32, !dbg !38
-  tail call void @llvm.dbg.value(metadata i32 %conv, metadata !31, metadata !DIExpression()), !dbg !39
-  %conv1 = zext nneg i32 %conv to i64
+  %conv1 = zext i1 %cmp to i64
+  tail call void @llvm.dbg.value(metadata i64 %conv1, metadata !31, metadata !DIExpression()), !dbg !39

[...]
!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!31 = !DILocalVariable(name: "f", scope: !27, file: !3, line: 7, type: !8)
```

but I don't know if that is an issue, or if this should be handled in later steps.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to