diff mbox

[libgcc] : Avoid warning: array subscript is above array bounds when compiling crtstuff.c

Message ID CAFULd4awVFMCqOP48Sq_1mqWOKZky1RvfGAsAHjhQONzM=4FAg@mail.gmail.com
State New
Headers show

Commit Message

Uros Bizjak March 7, 2014, 5:36 p.m. UTC
Hello!

Attached patch avoids a bunch of:

../../../gcc-svn/trunk/libgcc/crtstuff.c: In function 'frame_dummy':
../../../gcc-svn/trunk/libgcc/crtstuff.c:463:19: warning: array
subscript is above array bounds [-Warray-bounds]
   if (__JCR_LIST__[0])
                   ^

when compiling libgcc.

2014-03-08  Uros Bizjak  <ubizjak@gmail.com>

    * crtstuff.c (__JCR_LIST__): Declare as zero-length array.

Bootstrapped and regression tested on x86_64-pc-linux-gnu {,-m32}.

OK for mainline?

Uros.

Comments

Ian Lance Taylor March 7, 2014, 7:03 p.m. UTC | #1
On Fri, Mar 7, 2014 at 9:36 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
>
> Attached patch avoids a bunch of:
>
> ../../../gcc-svn/trunk/libgcc/crtstuff.c: In function 'frame_dummy':
> ../../../gcc-svn/trunk/libgcc/crtstuff.c:463:19: warning: array
> subscript is above array bounds [-Warray-bounds]
>    if (__JCR_LIST__[0])
>                    ^
>
> when compiling libgcc.
>
> 2014-03-08  Uros Bizjak  <ubizjak@gmail.com>
>
>     * crtstuff.c (__JCR_LIST__): Declare as zero-length array.
>
> Bootstrapped and regression tested on x86_64-pc-linux-gnu {,-m32}.
>
> OK for mainline?
>
> Uros.
>
>
> Index: crtstuff.c
> ===================================================================
> --- crtstuff.c  (revision 208403)
> +++ crtstuff.c  (working copy)
> @@ -257,7 +257,7 @@ STATIC EH_FRAME_SECTION_CONST char __EH_FRAME_BEGI
>  #ifdef JCR_SECTION_NAME
>  /* Stick a label at the beginning of the java class registration info
>     so we can register them properly.  */
> -STATIC void *__JCR_LIST__[]
> +STATIC void *__JCR_LIST__[0]
>    __attribute__ ((used, section(JCR_SECTION_NAME), aligned(sizeof(void*))))
>    = { };
>  #endif /* JCR_SECTION_NAME */

I don't understand why this works.  You can't index element 0 of a 0
element array.

This code is relying on linker magic and it's not surprising that it
confuses the compiler.  Can you use a type cast or variable assignment
in frame_dummy instead?

Ian
diff mbox

Patch

Index: crtstuff.c
===================================================================
--- crtstuff.c  (revision 208403)
+++ crtstuff.c  (working copy)
@@ -257,7 +257,7 @@  STATIC EH_FRAME_SECTION_CONST char __EH_FRAME_BEGI
 #ifdef JCR_SECTION_NAME
 /* Stick a label at the beginning of the java class registration info
    so we can register them properly.  */
-STATIC void *__JCR_LIST__[]
+STATIC void *__JCR_LIST__[0]
   __attribute__ ((used, section(JCR_SECTION_NAME), aligned(sizeof(void*))))
   = { };
 #endif /* JCR_SECTION_NAME */