From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 82D673858D35; Sun, 19 Mar 2023 12:54:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 82D673858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679230485; bh=2+6WvKgBK8tEdD24IRBpb2117yYg/aEvi9f327RuPmA=; h=From:To:Subject:Date:From; b=GjaWDxj9TbJUl7ouq+KmiIccxUjrlQOhNb5NHlIFsStB85BMLQFZoNbzTxDmrMxyG 7pFbK8a3bILi1CDyEKi/xfhJhSLtC513ko4ODQm4WhouFeiS4O9a2WmS6hESxs0A9u ED2jkD5GqNJalbpC19G6oFNvzZF8dzFMazwHnERQ= From: "geoffreydgr at icloud dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/109194] New: GCC Static Analyzer does not know "a+3 > b+1" in the true branch of "if (a > b) ", but it knows "a+2 > b+1" Date: Sun, 19 Mar 2023 12:54:45 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: analyzer X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: geoffreydgr at icloud dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: dmalcolm at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109194 Bug ID: 109194 Summary: GCC Static Analyzer does not know "a+3 > b+1" in the true branch of "if (a > b) ", but it knows "a+2 > b+1" 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 found a problem that GCC Static Analyzer does not know "a+3 > b+1" (line = 14) in the true branch of "if (a > b) ", but it knows "a+2 > b+1" (line 13) . I run gcc (trunk) with options `-fanalyzer -O0`. See it live: https://godbolt.org/z/61nMxo7Kv Input: ```c #include #include int main(int a, int b, int c, int d) { if ((a>b)){ __analyzer_eval(a>b); __analyzer_eval(!(a>b) =3D=3D false); __analyzer_eval(-a < -b); __analyzer_eval(0-a < 0-b); __analyzer_eval( a+0 > b+0); __analyzer_eval( a+1 > b+1); __analyzer_eval( a+2 > b+2); __analyzer_eval( a+2 > b+1); __analyzer_eval( a+3 > b+1); __analyzer_eval( a*0 > b*0 =3D=3D false); __analyzer_eval( a*1 > b*1); __analyzer_eval( a*2 > b*2); __analyzer_eval( a*3 > b*2); } } ``` Output: ```bash : In function 'main': :6:9: warning: implicit declaration of function '__analyzer_eval' [-Wimplicit-function-declaration] 6 | __analyzer_eval(a>b); | ^~~~~~~~~~~~~~~ :6:9: warning: TRUE 6 | __analyzer_eval(a>b); | ^~~~~~~~~~~~~~~~~~~~ :7:9: warning: TRUE 7 | __analyzer_eval(!(a>b) =3D=3D false); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :8:9: warning: TRUE 8 | __analyzer_eval(-a < -b); | ^~~~~~~~~~~~~~~~~~~~~~~~ :9:9: warning: TRUE 9 | __analyzer_eval(0-a < 0-b); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ :10:9: warning: TRUE 10 | __analyzer_eval( a+0 > b+0); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ :11:9: warning: TRUE 11 | __analyzer_eval( a+1 > b+1); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ :12:9: warning: TRUE 12 | __analyzer_eval( a+2 > b+2); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ :13:9: warning: TRUE 13 | __analyzer_eval( a+2 > b+1); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ :14:9: warning: UNKNOWN 14 | __analyzer_eval( a+3 > b+1); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ :15:9: warning: TRUE 15 | __analyzer_eval( a*0 > b*0 =3D=3D false); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :16:9: warning: TRUE 16 | __analyzer_eval( a*1 > b*1); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ :17:9: warning: TRUE 17 | __analyzer_eval( a*2 > b*2); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ :18:9: warning: TRUE 18 | __analyzer_eval( a*3 > b*2); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ Compiler returned: 0 ```=