debug: Normalize address-sized unsigned conversions [PR127676, PR127680]
Checks
Commit Message
Address-sized unsigned conversions can mix typed and generic DWARF
operands, producing invalid location expressions. Change the size check
in mem_loc_descriptor from < to <= to normalize the result, fixing
PR debug/127676 and PR debug/127680.
gcc/ChangeLog:
PR debug/127676
PR debug/127680
* dwarf2out.cc (mem_loc_descriptor): Convert address-sized
UNSIGNED_FIX results to the generic DWARF type.
gcc/testsuite/ChangeLog:
PR debug/127676
PR debug/127680
* gcc.dg/debug/dwarf2/pr127676.c: New test.
* gcc.dg/debug/dwarf2/pr127680.c: Likewise.
Signed-off-by: Jielun Wu <firmiana402@gmail.com>
---
Bootstrapped and regression tested on x86_64-pc-linux-gnu with no new
regressions.
OK for trunk?
gcc/dwarf2out.cc | 2 +-
gcc/testsuite/gcc.dg/debug/dwarf2/pr127676.c | 18 ++++++++++++++++++
gcc/testsuite/gcc.dg/debug/dwarf2/pr127680.c | 18 ++++++++++++++++++
3 files changed, 37 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/pr127676.c
create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/pr127680.c
+/* { dg-final { scan-assembler-times {DW_OP_convert[\r\n]+[
\t]*\.uleb128[ \t]+0[\r\n]} 1 } } */
@@ -17212,7 +17212,7 @@ mem_loc_descriptor (rtx rtl, machine_mode mode,
add_loc_descr (&op0, cvt);
if (is_a <scalar_int_mode> (mode, &int_mode)
&& (GET_CODE (rtl) == FIX
- || GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE))
+ || GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE))
{
op0 = convert_descriptor_to_mode (int_mode, op0);
if (op0 == NULL)
b/gcc/testsuite/gcc.dg/debug/dwarf2/pr127676.c
new file mode 100644
@@ -0,0 +1,18 @@
+/* PR debug/127676 */
+/* { dg-do compile { target { { i?86-*-* x86_64-*-* } && lp64 } } } */
+/* { dg-require-effective-target gas } */
+/* { dg-options "-O2 -gdwarf-5 -dA -fvar-tracking-assignments -fno-pie"
} */
+
+typedef unsigned long long u64;
+
+__attribute__((noinline, noclone)) u64
+bad_large_addend (double input)
+{
+ u64 value = (u64) input + 0x100000000ULL;
+ __asm__ volatile ("nop" ::: "memory");
+ return 0;
+}
+
+/* The address-sized unsigned conversion must return to the generic DWARF
+ type before adding a generic constant. */
+/* { dg-final { scan-assembler-times {DW_OP_convert[\r\n]+[
\t]*\.uleb128[ \t]+0[\r\n]} 1 } } */
b/gcc/testsuite/gcc.dg/debug/dwarf2/pr127680.c
new file mode 100644
@@ -0,0 +1,18 @@
+/* PR debug/127680 */
+/* { dg-do compile { target { { i?86-*-* x86_64-*-* } && lp64 } } } */
+/* { dg-require-effective-target gas } */
+/* { dg-options "-O2 -gdwarf-5 -dA -fvar-tracking-assignments -fno-pie"
} */
+
+typedef unsigned long long u64;
+
+__attribute__((noinline, noclone)) int
+less_than (double input)
+{
+ int result = (u64) input < 0x100000000ULL;
+ __asm__ volatile ("nop" ::: "memory");
+ return 0;
+}
+
+/* The address-sized unsigned conversion must return to the generic DWARF
+ type before comparing with a generic constant. */