* pre-process.c:569:18: error: bad constant expression
@ 2005-12-31 7:30 Alecs King
2005-12-31 19:31 ` Linus Torvalds
0 siblings, 1 reply; 4+ messages in thread
From: Alecs King @ 2005-12-31 7:30 UTC (permalink / raw)
To: linux-sparse
int nargs = sym->arglist ? sym->arglist->count.normal : 0;
struct arg args[nargs];
gcc went fine but sparse complaint about this. Declaring such kind of
variable-sized arrays is allowed or not? Seems 'nargs' cannot be
evaluated until runtime..?
--
Alecs King
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: pre-process.c:569:18: error: bad constant expression 2005-12-31 7:30 pre-process.c:569:18: error: bad constant expression Alecs King @ 2005-12-31 19:31 ` Linus Torvalds 2005-12-31 19:50 ` Linus Torvalds 0 siblings, 1 reply; 4+ messages in thread From: Linus Torvalds @ 2005-12-31 19:31 UTC (permalink / raw) To: Alecs King; +Cc: linux-sparse On Sat, 31 Dec 2005, Alecs King wrote: > > int nargs = sym->arglist ? sym->arglist->count.normal : 0; > struct arg args[nargs]; > > gcc went fine but sparse complaint about this. Declaring such kind of > variable-sized arrays is allowed or not? Seems 'nargs' cannot be > evaluated until runtime..? sparse doesn't really do C99, it does a mixture of traditional ANSI C with many (but not all) of the newer features. And sometimes it refuses to do traditional ANSI C too (warning about function prototypes without an explicit "(void)" to show that there are no arguments etc). And one of the things it doesn't like is variable-sized arrays. It will actually correctly handle _some_ aspects of them (it should parse them and so on)), but never got it working properly even enough to make "sizeof" work, and they are not liked in the kernel sources, so it warns about them. Variable-sized arrays really are pretty nasty to handle. I'e made "array_size" be a "struct expression *" in preparation for allowing it to be supported, but much more is needed. Linus ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: pre-process.c:569:18: error: bad constant expression 2005-12-31 19:31 ` Linus Torvalds @ 2005-12-31 19:50 ` Linus Torvalds 2005-12-31 21:19 ` Linus Torvalds 0 siblings, 1 reply; 4+ messages in thread From: Linus Torvalds @ 2005-12-31 19:50 UTC (permalink / raw) To: Alecs King; +Cc: linux-sparse On Sat, 31 Dec 2005, Linus Torvalds wrote: > > And one of the things it doesn't like is variable-sized arrays. It will > actually correctly handle _some_ aspects of them (it should parse them and > so on), but never got it working properly even enough to make "sizeof" > work Just in case somebody cares, a partial list of the problems I know about with variable-sized arrays as far as current sparse is concerned: - sparse just generates a list of symbols per block (and per function). That's correct and proper for _all_ other kinds of variables, but not for variable-sized ones. Why? Because those depend on where in the block they are declared. Example: int main(int argc, char **argv) { char p[argc]; argc++; char q[argc]; return sizeof(p) + sizeof(q); } iow, we'd have to make variable declarations real statements in the statement list. Which is by no means impossible, but it's a big change for something that has little gain for _me_ (ie the kernel). So I'm personally not very likely to do it. Side note: it's not just variable-sized arrays that need this. Any initializers of mixed declarations also have this same issue. That's another thing sparse warns about right now, as you already noticed. - "sizeof()" needs to generate a temporary variable. Example: int main(int argc, char **argv) { char p[argc++]; return sizeof(p); } should obviously return the original value of "argc", and only evaluate the expression once. The way sparse is set up right now, we parse the expression properly, but we don't create the internal temporary result for it. This is likely a fairly small change, though. If those two problems are fixed, sparse probably could handle variable-sized arrays fairly well. Linus ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: pre-process.c:569:18: error: bad constant expression 2005-12-31 19:50 ` Linus Torvalds @ 2005-12-31 21:19 ` Linus Torvalds 0 siblings, 0 replies; 4+ messages in thread From: Linus Torvalds @ 2005-12-31 21:19 UTC (permalink / raw) To: Alecs King; +Cc: linux-sparse On Sat, 31 Dec 2005, Linus Torvalds wrote: > > Just in case somebody cares, a partial list of the problems I know > about with variable-sized arrays as far as current sparse is concerned: > > - sparse just generates a list of symbols per block (and per function). Ok, I fixed this one. Instead of having just a list of symbols per block, declarations are not a special kind of statement in the block. It wasn't even that hard to do, although the amount of testing my change-over has gotten is pretty minimal. So sparse now gets int test(int arg) { int a = arg; arg++; int b = arg; return a+b; } right, which it didn't use to do (it would end up rewriting the above as symbol_list: a = arg; b = arg; statement_list: arg++; return a+b; and thus return "arg+arg" rather than "arg+arg+1". It still warns about mixing code and declarations, and there are still other issues that keep it from handling variable-sized arrays, but I think this was the main "conceptual" difficulty in sparse to handling some of it. Linus ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-12-31 21:19 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2005-12-31 7:30 pre-process.c:569:18: error: bad constant expression Alecs King 2005-12-31 19:31 ` Linus Torvalds 2005-12-31 19:50 ` Linus Torvalds 2005-12-31 21:19 ` Linus Torvalds
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.