[clang] [analyzer] Teach analzer about ms __analyzer_assume(bool) and friends (PR #80456)

via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 2 09:07:19 PST 2024


================
@@ -26,10 +27,41 @@ namespace {
 class BuiltinFunctionChecker : public Checker<eval::Call> {
 public:
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
+
+private:
+  const CallDescriptionSet MicrosoftAnalysisAssume{
+      {{"__analysis_assume"}, 1},
+      {{"_Analysis_assume_"}, 1},
+  };
+
+  void evalCallAssume(const CallEvent &Call, CheckerContext &C) const;
 };
 
 }
 
+void BuiltinFunctionChecker::evalCallAssume(const CallEvent &Call,
+                                            CheckerContext &C) const {
+  assert(Call.getNumArgs() > 0);
+  assert(Call.getResultType()->isVoidType());
+  SVal Arg = Call.getArgSVal(0);
+
+  if (Arg.isUndef())
+    return; // Return true to model purity.
+
+  ProgramStateRef State = C.getState();
+  State = State->assume(Arg.castAs<DefinedOrUnknownSVal>(), true);
+
+  // FIXME: do we want to warn here? Not right now. The most reports might
+  // come from infeasible paths, thus being false positives.
----------------
NagyDonat wrote:

I'm pretty sure that we don't want to warn here. This analyzer-specific hint/override is presumably used in code that's confusing for the analyzer, so let's trust it.

https://github.com/llvm/llvm-project/pull/80456


More information about the cfe-commits mailing list