gcc gives "array subscript is above array bounds [-Werror=array-bounds]" when using optimization option -03

Solution Unverified - Updated -

Issue

  • When I compile the a module using optimization level 2 it success, however when I do this same code with optimization level 3 it fails. The code content is in the file test_code.c which I have uploaded to this ticket.

  • The script to compile with -O2 option is:

/usr/bin/gcc -c -m32 -ansi -D_GNU_SOURCE \
        -funsigned-char -fno-zero-initialized-in-bss -fno-strict-aliasing \
        -DLANGUAGE_C  -Wall -Wno-strict-aliasing -Wextra -Werror \
        -O2 \
        -pipe -Wstrict-prototypes -Wmissing-prototypes test_code.c
  • Compile call with -O3 option:
/usr/bin/gcc -c -m32 -ansi -D_GNU_SOURCE \
        -funsigned-char -fno-zero-initialized-in-bss -fno-strict-aliasing \
        -DLANGUAGE_C  -Wall -Wno-strict-aliasing -Wextra -Werror \
        -O3 \
        -pipe -Wstrict-prototypes -Wmissing-prototypes test_code.c
  • The error from the compile with -O3 is attached to this ticket. I did not see any of these errors with the -O2 compile.

Environment

  • Red Hat Enterprise Linux 7.0
  • gcc-4.8.2-3.el7.x86_64

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content