C11, -Wunsequenced and aliasing

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?

Maybe this kind of analysis isn't for clang, and instead is for the clang static analyser.

Thank you in advance!

Sam

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

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

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).