forked from OSchip/llvm-project
[clang][sema] Ignore xor-used-as-pow if both sides are macros
This happens in codebases a lot, which use xor where both sides are macros. Using xor in that case is not the common error-prone 2^6 code that the warning was introduced for. Don't diagnose such a use of xor. Differential Revision: https://reviews.llvm.org/D97445
This commit is contained in:
parent
f4d78a5e3a
commit
2cc58463ca
|
@ -12102,6 +12102,11 @@ static void diagnoseXorMisusedAsPow(Sema &S, const ExprResult &XorLHS,
|
|||
if (Loc.isMacroID())
|
||||
return;
|
||||
|
||||
// Do not diagnose if both LHS and RHS are macros.
|
||||
if (XorLHS.get()->getExprLoc().isMacroID() &&
|
||||
XorRHS.get()->getExprLoc().isMacroID())
|
||||
return;
|
||||
|
||||
bool Negative = false;
|
||||
bool ExplicitPlus = false;
|
||||
const auto *LHSInt = dyn_cast<IntegerLiteral>(XorLHS.get());
|
||||
|
|
|
@ -65,6 +65,7 @@ void test(unsigned a, unsigned b) {
|
|||
|
||||
res = 2 ^ 0x4;
|
||||
res = 2 ^ 04;
|
||||
res = TWO ^ TEN;
|
||||
res = 0x2 ^ 10;
|
||||
res = 0X2 ^ 10;
|
||||
res = 02 ^ 10;
|
||||
|
|
Loading…
Reference in New Issue