[clang] Run PreStmt/PostStmt checker for GCCAsmStmt (PR #95409)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 10 00:34:59 PDT 2024


================
@@ -0,0 +1,90 @@
+//===- ExprEngineVisitTest.cpp -----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CheckerRegistration.h"
+#include "clang/AST/Stmt.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+
+void emitErrorReport(CheckerContext &C, const BugType &Bug,
+                     const std::string &Desc) {
+  if (ExplodedNode *Node = C.generateNonFatalErrorNode(C.getState())) {
+    auto Report = std::make_unique<PathSensitiveBugReport>(Bug, Desc, Node);
+    C.emitReport(std::move(Report));
+  }
+}
+
+class ExprEngineVisitPreChecker : public Checker<check::PreStmt<GCCAsmStmt>> {
+public:
+  void checkPreStmt(const GCCAsmStmt *ASM, CheckerContext &C) const {
+    emitErrorReport(C, Bug, "PreStmt<GCCAsmStmt>");
+  }
+
+private:
+  const BugType Bug{this, "GCCAsmStmtBug"};
+};
+
+class ExprEngineVisitPostChecker : public Checker<check::PostStmt<GCCAsmStmt>> {
+public:
+  void checkPostStmt(const GCCAsmStmt *ASM, CheckerContext &C) const {
+    emitErrorReport(C, Bug, "PostStmt<GCCAsmStmt>");
+  }
+
+private:
+  const BugType Bug{this, "GCCAsmStmtBug"};
+};
----------------
steakhal wrote:

I think you could merge these two into a single class.
Similar goes to the other parts. To me `asm stmt` is itself a thing to test.
But it's just a personal preference.
One other way to look at this is basically the combinatorical explosion of the tests if we wanted to cover all other statements and different callback kinds. The boilerplate to useful code would just blow up.

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


More information about the cfe-commits mailing list