Clang tautological-compare fails to warn in cases where gcc doesn't

Here is a simple test where clang fails to issue a warning in the first function but warns in the second function. gcc (6.x and above) gives a warning in both cases. Is the pointer dereference throwing clang off? Why should the pointer dereference matter in this case?

I suspect that clang cannot satisfy itself that the x->a cannot be changed by somebody else between the evaluation of the lhs and the rhs of the comparison.
All it knows is that the function cmp cannot modify it.
I’d say clang is correct, but I haven’t studied the problem much.


It’s not volatile, so it seems inappropriate for clang to think that it could be modified in between. In fact, at -O1, the comparisons are optimized out anyway, so it’s clear that the warning should be in place to tell developers that this comparison is not going to be performed:

cmp(Foo const*, Foo const*): # @cmp(Foo const*, Foo const*)
xor eax, eax

(clang 6.0.0)

I agree. Clang should warn in this case. If ‘const’ is changed to ‘volatile’, then gcc doesn’t warn either (as expected).

I will file a bug.