This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] avoid scheduling volatiles across sequence points


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>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]