linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "sylvain nahas" <sylvain.nahas@googlemail.com>
To: linux-sparse@vger.kernel.org
Subject: [PATCH] activate context checking when context input and output values in __attribute__() are the same and different of zero
Date: Mon, 4 Feb 2008 21:42:19 +0100	[thread overview]
Message-ID: <b98a45740802041242h35874d1fr563b92a122d30139@mail.gmail.com> (raw)

Hi,
the following patch activates context checking when context input and
output values are the same and different of zero in
__attribute__((context())), by making the parser generate a OP_CONTEXT
pseudo instruction.

Use case: specify that a function needs to be called in locked context.

Below is a sample case.
---
#define __needlock      __attribute__((context(lock,1,1)))
#define __acquire(x)	__context__(1)
#define __release(x)    __context__(-1)

static int __needlock test1(void)
{
	return 0;
}

static int __needlock test2(void)
{
	return test1(); /* OK */
}

static int test3(void)
{
        return test1(); /* should generate a warning */
}

int main(void)
{
	test1(); /* should generate a warning */
	test2(); /* should generate a warning */
	test3(); /* OK */
	__acquire();
	test1(); /* OK */
	__release();
	return -1;
}
---

I have used it on a relative big bunch of code and I believe it works well.
Thanks,

signed-off-by: Sylvain Nahas <sylvain.nahas@googlemailcom>
---
--- a/linearize.c
+++ b/linearize.c
@@ -1244,6 +1244,12 @@ static pseudo_t
linearize_call_expression(struct entrypoint *ep, struct expressi
                                out = 0;
                        }
                        context_diff = out - in;
+
+                       if( !context_diff && (in>0) ){
+                               check = 1;
+                               context_diff = in;
+                       }
+
                        if (check || context_diff) {
                                insn = alloc_instruction(OP_CONTEXT, 0);
                                insn->increment = context_diff;

             reply	other threads:[~2008-02-04 20:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-04 20:42 sylvain nahas [this message]
2008-04-21 19:17 ` [PATCH] activate context checking when context input and output values in __attribute__() are the same and different of zero Josh Triplett

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=b98a45740802041242h35874d1fr563b92a122d30139@mail.gmail.com \
    --to=sylvain.nahas@googlemail.com \
    --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 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).