[clang] [clang][Sema] Warn when macro operator mixes with outer operand due to precedence (PR #184924)
Rajveer Singh Bharadwaj via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 7 04:29:36 PST 2026
================
@@ -15844,6 +15844,55 @@ static void DiagnoseShiftCompare(Sema &S, SourceLocation OpLoc,
SourceRange(OCE->getArg(1)->getBeginLoc(), RHSExpr->getEndLoc()));
}
+static bool operandEscapesImmediateMacroExpansion(const SourceManager &SM,
+ SourceLocation OpLoc,
+ SourceRange OperandRange) {
+
+ if (!OpLoc.isMacroID())
+ return false;
+
+ SourceLocation Begin = OperandRange.getBegin();
+ SourceLocation End = OperandRange.getEnd();
+
+ if (!Begin.isValid() || !End.isValid())
+ return false;
+
+ // If operand comes directly from file → definitely escapes
+ if (!Begin.isMacroID() || !End.isMacroID())
+ return true;
+
+ // Compare the immediate expansion location
+ SourceLocation OpExp = SM.getImmediateMacroCallerLoc(OpLoc);
+ SourceLocation BeginExp = SM.getImmediateMacroCallerLoc(Begin);
+ SourceLocation EndExp = SM.getImmediateMacroCallerLoc(End);
+
+ return BeginExp != OpExp || EndExp != OpExp;
+}
----------------
Rajveer100 wrote:
```suggestion
}
```
https://github.com/llvm/llvm-project/pull/184924
More information about the cfe-commits
mailing list