public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/108082] New: False Warray-bounds warning
@ 2022-12-13 12:07 risto.alasaarela at nokia dot com
  2022-12-13 12:19 ` [Bug tree-optimization/108082] " rguenth at gcc dot gnu.org
  2022-12-13 12:21 ` risto.alasaarela at nokia dot com
  0 siblings, 2 replies; 3+ messages in thread
From: risto.alasaarela at nokia dot com @ 2022-12-13 12:07 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug tree-optimization/108082] False Warray-bounds warning
  2022-12-13 12:07 [Bug c/108082] New: False Warray-bounds warning risto.alasaarela at nokia dot com
@ 2022-12-13 12:19 ` rguenth at gcc dot gnu.org
  2022-12-13 12:21 ` risto.alasaarela at nokia dot com
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-12-13 12:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108082

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |tree-optimization
             Blocks|                            |56456
           Keywords|                            |diagnostic
   Last reconfirmed|                            |2022-12-13
             Status|UNCONFIRMED                 |WAITING
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Without a full testcase it's hard to tell but I would guess there's partial
inlining inlining the if (num < 2) num; check so the bound isn't present
when analyzing the body.  There's a duplicate bugreport for exactly this case
btw.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56456
[Bug 56456] [meta-bug] bogus/missing -Warray-bounds

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug tree-optimization/108082] False Warray-bounds warning
  2022-12-13 12:07 [Bug c/108082] New: False Warray-bounds warning risto.alasaarela at nokia dot com
  2022-12-13 12:19 ` [Bug tree-optimization/108082] " rguenth at gcc dot gnu.org
@ 2022-12-13 12:21 ` risto.alasaarela at nokia dot com
  1 sibling, 0 replies; 3+ messages in thread
From: risto.alasaarela at nokia dot com @ 2022-12-13 12:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108082

--- Comment #2 from Risto Alasaarela <risto.alasaarela at nokia dot com> ---
Could you please point the duplicate report?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-13 12:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-13 12:07 [Bug c/108082] New: False Warray-bounds warning risto.alasaarela at nokia dot com
2022-12-13 12:19 ` [Bug tree-optimization/108082] " rguenth at gcc dot gnu.org
2022-12-13 12:21 ` risto.alasaarela at nokia dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).