From: Tom de Vries Date: Mon, 9 Jul 2018 07:17:45 +0000 (+0000) Subject: [debug] Handle debug references to skipped params X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=74725f46ddc4bb020414320147cba37f907c3336;p=gcc.git [debug] Handle debug references to skipped params When compiling guality/vla-1.c with -O3 -g, vla a in f1 is optimized away, but f1 still contains a debug expression describing the upper bound of the vla (D.1914): ... __attribute__((noinline)) f1 (intD.6 iD.1900) { saved_stack.1_2 = __builtin_stack_save (); # DEBUG BEGIN_STMT # DEBUG D#3 => i_1(D) + 1 # DEBUG D#2 => (long intD.8) D#3 # DEBUG D#1 => D#2 + -1 # DEBUG D.1914 => (sizetype) D#1 ... Then f1 is cloned to a version f1.constprop with no parameters, eliminating parameter i, and 'DEBUG D#3 => i_1(D) + 1' turns into 'D#3 => NULL'. This patch fixes that by defining debug expressions for default defs of eliminated parameters in remap_ssa_name: ... __attribute__((noinline)) f1.constprop () { intD.6 iD.1949; # DEBUG D#8 s=> iD.1900 # DEBUG iD.1949 => D#8 + # DEBUG D#6 s=> iD.1949 saved_stack.1_1 = __builtin_stack_save (); # DEBUG BEGIN_STMT - # DEBUG D#3 => NULL + # DEBUG D#3 => D#6 + 1 # DEBUG D#2 => (long intD.8) D#3 # DEBUG D#1 => D#2 + -1 # DEBUG D.1951 => (sizetype) D#1 ... Bootstrapped and reg-tested on x86_64. 2018-07-09 Tom de Vries * cfgexpand.c (expand_debug_source_expr): Handle VAR_DECL. * tree-inline.c (remap_ssa_name): Handle default def ssa_name mapping onto VAR_DECL with abstract origin. * gcc.dg/vla-1.c: New test. From-SVN: r262510 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8966da1051b..8add29b83a3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-07-09 Tom de Vries + + * cfgexpand.c (expand_debug_source_expr): Handle VAR_DECL. + * tree-inline.c (remap_ssa_name): Handle default def ssa_name mapping + onto VAR_DECL with abstract origin. + 2018-07-07 Jim Wilson * config/riscv/riscv.c (TARGET_CUSTOM_FUNCTION_DESCRIPTORS): New. diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 9b91279282e..d6e3c382085 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -5141,6 +5141,10 @@ expand_debug_source_expr (tree exp) switch (TREE_CODE (exp)) { + case VAR_DECL: + if (DECL_ABSTRACT_ORIGIN (exp)) + return expand_debug_source_expr (DECL_ABSTRACT_ORIGIN (exp)); + break; case PARM_DECL: { mode = DECL_MODE (exp); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 04d705d68d2..988fac11b05 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-07-09 Tom de Vries + + * gcc.dg/vla-1.c: New test. + 2018-07-07 Tom de Vries * gcc.misc-tests/options.exp (check_for_all_options): Clean up dump diff --git a/gcc/testsuite/gcc.dg/vla-1.c b/gcc/testsuite/gcc.dg/vla-1.c new file mode 100644 index 00000000000..56437ae44de --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-1.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-options "-g -O3 -fdump-tree-optimized -fvar-tracking-assignments -fno-selective-scheduling -fno-selective-scheduling2" } */ + +int __attribute__((noinline)) +f1 (int i) +{ + char a[i + 1]; + char b[i + 2]; + b[1] = 3; + a[0] = 5; + return a[0] + b[1]; +} + +int +main () +{ + volatile int j; + int x = 5; + j = f1 (x); + return 0; +} + +/* One debug source bind is generated for the parameter, and two to describe the + sizes of a and b. */ +/* { dg-final { scan-tree-dump-times " s=> i" 3 "optimized" } } */ diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 427ef959740..45aba8171a6 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -208,7 +208,8 @@ remap_ssa_name (tree name, copy_body_data *id) n = id->decl_map->get (val); if (n != NULL) val = *n; - if (TREE_CODE (val) != PARM_DECL) + if (TREE_CODE (val) != PARM_DECL + && !(VAR_P (val) && DECL_ABSTRACT_ORIGIN (val))) { processing_debug_stmt = -1; return name;