All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicholas Mc Guire <hofrat@osadl.org>
To: Julia Lawall <Julia.Lawall@lip6.fr>
Cc: Gilles Muller <Gilles.Muller@lip6.fr>,
	Nicolas Palix <nicolas.palix@imag.fr>,
	Michal Marek <mmarek@suse.cz>,
	cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org,
	Nicholas Mc Guire <hofrat@osadl.org>
Subject: [PATCH RFC] Coccinelle: Check for return not matching function signature
Date: Tue,  5 May 2015 12:12:41 +0200	[thread overview]
Message-ID: <1430820761-28122-1-git-send-email-hofrat@osadl.org> (raw)

Check if the signature of a function and the return value type match. This
is currently not the case in more than 2300 functions. In many cases this
mismatch will have no side-effects but in some cases it may lead to hard
to locate problems - and for readability and code understanding it is also
helpful when types match.

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
---

Did not see any false positives in a scan of 4.0-rc2 (but did not check
all results either).

Not sure if scripts/coccinelle/tests/ is the right place for this
It did not seem to trigger any false positives but in some cases (notably
void pointers) the warning might be unnecessary.

The output is a bit lengthy - not sure if that is too much but it seemed
useful to me to see the non-matching types explicitly in the warning
message.

Patch is against 4.1-rc2 (localversion-next is -next-20150505)

 .../coccinelle/tests/signature_matches_ret.cocci   |   31 ++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 scripts/coccinelle/tests/signature_matches_ret.cocci

diff --git a/scripts/coccinelle/tests/signature_matches_ret.cocci b/scripts/coccinelle/tests/signature_matches_ret.cocci
new file mode 100644
index 0000000..2dd1086
--- /dev/null
+++ b/scripts/coccinelle/tests/signature_matches_ret.cocci
@@ -0,0 +1,31 @@
+// Find functions where return type and signature do not match
+// Comments:
+// Options: --no-includes --include-headers
+
+virtual context
+virtual org
+virtual report
+
+@match@
+identifier f,ret;
+position p;
+type T1,T2;
+@@
+
+T1 f(...) {
+ T2 ret;
+<+...
+* return@p ret
+;
+...+>
+}
+
+@script:python@
+p << match.p;
+fn << match.f;
+T1 << match.T1;
+T2 << match.T2;
+@@
+
+if T1 != T2:
+   print "%s:%s,%s WARNING: return of wrong type (%s != %s)" % (p[0].file,fn,p[0].line,T1,T2)
-- 
1.7.10.4


WARNING: multiple messages have this Message-ID (diff)
From: hofrat@osadl.org (Nicholas Mc Guire)
To: cocci@systeme.lip6.fr
Subject: [Cocci] [PATCH RFC] Coccinelle: Check for return not matching function signature
Date: Tue,  5 May 2015 12:12:41 +0200	[thread overview]
Message-ID: <1430820761-28122-1-git-send-email-hofrat@osadl.org> (raw)

Check if the signature of a function and the return value type match. This
is currently not the case in more than 2300 functions. In many cases this
mismatch will have no side-effects but in some cases it may lead to hard
to locate problems - and for readability and code understanding it is also
helpful when types match.

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
---

Did not see any false positives in a scan of 4.0-rc2 (but did not check
all results either).

Not sure if scripts/coccinelle/tests/ is the right place for this
It did not seem to trigger any false positives but in some cases (notably
void pointers) the warning might be unnecessary.

The output is a bit lengthy - not sure if that is too much but it seemed
useful to me to see the non-matching types explicitly in the warning
message.

Patch is against 4.1-rc2 (localversion-next is -next-20150505)

 .../coccinelle/tests/signature_matches_ret.cocci   |   31 ++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 scripts/coccinelle/tests/signature_matches_ret.cocci

diff --git a/scripts/coccinelle/tests/signature_matches_ret.cocci b/scripts/coccinelle/tests/signature_matches_ret.cocci
new file mode 100644
index 0000000..2dd1086
--- /dev/null
+++ b/scripts/coccinelle/tests/signature_matches_ret.cocci
@@ -0,0 +1,31 @@
+// Find functions where return type and signature do not match
+// Comments:
+// Options: --no-includes --include-headers
+
+virtual context
+virtual org
+virtual report
+
+ at match@
+identifier f,ret;
+position p;
+type T1,T2;
+@@
+
+T1 f(...) {
+ T2 ret;
+<+...
+* return@p ret
+;
+...+>
+}
+
+ at script:python@
+p << match.p;
+fn << match.f;
+T1 << match.T1;
+T2 << match.T2;
+@@
+
+if T1 != T2:
+   print "%s:%s,%s WARNING: return of wrong type (%s != %s)" % (p[0].file,fn,p[0].line,T1,T2)
-- 
1.7.10.4

             reply	other threads:[~2015-05-05 10:21 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-05 10:12 Nicholas Mc Guire [this message]
2015-05-05 10:12 ` [Cocci] [PATCH RFC] Coccinelle: Check for return not matching function signature Nicholas Mc Guire
2015-05-05 12:32 ` SF Markus Elfring
2015-05-05 12:32   ` [Cocci] " SF Markus Elfring
2015-05-05 13:04   ` Nicholas Mc Guire
2015-05-05 13:04     ` [Cocci] " Nicholas Mc Guire
2015-05-05 13:29     ` Julia Lawall
2015-05-05 13:29       ` Julia Lawall
2015-05-05 13:45     ` SF Markus Elfring
2015-05-05 13:45       ` [Cocci] " SF Markus Elfring
2015-05-05 14:40 ` Julia Lawall
2015-05-05 14:40   ` [Cocci] " Julia Lawall
2015-05-05 16:00   ` Nicholas Mc Guire
2015-05-05 16:00     ` [Cocci] " Nicholas Mc Guire
2015-05-05 21:24     ` Julia Lawall
2015-05-05 21:24       ` [Cocci] " Julia Lawall
2015-05-08  6:59       ` Nicholas Mc Guire
2015-05-08  6:59         ` [Cocci] " Nicholas Mc Guire
2015-05-05 16:25   ` SF Markus Elfring
2015-05-05 16:25     ` [Cocci] " SF Markus Elfring
2015-05-05 21:46     ` Julia Lawall
2015-05-05 21:46       ` [Cocci] " Julia Lawall
2015-05-06  7:15 ` SF Markus Elfring
2015-05-06  7:15   ` [Cocci] " SF Markus Elfring
2015-05-06  7:15   ` SF Markus Elfring

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=1430820761-28122-1-git-send-email-hofrat@osadl.org \
    --to=hofrat@osadl.org \
    --cc=Gilles.Muller@lip6.fr \
    --cc=Julia.Lawall@lip6.fr \
    --cc=cocci@systeme.lip6.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmarek@suse.cz \
    --cc=nicolas.palix@imag.fr \
    /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.