Skip to content

Commit 22242ae

Browse files
zeyi2localspook
andauthored
[clang-tidy] Rename cert-flp30-c to bugprone-float-loop-counter (llvm#166571)
Closes [llvm#157291](llvm#157291) --------- Co-authored-by: Victor Chernyakin <[email protected]>
1 parent 8b3a124 commit 22242ae

File tree

11 files changed

+48
-24
lines changed

11 files changed

+48
-24
lines changed

clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "EasilySwappableParametersCheck.h"
3131
#include "EmptyCatchCheck.h"
3232
#include "ExceptionEscapeCheck.h"
33+
#include "FloatLoopCounterCheck.h"
3334
#include "FoldInitTypeCheck.h"
3435
#include "ForwardDeclarationNamespaceCheck.h"
3536
#include "ForwardingReferenceOverloadCheck.h"
@@ -153,6 +154,8 @@ class BugproneModule : public ClangTidyModule {
153154
CheckFactories.registerCheck<EmptyCatchCheck>("bugprone-empty-catch");
154155
CheckFactories.registerCheck<ExceptionEscapeCheck>(
155156
"bugprone-exception-escape");
157+
CheckFactories.registerCheck<FloatLoopCounterCheck>(
158+
"bugprone-float-loop-counter");
156159
CheckFactories.registerCheck<FoldInitTypeCheck>("bugprone-fold-init-type");
157160
CheckFactories.registerCheck<ForwardDeclarationNamespaceCheck>(
158161
"bugprone-forward-declaration-namespace");

clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ add_clang_library(clangTidyBugproneModule STATIC
2626
EasilySwappableParametersCheck.cpp
2727
EmptyCatchCheck.cpp
2828
ExceptionEscapeCheck.cpp
29+
FloatLoopCounterCheck.cpp
2930
FoldInitTypeCheck.cpp
3031
ForwardDeclarationNamespaceCheck.cpp
3132
ForwardingReferenceOverloadCheck.cpp

clang-tools-extra/clang-tidy/cert/FloatLoopCounter.cpp renamed to clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "FloatLoopCounter.h"
9+
#include "FloatLoopCounterCheck.h"
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
1212
#include "clang/ASTMatchers/ASTMatchers.h"
1313

1414
using namespace clang::ast_matchers;
1515

16-
namespace clang::tidy::cert {
16+
namespace clang::tidy::bugprone {
1717

18-
void FloatLoopCounter::registerMatchers(MatchFinder *Finder) {
18+
void FloatLoopCounterCheck::registerMatchers(MatchFinder *Finder) {
1919
Finder->addMatcher(
2020
forStmt(hasIncrement(forEachDescendant(
2121
declRefExpr(hasType(realFloatingPointType()),
@@ -29,7 +29,7 @@ void FloatLoopCounter::registerMatchers(MatchFinder *Finder) {
2929
this);
3030
}
3131

32-
void FloatLoopCounter::check(const MatchFinder::MatchResult &Result) {
32+
void FloatLoopCounterCheck::check(const MatchFinder::MatchResult &Result) {
3333
const auto *FS = Result.Nodes.getNodeAs<ForStmt>("for");
3434

3535
diag(FS->getInc()->getBeginLoc(), "loop induction expression should not have "
@@ -43,4 +43,4 @@ void FloatLoopCounter::check(const MatchFinder::MatchResult &Result) {
4343
DiagnosticIDs::Note);
4444
}
4545

46-
} // namespace clang::tidy::cert
46+
} // namespace clang::tidy::bugprone

clang-tools-extra/clang-tidy/cert/FloatLoopCounter.h renamed to clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_FLOAT_LOOP_COUNTER_H
10-
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_FLOAT_LOOP_COUNTER_H
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FLOATLOOPCOUNTERCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FLOATLOOPCOUNTERCHECK_H
1111

1212
#include "../ClangTidyCheck.h"
1313

14-
namespace clang::tidy::cert {
14+
namespace clang::tidy::bugprone {
1515

1616
/// This check diagnoses when the loop induction expression of a for loop has
1717
/// floating-point type. The check corresponds to:
1818
/// https://www.securecoding.cert.org/confluence/display/c/FLP30-C.+Do+not+use+floating-point+variables+as+loop+counters
1919
///
2020
/// For the user-facing documentation see:
21-
/// https://clang.llvm.org/extra/clang-tidy/checks/cert/flp30-c.html
22-
class FloatLoopCounter : public ClangTidyCheck {
21+
/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/float-loop-counter.html
22+
class FloatLoopCounterCheck : public ClangTidyCheck {
2323
public:
24-
FloatLoopCounter(StringRef Name, ClangTidyContext *Context)
24+
FloatLoopCounterCheck(StringRef Name, ClangTidyContext *Context)
2525
: ClangTidyCheck(Name, Context) {}
2626
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2727
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
2828
};
2929

30-
} // namespace clang::tidy::cert
30+
} // namespace clang::tidy::bugprone
3131

32-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_FLOAT_LOOP_COUNTER_H
32+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FLOATLOOPCOUNTERCHECK_H

clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "../bugprone/BadSignalToKillThreadCheck.h"
1313
#include "../bugprone/CommandProcessorCheck.h"
1414
#include "../bugprone/DefaultOperatorNewOnOveralignedTypeCheck.h"
15+
#include "../bugprone/FloatLoopCounterCheck.h"
1516
#include "../bugprone/PointerArithmeticOnPolymorphicObjectCheck.h"
1617
#include "../bugprone/RawMemoryCallOnNonTrivialTypeCheck.h"
1718
#include "../bugprone/ReservedIdentifierCheck.h"
@@ -37,7 +38,6 @@
3738
#include "../performance/MoveConstructorInitCheck.h"
3839
#include "../readability/EnumInitialValueCheck.h"
3940
#include "../readability/UppercaseLiteralSuffixCheck.h"
40-
#include "FloatLoopCounter.h"
4141
#include "LimitedRandomnessCheck.h"
4242
#include "MutatingCopyCheck.h"
4343
#include "ProperlySeededRandomGeneratorCheck.h"
@@ -310,7 +310,8 @@ class CERTModule : public ClangTidyModule {
310310
CheckFactories.registerCheck<bugprone::SuspiciousMemoryComparisonCheck>(
311311
"cert-exp42-c");
312312
// FLP
313-
CheckFactories.registerCheck<FloatLoopCounter>("cert-flp30-c");
313+
CheckFactories.registerCheck<bugprone::FloatLoopCounterCheck>(
314+
"cert-flp30-c");
314315
CheckFactories.registerCheck<bugprone::SuspiciousMemoryComparisonCheck>(
315316
"cert-flp37-c");
316317
// FIO

clang-tools-extra/clang-tidy/cert/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ set(LLVM_LINK_COMPONENTS
55

66
add_clang_library(clangTidyCERTModule STATIC
77
CERTTidyModule.cpp
8-
FloatLoopCounter.cpp
98
LimitedRandomnessCheck.cpp
109
MutatingCopyCheck.cpp
1110
ProperlySeededRandomGeneratorCheck.cpp

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ New check aliases
269269
<clang-tidy/checks/bugprone/throwing-static-initialization>`
270270
keeping initial check as an alias to the new one.
271271

272+
- Renamed :doc:`cert-flp30-c <clang-tidy/checks/cert/flp30-c>` to
273+
:doc:`bugprone-float-loop-counter
274+
<clang-tidy/checks/bugprone/float-loop-counter>`
275+
keeping initial check as an alias to the new one.
276+
272277
- Renamed :doc:`cert-mem57-cpp <clang-tidy/checks/cert/mem57-cpp>` to
273278
:doc:`bugprone-default-operator-new-on-overaligned-type
274279
<clang-tidy/checks/bugprone/default-operator-new-on-overaligned-type>`
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.. title:: clang-tidy - bugprone-float-loop-counter
2+
3+
bugprone-float-loop-counter
4+
===========================
5+
6+
Flags ``for`` loops where the induction expression has a floating-point type.
7+
8+
References
9+
----------
10+
11+
This check corresponds to the CERT C Coding Standard rule
12+
`FLP30-C. Do not use floating-point variables as loop counters
13+
<https://www.securecoding.cert.org/confluence/display/c/FLP30-C.+Do+not+use+floating-point+variables+as+loop+counters>`_.

clang-tools-extra/docs/clang-tidy/checks/cert/flp30-c.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
cert-flp30-c
44
============
55

6-
This check flags ``for`` loops where the induction expression has a
7-
floating-point type.
6+
The `cert-flp30-c` check is an alias, please see
7+
`bugprone-float-loop-counter <../bugprone/float-loop-counter.html>`_
8+
for more information
89

910
This check corresponds to the CERT C Coding Standard rule
1011
`FLP30-C. Do not use floating-point variables as loop counters

clang-tools-extra/docs/clang-tidy/checks/list.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Clang-Tidy Checks
9898
:doc:`bugprone-easily-swappable-parameters <bugprone/easily-swappable-parameters>`,
9999
:doc:`bugprone-empty-catch <bugprone/empty-catch>`,
100100
:doc:`bugprone-exception-escape <bugprone/exception-escape>`,
101+
:doc:`bugprone-float-loop-counter <bugprone/float-loop-counter>`,
101102
:doc:`bugprone-fold-init-type <bugprone/fold-init-type>`,
102103
:doc:`bugprone-forward-declaration-namespace <bugprone/forward-declaration-namespace>`,
103104
:doc:`bugprone-forwarding-reference-overload <bugprone/forwarding-reference-overload>`,
@@ -178,7 +179,6 @@ Clang-Tidy Checks
178179
:doc:`bugprone-virtual-near-miss <bugprone/virtual-near-miss>`, "Yes"
179180
:doc:`cert-err33-c <cert/err33-c>`,
180181
:doc:`cert-err60-cpp <cert/err60-cpp>`,
181-
:doc:`cert-flp30-c <cert/flp30-c>`,
182182
:doc:`cert-msc50-cpp <cert/msc50-cpp>`,
183183
:doc:`cert-msc51-cpp <cert/msc51-cpp>`,
184184
:doc:`cert-oop58-cpp <cert/oop58-cpp>`,
@@ -451,6 +451,7 @@ Check aliases
451451
:doc:`cert-err61-cpp <cert/err61-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
452452
:doc:`cert-exp42-c <cert/exp42-c>`, :doc:`bugprone-suspicious-memory-comparison <bugprone/suspicious-memory-comparison>`,
453453
:doc:`cert-fio38-c <cert/fio38-c>`, :doc:`misc-non-copyable-objects <misc/non-copyable-objects>`,
454+
:doc:`cert-flp30-c <cert/flp30-c>`, :doc:`bugprone-float-loop-counter <bugprone/float-loop-counter>`,
454455
:doc:`cert-flp37-c <cert/flp37-c>`, :doc:`bugprone-suspicious-memory-comparison <bugprone/suspicious-memory-comparison>`,
455456
:doc:`cert-int09-c <cert/int09-c>`, :doc:`readability-enum-initial-value <readability/enum-initial-value>`, "Yes"
456457
:doc:`cert-mem57-cpp <cert/mem57-cpp>`, :doc:`bugprone-default-operator-new-on-overaligned-type <bugprone/default-operator-new-on-overaligned-type>`,

0 commit comments

Comments
 (0)