On Fri, Mar 7, 2014 at 8:03 PM, Ian Lance Taylor <i...@google.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  <ubiz...@gmail.com>
>>
>>     * crtstuff.c (__JCR_LIST__): Declare as zero-length array.
>>
>
> 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?

I was not able to cast variable with any sensible type cast (maybe I
didn't understand your suggestion correctly), the only other variant
that avoided warning was

--cut here--
Index: crtstuff.c
===================================================================
--- crtstuff.c  (revision 208403)
+++ crtstuff.c  (working copy)
@@ -259,7 +259,7 @@
    so we can register them properly.  */
 STATIC void *__JCR_LIST__[]
   __attribute__ ((used, section(JCR_SECTION_NAME), aligned(sizeof(void*))))
-  = { };
+  = { 0 };
 #endif /* JCR_SECTION_NAME */

 #if USE_TM_CLONE_REGISTRY
--cut here--

but I don't know if this is correct approach, concerning mentioned linker magic.

I have opened PR 60472 [1] with a reduced testcase, if somebody wants
to deal with this problem...

[1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60472

Uros.

Reply via email to