From: Pavel Roskin <proski@gnu.org>
To: linux-sparse@vger.kernel.org
Subject: Bogus locking warnings
Date: Mon, 26 Feb 2007 20:42:32 -0500 [thread overview]
Message-ID: <1172540552.5835.41.camel@dv> (raw)
Hello!
The current sparse issues a warning about this file:
void my_lock(void) __attribute__ ((context(lock, 0, 1)));
void my_unlock(void) __attribute__ ((context(lock, 1, 0)));
void foo(void);
static void bar(const int locked)
{
if (!locked)
my_lock();
foo();
if (!locked)
my_unlock();
}
$ sparse test.c
test.c:10:3: warning: context imbalance in 'bar' - unexpected unlock
Commenting out foo() call eliminated the warning. I understand that
sparse suspects that foo() could change "locked".
Changing "int locked" to "const int locked" makes no difference. I
don't see what else could be done to tell sparse that "locked" won't
change throughout the function call.
Something interesting happens if I change "!locked" to "locked" in both
places:
$ sparse test.c
test.c:9:2: warning: context imbalance in 'bar' - different lock
contexts for basic block
Although sparse doesn't know anything about the semantic of "locked", it
issues different warnings whether the variable is used "positively" or
"negatively". No amount of paranoia about foo() can excuse this
inconsistency.
--
Regards,
Pavel Roskin
next reply other threads:[~2007-02-27 1:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-27 1:42 Pavel Roskin [this message]
2007-02-27 4:19 ` Bogus locking warnings Linus Torvalds
2007-02-27 7:24 ` Pavel Roskin
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=1172540552.5835.41.camel@dv \
--to=proski@gnu.org \
--cc=linux-sparse@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.