[gdb/testsuite] Fix gdb.opt/clobbered-registers-O2.exp with gcc-12
authorTom de Vries <tdevries@suse.de>
Tue, 24 May 2022 20:41:45 +0000 (22:41 +0200)
committerTom de Vries <tdevries@suse.de>
Tue, 24 May 2022 20:41:45 +0000 (22:41 +0200)
commita0ae328a266d2b01ff640be9277e01592b08971a
tree8bc08e302eb5b5559d3e1cba52f5e054fc16ac9f
parent387e00f3b3e6ea3719f144d7090c1a242174be4d
[gdb/testsuite] Fix gdb.opt/clobbered-registers-O2.exp with gcc-12

When running test-case gdb.opt/clobbered-registers-O2.exp with gcc-12, I run
into:
...
(gdb) PASS: gdb.opt/clobbered-registers-O2.exp: backtracing
print operand0^M
$1 = (unsigned int *) 0x7fffffffd070^M
(gdb) print *operand0^M
$2 = 4195541^M
(gdb) FAIL: gdb.opt/clobbered-registers-O2.exp: print operand0
...

The problem is that starting gcc-12, the assignments to x and y in main are
optimized away:
...
int main(void)
{
  unsigned x, y;

  x = 13;
  y = 14;
  return (int)gen_movsd (&x, &y);
...

Fix this by making x and y volatile.

Note that the test-case intends to check the handling of debug info for
optimized code in function gen_movsd, so inhibiting optimization in main
doesn't interfere with that.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29161
gdb/testsuite/gdb.opt/clobbered-registers-O2.c