This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Re[2]: gcc 2.95.2 problem: alloca done within argument list evaluation, corrupts the rest of the argument list
- To: etienne dot lorrain at ibm dot net
- Subject: Re: Re[2]: gcc 2.95.2 problem: alloca done within argument list evaluation, corrupts the rest of the argument list
- From: Alexandre Oliva <oliva at lsd dot ic dot unicamp dot br>
- Date: 14 Jan 2000 09:22:03 -0200
- Cc: gcc-bugs at gcc dot gnu dot org
- References: <20000114105745.15716.qmail@web1901.mail.yahoo.com>
On Jan 14, 2000, Etienne LORRAIN <etienne_lorrain@yahoo.fr> wrote:
>> >> f (yyy((t1 = alloca(ALLOCA_SIZE),xxx(t1))), 2);
>> ^ matches ^
>> > undefined behavior: t1 is used and changed without
>> > resynchronisation point in between.
>> But there is a sequence point. t1=alloca(...) and xxx(t1) are
>> arguments or a function call, they form a single expression by means
>> of the comma operator.
oops, I meant they are *not* arguments to a function call.
> The comma operator is not a sequence point - at least if it
> did not changed on the last C standart.
I can't tell for C, but in C++, when comma is used as the comma
operator (as in the code snippet), not as an argument separator, it
definitely is a sequence point.
>> That's not true in general. In fact, there's no such thing as
>> `push'ing arguments in C. But, on x86, it's true, arguments are
>> usually evaluated from right to left, because arguments are passed on
>> the stack. But you already knew that :-)
> Was true for the 8 (really different) processor I used at work...
> In fact I do not know a real implementation of C without a stack,
> or how to implement varargs without a stack and pushing params
> right to left.
Any architecture that doesn't provide a fast push instruction doesn't
often lead to right-to-left evaluation of arguments. Moreover, most
RISC architectures use registers to pass (some) arguments, so the
order of evaluation of arguments just doesn't matter. And, even when
the arguments won't fit in the registers used for this purpose, and
they have to be passed in the stack, on most RISC architectures you'll
get the stack space pre-allocated for all arguments before any of them
is evaluated, and then, they're evaluated in any order and stored in
the appropriate places in the stack.
> It you want your trick, use a synchronisation point, i.e. a semicolon,
> like this:
> f (yyy( ({ t1 = alloca(ALLOCA_SIZE); xxx(t1) }) ), 2);
> ^^ ^ ^^
> That is a GCC extension, see:
> http://gcc.gnu.org/onlinedocs/gcc_4.html#SEC63
I don't think this is any different from the code snippet above,
except that it needlessly uses a GCC extension, but it gains nothing,
since alloca is still being called as part of an function-argument
expression.
--
Alexandre Oliva http://www.ic.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{lsd.ic.unicamp.br,guarana.{org,com}} aoliva@{acm,computer}.org
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them