[clang] [Webkit Checkers] Introduce a Webkit checker for memory unsafe casts (PR #114606)

via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 4 12:53:09 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff c3d15188cfe243900895a4f2c4f36b84e14928b7 c21e665617d588ae26b394deb0420969a4a263a5 --extensions cpp -- clang/lib/StaticAnalyzer/Checkers/WebKit/MemoryUnsafeCastChecker.cpp clang/test/Analysis/Checkers/WebKit/memory-unsafe-cast.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/MemoryUnsafeCastChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/MemoryUnsafeCastChecker.cpp
index a7bd056965..eeaccf9b70 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/MemoryUnsafeCastChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/MemoryUnsafeCastChecker.cpp
@@ -10,8 +10,8 @@
 // base type to a derived type.
 //===----------------------------------------------------------------------===//
 
-#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -30,8 +30,9 @@ static constexpr const char *const WarnRecordDecl = "WarnRecordDecl";
 
 class MemoryUnsafeCastChecker : public Checker<check::ASTCodeBody> {
   BugType BT{this, "Unsafe cast", "WebKit coding guidelines"};
+
 public:
-  void checkASTCodeBody(const Decl *D, AnalysisManager& Mgr,
+  void checkASTCodeBody(const Decl *D, AnalysisManager &Mgr,
                         BugReporter &BR) const;
 };
 } // end namespace
@@ -118,7 +119,7 @@ void MemoryUnsafeCastChecker::checkASTCodeBody(const Decl *D,
                 hasDeclaration(decl(cxxRecordDecl().bind(BaseNode))))))),
             hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
                 decl(cxxRecordDecl(isDerivedFrom(equalsBoundNode(BaseNode)))
-                     .bind(DerivedNode)))))),
+                         .bind(DerivedNode)))))),
             unless(anyOf(hasSourceExpression(hasDescendant(cxxThisExpr())),
                          hasType(templateTypeParmDecl()))));
 

``````````

</details>


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


More information about the cfe-commits mailing list