================ @@ -852,6 +877,58 @@ static bool areExprsMacroAndNonMacro(const Expr *&LhsExpr, return LhsLoc.isMacroID() != RhsLoc.isMacroID(); } + +static bool areExprsSameMacroOrLiteral(const BinaryOperator *BinOp, + const ASTContext *Context) { + + if (!BinOp) + return false; + + const auto *Lhs = BinOp->getLHS(); + const auto *Rhs = BinOp->getRHS(); + const SourceManager &SM = Context->getSourceManager(); + + SourceRange Lsr = Lhs->getSourceRange(); + SourceRange Rsr = Rhs->getSourceRange(); + if (Lsr.getBegin().isMacroID()) { + // Left is macro so right macro too + if (Rsr.getBegin().isMacroID()) { + // Both sides are macros so they are same macro or literal + llvm::StringRef L = Lexer::getSourceText( + CharSourceRange::getTokenRange(Lsr), SM, LangOptions(), 0); + llvm::StringRef R = Lexer::getSourceText( + CharSourceRange::getTokenRange(Rsr), SM, LangOptions(), 0); + return L.compare(R) == 0; + } + // Left is macro but right is not so they are not same macro or literal + return false; + } else { + const IntegerLiteral *Lil = dyn_cast<IntegerLiteral>(Lhs); + const IntegerLiteral *Ril = dyn_cast<IntegerLiteral>(Rhs); + if (Lil && Ril) { + return Lil->getValue() == Ril->getValue(); + } + + const StringLiteral *LStrl = dyn_cast<StringLiteral>(Lhs); ---------------- EugeneZelenko wrote:
Ditto. https://github.com/llvm/llvm-project/pull/121960 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits