aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* Parsing wide char stringChristopher Li2010-06-171-5/+8
| | | | | | | | A follow up change to parse the wide char string. It currently only parse and store it like normal strings. Need more change to reflect the base type and size etc. Signed-off-by: Christopher Li <sparse@chrisli.org>
* Allow parsing L'\0'Christopher Li2010-04-081-1/+2
| | | | | | | | | It is nasty that L'\0' start from an identifier letter. I try my best not to slow down the hot path. The test is done inside get_one_identifier() after the ident hash is built. It look a little bit out of palace but faster than testing 'L' before hand. Signed-off-by: Christopher Li <sparse@chrisli.org>
* Don't mix storage class bits with ctype->modifiers while parsing typeAl Viro2009-07-181-7/+5
| | | | | | | | | | | | | Keep storage class (and "is it inline") explicitly in decl_state; translate to modifiers only when we are done with parsing. That avoids the need to separate MOD_STORAGE bits while constructing the type (e.g. in alloc_indirect_symbol(), etc.). It also allows to get rid of MOD_FORCE for good - instead of passing it to typename() we pass an int * and let typename() tell whether we'd got a force-cast. Indication of force-cast never makes it into the modifier bits at all. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Christopher Li <chrisl@hera.kernel.org>
* Simplify get_number_value() and ctype_integer()Al Viro2009-07-181-20/+20
| | | | | | | | | | | There's no point whatsoever in constructing modifiers for chosen type when decoding integer constant only to have them picked apart by ctype_integer(). Seeing that the former is the only caller of the latter these days, we can bloody well just pass the rank and signedness explicitly and save a lot of efforts. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Christopher Li <chrisl@hera.kernel.org>
* Fix type_info_expression()Al Viro2009-07-171-2/+10
| | | | | | | | | sizeof (typename){initializers}.foo is nice and valid C99 - it's parsed as sizeof primary.foo <- sizeof postfix.foo <- sizeof postfix <- sizeof unary <- unary. Current type_info_expression() stops too early. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Christopher Li <sparse@chrisli.org>
* Set *tree to NULL on errorVegard Nossum2008-07-141-0/+2
| | | | | | | | | On "Syntax error in unary expression", the output parameter "tree" would be left uninitialized and subsequently used in unary_expression(), leading to segfault. Caught by valgrind and fixed by me ;-) Signed-off-by: Vegard Nossum <vegardno@ifi.uio.no>
* [PATCH] braino in conditional_expression()Al Viro2007-07-291-1/+1
| | | | Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* expression.c: Clean up match_oplist() and add missing va_end()ricknu-0@student.ltu.se2007-07-241-7/+7
| | | | Signed-off-by: Richard Knutsson <ricknu-0@student.ltu.se>
* fix handling of address_space in casts and assignmentsAl Viro2007-07-101-5/+13
| | | | | | | | | | | | | | | | | | | | | | | | Turn FORCE_MOD into storage class specifier (that's how it's actually used and that makes for much simpler logics). Introduce explicit EXPR_FORCE_CAST for forced casts; handle it properly. Kill the idiocy in get_as() (we end up picking the oddest things for address space - e.g. if we have int __attribute__((address_space(1))) *p, we'll get warnings about removal of address space when we do things like (unsigned short)*p. Fixed. BTW, that had caught a bunch of very odd bogosities in the kernel and eliminated several false positives in there. As the result, get_as() is gone now and evaluate_cast() got simpler. Kill the similar idiocy in handling pointer assignments; while we are at it, fix the qualifiers check for assignments to/from void * (you can't assign const int * to void * - qualifiers on the left side should be no less than on the right one; for normal codepath we get that checked, but the special case of void * skips these checks). Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* fix the comma handling in integer constant expressionsAl Viro2007-07-081-11/+3
| | | | | | | | | | Treat it as normal binary operation, taint the value, check the taint. We can do other kind of value tainting with the same infrastructure as well... Review and testing would be welcome; AFAICS, it works, but... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* [PATCH] fix handling of integer constant expressionsAl Viro2007-06-261-6/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hopefully correct handling of integer constant expressions. Please, review. Rules: * two new flags for expression: int_const_expr and float_literal. * parser sets them by the following rules: * EXPR_FVALUE gets float_literal * EXPR_VALUE gets int_const_expr * EXPR_PREOP[(] inherits from argument * EXPR_SIZEOF, EXPR_PTRSIZEOF, EXPR_ALIGNOF get int_const_expr * EXPR_BINOP, EXPR_COMPARE, EXPR_LOGICAL, EXPR_CONDITIONAL, EXPR_PREOP[+,-,!,~]: get marked int_const_expr if all their arguments are marked that way * EXPR_CAST gets marked int_const_expr if argument is marked that way; if argument is marked float_literal but not int_const_expr, we get both flags set. * EXPR_TYPE also gets marked int_const_expr (to make it DTRT on the builtin_same_type_p() et.al.) * EXPR_OFFSETOF gets marked int_const_expr When we get an expression from parser, we know that having int_const_expr on it is almost equivalent to "it's an integer constant expression". Indeed, the only checks we still have not done are that all casts present in there are to integer types, that expression is correctly typed and that all indices in offsetof are integer constant expressions. That belongs to evaluate_expression() and is easily done there. * evaluate_expression() removes int_const_expr from some nodes: * EXPR_BINOP, EXPR_COMPARE, EXPR_LOGICAL, EXPR_CONDITIONAL, EXPR_PREOP: if the node is marked int_const_expr and some of its arguments are not marked that way once we have done evaluate_expression() on them, unmark our node. * EXPR_IMLICIT_CAST: inherit flags from argument. * cannibalizing nodes in *& and &* simplifications: unmark the result. * EXPR_CAST: unmark if we are casting not to an integer type. Unmark if argument is not marked with int_const_expr after evaluate_expression() on it *and* our node is not marked float_literal (i.e. (int)0.0 is fine with us). * EXPR_BINOP created (or cannibalizing EXPR_OFFSETOF) by evaluation of evaluate_offsetof() get int_const_expr if both arguments (already typechecked) have int_const_expr. * unmark node when we declare it mistyped. That does it - after evaluate_expression() we keep int_const_expr only if expression was a valid integer constant expression. Remaining issue: VLA handling. Right now sparse doesn't deal with those in any sane way, but once we start handling their sizeof, we'll need to check that type is constant-sized before marking EXPR_SIZEOF int_const_expr. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* [PATCH] implement __builtin_offsetof()Al Viro2007-06-261-0/+67
| | | | Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* [PATCH] deal with enum members without excessive PITAAl Viro2007-06-251-0/+7
| | | | | | | | mark symbols for enum members, have primary_expression() copy their ->initializer instead of dancing through the EXRP_SYMBOL with expand_expression() finally getting to the damn thing. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* handle __alignof as equivalent of __alignof__Al Viro2007-05-261-0/+1
| | | | Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
* Fix typos in commentsJosh Triplett2007-03-091-1/+1
| | | | Signed-off-by: Josh Triplett <josh@freedesktop.org>
* double inclusionsNicolas Kaiser2006-11-211-1/+0
| | | | | | | Remove two double inclusions. Signed-off-by: Nicolas Kaiser <nikai@nikai.net> Signed-off-by: Josh Triplett <josh@freedesktop.org>
* [PATCH] Add support for GCC's __builtin_types_compatible_p extensionJosh Triplett2006-07-051-2/+47
| | | | | | | | | | | Parse and support GCC's __builtin_types_compatible_p extension, which takes two types as arguments, and returns 1 for compatible types or 0 for incompatible types. Since sparse already supports comparisons with types as the operands, just transform __builtin_types_compatible_p(a, b) into the comparison a == b. Signed-off-by: Josh Triplett <josh@freedesktop.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
* Re-name "error()" function to "sparse_error()"Linus Torvalds2005-11-161-4/+4
| | | | | | | | | Mitesh Shah (and others) report that broken libc's will have their own "error()" that the sparse naming clashes with. So use a sed-script to rewrite all the occurrences. Signed-off-by: Linus Torvalds <torvalds@osdl.org>
* [PATCH] replaced warnings with errors.Mitesh Shah2005-09-221-4/+4
| | | | | | | | | This replaceq calls to warning() with error() at places where (I think) the gcc reports an error. Also added a global variable die_if_error which is set if there is one or more errors. If someone wants to stop processing further, can check for the variable. Signed-off-by: Linus Torvalds <torvalds@osdl.org>
* Warn about undefined preprocessor symbols at expansion time, not parse timeLinus Torvalds2005-09-091-0/+9
| | | | | | | | | | | | | This means that we can do #if defined(TOKEN) && TOKEN > 1 and we will _not_ warn even with -Wundef, since the "TOKEN > 1" test will never even be expanded if TOKEN isn't defined. Al Viro gets credit for the algorithm changes, I just did the actual coding. Signed-off-by: Linus Torvalds <torvalds@osdl.org>
* Fix assignment and conditional expression parsing with no left side.Linus Torvalds2005-06-191-2/+2
| | | | | We used to parse it with a NULL left side, which just doesn't make any sense. Refuse to recognize it instead.
* Split out the blob allocator from lib.c into allocate.c.Linus Torvalds2005-04-071-0/+2
| | | | | | | | | It's disgusting how intimate lib.c is with all the types, and this is slowly trying to split things up a bit. Now the intimate part is in allocate.c, but maybe we can get to the point where each allocation user just declares its own allocation strategy, and just uses the generic routines in allocate.c
* Update copyright notices a bit.Linus Torvalds2005-04-071-1/+1
|
* Add __sizeof_ptr__ that looks at a pointer expression andLinus Torvalds2005-04-071-31/+47
| | | | | | | | | | | | | | | | | | | returns the size of the underlying object. This is different from "sizeof(*expr)" for arrays, where the array would degenerate to a pointer to one member, and thus "sizeof(*expr)" gives the size of one entry in the array. Why do this? It's useful for things like #define memset(a,b,c) ({ \ (void) __builtin_warning(__sizeof_ptr__(a) > 1, __sizeof_ptr__(a) != (c), "check memset size"); \ memset(a, b, c); }) where we really want to check the size of the object we're doing the "memset()" on, but the regular sizeof() just doesn't cut it.
* Handle __func__, __FUNCTION__ and __PRETTY_FUNCTION__ the sameLinus Torvalds2005-04-071-0/+59
| | | | | | | way, and give them a real string. This means that __func__ actually works as a constant string, not as a pseudo-symbol, which is wrong. But hey, sue me.
* Add system-specific compatibility functions to makeLinus Torvalds2005-04-071-2/+1
| | | | | | | | | | | up for various system deficiencies. This makes sparse easier to port to silly things like MinGW or Solaris. In particular: - strtold() is a C99 thing, not everybody has it - MinGW has problems with mmap(MAP_ANONYMOUS) and doesn't zero it. - st_ino/st_dev is POSIX identity testing, not supported by MinGW
* Many files:welinder@darter.rentec.com2005-04-071-10/+10
| | | | | | | | | | | warn->warning error->error_die new error lib.h: warn->warning error->error_die new error Add gcc format checking to warning/error/...
* Keep track of computed target label lists per-function.Linus Torvalds2005-04-071-1/+6
| | | | | Associate them with each computed goto, and copy them properly when inlining.
* Make sizeof understand the C99 "sizeof typed initializer" syntax.Linus Torvalds2005-04-071-1/+12
| | | | | | | Also fix the type return of initializer evaluation, so that we get the right size in the right place. Add the necessary lines to parse the thing too.
* [PATCH] FP handlingAlexander Viro2005-04-071-15/+25
| | | | FP handling added, everything straightforward by now.
* C99 says strings should be up to 4095 bytes.Linus Torvalds2005-04-071-5/+6
| | | | | | | Also, while we're here, be more careful about the exact limits, and concatenation: we want to have the ending NUL character even when we concatenate too much.
* Don't allow string concatenation to overflow MAX_STRING.Linus Torvalds2005-04-071-0/+9
|
* [PATCH] teach sparse about __alignof__Stephen Hemminger2005-04-071-11/+22
| | | | | | | | | | | | | | | | This teaches sparse what __alignof__ really means, instead of just using the same code as "__sizeof__" It gets rid of the warnings in ebtables that does: struct ebt_entries { ... char data[0] __attribute__ ((aligned (__alignof__(struct ebt_replace))); }; Which caused warning because sparse was evaluating __alignof__ as the same as sizeof, and sizeof was 57 (ie non-power of 2). This is just based on the existing code and a peek at the data structures in expression and symbol.
* [PATCH] Update get_number_value()Alexander Viro2005-04-071-80/+94
| | | | | | | | | | This updates the type semantics of "get_number_value()" to C99 semantics rather than the previous gcc/C90 type expansion semantics. Now regular decimal integers (without suffixes) that are too big to fit in "long" expand to "long long" rather than "unsigned long". It also uses "strtoull()" rather than open-coding the conversion.
* If int/long are the same size, an int that overflows intoLinus Torvalds2005-04-071-3/+2
| | | | | unsigned stays as an (unsigned) int. Otherwise it becomes a long.
* Macroize lr_binop_expression() helper function.Linus Torvalds2005-04-071-49/+85
| | | | | | | | | | | | | This function was the top performance offender in sparse. We really want it inlined, since all it really does is to do an indirect call or two, and if inlined that call turns into a direct call. Making it a macro allows us to pass in the operation comparison as code rather than as a list of integers, which again allows the compiler to do a much better job.
* Make sure we don't silently accept an empty expressionLinus Torvalds2005-04-071-2/+12
| | | | following unary expressions.
* Allow underscores in integer constants for readability.Linus Torvalds2005-04-071-2/+8
| | | | | | Thus 0x1234_5678 is a valid constant, as is 100_000_ul. The parser doesn't care where they are.
* Remove TOKEN_FP vs TOKEN_INTEGER distinction, and make numbers beLinus Torvalds2005-04-071-24/+30
| | | | | | | | | just TOKEN_NUMBER. This matches how tokenization is supposed to be done, and simplifies the code. Expression evaluation changed to cope with the new rules.
* Don't get confused about "void *" nodes.Linus Torvalds2005-04-071-1/+1
| | | | | | | | | We'd incorrectly test the right type of a compatible pointer expression for "void *" without dropping off the node information. This allows us to fix a casting bug, where we used to drop the node information at the cast.
* "a->b" is just shorthand for "(*a).b".Linus Torvalds2005-04-071-2/+9
| | | | | | So let's make that explicit in the parse tree, and avoid carrying the special cases around further. This makes the evaluation phase only have one case to worry about.
* Make "value is so big" warning print the constant.Linus Torvalds2005-04-071-3/+5
| | | | This makes it a lot easier to see what's up.
* Now that BITS_IN_XXXX aren't defined contstants any more,Linus Torvalds2005-04-071-6/+6
| | | | rename them lower cased to match standard C naming rules.
* Clean up type expression syntax.Linus Torvalds2005-04-071-2/+9
| | | | | | | | We now require square brackets around the type, to avoid any confusion with casts or variable declarations: if ([typeof(x)] == [int]) ...
* Support C types as first-class citizens, allowing typeLinus Torvalds2005-04-071-8/+8
| | | | | | | | | | comparisons etc: if (typeof(a) == int) { ... (although right now I don't actually do the proper comparison expansion and all comparisons return "true").
* Warn about users trying to use type names in expressions.Linus Torvalds2005-04-071-1/+15
| | | | | | I think I'll allow type expressions at some point, since it shouldn't actually be all that hard, and would even clean some stuff up. But for now, we'll just warn about non-C code.
* [PATCH] Make sparse understand complex initializers inside expressionsDave Olien2005-04-071-6/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch makes a cast expression followed by an initializer list into a postfix expression that can be dereferenced as a structure or an array. There are approximately 7 instances of these expressions in the Linux kernel, that give warnings about "expected lvalue for member dereference". The approach involved introducing a new "stack-based temporary" symbol of the same type as the cast expression, and using this as the target of the initialization expression. The subsequent array or structure member dereferences are made to that temporary symbol. show-parse.c need modification to display a symbol expression with an initializer list that is NOT in a symbol declaration list. An example of this form with structure member dereference is: typedef struct { long t1; long t2; long t3; } longstruct_t; long test; int main(void) { int a, b, c; test = (longstruct_t){a, b, c}.t3; return 0; } An example of this form with array member dereference is: typedef int iarray[2]; int pgp; main(void) { int index; int a, b; pgp = (iarray){a,b}[index]; }
* Update copyright notices to reflect the fact that TransmetaLinus Torvalds2005-04-071-0/+1
| | | | isn't the sole copyright owner these days.
* Make the tokenizer recognize FP tokens, even if we don'tLinus Torvalds2005-04-071-1/+5
| | | | actually handle them correctly later on yet.
* Parse and evaluate gcc computed goto extensions: label addressingLinus Torvalds2005-04-071-0/+10
| | | | | | | | (&&label) and computed goto (goto *expr). Add label ctype for __label__ identifier. This is still quite broken (it should create a block-symbol in the NS_LABEL namespace, right now it creates a regular symbol).