Skip to content

Commit 4821b32

Browse files
committed
merge main into amd-staging
xfails: llvm/test/CodeGen/AMDGPU/amdgpu-spill-cfi-saved-regs.ll llvm/test/CodeGen/AMDGPU/debug-frame.ll
2 parents 24931cb + 5c3b059 commit 4821b32

File tree

244 files changed

+16603
-17498
lines changed

Some content is hidden

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

244 files changed

+16603
-17498
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/clangd/Config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,18 @@ struct Config {
5959
std::optional<std::string> FixedCDBPath;
6060
};
6161

62+
enum class BuiltinHeaderPolicy { Clangd, QueryDriver };
6263
/// Controls how the compile command for the current file is determined.
6364
struct {
6465
/// Edits to apply to the compile command, in sequence.
6566
std::vector<llvm::unique_function<void(std::vector<std::string> &) const>>
6667
Edits;
6768
/// Where to search for compilation databases for this file's flags.
6869
CDBSearchSpec CDBSearch = {CDBSearchSpec::Ancestors, std::nullopt};
70+
71+
/// Whether to use clangd's own builtin headers, or ones from the system
72+
/// include extractor, if available.
73+
BuiltinHeaderPolicy BuiltinHeaders = BuiltinHeaderPolicy::Clangd;
6974
} CompileFlags;
7075

7176
enum class BackgroundPolicy { Build, Skip };

clang-tools-extra/clangd/ConfigCompile.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,18 @@ struct FragmentCompiler {
290290
});
291291
}
292292

293+
if (F.BuiltinHeaders) {
294+
if (auto Val =
295+
compileEnum<Config::BuiltinHeaderPolicy>("BuiltinHeaders",
296+
*F.BuiltinHeaders)
297+
.map("Clangd", Config::BuiltinHeaderPolicy::Clangd)
298+
.map("QueryDriver", Config::BuiltinHeaderPolicy::QueryDriver)
299+
.value())
300+
Out.Apply.push_back([Val](const Params &, Config &C) {
301+
C.CompileFlags.BuiltinHeaders = *Val;
302+
});
303+
}
304+
293305
if (F.CompilationDatabase) {
294306
std::optional<Config::CDBSearchSpec> Spec;
295307
if (**F.CompilationDatabase == "Ancestors") {

clang-tools-extra/clangd/ConfigFragment.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ struct Fragment {
170170
/// - Ancestors: search all parent directories (the default)
171171
/// - std::nullopt: do not use a compilation database, just default flags.
172172
std::optional<Located<std::string>> CompilationDatabase;
173+
174+
/// Controls whether Clangd should use its own built-in system headers (like
175+
/// stddef.h), or use the system headers from the query driver. Use the
176+
/// option value 'Clangd' (default) to indicate Clangd's headers, and use
177+
/// 'QueryDriver' to indicate QueryDriver's headers. `Clangd` is the
178+
/// fallback if no query driver is supplied or if the query driver regex
179+
/// string fails to match the compiler used in the CDB.
180+
std::optional<Located<std::string>> BuiltinHeaders;
173181
};
174182
CompileFlagsBlock CompileFlags;
175183

clang-tools-extra/clangd/ConfigYAML.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ class Parser {
104104
if (auto Values = scalarValues(N))
105105
F.Remove = std::move(*Values);
106106
});
107+
Dict.handle("BuiltinHeaders", [&](Node &N) {
108+
if (auto BuiltinHeaders = scalarValue(N, "BuiltinHeaders"))
109+
F.BuiltinHeaders = *BuiltinHeaders;
110+
});
107111
Dict.handle("CompilationDatabase", [&](Node &N) {
108112
F.CompilationDatabase = scalarValue(N, "CompilationDatabase");
109113
});

clang-tools-extra/clangd/SystemIncludeExtractor.cpp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
// in the paths that are explicitly included by the user.
3131

3232
#include "CompileCommands.h"
33+
#include "Config.h"
3334
#include "GlobalCompilationDatabase.h"
3435
#include "support/Logger.h"
3536
#include "support/Threading.h"
@@ -401,22 +402,30 @@ extractSystemIncludesAndTarget(const DriverArgs &InputArgs,
401402
if (!Info)
402403
return std::nullopt;
403404

404-
// The built-in headers are tightly coupled to parser builtins.
405-
// (These are clang's "resource dir", GCC's GCC_INCLUDE_DIR.)
406-
// We should keep using clangd's versions, so exclude the queried builtins.
407-
// They're not specially marked in the -v output, but we can get the path
408-
// with `$DRIVER -print-file-name=include`.
409-
if (auto BuiltinHeaders =
410-
run({Driver, "-print-file-name=include"}, /*OutputIsStderr=*/false)) {
411-
auto Path = llvm::StringRef(*BuiltinHeaders).trim();
412-
if (!Path.empty() && llvm::sys::path::is_absolute(Path)) {
413-
auto Size = Info->SystemIncludes.size();
414-
llvm::erase(Info->SystemIncludes, Path);
415-
vlog("System includes extractor: builtin headers {0} {1}", Path,
416-
(Info->SystemIncludes.size() != Size)
417-
? "excluded"
418-
: "not found in driver's response");
405+
switch (Config::current().CompileFlags.BuiltinHeaders) {
406+
case Config::BuiltinHeaderPolicy::Clangd: {
407+
// The built-in headers are tightly coupled to parser builtins.
408+
// (These are clang's "resource dir", GCC's GCC_INCLUDE_DIR.)
409+
// We should keep using clangd's versions, so exclude the queried
410+
// builtins. They're not specially marked in the -v output, but we can
411+
// get the path with `$DRIVER -print-file-name=include`.
412+
if (auto BuiltinHeaders = run({Driver, "-print-file-name=include"},
413+
/*OutputIsStderr=*/false)) {
414+
auto Path = llvm::StringRef(*BuiltinHeaders).trim();
415+
if (!Path.empty() && llvm::sys::path::is_absolute(Path)) {
416+
auto Size = Info->SystemIncludes.size();
417+
llvm::erase(Info->SystemIncludes, Path);
418+
vlog("System includes extractor: builtin headers {0} {1}", Path,
419+
(Info->SystemIncludes.size() != Size)
420+
? "excluded"
421+
: "not found in driver's response");
422+
}
419423
}
424+
break;
425+
}
426+
case Config::BuiltinHeaderPolicy::QueryDriver:
427+
vlog("System includes extractor: Using builtin headers from query driver.");
428+
break;
420429
}
421430

422431
log("System includes extractor: successfully executed {0}\n\tgot includes: "

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ Semantic Highlighting
5858
Compile flags
5959
^^^^^^^^^^^^^
6060

61+
- Added `BuiltinHeaders` config key which controls whether clangd's built-in
62+
headers are used or ones extracted from the driver.
63+
6164
Hover
6265
^^^^^
6366

@@ -112,7 +115,7 @@ Changes in existing checks
112115
<clang-tidy/checks/bugprone/unchecked-optional-access>` fixing false
113116
positives from smart pointer accessors repeated in checking ``has_value``
114117
and accessing ``value``. The option `IgnoreSmartPointerDereference` should
115-
no longer be needed and will be removed. Also fixing false positive from
118+
no longer be needed and will be removed. Also fixing false positive from
116119
const reference accessors to objects containing optional member.
117120

118121
- Improved :doc:`bugprone-unsafe-functions
@@ -128,14 +131,18 @@ Changes in existing checks
128131
- Improved :doc:`misc-redundant-expression
129132
<clang-tidy/checks/misc/redundant-expression>` check by providing additional
130133
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``.
131138

132139
- Improved :doc:`misc-use-internal-linkage
133140
<clang-tidy/checks/misc/use-internal-linkage>` check by fix false positives
134141
for function or variable in header file which contains macro expansion.
135142

136143
- Improved :doc:`performance/unnecessary-value-param
137144
<clang-tidy/checks/performance/unnecessary-value-param>` check performance by
138-
tolerating fix-it breaking compilation when functions is used as pointers
145+
tolerating fix-it breaking compilation when functions is used as pointers
139146
to avoid matching usage of functions within the current compilation unit.
140147

141148
- Improved :doc:`performance-move-const-arg

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/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

0 commit comments

Comments
 (0)