Skip to content

Commit 197e1be

Browse files
author
iclsrc
committed
Merge from 'main' to 'sycl-web' (111 commits)
2 parents 15938cb + 7075f38 commit 197e1be

File tree

475 files changed

+137021
-142242
lines changed

Some content is hidden

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

475 files changed

+137021
-142242
lines changed

clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ namespace {
2525

2626
AST_MATCHER(EnumDecl, hasEnumerators) { return !Node.enumerators().empty(); }
2727

28+
AST_MATCHER(EnumDecl, isExternC) {
29+
return Node.getDeclContext()->isExternCContext();
30+
}
31+
32+
AST_MATCHER_P(EnumDecl, hasTypedefNameForAnonDecl,
33+
ast_matchers::internal::Matcher<NamedDecl>, InnerMatcher) {
34+
if (const TypedefNameDecl *TD = Node.getTypedefNameForAnonDecl())
35+
return InnerMatcher.matches(*TD, Finder, Builder);
36+
return false;
37+
}
38+
2839
const std::uint64_t Min8 =
2940
std::imaxabs(std::numeric_limits<std::int8_t>::min());
3041
const std::uint64_t Max8 = std::numeric_limits<std::int8_t>::max();
@@ -90,8 +101,11 @@ bool EnumSizeCheck::isLanguageVersionSupported(
90101
void EnumSizeCheck::registerMatchers(MatchFinder *Finder) {
91102
Finder->addMatcher(
92103
enumDecl(unless(isExpansionInSystemHeader()), isDefinition(),
93-
hasEnumerators(),
94-
unless(matchers::matchesAnyListedRegexName(EnumIgnoreList)))
104+
hasEnumerators(), unless(isExternC()),
105+
unless(anyOf(
106+
matchers::matchesAnyListedRegexName(EnumIgnoreList),
107+
hasTypedefNameForAnonDecl(
108+
matchers::matchesAnyListedRegexName(EnumIgnoreList)))))
95109
.bind("e"),
96110
this);
97111
}

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ void NonConstParameterCheck::registerMatchers(MatchFinder *Finder) {
2626
Finder->addMatcher(declRefExpr().bind("Ref"), this);
2727

2828
// Analyse parameter usage in function.
29-
Finder->addMatcher(stmt(anyOf(unaryOperator(hasAnyOperatorName("++", "--")),
30-
binaryOperator(), callExpr(), returnStmt(),
31-
cxxConstructExpr()))
32-
.bind("Mark"),
33-
this);
29+
Finder->addMatcher(
30+
stmt(anyOf(unaryOperator(hasAnyOperatorName("++", "--")),
31+
binaryOperator(), callExpr(), returnStmt(), cxxConstructExpr(),
32+
cxxUnresolvedConstructExpr()))
33+
.bind("Mark"),
34+
this);
3435
Finder->addMatcher(varDecl(hasInitializer(anything())).bind("Mark"), this);
3536
}
3637

@@ -93,6 +94,9 @@ void NonConstParameterCheck::check(const MatchFinder::MatchResult &Result) {
9394
markCanNotBeConst(Arg->IgnoreParenCasts(), false);
9495
}
9596
}
97+
} else if (const auto *CE = dyn_cast<CXXUnresolvedConstructExpr>(S)) {
98+
for (const auto *Arg : CE->arguments())
99+
markCanNotBeConst(Arg->IgnoreParenCasts(), true);
96100
} else if (const auto *R = dyn_cast<ReturnStmt>(S)) {
97101
markCanNotBeConst(R->getRetValue(), true);
98102
} else if (const auto *U = dyn_cast<UnaryOperator>(S)) {

clang-tools-extra/clangd/index/Background.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,7 @@ llvm::Error BackgroundIndex::index(tooling::CompileCommand Cmd) {
309309

310310
IndexFileIn Index;
311311
auto Action = createStaticIndexingAction(
312-
IndexOpts, [&](SymbolSlab S) { Index.Symbols = std::move(S); },
313-
[&](RefSlab R) { Index.Refs = std::move(R); },
314-
[&](RelationSlab R) { Index.Relations = std::move(R); },
315-
[&](IncludeGraph IG) { Index.Sources = std::move(IG); });
312+
IndexOpts, [&](IndexFileIn Result) { Index = std::move(Result); });
316313

317314
// We're going to run clang here, and it could potentially crash.
318315
// We could use CrashRecoveryContext to try to make indexing crashes nonfatal,

clang-tools-extra/clangd/index/IndexAction.cpp

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "Headers.h"
1212
#include "clang-include-cleaner/Record.h"
1313
#include "index/Relation.h"
14+
#include "index/Serialization.h"
1415
#include "index/SymbolCollector.h"
1516
#include "index/SymbolOrigin.h"
1617
#include "clang/AST/ASTConsumer.h"
@@ -130,13 +131,8 @@ class IndexAction : public ASTFrontendAction {
130131
IndexAction(std::shared_ptr<SymbolCollector> C,
131132
std::unique_ptr<include_cleaner::PragmaIncludes> PI,
132133
const index::IndexingOptions &Opts,
133-
std::function<void(SymbolSlab)> SymbolsCallback,
134-
std::function<void(RefSlab)> RefsCallback,
135-
std::function<void(RelationSlab)> RelationsCallback,
136-
std::function<void(IncludeGraph)> IncludeGraphCallback)
137-
: SymbolsCallback(SymbolsCallback), RefsCallback(RefsCallback),
138-
RelationsCallback(RelationsCallback),
139-
IncludeGraphCallback(IncludeGraphCallback), Collector(C),
134+
std::function<void(IndexFileIn)> IndexContentsCallback)
135+
: IndexContentsCallback(IndexContentsCallback), Collector(C),
140136
PI(std::move(PI)), Opts(Opts) {
141137
this->Opts.ShouldTraverseDecl = [this](const Decl *D) {
142138
// Many operations performed during indexing is linear in terms of depth
@@ -161,9 +157,8 @@ class IndexAction : public ASTFrontendAction {
161157
std::unique_ptr<ASTConsumer>
162158
CreateASTConsumer(CompilerInstance &CI, llvm::StringRef InFile) override {
163159
PI->record(CI.getPreprocessor());
164-
if (IncludeGraphCallback != nullptr)
165-
CI.getPreprocessor().addPPCallbacks(
166-
std::make_unique<IncludeGraphCollector>(CI.getSourceManager(), IG));
160+
CI.getPreprocessor().addPPCallbacks(
161+
std::make_unique<IncludeGraphCollector>(CI.getSourceManager(), IG));
167162

168163
return index::createIndexingASTConsumer(Collector, Opts,
169164
CI.getPreprocessorPtr());
@@ -185,26 +180,21 @@ class IndexAction : public ASTFrontendAction {
185180
}
186181

187182
void EndSourceFileAction() override {
188-
SymbolsCallback(Collector->takeSymbols());
189-
if (RefsCallback != nullptr)
190-
RefsCallback(Collector->takeRefs());
191-
if (RelationsCallback != nullptr)
192-
RelationsCallback(Collector->takeRelations());
193-
if (IncludeGraphCallback != nullptr) {
183+
IndexFileIn Result;
184+
Result.Symbols = Collector->takeSymbols();
185+
Result.Refs = Collector->takeRefs();
186+
Result.Relations = Collector->takeRelations();
194187
#ifndef NDEBUG
195188
// This checks if all nodes are initialized.
196189
for (const auto &Node : IG)
197190
assert(Node.getKeyData() == Node.getValue().URI.data());
198191
#endif
199-
IncludeGraphCallback(std::move(IG));
200-
}
192+
Result.Sources = std::move(IG);
193+
IndexContentsCallback(std::move(Result));
201194
}
202195

203196
private:
204-
std::function<void(SymbolSlab)> SymbolsCallback;
205-
std::function<void(RefSlab)> RefsCallback;
206-
std::function<void(RelationSlab)> RelationsCallback;
207-
std::function<void(IncludeGraph)> IncludeGraphCallback;
197+
std::function<void(IndexFileIn)> IndexContentsCallback;
208198
std::shared_ptr<SymbolCollector> Collector;
209199
std::unique_ptr<include_cleaner::PragmaIncludes> PI;
210200
index::IndexingOptions Opts;
@@ -215,10 +205,7 @@ class IndexAction : public ASTFrontendAction {
215205

216206
std::unique_ptr<FrontendAction> createStaticIndexingAction(
217207
SymbolCollector::Options Opts,
218-
std::function<void(SymbolSlab)> SymbolsCallback,
219-
std::function<void(RefSlab)> RefsCallback,
220-
std::function<void(RelationSlab)> RelationsCallback,
221-
std::function<void(IncludeGraph)> IncludeGraphCallback) {
208+
std::function<void(IndexFileIn)> IndexContentsCallback) {
222209
index::IndexingOptions IndexOpts;
223210
IndexOpts.SystemSymbolFilter =
224211
index::IndexingOptions::SystemSymbolFilterKind::All;
@@ -231,16 +218,13 @@ std::unique_ptr<FrontendAction> createStaticIndexingAction(
231218
if (Opts.Origin == SymbolOrigin::Unknown)
232219
Opts.Origin = SymbolOrigin::Static;
233220
Opts.StoreAllDocumentation = false;
234-
if (RefsCallback != nullptr) {
235-
Opts.RefFilter = RefKind::All;
236-
Opts.RefsInHeaders = true;
237-
}
221+
Opts.RefFilter = RefKind::All;
222+
Opts.RefsInHeaders = true;
238223
auto PragmaIncludes = std::make_unique<include_cleaner::PragmaIncludes>();
239224
Opts.PragmaIncludes = PragmaIncludes.get();
240225
return std::make_unique<IndexAction>(std::make_shared<SymbolCollector>(Opts),
241226
std::move(PragmaIncludes), IndexOpts,
242-
SymbolsCallback, RefsCallback,
243-
RelationsCallback, IncludeGraphCallback);
227+
IndexContentsCallback);
244228
}
245229

246230
} // namespace clangd

clang-tools-extra/clangd/index/IndexAction.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88

99
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEXACTION_H
1010
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEXACTION_H
11-
#include "Headers.h"
1211
#include "index/SymbolCollector.h"
1312
#include "clang/Frontend/FrontendAction.h"
1413

1514
namespace clang {
1615
namespace clangd {
1716

17+
struct IndexFileIn;
18+
1819
// Creates an action that indexes translation units and delivers the results
19-
// for SymbolsCallback (each slab corresponds to one TU).
20+
// for IndexContentsCallback (each call corresponds to one TU).
2021
//
2122
// Only a subset of SymbolCollector::Options are respected:
2223
// - include paths are always collected, and canonicalized appropriately
@@ -25,10 +26,7 @@ namespace clangd {
2526
// - the symbol origin is set to Static if not specified by caller
2627
std::unique_ptr<FrontendAction> createStaticIndexingAction(
2728
SymbolCollector::Options Opts,
28-
std::function<void(SymbolSlab)> SymbolsCallback,
29-
std::function<void(RefSlab)> RefsCallback,
30-
std::function<void(RelationSlab)> RelationsCallback,
31-
std::function<void(IncludeGraph)> IncludeGraphCallback);
29+
std::function<void(IndexFileIn)> IndexContentsCallback);
3230

3331
} // namespace clangd
3432
} // namespace clang

clang-tools-extra/clangd/indexer/IndexerMain.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,33 +65,33 @@ class IndexActionFactory : public tooling::FrontendActionFactory {
6565
std::lock_guard<std::mutex> Lock(FilesMu);
6666
return Files.insert(*AbsPath).second; // Skip already processed files.
6767
};
68-
return createStaticIndexingAction(
69-
Opts,
70-
[&](SymbolSlab S) {
71-
// Merge as we go.
72-
std::lock_guard<std::mutex> Lock(SymbolsMu);
73-
for (const auto &Sym : S) {
74-
if (const auto *Existing = Symbols.find(Sym.ID))
75-
Symbols.insert(mergeSymbol(*Existing, Sym));
76-
else
77-
Symbols.insert(Sym);
78-
}
79-
},
80-
[&](RefSlab S) {
81-
std::lock_guard<std::mutex> Lock(RefsMu);
82-
for (const auto &Sym : S) {
83-
// Deduplication happens during insertion.
84-
for (const auto &Ref : Sym.second)
85-
Refs.insert(Sym.first, Ref);
86-
}
87-
},
88-
[&](RelationSlab S) {
89-
std::lock_guard<std::mutex> Lock(RelsMu);
90-
for (const auto &R : S) {
91-
Relations.insert(R);
92-
}
93-
},
94-
/*IncludeGraphCallback=*/nullptr);
68+
return createStaticIndexingAction(Opts, [&](IndexFileIn Result) {
69+
{
70+
// Merge as we go.
71+
std::lock_guard<std::mutex> Lock(SymbolsMu);
72+
for (const auto &Sym : *Result.Symbols) {
73+
if (const auto *Existing = Symbols.find(Sym.ID))
74+
Symbols.insert(mergeSymbol(*Existing, Sym));
75+
else
76+
Symbols.insert(Sym);
77+
}
78+
}
79+
{
80+
std::lock_guard<std::mutex> Lock(RefsMu);
81+
for (const auto &Sym : *Result.Refs) {
82+
// Deduplication happens during insertion.
83+
for (const auto &Ref : Sym.second)
84+
Refs.insert(Sym.first, Ref);
85+
}
86+
}
87+
{
88+
std::lock_guard<std::mutex> Lock(RelsMu);
89+
for (const auto &R : *Result.Relations) {
90+
Relations.insert(R);
91+
}
92+
}
93+
// FIXME: Handle Result.Sources?
94+
});
9595
}
9696

9797
bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ class IndexActionTest : public ::testing::Test {
8686
new FileManager(FileSystemOptions(), InMemoryFileSystem));
8787

8888
auto Action = createStaticIndexingAction(
89-
Opts, [&](SymbolSlab S) { IndexFile.Symbols = std::move(S); },
90-
[&](RefSlab R) { IndexFile.Refs = std::move(R); },
91-
[&](RelationSlab R) { IndexFile.Relations = std::move(R); },
92-
[&](IncludeGraph IG) { IndexFile.Sources = std::move(IG); });
89+
Opts, [&](IndexFileIn Result) { IndexFile = std::move(Result); });
9390

9491
std::vector<std::string> Args = {"index_action", "-fsyntax-only",
9592
"-xc++", "-std=c++11",

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ Changes in existing checks
155155
<clang-tidy/checks/modernize/use-using>` check by avoiding the generation
156156
of invalid code for function types with redundant parentheses.
157157

158+
- Improved :doc:`performance-enum-size
159+
<clang-tidy/checks/performance/enum-size>` check:
160+
161+
- Exclude ``enum`` in ``extern "C"`` blocks.
162+
163+
- Improved the ignore list to correctly handle ``typedef`` and ``enum``.
164+
158165
- Improved :doc:`performance-move-const-arg
159166
<clang-tidy/checks/performance/move-const-arg>` check by avoiding false
160167
positives on trivially copyable types with a non-public copy constructor.
@@ -164,6 +171,10 @@ Changes in existing checks
164171
now uses separate note diagnostics for each uninitialized enumerator, making
165172
it easier to see which specific enumerators need explicit initialization.
166173

174+
- Improved :doc:`readability-non-const-parameter
175+
<clang-tidy/checks/readability/non-const-parameter>` check by avoiding false
176+
positives on parameters used in dependent expressions.
177+
167178
Removed checks
168179
^^^^^^^^^^^^^^
169180

clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %check_clang_tidy -std=c++17-or-later %s performance-enum-size %t -- \
2-
// RUN: -config="{CheckOptions: {performance-enum-size.EnumIgnoreList: '::IgnoredEnum;IgnoredSecondEnum'}}"
2+
// RUN: -config="{CheckOptions: {performance-enum-size.EnumIgnoreList: '::IgnoredEnum;IgnoredSecondEnum;IgnoredTypedefEnum'}}"
33

44
namespace std
55
{
@@ -106,3 +106,15 @@ enum class EnumClassWithoutValues : int {};
106106
enum EnumWithoutValues {};
107107

108108
}
109+
110+
extern "C" {
111+
enum ExternCEnum {
112+
ec1,
113+
ec2
114+
};
115+
116+
typedef enum {
117+
tec1,
118+
tec2
119+
} IgnoredTypedefEnum;
120+
} // extern "C"

clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,25 @@ void constructLVRef(int *p) {
341341
// CHECK-MESSAGES-NOT: warning: pointer parameter 'p' can be
342342
Temp1 t(*p);
343343
}
344+
345+
template<bool>
346+
class A final {
347+
char* sz_ = {};
348+
349+
public:
350+
explicit A(char* sz) noexcept : sz_(sz) {}
351+
void f() { sz_ = {}; }
352+
};
353+
354+
class B final {
355+
char* sz_ = {};
356+
357+
public:
358+
explicit B(char* sz) noexcept : sz_(sz) {}
359+
void f() { sz_ = {}; }
360+
};
361+
362+
void gh176623() {
363+
auto const V1 = []<bool tc>(char* p) { auto X = A<tc>(p); };
364+
auto const V2 = []<bool tc>(char* p) { auto Y = B(p); };
365+
}

0 commit comments

Comments
 (0)