[clang-tools-extra] r339320 - [clangd] Record the file being processed in a TUScheduler thread in context.
Author: ioeric Date: Thu Aug 9 02:05:45 2018 New Revision: 339320 URL: http://llvm.org/viewvc/llvm-project?rev=339320&view=rev Log: [clangd] Record the file being processed in a TUScheduler thread in context. Summary: This allows implementations like different symbol indexes to know what the current active file is. For example, some customized index implementation might decide to only return results for some files. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: javed.absar, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D50446 Modified: clang-tools-extra/trunk/clangd/TUScheduler.cpp clang-tools-extra/trunk/clangd/TUScheduler.h clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp Modified: clang-tools-extra/trunk/clangd/TUScheduler.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/TUScheduler.cpp?rev=339320&r1=339319&r2=339320&view=diff == --- clang-tools-extra/trunk/clangd/TUScheduler.cpp (original) +++ clang-tools-extra/trunk/clangd/TUScheduler.cpp Thu Aug 9 02:05:45 2018 @@ -63,6 +63,14 @@ namespace { class ASTWorker; } +static const clang::clangd::Key kFileBeingProcessed; + +llvm::Optional TUScheduler::getFileBeingProcessedInContext() { + if (auto *File = Context::current().get(kFileBeingProcessed)) +return StringRef(*File); + return llvm::None; +} + /// An LRU cache of idle ASTs. /// Because we want to limit the overall number of these we retain, the cache /// owns ASTs (and may evict them) while their workers are idle. @@ -491,8 +499,9 @@ void ASTWorker::startTask(llvm::StringRe { std::lock_guard Lock(Mutex); assert(!Done && "running a task after stop()"); -Requests.push_back({std::move(Task), Name, steady_clock::now(), -Context::current().clone(), UpdateType}); +Requests.push_back( +{std::move(Task), Name, steady_clock::now(), + Context::current().derive(kFileBeingProcessed, FileName), UpdateType}); } RequestsCV.notify_all(); } @@ -734,10 +743,12 @@ void TUScheduler::runWithPreamble( Action(InputsAndPreamble{Contents, Command, Preamble.get()}); }; - PreambleTasks->runAsync("task:" + llvm::sys::path::filename(File), - Bind(Task, std::string(Name), std::string(File), - It->second->Contents, It->second->Command, - Context::current().clone(), std::move(Action))); + PreambleTasks->runAsync( + "task:" + llvm::sys::path::filename(File), + Bind(Task, std::string(Name), std::string(File), It->second->Contents, + It->second->Command, + Context::current().derive(kFileBeingProcessed, File), + std::move(Action))); } std::vector> Modified: clang-tools-extra/trunk/clangd/TUScheduler.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/TUScheduler.h?rev=339320&r1=339319&r2=339320&view=diff == --- clang-tools-extra/trunk/clangd/TUScheduler.h (original) +++ clang-tools-extra/trunk/clangd/TUScheduler.h Thu Aug 9 02:05:45 2018 @@ -122,6 +122,13 @@ public: /// an LRU cache. class ASTCache; + // The file being built/processed in the current thread. This is a hack in + // order to get the file name into the index implementations. Do not depend on + // this inside clangd. + // FIXME: remove this when there is proper index support via build system + // integration. + static llvm::Optional getFileBeingProcessedInContext(); + private: const bool StorePreamblesInMemory; const std::shared_ptr PCHOps; @@ -135,6 +142,7 @@ private: llvm::Optional WorkerThreads; std::chrono::steady_clock::duration UpdateDebounce; }; + } // namespace clangd } // namespace clang Modified: clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp?rev=339320&r1=339319&r2=339320&view=diff == --- clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp Thu Aug 9 02:05:45 2018 @@ -197,20 +197,22 @@ TEST_F(TUSchedulerTests, ManyUpdates) { { WithContextValue WithNonce(NonceKey, ++Nonce); S.update(File, Inputs, WantDiagnostics::Auto, - [Nonce, &Mut, + [File, Nonce, &Mut, &TotalUpdates](llvm::Optional> Diags) { EXPECT_THAT(Context::current().get(NonceKey), Pointee(Nonce)); std::lock_guard Lock(Mut); ++TotalUpdates; + EXPECT_EQ(File, +
[clang-tools-extra] r339322 - [clangd] Try to fix buildbot after r339320.
Author: ioeric Date: Thu Aug 9 02:25:26 2018 New Revision: 339322 URL: http://llvm.org/viewvc/llvm-project?rev=339322&view=rev Log: [clangd] Try to fix buildbot after r339320. http://lab.llvm.org:8011/builders/clang-cmake-armv8-quick/builds/5487 Modified: clang-tools-extra/trunk/clangd/TUScheduler.cpp Modified: clang-tools-extra/trunk/clangd/TUScheduler.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/TUScheduler.cpp?rev=339322&r1=339321&r2=339322&view=diff == --- clang-tools-extra/trunk/clangd/TUScheduler.cpp (original) +++ clang-tools-extra/trunk/clangd/TUScheduler.cpp Thu Aug 9 02:25:26 2018 @@ -63,7 +63,7 @@ namespace { class ASTWorker; } -static const clang::clangd::Key kFileBeingProcessed; +static clang::clangd::Key kFileBeingProcessed; llvm::Optional TUScheduler::getFileBeingProcessedInContext() { if (auto *File = Context::current().get(kFileBeingProcessed)) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r331923 - Add SourceManagerForFile helper which sets up SourceManager and dependencies for a single file with code snippet
Author: ioeric Date: Wed May 9 14:35:52 2018 New Revision: 331923 URL: http://llvm.org/viewvc/llvm-project?rev=331923&view=rev Log: Add SourceManagerForFile helper which sets up SourceManager and dependencies for a single file with code snippet Summary: This can be used to create a virtual environment (incl. VFS, source manager) for code snippets. Reviewers: sammccall, klimek Reviewed By: sammccall Subscribers: klimek, mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D46176 Modified: cfe/trunk/include/clang/Basic/SourceManager.h cfe/trunk/lib/Basic/SourceManager.cpp cfe/trunk/lib/Format/Format.cpp cfe/trunk/lib/Format/SortJavaScriptImports.cpp cfe/trunk/lib/Format/TokenAnalyzer.cpp cfe/trunk/lib/Format/TokenAnalyzer.h Modified: cfe/trunk/include/clang/Basic/SourceManager.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=331923&r1=331922&r2=331923&view=diff == --- cfe/trunk/include/clang/Basic/SourceManager.h (original) +++ cfe/trunk/include/clang/Basic/SourceManager.h Wed May 9 14:35:52 2018 @@ -35,6 +35,7 @@ #ifndef LLVM_CLANG_BASIC_SOURCEMANAGER_H #define LLVM_CLANG_BASIC_SOURCEMANAGER_H +#include "clang/Basic/Diagnostic.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/ArrayRef.h" @@ -60,7 +61,6 @@ namespace clang { class ASTReader; class ASTWriter; -class DiagnosticsEngine; class LineTableInfo; class SourceManager; @@ -1815,6 +1815,28 @@ public: } }; +/// SourceManager and necessary depdencies (e.g. VFS, FileManager) for a single +/// in-memorty file. +class SourceManagerForFile { +public: + /// Creates SourceManager and necessary depdencies (e.g. VFS, FileManager). + /// The main file in the SourceManager will be \p FileName with \p Content. + SourceManagerForFile(StringRef FileName, StringRef Content); + + SourceManager &get() { +assert(SourceMgr); +return *SourceMgr; + } + +private: + // The order of these fields are important - they should be in the same order + // as they are created in `createSourceManagerForFile` so that they can be + // deleted in the reverse order as they are created. + std::unique_ptr FileMgr; + std::unique_ptr Diagnostics; + std::unique_ptr SourceMgr; +}; + } // namespace clang #endif // LLVM_CLANG_BASIC_SOURCEMANAGER_H Modified: cfe/trunk/lib/Basic/SourceManager.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=331923&r1=331922&r2=331923&view=diff == --- cfe/trunk/lib/Basic/SourceManager.cpp (original) +++ cfe/trunk/lib/Basic/SourceManager.cpp Wed May 9 14:35:52 2018 @@ -2258,3 +2258,29 @@ size_t SourceManager::getDataStructureSi return size; } + +SourceManagerForFile::SourceManagerForFile(StringRef FileName, + StringRef Content) { + // This is referenced by `FileMgr` and will be released by `FileMgr` when it + // is deleted. + IntrusiveRefCntPtr InMemoryFileSystem( + new vfs::InMemoryFileSystem); + InMemoryFileSystem->addFile( + FileName, 0, + llvm::MemoryBuffer::getMemBuffer(Content, FileName, + /*RequiresNullTerminator=*/false)); + // This is passed to `SM` as reference, so the pointer has to be referenced + // in `Environment` so that `FileMgr` can out-live this function scope. + FileMgr = + llvm::make_unique(FileSystemOptions(), InMemoryFileSystem); + // This is passed to `SM` as reference, so the pointer has to be referenced + // by `Environment` due to the same reason above. + Diagnostics = llvm::make_unique( + IntrusiveRefCntPtr(new DiagnosticIDs), + new DiagnosticOptions); + SourceMgr = llvm::make_unique(*Diagnostics, *FileMgr); + FileID ID = SourceMgr->createFileID(FileMgr->getFile(FileName), + SourceLocation(), clang::SrcMgr::C_User); + assert(ID.isValid()); + SourceMgr->setMainFileID(ID); +} Modified: cfe/trunk/lib/Format/Format.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=331923&r1=331922&r2=331923&view=diff == --- cfe/trunk/lib/Format/Format.cpp (original) +++ cfe/trunk/lib/Format/Format.cpp Wed May 9 14:35:52 2018 @@ -1905,10 +1905,9 @@ unsigned getOffsetAfterTokenSequence( StringRef FileName, StringRef Code, const FormatStyle &Style, llvm::function_ref GetOffsetAfterSequence) { - std::unique_ptr Env = - Environment::CreateVirtualEnvironment(Code, FileName, /*Ranges=*/{}); - const SourceManager &SourceMgr = Env->getSourceManager(); - Lexer Lex(Env->getFileID(), SourceMgr.getBuffer(Env->getFileID()), SourceMgr, + Environment Env(Code, FileName, /*Ranges=*/{}); + const SourceMana
[clang-tools-extra] r332089 - [clangd] Move helpers that convert Replacements to TextEdits to SourceCode.h
Author: ioeric Date: Fri May 11 05:12:08 2018 New Revision: 332089 URL: http://llvm.org/viewvc/llvm-project?rev=332089&view=rev Log: [clangd] Move helpers that convert Replacements to TextEdits to SourceCode.h Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: klimek, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D46670 Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp clang-tools-extra/trunk/clangd/SourceCode.cpp clang-tools-extra/trunk/clangd/SourceCode.h Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=332089&r1=332088&r2=332089&view=diff == --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Fri May 11 05:12:08 2018 @@ -60,32 +60,6 @@ public: static URISchemeRegistry::Add X("test", "Test scheme for clangd lit tests."); -TextEdit replacementToEdit(StringRef Code, const tooling::Replacement &R) { - Range ReplacementRange = { - offsetToPosition(Code, R.getOffset()), - offsetToPosition(Code, R.getOffset() + R.getLength())}; - return {ReplacementRange, R.getReplacementText()}; -} - -std::vector -replacementsToEdits(StringRef Code, -const std::vector &Replacements) { - // Turn the replacements into the format specified by the Language Server - // Protocol. Fuse them into one big JSON array. - std::vector Edits; - for (const auto &R : Replacements) -Edits.push_back(replacementToEdit(Code, R)); - return Edits; -} - -std::vector replacementsToEdits(StringRef Code, - const tooling::Replacements &Repls) { - std::vector Edits; - for (const auto &R : Repls) -Edits.push_back(replacementToEdit(Code, R)); - return Edits; -} - SymbolKindBitset defaultSymbolKinds() { SymbolKindBitset Defaults; for (size_t I = SymbolKindMin; I <= static_cast(SymbolKind::Array); @@ -291,7 +265,11 @@ void ClangdLSPServer::onRename(RenamePar return replyError(ErrorCode::InternalError, llvm::toString(Replacements.takeError())); -std::vector Edits = replacementsToEdits(*Code, *Replacements); +// Turn the replacements into the format specified by the Language +// Server Protocol. Fuse them into one big JSON array. +std::vector Edits; +for (const auto &R : *Replacements) + Edits.push_back(replacementToEdit(*Code, R)); WorkspaceEdit WE; WE.changes = {{Params.textDocument.uri.uri(), Edits}}; reply(WE); Modified: clang-tools-extra/trunk/clangd/SourceCode.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SourceCode.cpp?rev=332089&r1=332088&r2=332089&view=diff == --- clang-tools-extra/trunk/clangd/SourceCode.cpp (original) +++ clang-tools-extra/trunk/clangd/SourceCode.cpp Fri May 11 05:12:08 2018 @@ -166,5 +166,20 @@ splitQualifiedName(llvm::StringRef QName return {QName.substr(0, Pos + 2), QName.substr(Pos + 2)}; } +TextEdit replacementToEdit(StringRef Code, const tooling::Replacement &R) { + Range ReplacementRange = { + offsetToPosition(Code, R.getOffset()), + offsetToPosition(Code, R.getOffset() + R.getLength())}; + return {ReplacementRange, R.getReplacementText()}; +} + +std::vector replacementsToEdits(StringRef Code, + const tooling::Replacements &Repls) { + std::vector Edits; + for (const auto &R : Repls) +Edits.push_back(replacementToEdit(Code, R)); + return Edits; +} + } // namespace clangd } // namespace clang Modified: clang-tools-extra/trunk/clangd/SourceCode.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SourceCode.h?rev=332089&r1=332088&r2=332089&view=diff == --- clang-tools-extra/trunk/clangd/SourceCode.h (original) +++ clang-tools-extra/trunk/clangd/SourceCode.h Fri May 11 05:12:08 2018 @@ -15,6 +15,7 @@ #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SOURCECODE_H #include "Protocol.h" #include "clang/Basic/SourceLocation.h" +#include "clang/Tooling/Core/Replacement.h" namespace clang { class SourceManager; @@ -55,6 +56,11 @@ std::pair offsetToClangL std::pair splitQualifiedName(llvm::StringRef QName); +TextEdit replacementToEdit(StringRef Code, const tooling::Replacement &R); + +std::vector replacementsToEdits(StringRef Code, + const tooling::Replacements &Repls); + } // namespace clangd } // namespace clang #endif ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r332236 - Redirect output to /dev/null in the tests added in r332160.
Author: ioeric Date: Mon May 14 05:07:56 2018 New Revision: 332236 URL: http://llvm.org/viewvc/llvm-project?rev=332236&view=rev Log: Redirect output to /dev/null in the tests added in r332160. Modified: cfe/trunk/test/Driver/clang-abi-compat.cpp Modified: cfe/trunk/test/Driver/clang-abi-compat.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang-abi-compat.cpp?rev=332236&r1=332235&r2=332236&view=diff == --- cfe/trunk/test/Driver/clang-abi-compat.cpp (original) +++ cfe/trunk/test/Driver/clang-abi-compat.cpp Mon May 14 05:07:56 2018 @@ -1,6 +1,6 @@ // PS4 target requires clang ABI version 6, check that a warning is emitted when a version other than 6 is requested. -// RUN: %clang -S --target=x86_64-scei-ps4 -fclang-abi-compat=4 %s 2>&1 | FileCheck %s -check-prefix=CHECK-WARNING -// RUN: %clang -S --target=x86_64-scei-ps4 -fclang-abi-compat=latest %s 2>&1 | FileCheck %s -check-prefix=CHECK-WARNING +// RUN: %clang -S --target=x86_64-scei-ps4 -fclang-abi-compat=4 %s -o /dev/null 2>&1 | FileCheck %s -check-prefix=CHECK-WARNING +// RUN: %clang -S --target=x86_64-scei-ps4 -fclang-abi-compat=latest %s -o /dev/null 2>&1 | FileCheck %s -check-prefix=CHECK-WARNING // REQUIRES: x86-registered-target ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r332237 - [clangd] Add helper for collecting #include directives in file.
Author: ioeric Date: Mon May 14 05:19:16 2018 New Revision: 332237 URL: http://llvm.org/viewvc/llvm-project?rev=332237&view=rev Log: [clangd] Add helper for collecting #include directives in file. Summary: Separate unit tests for the new function will be added in followup patch which will further refactor Headers.h Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D46675 Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp clang-tools-extra/trunk/clangd/ClangdUnit.h clang-tools-extra/trunk/clangd/Headers.cpp clang-tools-extra/trunk/clangd/Headers.h clang-tools-extra/trunk/clangd/XRefs.cpp Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=332237&r1=332236&r2=332237&view=diff == --- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Mon May 14 05:19:16 2018 @@ -83,44 +83,13 @@ private: std::vector TopLevelDecls; }; -class InclusionLocationsCollector : public PPCallbacks { -public: - InclusionLocationsCollector(SourceManager &SourceMgr, - InclusionLocations &IncLocations) - : SourceMgr(SourceMgr), IncLocations(IncLocations) {} - - void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, - StringRef FileName, bool IsAngled, - CharSourceRange FilenameRange, const FileEntry *File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, - SrcMgr::CharacteristicKind FileType) override { -auto SR = FilenameRange.getAsRange(); -if (SR.isInvalid() || !File || File->tryGetRealPathName().empty()) - return; - -if (SourceMgr.isInMainFile(SR.getBegin())) { - // Only inclusion directives in the main file make sense. The user cannot - // select directives not in the main file. - IncLocations.emplace_back(halfOpenToRange(SourceMgr, FilenameRange), -File->tryGetRealPathName()); -} - } - -private: - SourceManager &SourceMgr; - InclusionLocations &IncLocations; -}; - class CppFilePreambleCallbacks : public PreambleCallbacks { public: std::vector takeTopLevelDeclIDs() { return std::move(TopLevelDeclIDs); } - InclusionLocations takeInclusionLocations() { -return std::move(IncLocations); - } + std::vector takeInclusions() { return std::move(Inclusions); } void AfterPCHEmitted(ASTWriter &Writer) override { TopLevelDeclIDs.reserve(TopLevelDecls.size()); @@ -146,14 +115,15 @@ public: std::unique_ptr createPPCallbacks() override { assert(SourceMgr && "SourceMgr must be set at this point"); -return llvm::make_unique(*SourceMgr, - IncLocations); +return collectInclusionsInMainFileCallback( +*SourceMgr, +[this](Inclusion Inc) { Inclusions.push_back(std::move(Inc)); }); } private: std::vector TopLevelDecls; std::vector TopLevelDeclIDs; - InclusionLocations IncLocations; + std::vector Inclusions; SourceManager *SourceMgr = nullptr; }; @@ -191,15 +161,15 @@ ParsedAST::Build(std::unique_ptr Inclusions; // Copy over the includes from the preamble, then combine with the // non-preamble includes below. if (Preamble) -IncLocations = Preamble->IncLocations; +Inclusions = Preamble->Inclusions; - Clang->getPreprocessor().addPPCallbacks( - llvm::make_unique(Clang->getSourceManager(), - IncLocations)); + Clang->getPreprocessor().addPPCallbacks(collectInclusionsInMainFileCallback( + Clang->getSourceManager(), + [&Inclusions](Inclusion Inc) { Inclusions.push_back(std::move(Inc)); })); if (!Action->Execute()) log("Execute() failed when building AST for " + MainInput.getFile()); @@ -213,7 +183,7 @@ ParsedAST::Build(std::unique_ptr ParsedDecls = Action->takeTopLevelDecls(); return ParsedAST(std::move(Preamble), std::move(Clang), std::move(Action), std::move(ParsedDecls), ASTDiags.take(), - std::move(IncLocations)); + std::move(Inclusions)); } void ParsedAST::ensurePreambleDeclsDeserialized() { @@ -279,27 +249,27 @@ std::size_t ParsedAST::getUsedBytes() co ::getUsedBytes(TopLevelDecls) + ::getUsedBytes(Diags); } -const InclusionLocations &ParsedAST::getInclusionLocations() const { - return IncLocations; +const std::vector &ParsedAST::getInclusions() const { + return Inclusions; } PreambleData::PreambleData(PrecompiledPreamble Preamble, std::vector TopLevelDeclIDs,
r332284 - [clang-format] Move #include related style to libToolingCore
Author: ioeric Date: Mon May 14 12:51:33 2018 New Revision: 332284 URL: http://llvm.org/viewvc/llvm-project?rev=332284&view=rev Log: [clang-format] Move #include related style to libToolingCore Summary: This will be shared by include insertion/deletion library. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: mgorny, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D46758 Added: cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp Modified: cfe/trunk/include/clang/Format/Format.h cfe/trunk/lib/Format/Format.cpp cfe/trunk/lib/Tooling/Core/CMakeLists.txt cfe/trunk/unittests/Format/FormatTest.cpp cfe/trunk/unittests/Format/SortIncludesTest.cpp Modified: cfe/trunk/include/clang/Format/Format.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=332284&r1=332283&r2=332284&view=diff == --- cfe/trunk/include/clang/Format/Format.h (original) +++ cfe/trunk/include/clang/Format/Format.h Mon May 14 12:51:33 2018 @@ -16,6 +16,7 @@ #define LLVM_CLANG_FORMAT_FORMAT_H #include "clang/Basic/LangOptions.h" +#include "clang/Tooling/Core/IncludeStyle.h" #include "clang/Tooling/Core/Replacement.h" #include "llvm/ADT/ArrayRef.h" #include @@ -998,91 +999,7 @@ struct FormatStyle { /// For example: BOOST_FOREACH. std::vector ForEachMacros; - /// Styles for sorting multiple ``#include`` blocks. - enum IncludeBlocksStyle { -/// Sort each ``#include`` block separately. -/// \code -///#include "b.h" into #include "b.h" -/// -///#include #include "a.h" -///#include "a.h" #include -/// \endcode -IBS_Preserve, -/// Merge multiple ``#include`` blocks together and sort as one. -/// \code -///#include "b.h" into #include "a.h" -/// #include "b.h" -///#include #include -///#include "a.h" -/// \endcode -IBS_Merge, -/// Merge multiple ``#include`` blocks together and sort as one. -/// Then split into groups based on category priority. See -/// ``IncludeCategories``. -/// \code -///#include "b.h" into #include "a.h" -/// #include "b.h" -///#include -///#include "a.h" #include -/// \endcode -IBS_Regroup, - }; - - /// Dependent on the value, multiple ``#include`` blocks can be sorted - /// as one and divided based on category. - IncludeBlocksStyle IncludeBlocks; - - /// See documentation of ``IncludeCategories``. - struct IncludeCategory { -/// The regular expression that this category matches. -std::string Regex; -/// The priority to assign to this category. -int Priority; -bool operator==(const IncludeCategory &Other) const { - return Regex == Other.Regex && Priority == Other.Priority; -} - }; - - /// Regular expressions denoting the different ``#include`` categories - /// used for ordering ``#includes``. - /// - /// These regular expressions are matched against the filename of an include - /// (including the <> or "") in order. The value belonging to the first - /// matching regular expression is assigned and ``#includes`` are sorted first - /// according to increasing category number and then alphabetically within - /// each category. - /// - /// If none of the regular expressions match, INT_MAX is assigned as - /// category. The main header for a source file automatically gets category 0. - /// so that it is generally kept at the beginning of the ``#includes`` - /// (http://llvm.org/docs/CodingStandards.html#include-style). However, you - /// can also assign negative priorities if you have certain headers that - /// always need to be first. - /// - /// To configure this in the .clang-format file, use: - /// \code{.yaml} - /// IncludeCategories: - /// - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - /// Priority:2 - /// - Regex: '^(<|"(gtest|gmock|isl|json)/)' - /// Priority:3 - /// - Regex: '.*' - /// Priority:1 - /// \endcode - std::vector IncludeCategories; - - /// Specify a regular expression of suffixes that are allowed in the - /// file-to-main-include mapping. - /// - /// When guessing whether a #include is the "main" include (to assign - /// category 0, see above), use this regex of allowed suffixes to the header - /// stem. A partial match is done, so that: - /// - "" means "arbitrary suffix" - /// - "$" means "no suffix" - /// - /// For example, if configured to "(_test)?$", then a header a.h would be seen - /// as the "main" include in both a.cc and a_test.cc. - std::string I
r332287 - [Tooling] Pull #include manipulation code from clangFormat into libToolingCore.
Author: ioeric Date: Mon May 14 13:17:53 2018 New Revision: 332287 URL: http://llvm.org/viewvc/llvm-project?rev=332287&view=rev Log: [Tooling] Pull #include manipulation code from clangFormat into libToolingCore. Summary: Also pull #include related style out of FormatStyle as tooling::IncludeStyle. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: klimek, mgorny, cfe-commits, djasper Differential Revision: https://reviews.llvm.org/D46496 Added: cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp cfe/trunk/unittests/Tooling/HeaderIncludesTest.cpp Modified: cfe/trunk/include/clang/Format/Format.h cfe/trunk/lib/Format/Format.cpp cfe/trunk/lib/Tooling/Core/CMakeLists.txt cfe/trunk/unittests/Format/CleanupTest.cpp cfe/trunk/unittests/Tooling/CMakeLists.txt Modified: cfe/trunk/include/clang/Format/Format.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=332287&r1=332286&r2=332287&view=diff == --- cfe/trunk/include/clang/Format/Format.h (original) +++ cfe/trunk/include/clang/Format/Format.h Mon May 14 13:17:53 2018 @@ -19,6 +19,7 @@ #include "clang/Tooling/Core/IncludeStyle.h" #include "clang/Tooling/Core/Replacement.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/Support/Regex.h" #include namespace clang { @@ -1810,17 +1811,13 @@ formatReplacements(StringRef Code, const /// This also supports inserting/deleting C++ #include directives: /// - If a replacement has offset UINT_MAX, length 0, and a replacement text /// that is an #include directive, this will insert the #include into the -/// correct block in the \p Code. When searching for points to insert new -/// header, this ignores #include's after the #include block(s) in the -/// beginning of a file to avoid inserting headers into code sections where -/// new #include's should not be added by default. These code sections -/// include: -/// - raw string literals (containing #include). -/// - #if blocks. -/// - Special #include's among declarations (e.g. functions). +/// correct block in the \p Code. /// - If a replacement has offset UINT_MAX, length 1, and a replacement text /// that is the name of the header to be removed, the header will be removed /// from \p Code if it exists. +/// The include manipulation is done via `tooling::HeaderInclude`, see its +/// documentation for more details on how include insertion points are found and +/// what edits are produced. llvm::Expected cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style); Added: cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h?rev=332287&view=auto == --- cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h (added) +++ cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h Mon May 14 13:17:53 2018 @@ -0,0 +1,137 @@ +//===--- HeaderIncludes.h - Insert/Delete #includes for C++ code--*- C++-*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#ifndef LLVM_CLANG_TOOLING_CORE_HEADERINCLUDES_H +#define LLVM_CLANG_TOOLING_CORE_HEADERINCLUDES_H + +#include "clang/Basic/SourceManager.h" +#include "clang/Tooling/Core/Replacement.h" +#include "clang/Tooling/Core/IncludeStyle.h" +#include "llvm/Support/Path.h" +#include "llvm/Support/Regex.h" +#include + +namespace clang { +namespace tooling { + +/// This class manages priorities of C++ #include categories and calculates +/// priorities for headers. +/// FIXME(ioeric): move this class into implementation file when clang-format's +/// include sorting functions are also moved here. +class IncludeCategoryManager { +public: + IncludeCategoryManager(const IncludeStyle &Style, StringRef FileName); + + /// Returns the priority of the category which \p IncludeName belongs to. + /// If \p CheckMainHeader is true and \p IncludeName is a main header, returns + /// 0. Otherwise, returns the priority of the matching category or INT_MAX. + /// NOTE: this API is not thread-safe! + int getIncludePriority(StringRef IncludeName, bool CheckMainHeader) const; + +private: + bool isMainHeader(StringRef IncludeName) const; + + const IncludeStyle Style; + bool IsMainFile; + std::string FileName; + // This refers to a substring in FileName. + StringRef FileStem; + // Regex is not thread-safe. + mutable SmallVector CategoryRegexs; +}; + +/// Generates replacements for inserting or deleting #include directives in a +/// file. +class
[clang-tools-extra] r332362 - [clangd] Remove LSP command-based #include insertion.
Author: ioeric Date: Tue May 15 08:23:53 2018 New Revision: 332362 URL: http://llvm.org/viewvc/llvm-project?rev=332362&view=rev Log: [clangd] Remove LSP command-based #include insertion. Summary: clangd will populate #include insertions as addtionalEdits in completion items. The code completion tests in ClangdServerTest will be added back in D46497. Reviewers: ilya-biryukov, sammccall Reviewed By: ilya-biryukov Subscribers: klimek, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D46676 Removed: clang-tools-extra/trunk/test/clangd/insert-include.test Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp clang-tools-extra/trunk/clangd/ClangdServer.cpp clang-tools-extra/trunk/clangd/ClangdServer.h clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/clangd/Protocol.cpp clang-tools-extra/trunk/clangd/Protocol.h clang-tools-extra/trunk/test/clangd/initialize-params-invalid.test clang-tools-extra/trunk/test/clangd/initialize-params.test clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=332362&r1=332361&r2=332362&view=diff == --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Tue May 15 08:23:53 2018 @@ -115,9 +115,7 @@ void ClangdLSPServer::onInitialize(Initi {"workspaceSymbolProvider", true}, {"executeCommandProvider", json::obj{ - {"commands", - {ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND, - ExecuteCommandParams::CLANGD_INSERT_HEADER_INCLUDE}}, + {"commands", {ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND}}, }}, ); } @@ -190,42 +188,6 @@ void ClangdLSPServer::onCommand(ExecuteC reply("Fix applied."); ApplyEdit(*Params.workspaceEdit); - } else if (Params.command == - ExecuteCommandParams::CLANGD_INSERT_HEADER_INCLUDE) { -auto &FileURI = Params.includeInsertion->textDocument.uri; -auto Code = DraftMgr.getDraft(FileURI.file()); -if (!Code) - return replyError(ErrorCode::InvalidParams, -("command " + - ExecuteCommandParams::CLANGD_INSERT_HEADER_INCLUDE + - " called on non-added file " + FileURI.file()) -.str()); -llvm::StringRef DeclaringHeader = Params.includeInsertion->declaringHeader; -if (DeclaringHeader.empty()) - return replyError( - ErrorCode::InvalidParams, - "declaringHeader must be provided for include insertion."); -llvm::StringRef PreferredHeader = Params.includeInsertion->preferredHeader; -auto Replaces = Server.insertInclude( -FileURI.file(), *Code, DeclaringHeader, -PreferredHeader.empty() ? DeclaringHeader : PreferredHeader); -if (!Replaces) { - std::string ErrMsg = - ("Failed to generate include insertion edits for adding " + - DeclaringHeader + " (" + PreferredHeader + ") into " + - FileURI.file()) - .str(); - log(ErrMsg + ":" + llvm::toString(Replaces.takeError())); - replyError(ErrorCode::InternalError, ErrMsg); - return; -} -auto Edits = replacementsToEdits(*Code, *Replaces); -WorkspaceEdit WE; -WE.changes = {{FileURI.uri(), Edits}}; - -reply(("Inserted header " + DeclaringHeader + " (" + PreferredHeader + ")") - .str()); -ApplyEdit(std::move(WE)); } else { // We should not get here because ExecuteCommandParams would not have // parsed in the first place and this handler should not be called. But if Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=332362&r1=332361&r2=332362&view=diff == --- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue May 15 08:23:53 2018 @@ -272,66 +272,6 @@ void ClangdServer::rename(PathRef File, "Rename", File, Bind(Action, File.str(), NewName.str(), std::move(CB))); } -/// Creates a `HeaderFile` from \p Header which can be either a URI or a literal -/// include. -static llvm::Expected toHeaderFile(StringRef Header, - llvm::StringRef HintPath) { - if (isLiteralInclude(Header)) -return HeaderFile{Header.str(), /*Verbatim=*/true}; - auto U = URI::parse(Header); - if (!U) -return U.takeError(); - - auto IncludePath = URI::includeSpelling(*U); - if (!IncludePath) -return IncludePath.takeError(); - if (!Inc
[clang-tools-extra] r332363 - [clangd] Populate #include insertions as additional edits in completion items.
Author: ioeric Date: Tue May 15 08:29:32 2018 New Revision: 332363 URL: http://llvm.org/viewvc/llvm-project?rev=332363&view=rev Log: [clangd] Populate #include insertions as additional edits in completion items. Summary: o Remove IncludeInsertion LSP command. o Populate include insertion edits synchromously in completion items. o Share the code completion compiler instance and precompiled preamble to get existing inclusions in main file. o Include insertion logic lives only in CodeComplete now. o Use tooling::HeaderIncludes for inserting new includes. o Refactored tests. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D46497 Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/clangd/CodeComplete.h clang-tools-extra/trunk/clangd/Headers.cpp clang-tools-extra/trunk/clangd/Headers.h clang-tools-extra/trunk/clangd/Protocol.h clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=332363&r1=332362&r2=332363&view=diff == --- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue May 15 08:29:32 2018 @@ -161,6 +161,7 @@ void ClangdServer::codeComplete(PathRef // both the old and the new version in case only one of them matches. CompletionList Result = clangd::codeComplete( File, IP->Command, PreambleData ? &PreambleData->Preamble : nullptr, +PreambleData ? PreambleData->Inclusions : std::vector(), IP->Contents, Pos, FS, PCHs, CodeCompleteOpts); CB(std::move(Result)); }; Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=332363&r1=332362&r2=332363&view=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Tue May 15 08:29:32 2018 @@ -18,9 +18,11 @@ #include "CodeCompletionStrings.h" #include "Compiler.h" #include "FuzzyMatch.h" +#include "Headers.h" #include "Logger.h" #include "SourceCode.h" #include "Trace.h" +#include "URI.h" #include "index/Index.h" #include "clang/Format/Format.h" #include "clang/Frontend/CompilerInstance.h" @@ -219,6 +221,28 @@ std::string sortText(float Score, llvm:: return S; } +/// Creates a `HeaderFile` from \p Header which can be either a URI or a literal +/// include. +static llvm::Expected toHeaderFile(StringRef Header, + llvm::StringRef HintPath) { + if (isLiteralInclude(Header)) +return HeaderFile{Header.str(), /*Verbatim=*/true}; + auto U = URI::parse(Header); + if (!U) +return U.takeError(); + + auto IncludePath = URI::includeSpelling(*U); + if (!IncludePath) +return IncludePath.takeError(); + if (!IncludePath->empty()) +return HeaderFile{std::move(*IncludePath), /*Verbatim=*/true}; + + auto Resolved = URI::resolve(*U, HintPath); + if (!Resolved) +return Resolved.takeError(); + return HeaderFile{std::move(*Resolved), /*Verbatim=*/false}; +} + /// A code completion result, in clang-native form. /// It may be promoted to a CompletionItem if it's among the top-ranked results. struct CompletionCandidate { @@ -255,10 +279,10 @@ struct CompletionCandidate { } // Builds an LSP completion item. - CompletionItem build(llvm::StringRef FileName, - const CompletionItemScores &Scores, + CompletionItem build(StringRef FileName, const CompletionItemScores &Scores, const CodeCompleteOptions &Opts, - CodeCompletionString *SemaCCS) const { + CodeCompletionString *SemaCCS, + const IncludeInserter *Includes) const { assert(bool(SemaResult) == bool(SemaCCS)); CompletionItem I; if (SemaResult) { @@ -289,6 +313,30 @@ struct CompletionCandidate { I.documentation = D->Documentation; if (I.detail.empty()) I.detail = D->CompletionDetail; +if (Includes && !D->IncludeHeader.empty()) { + auto Edit = [&]() -> Expected> { +auto ResolvedDeclaring = toHeaderFile( +IndexResult->CanonicalDeclaration.FileURI, FileName); +if (!ResolvedDeclaring) + return ResolvedDeclaring.takeError(); +auto ResolvedInserted = toHeaderFile(D->IncludeHeader, FileName); +if (!ResolvedInserted) + return ResolvedInserted
[clang-tools-extra] r332366 - [clangd] Log error message instead write to errs(). NFC
Author: ioeric Date: Tue May 15 09:22:43 2018 New Revision: 332366 URL: http://llvm.org/viewvc/llvm-project?rev=332366&view=rev Log: [clangd] Log error message instead write to errs(). NFC Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=332366&r1=332365&r2=332366&view=diff == --- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original) +++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Tue May 15 09:22:43 2018 @@ -51,8 +51,7 @@ llvm::Optional toURI(const if (std::error_code EC = SM.getFileManager().getVirtualFileSystem()->makeAbsolute( AbsolutePath)) -llvm::errs() << "Warning: could not make absolute file: '" << EC.message() - << '\n'; +log("Warning: could not make absolute file: " + EC.message()); if (llvm::sys::path::is_absolute(AbsolutePath)) { // Handle the symbolic link path case where the current working directory // (getCurrentWorkingDirectory) is a symlink./ We always want to the real ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r332456 - [clangd] Filter out private proto symbols in SymbolCollector.
Author: ioeric Date: Wed May 16 05:12:30 2018 New Revision: 332456 URL: http://llvm.org/viewvc/llvm-project?rev=332456&view=rev Log: [clangd] Filter out private proto symbols in SymbolCollector. Summary: This uses heuristics to identify private proto symbols. For example, top-level symbols whose name contains "_" are considered private. These symbols are not expected to be used by users. Reviewers: ilya-biryukov, malaperle Reviewed By: ilya-biryukov Subscribers: sammccall, klimek, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D46751 Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=332456&r1=332455&r2=332456&view=diff == --- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original) +++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Wed May 16 05:12:30 2018 @@ -89,6 +89,46 @@ llvm::Optional toURI(const return llvm::None; } +// All proto generated headers should start with this line. +static const char *PROTO_HEADER_COMMENT = +"// Generated by the protocol buffer compiler. DO NOT EDIT!"; + +// Checks whether the decl is a private symbol in a header generated by +// protobuf compiler. +// To identify whether a proto header is actually generated by proto compiler, +// we check whether it starts with PROTO_HEADER_COMMENT. +// FIXME: make filtering extensible when there are more use cases for symbol +// filters. +bool isPrivateProtoDecl(const NamedDecl &ND) { + const auto &SM = ND.getASTContext().getSourceManager(); + auto Loc = findNameLoc(&ND); + auto FileName = SM.getFilename(Loc); + if (!FileName.endswith(".proto.h") && !FileName.endswith(".pb.h")) +return false; + auto FID = SM.getFileID(Loc); + // Double check that this is an actual protobuf header. + if (!SM.getBufferData(FID).startswith(PROTO_HEADER_COMMENT)) +return false; + + // ND without identifier can be operators. + if (ND.getIdentifier() == nullptr) +return false; + auto Name = ND.getIdentifier()->getName(); + if (!Name.contains('_')) +return false; + // Nested proto entities (e.g. Message::Nested) have top-level decls + // that shouldn't be used (Message_Nested). Ignore them completely. + // The nested entities are dangling type aliases, we may want to reconsider + // including them in the future. + // For enum constants, SOME_ENUM_CONSTANT is not private and should be + // indexed. Outer_INNER is private. This heuristic relies on naming style, it + // will include OUTER_INNER and exclude some_enum_constant. + // FIXME: the heuristic relies on naming style (i.e. no underscore in + // user-defined names) and can be improved. + return (ND.getKind() != Decl::EnumConstant) || + std::any_of(Name.begin(), Name.end(), islower); +} + bool shouldFilterDecl(const NamedDecl *ND, ASTContext *ASTCtx, const SymbolCollector::Options &Opts) { using namespace clang::ast_matchers; @@ -129,6 +169,9 @@ bool shouldFilterDecl(const NamedDecl *N .empty()) return true; + // Avoid indexing internal symbols in protobuf generated headers. + if (isPrivateProtoDecl(*ND)) +return true; return false; } Modified: clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp?rev=332456&r1=332455&r2=332456&view=diff == --- clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Wed May 16 05:12:30 2018 @@ -697,6 +697,41 @@ TEST_F(SymbolCollectorTest, UTF16Charact AllOf(QName("pörk"), DeclRange(Header.range(); } +TEST_F(SymbolCollectorTest, FilterPrivateProtoSymbols) { + TestHeaderName = testPath("x.proto.h"); + const std::string Header = + R"(// Generated by the protocol buffer compiler. DO NOT EDIT! + namespace nx { + class Top_Level {}; + class TopLevel {}; + enum Kind { + KIND_OK, + Kind_Not_Ok, + }; + bool operator<(const TopLevel &, const TopLevel &); + })"; + runSymbolCollector(Header, /*Main=*/""); + EXPECT_THAT(Symbols, + UnorderedElementsAre(QName("nx"), QName("nx::TopLevel"), + QName("nx::Kind"), QName("nx::KIND_OK"), + QName("nx::operator<"))); +} + +TEST_F(SymbolCollectorTest, DoubleCheckProtoHeaderComment) { + TestHeaderName = testPath("x.proto.h"); + const std::string Header
Re: r332436 - clang-format: Allow optimizer to break template declaration.
I can also reproduce on my local machine (Debian). On Wed, May 16, 2018 at 1:01 PM David Zarzycki via cfe-commits < cfe-commits@lists.llvm.org> wrote: > This change broke `test/Index/overriding-ftemplate-comments.cpp` on Red > Hat Fedora 28. Was this expected? > > > On May 16, 2018, at 4:25 AM, Francois Ferrand via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > > > > Author: typz > > Date: Wed May 16 01:25:03 2018 > > New Revision: 332436 > > > > URL: http://llvm.org/viewvc/llvm-project?rev=332436&view=rev > > Log: > > clang-format: Allow optimizer to break template declaration. > > > > Summary: > > Introduce `PenaltyBreakTemplateDeclaration` to control the penalty, > > and change `AlwaysBreakTemplateDeclarations` to an enum with 3 modes: > > * `No` for regular, penalty based, wrapping of template declaration > > * `MultiLine` for always wrapping before multi-line declarations (e.g. > > same as legacy behavior when `AlwaysBreakTemplateDeclarations=false`) > > * `Yes` for always wrapping (e.g. same as legacy behavior when > > `AlwaysBreakTemplateDeclarations=true`) > > > > Reviewers: krasimir, djasper, klimek > > > > Subscribers: cfe-commits > > > > Differential Revision: https://reviews.llvm.org/D42684 > > > > Modified: > >cfe/trunk/docs/ClangFormatStyleOptions.rst > >cfe/trunk/include/clang/Format/Format.h > >cfe/trunk/lib/Format/ContinuationIndenter.cpp > >cfe/trunk/lib/Format/Format.cpp > >cfe/trunk/lib/Format/TokenAnnotator.cpp > >cfe/trunk/unittests/Format/FormatTest.cpp > > > > Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst > > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=332436&r1=332435&r2=332436&view=diff > > > == > > --- cfe/trunk/docs/ClangFormatStyleOptions.rst (original) > > +++ cfe/trunk/docs/ClangFormatStyleOptions.rst Wed May 16 01:25:03 2018 > > @@ -490,15 +490,50 @@ the configuration (without a prefix: ``A > > """"; > > ""; > > > > -**AlwaysBreakTemplateDeclarations** (``bool``) > > - If ``true``, always break after the ``template<...>`` of a template > > - declaration. > > +**AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) > > + The template declaration breaking style to use. > > + > > + Possible values: > > + > > + * ``BTDS_No`` (in configuration: ``No``) > > +Do not force break before declaration. > > +``PenaltyBreakTemplateDeclaration`` is taken into account. > > + > > +.. code-block:: c++ > > + > > + template T foo() { > > + } > > + template T foo(int a, > > + int b) { > > + } > > + > > + * ``BTDS_MultiLine`` (in configuration: ``MultiLine``) > > +Force break after template declaration only when the following > > +declaration spans multiple lines. > > + > > +.. code-block:: c++ > > + > > + template T foo() { > > + } > > + template > > + T foo(int a, > > + int b) { > > + } > > + > > + * ``BTDS_Yes`` (in configuration: ``Yes``) > > +Always break after template declaration. > > + > > +.. code-block:: c++ > > + > > + template > > + T foo() { > > + } > > + template > > + T foo(int a, > > + int b) { > > + } > > > > - .. code-block:: c++ > > > > - true: false: > > - template vs. template class > C {}; > > - class C {}; > > > > **BinPackArguments** (``bool``) > > If ``false``, a function call's arguments will either be all on the > > @@ -1590,6 +1625,9 @@ the configuration (without a prefix: ``A > > **PenaltyBreakString** (``unsigned``) > > The penalty for each line break introduced inside a string literal. > > > > +**PenaltyBreakTemplateDeclaration** (``unsigned``) > > + The penalty for breaking after template declaration. > > + > > **PenaltyExcessCharacter** (``unsigned``) > > The penalty for each character outside of the column limit. > > > > > > Modified: cfe/trunk/include/clang/Format/Format.h > > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=332436&r1=332435&r2=332436&view=diff > > > == > > --- cfe/trunk/include/clang/Format/Format.h (original) > > +++ cfe/trunk/include/clang/Format/Format.h Wed May 16 01:25:03 2018 > > @@ -351,14 +351,44 @@ struct FormatStyle { > > /// \endcode > > bool AlwaysBreakBeforeMultilineStrings; > > > > - /// If ``true``, always break after the ``template<...>`` of a > template > > - /// declaration. > > - /// \code > > - ///true: false: > > - ///template vs. tem
Re: r332436 - clang-format: Allow optimizer to break template declaration.
OK, I'll send a fix for the index test. Please make sure you run all clang tests (`ninja check-clang` and `ninja check-clang-tools`) before landing a patch! Thanks! On Wed, May 16, 2018 at 2:32 PM Eric Liu wrote: > I can also reproduce on my local machine (Debian). > > On Wed, May 16, 2018 at 1:01 PM David Zarzycki via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> This change broke `test/Index/overriding-ftemplate-comments.cpp` on Red >> Hat Fedora 28. Was this expected? >> >> > On May 16, 2018, at 4:25 AM, Francois Ferrand via cfe-commits < >> cfe-commits@lists.llvm.org> wrote: >> > >> > Author: typz >> > Date: Wed May 16 01:25:03 2018 >> > New Revision: 332436 >> > >> > URL: http://llvm.org/viewvc/llvm-project?rev=332436&view=rev >> > Log: >> > clang-format: Allow optimizer to break template declaration. >> > >> > Summary: >> > Introduce `PenaltyBreakTemplateDeclaration` to control the penalty, >> > and change `AlwaysBreakTemplateDeclarations` to an enum with 3 modes: >> > * `No` for regular, penalty based, wrapping of template declaration >> > * `MultiLine` for always wrapping before multi-line declarations (e.g. >> > same as legacy behavior when `AlwaysBreakTemplateDeclarations=false`) >> > * `Yes` for always wrapping (e.g. same as legacy behavior when >> > `AlwaysBreakTemplateDeclarations=true`) >> > >> > Reviewers: krasimir, djasper, klimek >> > >> > Subscribers: cfe-commits >> > >> > Differential Revision: https://reviews.llvm.org/D42684 >> > >> > Modified: >> >cfe/trunk/docs/ClangFormatStyleOptions.rst >> >cfe/trunk/include/clang/Format/Format.h >> >cfe/trunk/lib/Format/ContinuationIndenter.cpp >> >cfe/trunk/lib/Format/Format.cpp >> >cfe/trunk/lib/Format/TokenAnnotator.cpp >> >cfe/trunk/unittests/Format/FormatTest.cpp >> > >> > Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst >> > URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=332436&r1=332435&r2=332436&view=diff >> > >> == >> > --- cfe/trunk/docs/ClangFormatStyleOptions.rst (original) >> > +++ cfe/trunk/docs/ClangFormatStyleOptions.rst Wed May 16 01:25:03 2018 >> > @@ -490,15 +490,50 @@ the configuration (without a prefix: ``A >> > """"; >> > ""; >> > >> > -**AlwaysBreakTemplateDeclarations** (``bool``) >> > - If ``true``, always break after the ``template<...>`` of a template >> > - declaration. >> > +**AlwaysBreakTemplateDeclarations** >> (``BreakTemplateDeclarationsStyle``) >> > + The template declaration breaking style to use. >> > + >> > + Possible values: >> > + >> > + * ``BTDS_No`` (in configuration: ``No``) >> > +Do not force break before declaration. >> > +``PenaltyBreakTemplateDeclaration`` is taken into account. >> > + >> > +.. code-block:: c++ >> > + >> > + template T foo() { >> > + } >> > + template T foo(int a, >> > + int b) { >> > + } >> > + >> > + * ``BTDS_MultiLine`` (in configuration: ``MultiLine``) >> > +Force break after template declaration only when the following >> > +declaration spans multiple lines. >> > + >> > +.. code-block:: c++ >> > + >> > + template T foo() { >> > + } >> > + template >> > + T foo(int a, >> > + int b) { >> > + } >> > + >> > + * ``BTDS_Yes`` (in configuration: ``Yes``) >> > +Always break after template declaration. >> > + >> > +.. code-block:: c++ >> > + >> > + template >> > + T foo() { >> > + } >> > + template >> > + T foo(int a, >> > + int b) { >> > + } >> > >> > - .. code-block:: c++ >> > >> > - true: false: >> > - template vs. template >> class C {}; >> > - class C {}; >> > >> > **BinPackArguments** (``bool``) >> > If ``false``, a function call's arguments will either be all on the >> > @@ -1590,6 +1625,9 @@ the configuration (without a prefix: ``A >> > **PenaltyBreakString** (``unsigned``) >> > The penalty for each line break introduced inside a string literal. >> > >> > +**PenaltyBreakTemplateDeclaration** (``unsigned``) >> > + The penalty for breaking after template declaration. >> > + >> > **PenaltyExcessCharacter** (``unsigned``) >> > The penalty for each character outside of the column limit. >> > >> > >> > Modified: cfe/trunk/include/clang/Format/Format.h >> > URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=332436&r1=332435&r2=332436&view=diff >> > >> == >> > --- cfe/trunk/include/clang/Format/Format.h (original) >> > +++ cfe/trunk/include/clang/Format/Format.h Wed May 16 01:25:03
r332465 - Fix an Index test caused by a clang-format change (r332436).
Author: ioeric Date: Wed May 16 05:58:13 2018 New Revision: 332465 URL: http://llvm.org/viewvc/llvm-project?rev=332465&view=rev Log: Fix an Index test caused by a clang-format change (r332436). Modified: cfe/trunk/test/Index/overriding-ftemplate-comments.cpp Modified: cfe/trunk/test/Index/overriding-ftemplate-comments.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/overriding-ftemplate-comments.cpp?rev=332465&r1=332464&r2=332465&view=diff == --- cfe/trunk/test/Index/overriding-ftemplate-comments.cpp (original) +++ cfe/trunk/test/Index/overriding-ftemplate-comments.cpp Wed May 16 05:58:13 2018 @@ -77,10 +77,10 @@ void comment_to_html_conversion_21(); template class BBB > class AAA> void comment_to_html_conversion_22(); -// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@>2#T#t>2#T#t>2#T#Tcomment_to_html_conversion_22#v#templateclass BBB>\n class AAA>\nvoid comment_to_html_conversion_22()C10 Ccc 1 AAA1 Zzz C2 Ccc 2 C3 Ccc 3 C4 Ccc 4 BBB Bbb] +// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@>2#T#t>2#T#t>2#T#Tcomment_to_html_conversion_22#v#template class BBB>\nclass AAA>\nvoid comment_to_html_conversion_22()C10 Ccc 1 AAA1 Zzz C2 Ccc 2 C3 Ccc 3 C4 Ccc 4 BBB Bbb] template class QQQ> class PPP> void comment_to_html_conversion_22(); -// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@>2#T#t>2#T#t>2#T#Tcomment_to_html_conversion_22#v#template \n class QQQ> class PPP>\nvoid comment_to_html_conversion_22()CCC10 Ccc 1 PPP1 Zzz CCC2 Ccc 2 CCC3 Ccc 3 CCC4 Ccc 4 QQQ Bbb] +// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@>2#T#t>2#T#t>2#T#Tcomment_to_html_conversion_22#v#template class QQQ>\n class PPP>\nvoid comment_to_html_conversion_22()CCC10 Ccc 1 PPP1 Zzz CCC2 Ccc 2 CCC3 Ccc 3 CCC4 Ccc 4 QQQ Bbb] ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r332436 - clang-format: Allow optimizer to break template declaration.
This should be fixed by r332465 On Wed, May 16, 2018 at 2:50 PM Eric Liu wrote: > OK, I'll send a fix for the index test. Please make sure you run all clang > tests (`ninja check-clang` and `ninja check-clang-tools`) before landing a > patch! Thanks! > > On Wed, May 16, 2018 at 2:32 PM Eric Liu wrote: > >> I can also reproduce on my local machine (Debian). >> >> On Wed, May 16, 2018 at 1:01 PM David Zarzycki via cfe-commits < >> cfe-commits@lists.llvm.org> wrote: >> >>> This change broke `test/Index/overriding-ftemplate-comments.cpp` on Red >>> Hat Fedora 28. Was this expected? >>> >>> > On May 16, 2018, at 4:25 AM, Francois Ferrand via cfe-commits < >>> cfe-commits@lists.llvm.org> wrote: >>> > >>> > Author: typz >>> > Date: Wed May 16 01:25:03 2018 >>> > New Revision: 332436 >>> > >>> > URL: http://llvm.org/viewvc/llvm-project?rev=332436&view=rev >>> > Log: >>> > clang-format: Allow optimizer to break template declaration. >>> > >>> > Summary: >>> > Introduce `PenaltyBreakTemplateDeclaration` to control the penalty, >>> > and change `AlwaysBreakTemplateDeclarations` to an enum with 3 modes: >>> > * `No` for regular, penalty based, wrapping of template declaration >>> > * `MultiLine` for always wrapping before multi-line declarations (e.g. >>> > same as legacy behavior when `AlwaysBreakTemplateDeclarations=false`) >>> > * `Yes` for always wrapping (e.g. same as legacy behavior when >>> > `AlwaysBreakTemplateDeclarations=true`) >>> > >>> > Reviewers: krasimir, djasper, klimek >>> > >>> > Subscribers: cfe-commits >>> > >>> > Differential Revision: https://reviews.llvm.org/D42684 >>> > >>> > Modified: >>> >cfe/trunk/docs/ClangFormatStyleOptions.rst >>> >cfe/trunk/include/clang/Format/Format.h >>> >cfe/trunk/lib/Format/ContinuationIndenter.cpp >>> >cfe/trunk/lib/Format/Format.cpp >>> >cfe/trunk/lib/Format/TokenAnnotator.cpp >>> >cfe/trunk/unittests/Format/FormatTest.cpp >>> > >>> > Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst >>> > URL: >>> http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=332436&r1=332435&r2=332436&view=diff >>> > >>> == >>> > --- cfe/trunk/docs/ClangFormatStyleOptions.rst (original) >>> > +++ cfe/trunk/docs/ClangFormatStyleOptions.rst Wed May 16 01:25:03 2018 >>> > @@ -490,15 +490,50 @@ the configuration (without a prefix: ``A >>> > """"; >>> > ""; >>> > >>> > -**AlwaysBreakTemplateDeclarations** (``bool``) >>> > - If ``true``, always break after the ``template<...>`` of a template >>> > - declaration. >>> > +**AlwaysBreakTemplateDeclarations** >>> (``BreakTemplateDeclarationsStyle``) >>> > + The template declaration breaking style to use. >>> > + >>> > + Possible values: >>> > + >>> > + * ``BTDS_No`` (in configuration: ``No``) >>> > +Do not force break before declaration. >>> > +``PenaltyBreakTemplateDeclaration`` is taken into account. >>> > + >>> > +.. code-block:: c++ >>> > + >>> > + template T foo() { >>> > + } >>> > + template T foo(int a, >>> > + int b) { >>> > + } >>> > + >>> > + * ``BTDS_MultiLine`` (in configuration: ``MultiLine``) >>> > +Force break after template declaration only when the following >>> > +declaration spans multiple lines. >>> > + >>> > +.. code-block:: c++ >>> > + >>> > + template T foo() { >>> > + } >>> > + template >>> > + T foo(int a, >>> > + int b) { >>> > + } >>> > + >>> > + * ``BTDS_Yes`` (in configuration: ``Yes``) >>> > +Always break after template declaration. >>> > + >>> > +.. code-block:: c++ >>> > + >>> > + template >>> > + T foo() { >>> > + } >>> > + template >>> > + T foo(int a, >>> > + int b) { >>> > + } >>> > >>> > - .. code-block:: c++ >>> > >>> > - true: false: >>> > - template vs. template >>> class C {}; >>> > - class C {}; >>> > >>> > **BinPackArguments** (``bool``) >>> > If ``false``, a function call's arguments will either be all on the >>> > @@ -1590,6 +1625,9 @@ the configuration (without a prefix: ``A >>> > **PenaltyBreakString** (``unsigned``) >>> > The penalty for each line break introduced inside a string literal. >>> > >>> > +**PenaltyBreakTemplateDeclaration** (``unsigned``) >>> > + The penalty for breaking after template declaration. >>> > + >>> > **PenaltyExcessCharacter** (``unsigned``) >>> > The penalty for each character outside of the column limit. >>> > >>> > >>> > Modified: cfe/trunk/include/clang/Format/Format.h >>> > URL: >>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=332436&r1=332435&r2=332436&view=diff
Re: [clang-tools-extra] r332363 - [clangd] Populate #include insertions as additional edits in completion items.
Looking... sorry that I missed the email from this bot. On Wed, May 16, 2018 at 9:43 PM Galina Kistanova wrote: > Hello Eric, > > This commit broke one of our builders: > http://lab.llvm.org:8011/builders/clang-x86_64-linux-abi-test/builds/26399 > > . . . > 387.403 [725/64/4163] Building CXX object > tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/CodeComplete.cpp.o > FAILED: > tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/CodeComplete.cpp.o > > /usr/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE > -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS > -Itools/clang/tools/extra/clangd > -I/home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/tools/extra/clangd > -I/home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/include > -Itools/clang/include -Iinclude > -I/home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/include > -fPIC -fvisibility-inlines-hidden -std=c++11 -Wall -W -Wno-unused-parameter > -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic > -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor > -Wno-comment -ffunction-sections -fdata-sections -fno-common > -Woverloaded-virtual -fno-strict-aliasing -O3-UNDEBUG -fno-exceptions > -fno-rtti -MD -MT > tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/CodeComplete.cpp.o > -MF > tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/CodeComplete.cpp.o.d > -o > tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/CodeComplete.cpp.o > -c > /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/tools/extra/clangd/CodeComplete.cpp > /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/tools/extra/clangd/CodeComplete.cpp: > In function ‘clang::clangd::SignatureHelp > clang::clangd::signatureHelp(clang::clangd::PathRef, const > clang::tooling::CompileCommand&, const clang::PrecompiledPreamble*, > llvm::StringRef, clang::clangd::Position, > llvm::IntrusiveRefCntPtr, > std::shared_ptr)’: > /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/tools/extra/clangd/CodeComplete.cpp:1127:37: > error: invalid initialization of reference of type ‘const > clang::clangd::{anonymous}::SemaCompleteInput&’ from expression of type > ‘’ > std::move(PCHs)}); > ^ > /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/tools/extra/clangd/CodeComplete.cpp:710:6: > error: in passing argument 3 of ‘bool > clang::clangd::{anonymous}::semaCodeComplete(std::unique_ptr, > const clang::CodeCompleteOptions&, const > clang::clangd::{anonymous}::SemaCompleteInput&, > std::unique_ptr*)’ > > bool semaCodeComplete(std::unique_ptr Consumer, > ^ > . . . > > Please have a look? > > It is not good idea to keep the bot red for too long. This hides new > problem which later hard to track down. > > Thanks > > > Galina > > > > On Tue, May 15, 2018 at 8:29 AM, Eric Liu via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> Author: ioeric >> Date: Tue May 15 08:29:32 2018 >> New Revision: 332363 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=332363&view=rev >> Log: >> [clangd] Populate #include insertions as additional edits in completion >> items. >> >> Summary: >> o Remove IncludeInsertion LSP command. >> o Populate include insertion edits synchromously in completion items. >> o Share the code completion compiler instance and precompiled preamble to >> get existing inclusions in main file. >> o Include insertion logic lives only in CodeComplete now. >> o Use tooling::HeaderIncludes for inserting new includes. >> o Refactored tests. >> >> Reviewers: sammccall >> >> Reviewed By: sammccall >> >> Subscribers: klimek, ilya-biryukov, MaskRay, jkorous, cfe-commits >> >> Differential Revision: https://reviews.llvm.org/D46497 >> >> Modified: >> clang-tools-extra/trunk/clangd/ClangdServer.cpp >> clang-tools-extra/trunk/clangd/CodeComplete.cpp >> clang-tools-extra/trunk/clangd/CodeComplete.h >> clang-tools-extra/trunk/clangd/Headers.cpp >> clang-tools-extra/trunk/clangd/Headers.h >> clang-tools-extra/trunk/clangd/Protocol.h >> clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp >> clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp >> >> Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cp
[clang-tools-extra] r332515 - Attempt to fix buildbot failure caused by r332363
Author: ioeric Date: Wed May 16 12:59:49 2018 New Revision: 332515 URL: http://llvm.org/viewvc/llvm-project?rev=332515&view=rev Log: Attempt to fix buildbot failure caused by r332363 Log: http://lab.llvm.org:8011/builders/clang-x86_64-linux-abi-test/builds/26399 Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=332515&r1=332514&r2=332515&view=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Wed May 16 12:59:49 2018 @@ -1069,9 +1069,8 @@ SignatureHelp signatureHelp(PathRef File Options.IncludeBriefComments = false; semaCodeComplete(llvm::make_unique(Options, Result), Options, - {FileName, Command, Preamble, -/*PreambleInclusions=*/{}, Contents, Pos, std::move(VFS), -std::move(PCHs)}); + {FileName, Command, Preamble, std::vector(), +Contents, Pos, std::move(VFS), std::move(PCHs)}); return Result; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r332518 - [clang-move] Fix a potential bug where realpath doesn't work on VFS.
Author: ioeric Date: Wed May 16 13:10:10 2018 New Revision: 332518 URL: http://llvm.org/viewvc/llvm-project?rev=332518&view=rev Log: [clang-move] Fix a potential bug where realpath doesn't work on VFS. Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=332518&r1=332517&r2=332518&view=diff == --- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original) +++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Wed May 16 13:10:10 2018 @@ -95,12 +95,16 @@ std::string MakeAbsolutePath(const Sourc llvm::sys::path::parent_path(AbsolutePath.str())); if (Dir) { StringRef DirName = SM.getFileManager().getCanonicalName(Dir); -SmallVector AbsoluteFilename; -llvm::sys::path::append(AbsoluteFilename, DirName, -llvm::sys::path::filename(AbsolutePath.str())); -return llvm::StringRef(AbsoluteFilename.data(), AbsoluteFilename.size()) -.str(); +// FIXME: getCanonicalName might fail to get real path on VFS. +if (llvm::sys::path::is_absolute(DirName)) { + SmallVector AbsoluteFilename; + llvm::sys::path::append(AbsoluteFilename, DirName, + llvm::sys::path::filename(AbsolutePath.str())); + return llvm::StringRef(AbsoluteFilename.data(), AbsoluteFilename.size()) + .str(); +} } + llvm::sys::path::remove_dots(AbsolutePath, /*remove_dot_dot=*/true); return AbsolutePath.str(); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r332520 - Second attempt to fix buildbot failure caused by r332363
Author: ioeric Date: Wed May 16 13:31:38 2018 New Revision: 332520 URL: http://llvm.org/viewvc/llvm-project?rev=332520&view=rev Log: Second attempt to fix buildbot failure caused by r332363 http://lab.llvm.org:8011/builders/clang-x86_64-linux-abi-test/builds/26501 Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=332520&r1=332519&r2=332520&view=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Wed May 16 13:31:38 2018 @@ -1067,10 +1067,11 @@ SignatureHelp signatureHelp(PathRef File Options.IncludeMacros = false; Options.IncludeCodePatterns = false; Options.IncludeBriefComments = false; + std::vector PreambleInclusions = {}; // Unused for signatureHelp semaCodeComplete(llvm::make_unique(Options, Result), Options, - {FileName, Command, Preamble, std::vector(), -Contents, Pos, std::move(VFS), std::move(PCHs)}); + {FileName, Command, Preamble, PreambleInclusions, Contents, +Pos, std::move(VFS), std::move(PCHs)}); return Result; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [clang-tools-extra] r332363 - [clangd] Populate #include insertions as additional edits in completion items.
r332520 fixed the broken build in clangd. On Wed, May 16, 2018 at 9:48 PM Eric Liu wrote: > Looking... sorry that I missed the email from this bot. > > On Wed, May 16, 2018 at 9:43 PM Galina Kistanova > wrote: > >> Hello Eric, >> >> This commit broke one of our builders: >> http://lab.llvm.org:8011/builders/clang-x86_64-linux-abi-test/builds/26399 >> >> . . . >> 387.403 [725/64/4163] Building CXX object >> tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/CodeComplete.cpp.o >> FAILED: >> tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/CodeComplete.cpp.o >> >> /usr/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE >> -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS >> -Itools/clang/tools/extra/clangd >> -I/home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/tools/extra/clangd >> -I/home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/include >> -Itools/clang/include -Iinclude >> -I/home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/include >> -fPIC -fvisibility-inlines-hidden -std=c++11 -Wall -W -Wno-unused-parameter >> -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic >> -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor >> -Wno-comment -ffunction-sections -fdata-sections -fno-common >> -Woverloaded-virtual -fno-strict-aliasing -O3-UNDEBUG -fno-exceptions >> -fno-rtti -MD -MT >> tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/CodeComplete.cpp.o >> -MF >> tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/CodeComplete.cpp.o.d >> -o >> tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/CodeComplete.cpp.o >> -c >> /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/tools/extra/clangd/CodeComplete.cpp >> /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/tools/extra/clangd/CodeComplete.cpp: >> In function ‘clang::clangd::SignatureHelp >> clang::clangd::signatureHelp(clang::clangd::PathRef, const >> clang::tooling::CompileCommand&, const clang::PrecompiledPreamble*, >> llvm::StringRef, clang::clangd::Position, >> llvm::IntrusiveRefCntPtr, >> std::shared_ptr)’: >> /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/tools/extra/clangd/CodeComplete.cpp:1127:37: >> error: invalid initialization of reference of type ‘const >> clang::clangd::{anonymous}::SemaCompleteInput&’ from expression of type >> ‘’ >> std::move(PCHs)}); >> ^ >> /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/tools/extra/clangd/CodeComplete.cpp:710:6: >> error: in passing argument 3 of ‘bool >> clang::clangd::{anonymous}::semaCodeComplete(std::unique_ptr, >> const clang::CodeCompleteOptions&, const >> clang::clangd::{anonymous}::SemaCompleteInput&, >> std::unique_ptr*)’ >> >> bool semaCodeComplete(std::unique_ptr Consumer, >> ^ >> . . . >> >> Please have a look? >> >> It is not good idea to keep the bot red for too long. This hides new >> problem which later hard to track down. >> >> Thanks >> >> >> Galina >> >> >> >> On Tue, May 15, 2018 at 8:29 AM, Eric Liu via cfe-commits < >> cfe-commits@lists.llvm.org> wrote: >> >>> Author: ioeric >>> Date: Tue May 15 08:29:32 2018 >>> New Revision: 332363 >>> >>> URL: http://llvm.org/viewvc/llvm-project?rev=332363&view=rev >>> Log: >>> [clangd] Populate #include insertions as additional edits in completion >>> items. >>> >>> Summary: >>> o Remove IncludeInsertion LSP command. >>> o Populate include insertion edits synchromously in completion items. >>> o Share the code completion compiler instance and precompiled preamble >>> to get existing inclusions in main file. >>> o Include insertion logic lives only in CodeComplete now. >>> o Use tooling::HeaderIncludes for inserting new includes. >>> o Refactored tests. >>> >>> Reviewers: sammccall >>> >>> Reviewed By: sammccall >>> >>> Subscribers: klimek, ilya-biryukov, MaskRay, jkorous, cfe-commits >>> >>> Differential Revision: https://reviews.llvm.org/D46497 >>> >>> Modified: >>> clang-tools-extra/trunk/clangd/ClangdServer.cpp >>> clang-tools-extra/trunk/clangd/CodeComplete.cpp >>> clang-tools-extra/trunk/clang
r332590 - Add vfs::FileSystem::getRealPath
Author: ioeric Date: Thu May 17 03:26:23 2018 New Revision: 332590 URL: http://llvm.org/viewvc/llvm-project?rev=332590&view=rev Log: Add vfs::FileSystem::getRealPath Summary: And change `FileManager::getCanonicalName` to use getRealPath. Reviewers: bkramer Reviewed By: bkramer Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D46942 Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h cfe/trunk/lib/Basic/FileManager.cpp cfe/trunk/lib/Basic/VirtualFileSystem.cpp Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=332590&r1=332589&r2=332590&view=diff == --- cfe/trunk/include/clang/Basic/VirtualFileSystem.h (original) +++ cfe/trunk/include/clang/Basic/VirtualFileSystem.h Thu May 17 03:26:23 2018 @@ -248,6 +248,12 @@ public: /// Get the working directory of this file system. virtual llvm::ErrorOr getCurrentWorkingDirectory() const = 0; + /// Gets real path of \p Path e.g. collapse all . and .. patterns, resolve + /// symlinks. For real file system, this uses `llvm::sys::fs::real_path`. + /// This returns errc::operation_not_permitted if not implemented by subclass. + virtual std::error_code getRealPath(const Twine &Path, + SmallVectorImpl &Output) const; + /// Check whether a file exists. Provided for convenience. bool exists(const Twine &Path); Modified: cfe/trunk/lib/Basic/FileManager.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=332590&r1=332589&r2=332590&view=diff == --- cfe/trunk/lib/Basic/FileManager.cpp (original) +++ cfe/trunk/lib/Basic/FileManager.cpp Thu May 17 03:26:23 2018 @@ -534,23 +534,9 @@ StringRef FileManager::getCanonicalName( StringRef CanonicalName(Dir->getName()); -#ifdef LLVM_ON_UNIX - char CanonicalNameBuf[PATH_MAX]; - if (realpath(Dir->getName().str().c_str(), CanonicalNameBuf)) + SmallString<4096> CanonicalNameBuf; + if (!FS->getRealPath(Dir->getName(), CanonicalNameBuf)) CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage); -#else - SmallString<256> CanonicalNameBuf(CanonicalName); - llvm::sys::fs::make_absolute(CanonicalNameBuf); - llvm::sys::path::native(CanonicalNameBuf); - // We've run into needing to remove '..' here in the wild though, so - // remove it. - // On Windows, symlinks are significantly less prevalent, so removing - // '..' is pretty safe. - // Ideally we'd have an equivalent of `realpath` and could implement - // sys::fs::canonical across all the platforms. - llvm::sys::path::remove_dots(CanonicalNameBuf, /* remove_dot_dot */ true); - CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage); -#endif CanonicalDirNames.insert(std::make_pair(Dir, CanonicalName)); return CanonicalName; Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=332590&r1=332589&r2=332590&view=diff == --- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original) +++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Thu May 17 03:26:23 2018 @@ -139,6 +139,11 @@ std::error_code FileSystem::makeAbsolute return llvm::sys::fs::make_absolute(WorkingDir.get(), Path); } +std::error_code FileSystem::getRealPath(const Twine &Path, +SmallVectorImpl &Output) const { + return errc::operation_not_permitted; +} + bool FileSystem::exists(const Twine &Path) { auto Status = status(Path); return Status && Status->exists(); @@ -236,6 +241,8 @@ public: llvm::ErrorOr getCurrentWorkingDirectory() const override; std::error_code setCurrentWorkingDirectory(const Twine &Path) override; + std::error_code getRealPath(const Twine &Path, + SmallVectorImpl &Output) const override; }; } // namespace @@ -274,6 +281,12 @@ std::error_code RealFileSystem::setCurre return llvm::sys::fs::set_current_path(Path); } +std::error_code +RealFileSystem::getRealPath(const Twine &Path, +SmallVectorImpl &Output) const { + return llvm::sys::fs::real_path(Path, Output); +} + IntrusiveRefCntPtr vfs::getRealFileSystem() { static IntrusiveRefCntPtr FS = new RealFileSystem(); return FS; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r332603 - Attempt to fix clang-move tests broken by r332590 on windows
Author: ioeric Date: Thu May 17 05:40:50 2018 New Revision: 332603 URL: http://llvm.org/viewvc/llvm-project?rev=332603&view=rev Log: Attempt to fix clang-move tests broken by r332590 on windows http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/12007 Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=332603&r1=332602&r2=332603&view=diff == --- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original) +++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Thu May 17 05:40:50 2018 @@ -61,6 +61,12 @@ AST_MATCHER_P(CXXMethodDecl, ofOutermost return InnerMatcher.matches(*Parent, Finder, Builder); } +std::string CleanPath(StringRef PathRef) { + llvm::SmallString<128> Path(PathRef); + llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true); + return Path.str(); +} + // Make the Path absolute using the CurrentDir if the Path is not an absolute // path. An empty Path will result in an empty string. std::string MakeAbsolutePath(StringRef CurrentDir, StringRef Path) { @@ -72,9 +78,7 @@ std::string MakeAbsolutePath(StringRef C llvm::sys::fs::make_absolute(InitialDirectory, AbsolutePath)) llvm::errs() << "Warning: could not make absolute file: '" << EC.message() << '\n'; - llvm::sys::path::remove_dots(AbsolutePath, /*remove_dot_dot=*/true); - llvm::sys::path::native(AbsolutePath); - return AbsolutePath.str(); + return CleanPath(std::move(AbsolutePath)); } // Make the Path absolute using the current working directory of the given @@ -97,15 +101,13 @@ std::string MakeAbsolutePath(const Sourc StringRef DirName = SM.getFileManager().getCanonicalName(Dir); // FIXME: getCanonicalName might fail to get real path on VFS. if (llvm::sys::path::is_absolute(DirName)) { - SmallVector AbsoluteFilename; + SmallString<128> AbsoluteFilename; llvm::sys::path::append(AbsoluteFilename, DirName, llvm::sys::path::filename(AbsolutePath.str())); - return llvm::StringRef(AbsoluteFilename.data(), AbsoluteFilename.size()) - .str(); + return CleanPath(AbsoluteFilename); } } - llvm::sys::path::remove_dots(AbsolutePath, /*remove_dot_dot=*/true); - return AbsolutePath.str(); + return CleanPath(AbsolutePath); } // Matches AST nodes that are expanded within the given AbsoluteFilePath. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r332612 - Second attempt to fix clang-move tests broken by r332590 on windows
Author: ioeric Date: Thu May 17 07:59:15 2018 New Revision: 332612 URL: http://llvm.org/viewvc/llvm-project?rev=332612&view=rev Log: Second attempt to fix clang-move tests broken by r332590 on windows http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/12010 Add back a path conversion removed in a previous attempt. I removed it because it didn't seem necessary. Added it back to see if this would fix the bot. Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=332612&r1=332611&r2=332612&view=diff == --- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original) +++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Thu May 17 07:59:15 2018 @@ -64,6 +64,8 @@ AST_MATCHER_P(CXXMethodDecl, ofOutermost std::string CleanPath(StringRef PathRef) { llvm::SmallString<128> Path(PathRef); llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true); + // FIXME: figure out why this is necessary. + llvm::sys::path::native(Path); return Path.str(); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r332620 - Disable a failing clang-move test on windows.
Author: ioeric Date: Thu May 17 09:13:36 2018 New Revision: 332620 URL: http://llvm.org/viewvc/llvm-project?rev=332620&view=rev Log: Disable a failing clang-move test on windows. This was broken by r332590 but is likely caused by a bug in clang-move. http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/12007 I don't have a windows machine to effectively debug the issue, so I'll investigate further but for now disable the failing test on windows to unbreak build bots. Modified: clang-tools-extra/trunk/test/clang-move/move-class.cpp Modified: clang-tools-extra/trunk/test/clang-move/move-class.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-move/move-class.cpp?rev=332620&r1=332619&r2=332620&view=diff == --- clang-tools-extra/trunk/test/clang-move/move-class.cpp (original) +++ clang-tools-extra/trunk/test/clang-move/move-class.cpp Thu May 17 09:13:36 2018 @@ -1,3 +1,7 @@ +// UNSUPPORTED: system-windows +// new_test.cpp contains #include of old test.h when running on windows. This is +// probably by a bug for path handling in clang-move. +// // RUN: mkdir -p %T/clang-move/build // RUN: mkdir -p %T/clang-move/include // RUN: mkdir -p %T/clang-move/src ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r332701 - Re-enable a clang-move test on windows.
Author: ioeric Date: Fri May 18 02:25:36 2018 New Revision: 332701 URL: http://llvm.org/viewvc/llvm-project?rev=332701&view=rev Log: Re-enable a clang-move test on windows. This was fixed by r332612. Modified: clang-tools-extra/trunk/test/clang-move/move-class.cpp Modified: clang-tools-extra/trunk/test/clang-move/move-class.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-move/move-class.cpp?rev=332701&r1=332700&r2=332701&view=diff == --- clang-tools-extra/trunk/test/clang-move/move-class.cpp (original) +++ clang-tools-extra/trunk/test/clang-move/move-class.cpp Fri May 18 02:25:36 2018 @@ -1,7 +1,3 @@ -// UNSUPPORTED: system-windows -// new_test.cpp contains #include of old test.h when running on windows. This is -// probably by a bug for path handling in clang-move. -// // RUN: mkdir -p %T/clang-move/build // RUN: mkdir -p %T/clang-move/include // RUN: mkdir -p %T/clang-move/src ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r332717 - [VFS] Implement getRealPath for OverlayFileSystem.
Author: ioeric Date: Fri May 18 06:22:49 2018 New Revision: 332717 URL: http://llvm.org/viewvc/llvm-project?rev=332717&view=rev Log: [VFS] Implement getRealPath for OverlayFileSystem. Reviewers: bkramer Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D47060 Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h cfe/trunk/lib/Basic/VirtualFileSystem.cpp cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=332717&r1=332716&r2=332717&view=diff == --- cfe/trunk/include/clang/Basic/VirtualFileSystem.h (original) +++ cfe/trunk/include/clang/Basic/VirtualFileSystem.h Fri May 18 06:22:49 2018 @@ -304,15 +304,20 @@ public: directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override; llvm::ErrorOr getCurrentWorkingDirectory() const override; std::error_code setCurrentWorkingDirectory(const Twine &Path) override; + std::error_code getRealPath(const Twine &Path, + SmallVectorImpl &Output) const override; using iterator = FileSystemList::reverse_iterator; - + using const_iterator = FileSystemList::const_reverse_iterator; + /// Get an iterator pointing to the most recently added file system. iterator overlays_begin() { return FSList.rbegin(); } + const_iterator overlays_begin() const { return FSList.rbegin(); } /// Get an iterator pointing one-past the least recently added file /// system. iterator overlays_end() { return FSList.rend(); } + const_iterator overlays_end() const { return FSList.rend(); } }; namespace detail { Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=332717&r1=332716&r2=332717&view=diff == --- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original) +++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Fri May 18 06:22:49 2018 @@ -381,6 +381,15 @@ OverlayFileSystem::setCurrentWorkingDire return {}; } +std::error_code +OverlayFileSystem::getRealPath(const Twine &Path, + SmallVectorImpl &Output) const { + for (auto &FS : FSList) +if (FS->exists(Path)) + return FS->getRealPath(Path, Output); + return errc::no_such_file_or_directory; +} + clang::vfs::detail::DirIterImpl::~DirIterImpl() = default; namespace { Modified: cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp?rev=332717&r1=332716&r2=332717&view=diff == --- cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp (original) +++ cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp Fri May 18 06:22:49 2018 @@ -67,6 +67,21 @@ public: std::error_code setCurrentWorkingDirectory(const Twine &Path) override { return std::error_code(); } + // Map any symlink to "/symlink". + std::error_code getRealPath(const Twine &Path, + SmallVectorImpl &Output) const override { +auto I = FilesAndDirs.find(Path.str()); +if (I == FilesAndDirs.end()) + return make_error_code(llvm::errc::no_such_file_or_directory); +if (I->second.isSymlink()) { + Output.clear(); + Twine("/symlink").toVector(Output); + return std::error_code(); +} +Output.clear(); +Path.toVector(Output); +return std::error_code(); + } struct DirIterImpl : public clang::vfs::detail::DirIterImpl { std::map &FilesAndDirs; @@ -196,6 +211,35 @@ TEST(VirtualFileSystemTest, BaseOnlyOver EXPECT_TRUE(Status->equivalent(*Status2)); } +TEST(VirtualFileSystemTest, GetRealPathInOverlay) { + IntrusiveRefCntPtr Lower(new DummyFileSystem()); + Lower->addRegularFile("/foo"); + Lower->addSymlink("/lower_link"); + IntrusiveRefCntPtr Upper(new DummyFileSystem()); + + IntrusiveRefCntPtr O( + new vfs::OverlayFileSystem(Lower)); + O->pushOverlay(Upper); + + // Regular file. + SmallString<16> RealPath; + EXPECT_FALSE(O->getRealPath("/foo", RealPath)); + EXPECT_EQ(RealPath.str(), "/foo"); + + // Expect no error getting real path for symlink in lower overlay. + EXPECT_FALSE(O->getRealPath("/lower_link", RealPath)); + EXPECT_EQ(RealPath.str(), "/symlink"); + + // Try a non-existing link. + EXPECT_EQ(O->getRealPath("/upper_link", RealPath), +errc::no_such_file_or_directory); + + // Add a new symlink in upper. + Upper->addSymlink("/upper_link"); + EXPECT_FALSE(O->getRealPath("/upper_link", RealPath)); + EXPECT_EQ(RealPath.str(), "/symlink"); +} + TEST(VirtualFileSystemTest, OverlayFiles) { IntrusiveRefCntPtr Base(new DummyFileSystem()); IntrusiveRefCntPtr Middle
r332720 - Move #include manipulation code to new lib/Tooling/Inclusions.
Author: ioeric Date: Fri May 18 07:16:37 2018 New Revision: 332720 URL: http://llvm.org/viewvc/llvm-project?rev=332720&view=rev Log: Move #include manipulation code to new lib/Tooling/Inclusions. Summary: clangToolingCore is linked into almost everything (incl. clang), but not few tools need #include manipulation at this point. So pull this into a separate library in Tooling. Reviewers: ilya-biryukov Subscribers: klimek, mgorny, cfe-commits, thakis Differential Revision: https://reviews.llvm.org/D47068 Added: cfe/trunk/include/clang/Tooling/Inclusions/ cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h - copied, changed from r332717, cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h - copied, changed from r332717, cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h cfe/trunk/lib/Tooling/Inclusions/ cfe/trunk/lib/Tooling/Inclusions/CMakeLists.txt - copied, changed from r332717, cfe/trunk/lib/Tooling/Core/CMakeLists.txt cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp - copied, changed from r332717, cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp cfe/trunk/lib/Tooling/Inclusions/IncludeStyle.cpp - copied, changed from r332717, cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp Removed: cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp Modified: cfe/trunk/include/clang/Format/Format.h cfe/trunk/lib/Format/CMakeLists.txt cfe/trunk/lib/Format/Format.cpp cfe/trunk/lib/Tooling/CMakeLists.txt cfe/trunk/lib/Tooling/Core/CMakeLists.txt cfe/trunk/unittests/Tooling/HeaderIncludesTest.cpp Modified: cfe/trunk/include/clang/Format/Format.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=332720&r1=332719&r2=332720&view=diff == --- cfe/trunk/include/clang/Format/Format.h (original) +++ cfe/trunk/include/clang/Format/Format.h Fri May 18 07:16:37 2018 @@ -16,8 +16,8 @@ #define LLVM_CLANG_FORMAT_FORMAT_H #include "clang/Basic/LangOptions.h" -#include "clang/Tooling/Core/IncludeStyle.h" #include "clang/Tooling/Core/Replacement.h" +#include "clang/Tooling/Inclusions/IncludeStyle.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/Support/Regex.h" #include Removed: cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h?rev=332719&view=auto == --- cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h (original) +++ cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h (removed) @@ -1,137 +0,0 @@ -//===--- HeaderIncludes.h - Insert/Delete #includes for C++ code--*- C++-*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===--===// - -#ifndef LLVM_CLANG_TOOLING_CORE_HEADERINCLUDES_H -#define LLVM_CLANG_TOOLING_CORE_HEADERINCLUDES_H - -#include "clang/Basic/SourceManager.h" -#include "clang/Tooling/Core/Replacement.h" -#include "clang/Tooling/Core/IncludeStyle.h" -#include "llvm/Support/Path.h" -#include "llvm/Support/Regex.h" -#include - -namespace clang { -namespace tooling { - -/// This class manages priorities of C++ #include categories and calculates -/// priorities for headers. -/// FIXME(ioeric): move this class into implementation file when clang-format's -/// include sorting functions are also moved here. -class IncludeCategoryManager { -public: - IncludeCategoryManager(const IncludeStyle &Style, StringRef FileName); - - /// Returns the priority of the category which \p IncludeName belongs to. - /// If \p CheckMainHeader is true and \p IncludeName is a main header, returns - /// 0. Otherwise, returns the priority of the matching category or INT_MAX. - /// NOTE: this API is not thread-safe! - int getIncludePriority(StringRef IncludeName, bool CheckMainHeader) const; - -private: - bool isMainHeader(StringRef IncludeName) const; - - const IncludeStyle Style; - bool IsMainFile; - std::string FileName; - // This refers to a substring in FileName. - StringRef FileStem; - // Regex is not thread-safe. - mutable SmallVector CategoryRegexs; -}; - -/// Generates replacements for inserting or deleting #include directives in a -/// file. -class HeaderIncludes { -public: - HeaderIncludes(llvm::StringRef FileName, llvm::StringRef Code, - const IncludeStyle &Style); - - /// Inserts an #include directive of \p Header into the code. If \p IsAngled - /// is true, \p Header will be quoted with <> in
[clang-tools-extra] r332721 - [clangd] Adapt file migration in r332720
Author: ioeric Date: Fri May 18 07:17:36 2018 New Revision: 332721 URL: http://llvm.org/viewvc/llvm-project?rev=332721&view=rev Log: [clangd] Adapt file migration in r332720 Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt clang-tools-extra/trunk/clangd/Headers.h Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=332721&r1=332720&r2=332721&view=diff == --- clang-tools-extra/trunk/clangd/CMakeLists.txt (original) +++ clang-tools-extra/trunk/clangd/CMakeLists.txt Fri May 18 07:17:36 2018 @@ -55,6 +55,7 @@ add_clang_library(clangDaemon clangSerialization clangTooling clangToolingCore + clangToolingInclusions clangToolingRefactor ${LLVM_PTHREAD_LIB} ${CLANGD_ATOMIC_LIB} Modified: clang-tools-extra/trunk/clangd/Headers.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.h?rev=332721&r1=332720&r2=332721&view=diff == --- clang-tools-extra/trunk/clangd/Headers.h (original) +++ clang-tools-extra/trunk/clangd/Headers.h Fri May 18 07:17:36 2018 @@ -17,7 +17,7 @@ #include "clang/Format/Format.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/PPCallbacks.h" -#include "clang/Tooling/Core/HeaderIncludes.h" +#include "clang/Tooling/Inclusions/HeaderIncludes.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/Error.h" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r332731 - [Tooling] Add an overload of runToolOnCodeWithArgs that takes VFS
Author: ioeric Date: Fri May 18 09:06:19 2018 New Revision: 332731 URL: http://llvm.org/viewvc/llvm-project?rev=332731&view=rev Log: [Tooling] Add an overload of runToolOnCodeWithArgs that takes VFS Summary: ... to support purely VFS-based tools. Reviewers: bkramer Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D47074 Modified: cfe/trunk/include/clang/Tooling/Tooling.h cfe/trunk/lib/Tooling/Tooling.cpp Modified: cfe/trunk/include/clang/Tooling/Tooling.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Tooling.h?rev=332731&r1=332730&r2=332731&view=diff == --- cfe/trunk/include/clang/Tooling/Tooling.h (original) +++ cfe/trunk/include/clang/Tooling/Tooling.h Fri May 18 09:06:19 2018 @@ -187,6 +187,15 @@ bool runToolOnCodeWithArgs( std::make_shared(), const FileContentMappings &VirtualMappedFiles = FileContentMappings()); +// Similar to the overload except this takes a VFS. +bool runToolOnCodeWithArgs( +FrontendAction *ToolAction, const Twine &Code, +llvm::IntrusiveRefCntPtr VFS, +const std::vector &Args, const Twine &FileName = "input.cc", +const Twine &ToolName = "clang-tool", +std::shared_ptr PCHContainerOps = +std::make_shared()); + /// Builds an AST for 'Code'. /// /// \param Code C++ code. Modified: cfe/trunk/lib/Tooling/Tooling.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?rev=332731&r1=332730&r2=332731&view=diff == --- cfe/trunk/lib/Tooling/Tooling.cpp (original) +++ cfe/trunk/lib/Tooling/Tooling.cpp Fri May 18 09:06:19 2018 @@ -155,27 +155,37 @@ namespace tooling { bool runToolOnCodeWithArgs( FrontendAction *ToolAction, const Twine &Code, +llvm::IntrusiveRefCntPtr VFS, const std::vector &Args, const Twine &FileName, const Twine &ToolName, -std::shared_ptr PCHContainerOps, -const FileContentMappings &VirtualMappedFiles) { +std::shared_ptr PCHContainerOps) { SmallString<16> FileNameStorage; StringRef FileNameRef = FileName.toNullTerminatedStringRef(FileNameStorage); - llvm::IntrusiveRefCntPtr OverlayFileSystem( - new vfs::OverlayFileSystem(vfs::getRealFileSystem())); - llvm::IntrusiveRefCntPtr InMemoryFileSystem( - new vfs::InMemoryFileSystem); - OverlayFileSystem->pushOverlay(InMemoryFileSystem); + llvm::IntrusiveRefCntPtr Files( - new FileManager(FileSystemOptions(), OverlayFileSystem)); + new FileManager(FileSystemOptions(), VFS)); ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster(); ToolInvocation Invocation( getSyntaxOnlyToolArgs(ToolName, Adjuster(Args, FileNameRef), FileNameRef), ToolAction, Files.get(), std::move(PCHContainerOps)); + return Invocation.run(); +} + +bool runToolOnCodeWithArgs( +FrontendAction *ToolAction, const Twine &Code, +const std::vector &Args, const Twine &FileName, +const Twine &ToolName, +std::shared_ptr PCHContainerOps, +const FileContentMappings &VirtualMappedFiles) { + llvm::IntrusiveRefCntPtr OverlayFileSystem( + new vfs::OverlayFileSystem(vfs::getRealFileSystem())); + llvm::IntrusiveRefCntPtr InMemoryFileSystem( + new vfs::InMemoryFileSystem); + OverlayFileSystem->pushOverlay(InMemoryFileSystem); SmallString<1024> CodeStorage; - InMemoryFileSystem->addFile(FileNameRef, 0, + InMemoryFileSystem->addFile(FileName, 0, llvm::MemoryBuffer::getMemBuffer( Code.toNullTerminatedStringRef(CodeStorage))); @@ -185,7 +195,8 @@ bool runToolOnCodeWithArgs( llvm::MemoryBuffer::getMemBuffer(FilenameWithContent.second)); } - return Invocation.run(); + return runToolOnCodeWithArgs(ToolAction, Code, OverlayFileSystem, Args, + FileName, ToolName); } std::string getAbsolutePath(StringRef File) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r332732 - Trying to fix clang-move tests on windows build bot broken by r332717
Author: ioeric Date: Fri May 18 09:08:18 2018 New Revision: 332732 URL: http://llvm.org/viewvc/llvm-project?rev=332732&view=rev Log: Trying to fix clang-move tests on windows build bot broken by r332717 http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/10702 Modified: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp Modified: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp?rev=332732&r1=332731&r2=332732&view=diff == --- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp Fri May 18 09:08:18 2018 @@ -24,10 +24,6 @@ namespace clang { namespace move { namespace { -const char TestHeaderName[] = "foo.h"; - -const char TestCCName[] = "foo.cc"; - const char TestHeader[] = "namespace a {\n" "class C1; // test\n" "template class C2;\n" @@ -196,6 +192,15 @@ const char ExpectedNewCC[] = "namespace "} // namespace b\n" "} // namespace a\n"; +#ifdef _WIN32 +const char WorkingDir[] = "C:\\test"; +#else +const char WorkingDir[] = "/test"; +#endif + +const char TestHeaderName[] = "foo.h"; +const char TestCCName[] = "foo.cc"; + std::map runClangMoveOnCode(const move::MoveDefinitionSpec &Spec, const char *const Header = TestHeader, @@ -203,9 +208,9 @@ runClangMoveOnCode(const move::MoveDefin DeclarationReporter *const Reporter = nullptr) { clang::RewriterTestContext Context; + Context.InMemoryFileSystem->setCurrentWorkingDirectory(WorkingDir); + std::map FileToFileID; - std::vector> FileToSourceText = { - {TestHeaderName, Header}, {TestCCName, CC}}; auto CreateFiles = [&Context, &FileToFileID](llvm::StringRef Name, llvm::StringRef Code) { @@ -215,25 +220,21 @@ runClangMoveOnCode(const move::MoveDefin }; CreateFiles(Spec.NewCC, ""); CreateFiles(Spec.NewHeader, ""); - CreateFiles(Spec.OldHeader, Header); - CreateFiles(Spec.OldCC, CC); + CreateFiles(TestHeaderName, Header); + CreateFiles(TestCCName, CC); std::map FileToReplacements; - llvm::SmallString<128> InitialDirectory; - std::error_code EC = llvm::sys::fs::current_path(InitialDirectory); - assert(!EC); - (void)EC; - ClangMoveContext MoveContext = {Spec, FileToReplacements, - InitialDirectory.str(), "LLVM", + ClangMoveContext MoveContext = {Spec, FileToReplacements, WorkingDir, "LLVM", Reporter != nullptr}; auto Factory = llvm::make_unique( &MoveContext, Reporter); + // std::string IncludeArg = Twine("-I" + WorkingDir; tooling::runToolOnCodeWithArgs( - Factory->create(), CC, {"-std=c++11", "-fparse-all-comments"}, - TestCCName, "clang-move", std::make_shared(), - FileToSourceText); + Factory->create(), CC, Context.InMemoryFileSystem, + {"-std=c++11", "-fparse-all-comments", "-I."}, TestCCName, "clang-move", + std::make_shared()); formatAndApplyAllReplacements(FileToReplacements, Context.Rewrite, "llvm"); // The Key is file name, value is the new code after moving the class. std::map Results; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r332734 - Fix unused variable warning in r332724
Author: ioeric Date: Fri May 18 09:29:42 2018 New Revision: 332734 URL: http://llvm.org/viewvc/llvm-project?rev=332734&view=rev Log: Fix unused variable warning in r332724 Modified: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp Modified: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp?rev=332734&r1=332733&r2=332734&view=diff == --- cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp Fri May 18 09:29:42 2018 @@ -1330,6 +1330,7 @@ void tools::AddHIPLinkerScript(const Too C.getSingleOffloadToolChain()); assert(HIPTC->getTriple().getArch() == llvm::Triple::amdgcn && "Wrong platform"); + (void)HIPTC; // Construct clang-offload-bundler command to bundle object files for // for different GPU archs. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r332720 - Move #include manipulation code to new lib/Tooling/Inclusions.
Hi Vedant, It seems that your build was not using cmake files in the source tree? lib/Tooling/Inclusions/ is a (new) standalone library (clangToolingInclusions, similar to clangToolingCore). You might need update your build to reflect this change. Let me know if you have any further question. Thanks, Eric On Fri, May 18, 2018 at 6:41 PM Vedant Kumar wrote: > Hi Eric, > > I think there might be a cyclic dependency issue here, possibly one that's > only visible with LLVM_ENABLE_MODULES=On. I see: > > While building module 'Clang_Tooling' imported from > /Users/vsk/src/llvm.org-master/llvm/tools/clang/lib/Tooling/Execution.cpp:10: > > While building module 'Clang_Format' imported from > /Users/vsk/src/llvm.org-master/llvm/tools/clang/include/clang/Tooling/Refactoring/AtomicChange.h:19: > > In file included from :1: > > > /Users/vsk/src/llvm.org-master/llvm/tools/clang/include/clang/Format/Format.h:20:10: > fatal error: cyclic dependency in module 'Clang_Tooling': Clang_Tooling $> > Clang_Format -> Clang_Tooling > > #include "clang/Tooling/Inclusions/IncludeStyle.h" > ^ > While building module 'Clang_Tooling' imported from > /Users/vsk/src/llvm.org-master/llvm/tools/clang/lib/Tooling/Execution.cpp:10: > In file included from :22: > > In file included from > /Users/vsk/src/llvm.org-master/llvm/tools/clang/include/clang/Tooling/Refactoring/RefactoringAction.h:14: > In file included from > /Users/vsk/src/llvm.org-master/llvm/tools/clang/include/clang/Tooling/Refactoring/RefactoringActionRules.h:14: > In file included from > /Users/vsk/src/llvm.org-master/llvm/tools/clang/include/clang/Tooling/Refactoring/RefactoringActionRulesInternal.h:16: > In file included from > /Users/vsk/src/llvm.org-master/llvm/tools/clang/include/clang/Tooling/Refactoring/RefactoringResultConsumer.h:14: > /Users/vsk/src/llvm.org-master/llvm/tools/clang/include/clang/Tooling/Refactoring/AtomicChange.h:19:10: > fatal error: could not build module 'Clang_Format' > #include "clang/Format/Format.h" > ^~~ > /Users/vsk/src/llvm.org-master/llvm/tools/clang/lib/Tooling/Execution.cpp:10:10: > fatal error: could not build module 'Clang_Tooling' > #include "clang/Tooling/Execution.h" > > ^~~ > 3 errors generated. > > Could you take a look? > > thanks, > vedant > > > On May 18, 2018, at 7:16 AM, Eric Liu via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > > > > Author: ioeric > > Date: Fri May 18 07:16:37 2018 > > New Revision: 332720 > > > > URL: http://llvm.org/viewvc/llvm-project?rev=332720&view=rev > > Log: > > Move #include manipulation code to new lib/Tooling/Inclusions. > > > > Summary: > > clangToolingCore is linked into almost everything (incl. clang), but > > not few tools need #include manipulation at this point. So pull this > into a > > separate library in Tooling. > > > > Reviewers: ilya-biryukov > > > > Subscribers: klimek, mgorny, cfe-commits, thakis > > > > Differential Revision: https://reviews.llvm.org/D47068 > > > > Added: > >cfe/trunk/include/clang/Tooling/Inclusions/ > >cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h > > - copied, changed from r332717, > cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h > >cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h > > - copied, changed from r332717, > cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h > >cfe/trunk/lib/Tooling/Inclusions/ > >cfe/trunk/lib/Tooling/Inclusions/CMakeLists.txt > > - copied, changed from r332717, > cfe/trunk/lib/Tooling/Core/CMakeLists.txt > >cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp > > - copied, changed from r332717, > cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp > >cfe/trunk/lib/Tooling/Inclusions/IncludeStyle.cpp > > - copied, changed from r332717, > cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp > > Removed: > >cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h > >cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h > >cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp > >cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp > > Modified: > >cfe/trunk/include/clang/Format/Format.h > >cfe/trunk/lib/Format/CMakeLists.txt > >cfe/trunk/lib/Format/Format.cpp > >cfe/trunk/lib/Tooling/CMakeLists.txt > >cfe/trunk/lib/Tooling/Core/CMakeLists.txt > >cfe/trunk/unittests/Tooling/HeaderIncludesTest.cpp > > > > Modified: cfe/
Re: r332720 - Move #include manipulation code to new lib/Tooling/Inclusions.
Sorry, I'll look into it right now. Will revert it if I can't find a quick fix. On Fri, May 18, 2018, 19:49 Amara Emerson wrote: > Hi Eric, > > Green dragon buildbots have started failing too, e.g.: > http://green.lab.llvm.org/green/job/clang-stage2-Rthinlto/10222/ > > If you don’t have a quick fix can you please revert it. > > Thanks, > Amara > > > On May 18, 2018, at 7:46 PM, Eric Liu wrote: > > Hi Vedant, > > It seems that your build was not using cmake files in the source tree? > lib/Tooling/Inclusions/ > is a (new) standalone library (clangToolingInclusions, similar to > clangToolingCore). You might need update your build to reflect this change. > Let me know if you have any further question. > > Thanks, > Eric > > On Fri, May 18, 2018 at 6:41 PM Vedant Kumar wrote: > >> Hi Eric, >> >> I think there might be a cyclic dependency issue here, possibly one >> that's only visible with LLVM_ENABLE_MODULES=On. I see: >> >> While building module 'Clang_Tooling' imported from /Users/vsk/src/ >> llvm.org-master/llvm/tools/clang/lib/Tooling/Execution.cpp:10: >> >> While building module 'Clang_Format' imported from /Users/vsk/src/ >> llvm.org-master/llvm/tools/clang/include/clang/Tooling/Refactoring/AtomicChange.h:19: >> >> In file included from :1: >> >> >> /Users/vsk/src/llvm.org-master/llvm/tools/clang/include/clang/Format/Format.h:20:10: >> fatal error: cyclic dependency in module 'Clang_Tooling': Clang_Tooling $> >> Clang_Format -> Clang_Tooling >> >> #include "clang/Tooling/Inclusions/IncludeStyle.h" >> ^ >> While building module 'Clang_Tooling' imported from /Users/vsk/src/ >> llvm.org-master/llvm/tools/clang/lib/Tooling/Execution.cpp:10: >> In file included from :22: >> >> In file included from /Users/vsk/src/llvm.org >> -master/llvm/tools/clang/include/clang/Tooling/Refactoring/RefactoringAction.h:14: >> In file included from /Users/vsk/src/llvm.org >> -master/llvm/tools/clang/include/clang/Tooling/Refactoring/RefactoringActionRules.h:14: >> In file included from /Users/vsk/src/llvm.org >> -master/llvm/tools/clang/include/clang/Tooling/Refactoring/RefactoringActionRulesInternal.h:16: >> In file included from /Users/vsk/src/llvm.org >> -master/llvm/tools/clang/include/clang/Tooling/Refactoring/RefactoringResultConsumer.h:14: >> /Users/vsk/src/llvm.org-master/llvm/tools/clang/include/clang/Tooling/Refactoring/AtomicChange.h:19:10: >> fatal error: could not build module 'Clang_Format' >> #include "clang/Format/Format.h" >> ~~~~^~~ >> /Users/vsk/src/llvm.org-master/llvm/tools/clang/lib/Tooling/Execution.cpp:10:10: >> fatal error: could not build module 'Clang_Tooling' >> #include "clang/Tooling/Execution.h" >> >> ^~~ >> 3 errors generated. >> >> Could you take a look? >> >> thanks, >> vedant >> >> > On May 18, 2018, at 7:16 AM, Eric Liu via cfe-commits < >> cfe-commits@lists.llvm.org> wrote: >> > >> > Author: ioeric >> > Date: Fri May 18 07:16:37 2018 >> > New Revision: 332720 >> > >> > URL: http://llvm.org/viewvc/llvm-project?rev=332720&view=rev >> > Log: >> > Move #include manipulation code to new lib/Tooling/Inclusions. >> > >> > Summary: >> > clangToolingCore is linked into almost everything (incl. clang), but >> > not few tools need #include manipulation at this point. So pull this >> into a >> > separate library in Tooling. >> > >> > Reviewers: ilya-biryukov >> > >> > Subscribers: klimek, mgorny, cfe-commits, thakis >> > >> > Differential Revision: https://reviews.llvm.org/D47068 >> > >> > Added: >> >cfe/trunk/include/clang/Tooling/Inclusions/ >> >cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h >> > - copied, changed from r332717, >> cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h >> >cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h >> > - copied, changed from r332717, >> cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h >> >cfe/trunk/lib/Tooling/Inclusions/ >> >cfe/trunk/lib/Tooling/Inclusions/CMakeLists.txt >> > - copied, changed from r332717, >> cfe/trunk/lib/Tooling/Core/CMakeLists.txt >> >cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp >> > - copied, change
r332751 - Revert "Move #include manipulation code to new lib/Tooling/Inclusions."
Author: ioeric Date: Fri May 18 11:33:08 2018 New Revision: 332751 URL: http://llvm.org/viewvc/llvm-project?rev=332751&view=rev Log: Revert "Move #include manipulation code to new lib/Tooling/Inclusions." This reverts commit r332720. This break build bot with modules. Need to investigate. Revert the change to unbreak bots. Added: cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h - copied, changed from r332738, cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h - copied, changed from r332738, cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp - copied, changed from r332738, cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp - copied, changed from r332738, cfe/trunk/lib/Tooling/Inclusions/IncludeStyle.cpp Removed: cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h cfe/trunk/lib/Tooling/Inclusions/CMakeLists.txt cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp cfe/trunk/lib/Tooling/Inclusions/IncludeStyle.cpp Modified: cfe/trunk/include/clang/Format/Format.h cfe/trunk/lib/Format/CMakeLists.txt cfe/trunk/lib/Format/Format.cpp cfe/trunk/lib/Tooling/CMakeLists.txt cfe/trunk/lib/Tooling/Core/CMakeLists.txt cfe/trunk/unittests/Tooling/HeaderIncludesTest.cpp Modified: cfe/trunk/include/clang/Format/Format.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=332751&r1=332750&r2=332751&view=diff == --- cfe/trunk/include/clang/Format/Format.h (original) +++ cfe/trunk/include/clang/Format/Format.h Fri May 18 11:33:08 2018 @@ -16,8 +16,8 @@ #define LLVM_CLANG_FORMAT_FORMAT_H #include "clang/Basic/LangOptions.h" +#include "clang/Tooling/Core/IncludeStyle.h" #include "clang/Tooling/Core/Replacement.h" -#include "clang/Tooling/Inclusions/IncludeStyle.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/Support/Regex.h" #include Copied: cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h (from r332738, cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h) URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h?p2=cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h&p1=cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h&r1=332738&r2=332751&rev=332751&view=diff == --- cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h (original) +++ cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h Fri May 18 11:33:08 2018 @@ -7,12 +7,12 @@ // //===--===// -#ifndef LLVM_CLANG_TOOLING_INCLUSIONS_HEADERINCLUDES_H -#define LLVM_CLANG_TOOLING_INCLUSIONS_HEADERINCLUDES_H +#ifndef LLVM_CLANG_TOOLING_CORE_HEADERINCLUDES_H +#define LLVM_CLANG_TOOLING_CORE_HEADERINCLUDES_H #include "clang/Basic/SourceManager.h" #include "clang/Tooling/Core/Replacement.h" -#include "clang/Tooling/Inclusions/IncludeStyle.h" +#include "clang/Tooling/Core/IncludeStyle.h" #include "llvm/Support/Path.h" #include "llvm/Support/Regex.h" #include @@ -134,4 +134,4 @@ private: } // namespace tooling } // namespace clang -#endif // LLVM_CLANG_TOOLING_INCLUSIONS_HEADERINCLUDES_H +#endif // LLVM_CLANG_TOOLING_CORE_HEADERINCLUDES_H Copied: cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h (from r332738, cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h) URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h?p2=cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h&p1=cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h&r1=332738&r2=332751&rev=332751&view=diff == --- cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h (original) +++ cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h Fri May 18 11:33:08 2018 @@ -7,8 +7,8 @@ // //===--===// -#ifndef LLVM_CLANG_TOOLING_INCLUSIONS_INCLUDESTYLE_H -#define LLVM_CLANG_TOOLING_INCLUSIONS_INCLUDESTYLE_H +#ifndef LLVM_CLANG_TOOLING_CORE_INCLUDESTYLE_H +#define LLVM_CLANG_TOOLING_CORE_INCLUDESTYLE_H #include "llvm/Support/YAMLTraits.h" #include @@ -130,4 +130,4 @@ struct ScalarEnumerationTraits< } // namespace yaml } // namespace llvm -#endif // LLVM_CLANG_TOOLING_INCLUSIONS_INCLUDESTYLE_H +#endif // LLVM_CLANG_TOOLING_CORE_INCLUDESTYLE_H Removed: cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h?rev=332750&view=auto
[clang-tools-extra] r332752 - Revert "[clangd] Adapt file migration in r332720"
Author: ioeric Date: Fri May 18 11:33:21 2018 New Revision: 332752 URL: http://llvm.org/viewvc/llvm-project?rev=332752&view=rev Log: Revert "[clangd] Adapt file migration in r332720" This reverts commit r332721 because the dependency r33270 will be reverted. Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt clang-tools-extra/trunk/clangd/Headers.h Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=332752&r1=332751&r2=332752&view=diff == --- clang-tools-extra/trunk/clangd/CMakeLists.txt (original) +++ clang-tools-extra/trunk/clangd/CMakeLists.txt Fri May 18 11:33:21 2018 @@ -55,7 +55,6 @@ add_clang_library(clangDaemon clangSerialization clangTooling clangToolingCore - clangToolingInclusions clangToolingRefactor ${LLVM_PTHREAD_LIB} ${CLANGD_ATOMIC_LIB} Modified: clang-tools-extra/trunk/clangd/Headers.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.h?rev=332752&r1=332751&r2=332752&view=diff == --- clang-tools-extra/trunk/clangd/Headers.h (original) +++ clang-tools-extra/trunk/clangd/Headers.h Fri May 18 11:33:21 2018 @@ -17,7 +17,7 @@ #include "clang/Format/Format.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/PPCallbacks.h" -#include "clang/Tooling/Inclusions/HeaderIncludes.h" +#include "clang/Tooling/Core/HeaderIncludes.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/Error.h" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r332720 - Move #include manipulation code to new lib/Tooling/Inclusions.
So I have reverted this with r332751. I can't see how this introduced cyclic dependencies in module build, as the dependencies should be clangTooling -> clangFormat -> clangToolingInclusions. I'm wondering if there is any module configurations that I need to update to make this work. Right now, module doesn't seem to make any difference between clangTooling and clangToolingInclusions... I'd appreciate it if someone who knows how clang module build is set up could help take a look. Unfortunately, I couldn't reproduce this on my workstation as the module build seemed to be broken due to other errors. I was seeing a lot of warnings; the clang I used to build llvm was built near HEAD. Maybe my clang is too new? Thanks, Eric On Fri, May 18, 2018 at 7:52 PM Eric Liu wrote: > Sorry, I'll look into it right now. Will revert it if I can't find a quick > fix. > > On Fri, May 18, 2018, 19:49 Amara Emerson wrote: > >> Hi Eric, >> >> Green dragon buildbots have started failing too, e.g.: >> http://green.lab.llvm.org/green/job/clang-stage2-Rthinlto/10222/ >> >> If you don’t have a quick fix can you please revert it. >> >> Thanks, >> Amara >> >> >> On May 18, 2018, at 7:46 PM, Eric Liu wrote: >> >> Hi Vedant, >> >> It seems that your build was not using cmake files in the source tree? >> lib/Tooling/Inclusions/ >> is a (new) standalone library (clangToolingInclusions, similar to >> clangToolingCore). You might need update your build to reflect this change. >> Let me know if you have any further question. >> >> Thanks, >> Eric >> >> On Fri, May 18, 2018 at 6:41 PM Vedant Kumar wrote: >> >>> Hi Eric, >>> >>> I think there might be a cyclic dependency issue here, possibly one >>> that's only visible with LLVM_ENABLE_MODULES=On. I see: >>> >>> While building module 'Clang_Tooling' imported from /Users/vsk/src/ >>> llvm.org-master/llvm/tools/clang/lib/Tooling/Execution.cpp:10: >>> >>> While building module 'Clang_Format' imported from /Users/vsk/src/ >>> llvm.org-master/llvm/tools/clang/include/clang/Tooling/Refactoring/AtomicChange.h:19: >>> >>> In file included from :1: >>> >>> >>> /Users/vsk/src/llvm.org-master/llvm/tools/clang/include/clang/Format/Format.h:20:10: >>> fatal error: cyclic dependency in module 'Clang_Tooling': Clang_Tooling $> >>> Clang_Format -> Clang_Tooling >>> >>> #include "clang/Tooling/Inclusions/IncludeStyle.h" >>> ^ >>> While building module 'Clang_Tooling' imported from /Users/vsk/src/ >>> llvm.org-master/llvm/tools/clang/lib/Tooling/Execution.cpp:10: >>> In file included from :22: >>> >>> In file included from /Users/vsk/src/llvm.org >>> -master/llvm/tools/clang/include/clang/Tooling/Refactoring/RefactoringAction.h:14: >>> In file included from /Users/vsk/src/llvm.org >>> -master/llvm/tools/clang/include/clang/Tooling/Refactoring/RefactoringActionRules.h:14: >>> In file included from /Users/vsk/src/llvm.org >>> -master/llvm/tools/clang/include/clang/Tooling/Refactoring/RefactoringActionRulesInternal.h:16: >>> In file included from /Users/vsk/src/llvm.org >>> -master/llvm/tools/clang/include/clang/Tooling/Refactoring/RefactoringResultConsumer.h:14: >>> /Users/vsk/src/llvm.org-master/llvm/tools/clang/include/clang/Tooling/Refactoring/AtomicChange.h:19:10: >>> fatal error: could not build module 'Clang_Format' >>> #include "clang/Format/Format.h" >>> ^~~ >>> /Users/vsk/src/llvm.org-master/llvm/tools/clang/lib/Tooling/Execution.cpp:10:10: >>> fatal error: could not build module 'Clang_Tooling' >>> #include "clang/Tooling/Execution.h" >>> >>> ^~~ >>> 3 errors generated. >>> >>> Could you take a look? >>> >>> thanks, >>> vedant >>> >>> > On May 18, 2018, at 7:16 AM, Eric Liu via cfe-commits < >>> cfe-commits@lists.llvm.org> wrote: >>> > >>> > Author: ioeric >>> > Date: Fri May 18 07:16:37 2018 >>> > New Revision: 332720 >>> > >>> > URL: http://llvm.org/viewvc/llvm-project?rev=332720&view=rev >>> > Log: >>> > Move #include manipulation code to new lib/Tooling/Inclusions. >>> > >>> > Summary: >>> > clangToolingCore is linked i
Re: r332720 - Move #include manipulation code to new lib/Tooling/Inclusions.
Thanks a lot for looking into this Bruno! The fix looks promising; I'll give it a try next week :D On Fri, May 18, 2018 at 10:33 PM David Blaikie via cfe-commits < cfe-commits@lists.llvm.org> wrote: > I haven't looked in detail here, but in general: Don't split an > implementation and its headers into different notional libraries, as that > breaks modular code generation (an implementation and its headers usually > have circular dependencies - inline functions that call non-inline > functions, and the other way around & so if they're in two different > libraries they won't be able to link (due to the way unix linkers > work/dependencies are resolved in a single pass, never looping back around). > David, I'm not exactly sure if I understand... This change pulls both declarations and implementations into a self-contained library which could be shared by clang-format and other tools that manipulate #includes. This seems to be a normal refactoring, and I hope this doesn't break modular code generation. > > On Fri, May 18, 2018 at 1:10 PM Bruno Cardoso Lopes via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> >> >> On Fri, May 18, 2018 at 12:46 PM Bruno Cardoso Lopes < >> bruno.card...@gmail.com> wrote: >> >>> >>> >>> On Fri, May 18, 2018 at 11:54 AM Vedant Kumar via cfe-commits < >>> cfe-commits@lists.llvm.org> wrote: >>> On May 18, 2018, at 11:48 AM, Eric Liu wrote: So I have reverted this with r332751. Thanks! I can't see how this introduced cyclic dependencies in module build, as the dependencies should be clangTooling -> clangFormat -> clangToolingInclusions. I'm wondering if there is any module configurations that I need to update to make this work. Right now, module doesn't seem to make any difference between clangTooling and clangToolingInclusions... I'd appreciate it if someone who knows how clang module build is set up could help take a look. + Bruno & David who have more experience in this area than I do. >>> >>> Gonna try to reproduce and take a look! >>> >> >> I could reproduce it. You should be good to go if you add another top >> level module for Inclusions (and break the dep): >> >> --- a/include/clang/module.modulemap >> +++ b/include/clang/module.modulemap >> @@ -153,3 +153,8 @@ module Clang_ToolingCore { >>requires cplusplus >>umbrella "Tooling/Core" module * { export * } >> } >> + >> +module Clang_ToolingInclusions { >> + requires cplusplus >> + umbrella "Tooling/Inclusions" module * { export * } >> +} >> >> -- >> Bruno Cardoso Lopes >> http://www.brunocardoso.cc >> ___ >> cfe-commits mailing list >> cfe-commits@lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits >> > ___ > cfe-commits mailing list > cfe-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r332720 - Move #include manipulation code to new lib/Tooling/Inclusions.
Sorry about the bad naming... I hope I could come up with something less confusing. Thanks for the clarification! On Fri, May 18, 2018 at 11:25 PM David Blaikie wrote: > > > On Fri, May 18, 2018 at 2:22 PM Eric Liu wrote: > >> Thanks a lot for looking into this Bruno! The fix looks promising; I'll >> give it a try next week :D >> >> On Fri, May 18, 2018 at 10:33 PM David Blaikie via cfe-commits < >> cfe-commits@lists.llvm.org> wrote: >> >>> I haven't looked in detail here, but in general: Don't split an >>> implementation and its headers into different notional libraries, as that >>> breaks modular code generation (an implementation and its headers usually >>> have circular dependencies - inline functions that call non-inline >>> functions, and the other way around & so if they're in two different >>> libraries they won't be able to link (due to the way unix linkers >>> work/dependencies are resolved in a single pass, never looping back around). >>> >> David, I'm not exactly sure if I understand... This change pulls both >> declarations and implementations into a self-contained library which could >> be shared by clang-format and other tools that manipulate #includes. This >> seems to be a normal refactoring, and I hope this doesn't break modular >> code generation. >> > > Sounds OK - so long as both header and implementation go together is all. > > (by the name "Inclusions" I was worried maybe just the headers had been > pulled out, but not their implementation) > > >> >>> On Fri, May 18, 2018 at 1:10 PM Bruno Cardoso Lopes via cfe-commits < >>> cfe-commits@lists.llvm.org> wrote: >>> On Fri, May 18, 2018 at 12:46 PM Bruno Cardoso Lopes < bruno.card...@gmail.com> wrote: > > > On Fri, May 18, 2018 at 11:54 AM Vedant Kumar via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> On May 18, 2018, at 11:48 AM, Eric Liu wrote: >> >> >> So I have reverted this with r332751. >> >> >> Thanks! >> >> >> I can't see how this introduced cyclic dependencies in module build, >> as the dependencies should be clangTooling -> clangFormat -> >> clangToolingInclusions. I'm wondering if there is any module >> configurations >> that I need to update to make this work. Right now, module doesn't seem >> to >> make any difference between clangTooling and clangToolingInclusions... >> I'd appreciate it if someone who knows how clang module build is set up >> could help take a look. >> >> >> + Bruno & David who have more experience in this area than I do. >> > > Gonna try to reproduce and take a look! > I could reproduce it. You should be good to go if you add another top level module for Inclusions (and break the dep): --- a/include/clang/module.modulemap +++ b/include/clang/module.modulemap @@ -153,3 +153,8 @@ module Clang_ToolingCore { requires cplusplus umbrella "Tooling/Core" module * { export * } } + +module Clang_ToolingInclusions { + requires cplusplus + umbrella "Tooling/Inclusions" module * { export * } +} -- Bruno Cardoso Lopes http://www.brunocardoso.cc ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits >>> ___ >>> cfe-commits mailing list >>> cfe-commits@lists.llvm.org >>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits >>> >> ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r332959 - [clangd] Correctly handle IWYU prama with verbatim #include header.
Author: ioeric Date: Tue May 22 01:33:30 2018 New Revision: 332959 URL: http://llvm.org/viewvc/llvm-project?rev=332959&view=rev Log: [clangd] Correctly handle IWYU prama with verbatim #include header. Modified: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Modified: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp?rev=332959&r1=332958&r2=332959&view=diff == --- clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp (original) +++ clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp Tue May 22 01:33:30 2018 @@ -65,8 +65,9 @@ collectIWYUHeaderMaps(CanonicalIncludes // FIXME(ioeric): resolve the header and store actual file path. For now, // we simply assume the written header is suitable to be #included. Includes->addMapping(PP.getSourceManager().getFilename(Range.getBegin()), - Text.startswith("<") ? Text.str() -: ("\"" + Text + "\"").str()); + (Text.startswith("<") || Text.startswith("\"")) + ? Text.str() + : ("\"" + Text + "\"").str()); return false; } Modified: clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp?rev=332959&r1=332958&r2=332959&view=diff == --- clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Tue May 22 01:33:30 2018 @@ -651,6 +651,21 @@ TEST_F(SymbolCollectorTest, IWYUPragma) IncludeHeader("\"the/good/header.h\""; } +TEST_F(SymbolCollectorTest, IWYUPragmaWithDoubleQuotes) { + CollectorOpts.CollectIncludePath = true; + CanonicalIncludes Includes; + PragmaHandler = collectIWYUHeaderMaps(&Includes); + CollectorOpts.Includes = &Includes; + const std::string Header = R"( +// IWYU pragma: private, include "the/good/header.h" +class Foo {}; + )"; + runSymbolCollector(Header, /*Main=*/""); + EXPECT_THAT(Symbols, UnorderedElementsAre( + AllOf(QName("Foo"), DeclURI(TestHeaderURI), + IncludeHeader("\"the/good/header.h\""; +} + TEST_F(SymbolCollectorTest, AvoidUsingFwdDeclsAsCanonicalDecls) { CollectorOpts.CollectIncludePath = true; Annotations Header(R"( ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r333172 - [VFS] Implement getRealPath in InMemoryFileSystem.
Author: ioeric Date: Thu May 24 04:17:00 2018 New Revision: 333172 URL: http://llvm.org/viewvc/llvm-project?rev=333172&view=rev Log: [VFS] Implement getRealPath in InMemoryFileSystem. Reviewers: bkramer Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D47262 Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h cfe/trunk/lib/Basic/VirtualFileSystem.cpp cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=333172&r1=333171&r2=333172&view=diff == --- cfe/trunk/include/clang/Basic/VirtualFileSystem.h (original) +++ cfe/trunk/include/clang/Basic/VirtualFileSystem.h Thu May 24 04:17:00 2018 @@ -374,6 +374,14 @@ public: llvm::ErrorOr getCurrentWorkingDirectory() const override { return WorkingDirectory; } + /// Canonicalizes \p Path by combining with the current working + /// directory and normalizing the path (e.g. remove dots). If the current + /// working directory is not set, this returns errc::operation_not_permitted. + /// + /// This doesn't resolve symlinks as they are not supported in in-memory file + /// system. + std::error_code getRealPath(const Twine &Path, + SmallVectorImpl &Output) const override; std::error_code setCurrentWorkingDirectory(const Twine &Path) override; }; Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=333172&r1=333171&r2=333172&view=diff == --- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original) +++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Thu May 24 04:17:00 2018 @@ -788,6 +788,19 @@ std::error_code InMemoryFileSystem::setC return {}; } +std::error_code +InMemoryFileSystem::getRealPath(const Twine &Path, +SmallVectorImpl &Output) const { + auto CWD = getCurrentWorkingDirectory(); + if (!CWD || CWD->empty()) +return errc::operation_not_permitted; + Path.toVector(Output); + if (auto EC = makeAbsolute(Output)) +return EC; + llvm::sys::path::remove_dots(Output, /*remove_dot_dot=*/true); + return {}; +} + } // namespace vfs } // namespace clang Modified: cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp?rev=333172&r1=333171&r2=333172&view=diff == --- cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp (original) +++ cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp Thu May 24 04:17:00 2018 @@ -813,6 +813,28 @@ TEST_F(InMemoryFileSystemTest, WorkingDi NormalizedFS.getCurrentWorkingDirectory().get())); } +TEST_F(InMemoryFileSystemTest, GetRealPath) { + SmallString<16> Path; + EXPECT_EQ(FS.getRealPath("b", Path), errc::operation_not_permitted); + + auto GetRealPath = [this](StringRef P) { +SmallString<16> Output; +auto EC = FS.getRealPath(P, Output); +EXPECT_FALSE(EC); +return Output.str().str(); + }; + + FS.setCurrentWorkingDirectory("a"); + EXPECT_EQ(GetRealPath("b"), "a/b"); + EXPECT_EQ(GetRealPath("../b"), "b"); + EXPECT_EQ(GetRealPath("b/./c"), "a/b/c"); + + FS.setCurrentWorkingDirectory("/a"); + EXPECT_EQ(GetRealPath("b"), "/a/b"); + EXPECT_EQ(GetRealPath("../b"), "/b"); + EXPECT_EQ(GetRealPath("b/./c"), "/a/b/c"); +} + TEST_F(InMemoryFileSystemTest, AddFileWithUser) { FS.addFile("/a/b/c", 0, MemoryBuffer::getMemBuffer("abc"), 0xFEEDFACE); auto Stat = FS.status("/a"); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r333174 - [clangd] Fix code completion in MACROs with stringification.
Author: ioeric Date: Thu May 24 04:20:19 2018 New Revision: 333174 URL: http://llvm.org/viewvc/llvm-project?rev=333174&view=rev Log: [clangd] Fix code completion in MACROs with stringification. Summary: Currently, we only handle the first callback from sema code completion and ignore results from potential following callbacks. This causes causes loss of completion results when multiple contexts are tried by Sema. For example, we wouldn't get any completion result in the following completion as the first attemped context is natural language which has no candidate. The parser would backtrack and tried a completion with AST semantic, which would find candidate "::x". ``` void f(const char*, int); #define F(x) f(#x, x) int x; void main() { F(::^); } ``` To fix this, we only process a sema callback when it gives completion results or the context supports index-based completion. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: klimek, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D47256 Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=333174&r1=333173&r2=333174&view=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu May 24 04:20:19 2018 @@ -406,6 +406,50 @@ std::vector getQueryScopes( return Info.scopesForIndexQuery(); } +// Should we perform index-based completion in a context of the specified kind? +// FIXME: consider allowing completion, but restricting the result types. +bool contextAllowsIndex(enum CodeCompletionContext::Kind K) { + switch (K) { + case CodeCompletionContext::CCC_TopLevel: + case CodeCompletionContext::CCC_ObjCInterface: + case CodeCompletionContext::CCC_ObjCImplementation: + case CodeCompletionContext::CCC_ObjCIvarList: + case CodeCompletionContext::CCC_ClassStructUnion: + case CodeCompletionContext::CCC_Statement: + case CodeCompletionContext::CCC_Expression: + case CodeCompletionContext::CCC_ObjCMessageReceiver: + case CodeCompletionContext::CCC_EnumTag: + case CodeCompletionContext::CCC_UnionTag: + case CodeCompletionContext::CCC_ClassOrStructTag: + case CodeCompletionContext::CCC_ObjCProtocolName: + case CodeCompletionContext::CCC_Namespace: + case CodeCompletionContext::CCC_Type: + case CodeCompletionContext::CCC_Name: // FIXME: why does ns::^ give this? + case CodeCompletionContext::CCC_PotentiallyQualifiedName: + case CodeCompletionContext::CCC_ParenthesizedExpression: + case CodeCompletionContext::CCC_ObjCInterfaceName: + case CodeCompletionContext::CCC_ObjCCategoryName: +return true; + case CodeCompletionContext::CCC_Other: // Be conservative. + case CodeCompletionContext::CCC_OtherWithMacros: + case CodeCompletionContext::CCC_DotMemberAccess: + case CodeCompletionContext::CCC_ArrowMemberAccess: + case CodeCompletionContext::CCC_ObjCPropertyAccess: + case CodeCompletionContext::CCC_MacroName: + case CodeCompletionContext::CCC_MacroNameUse: + case CodeCompletionContext::CCC_PreprocessorExpression: + case CodeCompletionContext::CCC_PreprocessorDirective: + case CodeCompletionContext::CCC_NaturalLanguage: + case CodeCompletionContext::CCC_SelectorName: + case CodeCompletionContext::CCC_TypeQualifiers: + case CodeCompletionContext::CCC_ObjCInstanceMessage: + case CodeCompletionContext::CCC_ObjCClassMessage: + case CodeCompletionContext::CCC_Recovery: +return false; + } + llvm_unreachable("unknown code completion context"); +} + // The CompletionRecorder captures Sema code-complete output, including context. // It filters out ignored results (but doesn't apply fuzzy-filtering yet). // It doesn't do scoring or conversion to CompletionItem yet, as we want to @@ -431,12 +475,17 @@ struct CompletionRecorder : public CodeC void ProcessCodeCompleteResults(class Sema &S, CodeCompletionContext Context, CodeCompletionResult *InResults, unsigned NumResults) override final { +// If a callback is called without any sema result and the context does not +// support index-based completion, we simply skip it to give way to +// potential future callbacks with results. +if (NumResults == 0 && !contextAllowsIndex(Context.getKind())) + return; if (CCSema) { log(llvm::formatv( "Multiple code complete callbacks (parser backtracked?). " "Dropping results from context {0}, keeping results from {1}.", - getCompletionKindString(this->CCContext.getKind()), - getCompletionKindString(Context.getKind(; + getCompletionKindString(Context.getKind()), + getCo
r333186 - Disable an in-memory vfs file path test on windows.
Author: ioeric Date: Thu May 24 06:52:48 2018 New Revision: 333186 URL: http://llvm.org/viewvc/llvm-project?rev=333186&view=rev Log: Disable an in-memory vfs file path test on windows. The test uses unix paths and doesn't make sense to run on windows. Fix bot failure caused by r333172: http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/10799 Modified: cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp Modified: cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp?rev=333186&r1=333185&r2=333186&view=diff == --- cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp (original) +++ cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp Thu May 24 06:52:48 2018 @@ -813,6 +813,7 @@ TEST_F(InMemoryFileSystemTest, WorkingDi NormalizedFS.getCurrentWorkingDirectory().get())); } +#if !defined(_WIN32) TEST_F(InMemoryFileSystemTest, GetRealPath) { SmallString<16> Path; EXPECT_EQ(FS.getRealPath("b", Path), errc::operation_not_permitted); @@ -834,6 +835,7 @@ TEST_F(InMemoryFileSystemTest, GetRealPa EXPECT_EQ(GetRealPath("../b"), "/b"); EXPECT_EQ(GetRealPath("b/./c"), "/a/b/c"); } +#endif // _WIN32 TEST_F(InMemoryFileSystemTest, AddFileWithUser) { FS.addFile("/a/b/c", 0, MemoryBuffer::getMemBuffer("abc"), 0xFEEDFACE); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r333188 - [clangd] Skip .inc headers when canonicalizing header #include.
Author: ioeric Date: Thu May 24 07:40:24 2018 New Revision: 333188 URL: http://llvm.org/viewvc/llvm-project?rev=333188&view=rev Log: [clangd] Skip .inc headers when canonicalizing header #include. Summary: This assumes that .inc files are supposed to be included via headers that include them. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D47187 Modified: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp clang-tools-extra/trunk/clangd/index/CanonicalIncludes.h clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Modified: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp?rev=333188&r1=333187&r2=333188&view=diff == --- clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp (original) +++ clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp Thu May 24 07:40:24 2018 @@ -8,6 +8,8 @@ //===--===// #include "CanonicalIncludes.h" +#include "../Headers.h" +#include "clang/Driver/Types.h" #include "llvm/Support/Regex.h" namespace clang { @@ -33,12 +35,33 @@ void CanonicalIncludes::addSymbolMapping } llvm::StringRef -CanonicalIncludes::mapHeader(llvm::StringRef Header, +CanonicalIncludes::mapHeader(llvm::ArrayRef Headers, llvm::StringRef QualifiedName) const { + assert(!Headers.empty()); auto SE = SymbolMapping.find(QualifiedName); if (SE != SymbolMapping.end()) return SE->second; std::lock_guard Lock(RegexMutex); + // Find the first header such that the extension is not '.inc', and isn't a + // recognized non-header file + auto I = + std::find_if(Headers.begin(), Headers.end(), [](llvm::StringRef Include) { +// Skip .inc file whose including header file should +// be #included instead. +return !Include.endswith(".inc"); + }); + if (I == Headers.end()) +return Headers[0]; // Fallback to the declaring header. + StringRef Header = *I; + // If Header is not expected be included (e.g. .cc file), we fall back to + // the declaring header. + StringRef Ext = llvm::sys::path::extension(Header).trim('.'); + // Include-able headers must have precompile type. Treat files with + // non-recognized extenstions (TY_INVALID) as headers. + auto ExtType = driver::types::lookupTypeForExtension(Ext); + if ((ExtType != driver::types::TY_INVALID) && + !driver::types::onlyPrecompileType(ExtType)) +return Headers[0]; for (auto &Entry : RegexHeaderMappingTable) { #ifndef NDEBUG std::string Dummy; @@ -65,9 +88,8 @@ collectIWYUHeaderMaps(CanonicalIncludes // FIXME(ioeric): resolve the header and store actual file path. For now, // we simply assume the written header is suitable to be #included. Includes->addMapping(PP.getSourceManager().getFilename(Range.getBegin()), - (Text.startswith("<") || Text.startswith("\"")) - ? Text.str() - : ("\"" + Text + "\"").str()); + isLiteralInclude(Text) ? Text.str() + : ("\"" + Text + "\"").str()); return false; } Modified: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/CanonicalIncludes.h?rev=333188&r1=333187&r2=333188&view=diff == --- clang-tools-extra/trunk/clangd/index/CanonicalIncludes.h (original) +++ clang-tools-extra/trunk/clangd/index/CanonicalIncludes.h Thu May 24 07:40:24 2018 @@ -48,9 +48,10 @@ public: void addSymbolMapping(llvm::StringRef QualifiedName, llvm::StringRef CanonicalPath); - /// Returns the canonical include for symbol with \p QualifiedName, which is - /// declared in \p Header - llvm::StringRef mapHeader(llvm::StringRef Header, + /// Returns the canonical include for symbol with \p QualifiedName. + /// \p Headers is the include stack: Headers.front() is the file declaring the + /// symbol, and Headers.back() is the main file. + llvm::StringRef mapHeader(llvm::ArrayRef Headers, llvm::StringRef QualifiedName) const; private: Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=333188&r1=333187&r2=333188&view=diff == --- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
[clang-tools-extra] r333197 - [clangd] Add clangDriver dependency after r333188
Author: ioeric Date: Thu May 24 08:54:32 2018 New Revision: 333197 URL: http://llvm.org/viewvc/llvm-project?rev=333197&view=rev Log: [clangd] Add clangDriver dependency after r333188 Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=333197&r1=333196&r2=333197&view=diff == --- clang-tools-extra/trunk/clangd/CMakeLists.txt (original) +++ clang-tools-extra/trunk/clangd/CMakeLists.txt Thu May 24 08:54:32 2018 @@ -47,6 +47,7 @@ add_clang_library(clangDaemon clangAST clangASTMatchers clangBasic + clangDriver clangFormat clangFrontend clangIndex ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r333519 - [clangd] Avoid inserting new #include when declaration is present in the main file.
Author: ioeric Date: Wed May 30 02:03:39 2018 New Revision: 333519 URL: http://llvm.org/viewvc/llvm-project?rev=333519&view=rev Log: [clangd] Avoid inserting new #include when declaration is present in the main file. Summary: Also fix USR generation for classes in unit tests. The previous USR only works for class members, which happens to work when completing class name inside the class, where constructors are suggested by sema. Reviewers: sammccall, ilya-biryukov Subscribers: klimek, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D47466 Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=333519&r1=333518&r2=333519&view=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Wed May 30 02:03:39 2018 @@ -235,6 +235,7 @@ struct CompletionCandidate { llvm::StringRef SemaDocComment) const { assert(bool(SemaResult) == bool(SemaCCS)); CompletionItem I; +bool ShouldInsertInclude = true; if (SemaResult) { I.kind = toCompletionItemKind(SemaResult->Kind, SemaResult->CursorKind); getLabelAndInsertText(*SemaCCS, &I.label, &I.insertText, @@ -242,6 +243,20 @@ struct CompletionCandidate { I.filterText = getFilterText(*SemaCCS); I.documentation = formatDocumentation(*SemaCCS, SemaDocComment); I.detail = getDetail(*SemaCCS); + // Avoid inserting new #include if the declaration is found in the current + // file e.g. the symbol is forward declared. + if (SemaResult->Kind == CodeCompletionResult::RK_Declaration) { +if (const auto *D = SemaResult->getDeclaration()) { + const auto &SM = D->getASTContext().getSourceManager(); + ShouldInsertInclude = + ShouldInsertInclude && + std::none_of(D->redecls_begin(), D->redecls_end(), + [&SM](const Decl *RD) { + return SM.isInMainFile( + SM.getExpansionLoc(RD->getLocStart())); + }); +} + } } if (IndexResult) { if (I.kind == CompletionItemKind::Missing) @@ -263,7 +278,7 @@ struct CompletionCandidate { I.documentation = D->Documentation; if (I.detail.empty()) I.detail = D->CompletionDetail; -if (Includes && !D->IncludeHeader.empty()) { +if (ShouldInsertInclude && Includes && !D->IncludeHeader.empty()) { auto Edit = [&]() -> Expected> { auto ResolvedDeclaring = toHeaderFile( IndexResult->CanonicalDeclaration.FileURI, FileName); Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=333519&r1=333518&r2=333519&view=diff == --- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Wed May 30 02:03:39 2018 @@ -159,7 +159,7 @@ Symbol func(StringRef Name) { // Assumes return sym(Name, index::SymbolKind::Function, "@F@\\0#"); // no args } Symbol cls(StringRef Name) { - return sym(Name, index::SymbolKind::Class, "@S@\\0@S@\\0"); + return sym(Name, index::SymbolKind::Class, "@S@\\0"); } Symbol var(StringRef Name) { return sym(Name, index::SymbolKind::Variable, "@\\0"); @@ -425,10 +425,9 @@ TEST(CompletionTest, NoDuplicates) { auto Results = completions( R"cpp( class Adapter { -void method(); }; - void Adapter::method() { + void f() { Adapter^ } )cpp", @@ -559,6 +558,37 @@ TEST(CompletionTest, IncludeInsertionPre ElementsAre(AllOf(Named("X"), Not(HasAdditionalEdits(); } +TEST(CompletionTest, NoIncludeInsertionWhenDeclFoundInFile) { + MockFSProvider FS; + MockCompilationDatabase CDB; + + IgnoreDiagnostics DiagConsumer; + ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest()); + Symbol::Details Scratch; + Symbol SymX = cls("ns::X"); + Symbol SymY = cls("ns::Y"); + std::string BarHeader = testPath("bar.h"); + auto BarURI = URI::createFile(BarHeader).toString(); + SymX.CanonicalDeclaration.FileURI = BarURI; + SymY.CanonicalDeclaration.FileURI = BarURI; + Scratch.IncludeHeader = ""; + SymX.Detail = &Scratch; + SymY.Detail = &Scratch; + // Shoten include path based on search dirctory and insert. + auto Results = completions(Server, + R"cpp( + namespace
Re: r315251 - [Modules TS] Module ownership semantics for redeclarations.
Hi Richard, This is breaking the boostrap stage in the internal integration. I'm seeing "unsupported: typedef changes linkage of anonymous type, but linkage was already computed" error for many `struct`s defined with typedef. I'm not sure if it is user code or clang that needs fixing; however, as there are likely many more struct definitions that would cause the same failure, I'll revert this commit as well as r315256, which depends on this. Sorry about that. I'll also send you the repros separately. Regards, Eric On Tue, Oct 10, 2017 at 1:42 AM Richard Smith via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: rsmith > Date: Mon Oct 9 16:42:09 2017 > New Revision: 315251 > > URL: http://llvm.org/viewvc/llvm-project?rev=315251&view=rev > Log: > [Modules TS] Module ownership semantics for redeclarations. > > When declaring an entity in the "purview" of a module, it's never a > redeclaration of an entity in the purview of a default module or in no > module > ("in the global module"). Don't consider those other declarations as > possible > redeclaration targets if they're not visible, and reject any cases where we > pick a prior visible declaration that violates this rule. > > Added: > cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/ > > cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/global-vs-module.cpp > > cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-global.cpp > > cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-module.cpp > Modified: > cfe/trunk/include/clang/AST/Decl.h > cfe/trunk/include/clang/AST/DeclBase.h > cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td > cfe/trunk/include/clang/Sema/Lookup.h > cfe/trunk/include/clang/Sema/Sema.h > cfe/trunk/lib/AST/Decl.cpp > cfe/trunk/lib/AST/DeclBase.cpp > cfe/trunk/lib/AST/DeclCXX.cpp > cfe/trunk/lib/Sema/SemaDecl.cpp > cfe/trunk/lib/Sema/SemaDeclCXX.cpp > cfe/trunk/lib/Sema/SemaDeclObjC.cpp > cfe/trunk/lib/Sema/SemaExprMember.cpp > cfe/trunk/lib/Sema/SemaLookup.cpp > cfe/trunk/lib/Sema/SemaOpenMP.cpp > cfe/trunk/lib/Sema/SemaTemplate.cpp > cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp > cfe/trunk/test/SemaCXX/modules-ts.cppm > > Modified: cfe/trunk/include/clang/AST/Decl.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=315251&r1=315250&r2=315251&view=diff > > == > --- cfe/trunk/include/clang/AST/Decl.h (original) > +++ cfe/trunk/include/clang/AST/Decl.h Mon Oct 9 16:42:09 2017 > @@ -339,6 +339,12 @@ public: > return clang::isExternallyVisible(getLinkageInternal()); >} > > + /// Determine whether this declaration can be redeclared in a > + /// different translation unit. > + bool isExternallyDeclarable() const { > +return isExternallyVisible() && !getOwningModuleForLinkage(); > + } > + >/// \brief Determines the visibility of this entity. >Visibility getVisibility() const { > return getLinkageAndVisibility().getVisibility(); > @@ -379,10 +385,6 @@ public: > return hasCachedLinkage(); >} > > - /// Get the module that owns this declaration for linkage purposes. > - /// There only ever is such a module under the C++ Modules TS. > - Module *getOwningModuleForLinkage() const; > - >/// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for >/// the underlying named decl. >NamedDecl *getUnderlyingDecl() { > > Modified: cfe/trunk/include/clang/AST/DeclBase.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=315251&r1=315250&r2=315251&view=diff > > == > --- cfe/trunk/include/clang/AST/DeclBase.h (original) > +++ cfe/trunk/include/clang/AST/DeclBase.h Mon Oct 9 16:42:09 2017 > @@ -738,6 +738,10 @@ public: > return isFromASTFile() ? getImportedOwningModule() : > getLocalOwningModule(); >} > > + /// Get the module that owns this declaration for linkage purposes. > + /// There only ever is such a module under the C++ Modules TS. > + Module *getOwningModuleForLinkage() const; > + >/// \brief Determine whether this declaration might be hidden from name >/// lookup. Note that the declaration might be visible even if this > returns >/// \c false, if the owning module is visible within the query context. > > Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=315251&r1=315250&r2=315251&view=diff > > == > --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) > +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Oct 9 > 16:42:09 2017 > @@ -4801,6 +4801,9 @@ def err_thread_non_thread : Error< > def err_thread_thread_differe
Re: r315256 - [Modules TS] Avoid computing the linkage of the enclosing DeclContext for a declaration in the global module.
I am reverting this commit as it depends on r315251. See r315251 thread for reason. On Tue, Oct 10, 2017 at 2:49 AM Richard Smith via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: rsmith > Date: Mon Oct 9 17:49:38 2017 > New Revision: 315256 > > URL: http://llvm.org/viewvc/llvm-project?rev=315256&view=rev > Log: > [Modules TS] Avoid computing the linkage of the enclosing DeclContext for > a declaration in the global module. > > This works around a language issue where adding a typedef name for linkage > purposes changes the linkage of an already-defined class after it becomes > complete. > > Added: > cfe/trunk/test/Modules/anon-linkage.cpp > Modified: > cfe/trunk/include/clang/AST/DeclBase.h > cfe/trunk/include/clang/Sema/Sema.h > cfe/trunk/lib/AST/Decl.cpp > > Modified: cfe/trunk/include/clang/AST/DeclBase.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=315256&r1=315255&r2=315256&view=diff > > == > --- cfe/trunk/include/clang/AST/DeclBase.h (original) > +++ cfe/trunk/include/clang/AST/DeclBase.h Mon Oct 9 17:49:38 2017 > @@ -740,7 +740,10 @@ public: > >/// Get the module that owns this declaration for linkage purposes. >/// There only ever is such a module under the C++ Modules TS. > - Module *getOwningModuleForLinkage() const; > + /// > + /// \param IgnoreLinkage Ignore the linkage of the entity; assume that > + /// all declarations in a global module fragment are unowned. > + Module *getOwningModuleForLinkage(bool IgnoreLinkage = false) const; > >/// \brief Determine whether this declaration might be hidden from name >/// lookup. Note that the declaration might be visible even if this > returns > > Modified: cfe/trunk/include/clang/Sema/Sema.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=315256&r1=315255&r2=315256&view=diff > > == > --- cfe/trunk/include/clang/Sema/Sema.h (original) > +++ cfe/trunk/include/clang/Sema/Sema.h Mon Oct 9 17:49:38 2017 > @@ -3051,8 +3051,11 @@ public: > >RedeclarationKind forRedeclarationInCurContext() { > // A declaration with an owning module for linkage can never link > against > -// anything that is not visible. > -if (cast(CurContext)->getOwningModuleForLinkage()) > +// anything that is not visible. We don't need to check linkage here; > if > +// the context has internal linkage, redeclaration lookup won't find > things > +// from other TUs, and we can't safely compute linkage yet in general. > +if (cast(CurContext) > +->getOwningModuleForLinkage(/*IgnoreLinkage*/true)) >return ForVisibleRedeclaration; > return ForExternalRedeclaration; >} > > Modified: cfe/trunk/lib/AST/Decl.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=315256&r1=315255&r2=315256&view=diff > > == > --- cfe/trunk/lib/AST/Decl.cpp (original) > +++ cfe/trunk/lib/AST/Decl.cpp Mon Oct 9 17:49:38 2017 > @@ -1395,7 +1395,7 @@ LinkageInfo LinkageComputer::getDeclLink > : > NamedDecl::VisibilityForValue)); > } > > -Module *Decl::getOwningModuleForLinkage() const { > +Module *Decl::getOwningModuleForLinkage(bool IgnoreLinkage) const { >Module *M = getOwningModule(); >if (!M) > return nullptr; > @@ -1413,6 +1413,8 @@ Module *Decl::getOwningModuleForLinkage( > // for linkage purposes. But internal linkage declarations in the > global > // module fragment of a particular module are owned by that module for > // linkage purposes. > +if (IgnoreLinkage) > + return nullptr; > bool InternalLinkage; > if (auto *ND = dyn_cast(this)) >InternalLinkage = !ND->hasExternalFormalLinkage(); > > Added: cfe/trunk/test/Modules/anon-linkage.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/anon-linkage.cpp?rev=315256&view=auto > > == > --- cfe/trunk/test/Modules/anon-linkage.cpp (added) > +++ cfe/trunk/test/Modules/anon-linkage.cpp Mon Oct 9 17:49:38 2017 > @@ -0,0 +1,12 @@ > +// RUN: %clang_cc1 -std=c++17 -fmodules-ts %s > + > +typedef struct { > + int c; > + union { > +int n; > +char c[4]; > + } v; > +} mbstate; > + > +export module M; > +export using ::mbstate; > > > ___ > cfe-commits mailing list > cfe-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r315308 - Revert "[Modules TS] Avoid computing the linkage of the enclosing DeclContext for a declaration in the global module."
Author: ioeric Date: Tue Oct 10 06:00:18 2017 New Revision: 315308 URL: http://llvm.org/viewvc/llvm-project?rev=315308&view=rev Log: Revert "[Modules TS] Avoid computing the linkage of the enclosing DeclContext for a declaration in the global module." This reverts commit r315256. See the original commit thread for reason. Removed: cfe/trunk/test/Modules/anon-linkage.cpp Modified: cfe/trunk/include/clang/AST/DeclBase.h cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/AST/Decl.cpp Modified: cfe/trunk/include/clang/AST/DeclBase.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=315308&r1=315307&r2=315308&view=diff == --- cfe/trunk/include/clang/AST/DeclBase.h (original) +++ cfe/trunk/include/clang/AST/DeclBase.h Tue Oct 10 06:00:18 2017 @@ -740,10 +740,7 @@ public: /// Get the module that owns this declaration for linkage purposes. /// There only ever is such a module under the C++ Modules TS. - /// - /// \param IgnoreLinkage Ignore the linkage of the entity; assume that - /// all declarations in a global module fragment are unowned. - Module *getOwningModuleForLinkage(bool IgnoreLinkage = false) const; + Module *getOwningModuleForLinkage() const; /// \brief Determine whether this declaration might be hidden from name /// lookup. Note that the declaration might be visible even if this returns Modified: cfe/trunk/include/clang/Sema/Sema.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=315308&r1=315307&r2=315308&view=diff == --- cfe/trunk/include/clang/Sema/Sema.h (original) +++ cfe/trunk/include/clang/Sema/Sema.h Tue Oct 10 06:00:18 2017 @@ -3051,11 +3051,8 @@ public: RedeclarationKind forRedeclarationInCurContext() { // A declaration with an owning module for linkage can never link against -// anything that is not visible. We don't need to check linkage here; if -// the context has internal linkage, redeclaration lookup won't find things -// from other TUs, and we can't safely compute linkage yet in general. -if (cast(CurContext) -->getOwningModuleForLinkage(/*IgnoreLinkage*/true)) +// anything that is not visible. +if (cast(CurContext)->getOwningModuleForLinkage()) return ForVisibleRedeclaration; return ForExternalRedeclaration; } Modified: cfe/trunk/lib/AST/Decl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=315308&r1=315307&r2=315308&view=diff == --- cfe/trunk/lib/AST/Decl.cpp (original) +++ cfe/trunk/lib/AST/Decl.cpp Tue Oct 10 06:00:18 2017 @@ -1395,7 +1395,7 @@ LinkageInfo LinkageComputer::getDeclLink : NamedDecl::VisibilityForValue)); } -Module *Decl::getOwningModuleForLinkage(bool IgnoreLinkage) const { +Module *Decl::getOwningModuleForLinkage() const { Module *M = getOwningModule(); if (!M) return nullptr; @@ -1413,8 +1413,6 @@ Module *Decl::getOwningModuleForLinkage( // for linkage purposes. But internal linkage declarations in the global // module fragment of a particular module are owned by that module for // linkage purposes. -if (IgnoreLinkage) - return nullptr; bool InternalLinkage; if (auto *ND = dyn_cast(this)) InternalLinkage = !ND->hasExternalFormalLinkage(); Removed: cfe/trunk/test/Modules/anon-linkage.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/anon-linkage.cpp?rev=315307&view=auto == --- cfe/trunk/test/Modules/anon-linkage.cpp (original) +++ cfe/trunk/test/Modules/anon-linkage.cpp (removed) @@ -1,12 +0,0 @@ -// RUN: %clang_cc1 -std=c++17 -fmodules-ts %s - -typedef struct { - int c; - union { -int n; -char c[4]; - } v; -} mbstate; - -export module M; -export using ::mbstate; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r315309 - Revert "[Modules TS] Module ownership semantics for redeclarations."
Author: ioeric Date: Tue Oct 10 06:09:40 2017 New Revision: 315309 URL: http://llvm.org/viewvc/llvm-project?rev=315309&view=rev Log: Revert "[Modules TS] Module ownership semantics for redeclarations." This reverts commit r315251. See the original commit thread for reason. Removed: cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/global-vs-module.cpp cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-global.cpp cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-module.cpp Modified: cfe/trunk/include/clang/AST/Decl.h cfe/trunk/include/clang/AST/DeclBase.h cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/include/clang/Sema/Lookup.h cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/AST/Decl.cpp cfe/trunk/lib/AST/DeclBase.cpp cfe/trunk/lib/AST/DeclCXX.cpp cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/lib/Sema/SemaDeclObjC.cpp cfe/trunk/lib/Sema/SemaExprMember.cpp cfe/trunk/lib/Sema/SemaLookup.cpp cfe/trunk/lib/Sema/SemaOpenMP.cpp cfe/trunk/lib/Sema/SemaTemplate.cpp cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp cfe/trunk/test/SemaCXX/modules-ts.cppm Modified: cfe/trunk/include/clang/AST/Decl.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=315309&r1=315308&r2=315309&view=diff == --- cfe/trunk/include/clang/AST/Decl.h (original) +++ cfe/trunk/include/clang/AST/Decl.h Tue Oct 10 06:09:40 2017 @@ -339,12 +339,6 @@ public: return clang::isExternallyVisible(getLinkageInternal()); } - /// Determine whether this declaration can be redeclared in a - /// different translation unit. - bool isExternallyDeclarable() const { -return isExternallyVisible() && !getOwningModuleForLinkage(); - } - /// \brief Determines the visibility of this entity. Visibility getVisibility() const { return getLinkageAndVisibility().getVisibility(); @@ -385,6 +379,10 @@ public: return hasCachedLinkage(); } + /// Get the module that owns this declaration for linkage purposes. + /// There only ever is such a module under the C++ Modules TS. + Module *getOwningModuleForLinkage() const; + /// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for /// the underlying named decl. NamedDecl *getUnderlyingDecl() { Modified: cfe/trunk/include/clang/AST/DeclBase.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=315309&r1=315308&r2=315309&view=diff == --- cfe/trunk/include/clang/AST/DeclBase.h (original) +++ cfe/trunk/include/clang/AST/DeclBase.h Tue Oct 10 06:09:40 2017 @@ -738,10 +738,6 @@ public: return isFromASTFile() ? getImportedOwningModule() : getLocalOwningModule(); } - /// Get the module that owns this declaration for linkage purposes. - /// There only ever is such a module under the C++ Modules TS. - Module *getOwningModuleForLinkage() const; - /// \brief Determine whether this declaration might be hidden from name /// lookup. Note that the declaration might be visible even if this returns /// \c false, if the owning module is visible within the query context. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=315309&r1=315308&r2=315309&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Oct 10 06:09:40 2017 @@ -4801,9 +4801,6 @@ def err_thread_non_thread : Error< def err_thread_thread_different_kind : Error< "thread-local declaration of %0 with %select{static|dynamic}1 initialization " "follows declaration with %select{dynamic|static}1 initialization">; -def err_mismatched_owning_module : Error< - "declaration of %0 in %select{the global module|module %2}1 follows " - "declaration in %select{the global module|module %4}3">; def err_redefinition_different_type : Error< "redefinition of %0 with a different type%diff{: $ vs $|}1,2">; def err_redefinition_different_kind : Error< Modified: cfe/trunk/include/clang/Sema/Lookup.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Lookup.h?rev=315309&r1=315308&r2=315309&view=diff == --- cfe/trunk/include/clang/Sema/Lookup.h (original) +++ cfe/trunk/include/clang/Sema/Lookup.h Tue Oct 10 06:09:40 2017 @@ -139,7 +139,6 @@ public: LookupKind(LookupKind), IDNS(0), Redecl(Redecl != Sema::NotForRedeclaration), - ExternalRedecl(Redecl == Sema::ForExternalRedeclaration), HideTags(true), Diagnose(Redecl == Sema::NotForRedeclarati
Re: r315251 - [Modules TS] Module ownership semantics for redeclarations.
No :( I tried reverting only r315256 but still got the errors. On Tue, Oct 10, 2017 at 6:10 PM Richard Smith wrote: > On 10 Oct 2017 05:41, "Eric Liu via cfe-commits" < > cfe-commits@lists.llvm.org> wrote: > > Hi Richard, > > This is breaking the boostrap stage in the internal integration. I'm > seeing "unsupported: typedef changes linkage of anonymous type, but > linkage was already computed" error for many `struct`s defined with > typedef. I'm not sure if it is user code or clang that needs fixing; > however, as there are likely many more struct definitions that would cause > the same failure, I'll revert this commit as well as r315256, which depends > on this. Sorry about that. > > > r315256 should have fixed those errors. Did it not? > > I'll also send you the repros separately. > > Regards, > Eric > > On Tue, Oct 10, 2017 at 1:42 AM Richard Smith via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> Author: rsmith >> Date: Mon Oct 9 16:42:09 2017 >> New Revision: 315251 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=315251&view=rev >> Log: >> [Modules TS] Module ownership semantics for redeclarations. >> >> When declaring an entity in the "purview" of a module, it's never a >> redeclaration of an entity in the purview of a default module or in no >> module >> ("in the global module"). Don't consider those other declarations as >> possible >> redeclaration targets if they're not visible, and reject any cases where >> we >> pick a prior visible declaration that violates this rule. >> >> Added: >> cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/ >> >> cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/global-vs-module.cpp >> >> cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-global.cpp >> >> cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-module.cpp >> Modified: >> cfe/trunk/include/clang/AST/Decl.h >> cfe/trunk/include/clang/AST/DeclBase.h >> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td >> cfe/trunk/include/clang/Sema/Lookup.h >> cfe/trunk/include/clang/Sema/Sema.h >> cfe/trunk/lib/AST/Decl.cpp >> cfe/trunk/lib/AST/DeclBase.cpp >> cfe/trunk/lib/AST/DeclCXX.cpp >> cfe/trunk/lib/Sema/SemaDecl.cpp >> cfe/trunk/lib/Sema/SemaDeclCXX.cpp >> cfe/trunk/lib/Sema/SemaDeclObjC.cpp >> cfe/trunk/lib/Sema/SemaExprMember.cpp >> cfe/trunk/lib/Sema/SemaLookup.cpp >> cfe/trunk/lib/Sema/SemaOpenMP.cpp >> cfe/trunk/lib/Sema/SemaTemplate.cpp >> cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp >> cfe/trunk/test/SemaCXX/modules-ts.cppm >> >> Modified: cfe/trunk/include/clang/AST/Decl.h >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=315251&r1=315250&r2=315251&view=diff >> >> == >> --- cfe/trunk/include/clang/AST/Decl.h (original) >> +++ cfe/trunk/include/clang/AST/Decl.h Mon Oct 9 16:42:09 2017 >> @@ -339,6 +339,12 @@ public: >> return clang::isExternallyVisible(getLinkageInternal()); >>} >> >> + /// Determine whether this declaration can be redeclared in a >> + /// different translation unit. >> + bool isExternallyDeclarable() const { >> +return isExternallyVisible() && !getOwningModuleForLinkage(); >> + } >> + >>/// \brief Determines the visibility of this entity. >>Visibility getVisibility() const { >> return getLinkageAndVisibility().getVisibility(); >> @@ -379,10 +385,6 @@ public: >> return hasCachedLinkage(); >>} >> >> - /// Get the module that owns this declaration for linkage purposes. >> - /// There only ever is such a module under the C++ Modules TS. >> - Module *getOwningModuleForLinkage() const; >> - >>/// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for >>/// the underlying named decl. >>NamedDecl *getUnderlyingDecl() { >> >> Modified: cfe/trunk/include/clang/AST/DeclBase.h >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=315251&r1=315250&r2=315251&view=diff >> >> == >> --- cfe/trunk/include/clang/AST/DeclBase.h (original) >> +++ cfe/trunk/include/clang/AST/DeclBase.h Mon Oct 9 16:42:09 2017 >>
Re: r315668 - [OpenCL] Add LangAS::opencl_private to represent private address space in AST
Hi Yaxun, this is causing failures in ppc build bots ( http://lab.llvm.org:8011/builders/clang-ppc64be-linux-multistage/builds/5486). I'll revert the patch for now. Please take a look. Thanks! On Fri, Oct 13, 2017 at 5:37 AM Yaxun Liu via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: yaxunl > Date: Thu Oct 12 20:37:48 2017 > New Revision: 315668 > > URL: http://llvm.org/viewvc/llvm-project?rev=315668&view=rev > Log: > [OpenCL] Add LangAS::opencl_private to represent private address space in > AST > > Currently Clang uses default address space (0) to represent private > address space for OpenCL > in AST. There are two issues with this: > > Multiple address spaces including private address space cannot be > diagnosed. > There is no mangling for default address space. For example, if private > int* is emitted as > i32 addrspace(5)* in IR. It is supposed to be mangled as PUAS5i but it is > mangled as > Pi instead. > > This patch attempts to represent OpenCL private address space explicitly > in AST. It adds > a new enum LangAS::opencl_private and adds it to the variable types which > are implicitly > private: > > automatic variables without address space qualifier > > function parameter > > pointee type without address space qualifier (OpenCL 1.2 and below) > > Differential Revision: https://reviews.llvm.org/D35082 > > Removed: > cfe/trunk/test/SemaOpenCL/extern.cl > Modified: > cfe/trunk/include/clang/Basic/AddressSpaces.h > cfe/trunk/lib/AST/ASTContext.cpp > cfe/trunk/lib/AST/Expr.cpp > cfe/trunk/lib/AST/ItaniumMangle.cpp > cfe/trunk/lib/AST/TypePrinter.cpp > cfe/trunk/lib/Basic/Targets/AMDGPU.cpp > cfe/trunk/lib/Basic/Targets/NVPTX.h > cfe/trunk/lib/Basic/Targets/SPIR.h > cfe/trunk/lib/Basic/Targets/TCE.h > cfe/trunk/lib/CodeGen/CGDecl.cpp > cfe/trunk/lib/Sema/SemaChecking.cpp > cfe/trunk/lib/Sema/SemaDecl.cpp > cfe/trunk/lib/Sema/SemaType.cpp > cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl > cfe/trunk/test/CodeGenOpenCL/address-spaces.cl > cfe/trunk/test/SemaOpenCL/address-spaces.cl > cfe/trunk/test/SemaOpenCL/cl20-device-side-enqueue.cl > cfe/trunk/test/SemaOpenCL/storageclass-cl20.cl > cfe/trunk/test/SemaOpenCL/storageclass.cl > cfe/trunk/test/SemaTemplate/address_space-dependent.cpp > > Modified: cfe/trunk/include/clang/Basic/AddressSpaces.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AddressSpaces.h?rev=315668&r1=315667&r2=315668&view=diff > > == > --- cfe/trunk/include/clang/Basic/AddressSpaces.h (original) > +++ cfe/trunk/include/clang/Basic/AddressSpaces.h Thu Oct 12 20:37:48 2017 > @@ -25,16 +25,17 @@ namespace LangAS { > /// > enum ID { >// The default value 0 is the value used in QualType for the the > situation > - // where there is no address space qualifier. For most languages, this > also > - // corresponds to the situation where there is no address space > qualifier in > - // the source code, except for OpenCL, where the address space value 0 > in > - // QualType represents private address space in OpenCL source code. > + // where there is no address space qualifier. >Default = 0, > >// OpenCL specific address spaces. > + // In OpenCL each l-value must have certain non-default address space, > each > + // r-value must have no address space (i.e. the default address space). > The > + // pointee of a pointer must have non-default address space. >opencl_global, >opencl_local, >opencl_constant, > + opencl_private, >opencl_generic, > >// CUDA specific address spaces. > > Modified: cfe/trunk/lib/AST/ASTContext.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=315668&r1=315667&r2=315668&view=diff > > == > --- cfe/trunk/lib/AST/ASTContext.cpp (original) > +++ cfe/trunk/lib/AST/ASTContext.cpp Thu Oct 12 20:37:48 2017 > @@ -707,6 +707,7 @@ static const LangAS::Map *getAddressSpac >1, // opencl_global >3, // opencl_local >2, // opencl_constant > + 0, // opencl_private >4, // opencl_generic >5, // cuda_device >6, // cuda_constant > > Modified: cfe/trunk/lib/AST/Expr.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=315668&r1=315667&r2=315668&view=diff > > == > --- cfe/trunk/lib/AST/Expr.cpp (original) > +++ cfe/trunk/lib/AST/Expr.cpp Thu Oct 12 20:37:48 2017 > @@ -3293,20 +3293,20 @@ Expr::isNullPointerConstant(ASTContext & >// Check that it is a cast to void*. >if (const PointerType *PT = CE->getType()->getAs()) { > QualType Pointee = PT->getPointeeType(); > -Qualifiers Q = Pointee.getQualifiers(); > -// In OpenCL v2.0 generic address space a
Re: r315668 - [OpenCL] Add LangAS::opencl_private to represent private address space in AST
Ah, I saw you already sent a fix in r315678. Thank you for the fix! No revert! :) On Fri, Oct 13, 2017 at 4:10 PM Eric Liu wrote: > Hi Yaxun, this is causing failures in ppc build bots ( > http://lab.llvm.org:8011/builders/clang-ppc64be-linux-multistage/builds/5486). > I'll revert the patch for now. Please take a look. Thanks! > > On Fri, Oct 13, 2017 at 5:37 AM Yaxun Liu via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> Author: yaxunl >> Date: Thu Oct 12 20:37:48 2017 >> New Revision: 315668 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=315668&view=rev >> Log: >> [OpenCL] Add LangAS::opencl_private to represent private address space in >> AST >> >> Currently Clang uses default address space (0) to represent private >> address space for OpenCL >> in AST. There are two issues with this: >> >> Multiple address spaces including private address space cannot be >> diagnosed. >> There is no mangling for default address space. For example, if private >> int* is emitted as >> i32 addrspace(5)* in IR. It is supposed to be mangled as PUAS5i but it is >> mangled as >> Pi instead. >> >> This patch attempts to represent OpenCL private address space explicitly >> in AST. It adds >> a new enum LangAS::opencl_private and adds it to the variable types which >> are implicitly >> private: >> >> automatic variables without address space qualifier >> >> function parameter >> >> pointee type without address space qualifier (OpenCL 1.2 and below) >> >> Differential Revision: https://reviews.llvm.org/D35082 >> >> Removed: >> cfe/trunk/test/SemaOpenCL/extern.cl >> Modified: >> cfe/trunk/include/clang/Basic/AddressSpaces.h >> cfe/trunk/lib/AST/ASTContext.cpp >> cfe/trunk/lib/AST/Expr.cpp >> cfe/trunk/lib/AST/ItaniumMangle.cpp >> cfe/trunk/lib/AST/TypePrinter.cpp >> cfe/trunk/lib/Basic/Targets/AMDGPU.cpp >> cfe/trunk/lib/Basic/Targets/NVPTX.h >> cfe/trunk/lib/Basic/Targets/SPIR.h >> cfe/trunk/lib/Basic/Targets/TCE.h >> cfe/trunk/lib/CodeGen/CGDecl.cpp >> cfe/trunk/lib/Sema/SemaChecking.cpp >> cfe/trunk/lib/Sema/SemaDecl.cpp >> cfe/trunk/lib/Sema/SemaType.cpp >> cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl >> cfe/trunk/test/CodeGenOpenCL/address-spaces.cl >> cfe/trunk/test/SemaOpenCL/address-spaces.cl >> cfe/trunk/test/SemaOpenCL/cl20-device-side-enqueue.cl >> cfe/trunk/test/SemaOpenCL/storageclass-cl20.cl >> cfe/trunk/test/SemaOpenCL/storageclass.cl >> cfe/trunk/test/SemaTemplate/address_space-dependent.cpp >> >> Modified: cfe/trunk/include/clang/Basic/AddressSpaces.h >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AddressSpaces.h?rev=315668&r1=315667&r2=315668&view=diff >> >> == >> --- cfe/trunk/include/clang/Basic/AddressSpaces.h (original) >> +++ cfe/trunk/include/clang/Basic/AddressSpaces.h Thu Oct 12 20:37:48 2017 >> @@ -25,16 +25,17 @@ namespace LangAS { >> /// >> enum ID { >>// The default value 0 is the value used in QualType for the the >> situation >> - // where there is no address space qualifier. For most languages, this >> also >> - // corresponds to the situation where there is no address space >> qualifier in >> - // the source code, except for OpenCL, where the address space value 0 >> in >> - // QualType represents private address space in OpenCL source code. >> + // where there is no address space qualifier. >>Default = 0, >> >>// OpenCL specific address spaces. >> + // In OpenCL each l-value must have certain non-default address space, >> each >> + // r-value must have no address space (i.e. the default address >> space). The >> + // pointee of a pointer must have non-default address space. >>opencl_global, >>opencl_local, >>opencl_constant, >> + opencl_private, >>opencl_generic, >> >>// CUDA specific address spaces. >> >> Modified: cfe/trunk/lib/AST/ASTContext.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=315668&r1=315667&r2=315668&view=diff >> >> == >> --- cfe/trunk/lib/AST/ASTContext.cpp (original) >> +++ cfe/trunk/lib/AST/ASTContext.cpp Thu Oct 12 20:37:48 2017 >> @@ -707,6 +707,7 @@ static const LangAS::Map *getAddressSpac >>1, // opencl_global >>3, // opencl_local >>2, // opencl_constant >> + 0, // opencl_private >>4, // opencl_generic >>5, // cuda_device >>6, // cuda_constant >> >> Modified: cfe/trunk/lib/AST/Expr.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=315668&r1=315667&r2=315668&view=diff >> >> == >> --- cfe/trunk/lib/AST/Expr.cpp (original) >> +++ cfe/trunk/lib/AST/Expr.cpp Thu Oct 12 20:37:48 2017 >> @@ -3293,20 +3293,20 @@ Expr::isNullPointerConstant(ASTContext &
[clang-tools-extra] r315892 - [change-namespace] do not change type locs in defaulted functions.
Author: ioeric Date: Mon Oct 16 01:20:10 2017 New Revision: 315892 URL: http://llvm.org/viewvc/llvm-project?rev=315892&view=rev Log: [change-namespace] do not change type locs in defaulted functions. Reviewers: hokein Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D38893 Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=315892&r1=315891&r2=315892&view=diff == --- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original) +++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Mon Oct 16 01:20:10 2017 @@ -427,7 +427,8 @@ void ChangeNamespaceTool::registerMatche unless(templateSpecializationType())), hasParent(nestedNameSpecifierLoc()), hasAncestor(isImplicit()), - hasAncestor(UsingShadowDeclInClass))), + hasAncestor(UsingShadowDeclInClass), + hasAncestor(functionDecl(isDefaulted(), hasAncestor(decl().bind("dc"))) .bind("type"), this); @@ -451,6 +452,7 @@ void ChangeNamespaceTool::registerMatche specifiesType(hasDeclaration(DeclMatcher.bind("from_decl"), unless(anyOf(hasAncestor(isImplicit()), hasAncestor(UsingShadowDeclInClass), + hasAncestor(functionDecl(isDefaulted())), hasAncestor(typeLoc(loc(qualType(hasDeclaration( decl(equalsBoundNode("from_decl")) .bind("nested_specifier_loc"), Modified: clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp?rev=315892&r1=315891&r2=315892&view=diff == --- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp (original) +++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp Mon Oct 16 01:20:10 2017 @@ -2093,6 +2093,68 @@ TEST_F(ChangeNamespaceTest, TypeAsTempla EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code)); } +TEST_F(ChangeNamespaceTest, DefaultMoveConstructors) { + std::string Code = "namespace na {\n" + "class B {\n" + " public:\n" + " B() = default;\n" + " // Allow move only.\n" + " B(B&&) = default;\n" + " B& operator=(B&&) = default;\n" + " B(const B&) = delete;\n" + " B& operator=(const B&) = delete;\n" + " private:\n" + " int ref_;\n" + "};\n" + "} // namespace na\n" + "namespace na {\n" + "namespace nb {\n" + "class A {\n" + "public:\n" + " A() = default;\n" + " A(A&&) = default;\n" + " A& operator=(A&&) = default;\n" + "private:\n" + " B b;\n" + " A(const A&) = delete;\n" + " A& operator=(const A&) = delete;\n" + "};\n" + "void f() { A a; a = A(); A aa = A(); }\n" + "} // namespace nb\n" + "} // namespace na\n"; + std::string Expected = "namespace na {\n" + "class B {\n" + " public:\n" + " B() = default;\n" + " // Allow move only.\n" + " B(B&&) = default;\n" + " B& operator=(B&&) = default;\n" + " B(const B&) = delete;\n" + " B& operator=(const B&) = delete;\n" + " private:\n" + " int ref_;\n" + "};\n" + "} // namespace na\n" + "\n" + "namespace x {\n" + "namespace y {\n" + "class A {\n" + "public:\n" + " A() = default;\n" + " A(A&&) = default;\n" + " A& operator=(A&&) = default;\n" + "private:\n" + " na::B b;\n" + " A(con
r316433 - [Tooling] Add a factory method for CommonOptionsParser
Author: ioeric Date: Tue Oct 24 06:10:58 2017 New Revision: 316433 URL: http://llvm.org/viewvc/llvm-project?rev=316433&view=rev Log: [Tooling] Add a factory method for CommonOptionsParser Summary: This returns error instead of exiting the program in case of error. Reviewers: klimek, hokein Reviewed By: hokein Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D39042 Modified: cfe/trunk/include/clang/Tooling/CommonOptionsParser.h cfe/trunk/lib/Tooling/CommonOptionsParser.cpp Modified: cfe/trunk/include/clang/Tooling/CommonOptionsParser.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/CommonOptionsParser.h?rev=316433&r1=316432&r2=316433&view=diff == --- cfe/trunk/include/clang/Tooling/CommonOptionsParser.h (original) +++ cfe/trunk/include/clang/Tooling/CommonOptionsParser.h Tue Oct 24 06:10:58 2017 @@ -30,6 +30,7 @@ #include "clang/Tooling/ArgumentsAdjusters.h" #include "clang/Tooling/CompilationDatabase.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Error.h" namespace clang { namespace tooling { @@ -86,13 +87,18 @@ public: /// All options not belonging to \p Category become hidden. /// /// It also allows calls to set the required number of positional parameters. - /// - /// This constructor exits program in case of error. CommonOptionsParser(int &argc, const char **argv, llvm::cl::OptionCategory &Category, llvm::cl::NumOccurrencesFlag OccurrencesFlag, const char *Overview = nullptr); + /// \brief A factory method that is similar to the above constructor, except + /// this returns an error instead exiting the program on error. + static llvm::Expected + create(int &argc, const char **argv, llvm::cl::OptionCategory &Category, + llvm::cl::NumOccurrencesFlag OccurrencesFlag, + const char *Overview = nullptr); + /// Returns a reference to the loaded compilations database. CompilationDatabase &getCompilations() { return *Compilations; @@ -106,6 +112,13 @@ public: static const char *const HelpMessage; private: + CommonOptionsParser() = default; + + llvm::Error init(int &argc, const char **argv, + llvm::cl::OptionCategory &Category, + llvm::cl::NumOccurrencesFlag OccurrencesFlag, + const char *Overview); + std::unique_ptr Compilations; std::vector SourcePathList; }; Modified: cfe/trunk/lib/Tooling/CommonOptionsParser.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CommonOptionsParser.cpp?rev=316433&r1=316432&r2=316433&view=diff == --- cfe/trunk/lib/Tooling/CommonOptionsParser.cpp (original) +++ cfe/trunk/lib/Tooling/CommonOptionsParser.cpp Tue Oct 24 06:10:58 2017 @@ -24,9 +24,9 @@ // //===--===// -#include "llvm/Support/CommandLine.h" #include "clang/Tooling/CommonOptionsParser.h" #include "clang/Tooling/Tooling.h" +#include "llvm/Support/CommandLine.h" using namespace clang::tooling; using namespace llvm; @@ -81,7 +81,7 @@ std::vector ArgumentsAdj return Commands; } -CommonOptionsParser::CommonOptionsParser( +llvm::Error CommonOptionsParser::init( int &argc, const char **argv, cl::OptionCategory &Category, llvm::cl::NumOccurrencesFlag OccurrencesFlag, const char *Overview) { static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden, @@ -105,20 +105,30 @@ CommonOptionsParser::CommonOptionsParser cl::desc("Additional argument to prepend to the compiler command line"), cl::cat(Category), cl::sub(*cl::AllSubCommands)); + cl::ResetAllOptionOccurrences(); + cl::HideUnrelatedOptions(Category); std::string ErrorMessage; Compilations = FixedCompilationDatabase::loadFromCommandLine(argc, argv, ErrorMessage); - if (!Compilations && !ErrorMessage.empty()) -llvm::errs() << ErrorMessage; - cl::ParseCommandLineOptions(argc, argv, Overview); + if (!ErrorMessage.empty()) +ErrorMessage.append("\n"); + llvm::raw_string_ostream OS(ErrorMessage); + // Stop initializing if command-line option parsing failed. + if (!cl::ParseCommandLineOptions(argc, argv, Overview, &OS)) { +OS.flush(); +return llvm::make_error("[CommonOptionsParser]: " + + ErrorMessage, + llvm::inconvertibleErrorCode()); + } + cl::PrintOptionValues(); SourcePathList = SourcePaths; if ((OccurrencesFlag == cl::ZeroOrMore || OccurrencesFlag == cl::Optional) && SourcePathList.empty()) -return; +return llvm::Error::success(); if (!Compilations) { if (!BuildPath.empty()) { Compilations = @@ -142,4 +152,27 @@ CommonOptionsParser::CommonOption
r340598 - [FileManager] Do not call 'real_path' in getFile().
Author: ioeric Date: Fri Aug 24 01:59:54 2018 New Revision: 340598 URL: http://llvm.org/viewvc/llvm-project?rev=340598&view=rev Log: [FileManager] Do not call 'real_path' in getFile(). Summary: This partially rolls back the change in D48903: https://github.com/llvm-mirror/clang/commit/89aa7f45a1f728144935289d4ce69d8522999de0#diff-0025af005307891b5429b6a834823d5eR318 `real_path` can be very expensive on real file systems, and calling it on each opened file can slow down the compilation. This also slows down deserialized ASTs for which real paths need to be recalculated for each input files again. For clangd code completion latency (using preamble): Before {F7039629} After {F7039630} Reviewers: ilya-biryukov, simark Reviewed By: ilya-biryukov Subscribers: kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D51159 Modified: cfe/trunk/lib/Basic/FileManager.cpp Modified: cfe/trunk/lib/Basic/FileManager.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=340598&r1=340597&r2=340598&view=diff == --- cfe/trunk/lib/Basic/FileManager.cpp (original) +++ cfe/trunk/lib/Basic/FileManager.cpp Fri Aug 24 01:59:54 2018 @@ -316,10 +316,14 @@ const FileEntry *FileManager::getFile(St UFE.File = std::move(F); UFE.IsValid = true; - SmallString<128> RealPathName; - if (!FS->getRealPath(InterndFileName, RealPathName)) -UFE.RealPathName = RealPathName.str(); - + llvm::SmallString<128> AbsPath(InterndFileName); + // This is not the same as `VFS::getRealPath()`, which resolves symlinks but + // can be very expensive on real file systems. + // FIXME: the semantic of RealPathName is unclear, and the name might be + // misleading. We need to clean up the interface here. + makeAbsolutePath(AbsPath); + llvm::sys::path::remove_dots(AbsPath, /*remove_dot_dot=*/true); + UFE.RealPathName = AbsPath.str(); return &UFE; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r340602 - Fix build bot after r340598.
Author: ioeric Date: Fri Aug 24 02:53:44 2018 New Revision: 340602 URL: http://llvm.org/viewvc/llvm-project?rev=340602&view=rev Log: Fix build bot after r340598. Revert to the original behavior: only calculate real file path when file is opened and avoid using InterndPath for real path calculation. Modified: cfe/trunk/lib/Basic/FileManager.cpp Modified: cfe/trunk/lib/Basic/FileManager.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=340602&r1=340601&r2=340602&view=diff == --- cfe/trunk/lib/Basic/FileManager.cpp (original) +++ cfe/trunk/lib/Basic/FileManager.cpp Fri Aug 24 02:53:44 2018 @@ -316,14 +316,18 @@ const FileEntry *FileManager::getFile(St UFE.File = std::move(F); UFE.IsValid = true; - llvm::SmallString<128> AbsPath(InterndFileName); - // This is not the same as `VFS::getRealPath()`, which resolves symlinks but - // can be very expensive on real file systems. - // FIXME: the semantic of RealPathName is unclear, and the name might be - // misleading. We need to clean up the interface here. - makeAbsolutePath(AbsPath); - llvm::sys::path::remove_dots(AbsPath, /*remove_dot_dot=*/true); - UFE.RealPathName = AbsPath.str(); + if (UFE.File) { +if (auto PathName = UFE.File->getName()) { + llvm::SmallString<128> AbsPath(*PathName); + // This is not the same as `VFS::getRealPath()`, which resolves symlinks + // but can be very expensive on real file systems. + // FIXME: the semantic of RealPathName is unclear, and the name might be + // misleading. We need to clean up the interface here. + makeAbsolutePath(AbsPath); + llvm::sys::path::remove_dots(AbsPath, /*remove_dot_dot=*/true); + UFE.RealPathName = AbsPath.str(); +} + } return &UFE; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r340604 - [clangd] Speculative code completion index request before Sema is run.
Author: ioeric Date: Fri Aug 24 04:23:56 2018 New Revision: 340604 URL: http://llvm.org/viewvc/llvm-project?rev=340604&view=rev Log: [clangd] Speculative code completion index request before Sema is run. Summary: For index-based code completion, send an asynchronous speculative index request, based on the index request for the last code completion on the same file and the filter text typed before the cursor, before sema code completion is invoked. This can reduce the code completion latency (by roughly latency of sema code completion) if the speculative request is the same as the one generated for the ongoing code completion from sema. As a sequence of code completions often have the same scopes and proximity paths etc, this should be effective for a number of code completions. Trace with speculative index request:{F6997544} Reviewers: hokein, ilya-biryukov Reviewed By: ilya-biryukov Subscribers: javed.absar, jfb, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D50962 Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp clang-tools-extra/trunk/clangd/ClangdServer.h clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/clangd/CodeComplete.h clang-tools-extra/trunk/clangd/TUScheduler.h clang-tools-extra/trunk/clangd/index/Index.h clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=340604&r1=340603&r2=340604&view=diff == --- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Fri Aug 24 04:23:56 2018 @@ -12,6 +12,7 @@ #include "FindSymbols.h" #include "Headers.h" #include "SourceCode.h" +#include "Trace.h" #include "XRefs.h" #include "index/Merge.h" #include "clang/Format/Format.h" @@ -22,6 +23,7 @@ #include "clang/Tooling/Refactoring/RefactoringResultConsumer.h" #include "clang/Tooling/Refactoring/Rename/RenamingAction.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Errc.h" @@ -29,6 +31,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include +#include using namespace clang; using namespace clang::clangd; @@ -181,21 +184,44 @@ void ClangdServer::codeComplete(PathRef // Copy PCHs to avoid accessing this->PCHs concurrently std::shared_ptr PCHs = this->PCHs; auto FS = FSProvider.getFileSystem(); - auto Task = [PCHs, Pos, FS, - CodeCompleteOpts](Path File, Callback CB, - llvm::Expected IP) { + + auto Task = [PCHs, Pos, FS, CodeCompleteOpts, + this](Path File, Callback CB, + llvm::Expected IP) { if (!IP) return CB(IP.takeError()); auto PreambleData = IP->Preamble; +llvm::Optional SpecFuzzyFind; +if (CodeCompleteOpts.Index && CodeCompleteOpts.SpeculativeIndexRequest) { + SpecFuzzyFind.emplace(); + { +std::lock_guard Lock(CachedCompletionFuzzyFindRequestMutex); +SpecFuzzyFind->CachedReq = CachedCompletionFuzzyFindRequestByFile[File]; + } +} + // FIXME(ibiryukov): even if Preamble is non-null, we may want to check // both the old and the new version in case only one of them matches. CodeCompleteResult Result = clangd::codeComplete( File, IP->Command, PreambleData ? &PreambleData->Preamble : nullptr, PreambleData ? PreambleData->Includes : IncludeStructure(), -IP->Contents, Pos, FS, PCHs, CodeCompleteOpts); -CB(std::move(Result)); +IP->Contents, Pos, FS, PCHs, CodeCompleteOpts, +SpecFuzzyFind ? SpecFuzzyFind.getPointer() : nullptr); +{ + clang::clangd::trace::Span Tracer("Completion results callback"); + CB(std::move(Result)); +} +if (SpecFuzzyFind && SpecFuzzyFind->NewReq.hasValue()) { + std::lock_guard Lock(CachedCompletionFuzzyFindRequestMutex); + CachedCompletionFuzzyFindRequestByFile[File] = + SpecFuzzyFind->NewReq.getValue(); +} +// SpecFuzzyFind is only destroyed after speculative fuzzy find finishes. +// We don't want `codeComplete` to wait for the async call if it doesn't use +// the result (e.g. non-index completion, speculation fails), so that `CB` +// is called as soon as results are available. }; WorkScheduler.runWithPreamble("CodeComplete", File, Modified: clang-tools-extra/trunk/clangd/ClangdServer.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=340604&r1=340603&r2=340604&view=diff == --- clang-t
[clang-tools-extra] r340822 - [clangd] Use buffered llvm::errs() in the clangd binary.
Author: ioeric Date: Tue Aug 28 06:15:50 2018 New Revision: 340822 URL: http://llvm.org/viewvc/llvm-project?rev=340822&view=rev Log: [clangd] Use buffered llvm::errs() in the clangd binary. Summary: Unbuffered stream can cause significant (non-deterministic) latency for the logger. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D51349 Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=340822&r1=340821&r2=340822&view=diff == --- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original) +++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Tue Aug 28 06:15:50 2018 @@ -259,6 +259,9 @@ int main(int argc, char *argv[]) { if (Tracer) TracingSession.emplace(*Tracer); + // Use buffered stream to stderr (we still flush each log message). Unbuffered + // stream can cause significant (non-deterministic) latency for the logger. + llvm::errs().SetBuffered(); JSONOutput Out(llvm::outs(), llvm::errs(), LogLevel, InputMirrorStream ? InputMirrorStream.getPointer() : nullptr, PrettyPrint); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r341304 - [clangd] Support multiple #include headers in one symbol.
Author: ioeric Date: Mon Sep 3 03:18:21 2018 New Revision: 341304 URL: http://llvm.org/viewvc/llvm-project?rev=341304&view=rev Log: [clangd] Support multiple #include headers in one symbol. Summary: Currently, a symbol can have only one #include header attached, which might not work well if the symbol can be imported via different #includes depending on where it's used. This patch stores multiple #include headers (with # references) for each symbol, so that CodeCompletion can decide which include to insert. In this patch, code completion simply picks the most popular include as the default inserted header. We also return all possible includes and their edits in the `CodeCompletion` results. Reviewers: sammccall Reviewed By: sammccall Subscribers: mgrang, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D51291 Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/clangd/CodeComplete.h clang-tools-extra/trunk/clangd/index/Index.cpp clang-tools-extra/trunk/clangd/index/Index.h clang-tools-extra/trunk/clangd/index/Merge.cpp clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=341304&r1=341303&r2=341304&view=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Mon Sep 3 03:18:21 2018 @@ -44,10 +44,13 @@ #include "clang/Sema/Sema.h" #include "clang/Tooling/Core/Replacement.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/Support/Error.h" #include "llvm/Support/Format.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/ScopedPrinter.h" +#include +#include #include // We log detailed candidate here if you run with -debug-only=codecomplete. @@ -247,6 +250,7 @@ struct CompletionCandidate { // We may have a result from Sema, from the index, or both. const CodeCompletionResult *SemaResult = nullptr; const Symbol *IndexResult = nullptr; + llvm::SmallVector RankedIncludeHeaders; // States whether this item is an override suggestion. bool IsOverride = false; @@ -267,7 +271,7 @@ struct CompletionCandidate { // This could break #include insertion. return hash_combine( (IndexResult->Scope + IndexResult->Name).toStringRef(Scratch), -headerToInsertIfNotPresent().getValueOr("")); +headerToInsertIfAllowed().getValueOr("")); default: return 0; } @@ -281,11 +285,12 @@ struct CompletionCandidate { llvm::raw_svector_ostream OS(Scratch); D->printQualifiedName(OS); } -return hash_combine(Scratch, headerToInsertIfNotPresent().getValueOr("")); +return hash_combine(Scratch, headerToInsertIfAllowed().getValueOr("")); } - llvm::Optional headerToInsertIfNotPresent() const { -if (!IndexResult || IndexResult->IncludeHeader.empty()) + // The best header to include if include insertion is allowed. + llvm::Optional headerToInsertIfAllowed() const { +if (RankedIncludeHeaders.empty()) return llvm::None; if (SemaResult && SemaResult->Declaration) { // Avoid inserting new #include if the declaration is found in the current @@ -295,7 +300,7 @@ struct CompletionCandidate { if (SM.isInMainFile(SM.getExpansionLoc(RD->getBeginLoc( return llvm::None; } -return IndexResult->IncludeHeader; +return RankedIncludeHeaders[0]; } using Bundle = llvm::SmallVector; @@ -358,31 +363,41 @@ struct CodeCompletionBuilder { if (Completion.Name.empty()) Completion.Name = C.IndexResult->Name; } -if (auto Inserted = C.headerToInsertIfNotPresent()) { - // Turn absolute path into a literal string that can be #included. - auto Include = [&]() -> Expected> { -auto ResolvedDeclaring = -toHeaderFile(C.IndexResult->CanonicalDeclaration.FileURI, FileName); -if (!ResolvedDeclaring) - return ResolvedDeclaring.takeError(); -auto ResolvedInserted = toHeaderFile(*Inserted, FileName); -if (!ResolvedInserted) - return ResolvedInserted.takeError(); -return std::make_pair(Includes.calculateIncludePath(*ResolvedDeclaring, -*ResolvedInserted), - Includes.shouldInsertInclude(*ResolvedDeclaring, -
[clang-tools-extra] r341449 - [clangd] Tune macro quality scoring for code completion.
Author: ioeric Date: Wed Sep 5 00:40:38 2018 New Revision: 341449 URL: http://llvm.org/viewvc/llvm-project?rev=341449&view=rev Log: [clangd] Tune macro quality scoring for code completion. x0.2 seems to be too much penalty, macros might be wanted in some cases; changing to 0.5x instead. The tuning didn't affect ranking for non-macro completions. Modified: clang-tools-extra/trunk/clangd/Quality.cpp Modified: clang-tools-extra/trunk/clangd/Quality.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=341449&r1=341448&r2=341449&view=diff == --- clang-tools-extra/trunk/clangd/Quality.cpp (original) +++ clang-tools-extra/trunk/clangd/Quality.cpp Wed Sep 5 00:40:38 2018 @@ -221,7 +221,7 @@ float SymbolQualitySignals::evaluate() c Score *= 0.8f; break; case Macro: -Score *= 0.2f; +Score *= 0.5f; break; case Unknown: case Constructor: // No boost constructors so they are after class types. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r341455 - [VFS] Cache the current working directory for the real FS.
Author: ioeric Date: Wed Sep 5 02:45:27 2018 New Revision: 341455 URL: http://llvm.org/viewvc/llvm-project?rev=341455&view=rev Log: [VFS] Cache the current working directory for the real FS. Reviewers: sammccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D51641 Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=341455&r1=341454&r2=341455&view=diff == --- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original) +++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Wed Sep 5 02:45:27 2018 @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -244,6 +245,9 @@ public: std::error_code setCurrentWorkingDirectory(const Twine &Path) override; std::error_code getRealPath(const Twine &Path, SmallVectorImpl &Output) const override; +private: + mutable std::mutex CWDMutex; + mutable std::string CWDCache; }; } // namespace @@ -266,10 +270,14 @@ RealFileSystem::openFileForRead(const Tw } llvm::ErrorOr RealFileSystem::getCurrentWorkingDirectory() const { + std::lock_guard Lock(CWDMutex); + if (!CWDCache.empty()) +return CWDCache; SmallString<256> Dir; if (std::error_code EC = llvm::sys::fs::current_path(Dir)) return EC; - return Dir.str().str(); + CWDCache = Dir.str(); + return CWDCache; } std::error_code RealFileSystem::setCurrentWorkingDirectory(const Twine &Path) { @@ -280,7 +288,13 @@ std::error_code RealFileSystem::setCurre // difference for example on network filesystems, where symlinks might be // switched during runtime of the tool. Fixing this depends on having a // file system abstraction that allows openat() style interactions. - return llvm::sys::fs::set_current_path(Path); + if (auto EC = llvm::sys::fs::set_current_path(Path)) +return EC; + + // Invalidate cache. + std::lock_guard Lock(CWDMutex); + CWDCache.clear(); + return std::error_code(); } std::error_code ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r341476 - [Sema] Store MacroInfo in CodeCompletionResult for macro results.
Author: ioeric Date: Wed Sep 5 07:59:17 2018 New Revision: 341476 URL: http://llvm.org/viewvc/llvm-project?rev=341476&view=rev Log: [Sema] Store MacroInfo in CodeCompletionResult for macro results. Summary: This provides information about the macro definition. For example, it can be used to compute macro USRs. Reviewers: sammccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D51675 Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h cfe/trunk/lib/Sema/SemaCodeComplete.cpp cfe/trunk/tools/libclang/CXCursor.cpp Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h?rev=341476&r1=341475&r2=341476&view=diff == --- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h (original) +++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h Wed Sep 5 07:59:17 2018 @@ -17,6 +17,7 @@ #include "clang-c/Index.h" #include "clang/AST/Type.h" #include "clang/Basic/LLVM.h" +#include "clang/Lex/MacroInfo.h" #include "clang/Sema/CodeCompleteOptions.h" #include "clang/Sema/DeclSpec.h" #include "llvm/ADT/ArrayRef.h" @@ -843,6 +844,11 @@ public: /// corresponding `using decl::qualified::name;` nearby. const UsingShadowDecl *ShadowDecl = nullptr; + /// If the result is RK_Macro, this can store the information about the macro + /// definition. This should be set in most cases but can be missing when + /// the macro has been undefined. + const MacroInfo *MacroDefInfo = nullptr; + /// Build a result that refers to a declaration. CodeCompletionResult(const NamedDecl *Declaration, unsigned Priority, NestedNameSpecifier *Qualifier = nullptr, @@ -867,11 +873,13 @@ public: /// Build a result that refers to a macro. CodeCompletionResult(const IdentifierInfo *Macro, + const MacroInfo *MI = nullptr, unsigned Priority = CCP_Macro) : Macro(Macro), Priority(Priority), Kind(RK_Macro), CursorKind(CXCursor_MacroDefinition), Hidden(false), QualifierIsInformative(false), StartsNestedNameSpecifier(false), -AllParametersAreInformative(false), DeclaringEntity(false) {} +AllParametersAreInformative(false), DeclaringEntity(false), +MacroDefInfo(MI) {} /// Build a result that refers to a pattern. CodeCompletionResult(CodeCompletionString *Pattern, Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=341476&r1=341475&r2=341476&view=diff == --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original) +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Wed Sep 5 07:59:17 2018 @@ -3313,14 +3313,14 @@ static void AddMacroResults(Preprocessor M != MEnd; ++M) { auto MD = PP.getMacroDefinition(M->first); if (IncludeUndefined || MD) { - if (MacroInfo *MI = MD.getMacroInfo()) -if (MI->isUsedForHeaderGuard()) - continue; + MacroInfo *MI = MD.getMacroInfo(); + if (MI && MI->isUsedForHeaderGuard()) +continue; - Results.AddResult(Result(M->first, - getMacroUsagePriority(M->first->getName(), - PP.getLangOpts(), - TargetTypeIsPointer))); + Results.AddResult( + Result(M->first, MI, + getMacroUsagePriority(M->first->getName(), PP.getLangOpts(), + TargetTypeIsPointer))); } } Modified: cfe/trunk/tools/libclang/CXCursor.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.cpp?rev=341476&r1=341475&r2=341476&view=diff == --- cfe/trunk/tools/libclang/CXCursor.cpp (original) +++ cfe/trunk/tools/libclang/CXCursor.cpp Wed Sep 5 07:59:17 2018 @@ -1412,16 +1412,16 @@ CXCompletionString clang_getCursorComple } } else if (kind == CXCursor_MacroDefinition) { const MacroDefinitionRecord *definition = getCursorMacroDefinition(cursor); -const IdentifierInfo *MacroInfo = definition->getName(); +const IdentifierInfo *Macro = definition->getName(); ASTUnit *unit = getCursorASTUnit(cursor); -CodeCompletionResult Result(MacroInfo); -CodeCompletionString *String - = Result.CreateCodeCompletionString(unit->getASTContext(), - unit->getPreprocessor(), - CodeCompletionContext::CCC_Other, - unit->getCodeCompletionTUInfo().getAllocator(), - unit->getCodeCompletionTUInfo(), - false); +Co
[clang-tools-extra] r341488 - [clang-tidy] minor bug fix to AbseilMatcher.h
Author: ioeric Date: Wed Sep 5 12:01:34 2018 New Revision: 341488 URL: http://llvm.org/viewvc/llvm-project?rev=341488&view=rev Log: [clang-tidy] minor bug fix to AbseilMatcher.h This missing directory is not yet released, but is causing some problems internally. It's gonna be released eventually and received permission to include it here. This matcher will also be periodically updated by my team as we have more releases and or problems internally. Patch by Hugo Gonzalez! Differential Revision: https://reviews.llvm.org/D51699 Modified: clang-tools-extra/trunk/clang-tidy/abseil/AbseilMatcher.h Modified: clang-tools-extra/trunk/clang-tidy/abseil/AbseilMatcher.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/AbseilMatcher.h?rev=341488&r1=341487&r2=341488&view=diff == --- clang-tools-extra/trunk/clang-tidy/abseil/AbseilMatcher.h (original) +++ clang-tools-extra/trunk/clang-tidy/abseil/AbseilMatcher.h Wed Sep 5 12:01:34 2018 @@ -48,10 +48,19 @@ AST_POLYMORPHIC_MATCHER( if (PrefixPosition == StringRef::npos) return false; Path = Path.drop_front(PrefixPosition + AbslPrefix.size()); - static const char *AbseilLibraries[] = { - "algorithm", "base", "container", "debugging", - "memory", "meta", "numeric", "strings", - "synchronization", "time", "types", "utility"}; + static const char *AbseilLibraries[] = {"algorithm", + "base", + "container", + "debugging", + "flags" + "memory", + "meta", + "numeric", + "strings", + "synchronization", + "time", + "types", + "utility"}; return std::any_of( std::begin(AbseilLibraries), std::end(AbseilLibraries), [&](const char *Library) { return Path.startswith(Library); }); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r341534 - [clangd] Set SymbolID for sema macros so that they can be merged with index macros.
Author: ioeric Date: Thu Sep 6 02:59:37 2018 New Revision: 341534 URL: http://llvm.org/viewvc/llvm-project?rev=341534&view=rev Log: [clangd] Set SymbolID for sema macros so that they can be merged with index macros. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D51688 Modified: clang-tools-extra/trunk/clangd/AST.cpp clang-tools-extra/trunk/clangd/AST.h clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Modified: clang-tools-extra/trunk/clangd/AST.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/AST.cpp?rev=341534&r1=341533&r2=341534&view=diff == --- clang-tools-extra/trunk/clangd/AST.cpp (original) +++ clang-tools-extra/trunk/clangd/AST.cpp Thu Sep 6 02:59:37 2018 @@ -61,5 +61,16 @@ llvm::Optional getSymbolID(con return SymbolID(USR); } +llvm::Optional getSymbolID(const IdentifierInfo &II, + const MacroInfo *MI, + const SourceManager &SM) { + if (MI == nullptr) +return None; + llvm::SmallString<128> USR; + if (index::generateUSRForMacro(II.getName(), MI->getDefinitionLoc(), SM, USR)) +return None; + return SymbolID(USR); +} + } // namespace clangd } // namespace clang Modified: clang-tools-extra/trunk/clangd/AST.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/AST.h?rev=341534&r1=341533&r2=341534&view=diff == --- clang-tools-extra/trunk/clangd/AST.h (original) +++ clang-tools-extra/trunk/clangd/AST.h Thu Sep 6 02:59:37 2018 @@ -37,6 +37,17 @@ std::string printQualifiedName(const Nam /// Gets the symbol ID for a declaration, if possible. llvm::Optional getSymbolID(const Decl *D); +/// Gets the symbol ID for a macro, if possible. +/// Currently, this is an encoded USR of the macro, which incorporates macro +/// locations (e.g. file name, offset in file). +/// FIXME: the USR semantics might not be stable enough as the ID for index +/// macro (e.g. a change in definition offset can result in a different USR). We +/// could change these semantics in the future by reimplementing this funcure +/// (e.g. avoid USR for macros). +llvm::Optional getSymbolID(const IdentifierInfo &II, + const MacroInfo *MI, + const SourceManager &SM); + } // namespace clangd } // namespace clang Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=341534&r1=341533&r2=341534&view=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu Sep 6 02:59:37 2018 @@ -505,14 +505,15 @@ private: }; // Determine the symbol ID for a Sema code completion result, if possible. -llvm::Optional getSymbolID(const CodeCompletionResult &R) { +llvm::Optional getSymbolID(const CodeCompletionResult &R, + const SourceManager &SM) { switch (R.Kind) { case CodeCompletionResult::RK_Declaration: case CodeCompletionResult::RK_Pattern: { return clang::clangd::getSymbolID(R.Declaration); } case CodeCompletionResult::RK_Macro: -// FIXME: Macros do have USRs, but the CCR doesn't contain enough info. +return clang::clangd::getSymbolID(*R.Macro, R.MacroDefInfo, SM); case CodeCompletionResult::RK_Keyword: return None; } @@ -1435,7 +1436,8 @@ private: llvm::DenseSet UsedIndexResults; auto CorrespondingIndexResult = [&](const CodeCompletionResult &SemaResult) -> const Symbol * { - if (auto SymID = getSymbolID(SemaResult)) { + if (auto SymID = + getSymbolID(SemaResult, Recorder->CCSema->getSourceManager())) { auto I = IndexResults.find(*SymID); if (I != IndexResults.end()) { UsedIndexResults.insert(&*I); Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=341534&r1=341533&r2=341534&view=diff == --- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original) +++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Thu Sep 6 02:59:37 2018 @@ -385,18 +385,16 @@ bool SymbolCollector::handleMacroOccuren Roles & static_cast(index::SymbolRole::Definition))) return true; - llvm::SmallString<128> USR; - if (index::generateUSRForMacro(Name->getName(), MI->
[clang-tools-extra] r341576 - [clangd] Add "Deprecated" field to Symbol and CodeCompletion.
Author: ioeric Date: Thu Sep 6 11:52:26 2018 New Revision: 341576 URL: http://llvm.org/viewvc/llvm-project?rev=341576&view=rev Log: [clangd] Add "Deprecated" field to Symbol and CodeCompletion. Summary: Also set "deprecated" field in LSP CompletionItem. Reviewers: sammccall, kadircet Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D51724 Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/clangd/CodeComplete.h clang-tools-extra/trunk/clangd/Protocol.cpp clang-tools-extra/trunk/clangd/Protocol.h clang-tools-extra/trunk/clangd/Quality.cpp clang-tools-extra/trunk/clangd/index/Index.cpp clang-tools-extra/trunk/clangd/index/Index.h clang-tools-extra/trunk/clangd/index/MemIndex.cpp clang-tools-extra/trunk/clangd/index/Merge.cpp clang-tools-extra/trunk/clangd/index/Serialization.cpp clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=341576&r1=341575&r2=341576&view=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu Sep 6 11:52:26 2018 @@ -353,6 +353,8 @@ struct CodeCompletionBuilder { return std::tie(X.range.start.line, X.range.start.character) < std::tie(Y.range.start.line, Y.range.start.character); }); + Completion.Deprecated |= + (C.SemaResult->Availability == CXAvailability_Deprecated); } if (C.IndexResult) { Completion.Origin |= C.IndexResult->Origin; @@ -362,6 +364,7 @@ struct CodeCompletionBuilder { Completion.Kind = toCompletionItemKind(C.IndexResult->SymInfo.Kind); if (Completion.Name.empty()) Completion.Name = C.IndexResult->Name; + Completion.Deprecated |= (C.IndexResult->Flags & Symbol::Deprecated); } // Turn absolute path into a literal string that can be #included. @@ -1625,6 +1628,7 @@ CompletionItem CodeCompletion::render(co LSP.kind = Kind; LSP.detail = BundleSize > 1 ? llvm::formatv("[{0} overloads]", BundleSize) : ReturnType; + LSP.deprecated = Deprecated; if (InsertInclude) LSP.detail += "\n" + InsertInclude->Header; LSP.documentation = Documentation; @@ -1656,6 +1660,7 @@ CompletionItem CodeCompletion::render(co : InsertTextFormat::PlainText; if (InsertInclude && InsertInclude->Insertion) LSP.additionalTextEdits.push_back(*InsertInclude->Insertion); + return LSP; } Modified: clang-tools-extra/trunk/clangd/CodeComplete.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.h?rev=341576&r1=341575&r2=341576&view=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.h (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.h Thu Sep 6 11:52:26 2018 @@ -177,6 +177,9 @@ struct CodeCompletion { }; Scores Score; + /// Indicates if this item is deprecated. + bool Deprecated = false; + // Serialize this to an LSP completion item. This is a lossy operation. CompletionItem render(const CodeCompleteOptions &) const; }; Modified: clang-tools-extra/trunk/clangd/Protocol.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=341576&r1=341575&r2=341576&view=diff == --- clang-tools-extra/trunk/clangd/Protocol.cpp (original) +++ clang-tools-extra/trunk/clangd/Protocol.cpp Thu Sep 6 11:52:26 2018 @@ -517,6 +517,8 @@ json::Value toJSON(const CompletionItem Result["textEdit"] = *CI.textEdit; if (!CI.additionalTextEdits.empty()) Result["additionalTextEdits"] = json::Array(CI.additionalTextEdits); + if (CI.deprecated) +Result["deprecated"] = CI.deprecated; return std::move(Result); } Modified: clang-tools-extra/trunk/clangd/Protocol.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=341576&r1=341575&r2=341576&view=diff == --- clang-tools-extra/trunk/clangd/Protocol.h (original) +++ clang-tools-extra/trunk/clangd/Protocol.h Thu Sep 6 11:52:26 2018 @@ -768,6 +768,9 @@ struct CompletionItem { /// them
[clang-tools-extra] r341645 - [clangd] Canonicalize include paths in clangd.
Author: ioeric Date: Fri Sep 7 02:40:36 2018 New Revision: 341645 URL: http://llvm.org/viewvc/llvm-project?rev=341645&view=rev Log: [clangd] Canonicalize include paths in clangd. Get rid of "../" and "../../". Modified: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp clang-tools-extra/trunk/clangd/index/FileIndex.cpp clang-tools-extra/trunk/clangd/index/FileIndex.h clang-tools-extra/trunk/clangd/index/MemIndex.cpp clang-tools-extra/trunk/clangd/index/Merge.cpp clang-tools-extra/trunk/clangd/index/Serialization.cpp clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp clang-tools-extra/trunk/clangd/index/dex/DexIndex.cpp clang-tools-extra/trunk/clangd/index/dex/DexIndex.h clang-tools-extra/trunk/clangd/index/dex/Token.h clang-tools-extra/trunk/clangd/index/dex/Trigram.cpp Modified: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp?rev=341645&r1=341644&r2=341645&view=diff == --- clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp (original) +++ clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp Fri Sep 7 02:40:36 2018 @@ -8,7 +8,7 @@ //===--===// #include "CanonicalIncludes.h" -#include "../Headers.h" +#include "Headers.h" #include "clang/Driver/Types.h" #include "llvm/Support/Path.h" #include Modified: clang-tools-extra/trunk/clangd/index/FileIndex.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.cpp?rev=341645&r1=341644&r2=341645&view=diff == --- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original) +++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Fri Sep 7 02:40:36 2018 @@ -8,7 +8,7 @@ //===--===// #include "FileIndex.h" -#include "../Logger.h" +#include "Logger.h" #include "SymbolCollector.h" #include "clang/Index/IndexingAction.h" #include "clang/Lex/Preprocessor.h" Modified: clang-tools-extra/trunk/clangd/index/FileIndex.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.h?rev=341645&r1=341644&r2=341645&view=diff == --- clang-tools-extra/trunk/clangd/index/FileIndex.h (original) +++ clang-tools-extra/trunk/clangd/index/FileIndex.h Fri Sep 7 02:40:36 2018 @@ -16,7 +16,7 @@ #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_FILEINDEX_H #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_FILEINDEX_H -#include "../ClangdUnit.h" +#include "ClangdUnit.h" #include "Index.h" #include "MemIndex.h" #include "clang/Lex/Preprocessor.h" Modified: clang-tools-extra/trunk/clangd/index/MemIndex.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/MemIndex.cpp?rev=341645&r1=341644&r2=341645&view=diff == --- clang-tools-extra/trunk/clangd/index/MemIndex.cpp (original) +++ clang-tools-extra/trunk/clangd/index/MemIndex.cpp Fri Sep 7 02:40:36 2018 @@ -8,9 +8,9 @@ //===---===// #include "MemIndex.h" -#include "../FuzzyMatch.h" -#include "../Logger.h" -#include "../Quality.h" +#include "FuzzyMatch.h" +#include "Logger.h" +#include "Quality.h" namespace clang { namespace clangd { Modified: clang-tools-extra/trunk/clangd/index/Merge.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Merge.cpp?rev=341645&r1=341644&r2=341645&view=diff == --- clang-tools-extra/trunk/clangd/index/Merge.cpp (original) +++ clang-tools-extra/trunk/clangd/index/Merge.cpp Fri Sep 7 02:40:36 2018 @@ -8,7 +8,7 @@ //===--===// #include "Merge.h" -#include "../Logger.h" +#include "Logger.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/raw_ostream.h" Modified: clang-tools-extra/trunk/clangd/index/Serialization.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Serialization.cpp?rev=341645&r1=341644&r2=341645&view=diff == --- clang-tools-extra/trunk/clangd/index/Serialization.cpp (original) +++ clang-tools-extra/trunk/clangd/index/Serialization.cpp Fri Sep 7 02:40:36 2018 @@ -7,8 +7,8 @@ // //===--===// #include "Serialization.h" -#include "../RIFF.h" #include "Index.h"
r342028 - [Tooling] Wait for all threads to finish before resetting CWD.
Author: ioeric Date: Wed Sep 12 01:29:47 2018 New Revision: 342028 URL: http://llvm.org/viewvc/llvm-project?rev=342028&view=rev Log: [Tooling] Wait for all threads to finish before resetting CWD. Modified: cfe/trunk/lib/Tooling/AllTUsExecution.cpp Modified: cfe/trunk/lib/Tooling/AllTUsExecution.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/AllTUsExecution.cpp?rev=342028&r1=342027&r2=342028&view=diff == --- cfe/trunk/lib/Tooling/AllTUsExecution.cpp (original) +++ cfe/trunk/lib/Tooling/AllTUsExecution.cpp Wed Sep 12 01:29:47 2018 @@ -129,6 +129,8 @@ llvm::Error AllTUsToolExecutor::execute( }, File); } +// Make sure all tasks have finished before resetting the working directory. +Pool.wait(); if (!InitialWorkingDir.empty()) { if (auto EC = llvm::sys::fs::set_current_path(InitialWorkingDir)) llvm::errs() << "Error while restoring working directory: " ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D51987: [clangd] Rename global-symbol-builder to clangd-symbol-builder.
I mean `clangd-symbol-builder` On Wed, Sep 12, 2018 at 4:32 PM Eric Liu via Phabricator < revi...@reviews.llvm.org> wrote: > ioeric accepted this revision. > ioeric added a comment. > This revision is now accepted and ready to land. > > lgtm > > +1 to `clang-symbol-builder` > > > Repository: > rCTE Clang Tools Extra > > https://reviews.llvm.org/D51987 > > > > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r342134 - [clangd] Clarify and hide -index flag.
Author: ioeric Date: Thu Sep 13 05:53:23 2018 New Revision: 342134 URL: http://llvm.org/viewvc/llvm-project?rev=342134&view=rev Log: [clangd] Clarify and hide -index flag. Summary: The wording implies global index support, which is confusing. As most users shouldn't care about this flag, also make it hidden to avoid further confusion. Reviewers: sammccall, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D51977 Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=342134&r1=342133&r2=342134&view=diff == --- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original) +++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Thu Sep 13 05:53:23 2018 @@ -130,10 +130,11 @@ static llvm::cl::opt InputMirrorFi static llvm::cl::opt EnableIndex( "index", -llvm::cl::desc("Enable index-based features such as global code completion " - "and searching for symbols. " - "Clang uses an index built from symbols in opened files"), -llvm::cl::init(true)); +llvm::cl::desc( +"Enable index-based features. By default, clangd maintains an index " +"built from symbols in opened files. Global index support needs to " +"enabled separatedly."), +llvm::cl::init(true), llvm::cl::Hidden); static llvm::cl::opt ShowOrigins("debug-origin", ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r337453 - [CodeComplete] Fix accessibilty of protected members from base class.
Author: ioeric Date: Thu Jul 19 06:32:00 2018 New Revision: 337453 URL: http://llvm.org/viewvc/llvm-project?rev=337453&view=rev Log: [CodeComplete] Fix accessibilty of protected members from base class. Summary: Currently, protected members from base classes are marked as inaccessible when completing in derived class. This patch fixes the problem by setting the naming class correctly when looking up results in base class according to [11.2.p5]. Reviewers: aaron.ballman, sammccall, rsmith Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D49421 Modified: cfe/trunk/lib/Sema/SemaAccess.cpp cfe/trunk/lib/Sema/SemaCodeComplete.cpp cfe/trunk/test/Index/complete-access-checks.cpp Modified: cfe/trunk/lib/Sema/SemaAccess.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAccess.cpp?rev=337453&r1=337452&r2=337453&view=diff == --- cfe/trunk/lib/Sema/SemaAccess.cpp (original) +++ cfe/trunk/lib/Sema/SemaAccess.cpp Thu Jul 19 06:32:00 2018 @@ -11,6 +11,7 @@ // //===--===// +#include "clang/Basic/Specifiers.h" #include "clang/Sema/SemaInternal.h" #include "clang/AST/ASTContext.h" #include "clang/AST/CXXInheritance.h" @@ -1856,29 +1857,31 @@ void Sema::CheckLookupAccess(const Looku } } -/// Checks access to Decl from the given class. The check will take access +/// Checks access to Target from the given class. The check will take access /// specifiers into account, but no member access expressions and such. /// -/// \param Decl the declaration to check if it can be accessed +/// \param Target the declaration to check if it can be accessed /// \param Ctx the class/context from which to start the search -/// \return true if the Decl is accessible from the Class, false otherwise. -bool Sema::IsSimplyAccessible(NamedDecl *Decl, DeclContext *Ctx) { +/// \return true if the Target is accessible from the Class, false otherwise. +bool Sema::IsSimplyAccessible(NamedDecl *Target, DeclContext *Ctx) { if (CXXRecordDecl *Class = dyn_cast(Ctx)) { -if (!Decl->isCXXClassMember()) +if (!Target->isCXXClassMember()) return true; +if (Target->getAccess() == AS_public) + return true; QualType qType = Class->getTypeForDecl()->getCanonicalTypeInternal(); +// The unprivileged access is AS_none as we don't know how the member was +// accessed, which is described by the access in DeclAccessPair. +// `IsAccessible` will examine the actual access of Target (i.e. +// Decl->getAccess()) when calculating the access. AccessTarget Entity(Context, AccessedEntity::Member, Class, -DeclAccessPair::make(Decl, Decl->getAccess()), -qType); -if (Entity.getAccess() == AS_public) - return true; - +DeclAccessPair::make(Target, AS_none), qType); EffectiveContext EC(CurContext); return ::IsAccessible(*this, EC, Entity) != ::AR_inaccessible; } - - if (ObjCIvarDecl *Ivar = dyn_cast(Decl)) { + + if (ObjCIvarDecl *Ivar = dyn_cast(Target)) { // @public and @package ivars are always accessible. if (Ivar->getCanonicalAccessControl() == ObjCIvarDecl::Public || Ivar->getCanonicalAccessControl() == ObjCIvarDecl::Package) Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=337453&r1=337452&r2=337453&view=diff == --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original) +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Thu Jul 19 06:32:00 2018 @@ -1303,8 +1303,33 @@ namespace { void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx, bool InBaseClass) override { bool Accessible = true; - if (Ctx) -Accessible = Results.getSema().IsSimplyAccessible(ND, Ctx); + if (Ctx) { +DeclContext *AccessingCtx = Ctx; +// If ND comes from a base class, set the naming class back to the +// derived class if the search starts from the derived class (i.e. +// InBaseClass is true). +// +// Example: +// class B { protected: int X; } +// class D : public B { void f(); } +// void D::f() { this->^; } +// The completion after "this->" will have `InBaseClass` set to true and +// `Ctx` set to "B", when looking up in `B`. We need to set the actual +// accessing context (i.e. naming class) to "D" so that access can be +// calculated correctly. +if (InBaseClass && isa(Ctx)) { + CXXRecordDecl *RC = nullptr; + // Get the enclosing record. + for (DeclContext *DC = CurContext; !DC->isFileContext(); + DC = DC->getParent()) { +
r337529 - [Index] Set OrigD before D is changed.
Author: ioeric Date: Fri Jul 20 01:08:56 2018 New Revision: 337529 URL: http://llvm.org/viewvc/llvm-project?rev=337529&view=rev Log: [Index] Set OrigD before D is changed. Reviewers: akyrtzi, arphaman Reviewed By: akyrtzi Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D49476 Added: cfe/trunk/test/Index/index-template-specialization.cpp Modified: cfe/trunk/lib/Index/IndexingContext.cpp cfe/trunk/tools/c-index-test/c-index-test.c cfe/trunk/tools/libclang/Indexing.cpp Modified: cfe/trunk/lib/Index/IndexingContext.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.cpp?rev=337529&r1=337528&r2=337529&view=diff == --- cfe/trunk/lib/Index/IndexingContext.cpp (original) +++ cfe/trunk/lib/Index/IndexingContext.cpp Fri Jul 20 01:08:56 2018 @@ -350,6 +350,9 @@ bool IndexingContext::handleDeclOccurren } } + if (!OrigD) +OrigD = D; + if (isTemplateImplicitInstantiation(D)) { if (!IsRef) return true; @@ -359,9 +362,6 @@ bool IndexingContext::handleDeclOccurren assert(!isTemplateImplicitInstantiation(D)); } - if (!OrigD) -OrigD = D; - if (IsRef) Roles |= (unsigned)SymbolRole::Reference; else if (isDeclADefinition(OrigD, ContainerDC, *Ctx)) Added: cfe/trunk/test/Index/index-template-specialization.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-template-specialization.cpp?rev=337529&view=auto == --- cfe/trunk/test/Index/index-template-specialization.cpp (added) +++ cfe/trunk/test/Index/index-template-specialization.cpp Fri Jul 20 01:08:56 2018 @@ -0,0 +1,19 @@ +template +class Foo { +public: + void f(T t) {} +}; + +void g() { + Foo foo; + foo.f(0); +} + +// FIXME: if c-index-test uses OrigD for symbol info, refererences below should +// refer to template specialization decls. +// RUN: env CINDEXTEST_INDEXIMPLICITTEMPLATEINSTANTIATIONS=1 c-index-test -index-file %s | FileCheck %s +// CHECK: [indexDeclaration]: kind: c++-class-template | name: Foo +// CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: f +// CHECK-NEXT: [indexDeclaration]: kind: function | name: g +// CHECK-NEXT: [indexEntityReference]: kind: c++-class-template | name: Foo | USR: c:@ST>1#T@Foo +// CHECK-NEXT: [indexEntityReference]: kind: c++-instance-method | name: f | USR: c:@ST>1#T@Foo@F@f#t0.0# Modified: cfe/trunk/tools/c-index-test/c-index-test.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=337529&r1=337528&r2=337529&view=diff == --- cfe/trunk/tools/c-index-test/c-index-test.c (original) +++ cfe/trunk/tools/c-index-test/c-index-test.c Fri Jul 20 01:08:56 2018 @@ -3652,6 +3652,8 @@ static unsigned getIndexOptions(void) { index_opts |= CXIndexOpt_IndexFunctionLocalSymbols; if (!getenv("CINDEXTEST_DISABLE_SKIPPARSEDBODIES")) index_opts |= CXIndexOpt_SkipParsedBodiesInSession; + if (getenv("CINDEXTEST_INDEXIMPLICITTEMPLATEINSTANTIATIONS")) +index_opts |= CXIndexOpt_IndexImplicitTemplateInstantiations; return index_opts; } Modified: cfe/trunk/tools/libclang/Indexing.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/Indexing.cpp?rev=337529&r1=337528&r2=337529&view=diff == --- cfe/trunk/tools/libclang/Indexing.cpp (original) +++ cfe/trunk/tools/libclang/Indexing.cpp Fri Jul 20 01:08:56 2018 @@ -402,6 +402,8 @@ static IndexingOptions getIndexingOption IndexingOptions IdxOpts; if (index_options & CXIndexOpt_IndexFunctionLocalSymbols) IdxOpts.IndexFunctionLocals = true; + if (index_options & CXIndexOpt_IndexImplicitTemplateInstantiations) +IdxOpts.IndexImplicitInstantiation = true; return IdxOpts; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r337681 - [clangd] Penalize non-instance members when accessed via class instances.
Author: ioeric Date: Mon Jul 23 03:56:37 2018 New Revision: 337681 URL: http://llvm.org/viewvc/llvm-project?rev=337681&view=rev Log: [clangd] Penalize non-instance members when accessed via class instances. Summary: The following are metrics for explicit member access completions. There is no noticeable impact on other completion types. Before: EXPLICIT_MEMBER_ACCESS Total measurements: 24382 All measurements: MRR: 62.27 Top10: 80.21% Top-100: 94.48% Full identifiers: MRR: 98.81 Top10: 99.89% Top-100: 99.95% 0-5 filter len: MRR: 13.25 46.31 62.47 67.77 70.40 81.91 Top-10: 29%74% 84% 91% 91% 97% Top-100: 67% 99% 99% 99% 99% 100% After: EXPLICIT_MEMBER_ACCESS Total measurements: 24382 All measurements: MRR: 63.18 Top10: 80.58% Top-100: 95.07% Full identifiers: MRR: 98.79 Top10: 99.89% Top-100: 99.95% 0-5 filter len: MRR: 13.84 48.39 63.55 68.83 71.28 82.64 Top-10: 30%75% 84% 91% 91% 97% Top-100: 70% 99% 99% 99% 99% 100% * Top-N: wanted result is found in the first N completion results. * MRR: Mean reciprocal rank. Remark: the change seems to have minor positive impact. Although the improvement is relatively small, down-ranking non-instance members in instance member access should reduce noise in the completion results. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D49543 Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/clangd/CodeComplete.h clang-tools-extra/trunk/clangd/Quality.cpp clang-tools-extra/trunk/clangd/Quality.h clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=337681&r1=337680&r2=337681&view=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Mon Jul 23 03:56:37 2018 @@ -1062,6 +1062,7 @@ private: Output.Completions.back().Score = C.second; } Output.HasMore = Incomplete; +Output.Context = Recorder->CCContext.getKind(); return Output; } @@ -1156,6 +1157,7 @@ private: CompletionCandidate::Bundle Bundle) { SymbolQualitySignals Quality; SymbolRelevanceSignals Relevance; +Relevance.Context = Recorder->CCContext.getKind(); Relevance.Query = SymbolRelevanceSignals::CodeComplete; Relevance.FileProximityMatch = FileProximity.getPointer(); auto &First = Bundle.front(); @@ -1290,6 +1292,7 @@ raw_ostream &operator<<(raw_ostream &OS, raw_ostream &operator<<(raw_ostream &OS, const CodeCompleteResult &R) { OS << "CodeCompleteResult: " << R.Completions.size() << (R.HasMore ? "+" : "") + << " (" << getCompletionKindString(R.Context) << ")" << " items:\n"; for (const auto &C : R.Completions) OS << C << "\n"; Modified: clang-tools-extra/trunk/clangd/CodeComplete.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.h?rev=337681&r1=337680&r2=337681&view=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.h (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.h Mon Jul 23 03:56:37 2018 @@ -21,6 +21,7 @@ #include "Protocol.h" #include "index/Index.h" #include "clang/Frontend/PrecompiledPreamble.h" +#include "clang/Sema/CodeCompleteConsumer.h" #include "clang/Sema/CodeCompleteOptions.h" #include "clang/Tooling/CompilationDatabase.h" @@ -144,6 +145,7 @@ raw_ostream &operator<<(raw_ostream &, c struct CodeCompleteResult { std::vector Completions; bool HasMore = false; + CodeCompletionContext::Kind Context = CodeCompletionContext::CCC_Other; }; raw_ostream &operator<<(raw_ostream &, const CodeCompleteResult &); Modified: clang-tools-extra/trunk/clangd/Quality.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=337681&r1=337680&r2=337681&view=diff == --- clang-tools-extra/trunk/clangd/Quality.cpp (original) +++ clang-tools-extra/trunk/clangd/Quality.cpp Mon Jul 23 03:56:37 2018 @@ -11,7 +11,9 @@ #include "URI.h" #include "index/Index.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" +#include "clang/AST/DeclTemplate.h" #include "clang/AST/DeclVisitor.h" #include "clang/Basic/CharInfo.h" #include "clang/Basic/SourceManager.h" @@ -139,6 +141,27 @@ categorize(const index::SymbolInfo &D) { llv
[clang-tools-extra] r337816 - [clangd] Tune down quality score for class constructors so that it's ranked after class types.
Author: ioeric Date: Tue Jul 24 01:51:52 2018 New Revision: 337816 URL: http://llvm.org/viewvc/llvm-project?rev=337816&view=rev Log: [clangd] Tune down quality score for class constructors so that it's ranked after class types. Summary: Currently, class constructors have the same score as the class types, and they are often ranked before class types. This is often not desireable and can be annoying when snippet is enabled and constructor signatures are added. Metrics: ``` == OVERALL == Total measurements: 17 (+0) All measurements: MRR: 64.06 (+0.20) Top-5: 75.73% (+0.14%) Top-100: 93.71% (+0.01%) Full identifiers: MRR: 98.25 (+0.55) Top-5: 99.04% (+0.03%) Top-100: 99.16% (+0.00%) Filter length 0-5: MRR: 15.23 (+0.02) 50.50 (-0.02) 65.04 (+0.11) 70.75 (+0.19) 74.37 (+0.25) 79.43 (+0.32) Top-5:40.90% (+0.03%) 74.52% (+0.03%) 87.23% (+0.15%) 91.68% (+0.08%) 93.68% (+0.14%) 95.87% (+0.12%) Top-100: 68.21% (+0.02%) 96.28% (+0.07%) 98.43% (+0.00%) 98.72% (+0.00%) 98.74% (+0.01%) 98.81% (+0.00%) == DEFAULT == Total measurements: 57535 (+0) All measurements: MRR: 58.07 (+0.37) Top-5: 69.94% (+0.26%) Top-100: 90.14% (+0.03%) Full identifiers: MRR: 97.13 (+1.05) Top-5: 98.14% (+0.06%) Top-100: 98.34% (+0.00%) Filter length 0-5: MRR: 13.91 (+0.00) 38.53 (+0.01) 55.58 (+0.21) 63.63 (+0.30) 69.23 (+0.47) 72.87 (+0.60) Top-5:24.99% (+0.00%) 62.70% (+0.06%) 82.80% (+0.30%) 88.66% (+0.16%) 92.02% (+0.27%) 93.53% (+0.21%) Top-100: 51.56% (+0.05%) 93.19% (+0.13%) 97.30% (+0.00%) 97.81% (+0.00%) 97.85% (+0.01%) 97.79% (+0.00%) ``` Remark: - The full-id completions have +1.05 MRR improvement. - There is no noticeable impact on EXPLICIT_MEMBER_ACCESS and WANT_LOCAL. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D49667 Modified: clang-tools-extra/trunk/clangd/Quality.cpp clang-tools-extra/trunk/clangd/Quality.h clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp Modified: clang-tools-extra/trunk/clangd/Quality.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=337816&r1=337815&r2=337816&view=diff == --- clang-tools-extra/trunk/clangd/Quality.cpp (original) +++ clang-tools-extra/trunk/clangd/Quality.cpp Tue Jul 24 01:51:52 2018 @@ -67,6 +67,7 @@ static SymbolQualitySignals::SymbolCateg MAP(TypeDecl, Type); MAP(TypeAliasTemplateDecl, Type); MAP(ClassTemplateDecl, Type); +MAP(CXXConstructorDecl, Constructor); MAP(ValueDecl, Variable); MAP(VarTemplateDecl, Variable); MAP(FunctionDecl, Function); @@ -96,6 +97,8 @@ categorize(const CodeCompletionResult &R return SymbolQualitySignals::Type; case CXCursor_MemberRef: return SymbolQualitySignals::Variable; + case CXCursor_Constructor: +return SymbolQualitySignals::Constructor; default: return SymbolQualitySignals::Keyword; } @@ -124,10 +127,11 @@ categorize(const index::SymbolInfo &D) { case index::SymbolKind::InstanceProperty: case index::SymbolKind::ClassProperty: case index::SymbolKind::StaticProperty: - case index::SymbolKind::Constructor: case index::SymbolKind::Destructor: case index::SymbolKind::ConversionFunction: return SymbolQualitySignals::Function; + case index::SymbolKind::Constructor: +return SymbolQualitySignals::Constructor; case index::SymbolKind::Variable: case index::SymbolKind::Field: case index::SymbolKind::EnumConstant: @@ -210,6 +214,7 @@ float SymbolQualitySignals::evaluate() c Score *= 0.2f; break; case Unknown: + case Constructor: // No boost constructors so they are after class types. break; } Modified: clang-tools-extra/trunk/clangd/Quality.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.h?rev=337816&r1=337815&r2=337816&view=diff == --- clang-tools-extra/trunk/clangd/Quality.h (original) +++ clang-tools-extra/trunk/clang
Re: r337850 - Revert "[VFS] Cleanups to VFS interfaces."
Please also include a link to the test failure in the commit message or this email thread. On Tue, Jul 24, 2018 at 10:28 PM Jordan Rupprecht via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: rupprecht > Date: Tue Jul 24 13:28:07 2018 > New Revision: 337850 > > URL: http://llvm.org/viewvc/llvm-project?rev=337850&view=rev > Log: > Revert "[VFS] Cleanups to VFS interfaces." > > This reverts commit r337834 due to test failures. > > Modified: > cfe/trunk/include/clang/Basic/VirtualFileSystem.h > cfe/trunk/lib/Basic/FileManager.cpp > cfe/trunk/lib/Basic/VirtualFileSystem.cpp > > Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=337850&r1=337849&r2=337850&view=diff > > == > --- cfe/trunk/include/clang/Basic/VirtualFileSystem.h (original) > +++ cfe/trunk/include/clang/Basic/VirtualFileSystem.h Tue Jul 24 13:28:07 > 2018 > @@ -45,8 +45,7 @@ class MemoryBuffer; > namespace clang { > namespace vfs { > > -/// File information from a \p File::status() operation. > -/// This is roughly equivalent to a `struct stat` plus a file path. > +/// The result of a \p status operation. > class Status { >std::string Name; >llvm::sys::fs::UniqueID UID; > @@ -67,14 +66,13 @@ public: > llvm::sys::TimePoint<> MTime, uint32_t User, uint32_t Group, > uint64_t Size, llvm::sys::fs::file_type Type, > llvm::sys::fs::perms Perms); > - Status(const llvm::sys::fs::file_status &FSStatus, StringRef Name); > > - /// Get a copy of a this Status with a different name. > - Status copyWithNewName(StringRef NewName); > + /// Get a copy of a Status with a different name. > + static Status copyWithNewName(const Status &In, StringRef NewName); > + static Status copyWithNewName(const llvm::sys::fs::file_status &In, > +StringRef NewName); > >/// Returns the name that should be used for this file or directory. > - /// This is usually the path that the file was opened as, without > resolving > - /// relative paths or symlinks. >StringRef getName() const { return Name; } > >/// @name Status interface from llvm::sys::fs > @@ -109,16 +107,15 @@ public: >virtual ~File(); > >/// Get the status of the file. > - /// This may access the filesystem (e.g. `stat()`), or return a cached > value. >virtual llvm::ErrorOr status() = 0; > > - /// Get the "real name" of the file, if available. > - /// This should be absolute, and typically has symlinks resolved. > - /// > - /// Only some VFS implementations provide this, and only sometimes. > - /// FIXME: these maybe-available semantics are not very useful. It > would be > - /// nice if this was more consistent with FileSystem::getRealPath(). > - virtual llvm::Optional getRealPath() { return llvm::None; } > + /// Get the name of the file > + virtual llvm::ErrorOr getName() { > +if (auto Status = status()) > + return Status->getName().str(); > +else > + return Status.getError(); > + } > >/// Get the contents of the file as a \p MemoryBuffer. >virtual llvm::ErrorOr> > > Modified: cfe/trunk/lib/Basic/FileManager.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=337850&r1=337849&r2=337850&view=diff > > == > --- cfe/trunk/lib/Basic/FileManager.cpp (original) > +++ cfe/trunk/lib/Basic/FileManager.cpp Tue Jul 24 13:28:07 2018 > @@ -316,7 +316,7 @@ const FileEntry *FileManager::getFile(St >UFE.File = std::move(F); >UFE.IsValid = true; >if (UFE.File) > -if (auto RealPathName = UFE.File->getRealPath()) > +if (auto RealPathName = UFE.File->getName()) >UFE.RealPathName = *RealPathName; >return &UFE; > } > > Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=337850&r1=337849&r2=337850&view=diff > > == > --- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original) > +++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Tue Jul 24 13:28:07 2018 > @@ -73,14 +73,16 @@ Status::Status(StringRef Name, UniqueID > : Name(Name), UID(UID), MTime(MTime), User(User), Group(Group), > Size(Size), >Type(Type), Perms(Perms) {} > > -Status::Status(const file_status &In, StringRef NewName) > -: Status(NewName, In.getUniqueID(), In.getLastModificationTime(), > - In.getUser(), In.getGroup(), In.getSize(), In.type(), > - In.permissions()) {} > - > -Status Status::copyWithNewName(StringRef NewName) { > - return Status(NewName, getUniqueID(), getLastModificationTime(), > getUser(), > -getGroup(), getSize(), getType(), getPermissions()); > +Status Status::copyW
[clang-tools-extra] r337907 - [clangd] Use a sigmoid style function for #usages boost in symbol quality.
Author: ioeric Date: Wed Jul 25 04:26:35 2018 New Revision: 337907 URL: http://llvm.org/viewvc/llvm-project?rev=337907&view=rev Log: [clangd] Use a sigmoid style function for #usages boost in symbol quality. Summary: This has a shape to similar logarithm function but grows much slower for large #usages. Metrics: https://reviews.llvm.org/P8096 Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, cfe-commits, sammccall Differential Revision: https://reviews.llvm.org/D49780 Modified: clang-tools-extra/trunk/clangd/Quality.cpp clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Modified: clang-tools-extra/trunk/clangd/Quality.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=337907&r1=337906&r2=337907&view=diff == --- clang-tools-extra/trunk/clangd/Quality.cpp (original) +++ clang-tools-extra/trunk/clangd/Quality.cpp Wed Jul 25 04:26:35 2018 @@ -190,8 +190,18 @@ float SymbolQualitySignals::evaluate() c // This avoids a sharp gradient for tail symbols, and also neatly avoids the // question of whether 0 references means a bad symbol or missing data. - if (References >= 10) -Score *= std::log10(References); + if (References >= 10) { +// Use a sigmoid style boosting function, which flats out nicely for large +// numbers (e.g. 2.58 for 1M refererences). +// The following boosting function is equivalent to: +// m = 0.06 +// f = 12.0 +// boost = f * sigmoid(m * std::log(References)) - 0.5 * f + 0.59 +// Sample data points: (10, 1.00), (100, 1.41), (1000, 1.82), +// (10K, 2.21), (100K, 2.58), (1M, 2.94) +float s = std::pow(References, -0.06); +Score *= 6.0 * (1 - s) / (1 + s) + 0.59; + } if (Deprecated) Score *= 0.1f; Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=337907&r1=337906&r2=337907&view=diff == --- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Wed Jul 25 04:26:35 2018 @@ -476,11 +476,12 @@ TEST(CompletionTest, ScopedWithFilter) { } TEST(CompletionTest, ReferencesAffectRanking) { - auto Results = completions("int main() { abs^ }", {ns("absl"), func("abs")}); - EXPECT_THAT(Results.Completions, HasSubsequence(Named("abs"), Named("absl"))); + auto Results = completions("int main() { abs^ }", {ns("absl"), func("absb")}); + EXPECT_THAT(Results.Completions, HasSubsequence(Named("absb"), Named("absl"))); Results = completions("int main() { abs^ }", -{withReferences(1, ns("absl")), func("abs")}); - EXPECT_THAT(Results.Completions, HasSubsequence(Named("absl"), Named("abs"))); +{withReferences(1, ns("absl")), func("absb")}); + EXPECT_THAT(Results.Completions, + HasSubsequence(Named("absl"), Named("absb"))); } TEST(CompletionTest, GlobalQualified) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D48903: [VirtualFileSystem] InMemoryFileSystem::status: Return a Status with the requested name
It would make it easier for your reviewers to look at the new changes if you just reopen this patch and update the diff :) On Wed, Jul 25, 2018 at 5:49 PM Simon Marchi via Phabricator < revi...@reviews.llvm.org> wrote: > simark added a comment. > > I uploaded a new version of this patch here: > https://reviews.llvm.org/D49804 > > > Repository: > rC Clang > > https://reviews.llvm.org/D48903 > > > > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r337850 - Revert "[VFS] Cleanups to VFS interfaces."
Thanks Jordan! On Wed, Jul 25, 2018 at 6:01 PM Jordan Rupprecht wrote: > On Wed, Jul 25, 2018 at 1:40 AM Eric Liu wrote: > >> Please also include a link to the test failure in the commit message or >> this email thread. >> > Sorry, I left the failure on the review thread ( > https://reviews.llvm.org/D49724) but forgot to include it in the commit > message. I'll make sure to do that next time! > > Build bot logs: > http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/14441/steps/ninja%20check%201 > Sample snippet: > > [ RUN ] GoToInclude.All > /home/buildslave/buildslave/clang-cmake-aarch64-quick/llvm/tools/clang/tools/extra/unittests/clangd/XRefsTests.cpp:953: > Failure > Value of: *Locations > Expected: has 1 element that is equal to 0:0-0:0@file:///clangd-test/foo.h > Actual: {} > > > >> >> On Tue, Jul 24, 2018 at 10:28 PM Jordan Rupprecht via cfe-commits < >> cfe-commits@lists.llvm.org> wrote: >> >>> Author: rupprecht >>> Date: Tue Jul 24 13:28:07 2018 >>> New Revision: 337850 >>> >>> URL: http://llvm.org/viewvc/llvm-project?rev=337850&view=rev >>> Log: >>> Revert "[VFS] Cleanups to VFS interfaces." >>> >>> This reverts commit r337834 due to test failures. >>> >>> Modified: >>> cfe/trunk/include/clang/Basic/VirtualFileSystem.h >>> cfe/trunk/lib/Basic/FileManager.cpp >>> cfe/trunk/lib/Basic/VirtualFileSystem.cpp >>> >>> Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h >>> URL: >>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=337850&r1=337849&r2=337850&view=diff >>> >>> == >>> --- cfe/trunk/include/clang/Basic/VirtualFileSystem.h (original) >>> +++ cfe/trunk/include/clang/Basic/VirtualFileSystem.h Tue Jul 24 >>> 13:28:07 2018 >>> @@ -45,8 +45,7 @@ class MemoryBuffer; >>> namespace clang { >>> namespace vfs { >>> >>> -/// File information from a \p File::status() operation. >>> -/// This is roughly equivalent to a `struct stat` plus a file path. >>> +/// The result of a \p status operation. >>> class Status { >>>std::string Name; >>>llvm::sys::fs::UniqueID UID; >>> @@ -67,14 +66,13 @@ public: >>> llvm::sys::TimePoint<> MTime, uint32_t User, uint32_t Group, >>> uint64_t Size, llvm::sys::fs::file_type Type, >>> llvm::sys::fs::perms Perms); >>> - Status(const llvm::sys::fs::file_status &FSStatus, StringRef Name); >>> >>> - /// Get a copy of a this Status with a different name. >>> - Status copyWithNewName(StringRef NewName); >>> + /// Get a copy of a Status with a different name. >>> + static Status copyWithNewName(const Status &In, StringRef NewName); >>> + static Status copyWithNewName(const llvm::sys::fs::file_status &In, >>> +StringRef NewName); >>> >>>/// Returns the name that should be used for this file or directory. >>> - /// This is usually the path that the file was opened as, without >>> resolving >>> - /// relative paths or symlinks. >>>StringRef getName() const { return Name; } >>> >>>/// @name Status interface from llvm::sys::fs >>> @@ -109,16 +107,15 @@ public: >>>virtual ~File(); >>> >>>/// Get the status of the file. >>> - /// This may access the filesystem (e.g. `stat()`), or return a >>> cached value. >>>virtual llvm::ErrorOr status() = 0; >>> >>> - /// Get the "real name" of the file, if available. >>> - /// This should be absolute, and typically has symlinks resolved. >>> - /// >>> - /// Only some VFS implementations provide this, and only sometimes. >>> - /// FIXME: these maybe-available semantics are not very useful. It >>> would be >>> - /// nice if this was more consistent with FileSystem::getRealPath(). >>> - virtual llvm::Optional getRealPath() { return >>> llvm::None; } >>> + /// Get the name of the file >>> + virtual llvm::ErrorOr getName() { >>> +if (auto Status = status()) >>> + return Status->getName().str(); >>> +else >>> + return Status.getError(); >>> + } >>> >>>/// Get the contents of the file as a \p MemoryBuffer. >>>virtual llvm::ErrorOr> >>> >>> Modified: cfe/trunk/lib/Basic/FileManager.cpp >>> URL: >>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=337850&r1=337849&r2=337850&view=diff >>> >>> == >>> --- cfe/trunk/lib/Basic/FileManager.cpp (original) >>> +++ cfe/trunk/lib/Basic/FileManager.cpp Tue Jul 24 13:28:07 2018 >>> @@ -316,7 +316,7 @@ const FileEntry *FileManager::getFile(St >>>UFE.File = std::move(F); >>>UFE.IsValid = true; >>>if (UFE.File) >>> -if (auto RealPathName = UFE.File->getRealPath()) >>> +if (auto RealPathName = UFE.File->getName()) >>>UFE.RealPathName = *RealPathName; >>>return &UFE; >>> } >>> >>> Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp >>> URL: >>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/B
Re: r337453 - [CodeComplete] Fix accessibilty of protected members from base class.
Thanks a lot for looking into this! You are right, the change in SemaAccess seemed to have done the job to fix the protected member bug in specific. I think I made the change in SemaCodeComplete before SemaAccess and didn't realized the previous one was unnecessary to fix the tests. I think the accessing context/naming class is still wrong though. Basically, we want the naming class to be the derived class instead of the base class if the access is from a derived class. Without this, accessibility check is relaxed, but it probably doesn't have very negative impact on code completion experience, so I think it's okay to revert the change in SemaCodeComplete. Thanks again! On Mon, Jul 30, 2018 at 5:22 PM Ilya Biryukov wrote: > Prtially reverted the commit in r338255 to fix a very frequent crash. > The code seemed obviously wrong there (calling accessibility checking, > passing a possibly unrelated class) and the tests didn't break after > reverting it. > > Let me know if I missed anything. > > On Thu, Jul 19, 2018 at 3:37 PM Eric Liu via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> Author: ioeric >> Date: Thu Jul 19 06:32:00 2018 >> New Revision: 337453 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=337453&view=rev >> Log: >> [CodeComplete] Fix accessibilty of protected members from base class. >> >> Summary: >> Currently, protected members from base classes are marked as >> inaccessible when completing in derived class. This patch fixes the >> problem by >> setting the naming class correctly when looking up results in base class >> according to [11.2.p5]. >> >> Reviewers: aaron.ballman, sammccall, rsmith >> >> Reviewed By: aaron.ballman >> >> Subscribers: cfe-commits >> >> Differential Revision: https://reviews.llvm.org/D49421 >> >> Modified: >> cfe/trunk/lib/Sema/SemaAccess.cpp >> cfe/trunk/lib/Sema/SemaCodeComplete.cpp >> cfe/trunk/test/Index/complete-access-checks.cpp >> >> Modified: cfe/trunk/lib/Sema/SemaAccess.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAccess.cpp?rev=337453&r1=337452&r2=337453&view=diff >> >> == >> --- cfe/trunk/lib/Sema/SemaAccess.cpp (original) >> +++ cfe/trunk/lib/Sema/SemaAccess.cpp Thu Jul 19 06:32:00 2018 >> @@ -11,6 +11,7 @@ >> // >> >> >> //===--===// >> >> +#include "clang/Basic/Specifiers.h" >> #include "clang/Sema/SemaInternal.h" >> #include "clang/AST/ASTContext.h" >> #include "clang/AST/CXXInheritance.h" >> @@ -1856,29 +1857,31 @@ void Sema::CheckLookupAccess(const Looku >>} >> } >> >> -/// Checks access to Decl from the given class. The check will take >> access >> +/// Checks access to Target from the given class. The check will take >> access >> /// specifiers into account, but no member access expressions and such. >> /// >> -/// \param Decl the declaration to check if it can be accessed >> +/// \param Target the declaration to check if it can be accessed >> /// \param Ctx the class/context from which to start the search >> -/// \return true if the Decl is accessible from the Class, false >> otherwise. >> -bool Sema::IsSimplyAccessible(NamedDecl *Decl, DeclContext *Ctx) { >> +/// \return true if the Target is accessible from the Class, false >> otherwise. >> +bool Sema::IsSimplyAccessible(NamedDecl *Target, DeclContext *Ctx) { >>if (CXXRecordDecl *Class = dyn_cast(Ctx)) { >> -if (!Decl->isCXXClassMember()) >> +if (!Target->isCXXClassMember()) >>return true; >> >> +if (Target->getAccess() == AS_public) >> + return true; >> QualType qType = Class->getTypeForDecl()->getCanonicalTypeInternal(); >> +// The unprivileged access is AS_none as we don't know how the >> member was >> +// accessed, which is described by the access in DeclAccessPair. >> +// `IsAccessible` will examine the actual access of Target (i.e. >> +// Decl->getAccess()) when calculating the access. >> AccessTarget Entity(Context, AccessedEntity::Member, Class, >> -DeclAccessPair::make(Decl, Decl->getAccess()), >> -qType); >> -if (Entity.getAccess() == AS_public) >> - return true; >> - >> +DeclAccessPair::make(Tar
[clang-tools-extra] r338696 - Replace hardcoded format styles in a few tools with the default style in libFormat.
Author: ioeric Date: Thu Aug 2 03:30:56 2018 New Revision: 338696 URL: http://llvm.org/viewvc/llvm-project?rev=338696&view=rev Log: Replace hardcoded format styles in a few tools with the default style in libFormat. Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp clang-tools-extra/trunk/clang-move/ClangMove.cpp clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=338696&r1=338695&r2=338696&view=diff == --- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original) +++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Thu Aug 2 03:30:56 2018 @@ -989,7 +989,8 @@ void ChangeNamespaceTool::onEndOfTransla // Add replacements referring to the changed code to existing replacements, // which refers to the original code. Replaces = Replaces.merge(NewReplacements); -auto Style = format::getStyle("file", FilePath, FallbackStyle); +auto Style = +format::getStyle(format::DefaultFormatStyle, FilePath, FallbackStyle); if (!Style) { llvm::errs() << llvm::toString(Style.takeError()) << "\n"; continue; Modified: clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp?rev=338696&r1=338695&r2=338696&view=diff == --- clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp (original) +++ clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp Thu Aug 2 03:30:56 2018 @@ -97,8 +97,8 @@ int main(int argc, char **argv) { IntrusiveRefCntPtr(new DiagnosticIDs()), DiagOpts.get()); // Determine a formatting style from options. - auto FormatStyleOrError = - format::getStyle(FormatStyleOpt, FormatStyleConfig, "LLVM"); + auto FormatStyleOrError = format::getStyle(FormatStyleOpt, FormatStyleConfig, + format::DefaultFallbackStyle); if (!FormatStyleOrError) { llvm::errs() << llvm::toString(FormatStyleOrError.takeError()) << "\n"; return 1; Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=338696&r1=338695&r2=338696&view=diff == --- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original) +++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Thu Aug 2 03:30:56 2018 @@ -795,7 +795,8 @@ void ClangMoveTool::removeDeclsInOldFile // Ignore replacements for new.h/cc. if (SI == FilePathToFileID.end()) continue; llvm::StringRef Code = SM.getBufferData(SI->second); -auto Style = format::getStyle("file", FilePath, Context->FallbackStyle); +auto Style = format::getStyle(format::DefaultFormatStyle, FilePath, + Context->FallbackStyle); if (!Style) { llvm::errs() << llvm::toString(Style.takeError()) << "\n"; continue; Modified: clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp?rev=338696&r1=338695&r2=338696&view=diff == --- clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp (original) +++ clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp Thu Aug 2 03:30:56 2018 @@ -324,7 +324,8 @@ int includeFixerMain(int argc, const cha const IncludeFixerContext::HeaderInfo &RHS) { return LHS.QualifiedName == RHS.QualifiedName; }); -auto InsertStyle = format::getStyle("file", Context.getFilePath(), Style); +auto InsertStyle = format::getStyle(format::DefaultFormatStyle, +Context.getFilePath(), Style); if (!InsertStyle) { llvm::errs() << llvm::toString(InsertStyle.takeError()) << "\n"; return 1; @@ -402,7 +403,8 @@ int includeFixerMain(int argc, const cha std::vector FixerReplacements; for (const auto &Context : Contexts) { StringRef FilePath = Context.getFilePath(); -auto InsertStyle = format::getStyle("file", FilePath, Style); +auto InsertStyle = +format::getStyle(format::DefaultFormatStyle, FilePath, Style); if (!InsertStyle) { llvm::errs() << llvm::toString(InsertStyle.takeError()) << "\n"; return 1;
r338832 - Fully qualify the renamed symbol if the shortened name is ambiguous.
Author: ioeric Date: Fri Aug 3 02:16:07 2018 New Revision: 338832 URL: http://llvm.org/viewvc/llvm-project?rev=338832&view=rev Log: Fully qualify the renamed symbol if the shortened name is ambiguous. Summary: For example, when renaming `a::b::x::foo` to `y::foo` below, replacing `x::foo()` with `y::foo()` can cause ambiguity. In such cases, we simply fully qualify the name with leading `::`. ``` namespace a { namespace b { namespace x { void foo() {} } namespace y { void foo() {} } } } namespace a { namespace b { void f() { x::foo(); } } } ``` Reviewers: ilya-biryukov, hokein Reviewed By: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D50189 Modified: cfe/trunk/lib/Tooling/Core/Lookup.cpp cfe/trunk/unittests/Tooling/LookupTest.cpp Modified: cfe/trunk/lib/Tooling/Core/Lookup.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Core/Lookup.cpp?rev=338832&r1=338831&r2=338832&view=diff == --- cfe/trunk/lib/Tooling/Core/Lookup.cpp (original) +++ cfe/trunk/lib/Tooling/Core/Lookup.cpp Fri Aug 3 02:16:07 2018 @@ -14,6 +14,7 @@ #include "clang/Tooling/Core/Lookup.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" +#include "clang/AST/DeclarationName.h" using namespace clang; using namespace clang::tooling; @@ -114,6 +115,37 @@ static bool isFullyQualified(const Neste return false; } +// Returns true if spelling symbol \p QName as \p Spelling in \p UseContext is +// ambiguous. For example, if QName is "::y::bar" and the spelling is "y::bar" +// in `UseContext` "a" that contains a nested namespace "a::y", then "y::bar" +// can be resolved to ::a::y::bar, which can cause compile error. +// FIXME: consider using namespaces. +static bool isAmbiguousNameInScope(StringRef Spelling, StringRef QName, + const DeclContext &UseContext) { + assert(QName.startswith("::")); + if (Spelling.startswith("::")) +return false; + + // Lookup the first component of Spelling in all enclosing namespaces and + // check if there is any existing symbols with the same name but in different + // scope. + StringRef Head = Spelling.split("::").first; + + llvm::SmallVector UseNamespaces = + getAllNamedNamespaces(&UseContext); + auto &AST = UseContext.getParentASTContext(); + StringRef TrimmedQName = QName.substr(2); + for (const auto *NS : UseNamespaces) { +auto LookupRes = NS->lookup(DeclarationName(&AST.Idents.get(Head))); +if (!LookupRes.empty()) { + for (const NamedDecl *Res : LookupRes) +if (!TrimmedQName.startswith(Res->getQualifiedNameAsString())) + return true; +} + } + return false; +} + std::string tooling::replaceNestedName(const NestedNameSpecifier *Use, const DeclContext *UseContext, const NamedDecl *FromDecl, @@ -146,6 +178,14 @@ std::string tooling::replaceNestedName(c // figure out how good a namespace match we have with our destination type. // We work backwards (from most specific possible namespace to least // specific). - return getBestNamespaceSubstr(UseContext, ReplacementString, -isFullyQualified(Use)); + StringRef Suggested = getBestNamespaceSubstr(UseContext, ReplacementString, + isFullyQualified(Use)); + // Use the fully qualified name if the suggested name is ambiguous. + // FIXME: consider re-shortening the name until the name is not ambiguous. We + // are not doing this because ambiguity is pretty bad and we should not try to + // be clever in handling such cases. Making this noticeable to users seems to + // be a better option. + return isAmbiguousNameInScope(Suggested, ReplacementString, *UseContext) + ? ReplacementString + : Suggested; } Modified: cfe/trunk/unittests/Tooling/LookupTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/LookupTest.cpp?rev=338832&r1=338831&r2=338832&view=diff == --- cfe/trunk/unittests/Tooling/LookupTest.cpp (original) +++ cfe/trunk/unittests/Tooling/LookupTest.cpp Fri Aug 3 02:16:07 2018 @@ -68,7 +68,7 @@ TEST(LookupTest, replaceNestedFunctionNa "namespace b { void f() { a::foo(); } }\n"); Visitor.OnCall = [&](CallExpr *Expr) { -EXPECT_EQ("a::bar", replaceCallExpr(Expr, "::a::bar")); +EXPECT_EQ("::a::bar", replaceCallExpr(Expr, "::a::bar")); }; Visitor.runOver("namespace a { void foo(); }\n" "namespace b { namespace a { void foo(); }\n" @@ -127,6 +127,38 @@ TEST(LookupTest, replaceNestedFunctionNa "namespace a { namespace b { namespace c {" "void f() { foo(); }" "} } }\n"); + + // If the shortest name is ambiguous,
[clang-tools-extra] r324354 - [clangd] Remove unused variable. NFC
Author: ioeric Date: Tue Feb 6 07:27:43 2018 New Revision: 324354 URL: http://llvm.org/viewvc/llvm-project?rev=324354&view=rev Log: [clangd] Remove unused variable. NFC Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=324354&r1=324353&r2=324354&view=diff == --- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original) +++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Tue Feb 6 07:27:43 2018 @@ -244,7 +244,6 @@ static llvm::Optional readS if (ContentLength > 0) { std::string JSON(ContentLength, '\0'); -llvm::StringRef JSONRef; In.read(&JSON[0], ContentLength); Out.mirrorInput(StringRef(JSON.data(), In.gcount())); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r324358 - [clangd] Use URIs in index symbols.
Author: ioeric Date: Tue Feb 6 08:10:35 2018 New Revision: 324358 URL: http://llvm.org/viewvc/llvm-project?rev=324358&view=rev Log: [clangd] Use URIs in index symbols. Reviewers: hokein, sammccall Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D42915 Modified: clang-tools-extra/trunk/clangd/index/Index.cpp clang-tools-extra/trunk/clangd/index/Index.h clang-tools-extra/trunk/clangd/index/Merge.cpp clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp clang-tools-extra/trunk/clangd/index/SymbolCollector.h clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Modified: clang-tools-extra/trunk/clangd/index/Index.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=324358&r1=324357&r2=324358&view=diff == --- clang-tools-extra/trunk/clangd/index/Index.cpp (original) +++ clang-tools-extra/trunk/clangd/index/Index.cpp Tue Feb 6 08:10:35 2018 @@ -54,7 +54,7 @@ static void own(Symbol &S, DenseSethttp://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=324358&r1=324357&r2=324358&view=diff == --- clang-tools-extra/trunk/clangd/index/Index.h (original) +++ clang-tools-extra/trunk/clangd/index/Index.h Tue Feb 6 08:10:35 2018 @@ -23,8 +23,8 @@ namespace clang { namespace clangd { struct SymbolLocation { - // The absolute path of the source file where a symbol occurs. - llvm::StringRef FilePath; + // The URI of the source file where a symbol occurs. + llvm::StringRef FileURI; // The 0-based offset to the first character of the symbol from the beginning // of the source file. unsigned StartOffset; Modified: clang-tools-extra/trunk/clangd/index/Merge.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Merge.cpp?rev=324358&r1=324357&r2=324358&view=diff == --- clang-tools-extra/trunk/clangd/index/Merge.cpp (original) +++ clang-tools-extra/trunk/clangd/index/Merge.cpp Tue Feb 6 08:10:35 2018 @@ -63,7 +63,7 @@ mergeSymbol(const Symbol &L, const Symbo Symbol S = L; // For each optional field, fill it from R if missing in L. // (It might be missing in R too, but that's a no-op). - if (S.CanonicalDeclaration.FilePath == "") + if (S.CanonicalDeclaration.FileURI == "") S.CanonicalDeclaration = R.CanonicalDeclaration; if (S.CompletionLabel == "") S.CompletionLabel = R.CompletionLabel; Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=324358&r1=324357&r2=324358&view=diff == --- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original) +++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Tue Feb 6 08:10:35 2018 @@ -9,6 +9,8 @@ #include "SymbolCollector.h" #include "../CodeCompletionStrings.h" +#include "../Logger.h" +#include "../URI.h" #include "clang/AST/DeclCXX.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Basic/SourceManager.h" @@ -22,14 +24,17 @@ namespace clang { namespace clangd { namespace { -// Make the Path absolute using the current working directory of the given -// SourceManager if the Path is not an absolute path. If failed, this combine -// relative paths with \p FallbackDir to get an absolute path. +// Returns a URI of \p Path. Firstly, this makes the \p Path absolute using the +// current working directory of the given SourceManager if the Path is not an +// absolute path. If failed, this resolves relative paths against \p FallbackDir +// to get an absolute path. Then, this tries creating an URI for the absolute +// path with schemes specified in \p Opts. This returns an URI with the first +// working scheme, if there is any; otherwise, this returns None. // // The Path can be a path relative to the build directory, or retrieved from // the SourceManager. -std::string makeAbsolutePath(const SourceManager &SM, StringRef Path, - StringRef FallbackDir) { +llvm::Optional toURI(const SourceManager &SM, StringRef Path, + const SymbolCollector::Options &Opts) { llvm::SmallString<128> AbsolutePath(Path); if (std::error_code EC = SM.getFileManager().getVirtualFileSystem()->makeAbsolute( @@ -56,11 +61,21 @@ std::string makeAbsolutePath(const Sourc llvm::sys::path::filename(AbsolutePath.str())); AbsolutePath = AbsoluteFilename; } - } else if (!Fallba
[clang-tools-extra] r324475 - [clangd] Do not precent-encode numbers in URI.
Author: ioeric Date: Wed Feb 7 04:12:06 2018 New Revision: 324475 URL: http://llvm.org/viewvc/llvm-project?rev=324475&view=rev Log: [clangd] Do not precent-encode numbers in URI. Reviewers: ilya-biryukov Subscribers: klimek, jkorous-apple, cfe-commits, sammccall Differential Revision: https://reviews.llvm.org/D43009 Modified: clang-tools-extra/trunk/clangd/URI.cpp clang-tools-extra/trunk/unittests/clangd/URITests.cpp Modified: clang-tools-extra/trunk/clangd/URI.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/URI.cpp?rev=324475&r1=324474&r2=324475&view=diff == --- clang-tools-extra/trunk/clangd/URI.cpp (original) +++ clang-tools-extra/trunk/clangd/URI.cpp Wed Feb 7 04:12:06 2018 @@ -79,7 +79,8 @@ findSchemeByName(llvm::StringRef Scheme) bool shouldEscape(unsigned char C) { // Unreserved characters. - if ((C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z')) + if ((C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') || + (C >= '0' && C <= '9')) return false; switch (C) { case '-': Modified: clang-tools-extra/trunk/unittests/clangd/URITests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/URITests.cpp?rev=324475&r1=324474&r2=324475&view=diff == --- clang-tools-extra/trunk/unittests/clangd/URITests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/URITests.cpp Wed Feb 7 04:12:06 2018 @@ -72,6 +72,7 @@ URI parseOrDie(llvm::StringRef Uri) { TEST(PercentEncodingTest, Encode) { EXPECT_EQ(URI("x", /*Authority=*/"", "a/b/c").toString(), "x:a/b/c"); EXPECT_EQ(URI("x", /*Authority=*/"", "a!b;c~").toString(), "x:a%21b%3bc~"); + EXPECT_EQ(URI("x", /*Authority=*/"", "a123b").toString(), "x:a123b"); } TEST(PercentEncodingTest, Decode) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r325343 - [clangd] collect symbol #include & insert #include in global code completion.
Author: ioeric Date: Fri Feb 16 06:15:55 2018 New Revision: 325343 URL: http://llvm.org/viewvc/llvm-project?rev=325343&view=rev Log: [clangd] collect symbol #include & insert #include in global code completion. Summary: o Collect suitable #include paths for index symbols. This also does smart mapping for STL symbols and IWYU pragma (code borrowed from include-fixer). o For global code completion, add a command for inserting new #include in each code completion item. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, mgorny, ilya-biryukov, jkorous-apple, hintonda, cfe-commits Differential Revision: https://reviews.llvm.org/D42640 Added: clang-tools-extra/trunk/clangd/Headers.cpp clang-tools-extra/trunk/clangd/Headers.h clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp clang-tools-extra/trunk/clangd/index/CanonicalIncludes.h clang-tools-extra/trunk/test/clangd/insert-include.test clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp clang-tools-extra/trunk/clangd/ClangdServer.cpp clang-tools-extra/trunk/clangd/ClangdServer.h clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/clangd/Protocol.cpp clang-tools-extra/trunk/clangd/Protocol.h clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp clang-tools-extra/trunk/clangd/index/Index.cpp clang-tools-extra/trunk/clangd/index/Index.h clang-tools-extra/trunk/clangd/index/Merge.cpp clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp clang-tools-extra/trunk/clangd/index/SymbolCollector.h clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp clang-tools-extra/trunk/test/clangd/completion-snippets.test clang-tools-extra/trunk/test/clangd/initialize-params-invalid.test clang-tools-extra/trunk/test/clangd/initialize-params.test clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=325343&r1=325342&r2=325343&view=diff == --- clang-tools-extra/trunk/clangd/CMakeLists.txt (original) +++ clang-tools-extra/trunk/clangd/CMakeLists.txt Fri Feb 16 06:15:55 2018 @@ -14,6 +14,7 @@ add_clang_library(clangDaemon DraftStore.cpp FuzzyMatch.cpp GlobalCompilationDatabase.cpp + Headers.cpp JSONExpr.cpp JSONRPCDispatcher.cpp Logger.cpp @@ -25,6 +26,7 @@ add_clang_library(clangDaemon TUScheduler.cpp URI.cpp XRefs.cpp + index/CanonicalIncludes.cpp index/FileIndex.cpp index/Index.cpp index/MemIndex.cpp Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=325343&r1=325342&r2=325343&view=diff == --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Fri Feb 16 06:15:55 2018 @@ -121,7 +121,9 @@ void ClangdLSPServer::onInitialize(Initi {"renameProvider", true}, {"executeCommandProvider", json::obj{ - {"commands", {ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND}}, + {"commands", + {ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND, + ExecuteCommandParams::CLANGD_INSERT_HEADER_INCLUDE}}, }}, ); } @@ -155,6 +157,14 @@ void ClangdLSPServer::onFileEvent(DidCha } void ClangdLSPServer::onCommand(ExecuteCommandParams &Params) { + auto ApplyEdit = [](WorkspaceEdit WE) { +ApplyWorkspaceEditParams Edit; +Edit.edit = std::move(WE); +// We don't need the response so id == 1 is OK. +// Ideally, we would wait for the response and if there is no error, we +// would reply success/failure to the original RPC. +call("workspace/applyEdit", Edit); + }; if (Params.command == ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND && Params.workspaceEdit) { // The flow for "apply-fix" : @@ -166,13 +176,35 @@ void ClangdLSPServer::onCommand(ExecuteC // 6. The editor applies the changes (applyEdit), and sends us a reply (but // we ignore it) -ApplyWorkspaceEditParams ApplyEdit; -ApplyEdit.edit = *Params.workspaceEdit; reply("Fix applied."); -// We don't need the response so id == 1 is OK. -// Ideally, we would wait for the response and if there is no error, we -// would reply success/failure to the original RPC. -call("workspace/applyEdit", A
[clang-tools-extra] r325346 - [clangd] remove redundant '; ' introduced in r325343
Author: ioeric Date: Fri Feb 16 06:47:08 2018 New Revision: 325346 URL: http://llvm.org/viewvc/llvm-project?rev=325346&view=rev Log: [clangd] remove redundant ';' introduced in r325343 Modified: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp Modified: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp?rev=325346&r1=325345&r2=325346&view=diff == --- clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp (original) +++ clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp Fri Feb 16 06:47:08 2018 @@ -19,7 +19,7 @@ const char IWYUPragma[] = "// IWYU pragm void CanonicalIncludes::addMapping(llvm::StringRef Path, llvm::StringRef CanonicalPath) { addRegexMapping((llvm::Twine("^") + Path + "$").str(), CanonicalPath); -}; +} void CanonicalIncludes::addRegexMapping(llvm::StringRef RE, llvm::StringRef CanonicalPath) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D42640: [clangd] collect symbol #include & insert #include in global code completion.
Hi Carlos, did this fail on a Windows build bot? Would you mind pointing me to the broken test? Thanks! On Fri, Feb 16, 2018 at 4:23 PM Carlos Alberto Enciso via Phabricator < revi...@reviews.llvm.org> wrote: > CarlosAlbertoEnciso added a comment. > > Hi @ioeric: > > Just to let you know that your submission seems to break a Windows test. > > FAIL: Extra Tools Unit Tests :: > clangd/Checking/./ClangdTests.exe/SymbolCollectorTest.IWYUPragma (15474 of > 36599) > > Thanks > > > Repository: > rL LLVM > > https://reviews.llvm.org/D42640 > > > > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r325482 - [clangd] Try to fix build bot failure caused by r325343: escape regex string.
Author: ioeric Date: Mon Feb 19 02:45:48 2018 New Revision: 325482 URL: http://llvm.org/viewvc/llvm-project?rev=325482&view=rev Log: [clangd] Try to fix build bot failure caused by r325343: escape regex string. Modified: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp Modified: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp?rev=325482&r1=325481&r2=325482&view=diff == --- clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp (original) +++ clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp Mon Feb 19 02:45:48 2018 @@ -18,7 +18,8 @@ const char IWYUPragma[] = "// IWYU pragm void CanonicalIncludes::addMapping(llvm::StringRef Path, llvm::StringRef CanonicalPath) { - addRegexMapping((llvm::Twine("^") + Path + "$").str(), CanonicalPath); + addRegexMapping((llvm::Twine("^") + llvm::Regex::escape(Path) + "$").str(), + CanonicalPath); } void CanonicalIncludes::addRegexMapping(llvm::StringRef RE, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D42640: [clangd] collect symbol #include & insert #include in global code completion.
I've sent r325482 which (hopefully) fixes the failure. I'll keep an eye on the bot to make sure this is fixed ASAP. Sorry about the inconvenience! o Eric On Mon, Feb 19, 2018 at 11:39 AM Carlos Alberto Enciso via Phabricator < revi...@reviews.llvm.org> wrote: > CarlosAlbertoEnciso added a subscriber: aheejin. > CarlosAlbertoEnciso added a comment. > > Thanks @aheejin > > > Repository: > rL LLVM > > https://reviews.llvm.org/D42640 > > > > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r325523 - [clangd] Fixes for #include insertion.
Author: ioeric Date: Mon Feb 19 10:48:44 2018 New Revision: 325523 URL: http://llvm.org/viewvc/llvm-project?rev=325523&view=rev Log: [clangd] Fixes for #include insertion. Summary: o Avoid inserting a header include into the header itself. o Avoid inserting non-header files (by not indexing symbols in main files at all). o Canonicalize include paths for symbols in dynamic index. Reviewers: sammccall, ilya-biryukov Reviewed By: ilya-biryukov Subscribers: klimek, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D43462 Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp clang-tools-extra/trunk/clangd/Headers.cpp clang-tools-extra/trunk/clangd/Headers.h clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp clang-tools-extra/trunk/clangd/index/CanonicalIncludes.h clang-tools-extra/trunk/clangd/index/FileIndex.cpp clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=325523&r1=325522&r2=325523&view=diff == --- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Feb 19 10:48:44 2018 @@ -327,13 +327,11 @@ ClangdServer::insertInclude(PathRef File if (!Resolved) return Resolved.takeError(); -auto FS = FSProvider.getTaggedFileSystem(File).Value; tooling::CompileCommand CompileCommand = CompileArgs.getCompileCommand(File); -FS->setCurrentWorkingDirectory(CompileCommand.Directory); - auto Include = -shortenIncludePath(File, Code, *Resolved, CompileCommand, FS); +calculateIncludePath(File, Code, *Resolved, CompileCommand, + FSProvider.getTaggedFileSystem(File).Value); if (!Include) return Include.takeError(); if (Include->empty()) Modified: clang-tools-extra/trunk/clangd/Headers.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.cpp?rev=325523&r1=325522&r2=325523&view=diff == --- clang-tools-extra/trunk/clangd/Headers.cpp (original) +++ clang-tools-extra/trunk/clangd/Headers.cpp Mon Feb 19 10:48:44 2018 @@ -16,6 +16,7 @@ #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/PreprocessorOptions.h" #include "clang/Tooling/CompilationDatabase.h" +#include "llvm/Support/Path.h" namespace clang { namespace clangd { @@ -45,10 +46,17 @@ private: /// FIXME(ioeric): we might not want to insert an absolute include path if the /// path is not shortened. llvm::Expected -shortenIncludePath(llvm::StringRef File, llvm::StringRef Code, - llvm::StringRef Header, - const tooling::CompileCommand &CompileCommand, - IntrusiveRefCntPtr FS) { +calculateIncludePath(llvm::StringRef File, llvm::StringRef Code, + llvm::StringRef Header, + const tooling::CompileCommand &CompileCommand, + IntrusiveRefCntPtr FS) { + assert(llvm::sys::path::is_absolute(File) && + llvm::sys::path::is_absolute(Header)); + + if (File == Header) +return ""; + FS->setCurrentWorkingDirectory(CompileCommand.Directory); + // Set up a CompilerInstance and create a preprocessor to collect existing // #include headers in \p Code. Preprocesor also provides HeaderSearch with // which we can calculate the shortest include path for \p Header. Modified: clang-tools-extra/trunk/clangd/Headers.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.h?rev=325523&r1=325522&r2=325523&view=diff == --- clang-tools-extra/trunk/clangd/Headers.h (original) +++ clang-tools-extra/trunk/clangd/Headers.h Mon Feb 19 10:48:44 2018 @@ -18,18 +18,21 @@ namespace clang { namespace clangd { + /// Determines the preferred way to #include a file, taking into account the /// search path. Usually this will prefer a shorter representation like /// 'Foo/Bar.h' over a longer one like 'Baz/include/Foo/Bar.h'. /// +/// \param File is an absolute file path. /// \param Header is an absolute file path. -/// \return A quoted "path" or . If \p Header is already (directly) -/// included in the file (including those included via different paths), this -/// returns an empty string. +/// \return A quoted "path" or . This returns an empty string if: +/// - \p Header is already (directly) included in the file (including those +/// included via different paths). +/// - \p Header is the same as \p File. llvm::Expected -shortenIncludePath(PathRef File, llvm::Str
r325678 - [ASTMatchers] isTemplateInstantiation: also match explicit instantiation declaration.
Author: ioeric Date: Wed Feb 21 05:51:27 2018 New Revision: 325678 URL: http://llvm.org/viewvc/llvm-project?rev=325678&view=rev Log: [ASTMatchers] isTemplateInstantiation: also match explicit instantiation declaration. Summary: Example: template class X {}; class A {}; // Explicit instantiation declaration. extern template class X; Reviewers: bkramer Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D43567 Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=325678&r1=325677&r2=325678&view=diff == --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original) +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Wed Feb 21 05:51:27 2018 @@ -4649,6 +4649,10 @@ AST_MATCHER_P(UsingShadowDecl, hasTarget /// \code /// template class X {}; class A {}; template class X; /// \endcode +/// or +/// \code +/// template class X {}; class A {}; extern template class X; +/// \endcode /// cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) /// matches the template instantiation of X. /// @@ -4666,7 +4670,9 @@ AST_POLYMORPHIC_MATCHER(isTemplateInstan CXXRecordDecl)) { return (Node.getTemplateSpecializationKind() == TSK_ImplicitInstantiation || Node.getTemplateSpecializationKind() == - TSK_ExplicitInstantiationDefinition); + TSK_ExplicitInstantiationDefinition || + Node.getTemplateSpecializationKind() == + TSK_ExplicitInstantiationDeclaration); } /// \brief Matches declarations that are template instantiations or are inside Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp?rev=325678&r1=325677&r2=325678&view=diff == --- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp (original) +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Wed Feb 21 05:51:27 2018 @@ -1623,6 +1623,14 @@ TEST(IsTemplateInstantiation, MatchesExp "template class X;", cxxRecordDecl(isTemplateInstantiation(), hasDescendant( fieldDecl(hasType(recordDecl(hasName("A"; + + // Make sure that we match the instantiation instead of the template + // definition by checking whether the member function is present. + EXPECT_TRUE( + matches("template class X { void f() { T t; } };" + "extern template class X;", + cxxRecordDecl(isTemplateInstantiation(), +unless(hasDescendant(varDecl(hasName("t"))); } TEST(IsTemplateInstantiation, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r325678 - [ASTMatchers] isTemplateInstantiation: also match explicit instantiation declaration.
Oops, I only saw this after landing the patch. I'll send another one to update the doc. Sorry about that! On Wed, Feb 21, 2018 at 2:54 PM Aaron Ballman wrote: > On Wed, Feb 21, 2018 at 8:51 AM, Eric Liu via cfe-commits > wrote: > > Author: ioeric > > Date: Wed Feb 21 05:51:27 2018 > > New Revision: 325678 > > > > URL: http://llvm.org/viewvc/llvm-project?rev=325678&view=rev > > Log: > > [ASTMatchers] isTemplateInstantiation: also match explicit instantiation > declaration. > > > > Summary: > > Example: > > template class X {}; class A {}; > > // Explicit instantiation declaration. > > extern template class X; > > > > Reviewers: bkramer > > > > Subscribers: klimek, cfe-commits > > > > Differential Revision: https://reviews.llvm.org/D43567 > > > > Modified: > > cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h > > cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp > > Please regenerate the AST matcher documentation as well. > > ~Aaron > > > > > Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h > > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=325678&r1=325677&r2=325678&view=diff > > > == > > --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original) > > +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Wed Feb 21 > 05:51:27 2018 > > @@ -4649,6 +4649,10 @@ AST_MATCHER_P(UsingShadowDecl, hasTarget > > /// \code > > /// template class X {}; class A {}; template class X; > > /// \endcode > > +/// or > > +/// \code > > +/// template class X {}; class A {}; extern template > class X; > > +/// \endcode > > /// cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) > > /// matches the template instantiation of X. > > /// > > @@ -4666,7 +4670,9 @@ AST_POLYMORPHIC_MATCHER(isTemplateInstan > > CXXRecordDecl)) > { > >return (Node.getTemplateSpecializationKind() == > TSK_ImplicitInstantiation || > >Node.getTemplateSpecializationKind() == > > - TSK_ExplicitInstantiationDefinition); > > + TSK_ExplicitInstantiationDefinition || > > + Node.getTemplateSpecializationKind() == > > + TSK_ExplicitInstantiationDeclaration); > > } > > > > /// \brief Matches declarations that are template instantiations or are > inside > > > > Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp > > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp?rev=325678&r1=325677&r2=325678&view=diff > > > == > > --- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp > (original) > > +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Wed Feb > 21 05:51:27 2018 > > @@ -1623,6 +1623,14 @@ TEST(IsTemplateInstantiation, MatchesExp > >"template class X;", > > cxxRecordDecl(isTemplateInstantiation(), hasDescendant( > >fieldDecl(hasType(recordDecl(hasName("A"; > > + > > + // Make sure that we match the instantiation instead of the template > > + // definition by checking whether the member function is present. > > + EXPECT_TRUE( > > + matches("template class X { void f() { T t; } };" > > + "extern template class X;", > > + cxxRecordDecl(isTemplateInstantiation(), > > + > unless(hasDescendant(varDecl(hasName("t"))); > > } > > > > TEST(IsTemplateInstantiation, > > > > > > ___ > > cfe-commits mailing list > > cfe-commits@lists.llvm.org > > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r325682 - [ASTMatchers] Regenerate documentation after r325678
Author: ioeric Date: Wed Feb 21 06:22:42 2018 New Revision: 325682 URL: http://llvm.org/viewvc/llvm-project?rev=325682&view=rev Log: [ASTMatchers] Regenerate documentation after r325678 Modified: cfe/trunk/docs/LibASTMatchersReference.html Modified: cfe/trunk/docs/LibASTMatchersReference.html URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=325682&r1=325681&r2=325682&view=diff == --- cfe/trunk/docs/LibASTMatchersReference.html (original) +++ cfe/trunk/docs/LibASTMatchersReference.html Wed Feb 21 06:22:42 2018 @@ -2376,6 +2376,8 @@ Given templateclass X {}; class A {}; X x; or template class X {}; class A {}; template class X; +or + template class X {}; class A {}; extern template class X; cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) matches the template instantiation of X. @@ -2913,6 +2915,8 @@ Given template class X {}; class A {}; X x; or template class X {}; class A {}; template class X; +or + template class X {}; class A {}; extern template class X; cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) matches the template instantiation of X. @@ -3873,6 +3877,8 @@ Given template class X {}; class A {}; X x; or template class X {}; class A {}; template class X; +or + template class X {}; class A {}; extern template class X; cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) matches the template instantiation of X. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r325694 - [clangd] Update canonical header mapping for STL
Author: ioeric Date: Wed Feb 21 08:17:25 2018 New Revision: 325694 URL: http://llvm.org/viewvc/llvm-project?rev=325694&view=rev Log: [clangd] Update canonical header mapping for STL Modified: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp Modified: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp?rev=325694&r1=325693&r2=325694&view=diff == --- clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp (original) +++ clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp Wed Feb 21 08:17:25 2018 @@ -266,6 +266,10 @@ void addSystemHeadersMapping(CanonicalIn {"cwctype$", ""}, {"cxxabi.h$", ""}, {"debug/debug.h$", ""}, + {"debug/map.h$", ""}, + {"debug/multimap.h$", ""}, + {"debug/multiset.h$", ""}, + {"debug/set.h$", ""}, {"deque$", ""}, {"exception$", ""}, {"ext/alloc_traits.h$", ""}, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r325764 - [clangd] Not collect include headers for dynamic index for now.
Author: ioeric Date: Thu Feb 22 02:14:05 2018 New Revision: 325764 URL: http://llvm.org/viewvc/llvm-project?rev=325764&view=rev Log: [clangd] Not collect include headers for dynamic index for now. Summary: The new behaviors introduced by this patch: o When include collection is enabled, we always set IncludeHeader field in Symbol even if it's the same as FileURI in decl. o Disable include collection in FileIndex which is currently only used to build dynamic index. We should revisit when we actually want to use FileIndex to global index. o Code-completion only uses IncludeHeader to insert headers but not FileURI in CanonicalDeclaration. This ensures that inserted headers are always canonicalized. Note that include insertion can still be triggered for symbols that are already included if they are merged from dynamic index and static index, but we would only use includes that are already canonicalized (e.g. from static index). Reason for change: Collecting header includes in dynamic index enables inserting includes for headers that are not indexed but opened in the editor. Comparing to inserting includes for symbols in global/static index, this is nice-to-have but would probably require non-trivial amount of work to get right. For example: o Currently it's not easy to fully support CanonicalIncludes in dynamic index, given the way we run dynamic index. o It's also harder to reason about the correctness of include canonicalization for dynamic index (i.e. symbols in the current file/TU) than static index where symbols are collected offline and sanity check is possible before shipping to production. o We have less control/flexibility over symbol info in the dynamic index (e.g. URIs, path normalization), which could be used to help make decision when inserting includes. As header collection (especially canonicalization) is relatively new, and enabling it for dynamic index would immediately affect current users with only dynamic index support, I propose we disable it for dynamic index for now to avoid compromising other hot features like code completion and only support it for static index where include insertion would likely to bring more value. Reviewers: ilya-biryukov, sammccall, hokein Subscribers: klimek, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D43550 Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/clangd/index/FileIndex.cpp clang-tools-extra/trunk/clangd/index/Index.h clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=325764&r1=325763&r2=325764&view=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu Feb 22 02:14:05 2018 @@ -286,13 +286,9 @@ struct CompletionCandidate { I.documentation = D->Documentation; if (I.detail.empty()) I.detail = D->CompletionDetail; -// We only insert #include for items with details, since we can't tell -// whether the file URI of the canonical declaration would be the -// canonical #include without checking IncludeHeader in the detail. // FIXME: delay creating include insertion command to // "completionItem/resolve", when it is supported -if (!D->IncludeHeader.empty() || -!IndexResult->CanonicalDeclaration.FileURI.empty()) { +if (!D->IncludeHeader.empty()) { // LSP favors additionalTextEdits over command. But we are still using // command here because it would be expensive to calculate #include // insertion edits for all candidates, and the include insertion edit @@ -301,9 +297,7 @@ struct CompletionCandidate { // Command title is not added since this is not a user-facing command. Cmd.command = ExecuteCommandParams::CLANGD_INSERT_HEADER_INCLUDE; IncludeInsertion Insertion; - Insertion.header = D->IncludeHeader.empty() - ? IndexResult->CanonicalDeclaration.FileURI - : D->IncludeHeader; + Insertion.header = D->IncludeHeader; Insertion.textDocument.uri = URIForFile(FileName); Cmd.includeInsertion = std::move(Insertion); I.command = std::move(Cmd); Modified: clang-tools-extra/trunk/clangd/index/FileIndex.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.cpp?rev=325764&r1=325763&r2=325764&view=diff == --- clang-tools-extra/trunk/clangd/index/FileIndex.cp
[clang-tools-extra] r325813 - [clangd] Extend textDocument/didChange to specify whether diagnostics should be generated.
Author: ioeric Date: Thu Feb 22 10:40:39 2018 New Revision: 325813 URL: http://llvm.org/viewvc/llvm-project?rev=325813&view=rev Log: [clangd] Extend textDocument/didChange to specify whether diagnostics should be generated. Summary: This would allow us to disable diagnostics when didChange is called but diagnostics are not wanted (e.g. code completion). Reviewers: sammccall Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D43634 Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp clang-tools-extra/trunk/clangd/Protocol.cpp clang-tools-extra/trunk/clangd/Protocol.h Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=325813&r1=325812&r2=325813&view=diff == --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Thu Feb 22 10:40:39 2018 @@ -149,9 +149,13 @@ void ClangdLSPServer::onDocumentDidChang if (Params.contentChanges.size() != 1) return replyError(ErrorCode::InvalidParams, "can only apply one change at a time"); + auto WantDiags = WantDiagnostics::Auto; + if (Params.wantDiagnostics.hasValue()) +WantDiags = Params.wantDiagnostics.getValue() ? WantDiagnostics::Yes + : WantDiagnostics::No; // We only support full syncing right now. Server.addDocument(Params.textDocument.uri.file(), - Params.contentChanges[0].text, WantDiagnostics::Auto); + Params.contentChanges[0].text, WantDiags); } void ClangdLSPServer::onFileEvent(DidChangeWatchedFilesParams &Params) { Modified: clang-tools-extra/trunk/clangd/Protocol.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=325813&r1=325812&r2=325813&view=diff == --- clang-tools-extra/trunk/clangd/Protocol.cpp (original) +++ clang-tools-extra/trunk/clangd/Protocol.cpp Thu Feb 22 10:40:39 2018 @@ -221,7 +221,8 @@ bool fromJSON(const json::Expr &Params, bool fromJSON(const json::Expr &Params, DidChangeTextDocumentParams &R) { json::ObjectMapper O(Params); return O && O.map("textDocument", R.textDocument) && - O.map("contentChanges", R.contentChanges); + O.map("contentChanges", R.contentChanges) && + O.map("wantDiagnostics", R.wantDiagnostics); } bool fromJSON(const json::Expr &E, FileChangeType &Out) { Modified: clang-tools-extra/trunk/clangd/Protocol.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=325813&r1=325812&r2=325813&view=diff == --- clang-tools-extra/trunk/clangd/Protocol.h (original) +++ clang-tools-extra/trunk/clangd/Protocol.h Thu Feb 22 10:40:39 2018 @@ -297,6 +297,12 @@ struct DidChangeTextDocumentParams { /// The actual content changes. std::vector contentChanges; + + /// Forces diagnostics to be generated, or to not be generated, for this + /// version of the file. If not set, diagnostics are eventually consistent: + /// either they will be provided for this version or some subsequent one. + /// This is a clangd extension. + llvm::Optional wantDiagnostics; }; bool fromJSON(const json::Expr &, DidChangeTextDocumentParams &); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r326070 - [clangd] don't insert new includes if either original header or canonical header is already included.
Author: ioeric Date: Mon Feb 26 00:32:13 2018 New Revision: 326070 URL: http://llvm.org/viewvc/llvm-project?rev=326070&view=rev Log: [clangd] don't insert new includes if either original header or canonical header is already included. Summary: Changes: o Store both the original header and the canonical header in LSP command. o Also check that both original and canonical headers are not already included by comparing both resolved header path and written literal includes. This addresses the use case where private IWYU pragma is defined in a private header while it would still be preferrable to include the private header, in the internal implementation file. If we have seen that the priviate header is already included, we don't try to insert the canonical include. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D43510 Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp clang-tools-extra/trunk/clangd/ClangdServer.cpp clang-tools-extra/trunk/clangd/ClangdServer.h clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/clangd/Headers.cpp clang-tools-extra/trunk/clangd/Headers.h clang-tools-extra/trunk/clangd/Protocol.cpp clang-tools-extra/trunk/clangd/Protocol.h clang-tools-extra/trunk/test/clangd/insert-include.test clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=326070&r1=326069&r2=326070&view=diff == --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Mon Feb 26 00:32:13 2018 @@ -194,12 +194,20 @@ void ClangdLSPServer::onCommand(ExecuteC ExecuteCommandParams::CLANGD_INSERT_HEADER_INCLUDE + " called on non-added file " + FileURI.file()) .str()); -auto Replaces = Server.insertInclude(FileURI.file(), *Code, - Params.includeInsertion->header); +llvm::StringRef DeclaringHeader = Params.includeInsertion->declaringHeader; +if (DeclaringHeader.empty()) + return replyError( + ErrorCode::InvalidParams, + "declaringHeader must be provided for include insertion."); +llvm::StringRef PreferredHeader = Params.includeInsertion->preferredHeader; +auto Replaces = Server.insertInclude( +FileURI.file(), *Code, DeclaringHeader, +PreferredHeader.empty() ? DeclaringHeader : PreferredHeader); if (!Replaces) { std::string ErrMsg = ("Failed to generate include insertion edits for adding " + - Params.includeInsertion->header + " into " + FileURI.file()) + DeclaringHeader + " (" + PreferredHeader + ") into " + + FileURI.file()) .str(); log(ErrMsg + ":" + llvm::toString(Replaces.takeError())); replyError(ErrorCode::InternalError, ErrMsg); @@ -209,7 +217,8 @@ void ClangdLSPServer::onCommand(ExecuteC WorkspaceEdit WE; WE.changes = {{FileURI.uri(), Edits}}; -reply("Inserted header " + Params.includeInsertion->header); +reply(("Inserted header " + DeclaringHeader + " (" + PreferredHeader + ")") + .str()); ApplyEdit(std::move(WE)); } else { // We should not get here because ExecuteCommandParams would not have Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=326070&r1=326069&r2=326070&view=diff == --- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Feb 26 00:32:13 2018 @@ -313,31 +313,42 @@ void ClangdServer::rename( Bind(Action, File.str(), NewName.str(), std::move(Callback))); } +/// Creates a `HeaderFile` from \p Header which can be either a URI or a literal +/// include. +static llvm::Expected toHeaderFile(StringRef Header, + llvm::StringRef HintPath) { + if (isLiteralInclude(Header)) +return HeaderFile{Header.str(), /*Verbatim=*/true}; + auto U = URI::parse(Header); + if (!U) +return U.takeError(); + auto Resolved = URI::resolve(*U, HintPath); + if (!Resolved) +return Resolved.takeError(); + return HeaderFile{std::move(*Resolved), /*Verbatim=*/false}; +}; + Expected ClangdServer::insertInclude(PathRef File, StringRef Code, -llvm::StringRef Header) { +StringRef DeclaringHeader, +StringRef In
[clang-tools-extra] r320688 - [clangd] Symbol index interfaces and an in-memory index implementation.
Author: ioeric Date: Thu Dec 14 03:25:49 2017 New Revision: 320688 URL: http://llvm.org/viewvc/llvm-project?rev=320688&view=rev Log: [clangd] Symbol index interfaces and an in-memory index implementation. Summary: o Index interfaces to support using different index sources (e.g. AST index, global index) for code completion, cross-reference finding etc. This patch focuses on code completion. The following changes in the original patch has been split out. o Implement an AST-based index. o Add an option to replace sema code completion for qualified-id with index-based completion. o Implement an initial naive code completion index which matches symbols that have the query string as substring. Reviewers: malaperle, sammccall Reviewed By: sammccall Subscribers: hokein, klimek, malaperle, mgorny, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D40548 Added: clang-tools-extra/trunk/clangd/index/MemIndex.cpp clang-tools-extra/trunk/clangd/index/MemIndex.h clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt clang-tools-extra/trunk/clangd/index/Index.h clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=320688&r1=320687&r2=320688&view=diff == --- clang-tools-extra/trunk/clangd/CMakeLists.txt (original) +++ clang-tools-extra/trunk/clangd/CMakeLists.txt Thu Dec 14 03:25:49 2017 @@ -19,6 +19,7 @@ add_clang_library(clangDaemon Protocol.cpp ProtocolHandlers.cpp Trace.cpp + index/MemIndex.cpp index/Index.cpp index/SymbolCollector.cpp Modified: clang-tools-extra/trunk/clangd/index/Index.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=320688&r1=320687&r2=320688&view=diff == --- clang-tools-extra/trunk/clangd/index/Index.h (original) +++ clang-tools-extra/trunk/clangd/index/Index.h Thu Dec 14 03:25:49 2017 @@ -10,6 +10,7 @@ #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H +#include "../Context.h" #include "clang/Index/IndexSymbol.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/Hashing.h" @@ -110,6 +111,34 @@ private: llvm::DenseMap Symbols; }; +struct FuzzyFindRequest { + /// \brief A query string for the fuzzy find. This is matched against symbols' + /// qualfified names. + std::string Query; + /// \brief The maxinum number of candidates to return. + size_t MaxCandidateCount = UINT_MAX; +}; + +/// \brief Interface for symbol indexes that can be used for searching or +/// matching symbols among a set of symbols based on names or unique IDs. +class SymbolIndex { +public: + virtual ~SymbolIndex() = default; + + /// \brief Matches symbols in the index fuzzily and applies \p Callback on + /// each matched symbol before returning. + /// + /// Returns true if the result list is complete, false if it was truncated due + /// to MaxCandidateCount + virtual bool + fuzzyFind(Context &Ctx, const FuzzyFindRequest &Req, +std::function Callback) const = 0; + + // FIXME: add interfaces for more index use cases: + // - Symbol getSymbolInfo(SymbolID); + // - getAllOccurrences(SymbolID); +}; + } // namespace clangd } // namespace clang Added: clang-tools-extra/trunk/clangd/index/MemIndex.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/MemIndex.cpp?rev=320688&view=auto == --- clang-tools-extra/trunk/clangd/index/MemIndex.cpp (added) +++ clang-tools-extra/trunk/clangd/index/MemIndex.cpp Thu Dec 14 03:25:49 2017 @@ -0,0 +1,52 @@ +//===--- MemIndex.cpp - Dynamic in-memory symbol index. --*- C++-*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===---===// + +#include "MemIndex.h" + +namespace clang { +namespace clangd { + +void MemIndex::build(std::shared_ptr> Syms) { + llvm::DenseMap TempIndex; + for (const Symbol *Sym : *Syms) +TempIndex[Sym->ID] = Sym; + + // Swap out the old symbols and index. + { +std::lock_guard Lock(Mutex); +Index = std::move(TempIndex); +Symbols = std::move(Syms); // Relase old symbols. + } +} + +bool MemIndex::fuzzyFind(Context & /*Ctx*/, const FuzzyFindRequest &Req, + std::function Callback) const { + std::string LoweredQuery = llvm::StringRef(Req.Query).lower(); + unsigned Matched = 0; + { +std::lock_guard Lock(Mutex); +for (const auto Pair : Index) {
[clang-tools-extra] r320695 - [clangd] Fix a potential use-after-move bug.
Author: ioeric Date: Thu Dec 14 04:31:04 2017 New Revision: 320695 URL: http://llvm.org/viewvc/llvm-project?rev=320695&view=rev Log: [clangd] Fix a potential use-after-move bug. Modified: clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp Modified: clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp?rev=320695&r1=320694&r2=320695&view=diff == --- clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp Thu Dec 14 04:31:04 2017 @@ -48,7 +48,8 @@ generateNumSymbols(int Begin, int End, for (const auto &Sym : Slab->Slab) Slab->Pointers.push_back(&Sym.second); - return {std::move(Slab), &Slab->Pointers}; + auto *Pointers = &Slab->Pointers; + return {std::move(Slab), Pointers}; } std::vector match(const SymbolIndex &I, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r320701 - [clangd] Add a FileSymbols container that manages symbols from multiple files.
Author: ioeric Date: Thu Dec 14 06:50:58 2017 New Revision: 320701 URL: http://llvm.org/viewvc/llvm-project?rev=320701&view=rev Log: [clangd] Add a FileSymbols container that manages symbols from multiple files. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, mgorny, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D41232 Added: clang-tools-extra/trunk/clangd/index/FileSymbols.cpp clang-tools-extra/trunk/clangd/index/FileSymbols.h clang-tools-extra/trunk/unittests/clangd/FileSymbolsTests.cpp Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=320701&r1=320700&r2=320701&view=diff == --- clang-tools-extra/trunk/clangd/CMakeLists.txt (original) +++ clang-tools-extra/trunk/clangd/CMakeLists.txt Thu Dec 14 06:50:58 2017 @@ -19,8 +19,9 @@ add_clang_library(clangDaemon Protocol.cpp ProtocolHandlers.cpp Trace.cpp - index/MemIndex.cpp + index/FileSymbols.cpp index/Index.cpp + index/MemIndex.cpp index/SymbolCollector.cpp index/SymbolYAML.cpp Added: clang-tools-extra/trunk/clangd/index/FileSymbols.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileSymbols.cpp?rev=320701&view=auto == --- clang-tools-extra/trunk/clangd/index/FileSymbols.cpp (added) +++ clang-tools-extra/trunk/clangd/index/FileSymbols.cpp Thu Dec 14 06:50:58 2017 @@ -0,0 +1,48 @@ +//===--- FileSymbols.cpp - Symbols from files. --*- C++-*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "FileSymbols.h" +#include "clang/Index/IndexingAction.h" + +namespace clang { +namespace clangd { + +void FileSymbols::update(PathRef Path, std::unique_ptr Slab) { + std::lock_guard Lock(Mutex); + if (!Slab) +FileToSlabs.erase(Path); + else +FileToSlabs[Path] = std::shared_ptr(Slab.release()); +} + +std::shared_ptr> FileSymbols::allSymbols() { + // The snapshot manages life time of symbol slabs and provides pointers of all + // symbols in all slabs. + struct Snapshot { +std::vector Pointers; +std::vector> KeepAlive; + }; + auto Snap = std::make_shared(); + { +std::lock_guard Lock(Mutex); + +for (const auto &FileAndSlab : FileToSlabs) { + Snap->KeepAlive.push_back(FileAndSlab.second); + for (const auto &Iter : *FileAndSlab.second) +Snap->Pointers.push_back(&Iter.second); +} + } + auto *Pointers = &Snap->Pointers; + // Use aliasing constructor to keep the snapshot alive along with the + // pointers. + return {std::move(Snap), Pointers}; +} + +} // namespace clangd +} // namespace clang Added: clang-tools-extra/trunk/clangd/index/FileSymbols.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileSymbols.h?rev=320701&view=auto == --- clang-tools-extra/trunk/clangd/index/FileSymbols.h (added) +++ clang-tools-extra/trunk/clangd/index/FileSymbols.h Thu Dec 14 06:50:58 2017 @@ -0,0 +1,53 @@ +//===--- FileSymbols.h - Symbols from files. -*- C++-*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_FILESYMBOLS_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_FILESYMBOLS_H + +#include "../Path.h" +#include "Index.h" +#include "llvm/ADT/StringMap.h" +#include + +namespace clang { +namespace clangd { + +/// \brief A container of Symbols from several source files. It can be updated +/// at source-file granularity, replacing all symbols from one file with a new +/// set. +/// +/// This implements a snapshot semantics for symbols in a file. Each update to a +/// file will create a new snapshot for all symbols in the file. Snapshots are +/// managed with shared pointers that are shared between this class and the +/// users. For each file, this class only stores a pointer pointing to the +/// newest snapshot, and an outdated snapshot is deleted by the last owner of +/// the snapshot, either this class or the symbol index. +/// +/// The snapshot semantics keeps critical sections minimal since we only need +/// locking when we swap or obtain refereces to snapshots. +class FileSymbols { +public: + /// \brief Update