[LLVMdev] Aliasing of volatile and non-volatile
Eli Friedman
eli.friedman at gmail.com
Wed Sep 4 14:48:49 PDT 2013
On Wed, Sep 4, 2013 at 2:33 PM, Krzysztof Parzyszek <kparzysz at codeaurora.org
> wrote:
> A customer has reported a performance problem, which I have eventually
> tracked down to the following situation:
>
> Consider this program:
>
> int foo(int *p, volatile int *q, int n) {
> int i, s = 0;
> for (i = 0; i < n; ++i)
> s += *p + *q;
> return s;
> }
>
>
> 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.
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.
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.
(The section in the standard is 6.5p7.)
-Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130904/31e30f32/attachment.html>
More information about the llvm-dev
mailing list