public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/109190] New: GCC Static Analyzer cannot handle the initialization of an array with a for loop
@ 2023-03-19  8:57 geoffreydgr at icloud dot com
  2023-04-03 12:59 ` [Bug analyzer/109190] " geoffreydgr at icloud dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: geoffreydgr at icloud dot com @ 2023-03-19  8:57 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109190
           Summary: GCC Static Analyzer cannot handle the initialization
                    of an array with a for loop
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: geoffreydgr at icloud dot com
  Target Milestone: ---

I got a false negative error when compiling the following program with
gcc(trunk) -fanalyzer -O0 in https://godbolt.org/z/KvoxvPq5c. When I replace
the array `m` with the variable `a` (https://godbolt.org/z/jTzo9bEo9), the NPD
appears.

```c
#include "stdio.h"
int main() {
    int i = 0;
    int *g = &i;
    int m[1];

    for (int j = 0; j < 1; j++) {
         m[j] = 0;
    }

    if (m[0])
        ;
    else
        g = m[i];

    printf("NPD_FLAG\n");
    *g = 1;
}
```

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

* [Bug analyzer/109190] GCC Static Analyzer cannot handle the initialization of an array with a for loop
  2023-03-19  8:57 [Bug analyzer/109190] New: GCC Static Analyzer cannot handle the initialization of an array with a for loop geoffreydgr at icloud dot com
@ 2023-04-03 12:59 ` geoffreydgr at icloud dot com
  2023-04-03 13:39 ` xry111 at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: geoffreydgr at icloud dot com @ 2023-04-03 12:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Geoffrey <geoffreydgr at icloud dot com> ---
Hi, David! Could you spare a little time to explain this case to me? Thanks a
loooot!

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

* [Bug analyzer/109190] GCC Static Analyzer cannot handle the initialization of an array with a for loop
  2023-03-19  8:57 [Bug analyzer/109190] New: GCC Static Analyzer cannot handle the initialization of an array with a for loop geoffreydgr at icloud dot com
  2023-04-03 12:59 ` [Bug analyzer/109190] " geoffreydgr at icloud dot com
@ 2023-04-03 13:39 ` xry111 at gcc dot gnu.org
  2023-04-08 14:44 ` geoffreydgr at icloud dot com
  2023-04-10 20:18 ` StevenSun2021 at hotmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-04-03 13:39 UTC (permalink / raw)
  To: gcc-bugs

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

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

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

--- Comment #2 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
With -O0 GCC does not attempt to analyze any loops.  I doubt if "-O0
-fanalyzer" really makes sense.  Maybe we should just emit a warning when
-fanalyzer is used with -O0.

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

* [Bug analyzer/109190] GCC Static Analyzer cannot handle the initialization of an array with a for loop
  2023-03-19  8:57 [Bug analyzer/109190] New: GCC Static Analyzer cannot handle the initialization of an array with a for loop geoffreydgr at icloud dot com
  2023-04-03 12:59 ` [Bug analyzer/109190] " geoffreydgr at icloud dot com
  2023-04-03 13:39 ` xry111 at gcc dot gnu.org
@ 2023-04-08 14:44 ` geoffreydgr at icloud dot com
  2023-04-10 20:18 ` StevenSun2021 at hotmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: geoffreydgr at icloud dot com @ 2023-04-08 14:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Geoffrey <geoffreydgr at icloud dot com> ---
(In reply to Xi Ruoyao from comment #2)
> With -O0 GCC does not attempt to analyze any loops.  I doubt if "-O0
> -fanalyzer" really makes sense.  Maybe we should just emit a warning when
> -fanalyzer is used with -O0.

Could you explain why GCC does not attempt to analyze any loops with -O0 ? 
Because it depends some optimization passes to help handling loops?

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

* [Bug analyzer/109190] GCC Static Analyzer cannot handle the initialization of an array with a for loop
  2023-03-19  8:57 [Bug analyzer/109190] New: GCC Static Analyzer cannot handle the initialization of an array with a for loop geoffreydgr at icloud dot com
                   ` (2 preceding siblings ...)
  2023-04-08 14:44 ` geoffreydgr at icloud dot com
@ 2023-04-10 20:18 ` StevenSun2021 at hotmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: StevenSun2021 at hotmail dot com @ 2023-04-10 20:18 UTC (permalink / raw)
  To: gcc-bugs

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

Steven Sun <StevenSun2021 at hotmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |StevenSun2021 at hotmail dot com

--- Comment #4 from Steven Sun <StevenSun2021 at hotmail dot com> ---
The analyzer is implemented as a ipa pass, which eats codes partially optimized
by the middle end, or the optimizer.

Your code presented to the analyzer looks like this in -O1

https://godbolt.org/z/KdaKW5Yae
```
int main ()
{
  int j;
  goto <bb 4>; [100.00%]
  <bb 3> [local count: 536870913]:
  j_4 = j_1 + 1;
  <bb 4> [local count: 1073741824]:
  if (j_1 <= 0)
    goto <bb 3>; [50.00%]
  else
    goto <bb 5>; [50.00%]
  <bb 5> [local count: 536870913]:
  return 0;
}
```

And it looks like this in -O2
https://godbolt.org/z/rrjdaM4WP

```
int main ()
{
  MEM[(int *)0B] = 1;
  return 0;
}
```

The analyzer outputs should be definitely different.

I am not here to what causes this, but in case you're interested, you can use
godbolt to check all optimize passes.

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

end of thread, other threads:[~2023-04-10 20:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-19  8:57 [Bug analyzer/109190] New: GCC Static Analyzer cannot handle the initialization of an array with a for loop geoffreydgr at icloud dot com
2023-04-03 12:59 ` [Bug analyzer/109190] " geoffreydgr at icloud dot com
2023-04-03 13:39 ` xry111 at gcc dot gnu.org
2023-04-08 14:44 ` geoffreydgr at icloud dot com
2023-04-10 20:18 ` StevenSun2021 at hotmail 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).