[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 22:57:30 PST 2025
https://github.com/zeyi2 updated https://github.com/llvm/llvm-project/pull/166571
>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 1/4] [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
}
>From f72f6c4c83dd9ded6fd251e3fb02ff88d2a221cc Mon Sep 17 00:00:00 2001
From: mtx <mitchell.xu2 at gmail.com>
Date: Thu, 6 Nov 2025 12:40:20 +0800
Subject: [PATCH 2/4] Rename
---
.../clang-tidy/bugprone/BugproneTidyModule.cpp | 6 +++---
clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt | 2 +-
...oopCounterCheck.cpp => FloatLoopCounterCheck.cpp} | 6 +++---
...oatLoopCounterCheck.h => FloatLoopCounterCheck.h} | 12 ++++++------
clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp | 4 ++--
clang-tools-extra/docs/ReleaseNotes.rst | 4 ++--
...float-loop-counter.rst => float-loop-counter.rst} | 6 +++---
.../docs/clang-tidy/checks/cert/flp30-c.rst | 4 ++--
clang-tools-extra/docs/clang-tidy/checks/list.rst | 4 ++--
.../flp30-c.c => bugprone/float-loop-counter.c} | 10 +++++-----
10 files changed, 29 insertions(+), 29 deletions(-)
rename clang-tools-extra/clang-tidy/bugprone/{AvoidFloatLoopCounterCheck.cpp => FloatLoopCounterCheck.cpp} (89%)
rename clang-tools-extra/clang-tidy/bugprone/{AvoidFloatLoopCounterCheck.h => FloatLoopCounterCheck.h} (67%)
rename clang-tools-extra/docs/clang-tidy/checks/bugprone/{avoid-float-loop-counter.rst => float-loop-counter.rst} (73%)
rename clang-tools-extra/test/clang-tidy/checkers/{cert/flp30-c.c => bugprone/float-loop-counter.c} (65%)
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 666f44153086f..e1856ff24cd86 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -12,7 +12,6 @@
#include "ArgumentCommentCheck.h"
#include "AssertSideEffectCheck.h"
#include "AssignmentInIfConditionCheck.h"
-#include "AvoidFloatLoopCounterCheck.h"
#include "BadSignalToKillThreadCheck.h"
#include "BitwisePointerCastCheck.h"
#include "BoolPointerImplicitConversionCheck.h"
@@ -31,6 +30,7 @@
#include "EasilySwappableParametersCheck.h"
#include "EmptyCatchCheck.h"
#include "ExceptionEscapeCheck.h"
+#include "FloatLoopCounterCheck.h"
#include "FoldInitTypeCheck.h"
#include "ForwardDeclarationNamespaceCheck.h"
#include "ForwardingReferenceOverloadCheck.h"
@@ -122,8 +122,6 @@ 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>(
@@ -156,6 +154,8 @@ class BugproneModule : public ClangTidyModule {
CheckFactories.registerCheck<EmptyCatchCheck>("bugprone-empty-catch");
CheckFactories.registerCheck<ExceptionEscapeCheck>(
"bugprone-exception-escape");
+ CheckFactories.registerCheck<FloatLoopCounterCheck>(
+ "bugprone-float-loop-counter");
CheckFactories.registerCheck<FoldInitTypeCheck>("bugprone-fold-init-type");
CheckFactories.registerCheck<ForwardDeclarationNamespaceCheck>(
"bugprone-forward-declaration-namespace");
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 99c3b624cbc5a..7d2e10887dfe5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -7,7 +7,6 @@ add_clang_library(clangTidyBugproneModule STATIC
ArgumentCommentCheck.cpp
AssertSideEffectCheck.cpp
AssignmentInIfConditionCheck.cpp
- AvoidFloatLoopCounterCheck.cpp
BadSignalToKillThreadCheck.cpp
BitwisePointerCastCheck.cpp
BoolPointerImplicitConversionCheck.cpp
@@ -27,6 +26,7 @@ add_clang_library(clangTidyBugproneModule STATIC
EasilySwappableParametersCheck.cpp
EmptyCatchCheck.cpp
ExceptionEscapeCheck.cpp
+ FloatLoopCounterCheck.cpp
FoldInitTypeCheck.cpp
ForwardDeclarationNamespaceCheck.cpp
ForwardingReferenceOverloadCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/bugprone/AvoidFloatLoopCounterCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.cpp
similarity index 89%
rename from clang-tools-extra/clang-tidy/bugprone/AvoidFloatLoopCounterCheck.cpp
rename to clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.cpp
index 5f82e0ca780d8..adf2d2b4bcc07 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AvoidFloatLoopCounterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "AvoidFloatLoopCounterCheck.h"
+#include "FloatLoopCounterCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
@@ -15,7 +15,7 @@ using namespace clang::ast_matchers;
namespace clang::tidy::bugprone {
-void AvoidFloatLoopCounterCheck::registerMatchers(MatchFinder *Finder) {
+void FloatLoopCounterCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
forStmt(hasIncrement(forEachDescendant(
declRefExpr(hasType(realFloatingPointType()),
@@ -29,7 +29,7 @@ void AvoidFloatLoopCounterCheck::registerMatchers(MatchFinder *Finder) {
this);
}
-void AvoidFloatLoopCounterCheck::check(const MatchFinder::MatchResult &Result) {
+void FloatLoopCounterCheck::check(const MatchFinder::MatchResult &Result) {
const auto *FS = Result.Nodes.getNodeAs<ForStmt>("for");
diag(FS->getInc()->getBeginLoc(), "loop induction expression should not have "
diff --git a/clang-tools-extra/clang-tidy/bugprone/AvoidFloatLoopCounterCheck.h b/clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.h
similarity index 67%
rename from clang-tools-extra/clang-tidy/bugprone/AvoidFloatLoopCounterCheck.h
rename to clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.h
index 24afb8ba7d86d..43dd9c2c93515 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AvoidFloatLoopCounterCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_AVOIDFLOATLOOPCOUNTERCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_AVOIDFLOATLOOPCOUNTERCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FLOATLOOPCOUNTERCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FLOATLOOPCOUNTERCHECK_H
#include "../ClangTidyCheck.h"
@@ -18,10 +18,10 @@ namespace clang::tidy::bugprone {
/// 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/bugprone/avoid-float-loop-counter.html
-class AvoidFloatLoopCounterCheck : public ClangTidyCheck {
+/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/float-loop-counter.html
+class FloatLoopCounterCheck : public ClangTidyCheck {
public:
- AvoidFloatLoopCounterCheck(StringRef Name, ClangTidyContext *Context)
+ FloatLoopCounterCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
@@ -29,4 +29,4 @@ class AvoidFloatLoopCounterCheck : public ClangTidyCheck {
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_AVOIDFLOATLOOPCOUNTERCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FLOATLOOPCOUNTERCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
index f7b99be81bb39..a1f62707b107e 100644
--- a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
@@ -9,10 +9,10 @@
#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"
+#include "../bugprone/FloatLoopCounterCheck.h"
#include "../bugprone/PointerArithmeticOnPolymorphicObjectCheck.h"
#include "../bugprone/RawMemoryCallOnNonTrivialTypeCheck.h"
#include "../bugprone/ReservedIdentifierCheck.h"
@@ -310,7 +310,7 @@ class CERTModule : public ClangTidyModule {
CheckFactories.registerCheck<bugprone::SuspiciousMemoryComparisonCheck>(
"cert-exp42-c");
// FLP
- CheckFactories.registerCheck<bugprone::AvoidFloatLoopCounterCheck>(
+ CheckFactories.registerCheck<bugprone::FloatLoopCounterCheck>(
"cert-flp30-c");
CheckFactories.registerCheck<bugprone::SuspiciousMemoryComparisonCheck>(
"cert-flp37-c");
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index e787813664fd7..8ba1d1a78bf91 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -270,8 +270,8 @@ New check aliases
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>`
+ :doc:`bugprone-float-loop-counter
+ <clang-tidy/checks/bugprone/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
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/float-loop-counter.rst
similarity index 73%
rename from clang-tools-extra/docs/clang-tidy/checks/bugprone/avoid-float-loop-counter.rst
rename to clang-tools-extra/docs/clang-tidy/checks/bugprone/float-loop-counter.rst
index 5b0a4134f7e36..e663b40ab5a5d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/avoid-float-loop-counter.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/float-loop-counter.rst
@@ -1,7 +1,7 @@
-.. title:: clang-tidy - bugprone-avoid-float-loop-counter
+.. title:: clang-tidy - bugprone-float-loop-counter
-bugprone-avoid-float-loop-counter
-=================================
+bugprone-float-loop-counter
+===========================
Flags ``for`` loops where the induction expression has a floating-point type.
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 649d35c0e273f..00b604a7de8a8 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,8 @@
cert-flp30-c
============
-The `cert-flp30-c` is an aliaes, please see
-`bugprone-avoid-float-loop-counter <../bugprone/avoid-float-loop-counter.html>`_
+The `cert-flp30-c` check is an aliaes, please see
+`bugprone-float-loop-counter <../bugprone/float-loop-counter.html>`_
for more information
This check corresponds to the CERT C Coding Standard rule
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 155516824a752..52aa0d03f8548 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -80,7 +80,6 @@ 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"
@@ -99,6 +98,7 @@ Clang-Tidy Checks
:doc:`bugprone-easily-swappable-parameters <bugprone/easily-swappable-parameters>`,
:doc:`bugprone-empty-catch <bugprone/empty-catch>`,
:doc:`bugprone-exception-escape <bugprone/exception-escape>`,
+ :doc:`bugprone-float-loop-counter <bugprone/avoid-float-loop-counter>`,
:doc:`bugprone-fold-init-type <bugprone/fold-init-type>`,
:doc:`bugprone-forward-declaration-namespace <bugprone/forward-declaration-namespace>`,
:doc:`bugprone-forwarding-reference-overload <bugprone/forwarding-reference-overload>`,
@@ -451,7 +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-flp30-c <cert/flp30-c>`, :doc:`bugprone-float-loop-counter <bugprone/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/bugprone/float-loop-counter.c
similarity index 65%
rename from clang-tools-extra/test/clang-tidy/checkers/cert/flp30-c.c
rename to clang-tools-extra/test/clang-tidy/checkers/bugprone/float-loop-counter.c
index 9762a22af49ef..77812f01eace5 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cert/flp30-c.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/float-loop-counter.c
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s bugprone-avoid-float-loop-counter %t
+// RUN: %check_clang_tidy %s bugprone-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 [bugprone-avoid-float-loop-counter]
+ // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: loop induction expression should not have floating-point type [bugprone-float-loop-counter]
for (; f > 0; --f) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: loop induction expression should not have floating-point type [bugprone-avoid-float-loop-counter]
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: loop induction expression should not have floating-point type [bugprone-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 [bugprone-avoid-float-loop-counter]
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: loop induction expression should not have floating-point type [bugprone-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 [bugprone-avoid-float-loop-counter]
+ // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: loop induction expression should not have floating-point type [bugprone-float-loop-counter]
// CHECK-MESSAGES: :5:1: note: floating-point type loop induction variable
}
>From 9c972ae61677515b98cce91ff82efd4adba9801d Mon Sep 17 00:00:00 2001
From: mtx <mitchell.xu2 at gmail.com>
Date: Thu, 6 Nov 2025 12:47:30 +0800
Subject: [PATCH 3/4] [~]
---
clang-tools-extra/docs/clang-tidy/checks/list.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 52aa0d03f8548..be509abab00a5 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -98,7 +98,7 @@ Clang-Tidy Checks
:doc:`bugprone-easily-swappable-parameters <bugprone/easily-swappable-parameters>`,
:doc:`bugprone-empty-catch <bugprone/empty-catch>`,
:doc:`bugprone-exception-escape <bugprone/exception-escape>`,
- :doc:`bugprone-float-loop-counter <bugprone/avoid-float-loop-counter>`,
+ :doc:`bugprone-float-loop-counter <bugprone/float-loop-counter>`,
:doc:`bugprone-fold-init-type <bugprone/fold-init-type>`,
:doc:`bugprone-forward-declaration-namespace <bugprone/forward-declaration-namespace>`,
:doc:`bugprone-forwarding-reference-overload <bugprone/forwarding-reference-overload>`,
>From dec5ae1939f5f08f039cabee895a904820d551c7 Mon Sep 17 00:00:00 2001
From: mitchell <mitchell.xu2 at gmail.com>
Date: Thu, 6 Nov 2025 14:57:21 +0800
Subject: [PATCH 4/4] Update docs
Co-authored-by: Victor Chernyakin <chernyakin.victor.j at outlook.com>
---
clang-tools-extra/docs/clang-tidy/checks/cert/flp30-c.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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 00b604a7de8a8..5f6eff447cc2f 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,7 +3,7 @@
cert-flp30-c
============
-The `cert-flp30-c` check is an aliaes, please see
+The `cert-flp30-c` check is an alias, please see
`bugprone-float-loop-counter <../bugprone/float-loop-counter.html>`_
for more information
More information about the cfe-commits
mailing list