All of lore.kernel.org
 help / color / mirror / Atom feed
* function designators & function pointers
@ 2017-11-26 21:58 Luc Van Oostenryck
  2017-11-27 18:23 ` Christopher Li
  0 siblings, 1 reply; 2+ messages in thread
From: Luc Van Oostenryck @ 2017-11-26 21:58 UTC (permalink / raw)
  To: linux-sparse; +Cc: Linus Torvalds, Al Viro

I've found some problems with the linearization of
function calls and/or their evaluation.
But I would like first to be sure of what is wanted here.

The problems turn around the fact that in the C standards:
1) a function designator is usually implicitly converted to a
   function pointer (C11 6.3.2.1p4)
	"(except with 'sizeof' ...) a function designator with type
	 ‘function returning type’ is converted to an expression
	  that has type ‘pointer to function returning type’".
2) for function calls (C11 6.5.2.2p1):
	"The expression that denotes the called function
	 (Most often, this is the result of converting an
	 identifier that is a function designator) shall have
	 type 'pointer to function returning ...'"
3) for the '*' operator and functions (C11 6.5.3.2p4):
	"If the operand points to a function, the result is a
	 function designator; ... If the operand has type
	 ‘pointer to type’, the result has type ‘type’".


So, my understanding of the standard is that the following
function calls are all strictly equivalent (and GCC seems to agree):

	extern int foo(void);

	foo();
	(foo)();
	(*foo)();
	(**foo)();
	(***foo)();
	// and so on

Same for the following ones:
	extern int (*bar)(void);

	bar();
	(bar)();
	(*bar)();
	(**bar)();
	(***bar)();
	// and so on


On both cases we can add as much '*' as we want: each one produces
a function designator that is/should directly be re-converted to
a function pointer (and the function pointer is then used for the
cal in itself).

Currently, sparse doesn't like those 'unneeded dereferences'.
Do we want to accept them?
Do we want to warn on them (because they're really weird, unneeded
and thus maybe the sign of some errors)?

-- Luc

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

* Re: function designators & function pointers
  2017-11-26 21:58 function designators & function pointers Luc Van Oostenryck
@ 2017-11-27 18:23 ` Christopher Li
  0 siblings, 0 replies; 2+ messages in thread
From: Christopher Li @ 2017-11-27 18:23 UTC (permalink / raw)
  To: Luc Van Oostenryck; +Cc: Linux-Sparse, Linus Torvalds, Al Viro

On Mon, Nov 27, 2017 at 5:58 AM, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
>
> Currently, sparse doesn't like those 'unneeded dereferences'.
> Do we want to accept them?

I think so. It is valid C after all.

> Do we want to warn on them (because they're really weird, unneeded
> and thus maybe the sign of some errors)?

Unneeded, yes.

Warning about it. I don't feel strongly either way. I guess we
can have a warning default to off.

Chris

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

end of thread, other threads:[~2017-11-27 18:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-26 21:58 function designators & function pointers Luc Van Oostenryck
2017-11-27 18:23 ` Christopher Li

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.