[clang] [clang][analyzer] Check initialization and argument passing in FixedAddressChecker (PR #110977)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 3 03:25:31 PDT 2024


================
@@ -63,11 +62,39 @@ void FixedAddressChecker::checkPreStmt(const BinaryOperator *B,
         "Using a fixed address is not portable because that address will "
         "probably not be valid in all environments or platforms.";
     auto R = std::make_unique<PathSensitiveBugReport>(BT, Msg, N);
-    R->addRange(B->getRHS()->getSourceRange());
+    R->addRange(SrcExpr->getSourceRange());
     C.emitReport(std::move(R));
   }
 }
 
+void FixedAddressChecker::checkPreStmt(const BinaryOperator *B,
+                                       CheckerContext &C) const {
+  if (B->getOpcode() != BO_Assign)
+    return;
+
+  checkUseOfFixedAddress(B->getType(), B->getRHS(), C);
+}
+
+void FixedAddressChecker::checkPreStmt(const DeclStmt *D,
+                                       CheckerContext &C) const {
+  for (const auto *D1 : D->decls()) {
+    if (const auto *VD1 = dyn_cast<VarDecl>(D1); VD1 && VD1->hasInit())
+      checkUseOfFixedAddress(VD1->getType(), VD1->getInit(), C);
+  }
+}
+
+void FixedAddressChecker::checkPreStmt(const CallExpr *CE,
+                                       CheckerContext &C) const {
+  const FunctionDecl *Callee = CE->getDirectCallee();
+  if (!Callee)
+    return;
+  if (CE->getNumArgs() != Callee->getNumParams())
----------------
steakhal wrote:

Why do you disallow default parametered functions (when calling them with fewer arguments than params)?

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


More information about the cfe-commits mailing list