Skip to content

Commit 93dd9cf

Browse files
author
Valery N Dmitriev
committed
Merge from 'master' to 'sycl-web' (intel#99)
CONFLICT (content): Merge conflict in llvm/CMakeLists.txt
2 parents 49ca2d7 + afa1afd commit 93dd9cf

File tree

430 files changed

+23206
-11254
lines changed

Some content is hidden

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

430 files changed

+23206
-11254
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ static QualType getUnqualifiedType(const Expr &E) {
7979
}
8080

8181
static APValue getConstantExprValue(const ASTContext &Ctx, const Expr &E) {
82-
llvm::APSInt IntegerConstant;
83-
if (E.isIntegerConstantExpr(IntegerConstant, Ctx))
84-
return APValue(IntegerConstant);
82+
if (auto IntegerConstant = E.getIntegerConstantExpr(Ctx))
83+
return APValue(*IntegerConstant);
8584
APValue Constant;
8685
if (Ctx.getLangOpts().CPlusPlus && E.isCXX11ConstantExpr(Ctx, &Constant))
8786
return Constant;

clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ void ProBoundsConstantArrayIndexCheck::check(
6565
if (IndexExpr->isValueDependent())
6666
return; // We check in the specialization.
6767

68-
llvm::APSInt Index;
69-
if (!IndexExpr->isIntegerConstantExpr(Index, *Result.Context, nullptr,
70-
/*isEvaluated=*/true)) {
68+
Optional<llvm::APSInt> Index =
69+
IndexExpr->getIntegerConstantExpr(*Result.Context);
70+
if (!Index) {
7171
SourceRange BaseRange;
7272
if (const auto *ArraySubscriptE = dyn_cast<ArraySubscriptExpr>(Matched))
7373
BaseRange = ArraySubscriptE->getBase()->getSourceRange();
@@ -101,9 +101,9 @@ void ProBoundsConstantArrayIndexCheck::check(
101101
if (!StdArrayDecl)
102102
return;
103103

104-
if (Index.isSigned() && Index.isNegative()) {
104+
if (Index->isSigned() && Index->isNegative()) {
105105
diag(Matched->getExprLoc(), "std::array<> index %0 is negative")
106-
<< Index.toString(10);
106+
<< Index->toString(10);
107107
return;
108108
}
109109

@@ -118,11 +118,11 @@ void ProBoundsConstantArrayIndexCheck::check(
118118

119119
// Get uint64_t values, because different bitwidths would lead to an assertion
120120
// in APInt::uge.
121-
if (Index.getZExtValue() >= ArraySize.getZExtValue()) {
121+
if (Index->getZExtValue() >= ArraySize.getZExtValue()) {
122122
diag(Matched->getExprLoc(),
123123
"std::array<> index %0 is past the end of the array "
124124
"(which contains %1 elements)")
125-
<< Index.toString(10) << ArraySize.toString(10, false);
125+
<< Index->toString(10) << ArraySize.toString(10, false);
126126
}
127127
}
128128

clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp

+15-7
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,13 @@ static bool retrieveIntegerConstantExpr(const MatchFinder::MatchResult &Result,
500500
const Expr *&ConstExpr) {
501501
std::string CstId = (Id + "-const").str();
502502
ConstExpr = Result.Nodes.getNodeAs<Expr>(CstId);
503-
return ConstExpr && ConstExpr->isIntegerConstantExpr(Value, *Result.Context);
503+
if (!ConstExpr)
504+
return false;
505+
Optional<llvm::APSInt> R = ConstExpr->getIntegerConstantExpr(*Result.Context);
506+
if (!R)
507+
return false;
508+
Value = *R;
509+
return true;
504510
}
505511

506512
// Overloaded `retrieveIntegerConstantExpr` for compatibility.
@@ -673,7 +679,7 @@ static bool retrieveRelationalIntegerConstantExpr(
673679

674680
if (const auto *Arg = OverloadedOperatorExpr->getArg(1)) {
675681
if (!Arg->isValueDependent() &&
676-
!Arg->isIntegerConstantExpr(Value, *Result.Context))
682+
!Arg->isIntegerConstantExpr(*Result.Context))
677683
return false;
678684
}
679685
Symbol = OverloadedOperatorExpr->getArg(0);
@@ -1265,21 +1271,23 @@ void RedundantExpressionCheck::check(const MatchFinder::MatchResult &Result) {
12651271
"left-right-shift-confusion")) {
12661272
const auto *ShiftingConst = Result.Nodes.getNodeAs<Expr>("shift-const");
12671273
assert(ShiftingConst && "Expr* 'ShiftingConst' is nullptr!");
1268-
APSInt ShiftingValue;
1274+
Optional<llvm::APSInt> ShiftingValue =
1275+
ShiftingConst->getIntegerConstantExpr(*Result.Context);
12691276

1270-
if (!ShiftingConst->isIntegerConstantExpr(ShiftingValue, *Result.Context))
1277+
if (!ShiftingValue)
12711278
return;
12721279

12731280
const auto *AndConst = Result.Nodes.getNodeAs<Expr>("and-const");
12741281
assert(AndConst && "Expr* 'AndCont' is nullptr!");
1275-
APSInt AndValue;
1276-
if (!AndConst->isIntegerConstantExpr(AndValue, *Result.Context))
1282+
Optional<llvm::APSInt> AndValue =
1283+
AndConst->getIntegerConstantExpr(*Result.Context);
1284+
if (!AndValue)
12771285
return;
12781286

12791287
// If ShiftingConst is shifted left with more bits than the position of the
12801288
// leftmost 1 in the bit representation of AndValue, AndConstant is
12811289
// ineffective.
1282-
if (AndValue.getActiveBits() > ShiftingValue)
1290+
if (AndValue->getActiveBits() > *ShiftingValue)
12831291
return;
12841292

12851293
auto Diag = diag(BinaryAndExpr->getOperatorLoc(),

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,12 @@ static bool arrayMatchesBoundExpr(ASTContext *Context,
438438
Context->getAsConstantArrayType(ArrayType);
439439
if (!ConstType)
440440
return false;
441-
llvm::APSInt ConditionSize;
442-
if (!ConditionExpr->isIntegerConstantExpr(ConditionSize, *Context))
441+
Optional<llvm::APSInt> ConditionSize =
442+
ConditionExpr->getIntegerConstantExpr(*Context);
443+
if (!ConditionSize)
443444
return false;
444445
llvm::APSInt ArraySize(ConstType->getSize());
445-
return llvm::APSInt::isSameValue(ConditionSize, ArraySize);
446+
return llvm::APSInt::isSameValue(*ConditionSize, ArraySize);
446447
}
447448

448449
ForLoopIndexUseVisitor::ForLoopIndexUseVisitor(ASTContext *Context,

clang-tools-extra/clangd/URI.cpp

+33-12
Original file line numberDiff line numberDiff line change
@@ -26,35 +26,56 @@ inline llvm::Error make_string_error(const llvm::Twine &Message) {
2626
llvm::inconvertibleErrorCode());
2727
}
2828

29+
bool isWindowsPath(llvm::StringRef Path) {
30+
return Path.size() > 1 && llvm::isAlpha(Path[0]) && Path[1] == ':';
31+
}
32+
33+
bool isNetworkPath(llvm::StringRef Path) {
34+
return Path.size() > 2 && Path[0] == Path[1] &&
35+
llvm::sys::path::is_separator(Path[0]);
36+
}
37+
2938
/// This manages file paths in the file system. All paths in the scheme
3039
/// are absolute (with leading '/').
3140
/// Note that this scheme is hardcoded into the library and not registered in
3241
/// registry.
3342
class FileSystemScheme : public URIScheme {
3443
public:
3544
llvm::Expected<std::string>
36-
getAbsolutePath(llvm::StringRef /*Authority*/, llvm::StringRef Body,
45+
getAbsolutePath(llvm::StringRef Authority, llvm::StringRef Body,
3746
llvm::StringRef /*HintPath*/) const override {
3847
if (!Body.startswith("/"))
3948
return make_string_error("File scheme: expect body to be an absolute "
4049
"path starting with '/': " +
4150
Body);
42-
// For Windows paths e.g. /X:
43-
if (Body.size() > 2 && Body[0] == '/' && Body[2] == ':')
51+
llvm::SmallString<128> Path;
52+
if (!Authority.empty()) {
53+
// Windows UNC paths e.g. file://server/share => \\server\share
54+
("//" + Authority).toVector(Path);
55+
} else if (isWindowsPath(Body.substr(1))) {
56+
// Windows paths e.g. file:///X:/path => X:\path
4457
Body.consume_front("/");
45-
llvm::SmallVector<char, 16> Path(Body.begin(), Body.end());
58+
}
59+
Path.append(Body);
4660
llvm::sys::path::native(Path);
47-
return std::string(Path.begin(), Path.end());
61+
return std::string(Path);
4862
}
4963

5064
llvm::Expected<URI>
5165
uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override {
5266
std::string Body;
53-
// For Windows paths e.g. X:
54-
if (AbsolutePath.size() > 1 && AbsolutePath[1] == ':')
67+
llvm::StringRef Authority;
68+
llvm::StringRef Root = llvm::sys::path::root_name(AbsolutePath);
69+
if (isNetworkPath(Root)) {
70+
// Windows UNC paths e.g. \\server\share => file://server/share
71+
Authority = Root.drop_front(2);
72+
AbsolutePath.consume_front(Root);
73+
} else if (isWindowsPath(Root)) {
74+
// Windows paths e.g. X:\path => file:///X:/path
5575
Body = "/";
76+
}
5677
Body += llvm::sys::path::convert_to_slash(AbsolutePath);
57-
return URI("file", /*Authority=*/"", Body);
78+
return URI("file", Authority, Body);
5879
}
5980
};
6081

@@ -96,13 +117,13 @@ bool shouldEscape(unsigned char C) {
96117
void percentEncode(llvm::StringRef Content, std::string &Out) {
97118
std::string Result;
98119
for (unsigned char C : Content)
99-
if (shouldEscape(C))
100-
{
120+
if (shouldEscape(C)) {
101121
Out.push_back('%');
102122
Out.push_back(llvm::hexdigit(C / 16));
103123
Out.push_back(llvm::hexdigit(C % 16));
104-
} else
105-
{ Out.push_back(C); }
124+
} else {
125+
Out.push_back(C);
126+
}
106127
}
107128

108129
/// Decodes a string according to percent-encoding.

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

+11-9
Original file line numberDiff line numberDiff line change
@@ -373,16 +373,12 @@ bool SymbolCollector::handleMacroOccurrence(const IdentifierInfo *Name,
373373
index::SymbolRoleSet Roles,
374374
SourceLocation Loc) {
375375
assert(PP.get());
376-
377-
const auto &SM = PP->getSourceManager();
378-
auto DefLoc = MI->getDefinitionLoc();
379-
auto SpellingLoc = SM.getSpellingLoc(Loc);
380-
bool IsMainFileSymbol = SM.isInMainFile(SM.getExpansionLoc(DefLoc));
381-
382376
// Builtin macros don't have useful locations and aren't needed in completion.
383377
if (MI->isBuiltinMacro())
384378
return true;
385379

380+
const auto &SM = PP->getSourceManager();
381+
auto DefLoc = MI->getDefinitionLoc();
386382
// Also avoid storing predefined macros like __DBL_MIN__.
387383
if (SM.isWrittenInBuiltinFile(DefLoc))
388384
return true;
@@ -391,8 +387,13 @@ bool SymbolCollector::handleMacroOccurrence(const IdentifierInfo *Name,
391387
if (!ID)
392388
return true;
393389

390+
auto SpellingLoc = SM.getSpellingLoc(Loc);
391+
bool IsMainFileOnly =
392+
SM.isInMainFile(SM.getExpansionLoc(DefLoc)) &&
393+
!isHeaderFile(SM.getFileEntryForID(SM.getMainFileID())->getName(),
394+
ASTCtx->getLangOpts());
394395
// Do not store references to main-file macros.
395-
if ((static_cast<unsigned>(Opts.RefFilter) & Roles) && !IsMainFileSymbol &&
396+
if ((static_cast<unsigned>(Opts.RefFilter) & Roles) && !IsMainFileOnly &&
396397
(Opts.RefsInHeaders || SM.getFileID(SpellingLoc) == SM.getMainFileID()))
397398
MacroRefs[*ID].push_back({Loc, Roles});
398399

@@ -401,7 +402,7 @@ bool SymbolCollector::handleMacroOccurrence(const IdentifierInfo *Name,
401402
return true;
402403

403404
// Skip main-file macros if we are not collecting them.
404-
if (IsMainFileSymbol && !Opts.CollectMainFileSymbols)
405+
if (IsMainFileOnly && !Opts.CollectMainFileSymbols)
405406
return false;
406407

407408
// Mark the macro as referenced if this is a reference coming from the main
@@ -425,11 +426,12 @@ bool SymbolCollector::handleMacroOccurrence(const IdentifierInfo *Name,
425426
Symbol S;
426427
S.ID = std::move(*ID);
427428
S.Name = Name->getName();
428-
if (!IsMainFileSymbol) {
429+
if (!IsMainFileOnly) {
429430
S.Flags |= Symbol::IndexedForCodeCompletion;
430431
S.Flags |= Symbol::VisibleOutsideFile;
431432
}
432433
S.SymInfo = index::getSymbolInfoForMacro(*MI);
434+
S.Origin = Opts.Origin;
433435
std::string FileURI;
434436
// FIXME: use the result to filter out symbols.
435437
shouldIndexFile(SM.getFileID(Loc));
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
# We need to splice paths into file:// URIs for this test.
2-
# UNSUPPORTED: windows-msvc
3-
41
# Use a copy of inputs, as we'll mutate it (as will the background index).
5-
# RUN: rm -rf %t
6-
# RUN: cp -r %S/Inputs/background-index %t
2+
# RUN: rm -rf %/t
3+
# RUN: cp -r %/S/Inputs/background-index %/t
74
# Need to embed the correct temp path in the actual JSON-RPC requests.
8-
# RUN: sed -i -e "s|DIRECTORY|%t|" %t/definition.jsonrpc
9-
# RUN: sed -i -e "s|DIRECTORY|%t|" %t/compile_commands.json
5+
# RUN: sed -e "s|DIRECTORY|%/t|" %/t/definition.jsonrpc.tmpl > %/t/definition.jsonrpc.1
6+
# RUN: sed -e "s|DIRECTORY|%/t|" %/t/compile_commands.json.tmpl > %/t/compile_commands.json
7+
# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
8+
# (with the extra slash in the front), so we add it here.
9+
# RUN: sed -E -e 's|"file://([A-Z]):/|"file:///\1:/|g' %/t/definition.jsonrpc.1 > %/t/definition.jsonrpc
1010

1111
# We're editing bar.cpp, which includes foo.h.
1212
# foo() is declared in foo.h and defined in foo.cpp.
1313
# The background index should allow us to go-to-definition on foo().
1414
# We should also see indexing progress notifications.
15-
# RUN: clangd -background-index -lit-test < %t/definition.jsonrpc | FileCheck %t/definition.jsonrpc --check-prefixes=CHECK,BUILD
15+
# RUN: clangd -background-index -lit-test < %/t/definition.jsonrpc | FileCheck %/t/definition.jsonrpc --check-prefixes=CHECK,BUILD
1616

1717
# Test that the index is writing files in the expected location.
18-
# RUN: ls %t/.cache/clangd/index/foo.cpp.*.idx
19-
# RUN: ls %t/sub_dir/.cache/clangd/index/foo.h.*.idx
18+
# RUN: ls %/t/.cache/clangd/index/foo.cpp.*.idx
19+
# RUN: ls %/t/sub_dir/.cache/clangd/index/foo.h.*.idx
2020

2121
# Test the index is read from disk: delete code and restart clangd.
22-
# RUN: rm %t/foo.cpp
23-
# RUN: clangd -background-index -lit-test < %t/definition.jsonrpc | FileCheck %t/definition.jsonrpc --check-prefixes=CHECK,USE
22+
# RUN: rm %/t/foo.cpp
23+
# RUN: clangd -background-index -lit-test < %/t/definition.jsonrpc | FileCheck %/t/definition.jsonrpc --check-prefixes=CHECK,USE

clang-tools-extra/clangd/test/did-change-configuration-params.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: clangd -compile_args_from=lsp -lit-test < %s 2> %t | FileCheck -strict-whitespace %s
2-
# RUN: cat %t | FileCheck --check-prefix=ERR %s
2+
# RUN: FileCheck --check-prefix=ERR --input-file=%t %s
33
# UNSUPPORTED: windows-gnu,windows-msvc
44
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
55
---

clang-tools-extra/clangd/test/test-uri-windows.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
2-
# REQUIRES: windows-gnu || windows-msvc
2+
# UNSUPPORTED: !(windows-gnu || windows-msvc)
33
# Test authority-less URI
44
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
55
---

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

+10
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,9 @@ TEST_F(SymbolCollectorTest, Origin) {
14021402
runSymbolCollector("class Foo {};", /*Main=*/"");
14031403
EXPECT_THAT(Symbols, UnorderedElementsAre(
14041404
Field(&Symbol::Origin, SymbolOrigin::Static)));
1405+
runSymbolCollector("#define FOO", /*Main=*/"");
1406+
EXPECT_THAT(Symbols, UnorderedElementsAre(
1407+
Field(&Symbol::Origin, SymbolOrigin::Static)));
14051408
}
14061409

14071410
TEST_F(SymbolCollectorTest, CollectMacros) {
@@ -1504,6 +1507,13 @@ TEST_F(SymbolCollectorTest, BadUTF8) {
15041507
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "PUNCT").ID, _)));
15051508
}
15061509

1510+
TEST_F(SymbolCollectorTest, MacrosInHeaders) {
1511+
CollectorOpts.CollectMacro = true;
1512+
TestFileName = testPath("test.h");
1513+
runSymbolCollector("", "#define X");
1514+
EXPECT_THAT(Symbols,
1515+
UnorderedElementsAre(AllOf(QName("X"), ForCodeCompletion(true))));
1516+
}
15071517
} // namespace
15081518
} // namespace clangd
15091519
} // namespace clang

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

+29-2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ TEST(URITest, Create) {
7676
#endif
7777
}
7878

79+
TEST(URITest, CreateUNC) {
80+
#ifdef _WIN32
81+
EXPECT_THAT(createOrDie("\\\\test.org\\x\\y\\z"), "file://test.org/x/y/z");
82+
EXPECT_THAT(createOrDie("\\\\10.0.0.1\\x\\y\\z"), "file://10.0.0.1/x/y/z");
83+
#else
84+
EXPECT_THAT(createOrDie("//test.org/x/y/z"), "file://test.org/x/y/z");
85+
EXPECT_THAT(createOrDie("//10.0.0.1/x/y/z"), "file://10.0.0.1/x/y/z");
86+
#endif
87+
}
88+
7989
TEST(URITest, FailedCreate) {
8090
EXPECT_ERROR(URI::create("/x/y/z", "no"));
8191
// Path has to be absolute.
@@ -127,15 +137,32 @@ TEST(URITest, Resolve) {
127137
EXPECT_THAT(resolveOrDie(parseOrDie("file:///c:/x/y/z")), "c:\\x\\y\\z");
128138
#else
129139
EXPECT_EQ(resolveOrDie(parseOrDie("file:/a/b/c")), "/a/b/c");
130-
EXPECT_EQ(resolveOrDie(parseOrDie("file://auth/a/b/c")), "/a/b/c");
140+
EXPECT_EQ(resolveOrDie(parseOrDie("file://auth/a/b/c")), "//auth/a/b/c");
131141
EXPECT_THAT(resolveOrDie(parseOrDie("file://au%3dth/%28x%29/y/%20z")),
132-
"/(x)/y/ z");
142+
"//au=th/(x)/y/ z");
133143
EXPECT_THAT(resolveOrDie(parseOrDie("file:///c:/x/y/z")), "c:/x/y/z");
134144
#endif
135145
EXPECT_EQ(resolveOrDie(parseOrDie("unittest:///a"), testPath("x")),
136146
testPath("a"));
137147
}
138148

149+
TEST(URITest, ResolveUNC) {
150+
#ifdef _WIN32
151+
EXPECT_THAT(resolveOrDie(parseOrDie("file://example.com/x/y/z")),
152+
"\\\\example.com\\x\\y\\z");
153+
EXPECT_THAT(resolveOrDie(parseOrDie("file://127.0.0.1/x/y/z")),
154+
"\\\\127.0.0.1\\x\\y\\z");
155+
// Ensure non-traditional file URI still resolves to correct UNC path.
156+
EXPECT_THAT(resolveOrDie(parseOrDie("file:////127.0.0.1/x/y/z")),
157+
"\\\\127.0.0.1\\x\\y\\z");
158+
#else
159+
EXPECT_THAT(resolveOrDie(parseOrDie("file://example.com/x/y/z")),
160+
"//example.com/x/y/z");
161+
EXPECT_THAT(resolveOrDie(parseOrDie("file://127.0.0.1/x/y/z")),
162+
"//127.0.0.1/x/y/z");
163+
#endif
164+
}
165+
139166
std::string resolvePathOrDie(llvm::StringRef AbsPath,
140167
llvm::StringRef HintPath = "") {
141168
auto Path = URI::resolvePath(AbsPath, HintPath);

clang-tools-extra/unittests/CMakeLists.txt

-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ function(add_extra_unittest test_dirname)
55
add_unittest(ExtraToolsUnitTests ${test_dirname} ${ARGN})
66
endfunction()
77

8-
if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
9-
add_definitions("-Wno-suggest-override")
10-
endif()
11-
128
add_subdirectory(clang-apply-replacements)
139
add_subdirectory(clang-change-namespace)
1410
add_subdirectory(clang-doc)

0 commit comments

Comments
 (0)