public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/96629] New: spurious uninitialized variable warning with branches at -O1 and higher
@ 2020-08-16  6:10 yyc1992 at gmail dot com
  2020-08-25 10:20 ` [Bug c/96629] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: yyc1992 at gmail dot com @ 2020-08-16  6:10 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96629
           Summary: spurious uninitialized variable warning with branches
                    at -O1 and higher
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yyc1992 at gmail dot com
  Target Milestone: ---

Reduced test code:

```
int mem(char *data);
int cond(void);
void f(char *data, unsigned idx, unsigned inc)
{
    char *d2;
    int c = cond();
    if (idx >= 2) {
        if (c)
            d2 = data;
        mem(data);
    }
    else if (inc > 3) {
        if (c)
            d2 = data;
        mem(data);
    }
    else {
        if (c) {
            d2 = data;
        }
    }
    if (*data) {
    }
    else if (c) {
        mem(d2);
    }
}
```

Compiling with `gcc -Wall -Wextra -O{1,2,s,3,fast}` warns about

```
a.c: In function 'f':
a.c:27:9: warning: 'd2' may be used uninitialized in this function
[-Wmaybe-uninitialized]
   27 |         mem(d2);
      |         ^~~~~~~
```

However, it should be clear that `d2` is always assigned when `c` is true. In
fact, it seems that GCC could figure this out in some cases. Changes that can
surpress the warning includes,

1. Remove any of the `mem(data)` calls.
2. Remove any one of the `if`s (leaving only the if or else branch
unconditionally)
3. Change first condition to be on inc instead.
4. Removing the last `*data` branch.

Version tested:
AArch64: 10.2.0
ARM: 9.1.0
x86_64: 10.1.0
mingw64: 10.2.0

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

* [Bug c/96629] spurious uninitialized variable warning with branches at -O1 and higher
  2020-08-16  6:10 [Bug c/96629] New: spurious uninitialized variable warning with branches at -O1 and higher yyc1992 at gmail dot com
@ 2020-08-25 10:20 ` rguenth at gcc dot gnu.org
  2020-09-03 18:13 ` [Bug c/96629] spurious maybe uninitialized variable warning with difficult control-flow analysis manu at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-08-25 10:20 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-08-25
     Ever confirmed|0                           |1
             Blocks|                            |24639
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |diagnostic

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
the control-flow analysis of the uninit warning isn't powerful enough to
capture this.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639
[Bug 24639] [meta-bug] bug to track all Wuninitialized issues

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

* [Bug c/96629] spurious maybe uninitialized variable warning with difficult control-flow analysis
  2020-08-16  6:10 [Bug c/96629] New: spurious uninitialized variable warning with branches at -O1 and higher yyc1992 at gmail dot com
  2020-08-25 10:20 ` [Bug c/96629] " rguenth at gcc dot gnu.org
@ 2020-09-03 18:13 ` manu at gcc dot gnu.org
  2020-09-03 18:21 ` yyc1992 at gmail dot com
  2022-11-20  4:50 ` [Bug tree-optimization/96629] " law at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu.org @ 2020-09-03 18:13 UTC (permalink / raw)
  To: gcc-bugs

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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|spurious uninitialized      |spurious maybe
                   |variable warning with       |uninitialized variable
                   |branches at -O1 and higher  |warning with difficult
                   |                            |control-flow analysis
                 CC|                            |manu at gcc dot gnu.org

--- Comment #2 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
Yes, the pass seems to give up:

[CHECK]: Found unguarded use: d2_29 = PHI <d2_4(19), data_13(D)(22)>
[WORKLIST]: Update worklist with phi: d2_29 = PHI <d2_4(19), data_13(D)(22)>
[CHECK]: examining phi: d2_29 = PHI <d2_4(19), data_13(D)(22)>
[CHECK]: Found unguarded use: mem (d2_29); [tail call]

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

* [Bug c/96629] spurious maybe uninitialized variable warning with difficult control-flow analysis
  2020-08-16  6:10 [Bug c/96629] New: spurious uninitialized variable warning with branches at -O1 and higher yyc1992 at gmail dot com
  2020-08-25 10:20 ` [Bug c/96629] " rguenth at gcc dot gnu.org
  2020-09-03 18:13 ` [Bug c/96629] spurious maybe uninitialized variable warning with difficult control-flow analysis manu at gcc dot gnu.org
@ 2020-09-03 18:21 ` yyc1992 at gmail dot com
  2022-11-20  4:50 ` [Bug tree-optimization/96629] " law at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: yyc1992 at gmail dot com @ 2020-09-03 18:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Yichao Yu <yyc1992 at gmail dot com> ---
Just curious, is it some particular structure that is upsetting it or did it
simply hit some depth limit.

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

* [Bug tree-optimization/96629] spurious maybe uninitialized variable warning with difficult control-flow analysis
  2020-08-16  6:10 [Bug c/96629] New: spurious uninitialized variable warning with branches at -O1 and higher yyc1992 at gmail dot com
                   ` (2 preceding siblings ...)
  2020-09-03 18:21 ` yyc1992 at gmail dot com
@ 2022-11-20  4:50 ` law at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: law at gcc dot gnu.org @ 2022-11-20  4:50 UTC (permalink / raw)
  To: gcc-bugs

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

Jeffrey A. Law <law at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |law at gcc dot gnu.org

--- Comment #4 from Jeffrey A. Law <law at gcc dot gnu.org> ---
It's worth noting that at -O2, -O3 and -Ofast the warning does not trigger.  I
haven't dug deeply as this is fairly common.  At higher optimization levels the
various optimizers try harder to find and eliminate redundancies.

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

end of thread, other threads:[~2022-11-20  4:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-16  6:10 [Bug c/96629] New: spurious uninitialized variable warning with branches at -O1 and higher yyc1992 at gmail dot com
2020-08-25 10:20 ` [Bug c/96629] " rguenth at gcc dot gnu.org
2020-09-03 18:13 ` [Bug c/96629] spurious maybe uninitialized variable warning with difficult control-flow analysis manu at gcc dot gnu.org
2020-09-03 18:21 ` yyc1992 at gmail dot com
2022-11-20  4:50 ` [Bug tree-optimization/96629] " law at gcc dot gnu.org

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).