This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] avoid scheduling volatiles across sequence points
- From: Geoff Keating <geoffk at geoffk dot org>
- To: Eric Christopher <echristo at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: 30 May 2002 23:28:16 -0700
- Subject: Re: [PATCH] avoid scheduling volatiles across sequence points
- References: <1022811488.11077.71.camel@ghostwheel.cygnus.com>
Eric Christopher <echristo@redhat.com> writes:
> OK. My confidence that this is the right way to go is very low, but I
> thought that I'd send it here first.
>
> So, the testcase:
>
> volatile int flag = 0;
>
> extern struct {
> int mode;
> int offset;
> int size;
> } buffer[];
>
> void foo(int i, int track)
> {
> int parent;
> int check;
>
> flag = 1;
> buffer[i].offset = track * buffer[parent].size;
> flag = 0;
> }
>
> Now, this doesn't trigger on x86, but does on every mips I could test,
> as well as ppc.
>
> Effectively the scheduler takes the code from:
>
> <volatile write>
> <seq point>
> <volatile write>
>
> to:
>
> <seq point>
> <volatile write>
> <volatile write>
>
> Which is, of course, incorrect.
No, it's OK. The compiler is allowed to rearrange other memory
accesses so long as it keeps volatile accesses and file operations in
program order. 'program order' is determined by sequence points.
--
- Geoffrey Keating <geoffk@geoffk.org> <geoffk@redhat.com>