https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108082
Bug ID: 108082 Summary: False Warray-bounds warning Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: risto.alasaarela at nokia dot com Target Milestone: --- Code: static inline int count_same_evgroup(event_hdr_t *ev_hdr_tbl[], const unsigned int num) { if (unlikely(num < 2)) { return num; } else { const em_event_group_t egrp = ev_hdr_tbl[0]->egrp; unsigned int i = 1; /* 2nd hdr */ if (EM_EVENT_GROUP_SAFE_MODE) { const int32_t egrp_gen = ev_hdr_tbl[0]->egrp_gen; for (; i < num && egrp == ev_hdr_tbl[i]->egrp && egrp_gen == ev_hdr_tbl[i]->egrp_gen; i++) ; } else { for (; i < num && egrp == ev_hdr_tbl[i]->egrp; i++) ; } return i; } } Warning: In file included from ../../src/em_include.h:115, from ../../src/event_machine_dispatcher.c:31: In function 'count_same_evgroup', inlined from 'dispatch_multi_receive' at ../../src/em_dispatcher.h:362:24, inlined from 'dispatch_local_queues' at ../../src/em_dispatcher.h:284:4, inlined from 'check_local_queues.part.0' at ../../src/em_dispatcher.h:316:3: ../../src/em_dispatcher.h:336:40: error: array subscript 1 is outside array bounds of 'event_hdr_t *[1]' [-Werror=array-bounds] 336 | egrp == ev_hdr_tbl[i]->egrp && Description: When setting the "num" parameter of the function to 1, compiler throws an unnecessary warning, even if else branch is dedicated to handle the bigger table indexes than 0.