public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dmalcolm at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug analyzer/106325] `analyzer-null-dereference` gets thrown on a parameter on a function marked with `__attribute__((nonnull))`
Date: Sat, 16 Jul 2022 15:36:40 +0000	[thread overview]
Message-ID: <bug-106325-4-I37WsH32Jx@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-106325-4@http.gcc.gnu.org/bugzilla/>

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

David Malcolm <dmalcolm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-07-16

--- Comment #3 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Thanks for filing this bug report.

Near the start of the analysis, it sees:

  ‘arranger_object_unsplit’: event 1
    |
    |../src/gui/backend/arranger_object.c:3021:1:
    | 3021 | arranger_object_unsplit (
    |      | ^~~~~~~~~~~~~~~~~~~~~~~
    |      | |
    |      | (1) entry to ‘arranger_object_unsplit’
    |
  ‘arranger_object_unsplit’: event 2
    |
    |../src/gui/backend/arranger_object.c:3043:10:
    | 3043 |   *obj = arranger_object_clone (r1);
    |      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |          |
    |      |          (2) calling ‘arranger_object_clone’ from
‘arranger_object_unsplit’
    |
    +--> ‘arranger_object_clone’: events 3-6
           |
           |../src/gui/backend/arranger_object.c:2568:1:
           | 2568 | arranger_object_clone (const ArrangerObject * self)
           |      | ^~~~~~~~~~~~~~~~~~~~~
           |      | |
           |      | (3) entry to ‘arranger_object_clone’
           | 2569 | {
           | 2570 |   g_return_val_if_fail (self, NULL);
           |      |           ~                   ~~~~~~                        
           |      |           |                   |                            
                                                  |
           |      |           |                   (5) ...to here               
                                 (6) ‘r1’ is NULL
           |      |           (4) following ‘false’ branch (when ‘self’ is
NULL)...
           |
    <------+

...and so within the g_return_val_if_fail in arranger_object_clone it considers
the case in which "self" (and thus the "r1" param passed to
arranger_object_unsplit) is NULL.

However, I see this declaration in the preprocessed code:

__attribute__((nonnull(1, 2)))
void
arranger_object_unsplit (
  ArrangerObject * r1,
  ArrangerObject * r2,
  ArrangerObject ** obj,
 _Bool fire_events);

and hence the analyzer *ought* to be assuming that r1 and r2 are non-NULL, and
thus not consider the early-bailout case in that g_return_val_if_fail.

Looks like a bug in the analyzer to me; marking as confirmed (reproduced on gcc
trunk).

  parent reply	other threads:[~2022-07-16 15:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-16 13:11 [Bug analyzer/106325] New: " alex at zrythm dot org
2022-07-16 13:14 ` [Bug analyzer/106325] " alex at zrythm dot org
2022-07-16 13:25 ` alex at zrythm dot org
2022-07-16 15:36 ` dmalcolm at gcc dot gnu.org [this message]
2022-12-05 22:58 ` [Bug analyzer/106325] -Wanalyzer-null-dereference false positive due to analyzer not making assumptions for `__attribute__((nonnull))` dmalcolm at gcc dot gnu.org
2022-12-05 23:00 ` dmalcolm at gcc dot gnu.org
2022-12-05 23:08 ` dmalcolm at gcc dot gnu.org
2022-12-06 18:28 ` cvs-commit at gcc dot gnu.org
2022-12-06 18:56 ` dmalcolm at gcc dot gnu.org
2023-03-29 18:18 ` cvs-commit at gcc dot gnu.org
2023-03-29 19:29 ` 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-106325-4-I37WsH32Jx@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).