public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug analyzer/108806] -Wanalyzer-null-dereference false positives due to not handling bitmasks
Date: Thu, 16 Feb 2023 23:14:53 +0000	[thread overview]
Message-ID: <bug-108806-4-BlqbcZzUJe@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-108806-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by David Malcolm <dmalcolm@gcc.gnu.org>:

https://gcc.gnu.org/g:4d3b7be281e73ecdaa233598db1a8390422b7770

commit r13-6101-g4d3b7be281e73ecdaa233598db1a8390422b7770
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Thu Feb 16 18:12:55 2023 -0500

    analyzer: respect some conditions from bit masks [PR108806]

    PR analyzer/108806 reports false +ves seen from -fanalyzer on code like
this
    in qemu-7.2.0's hw/intc/omap_intc.c:

      [...snip...]
      struct omap_intr_handler_bank_s* bank = NULL;
      if ((offset & 0xf80) == 0x80) {
        [...set "bank" to non-NULL...]
      }
      switch (offset) {
        [...snip various cases that don't deref "bank"...]
        case 0x80:
          return bank->inputs;
        case 0x84:
          return bank->mask;
        [...etc...]
       }

    where the analyzer falsely complains about execution paths in which
    "(offset & 0xf80) == 0x80" was false (leaving "bank" as NULL), but then
    in which "switch (offset)" goes to a case for which
    "(offset & 0xf80) == 0x80" is true and dereferences NULL "bank", i.e.
    paths in which "(offset & 0xf80) == 0x80" is both true *and* false.

    This patch adds enough logic to constraint_manager for -fanalyzer to
    reject such execution paths as impossible, fixing the false +ves.

    Integration testing shows this eliminates 20 probable false positives:

    Comparison: 9.08% -> 9.34% GOOD: 66 BAD: 661 -> 641 (-20)

    where the affected warnings/projects are:

      -Wanalyzer-null-dereference: 0.00% GOOD: 0 BAD: 279 -> 269 (-10)
            qemu-7.2.0: 175 -> 165 (-10)

      -Wanalyzer-use-of-uninitialized-value: 0.00% GOOD: 0 BAD: 153 -> 143
(-10)
         coreutils-9.1:  18 ->  14 (-4)
            qemu-7.2.0:  54 ->  48 (-6)

    gcc/analyzer/ChangeLog:
            PR analyzer/108806
            * constraint-manager.cc (bounded_range::dump_to_pp): Use
            bounded_range::singleton_p.
            (constraint_manager::add_bounded_ranges): Handle singleton ranges
            by adding an EQ_EXPR constraint.
            (constraint_manager::impossible_derived_conditions_p): New.
            (constraint_manager::eval_condition): Reject EQ_EXPR when it would
            imply impossible derived conditions.
            (selftest::test_bits): New.
            (selftest::run_constraint_manager_tests): Run it.
            * constraint-manager.h (bounded_range::singleton_p): New.
            (constraint_manager::impossible_derived_conditions_p): New decl.
            * region-model.cc (region_model::get_rvalue_1): Handle
            BIT_AND_EXPR, BIT_IOR_EXPR, and BIT_XOR_EXPR.

    gcc/testsuite/ChangeLog:
            PR analyzer/108806
            * gcc.dg/analyzer/null-deref-pr108806-qemu.c: New test.
            * gcc.dg/analyzer/pr103217.c: Add -Wno-analyzer-too-complex.
            * gcc.dg/analyzer/switch.c (test_bitmask_1): New.
            (test_bitmask_2): New.
            * gcc.dg/analyzer/uninit-pr108806-qemu.c: New test.

    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

  reply	other threads:[~2023-02-16 23:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-15 16:36 [Bug analyzer/108806] New: " dmalcolm at gcc dot gnu.org
2023-02-16 23:14 ` cvs-commit at gcc dot gnu.org [this message]
2023-02-16 23:20 ` [Bug analyzer/108806] " dmalcolm at gcc dot gnu.org
2024-04-14  5:06 ` [Bug analyzer/108806] [12 Regression] " pinskia at gcc dot gnu.org
2024-06-20  9:11 ` rguenth 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-108806-4-BlqbcZzUJe@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).