[clang-tools-extra] [clang-tidy] Add new `bugprone-suspicious-pointer-arithmetics-using-sizeof` (`cert-arr39-c`) check (PR #106061)
Nicolas van Kempen via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 27 14:35:21 PDT 2024
================
@@ -0,0 +1,31 @@
+//===--- SuspiciousPointerArithmeticsUsingSizeofCheck.h -------*- C++ -*---===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SUSPICIOUSPOINTERARITHMETICSUSINGSIZEOFCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SUSPICIOUSPOINTERARITHMETICSUSINGSIZEOFCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// Finds suspicious pointer arithmetic calculations where the pointer is
+/// offset by an alignof(), offsetof(), or sizeof() expression.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/suspicious-pointer-arithmetics-using-sizeof.html
+class SuspiciousPointerArithmeticsUsingSizeofCheck : public ClangTidyCheck {
+public:
+ SuspiciousPointerArithmeticsUsingSizeofCheck(StringRef Name,
+ ClangTidyContext *Context);
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
----------------
nicovank wrote:
```
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
```
Support C and C++? Maybe add a C++ test file testing the three operations, also testing with template types.
https://github.com/llvm/llvm-project/pull/106061
More information about the cfe-commits
mailing list