Skip to content

Commit 3ceb1fb

Browse files
authored
Merge branch 'llvm:main' into fix-jitlink
2 parents 7e64904 + 67c8e38 commit 3ceb1fb

File tree

67 files changed

+785
-279
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+785
-279
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434
#include "../google/UnnamedNamespaceInHeaderCheck.h"
3535
#include "../misc/NewDeleteOverloadsCheck.h"
3636
#include "../misc/NonCopyableObjectsCheck.h"
37+
#include "../misc/PredictableRandCheck.h"
3738
#include "../misc/StaticAssertCheck.h"
3839
#include "../misc/ThrowByValueCatchByReferenceCheck.h"
3940
#include "../modernize/AvoidSetjmpLongjmpCheck.h"
4041
#include "../modernize/AvoidVariadicFunctionsCheck.h"
4142
#include "../performance/MoveConstructorInitCheck.h"
4243
#include "../readability/EnumInitialValueCheck.h"
4344
#include "../readability/UppercaseLiteralSuffixCheck.h"
44-
#include "LimitedRandomnessCheck.h"
4545

4646
namespace {
4747

@@ -271,7 +271,7 @@ class CERTModule : public ClangTidyModule {
271271
.registerCheck<bugprone::DefaultOperatorNewOnOveralignedTypeCheck>(
272272
"cert-mem57-cpp");
273273
// MSC
274-
CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc50-cpp");
274+
CheckFactories.registerCheck<misc::PredictableRandCheck>("cert-msc50-cpp");
275275
CheckFactories.registerCheck<bugprone::RandomGeneratorSeedCheck>(
276276
"cert-msc51-cpp");
277277
CheckFactories.registerCheck<bugprone::SignalHandlerCheck>(
@@ -324,7 +324,7 @@ class CERTModule : public ClangTidyModule {
324324
// MSC
325325
CheckFactories.registerCheck<bugprone::UnsafeFunctionsCheck>(
326326
"cert-msc24-c");
327-
CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc30-c");
327+
CheckFactories.registerCheck<misc::PredictableRandCheck>("cert-msc30-c");
328328
CheckFactories.registerCheck<bugprone::RandomGeneratorSeedCheck>(
329329
"cert-msc32-c");
330330
CheckFactories.registerCheck<bugprone::UnsafeFunctionsCheck>(

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-
LimitedRandomnessCheck.cpp
98

109
LINK_LIBS
1110
clangTidy

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ add_clang_library(clangTidyMiscModule STATIC
3333
NonCopyableObjectsCheck.cpp
3434
NonPrivateMemberVariablesInClassesCheck.cpp
3535
OverrideWithDifferentVisibilityCheck.cpp
36+
PredictableRandCheck.cpp
3637
RedundantExpressionCheck.cpp
3738
StaticAssertCheck.cpp
3839
ThrowByValueCatchByReferenceCheck.cpp

clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "NonCopyableObjectsCheck.h"
2424
#include "NonPrivateMemberVariablesInClassesCheck.h"
2525
#include "OverrideWithDifferentVisibilityCheck.h"
26+
#include "PredictableRandCheck.h"
2627
#include "RedundantExpressionCheck.h"
2728
#include "StaticAssertCheck.h"
2829
#include "ThrowByValueCatchByReferenceCheck.h"
@@ -63,6 +64,9 @@ class MiscModule : public ClangTidyModule {
6364
"misc-non-copyable-objects");
6465
CheckFactories.registerCheck<NonPrivateMemberVariablesInClassesCheck>(
6566
"misc-non-private-member-variables-in-classes");
67+
CheckFactories.registerCheck<OverrideWithDifferentVisibilityCheck>(
68+
"misc-override-with-different-visibility");
69+
CheckFactories.registerCheck<PredictableRandCheck>("misc-predictable-rand");
6670
CheckFactories.registerCheck<RedundantExpressionCheck>(
6771
"misc-redundant-expression");
6872
CheckFactories.registerCheck<StaticAssertCheck>("misc-static-assert");
@@ -82,8 +86,6 @@ class MiscModule : public ClangTidyModule {
8286
"misc-use-anonymous-namespace");
8387
CheckFactories.registerCheck<UseInternalLinkageCheck>(
8488
"misc-use-internal-linkage");
85-
CheckFactories.registerCheck<OverrideWithDifferentVisibilityCheck>(
86-
"misc-override-with-different-visibility");
8789
}
8890
};
8991

clang-tools-extra/clang-tidy/cert/LimitedRandomnessCheck.cpp renamed to clang-tools-extra/clang-tidy/misc/PredictableRandCheck.cpp

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

9-
#include "LimitedRandomnessCheck.h"
9+
#include "PredictableRandCheck.h"
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
1212

1313
using namespace clang::ast_matchers;
1414

15-
namespace clang::tidy::cert {
15+
namespace clang::tidy::misc {
1616

17-
void LimitedRandomnessCheck::registerMatchers(MatchFinder *Finder) {
17+
void PredictableRandCheck::registerMatchers(MatchFinder *Finder) {
1818
Finder->addMatcher(callExpr(callee(functionDecl(namedDecl(hasName("::rand")),
1919
parameterCountIs(0))))
2020
.bind("randomGenerator"),
2121
this);
2222
}
2323

24-
void LimitedRandomnessCheck::check(const MatchFinder::MatchResult &Result) {
24+
void PredictableRandCheck::check(const MatchFinder::MatchResult &Result) {
2525
std::string Msg;
2626
if (getLangOpts().CPlusPlus)
2727
Msg = "; use C++11 random library instead";
@@ -30,4 +30,4 @@ void LimitedRandomnessCheck::check(const MatchFinder::MatchResult &Result) {
3030
diag(MatchedDecl->getBeginLoc(), "rand() has limited randomness" + Msg);
3131
}
3232

33-
} // namespace clang::tidy::cert
33+
} // namespace clang::tidy::misc

clang-tools-extra/clang-tidy/cert/LimitedRandomnessCheck.h renamed to clang-tools-extra/clang-tidy/misc/PredictableRandCheck.h

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

9-
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_LIMITEDRANDOMNESSCHECK_H
10-
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_LIMITEDRANDOMNESSCHECK_H
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_PREDICTABLERANDCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_PREDICTABLERANDCHECK_H
1111

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

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

1616
/// Pseudorandom number generators are not genuinely random. The result of the
1717
/// std::rand() function makes no guarantees as to the quality of the random
1818
/// sequence produced.
1919
/// This check warns for the usage of std::rand() function.
2020
///
2121
/// For the user-facing documentation see:
22-
/// https://clang.llvm.org/extra/clang-tidy/checks/cert/msc50-cpp.html
23-
class LimitedRandomnessCheck : public ClangTidyCheck {
22+
/// https://clang.llvm.org/extra/clang-tidy/checks/misc/predictable-rand.html
23+
class PredictableRandCheck : public ClangTidyCheck {
2424
public:
25-
LimitedRandomnessCheck(StringRef Name, ClangTidyContext *Context)
25+
PredictableRandCheck(StringRef Name, ClangTidyContext *Context)
2626
: ClangTidyCheck(Name, Context) {}
2727
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2828
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
2929
};
3030

31-
} // namespace clang::tidy::cert
31+
} // namespace clang::tidy::misc
3232

33-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_LIMITEDRANDOMNESSCHECK_H
33+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_PREDICTABLERANDCHECK_H

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,21 @@ New check aliases
283283
<clang-tidy/checks/bugprone/default-operator-new-on-overaligned-type>`
284284
keeping initial check as an alias to the new one.
285285

286+
- Renamed :doc:`cert-msc30-c <clang-tidy/checks/cert/msc30-c>` to
287+
:doc:`misc-predictable-rand
288+
<clang-tidy/checks/misc/predictable-rand>`
289+
keeping initial check as an alias to the new one.
290+
286291
- Renamed :doc:`cert-msc32-c <clang-tidy/checks/cert/msc32-c>` to
287292
:doc:`bugprone-random-generator-seed
288293
<clang-tidy/checks/bugprone/random-generator-seed>`
289294
keeping initial check as an alias to the new one.
290295

296+
- Renamed :doc:`cert-msc50-cpp <clang-tidy/checks/cert/msc50-cpp>` to
297+
:doc:`misc-predictable-rand
298+
<clang-tidy/checks/misc/predictable-rand>`
299+
keeping initial check as an alias to the new one.
300+
291301
- Renamed :doc:`cert-msc51-cpp <clang-tidy/checks/cert/msc51-cpp>` to
292302
:doc:`bugprone-random-generator-seed
293303
<clang-tidy/checks/bugprone/random-generator-seed>`
@@ -316,7 +326,7 @@ Changes in existing checks
316326
exceptions from captures are now diagnosed, exceptions in the bodies of
317327
lambdas that aren't actually invoked are not. Additionally, fixed an issue
318328
where the check wouldn't diagnose throws in arguments to functions or
319-
constructors. Added fine-grained configuration via options
329+
constructors. Added fine-grained configuration via options
320330
`CheckDestructors`, `CheckMoveMemberFunctions`, `CheckMain`,
321331
`CheckedSwapFunctions`, and `CheckNothrowFunctions`.
322332

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
.. title:: clang-tidy - cert-msc30-c
22
.. meta::
3-
:http-equiv=refresh: 5;URL=../cert/msc50-cpp.html
3+
:http-equiv=refresh: 5;URL=../misc/predictable-rand.html
44

55
cert-msc30-c
66
============
77

88
The `cert-msc30-c` check is an alias, please see
9-
:doc:`cert-msc50-cpp <../cert/msc50-cpp>` for more information.
9+
:doc:`misc-predictable-rand <../misc/predictable-rand>` for more information.
10+
11+
This check corresponds to the CERT C Coding Standard rule
12+
`MSC30-C. Do not use the rand() function for generating pseudorandom numbers
13+
<https://wiki.sei.cmu.edu/confluence/display/c/MSC30-C.+Do+not+use+the+rand%28%29+function+for+generating+pseudorandom+numbers>`_.
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
.. title:: clang-tidy - cert-msc50-cpp
2+
.. meta::
3+
:http-equiv=refresh: 5;URL=../misc/predictable-rand.html
24

35
cert-msc50-cpp
46
==============
57

6-
Pseudorandom number generators use mathematical algorithms to produce a
7-
sequence of numbers with good statistical properties, but the numbers
8-
produced are not genuinely random. The ``std::rand()`` function takes a
9-
seed (number), runs a mathematical operation on it and returns the result.
10-
By manipulating the seed the result can be predictable. This check warns
11-
for the usage of ``std::rand()``.
8+
The `cert-msc50-cpp` check is an alias, please see
9+
:doc:`misc-predictable-rand <../misc/predictable-rand>` for more information.
10+
11+
This check corresponds to the CERT C Coding Standard rule
12+
`MSC50-CPP. Do not use std::rand() for generating pseudorandom numbers
13+
<https://wiki.sei.cmu.edu/confluence/display/cplusplus/MSC50-CPP.+Do+not+use+std%3A%3Arand%28%29+for+generating+pseudorandom+numbers>`_.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ Clang-Tidy Checks
278278
:doc:`misc-non-copyable-objects <misc/non-copyable-objects>`,
279279
:doc:`misc-non-private-member-variables-in-classes <misc/non-private-member-variables-in-classes>`,
280280
:doc:`misc-override-with-different-visibility <misc/override-with-different-visibility>`,
281+
:doc:`misc-predictable-rand <misc/predictable-rand>`,
281282
:doc:`misc-redundant-expression <misc/redundant-expression>`, "Yes"
282283
:doc:`misc-static-assert <misc/static-assert>`, "Yes"
283284
:doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
@@ -460,7 +461,8 @@ Check aliases
460461
:doc:`cert-int09-c <cert/int09-c>`, :doc:`readability-enum-initial-value <readability/enum-initial-value>`, "Yes"
461462
:doc:`cert-mem57-cpp <cert/mem57-cpp>`, :doc:`bugprone-default-operator-new-on-overaligned-type <bugprone/default-operator-new-on-overaligned-type>`,
462463
:doc:`cert-msc24-c <cert/msc24-c>`, :doc:`bugprone-unsafe-functions <bugprone/unsafe-functions>`,
463-
:doc:`cert-msc30-c <cert/msc30-c>`, :doc:`cert-msc50-cpp <cert/msc50-cpp>`,
464+
:doc:`cert-msc30-c <cert/msc30-c>`, :doc:`misc-predictable-rand <misc/predictable-rand>`,
465+
:doc:`cert-msc50-cpp <cert/msc50-cpp>`, :doc:`misc-predictable-rand <misc/predictable-rand>`,
464466
:doc:`cert-msc32-c <cert/msc32-c>`, :doc:`bugprone-random-generator-seed <bugprone/random-generator-seed>`,
465467
:doc:`cert-msc33-c <cert/msc33-c>`, :doc:`bugprone-unsafe-functions <bugprone/unsafe-functions>`,
466468
:doc:`cert-msc51-cpp <cert/msc51-cpp>`, :doc:`bugprone-random-generator-seed <bugprone/random-generator-seed>`,

0 commit comments

Comments
 (0)