<div dir="ltr">On Wed, Sep 4, 2013 at 2:33 PM, Krzysztof Parzyszek <span dir="ltr"><<a href="mailto:kparzysz@codeaurora.org" target="_blank">kparzysz@codeaurora.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">A customer has reported a performance problem, which I have eventually tracked down to the following situation:<br>
<br>
Consider this program:<br>
<br>
int foo(int *p, volatile int *q, int n) {<br>
  int i, s = 0;<br>
  for (i = 0; i < n; ++i)<br>
    s += *p + *q;<br>
  return s;<br>
}<br>
<br>
<br>
LLVM's analysis indicates that *p and *q can alias, even though *p is non-volatile whereas *q is volatile.  I don't have the exact section from the C standard, but if I remember correctly, accessing volatile memory via a non-volatile object results in an undefined behavior.</blockquote>
<div><br></div><div>Accessing a variable declared as "volatile int" through a non-volatile pointer isn't allowed.  Accessing a variable declared as non-volatile "int" through a volatile pointer is allowed.</div>
<div><br></div><div>You might be able to reason out that either p and q don't alias, or q points to non-volatile memory... but that's substantially more complicated than what you're proposing.</div><div><br></div>
<div>(The section in the standard is 6.5p7.)</div><div><br></div><div>-Eli</div></div></div></div>