Hint = FixItHint::CreateReplacement(BinCmpRewritten->getSourceRange(),
ReplacementText);
} else if (BinaryOp) { // Determine the correct transformation.
+ const auto *LiteralLHS =
+ llvm::dyn_cast<IntegerLiteral>(BinaryOp->getLHS()->IgnoreImpCasts());
+ const auto *LiteralRHS =
+ llvm::dyn_cast<IntegerLiteral>(BinaryOp->getRHS()->IgnoreImpCasts());
+ const bool ContainerIsLHS = !LiteralLHS;
+
+ uint64_t Value = 0;
+ if (LiteralLHS)
+ Value = LiteralLHS->getValue().getLimitedValue();
+ else if (LiteralRHS)
+ Value = LiteralRHS->getValue().getLimitedValue();
+ else
+ return;
+
bool Negation = false;
- const bool ContainerIsLHS =
- !llvm::isa<IntegerLiteral>(BinaryOp->getLHS()->IgnoreImpCasts());
const auto OpCode = BinaryOp->getOpcode();
- uint64_t Value = 0;
- if (ContainerIsLHS) {
- if (const auto *Literal = llvm::dyn_cast<IntegerLiteral>(
- BinaryOp->getRHS()->IgnoreImpCasts()))
- Value = Literal->getValue().getLimitedValue();
- else
- return;
- } else {
- Value =
- llvm::dyn_cast<IntegerLiteral>(BinaryOp->getLHS()->IgnoreImpCasts())
- ->getValue()
- .getLimitedValue();
- }
// Constant that is not handled.
if (Value > 1)