================
@@ -1140,6 +1143,152 @@ static bool ProcessFormatStringLiteral(const Expr 
*FormatExpr,
   return false;
 }
 
+static std::optional<int> getPathMaxValue(const ASTContext &Ctx) {
+  if (Ctx.getTargetInfo().getTriple().isOSGlibc())
+    return {4096};
+
+  if (Ctx.getTargetInfo().getTriple().isOSDarwin())
+    return {1024};
+
+  return std::nullopt;
+}
+
+/* Follow simple references to other macros so we can match the Expr spelling 
*/
+static const MacroInfo *resolveMacroChainAtLoc(Preprocessor &PP,
+                                               const IdentifierInfo *MII,
+                                               SourceLocation Loc) {
+  auto *MI = PP.getMacroDefinitionAtLoc(MII, Loc).getMacroInfo();
+  if (!MI)
+    return nullptr;
+  const IdentifierInfo *MIIN = MII;
+  while (MI->getNumTokens() == 1 && MI->tokens_begin()->is(tok::identifier) &&
+         (MIIN = MI->tokens_begin()->getIdentifierInfo()) &&
+         MIIN->hasMacroDefinition()) {
+    MacroDefinition MacroDef = PP.getMacroDefinitionAtLoc(MIIN, Loc);
+    MI = MacroDef.getMacroInfo();
+  }
+  return MI;
+}
+
+// Search subexpressions for macros and attempt to evaluate them
+class MacroFlagMatcher : public ConstDynamicRecursiveASTVisitor {
----------------
ColinKinloch wrote:

In my first pass at writing visitor it stopped traversing and reported failure 
when a visited sub-expression was not a macro, integer literal, "or" operation 
or parenthesis.  If it successfully reached the end of the expression it would 
return a list of searched macros it found along the way.

This would avoid evaluating anything but not warn if the flags value is at all 
complicated.

Would that search be preferable?

https://github.com/llvm/llvm-project/pull/177286
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to