GCC 4.8.4 4.9.2 nifti_swap_2bytes optimization bug

Andreas Schuh andreas.schuh.84@gmail.com
Wed Apr 1 14:36:00 GMT 2015


Hi,

I believe I have encountered a bug in the optimization at least in versions 4.8.4 and 4.9.2. The problem is not present in version 4.6.3. The attached complete example code can be used to reproduce the error (my system is Ubuntu 12.04). This code is crucial in medical image processing where the NIfTI-1 file format is commonly used. The respective function that is optimized incorrectly by most recent C/C++ compilers of GCC was copied from the NIfTI-1 C library and is used by many medical image processing tools. It is responsible for swapping the bytes if necessary when the image data was written on a system with differing endianness.

The problem is only present with optimization level >1 (i.e., -O2 or -O3), e.g.,

    gcc swap.c -o swap -O2 -v

The verbose output is enclosed as well.

Running the program with the argument 768, for example, should produce the output 3. However, with the optimization enabled, the input argument is not modified.

  > ./swap 768
  3

Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: swap.c
Type: text/x-csrc
Size: 604 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20150401/3eddd0ff/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-4.9.2-v.log
Type: text/x-log
Size: 4095 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20150401/3eddd0ff/attachment-0001.bin>


More information about the Gcc-help mailing list