Skip to content

Commit 414975e

Browse files
committed
[clang-tidy] Rename 'cert-err52-cpp' to 'bugprone-avoid-setjmp-longjmp'
1 parent 84a796d commit 414975e

File tree

11 files changed

+50
-31
lines changed

11 files changed

+50
-31
lines changed

clang-tools-extra/clang-tidy/cert/SetLongJmpCheck.cpp renamed to clang-tools-extra/clang-tidy/bugprone/AvoidSetjmpLongjmpCheck.cpp

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

9-
#include "SetLongJmpCheck.h"
9+
#include "AvoidSetjmpLongjmpCheck.h"
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
1212
#include "clang/Frontend/CompilerInstance.h"
@@ -15,17 +15,18 @@
1515

1616
using namespace clang::ast_matchers;
1717

18-
namespace clang::tidy::cert {
18+
namespace clang::tidy::bugprone {
1919

2020
namespace {
2121
const char DiagWording[] =
2222
"do not call %0; consider using exception handling instead";
2323

2424
class SetJmpMacroCallbacks : public PPCallbacks {
25-
SetLongJmpCheck &Check;
25+
AvoidSetjmpLongjmpCheck &Check;
2626

2727
public:
28-
explicit SetJmpMacroCallbacks(SetLongJmpCheck &Check) : Check(Check) {}
28+
explicit SetJmpMacroCallbacks(AvoidSetjmpLongjmpCheck &Check)
29+
: Check(Check) {}
2930

3031
void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
3132
SourceRange Range, const MacroArgs *Args) override {
@@ -39,15 +40,14 @@ class SetJmpMacroCallbacks : public PPCallbacks {
3940
};
4041
} // namespace
4142

42-
void SetLongJmpCheck::registerPPCallbacks(const SourceManager &SM,
43-
Preprocessor *PP,
44-
Preprocessor *ModuleExpanderPP) {
43+
void AvoidSetjmpLongjmpCheck::registerPPCallbacks(
44+
const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
4545
// Per [headers]p5, setjmp must be exposed as a macro instead of a function,
4646
// despite the allowance in C for setjmp to also be an extern function.
4747
PP->addPPCallbacks(std::make_unique<SetJmpMacroCallbacks>(*this));
4848
}
4949

50-
void SetLongJmpCheck::registerMatchers(MatchFinder *Finder) {
50+
void AvoidSetjmpLongjmpCheck::registerMatchers(MatchFinder *Finder) {
5151
// In case there is an implementation that happens to define setjmp as a
5252
// function instead of a macro, this will also catch use of it. However, we
5353
// are primarily searching for uses of longjmp.
@@ -57,9 +57,9 @@ void SetLongJmpCheck::registerMatchers(MatchFinder *Finder) {
5757
this);
5858
}
5959

60-
void SetLongJmpCheck::check(const MatchFinder::MatchResult &Result) {
60+
void AvoidSetjmpLongjmpCheck::check(const MatchFinder::MatchResult &Result) {
6161
const auto *E = Result.Nodes.getNodeAs<CallExpr>("expr");
6262
diag(E->getExprLoc(), DiagWording) << cast<NamedDecl>(E->getCalleeDecl());
6363
}
6464

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

clang-tools-extra/clang-tidy/cert/SetLongJmpCheck.h renamed to clang-tools-extra/clang-tidy/bugprone/AvoidSetjmpLongjmpCheck.h

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

9-
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SETLONGJMPCHECK_H
10-
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SETLONGJMPCHECK_H
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_AVOIDSETJMPLONGJMPCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_AVOIDSETJMPLONGJMPCHECK_H
1111

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

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

1616
/// Guards against use of setjmp/longjmp in C++ code
1717
///
1818
/// For the user-facing documentation see:
19-
/// http://clang.llvm.org/extra/clang-tidy/checks/cert/err52-cpp.html
20-
class SetLongJmpCheck : public ClangTidyCheck {
19+
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/avoid-setjmp-longjmp.html
20+
class AvoidSetjmpLongjmpCheck : public ClangTidyCheck {
2121
public:
22-
SetLongJmpCheck(StringRef Name, ClangTidyContext *Context)
22+
AvoidSetjmpLongjmpCheck(StringRef Name, ClangTidyContext *Context)
2323
: ClangTidyCheck(Name, Context) {}
2424
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
2525
return LangOpts.CPlusPlus;
@@ -30,6 +30,6 @@ class SetLongJmpCheck : public ClangTidyCheck {
3030
Preprocessor *ModuleExpanderPP) override;
3131
};
3232

33-
} // namespace clang::tidy::cert
33+
} // namespace clang::tidy::bugprone
3434

35-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SETLONGJMPCHECK_H
35+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_AVOIDSETJMPLONGJMPCHECK_H

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "ArgumentCommentCheck.h"
1313
#include "AssertSideEffectCheck.h"
1414
#include "AssignmentInIfConditionCheck.h"
15+
#include "AvoidSetjmpLongjmpCheck.h"
1516
#include "BadSignalToKillThreadCheck.h"
1617
#include "BitwisePointerCastCheck.h"
1718
#include "BoolPointerImplicitConversionCheck.h"
@@ -117,6 +118,8 @@ class BugproneModule : public ClangTidyModule {
117118
"bugprone-assert-side-effect");
118119
CheckFactories.registerCheck<AssignmentInIfConditionCheck>(
119120
"bugprone-assignment-in-if-condition");
121+
CheckFactories.registerCheck<AvoidSetjmpLongjmpCheck>(
122+
"bugprone-avoid-setjmp-longjmp");
120123
CheckFactories.registerCheck<BadSignalToKillThreadCheck>(
121124
"bugprone-bad-signal-to-kill-thread");
122125
CheckFactories.registerCheck<BitwisePointerCastCheck>(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_clang_library(clangTidyBugproneModule STATIC
77
ArgumentCommentCheck.cpp
88
AssertSideEffectCheck.cpp
99
AssignmentInIfConditionCheck.cpp
10+
AvoidSetjmpLongjmpCheck.cpp
1011
BadSignalToKillThreadCheck.cpp
1112
BitwisePointerCastCheck.cpp
1213
BoolPointerImplicitConversionCheck.cpp

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "../ClangTidy.h"
1010
#include "../ClangTidyModule.h"
1111
#include "../ClangTidyModuleRegistry.h"
12+
#include "../bugprone/AvoidSetjmpLongjmpCheck.h"
1213
#include "../bugprone/BadSignalToKillThreadCheck.h"
1314
#include "../bugprone/PointerArithmeticOnPolymorphicObjectCheck.h"
1415
#include "../bugprone/ReservedIdentifierCheck.h"
@@ -40,14 +41,13 @@
4041
#include "MutatingCopyCheck.h"
4142
#include "NonTrivialTypesLibcMemoryCallsCheck.h"
4243
#include "ProperlySeededRandomGeneratorCheck.h"
43-
#include "SetLongJmpCheck.h"
4444
#include "ThrownExceptionTypeCheck.h"
4545

4646
namespace {
4747

4848
// Checked functions for cert-err33-c.
49-
// The following functions are deliberately excluded because they can be called
50-
// with NULL argument and in this case the check is not applicable:
49+
// The following functions are deliberately excluded because they can be
50+
// called with NULL argument and in this case the check is not applicable:
5151
// `mblen, mbrlen, mbrtowc, mbtowc, wctomb, wctomb_s`.
5252
// FIXME: The check can be improved to handle such cases.
5353
const llvm::StringRef CertErr33CCheckedFunctions = "^::aligned_alloc$;"
@@ -257,9 +257,11 @@ class CERTModule : public ClangTidyModule {
257257
// ERR
258258
CheckFactories.registerCheck<misc::ThrowByValueCatchByReferenceCheck>(
259259
"cert-err09-cpp");
260-
CheckFactories.registerCheck<SetLongJmpCheck>("cert-err52-cpp");
260+
CheckFactories.registerCheck<bugprone::AvoidSetjmpLongjmpCheck>(
261+
"cert-err52-cpp");
261262
CheckFactories.registerCheck<bugprone::ThrowingStaticInitializationCheck>(
262263
"cert-err58-cpp");
264+
CheckFactories.registerCheck<StaticObjectExceptionCheck>("cert-err58-cpp");
263265
CheckFactories.registerCheck<ThrownExceptionTypeCheck>("cert-err60-cpp");
264266
CheckFactories.registerCheck<misc::ThrowByValueCatchByReferenceCheck>(
265267
"cert-err61-cpp");

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ add_clang_library(clangTidyCERTModule STATIC
1313
MutatingCopyCheck.cpp
1414
NonTrivialTypesLibcMemoryCallsCheck.cpp
1515
ProperlySeededRandomGeneratorCheck.cpp
16-
SetLongJmpCheck.cpp
1716
ThrownExceptionTypeCheck.cpp
1817

1918
LINK_LIBS

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ New check aliases
216216
<clang-tidy/checks/bugprone/unchecked-string-to-number-conversion>`
217217
keeping initial check as an alias to the new one.
218218

219+
- Renamed :doc:`cert-err52-cpp <clang-tidy/checks/cert/err52-cpp>` to
220+
:doc:`bugprone-avoid-setjmp-longjmp
221+
<clang-tidy/checks/bugprone/avoid-setjmp-longjmp>`
222+
keeping initial check as an alias to the new one.
223+
219224
- Renamed :doc:`cert-err58-cpp <clang-tidy/checks/cert/err58-cpp>` to
220225
:doc:`bugprone-throwing-static-initialization
221226
<clang-tidy/checks/bugprone/throwing-static-initialization>`
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. title:: clang-tidy - bugprone-avoid-setjmp-longjmp
2+
3+
bugprone-avoid-setjmp-longjmp
4+
=============================
5+
6+
Flags all call expressions involving ``setjmp()`` and ``longjmp()``.
7+
8+
This check corresponds to the CERT C++ Coding Standard rule
9+
`ERR52-CPP. Do not use setjmp() or longjmp()
10+
<https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=88046492>`_.

clang-tools-extra/docs/clang-tidy/checks/cert/err52-cpp.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
cert-err52-cpp
44
==============
55

6-
This check flags all call expressions involving ``setjmp()`` and ``longjmp()``.
7-
8-
This check corresponds to the CERT C++ Coding Standard rule
9-
`ERR52-CPP. Do not use setjmp() or longjmp()
10-
<https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=1834>`_.
6+
The cert-err52-cpp check is an alias, please see
7+
`bugprone-avoid-setjmp-longjmp <../bugprone/avoid-setjmp-longjmp.html>`_
8+
for more information.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Clang-Tidy Checks
8080
:doc:`bugprone-argument-comment <bugprone/argument-comment>`, "Yes"
8181
:doc:`bugprone-assert-side-effect <bugprone/assert-side-effect>`,
8282
:doc:`bugprone-assignment-in-if-condition <bugprone/assignment-in-if-condition>`,
83+
:doc:`bugprone-avoid-setjmp-longjmp <bugprone/avoid-setjmp-longjmp>`,
8384
:doc:`bugprone-bad-signal-to-kill-thread <bugprone/bad-signal-to-kill-thread>`,
8485
:doc:`bugprone-bitwise-pointer-cast <bugprone/bitwise-pointer-cast>`,
8586
:doc:`bugprone-bool-pointer-implicit-conversion <bugprone/bool-pointer-implicit-conversion>`, "Yes"
@@ -175,7 +176,6 @@ Clang-Tidy Checks
175176
:doc:`cert-dcl58-cpp <cert/dcl58-cpp>`,
176177
:doc:`cert-env33-c <cert/env33-c>`,
177178
:doc:`cert-err33-c <cert/err33-c>`,
178-
:doc:`cert-err52-cpp <cert/err52-cpp>`,
179179
:doc:`cert-err60-cpp <cert/err60-cpp>`,
180180
:doc:`cert-flp30-c <cert/flp30-c>`,
181181
:doc:`cert-mem57-cpp <cert/mem57-cpp>`,
@@ -441,6 +441,7 @@ Check aliases
441441
:doc:`cert-dcl59-cpp <cert/dcl59-cpp>`, :doc:`google-build-namespaces <google/build-namespaces>`,
442442
:doc:`cert-err09-cpp <cert/err09-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
443443
:doc:`cert-err34-c <cert/err34-c>`, :doc:`bugprone-unchecked-string-to-number-conversion <bugprone/unchecked-string-to-number-conversion>`,
444+
:doc:`cert-err52-cpp <cert/err52-cpp>`, :doc:`bugprone-avoid-setjmp-longjmp <bugprone/avoid-setjmp-longjmp>`,
444445
:doc:`cert-err58-cpp <cert/err58-cpp>`, :doc:`bugprone-throwing-static-initialization <bugprone/throwing-static-initialization>`,
445446
:doc:`cert-err61-cpp <cert/err61-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
446447
:doc:`cert-exp42-c <cert/exp42-c>`, :doc:`bugprone-suspicious-memory-comparison <bugprone/suspicious-memory-comparison>`,

0 commit comments

Comments
 (0)