[cfe-dev] C11, -Wunsequenced and aliasing

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Thu Aug 17 13:56:33 PDT 2017


On 17 August 2017 at 12:35, Sam Elliott via cfe-dev <cfe-dev at lists.llvm.org>
wrote:

> Hi Cfe-dev,
>
> I asked the questions below on cfe-users, to no reply. I was wondering if
> any clang developers could shed light on this issue.
>
> Sam
>
> On 26 Jul 2017, at 4:38 pm, Archibald Samuel Elliott <
> ashe2 at cs.washington.edu> wrote:
>
> Hi Clang-users!
>
> What are the expectations for the -Wunsequenced warning in Clang with C11?
>
> My understanding was the following expression would be unsequenced
> according to the spec, but clang doesn't give me a warning:
>
> ((*p = 3) + (*q = 4))
>
> Is clang only going to warn if it knows p and q definitely alias each
> other here?
>
> I also tried the expression:
>
> ((*p = 3) + (*p = 4))
>
> Which also gave no warnings, despite p aliasing itself.
>
> Is the warning based on a heuristic of whether the unsequenced behaviour
> will be observable, or on whether the two assignments ever alias, or will
> it only warn if it knows two side-effecting expressions are definitely
> unsequenced?
>
> Clang's warning is extremely superficial and conservative at the moment:
it only warns if it sees unsequenced operations on the same variable, which
is referenced directly. So ((n = 3) + (n = 4)) will warn, but ((*p = 3) +
(*p = 4)) will not.

> Maybe this kind of analysis isn't for clang, and instead is for the clang
> static analyser.
>
> Yes, if you want to be able to catch more subtle cases, and especially
cases where two different pointers may alias the same storage, that would
be best handled by the Clang Static Analyzer (though I think it doesn't
have any checking for unsequenced operations as yet).

> Thank you in advance!
>
> Sam
>
>
> --
> Archibald Sam Elliott
> ashe2 at cs.washington.edu
> PhD Student, PLSE Group
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170817/361e17e5/attachment.html>


More information about the cfe-dev mailing list