public inbox for cocci@systeme.lip6.fr
 help / color / mirror / Atom feed
* [Cocci] Inter-procedural analysis.
@ 2012-12-22 20:39 Cyril Roelandt
  2012-12-22 20:49 ` Julia Lawall
  0 siblings, 1 reply; 6+ messages in thread
From: Cyril Roelandt @ 2012-12-22 20:39 UTC (permalink / raw)
  To: cocci

Hello!

I was trying to find cases of double mutex unlocks in the Hurd, and 
wrote a very simple semantic patch:

@exists@
expression E;
@@
* pthread_mutex_unlock(E);
... when != pthread_mutex_lock(E)
* pthread_mutex_unlock(E);

This works as expected with this snippet of C code:

static void
foo(void)
{
	pthread_mutex_lock(&lock);
	do_stg();
	pthread_mutex_unlock(&lock);
	if (some_condition)
		pthread_mutex_unlock(&lock);
}

--- x.c
+++ /tmp/cocci-output-4955-ff7d08-x.c
@@ -3,7 +3,5 @@ foo(void)
  {
  	pthread_mutex_lock(&lock);
  	do_stg();
-	pthread_mutex_unlock(&lock);
  	if (some_condition)
-		pthread_mutex_unlock(&lock);
  }

But it will report a false positive with this code:

static void
lock_it(pthread_mutex_t *lock)
{
	pthread_mutex_lock(lock);
}

static void
foo(void)
{
	pthread_mutex_lock(&lock);
	do_stg();
	pthread_mutex_unlock(&lock);
	lock_it(&lock);
	pthread_mutex_unlock(&lock);
}

It is perfectly fine to call pthread_mutex_unlock the second time, since 
LOCK has been re-acquired by lock_it(). Is there any way to do 
inter-procedural analysis in a semantic patch ?

Cyril Roelandt.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-12-23  7:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-22 20:39 [Cocci] Inter-procedural analysis Cyril Roelandt
2012-12-22 20:49 ` Julia Lawall
2012-12-22 21:31   ` Cyril Roelandt
2012-12-22 23:15     ` Rene Rydhof Hansen
2012-12-23  7:45       ` Julia Lawall
2012-12-23  7:33     ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox