public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "geoffreydgr at icloud dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug analyzer/108739] New: GCC Static Analyzer evaluates `a > b `to be TRUE but evaluates `b < a` to be UNKNOWN
Date: Thu, 09 Feb 2023 08:10:56 +0000	[thread overview]
Message-ID: <bug-108739-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 108739
           Summary: GCC Static Analyzer evaluates `a > b `to be TRUE but
                    evaluates `b < a` to be UNKNOWN
           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 GSA evaluates `a > b `to be TRUE but
evaluates `b < a` to be UNKNOWN. I think that in the True branch of `if(a>b)`
there should exist a constraint, and then GSA can evaluates `b < a` to be
FALSE.

Compiling the following test case with gcc (trunk) with options "-fanalyzer ". 
 https://godbolt.org/z/7EWreG66W
Input
```c
#include "stdint.h"
#include "stdio.h"
#include <stdbool.h>
extern void __analyzer_describe ();
extern void __analyzer_eval ();
extern void __analyzer_dump ();
extern void __analyzer_dump_state (const char *name, ...);
extern void __analyzer_dump_region_model ();

void foo (size_t size)
{
  size_t a = size + 2;
  size_t b = size + 1;
  __analyzer_dump ();
  if(a > b){
    __analyzer_dump ();
    __analyzer_eval (a > b);
    __analyzer_eval (b < a);
    __analyzer_eval (b > a);
  }

}
```

Output:
```
rmodel:
stack depth: 1
  frame (index 0): frame: 'foo'@1
clusters within frame: 'foo'@1
  cluster for: a_9: (INIT_VAL(size_8(D))+(size_t)2)
  cluster for: b_10: (INIT_VAL(size_8(D))+(size_t)1)
m_called_unknown_fn: FALSE
constraint_manager:
  equiv classes:
  constraints:
rmodel:
stack depth: 1
  frame (index 0): frame: 'foo'@1
clusters within frame: 'foo'@1
  cluster for: a_9: (INIT_VAL(size_8(D))+(size_t)2)
  cluster for: b_10: (INIT_VAL(size_8(D))+(size_t)1)
m_called_unknown_fn: FALSE
constraint_manager:
  equiv classes:
  constraints:
<source>: In function 'foo':
<source>:17:5: warning: TRUE
   17 |     __analyzer_eval (a > b);
      |     ^~~~~~~~~~~~~~~~~~~~~~~
<source>:18:5: warning: UNKNOWN
   18 |     __analyzer_eval (b < a);
      |     ^~~~~~~~~~~~~~~~~~~~~~~
<source>:19:5: warning: UNKNOWN
   19 |     __analyzer_eval (b > a);
      |     ^~~~~~~~~~~~~~~~~~~~~~~
Compiler returned: 0
```

                 reply	other threads:[~2023-02-09  8:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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