From: Josh Triplett <josh@joshtriplett.org>
To: Matthew Wilcox <willy@infradead.org>
Cc: linux-sparse@vger.kernel.org
Subject: Re: Unreachable code diagnostic
Date: Fri, 24 Feb 2017 10:57:07 -0800 [thread overview]
Message-ID: <20170224185707.jll2n5634hju7vy6@x> (raw)
In-Reply-To: <20170224180759.GB16328@bombadil.infradead.org>
On Fri, Feb 24, 2017 at 10:07:59AM -0800, Matthew Wilcox wrote:
> I was recently sent some code that looked like this:
>
> int foo()
> {
> lock();
> return bar();
> unlock();
> }
>
> When you're restructuring code that contains locks, this is a
> *really* easy mistake to make. I've done it myself. But there's no
> compiler warning for it! gcc doesn't have it, sparse doesn't have it.
Sparse does have a warning (via -Wcontext) for this, if you annotate
lock() and unlock() with __acquires(somelock) and __releases(somelock),
which expand to __attribute__((context(somelock,0,1))) and
__attribute__((context(somelock,0,1))) respectively. You'll get a
warning that foo() returns with the lock held.
Not at all perfect, but it does have reasonable handling of
conditionals, including a way to handle cond_lock().
next prev parent reply other threads:[~2017-02-24 18:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-24 18:07 Unreachable code diagnostic Matthew Wilcox
2017-02-24 18:33 ` Linus Torvalds
2017-02-24 20:11 ` Luc Van Oostenryck
2017-02-24 20:43 ` Josh Triplett
2017-02-24 20:47 ` Luc Van Oostenryck
2017-02-24 18:57 ` Josh Triplett [this message]
2017-02-24 19:56 ` Luc Van Oostenryck
2017-02-24 21:05 ` Matthew Wilcox
2017-02-24 19:26 ` Dan Carpenter
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=20170224185707.jll2n5634hju7vy6@x \
--to=josh@joshtriplett.org \
--cc=linux-sparse@vger.kernel.org \
--cc=willy@infradead.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 NNTP newsgroup(s).