linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patchset] rewrite of initializer handling
@ 2007-06-18 10:19 Al Viro
  2007-06-18 10:26 ` Al Viro
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Al Viro @ 2007-06-18 10:19 UTC (permalink / raw)
  To: linux-sparse; +Cc: Linus Torvalds

	Current tree handling of initializers is rather incomplete
and in many cases broken.  Patchset rewrites that stuff pretty much
from scratch; AFAICS it works.

Fixed:
	* proper walking into subobjects, with warnings about missing
braces.  Current tree doesn't handle that and in the best case we
get a warning when initializer hits the wrong subobject and gets a type
mismatch; in the worst case we get nothing.
	* excess of initializer list elements is reported
	* unnamed bitfields are skipped as the should be; the current tree
doesn't do that
	* fixed handling of string literals; current tree is inconsistent
in that area, especially when they come from inlined functions
(evaluate_expression() changes expr->type, so it's not recognized as string
literal the next time aroung).
	* fixed handling of struct/union assignment-style initializers.
	* fixed handling of gccisms (unnamed union as a member, empty struct
as a member) to match gcc behaviour; gcc extension allowing ("a") to be
treated as "a" is handled, with a warning conditional on -Wparen-string
(default is off).  BTW, several places in the kernel have that sort of
idiocy.

Areas still missing:
	* wide string literals.  We don't support wide char anyway, so...
	* expand doesn't care for order of initializers.  For overlapping
ones that becomes a problem, especially when mixed with gcc range
designators (e.g. [20 ... 100] = {1, 2}, [0 ... 30].a = 15, [49] = {15, 20})
	* expand still leaves EXPR_POS -> EXPR_POS -> EXPR_VALUE for
[0 ... 1][0] = 1, which makes compile-i386.c rather unhappy (segfaults).
While we are at it, compile-i386.c apparently is unaware of range designators
at all - it ignores the count.  Probably best fixed in compile-i386.c...
	* calculation of array size by initializer is still broken; at least
now we get warnings about missing braces in the cases that trigger that
crap; struct {int a, b;} a[] = {1,2,3,4,5}; should give a 3-element array,
not 5-element one.  New code warns about missing braces and puts the values
in right places, but it still doesn't fix the array size calculation - it's
done too early.  Since evaluate_initializer() can work with array of
unknown size, perhaps the best solution would be to call it from the
count_array_initializer() and look for maximal index in the results if
we have EXPR_INITIALIZER / look for string size otherwise (no other
variants are possible for arrays).  Objections?

Have fun...  The tree is in branch 'initializers' of
git://git.kernel.org//pub/scm/linux/kernel/git/viro/sparse/

Al Viro (4):
      make copying of EXPR_INDEX non-lazy
      tie the fields of struct in simple list
      rewrite of initializer handling
      fix handling of typeof on structs

 evaluate.c   |  569 ++++++++++++++++++++++++++++++++++++++++------------------
 expression.h |    1 +
 inline.c     |    2 -
 lib.c        |    2 +
 lib.h        |    1 +
 parse.c      |   20 ++-
 symbol.c     |    7 +-
 symbol.h     |    6 +-
 8 files changed, 428 insertions(+), 180 deletions(-)

^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: [patchset] rewrite of initializer handling
@ 2007-06-19 17:12 Alexey Dobriyan
  2007-06-19 17:21 ` Al Viro
  0 siblings, 1 reply; 18+ messages in thread
From: Alexey Dobriyan @ 2007-06-19 17:12 UTC (permalink / raw)
  To: viro; +Cc: linux-sparse

sparse can segfault in while loop in is_string_literal():

static int is_string_literal(struct expression **v)
{
	struct expression *e = *v;
	while (e->type == EXPR_PREOP && e->op == '(')
===>		e = e->unop;	<===

Here expression is NULL.

Steps to reproduce:

	$ echo 'char a[][] = {(};' | sparse -
	-:1:16: error: Expected ) in expression
	-:1:16: error: got }
	Segmentation fault

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

end of thread, other threads:[~2007-06-20 21:29 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-18 10:19 [patchset] rewrite of initializer handling Al Viro
2007-06-18 10:26 ` Al Viro
2007-06-18 17:07 ` Linus Torvalds
2007-06-18 18:02   ` Josh Triplett
2007-06-18 19:30     ` Al Viro
2007-06-18 18:19 ` Josh Triplett
2007-06-18 19:16   ` Al Viro
2007-06-18 19:27     ` Linus Torvalds
2007-06-18 21:46     ` Michael Stefaniuc
2007-06-18 22:43       ` Al Viro
2007-06-19  9:47         ` Michael Stefaniuc
2007-06-19 20:15     ` Michael Stefaniuc
2007-06-19 22:41       ` Al Viro
2007-06-20  8:54         ` Michael Stefaniuc
2007-06-20 21:29           ` Michael Stefaniuc
  -- strict thread matches above, loose matches on Subject: below --
2007-06-19 17:12 Alexey Dobriyan
2007-06-19 17:21 ` Al Viro
2007-06-19 22:33   ` Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).