This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, libgcc]: Avoid warning: array subscript is above array bounds when compiling crtstuff.c
- From: Ian Lance Taylor <iant at google dot com>
- To: Uros Bizjak <ubizjak at gmail dot com>
- Cc: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 7 Mar 2014 11:03:13 -0800
- Subject: Re: [PATCH, libgcc]: Avoid warning: array subscript is above array bounds when compiling crtstuff.c
- Authentication-results: sourceware.org; auth=none
- References: <CAFULd4awVFMCqOP48Sq_1mqWOKZky1RvfGAsAHjhQONzM=4FAg at mail dot gmail dot com>
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