This is an archive of the discontinued LLVM Phabricator instance.

[clang][sema] Ignore xor-used-as-pow if both sides are macros
ClosedPublic

Authored by tbaeder on Feb 24 2021, 11:25 PM.

Details

Summary

I've read both https://reviews.llvm.org/D63423 and https://reviews.llvm.org/D66397, but I think both of them miss the case where both RHS and LHS of the XOR are macros, and thus the warning should not be emitted (I think).

I ran into this while compiling elfutils with clang and all the available changes to the code seem non-sensical and the warning in clang seems misplaced given that both operands are macros, even if the left side evaluates to 2 and the right side to 10, for example. They are just used as state.

I know this warning (in conjunction with macros especially) has been discussed a lot in the past (as far as I know regarding the Chrome code base), but this patch is very conservative regarding the change to the warning semantics. And the case it changes was not even covered by the tests. I've added a test for it now.

Diff Detail

Event Timeline

tbaeder requested review of this revision.Feb 24 2021, 11:25 PM
tbaeder created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 24 2021, 11:25 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

No problem, +1

aaron.ballman accepted this revision.Feb 25 2021, 5:04 AM

LGTM with a small nit, thanks!

clang/lib/Sema/SemaExpr.cpp
12105
This revision is now accepted and ready to land.Feb 25 2021, 5:04 AM

Thanks everyone!