This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: volatile is not volatile enough
- From: Richard Earnshaw <rearnsha at arm dot com>
- To: Hirogen2 <hirogen2 at gmx dot de>
- Cc: gcc-bugs at gcc dot gnu dot org, Richard dot Earnshaw at arm dot com
- Date: Wed, 25 Jun 2003 15:33:35 +0100
- Subject: Re: volatile is not volatile enough
- Organization: ARM Ltd.
- Reply-to: Richard dot Earnshaw at arm dot com
> Hi,
>
> given a statement like
> int a[2];
> func2(func1(a), a[0], a[1]);
> where a is modified by func1, func2 receives wrong input on the stack. In
> detail, first a[1], then a[0] and then a is pushed onto the stack, then func1
> gets called and pops off its a -- which is modified after.
> Adding the keyword volatile doesnot help.
>
> I am using gcc 3.3 20030226 (prerelease) SuSE Linux 8.2.
>
> Here is a test script:
> #include <stdio.h>
> #define volatile
>
> volatile void *func1(volatile int[]);
> volatile void *func2(volatile void *, volatile int, volatile int);
>
> int main(void) {
> volatile int a[2] = {13, 101};
> volatile void *result;
>
> /* IMPACT
> The result on stdout should be x=14 y=102 not x=13 y=101.
> */
> func2(func1(a), a[0], a[1]);
>
Wrong. The result is unspecified. iso/iec 9899:1990 6.3.2.2 "The order
of evaluation of the function designator, the arguments and subexpressions
within the arguments is unspecified, but there is a sequence point before
the actual call."
R.