================
@@ -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;
----------------
earnol wrote:
I agree, but in this case the both sides are not literally the same.
I propose to make it space for improvement.
https://github.com/llvm/llvm-project/pull/121960
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits