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

Uros Bizjak ubizjak@gmail.com
Mon Mar 10 13:22:00 GMT 2014


On Mon, Mar 10, 2014 at 11:14 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>> > Well, better is non-obvious, while it is smaller (which is good for
>> > initialization and thus rarely executed code), the common case is that
>> > *jcr_list is 0 (gcj is used rarely these days) and for the common case it is
>> > one instruction longer.
>> > Perhaps at least use if (__builtin_expect (*jcr_list != NULL, 0))?
>> > Otherwise looks good to me.
>>
>> Following source:
>>
>> void frame_dummy (void)
>> {
>>   void **jcr_list = __JCR_LIST__;
>>   if (__builtin_expect (*jcr_list != 0, 0))
>>     register_classes (jcr_list);
>> }
>>
>> generates exactly the same code while avoiding the warning. So,
>> following your concern, I am testing following patch:
>
> But then the asm is gone and it can start to break any time soon.
> For GCC __JCR_LIST__ is simply a zero sized local array and thus
> dereferencing it's first element is invalid.  It doesn't know that we use
> linker magic to populate the array.

OK, then we have to live with additional instruction (which isn't bad
either, since the r/i compare can be fused with the cjump, where m/i
compare can't be).

I will bootstrap/regtest with additional __built_expect.

Uros.



More information about the Gcc-patches mailing list