[LLVMdev] LLVM introduces racy read - Unsafe transformation?
David Chisnall
David.Chisnall at cl.cam.ac.uk
Mon Jan 26 07:44:47 PST 2015
On 26 Jan 2015, at 15:22, sohachak at mpi-sws.org wrote:
>
> The source program has no data race if flag=false. But the target program
> is racy due to the introduced load(a) operation.
>
> This is a benign race since the load(a) is used only when flag=true.
>
> However, according to the C11/C++11 consistency model the semantics of a
> racy program is undefined and may have arbitrary behavior.
It's not clear to me that this is correct. Neither variable is atomic and so loads do not establish happens-before edges. The load of a is not observable and so is safe to hoist. According to the C[++]11 model the transformed version appears correct. There is no guarantee of serialisation of the loads of flag and a, because neither is atomic.
It's not actually clear to me that the original is race-free. If flag ever transitions from false to true without something else that establishes a happens-before relationship between these two threads then this is racy. If flag is always false, then this is not racy and the LLVM output is not *observably* racy (the IR does not permit this load to have observable side effects, and its result is never used). If flag is always true then this is racy. If flag transitions from true to false without a happens-before edge, then this is also racy.
David
More information about the llvm-dev
mailing list