[clang-tools-extra] [clang-tidy] Rename `cert-flp30-c` to `bugprone-avoid-float-loop-counter` (PR #166571)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 5 07:20:18 PST 2025
https://github.com/zeyi2 created https://github.com/llvm/llvm-project/pull/166571
Closes [#157291](https://github.com/llvm/llvm-project/issues/157291)
>From 7b24432b9ec88c5a5dd66fcc2179356ffb0a8db7 Mon Sep 17 00:00:00 2001
From: mtx <mitchell.xu2 at gmail.com>
Date: Wed, 5 Nov 2025 22:28:54 +0800
Subject: [PATCH] [clang-tidy] Rename `cert-flp30-c` to
`bugprone-avoid-float-loop-counter`
---
.../AvoidFloatLoopCounterCheck.cpp} | 10 +++++-----
.../AvoidFloatLoopCounterCheck.h} | 16 ++++++++--------
.../clang-tidy/bugprone/BugproneTidyModule.cpp | 3 +++
.../clang-tidy/bugprone/CMakeLists.txt | 1 +
.../clang-tidy/cert/CERTTidyModule.cpp | 5 +++--
clang-tools-extra/clang-tidy/cert/CMakeLists.txt | 1 -
clang-tools-extra/docs/ReleaseNotes.rst | 5 +++++
.../checks/bugprone/avoid-float-loop-counter.rst | 13 +++++++++++++
.../docs/clang-tidy/checks/cert/flp30-c.rst | 5 +++--
.../docs/clang-tidy/checks/list.rst | 3 ++-
.../test/clang-tidy/checkers/cert/flp30-c.c | 10 +++++-----
11 files changed, 48 insertions(+), 24 deletions(-)
rename clang-tools-extra/clang-tidy/{cert/FloatLoopCounter.cpp => bugprone/AvoidFloatLoopCounterCheck.cpp} (85%)
rename clang-tools-extra/clang-tidy/{cert/FloatLoopCounter.h => bugprone/AvoidFloatLoopCounterCheck.h} (62%)
create mode 100644 clang-tools-extra/docs/clang-tidy/checks/bugprone/avoid-float-loop-counter.rst
diff --git a/clang-tools-extra/clang-tidy/cert/FloatLoopCounter.cpp b/clang-tools-extra/clang-tidy/bugprone/AvoidFloatLoopCounterCheck.cpp
similarity index 85%
rename from clang-tools-extra/clang-tidy/cert/FloatLoopCounter.cpp
rename to clang-tools-extra/clang-tidy/bugprone/AvoidFloatLoopCounterCheck.cpp
index 01299e0e5ab48..5f82e0ca780d8 100644
--- a/clang-tools-extra/clang-tidy/cert/FloatLoopCounter.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AvoidFloatLoopCounterCheck.cpp
@@ -6,16 +6,16 @@
//
//===----------------------------------------------------------------------===//
-#include "FloatLoopCounter.h"
+#include "AvoidFloatLoopCounterCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
using namespace clang::ast_matchers;
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
-void FloatLoopCounter::registerMatchers(MatchFinder *Finder) {
+void AvoidFloatLoopCounterCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
forStmt(hasIncrement(forEachDescendant(
declRefExpr(hasType(realFloatingPointType()),
@@ -29,7 +29,7 @@ void FloatLoopCounter::registerMatchers(MatchFinder *Finder) {
this);
}
-void FloatLoopCounter::check(const MatchFinder::MatchResult &Result) {
+void AvoidFloatLoopCounterCheck::check(const MatchFinder::MatchResult &Result) {
const auto *FS = Result.Nodes.getNodeAs<ForStmt>("for");
diag(FS->getInc()->getBeginLoc(), "loop induction expression should not have "
@@ -43,4 +43,4 @@ void FloatLoopCounter::check(const MatchFinder::MatchResult &Result) {
DiagnosticIDs::Note);
}
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/cert/FloatLoopCounter.h b/clang-tools-extra/clang-tidy/bugprone/AvoidFloatLoopCounterCheck.h
similarity index 62%
rename from clang-tools-extra/clang-tidy/cert/FloatLoopCounter.h
rename to clang-tools-extra/clang-tidy/bugprone/AvoidFloatLoopCounterCheck.h
index d00c036f00f24..24afb8ba7d86d 100644
--- a/clang-tools-extra/clang-tidy/cert/FloatLoopCounter.h
+++ b/clang-tools-extra/clang-tidy/bugprone/AvoidFloatLoopCounterCheck.h
@@ -6,27 +6,27 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_FLOAT_LOOP_COUNTER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_FLOAT_LOOP_COUNTER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_AVOIDFLOATLOOPCOUNTERCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_AVOIDFLOATLOOPCOUNTERCHECK_H
#include "../ClangTidyCheck.h"
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
/// This check diagnoses when the loop induction expression of a for loop has
/// floating-point type. The check corresponds to:
/// https://www.securecoding.cert.org/confluence/display/c/FLP30-C.+Do+not+use+floating-point+variables+as+loop+counters
///
/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/cert/flp30-c.html
-class FloatLoopCounter : public ClangTidyCheck {
+/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/avoid-float-loop-counter.html
+class AvoidFloatLoopCounterCheck : public ClangTidyCheck {
public:
- FloatLoopCounter(StringRef Name, ClangTidyContext *Context)
+ AvoidFloatLoopCounterCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_FLOAT_LOOP_COUNTER_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_AVOIDFLOATLOOPCOUNTERCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 611717a64b768..666f44153086f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -12,6 +12,7 @@
#include "ArgumentCommentCheck.h"
#include "AssertSideEffectCheck.h"
#include "AssignmentInIfConditionCheck.h"
+#include "AvoidFloatLoopCounterCheck.h"
#include "BadSignalToKillThreadCheck.h"
#include "BitwisePointerCastCheck.h"
#include "BoolPointerImplicitConversionCheck.h"
@@ -121,6 +122,8 @@ class BugproneModule : public ClangTidyModule {
"bugprone-assert-side-effect");
CheckFactories.registerCheck<AssignmentInIfConditionCheck>(
"bugprone-assignment-in-if-condition");
+ CheckFactories.registerCheck<AvoidFloatLoopCounterCheck>(
+ "bugprone-avoid-float-loop-counter");
CheckFactories.registerCheck<BadSignalToKillThreadCheck>(
"bugprone-bad-signal-to-kill-thread");
CheckFactories.registerCheck<BitwisePointerCastCheck>(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 6c96996458040..99c3b624cbc5a 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -7,6 +7,7 @@ add_clang_library(clangTidyBugproneModule STATIC
ArgumentCommentCheck.cpp
AssertSideEffectCheck.cpp
AssignmentInIfConditionCheck.cpp
+ AvoidFloatLoopCounterCheck.cpp
BadSignalToKillThreadCheck.cpp
BitwisePointerCastCheck.cpp
BoolPointerImplicitConversionCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
index 15592d5c03c06..f7b99be81bb39 100644
--- a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
@@ -9,6 +9,7 @@
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
+#include "../bugprone/AvoidFloatLoopCounterCheck.h"
#include "../bugprone/BadSignalToKillThreadCheck.h"
#include "../bugprone/CommandProcessorCheck.h"
#include "../bugprone/DefaultOperatorNewOnOveralignedTypeCheck.h"
@@ -37,7 +38,6 @@
#include "../performance/MoveConstructorInitCheck.h"
#include "../readability/EnumInitialValueCheck.h"
#include "../readability/UppercaseLiteralSuffixCheck.h"
-#include "FloatLoopCounter.h"
#include "LimitedRandomnessCheck.h"
#include "MutatingCopyCheck.h"
#include "ProperlySeededRandomGeneratorCheck.h"
@@ -310,7 +310,8 @@ class CERTModule : public ClangTidyModule {
CheckFactories.registerCheck<bugprone::SuspiciousMemoryComparisonCheck>(
"cert-exp42-c");
// FLP
- CheckFactories.registerCheck<FloatLoopCounter>("cert-flp30-c");
+ CheckFactories.registerCheck<bugprone::AvoidFloatLoopCounterCheck>(
+ "cert-flp30-c");
CheckFactories.registerCheck<bugprone::SuspiciousMemoryComparisonCheck>(
"cert-flp37-c");
// FIO
diff --git a/clang-tools-extra/clang-tidy/cert/CMakeLists.txt b/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
index 27cf392ce0bb1..b25576a312724 100644
--- a/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
@@ -5,7 +5,6 @@ set(LLVM_LINK_COMPONENTS
add_clang_library(clangTidyCERTModule STATIC
CERTTidyModule.cpp
- FloatLoopCounter.cpp
LimitedRandomnessCheck.cpp
MutatingCopyCheck.cpp
ProperlySeededRandomGeneratorCheck.cpp
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 88eb0ebff4501..e787813664fd7 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -269,6 +269,11 @@ New check aliases
<clang-tidy/checks/bugprone/throwing-static-initialization>`
keeping initial check as an alias to the new one.
+- Renamed :doc:`cert-flp30-c <clang-tidy/checks/cert/flp30-c>` to
+ :doc:`bugprone-avoid-float-loop-counter
+ <clang-tidy/checks/bugprone/avoid-float-loop-counter>`
+ keeping initial check as an alias to the new one.
+
- Renamed :doc:`cert-mem57-cpp <clang-tidy/checks/cert/mem57-cpp>` to
:doc:`bugprone-default-operator-new-on-overaligned-type
<clang-tidy/checks/bugprone/default-operator-new-on-overaligned-type>`
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/avoid-float-loop-counter.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/avoid-float-loop-counter.rst
new file mode 100644
index 0000000000000..5b0a4134f7e36
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/avoid-float-loop-counter.rst
@@ -0,0 +1,13 @@
+.. title:: clang-tidy - bugprone-avoid-float-loop-counter
+
+bugprone-avoid-float-loop-counter
+=================================
+
+Flags ``for`` loops where the induction expression has a floating-point type.
+
+References
+----------
+
+This check corresponds to the CERT C Coding Standard rule
+`FLP30-C. Do not use floating-point variables as loop counters
+<https://www.securecoding.cert.org/confluence/display/c/FLP30-C.+Do+not+use+floating-point+variables+as+loop+counters>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/flp30-c.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/flp30-c.rst
index c37b63980be76..649d35c0e273f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/flp30-c.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/flp30-c.rst
@@ -3,8 +3,9 @@
cert-flp30-c
============
-This check flags ``for`` loops where the induction expression has a
-floating-point type.
+The `cert-flp30-c` is an aliaes, please see
+`bugprone-avoid-float-loop-counter <../bugprone/avoid-float-loop-counter.html>`_
+for more information
This check corresponds to the CERT C Coding Standard rule
`FLP30-C. Do not use floating-point variables as loop counters
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 5094bcc90caf3..155516824a752 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -80,6 +80,7 @@ Clang-Tidy Checks
:doc:`bugprone-argument-comment <bugprone/argument-comment>`, "Yes"
:doc:`bugprone-assert-side-effect <bugprone/assert-side-effect>`,
:doc:`bugprone-assignment-in-if-condition <bugprone/assignment-in-if-condition>`,
+ :doc:`bugprone-avoid-float-loop-counter <bugprone/avoid-float-loop-counter>`,
:doc:`bugprone-bad-signal-to-kill-thread <bugprone/bad-signal-to-kill-thread>`,
:doc:`bugprone-bitwise-pointer-cast <bugprone/bitwise-pointer-cast>`,
:doc:`bugprone-bool-pointer-implicit-conversion <bugprone/bool-pointer-implicit-conversion>`, "Yes"
@@ -178,7 +179,6 @@ Clang-Tidy Checks
:doc:`bugprone-virtual-near-miss <bugprone/virtual-near-miss>`, "Yes"
:doc:`cert-err33-c <cert/err33-c>`,
:doc:`cert-err60-cpp <cert/err60-cpp>`,
- :doc:`cert-flp30-c <cert/flp30-c>`,
:doc:`cert-msc50-cpp <cert/msc50-cpp>`,
:doc:`cert-msc51-cpp <cert/msc51-cpp>`,
:doc:`cert-oop58-cpp <cert/oop58-cpp>`,
@@ -451,6 +451,7 @@ Check aliases
:doc:`cert-err61-cpp <cert/err61-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
:doc:`cert-exp42-c <cert/exp42-c>`, :doc:`bugprone-suspicious-memory-comparison <bugprone/suspicious-memory-comparison>`,
:doc:`cert-fio38-c <cert/fio38-c>`, :doc:`misc-non-copyable-objects <misc/non-copyable-objects>`,
+ :doc:`cert-flp30-c <cert/flp30-c>`, :doc:`bugprone-avoid-float-loop-counter <bugprone/avoid-float-loop-counter>`,
:doc:`cert-flp37-c <cert/flp37-c>`, :doc:`bugprone-suspicious-memory-comparison <bugprone/suspicious-memory-comparison>`,
:doc:`cert-int09-c <cert/int09-c>`, :doc:`readability-enum-initial-value <readability/enum-initial-value>`, "Yes"
:doc:`cert-mem57-cpp <cert/mem57-cpp>`, :doc:`bugprone-default-operator-new-on-overaligned-type <bugprone/default-operator-new-on-overaligned-type>`,
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/flp30-c.c b/clang-tools-extra/test/clang-tidy/checkers/cert/flp30-c.c
index b9985887a81c5..9762a22af49ef 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cert/flp30-c.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/cert/flp30-c.c
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s cert-flp30-c %t
+// RUN: %check_clang_tidy %s bugprone-avoid-float-loop-counter %t
float g(void);
int c(float);
@@ -7,16 +7,16 @@ float f = 1.0f;
void match(void) {
for (float x = 0.1f; x <= 1.0f; x += 0.1f) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: loop induction expression should not have floating-point type [cert-flp30-c]
+ // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: loop induction expression should not have floating-point type [bugprone-avoid-float-loop-counter]
for (; f > 0; --f) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: loop induction expression should not have floating-point type [cert-flp30-c]
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: loop induction expression should not have floating-point type [bugprone-avoid-float-loop-counter]
for (float x = 0.0f; c(x); x = g()) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: loop induction expression should not have floating-point type [cert-flp30-c]
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: loop induction expression should not have floating-point type [bugprone-avoid-float-loop-counter]
for (int i=0; i < 10 && f < 2.0f; f++, i++) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: loop induction expression should not have floating-point type [cert-flp30-c]
+ // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: loop induction expression should not have floating-point type [bugprone-avoid-float-loop-counter]
// CHECK-MESSAGES: :5:1: note: floating-point type loop induction variable
}
More information about the cfe-commits
mailing list