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/112790] New: -Wanalyzer-deref-before-check false positives seen in Linux kernel due to inlining Date: Thu, 30 Nov 2023 21:14:20 +0000 [thread overview] Message-ID: <bug-112790-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112790 Bug ID: 112790 Summary: -Wanalyzer-deref-before-check false positives seen in Linux kernel due to inlining Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: analyzer Assignee: dmalcolm at gcc dot gnu.org Reporter: dmalcolm at gcc dot gnu.org Target Milestone: --- https://godbolt.org/z/4fjjcfbPb False positive on: typedef unsigned char u8; struct inode { void *i_mapping; u8 i_blkbits; }; struct block_device { struct inode *bd_inode; }; int sync_blockdev(struct block_device *bdev); int set_blocksize(struct block_device *bdev, u8 size) { if (bdev->bd_inode->i_blkbits != size) { sync_blockdev(bdev); } return 0; } extern int filemap_write_and_wait(void *); int sync_blockdev(struct block_device *bdev) { if (!bdev) return 0; return filemap_write_and_wait(bdev->bd_inode->i_mapping); } $ xgcc B. -Wall -fno-delete-null-pointer-checks -O2 -fanalyzer -g -S False positive: In function ‘sync_blockdev’, inlined from ‘set_blocksize’ at t.c:12:5: t.c:18:6: warning: check of ‘bdev’ for NULL after already dereferencing it [-Wanalyzer-deref-before-check] 18 | if (!bdev) | ^ ‘set_blocksize’: events 1-4 | | 11 | if (bdev->bd_inode->i_blkbits != size) { | | ~~~~~^~~~~~~~~~ | | | | | | | (1) pointer ‘bdev’ is dereferenced here | | (2) following ‘true’ branch... | 12 | sync_blockdev(bdev); | | ~~~~~~~~~~~~~ | | | | | (3) ...to here | | (4) inlined call to ‘sync_blockdev’ from ‘set_blocksize’ | +--> ‘sync_blockdev’: event 5 | | 18 | if (!bdev) | | ^ | | | | | (5) pointer ‘bdev’ is checked for NULL here but it was already dereferenced at (1) | The check from the inlined function shouldn't lead to this warning. All of "-fno-delete-null-pointer-checks -O2 -fanalyzer -g" seem to be necessary. (reduced from block/bdev.c)
next reply other threads:[~2023-11-30 21:14 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-11-30 21:14 dmalcolm at gcc dot gnu.org [this message] 2023-11-30 21:16 ` [Bug analyzer/112790] " dmalcolm at gcc dot gnu.org 2024-01-04 14:16 ` cvs-commit at gcc dot gnu.org 2024-01-04 14:21 ` cvs-commit at gcc dot gnu.org 2024-01-04 15:06 ` dmalcolm at gcc dot gnu.org 2024-04-14 5:20 ` [Bug analyzer/112790] [13 Regression] " pinskia at gcc dot gnu.org 2024-05-09 17:11 ` cvs-commit at gcc dot gnu.org 2024-05-09 17:52 ` [Bug analyzer/112790] " 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-112790-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: linkBe 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).