public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sparse type checking on function pointers
@ 2003-06-10 21:24 Dave Olien
  2003-06-10 22:33 ` Steven Cole
  0 siblings, 1 reply; 5+ messages in thread
From: Dave Olien @ 2003-06-10 21:24 UTC (permalink / raw)
  To: torvalds; +Cc: linux-kernel


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";
 		}

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

* Re: [PATCH] sparse type checking on function pointers
  2003-06-10 21:24 [PATCH] sparse type checking on function pointers Dave Olien
@ 2003-06-10 22:33 ` Steven Cole
  2003-06-10 23:03   ` Dave Olien
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Cole @ 2003-06-10 22:33 UTC (permalink / raw)
  To: Dave Olien; +Cc: Linus Torvalds, linux-kernel

On Tue, 2003-06-10 at 15:24, Dave Olien wrote:
> This patch fixes type checking on function arguments that are pointers
> to functions.  Below is an example.
> 
That reduced the number of that kind of warning significantly.

[steven@spc1 testing-2.5]$ grep "different base types" build4 | grep "in argument" | wc -l
     37
[steven@spc1 testing-2.5]$ grep "different base types" build5 | grep "in argument" | wc -l
      4
[steven@spc1 testing-2.5]$ grep "different base types" build5 | grep "in argument"
warning: include/linux/mpage.h:24:40: incorrect type in argument 3 (different base types)
warning: include/linux/mpage.h:24:40: incorrect type in argument 3 (different base types)
warning: drivers/ide/ide.c:1872:26: incorrect type in argument 2 (different base types)
warning: drivers/ide/ide.c:1947:25: incorrect type in argument 2 (different base types)

Now, if only Linus would change this:

CHECK           = /home/torvalds/parser/check

to something more reasonable like

CHECK           = /usr/local/bin/check

Steven



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

* Re: [PATCH] sparse type checking on function pointers
  2003-06-10 22:33 ` Steven Cole
@ 2003-06-10 23:03   ` Dave Olien
  2003-06-10 23:06     ` Linus Torvalds
  0 siblings, 1 reply; 5+ messages in thread
From: Dave Olien @ 2003-06-10 23:03 UTC (permalink / raw)
  To: Steven Cole; +Cc: Linus Torvalds, linux-kernel

On Tue, Jun 10, 2003 at 04:33:20PM -0600, Steven Cole wrote:
>
> That reduced the number of that kind of warning significantly.
> 

Thanks! I'm still kind of groping my way through the code, fixing
these warnings as a motivator to keep me working my way through it.

> 
> Now, if only Linus would change this:
> 
> CHECK           = /home/torvalds/parser/check
> 
> to something more reasonable like
> 
> CHECK           = /usr/local/bin/check
> 
> Steven
> 

I assume Linus has done this because the sparse library is still
a prototype, and the "check" binary is not really the intended end point
but just a simple front-end to invoke the library to test it.

I find it really easy to just over-ride this on the make command line:

	make CHECK=/dmo_local/BK_TREES/sparse_original/check C=1

This makes it easy for me to test different versions of the library as
I'm making modifications either to fix a problem, or to put debug statements
into the source code to undestand it.

Combine this with a good shell that supports history editing, and it's
not really a big problem.

Dave

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

* Re: [PATCH] sparse type checking on function pointers
  2003-06-10 23:03   ` Dave Olien
@ 2003-06-10 23:06     ` Linus Torvalds
  2003-06-11  7:39       ` Kevin O'Connor
  0 siblings, 1 reply; 5+ messages in thread
From: Linus Torvalds @ 2003-06-10 23:06 UTC (permalink / raw)
  To: Dave Olien; +Cc: Steven Cole, linux-kernel


On Tue, 10 Jun 2003, Dave Olien wrote:
>
> I find it really easy to just over-ride this on the make command line:
> 
> 	make CHECK=/dmo_local/BK_TREES/sparse_original/check C=1

Yeah. That said, I agree with the complaint and there really is no excuse 
for the bad default values except for me being a lazy bastard. So I'm 
checking in a "make install" target for sparse, and I'll make the default 
CHECK binary be "sparse".

		Linus


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

* Re: [PATCH] sparse type checking on function pointers
  2003-06-10 23:06     ` Linus Torvalds
@ 2003-06-11  7:39       ` Kevin O'Connor
  0 siblings, 0 replies; 5+ messages in thread
From: Kevin O'Connor @ 2003-06-11  7:39 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel

On Tue, Jun 10, 2003 at 04:06:46PM -0700, Linus Torvalds wrote:
>So I'm
> checking in a "make install" target for sparse, and I'll make the default
> CHECK binary be "sparse".

Hi Linus,

The name "sparse" is very difficult to google for because it's a common
English word.  It can also make comments and emails confusing when one
doesn't immediately know which meaning of "sparse" is being used.  Perhaps
a name like "s-parse" would be more appropriate.

-Kevin

-- 
 ------------------------------------------------------------------------
 | Kevin O'Connor                     "BTW, IMHO we need a FAQ for      |
 | kevin@koconnor.net                  'IMHO', 'FAQ', 'BTW', etc. !"    |
 ------------------------------------------------------------------------

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

end of thread, other threads:[~2003-06-11  7:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-10 21:24 [PATCH] sparse type checking on function pointers Dave Olien
2003-06-10 22:33 ` Steven Cole
2003-06-10 23:03   ` Dave Olien
2003-06-10 23:06     ` Linus Torvalds
2003-06-11  7:39       ` Kevin O'Connor

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