Hi,

I am noticing a very concerning change of behaviour from GCC45 to GCC46 on our applications.

The following code:
static const unsigned int foo = 1;
unsigned int test( void )
{
  const volatile unsigned int *bar = &foo;
  return ( *bar );
}

in GCC45 works as expected:
$test:
  ld AL,#foo  ;; AL is return register
  bra 0,X     ;; end function

in GCC46:
$test:
  ld AL,0
  bra 0,X

This is worrying because qualifying the data as volatile should be enough to prevent these sort of optimizations. It did until GCC46.

I noticed that this seems to be implementation dependent according to C99 6.7.3.6, however, this change of implementation is unexpected and I don't see a reason for it. Is there any reason for this change?

The correct code is generated is both the pointer and data are qualified as volatile even it is not straightforward code since it has some moves to and from the stack pointer.

This is easily reproducible in i386 so, it's definitely not backend specific.

Cheers,
--
PMatos

Reply via email to