RE: [PATCH] phy: fix compiler array bounds warning on settings[]

From: David Laight
Date: Thu Mar 06 2014 - 04:13:53 EST


From: Bjorn Helgaas
> I'm stumped. phy_find_valid() is static and only called from one
> place. The 'idx' argument is always the result of phy_find_setting(),
> which should always return something between 0 and
> ARRAY_SIZE(settings), so I don't see any way idx can be < 0.
>
> I stripped this down as far as I could; the resulting test code is at
> http://pastebin.com/pp1zMEWu if anybody else wants to look at it. I'm
> using gcc 4.8.x 20131105 (prerelease), with "-Warray-bounds -O2"
> flags.
>
> I hesitate to suspect a compiler bug, but it is very strange. For
> example, in my test code, replacing "MAX_NUM_SETTINGS" with "2" gets
> rid of the warnings. MAX_NUM_SETTINGS is known to be 2 at
> compile-time, so I don't know why this should make a difference.

I can't get an array bounds error from the gcc 4.8.1-10ubuntu9 at all.
Not even when I index the array with a constant 3.
I wonder if they compiled it out!

David

N‹§²æ¸›yú²X¬¶ÇvØ–)Þ{.nlj·¥Š{±‘êX§¶›¡Ü}©ž²ÆzÚj:+v‰¨¾«‘êZ+€Êzf£¢·hšˆ§~†­†Ûÿû®w¥¢¸?™¨è&¢)ßf”ùy§m…á«a¶Úÿ 0¶ìå