public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hv at crypt dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/102381] New: unexpected -Wmaybe-uninitialized
Date: Fri, 17 Sep 2021 01:43:31 +0000	[thread overview]
Message-ID: <bug-102381-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 102381
           Summary: unexpected -Wmaybe-uninitialized
           Product: gcc
           Version: 7.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hv at crypt dot org
  Target Milestone: ---

This is reduced from perl source code. Reduction was a challenge, so there's a
risk the essence may have been lost.

The following code gives a -Wmaybe-uninitialized warning with each of "gcc-7
(Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0", "gcc-9 (Ubuntu 9.2.1-17ubuntu1~18.04.1)
9.2.1 20191102" and self-built "gcc (GCC) 11.2.0".

% cat test.c
extern void fail(void) __attribute__((__noreturn__));
int** f(void);

extern int *ip;
extern int i2, i3; 

void test(int i1) {
    int **ipp;

    if (i1) {
        ipp = f();
    }
    for (int i4 = 0; i4 < i2; i4++) {
        if (((i3 & 1) != 1) && ((i3 & 3) != 3))
            fail();
    }
    if (i1) {
        ip = *ipp;
    }
    return;
}
% gcc -c -Wmaybe-uninitialized -O1 test.c
test.c: In function 'test':
test.c:18:14: warning: 'ipp' may be used uninitialized in this function
[-Wmaybe-uninitialized]
         ip = *ipp;
              ^~~~
% 

I think it should be clear that i1 does not change within this code, and the
'ip = *ipp' therefore cannot be reached without also previously having reached
'ipp = f()'. The sensitivity of the intervening code suggests this must be a
bug, eg replacing 'if (((i3 & 1) != 1) && ((i3 & 3) != 3))' with 'if ((i3 & 3)
!= 3)' makes the warning disappear.

             reply	other threads:[~2021-09-17  1:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-17  1:43 hv at crypt dot org [this message]
2021-09-17  4:00 ` [Bug tree-optimization/102381] " pinskia at gcc dot gnu.org
2021-09-17  4:02 ` [Bug tree-optimization/102381] unexpected -Wmaybe-uninitialized with noreturn inside loop and conditional setting of variable pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-102381-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).