================ @@ -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; ---------------- PiotrZSL wrote:
what with ``` #define getX(x) x int var = getX(1) > getX( 1); ``` In such case string compare won't work. 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