Skip to content

Commit

Permalink
Overwritten with: ee8e7ff Merged main:5471b1fa4013 into amd-gfx:5a673…
Browse files Browse the repository at this point in the history
…28b3f94

Based on upstream llvm : 5471b1f [gn build] Port d2ddc69

Local changes since 9ef380b:
ee8e7ff Merged main:5471b1fa4013 into amd-gfx:5a67328b3f94
5a67328 Merged main:238dbeb1e7ba into amd-gfx:578e90088656
578e900 Merged main:25bf4a8f4285 into amd-gfx:d8030f7eb81d
d8030f7 Merged main:3505d8dc0742 into amd-gfx:1ba35b4ee8bf
1ba35b4 Merged main:37e83bc6db3a into amd-gfx:cb2b919330e6
cb2b919 Merged main:fb1c52852690 into amd-gfx:8a4e2494e40a
8a4e249 Merged main:0e874fc014be into amd-gfx:abefc15690ba
abefc15 Merged main:1ca5e68aa07e into amd-gfx:8b5343c48207
8b5343c Merged main:0a3cf7f4762e into amd-gfx:ab07f2cc37e7
ab07f2c Merged main:4e0e79dd349a into amd-gfx:edf208676d23
edf2086 Merged main:ce8c59e6af48 into amd-gfx:33a7a3576da9
33a7a35 Merged main:979228f120f4 into amd-gfx:4da302fb8562
4da302f Merged main:7f7b0dc4e15f into amd-gfx:4da34311e394
4da3431 Merged main:c1cd42d69848 into amd-gfx:784cdf03f5db
784cdf0 Merged main:8444a2494d3d into amd-gfx:8416743e8944
8416743 Merged main:a39b19821b6b into amd-gfx:1fb289de71aa
1fb289d Merged main:cb5b52a06eeb into amd-gfx:7092d3ce882a
7092d3c Merged main:65cd3cbb3fc9 into amd-gfx:81ea74a95cce
81ea74a Merged main:86d68e288585 into amd-gfx:ebfd6644a317
ebfd664 Merged main:9eb2284f6039 into amd-gfx:d8c2161d55d3
d8c2161 Merged main:c73ae747cb0c into amd-gfx:9e2279be6db6
9e2279b Merged main:89ae5b5b6a47 into amd-gfx:c46db56b4c1a
c46db56 Merged main:9a1ac97d3af5 into amd-gfx
02d2ce9 Merged main:f784be0777f3 into amd-gfx:273a500bfd31

Added AMD modification notices and removed some GPL files.

Change-Id: I9f5237d2f352a16046b9c121018c6fcb4a343e51
  • Loading branch information
trenouf committed Jan 7, 2021
2 parents 9ef380b + ee8e7ff commit 294f18d
Show file tree
Hide file tree
Showing 1,347 changed files with 56,005 additions and 11,806 deletions.
59 changes: 27 additions & 32 deletions clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ namespace clang {
namespace tidy {
namespace abseil {

using ::clang::transformer::addInclude;
using ::clang::transformer::applyFirst;
using ::clang::transformer::cat;
using ::clang::transformer::change;
using ::clang::transformer::changeTo;
using ::clang::transformer::makeRule;
using ::clang::transformer::node;
using ::clang::transformer::RewriteRule;
Expand All @@ -38,22 +39,9 @@ static const char DefaultStringLikeClasses[] = "::std::basic_string;"
"::absl::string_view";
static const char DefaultAbseilStringsMatchHeader[] = "absl/strings/match.h";

static llvm::Optional<transformer::RewriteRule>
MakeRule(const LangOptions &LangOpts,
const ClangTidyCheck::OptionsView &Options) {
// Parse options.
//
// FIXME(tdl-g): These options are being parsed redundantly with the
// constructor because TransformerClangTidyCheck forces us to provide MakeRule
// before "this" is fully constructed, but StoreOptions requires us to store
// the parsed options in "this". We need to fix TransformerClangTidyCheck and
// then we can clean this up.
const std::vector<std::string> StringLikeClassNames =
utils::options::parseStringList(
Options.get("StringLikeClasses", DefaultStringLikeClasses));
const std::string AbseilStringsMatchHeader =
Options.get("AbseilStringsMatchHeader", DefaultAbseilStringsMatchHeader);

static transformer::RewriteRule
makeRewriteRule(const std::vector<std::string> &StringLikeClassNames,
StringRef AbseilStringsMatchHeader) {
auto StringLikeClass = cxxRecordDecl(hasAnyName(SmallVector<StringRef, 4>(
StringLikeClassNames.begin(), StringLikeClassNames.end())));
auto StringType =
Expand All @@ -75,29 +63,36 @@ MakeRule(const LangOptions &LangOpts,
onImplicitObjectArgument(expr().bind("string_being_searched")));

RewriteRule rule = applyFirst(
{makeRule(binaryOperator(hasOperatorName("=="),
hasOperands(ignoringParenImpCasts(StringNpos),
ignoringParenImpCasts(StringFind))),
change(cat("!absl::StrContains(", node("string_being_searched"),
", ", node("parameter_to_find"), ")")),
cat("use !absl::StrContains instead of find() == npos")),
makeRule(binaryOperator(hasOperatorName("!="),
hasOperands(ignoringParenImpCasts(StringNpos),
ignoringParenImpCasts(StringFind))),
change(cat("absl::StrContains(", node("string_being_searched"),
", ", node("parameter_to_find"), ")")),
cat("use absl::StrContains instead of find() != npos"))});
addInclude(rule, AbseilStringsMatchHeader);
{makeRule(
binaryOperator(hasOperatorName("=="),
hasOperands(ignoringParenImpCasts(StringNpos),
ignoringParenImpCasts(StringFind))),
{changeTo(cat("!absl::StrContains(", node("string_being_searched"),
", ", node("parameter_to_find"), ")")),
addInclude(AbseilStringsMatchHeader)},
cat("use !absl::StrContains instead of find() == npos")),
makeRule(
binaryOperator(hasOperatorName("!="),
hasOperands(ignoringParenImpCasts(StringNpos),
ignoringParenImpCasts(StringFind))),
{changeTo(cat("absl::StrContains(", node("string_being_searched"),
", ", node("parameter_to_find"), ")")),
addInclude(AbseilStringsMatchHeader)},
cat("use absl::StrContains instead "
"of find() != npos"))});
return rule;
}

StringFindStrContainsCheck::StringFindStrContainsCheck(
StringRef Name, ClangTidyContext *Context)
: TransformerClangTidyCheck(&MakeRule, Name, Context),
: TransformerClangTidyCheck(Name, Context),
StringLikeClassesOption(utils::options::parseStringList(
Options.get("StringLikeClasses", DefaultStringLikeClasses))),
AbseilStringsMatchHeaderOption(Options.get(
"AbseilStringsMatchHeader", DefaultAbseilStringsMatchHeader)) {}
"AbseilStringsMatchHeader", DefaultAbseilStringsMatchHeader)) {
setRule(
makeRewriteRule(StringLikeClassesOption, AbseilStringsMatchHeaderOption));
}

bool StringFindStrContainsCheck::isLanguageVersionSupported(
const LangOptions &LangOpts) const {
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clangd/ClangdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,8 @@ void ClangdServer::switchSourceHeader(
// the same directory.
// 2) if 1) fails, we use the AST&Index approach, it is slower but supports
// different code layout.
if (auto CorrespondingFile = getCorrespondingHeaderOrSource(
std::string(Path), TFS.view(llvm::None)))
if (auto CorrespondingFile =
getCorrespondingHeaderOrSource(Path, TFS.view(llvm::None)))
return CB(std::move(CorrespondingFile));
auto Action = [Path = Path.str(), CB = std::move(CB),
this](llvm::Expected<InputsAndAST> InpAST) mutable {
Expand Down
15 changes: 6 additions & 9 deletions clang-tools-extra/clangd/HeaderSourceSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ namespace clang {
namespace clangd {

llvm::Optional<Path> getCorrespondingHeaderOrSource(
const Path &OriginalFile,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
PathRef OriginalFile, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
llvm::StringRef SourceExtensions[] = {".cpp", ".c", ".cc", ".cxx",
".c++", ".m", ".mm"};
llvm::StringRef HeaderExtensions[] = {".h", ".hh", ".hpp", ".hxx", ".inc"};
Expand Down Expand Up @@ -51,25 +50,23 @@ llvm::Optional<Path> getCorrespondingHeaderOrSource(
NewExts = SourceExtensions;

// Storage for the new path.
llvm::SmallString<128> NewPath = llvm::StringRef(OriginalFile);
llvm::SmallString<128> NewPath = OriginalFile;

// Loop through switched extension candidates.
for (llvm::StringRef NewExt : NewExts) {
llvm::sys::path::replace_extension(NewPath, NewExt);
if (VFS->exists(NewPath))
return NewPath.str().str(); // First str() to convert from SmallString to
// StringRef, second to convert from StringRef
// to std::string
return Path(NewPath);

// Also check NewExt in upper-case, just in case.
llvm::sys::path::replace_extension(NewPath, NewExt.upper());
if (VFS->exists(NewPath))
return NewPath.str().str();
return Path(NewPath);
}
return None;
}

llvm::Optional<Path> getCorrespondingHeaderOrSource(const Path &OriginalFile,
llvm::Optional<Path> getCorrespondingHeaderOrSource(PathRef OriginalFile,
ParsedAST &AST,
const SymbolIndex *Index) {
if (!Index) {
Expand Down Expand Up @@ -121,7 +118,7 @@ llvm::Optional<Path> getCorrespondingHeaderOrSource(const Path &OriginalFile,
// candidates.
Best = It;
}
return Path(std::string(Best->first()));
return Path(Best->first());
}

std::vector<const Decl *> getIndexableLocalDecls(ParsedAST &AST) {
Expand Down
5 changes: 2 additions & 3 deletions clang-tools-extra/clangd/HeaderSourceSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ namespace clangd {
/// Given a header file, returns the best matching source file, and vice visa.
/// It only uses the filename heuristics to do the inference.
llvm::Optional<Path> getCorrespondingHeaderOrSource(
const Path &OriginalFile,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS);
PathRef OriginalFile, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS);

/// Given a header file, returns the best matching source file, and vice visa.
/// The heuristics incorporate with the AST and the index (if provided).
llvm::Optional<Path> getCorrespondingHeaderOrSource(const Path &OriginalFile,
llvm::Optional<Path> getCorrespondingHeaderOrSource(PathRef OriginalFile,
ParsedAST &AST,
const SymbolIndex *Index);

Expand Down
24 changes: 22 additions & 2 deletions clang-tools-extra/clangd/QueryDriverDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,26 @@ llvm::Optional<DriverInfo> parseDriverOutput(llvm::StringRef Output) {
}

llvm::Optional<DriverInfo>
extractSystemIncludesAndTarget(PathRef Driver, llvm::StringRef Lang,
extractSystemIncludesAndTarget(llvm::SmallString<128> Driver,
llvm::StringRef Lang,
llvm::ArrayRef<std::string> CommandLine,
const llvm::Regex &QueryDriverRegex) {
trace::Span Tracer("Extract system includes and target");

if (!llvm::sys::path::is_absolute(Driver)) {
assert(llvm::none_of(
Driver, [](char C) { return llvm::sys::path::is_separator(C); }));
auto DriverProgram = llvm::sys::findProgramByName(Driver);
if (DriverProgram) {
vlog("System include extraction: driver {0} expanded to {1}", Driver,
*DriverProgram);
Driver = *DriverProgram;
} else {
elog("System include extraction: driver {0} not found in PATH", Driver);
return llvm::None;
}
}

SPAN_ATTACH(Tracer, "driver", Driver);
SPAN_ATTACH(Tracer, "lang", Lang);

Expand Down Expand Up @@ -332,7 +348,11 @@ class QueryDriverDatabase : public GlobalCompilationDatabase {
}

llvm::SmallString<128> Driver(Cmd->CommandLine.front());
llvm::sys::fs::make_absolute(Cmd->Directory, Driver);
if (llvm::any_of(Driver,
[](char C) { return llvm::sys::path::is_separator(C); }))
// Driver is a not a single executable name but instead a path (either
// relative or absolute).
llvm::sys::fs::make_absolute(Cmd->Directory, Driver);

if (auto Info =
QueriedDrivers.get(/*Key=*/(Driver + ":" + Lang).str(), [&] {
Expand Down
11 changes: 6 additions & 5 deletions clang-tools-extra/clangd/index/Merge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
namespace clang {
namespace clangd {

// FIXME: Deleted symbols in dirty files are still returned (from Static).
// To identify these eliminate these, we should:
// - find the generating file from each Symbol which is Static-only
// - ask Dynamic if it has that file (needs new SymbolIndex method)
// - if so, drop the Symbol.
bool MergedIndex::fuzzyFind(
const FuzzyFindRequest &Req,
llvm::function_ref<void(const Symbol &)> Callback) const {
Expand All @@ -49,7 +44,13 @@ bool MergedIndex::fuzzyFind(
SymbolSlab Dyn = std::move(DynB).build();

llvm::DenseSet<SymbolID> SeenDynamicSymbols;
auto DynamicContainsFile = Dynamic->indexedFiles();
More |= Static->fuzzyFind(Req, [&](const Symbol &S) {
// We expect the definition to see the canonical declaration, so it seems
// to be enough to check only the definition if it exists.
if (DynamicContainsFile(S.Definition ? S.Definition.FileURI
: S.CanonicalDeclaration.FileURI))
return;
auto DynS = Dyn.find(S.ID);
++StaticCount;
if (DynS == Dyn.end())
Expand Down
4 changes: 0 additions & 4 deletions clang-tools-extra/clangd/index/Merge.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ Symbol mergeSymbol(const Symbol &L, const Symbol &R);
// - the Dynamic index covers few files, but is relatively up-to-date.
// - the Static index covers a bigger set of files, but is relatively stale.
// The returned index attempts to combine results, and avoid duplicates.
//
// FIXME: We don't have a mechanism in Index to track deleted symbols and
// refs in dirty files, so the merged index may return stale symbols
// and refs from Static index.
class MergedIndex : public SymbolIndex {
const SymbolIndex *Dynamic, *Static;

Expand Down
5 changes: 2 additions & 3 deletions clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ const FunctionDecl *getSelectedFunction(const SelectionTree::Node *SelNode) {
llvm::Optional<Path> getSourceFile(llvm::StringRef FileName,
const Tweak::Selection &Sel) {
if (auto Source = getCorrespondingHeaderOrSource(
std::string(FileName),
FileName,
&Sel.AST->getSourceManager().getFileManager().getVirtualFileSystem()))
return *Source;
return getCorrespondingHeaderOrSource(std::string(FileName), *Sel.AST,
Sel.Index);
return getCorrespondingHeaderOrSource(FileName, *Sel.AST, Sel.Index);
}

// Synthesize a DeclContext for TargetNS from CurContext. TargetNS must be empty
Expand Down
31 changes: 17 additions & 14 deletions clang-tools-extra/clangd/test/system-include-extractor.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@
# The mock driver below is a shell script:
# REQUIRES: shell

# Create a bin directory to store the mock-driver and add it to the path
# RUN: mkdir -p %t.dir/bin
# RUN: export PATH=%t.dir/bin:$PATH
# Generate a mock-driver that will print %temp_dir%/my/dir and
# %temp_dir%/my/dir2 as include search paths.
# RUN: echo '#!/bin/sh' >> %t.dir/my_driver.sh
# RUN: echo '[ "$0" = "%t.dir/my_driver.sh" ] || exit' >> %t.dir/my_driver.sh
# RUN: echo 'args="$*"' >> %t.dir/my_driver.sh
# RUN: echo '[ -z "${args##*"-nostdinc"*}" ] || exit' >> %t.dir/my_driver.sh
# RUN: echo '[ -z "${args##*"-isysroot=/isysroot"*}" ] || exit' >> %t.dir/my_driver.sh
# RUN: echo 'echo " $* " | grep " --sysroot /my/sysroot/path " || exit' >> %t.dir/my_driver.sh
# RUN: echo 'echo line to ignore >&2' >> %t.dir/my_driver.sh
# RUN: echo 'printf "Target: arm-linux-gnueabihf\r\n" >&2' >> %t.dir/my_driver.sh
# RUN: echo 'printf "#include <...> search starts here:\r\n" >&2' >> %t.dir/my_driver.sh
# RUN: echo 'echo %t.dir/my/dir/ >&2' >> %t.dir/my_driver.sh
# RUN: echo 'echo %t.dir/my/dir2/ >&2' >> %t.dir/my_driver.sh
# RUN: echo 'printf "End of search list.\r\n" >&2' >> %t.dir/my_driver.sh
# RUN: chmod +x %t.dir/my_driver.sh
# RUN: echo '#!/bin/sh' >> %t.dir/bin/my_driver.sh
# RUN: echo '[ "$0" = "%t.dir/bin/my_driver.sh" ] || exit' >> %t.dir/bin/my_driver.sh
# RUN: echo 'args="$*"' >> %t.dir/bin/my_driver.sh
# RUN: echo '[ -z "${args##*"-nostdinc"*}" ] || exit' >> %t.dir/bin/my_driver.sh
# RUN: echo '[ -z "${args##*"-isysroot=/isysroot"*}" ] || exit' >> %t.dir/bin/my_driver.sh
# RUN: echo 'echo " $* " | grep " --sysroot /my/sysroot/path " || exit' >> %t.dir/bin/my_driver.sh
# RUN: echo 'echo line to ignore >&2' >> %t.dir/bin/my_driver.sh
# RUN: echo 'printf "Target: arm-linux-gnueabihf\r\n" >&2' >> %t.dir/bin/my_driver.sh
# RUN: echo 'printf "#include <...> search starts here:\r\n" >&2' >> %t.dir/bin/my_driver.sh
# RUN: echo 'echo %t.dir/my/dir/ >&2' >> %t.dir/bin/my_driver.sh
# RUN: echo 'echo %t.dir/my/dir2/ >&2' >> %t.dir/bin/my_driver.sh
# RUN: echo 'printf "End of search list.\r\n" >&2' >> %t.dir/bin/my_driver.sh
# RUN: chmod +x %t.dir/bin/my_driver.sh

# Create header files my/dir/a.h and my/dir2/b.h
# RUN: mkdir -p %t.dir/my/dir
Expand All @@ -27,7 +30,7 @@

# Generate a compile_commands.json that will query the mock driver we've
# created. Which should add a.h and b.h into include search path.
# RUN: echo '[{"directory": "%/t.dir", "command": "%/t.dir/my_driver.sh the-file.cpp -nostdinc --sysroot /my/sysroot/path -isysroot=/isysroot", "file": "the-file.cpp"}]' > %t.dir/compile_commands.json
# RUN: echo '[{"directory": "%/t.dir", "command": "my_driver.sh the-file.cpp -nostdinc --sysroot /my/sysroot/path -isysroot=/isysroot", "file": "the-file.cpp"}]' > %t.dir/compile_commands.json

# RUN: sed -e "s|INPUT_DIR|%/t.dir|g" %s > %t.test.1
# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
Expand Down
12 changes: 11 additions & 1 deletion clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ std::vector<SymbolInformation> getSymbols(TestTU &TU, llvm::StringRef Query,
return *SymbolInfos;
}

TEST(WorkspaceSymbols, Macros) {
// FIXME: We update two indexes during main file processing:
// - preamble index (static)
// - main-file index (dynamic)
// The macro in this test appears to be in the preamble index and not
// in the main-file index. According to our logic of indexes merging, we
// do not take this macro from the static (preamble) index, because it
// location within the file from the dynamic (main-file) index.
//
// Possible solution is to exclude main-file symbols from the preamble
// index, after that we can enable this test again.
TEST(WorkspaceSymbols, DISABLED_Macros) {
TestTU TU;
TU.Code = R"cpp(
#define MACRO X
Expand Down
33 changes: 33 additions & 0 deletions clang-tools-extra/clangd/unittests/IndexTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,39 @@ TEST(MergeIndexTest, FuzzyFind) {
UnorderedElementsAre("ns::A", "ns::B", "ns::C"));
}

TEST(MergeIndexTest, FuzzyFindRemovedSymbol) {
FileIndex DynamicIndex, StaticIndex;
MergedIndex Merge(&DynamicIndex, &StaticIndex);

const char *HeaderCode = "class Foo;";
auto HeaderSymbols = TestTU::withHeaderCode(HeaderCode).headerSymbols();
auto Foo = findSymbol(HeaderSymbols, "Foo");

// Build static index for test.cc with Foo symbol
TestTU Test;
Test.HeaderCode = HeaderCode;
Test.Code = "class Foo {};";
Test.Filename = "test.cc";
auto AST = Test.build();
StaticIndex.updateMain(testPath(Test.Filename), AST);

// Remove Foo symbol, i.e. build dynamic index for test.cc, which is empty.
Test.HeaderCode = "";
Test.Code = "";
AST = Test.build();
DynamicIndex.updateMain(testPath(Test.Filename), AST);

// Merged index should not return removed symbol.
FuzzyFindRequest Req;
Req.AnyScope = true;
Req.Query = "Foo";
unsigned SymbolCounter = 0;
bool IsIncomplete =
Merge.fuzzyFind(Req, [&](const Symbol &) { ++SymbolCounter; });
EXPECT_FALSE(IsIncomplete);
EXPECT_EQ(SymbolCounter, 0u);
}

TEST(MergeTest, Merge) {
Symbol L, R;
L.ID = R.ID = SymbolID("hello");
Expand Down
7 changes: 4 additions & 3 deletions clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ TEST_F(TUSchedulerTests, CommandLineWarnings) {

TEST(DebouncePolicy, Compute) {
namespace c = std::chrono;
std::vector<DebouncePolicy::clock::duration> History = {
DebouncePolicy::clock::duration History[] = {
c::seconds(0),
c::seconds(5),
c::seconds(10),
Expand All @@ -1053,8 +1053,9 @@ TEST(DebouncePolicy, Compute) {
Policy.Max = c::seconds(25);
// Call Policy.compute(History) and return seconds as a float.
auto Compute = [&](llvm::ArrayRef<DebouncePolicy::clock::duration> History) {
using FloatingSeconds = c::duration<float, c::seconds::period>;
return static_cast<float>(Policy.compute(History) / FloatingSeconds(1));
return c::duration_cast<c::duration<float, c::seconds::period>>(
Policy.compute(History))
.count();
};
EXPECT_NEAR(10, Compute(History), 0.01) << "(upper) median = 10";
Policy.RebuildRatio = 1.5;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s bugprone-suspicious-semicolon %t -- -- -std=c++17
// RUN: %check_clang_tidy -std=c++17-or-later %s bugprone-suspicious-semicolon %t

void fail()
{
Expand Down
Loading

0 comments on commit 294f18d

Please sign in to comment.