public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Olien <dmo@osdl.org>
To: torvalds@transmeta.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] sparse type checking on function pointers
Date: Tue, 10 Jun 2003 14:24:04 -0700	[thread overview]
Message-ID: <20030610212404.GA25410@osdl.org> (raw)


This patch fixes type checking on function arguments that are pointers
to functions.  Below is an example.

int total;

void dofunc(void (f)(int))
{
	f(5);
}

void func(int z)
{
	total += z;
}

main(void)
{
	dofunc(func);
}

without this patch, check reports the warnings:

warning: testfunc.c:16:9: incorrect type in argument 1 (different base types)
warning: testfunc.c:16:9:   expected void ( f )( ... )
warning: testfunc.c:16:9:   got void ( * )( ... )

------------------------------------------------------------------------

--- sparse_original/evaluate.c	2003-06-03 09:00:47.000000000 -0700
+++ sparse_test/evaluate.c	2003-06-10 12:08:23.000000000 -0700
@@ -431,6 +431,17 @@
 			/* Ignore ARRAY/PTR differences, as long as they point to the same type */
 			type1 = type1 == SYM_ARRAY ? SYM_PTR : type1;
 			type2 = type2 == SYM_ARRAY ? SYM_PTR : type2;
+
+			if ((type1 == SYM_PTR) && (target->ctype.base_type->type == SYM_FN)) {
+				target = target->ctype.base_type;
+				type1 = SYM_FN;
+			}
+
+			if ((type2 == SYM_PTR) && (source->ctype.base_type->type == SYM_FN)) {
+				source = source->ctype.base_type;
+				type2 = SYM_FN;
+			}
+
 			if (type1 != type2)
 				return "different base types";
 		}

             reply	other threads:[~2003-06-10 21:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-10 21:24 Dave Olien [this message]
2003-06-10 22:33 ` [PATCH] sparse type checking on function pointers Steven Cole
2003-06-10 23:03   ` Dave Olien
2003-06-10 23:06     ` Linus Torvalds
2003-06-11  7:39       ` Kevin O'Connor

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=20030610212404.GA25410@osdl.org \
    --to=dmo@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /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