extern int printf (__const char *__restrict __format, ...);
static int f2(char formatstr[10][100]) {
int anz;
for( anz = 0; anz < 10; ++anz ) {
printf( "%d %s\n", anz, formatstr[anz] );
}
return anz;
}
static char formatstr[10][100];
int main( void ) {
int anz;
anz = f2(formatstr);
printf( " %d\n",anz);
return 0;
}
with -O3 -Wall this reports
t.c: In function main:
t.c:6: warning: array subscript is above array bounds
t.c:6: warning: array subscript is above array bounds
t.c:6: warning: array subscript is above array bounds
t.c:6: warning: array subscript is above array bounds
t.c:6: warning: array subscript is above array bounds
t.c:6: warning: array subscript is above array bounds
t.c:6: warning: array subscript is above array bounds
t.c:6: warning: array subscript is above array bounds
because we end up with
<bb 3>:
# anz_23 = PHI <anz_6(4), anz_22(6)>
D.1572_5 = (long unsigned int) anz_23;
D.1573_7 = D.1572_5 * 100;
D.1574_8 = &formatstr[0][D.1573_7];
printf (&"%d %s\n"[0], anz_23, D.1574_8);
anz_9 = anz_23 + 1;
<bb 4>:
# anz_6 = PHI <anz_9(3)>
if (anz_6 <= 9)
goto <bb 3>;
else
goto <bb 5>;
--
Summary: Bogus array bounds warning
Product: gcc
Version: 4.3.2
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: rguenth at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37861