Skip to content

Commit a3173a8

Browse files
committed
Merge from 'main' to 'sycl-web' (186 commits)
CONFLICT (content): Merge conflict in llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
2 parents 1e0ff5e + 9727c77 commit a3173a8

File tree

587 files changed

+15200
-7961
lines changed

Some content is hidden

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

587 files changed

+15200
-7961
lines changed

bolt/CMakeLists.txt

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,31 @@ architecture for use in BOLT tests")
1616

1717
set(BOLT_INCLUDE_TESTS OFF)
1818
if (LLVM_INCLUDE_TESTS)
19+
set(BOLT_CLANG_PRESENT OFF)
20+
set(BOLT_LLD_PRESENT OFF)
21+
22+
if ("clang" IN_LIST LLVM_ENABLE_PROJECTS AND BOLT_CLANG_EXE)
23+
message(WARNING "BOLT_CLANG_EXE is set and clang project is enabled. \
24+
BOLT_CLANG_EXE will be used for BOLT tests.")
25+
endif()
1926
if ("clang" IN_LIST LLVM_ENABLE_PROJECTS OR BOLT_CLANG_EXE)
20-
if ("clang" IN_LIST LLVM_ENABLE_PROJECTS AND BOLT_CLANG_EXE)
21-
message(WARNING "BOLT_CLANG_EXE is set and clang project is enabled. \
22-
BOLT_CLANG_EXE will be used for BOLT tests.")
23-
endif()
24-
if ("lld" IN_LIST LLVM_ENABLE_PROJECTS OR BOLT_LLD_EXE)
25-
if ("lld" IN_LIST LLVM_ENABLE_PROJECTS AND BOLT_LLD_EXE)
26-
message(WARNING "BOLT_LLD_EXE is set and lld project is enabled. \
27-
BOLT_LLD_EXE will be used for BOLT tests.")
28-
endif()
29-
set(BOLT_INCLUDE_TESTS ON)
30-
else()
31-
message(WARNING "Not including BOLT tests since lld is disabled. \
32-
Enable lld in LLVM_ENABLE_PROJECTS or provide a path to lld binary \
33-
in BOLT_LLD_EXE.")
34-
endif()
27+
set(BOLT_CLANG_PRESENT ON)
28+
endif()
29+
30+
if ("lld" IN_LIST LLVM_ENABLE_PROJECTS AND BOLT_LLD_EXE)
31+
message(WARNING "BOLT_LLD_EXE is set and lld project is enabled. \
32+
BOLT_LLD_EXE will be used for BOLT tests.")
33+
endif()
34+
if ("lld" IN_LIST LLVM_ENABLE_PROJECTS OR BOLT_LLD_EXE)
35+
set(BOLT_LLD_PRESENT ON)
36+
endif()
37+
38+
if (BOLT_CLANG_PRESENT AND BOLT_LLD_PRESENT)
39+
set(BOLT_INCLUDE_TESTS ON)
3540
else()
36-
message(WARNING "Not including BOLT tests since clang is disabled. \
37-
Enable clang in LLVM_ENABLE_PROJECTS or provide a path to clang \
38-
binary in BOLT_CLANG_EXE.")
41+
message(WARNING "Not including BOLT tests since clang or lld is disabled. \
42+
Add clang and lld to LLVM_ENABLE_PROJECTS or provide paths to clang \
43+
and lld binaries in BOLT_CLANG_EXE and BOLT_LLD_EXE.")
3944
endif()
4045
endif()
4146

clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ struct FileState {
121121
SourceLocation LastMacroLocation;
122122
};
123123

124+
} // namespace
125+
124126
class MacroToEnumCallbacks : public PPCallbacks {
125127
public:
126128
MacroToEnumCallbacks(MacroToEnumCheck *Check, const LangOptions &LangOptions,
@@ -197,6 +199,8 @@ class MacroToEnumCallbacks : public PPCallbacks {
197199
// After we've seen everything, issue warnings and fix-its.
198200
void EndOfMainFile() override;
199201

202+
void invalidateRange(SourceRange Range);
203+
200204
private:
201205
void newEnum() {
202206
if (Enums.empty() || !Enums.back().empty())
@@ -224,6 +228,7 @@ class MacroToEnumCallbacks : public PPCallbacks {
224228
void checkName(const Token &MacroNameTok);
225229
void rememberExpressionName(const Token &MacroNameTok);
226230
void invalidateExpressionNames();
231+
void issueDiagnostics();
227232
void warnMacroEnum(const EnumMacro &Macro) const;
228233
void fixEnumMacro(const MacroList &MacroList) const;
229234

@@ -472,8 +477,20 @@ void MacroToEnumCallbacks::invalidateExpressionNames() {
472477
}
473478

474479
void MacroToEnumCallbacks::EndOfMainFile() {
475-
invalidateExpressionNames();
480+
invalidateExpressionNames();
481+
issueDiagnostics();
482+
}
476483

484+
void MacroToEnumCallbacks::invalidateRange(SourceRange Range) {
485+
llvm::erase_if(Enums, [Range](const MacroList &MacroList) {
486+
return llvm::any_of(MacroList, [Range](const EnumMacro &Macro) {
487+
return Macro.Directive->getLocation() >= Range.getBegin() &&
488+
Macro.Directive->getLocation() <= Range.getEnd();
489+
});
490+
});
491+
}
492+
493+
void MacroToEnumCallbacks::issueDiagnostics() {
477494
for (const MacroList &MacroList : Enums) {
478495
if (MacroList.empty())
479496
continue;
@@ -530,13 +547,43 @@ void MacroToEnumCallbacks::fixEnumMacro(const MacroList &MacroList) const {
530547
Diagnostic << FixItHint::CreateInsertion(End, "};\n");
531548
}
532549

533-
} // namespace
534-
535550
void MacroToEnumCheck::registerPPCallbacks(const SourceManager &SM,
536551
Preprocessor *PP,
537552
Preprocessor *ModuleExpanderPP) {
538-
PP->addPPCallbacks(
539-
std::make_unique<MacroToEnumCallbacks>(this, getLangOpts(), SM));
553+
auto Callback = std::make_unique<MacroToEnumCallbacks>(this, getLangOpts(), SM);
554+
PPCallback = Callback.get();
555+
PP->addPPCallbacks(std::move(Callback));
556+
}
557+
558+
void MacroToEnumCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
559+
using namespace ast_matchers;
560+
auto TopLevelDecl = hasParent(translationUnitDecl());
561+
Finder->addMatcher(decl(TopLevelDecl).bind("top"), this);
562+
}
563+
564+
static bool isValid(SourceRange Range) {
565+
return Range.getBegin().isValid() && Range.getEnd().isValid();
566+
}
567+
568+
static bool empty(SourceRange Range) {
569+
return Range.getBegin() == Range.getEnd();
570+
}
571+
572+
void MacroToEnumCheck::check(
573+
const ast_matchers::MatchFinder::MatchResult &Result) {
574+
auto *TLDecl = Result.Nodes.getNodeAs<Decl>("top");
575+
if (TLDecl == nullptr)
576+
return;
577+
578+
SourceRange Range = TLDecl->getSourceRange();
579+
if (auto *TemplateFn = Result.Nodes.getNodeAs<FunctionTemplateDecl>("top")) {
580+
if (TemplateFn->isThisDeclarationADefinition() && TemplateFn->hasBody())
581+
Range = SourceRange{TemplateFn->getBeginLoc(),
582+
TemplateFn->getUnderlyingDecl()->getBodyRBrace()};
583+
}
584+
585+
if (isValid(Range) && !empty(Range))
586+
PPCallback->invalidateRange(Range);
540587
}
541588

542589
} // namespace modernize

clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace clang {
1515
namespace tidy {
1616
namespace modernize {
1717

18+
class MacroToEnumCallbacks;
19+
1820
/// Replaces groups of related macros with an unscoped anonymous enum.
1921
///
2022
/// For the user-facing documentation see:
@@ -25,6 +27,11 @@ class MacroToEnumCheck : public ClangTidyCheck {
2527
: ClangTidyCheck(Name, Context) {}
2628
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
2729
Preprocessor *ModuleExpanderPP) override;
30+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
31+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
32+
33+
private:
34+
MacroToEnumCallbacks *PPCallback{};
2835
};
2936

3037
} // namespace modernize

clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,14 @@ def strtobool(val):
7373

7474
def find_compilation_database(path):
7575
"""Adjusts the directory until a compilation database is found."""
76-
result = './'
76+
result = os.path.realpath('./')
7777
while not os.path.isfile(os.path.join(result, path)):
78-
if os.path.realpath(result) == '/':
78+
parent = os.path.dirname(result)
79+
if result == parent:
7980
print('Error: could not find compilation database.')
8081
sys.exit(1)
81-
result += '../'
82-
return os.path.realpath(result)
82+
result = parent
83+
return result
8384

8485

8586
def make_absolute(f, directory):

clang-tools-extra/clangd/Selection.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "llvm/Support/Casting.h"
3131
#include "llvm/Support/raw_ostream.h"
3232
#include <algorithm>
33+
#include <set>
3334
#include <string>
3435

3536
namespace clang {

clang-tools-extra/clangd/index/dex/Dex.cpp

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@
1313
#include "URI.h"
1414
#include "index/Index.h"
1515
#include "index/dex/Iterator.h"
16+
#include "index/dex/Token.h"
1617
#include "index/dex/Trigram.h"
1718
#include "support/Logger.h"
1819
#include "support/Trace.h"
20+
#include "llvm/ADT/DenseMap.h"
21+
#include "llvm/ADT/StringMap.h"
1922
#include "llvm/ADT/StringSet.h"
2023
#include "llvm/Support/Path.h"
2124
#include "llvm/Support/ScopedPrinter.h"
2225
#include <algorithm>
2326
#include <queue>
27+
#include <utility>
28+
#include <vector>
2429

2530
namespace clang {
2631
namespace clangd {
@@ -76,23 +81,38 @@ class IndexBuilder {
7681
}
7782

7883
// Assemble the final compressed posting lists for the added symbols.
79-
llvm::DenseMap<Token, PostingList> build() {
84+
llvm::DenseMap<Token, PostingList> build() && {
8085
llvm::DenseMap<Token, PostingList> Result(/*InitialReserve=*/
8186
TrigramDocs.size() +
8287
RestrictedCCDocs.size() +
8388
TypeDocs.size() +
8489
ScopeDocs.size() +
8590
ProximityDocs.size());
86-
for (const auto &E : TrigramDocs)
91+
// Tear down intermediate structs as we go to reduce memory usage.
92+
// Since we're trying to get rid of underlying allocations, clearing the
93+
// containers is not enough.
94+
auto CreatePostingList =
95+
[&Result](Token::Kind TK, llvm::StringMap<std::vector<DocID>> &Docs) {
96+
for (auto &E : Docs) {
97+
Result.try_emplace(Token(TK, E.first()), E.second);
98+
E.second = {};
99+
}
100+
Docs = {};
101+
};
102+
CreatePostingList(Token::Kind::Type, TypeDocs);
103+
CreatePostingList(Token::Kind::Scope, ScopeDocs);
104+
CreatePostingList(Token::Kind::ProximityURI, ProximityDocs);
105+
106+
// TrigramDocs are stored in a DenseMap and RestrictedCCDocs is not even a
107+
// map, treat them specially.
108+
for (auto &E : TrigramDocs) {
87109
Result.try_emplace(Token(Token::Kind::Trigram, E.first.str()), E.second);
88-
for (const auto &E : TypeDocs)
89-
Result.try_emplace(Token(Token::Kind::Type, E.first()), E.second);
90-
for (const auto &E : ScopeDocs)
91-
Result.try_emplace(Token(Token::Kind::Scope, E.first()), E.second);
92-
for (const auto &E : ProximityDocs)
93-
Result.try_emplace(Token(Token::Kind::ProximityURI, E.first()), E.second);
110+
E.second = {};
111+
}
112+
TrigramDocs = llvm::DenseMap<Trigram, std::vector<DocID>>{};
94113
if (!RestrictedCCDocs.empty())
95-
Result.try_emplace(RestrictedForCodeCompletion, RestrictedCCDocs);
114+
Result.try_emplace(RestrictedForCodeCompletion,
115+
std::move(RestrictedCCDocs));
96116
return Result;
97117
}
98118
};
@@ -125,7 +145,7 @@ void Dex::buildIndex() {
125145
IndexBuilder Builder;
126146
for (DocID SymbolRank = 0; SymbolRank < Symbols.size(); ++SymbolRank)
127147
Builder.add(*Symbols[SymbolRank], SymbolRank);
128-
InvertedIndex = Builder.build();
148+
InvertedIndex = std::move(Builder).build();
129149
}
130150

131151
std::unique_ptr<Iterator> Dex::iterator(const Token &Tok) const {

clang-tools-extra/pseudo/lib/Lex.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "clang-pseudo/Token.h"
10+
#include "clang/Basic/IdentifierTable.h"
1011
#include "clang/Basic/SourceLocation.h"
1112
#include "clang/Basic/TokenKinds.h"
1213
#include "clang/Lex/Lexer.h"
File renamed without changes.

clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-macro-to-enum %t -- -- -I%S/Inputs/modernize-macro-to-enum
1+
// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-macro-to-enum %t -- -- -I%S/Inputs/modernize-macro-to-enum -fno-delayed-template-parsing
22
// C++14 or later required for binary literals.
33

44
#if 1
@@ -303,3 +303,89 @@ void f()
303303
FN_GREEN(0);
304304
FN_BLUE(0);
305305
}
306+
307+
// Ignore macros defined inside a top-level function definition.
308+
void g(int x)
309+
{
310+
if (x != 0) {
311+
#define INSIDE1 1
312+
#define INSIDE2 2
313+
if (INSIDE1 > 1) {
314+
f();
315+
}
316+
} else {
317+
if (INSIDE2 == 1) {
318+
f();
319+
}
320+
}
321+
}
322+
323+
// Ignore macros defined inside a top-level function declaration.
324+
extern void g2(
325+
#define INSIDE3 3
326+
#define INSIDE4 4
327+
);
328+
329+
// Ignore macros defined inside a record (structure) declaration.
330+
struct S {
331+
#define INSIDE5 5
332+
#define INSIDE6 6
333+
char storage[INSIDE5];
334+
};
335+
class C {
336+
#define INSIDE7 7
337+
#define INSIDE8 8
338+
};
339+
340+
// Ignore macros defined inside a template function definition.
341+
template <int N>
342+
#define INSIDE9 9
343+
bool fn()
344+
{
345+
#define INSIDE10 10
346+
return INSIDE9 > 1 || INSIDE10 < N;
347+
}
348+
349+
// Ignore macros defined inside a variable declaration.
350+
extern int
351+
#define INSIDE11 11
352+
v;
353+
354+
// Ignore macros defined inside a template class definition.
355+
template <int N>
356+
class C2 {
357+
public:
358+
#define INSIDE12 12
359+
char storage[N];
360+
bool f() {
361+
return N > INSIDE12;
362+
}
363+
bool g();
364+
};
365+
366+
// Ignore macros defined inside a template member function definition.
367+
template <int N>
368+
#define INSIDE13 13
369+
bool C2<N>::g() {
370+
#define INSIDE14 14
371+
return N < INSIDE12 || N > INSIDE13 || INSIDE14 > N;
372+
};
373+
374+
// Ignore macros defined inside a template type alias.
375+
template <typename T>
376+
class C3 {
377+
T data;
378+
};
379+
template <typename T>
380+
#define INSIDE15 15
381+
using Data = C3<T[INSIDE15]>;
382+
383+
// Ignore macros defined inside a type alias.
384+
using Data2 =
385+
#define INSIDE16 16
386+
char[INSIDE16];
387+
388+
// Ignore macros defined inside a (constexpr) variable definition.
389+
constexpr int
390+
#define INSIDE17 17
391+
value = INSIDE17;

0 commit comments

Comments
 (0)