public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "vincent-gcc at vinc17 dot net" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug analyzer/94732] New: Analyzer: false positive in MPFR's atan.c
Date: Thu, 23 Apr 2020 14:58:46 +0000	[thread overview]
Message-ID: <bug-94732-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 94732
           Summary: Analyzer: false positive in MPFR's atan.c
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: vincent-gcc at vinc17 dot net
  Target Milestone: ---

Created attachment 48360
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48360&action=edit
testcase

Test with: gcc-10 (Debian 10-20200418-1) 10.0.1 20200418 (experimental) [master
revision 27c171775ab:4c277008be0:c5bac7d127f288fd2f8a1f15c3f30da5903141c6]

When I want to compile GNU MPFR with -fanalyzer, the compilation of atan.c
fails on what appears to be a false positive. I've managed to reduce the
6000-line preprocessed code to code with fewer than 300 lines (attached bug.i
file). More specifically, I've removed
  * blank lines and comments;
  * unused declarations/definitions;
  * code that could have an influence only after the "error";
  * code testing and handling special cases.

I order to see where the issue could come from, I've added 2 lines
  * "((y)->_mpfr_d)[0] = 0;" at the beginning of mpfr_atan_aux;
  * "((tmp2)->_mpfr_d)[0] = 0;" just before the call to mpfr_atan_aux.

Without these 2 lines, "gcc-10 -c -fanalyzer bug.i" gives:

bug.i: In function ‘set_table’:
bug.i:145:9: warning: use of uninitialized value ‘yp’ [CWE-457]
[-Wanalyzer-use-of-uninitialized-value]
  145 |   yp[0] &= ~(((void) 0), sh ==
      |         ^~

where yp is set with

  mp_limb_t *yp = ((y)->_mpfr_d);

So I suppose that the analyzer complains that (y)->_mpfr_d is uninitialized.
This comes from mpfr_atan_aux, and "((y)->_mpfr_d)[0] = 0;" at the beginning of
this function should trigger the same error. If I add this line, I get in a
consistent way:

bug.i: In function ‘mpfr_atan_aux’:
bug.i:154:19: warning: use of uninitialized value ‘<unknown>’ [CWE-457]
[-Wanalyzer-use-of-uninitialized-value]
  154 | ((y)->_mpfr_d)[0] = 0;
      | ~~~~~~~~~~~~~~~~~~^~~

This mpfr_atan_aux function is called at only one place:

              mpfr_atan_aux (tmp2, ukz, twopoweri, n0 - i, tabz);

So I added "((tmp2)->_mpfr_d)[0] = 0;" just before this call. I thought that I
would get an error on this, but I still get an error only on "((y)->_mpfr_d)[0]
= 0;" in mpfr_atan_aux. If I remove this line (just keeping the one before the
call to mpfr_atan_aux), I get the error in set_table only, just like in the
first test.

Now, this appears to be a false positif since (tmp2)->_mpfr_d was initialized
earlier.

I could probably simplify the code even further, focusing on (tmp2)->_mpfr_d
only.

             reply	other threads:[~2020-04-23 14:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-23 14:58 vincent-gcc at vinc17 dot net [this message]
2020-04-23 18:36 ` [Bug analyzer/94732] " vincent-gcc at vinc17 dot net
2020-04-28 13:26 ` cvs-commit at gcc dot gnu.org
2020-04-28 13:34 ` dmalcolm at gcc dot gnu.org

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