2017-03-20 01:23:23 +08:00
|
|
|
//===------- HICPPTidyModule.cpp - clang-tidy -----------------------------===//
|
[clang-tidy] safety-no-assembler
Summary:
Add a new clang-tidy module for safety-critical checks.
Include a check for inline assembler.
Reviewers: Prazek, dtarditi, malcolm.parsons, alexfh, aaron.ballman, idlecode
Reviewed By: idlecode
Subscribers: idlecode, JonasToth, Eugene.Zelenko, mgorny, JDevlieghere, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D29267
llvm-svn: 294255
2017-02-07 06:57:14 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
[clang-tidy] safety-no-assembler
Summary:
Add a new clang-tidy module for safety-critical checks.
Include a check for inline assembler.
Reviewers: Prazek, dtarditi, malcolm.parsons, alexfh, aaron.ballman, idlecode
Reviewed By: idlecode
Subscribers: idlecode, JonasToth, Eugene.Zelenko, mgorny, JDevlieghere, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D29267
llvm-svn: 294255
2017-02-07 06:57:14 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "../ClangTidy.h"
|
|
|
|
#include "../ClangTidyModule.h"
|
|
|
|
#include "../ClangTidyModuleRegistry.h"
|
2017-11-24 22:16:29 +08:00
|
|
|
#include "../bugprone/UseAfterMoveCheck.h"
|
[clang-tidy] implement check for goto
The usage of `goto` is discourage in C++ since forever. This check implements
a warning for every `goto`. Even though there are (rare) valid use cases for
`goto`, better high level constructs should be used.
`goto` is used sometimes in C programs to free resources at the end of
functions in the case of errors. This pattern is better implemented with
RAII in C++.
Reviewers: aaron.ballman, alexfh, hokein
Reviewed By: aaron.ballman
Subscribers: lebedev.ri, jbcoe, Eugene.Zelenko, klimek, nemanjai, mgorny, xazax.hun, kbarton, cfe-commits
Differential Revision: https://reviews.llvm.org/D41815
llvm-svn: 322626
2018-01-17 18:27:41 +08:00
|
|
|
#include "../cppcoreguidelines/AvoidGotoCheck.h"
|
2017-09-11 17:20:07 +08:00
|
|
|
#include "../cppcoreguidelines/NoMallocCheck.h"
|
|
|
|
#include "../cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.h"
|
2017-03-30 19:57:54 +08:00
|
|
|
#include "../cppcoreguidelines/ProTypeMemberInitCheck.h"
|
2017-09-11 17:20:07 +08:00
|
|
|
#include "../cppcoreguidelines/ProTypeVarargCheck.h"
|
2017-03-30 19:57:54 +08:00
|
|
|
#include "../cppcoreguidelines/SpecialMemberFunctionsCheck.h"
|
|
|
|
#include "../google/DefaultArgumentsCheck.h"
|
|
|
|
#include "../google/ExplicitConstructorCheck.h"
|
|
|
|
#include "../misc/NewDeleteOverloadsCheck.h"
|
2017-09-11 17:20:07 +08:00
|
|
|
#include "../misc/StaticAssertCheck.h"
|
2018-03-01 07:47:15 +08:00
|
|
|
#include "../bugprone/UndelegatedConstructorCheck.h"
|
[clang-tidy] Avoid C arrays check
Summary:
[[ https://bugs.llvm.org/show_bug.cgi?id=39224 | PR39224 ]]
As discussed, we can't always do the transform automatically due to that array-to-pointer decay of C array.
In order to detect whether we can do said transform, we'd need to be able to see all usages of said array,
which is, i would say, rather impossible if e.g. it is in the header.
Thus right now no fixit exists.
Exceptions: `extern "C"` code.
References:
* [[ https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es27-use-stdarray-or-stack_array-for-arrays-on-the-stack | CPPCG ES.27: Use std::array or stack_array for arrays on the stack ]]
* [[ https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#slcon1-prefer-using-stl-array-or-vector-instead-of-a-c-array | CPPCG SL.con.1: Prefer using STL array or vector instead of a C array ]]
* HICPP `4.1.1 Ensure that a function argument does not undergo an array-to-pointer conversion`
* MISRA `5-2-12 An identifier with array type passed as a function argument shall not decay to a pointer`
Reviewers: aaron.ballman, JonasToth, alexfh, hokein, xazax.hun
Reviewed By: JonasToth
Subscribers: Eugene.Zelenko, mgorny, rnkovacs, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D53771
llvm-svn: 346835
2018-11-14 17:01:08 +08:00
|
|
|
#include "../modernize/AvoidCArraysCheck.h"
|
2017-09-11 17:20:07 +08:00
|
|
|
#include "../modernize/DeprecatedHeadersCheck.h"
|
|
|
|
#include "../modernize/UseAutoCheck.h"
|
|
|
|
#include "../modernize/UseEmplaceCheck.h"
|
2017-03-30 19:57:54 +08:00
|
|
|
#include "../modernize/UseEqualsDefaultCheck.h"
|
|
|
|
#include "../modernize/UseEqualsDeleteCheck.h"
|
2017-09-11 17:20:07 +08:00
|
|
|
#include "../modernize/UseNoexceptCheck.h"
|
|
|
|
#include "../modernize/UseNullptrCheck.h"
|
2017-03-30 19:57:54 +08:00
|
|
|
#include "../modernize/UseOverrideCheck.h"
|
2017-11-29 00:41:03 +08:00
|
|
|
#include "../performance/MoveConstArgCheck.h"
|
|
|
|
#include "../performance/NoexceptMoveConstructorCheck.h"
|
2017-08-11 20:12:36 +08:00
|
|
|
#include "../readability/BracesAroundStatementsCheck.h"
|
2017-03-30 19:57:54 +08:00
|
|
|
#include "../readability/FunctionSizeCheck.h"
|
|
|
|
#include "../readability/IdentifierNamingCheck.h"
|
[clang-tidy] Re-commit: Add new 'readability-uppercase-literal-suffix' check (CERT DCL16-C, MISRA C:2012, 7.3, MISRA C++:2008, 2-13-4)
Summary:
Detects when the integral literal or floating point (decimal or hexadecimal)
literal has non-uppercase suffix, and suggests to make the suffix uppercase,
with fix-it.
All valid combinations of suffixes are supported.
```
auto x = 1; // OK, no suffix.
auto x = 1u; // warning: integer literal suffix 'u' is not upper-case
auto x = 1U; // OK, suffix is uppercase.
...
```
This is a re-commit, the original was reverted by me in
rL345305 due to discovered bugs. (implicit code, template instantiation)
Tests were added, and the bugs were fixed.
I'm unable to find any further bugs, hopefully there aren't any..
References:
* [[ https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152241 | CERT DCL16-C ]]
* MISRA C:2012, 7.3 - The lowercase character "l" shall not be used in a literal suffix
* MISRA C++:2008, 2-13-4 - Literal suffixes shall be upper case
Reviewers: JonasToth, aaron.ballman, alexfh, hokein, xazax.hun
Reviewed By: aaron.ballman
Subscribers: Eugene.Zelenko, mgorny, rnkovacs, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D52670
llvm-svn: 345381
2018-10-26 21:09:27 +08:00
|
|
|
#include "../readability/UppercaseLiteralSuffixCheck.h"
|
2017-08-12 00:31:51 +08:00
|
|
|
#include "ExceptionBaseclassCheck.h"
|
2018-03-21 23:34:15 +08:00
|
|
|
#include "MultiwayPathsCoveredCheck.h"
|
[clang-tidy] safety-no-assembler
Summary:
Add a new clang-tidy module for safety-critical checks.
Include a check for inline assembler.
Reviewers: Prazek, dtarditi, malcolm.parsons, alexfh, aaron.ballman, idlecode
Reviewed By: idlecode
Subscribers: idlecode, JonasToth, Eugene.Zelenko, mgorny, JDevlieghere, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D29267
llvm-svn: 294255
2017-02-07 06:57:14 +08:00
|
|
|
#include "NoAssemblerCheck.h"
|
2017-08-30 21:32:05 +08:00
|
|
|
#include "SignedBitwiseCheck.h"
|
[clang-tidy] safety-no-assembler
Summary:
Add a new clang-tidy module for safety-critical checks.
Include a check for inline assembler.
Reviewers: Prazek, dtarditi, malcolm.parsons, alexfh, aaron.ballman, idlecode
Reviewed By: idlecode
Subscribers: idlecode, JonasToth, Eugene.Zelenko, mgorny, JDevlieghere, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D29267
llvm-svn: 294255
2017-02-07 06:57:14 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
2017-03-20 01:23:23 +08:00
|
|
|
namespace hicpp {
|
[clang-tidy] safety-no-assembler
Summary:
Add a new clang-tidy module for safety-critical checks.
Include a check for inline assembler.
Reviewers: Prazek, dtarditi, malcolm.parsons, alexfh, aaron.ballman, idlecode
Reviewed By: idlecode
Subscribers: idlecode, JonasToth, Eugene.Zelenko, mgorny, JDevlieghere, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D29267
llvm-svn: 294255
2017-02-07 06:57:14 +08:00
|
|
|
|
2017-03-20 01:23:23 +08:00
|
|
|
class HICPPModule : public ClangTidyModule {
|
[clang-tidy] safety-no-assembler
Summary:
Add a new clang-tidy module for safety-critical checks.
Include a check for inline assembler.
Reviewers: Prazek, dtarditi, malcolm.parsons, alexfh, aaron.ballman, idlecode
Reviewed By: idlecode
Subscribers: idlecode, JonasToth, Eugene.Zelenko, mgorny, JDevlieghere, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D29267
llvm-svn: 294255
2017-02-07 06:57:14 +08:00
|
|
|
public:
|
|
|
|
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
|
[clang-tidy] Avoid C arrays check
Summary:
[[ https://bugs.llvm.org/show_bug.cgi?id=39224 | PR39224 ]]
As discussed, we can't always do the transform automatically due to that array-to-pointer decay of C array.
In order to detect whether we can do said transform, we'd need to be able to see all usages of said array,
which is, i would say, rather impossible if e.g. it is in the header.
Thus right now no fixit exists.
Exceptions: `extern "C"` code.
References:
* [[ https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es27-use-stdarray-or-stack_array-for-arrays-on-the-stack | CPPCG ES.27: Use std::array or stack_array for arrays on the stack ]]
* [[ https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#slcon1-prefer-using-stl-array-or-vector-instead-of-a-c-array | CPPCG SL.con.1: Prefer using STL array or vector instead of a C array ]]
* HICPP `4.1.1 Ensure that a function argument does not undergo an array-to-pointer conversion`
* MISRA `5-2-12 An identifier with array type passed as a function argument shall not decay to a pointer`
Reviewers: aaron.ballman, JonasToth, alexfh, hokein, xazax.hun
Reviewed By: JonasToth
Subscribers: Eugene.Zelenko, mgorny, rnkovacs, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D53771
llvm-svn: 346835
2018-11-14 17:01:08 +08:00
|
|
|
CheckFactories.registerCheck<modernize::AvoidCArraysCheck>(
|
|
|
|
"hicpp-avoid-c-arrays");
|
[clang-tidy] implement check for goto
The usage of `goto` is discourage in C++ since forever. This check implements
a warning for every `goto`. Even though there are (rare) valid use cases for
`goto`, better high level constructs should be used.
`goto` is used sometimes in C programs to free resources at the end of
functions in the case of errors. This pattern is better implemented with
RAII in C++.
Reviewers: aaron.ballman, alexfh, hokein
Reviewed By: aaron.ballman
Subscribers: lebedev.ri, jbcoe, Eugene.Zelenko, klimek, nemanjai, mgorny, xazax.hun, kbarton, cfe-commits
Differential Revision: https://reviews.llvm.org/D41815
llvm-svn: 322626
2018-01-17 18:27:41 +08:00
|
|
|
CheckFactories.registerCheck<cppcoreguidelines::AvoidGotoCheck>(
|
|
|
|
"hicpp-avoid-goto");
|
2017-08-11 20:12:36 +08:00
|
|
|
CheckFactories.registerCheck<readability::BracesAroundStatementsCheck>(
|
|
|
|
"hicpp-braces-around-statements");
|
2017-09-11 17:20:07 +08:00
|
|
|
CheckFactories.registerCheck<modernize::DeprecatedHeadersCheck>(
|
|
|
|
"hicpp-deprecated-headers");
|
2017-08-12 00:31:51 +08:00
|
|
|
CheckFactories.registerCheck<ExceptionBaseclassCheck>(
|
|
|
|
"hicpp-exception-baseclass");
|
2018-03-21 23:34:15 +08:00
|
|
|
CheckFactories.registerCheck<MultiwayPathsCoveredCheck>(
|
|
|
|
"hicpp-multiway-paths-covered");
|
2018-01-17 18:23:50 +08:00
|
|
|
CheckFactories.registerCheck<SignedBitwiseCheck>("hicpp-signed-bitwise");
|
2017-03-30 19:57:54 +08:00
|
|
|
CheckFactories.registerCheck<google::ExplicitConstructorCheck>(
|
|
|
|
"hicpp-explicit-conversions");
|
|
|
|
CheckFactories.registerCheck<readability::FunctionSizeCheck>(
|
|
|
|
"hicpp-function-size");
|
|
|
|
CheckFactories.registerCheck<readability::IdentifierNamingCheck>(
|
|
|
|
"hicpp-named-parameter");
|
2017-11-24 22:16:29 +08:00
|
|
|
CheckFactories.registerCheck<bugprone::UseAfterMoveCheck>(
|
2017-03-30 19:57:54 +08:00
|
|
|
"hicpp-invalid-access-moved");
|
|
|
|
CheckFactories.registerCheck<cppcoreguidelines::ProTypeMemberInitCheck>(
|
|
|
|
"hicpp-member-init");
|
2017-11-29 00:41:03 +08:00
|
|
|
CheckFactories.registerCheck<performance::MoveConstArgCheck>(
|
2017-09-11 17:20:07 +08:00
|
|
|
"hicpp-move-const-arg");
|
2017-03-30 19:57:54 +08:00
|
|
|
CheckFactories.registerCheck<misc::NewDeleteOverloadsCheck>(
|
|
|
|
"hicpp-new-delete-operators");
|
2017-11-29 00:41:03 +08:00
|
|
|
CheckFactories.registerCheck<performance::NoexceptMoveConstructorCheck>(
|
2017-03-30 19:57:54 +08:00
|
|
|
"hicpp-noexcept-move");
|
2017-09-11 17:20:07 +08:00
|
|
|
CheckFactories
|
|
|
|
.registerCheck<cppcoreguidelines::ProBoundsArrayToPointerDecayCheck>(
|
|
|
|
"hicpp-no-array-decay");
|
2017-03-30 19:57:54 +08:00
|
|
|
CheckFactories.registerCheck<NoAssemblerCheck>("hicpp-no-assembler");
|
2017-09-11 17:20:07 +08:00
|
|
|
CheckFactories.registerCheck<cppcoreguidelines::NoMallocCheck>(
|
|
|
|
"hicpp-no-malloc");
|
2017-03-30 19:57:54 +08:00
|
|
|
CheckFactories
|
|
|
|
.registerCheck<cppcoreguidelines::SpecialMemberFunctionsCheck>(
|
|
|
|
"hicpp-special-member-functions");
|
2017-09-11 17:20:07 +08:00
|
|
|
CheckFactories.registerCheck<misc::StaticAssertCheck>(
|
|
|
|
"hicpp-static-assert");
|
|
|
|
CheckFactories.registerCheck<modernize::UseAutoCheck>("hicpp-use-auto");
|
2018-03-01 07:47:15 +08:00
|
|
|
CheckFactories.registerCheck<bugprone::UndelegatedConstructorCheck>(
|
2017-03-30 19:57:54 +08:00
|
|
|
"hicpp-undelegated-constructor");
|
2017-09-11 17:20:07 +08:00
|
|
|
CheckFactories.registerCheck<modernize::UseEmplaceCheck>(
|
|
|
|
"hicpp-use-emplace");
|
2017-03-30 19:57:54 +08:00
|
|
|
CheckFactories.registerCheck<modernize::UseEqualsDefaultCheck>(
|
|
|
|
"hicpp-use-equals-default");
|
|
|
|
CheckFactories.registerCheck<modernize::UseEqualsDeleteCheck>(
|
|
|
|
"hicpp-use-equals-delete");
|
2017-09-11 17:20:07 +08:00
|
|
|
CheckFactories.registerCheck<modernize::UseNoexceptCheck>(
|
|
|
|
"hicpp-use-noexcept");
|
|
|
|
CheckFactories.registerCheck<modernize::UseNullptrCheck>(
|
|
|
|
"hicpp-use-nullptr");
|
2017-03-30 19:57:54 +08:00
|
|
|
CheckFactories.registerCheck<modernize::UseOverrideCheck>(
|
|
|
|
"hicpp-use-override");
|
[clang-tidy] Re-commit: Add new 'readability-uppercase-literal-suffix' check (CERT DCL16-C, MISRA C:2012, 7.3, MISRA C++:2008, 2-13-4)
Summary:
Detects when the integral literal or floating point (decimal or hexadecimal)
literal has non-uppercase suffix, and suggests to make the suffix uppercase,
with fix-it.
All valid combinations of suffixes are supported.
```
auto x = 1; // OK, no suffix.
auto x = 1u; // warning: integer literal suffix 'u' is not upper-case
auto x = 1U; // OK, suffix is uppercase.
...
```
This is a re-commit, the original was reverted by me in
rL345305 due to discovered bugs. (implicit code, template instantiation)
Tests were added, and the bugs were fixed.
I'm unable to find any further bugs, hopefully there aren't any..
References:
* [[ https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152241 | CERT DCL16-C ]]
* MISRA C:2012, 7.3 - The lowercase character "l" shall not be used in a literal suffix
* MISRA C++:2008, 2-13-4 - Literal suffixes shall be upper case
Reviewers: JonasToth, aaron.ballman, alexfh, hokein, xazax.hun
Reviewed By: aaron.ballman
Subscribers: Eugene.Zelenko, mgorny, rnkovacs, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D52670
llvm-svn: 345381
2018-10-26 21:09:27 +08:00
|
|
|
CheckFactories.registerCheck<readability::UppercaseLiteralSuffixCheck>(
|
|
|
|
"hicpp-uppercase-literal-suffix");
|
2017-09-11 17:20:07 +08:00
|
|
|
CheckFactories.registerCheck<cppcoreguidelines::ProTypeVarargCheck>(
|
|
|
|
"hicpp-vararg");
|
[clang-tidy] safety-no-assembler
Summary:
Add a new clang-tidy module for safety-critical checks.
Include a check for inline assembler.
Reviewers: Prazek, dtarditi, malcolm.parsons, alexfh, aaron.ballman, idlecode
Reviewed By: idlecode
Subscribers: idlecode, JonasToth, Eugene.Zelenko, mgorny, JDevlieghere, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D29267
llvm-svn: 294255
2017-02-07 06:57:14 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-20 01:23:23 +08:00
|
|
|
// Register the HICPPModule using this statically initialized variable.
|
|
|
|
static ClangTidyModuleRegistry::Add<HICPPModule>
|
|
|
|
X("hicpp-module", "Adds High-Integrity C++ checks.");
|
[clang-tidy] safety-no-assembler
Summary:
Add a new clang-tidy module for safety-critical checks.
Include a check for inline assembler.
Reviewers: Prazek, dtarditi, malcolm.parsons, alexfh, aaron.ballman, idlecode
Reviewed By: idlecode
Subscribers: idlecode, JonasToth, Eugene.Zelenko, mgorny, JDevlieghere, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D29267
llvm-svn: 294255
2017-02-07 06:57:14 +08:00
|
|
|
|
2017-03-20 01:23:23 +08:00
|
|
|
} // namespace hicpp
|
[clang-tidy] safety-no-assembler
Summary:
Add a new clang-tidy module for safety-critical checks.
Include a check for inline assembler.
Reviewers: Prazek, dtarditi, malcolm.parsons, alexfh, aaron.ballman, idlecode
Reviewed By: idlecode
Subscribers: idlecode, JonasToth, Eugene.Zelenko, mgorny, JDevlieghere, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D29267
llvm-svn: 294255
2017-02-07 06:57:14 +08:00
|
|
|
|
|
|
|
// This anchor is used to force the linker to link in the generated object file
|
2017-03-20 01:23:23 +08:00
|
|
|
// and thus register the HICPPModule.
|
|
|
|
volatile int HICPPModuleAnchorSource = 0;
|
[clang-tidy] safety-no-assembler
Summary:
Add a new clang-tidy module for safety-critical checks.
Include a check for inline assembler.
Reviewers: Prazek, dtarditi, malcolm.parsons, alexfh, aaron.ballman, idlecode
Reviewed By: idlecode
Subscribers: idlecode, JonasToth, Eugene.Zelenko, mgorny, JDevlieghere, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D29267
llvm-svn: 294255
2017-02-07 06:57:14 +08:00
|
|
|
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|