Skip to content

Commit

Permalink
Merged master:170ee645f4d into amd-gfx:817733143d1
Browse files Browse the repository at this point in the history
Local branch amd-gfx 8177331 Merged master:6dad5e441db into amd-gfx:e29b386cb9a
Remote branch master 170ee64 [clang-tidy] Link shared library clangTidyOpenMPModule to library LLVMFrontendOpenMP
  • Loading branch information
Sw authored and Sw committed Dec 11, 2019
2 parents 8177331 + 170ee64 commit 9333d68
Show file tree
Hide file tree
Showing 1,046 changed files with 28,296 additions and 8,915 deletions.
1 change: 1 addition & 0 deletions clang-tools-extra/clang-tidy/openmp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ add_clang_library(clangTidyOpenMPModule
clangBasic
clangTidy
clangTidyUtils
LLVMFrontendOpenMP
)
7 changes: 6 additions & 1 deletion clang-tools-extra/clangd/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ bool isImplementationDetail(const Decl *D) {
D->getASTContext().getSourceManager());
}

SourceLocation findName(const clang::Decl *D) { return D->getLocation(); }
SourceLocation nameLocation(const clang::Decl &D, const SourceManager &SM) {
auto L = D.getLocation();
if (isSpelledInSource(L, SM))
return SM.getSpellingLoc(L);
return SM.getExpansionLoc(L);
}

std::string printQualifiedName(const NamedDecl &ND) {
std::string QName;
Expand Down
10 changes: 5 additions & 5 deletions clang-tools-extra/clangd/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ namespace clangd {
/// in code is considered implementation detail.
bool isImplementationDetail(const Decl *D);

/// Find the identifier source location of the given D.
///
/// The returned location is usually the spelling location where the name of the
/// decl occurs in the code.
SourceLocation findName(const clang::Decl *D);
/// Find the source location of the identifier for \p D.
/// Transforms macro locations to locations spelled inside files. All code
/// that needs locations of declaration names (e.g. the index) should go through
/// this function.
SourceLocation nameLocation(const clang::Decl &D, const SourceManager &SM);

/// Returns the qualified name of ND. The scope doesn't contain unwritten scopes
/// like inline namespaces.
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/FindSymbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace {
llvm::Optional<DocumentSymbol> declToSym(ASTContext &Ctx, const NamedDecl &ND) {
auto &SM = Ctx.getSourceManager();

SourceLocation NameLoc = spellingLocIfSpelled(findName(&ND), SM);
SourceLocation NameLoc = nameLocation(ND, SM);
// getFileLoc is a good choice for us, but we also need to make sure
// sourceLocToPosition won't switch files, so we call getSpellingLoc on top of
// that to make sure it does not switch files.
Expand Down
8 changes: 0 additions & 8 deletions clang-tools-extra/clangd/SourceCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,6 @@ bool isSpelledInSource(SourceLocation Loc, const SourceManager &SM) {
return true;
}

SourceLocation spellingLocIfSpelled(SourceLocation Loc,
const SourceManager &SM) {
if (!isSpelledInSource(Loc, SM))
// Use the expansion location as spelling location is not interesting.
return SM.getExpansionRange(Loc).getBegin();
return SM.getSpellingLoc(Loc);
}

llvm::Optional<Range> getTokenRange(const SourceManager &SM,
const LangOptions &LangOpts,
SourceLocation TokLoc) {
Expand Down
6 changes: 0 additions & 6 deletions clang-tools-extra/clangd/SourceCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ SourceLocation includeHashLoc(FileID IncludedFile, const SourceManager &SM);
/// `-DName=foo`, the spelling location will be "<command line>".
bool isSpelledInSource(SourceLocation Loc, const SourceManager &SM);

/// Returns the spelling location of the token at Loc if isSpelledInSource,
/// otherwise its expansion location.
/// FIXME: Most callers likely want some variant of "file location" instead.
SourceLocation spellingLocIfSpelled(SourceLocation Loc,
const SourceManager &SM);

/// Turns a token range into a half-open range and checks its correctness.
/// The resulting range will have only valid source location on both sides, both
/// of which are file locations.
Expand Down
6 changes: 2 additions & 4 deletions clang-tools-extra/clangd/XRefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ std::vector<LocatedSymbol> locateSymbolAt(ParsedAST &AST, Position Pos,
}
}

auto Loc = makeLocation(AST.getASTContext(),
spellingLocIfSpelled(findName(Preferred), SM),
auto Loc = makeLocation(AST.getASTContext(), nameLocation(*Preferred, SM),
*MainFilePath);
if (!Loc)
continue;
Expand Down Expand Up @@ -535,8 +534,7 @@ static llvm::Optional<TypeHierarchyItem>
declToTypeHierarchyItem(ASTContext &Ctx, const NamedDecl &ND) {
auto &SM = Ctx.getSourceManager();

SourceLocation NameLoc =
spellingLocIfSpelled(findName(&ND), Ctx.getSourceManager());
SourceLocation NameLoc = nameLocation(ND, Ctx.getSourceManager());
// getFileLoc is a good choice for us, but we also need to make sure
// sourceLocToPosition won't switch files, so we call getSpellingLoc on top of
// that to make sure it does not switch files.
Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clangd/index/SymbolCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static const char *PROTO_HEADER_COMMENT =
// filters.
bool isPrivateProtoDecl(const NamedDecl &ND) {
const auto &SM = ND.getASTContext().getSourceManager();
auto Loc = spellingLocIfSpelled(findName(&ND), SM);
auto Loc = nameLocation(ND, SM);
auto FileName = SM.getFilename(Loc);
if (!FileName.endswith(".proto.h") && !FileName.endswith(".pb.h"))
return false;
Expand Down Expand Up @@ -595,7 +595,7 @@ const Symbol *SymbolCollector::addDeclaration(const NamedDecl &ND, SymbolID ID,
S.Flags |= Symbol::VisibleOutsideFile;
S.SymInfo = index::getSymbolInfo(&ND);
std::string FileURI;
auto Loc = spellingLocIfSpelled(findName(&ND), SM);
auto Loc = nameLocation(ND, SM);
assert(Loc.isValid() && "Invalid source location for NamedDecl");
// FIXME: use the result to filter out symbols.
shouldIndexFile(SM.getFileID(Loc));
Expand Down Expand Up @@ -656,7 +656,7 @@ void SymbolCollector::addDefinition(const NamedDecl &ND,
Symbol S = DeclSym;
std::string FileURI;
const auto &SM = ND.getASTContext().getSourceManager();
auto Loc = spellingLocIfSpelled(findName(&ND), SM);
auto Loc = nameLocation(ND, SM);
// FIXME: use the result to filter out symbols.
shouldIndexFile(SM.getFileID(Loc));
if (auto DefLoc =
Expand Down
15 changes: 12 additions & 3 deletions clang-tools-extra/clangd/refactor/Rename.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,12 @@ findOccurrencesOutsideFile(const NamedDecl &RenameDecl,
RenameDecl.getQualifiedNameAsString()),
llvm::inconvertibleErrorCode());
}

// Sort and deduplicate the results, in case that index returns duplications.
for (auto &FileAndOccurrences : AffectedFiles) {
auto &Ranges = FileAndOccurrences.getValue();
llvm::sort(Ranges);
Ranges.erase(std::unique(Ranges.begin(), Ranges.end()), Ranges.end());
}
return AffectedFiles;
}

Expand Down Expand Up @@ -514,7 +519,11 @@ llvm::Expected<Edit> buildRenameEdit(llvm::StringRef AbsFilePath,
llvm::StringRef InitialCode,
std::vector<Range> Occurrences,
llvm::StringRef NewName) {
llvm::sort(Occurrences);
assert(std::is_sorted(Occurrences.begin(), Occurrences.end()));
assert(std::unique(Occurrences.begin(), Occurrences.end()) ==
Occurrences.end() &&
"Occurrences must be unique");

// These two always correspond to the same position.
Position LastPos{0, 0};
size_t LastOffset = 0;
Expand Down Expand Up @@ -574,9 +583,9 @@ llvm::Optional<std::vector<Range>>
adjustRenameRanges(llvm::StringRef DraftCode, llvm::StringRef Identifier,
std::vector<Range> Indexed, const LangOptions &LangOpts) {
assert(!Indexed.empty());
assert(std::is_sorted(Indexed.begin(), Indexed.end()));
std::vector<Range> Lexed =
collectIdentifierRanges(Identifier, DraftCode, LangOpts);
llvm::sort(Indexed);
llvm::sort(Lexed);
return getMappedRanges(Indexed, Lexed);
}
Expand Down
2 changes: 2 additions & 0 deletions clang-tools-extra/clangd/refactor/Rename.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ llvm::Expected<FileEdits> rename(const RenameInputs &RInputs);
/// Generates rename edits that replaces all given occurrences with the
/// NewName.
/// Exposed for testing only.
/// REQUIRED: Occurrences is sorted and doesn't have duplicated ranges.
llvm::Expected<Edit> buildRenameEdit(llvm::StringRef AbsFilePath,
llvm::StringRef InitialCode,
std::vector<Range> Occurrences,
Expand All @@ -65,6 +66,7 @@ llvm::Expected<Edit> buildRenameEdit(llvm::StringRef AbsFilePath,
///
/// The API assumes that Indexed contains only named occurrences (each
/// occurrence has the same length).
/// REQUIRED: Indexed is sorted.
llvm::Optional<std::vector<Range>>
adjustRenameRanges(llvm::StringRef DraftCode, llvm::StringRef Identifier,
std::vector<Range> Indexed, const LangOptions &LangOpts);
Expand Down
83 changes: 68 additions & 15 deletions clang-tools-extra/clangd/unittests/RenameTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ using testing::IsEmpty;
using testing::UnorderedElementsAre;
using testing::UnorderedElementsAreArray;

// Covnert a Range to a Ref.
Ref refWithRange(const clangd::Range &Range, const std::string &URI) {
Ref Result;
Result.Kind = RefKind::Reference;
Result.Location.Start.setLine(Range.start.line);
Result.Location.Start.setColumn(Range.start.character);
Result.Location.End.setLine(Range.end.line);
Result.Location.End.setColumn(Range.end.character);
Result.Location.FileURI = URI.c_str();
return Result;
}

// Build a RefSlab from all marked ranges in the annotation. The ranges are
// assumed to associate with the given SymbolName.
std::unique_ptr<RefSlab> buildRefSlab(const Annotations &Code,
Expand All @@ -40,17 +52,9 @@ std::unique_ptr<RefSlab> buildRefSlab(const Annotations &Code,
TU.HeaderCode = Code.code();
auto Symbols = TU.headerSymbols();
const auto &SymbolID = findSymbol(Symbols, SymbolName).ID;
for (const auto &Range : Code.ranges()) {
Ref R;
R.Kind = RefKind::Reference;
R.Location.Start.setLine(Range.start.line);
R.Location.Start.setColumn(Range.start.character);
R.Location.End.setLine(Range.end.line);
R.Location.End.setColumn(Range.end.character);
auto U = URI::create(Path).toString();
R.Location.FileURI = U.c_str();
Builder.insert(SymbolID, R);
}
std::string PathURI = URI::create(Path).toString();
for (const auto &Range : Code.ranges())
Builder.insert(SymbolID, refWithRange(Range, PathURI));

return std::make_unique<RefSlab>(std::move(Builder).build());
}
Expand Down Expand Up @@ -664,6 +668,54 @@ TEST(CrossFileRenameTests, DirtyBuffer) {
testing::HasSubstr("too many occurrences"));
}

TEST(CrossFileRenameTests, DeduplicateRefsFromIndex) {
auto MainCode = Annotations("int [[^x]] = 2;");
auto MainFilePath = testPath("main.cc");
auto BarCode = Annotations("int [[x]];");
auto BarPath = testPath("bar.cc");
auto TU = TestTU::withCode(MainCode.code());
// Set a file "bar.cc" on disk.
TU.AdditionalFiles["bar.cc"] = BarCode.code();
auto AST = TU.build();
std::string BarPathURI = URI::create(BarPath).toString();
Ref XRefInBarCC = refWithRange(BarCode.range(), BarPathURI);
// The index will return duplicated refs, our code should be robost to handle
// it.
class DuplicatedXRefIndex : public SymbolIndex {
public:
DuplicatedXRefIndex(const Ref &ReturnedRef) : ReturnedRef(ReturnedRef) {}
bool refs(const RefsRequest &Req,
llvm::function_ref<void(const Ref &)> Callback) const override {
// Return two duplicated refs.
Callback(ReturnedRef);
Callback(ReturnedRef);
return false;
}

bool fuzzyFind(const FuzzyFindRequest &,
llvm::function_ref<void(const Symbol &)>) const override {
return false;
}
void lookup(const LookupRequest &,
llvm::function_ref<void(const Symbol &)>) const override {}

void relations(const RelationsRequest &,
llvm::function_ref<void(const SymbolID &, const Symbol &)>)
const override {}
size_t estimateMemoryUsage() const override { return 0; }
Ref ReturnedRef;
} DIndex(XRefInBarCC);
llvm::StringRef NewName = "newName";
auto Results = rename({MainCode.point(), NewName, AST, MainFilePath, &DIndex,
/*CrossFile=*/true});
ASSERT_TRUE(bool(Results)) << Results.takeError();
EXPECT_THAT(
applyEdits(std::move(*Results)),
UnorderedElementsAre(
Pair(Eq(BarPath), Eq(expectedResult(BarCode, NewName))),
Pair(Eq(MainFilePath), Eq(expectedResult(MainCode, NewName)))));
}

TEST(CrossFileRenameTests, WithUpToDateIndex) {
MockCompilationDatabase CDB;
CDB.ExtraClangFlags = {"-xc++"};
Expand Down Expand Up @@ -832,15 +884,16 @@ TEST(CrossFileRenameTests, BuildRenameEdits) {
Annotations Code("[[😂]]");
auto LSPRange = Code.range();
llvm::StringRef FilePath = "/test/TestTU.cpp";
auto Edit = buildRenameEdit(FilePath, Code.code(), {LSPRange}, "abc");
llvm::StringRef NewName = "abc";
auto Edit = buildRenameEdit(FilePath, Code.code(), {LSPRange}, NewName);
ASSERT_TRUE(bool(Edit)) << Edit.takeError();
ASSERT_EQ(1UL, Edit->Replacements.size());
EXPECT_EQ(FilePath, Edit->Replacements.begin()->getFilePath());
EXPECT_EQ(4UL, Edit->Replacements.begin()->getLength());

// Test invalid range.
LSPRange.end = {10, 0}; // out of range
Edit = buildRenameEdit(FilePath, Code.code(), {LSPRange}, "abc");
Edit = buildRenameEdit(FilePath, Code.code(), {LSPRange}, NewName);
EXPECT_FALSE(Edit);
EXPECT_THAT(llvm::toString(Edit.takeError()),
testing::HasSubstr("fail to convert"));
Expand All @@ -851,10 +904,10 @@ TEST(CrossFileRenameTests, BuildRenameEdits) {
[[range]]
[[range]]
)cpp");
Edit = buildRenameEdit(FilePath, T.code(), T.ranges(), "abc");
Edit = buildRenameEdit(FilePath, T.code(), T.ranges(), NewName);
ASSERT_TRUE(bool(Edit)) << Edit.takeError();
EXPECT_EQ(applyEdits(FileEdits{{T.code(), std::move(*Edit)}}).front().second,
expectedResult(Code, expectedResult(T, "abc")));
expectedResult(T, NewName));
}

TEST(CrossFileRenameTests, adjustRenameRanges) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %check_clang_tidy %s -std=c++14 cert-mem57-cpp %t
// RUN: clang-tidy --extra-arg='-std=c++17' --extra-arg='-faligned-allocation' -checks='-*,cert-mem57-cpp' --warnings-as-errors='*' %s
// RUN: clang-tidy --extra-arg='-std=c++2a' --extra-arg='-faligned-allocation' -checks='-*,cert-mem57-cpp' --warnings-as-errors='*' %s
// RUN: clang-tidy --extra-arg='-std=c++17' --extra-arg='-faligned-allocation' -checks='-*,cert-mem57-cpp' --extra-arg=-Wno-unused-variable --warnings-as-errors='*' %s
// RUN: clang-tidy --extra-arg='-std=c++2a' --extra-arg='-faligned-allocation' -checks='-*,cert-mem57-cpp' --extra-arg=-Wno-unused-variable --warnings-as-errors='*' %s

struct alignas(128) Vector {
char Elems[128];
Expand Down
15 changes: 13 additions & 2 deletions clang/docs/ClangCommandLineReference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1699,9 +1699,14 @@ Emit OpenMP code only for SIMD-based constructs.

.. option:: -foperator-arrow-depth=<arg>

.. option:: -foptimization-record-file=<arg>
.. option:: -foptimization-record-file=<file>

Specify the file name of any generated YAML optimization record
Implies -fsave-optimization-record. On Darwin platforms, this
cannot be used with multiple -arch <arch> options.

.. option:: -foptimization-record-passes=<regex>

Only include passes which match a specified regular expression in the generated optimization record (by default, include all passes)

.. option:: -foptimize-sibling-calls, -fno-optimize-sibling-calls

Expand Down Expand Up @@ -1834,6 +1839,12 @@ Turn on loop reroller

Generate a YAML optimization record file

.. program:: clang1
.. option:: -fsave-optimization-record=<format>
.. program:: clang

Generate an optimization record file in a specific format.

.. option:: -fseh-exceptions

Use SEH style exceptions
Expand Down
Loading

0 comments on commit 9333d68

Please sign in to comment.