| Age | Commit message (Collapse) | Author | Files | Lines |
|
On Thu, Aug 31, 2017 at 09:54:33PM +0100, Al Viro wrote:
> What a mess... Note that for non-vararg it *is* the right interpretation
> (with #define A(x) [x] we will have A() interpreted as "empty token sequence
> as the only argument", not "no arguments given"). For vararg case we
> normally do not need to distinguish "not given" and "empty" - the only
> thing that cares is exactly the ,## kludge. There with
> #define B(x,...) [x,##__VA_ARGS__]
> B(1) and B(1,) yield [1] and [1,] resp. And for everything other than
> "just ..." we even get it right...
>
> I see what's going on there; will post a fix in a few.
Fix macro argument parsing for (...) case
Nasty corner case for the sake of ,##__VA_ARGS__ perversion - for something
like #define A(x,...) [x,##__VA_ARGS] we want A(1) to expand to [1] and
A(1,) - to [1,]. In other words, "no vararg given" and "vararg empty" are
different and need to be distinguished. Unfortunately, in case when there
was nothing but vararg we got it wrong - #define A(...) ,##__VA_ARGS ended
up with A() interpreted as "one empty argument" (as it would in non-vararg
case) rather than "zero arguments".
Reported-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Christopher Li <sparse@chrisli.org>
|
|
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
|
|
__COUNTER__ macro is expanded to a sequential number starting from 0.
This is sometimes used to declare unique variable names.
Implement support for __COUNTER__ in sparse including a set of
small test programs for the test suite.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Tested-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Christopher Li <sparse@chrisli.org>
|
|
The string is shared between different macro expand.
It is wrong to modify the string in place if the string
is used in a macro. Avoid overwriting the string in that
case.
Reported-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Tested-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Signed-off-by: Christopher Li <sparse@chrisli.org>
|
|
The old code was relicensed by Novafora Corporation, successor in interest to
Transmeta Corporation, in 2009. Other authors were also asked about the change
of their contributions to the MIT license and all with copyrightable changes
agreed to it.
Signed-off-by: Franz Schrober <franzschrober@yahoo.de>
Acked-by: Adam DiCarlo <adam@bikko.org>
Acked-by: Al Viro <viro@ZenIV.linux.org.uk>
Acked-by: Alberto Bertogli <albertito@blitiri.com.ar>
Acked-by: Alecs King <alecs@perlchina.org>
Acked-by: Alexander Shishkin <alexander.shishckin@gmail.com>
Acked-by: Alexey Dobriyan <adobriyan@gmail.com>
Acked-by: Alexey Zaytsev <alexey.zaytsev@gmail.com>
Acked-by: Andries E. Brouwer <Andries.Brouwer@cwi.nl>
Acked-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Acked-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Acked-by: Ben Pfaff <blp@nicira.com>
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Bernd Petrovitsch <bernd@petrovitsch.priv.at>
Acked-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Acked-by: Blue Swirl <blauwirbel@gmail.com>
Acked-by: Chris Forbes <chrisf@ijw.co.nz>
Acked-by: Chris Wedgwood <cw@f00f.org>
Acked-by: Christopher Li <sparse@chrisli.org>
Acked-by: Damien Lespiau <damien.lespiau@gmail.com>
Acked-by: Dan Carpenter <error27@gmail.com>
Acked-by: Dan McGee <dan@archlinux.org>
Acked-by: Daniel De Graaf <danieldegraaf@gmail.com>
Acked-by: Daniel Sheridan <dan.sheridan@postman.org.uk>
Acked-by: Dave Jones <davej@redhat.com>
Acked-by: David Given <dg@cowlark.com>
Acked-by: David Miller <davem@redhat.com>
Acked-by: David Mosberger-Tang <dmosberger@gmail.com>
Acked-by: David Olien <David.Olien@lsi.com>
Acked-by: Diego Elio Pettenò <flameeyes@flameeyes.eu>
Acked-by: Emil Medve <Emilian.Medve@Freescale.com>
Acked-by: Ethan Jackson <jacksone@nicira.com>
Acked-by: Florian Fainelli <f.fainelli@gmail.com>
Acked-by: Frank Zago <fzago@systemfabricworks.com>
Acked-by: Frederic Crozat <fcrozat@suse.com>
Acked-by: Geoff Johnstone <geoff.johnstone@gmail.com>
Acked-by: Hannes Eder <hannes@hanneseder.net>
Acked-by: Jan Pokorný <pokorny_jan@seznam.cz>
Acked-by: Jeff Garzik <jgarzik@redhat.com>
Acked-by: Jiri Slaby <jslaby@suse.cz>
Acked-by: Joe Perches <joe@perches.com>
Acked-by: Joel Soete <rubisher@scarlet.be>
Acked-by: Johannes Berg <johannes@sipsolutions.net>
Acked-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
Acked-by: Josh Triplett <josh@kernel.org>
Acked-by: Kamil Dudka <kdudka@redhat.com>
Acked-by: Kim Phillips <kim.phillips@linaro.org>
Acked-by: KOSAKI Motohiro <kosaki.motohiro@gmail.com>
Acked-by: Kovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Acked-by: Martin Nagy <nagy.martin@gmail.com>
Acked-by: Masatake YAMATO <yamato@redhat.com>
Acked-by: Mauro Dreissig <mukadr@gmail.com>
Acked-by: Michael Büsch <m@bues.ch>
Acked-by: Michael Stefaniuc <mstefani@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Mika Kukkonen <mikukkon@iki.fi>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Acked-by: Mitesh Shah <Mitesh.Shah@synopsys.com>
Acked-by: Morten Welinder <mortenw@gnome.org>
Acked-by: Namhyung Kim <namhyung@gmail.com>
Acked-by: Nicolas Kaiser <nikai@nikai.net>
Acked-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Pavel Roskin <proski@gnu.org>
Acked-by: Pekka Enberg <penberg@cs.helsinki.fi>
Acked-by: Peter Jones <pjones@redhat.com>
Acked-by: Peter A Jonsson <pj@sics.se>
Acked-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
Acked-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Acked-by: Randy Dunlap <rdunlap@xenotime.net>
Acked-by: Reinhard Tartler <siretart@tauware.de>
Ached-by: Richard Knutsson <richard.knutsson@gmail.com>
Acked-by: Rob Taylor <rob.taylor@codethink.co.uk>
Acked-by: Rui Saraiva <rmpsaraiva@gmail.com>
Acked-by: Ryan Anderson <ryan@michonline.com>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Acked-by: Samuel Bronson <naesten@gmail.com>
Acked-by: Santtu Hyrkkö <santtu.hyrkko@gmail.com>
Acked-by: Shakthi Kannan <shakthimaan@gmail.com>
Acked-by: Stephen Hemminger <shemminger@linux-foundation.org>
Acked-by: Thomas Schmid <Thomas.Schmid@br-automation.com>
Acked-by: Tilman Sauerbeck <tilman@code-monkey.de>
Acked-by: Vegard Nossum <vegardno@ifi.uio.no>
Acked-by: Xi Wang <xi.wang@gmail.com>
Acked-by: Yura Pakhuchiy <pakhuchiy@gmail.com>
Signed-off-by: Christopher Li <sparse@chrisli.org>
|
|
"#pragma once" acts like a multiple-inclusion guard affecting the entire file,
without an associated preprocessor symbol.
This allows use of sparse on projects that rely on #pragma once without
also using an ifndef-based multiple-inclusion guard, such as systemd;
without this change, sparse will get into an include loop.
Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Christopher Li <sparse@chrisli.org>
|
|
Currently there are a few source file in the kernel can't
parse property due to over run of the concatenation buffer.
They either have a large string concatnation or huge macro
expand. The TRACE macro is a common one.
Now show_token_sequence and quote_token_sequence is combined
into one function with a bigger buffer. It works for most
of the kernel source except the config_data.h. The kernel
config is about 70K, larger than the string allocator chunk size.
It needs some plumbing work in the allocator before we can
allow bigger string token.
Signed-off-by: Christopher Li <sparse@chrisli.org>
|
|
Signed-off-by: Christopher Li <sparse@chrisli.org>
|
|
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
|
|
#define A(x) #x
A('\12')
should *not* yield "'\\n'"; the problem is that we are doing the conversion
too early.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
|
|
-include foo.h will search not only in the current directory...
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
|
|
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
|
|
a) it actually allows any number of ##<arg>##... in between, as long as all
those args are empty.
b) it does *not* allow ## after __VA_ARGS__ - if it's there magic disappears
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
|
|
The new gcc complain about set but not used
variable. This should make the new gcc happy.
Signed-off-by: Christopher Li <sparse@chrisli.org>
|
|
This replaces the "loop over all streams" with a simple hash lookup. It
makes the cost of checking for already tokenized streams basically go
away (it could be up to 5% of CPU time, almost entirely due to the
"strcmp()" of the name).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Christopher Li <sparse@chrisli.org>
|
|
Convert (sizeof arr / sizeof arr[0]) to ARRAY_SIZE(arr).
Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Signed-off-by: Christopher Li <sparse@chrisli.org>
|
|
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>
|
|
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>
|
|
On Sat, Mar 21, 2009 at 04:40:20AM +0000, Al Viro wrote:
>
> Well... patch below would give more or less close approximation to the
> current set of nasal demons produced by gcc in these situations + error
> when that crap happens.
> Warning: it might make things slower, and it needs testing.
>
> ---
It needed testing, all right - #elif handling got broken by the initial
variant... Hopefully fixed version follows:
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Christopher Li <sparse@chrisli.org>
|
|
Dirafter was probably just a mistake.
Gcc uses -idirafter.
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Alexey zaytsev <alexey.zaytsev@gmail.com>
|
|
You can now tell sparse where to look for the compiler
headers with -gcc-base-dir <dir>. Otherwise sparse will
look for headers used to build it.
Also adds $GCC_BASE/include-fixed used by newer gcc
versions.
Signed-off-by: Alexey zaytsev <alexey.zaytsev@gmail.com>
|
|
While running if-2.c from gcc testsuite sparse goes into infinite loop in
free_preprocessor_line().
Trimmed down test-case is
#if 1
#if
(two lines)
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
|
|
6.10.3(3) requires a whitespace between object-like macro
and its replacement list.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
|
|
Makes __DATE__expand to a character string literal of
the form "Mmm dd yyyy" where the names of the months
are the same as those generated by the asctime function,
and the first character of dd is a space character if the
value is less than 10.
Makes __TIME__ expand to a a character string literal of
the form "hh:mm:ss" as in the time generated by the
asctime function.
Signed-off-by: Damien Lespiau <damien.lespiau@gmail.com>
|
|
Thanks to Florian Krohm of IBM for reporting the problem.
Signed-off-by: Josh Triplett <josh@freedesktop.org>
|
|
Signed-off-by: Josh Triplett <josh@freedesktop.org>
|
|
Example
// pre-buffer
#strong_undef CONFIG_SMP
// include/linux/autoconf.h
#define CONFIG_SMP 1 // silently ignored
#ifdef CONFIG_SMP
... // not taken
#endif
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
|
|
Example
#strong_define FOO 1
#undef FOO // silently ignored
#define FOO 2 // silently ignored
This allows (for example) to override CONFIG_XXX values without
editing include/linux/autoconf.h
I think this is useful. If you think differently, I will appreciate
your comments on this patch correctness.
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
|
|
This patch renames symbol->weak to symbol->attr and adds
symbolic names for it's values.
I don't like the new name, and will be happy to rename if
you suggest me something different.
Probably it is also better to move ->attr into the NS_MACRO
part of the union and make it integer.
No changes in pre-process.o
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
|
|
When NS_MACRO symbol is used, sparse clears it's 'weak' flag.
This is bad for multifile parsing, and wrong:
#weak_define FOO 1
FOO
#weak_define FOO 2 // silently ignored
After this patch sparse never writes to NS_MACRO symbols from
another scope (except ->used_in).
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
|
|
This patch fixes 2 bugs in do_handle_define()
1. if (sym->weak)
goto replace_it;
This is wrong, we should allocate a new symbol if
sym->scope != file_scope, example:
inc.h:
#weak_define FOO default
redefine.c:
#define FOO redefine
FOO
default.c:
FOO
$ ./test-lexing -include inc.h redefine.c default.c
redefine
Segmentation fault
2. if (token_list_different(...)) {
...
}
return 1;
This is wrong too:
#weak_define FOO 1
#define FOO 1 // has no effect
#define FOO 2 // redefined without warning
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
|
|
With this patch handle_undef() doesn't corrupt the builtin macros.
This (imho) cleanups the code and is used in the next patches.
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
|
|
Current code looks strange, I think it used to remove the symbol
from ->symbols list some time ago.
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
|
|
Sparse complain about the using do while without
compound statment in pre-process.c. This trivial patch
fixes that.
Signed-Off-By: Christopher Li <sparse@chrisli.org>
|
|
Signed-off-by: Pavel Roskin <proski@gnu.org>
Signed-off-by: Josh Triplett <josh@freedesktop.org>
|
|
No need to bother with stack; we can just keep # tokens from #if... and
use _those_ as a stack instead. struct stream gets a pointer to the
current #if..., checks for #elif/#else/#endif out of place become simple
if (!stream->top_if) and stream->ifndef becomes a pointer to token
instead of an integer (pointer to token in that stack instead of nesting
depth).
We lose elif_ignore[] array, if_nesting and stream->nesting (nothing
cares of those anymore) and get sane handling of unterminated #if for
free - instead of reporting the location of the last #if on depth 0
(very likely - in another file and having an #endif) we can give
location of the #if that really lacks #endif.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
|
|
Not used anywhere else.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
|
|
eof_token(token)
IOW, handling of #<newline> had been broken since way back...
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
|
|
New mechanism: we introduce new fields of struct stream - ifndef and
dirty. The former is the nesting level of ifndef that currently
protects us, or 0 if there's none. The latter is a boolean - "do we
ignore new non-empty stuff shows up right now?".
There are five states, more or less matching the old ->constant ones:
1) nothing - dirty = 0, ->protect = NULL, ->ifndef = 0.
2) candidate - dirty = 0, ->protect = <ident>, ->ifndef > 0.
3) checking - dirty = 0, ->protect = <ident>, ->ifndef = 0.
4) maybe - dirty = 1, ->protect = <ident>, ->ifndef > 0.
5) not - dirty = 1, ->protect = NULL, ->ifndef = 0.
Rules:
- any directive except #ifdef, #ifndef, #else, #endif, #<newline> is
considered dirty.
- any non-directive (#<not a directive name>...) is considered dirty
- any tokens in lines that do not begin with # are considered dirty
- #if[n]def with syntax errors is considered dirty.
- any nesting errors => stream is non-constant.
- any dirty material not under ifndef => stream is non-constant.
- the outermost ifndef at the first time we run into dirty material
will be the candidate for stream protector.
- any subsequent dirty material not under ifndef <protector> => stream
is non-constant.
We start in "nothing". Transitions:
- "nothing": dirty material => "not", see ifndef => "candidate"
- "candidate": dirty material => "maybe", leave that ifndef => "nothing"
- "maybe": dirty material => "maybe", leave that ifndef => "checking"
- "checking": dirty material => "not", same ifndef => "maybe
- "not": they check in, but they don't check out...
Seeing a nesting error (#else/#elif/#endif out of place/order or
unclosed #if... in the end) gets us to "not", no matter which state we
were in.
That's it. Implementation is actually pretty simple and
straightforward; it's less scary than the description above.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
|
|
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
|
|
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
|
|
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
|
|
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
|
|
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
|
|
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
|
|
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
|
|
Standard requires much more relaxed treatment of the groups that
are #if...'ed out. We used to generate bogus warnings there; fixed,
testcase added.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
|
|
... normal execution will do exactly the same on the next iteration;
case is damn rare (it's _not_ the GNU kludge - there we have ,##) and
it's not worth an extra check.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
|
|
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>
|
|
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>
|
|
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>
|
|
This means that we may have both an "invisible" macro _and_ a visible
one in scope, so we need to be a bit more careful about lookup.
We always look up the topmost one (either visible or invisible), and if
it's invisible, that means it is undefined (a builtin macro was first
re-defined, and then that redefinition was undefined).
|
|
Start off with
sparse_initialize(argc, argv);
which will return the number of filenames found. You can then use that,
or just check if *argv is NULL in a loop like
while (*argv)
list = sparse(argv);
where you get the declaration list for each file in turn.
|
|
It used to be that we only had pre-processor expressions at that point,
but now that we can pre-process multiple files, we end up having
expressions of previous files too, and we mustn't free those..
There aren't enough pre-processor expressions around to be worth
worrying about the memory usage anyway.
|
|
sparse segfaults with the following input:
---
#ifdef notdef
oops!
---
The segfault occurs at pre-processor.c:free_preprocessor_line()
because of the extra calls of handle_endif done in do_preproccess()
while trying to do error recoverage.
Fix it by not trying to free the non-existent token line in the
faked endif handling.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@looxix.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
|
|
Luc Van Oostenryck points out that we free all the preprocessor tokens
after processing these days, so that pointing back to them for position
reporting isn't very clever any more.
Fix by just saving the position instead of the token instead.
|
|
This patch add static declare to make sparse happy of checking itself.
|
|
Search include paths in same order as gcc does.
In other words search directories specified with -I before system
directories.
This fixes a bug reported by a few persons after the kernel switched
over to use -isystem to specify where to find compiler specific include files.
Sparse now supports the following include path relevant options:
-I dir Add dir to list of directories to search for. Search dir
before system dirs. Used for both <> and "" includes.
-I- Split include path - previous -I dir paths only used for
include "".
Also disable searching same dir as input file.
-isystem dir Add dir first in row of system dirs to search.
-dirafter dir Add dir in end of system dirs to search.
-nostdinc Discard all defined system dirs
The -iwithprefix, -iprefix and -iwithprefixbefore options are not not
supported and silently ignored. gcc discourage use of these options.
|
|
Much prettier than "input_streams[x].name", since most
users really don't want to know about the internals of
how the preprocessor lays out its stream tracking.
|
|
Replace it with a simple pathname comparison instead.
The pathname check is not only portable (no need for any
compatibility helper functions), but we can do it much
earlier, and thus make the check much cheaper by avoiding
three extra system calls when it triggers (open/fstat/close).
And the pathname test seems to match all the cases anyway.
|
|
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
|
|
Nothing uses it yet, but it's a good way to test bad
ideas (call it an "optimization", and run diff on the
result with and without).
|
|
|
|
It now re-uses the '#' token for all preprocessor lines,
and the 'define' token itself (even though it obviously
can't free the tokens from the definition).
This makes the 2004 IOCC entry a non-issue memory-wise.
Now I just need to speed up the parser. Sixteen seconds
on pre-processing is not acceptable..
|
|
into the token stream.
Most preprocessor lines are unused after handling, with the
notable exception of a #define. And regular tokens that get
skipped due to being in a region that is inside a false #if
case are also obvious fodder for this.
This shrinks the memory usage by a factor of five on some
particularly nasty code in the 2004 IOCCC.
|
|
We still warn about them, but we act as if it was ok.
The "vik2" IOCCC-2004 entry does some nasty preprocessor stuff on
purpose. We parse it all right, but because we refused to honor #if
statements that are terminated in another stream, we didn't get the
output Daniel Vik intended.
|
|
This causes us to warn if somebody tries to re-define a
symbol that has already been used, even if it was originally
non-weak.
Noted by Morten Welinder
|
|
"token_defined(token)" does it all.
|
|
They work like weak symbols: they get used if nobody defines
anything else for them, and re-defining them doesn't cause a
warning.
|
|
Don't just complain. It may be wrogn to redefine, but if people
do it, use the most recent one.
|
|
- handling of "unexpanded identifiers should be replaced with 0" is
moved to pre-process.c and done on token replacement level
- warning about such replacement made conditional
- expand() and expand_one_symbol() return int now - it's "is the first
token completely expanded now" (simplifies the life in #if handling,
etc.)
- crud removed from evaluate.c and expand.c
|
|
|
|
Caught by checking sparse with itself.
|
|
The only remaining place was the magic constant "0" "1" number
token generated by "defined(xxx)". And since we never actually
modify number tokens (which would have broken that code anyway),
let's just make that const'ness explicit.
|
|
|
|
warn->warning
error->error_die
new error
lib.h:
warn->warning
error->error_die
new error
Add gcc format checking to warning/error/...
|
|
It may well come back as a debugging and prototyping thing,
but I'd rather remove it and have to re-introduce it, than
have people use that stupid interface just "because it's there".
Sparse is very good at hashing identifiers and making them
all unique. So you really should never need to match by
string, you can just compare "struct ident" pointers directly.
Thanks to Chris for getting rid of the users.
|
|
This all started with I want to remove match_string_ident in preprocessor.
I decide that I don't want to search a pointer in the list. There is faster
way which is register a symbol with a new name space which contain the
handler.
This changes:
1) changed name of NS_PRECESSOR to NS_MACRO and give it a new meaning
for preprocessor command. Now NS_MACRO means a macro name, and the
new NS_PREPROCESSOR means a preprocessor command.
2) The ctype and preprocessor can put into one union. They are on
different name space so they _should_ never collapse. I did that and
made struct symbol 8 bytes smaller. Nothing blew up for me so it
must be correct ;)
And a question:
3) When to initialize the preprocessor command symbol. Should we make
it part of the init_symbol or let the caller(check.c) initialize it?
Do we want to remove the preprocessor command afterwords?
|
|
Make eval_init_table static.
pre-process.c:
Fix match_string_ident.
|
|
|
|
Check for unterminated #if on a per-stream basis.
Check for #else after #else or #elif.
Check for unmatched #else/#elif/#endif on a per-stream basis.
|
|
is not constant. Not that it really matters, but still...
|
|
|
|
Maybe this makes us gcc-compatible. Maybe it doesn't.
|
|
It's trivial now with the re-organized include path handling.
|
|
This is a cunning plan to make "include_next" work. This
is just the infrastructure. Actual include_next handling
in the next patch.
|
|
Fix file-is-const for #define, #undef, C-code inside
the #ifndef.
Make it easy to debug file-is-const.
tokenize.c:
Fix check for identical-file.
token.h:
Introduce symbolic names for the stream->constant states
and comment those states.
|
|
Never call isdigit/isspace on type char, use unsigned char only.
|
|
Gnome needs lots of -Ipath -- just up the limit a whole lot.
|
|
This is the format gcc will output the line information in, for example.
We still don't actually _use_ the information, and perhaps never will,
but at least we'll silently ignore it rather than complain.
|
|
Stuff from bison contains #line directives. This makes sparse ignore
such lines. This helps but doesn't exactly make sparse happy over such
.c files.
(Ignoring isn't quite right because, arguably, later error messages should
refer to the file from which the c code was generated, not from the c code
itself.)
|
|
We used to try to use the search path for them, which just
doesn't work (it happened to work just by mistake in the common
case of an empty path base component, but not in general).
|
|
|
|
This is almost a total rewrite of the macro expansion. It now does
lazy-copy or the arguments, with the realization that if an argument
only shows up once in the macro expansion (quite common), we don't need
to allocate a new copy of the argument token stream, we can just insert
it as-is.
I hope it's reasonably clean and readable; review would be obviously welcome.
|
|
This does two things:
a) get C99 varargs to use the same mechanism as gcc ones use - all
we need is to internally convert final ... in the list to ident[__VA_ARGS__]
and set its ->next to &variable_argument. After that we don't need any
special-casing for them.
b) take parsing the argument list in a separate function and does
it with all sanity checks; normally it ends up with fewer tests than old
variant.
|
|
On top of previous patch, takes handling of macros body into a separate
function and cleans it up. No changes of behaviour (same tests).
|
|
> 1) no ## in the beginning or end of body. [6.10.3.3(1)]
> It's a warning, recovery consists in dropping them at #define time.
Fixed in the patch I'm testing, and I was wrong about proper recovery -
better ignore the entire definition than go on with mangled one.
> 2) ## that comes from argument does *not* have a special meaning;
> only one from the body does. [6.10.3.3(3)]
Fixed.
> 3) assuming left-to-right order of evaluation for ## (we are free
> to choose any [6.10.3.3(3)] and left-to-right is much easier when we get
> to merging tokens), if ## immediately follows another ## it can be treated
> as not having a special meaning (it will be merged with whatever precedes
> the first one and even if result of merge will be "##", it won't have a
> special meaning). IOW, in
> a ## b ## ## c ## ## ## d
> the 1st, 2nd, 4th and 6th ## will concatenate; 3rd and 5th ones will be
> merge arguments and won't merge anything themselves.
Fixed. The rest is not - it will be a separate patch. BTW, there's another
couple of bugs - see preprocessor9.c and preprocessor10.c for the stuff that
triggers them.
Parsing of macro bodies should be OK by now; the only missing check is
"the only place where __VA_ARGS__ can occur is in the body of macro with
argument list ending on ellipsis" and that will be dealt with later.
We get three new kinds of tokens - TOKEN_QUOTED_ARGUMENT (unexpanded arguments
next to ##), TOKEN_STR_ARGUMENT (#<argument>) and TOKEN_CONCAT (concatenation
operator). When we go through the body of macro at #define time, we
a) decide which ## will be operators there (see (3) above) and set
the type of those to TOKEN_CONCAT; retokenize() is looking for that
token_type() now instead of doing match_op().
b) collapse OP[#] IDENT[argument] to a single token -
STR_ARGUMENT[argnum]. expand_arguments() looks for that token type instead
of messing with match_op() + check that the next one is an argument.
c) mark the rest of arguments either as QUOTED_ARGUMENT or
MACRO_ARGUMENT, depending on whether they have a concatenation as neighbor
or not; expand_arguments() looks for that to decide if expand_one_arg()
should do expansion when subsitituting (instead of messing with checking
neighbors).
All that stuff is done in one pass and comes pretty much for free -
see handle_define() for details. And we get a nice payoff at expansion
time for that (will get more when we get to collecting the information on
arguments uses).
preprocessor{8,9,10}.c added; the first one shows the stuff fixed by
now; other two are still not handled correctly.
I don't see any regression - neither on validation/* stuff nor on full
kernel build.
|
|
This makes it take one bit (which we can just steal from the line
number), instead of four bytes.
|
|
comparison.
|
|
We taint identifiers when we are done with argument expansion; we
untaint them when scan gets through the "untaint" token we leave right
after the body of macro; we mark tokens noexpand in three situations:
1) when we copy a token marked noexpand;
2) when we get to expanding a token and see that its identifier is
currently tainted;
3) when we scan for closing ) and see an identifier token with
currently tainted identifier.
That makes sure that by the time we get past the expanded body (and
untaint the left-hand side of macro), all tokens bearing that identifier
will be seen and marked noexpand.
There is more elegant variant (it's practically straight from text of
standard - set noexpand only in dup_token() and make it
if (token_type(token) == TOKEN_IDENT)
alloc->noexpand = token->noexpand | token->ident->tainted;
which is as close as to transliteration of 6.10.3.4(2) as it gets), but
before we can go for it, we need to sort out another problem - order of
expansion/copying for arguments.
So for now here's an equivalent heavier variant with a wart ((3) above)
that works even with current expand_arguments() and when that gets sorted
out we'll be able to get anti-recursion logics absolutely straightforward.
And yes, it does preprocessor1.c correctly; it even get much subtler
preprocessor7.c right.
|
|
so the preprocessor "redefine" check should now be
exact.
Call me anal.
|
|
|
|
That's what everybody else does too.
|
|
We just move the arglist re-write up to before
the equality test, so that we have rewritten
the expansion in both the new and the old version.
Otherwise we'd get spurious differences due to
the rewriting and thus incorrect warnings.
|
|
Trivial observation: we don't have to check every bloody identifier in
the body of macro and see if it's a formal argument _every_ _time_ _we_
_do_ _substitution_.
New token type: TOKEN_MACRO_ARGUMENT, with token->argnum as its data.
Occurs only in bodies of macros with arguments.
handle_define() goes through the body, checks which identifier tokens
are arguments (using the same arg_number() we used to do on every
expansion) and turns those into TOKEN_MACRO_ARGUMENT ones.
expand_arguments() simply checks for TOKEN_MACRO_ARGUMENT.
expand_one_argument() doesn't need arglist argument anymore - it gets
argument number from token->argnum.
|
|
handling, we can simplify ## too. The previous code was
only needed because the tokenizer split things up too
much.
|
|
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.
|
|
It's not perfect now either, but it makes a hell of a lot more
sense now, and gets all the kernel cases I've tested right. Which
is actually saying quite a lot, since the kernel uses things that
are arguably not standard (the token fragments it pastes are not
valid tokens on their own, and I think that may be borderline in
ANSI - who knows).
It still doesn't do the _really_ strange cases, ie trying to
paste
a ## 0.e10
and expecting that to become "a0" "." "e10" is just not going
to happen. I think that's undefined behaviour anyway.
|
|
is an informational part of a previous warning, don't
count it as a separate warning.
|
|
This has been broken since day one, but since most uses
were to things that could happily live with just the
first argument in the list, we never noticed.
|
|
|
|
This fixes a bug in adding white space in macro expanding, which cause
drivers/atm/ambassador.c complain about include file not found and stop
the make.
The offensive macro is that
#define UCODE(x) UCODE2(atmsar11.x)
#define UCODE2(x) #x
UCODE(start)
It will expand to "atmsar11 . start" instead of "atmsar11.start"
|
|
This adds support support for variable macro arguments:
#define msg(fmt, ...) printf(fmt, __VA_ARGS__)
#define msg(fmt, arg...) printf(fmt, arg)
make ARCH=um will hit that kind of macros.
|
|
|
|
isn't the sole copyright owner these days.
|
|
|
|
Warn about internal "not implemented yet" kinds of things only
when verbose. These warnings have nothing to do with the sources
we're checking, they're only good for pointing out limitations
of sparse itself.
|
|
path to eventually start parsing them.
Basic approach: we'll replace the pragma line with some kind
of internal attribute-looking thing for the front end.
|
|
This update (hopefully) will allow 'check' to find the appropriate, gcc-local
include headers (dependent, of course, upon the system it was built on)
It's still a hack, but at least it will work in a few more places.
|
|
a string name, while <xxxx.h> searches only the path.
|
|
In the meantime this fixes some of it. The pre-processor is still a
horrible mess.
|
|
expanding the arguments, just the macro body. Otherwise
a simple
#define A(x) xx(x)
A(A(x))
would decide that the "inner" A(x) was a recursive expansion.
|
|
|
|
parenthood. I desperately tried to avoid expanding the size of a token
by using other means, but I couldn't fix the problems that led to.
The pre-processor is still a pile of crud and gets multi-token pasting
quite wrong (and probably other cases too). I should try to find some
test-suite, but I'm afraid of what it would find.
|
|
|
|
handling. This also should get relative includes right.
|
|
preparing for better include-path searching.
|
|
|
|
preparing for a public release.
|
|
macro expander busy only oevr its own expansion, not the expansion
of the arguments. That way the arguments can expand the same token
again, without hitting the recursion limiter.
|
|
take the semantic differences into account (a undefined symbol
behaves differently in a C parse tree than in a preprocessor
expression)
|
|
The last one gives a "context mask" and "context value" to a symbol,
which can be used to verify that the symbol is only used in a certain
context.
|
|
the real one when it goes out the door.
|
|
to it, instead of having everybody have pointers to "struct token"
only because they wanted to have the position.
Fix array addition type degeneration.
|
|
dangling anonymous "int_type" types with magic modifiers,
but turn all types into explicit C types.
|
|
|
|
|
|
|
|
evaluate.c instead of keeping it in pre-process.c.
Add the proper dependencies
|
|
left behind in "parse.h" when the files were split.
|
|
Make the stringifier stop at argument separators.
|
|
|
|
by '##' (ANSI C - Appending A �12.3)
|
|
|
|
away entirely if 'arg' is empty.
|
|
|
|
|
|
|
|
arguments in the functions involved instead.
|
|
|
|
to change it from the callers..
|
|
proper values.
Make macro re-declaration legal if the new and old
values match.
|
|
placeholder LICENSE file.
|
|
contain conditionals, but _not_ assignment expressions)
|
|
Fix up function argument list to use a proper symbol list.
|
|
EXPR_SIZEOF with the token being "alignof").
Remove stale debug printouts.
|
|
|
|
|
|
#ifndef X ... #endif X if X is already defined. This avoids
doing unnecessary work on duplicate includes.
|
|
|
|
so that the pre-processor might some day track them.
For now, make the pre-processor just mask them out of the stream.
|
|
Our pre-processor token allocator has different initialization needs
from the one in tokenize.c - don't try to share them.
|
|
|
|
meaningful in parsing: at preprocessor macro definition time, where
the whitespace between the macro name and the potentially following
'(' determines whether the macro takes arguments or not.
Make tokenization save off one bit of whitespace (in addition to the
one bit of newline that it already saves off).
|
|
- Notice loudly if one of out list walkers end up looping.
- Fix the 'defined(x)' case for preprocessor conditionals.
- Add the internal gcc headers to the search path.
- Fix '#else' mixup with '#elif'
|
|
|
|
splitting it up into several smaller functions.
|
|
|
|
|
|
expressions by just walking the parse tree.
We de-allocate all the C preprocessor expressions at the end, before
we actually start doing the real C parsing. There is no history.
|
|
|
|
at the right point.
|
|
right expression parsing.
|
|
self-expansions.
In particular
#define A a B
#define B b C
#define C c A
A
should result in 'a b c A' since 'A' won't be recursively expanded.
|
|
instead of passing around a pointer to a static buffer that will change.
|
|
we can't just switch from a false region to a true region. Use a
"elif_ignore[]" stack to keep track of our elif nesting behaviour.
|
|
preprocessor and the "real" parser can share them.
Add some initial preprocessor expression parsing.
|
|
'elif'.
|
|
sanely and efficiently, including proper nesting.
Add 'undef'/'error'/'warning' support.
|
|
symbol expansion (ie no argument-handling yet).
Mark the EOF token as being on a new line, to make preprocessing simpler.
|
|
Make tokens know about newlines
|