This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Should -fcross-jumping be part of -O1?


On 02 Dec 2003 11:48:30 -0800, Geoff Keating <geoffk@geoffk.org> said:
> David Carlton <carlton@kealia.com> writes:

>> This is obviously a very special case, but dead code elimination
>> sometimes makes it difficult to write tests for GDB's test suite.  And
>> even when working on real programs I occasionally insert dead code as
>> a place where I can set breakpoints.  So, personally, I'd prefer that
>> -O0 be pretty stupid.  (Though I don't mind if it's not the default.)

> I thought that the dead code elimination at -O0 is supposed to work
> properly with GDB: it puts in a 'nop' that the breakpoint can target.
> Is this not working?

Not always.  I went and dug up the original thread, and trimmed the
resulting program a little bit.  Compile the program after my
signature (using gcc -g -O0; I've seen this on stock GCC 3.1 and on
Red Hat's 3.2, though I haven't tried more recent GCC's), and run gdb
on it, and do 'break main' and then 'run': it skips everything until
the call to 'wack_struct_1'.  And looking at the assembly code, 'main'
is a lot shorter than I would wish.

David Carlton
carlton@kealia.com

/* Check that GDB can correctly update a value, living in a register,
   in the target.  This pretty much relies on the compiler taking heed
   of requests for values to be stored in registers.  */

static char
add_char (register char u, register char v)
{
  return u + v;
}

static short
add_short (register short u, register short v)
{
  return u + v;
}

static int
add_int (register int u, register int v)
{
  return u + v;
}

static long
add_long (register long u, register long v)
{
  return u + v;
}

static float
add_float (register float u, register float v)
{
  return u + v;
}

static double
add_double (register double u, register double v)
{
  return u + v;
}

/* */

static char
wack_char (register char u, register char v)
{
  register char l = u;
  l = add_char (l, v);
  return l;
}

static short
wack_short (register short u, register short v)
{
  register short l = u;
  l = add_short (l, v);
  return l;
}

static int
wack_int (register int u, register int v)
{
  register int l = u;
  l = add_int (l, v);
  return l;
}

static long
wack_long (register long u, register long v)
{
  register long l = u;
  l = add_long (l, v);
  return l;
}

static float
wack_float (register float u, register float v)
{
  register float l = u;
  l = add_float (l, v);
  return l;
}

static double
wack_double (register double u, register double v)
{
  register double l = u;
  l = add_double (l, v);
  return l;
}

struct s_1 { short s[1]; } z_1, s_1;

static struct s_1
add_struct_1 (struct s_1 s)
{
  int i;
  for (i = 0; i < sizeof (s) / sizeof (s.s[0]); i++)
    {
      s.s[i] = s.s[i] + s.s[i];
    }
  return s;
}

static struct s_1
wack_struct_1 (void)
{
  int i; register struct s_1 u = z_1;
  for (i = 0; i < sizeof (s_1) / sizeof (s_1.s[0]); i++) { s_1.s[i] = i + 1; }
  u = add_struct_1 (u);
  return u;
}

int
main ()
{
  /* These calls are for current frame test.  */
  wack_char (1, 2);
  wack_short (1, 2);
  wack_int (1, 2);
  wack_long (1, 2);
  wack_float (1, 2);
  wack_double (1, 2);

  /* These calls are for up frame.  */
  wack_char (1, 2);
  wack_short (1, 2);
  wack_int (1, 2);
  wack_long (1, 2);
  wack_float (1, 2);
  wack_double (1, 2);

  /* These calls are for current frame test.  */
  wack_struct_1 ();

  return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]