public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/109736] New: GCC Static Analyzer evaluates `e == d + 1` to be UNKNOWN with the fact that `e == d`, e is a pointer, and d is an array
@ 2023-05-04 14:16 geoffreydgr at icloud dot com
  0 siblings, 0 replies; only message in thread
From: geoffreydgr at icloud dot com @ 2023-05-04 14:16 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109736
           Summary: GCC Static Analyzer evaluates `e == d + 1` to be
                    UNKNOWN with the fact that `e == d`, e is a pointer,
                    and d is an array
           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: ---

Hi, David. I found a problem that GCC Static Analyzer evaluates `e == d + 1` to
be UNKNOWN with the fact that `e == d`.  
Maybe GCC Static Analyzer should have the ability to evaluates `e == d + 1` to
be FALSE ?

See it live: https://godbolt.org/z/xKMxzvj6E

Input:
```c
void __analyzer_eval();
void __analyzer_describe();

void c()
{
    int d[2] = {42,43};
    int *e = d;

    if (e == d)
    {
        __analyzer_describe(0, e);
        __analyzer_describe(0, e + 1);
        __analyzer_describe(0, d + 1);

        __analyzer_eval(e == d + 1);
        __analyzer_eval(e + 1 == d + 1);
    }
}
```

Output:
```bash
<source>: In function 'c':
<source>:11:9: warning: svalue: '&d'
   11 |         __analyzer_describe(0, e);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~
<source>:12:9: warning: svalue: '(&d+(sizetype)4)'
   12 |         __analyzer_describe(0, &d + 1);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:14:9: warning: UNKNOWN
   14 |         __analyzer_eval(e == &d + 1);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:15:9: warning: TRUE
   15 |         __analyzer_eval(e + 1 == &d + 1);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compiler returned: 0

```

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-05-04 14:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-04 14:16 [Bug analyzer/109736] New: GCC Static Analyzer evaluates `e == d + 1` to be UNKNOWN with the fact that `e == d`, e is a pointer, and d is an array geoffreydgr at icloud 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).