https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65461
Bug ID: 65461 Summary: -Warray-bounds warnings in the linux kernel (free_area_init_nodes) Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: marxin at gcc dot gnu.org Hello. After reducing following test case, I see false positive VRP warning for: enum zone_type { ZONE_NORMAL, ZONE_MOVABLE, __MAX_NR_ZONES }; unsigned long arch_zone_lowest_possible_pfn[2]; unsigned long arch_zone_highest_possible_pfn[2]; void __next_mem_pfn_range(int *a, unsigned long *b, unsigned long *c, int *d); void free_area_init_nodes(unsigned long *max_zone_pfn) { unsigned long start_pfn, end_pfn; int i, nid; for (i = 1; i < 2; i++) { if (i == ZONE_MOVABLE) continue; arch_zone_lowest_possible_pfn[i] = arch_zone_highest_possible_pfn[i-1]; } for (i = -1; i >= 0; __next_mem_pfn_range(&i, &start_pfn, &end_pfn, &nid)) {} } testcase.i: In function ‘free_area_init_nodes’: testcase.i:18:74: warning: array subscript is below array bounds [-Warray-bounds] arch_zone_lowest_possible_pfn[i] = arch_zone_highest_possible_pfn[i-1]; Well, it looks the issue is similar (duplicate) to PR1006, but maybe it worth for analysis. VPR dump shows following code: Value ranges after VRP: .MEM_1: VARYING .MEM_2: VARYING .MEM_3: VARYING i.0_6: VARYING _7: [-INF(OVF), -1] _8: VARYING i.1_10: [-2147483647, 2] i.0_13: VARYING i.0_19: [1, 1] EQUIVALENCES: { i.0_6 i.0_21 } (2 elements) i.0_20: [-INF, 0] EQUIVALENCES: { i.0_6 i.0_21 } (2 elements) i.0_21: [-INF, 1] EQUIVALENCES: { i.0_6 } (1 elements) For: free_area_init_nodes (long unsigned int * max_zone_pfn) { int nid; int i; long unsigned int end_pfn; long unsigned int start_pfn; int i.0_6; int _7; long unsigned int _8; int i.1_10; int i.0_13; <bb 2>: i = 1; goto <bb 6>; <bb 3>: if (i.0_6 == 1) goto <bb 5>; else goto <bb 4>; <bb 4>: _7 = i.0_6 + -1; _8 = arch_zone_highest_possible_pfn[_7]; arch_zone_lowest_possible_pfn[i.0_6] = _8; <bb 5>: i.1_10 = i.0_6 + 1; i = i.1_10; <bb 6>: i.0_6 = i; if (i.0_6 <= 1) goto <bb 3>; else goto <bb 7>; <bb 7>: i = -1; goto <bb 9>; <bb 8>: __next_mem_pfn_range (&i, &start_pfn, &end_pfn, &nid); <bb 9>: i.0_13 = i; if (i.0_13 >= 0) goto <bb 8>; else goto <bb 10>; <bb 10>: start_pfn ={v} {CLOBBER}; end_pfn ={v} {CLOBBER}; i ={v} {CLOBBER}; nid ={v} {CLOBBER}; return; } Thanks, Martin