Skip to content

Commit 524dad4

Browse files
Merge from 'master' to 'sycl-web' (#1)
CONFLICT (content): Merge conflict in llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
2 parents 11fcc9d + 2ef4791 commit 524dad4

File tree

721 files changed

+18188
-11922
lines changed

Some content is hidden

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

721 files changed

+18188
-11922
lines changed

clang-tools-extra/clang-tidy/GlobList.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static llvm::Regex ConsumeGlob(StringRef &GlobList) {
3434
for (char C : Glob) {
3535
if (C == '*')
3636
RegexText.push_back('.');
37-
else if (MetaChars.find(C) != StringRef::npos)
37+
else if (MetaChars.contains(C))
3838
RegexText.push_back('\\');
3939
RegexText.push_back(C);
4040
}
@@ -43,6 +43,7 @@ static llvm::Regex ConsumeGlob(StringRef &GlobList) {
4343
}
4444

4545
GlobList::GlobList(StringRef Globs) {
46+
Items.reserve(Globs.count(',') + 1);
4647
do {
4748
GlobListItem Item;
4849
Item.IsPositive = !ConsumeNegativeIndicator(Globs);
@@ -52,10 +53,11 @@ GlobList::GlobList(StringRef Globs) {
5253
}
5354

5455
bool GlobList::contains(StringRef S) {
55-
bool Contains = false;
56-
for (const GlobListItem &Item : Items) {
56+
// Iterating the container backwards as the last match determins if S is in
57+
// the list.
58+
for (const GlobListItem &Item : llvm::reverse(Items)) {
5759
if (Item.Regex.match(S))
58-
Contains = Item.IsPositive;
60+
return Item.IsPositive;
5961
}
60-
return Contains;
62+
return false;
6163
}

clang-tools-extra/clang-tidy/GlobList.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H
1111

1212
#include "clang/Basic/LLVM.h"
13+
#include "llvm/ADT/SmallVector.h"
1314
#include "llvm/ADT/StringRef.h"
1415
#include "llvm/Support/Regex.h"
15-
#include <vector>
1616

1717
namespace clang {
1818
namespace tidy {
@@ -39,9 +39,9 @@ class GlobList {
3939

4040
struct GlobListItem {
4141
bool IsPositive;
42-
mutable llvm::Regex Regex;
42+
llvm::Regex Regex;
4343
};
44-
std::vector<GlobListItem> Items;
44+
SmallVector<GlobListItem, 0> Items;
4545
};
4646

4747
} // end namespace tidy

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ readCompileCommand(Reader CmdReader, llvm::ArrayRef<llvm::StringRef> Strings) {
418418
// The current versioning scheme is simple - non-current versions are rejected.
419419
// If you make a breaking change, bump this version number to invalidate stored
420420
// data. Later we may want to support some backward compatibility.
421-
constexpr static uint32_t Version = 13;
421+
constexpr static uint32_t Version = 14;
422422

423423
llvm::Expected<IndexFileIn> readRIFF(llvm::StringRef Data) {
424424
auto RIFF = riff::readFile(Data);

clang-tools-extra/clangd/index/remote/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,20 @@ tools you will need to set this CMake flag &mdash; `-DCLANGD_ENABLE_REMOTE=On`.
2222
On Debian-like systems gRPC and Protobuf can be installed from apt:
2323

2424
```bash
25-
apt install libgrpc++-dev libprotobuf-dev protobuf-compiler protobuf-compiler-grpc
25+
apt install libgrpc++-dev libprotobuf-dev protobuf-compiler-grpc
2626
```
2727

2828
### Building from sources
2929

3030
Another way of installing gRPC and Protobuf is building from sources using
31-
CMake. The easiest way of doing that would be to choose a directory where you
32-
want to install so that the installation files are not copied to system root and
33-
you can uninstall gRPC or use different versions of the library.
31+
CMake (we need CMake config files to find necessary libraries in LLVM). The
32+
easiest way of doing that would be to choose a directory where you want to
33+
install so that the installation files are not copied to system root and you
34+
can easily uninstall gRPC or use different versions.
3435

3536
```bash
3637
# Get source code.
37-
$ git clone -b v1.28.1 https://github.com/grpc/grpc
38+
$ git clone -b v1.33.2 https://github.com/grpc/grpc
3839
$ cd grpc
3940
$ git submodule update --init
4041
# Choose directory where you want gRPC installation to live.
@@ -55,5 +56,5 @@ flag will inform build system that you chose this option &mdash;
5556

5657
## Running
5758

58-
The remote index isn't usable with Clangd yet, but you can try the
59-
proof-of-concept tools in `client/` and `server/` subdirectories.
59+
You can run `clangd-index-server` and connect `clangd` instance to it using
60+
`--remote-index-address` and `--project-root` flags.

clang-tools-extra/clangd/refactor/Rename.cpp

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,84 @@ std::vector<SourceLocation> findOccurrencesWithinFile(ParsedAST &AST,
254254
return Results;
255255
}
256256

257+
// Lookup the declarations (if any) with the given Name in the context of
258+
// RenameDecl.
259+
const NamedDecl *lookupSiblingWithName(const ASTContext &Ctx,
260+
const NamedDecl &RenamedDecl,
261+
llvm::StringRef Name) {
262+
const auto &II = Ctx.Idents.get(Name);
263+
DeclarationName LookupName(&II);
264+
DeclContextLookupResult LookupResult;
265+
const auto *DC = RenamedDecl.getDeclContext();
266+
while (DC && DC->isTransparentContext())
267+
DC = DC->getParent();
268+
switch (DC->getDeclKind()) {
269+
// The enclosing DeclContext may not be the enclosing scope, it might have
270+
// false positives and negatives, so we only choose "confident" DeclContexts
271+
// that don't have any subscopes that are neither DeclContexts nor
272+
// transparent.
273+
//
274+
// Notably, FunctionDecl is excluded -- because local variables are not scoped
275+
// to the function, but rather to the CompoundStmt that is its body. Lookup
276+
// will not find function-local variables.
277+
case Decl::TranslationUnit:
278+
case Decl::Namespace:
279+
case Decl::Record:
280+
case Decl::Enum:
281+
case Decl::CXXRecord:
282+
LookupResult = DC->lookup(LookupName);
283+
break;
284+
default:
285+
break;
286+
}
287+
// Lookup may contain the RenameDecl itself, exclude it.
288+
for (const auto *D : LookupResult)
289+
if (D->getCanonicalDecl() != RenamedDecl.getCanonicalDecl())
290+
return D;
291+
return nullptr;
292+
}
293+
294+
struct InvalidName {
295+
enum Kind {
296+
Keywords,
297+
Conflict,
298+
};
299+
Kind K;
300+
std::string Details;
301+
};
302+
303+
llvm::Error makeError(InvalidName Reason) {
304+
auto Message = [](InvalidName Reason) {
305+
switch (Reason.K) {
306+
case InvalidName::Keywords:
307+
return llvm::formatv("the chosen name \"{0}\" is a keyword",
308+
Reason.Details);
309+
case InvalidName::Conflict:
310+
return llvm::formatv("conflict with the symbol in {0}", Reason.Details);
311+
}
312+
llvm_unreachable("unhandled InvalidName kind");
313+
};
314+
return error("invalid name: {0}", Message(Reason));
315+
}
316+
317+
// Check if we can rename the given RenameDecl into NewName.
318+
// Return details if the rename would produce a conflict.
319+
llvm::Optional<InvalidName> checkName(const NamedDecl &RenameDecl,
320+
llvm::StringRef NewName) {
321+
auto &ASTCtx = RenameDecl.getASTContext();
322+
if (isKeyword(NewName, ASTCtx.getLangOpts()))
323+
return InvalidName{InvalidName::Keywords, NewName.str()};
324+
// Name conflict detection.
325+
// Function conflicts are subtle (overloading), so ignore them.
326+
if (RenameDecl.getKind() != Decl::Function) {
327+
if (auto *Conflict = lookupSiblingWithName(ASTCtx, RenameDecl, NewName))
328+
return InvalidName{
329+
InvalidName::Conflict,
330+
Conflict->getLocation().printToString(ASTCtx.getSourceManager())};
331+
}
332+
return llvm::None;
333+
}
334+
257335
// AST-based rename, it renames all occurrences in the main file.
258336
llvm::Expected<tooling::Replacements>
259337
renameWithinFile(ParsedAST &AST, const NamedDecl &RenameDecl,
@@ -476,11 +554,12 @@ llvm::Expected<RenameResult> rename(const RenameInputs &RInputs) {
476554
return makeError(ReasonToReject::NoSymbolFound);
477555
if (DeclsUnderCursor.size() > 1)
478556
return makeError(ReasonToReject::AmbiguousSymbol);
479-
if (isKeyword(RInputs.NewName, AST.getLangOpts()))
480-
return makeError(ReasonToReject::RenameToKeywords);
481-
482557
const auto &RenameDecl =
483558
llvm::cast<NamedDecl>(*(*DeclsUnderCursor.begin())->getCanonicalDecl());
559+
auto Invalid = checkName(RenameDecl, RInputs.NewName);
560+
if (Invalid)
561+
return makeError(*Invalid);
562+
484563
auto Reject = renameable(RenameDecl, RInputs.MainFilePath, RInputs.Index,
485564
Opts.AllowCrossFile);
486565
if (Reject)

0 commit comments

Comments
 (0)