Skip to content

Commit 5a8a8ff

Browse files
authored
Merge branch 'main' into x86-immcost-icmp-eq64
2 parents ad26bbe + b2266d6 commit 5a8a8ff

File tree

437 files changed

+17460
-5087
lines changed

Some content is hidden

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

437 files changed

+17460
-5087
lines changed

clang-tools-extra/clang-tidy/altera/SingleWorkItemBarrierCheck.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ namespace clang::tidy::altera {
1616

1717
void SingleWorkItemBarrierCheck::registerMatchers(MatchFinder *Finder) {
1818
// Find any function that calls barrier but does not call an ID function.
19-
// hasAttr(attr::Kind::OpenCLKernel) restricts it to only kernel functions.
19+
// hasAttr(attr::Kind::DeviceKernel) restricts it to only kernel functions.
2020
// FIXME: Have it accept all functions but check for a parameter that gets an
2121
// ID from one of the four ID functions.
2222
Finder->addMatcher(
2323
// Find function declarations...
2424
functionDecl(
25-
// That are OpenCL kernels...
26-
hasAttr(attr::Kind::OpenCLKernel),
25+
// That are device kernels...
26+
hasAttr(attr::Kind::DeviceKernel),
2727
// And call a barrier function (either 1.x or 2.x version)...
2828
forEachDescendant(callExpr(callee(functionDecl(hasAnyName(
2929
"barrier", "work_group_barrier"))))

clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ using namespace clang::ast_matchers;
1616
namespace clang::tidy::readability {
1717

1818
void MathMissingParenthesesCheck::registerMatchers(MatchFinder *Finder) {
19-
Finder->addMatcher(binaryOperator(unless(hasParent(binaryOperator())),
20-
unless(isAssignmentOperator()),
21-
unless(isComparisonOperator()),
22-
unless(hasAnyOperatorName("&&", "||")),
23-
hasDescendant(binaryOperator()))
24-
.bind("binOp"),
25-
this);
19+
Finder->addMatcher(
20+
binaryOperator(
21+
unless(hasParent(binaryOperator(unless(isAssignmentOperator()),
22+
unless(isComparisonOperator())))),
23+
unless(isAssignmentOperator()), unless(isComparisonOperator()),
24+
unless(hasAnyOperatorName("&&", "||")),
25+
hasDescendant(binaryOperator()))
26+
.bind("binOp"),
27+
this);
2628
}
2729

2830
static int getPrecedence(const BinaryOperator *BinOp) {

clang-tools-extra/clangd/IncludeCleaner.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ bool mayConsiderUnused(const Inclusion &Inc, ParsedAST &AST,
117117

118118
std::vector<Diag> generateMissingIncludeDiagnostics(
119119
ParsedAST &AST, llvm::ArrayRef<MissingIncludeDiagInfo> MissingIncludes,
120-
llvm::StringRef Code, HeaderFilter IgnoreHeaders, const ThreadsafeFS &TFS) {
120+
llvm::StringRef Code, HeaderFilter IgnoreHeaders,
121+
HeaderFilter AngledHeaders, HeaderFilter QuotedHeaders,
122+
const ThreadsafeFS &TFS) {
121123
std::vector<Diag> Result;
122124
const SourceManager &SM = AST.getSourceManager();
123125
const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID());
@@ -141,7 +143,18 @@ std::vector<Diag> generateMissingIncludeDiagnostics(
141143
AST.getPreprocessor().getHeaderSearchInfo(), MainFile});
142144

143145
llvm::StringRef HeaderRef{Spelling};
146+
144147
bool Angled = HeaderRef.starts_with("<");
148+
if (SymbolWithMissingInclude.Providers.front().kind() ==
149+
include_cleaner::Header::Kind::Physical) {
150+
for (auto &Filter : Angled ? QuotedHeaders : AngledHeaders) {
151+
if (Filter(ResolvedPath)) {
152+
Angled = !Angled;
153+
break;
154+
}
155+
}
156+
}
157+
145158
// We might suggest insertion of an existing include in edge cases, e.g.,
146159
// include is present in a PP-disabled region, or spelling of the header
147160
// turns out to be the same as one of the unresolved includes in the
@@ -151,6 +164,11 @@ std::vector<Diag> generateMissingIncludeDiagnostics(
151164
if (!Replacement.has_value())
152165
continue;
153166

167+
if (Angled != (Spelling.front() == '<')) {
168+
Spelling.front() = Angled ? '<' : '"';
169+
Spelling.back() = Angled ? '>' : '"';
170+
}
171+
154172
Diag &D = Result.emplace_back();
155173
D.Message =
156174
llvm::formatv("No header providing \"{0}\" is directly included",
@@ -481,18 +499,19 @@ bool isPreferredProvider(const Inclusion &Inc,
481499
return false; // no header provides the symbol
482500
}
483501

484-
std::vector<Diag>
485-
issueIncludeCleanerDiagnostics(ParsedAST &AST, llvm::StringRef Code,
486-
const IncludeCleanerFindings &Findings,
487-
const ThreadsafeFS &TFS,
488-
HeaderFilter IgnoreHeaders) {
502+
std::vector<Diag> issueIncludeCleanerDiagnostics(
503+
ParsedAST &AST, llvm::StringRef Code,
504+
const IncludeCleanerFindings &Findings, const ThreadsafeFS &TFS,
505+
HeaderFilter IgnoreHeaders, HeaderFilter AngledHeaders,
506+
HeaderFilter QuotedHeaders) {
489507
trace::Span Tracer("IncludeCleaner::issueIncludeCleanerDiagnostics");
490508
std::vector<Diag> UnusedIncludes = generateUnusedIncludeDiagnostics(
491509
AST.tuPath(), Findings.UnusedIncludes, Code, IgnoreHeaders);
492510
std::optional<Fix> RemoveAllUnused = removeAllUnusedIncludes(UnusedIncludes);
493511

494512
std::vector<Diag> MissingIncludeDiags = generateMissingIncludeDiagnostics(
495-
AST, Findings.MissingIncludes, Code, IgnoreHeaders, TFS);
513+
AST, Findings.MissingIncludes, Code, IgnoreHeaders, AngledHeaders,
514+
QuotedHeaders, TFS);
496515
std::optional<Fix> AddAllMissing = addAllMissingIncludes(MissingIncludeDiags);
497516

498517
std::optional<Fix> FixAll;

clang-tools-extra/clangd/IncludeCleaner.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ IncludeCleanerFindings
5757
computeIncludeCleanerFindings(ParsedAST &AST,
5858
bool AnalyzeAngledIncludes = false);
5959

60-
std::vector<Diag>
61-
issueIncludeCleanerDiagnostics(ParsedAST &AST, llvm::StringRef Code,
62-
const IncludeCleanerFindings &Findings,
63-
const ThreadsafeFS &TFS,
64-
HeaderFilter IgnoreHeader = {});
60+
std::vector<Diag> issueIncludeCleanerDiagnostics(
61+
ParsedAST &AST, llvm::StringRef Code,
62+
const IncludeCleanerFindings &Findings, const ThreadsafeFS &TFS,
63+
HeaderFilter IgnoreHeader = {}, HeaderFilter AngledHeaders = {},
64+
HeaderFilter QuotedHeaders = {});
6565

6666
/// Converts the clangd include representation to include-cleaner
6767
/// include representation.

clang-tools-extra/clangd/ModulesBuilder.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,10 @@ class CachingProjectModules : public ProjectModules {
430430
/// Collect the directly and indirectly required module names for \param
431431
/// ModuleName in topological order. The \param ModuleName is guaranteed to
432432
/// be the last element in \param ModuleNames.
433-
llvm::SmallVector<StringRef> getAllRequiredModules(PathRef RequiredSource,
434-
CachingProjectModules &MDB,
435-
StringRef ModuleName) {
436-
llvm::SmallVector<llvm::StringRef> ModuleNames;
433+
llvm::SmallVector<std::string> getAllRequiredModules(PathRef RequiredSource,
434+
CachingProjectModules &MDB,
435+
StringRef ModuleName) {
436+
llvm::SmallVector<std::string> ModuleNames;
437437
llvm::StringSet<> ModuleNamesSet;
438438

439439
auto VisitDeps = [&](StringRef ModuleName, auto Visitor) -> void {
@@ -444,7 +444,7 @@ llvm::SmallVector<StringRef> getAllRequiredModules(PathRef RequiredSource,
444444
if (ModuleNamesSet.insert(RequiredModuleName).second)
445445
Visitor(RequiredModuleName, Visitor);
446446

447-
ModuleNames.push_back(ModuleName);
447+
ModuleNames.push_back(ModuleName.str());
448448
};
449449
VisitDeps(ModuleName, VisitDeps);
450450

@@ -494,28 +494,30 @@ llvm::Error ModulesBuilder::ModulesBuilderImpl::getOrBuildModuleFile(
494494
// Get Required modules in topological order.
495495
auto ReqModuleNames = getAllRequiredModules(RequiredSource, MDB, ModuleName);
496496
for (llvm::StringRef ReqModuleName : ReqModuleNames) {
497-
if (BuiltModuleFiles.isModuleUnitBuilt(ModuleName))
497+
if (BuiltModuleFiles.isModuleUnitBuilt(ReqModuleName))
498498
continue;
499499

500500
if (auto Cached = Cache.getModule(ReqModuleName)) {
501501
if (IsModuleFileUpToDate(Cached->getModuleFilePath(), BuiltModuleFiles,
502502
TFS.view(std::nullopt))) {
503-
log("Reusing module {0} from {1}", ModuleName,
503+
log("Reusing module {0} from {1}", ReqModuleName,
504504
Cached->getModuleFilePath());
505505
BuiltModuleFiles.addModuleFile(std::move(Cached));
506506
continue;
507507
}
508508
Cache.remove(ReqModuleName);
509509
}
510510

511+
std::string ReqFileName =
512+
MDB.getSourceForModuleName(ReqModuleName, RequiredSource);
511513
llvm::Expected<ModuleFile> MF = buildModuleFile(
512-
ModuleName, ModuleUnitFileName, getCDB(), TFS, BuiltModuleFiles);
514+
ReqModuleName, ReqFileName, getCDB(), TFS, BuiltModuleFiles);
513515
if (llvm::Error Err = MF.takeError())
514516
return Err;
515517

516-
log("Built module {0} to {1}", ModuleName, MF->getModuleFilePath());
518+
log("Built module {0} to {1}", ReqModuleName, MF->getModuleFilePath());
517519
auto BuiltModuleFile = std::make_shared<const ModuleFile>(std::move(*MF));
518-
Cache.add(ModuleName, BuiltModuleFile);
520+
Cache.add(ReqModuleName, BuiltModuleFile);
519521
BuiltModuleFiles.addModuleFile(std::move(BuiltModuleFile));
520522
}
521523

clang-tools-extra/clangd/ParsedAST.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,9 @@ std::vector<Diag> getIncludeCleanerDiags(ParsedAST &AST, llvm::StringRef Code,
381381
Findings.MissingIncludes.clear();
382382
if (SuppressUnused)
383383
Findings.UnusedIncludes.clear();
384-
return issueIncludeCleanerDiagnostics(AST, Code, Findings, TFS,
385-
Cfg.Diagnostics.Includes.IgnoreHeader);
384+
return issueIncludeCleanerDiagnostics(
385+
AST, Code, Findings, TFS, Cfg.Diagnostics.Includes.IgnoreHeader,
386+
Cfg.Style.AngledHeaders, Cfg.Style.QuotedHeaders);
386387
}
387388

388389
tidy::ClangTidyCheckFactories
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# A smoke test to check that a simple dependency chain for modules can work.
2+
#
3+
# FIXME: This fails on the Windows ARM64 build server. Not entirely sure why as it has been tested on
4+
# an ARM64 Windows VM and appears to work there.
5+
# UNSUPPORTED: host=aarch64-pc-windows-msvc
6+
#
7+
# RUN: rm -fr %t
8+
# RUN: mkdir -p %t
9+
# RUN: split-file %s %t
10+
#
11+
# RUN: sed -e "s|DIR|%/t|g" %t/compile_commands.json.tmpl > %t/compile_commands.json.tmp
12+
# RUN: sed -e "s|CLANG_CC|%clang|g" %t/compile_commands.json.tmp > %t/compile_commands.json
13+
# RUN: sed -e "s|DIR|%/t|g" %t/definition.jsonrpc.tmpl > %t/definition.jsonrpc.tmp
14+
#
15+
# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
16+
# (with the extra slash in the front), so we add it here.
17+
# RUN: sed -E -e 's|"file://([A-Z]):/|"file:///\1:/|g' %/t/definition.jsonrpc.tmp > %/t/definition.jsonrpc
18+
#
19+
# RUN: clangd -experimental-modules-support -lit-test < %t/definition.jsonrpc \
20+
# RUN: | FileCheck -strict-whitespace %t/definition.jsonrpc
21+
22+
#--- A-frag.cppm
23+
export module A:frag;
24+
export void printA() {}
25+
26+
#--- A.cppm
27+
export module A;
28+
export import :frag;
29+
30+
#--- Use.cpp
31+
import A;
32+
void foo() {
33+
print
34+
}
35+
36+
#--- compile_commands.json.tmpl
37+
[
38+
{
39+
"directory": "DIR",
40+
"command": "CLANG_CC -fprebuilt-module-path=DIR -std=c++20 -o DIR/main.cpp.o -c DIR/Use.cpp",
41+
"file": "DIR/Use.cpp"
42+
},
43+
{
44+
"directory": "DIR",
45+
"command": "CLANG_CC -std=c++20 DIR/A.cppm --precompile -o DIR/A.pcm",
46+
"file": "DIR/A.cppm"
47+
},
48+
{
49+
"directory": "DIR",
50+
"command": "CLANG_CC -std=c++20 DIR/A-frag.cppm --precompile -o DIR/A-frag.pcm",
51+
"file": "DIR/A-frag.cppm"
52+
}
53+
]
54+
55+
#--- definition.jsonrpc.tmpl
56+
{
57+
"jsonrpc": "2.0",
58+
"id": 0,
59+
"method": "initialize",
60+
"params": {
61+
"processId": 123,
62+
"rootPath": "clangd",
63+
"capabilities": {
64+
"textDocument": {
65+
"completion": {
66+
"completionItem": {
67+
"snippetSupport": true
68+
}
69+
}
70+
}
71+
},
72+
"trace": "off"
73+
}
74+
}
75+
---
76+
{
77+
"jsonrpc": "2.0",
78+
"method": "textDocument/didOpen",
79+
"params": {
80+
"textDocument": {
81+
"uri": "file://DIR/Use.cpp",
82+
"languageId": "cpp",
83+
"version": 1,
84+
"text": "import A;\nvoid foo() {\n print\n}\n"
85+
}
86+
}
87+
}
88+
89+
# CHECK: "message"{{.*}}printA{{.*}}(fix available)
90+
91+
---
92+
{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file://DIR/Use.cpp"},"context":{"triggerKind":1},"position":{"line":2,"character":6}}}
93+
---
94+
{"jsonrpc":"2.0","id":2,"method":"shutdown"}
95+
---
96+
{"jsonrpc":"2.0","method":"exit"}

clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,16 @@ TEST(IncludeCleaner, ComputeMissingHeaders) {
220220
TEST(IncludeCleaner, GenerateMissingHeaderDiags) {
221221
Annotations MainFile(R"cpp(
222222
#include "a.h"
223+
#include "angled_wrapper.h"
223224
#include "all.h"
224225
$insert_b[[]]#include "baz.h"
225226
#include "dir/c.h"
226227
$insert_d[[]]$insert_foo[[]]#include "fuzz.h"
227228
#include "header.h"
228-
$insert_foobar[[]]#include <e.h>
229-
$insert_f[[]]$insert_vector[[]]
229+
$insert_foobar[[]]$insert_quoted[[]]$insert_quoted2[[]]#include "quoted_wrapper.h"
230+
$insert_angled[[]]#include <e.h>
231+
$insert_f[[]]#include <quoted2_wrapper.h>
232+
$insert_vector[[]]
230233
231234
#define DEF(X) const Foo *X;
232235
#define BAZ(X) const X x
@@ -237,6 +240,9 @@ TEST(IncludeCleaner, GenerateMissingHeaderDiags) {
237240
238241
void foo() {
239242
$b[[b]]();
243+
$angled[[angled]]();
244+
$quoted[[quoted]]();
245+
$quoted2[[quoted2]]();
240246
241247
ns::$bar[[Bar]] bar;
242248
bar.d();
@@ -263,12 +269,22 @@ TEST(IncludeCleaner, GenerateMissingHeaderDiags) {
263269
TU.AdditionalFiles["a.h"] = guard("#include \"b.h\"");
264270
TU.AdditionalFiles["b.h"] = guard("void b();");
265271

272+
TU.AdditionalFiles["angled_wrapper.h"] = guard("#include <angled.h>");
273+
TU.AdditionalFiles["angled.h"] = guard("void angled();");
274+
TU.ExtraArgs.push_back("-I" + testPath("."));
275+
276+
TU.AdditionalFiles["quoted_wrapper.h"] = guard("#include \"quoted.h\"");
277+
TU.AdditionalFiles["quoted.h"] = guard("void quoted();");
278+
266279
TU.AdditionalFiles["dir/c.h"] = guard("#include \"d.h\"");
267280
TU.AdditionalFiles["dir/d.h"] =
268281
guard("namespace ns { struct Bar { void d(); }; }");
269282

270283
TU.AdditionalFiles["system/e.h"] = guard("#include <f.h>");
271284
TU.AdditionalFiles["system/f.h"] = guard("void f();");
285+
TU.AdditionalFiles["system/quoted2_wrapper.h"] =
286+
guard("#include <system/quoted2.h>");
287+
TU.AdditionalFiles["system/quoted2.h"] = guard("void quoted2();");
272288
TU.ExtraArgs.push_back("-isystem" + testPath("system"));
273289

274290
TU.AdditionalFiles["fuzz.h"] = guard("#include \"buzz.h\"");
@@ -297,7 +313,15 @@ TEST(IncludeCleaner, GenerateMissingHeaderDiags) {
297313
Findings.UnusedIncludes.clear();
298314
std::vector<clangd::Diag> Diags = issueIncludeCleanerDiagnostics(
299315
AST, TU.Code, Findings, MockFS(),
300-
{[](llvm::StringRef Header) { return Header.ends_with("buzz.h"); }});
316+
/*IgnoreHeaders=*/{[](llvm::StringRef Header) {
317+
return Header.ends_with("buzz.h");
318+
}},
319+
/*AngledHeaders=*/{[](llvm::StringRef Header) {
320+
return Header.contains("angled.h");
321+
}},
322+
/*QuotedHeaders=*/{[](llvm::StringRef Header) {
323+
return Header.contains("quoted.h") || Header.contains("quoted2.h");
324+
}});
301325
EXPECT_THAT(
302326
Diags,
303327
UnorderedElementsAre(
@@ -306,6 +330,23 @@ TEST(IncludeCleaner, GenerateMissingHeaderDiags) {
306330
withFix({Fix(MainFile.range("insert_b"), "#include \"b.h\"\n",
307331
"#include \"b.h\""),
308332
FixMessage("add all missing includes")})),
333+
AllOf(Diag(MainFile.range("angled"),
334+
"No header providing \"angled\" is directly included"),
335+
withFix({Fix(MainFile.range("insert_angled"),
336+
"#include <angled.h>\n", "#include <angled.h>"),
337+
FixMessage("add all missing includes")})),
338+
AllOf(
339+
Diag(MainFile.range("quoted"),
340+
"No header providing \"quoted\" is directly included"),
341+
withFix({Fix(MainFile.range("insert_quoted"),
342+
"#include \"quoted.h\"\n", "#include \"quoted.h\""),
343+
FixMessage("add all missing includes")})),
344+
AllOf(Diag(MainFile.range("quoted2"),
345+
"No header providing \"quoted2\" is directly included"),
346+
withFix(
347+
{Fix(MainFile.range("insert_quoted2"),
348+
"#include \"quoted2.h\"\n", "#include \"quoted2.h\""),
349+
FixMessage("add all missing includes")})),
309350
AllOf(Diag(MainFile.range("bar"),
310351
"No header providing \"ns::Bar\" is directly included"),
311352
withFix({Fix(MainFile.range("insert_d"),

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ Changes in existing checks
245245
tolerating fix-it breaking compilation when functions is used as pointers
246246
to avoid matching usage of functions within the current compilation unit.
247247

248+
- Improved :doc:`readability-math-missing-parentheses
249+
<clang-tidy/checks/readability/math-missing-parentheses>` check by fixing
250+
false negatives where math expressions are the operand of assignment operators
251+
or comparison operators.
252+
248253
- Improved :doc:`readability-qualified-auto
249254
<clang-tidy/checks/readability/qualified-auto>` check by adding the option
250255
`AllowedTypes`, that excludes specified types from adding qualifiers.

0 commit comments

Comments
 (0)