Skip to content

Commit dcf857e

Browse files
committed
Merge branch 'main' into users/ylzsx/r-tls-noie
2 parents 7dc7264 + fa45bf4 commit dcf857e

File tree

89 files changed

+3015
-780
lines changed

Some content is hidden

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

89 files changed

+3015
-780
lines changed

clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,19 @@ void UseRangesCheck::check(const MatchFinder::MatchResult &Result) {
215215
const auto *Call = Result.Nodes.getNodeAs<CallExpr>(Buffer);
216216
if (!Call)
217217
continue;
218+
219+
// FIXME: This check specifically handles `CXXNullPtrLiteralExpr`, but
220+
// a more general solution might be needed.
221+
if (Function->getName() == "find") {
222+
const unsigned ValueArgIndex = 2;
223+
if (Call->getNumArgs() <= ValueArgIndex)
224+
continue;
225+
const Expr *ValueExpr =
226+
Call->getArg(ValueArgIndex)->IgnoreParenImpCasts();
227+
if (isa<CXXNullPtrLiteralExpr>(ValueExpr))
228+
return;
229+
}
230+
218231
auto Diag = createDiag(*Call);
219232
if (auto ReplaceName = Replacer->getReplaceName(*Function))
220233
Diag << FixItHint::CreateReplacement(Call->getCallee()->getSourceRange(),

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ Changes in existing checks
131131
- Improved :doc:`misc-redundant-expression
132132
<clang-tidy/checks/misc/redundant-expression>` check by providing additional
133133
examples and fixing some macro related false positives.
134+
135+
- Improved :doc:`modernize-use-ranges
136+
<clang-tidy/checks/modernize/use-ranges>` check by updating suppress
137+
warnings logic for ``nullptr`` in ``std::find``.
134138

135139
- Improved :doc:`misc-use-internal-linkage
136140
<clang-tidy/checks/misc/use-internal-linkage>` check by fix false positives

clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1-
// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I %S/Inputs/use-ranges/
2-
// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t -check-suffixes=,CPP23 -- -I %S/Inputs/use-ranges/
1+
// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I %S/Inputs/
2+
// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t -check-suffixes=,CPP23 -- -I %S/Inputs/
3+
// Example: ./check_clang_tidy.py -std=c++20 checkers/modernize/use-ranges.cpp modernize-use-ranges temp.txt -- -- -I ~/llvm-project/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/
34

45
// CHECK-FIXES: #include <algorithm>
56
// CHECK-FIXES-CPP23: #include <numeric>
67
// CHECK-FIXES: #include <ranges>
78

8-
#include "fake_std.h"
9+
#include "use-ranges/fake_std.h"
10+
#include "smart-ptr/unique_ptr.h"
911

1012
void Positives() {
1113
std::vector<int> I, J;
14+
std::vector<std::unique_ptr<int>> K;
15+
16+
// Expect to have no check messages
17+
std::find(K.begin(), K.end(), nullptr);
18+
19+
std::find(K.begin(), K.end(), std::unique_ptr<int>());
20+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this algorithm
21+
// CHECK-FIXES: std::ranges::find(K, std::unique_ptr<int>());
22+
1223
std::find(I.begin(), I.end(), 0);
1324
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this algorithm
1425
// CHECK-FIXES: std::ranges::find(I, 0);
@@ -76,6 +87,15 @@ void Positives() {
7687

7788
void Reverse(){
7889
std::vector<int> I, J;
90+
std::vector<std::unique_ptr<int>> K;
91+
92+
// Expect to have no check messages
93+
std::find(K.rbegin(), K.rend(), nullptr);
94+
95+
std::find(K.rbegin(), K.rend(), std::unique_ptr<int>());
96+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this algorithm
97+
// CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(K), std::unique_ptr<int>());
98+
7999
std::find(I.rbegin(), I.rend(), 0);
80100
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this algorithm
81101
// CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(I), 0);

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ Bug Fixes to C++ Support
294294
direct-list-initialized from an array is corrected to direct-initialization.
295295
- Clang no longer crashes when a coroutine is declared ``[[noreturn]]``. (#GH127327)
296296
- Clang now uses the parameter location for abbreviated function templates in ``extern "C"``. (#GH46386)
297+
- Clang now correctly parses ``if constexpr`` expressions in immediate function context. (#GH123524)
297298

298299
Improvements to C++ diagnostics
299300
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/docs/analyzer/checkers.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3522,6 +3522,18 @@ Raw pointers and references to an object which supports CheckedPtr or CheckedRef
35223522
35233523
See `WebKit Guidelines for Safer C++ Programming <https://github.com/WebKit/WebKit/wiki/Safer-CPP-Guidelines>`_ for details.
35243524
3525+
alpha.webkit.UnretainedLambdaCapturesChecker
3526+
""""""""""""""""""""""""""""""""""""""""""""
3527+
Raw pointers and references to NS or CF types can't be captured in lambdas. Only RetainPtr is allowed for CF types regardless of whether ARC is enabled or disabled, and only RetainPtr is allowed for NS types when ARC is disabled.
3528+
3529+
.. code-block:: cpp
3530+
3531+
void foo(NSObject *a, NSObject *b) {
3532+
[&, a](){ // warn about 'a'
3533+
do_something(b); // warn about 'b'
3534+
};
3535+
};
3536+
35253537
.. _alpha-webkit-UncountedCallArgsChecker:
35263538
35273539
alpha.webkit.UncountedCallArgsChecker

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,5 +1817,9 @@ def ext_hlsl_access_specifiers : ExtWarn<
18171817
InGroup<HLSLExtension>;
18181818
def err_hlsl_unsupported_component : Error<"invalid component '%0' used; expected 'x', 'y', 'z', or 'w'">;
18191819
def err_hlsl_packoffset_invalid_reg : Error<"invalid resource class specifier '%0' for packoffset, expected 'c'">;
1820+
def err_hlsl_virtual_function
1821+
: Error<"virtual functions are unsupported in HLSL">;
1822+
def err_hlsl_virtual_inheritance
1823+
: Error<"virtual inheritance is unsupported in HLSL">;
18201824

18211825
} // end of Parser diagnostics

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12707,6 +12707,10 @@ def err_hlsl_param_qualifier_mismatch :
1270712707
def err_hlsl_vector_compound_assignment_truncation : Error<
1270812708
"left hand operand of type %0 to compound assignment cannot be truncated "
1270912709
"when used with right hand operand of type %1">;
12710+
def err_hlsl_builtin_scalar_vector_mismatch
12711+
: Error<
12712+
"%select{all|second and third}0 arguments to %1 must be of scalar or "
12713+
"vector type with matching scalar element type%diff{: $ vs $|}2,3">;
1271012714

1271112715
def warn_hlsl_impcast_vector_truncation : Warning<
1271212716
"implicit conversion truncates vector: %0 to %1">, InGroup<Conversion>;

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ VALUE_LANGOPT(FuchsiaAPILevel, 32, 0, "Fuchsia API level")
515515
// on large _BitInts.
516516
BENIGN_VALUE_LANGOPT(MaxBitIntWidth, 32, 128, "Maximum width of a _BitInt")
517517

518-
COMPATIBLE_LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process statements"
518+
COMPATIBLE_LANGOPT(IncrementalExtensions, 1, 0, "True if we want to process statements "
519519
"on the global scope, ignore EOF token and continue later on (thus "
520520
"avoid tearing the Lexer and etc. down). Controlled by "
521521
"-fincremental-extensions.")

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ def Wa_COMMA : CommaJoined<["-"], "Wa,">,
876876
MetaVarName<"<arg>">;
877877
def warning_suppression_mappings_EQ : Joined<["--"],
878878
"warning-suppression-mappings=">, Group<Diag_Group>,
879-
HelpText<"File containing diagnostic suppresion mappings. See user manual "
879+
HelpText<"File containing diagnostic suppression mappings. See user manual "
880880
"for file format.">, Visibility<[ClangOption, CC1Option]>;
881881
def Wall : Flag<["-"], "Wall">, Group<W_Group>, Flags<[HelpHidden]>,
882882
Visibility<[ClangOption, CC1Option, FlangOption]>;
@@ -941,7 +941,7 @@ def Xarch__
941941
target matches the specified architecture. This can be used with the target
942942
CPU, triple architecture, or offloading host and device. It is most useful
943943
for separating behavior undesirable on one of the targets when combining many
944-
compilation jobs, as is commong with offloading. For example, -Xarch_x86_64,
944+
compilation jobs, as is common with offloading. For example, -Xarch_x86_64,
945945
-Xarch_gfx90a, and -Xarch_device are all valid selectors. -Xarch_device will
946946
forward the argument to the offloading device while -Xarch_host will target
947947
the host system, which can be used to suppress incompatible GPU arguments.}]>,
@@ -1678,7 +1678,7 @@ def fsample_profile_use_profi : Flag<["-"], "fsample-profile-use-profi">,
16781678
HelpText<"Use profi to infer block and edge counts">,
16791679
DocBrief<[{Infer block and edge counts. If the profiles have errors or missing
16801680
blocks caused by sampling, profile inference (profi) can convert
1681-
basic block counts to branch probabilites to fix them by extended
1681+
basic block counts to branch probabilities to fix them by extended
16821682
and re-engineered classic MCMF (min-cost max-flow) approach.}]>;
16831683
def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">, Group<f_Group>;
16841684
def fno_auto_profile : Flag<["-"], "fno-auto-profile">, Group<f_Group>,

clang/include/clang/StaticAnalyzer/Checkers/Checkers.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,10 @@ def NoUncheckedPtrMemberChecker : Checker<"NoUncheckedPtrMemberChecker">,
17651765
HelpText<"Check for no unchecked member variables.">,
17661766
Documentation<HasDocumentation>;
17671767

1768+
def UnretainedLambdaCapturesChecker : Checker<"UnretainedLambdaCapturesChecker">,
1769+
HelpText<"Check unretained lambda captures.">,
1770+
Documentation<HasDocumentation>;
1771+
17681772
def UncountedCallArgsChecker : Checker<"UncountedCallArgsChecker">,
17691773
HelpText<"Check uncounted call arguments.">,
17701774
Documentation<HasDocumentation>;

0 commit comments

Comments
 (0)