Bug #83517 shift-or compiler bug with gcc -fexpensive-optimizations
Submitted: 25 Oct 2016 9:38 Modified: 16 Nov 2016 16:32
Reporter: Mauritz Sundell Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: CPU Architecture:Any

[25 Oct 2016 9:38] Mauritz Sundell
Description:
GNU C/C++ 5.3.0 compiler for sparc have a faulty shift-or optimization that recently hit MySQL Cluster 7.5.4 release build, see details in Bug#24941880 SPARC COMPILER BUG DUE TO SIGNED INT IN SHIFT OPERATIONS

Bug#24941880 was fixed by refactoring to avoid a known instance of the faulty optimization.

-fexpensive-optimizations should be turned off to avoid this faulty optimization also for potentially undetected instances.

Most likely the bug in question is GCC Bug 67781 and should been fixed in 5.4.0 and 6.0
Bug 67781 - [5 Regression] wrong code generated on big-endian with -O1 -fexpensive-optimizations
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67781

How to repeat:
Compile and run below code on sparc with GNU C or C++ 5.3.0

struct X
{
  int i;
  unsigned short s;
};

unsigned __attribute__((noinline)) f(struct X x)
{
  return x.s | (x.i << 16);
}

int
main()
{
  struct X x;
  x.i = 0x00001234;
  x.s = 0x5678;
  unsigned y = f(x);
  /* Succeed (return 0) if compiler have bug */
  return y == 0x12345678 ? 1 : 0;
}

Suggested fix:
Add cmake check using above code, and turn off expensive optimizations if compiler is found faulty.

This should be pushed at least to 5.7/7.5 and up since we currently build releases affected by bug.

Alternatively upgrade to newer compiler and verify bug is gone.
And let any other building using 5.3.0 on sparc be on their own.
[16 Nov 2016 16:32] Paul DuBois
Posted by developer:
 
Noted in 5.7.16-ndb-7.5.5, 5.7.17, 8.0.1 changelogs.

CMake now avoids configuring the -fexpensive-optimizations option for
GCC versions for which the option triggers faulty shift-or
optimizations.