foo (int b)
{
  int a = b;

loop:
  if (b > 0)
    {
      b--;
      goto loop;
    }

  return a + b;
}

main()
{
  printf ("%d\n", foo (93));
}

Compile with '-g -O1'

GNU C version 3.5-tree-ssa 20040318 (merged 20040307) (i686-pc-linux-gnu)
        compiled by GNU C version 3.5-tree-ssa 20040318 (merged 20040307).

$ gcc -O1 -g a.c -o a
$ gdb ./a
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y

Starting program: /to/scratch/dnovillo/tree-ssa-00/native/00wrk/14511/a

Breakpoint 1, foo (b=93) at a.c:8
8             b--;
(gdb) p b
$2 = 93
(gdb) n
6         if (b > 0)
(gdb) n
8             b--;
(gdb) n
6         if (b > 0)
(gdb) n
8             b--;
(gdb) n
6         if (b > 0)
(gdb) p b
$3 = 93
(gdb) p a
No symbol "a" in current context.
(gdb)

Notice how 'b' never seems to change value and 'a' just doesn't exist.  This
works fine with GCC 3.2.3 and mainline as of 2004-03-16.

The problem in this case is that we don't map good debugging information to the
original symbols when we take the program out of SSA.  The final tree dump file
contains:

foo (b)
{
  int b.0, a;

<bb 0>:
  if (b > 0) goto <L8>; else goto <L9>;

<L8>:;
  b.0 = b;
  goto <bb 2> (<L1>);

loop:;
  if (b.0 > 0) goto <L1>; else goto <L2>;

<L1>:;
  b.0 = b.0 - 1;
  goto <bb 1> (loop);

<L9>:;
  b.0 = b;

<L2>:;
  return b + b.0;
}


Notice how 'b.0' has taken the place of 'b' and 'a' has disappeared completely.
 As a temporary workaround, we could perhaps not do copy propagation at -O1.

Long term, we need to explore the ideas of not coming out of SSA ever and do a
better job at mapping debugging information to symbols.

-- 
           Summary: [tree-ssa] Variables disappear from debug info at -O1
           Product: gcc
           Version: tree-ssa
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: debug
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dnovillo at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14638

Reply via email to