[clang-tools-extra] r358496 - [clangd] Check file path of declaring header when deciding whether to insert include.
Author: ioeric Date: Tue Apr 16 07:35:49 2019 New Revision: 358496 URL: http://llvm.org/viewvc/llvm-project?rev=358496=rev Log: [clangd] Check file path of declaring header when deciding whether to insert include. Summary: Previously, we would use include spelling of the declaring header to check whether the inserted header is the same as the main file. This doesn't help because we only have file path of the main file. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60687 Modified: 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/IncludeFixer.cpp clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=358496=358495=358496=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Tue Apr 16 07:35:49 2019 @@ -349,15 +349,18 @@ struct CodeCompletionBuilder { // Turn absolute path into a literal string that can be #included. auto Inserted = [&](llvm::StringRef Header) -> llvm::Expected> { - auto ResolvedDeclaring = - toHeaderFile(C.IndexResult->CanonicalDeclaration.FileURI, FileName); + auto DeclaringURI = + URI::parse(C.IndexResult->CanonicalDeclaration.FileURI); + if (!DeclaringURI) +return DeclaringURI.takeError(); + auto ResolvedDeclaring = URI::resolve(*DeclaringURI, FileName); if (!ResolvedDeclaring) return ResolvedDeclaring.takeError(); auto ResolvedInserted = toHeaderFile(Header, FileName); if (!ResolvedInserted) return ResolvedInserted.takeError(); return std::make_pair( - Includes.calculateIncludePath(*ResolvedDeclaring, *ResolvedInserted), + Includes.calculateIncludePath(*ResolvedInserted), Includes.shouldInsertInclude(*ResolvedDeclaring, *ResolvedInserted)); }; bool ShouldInsert = C.headerToInsertIfAllowed(Opts).hasValue(); Modified: clang-tools-extra/trunk/clangd/Headers.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.cpp?rev=358496=358495=358496=diff == --- clang-tools-extra/trunk/clangd/Headers.cpp (original) +++ clang-tools-extra/trunk/clangd/Headers.cpp Tue Apr 16 07:35:49 2019 @@ -173,22 +173,21 @@ void IncludeInserter::addExisting(const /// FIXME(ioeric): we might not want to insert an absolute include path if the /// path is not shortened. bool IncludeInserter::shouldInsertInclude( -const HeaderFile , const HeaderFile ) const { - assert(DeclaringHeader.valid() && InsertedHeader.valid()); +PathRef DeclaringHeader, const HeaderFile ) const { + assert(InsertedHeader.valid()); if (!HeaderSearchInfo && !InsertedHeader.Verbatim) return false; - if (FileName == DeclaringHeader.File || FileName == InsertedHeader.File) + if (FileName == DeclaringHeader || FileName == InsertedHeader.File) return false; auto Included = [&](llvm::StringRef Header) { return IncludedHeaders.find(Header) != IncludedHeaders.end(); }; - return !Included(DeclaringHeader.File) && !Included(InsertedHeader.File); + return !Included(DeclaringHeader) && !Included(InsertedHeader.File); } std::string -IncludeInserter::calculateIncludePath(const HeaderFile , - const HeaderFile ) const { - assert(DeclaringHeader.valid() && InsertedHeader.valid()); +IncludeInserter::calculateIncludePath(const HeaderFile ) const { + assert(InsertedHeader.valid()); if (InsertedHeader.Verbatim) return InsertedHeader.File; bool IsSystem = false; Modified: clang-tools-extra/trunk/clangd/Headers.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.h?rev=358496=358495=358496=diff == --- clang-tools-extra/trunk/clangd/Headers.h (original) +++ clang-tools-extra/trunk/clangd/Headers.h Tue Apr 16 07:35:49 2019 @@ -137,25 +137,22 @@ public: /// in \p Inclusions (including those included via different paths). /// - \p DeclaringHeader or \p InsertedHeader is the same as \p File. /// - /// \param DeclaringHeader is the original header corresponding to \p + /// \param DeclaringHeader is path of the original header corresponding to \p /// InsertedHeader e.g. the header that declares a symbol. /// \param InsertedHeader The preferred header to be inserted. This could be /// the same as DeclaringHeader but must be provided. - bool
[clang-tools-extra] r358400 - [clangd] Wait for compile command in ASTWorker instead of ClangdServer
Author: ioeric Date: Mon Apr 15 05:32:28 2019 New Revision: 358400 URL: http://llvm.org/viewvc/llvm-project?rev=358400=rev Log: [clangd] Wait for compile command in ASTWorker instead of ClangdServer Summary: This makes addDocument non-blocking and would also allow code completion (in fallback mode) to run when worker waits for the compile command. Reviewers: sammccall, ilya-biryukov Reviewed By: ilya-biryukov Subscribers: javed.absar, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60607 Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp clang-tools-extra/trunk/clangd/ClangdServer.h clang-tools-extra/trunk/clangd/Compiler.h clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp clang-tools-extra/trunk/clangd/TUScheduler.cpp clang-tools-extra/trunk/clangd/TUScheduler.h clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=358400=358399=358400=diff == --- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Apr 15 05:32:28 2019 @@ -109,7 +109,7 @@ ClangdServer::ClangdServer(const GlobalC const FileSystemProvider , DiagnosticsConsumer , const Options ) -: CDB(CDB), FSProvider(FSProvider), +: FSProvider(FSProvider), DynamicIdx(Opts.BuildDynamicSymbolIndex ? new FileIndex(Opts.HeavyweightDynamicSymbolIndex) : nullptr), @@ -121,7 +121,7 @@ ClangdServer::ClangdServer(const GlobalC // is parsed. // FIXME(ioeric): this can be slow and we may be able to index on less // critical paths. - WorkScheduler(Opts.AsyncThreadsCount, Opts.StorePreamblesInMemory, + WorkScheduler(CDB, Opts.AsyncThreadsCount, Opts.StorePreamblesInMemory, llvm::make_unique(DynamicIdx.get(), DiagConsumer), Opts.UpdateDebounce, Opts.RetentionPolicy) { @@ -155,12 +155,8 @@ void ClangdServer::addDocument(PathRef F Opts.ClangTidyOpts = ClangTidyOptProvider->getOptions(File); Opts.SuggestMissingIncludes = SuggestMissingIncludes; - // FIXME: some build systems like Bazel will take time to preparing - // environment to build the file, it would be nice if we could emit a - // "PreparingBuild" status to inform users, it is non-trivial given the - // current implementation. + // Compile command is set asynchronously during update, as it can be slow. ParseInputs Inputs; - Inputs.CompileCommand = getCompileCommand(File); Inputs.FS = FSProvider.getFileSystem(); Inputs.Contents = Contents; Inputs.Opts = std::move(Opts); @@ -543,14 +539,6 @@ void ClangdServer::typeHierarchy(PathRef WorkScheduler.runWithAST("Type Hierarchy", File, Bind(Action, std::move(CB))); } -tooling::CompileCommand ClangdServer::getCompileCommand(PathRef File) { - trace::Span Span("GetCompileCommand"); - llvm::Optional C = CDB.getCompileCommand(File); - if (!C) // FIXME: Suppress diagnostics? Let the user know? -C = CDB.getFallbackCommand(File); - return std::move(*C); -} - void ClangdServer::onFileEvent(const DidChangeWatchedFilesParams ) { // FIXME: Do nothing for now. This will be used for indexing and potentially // invalidating other caches. Modified: clang-tools-extra/trunk/clangd/ClangdServer.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=358400=358399=358400=diff == --- clang-tools-extra/trunk/clangd/ClangdServer.h (original) +++ clang-tools-extra/trunk/clangd/ClangdServer.h Mon Apr 15 05:32:28 2019 @@ -266,9 +266,6 @@ private: formatCode(llvm::StringRef Code, PathRef File, ArrayRef Ranges); - tooling::CompileCommand getCompileCommand(PathRef File); - - const GlobalCompilationDatabase const FileSystemProvider Path ResourceDir; Modified: clang-tools-extra/trunk/clangd/Compiler.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Compiler.h?rev=358400=358399=358400=diff == --- clang-tools-extra/trunk/clangd/Compiler.h (original) +++ clang-tools-extra/trunk/clangd/Compiler.h Mon Apr 15 05:32:28 2019 @@ -16,9 +16,9 @@ #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H #include "../clang-tidy/ClangTidyOptions.h" +#include "GlobalCompilationDatabase.h" #include "index/Index.h"
r358378 - [Lookup] Invisible decls should not be ambiguous when renaming.
Author: ioeric Date: Mon Apr 15 01:46:34 2019 New Revision: 358378 URL: http://llvm.org/viewvc/llvm-project?rev=358378=rev Log: [Lookup] Invisible decls should not be ambiguous when renaming. Summary: For example, a renamed type in a header file can conflict with declaration in a random file that includes the header, but we should not consider the decl ambiguous if it's not visible at the rename location. This improves consistency of generated replacements when header file is included in different TUs. Reviewers: hokein Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60257 Modified: cfe/trunk/include/clang/Tooling/Core/Lookup.h cfe/trunk/lib/Tooling/Core/Lookup.cpp cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp cfe/trunk/unittests/Tooling/LookupTest.cpp Modified: cfe/trunk/include/clang/Tooling/Core/Lookup.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Core/Lookup.h?rev=358378=358377=358378=diff == --- cfe/trunk/include/clang/Tooling/Core/Lookup.h (original) +++ cfe/trunk/include/clang/Tooling/Core/Lookup.h Mon Apr 15 01:46:34 2019 @@ -14,6 +14,7 @@ #define LLVM_CLANG_TOOLING_CORE_LOOKUP_H #include "clang/Basic/LLVM.h" +#include "clang/Basic/SourceLocation.h" #include namespace clang { @@ -30,6 +31,7 @@ namespace tooling { /// This does not perform a full C++ lookup so ADL will not work. /// /// \param Use The nested name to be replaced. +/// \param UseLoc The location of name to be replaced. /// \param UseContext The context in which the nested name is contained. This /// will be used to minimize namespace qualifications. /// \param FromDecl The declaration to which the nested name points. @@ -37,6 +39,7 @@ namespace tooling { /// qualified including a leading "::". /// \returns The new name to be inserted in place of the current nested name. std::string replaceNestedName(const NestedNameSpecifier *Use, + SourceLocation UseLoc, const DeclContext *UseContext, const NamedDecl *FromDecl, StringRef ReplacementString); Modified: cfe/trunk/lib/Tooling/Core/Lookup.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Core/Lookup.cpp?rev=358378=358377=358378=diff == --- cfe/trunk/lib/Tooling/Core/Lookup.cpp (original) +++ cfe/trunk/lib/Tooling/Core/Lookup.cpp Mon Apr 15 01:46:34 2019 @@ -14,6 +14,7 @@ #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclarationName.h" +#include "clang/Basic/SourceLocation.h" #include "llvm/ADT/SmallVector.h" using namespace clang; using namespace clang::tooling; @@ -123,7 +124,8 @@ static bool isFullyQualified(const Neste // FIXME: consider using namespaces. static std::string disambiguateSpellingInScope(StringRef Spelling, StringRef QName, - const DeclContext ) { + const DeclContext , + SourceLocation UseLoc) { assert(QName.startswith("::")); assert(QName.endswith(Spelling)); if (Spelling.startswith("::")) @@ -138,9 +140,10 @@ static std::string disambiguateSpellingI getAllNamedNamespaces(); auto = UseContext.getParentASTContext(); StringRef TrimmedQName = QName.substr(2); + const auto = UseContext.getParentASTContext().getSourceManager(); + UseLoc = SM.getSpellingLoc(UseLoc); - auto IsAmbiguousSpelling = [, , ]( - const llvm::StringRef CurSpelling) { + auto IsAmbiguousSpelling = [&](const llvm::StringRef CurSpelling) { if (CurSpelling.startswith("::")) return false; // Lookup the first component of Spelling in all enclosing namespaces @@ -151,7 +154,13 @@ static std::string disambiguateSpellingI auto LookupRes = NS->lookup(DeclarationName((Head))); if (!LookupRes.empty()) { for (const NamedDecl *Res : LookupRes) - if (!TrimmedQName.startswith(Res->getQualifiedNameAsString())) + // If `Res` is not visible in `UseLoc`, we don't consider it + // ambiguous. For example, a reference in a header file should not be + // affected by a potentially ambiguous name in some file that includes + // the header. + if (!TrimmedQName.startswith(Res->getQualifiedNameAsString()) && + SM.isBeforeInTranslationUnit( + SM.getSpellingLoc(Res->getLocation()), UseLoc)) return true; } } @@ -172,6 +181,7 @@ static std::string disambiguateSpellingI } std::string tooling::replaceNestedName(const NestedNameSpecifier *Use, +
[clang-tools-extra] r358159 - [clangd] Use identifiers in file as completion candidates when build is not ready.
Author: ioeric Date: Thu Apr 11 02:36:36 2019 New Revision: 358159 URL: http://llvm.org/viewvc/llvm-project?rev=358159=rev Log: [clangd] Use identifiers in file as completion candidates when build is not ready. Summary: o Lex the code to get the identifiers and put them into a "symbol" index. o Adds a new completion mode without compilation/sema into code completion workflow. o Make IncludeInserter work even when no compile command is present, by avoiding inserting non-verbatim headers. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60126 Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp clang-tools-extra/trunk/clangd/ClangdUnit.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/SourceCode.cpp clang-tools-extra/trunk/clangd/SourceCode.h clang-tools-extra/trunk/clangd/index/SymbolOrigin.cpp clang-tools-extra/trunk/clangd/index/SymbolOrigin.h clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp clang-tools-extra/trunk/unittests/clangd/SourceCodeTests.cpp Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=358159=358158=358159=diff == --- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Thu Apr 11 02:36:36 2019 @@ -23,7 +23,6 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/CompilerInvocation.h" #include "clang/Lex/Preprocessor.h" -#include "clang/Sema/CodeCompleteConsumer.h" #include "clang/Tooling/CompilationDatabase.h" #include "clang/Tooling/Core/Replacement.h" #include "clang/Tooling/Refactoring/RefactoringResultConsumer.h" @@ -187,28 +186,23 @@ void ClangdServer::codeComplete(PathRef return CB(IP.takeError()); if (isCancelled()) return CB(llvm::make_error()); -if (!IP->Preamble) { - vlog("File {0} is not ready for code completion. Enter fallback mode.", - File); - CodeCompleteResult CCR; - CCR.Context = CodeCompletionContext::CCC_Recovery; - - // FIXME: perform simple completion e.g. using identifiers in the current - // file and symbols in the index. - // FIXME: let clients know that we've entered fallback mode. - - return CB(std::move(CCR)); -} llvm::Optional SpecFuzzyFind; -if (CodeCompleteOpts.Index && CodeCompleteOpts.SpeculativeIndexRequest) { - SpecFuzzyFind.emplace(); - { -std::lock_guard Lock(CachedCompletionFuzzyFindRequestMutex); -SpecFuzzyFind->CachedReq = CachedCompletionFuzzyFindRequestByFile[File]; +if (!IP->Preamble) { + // No speculation in Fallback mode, as it's supposed to be much faster + // without compiling. + vlog("Build for file {0} is not ready. Enter fallback mode.", File); +} else { + 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( Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=358159=358158=358159=diff == --- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Thu Apr 11 02:36:36 2019 @@ -311,7 +311,7 @@ ParsedAST::build(std::unique_ptr( MainInput.getFile(), Content, Style, BuildDir.get(), -Clang->getPreprocessor().getHeaderSearchInfo()); +>getPreprocessor().getHeaderSearchInfo()); if (Preamble) { for (const auto : Preamble->Includes.MainFileIncludes) Inserter->addExisting(Inc); Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=358159=358158=358159=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++
[clang-tools-extra] r357916 - [clangd] Add fallback mode for code completion when compile command or preamble is not ready.
Author: ioeric Date: Mon Apr 8 07:53:16 2019 New Revision: 357916 URL: http://llvm.org/viewvc/llvm-project?rev=357916=rev Log: [clangd] Add fallback mode for code completion when compile command or preamble is not ready. Summary: When calling TUScehduler::runWithPreamble (e.g. in code compleiton), allow entering a fallback mode when compile command or preamble is not ready, instead of waiting. This allows clangd to perform naive code completion e.g. using identifiers in the current file or symbols in the index. This patch simply returns empty result for code completion in fallback mode. Identifier-based plus more advanced index-based completion will be added in followup patches. Reviewers: ilya-biryukov, sammccall Reviewed By: sammccall Subscribers: sammccall, javed.absar, MaskRay, jkorous, arphaman, kadircet, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59811 Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp clang-tools-extra/trunk/clangd/CodeComplete.h clang-tools-extra/trunk/clangd/TUScheduler.cpp clang-tools-extra/trunk/clangd/TUScheduler.h clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=357916=357915=357916=diff == --- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Apr 8 07:53:16 2019 @@ -11,7 +11,9 @@ #include "CodeComplete.h" #include "FindSymbols.h" #include "Headers.h" +#include "Protocol.h" #include "SourceCode.h" +#include "TUScheduler.h" #include "Trace.h" #include "index/CanonicalIncludes.h" #include "index/FileIndex.h" @@ -21,6 +23,7 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/CompilerInvocation.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Sema/CodeCompleteConsumer.h" #include "clang/Tooling/CompilationDatabase.h" #include "clang/Tooling/Core/Replacement.h" #include "clang/Tooling/Refactoring/RefactoringResultConsumer.h" @@ -152,6 +155,7 @@ void ClangdServer::addDocument(PathRef F if (ClangTidyOptProvider) Opts.ClangTidyOpts = ClangTidyOptProvider->getOptions(File); Opts.SuggestMissingIncludes = SuggestMissingIncludes; + // FIXME: some build systems like Bazel will take time to preparing // environment to build the file, it would be nice if we could emit a // "PreparingBuild" status to inform users, it is non-trivial given the @@ -183,6 +187,18 @@ void ClangdServer::codeComplete(PathRef return CB(IP.takeError()); if (isCancelled()) return CB(llvm::make_error()); +if (!IP->Preamble) { + vlog("File {0} is not ready for code completion. Enter fallback mode.", + File); + CodeCompleteResult CCR; + CCR.Context = CodeCompletionContext::CCC_Recovery; + + // FIXME: perform simple completion e.g. using identifiers in the current + // file and symbols in the index. + // FIXME: let clients know that we've entered fallback mode. + + return CB(std::move(CCR)); +} llvm::Optional SpecFuzzyFind; if (CodeCompleteOpts.Index && CodeCompleteOpts.SpeculativeIndexRequest) { @@ -214,7 +230,9 @@ void ClangdServer::codeComplete(PathRef }; // We use a potentially-stale preamble because latency is critical here. - WorkScheduler.runWithPreamble("CodeComplete", File, TUScheduler::Stale, + WorkScheduler.runWithPreamble("CodeComplete", File, +Opts.AllowFallback ? TUScheduler::StaleOrAbsent + : TUScheduler::Stale, Bind(Task, File.str(), std::move(CB))); } Modified: clang-tools-extra/trunk/clangd/CodeComplete.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.h?rev=357916=357915=357916=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.h (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.h Mon Apr 8 07:53:16 2019 @@ -109,6 +109,12 @@ struct CodeCompleteOptions { /// /// Such completions can insert scope qualifiers. bool AllScopes = false; + + /// Whether to allow falling back to code completion without compiling files + /// (using identifiers in the current file and symbol indexes), when file + /// cannot be built (e.g. missing compile command), or the build is not ready + /// (e.g. preamble is still being built). + bool AllowFallback = false; }; // Semi-structured representation of a code-complete suggestion for our C++ API. Modified: clang-tools-extra/trunk/clangd/TUScheduler.cpp URL:
r357567 - [clang-format] Regroup #includes into blocks for Google style
Author: ioeric Date: Wed Apr 3 02:25:16 2019 New Revision: 357567 URL: http://llvm.org/viewvc/llvm-project?rev=357567=rev Log: [clang-format] Regroup #includes into blocks for Google style Summary: Regrouping #includes in blocks separated by blank lines when sorting C++ #include headers was implemented recently, and it has been preferred in Google's C++ style guide: https://google.github.io/styleguide/cppguide.html#Names_and_Order_of_Includes Reviewers: sammccall, klimek Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60116 Modified: cfe/trunk/lib/Format/Format.cpp cfe/trunk/unittests/Format/CleanupTest.cpp cfe/trunk/unittests/Format/SortIncludesTest.cpp Modified: cfe/trunk/lib/Format/Format.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=357567=357566=357567=diff == --- cfe/trunk/lib/Format/Format.cpp (original) +++ cfe/trunk/lib/Format/Format.cpp Wed Apr 3 02:25:16 2019 @@ -784,6 +784,7 @@ FormatStyle getGoogleStyle(FormatStyle:: GoogleStyle.IncludeStyle.IncludeCategories = { {"^", 2}, {"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}}; GoogleStyle.IncludeStyle.IncludeIsMainRegex = "([-_](test|unittest))?$"; + GoogleStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; GoogleStyle.IndentCaseLabels = true; GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false; GoogleStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Never; Modified: cfe/trunk/unittests/Format/CleanupTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/CleanupTest.cpp?rev=357567=357566=357567=diff == --- cfe/trunk/unittests/Format/CleanupTest.cpp (original) +++ cfe/trunk/unittests/Format/CleanupTest.cpp Wed Apr 3 02:25:16 2019 @@ -420,8 +420,10 @@ TEST_F(CleanUpReplacementsTest, InsertMu TEST_F(CleanUpReplacementsTest, InsertMultipleNewHeadersAndSortGoogle) { std::string Code = "\nint x;"; std::string Expected = "\n#include \"fix.h\"\n" + "\n" "#include \n" "#include \n" + "\n" "#include \"a.h\"\n" "#include \"b.h\"\n" "#include \"c.h\"\n" Modified: cfe/trunk/unittests/Format/SortIncludesTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/SortIncludesTest.cpp?rev=357567=357566=357567=diff == --- cfe/trunk/unittests/Format/SortIncludesTest.cpp (original) +++ cfe/trunk/unittests/Format/SortIncludesTest.cpp Wed Apr 3 02:25:16 2019 @@ -262,9 +262,13 @@ TEST_F(SortIncludesTest, CommentsAlwaysS TEST_F(SortIncludesTest, HandlesAngledIncludesAsSeparateBlocks) { EXPECT_EQ("#include \"a.h\"\n" "#include \"c.h\"\n" +"#include \n" "#include \n" -"#include \n", -sort("#include \n" +"#include \n" +"#include \n", +sort("#include \n" + "#include \n" + "#include \n" "#include \n" "#include \"c.h\"\n" "#include \"a.h\"\n")); @@ -272,9 +276,15 @@ TEST_F(SortIncludesTest, HandlesAngledIn FmtStyle = getGoogleStyle(FormatStyle::LK_Cpp); EXPECT_EQ("#include \n" "#include \n" +"\n" +"#include \n" +"#include \n" +"\n" "#include \"a.h\"\n" "#include \"c.h\"\n", -sort("#include \n" +sort("#include \n" + "#include \n" + "#include \n" "#include \n" "#include \"c.h\"\n" "#include \"a.h\"\n")); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r356446 - [Tooling] Add more scope specifiers until spelling is not ambiguous.
Author: ioeric Date: Tue Mar 19 03:12:15 2019 New Revision: 356446 URL: http://llvm.org/viewvc/llvm-project?rev=356446=rev Log: [Tooling] Add more scope specifiers until spelling is not ambiguous. Summary: Previously, when the renamed spelling is ambiguous, we simply use the full-qualfied name (with leading "::"). This patch makes it try adding additional specifiers one at a time until name is no longer ambiguous, which allows us to find better disambuguated spelling. Reviewers: kadircet, gribozavr Subscribers: jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59487 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=356446=356445=356446=diff == --- cfe/trunk/lib/Tooling/Core/Lookup.cpp (original) +++ cfe/trunk/lib/Tooling/Core/Lookup.cpp Tue Mar 19 03:12:15 2019 @@ -14,6 +14,7 @@ #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclarationName.h" +#include "llvm/ADT/SmallVector.h" using namespace clang; using namespace clang::tooling; @@ -114,35 +115,60 @@ 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. +// Adds more scope specifier to the spelled name until the spelling is not +// ambiguous. A spelling is ambiguous if the resolution of the symbol is +// ambiguous. For example, if QName is "::y::bar", the spelling is "y::bar", and +// context contains a nested namespace "a::y", then "y::bar" can be resolved to +// ::a::y::bar in the context, which can cause compile error. // FIXME: consider using namespaces. -static bool isAmbiguousNameInScope(StringRef Spelling, StringRef QName, - const DeclContext ) { +static std::string disambiguateSpellingInScope(StringRef Spelling, + StringRef QName, + const DeclContext ) { assert(QName.startswith("::")); + assert(QName.endswith(Spelling)); if (Spelling.startswith("::")) -return false; +return Spelling; - // 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; + auto UnspelledSpecifier = QName.drop_back(Spelling.size()); + llvm::SmallVector UnspelledScopes; + UnspelledSpecifier.split(UnspelledScopes, "::", /*MaxSplit=*/-1, + /*KeepEmpty=*/false); - llvm::SmallVector UseNamespaces = + llvm::SmallVector EnclosingNamespaces = getAllNamedNamespaces(); auto = UseContext.getParentASTContext(); StringRef TrimmedQName = QName.substr(2); - for (const auto *NS : UseNamespaces) { -auto LookupRes = NS->lookup(DeclarationName((Head))); -if (!LookupRes.empty()) { - for (const NamedDecl *Res : LookupRes) -if (!TrimmedQName.startswith(Res->getQualifiedNameAsString())) - return true; + + auto IsAmbiguousSpelling = [, , ]( + const llvm::StringRef CurSpelling) { +if (CurSpelling.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 = CurSpelling.split("::").first; +for (const auto *NS : EnclosingNamespaces) { + auto LookupRes = NS->lookup(DeclarationName((Head))); + if (!LookupRes.empty()) { +for (const NamedDecl *Res : LookupRes) + if (!TrimmedQName.startswith(Res->getQualifiedNameAsString())) +return true; + } +} +return false; + }; + + // Add more qualifiers until the spelling is not ambiguous. + std::string Disambiguated = Spelling; + while (IsAmbiguousSpelling(Disambiguated)) { +if (UnspelledScopes.empty()) { + Disambiguated = "::" + Disambiguated; +} else { + Disambiguated = (UnspelledScopes.back() + "::" + Disambiguated).str(); + UnspelledScopes.pop_back(); } } - return false; + return Disambiguated; } std::string tooling::replaceNestedName(const NestedNameSpecifier *Use, @@ -179,12 +205,6 @@ std::string tooling::replaceNestedName(c // specific). StringRef Suggested = getBestNamespaceSubstr(UseContext, ReplacementString, isFullyQualified(Use)); - // Use the fully qualified name if the suggested
[clang-tools-extra] r355200 - [clangd] Enable SuggestMissingIncludes by default.
Author: ioeric Date: Fri Mar 1 06:17:55 2019 New Revision: 355200 URL: http://llvm.org/viewvc/llvm-project?rev=355200=rev Log: [clangd] Enable SuggestMissingIncludes by default. Summary: This seems to work stably now. Turn on by default. Reviewers: kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58772 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=355200=355199=355200=diff == --- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original) +++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Fri Mar 1 06:17:55 2019 @@ -217,7 +217,7 @@ static llvm::cl::opt SuggestMissin "suggest-missing-includes", llvm::cl::desc("Attempts to fix diagnostic errors caused by missing " "includes using index."), -llvm::cl::init(false)); +llvm::cl::init(true)); namespace { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r354963 - [clangd] Improve global code completion when scope specifier is unresolved.
Author: ioeric Date: Wed Feb 27 03:42:37 2019 New Revision: 354963 URL: http://llvm.org/viewvc/llvm-project?rev=354963=rev Log: [clangd] Improve global code completion when scope specifier is unresolved. Summary: Suppose `clangd::` is unresolved in the following example. Currently, we simply use "clangd::" as the query scope. We can do better by combining with accessible scopes in the context. The query scopes can be `{clangd::, clang::clangd::}`. ``` namespace clang { clangd::^ } ``` Reviewers: ilya-biryukov, sammccall, hokein, kadircet Reviewed By: kadircet Subscribers: MaskRay, jkorous, arphaman, kadircet, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58448 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=354963=354962=354963=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Wed Feb 27 03:42:37 2019 @@ -48,6 +48,7 @@ #include "llvm/ADT/None.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" #include "llvm/Support/Format.h" #include "llvm/Support/FormatVariadic.h" @@ -526,7 +527,7 @@ struct SpecifiedScope { std::set Results; for (llvm::StringRef AS : AccessibleScopes) Results.insert( - ((UnresolvedQualifier ? *UnresolvedQualifier : "") + AS).str()); + (AS + (UnresolvedQualifier ? *UnresolvedQualifier : "")).str()); return {Results.begin(), Results.end()}; } }; @@ -570,16 +571,15 @@ getQueryScopes(CodeCompletionContext } // Unresolved qualifier. - // FIXME: When Sema can resolve part of a scope chain (e.g. - // "known::unknown::id"), we should expand the known part ("known::") rather - // than treating the whole thing as unknown. - SpecifiedScope Info; - Info.AccessibleScopes.push_back(""); // global namespace + SpecifiedScope Info = GetAllAccessibleScopes(CCContext); + Info.AccessibleScopes.push_back(""); // Make sure global scope is included. - Info.UnresolvedQualifier = + llvm::StringRef SpelledSpecifier = Lexer::getSourceText(CharSourceRange::getCharRange((*SS)->getRange()), - CCSema.SourceMgr, clang::LangOptions()) - .ltrim("::"); + CCSema.SourceMgr, clang::LangOptions()); + if (SpelledSpecifier.consume_front("::")) +Info.AccessibleScopes = {""}; + Info.UnresolvedQualifier = SpelledSpecifier; // Sema excludes the trailing "::". if (!Info.UnresolvedQualifier->empty()) *Info.UnresolvedQualifier += "::"; 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=354963=354962=354963=diff == --- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Wed Feb 27 03:42:37 2019 @@ -1095,8 +1095,10 @@ TEST(CompletionTest, UnresolvedQualifier } // namespace ns )cpp"); - EXPECT_THAT(Requests, ElementsAre(Field(::Scopes, - UnorderedElementsAre("bar::"; + EXPECT_THAT(Requests, + ElementsAre(Field( + ::Scopes, + UnorderedElementsAre("a::bar::", "ns::bar::", "bar::"; } TEST(CompletionTest, UnresolvedNestedQualifierIdQuery) { @@ -2335,6 +2337,35 @@ TEST(CompletionTest, UsingDecl) { Kind(CompletionItemKind::Reference; } +TEST(CompletionTest, ScopeIsUnresolved) { + clangd::CodeCompleteOptions Opts = {}; + Opts.AllScopes = true; + + auto Results = completions(R"cpp( +namespace a { +void f() { b::X^ } +} + )cpp", + {cls("a::b::XYZ")}, Opts); + EXPECT_THAT(Results.Completions, + UnorderedElementsAre(AllOf(Qualifier(""), Named("XYZ"; +} + +TEST(CompletionTest, NestedScopeIsUnresolved) { + clangd::CodeCompleteOptions Opts = {}; + Opts.AllScopes = true; + + auto Results = completions(R"cpp( +namespace a { +namespace b {} +void f() { b::c::X^ } +} + )cpp", + {cls("a::b::c::XYZ")}, Opts); + EXPECT_THAT(Results.Completions, + UnorderedElementsAre(AllOf(Qualifier(""), Named("XYZ"; +} + } // namespace } // namespace clangd } // namespace clang ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D58448: [clangd] Improve global code completion when scope specifier is unresolved.
Unfortunately, the evaluation tool I use only works on compilable code, so it doesn't capture the unsolved specifier case in this patch. I didn't try to collect the metrics because I think this is more of a bug fix than quality improvement. On Tue, Feb 26, 2019, 10:25 Kadir Cetinkaya via Phabricator < revi...@reviews.llvm.org> wrote: > kadircet added a comment. > > LG > > Do we have any metrics regarding change in completion quality? > > > Repository: > rCTE Clang Tools Extra > > CHANGES SINCE LAST ACTION > https://reviews.llvm.org/D58448/new/ > > https://reviews.llvm.org/D58448 > > > > ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r354570 - [CodeComplete] Collect visited contexts when scope specifier is invalid.
Author: ioeric Date: Thu Feb 21 03:22:58 2019 New Revision: 354570 URL: http://llvm.org/viewvc/llvm-project?rev=354570=rev Log: [CodeComplete] Collect visited contexts when scope specifier is invalid. Summary: This will allow completion consumers to guess the specified scope by putting together scopes in the context with the specified scope (e.g. when the specified namespace is not imported yet). Reviewers: ilya-biryukov Subscribers: jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58446 Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp cfe/trunk/unittests/Sema/CodeCompleteTest.cpp Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=354570=354569=354570=diff == --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original) +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Thu Feb 21 03:22:58 2019 @@ -5061,7 +5061,20 @@ void Sema::CodeCompleteQualifiedId(Scope if (SS.isInvalid()) { CodeCompletionContext CC(CodeCompletionContext::CCC_Symbol); CC.setCXXScopeSpecifier(SS); -HandleCodeCompleteResults(this, CodeCompleter, CC, nullptr, 0); +// As SS is invalid, we try to collect accessible contexts from the current +// scope with a dummy lookup so that the completion consumer can try to +// guess what the specified scope is. +ResultBuilder DummyResults(*this, CodeCompleter->getAllocator(), + CodeCompleter->getCodeCompletionTUInfo(), CC); +if (S->getEntity()) { + CodeCompletionDeclConsumer Consumer(DummyResults, S->getEntity(), + BaseType); + LookupVisibleDecls(S, LookupOrdinaryName, Consumer, + /*IncludeGlobalScope=*/false, + /*LoadExternal=*/false); +} +HandleCodeCompleteResults(this, CodeCompleter, + DummyResults.getCompletionContext(), nullptr, 0); return; } // Always pretend to enter a context to ensure that a dependent type Modified: cfe/trunk/unittests/Sema/CodeCompleteTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Sema/CodeCompleteTest.cpp?rev=354570=354569=354570=diff == --- cfe/trunk/unittests/Sema/CodeCompleteTest.cpp (original) +++ cfe/trunk/unittests/Sema/CodeCompleteTest.cpp Thu Feb 21 03:22:58 2019 @@ -173,12 +173,16 @@ TEST(SemaCodeCompleteTest, VisitedNSForV "foo::(anonymous)")); } -TEST(SemaCodeCompleteTest, VisitedNSForInvalideQualifiedId) { +TEST(SemaCodeCompleteTest, VisitedNSForInvalidQualifiedId) { auto VisitedNS = runCodeCompleteOnCode(R"cpp( - namespace ns { foo::^ } + namespace na {} + namespace ns1 { + using namespace na; + foo::^ + } )cpp") .VisitedNamespaces; - EXPECT_TRUE(VisitedNS.empty()); + EXPECT_THAT(VisitedNS, UnorderedElementsAre("ns1", "na")); } TEST(SemaCodeCompleteTest, VisitedNSWithoutQualifier) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r354558 - [clangd] Handle another incomplete-type diagnostic case in IncludeFixer.
Author: ioeric Date: Thu Feb 21 01:33:49 2019 New Revision: 354558 URL: http://llvm.org/viewvc/llvm-project?rev=354558=rev Log: [clangd] Handle another incomplete-type diagnostic case in IncludeFixer. Modified: clang-tools-extra/trunk/clangd/IncludeFixer.cpp clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp Modified: clang-tools-extra/trunk/clangd/IncludeFixer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/IncludeFixer.cpp?rev=354558=354557=354558=diff == --- clang-tools-extra/trunk/clangd/IncludeFixer.cpp (original) +++ clang-tools-extra/trunk/clangd/IncludeFixer.cpp Thu Feb 21 01:33:49 2019 @@ -67,6 +67,7 @@ std::vector IncludeFixer::fix(Diagn case diag::err_incomplete_type: case diag::err_incomplete_member_access: case diag::err_incomplete_base_class: + case diag::err_incomplete_nested_name_spec: // Incomplete type diagnostics should have a QualType argument for the // incomplete type. for (unsigned Idx = 0; Idx < Info.getNumArgs(); ++Idx) { Modified: clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp?rev=354558=354557=354558=diff == --- clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp Thu Feb 21 01:33:49 2019 @@ -311,6 +311,7 @@ TEST(IncludeFixerTest, IncompleteType) { Annotations Test(R"cpp( $insert[[]]namespace ns { class X; + $nested[[X::]]Nested n; } class Y : $base[[public ns::X]] {}; int main() { @@ -326,6 +327,10 @@ int main() { EXPECT_THAT( TU.build().getDiagnostics(), UnorderedElementsAre( + AllOf(Diag(Test.range("nested"), + "incomplete type 'ns::X' named in nested name specifier"), +WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n", +"Add include \"x.h\" for symbol ns::X"))), AllOf(Diag(Test.range("base"), "base class has incomplete type"), WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n", "Add include \"x.h\" for symbol ns::X"))), ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r354330 - [clangd] Handle unresolved scope specifier when fixing includes.
Author: ioeric Date: Tue Feb 19 06:32:22 2019 New Revision: 354330 URL: http://llvm.org/viewvc/llvm-project?rev=354330=rev Log: [clangd] Handle unresolved scope specifier when fixing includes. Summary: In the following examples, "clangd" is unresolved, and the fixer will try to fix include for `clang::clangd`; however, clang::clangd::X is usually intended. So when handling a qualifier that is unresolved, we change the unresolved name and scopes so that the fixer will fix "clang::clangd::X" in the following example. ``` namespace clang { clangd::X ~~ } // or clang::clangd::X ~~ ``` Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58185 Modified: clang-tools-extra/trunk/clangd/IncludeFixer.cpp clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp Modified: clang-tools-extra/trunk/clangd/IncludeFixer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/IncludeFixer.cpp?rev=354330=354329=354330=diff == --- clang-tools-extra/trunk/clangd/IncludeFixer.cpp (original) +++ clang-tools-extra/trunk/clangd/IncludeFixer.cpp Tue Feb 19 06:32:22 2019 @@ -19,6 +19,10 @@ #include "clang/AST/Type.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticSema.h" +#include "clang/Basic/LangOptions.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/SourceManager.h" +#include "clang/Basic/TokenKinds.h" #include "clang/Sema/DeclSpec.h" #include "clang/Sema/Lookup.h" #include "clang/Sema/Scope.h" @@ -28,6 +32,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/None.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/Error.h" #include "llvm/Support/FormatVariadic.h" @@ -172,6 +177,121 @@ std::vector IncludeFixer::fixesForS } return Fixes; } + +// Returns the identifiers qualified by an unresolved name. \p Loc is the +// start location of the unresolved name. For the example below, this returns +// "::X::Y" that is qualified by unresolved name "clangd": +// clang::clangd::X::Y +//~ +llvm::Optional qualifiedByUnresolved(const SourceManager , + SourceLocation Loc, + const LangOptions ) { + std::string Result; + + SourceLocation NextLoc = Loc; + while (auto CCTok = Lexer::findNextToken(NextLoc, SM, LangOpts)) { +if (!CCTok->is(tok::coloncolon)) + break; +auto IDTok = Lexer::findNextToken(CCTok->getLocation(), SM, LangOpts); +if (!IDTok || !IDTok->is(tok::raw_identifier)) + break; +Result.append(("::" + IDTok->getRawIdentifier()).str()); +NextLoc = IDTok->getLocation(); + } + if (Result.empty()) +return llvm::None; + return Result; +} + +// An unresolved name and its scope information that can be extracted cheaply. +struct CheapUnresolvedName { + std::string Name; + // This is the part of what was typed that was resolved, and it's in its + // resolved form not its typed form (think `namespace clang { clangd::x }` --> + // `clang::clangd::`). + llvm::Optional ResolvedScope; + + // Unresolved part of the scope. When the unresolved name is a specifier, we + // use the name that comes after it as the alternative name to resolve and use + // the specifier as the extra scope in the accessible scopes. + llvm::Optional UnresolvedScope; +}; + +// Extracts unresolved name and scope information around \p Unresolved. +// FIXME: try to merge this with the scope-wrangling code in CodeComplete. +llvm::Optional extractUnresolvedNameCheaply( +const SourceManager , const DeclarationNameInfo , +CXXScopeSpec *SS, const LangOptions , bool UnresolvedIsSpecifier) { + bool Invalid = false; + llvm::StringRef Code = SM.getBufferData( + SM.getDecomposedLoc(Unresolved.getBeginLoc()).first, ); + if (Invalid) +return llvm::None; + CheapUnresolvedName Result; + Result.Name = Unresolved.getAsString(); + if (SS && SS->isNotEmpty()) { // "::" or "ns::" +if (auto *Nested = SS->getScopeRep()) { + if (Nested->getKind() == NestedNameSpecifier::Global) +Result.ResolvedScope = ""; + else if (const auto *NS = Nested->getAsNamespace()) { +auto SpecifiedNS = printNamespaceScope(*NS); + +// Check the specifier spelled in the source. +// If the resolved scope doesn't end with the spelled scope. The +// resolved scope can come from a sema typo correction. For example, +// sema assumes that "clangd::" is a typo of "clang::" and uses +// "clang::" as the specified scope in: +// namespace clang { clangd::X; } +// In this case, we use the "typo" specifier as extra scope instead +
[clang-tools-extra] r354268 - [clangd] Cache include fixes for diagnostics caused by the same unresolved name or incomplete type.
Author: ioeric Date: Mon Feb 18 05:12:10 2019 New Revision: 354268 URL: http://llvm.org/viewvc/llvm-project?rev=354268=rev Log: [clangd] Cache include fixes for diagnostics caused by the same unresolved name or incomplete type. Summary: Multiple diagnostics can be caused by the same unresolved name or incomplete type, especially if the code is copy-pasted without #includes. The cache can avoid making repetitive index requests, and thus reduce latency and allow more diagnostics to be fixed (we limit the number of index requests for each parse). Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58239 Modified: clang-tools-extra/trunk/clangd/IncludeFixer.cpp clang-tools-extra/trunk/clangd/IncludeFixer.h clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp Modified: clang-tools-extra/trunk/clangd/IncludeFixer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/IncludeFixer.cpp?rev=354268=354267=354268=diff == --- clang-tools-extra/trunk/clangd/IncludeFixer.cpp (original) +++ clang-tools-extra/trunk/clangd/IncludeFixer.cpp Mon Feb 18 05:12:10 2019 @@ -27,6 +27,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/None.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/Error.h" #include "llvm/Support/FormatVariadic.h" @@ -57,8 +58,6 @@ private: std::vector IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic ) const { - if (IndexRequestCount >= IndexRequestLimit) -return {}; // Avoid querying index too many times in a single parse. switch (Info.getID()) { case diag::err_incomplete_type: case diag::err_incomplete_member_access: @@ -118,26 +117,21 @@ std::vector IncludeFixer::fixIncomp auto ID = getSymbolID(TD); if (!ID) return {}; - ++IndexRequestCount; - // FIXME: consider batching the requests for all diagnostics. - // FIXME: consider caching the lookup results. - LookupRequest Req; - Req.IDs.insert(*ID); - llvm::Optional Matched; - Index.lookup(Req, [&](const Symbol ) { -if (Matched) - return; -Matched = Sym; - }); - - if (!Matched || Matched->IncludeHeaders.empty() || !Matched->Definition || - Matched->CanonicalDeclaration.FileURI != Matched->Definition.FileURI) + llvm::Optional Symbols = lookupCached(*ID); + if (!Symbols) return {}; - return fixesForSymbols({*Matched}); + const SymbolSlab = **Symbols; + std::vector Fixes; + if (!Syms.empty()) { +auto = *Syms.begin(); +if (!Matched.IncludeHeaders.empty() && Matched.Definition && +Matched.CanonicalDeclaration.FileURI == Matched.Definition.FileURI) + Fixes = fixesForSymbols(Syms); + } + return Fixes; } -std::vector -IncludeFixer::fixesForSymbols(llvm::ArrayRef Syms) const { +std::vector IncludeFixer::fixesForSymbols(const SymbolSlab ) const { auto Inserted = [&](const Symbol , llvm::StringRef Header) -> llvm::Expected> { auto ResolvedDeclaring = @@ -289,6 +283,24 @@ std::vector IncludeFixer::fixUnreso Req.RestrictForCodeCompletion = true; Req.Limit = 100; + if (llvm::Optional Syms = fuzzyFindCached(Req)) +return fixesForSymbols(**Syms); + + return {}; +} + + +llvm::Optional +IncludeFixer::fuzzyFindCached(const FuzzyFindRequest ) const { + auto ReqStr = llvm::formatv("{0}", toJSON(Req)).str(); + auto I = FuzzyFindCache.find(ReqStr); + if (I != FuzzyFindCache.end()) +return >second; + + if (IndexRequestCount >= IndexRequestLimit) +return llvm::None; + IndexRequestCount++; + SymbolSlab::Builder Matches; Index.fuzzyFind(Req, [&](const Symbol ) { if (Sym.Name != Req.Query) @@ -297,7 +309,37 @@ std::vector IncludeFixer::fixUnreso Matches.insert(Sym); }); auto Syms = std::move(Matches).build(); - return fixesForSymbols(std::vector(Syms.begin(), Syms.end())); + auto E = FuzzyFindCache.try_emplace(ReqStr, std::move(Syms)); + return >second; +} + +llvm::Optional +IncludeFixer::lookupCached(const SymbolID ) const { + LookupRequest Req; + Req.IDs.insert(ID); + + auto I = LookupCache.find(ID); + if (I != LookupCache.end()) +return >second; + + if (IndexRequestCount >= IndexRequestLimit) +return llvm::None; + IndexRequestCount++; + + // FIXME: consider batching the requests for all diagnostics. + SymbolSlab::Builder Matches; + Index.lookup(Req, [&](const Symbol ) { Matches.insert(Sym); }); + auto Syms = std::move(Matches).build(); + + std::vector Fixes; + if (!Syms.empty()) { +auto = *Syms.begin(); +if (!Matched.IncludeHeaders.empty() && Matched.Definition && +Matched.CanonicalDeclaration.FileURI == Matched.Definition.FileURI) + Fixes = fixesForSymbols(Syms); +
[clang-tools-extra] r353926 - [clangd] Handle a few more diag kinds in include fixer.
Author: ioeric Date: Wed Feb 13 00:58:54 2019 New Revision: 353926 URL: http://llvm.org/viewvc/llvm-project?rev=353926=rev Log: [clangd] Handle a few more diag kinds in include fixer. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58135 Modified: clang-tools-extra/trunk/clangd/IncludeFixer.cpp clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp Modified: clang-tools-extra/trunk/clangd/IncludeFixer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/IncludeFixer.cpp?rev=353926=353925=353926=diff == --- clang-tools-extra/trunk/clangd/IncludeFixer.cpp (original) +++ clang-tools-extra/trunk/clangd/IncludeFixer.cpp Wed Feb 13 00:58:54 2019 @@ -79,6 +79,12 @@ std::vector IncludeFixer::fix(Diagn case diag::err_typename_nested_not_found: case diag::err_no_template: case diag::err_no_template_suggest: + case diag::err_undeclared_use: + case diag::err_undeclared_use_suggest: + case diag::err_undeclared_var_use: + case diag::err_undeclared_var_use_suggest: + case diag::err_no_member: // Could be no member in namespace. + case diag::err_no_member_suggest: if (LastUnresolvedName) { // Try to fix unresolved name caused by missing declaraion. // E.g. Modified: clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp?rev=353926=353925=353926=diff == --- clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp Wed Feb 13 00:58:54 2019 @@ -368,11 +368,14 @@ TEST(IncludeFixerTest, Typo) { Annotations Test(R"cpp( $insert[[]]namespace ns { void foo() { - $unqualified[[X]] x; + $unqualified1[[X]] x; + $unqualified2[[X]]::Nested n; } } void bar() { - ns::$qualified[[X]] x; // ns:: is valid. + ns::$qualified1[[X]] x; // ns:: is valid. + ns::$qualified2[[X]](); // Error: no member in namespace + ::$global[[Global]] glob; } )cpp"); @@ -385,13 +388,21 @@ void bar() { EXPECT_THAT( TU.build().getDiagnostics(), UnorderedElementsAre( - AllOf(Diag(Test.range("unqualified"), "unknown type name 'X'"), + AllOf(Diag(Test.range("unqualified1"), "unknown type name 'X'"), +WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n", +"Add include \"x.h\" for symbol ns::X"))), + AllOf(Diag(Test.range("unqualified2"), + "use of undeclared identifier 'X'"), WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n", "Add include \"x.h\" for symbol ns::X"))), - AllOf(Diag(Test.range("qualified"), + AllOf(Diag(Test.range("qualified1"), "no type named 'X' in namespace 'ns'"), WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n", "Add include \"x.h\" for symbol ns::X"))), + AllOf(Diag(Test.range("qualified2"), + "no member named 'X' in namespace 'ns'"), +WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n", +"Add include \"x.h\" for symbol ns::X"))), AllOf(Diag(Test.range("global"), "no type named 'Global' in the global namespace"), WithFix(Fix(Test.range("insert"), "#include \"global.h\"\n", ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r353708 - [clangd] Prefer location from codegen files when merging symbols.
Author: ioeric Date: Mon Feb 11 07:05:29 2019 New Revision: 353708 URL: http://llvm.org/viewvc/llvm-project?rev=353708=rev Log: [clangd] Prefer location from codegen files when merging symbols. Summary: For example, if an index symbol has location in a .proto file and an AST symbol has location in a generated .proto.h file, then we prefer location in .proto which is more meaningful to users. Also use `mergeSymbols` to get the preferred location between AST location and index location in go-to-def. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58037 Modified: clang-tools-extra/trunk/clangd/XRefs.cpp clang-tools-extra/trunk/clangd/index/Merge.cpp clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Modified: clang-tools-extra/trunk/clangd/XRefs.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=353708=353707=353708=diff == --- clang-tools-extra/trunk/clangd/XRefs.cpp (original) +++ clang-tools-extra/trunk/clangd/XRefs.cpp Mon Feb 11 07:05:29 2019 @@ -10,6 +10,8 @@ #include "Logger.h" #include "SourceCode.h" #include "URI.h" +#include "index/Index.h" +#include "index/Merge.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/RecursiveASTVisitor.h" #include "clang/Index/IndexDataConsumer.h" @@ -77,6 +79,32 @@ llvm::Optional toLSPLocation(c return LSPLoc; } +SymbolLocation toIndexLocation(const Location , std::string ) { + SymbolLocation SymLoc; + URIStorage = Loc.uri.uri(); + SymLoc.FileURI = URIStorage.c_str(); + SymLoc.Start.setLine(Loc.range.start.line); + SymLoc.Start.setColumn(Loc.range.start.character); + SymLoc.End.setLine(Loc.range.end.line); + SymLoc.End.setColumn(Loc.range.end.character); + return SymLoc; +} + +// Returns the preferred location between an AST location and an index location. +SymbolLocation getPreferredLocation(const Location , +const SymbolLocation ) { + // Also use a dummy symbol for the index location so that other fields (e.g. + // definition) are not factored into the preferrence. + Symbol ASTSym, IdxSym; + ASTSym.ID = IdxSym.ID = SymbolID("dummy_id"); + std::string URIStore; + ASTSym.CanonicalDeclaration = toIndexLocation(ASTLoc, URIStore); + IdxSym.CanonicalDeclaration = IdxLoc; + auto Merged = mergeSymbol(ASTSym, IdxSym); + return Merged.CanonicalDeclaration; +} + + struct MacroDecl { llvm::StringRef Name; const MacroInfo *Info; @@ -329,12 +357,23 @@ std::vector locateSymbolA // Special case: if the AST yielded a definition, then it may not be // the right *declaration*. Prefer the one from the index. - if (R.Definition) // from AST + if (R.Definition) { // from AST if (auto Loc = toLSPLocation(Sym.CanonicalDeclaration, *MainFilePath)) R.PreferredDeclaration = *Loc; - - if (!R.Definition) + } else { R.Definition = toLSPLocation(Sym.Definition, *MainFilePath); + +if (Sym.CanonicalDeclaration) { + // Use merge logic to choose AST or index declaration. + // We only do this for declarations as definitions from AST + // is generally preferred (e.g. definitions in main file). + if (auto Loc = + toLSPLocation(getPreferredLocation(R.PreferredDeclaration, + Sym.CanonicalDeclaration), +*MainFilePath)) +R.PreferredDeclaration = *Loc; +} + } }); } 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=353708=353707=353708=diff == --- clang-tools-extra/trunk/clangd/index/Merge.cpp (original) +++ clang-tools-extra/trunk/clangd/index/Merge.cpp Mon Feb 11 07:05:29 2019 @@ -9,9 +9,13 @@ #include "Merge.h" #include "Logger.h" #include "Trace.h" +#include "index/Index.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/raw_ostream.h" +#include +#include namespace clang { namespace clangd { @@ -114,6 +118,23 @@ void MergedIndex::refs(const RefsRequest }); } +// Returns true if \p L is (strictly) preferred to \p R (e.g. by file paths). If +// neither is preferred, this returns false. +bool prefer(const SymbolLocation , const SymbolLocation ) { + if (!L) +return false; + if (!R) +return true; + auto HasCodeGenSuffix = [](const SymbolLocation ) { +constexpr static const char *CodegenSuffixes[] = {".proto"}; +return std::any_of(std::begin(CodegenSuffixes), std::end(CodegenSuffixes), +
[clang-tools-extra] r353514 - [clangd] Fix an assertion in TypoCorrection.
Author: ioeric Date: Fri Feb 8 05:27:47 2019 New Revision: 353514 URL: http://llvm.org/viewvc/llvm-project?rev=353514=rev Log: [clangd] Fix an assertion in TypoCorrection. Summary: https://github.com/clangd/clangd/issues/7 Reviewers: sammccall, hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D57944 Modified: clang-tools-extra/trunk/clangd/IncludeFixer.cpp clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp Modified: clang-tools-extra/trunk/clangd/IncludeFixer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/IncludeFixer.cpp?rev=353514=353513=353514=diff == --- clang-tools-extra/trunk/clangd/IncludeFixer.cpp (original) +++ clang-tools-extra/trunk/clangd/IncludeFixer.cpp Fri Feb 8 05:27:47 2019 @@ -192,12 +192,6 @@ public: if (!SemaPtr->SourceMgr.isWrittenInMainFile(Typo.getLoc())) return clang::TypoCorrection(); -assert(S && "Enclosing scope must be set."); - -UnresolvedName Unresolved; -Unresolved.Name = Typo.getAsString(); -Unresolved.Loc = Typo.getBeginLoc(); - // FIXME: support invalid scope before a type name. In the following // example, namespace "clang::tidy::" hasn't been declared/imported. //namespace clang { @@ -228,6 +222,12 @@ public: return TypoCorrection(); } } +if (!SpecifiedScope && !S) // Give up if no scope available. + return TypoCorrection(); + +UnresolvedName Unresolved; +Unresolved.Name = Typo.getAsString(); +Unresolved.Loc = Typo.getBeginLoc(); auto *Sem = SemaPtr; // Avoid capturing `this`. Unresolved.GetScopes = [Sem, SpecifiedScope, S, LookupKind]() { @@ -235,6 +235,7 @@ public: if (SpecifiedScope) { Scopes.push_back(*SpecifiedScope); } else { +assert(S); // No scope qualifier is specified. Collect all accessible scopes in the // context. VisitedContextCollector Collector; Modified: clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp?rev=353514=353513=353514=diff == --- clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp Fri Feb 8 05:27:47 2019 @@ -423,6 +423,21 @@ void foo() { "Add include \"b.h\" for symbol na::nb::X"); } +TEST(IncludeFixerTest, NoCrashMemebrAccess) { + Annotations Test(R"cpp( +struct X { int xyz; }; +void g() { X x; x.$[[xy]] } + )cpp"); + auto TU = TestTU::withCode(Test.code()); + auto Index = buildIndexWithSymbol( + SymbolWithHeader{"na::X", "unittest:///a.h", "\"a.h\""}); + TU.ExternalIndex = Index.get(); + + EXPECT_THAT( + TU.build().getDiagnostics(), + UnorderedElementsAre(Diag(Test.range(), "no member named 'xy' in 'X'"))); +} + } // namespace } // namespace clangd } // namespace clang ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r353413 - [clangd] Use Dex for dynamic index by default.
Author: ioeric Date: Thu Feb 7 07:34:37 2019 New Revision: 353413 URL: http://llvm.org/viewvc/llvm-project?rev=353413=rev Log: [clangd] Use Dex for dynamic index by default. Summary: Memory usage for a sample TU: Without Dex: 17.9M WithDex: 24.4M The memory increase is considerable but seems tolerable. Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D57878 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=353413=353412=353413=diff == --- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original) +++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Thu Feb 7 07:34:37 2019 @@ -31,7 +31,7 @@ namespace clangd { static llvm::cl::opt UseDex("use-dex-index", llvm::cl::desc("Use experimental Dex dynamic index."), - llvm::cl::init(false), llvm::cl::Hidden); + llvm::cl::init(true), llvm::cl::Hidden); static llvm::cl::opt CompileCommandsDir( "compile-commands-dir", ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r353380 - [clangd] Suggest adding missing includes for typos (like include-fixer).
Author: ioeric Date: Thu Feb 7 01:23:22 2019 New Revision: 353380 URL: http://llvm.org/viewvc/llvm-project?rev=353380=rev Log: [clangd] Suggest adding missing includes for typos (like include-fixer). Summary: This adds include-fixer feature into clangd based on D56903. Clangd now captures diagnostics caused by typos and attach include insertion fixes to potentially fix the typo. Reviewers: sammccall Reviewed By: sammccall Subscribers: cfe-commits, kadircet, arphaman, mgrang, jkorous, MaskRay, javed.absar, ilya-biryukov, mgorny Tags: #clang Differential Revision: https://reviews.llvm.org/D57021 Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp clang-tools-extra/trunk/clangd/IncludeFixer.cpp clang-tools-extra/trunk/clangd/IncludeFixer.h clang-tools-extra/trunk/clangd/SourceCode.h clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=353380=353379=353380=diff == --- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Thu Feb 7 01:23:22 2019 @@ -322,6 +322,7 @@ ParsedAST::build(std::unique_ptrfix(DiagLevl, Info); }); +Clang->setExternalSemaSource(FixIncludes->unresolvedNameRecorder()); } // Copy over the includes from the preamble, then combine with the @@ -565,10 +566,10 @@ buildAST(PathRef FileName, std::unique_p // dirs. } - return ParsedAST::build( - llvm::make_unique(*Invocation), Preamble, - llvm::MemoryBuffer::getMemBufferCopy(Inputs.Contents), PCHs, - std::move(VFS), Inputs.Index ? Inputs.Index : nullptr, Inputs.Opts); + return ParsedAST::build(llvm::make_unique(*Invocation), + Preamble, + llvm::MemoryBuffer::getMemBufferCopy(Inputs.Contents), + PCHs, std::move(VFS), Inputs.Index, Inputs.Opts); } SourceLocation getBeginningOfIdentifier(ParsedAST , const Position , Modified: clang-tools-extra/trunk/clangd/IncludeFixer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/IncludeFixer.cpp?rev=353380=353379=353380=diff == --- clang-tools-extra/trunk/clangd/IncludeFixer.cpp (original) +++ clang-tools-extra/trunk/clangd/IncludeFixer.cpp Thu Feb 7 01:23:22 2019 @@ -14,16 +14,47 @@ #include "Trace.h" #include "index/Index.h" #include "clang/AST/Decl.h" +#include "clang/AST/DeclBase.h" +#include "clang/AST/NestedNameSpecifier.h" #include "clang/AST/Type.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticSema.h" +#include "clang/Sema/DeclSpec.h" +#include "clang/Sema/Lookup.h" +#include "clang/Sema/Scope.h" +#include "clang/Sema/Sema.h" +#include "clang/Sema/TypoCorrection.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/None.h" +#include "llvm/ADT/StringSet.h" #include "llvm/Support/Error.h" #include "llvm/Support/FormatVariadic.h" +#include namespace clang { namespace clangd { +namespace { + +// Collects contexts visited during a Sema name lookup. +class VisitedContextCollector : public VisibleDeclConsumer { +public: + void EnteredContext(DeclContext *Ctx) override { Visited.push_back(Ctx); } + + void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx, + bool InBaseClass) override {} + + std::vector takeVisitedContexts() { +return std::move(Visited); + } + +private: + std::vector Visited; +}; + +} // namespace + std::vector IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic ) const { if (IndexRequestCount >= IndexRequestLimit) @@ -42,6 +73,28 @@ std::vector IncludeFixer::fix(Diagn return fixIncompleteType(*T); } } +break; + case diag::err_unknown_typename: + case diag::err_unknown_typename_suggest: + case diag::err_typename_nested_not_found: + case diag::err_no_template: + case diag::err_no_template_suggest: +if (LastUnresolvedName) { + // Try to fix unresolved name caused by missing declaraion. + // E.g. + // clang::SourceManager SM; + // ~ + // UnresolvedName + // or + // namespace clang { SourceManager SM; } + // ~ + // UnresolvedName + // We only attempt to recover a diagnostic if it has the same location as + // the last seen unresolved name. + if (DiagLevel >= DiagnosticsEngine::Error && + LastUnresolvedName->Loc == Info.getLocation()) +return fixUnresolvedName(); +} } return {}; } @@ -74,11 +127,12 @@ std::vector IncludeFixer::fixIncomp if (!Matched ||
[clang-tools-extra] r353310 - [clangd] Add type boost to fuzzy find in Dex.
Author: ioeric Date: Wed Feb 6 07:36:23 2019 New Revision: 353310 URL: http://llvm.org/viewvc/llvm-project?rev=353310=rev Log: [clangd] Add type boost to fuzzy find in Dex. Summary: No noticeable impact on code completions overall except some improvement on cross-namespace completion. Reviewers: sammccall, ilya-biryukov Reviewed By: sammccall Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D57815 Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/clangd/index/Index.cpp clang-tools-extra/trunk/clangd/index/Index.h clang-tools-extra/trunk/clangd/index/dex/Dex.cpp clang-tools-extra/trunk/clangd/index/dex/Dex.h clang-tools-extra/trunk/clangd/index/dex/Token.h clang-tools-extra/trunk/unittests/clangd/DexTests.cpp Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=353310=353309=353310=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Wed Feb 6 07:36:23 2019 @@ -1333,6 +1333,8 @@ private: Req.AnyScope = AllScopes; // FIXME: we should send multiple weighted paths here. Req.ProximityPaths.push_back(FileName); +if (PreferredType) + Req.PreferredTypes.push_back(PreferredType->raw()); vlog("Code complete: fuzzyFind({0:2})", toJSON(Req)); if (SpecFuzzyFind) 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=353310=353309=353310=diff == --- clang-tools-extra/trunk/clangd/index/Index.cpp (original) +++ clang-tools-extra/trunk/clangd/index/Index.cpp Wed Feb 6 07:36:23 2019 @@ -179,7 +179,8 @@ bool fromJSON(const llvm::json::Value O && O.map("Query", Request.Query) && O.map("Scopes", Request.Scopes) && O.map("AnyScope", Request.AnyScope) && O.map("Limit", Limit) && O.map("RestrictForCodeCompletion", Request.RestrictForCodeCompletion) && - O.map("ProximityPaths", Request.ProximityPaths); + O.map("ProximityPaths", Request.ProximityPaths) && + O.map("PreferredTypes", Request.PreferredTypes); if (OK && Limit <= std::numeric_limits::max()) Request.Limit = Limit; return OK; @@ -193,6 +194,7 @@ llvm::json::Value toJSON(const FuzzyFind {"Limit", Request.Limit}, {"RestrictForCodeCompletion", Request.RestrictForCodeCompletion}, {"ProximityPaths", llvm::json::Array{Request.ProximityPaths}}, + {"PreferredTypes", llvm::json::Array{Request.PreferredTypes}}, }; } 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=353310=353309=353310=diff == --- clang-tools-extra/trunk/clangd/index/Index.h (original) +++ clang-tools-extra/trunk/clangd/index/Index.h Wed Feb 6 07:36:23 2019 @@ -454,14 +454,15 @@ struct FuzzyFindRequest { /// Contextually relevant files (e.g. the file we're code-completing in). /// Paths should be absolute. std::vector ProximityPaths; - - // FIXME(ibiryukov): add expected type to the request. + /// Preferred types of symbols. These are raw representation of `OpaqueType`. + std::vector PreferredTypes; bool operator==(const FuzzyFindRequest ) const { return std::tie(Query, Scopes, Limit, RestrictForCodeCompletion, -ProximityPaths) == +ProximityPaths, PreferredTypes) == std::tie(Req.Query, Req.Scopes, Req.Limit, -Req.RestrictForCodeCompletion, Req.ProximityPaths); +Req.RestrictForCodeCompletion, Req.ProximityPaths, +Req.PreferredTypes); } bool operator!=(const FuzzyFindRequest ) const { return !(*this == Req); } }; Modified: clang-tools-extra/trunk/clangd/index/dex/Dex.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Dex.cpp?rev=353310=353309=353310=diff == --- clang-tools-extra/trunk/clangd/index/dex/Dex.cpp (original) +++ clang-tools-extra/trunk/clangd/index/dex/Dex.cpp Wed Feb 6 07:36:23 2019 @@ -42,7 +42,6 @@ const Token RestrictedForCodeCompletion // Returns the tokens which are given symbols's characteristics. For example, // trigrams and scopes. // FIXME(kbobyrev): Support more token types: -// * Types // * Namespace proximity std::vector generateSearchTokens(const Symbol ) { std::vector Result = generateIdentifierTrigrams(Sym.Name); @@ -54,49 +53,11 @@ std::vector generateSearchTokens(
[clang-tools-extra] r352957 - [clangd] Fix heap-use-after-free after r352868
Author: ioeric Date: Sat Feb 2 02:35:39 2019 New Revision: 352957 URL: http://llvm.org/viewvc/llvm-project?rev=352957=rev Log: [clangd] Fix heap-use-after-free after r352868 Modified: clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp Modified: clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp?rev=352957=352956=352957=diff == --- clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp Sat Feb 2 02:35:39 2019 @@ -180,14 +180,17 @@ TEST(QualityTests, SymbolRelevanceSignal EXPECT_TRUE(Relevance.InBaseClass); auto Index = Test.index(); - Symbol X; FuzzyFindRequest Req; Req.Query = "X"; Req.AnyScope = true; - Index->fuzzyFind(Req, [](const Symbol& S){ X = S; }); - Relevance = {}; - Relevance.merge(X); - EXPECT_EQ(Relevance.Scope, SymbolRelevanceSignals::FileScope); + bool Matched = false; + Index->fuzzyFind(Req, [&](const Symbol ) { +Matched = true; +Relevance = {}; +Relevance.merge(S); +EXPECT_EQ(Relevance.Scope, SymbolRelevanceSignals::FileScope); + }); + EXPECT_TRUE(Matched); } // Do the signals move the scores in the direction we expect? ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r352865 - [CUDA] Relax lit test condition after r352798.
Author: ioeric Date: Fri Feb 1 03:36:23 2019 New Revision: 352865 URL: http://llvm.org/viewvc/llvm-project?rev=352865=rev Log: [CUDA] Relax lit test condition after r352798. Clang executable doesn't match clang.* in all test environment. Modified: cfe/trunk/test/Driver/cuda-detect.cu Modified: cfe/trunk/test/Driver/cuda-detect.cu URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cuda-detect.cu?rev=352865=352864=352865=diff == --- cfe/trunk/test/Driver/cuda-detect.cu (original) +++ cfe/trunk/test/Driver/cuda-detect.cu Fri Feb 1 03:36:23 2019 @@ -178,14 +178,14 @@ // CHECK-CXXINCLUDE-SAME: {{.*}}"-internal-isystem" "{{.+}}/include/c++/4.8" // CHECK-CXXINCLUDE: ld{{.*}}" -// CUDA80: clang{{.*}} "-cc1" "-triple" "nvptx64-nvidia-cuda" +// CUDA80: "-cc1" "-triple" "nvptx64-nvidia-cuda" // CUDA80-SAME: -target-sdk-version=8.0 -// CUDA80: clang{{.*}} "-cc1" "-triple" "x86_64-unknown-linux-gnu" +// CUDA80: "-cc1" "-triple" "x86_64-unknown-linux-gnu" // CUDA80-SAME: -target-sdk-version=8.0 // CUDA80: ld{{.*}}" -// CUDA70: clang{{.*}} "-cc1" "-triple" "nvptx64-nvidia-cuda" +// CUDA70: "-cc1" "-triple" "nvptx64-nvidia-cuda" // CUDA70-SAME: -target-sdk-version=7.0 -// CUDA70: clang{{.*}} "-cc1" "-triple" "x86_64-unknown-linux-gnu" +// CUDA70: "-cc1" "-triple" "x86_64-unknown-linux-gnu" // CUDA70-SAME: -target-sdk-version=7.0 // CUDA70: ld{{.*}}" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r352764 - [clangd] Append "(fix available)" to diagnostic message when fixes are present.
Author: ioeric Date: Thu Jan 31 08:09:25 2019 New Revision: 352764 URL: http://llvm.org/viewvc/llvm-project?rev=352764=rev Log: [clangd] Append "(fix available)" to diagnostic message when fixes are present. Summary: This would make diagnostic fixits more discoverable, especially for plugins like YCM. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D57509 Modified: clang-tools-extra/trunk/clangd/Diagnostics.cpp clang-tools-extra/trunk/test/clangd/diagnostic-category.test clang-tools-extra/trunk/test/clangd/diagnostics.test clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test clang-tools-extra/trunk/test/clangd/execute-command.test clang-tools-extra/trunk/test/clangd/fixits-codeaction.test clang-tools-extra/trunk/test/clangd/fixits-command.test clang-tools-extra/trunk/test/clangd/fixits-embed-in-diagnostic.test clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp Modified: clang-tools-extra/trunk/clangd/Diagnostics.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Diagnostics.cpp?rev=352764=352763=352764=diff == --- clang-tools-extra/trunk/clangd/Diagnostics.cpp (original) +++ clang-tools-extra/trunk/clangd/Diagnostics.cpp Thu Jan 31 08:09:25 2019 @@ -165,6 +165,8 @@ std::string mainMessage(const Diag ) { std::string Result; llvm::raw_string_ostream OS(Result); OS << D.Message; + if (!D.Fixes.empty()) +OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)"; for (auto : D.Notes) { OS << "\n\n"; printDiag(OS, Note); Modified: clang-tools-extra/trunk/test/clangd/diagnostic-category.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/diagnostic-category.test?rev=352764=352763=352764=diff == --- clang-tools-extra/trunk/test/clangd/diagnostic-category.test (original) +++ clang-tools-extra/trunk/test/clangd/diagnostic-category.test Thu Jan 31 08:09:25 2019 @@ -7,7 +7,7 @@ # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { # CHECK-NEXT:"category": "Semantic Issue", -# CHECK-NEXT:"message": "Use of 'Point' with tag type that does not match previous declaration\n\nfoo.c:1:8: note: previous use is here", +# CHECK-NEXT:"message": "Use of 'Point' with tag type that does not match previous declaration (fix available)\n\nfoo.c:1:8: note: previous use is here", # CHECK-NEXT:"range": { # CHECK-NEXT: "end": { # CHECK-NEXT:"character": 22, Modified: clang-tools-extra/trunk/test/clangd/diagnostics.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/diagnostics.test?rev=352764=352763=352764=diff == --- clang-tools-extra/trunk/test/clangd/diagnostics.test (original) +++ clang-tools-extra/trunk/test/clangd/diagnostics.test Thu Jan 31 08:09:25 2019 @@ -6,7 +6,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT:"diagnostics": [ # CHECK-NEXT: { -# CHECK-NEXT:"message": "Return type of 'main' is not 'int'", +# CHECK-NEXT:"message": "Return type of 'main' is not 'int' (fix available)", # CHECK-NEXT:"range": { # CHECK-NEXT: "end": { # CHECK-NEXT:"character": 4, Modified: clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test?rev=352764=352763=352764=diff == --- clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test (original) +++ clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test Thu Jan 31 08:09:25 2019 @@ -24,7 +24,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT:"diagnostics": [ # CHECK-NEXT: { -# CHECK-NEXT:"message": "Variable 'i' is uninitialized when used here", +# CHECK-NEXT:"message": "Variable 'i' is uninitialized when used here (fix available)", # CHECK-NEXT:"range": { # CHECK-NEXT: "end": { # CHECK-NEXT:"character": 28, Modified: clang-tools-extra/trunk/test/clangd/execute-command.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/execute-command.test?rev=352764=352763=352764=diff == --- clang-tools-extra/trunk/test/clangd/execute-command.test (original) +++ clang-tools-extra/trunk/test/clangd/execute-command.test Thu Jan 31 08:09:25 2019 @@ -6,7 +6,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT:"diagnostics": [ # CHECK-NEXT: { -#
r352755 - Revert "[Sanitizers] UBSan unreachable incompatible with ASan in the presence of `noreturn` calls"
Author: ioeric Date: Thu Jan 31 06:20:02 2019 New Revision: 352755 URL: http://llvm.org/viewvc/llvm-project?rev=352755=rev Log: Revert "[Sanitizers] UBSan unreachable incompatible with ASan in the presence of `noreturn` calls" This reverts commit r352690. This causes clang to crash. Sent reproducer to the author in the orginal commit. Removed: cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c Modified: cfe/trunk/lib/CodeGen/CGCall.cpp cfe/trunk/lib/CodeGen/CodeGenFunction.h cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp Modified: cfe/trunk/lib/CodeGen/CGCall.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=352755=352754=352755=diff == --- cfe/trunk/lib/CodeGen/CGCall.cpp (original) +++ cfe/trunk/lib/CodeGen/CGCall.cpp Thu Jan 31 06:20:02 2019 @@ -4398,23 +4398,10 @@ RValue CodeGenFunction::EmitCall(const C // Strip away the noreturn attribute to better diagnose unreachable UB. if (SanOpts.has(SanitizerKind::Unreachable)) { - // Also remove from function since CI->hasFnAttr(..) also checks attributes - // of the called function. if (auto *F = CI->getCalledFunction()) F->removeFnAttr(llvm::Attribute::NoReturn); CI->removeAttribute(llvm::AttributeList::FunctionIndex, llvm::Attribute::NoReturn); - - // Avoid incompatibility with ASan which relies on the `noreturn` - // attribute to insert handler calls. - if (SanOpts.has(SanitizerKind::Address)) { -SanitizerScope SanScope(this); -Builder.SetInsertPoint(CI); -auto *FnType = llvm::FunctionType::get(CGM.VoidTy, /*isVarArg=*/false); -auto *Fn = CGM.CreateRuntimeFunction(FnType, "__asan_handle_no_return"); -EmitNounwindRuntimeCall(Fn); -Builder.SetInsertPoint(CI->getParent()); - } } EmitUnreachable(Loc); Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=352755=352754=352755=diff == --- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original) +++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Thu Jan 31 06:20:02 2019 @@ -4084,8 +4084,8 @@ public: /// passing to a runtime sanitizer handler. llvm::Constant *EmitCheckSourceLocation(SourceLocation Loc); - /// Create a basic block that will either trap or call a handler function in - /// the UBSan runtime with the provided arguments, and create a conditional + /// Create a basic block that will call a handler function in a + /// sanitizer runtime with the provided arguments, and create a conditional /// branch to it. void EmitCheck(ArrayRef> Checked, SanitizerHandler Check, ArrayRef StaticArgs, Removed: cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c?rev=352754=auto == --- cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c (original) +++ cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c (removed) @@ -1,21 +0,0 @@ -// Ensure compatiblity of UBSan unreachable with ASan in the presence of -// noreturn functions. -// RUN: %clang_cc1 -fsanitize=unreachable,address -triple x86_64-linux -emit-llvm -o - %s | FileCheck %s - -void my_longjmp(void) __attribute__((noreturn)); - -// CHECK-LABEL: define void @calls_noreturn() -void calls_noreturn() { - my_longjmp(); - // CHECK: @__asan_handle_no_return{{.*}} !nosanitize - // CHECK-NEXT: @my_longjmp(){{[^#]*}} - // CHECK: @__asan_handle_no_return() - // CHECK-NEXT: @__ubsan_handle_builtin_unreachable{{.*}} !nosanitize - // CHECK-NEXT: unreachable -} - -// CHECK: declare void @my_longjmp() [[FN_ATTR:#[0-9]+]] -// CHECK: declare void @__asan_handle_no_return() - -// CHECK-LABEL: attributes -// CHECK-NOT: [[FN_ATTR]] = { {{.*noreturn.*}} } Modified: cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp?rev=352755=352754=352755=diff == --- cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp (original) +++ cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp Thu Jan 31 06:20:02 2019 @@ -1,37 +1,39 @@ // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=unreachable | FileCheck %s -void abort() __attribute__((noreturn)); +extern void __attribute__((noreturn)) abort(); -// CHECK-LABEL: define void @_Z14calls_noreturnv() +// CHECK-LABEL: define void @_Z14calls_noreturnv void calls_noreturn() { - // Check absence ([^#]*) of call site attributes (including noreturn) - // CHECK: call void @_Z5abortv(){{[^#]*}} abort(); + // Check that there are no attributes on the call site. + //
Re: r352690 - [Sanitizers] UBSan unreachable incompatible with ASan in the presence of `noreturn` calls
And the stack trace is: ``` 1. parser at end of file [31/1788] 2. Code generation 3. Running pass 'Function Pass Manager' on module 'absl/base/internal/throw_delegate.cc'. 4. Running pass 'X86 DAG->DAG Instruction Selection' on function '@_ZN4absl13base_internal18ThrowStdLogicErrorERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE' #0 0x55c42e7bce9d SignalHandler(int) (bin/clang+0x1aabe9d) #1 0x7f41b11309a0 __restore_rt (/usr/grte/v4/lib64/libpthread.so.0+0xf9a0) #2 0x55c42fe10b5b findUnwindDestinations(llvm::FunctionLoweringInfo&, llvm::BasicBlock const*, llvm::BranchProbability, llvm::SmallVectorImpl >&) (bin/clang+0x30ffb5b) #3 0x55c42fe0b49a llvm::SelectionDAGBuilder::visitInvoke(llvm::InvokeInst const&) (bin/clang+0x30fa49a) #4 0x55c4308a8a2f llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) (bin/clang+0x3b97a2f) #5 0x55c430878aa5 llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator, false, true>, llvm::ilist_iterator, false, true>, bool&) (bin/clang+0x3b67aa5) #6 0x55c4308768ed llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (bin/clang+0x3b658 ed) #7 0x55c43087354a llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (bin/clang+0x3b62 54a) #8 0x55c43086d1da (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) ( bin/clang+0x3b5c1da) #9 0x55c4309eb833 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (bin/clang+0x3cda833) #10 0x55c43070edbe llvm::FPPassManager::runOnFunction(llvm::Function&) (bin/clang+0x39fddbe) #11 0x55c430711521 llvm::FPPassManager::runOnModule(llvm::Module&) (bin/clang+0x3a00521) #12 0x55c42e4a6f7f llvm::legacy::PassManagerImpl::run(llvm::Module&) (bin/clang+0x1795f7f) #13 0x55c42e7d9594 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayou t const&, llvm::Module*, clang::BackendAction, std::__g::unique_ptr >) (bin/clang+0x1ac8594) #14 0x55c42e7a4d8c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (bin/clang+0x1a93d8c ) #15 0x55c42e6499b6 clang::ParseAST(clang::Sema&, bool, bool) (bin/clang+0x19389b6) #16 0x55c42e7a8b37 clang::FrontendAction::Execute() (bin/clang+0x1a97b37) #17 0x55c42e7ae75f clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (bin/clang+0x1a9d75f) #18 0x55c42e796cfb clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (bin/clang+0x1a85cfb) #19 0x55c42e791071 cc1_main(llvm::ArrayRef, char const*, void*) (bin/clang+0x1a80071) #20 0x55c42e5c019e main (bin/clang+0x18af19e) #21 0x7f41b0e9ebbd __libc_start_main (/usr/grte/v4/lib64/libc.so.6+0x38bbd) #22 0x55c42e6d44a9 _start (bin/clang+0x19c34a9) clang: error: unable to execute command: Segmentation fault clang: error: clang frontend command failed due to signal (use -v to see invocation) ``` On Thu, Jan 31, 2019 at 3:11 PM Eric Liu wrote: > I managed to get a reproducer (attached) from absl: > ``` > clang++ -std=c++17 -fsanitize=address,unreachable throw_delegate.pic.ii > ``` > > You could regenerate the preprocessed code: > ``` > git clone https://github.com/abseil/abseil-cpp.git > cd abseil-cpp/absl > bazel build --compilation_mode=fastbuild --save_temps > --compile_one_dependency base/internal/throw_delegate.cc > ``` > > I'll revert the commit to unblock our integration process. Let us know if > you need more information. > > - Eric > > On Thu, Jan 31, 2019 at 9:01 AM Eric Christopher > wrote: > >> Looks like this broke optimized asan builds via an assert in SCCP. I'll >> see what I can do about a testcase (or Eric will), however, would you mind >> reverting in the meantime? >> >> Thanks! >> >> -eric >> >> On Wed, Jan 30, 2019 at 4:41 PM Julian Lettner via cfe-commits < >> cfe-commits@lists.llvm.org> wrote: >> >>> Author: yln >>> Date: Wed Jan 30 15:42:13 2019 >>> New Revision: 352690 >>> >>> URL: http://llvm.org/viewvc/llvm-project?rev=352690=rev >>> Log: >>> [Sanitizers] UBSan unreachable incompatible with ASan in the presence of >>> `noreturn` calls >>> >>> Summary: >>> UBSan wants to detect when unreachable code is actually reached, so it >>> adds instrumentation before every unreachable instruction. However, the >>> optimizer will remove code after calls to functions marked with >>> noreturn. To avoid this UBSan removes noreturn from both the call >>> instruction as well as from the function itself. Unfortunately, ASan >>> relies on this annotation to unpoison the stack by inserting calls to >>> _asan_handle_no_return before noreturn functions. This is important for >>> functions that do not return but access the the stack memory, e.g., >>> unwinder functions *like* longjmp (longjmp itself is actually >>> "double-proofed" via its interceptor). The result is that
r352618 - [OpenGL] Fix test on PPC after r352540
Author: ioeric Date: Wed Jan 30 03:24:04 2019 New Revision: 352618 URL: http://llvm.org/viewvc/llvm-project?rev=352618=rev Log: [OpenGL] Fix test on PPC after r352540 Summary: Specify -triple like test/SemaOpenCL/logical-ops.cl. Otherwise, this test fails on PPC. Reviewers: bkramer Subscribers: Anastasia, cfe-commits Differential Revision: https://reviews.llvm.org/D57442 Modified: cfe/trunk/test/SemaOpenCL/format-strings-fixit.cl Modified: cfe/trunk/test/SemaOpenCL/format-strings-fixit.cl URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/format-strings-fixit.cl?rev=352618=352617=352618=diff == --- cfe/trunk/test/SemaOpenCL/format-strings-fixit.cl (original) +++ cfe/trunk/test/SemaOpenCL/format-strings-fixit.cl Wed Jan 30 03:24:04 2019 @@ -1,7 +1,7 @@ // RUN: cp %s %t -// RUN: %clang_cc1 -cl-std=CL1.2 -pedantic -Wall -fixit %t -// RUN: %clang_cc1 -cl-std=CL1.2 -fsyntax-only -pedantic -Wall -Werror %t -// RUN: %clang_cc1 -cl-std=CL1.2 -E -o - %t | FileCheck %s +// RUN: %clang_cc1 -cl-std=CL1.2 -pedantic -Wall -fixit %t -triple x86_64-unknown-linux-gnu +// RUN: %clang_cc1 -cl-std=CL1.2 -fsyntax-only -pedantic -Wall -Werror %t -triple x86_64-unknown-linux-gnu +// RUN: %clang_cc1 -cl-std=CL1.2 -E -o - %t -triple x86_64-unknown-linux-gnu | FileCheck %s #pragma OPENCL EXTENSION cl_khr_fp64 : enable ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r352503 - [Tooling] Handle #pragma once header guard in include insertion.
Author: ioeric Date: Tue Jan 29 06:40:01 2019 New Revision: 352503 URL: http://llvm.org/viewvc/llvm-project?rev=352503=rev Log: [Tooling] Handle #pragma once header guard in include insertion. Reviewers: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D57223 Modified: cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp cfe/trunk/unittests/Tooling/HeaderIncludesTest.cpp Modified: cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp?rev=352503=352502=352503=diff == --- cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp (original) +++ cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp Tue Jan 29 06:40:01 2019 @@ -9,6 +9,7 @@ #include "clang/Tooling/Inclusions/HeaderIncludes.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/Lexer.h" +#include "llvm/ADT/Optional.h" #include "llvm/Support/FormatVariadic.h" namespace clang { @@ -50,12 +51,16 @@ unsigned getOffsetAfterTokenSequence( // Check if a sequence of tokens is like "# ". If it is, // \p Tok will be the token after this directive; otherwise, it can be any token -// after the given \p Tok (including \p Tok). -bool checkAndConsumeDirectiveWithName(Lexer , StringRef Name, Token ) { +// after the given \p Tok (including \p Tok). If \p RawIDName is provided, the +// (second) raw_identifier name is checked. +bool checkAndConsumeDirectiveWithName( +Lexer , StringRef Name, Token , +llvm::Optional RawIDName = llvm::None) { bool Matched = Tok.is(tok::hash) && !Lex.LexFromRawLexer(Tok) && Tok.is(tok::raw_identifier) && Tok.getRawIdentifier() == Name && !Lex.LexFromRawLexer(Tok) && - Tok.is(tok::raw_identifier); + Tok.is(tok::raw_identifier) && + (!RawIDName || Tok.getRawIdentifier() == *RawIDName); if (Matched) Lex.LexFromRawLexer(Tok); return Matched; @@ -68,24 +73,45 @@ void skipComments(Lexer , Token } // Returns the offset after header guard directives and any comments -// before/after header guards. If no header guard presents in the code, this -// will returns the offset after skipping all comments from the start of the -// code. +// before/after header guards (e.g. #ifndef/#define pair, #pragma once). If no +// header guard is present in the code, this will return the offset after +// skipping all comments from the start of the code. unsigned getOffsetAfterHeaderGuardsAndComments(StringRef FileName, StringRef Code, const IncludeStyle ) { - return getOffsetAfterTokenSequence( - FileName, Code, Style, - [](const SourceManager , Lexer , Token Tok) { -skipComments(Lex, Tok); -unsigned InitialOffset = SM.getFileOffset(Tok.getLocation()); -if (checkAndConsumeDirectiveWithName(Lex, "ifndef", Tok)) { - skipComments(Lex, Tok); - if (checkAndConsumeDirectiveWithName(Lex, "define", Tok)) -return SM.getFileOffset(Tok.getLocation()); -} -return InitialOffset; - }); + // \p Consume returns location after header guard or 0 if no header guard is + // found. + auto ConsumeHeaderGuardAndComment = + [&](std::function + Consume) { +return getOffsetAfterTokenSequence( +FileName, Code, Style, +[](const SourceManager , Lexer , Token Tok) { + skipComments(Lex, Tok); + unsigned InitialOffset = SM.getFileOffset(Tok.getLocation()); + return std::max(InitialOffset, Consume(SM, Lex, Tok)); +}); + }; + return std::max( + // #ifndef/#define + ConsumeHeaderGuardAndComment( + [](const SourceManager , Lexer , Token Tok) -> unsigned { +if (checkAndConsumeDirectiveWithName(Lex, "ifndef", Tok)) { + skipComments(Lex, Tok); + if (checkAndConsumeDirectiveWithName(Lex, "define", Tok)) +return SM.getFileOffset(Tok.getLocation()); +} +return 0; + }), + // #pragma once + ConsumeHeaderGuardAndComment( + [](const SourceManager , Lexer , Token Tok) -> unsigned { +if (checkAndConsumeDirectiveWithName(Lex, "pragma", Tok, + StringRef("once"))) + return SM.getFileOffset(Tok.getLocation()); +return 0; + })); } // Check if a sequence of tokens is like Modified: cfe/trunk/unittests/Tooling/HeaderIncludesTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/HeaderIncludesTest.cpp?rev=352503=352502=352503=diff == ---
[clang-tools-extra] r352361 - [clangd] Suggest adding missing includes for incomplete type diagnostics.
Author: ioeric Date: Mon Jan 28 06:01:55 2019 New Revision: 352361 URL: http://llvm.org/viewvc/llvm-project?rev=352361=rev Log: [clangd] Suggest adding missing includes for incomplete type diagnostics. Summary: This enables clangd to intercept compiler diagnostics and attach fixes (e.g. by querying index). This patch adds missing includes for incomplete types e.g. member access into class with only forward declaration. This would allow adding missing includes for user-typed symbol names that are missing declarations (e.g. typos) in the future. Reviewers: sammccall Reviewed By: sammccall Subscribers: mgorny, ilya-biryukov, javed.absar, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D56903 Added: clang-tools-extra/trunk/clangd/IncludeFixer.cpp clang-tools-extra/trunk/clangd/IncludeFixer.h clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp - copied, changed from r352290, clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt clang-tools-extra/trunk/clangd/ClangdServer.cpp clang-tools-extra/trunk/clangd/ClangdServer.h clang-tools-extra/trunk/clangd/ClangdUnit.cpp clang-tools-extra/trunk/clangd/ClangdUnit.h clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/clangd/Compiler.h clang-tools-extra/trunk/clangd/Diagnostics.cpp clang-tools-extra/trunk/clangd/Diagnostics.h clang-tools-extra/trunk/clangd/Headers.cpp clang-tools-extra/trunk/clangd/Headers.h clang-tools-extra/trunk/clangd/SourceCode.cpp clang-tools-extra/trunk/clangd/SourceCode.h clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp clang-tools-extra/trunk/unittests/clangd/TestIndex.cpp clang-tools-extra/trunk/unittests/clangd/TestIndex.h clang-tools-extra/trunk/unittests/clangd/TestTU.cpp clang-tools-extra/trunk/unittests/clangd/TestTU.h Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=352361=352360=352361=diff == --- clang-tools-extra/trunk/clangd/CMakeLists.txt (original) +++ clang-tools-extra/trunk/clangd/CMakeLists.txt Mon Jan 28 06:01:55 2019 @@ -40,6 +40,7 @@ add_clang_library(clangDaemon FuzzyMatch.cpp GlobalCompilationDatabase.cpp Headers.cpp + IncludeFixer.cpp JSONTransport.cpp Logger.cpp Protocol.cpp Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=352361=352360=352361=diff == --- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Jan 28 06:01:55 2019 @@ -7,6 +7,7 @@ //===---===// #include "ClangdServer.h" +#include "ClangdUnit.h" #include "CodeComplete.h" #include "FindSymbols.h" #include "Headers.h" @@ -106,6 +107,7 @@ ClangdServer::ClangdServer(const GlobalC ? new FileIndex(Opts.HeavyweightDynamicSymbolIndex) : nullptr), ClangTidyOptProvider(Opts.ClangTidyOptProvider), + SuggestMissingIncludes(Opts.SuggestMissingIncludes), WorkspaceRoot(Opts.WorkspaceRoot), PCHs(std::make_shared()), // Pass a callback into `WorkScheduler` to extract symbols from a newly @@ -141,17 +143,22 @@ ClangdServer::ClangdServer(const GlobalC void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents, WantDiagnostics WantDiags) { - tidy::ClangTidyOptions Options = tidy::ClangTidyOptions::getDefaults(); + ParseOptions Opts; + Opts.ClangTidyOpts = tidy::ClangTidyOptions::getDefaults(); if (ClangTidyOptProvider) -Options = ClangTidyOptProvider->getOptions(File); +Opts.ClangTidyOpts = ClangTidyOptProvider->getOptions(File); + Opts.SuggestMissingIncludes = SuggestMissingIncludes; // FIXME: some build systems like Bazel will take time to preparing // environment to build the file, it would be nice if we could emit a // "PreparingBuild" status to inform users, it is non-trivial given the // current implementation. - WorkScheduler.update(File, ParseInputs{getCompileCommand(File), - FSProvider.getFileSystem(), - Contents.str(), Options}, - WantDiags); + ParseInputs
[clang-tools-extra] r351813 - [clangd] NFC: reduce log noise from Diagnostics.
Author: ioeric Date: Tue Jan 22 04:55:27 2019 New Revision: 351813 URL: http://llvm.org/viewvc/llvm-project?rev=351813=rev Log: [clangd] NFC: reduce log noise from Diagnostics. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D57042 Modified: clang-tools-extra/trunk/clangd/Diagnostics.cpp Modified: clang-tools-extra/trunk/clangd/Diagnostics.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Diagnostics.cpp?rev=351813=351812=351813=diff == --- clang-tools-extra/trunk/clangd/Diagnostics.cpp (original) +++ clang-tools-extra/trunk/clangd/Diagnostics.cpp Tue Jan 22 04:55:27 2019 @@ -403,8 +403,8 @@ void StoreDiags::flushLastDiag() { if (mentionsMainFile(*LastDiag)) Output.push_back(std::move(*LastDiag)); else -log("Dropped diagnostic outside main file: {0}: {1}", LastDiag->File, -LastDiag->Message); +vlog("Dropped diagnostic outside main file: {0}: {1}", LastDiag->File, + LastDiag->Message); LastDiag.reset(); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r349502 - [clangd] Try to fix buildbot failure after r349496
Author: ioeric Date: Tue Dec 18 08:06:29 2018 New Revision: 349502 URL: http://llvm.org/viewvc/llvm-project?rev=349502=rev Log: [clangd] Try to fix buildbot failure after r349496 Increase timeout from 10ms to 100ms. See http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/27959 Modified: clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp Modified: clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp?rev=349502=349501=349502=diff == --- clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp Tue Dec 18 08:06:29 2018 @@ -251,7 +251,7 @@ TEST_F(BackgroundIndexTest, PeriodicalIn OverlayCDB CDB(/*Base=*/nullptr); BackgroundIndex Idx( Context::empty(), "", FS, CDB, [&](llvm::StringRef) { return }, - /*BuildIndexPeriodMs=*/10); + /*BuildIndexPeriodMs=*/100); FS.Files[testPath("root/A.cc")] = "#include \"A.h\""; @@ -263,7 +263,7 @@ TEST_F(BackgroundIndexTest, PeriodicalIn ASSERT_TRUE(Idx.blockUntilIdleForTest()); EXPECT_THAT(runFuzzyFind(Idx, ""), ElementsAre()); - std::this_thread::sleep_for(std::chrono::milliseconds(15)); + std::this_thread::sleep_for(std::chrono::milliseconds(150)); EXPECT_THAT(runFuzzyFind(Idx, ""), ElementsAre(Named("X"))); FS.Files[testPath("root/A.h")] = "class Y {};"; @@ -273,7 +273,7 @@ TEST_F(BackgroundIndexTest, PeriodicalIn ASSERT_TRUE(Idx.blockUntilIdleForTest()); EXPECT_THAT(runFuzzyFind(Idx, ""), ElementsAre(Named("X"))); - std::this_thread::sleep_for(std::chrono::milliseconds(15)); + std::this_thread::sleep_for(std::chrono::milliseconds(150)); EXPECT_THAT(runFuzzyFind(Idx, ""), ElementsAre(Named("Y"))); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r349496 - [clangd] BackgroundIndex rebuilds symbol index periodically.
Author: ioeric Date: Tue Dec 18 07:39:33 2018 New Revision: 349496 URL: http://llvm.org/viewvc/llvm-project?rev=349496=rev Log: [clangd] BackgroundIndex rebuilds symbol index periodically. Summary: Currently, background index rebuilds symbol index on every indexed file, which can be inefficient. This patch makes it only rebuild symbol index periodically. As the rebuild no longer happens too often, we could also build more efficient dex index. Reviewers: ilya-biryukov, kadircet Reviewed By: kadircet Subscribers: dblaikie, MaskRay, jkorous, arphaman, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D55770 Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp clang-tools-extra/trunk/clangd/ClangdServer.h clang-tools-extra/trunk/clangd/index/Background.cpp clang-tools-extra/trunk/clangd/index/Background.h clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp clang-tools-extra/trunk/test/clangd/background-index.test clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=349496=349495=349496=diff == --- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Dec 18 07:39:33 2018 @@ -139,7 +139,8 @@ ClangdServer::ClangdServer(const GlobalC if (Opts.BackgroundIndex) { BackgroundIdx = llvm::make_unique( Context::current().clone(), ResourceDir, FSProvider, CDB, -BackgroundIndexStorage::createDiskBackedStorageFactory()); +BackgroundIndexStorage::createDiskBackedStorageFactory(), +Opts.BackgroundIndexRebuildPeriodMs); AddIndex(BackgroundIdx.get()); } if (DynamicIdx) Modified: clang-tools-extra/trunk/clangd/ClangdServer.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=349496=349495=349496=diff == --- clang-tools-extra/trunk/clangd/ClangdServer.h (original) +++ clang-tools-extra/trunk/clangd/ClangdServer.h Tue Dec 18 07:39:33 2018 @@ -85,6 +85,10 @@ public: /// If true, ClangdServer automatically indexes files in the current project /// on background threads. The index is stored in the project root. bool BackgroundIndex = false; +/// If set to non-zero, the background index rebuilds the symbol index +/// periodically every BuildIndexPeriodMs milliseconds; otherwise, the +/// symbol index will be updated for each indexed file. +size_t BackgroundIndexRebuildPeriodMs = 0; /// If set, use this index to augment code completion results. SymbolIndex *StaticIndex = nullptr; Modified: clang-tools-extra/trunk/clangd/index/Background.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=349496=349495=349496=diff == --- clang-tools-extra/trunk/clangd/index/Background.cpp (original) +++ clang-tools-extra/trunk/clangd/index/Background.cpp Tue Dec 18 07:39:33 2018 @@ -27,11 +27,13 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/SHA1.h" +#include #include #include #include #include #include +#include using namespace llvm; namespace clang { @@ -125,10 +127,13 @@ createFileFilter(const llvm::StringMap()), ResourceDir(ResourceDir), FSProvider(FSProvider), CDB(CDB), BackgroundContext(std::move(BackgroundContext)), + BuildIndexPeriodMs(BuildIndexPeriodMs), + SymbolsUpdatedSinceLastIndex(false), IndexStorageFactory(std::move(IndexStorageFactory)), CommandsChanged( CDB.watch([&](const std::vector ) { @@ -138,6 +143,11 @@ BackgroundIndex::BackgroundIndex( assert(this->IndexStorageFactory && "Storage factory can not be null!"); while (ThreadPoolSize--) ThreadPool.emplace_back([this] { run(); }); + if (BuildIndexPeriodMs > 0) { +log("BackgroundIndex: build symbol index periodically every {0} ms.", +BuildIndexPeriodMs); +ThreadPool.emplace_back([this] { buildIndex(); }); + } } BackgroundIndex::~BackgroundIndex() { @@ -148,10 +158,12 @@ BackgroundIndex::~BackgroundIndex() { void BackgroundIndex::stop() { { -std::lock_guard Lock(QueueMu); +std::lock_guard QueueLock(QueueMu); +std::lock_guard IndexLock(IndexMu); ShouldStop = true; } QueueCV.notify_all(); + IndexCV.notify_all(); } void BackgroundIndex::run() { @@ -332,6 +344,30 @@ void BackgroundIndex::update(StringRef M } } +void BackgroundIndex::buildIndex() { + assert(BuildIndexPeriodMs > 0); + while (true) { +{ + std::unique_lock Lock(IndexMu); + if (ShouldStop) // Avoid waiting if stopped. +break; + // Wait until this is notified to
[clang-tools-extra] r349049 - [clangd] Enable cross-namespace completions by default in clangd
Author: ioeric Date: Thu Dec 13 07:35:43 2018 New Revision: 349049 URL: http://llvm.org/viewvc/llvm-project?rev=349049=rev Log: [clangd] Enable cross-namespace completions by default in clangd Summary: Code completion will suggest symbols from any scope (incl. inaccessible scopes) when there's no qualifier explicitly specified. E.g. {F7689815} As we are assigning relatively low scores for cross-namespace completion items, the overall code completion quality doesn't regress. The feature has been tried out by a few folks, and the feedback is generally positive, so I think it should be ready to be enabled by default. Reviewers: hokein, ilya-biryukov, kadircet Reviewed By: hokein, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D55649 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=349049=349048=349049=diff == --- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original) +++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Thu Dec 13 07:35:43 2018 @@ -141,7 +141,7 @@ static cl::opt AllScopesCompletion "not defined in the scopes (e.g. " "namespaces) visible from the code completion point. Such completions " "can insert scope qualifiers."), -cl::init(false), cl::Hidden); +cl::init(true)); static cl::opt ShowOrigins("debug-origin", cl::desc("Show origins of completion items"), ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r347983 - [clangd] Penalize destructor and overloaded operators in code completion.
Author: ioeric Date: Fri Nov 30 03:17:15 2018 New Revision: 347983 URL: http://llvm.org/viewvc/llvm-project?rev=347983=rev Log: [clangd] Penalize destructor and overloaded operators in code completion. Reviewers: hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D55061 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=347983=347982=347983=diff == --- clang-tools-extra/trunk/clangd/Quality.cpp (original) +++ clang-tools-extra/trunk/clangd/Quality.cpp Fri Nov 30 03:17:15 2018 @@ -62,6 +62,10 @@ static bool hasUsingDeclInMainFile(const } static SymbolQualitySignals::SymbolCategory categorize(const NamedDecl ) { + if (const auto *FD = dyn_cast()) { +if (FD->isOverloadedOperator()) + return SymbolQualitySignals::Operator; + } class Switch : public ConstDeclVisitor { public: @@ -75,6 +79,7 @@ static SymbolQualitySignals::SymbolCateg MAP(TypeAliasTemplateDecl, Type); MAP(ClassTemplateDecl, Type); MAP(CXXConstructorDecl, Constructor); +MAP(CXXDestructorDecl, Destructor); MAP(ValueDecl, Variable); MAP(VarTemplateDecl, Variable); MAP(FunctionDecl, Function); @@ -134,9 +139,10 @@ categorize(const index::SymbolInfo ) { case index::SymbolKind::InstanceProperty: case index::SymbolKind::ClassProperty: case index::SymbolKind::StaticProperty: - case index::SymbolKind::Destructor: case index::SymbolKind::ConversionFunction: return SymbolQualitySignals::Function; + case index::SymbolKind::Destructor: +return SymbolQualitySignals::Destructor; case index::SymbolKind::Constructor: return SymbolQualitySignals::Constructor; case index::SymbolKind::Variable: @@ -231,10 +237,12 @@ float SymbolQualitySignals::evaluate() c Score *= 0.8f; break; case Macro: + case Destructor: + case Operator: Score *= 0.5f; break; - case Unknown: case Constructor: // No boost constructors so they are after class types. + case Unknown: break; } Modified: clang-tools-extra/trunk/clangd/Quality.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.h?rev=347983=347982=347983=diff == --- clang-tools-extra/trunk/clangd/Quality.h (original) +++ clang-tools-extra/trunk/clangd/Quality.h Fri Nov 30 03:17:15 2018 @@ -68,8 +68,10 @@ struct SymbolQualitySignals { Type, Function, Constructor, +Destructor, Namespace, Keyword, +Operator, } Category = Unknown; void merge(const CodeCompletionResult ); Modified: clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp?rev=347983=347982=347983=diff == --- clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp Fri Nov 30 03:17:15 2018 @@ -205,16 +205,22 @@ TEST(QualityTests, SymbolQualitySignalsS EXPECT_GT(WithReferences.evaluate(), Default.evaluate()); EXPECT_GT(ManyReferences.evaluate(), WithReferences.evaluate()); - SymbolQualitySignals Keyword, Variable, Macro, Constructor, Function; + SymbolQualitySignals Keyword, Variable, Macro, Constructor, Function, + Destructor, Operator; Keyword.Category = SymbolQualitySignals::Keyword; Variable.Category = SymbolQualitySignals::Variable; Macro.Category = SymbolQualitySignals::Macro; Constructor.Category = SymbolQualitySignals::Constructor; + Destructor.Category = SymbolQualitySignals::Destructor; + Destructor.Category = SymbolQualitySignals::Destructor; + Operator.Category = SymbolQualitySignals::Operator; Function.Category = SymbolQualitySignals::Function; EXPECT_GT(Variable.evaluate(), Default.evaluate()); EXPECT_GT(Keyword.evaluate(), Variable.evaluate()); EXPECT_LT(Macro.evaluate(), Default.evaluate()); + EXPECT_LT(Operator.evaluate(), Default.evaluate()); EXPECT_LT(Constructor.evaluate(), Function.evaluate()); + EXPECT_LT(Destructor.evaluate(), Constructor.evaluate()); } TEST(QualityTests, SymbolRelevanceSignalsSanity) { @@ -385,11 +391,12 @@ TEST(QualityTests, IsInstanceMember) { EXPECT_TRUE(Rel.IsInstanceMember); } -TEST(QualityTests, ConstructorQuality) { +TEST(QualityTests, ConstructorDestructor) { auto Header = TestTU::withHeaderCode(R"cpp( class Foo { public: Foo(int); + ~Foo(); }; )cpp"); auto Symbols = Header.headerSymbols(); @@
[clang-tools-extra] r347982 - [clangd] Drop injected class name when class scope is not explicitly specified.
Author: ioeric Date: Fri Nov 30 03:12:40 2018 New Revision: 347982 URL: http://llvm.org/viewvc/llvm-project?rev=347982=rev Log: [clangd] Drop injected class name when class scope is not explicitly specified. Summary: E.g. allow injected "A::A" in `using A::A^` but not in "A^". Reviewers: kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D55065 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=347982=347981=347982=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Fri Nov 30 03:12:40 2018 @@ -656,6 +656,13 @@ bool contextAllowsIndex(enum CodeComplet llvm_unreachable("unknown code completion context"); } +static bool isInjectedClass(const NamedDecl ) { + if (auto *R = dyn_cast_or_null()) +if (R->isInjectedClassName()) + return true; + return false; +} + // Some member calls are blacklisted because they're so rarely useful. static bool isBlacklistedMember(const NamedDecl ) { // Destructor completion is rarely useful, and works inconsistently. @@ -663,9 +670,8 @@ static bool isBlacklistedMember(const Na if (D.getKind() == Decl::CXXDestructor) return true; // Injected name may be useful for A::foo(), but who writes A::A::foo()? - if (auto *R = dyn_cast_or_null()) -if (R->isInjectedClassName()) - return true; + if (isInjectedClass(D)) +return true; // Explicit calls to operators are also rare. auto NameKind = D.getDeclName().getNameKind(); if (NameKind == DeclarationName::CXXOperatorName || @@ -744,6 +750,11 @@ struct CompletionRecorder : public CodeC !Context.getBaseType().isNull() // is this a member-access context? && isBlacklistedMember(*Result.Declaration)) continue; + // Skip injected class name when no class scope is not explicitly set. + // E.g. show injected A::A in `using A::A^` but not in "A^". + if (Result.Declaration && !Context.getCXXScopeSpecifier().hasValue() && + isInjectedClass(*Result.Declaration)) +continue; // We choose to never append '::' to completion results in clangd. Result.StartsNestedNameSpecifier = false; Results.push_back(Result); 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=347982=347981=347982=diff == --- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Fri Nov 30 03:12:40 2018 @@ -416,6 +416,11 @@ TEST(CompletionTest, InjectedTypename) { Has("X")); } +TEST(CompletionTest, SkipInjectedWhenUnqualified) { + EXPECT_THAT(completions("struct X { void f() { X^ }};").Completions, + ElementsAre(Named("X"), Named("~X"))); +} + TEST(CompletionTest, Snippets) { clangd::CodeCompleteOptions Opts; auto Results = completions( ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r347755 - [clangd] Fix test broken in r347754.
Author: ioeric Date: Wed Nov 28 06:00:09 2018 New Revision: 347755 URL: http://llvm.org/viewvc/llvm-project?rev=347755=rev Log: [clangd] Fix test broken in r347754. 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=347755=347754=347755=diff == --- clang-tools-extra/trunk/clangd/Quality.cpp (original) +++ clang-tools-extra/trunk/clangd/Quality.cpp Wed Nov 28 06:00:09 2018 @@ -325,7 +325,7 @@ static float scopeBoost(ScopeDistance auto D = Distance.distance(*SymbolScope); if (D == FileDistance::Unreachable) return 0.6f; - return std::max(0.6, 2.0 * std::pow(0.6, D / 2.0)); + return std::max(0.65, 2.0 * std::pow(0.6, D / 2.0)); } float SymbolRelevanceSignals::evaluate() const { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r347754 - [clangd] Less penalty for cross-namespace completions.
Author: ioeric Date: Wed Nov 28 05:45:25 2018 New Revision: 347754 URL: http://llvm.org/viewvc/llvm-project?rev=347754=rev Log: [clangd] Less penalty for cross-namespace 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=347754=347753=347754=diff == --- clang-tools-extra/trunk/clangd/Quality.cpp (original) +++ clang-tools-extra/trunk/clangd/Quality.cpp Wed Nov 28 05:45:25 2018 @@ -324,8 +324,8 @@ static float scopeBoost(ScopeDistance return 1; auto D = Distance.distance(*SymbolScope); if (D == FileDistance::Unreachable) -return 0.4f; - return std::max(0.5, 2.0 * std::pow(0.6, D / 2.0)); +return 0.6f; + return std::max(0.6, 2.0 * std::pow(0.6, D / 2.0)); } float SymbolRelevanceSignals::evaluate() const { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r347739 - [clangd] Canonicalize file path in URIForFile.
Author: ioeric Date: Wed Nov 28 02:30:42 2018 New Revision: 347739 URL: http://llvm.org/viewvc/llvm-project?rev=347739=rev Log: [clangd] Canonicalize file path in URIForFile. Summary: File paths in URIForFile can come from index or local AST. Path from index goes through URI transformation and the final path is resolved by URI scheme and could be potentially different from the original path. Hence, we should do the same transformation for all paths. We do this in URIForFile, which now converts a path to URI and back to a canonicalized path. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D54845 Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp clang-tools-extra/trunk/clangd/FindSymbols.cpp clang-tools-extra/trunk/clangd/Protocol.cpp clang-tools-extra/trunk/clangd/Protocol.h clang-tools-extra/trunk/clangd/URI.cpp clang-tools-extra/trunk/clangd/URI.h clang-tools-extra/trunk/clangd/XRefs.cpp clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp clang-tools-extra/trunk/unittests/clangd/TestFS.cpp clang-tools-extra/trunk/unittests/clangd/URITests.cpp clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=347739=347738=347739=diff == --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Wed Nov 28 02:30:42 2018 @@ -775,7 +775,7 @@ std::vector ClangdLSPServer::getFix void ClangdLSPServer::onDiagnosticsReady(PathRef File, std::vector Diagnostics) { - URIForFile URI(File); + auto URI = URIForFile::canonicalize(File, /*TUPath=*/File); std::vector LSPDiagnostics; DiagnosticToReplacementMap LocalFixIts; // Temporary storage for (auto : Diagnostics) { Modified: clang-tools-extra/trunk/clangd/FindSymbols.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FindSymbols.cpp?rev=347739=347738=347739=diff == --- clang-tools-extra/trunk/clangd/FindSymbols.cpp (original) +++ clang-tools-extra/trunk/clangd/FindSymbols.cpp Wed Nov 28 02:30:42 2018 @@ -142,7 +142,9 @@ getWorkspaceSymbols(StringRef Query, int return; } Location L; -L.uri = URIForFile((*Path)); +// Use HintPath as TUPath since there is no TU associated with this +// request. +L.uri = URIForFile::canonicalize(*Path, HintPath); Position Start, End; Start.line = CD.Start.line(); Start.character = CD.Start.column(); Modified: clang-tools-extra/trunk/clangd/Protocol.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=347739=347738=347739=diff == --- clang-tools-extra/trunk/clangd/Protocol.cpp (original) +++ clang-tools-extra/trunk/clangd/Protocol.cpp Wed Nov 28 02:30:42 2018 @@ -30,29 +30,44 @@ namespace clangd { char LSPError::ID; -URIForFile::URIForFile(std::string AbsPath) { +URIForFile URIForFile::canonicalize(StringRef AbsPath, StringRef TUPath) { assert(sys::path::is_absolute(AbsPath) && "the path is relative"); - File = std::move(AbsPath); + auto Resolved = URI::resolvePath(AbsPath, TUPath); + if (!Resolved) { +elog("URIForFile: failed to resolve path {0} with TU path {1}: " + "{2}.\nUsing unresolved path.", + AbsPath, TUPath, Resolved.takeError()); +return URIForFile(AbsPath); + } + return URIForFile(std::move(*Resolved)); +} + +Expected URIForFile::fromURI(const URI , StringRef HintPath) { + auto Resolved = URI::resolve(U, HintPath); + if (!Resolved) +return Resolved.takeError(); + return URIForFile(std::move(*Resolved)); } bool fromJSON(const json::Value , URIForFile ) { if (auto S = E.getAsString()) { -auto U = URI::parse(*S); -if (!U) { - elog("Failed to parse URI {0}: {1}", *S, U.takeError()); +auto Parsed = URI::parse(*S); +if (!Parsed) { + elog("Failed to parse URI {0}: {1}", *S, Parsed.takeError()); return false; } -if (U->scheme() != "file" && U->scheme() != "test") { +if (Parsed->scheme() != "file" && Parsed->scheme() != "test") { elog("Clangd only supports 'file' URI scheme for workspace files: {0}", *S); return false; } -auto Path = URI::resolve(*U); -if (!Path) { - log("{0}", Path.takeError()); +// "file" and "test" schemes do not require hint path. +auto U = URIForFile::fromURI(*Parsed, /*HintPath=*/""); +if (!U) { + elog("{0}",
[clang-tools-extra] r347548 - [clangd] Tune down scope boost for global scope
Author: ioeric Date: Mon Nov 26 04:12:01 2018 New Revision: 347548 URL: http://llvm.org/viewvc/llvm-project?rev=347548=rev Log: [clangd] Tune down scope boost for global scope Summary: This improves cross-namespace completions and has ignorable impact on other completion types. Metrics ``` == OVERALL (excl. CROSS_NAMESPACE) == Total measurements: 109367 (-6) All measurements: MRR: 68.11 (+0.04) Top-1: 58.59% (+0.03%) Top-5: 80.00% (+0.01%) Top-100: 95.92% (-0.02%) Full identifiers: MRR: 98.35 (+0.09) Top-1: 97.87% (+0.17%) Top-5: 98.96% (+0.01%) Top-100: 99.03% (+0.00%) Filter length 0-5: MRR: 23.20 (+0.05) 58.72 (+0.01) 70.16 (-0.03) 73.44 (+0.03) 76.24 (+0.00) 80.79 (+0.14) Top-1:11.90% (+0.03%) 45.07% (+0.03%) 58.49% (-0.05%) 62.44% (-0.02%) 66.31% (-0.05%) 72.10% (+0.07%) Top-5:35.51% (+0.08%) 76.94% (-0.01%) 85.10% (-0.13%) 87.40% (-0.02%) 88.65% (+0.01%) 91.84% (+0.17%) Top-100: 83.25% (-0.02%) 96.61% (-0.15%) 98.15% (-0.02%) 98.43% (-0.01%) 98.53% (+0.01%) 98.66% (+0.02%) == CROSS_NAMESPACE == Total measurements: 17702 (+27) All measurements: MRR: 28.12 (+3.26) Top-1: 21.07% (+2.70%) Top-5: 35.11% (+4.48%) Top-100: 74.31% (+1.02%) Full identifiers: MRR: 79.20 (+3.72) Top-1: 71.78% (+4.86%) Top-5: 88.39% (+2.84%) Top-100: 98.99% (+0.00%) Filter length 0-5: MRR: 0.92 (-0.10) 5.51 (+0.57)18.30 (+2.34) 21.62 (+3.76) 32.00 (+6.00) 41.55 (+7.61) Top-1:0.56% (-0.08%)2.44% (+0.15%) 9.82% (+1.47%) 12.59% (+2.16%) 21.17% (+4.47%) 30.05% (+6.72%) Top-5:1.20% (-0.15%)7.14% (+1.04%) 25.17% (+3.91%) 29.74% (+5.90%) 43.29% (+9.59%) 54.75% (+9.79%) Top-100: 5.49% (-0.01%)56.22% (+2.59%) 86.69% (+1.08%) 89.03% (+2.04%) 93.74% (+0.78%) 96.99% (+0.59%) ``` Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D54851 Modified: clang-tools-extra/trunk/clangd/FileDistance.cpp Modified: clang-tools-extra/trunk/clangd/FileDistance.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FileDistance.cpp?rev=347548=347547=347548=diff == --- clang-tools-extra/trunk/clangd/FileDistance.cpp (original) +++ clang-tools-extra/trunk/clangd/FileDistance.cpp Mon Nov 26 04:12:01 2018 @@ -196,11 +196,11 @@ static FileDistance createScopeFileDista // symbols in it, and there is pattern where using-namespace is used in // place of enclosing namespaces (e.g. in implementation files). if (S == Preferred) - Param.Cost = S == "" ? 2 : 0; + Param.Cost = S == "" ? 4 : 0; else if (Preferred.startswith(S) && !S.empty()) continue; // just rely on up-traversals. else - Param.Cost = S == "" ? 5 : 2; + Param.Cost = S == "" ? 6 : 2; auto Path = scopeToPath(S); // The global namespace is not 'near' its children. Param.MaxUpTraversals = std::max(Path.second - 1, 0); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r347467 - [clangd] Cleanup: stop passing around list of supported URI schemes.
Author: ioeric Date: Thu Nov 22 07:02:05 2018 New Revision: 347467 URL: http://llvm.org/viewvc/llvm-project?rev=347467=rev Log: [clangd] Cleanup: stop passing around list of supported URI schemes. Summary: Instead of passing around a list of supported URI schemes in clangd, we expose an interface to convert a path to URI using any compatible scheme that has been registered. It favors customized schemes and falls back to "file" when no other scheme works. Changes in this patch are: - URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a compatible scheme from the registry. - Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc). - Unit tests will use "unittest" by default. - Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only register the test scheme when lit-test or enable-lit-scheme is set. (The new flag is added to make lit protocol.test work; I wonder if there is alternative here.) Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D54800 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/URI.cpp clang-tools-extra/trunk/clangd/URI.h clang-tools-extra/trunk/clangd/index/Background.cpp clang-tools-extra/trunk/clangd/index/Background.h clang-tools-extra/trunk/clangd/index/FileIndex.cpp clang-tools-extra/trunk/clangd/index/FileIndex.h clang-tools-extra/trunk/clangd/index/Serialization.cpp clang-tools-extra/trunk/clangd/index/Serialization.h clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp clang-tools-extra/trunk/clangd/index/SymbolCollector.h clang-tools-extra/trunk/clangd/index/dex/Dex.cpp clang-tools-extra/trunk/clangd/index/dex/Dex.h clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp clang-tools-extra/trunk/test/clangd/protocol.test clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp clang-tools-extra/trunk/unittests/clangd/DexTests.cpp clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp clang-tools-extra/trunk/unittests/clangd/TestTU.cpp Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=347467=347466=347467=diff == --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Thu Nov 22 07:02:05 2018 @@ -23,43 +23,6 @@ namespace clang { namespace clangd { namespace { -/// \brief Supports a test URI scheme with relaxed constraints for lit tests. -/// The path in a test URI will be combined with a platform-specific fake -/// directory to form an absolute path. For example, test:///a.cpp is resolved -/// C:\clangd-test\a.cpp on Windows and /clangd-test/a.cpp on Unix. -class TestScheme : public URIScheme { -public: - Expected getAbsolutePath(StringRef /*Authority*/, StringRef Body, -StringRef /*HintPath*/) const override { -using namespace llvm::sys; -// Still require "/" in body to mimic file scheme, as we want lengths of an -// equivalent URI in both schemes to be the same. -if (!Body.startswith("/")) - return make_error( - "Expect URI body to be an absolute path starting with '/': " + Body, - inconvertibleErrorCode()); -Body = Body.ltrim('/'); -#ifdef _WIN32 -constexpr char TestDir[] = "C:\\clangd-test"; -#else -constexpr char TestDir[] = "/clangd-test"; -#endif -SmallVector Path(Body.begin(), Body.end()); -path::native(Path); -auto Err = fs::make_absolute(TestDir, Path); -if (Err) - llvm_unreachable("Failed to make absolute path in test scheme."); -return std::string(Path.begin(), Path.end()); - } - - Expected uriFromAbsolutePath(StringRef AbsolutePath) const override { -llvm_unreachable("Clangd must never create a test URI."); - } -}; - -static URISchemeRegistry::Add -X("test", "Test scheme for clangd lit tests."); - SymbolKindBitset defaultSymbolKinds() { SymbolKindBitset Defaults; for (size_t I = SymbolKindMin; I <= static_cast(SymbolKind::Array); Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=347467=347466=347467=diff
[clang-tools-extra] r347466 - [clangd] Cleanup: use index file instead of header in workspace symbols lit test.
Author: ioeric Date: Thu Nov 22 06:59:22 2018 New Revision: 347466 URL: http://llvm.org/viewvc/llvm-project?rev=347466=rev Log: [clangd] Cleanup: use index file instead of header in workspace symbols lit test. Summary: The full path of the input header depends on the execution environment and may result in different behavior (e.g. when different URI schemes are used). Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D54833 Added: clang-tools-extra/trunk/test/clangd/Inputs/symbols.test.yaml Removed: clang-tools-extra/trunk/test/clangd/Inputs/sstream.h Modified: clang-tools-extra/trunk/test/clangd/symbols.test Removed: clang-tools-extra/trunk/test/clangd/Inputs/sstream.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/Inputs/sstream.h?rev=347465=auto == --- clang-tools-extra/trunk/test/clangd/Inputs/sstream.h (original) +++ clang-tools-extra/trunk/test/clangd/Inputs/sstream.h (removed) @@ -1,3 +0,0 @@ -namespace std { -class basic_ostringstream {}; -} Added: clang-tools-extra/trunk/test/clangd/Inputs/symbols.test.yaml URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/Inputs/symbols.test.yaml?rev=347466=auto == --- clang-tools-extra/trunk/test/clangd/Inputs/symbols.test.yaml (added) +++ clang-tools-extra/trunk/test/clangd/Inputs/symbols.test.yaml Thu Nov 22 06:59:22 2018 @@ -0,0 +1,17 @@ +--- +!Symbol +ID: 057557CEBF6E6B2D +Name:'vector' +Scope: 'std::' +SymInfo: + Kind:Class + Lang:Cpp +CanonicalDeclaration: + FileURI: 'file:///vector.h' + Start: +Line:215 +Column: 10 + End: +Line:215 +Column: 16 +... Modified: clang-tools-extra/trunk/test/clangd/symbols.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/symbols.test?rev=347466=347465=347466=diff == --- clang-tools-extra/trunk/test/clangd/symbols.test (original) +++ clang-tools-extra/trunk/test/clangd/symbols.test Thu Nov 22 06:59:22 2018 @@ -1,9 +1,9 @@ -# RUN: env CPATH=%S/Inputs clangd -lit-test < %s | FileCheck %s +# RUN: clangd --index-file=%S/Inputs/symbols.test.yaml -lit-test < %s | FileCheck %s {"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"workspace":{"symbol":{"symbolKind":{"valueSet": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26],"trace":"off"}} --- -{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"#include \nvoid foo(); int main() { foo(); }\n"}}} +{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"void foo(); int main() { foo(); }\n"}}} --- -{"jsonrpc":"2.0","id":1,"method":"workspace/symbol","params":{"query":"std::basic_ostringstream"}} +{"jsonrpc":"2.0","id":1,"method":"workspace/symbol","params":{"query":"vector"}} # CHECK: "id": 1, # CHECK-NEXT: "jsonrpc": "2.0", # CHECK-NEXT:"result": [ @@ -21,9 +21,9 @@ # CHECK-NEXT: "line": {{.*}} # CHECK-NEXT:} # CHECK-NEXT: }, -# CHECK-NEXT: "uri": "file://{{.*}}/sstream.h" +# CHECK-NEXT: "uri": "file:///vector.h" # CHECK-NEXT:}, -# CHECK-NEXT:"name": "basic_ostringstream" +# CHECK-NEXT:"name": "vector" # CHECK-NEXT: } # CHECK-NEXT:] # CHECK-NEXT:} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r346648 - [clangd] Remember to serialize AnyScope in FuzzyFindRequest json.
Author: ioeric Date: Mon Nov 12 04:24:08 2018 New Revision: 346648 URL: http://llvm.org/viewvc/llvm-project?rev=346648=rev Log: [clangd] Remember to serialize AnyScope in FuzzyFindRequest json. Modified: clang-tools-extra/trunk/clangd/index/Index.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=346648=346647=346648=diff == --- clang-tools-extra/trunk/clangd/index/Index.cpp (original) +++ clang-tools-extra/trunk/clangd/index/Index.cpp Mon Nov 12 04:24:08 2018 @@ -207,7 +207,7 @@ bool fromJSON(const json::Value int64_t Limit; bool OK = O && O.map("Query", Request.Query) && O.map("Scopes", Request.Scopes) && - O.map("Limit", Limit) && + O.map("AnyScope", Request.AnyScope) && O.map("Limit", Limit) && O.map("RestrictForCodeCompletion", Request.RestrictForCodeCompletion) && O.map("ProximityPaths", Request.ProximityPaths); if (OK && Limit <= std::numeric_limits::max()) @@ -219,6 +219,7 @@ json::Value toJSON(const FuzzyFindReques return json::Object{ {"Query", Request.Query}, {"Scopes", json::Array{Request.Scopes}}, + {"AnyScope", Request.AnyScope}, {"Limit", Request.Limit}, {"RestrictForCodeCompletion", Request.RestrictForCodeCompletion}, {"ProximityPaths", json::Array{Request.ProximityPaths}}, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r346224 - [clangd] Deduplicate query scopes.
Author: ioeric Date: Tue Nov 6 03:17:40 2018 New Revision: 346224 URL: http://llvm.org/viewvc/llvm-project?rev=346224=rev Log: [clangd] Deduplicate query scopes. Summary: For example, when anonymous namespace is present, duplicated namespaces might be generated for the enclosing namespace. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D54105 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=346224=346223=346224=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Tue Nov 6 03:17:40 2018 @@ -541,16 +541,14 @@ struct SpecifiedScope { // Set if the qualifier is not fully resolved by Sema. Optional UnresolvedQualifier; - // Construct scopes being queried in indexes. + // Construct scopes being queried in indexes. The results are deduplicated. // This method format the scopes to match the index request representation. std::vector scopesForIndexQuery() { -std::vector Results; -for (StringRef AS : AccessibleScopes) { - Results.push_back(AS); - if (UnresolvedQualifier) -Results.back() += *UnresolvedQualifier; -} -return Results; +std::set Results; +for (StringRef AS : AccessibleScopes) + Results.insert( + ((UnresolvedQualifier ? *UnresolvedQualifier : "") + AS).str()); +return {Results.begin(), Results.end()}; } }; 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=346224=346223=346224=diff == --- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Tue Nov 6 03:17:40 2018 @@ -1142,6 +1142,23 @@ TEST(CompletionTest, GlobalQualifiedQuer UnorderedElementsAre(""; } +TEST(CompletionTest, NoDuplicatedQueryScopes) { + auto Requests = captureIndexRequests(R"cpp( + namespace {} + + namespace na { + namespace {} + namespace nb { + ^ + } // namespace nb + } // namespace na + )cpp"); + + EXPECT_THAT(Requests, + ElementsAre(Field(::Scopes, +UnorderedElementsAre("na::", "na::nb::", ""; +} + TEST(CompletionTest, NoIndexCompletionsInsideClasses) { auto Completions = completions( R"cpp( ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r346223 - [clangd] Get rid of QueryScopes.empty() == AnyScope special case.
Author: ioeric Date: Tue Nov 6 03:08:17 2018 New Revision: 346223 URL: http://llvm.org/viewvc/llvm-project?rev=346223=rev Log: [clangd] Get rid of QueryScopes.empty() == AnyScope special case. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D53933 Modified: clang-tools-extra/trunk/clangd/FindSymbols.cpp clang-tools-extra/trunk/clangd/index/Index.h clang-tools-extra/trunk/clangd/index/MemIndex.cpp clang-tools-extra/trunk/clangd/index/dex/Dex.cpp clang-tools-extra/trunk/unittests/clangd/DexTests.cpp clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp Modified: clang-tools-extra/trunk/clangd/FindSymbols.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FindSymbols.cpp?rev=346223=346222=346223=diff == --- clang-tools-extra/trunk/clangd/FindSymbols.cpp (original) +++ clang-tools-extra/trunk/clangd/FindSymbols.cpp Tue Nov 6 03:08:17 2018 @@ -116,6 +116,8 @@ getWorkspaceSymbols(StringRef Query, int // not). if (IsGlobalQuery || !Names.first.empty()) Req.Scopes = {Names.first}; + else +Req.AnyScope = true; if (Limit) Req.Limit = Limit; TopN Top( 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=346223=346222=346223=diff == --- clang-tools-extra/trunk/clangd/index/Index.h (original) +++ clang-tools-extra/trunk/clangd/index/Index.h Tue Nov 6 03:08:17 2018 @@ -460,9 +460,6 @@ struct FuzzyFindRequest { /// namespace xyz::abc. /// /// The global scope is "", a top level scope is "foo::", etc. - /// FIXME: drop the special case for empty list, which is the same as - /// `AnyScope = true`. - /// FIXME: support scope proximity. std::vector Scopes; /// If set to true, allow symbols from any scope. Scopes explicitly listed /// above will be ranked higher. 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=346223=346222=346223=diff == --- clang-tools-extra/trunk/clangd/index/MemIndex.cpp (original) +++ clang-tools-extra/trunk/clangd/index/MemIndex.cpp Tue Nov 6 03:08:17 2018 @@ -39,8 +39,7 @@ bool MemIndex::fuzzyFind(const FuzzyFind const Symbol *Sym = Pair.second; // Exact match against all possible scopes. -if (!Req.AnyScope && !Req.Scopes.empty() && -!is_contained(Req.Scopes, Sym->Scope)) +if (!Req.AnyScope && !is_contained(Req.Scopes, Sym->Scope)) continue; if (Req.RestrictForCodeCompletion && !(Sym->Flags & Symbol::IndexedForCodeCompletion)) Modified: clang-tools-extra/trunk/clangd/index/dex/Dex.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Dex.cpp?rev=346223=346222=346223=diff == --- clang-tools-extra/trunk/clangd/index/dex/Dex.cpp (original) +++ clang-tools-extra/trunk/clangd/index/dex/Dex.cpp Tue Nov 6 03:08:17 2018 @@ -178,7 +178,7 @@ bool Dex::fuzzyFind(const FuzzyFindReque std::vector> ScopeIterators; for (const auto : Req.Scopes) ScopeIterators.push_back(iterator(Token(Token::Kind::Scope, Scope))); - if (Req.AnyScope || /*legacy*/ Req.Scopes.empty()) + if (Req.AnyScope) ScopeIterators.push_back( Corpus.boost(Corpus.all(), ScopeIterators.empty() ? 1.0 : 0.2)); Criteria.push_back(Corpus.unionOf(move(ScopeIterators))); Modified: clang-tools-extra/trunk/unittests/clangd/DexTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/DexTests.cpp?rev=346223=346222=346223=diff == --- clang-tools-extra/trunk/unittests/clangd/DexTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/DexTests.cpp Tue Nov 6 03:08:17 2018 @@ -485,6 +485,7 @@ TEST(Dex, FuzzyFind) { UnorderedElementsAre("other::A", "other::ABC")); Req.Query = ""; Req.Scopes = {}; + Req.AnyScope = true; EXPECT_THAT(match(*Index, Req), UnorderedElementsAre("ns::ABC", "ns::BCD", "::ABC", "ns::nested::ABC", "other::ABC", @@ -495,6 +496,7 @@ TEST(DexTest, DexLimitedNumMatches) { auto I = Dex::build(generateNumSymbols(0, 100), RefSlab(), URISchemes); FuzzyFindRequest Req; Req.Query = "5"; + Req.AnyScope = true; Req.Limit = 3; bool Incomplete; auto Matches = match(*I, Req, ); @@ -509,6 +511,7 @@ TEST(DexTest, FuzzyMatch) { RefSlab(),
[clang-tools-extra] r346221 - [clangd] auto-index stores symbols per-file instead of per-TU.
Author: ioeric Date: Tue Nov 6 02:55:21 2018 New Revision: 346221 URL: http://llvm.org/viewvc/llvm-project?rev=346221=rev Log: [clangd] auto-index stores symbols per-file instead of per-TU. Summary: This allows us to deduplicate header symbols across TUs. File digests are collects when collecting symbols/refs. And the index store deduplicates file symbols based on the file digest. Reviewers: sammccall, hokein Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D53433 Modified: clang-tools-extra/trunk/clangd/index/Background.cpp clang-tools-extra/trunk/clangd/index/Background.h clang-tools-extra/trunk/clangd/index/FileIndex.cpp clang-tools-extra/trunk/clangd/index/FileIndex.h clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp clang-tools-extra/trunk/clangd/index/SymbolCollector.h clang-tools-extra/trunk/clangd/index/dex/Dex.h clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp clang-tools-extra/trunk/unittests/clangd/DexTests.cpp clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp clang-tools-extra/trunk/unittests/clangd/SyncAPI.h Modified: clang-tools-extra/trunk/clangd/index/Background.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=346221=346220=346221=diff == --- clang-tools-extra/trunk/clangd/index/Background.cpp (original) +++ clang-tools-extra/trunk/clangd/index/Background.cpp Tue Nov 6 02:55:21 2018 @@ -13,11 +13,19 @@ #include "Logger.h" #include "Threading.h" #include "Trace.h" +#include "URI.h" #include "index/IndexAction.h" #include "index/MemIndex.h" #include "index/Serialization.h" +#include "index/SymbolCollector.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/SourceManager.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/SHA1.h" #include +#include using namespace llvm; namespace clang { @@ -125,6 +133,142 @@ void BackgroundIndex::enqueueLocked(tool std::move(Cmd))); } +static BackgroundIndex::FileDigest digest(StringRef Content) { + return SHA1::hash({(const uint8_t *)Content.data(), Content.size()}); +} + +static Optional digestFile(const SourceManager , +FileID FID) { + bool Invalid = false; + StringRef Content = SM.getBufferData(FID, ); + if (Invalid) +return None; + return digest(Content); +} + +// Resolves URI to file paths with cache. +class URIToFileCache { +public: + URIToFileCache(llvm::StringRef HintPath) : HintPath(HintPath) {} + + llvm::StringRef resolve(llvm::StringRef FileURI) { +auto I = URIToPathCache.try_emplace(FileURI); +if (I.second) { + auto U = URI::parse(FileURI); + if (!U) { +elog("Failed to parse URI {0}: {1}", FileURI, U.takeError()); +assert(false && "Failed to parse URI"); +return ""; + } + auto Path = URI::resolve(*U, HintPath); + if (!Path) { +elog("Failed to resolve URI {0}: {1}", FileURI, Path.takeError()); +assert(false && "Failed to resolve URI"); +return ""; + } + I.first->second = *Path; +} +return I.first->second; + } + +private: + std::string HintPath; + llvm::StringMap URIToPathCache; +}; + +/// Given index results from a TU, only update files in \p FilesToUpdate. +void BackgroundIndex::update(StringRef MainFile, SymbolSlab Symbols, + RefSlab Refs, + const StringMap ) { + // Partition symbols/references into files. + struct File { +DenseSet Symbols; +DenseSet Refs; + }; + StringMap Files; + URIToFileCache URICache(MainFile); + for (const auto : Symbols) { +if (Sym.CanonicalDeclaration) { + auto DeclPath = URICache.resolve(Sym.CanonicalDeclaration.FileURI); + if (FilesToUpdate.count(DeclPath) != 0) +Files[DeclPath].Symbols.insert(); +} +// For symbols with different declaration and definition locations, we store +// the full symbol in both the header file and the implementation file, so +// that merging can tell the preferred symbols (from canonical headers) from +// other symbols (e.g. forward declarations). +if (Sym.Definition && +Sym.Definition.FileURI != Sym.CanonicalDeclaration.FileURI) { + auto DefPath = URICache.resolve(Sym.Definition.FileURI); + if (FilesToUpdate.count(DefPath) != 0) +Files[DefPath].Symbols.insert(); +} + } + DenseMap RefToIDs; + for (const auto : Refs) { +for (const auto : SymRefs.second) { + auto Path = URICache.resolve(R.Location.FileURI); + if (FilesToUpdate.count(Path) != 0) { +auto = Files[Path]; +
[clang-tools-extra] r345140 - [clangd] Downrank members from base class
Author: ioeric Date: Wed Oct 24 06:45:17 2018 New Revision: 345140 URL: http://llvm.org/viewvc/llvm-project?rev=345140=rev Log: [clangd] Downrank members from base class Reviewers: sammccall, ilya-biryukov Reviewed By: sammccall Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D53638 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=345140=345139=345140=diff == --- clang-tools-extra/trunk/clangd/Quality.cpp (original) +++ clang-tools-extra/trunk/clangd/Quality.cpp Wed Oct 24 06:45:17 2018 @@ -299,6 +299,7 @@ void SymbolRelevanceSignals::merge(const : 0.6; SemaFileProximityScore = std::max(DeclProximity, SemaFileProximityScore); IsInstanceMember |= isInstanceMember(SemaCCResult.Declaration); +InBaseClass |= SemaCCResult.InBaseClass; } // Declarations are scoped, others (like macros) are assumed global. @@ -372,9 +373,12 @@ float SymbolRelevanceSignals::evaluate() if (!IsInstanceMember && (Context == CodeCompletionContext::CCC_DotMemberAccess || Context == CodeCompletionContext::CCC_ArrowMemberAccess)) { -Score *= 0.5; +Score *= 0.2; } + if (InBaseClass) +Score *= 0.5; + // Penalize for FixIts. if (NeedsFixIts) Score *= 0.5; Modified: clang-tools-extra/trunk/clangd/Quality.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.h?rev=345140=345139=345140=diff == --- clang-tools-extra/trunk/clangd/Quality.h (original) +++ clang-tools-extra/trunk/clangd/Quality.h Wed Oct 24 06:45:17 2018 @@ -87,6 +87,7 @@ struct SymbolRelevanceSignals { bool Forbidden = false; // Unavailable (e.g const) or inaccessible (private). /// Whether fixits needs to be applied for that completion or not. bool NeedsFixIts = false; + bool InBaseClass = false; // A member from base class of the accessed class. URIDistance *FileProximityMatch = nullptr; /// These are used to calculate proximity between the index symbol and the Modified: clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp?rev=345140=345139=345140=diff == --- clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp Wed Oct 24 06:45:17 2018 @@ -185,6 +185,13 @@ TEST(QualityTests, SymbolRelevanceSignal Relevance = {}; Relevance.merge(CodeCompletionResult((AST, "S::S"), 42)); EXPECT_EQ(Relevance.Scope, SymbolRelevanceSignals::GlobalScope); + + Relevance = {}; + EXPECT_FALSE(Relevance.InBaseClass); + auto BaseMember = CodeCompletionResult((AST, "y"), 42); + BaseMember.InBaseClass = true; + Relevance.merge(BaseMember); + EXPECT_TRUE(Relevance.InBaseClass); } // Do the signals move the scores in the direction we expect? @@ -276,6 +283,10 @@ TEST(QualityTests, SymbolRelevanceSignal EXPECT_LT(Instance.evaluate(), Default.evaluate()); Instance.IsInstanceMember = true; EXPECT_EQ(Instance.evaluate(), Default.evaluate()); + + SymbolRelevanceSignals InBaseClass; + InBaseClass.InBaseClass = true; + EXPECT_LT(InBaseClass.evaluate(), Default.evaluate()); } TEST(QualityTests, ScopeProximity) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r345135 - [CodeComplete] Expose InBaseClass signal in code completion results.
Author: ioeric Date: Wed Oct 24 05:57:27 2018 New Revision: 345135 URL: http://llvm.org/viewvc/llvm-project?rev=345135=rev Log: [CodeComplete] Expose InBaseClass signal in code completion results. Summary: No new tests as the existing tests for result priority should give us coverage. Also as the new flag is trivial enough, I'm reluctant to plumb the flag to c-index-test output. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D53635 Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp cfe/trunk/lib/Sema/SemaCodeComplete.cpp cfe/trunk/test/CodeCompletion/member-access.cpp cfe/trunk/test/CodeCompletion/objc-message.mm Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h?rev=345135=345134=345135=diff == --- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h (original) +++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h Wed Oct 24 05:57:27 2018 @@ -821,6 +821,9 @@ public: /// Whether this result is hidden by another name. bool Hidden : 1; + /// Whether this is a class member from base class. + bool InBaseClass : 1; + /// Whether this result was found via lookup into a base class. bool QualifierIsInformative : 1; @@ -859,7 +862,7 @@ public: bool Accessible = true, std::vector FixIts = std::vector()) : Declaration(Declaration), Priority(Priority), Kind(RK_Declaration), -FixIts(std::move(FixIts)), Hidden(false), +FixIts(std::move(FixIts)), Hidden(false), InBaseClass(false), QualifierIsInformative(QualifierIsInformative), StartsNestedNameSpecifier(false), AllParametersAreInformative(false), DeclaringEntity(false), Qualifier(Qualifier) { @@ -870,7 +873,7 @@ public: /// Build a result that refers to a keyword or symbol. CodeCompletionResult(const char *Keyword, unsigned Priority = CCP_Keyword) : Keyword(Keyword), Priority(Priority), Kind(RK_Keyword), -CursorKind(CXCursor_NotImplemented), Hidden(false), +CursorKind(CXCursor_NotImplemented), Hidden(false), InBaseClass(false), QualifierIsInformative(false), StartsNestedNameSpecifier(false), AllParametersAreInformative(false), DeclaringEntity(false) {} @@ -879,28 +882,29 @@ public: const MacroInfo *MI = nullptr, unsigned Priority = CCP_Macro) : Macro(Macro), Priority(Priority), Kind(RK_Macro), -CursorKind(CXCursor_MacroDefinition), Hidden(false), +CursorKind(CXCursor_MacroDefinition), Hidden(false), InBaseClass(false), QualifierIsInformative(false), StartsNestedNameSpecifier(false), AllParametersAreInformative(false), DeclaringEntity(false), MacroDefInfo(MI) {} /// Build a result that refers to a pattern. - CodeCompletionResult(CodeCompletionString *Pattern, - unsigned Priority = CCP_CodePattern, - CXCursorKind CursorKind = CXCursor_NotImplemented, - CXAvailabilityKind Availability = CXAvailability_Available, - const NamedDecl *D = nullptr) + CodeCompletionResult( + CodeCompletionString *Pattern, unsigned Priority = CCP_CodePattern, + CXCursorKind CursorKind = CXCursor_NotImplemented, + CXAvailabilityKind Availability = CXAvailability_Available, + const NamedDecl *D = nullptr) : Declaration(D), Pattern(Pattern), Priority(Priority), Kind(RK_Pattern), CursorKind(CursorKind), Availability(Availability), Hidden(false), -QualifierIsInformative(false), StartsNestedNameSpecifier(false), -AllParametersAreInformative(false), DeclaringEntity(false) {} +InBaseClass(false), QualifierIsInformative(false), +StartsNestedNameSpecifier(false), AllParametersAreInformative(false), +DeclaringEntity(false) {} /// Build a result that refers to a pattern with an associated /// declaration. CodeCompletionResult(CodeCompletionString *Pattern, const NamedDecl *D, unsigned Priority) : Declaration(D), Pattern(Pattern), Priority(Priority), Kind(RK_Pattern), -Hidden(false), QualifierIsInformative(false), +Hidden(false), InBaseClass(false), QualifierIsInformative(false), StartsNestedNameSpecifier(false), AllParametersAreInformative(false), DeclaringEntity(false) { computeCursorKindAndAvailability(); Modified: cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp?rev=345135=345134=345135=diff == ---
[clang-tools-extra] r344912 - [clangd] Support URISchemes configuration in BackgroundIndex.
Author: ioeric Date: Mon Oct 22 08:37:58 2018 New Revision: 344912 URL: http://llvm.org/viewvc/llvm-project?rev=344912=rev Log: [clangd] Support URISchemes configuration in BackgroundIndex. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D53503 Modified: clang-tools-extra/trunk/clangd/index/Background.cpp clang-tools-extra/trunk/clangd/index/Background.h Modified: clang-tools-extra/trunk/clangd/index/Background.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=344912=344911=344912=diff == --- clang-tools-extra/trunk/clangd/index/Background.cpp (original) +++ clang-tools-extra/trunk/clangd/index/Background.cpp Mon Oct 22 08:37:58 2018 @@ -24,10 +24,11 @@ namespace clangd { BackgroundIndex::BackgroundIndex(Context BackgroundContext, StringRef ResourceDir, - const FileSystemProvider ) + const FileSystemProvider , + ArrayRef URISchemes) : SwapIndex(make_unique()), ResourceDir(ResourceDir), FSProvider(FSProvider), BackgroundContext(std::move(BackgroundContext)), - Thread([this] { run(); }) {} + URISchemes(URISchemes), Thread([this] { run(); }) {} BackgroundIndex::~BackgroundIndex() { stop(); @@ -185,7 +186,7 @@ Error BackgroundIndex::index(tooling::Co // FIXME: this should rebuild once-in-a-while, not after every file. // At that point we should use Dex, too. vlog("Rebuilding automatic index"); - reset(IndexedSymbols.buildIndex(IndexType::Light)); + reset(IndexedSymbols.buildIndex(IndexType::Light, URISchemes)); return Error::success(); } Modified: clang-tools-extra/trunk/clangd/index/Background.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.h?rev=344912=344911=344912=diff == --- clang-tools-extra/trunk/clangd/index/Background.h (original) +++ clang-tools-extra/trunk/clangd/index/Background.h Mon Oct 22 08:37:58 2018 @@ -18,7 +18,9 @@ #include "llvm/Support/SHA1.h" #include #include +#include #include +#include namespace clang { namespace clangd { @@ -31,7 +33,8 @@ class BackgroundIndex : public SwapIndex public: // FIXME: resource-dir injection should be hoisted somewhere common. BackgroundIndex(Context BackgroundContext, StringRef ResourceDir, - const FileSystemProvider &); + const FileSystemProvider &, + ArrayRef URISchemes = {}); ~BackgroundIndex(); // Blocks while the current task finishes. // Enqueue a translation unit for indexing. @@ -54,6 +57,7 @@ private: std::string ResourceDir; const FileSystemProvider Context BackgroundContext; + std::vector URISchemes; // index state llvm::Error index(tooling::CompileCommand); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r344897 - [change-namespace] Enhance detection of conflicting namespaces.
Author: ioeric Date: Mon Oct 22 05:48:49 2018 New Revision: 344897 URL: http://llvm.org/viewvc/llvm-project?rev=344897=rev Log: [change-namespace] Enhance detection of conflicting namespaces. Summary: For example: ``` namespace util { class Base; } namespace new { namespace util { class Internal; } } namespace old { util::Base b1; } ``` When changing `old::` to `new::`, `util::` in namespace "new::" will conflict with "new::util::" unless a leading "::" is added. Reviewers: hokein Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D53489 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=344897=344896=344897=diff == --- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original) +++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Mon Oct 22 05:48:49 2018 @@ -7,8 +7,10 @@ // //===--===// #include "ChangeNamespace.h" +#include "clang/AST/ASTContext.h" #include "clang/Format/Format.h" #include "clang/Lex/Lexer.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" using namespace clang::ast_matchers; @@ -283,23 +285,48 @@ bool isDeclVisibleAtLocation(const Sourc } // Given a qualified symbol name, returns true if the symbol will be -// incorrectly qualified without leading "::". -bool conflictInNamespace(llvm::StringRef QualifiedSymbol, +// incorrectly qualified without leading "::". For example, a symbol +// "nx::ny::Foo" in namespace "na::nx::ny" without leading "::"; a symbol +// "util::X" in namespace "na" can potentially conflict with "na::util" (if this +// exists). +bool conflictInNamespace(const ASTContext , llvm::StringRef QualifiedSymbol, llvm::StringRef Namespace) { auto SymbolSplitted = splitSymbolName(QualifiedSymbol.trim(":")); assert(!SymbolSplitted.empty()); SymbolSplitted.pop_back(); // We are only interested in namespaces. - if (SymbolSplitted.size() > 1 && !Namespace.empty()) { + if (SymbolSplitted.size() >= 1 && !Namespace.empty()) { +auto SymbolTopNs = SymbolSplitted.front(); auto NsSplitted = splitSymbolName(Namespace.trim(":")); assert(!NsSplitted.empty()); -// We do not check the outermost namespace since it would not be a conflict -// if it equals to the symbol's outermost namespace and the symbol name -// would have been shortened. + +auto LookupDecl = [](const Decl , + llvm::StringRef Name) -> const NamedDecl * { + const auto *DC = llvm::dyn_cast(); + if (!DC) +return nullptr; + auto LookupRes = DC->lookup(DeclarationName((Name))); + if (LookupRes.empty()) +return nullptr; + return LookupRes.front(); +}; +// We do not check the outermost namespace since it would not be a +// conflict if it equals to the symbol's outermost namespace and the +// symbol name would have been shortened. +const NamedDecl *Scope = +LookupDecl(*AST.getTranslationUnitDecl(), NsSplitted.front()); for (auto I = NsSplitted.begin() + 1, E = NsSplitted.end(); I != E; ++I) { - if (*I == SymbolSplitted.front()) + if (*I == SymbolTopNs) // Handles "::ny" in "::nx::ny" case. return true; + // Handles "::util" and "::nx::util" conflicts. + if (Scope) { +if (LookupDecl(*Scope, SymbolTopNs)) + return true; +Scope = LookupDecl(*Scope, *I); + } } +if (Scope && LookupDecl(*Scope, SymbolTopNs)) + return true; } return false; } @@ -844,15 +871,16 @@ void ChangeNamespaceTool::replaceQualifi } } } + bool Conflict = conflictInNamespace(DeclCtx->getParentASTContext(), + ReplaceName, NewNamespace); // If the new nested name in the new namespace is the same as it was in the - // old namespace, we don't create replacement. - if (NestedName == ReplaceName || + // old namespace, we don't create replacement unless there can be ambiguity. + if ((NestedName == ReplaceName && !Conflict) || (NestedName.startswith("::") && NestedName.drop_front(2) == ReplaceName)) return; // If the reference need to be fully-qualified, add a leading "::" unless // NewNamespace is the global namespace. - if (ReplaceName == FromDeclName && !NewNamespace.empty() && - conflictInNamespace(ReplaceName, NewNamespace)) + if (ReplaceName == FromDeclName && !NewNamespace.empty() && Conflict) ReplaceName = "::" + ReplaceName; addReplacementOrDie(Start, End, ReplaceName, *Result.SourceManager,
r344889 - [CodeComplete] Fix accessibility of protected members when accessing members implicitly.
Author: ioeric Date: Mon Oct 22 01:47:31 2018 New Revision: 344889 URL: http://llvm.org/viewvc/llvm-project?rev=344889=rev Log: [CodeComplete] Fix accessibility of protected members when accessing members implicitly. Reviewers: ilya-biryukov Subscribers: arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D53369 Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp cfe/trunk/test/Index/complete-access-checks.cpp Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=344889=344888=344889=diff == --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original) +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Mon Oct 22 01:47:31 2018 @@ -3686,13 +3686,20 @@ void Sema::CodeCompleteOrdinaryName(Scop } // If we are in a C++ non-static member function, check the qualifiers on - // the member function to filter/prioritize the results list. - if (CXXMethodDecl *CurMethod = dyn_cast(CurContext)) -if (CurMethod->isInstance()) + // the member function to filter/prioritize the results list and set the + // context to the record context so that accessibility check in base class + // works correctly. + RecordDecl *MemberCompletionRecord = nullptr; + if (CXXMethodDecl *CurMethod = dyn_cast(CurContext)) { +if (CurMethod->isInstance()) { Results.setObjectTypeQualifiers( Qualifiers::fromCVRMask(CurMethod->getTypeQualifiers())); + MemberCompletionRecord = CurMethod->getParent(); +} + } - CodeCompletionDeclConsumer Consumer(Results, CurContext); + CodeCompletionDeclConsumer Consumer(Results, CurContext, /*FixIts=*/{}, + MemberCompletionRecord); LookupVisibleDecls(S, LookupOrdinaryName, Consumer, CodeCompleter->includeGlobals(), CodeCompleter->loadExternal()); Modified: cfe/trunk/test/Index/complete-access-checks.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-access-checks.cpp?rev=344889=344888=344889=diff == --- cfe/trunk/test/Index/complete-access-checks.cpp (original) +++ cfe/trunk/test/Index/complete-access-checks.cpp Mon Oct 22 01:47:31 2018 @@ -29,8 +29,11 @@ void Y::doSomething() { // RUN: c-index-test -code-completion-at=%s:30:9 %s | FileCheck -check-prefix=CHECK-SUPER-ACCESS %s this->; + // RUN: c-index-test -code-completion-at=%s:33:3 %s | FileCheck -check-prefix=CHECK-SUPER-ACCESS-IMPLICIT %s + + Z that; - // RUN: c-index-test -code-completion-at=%s:34:8 %s | FileCheck -check-prefix=CHECK-ACCESS %s + // RUN: c-index-test -code-completion-at=%s:37:8 %s | FileCheck -check-prefix=CHECK-ACCESS %s that. } @@ -48,6 +51,14 @@ void Y::doSomething() { // CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{Informative X::}{TypedText ~X}{LeftParen (}{RightParen )} (81) // CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{TypedText ~Y}{LeftParen (}{RightParen )} (79) +// CHECK-SUPER-ACCESS-IMPLICIT: CXXMethod:{ResultType void}{TypedText doSomething}{LeftParen (}{RightParen )} (34) +// CHECK-SUPER-ACCESS-IMPLICIT: CXXMethod:{ResultType void}{TypedText func1}{LeftParen (}{RightParen )} (36) +// CHECK-SUPER-ACCESS-IMPLICIT: CXXMethod:{ResultType void}{TypedText func2}{LeftParen (}{RightParen )} (36){{$}} +// CHECK-SUPER-ACCESS-IMPLICIT: CXXMethod:{ResultType void}{TypedText func3}{LeftParen (}{RightParen )} (36) (inaccessible) +// CHECK-SUPER-ACCESS-IMPLICIT: FieldDecl:{ResultType int}{TypedText member1} (37) +// CHECK-SUPER-ACCESS-IMPLICIT: FieldDecl:{ResultType int}{TypedText member2} (37){{$}} +// CHECK-SUPER-ACCESS-IMPLICIT: FieldDecl:{ResultType int}{TypedText member3} (37) (inaccessible) + // CHECK-ACCESS: CXXMethod:{ResultType void}{TypedText func1}{LeftParen (}{RightParen )} (34) // CHECK-ACCESS: CXXMethod:{ResultType void}{TypedText func2}{LeftParen (}{RightParen )} (34) (inaccessible) // CHECK-ACCESS: CXXMethod:{ResultType void}{TypedText func3}{LeftParen (}{RightParen )} (34) (inaccessible) @@ -69,9 +80,9 @@ public: }; void f(P x, Q y) { - // RUN: c-index-test -code-completion-at=%s:73:5 %s | FileCheck -check-prefix=CHECK-USING-INACCESSIBLE %s + // RUN: c-index-test -code-completion-at=%s:84:5 %s | FileCheck -check-prefix=CHECK-USING-INACCESSIBLE %s x.; // member is inaccessible - // RUN: c-index-test -code-completion-at=%s:75:5 %s | FileCheck -check-prefix=CHECK-USING-ACCESSIBLE %s + // RUN: c-index-test -code-completion-at=%s:86:5 %s | FileCheck -check-prefix=CHECK-USING-ACCESSIBLE %s y.; // member is accessible } @@ -102,11 +113,11 @@ class D : public C { }; void D::f(::B *that) { - // RUN: c-index-test -code-completion-at=%s:106:9 %s | FileCheck -check-prefix=CHECK-PRIVATE-SUPER-THIS %s + // RUN: c-index-test
[clang-tools-extra] r344736 - [clangd] Names that are not spelled in source code are reserved.
Author: ioeric Date: Thu Oct 18 05:23:05 2018 New Revision: 344736 URL: http://llvm.org/viewvc/llvm-project?rev=344736=rev Log: [clangd] Names that are not spelled in source code are reserved. Summary: These are often not expected to be used directly e.g. ``` TEST_F(Fixture, X) { ^ // "Fixture_X_Test" expanded in the macro should be down ranked. } ``` Only doing this for sema for now, as such symbols are mostly coming from sema e.g. gtest macros expanded in the main file. We could also add a similar field for the index symbol. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D53374 Modified: clang-tools-extra/trunk/clangd/AST.cpp clang-tools-extra/trunk/clangd/AST.h clang-tools-extra/trunk/clangd/Quality.cpp clang-tools-extra/trunk/clangd/Quality.h clang-tools-extra/trunk/clangd/index/Index.h clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Modified: clang-tools-extra/trunk/clangd/AST.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/AST.cpp?rev=344736=344735=344736=diff == --- clang-tools-extra/trunk/clangd/AST.cpp (original) +++ clang-tools-extra/trunk/clangd/AST.cpp Thu Oct 18 05:23:05 2018 @@ -11,6 +11,7 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" +#include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "clang/Index/USRGeneration.h" @@ -18,25 +19,34 @@ namespace clang { namespace clangd { using namespace llvm; -SourceLocation findNameLoc(const clang::Decl* D) { - const auto& SM = D->getASTContext().getSourceManager(); +// Returns true if the complete name of decl \p D is spelled in the source code. +// This is not the case for +// * symbols formed via macro concatenation, the spelling location will +// be "" +// * symbols controlled and defined by a compile command-line option +// `-DName=foo`, the spelling location will be "". +bool isSpelledInSourceCode(const Decl *D) { + const auto = D->getASTContext().getSourceManager(); + auto Loc = D->getLocation(); // FIXME: Revisit the strategy, the heuristic is limitted when handling // macros, we should use the location where the whole definition occurs. - SourceLocation SpellingLoc = SM.getSpellingLoc(D->getLocation()); - if (D->getLocation().isMacroID()) { -std::string PrintLoc = SpellingLoc.printToString(SM); + if (Loc.isMacroID()) { +std::string PrintLoc = SM.getSpellingLoc(Loc).printToString(SM); if (llvm::StringRef(PrintLoc).startswith("")) { - // We use the expansion location for the following symbols, as spelling - // locations of these symbols are not interesting to us: - // * symbols formed via macro concatenation, the spelling location will - // be "" - // * symbols controlled and defined by a compile command-line option - // `-DName=foo`, the spelling location will be "". - SpellingLoc = SM.getExpansionRange(D->getLocation()).getBegin(); -} +llvm::StringRef(PrintLoc).startswith("")) + return false; } - return SpellingLoc; + return true; +} + +bool isImplementationDetail(const Decl *D) { return !isSpelledInSourceCode(D); } + +SourceLocation findNameLoc(const clang::Decl* D) { + const auto = D->getASTContext().getSourceManager(); + if (!isSpelledInSourceCode(D)) +// Use the expansion location as spelling location is not interesting. +return SM.getExpansionRange(D->getLocation()).getBegin(); + return SM.getSpellingLoc(D->getLocation()); } std::string printQualifiedName(const NamedDecl ) { Modified: clang-tools-extra/trunk/clangd/AST.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/AST.h?rev=344736=344735=344736=diff == --- clang-tools-extra/trunk/clangd/AST.h (original) +++ clang-tools-extra/trunk/clangd/AST.h Thu Oct 18 05:23:05 2018 @@ -24,6 +24,11 @@ class Decl; namespace clangd { +/// Returns true if the declaration is considered implementation detail based on +/// heuristics. For example, a declaration whose name is not explicitly spelled +/// in code is considered implementation detail. +bool isImplementationDetail(const Decl *D); + /// Find the identifier source location of the given D. /// /// The returned location is usually the spelling location where the name of the Modified: clang-tools-extra/trunk/clangd/Quality.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=344736=344735=344736=diff == ---
[clang-tools-extra] r344688 - [clangd] Support scope proximity in code completion.
Author: ioeric Date: Wed Oct 17 04:19:02 2018 New Revision: 344688 URL: http://llvm.org/viewvc/llvm-project?rev=344688=rev Log: [clangd] Support scope proximity in code completion. Summary: This should make all-scope completion more usable. Scope proximity for indexes will be added in followup patch. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D53131 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/FileDistance.cpp clang-tools-extra/trunk/clangd/FileDistance.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/FileDistanceTests.cpp clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp Modified: clang-tools-extra/trunk/clangd/AST.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/AST.cpp?rev=344688=344687=344688=diff == --- clang-tools-extra/trunk/clangd/AST.cpp (original) +++ clang-tools-extra/trunk/clangd/AST.cpp Wed Oct 17 04:19:02 2018 @@ -54,6 +54,14 @@ std::string printQualifiedName(const Nam return QName; } +std::string printNamespaceScope(const DeclContext ) { + for (const auto *Ctx = Ctx != nullptr; Ctx = Ctx->getParent()) +if (const auto *NS = dyn_cast(Ctx)) + if (!NS->isAnonymousNamespace() && !NS->isInlineNamespace()) +return printQualifiedName(*NS) + "::"; + return ""; +} + llvm::Optional getSymbolID(const Decl *D) { llvm::SmallString<128> USR; if (index::generateUSRForDecl(D, USR)) Modified: clang-tools-extra/trunk/clangd/AST.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/AST.h?rev=344688=344687=344688=diff == --- clang-tools-extra/trunk/clangd/AST.h (original) +++ clang-tools-extra/trunk/clangd/AST.h Wed Oct 17 04:19:02 2018 @@ -34,6 +34,9 @@ SourceLocation findNameLoc(const clang:: /// like inline namespaces. std::string printQualifiedName(const NamedDecl ); +/// Returns the first enclosing namespace scope starting from \p DC. +std::string printNamespaceScope(const DeclContext ); + /// Gets the symbol ID for a declaration, if possible. llvm::Optional getSymbolID(const Decl *D); Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=344688=344687=344688=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Wed Oct 17 04:19:02 2018 @@ -34,6 +34,8 @@ #include "Trace.h" #include "URI.h" #include "index/Index.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclBase.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/SourceLocation.h" @@ -44,6 +46,7 @@ #include "clang/Sema/CodeCompleteConsumer.h" #include "clang/Sema/Sema.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/None.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Error.h" @@ -549,9 +552,10 @@ struct SpecifiedScope { }; // Get all scopes that will be queried in indexes and whether symbols from -// any scope is allowed. +// any scope is allowed. The first scope in the list is the preferred scope +// (e.g. enclosing namespace). std::pair, bool> -getQueryScopes(CodeCompletionContext , const SourceManager , +getQueryScopes(CodeCompletionContext , const Sema , const CodeCompleteOptions ) { auto GetAllAccessibleScopes = [](CodeCompletionContext ) { SpecifiedScope Info; @@ -559,7 +563,7 @@ getQueryScopes(CodeCompletionContext if (isa(Context)) Info.AccessibleScopes.push_back(""); // global namespace else if (const auto *NS = dyn_cast(Context)) -Info.AccessibleScopes.push_back(NS->getQualifiedNameAsString() + "::"); +Info.AccessibleScopes.push_back(printNamespaceScope(*Context)); } return Info; }; @@ -568,12 +572,13 @@ getQueryScopes(CodeCompletionContext // Unqualified completion (e.g. "vec^"). if (!SS) { -// FIXME: Once we can insert namespace qualifiers and use the in-scope -//namespaces for scoring, search in all namespaces. -// FIXME: Capture scopes and use for scoring, for example, -//"using namespace std; namespace foo {v^}" => -//foo::value > std::vector > boost::variant -auto Scopes = GetAllAccessibleScopes(CCContext).scopesForIndexQuery(); +std::vector Scopes; +
[clang-tools-extra] r344604 - [clangd] Allow disble down traversals from root.
Author: ioeric Date: Tue Oct 16 03:41:17 2018 New Revision: 344604 URL: http://llvm.org/viewvc/llvm-project?rev=344604=rev Log: [clangd] Allow disble down traversals from root. Summary: This is useful for symbo scope proximity, where down traversals from the global scope if not desired. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D53317 Modified: clang-tools-extra/trunk/clangd/FileDistance.cpp clang-tools-extra/trunk/clangd/FileDistance.h clang-tools-extra/trunk/unittests/clangd/FileDistanceTests.cpp Modified: clang-tools-extra/trunk/clangd/FileDistance.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FileDistance.cpp?rev=344604=344603=344604=diff == --- clang-tools-extra/trunk/clangd/FileDistance.cpp (original) +++ clang-tools-extra/trunk/clangd/FileDistance.cpp Tue Oct 16 03:41:17 2018 @@ -54,6 +54,7 @@ static SmallString<128> canonicalize(Str } constexpr const unsigned FileDistance::Unreachable; +const llvm::hash_code FileDistance::RootHash = hash_value(StringRef("/")); FileDistance::FileDistance(StringMap Sources, const FileDistanceOptions ) @@ -99,15 +100,18 @@ FileDistance::FileDistance(StringMapgetSecond(); - if (ParentCost + Opts.DownCost < ChildCost) -ChildCost = ParentCost + Opts.DownCost; +auto Parent = Next.front(); +Next.pop(); +auto ParentCost = Cache.lookup(Parent); +for (auto Child : DownEdges.lookup(Parent)) { + if (Parent != RootHash || Opts.AllowDownTraversalFromRoot) { +auto = +Cache.try_emplace(Child, Unreachable).first->getSecond(); +if (ParentCost + Opts.DownCost < ChildCost) + ChildCost = ParentCost + Opts.DownCost; + } Next.push(Child); } -Next.pop(); } } @@ -119,6 +123,11 @@ unsigned FileDistance::distance(StringRe for (StringRef Rest = Canonical; !Rest.empty(); Rest = parent_path(Rest, sys::path::Style::posix)) { auto Hash = hash_value(Rest); +if (Hash == RootHash && !Ancestors.empty() && +!Opts.AllowDownTraversalFromRoot) { + Cost = Unreachable; + break; +} auto It = Cache.find(Hash); if (It != Cache.end()) { Cost = It->second; Modified: clang-tools-extra/trunk/clangd/FileDistance.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FileDistance.h?rev=344604=344603=344604=diff == --- clang-tools-extra/trunk/clangd/FileDistance.h (original) +++ clang-tools-extra/trunk/clangd/FileDistance.h Tue Oct 16 03:41:17 2018 @@ -56,6 +56,7 @@ struct FileDistanceOptions { unsigned UpCost = 2; // |foo/bar.h -> foo| unsigned DownCost = 1;// |foo -> foo/bar.h| unsigned IncludeCost = 2; // |foo.cc -> included_header.h| + bool AllowDownTraversalFromRoot = true; // | / -> /a | }; struct SourceParams { @@ -70,6 +71,7 @@ struct SourceParams { class FileDistance { public: static constexpr unsigned Unreachable = std::numeric_limits::max(); + static const llvm::hash_code RootHash; FileDistance(llvm::StringMap Sources, const FileDistanceOptions = {}); Modified: clang-tools-extra/trunk/unittests/clangd/FileDistanceTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/FileDistanceTests.cpp?rev=344604=344603=344604=diff == --- clang-tools-extra/trunk/unittests/clangd/FileDistanceTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/FileDistanceTests.cpp Tue Oct 16 03:41:17 2018 @@ -95,6 +95,20 @@ TEST(FileDistance, LimitUpTraversals) { EXPECT_EQ(D.distance("/a/b/z"), 2u); } +TEST(FileDistance, DisallowDownTraversalsFromRoot) { + FileDistanceOptions Opts; + Opts.UpCost = Opts.DownCost = 1; + Opts.AllowDownTraversalFromRoot = false; + SourceParams CostLots; + CostLots.Cost = 100; + + FileDistance D({{"/", SourceParams()}, {"/a/b/c", CostLots}}, Opts); + EXPECT_EQ(D.distance("/"), 0u); + EXPECT_EQ(D.distance("/a"), 102u); + EXPECT_EQ(D.distance("/a/b"), 101u); + EXPECT_EQ(D.distance("/x"), FileDistance::Unreachable); +} + } // namespace } // namespace clangd } // namespace clang ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r344509 - [CodeComplete] Make sure keyword 'template' is added even when code pattern is disabled.
Author: ioeric Date: Mon Oct 15 05:37:23 2018 New Revision: 344509 URL: http://llvm.org/viewvc/llvm-project?rev=344509=rev Log: [CodeComplete] Make sure keyword 'template' is added even when code pattern is disabled. Reviewers: sammccall, hokein Subscribers: arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D53284 Added: cfe/trunk/test/Index/complete-template-keywords.cpp Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=344509=344508=344509=diff == --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original) +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Mon Oct 15 05:37:23 2018 @@ -1731,6 +1731,8 @@ static void AddOrdinaryNameResults(Sema: Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("declaration"); Results.AddResult(Result(Builder.TakeString())); + } else { +Results.AddResult(Result("template", CodeCompletionResult::RK_Keyword)); } } @@ -1805,6 +1807,8 @@ static void AddOrdinaryNameResults(Sema: Builder.AddPlaceholderChunk("parameters"); Builder.AddChunk(CodeCompletionString::CK_RightAngle); Results.AddResult(Result(Builder.TakeString())); +} else { + Results.AddResult(Result("template", CodeCompletionResult::RK_Keyword)); } AddStorageSpecifiers(CCC, SemaRef.getLangOpts(), Results); Added: cfe/trunk/test/Index/complete-template-keywords.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-template-keywords.cpp?rev=344509=auto == --- cfe/trunk/test/Index/complete-template-keywords.cpp (added) +++ cfe/trunk/test/Index/complete-template-keywords.cpp Mon Oct 15 05:37:23 2018 @@ -0,0 +1,5 @@ +templ +// RUN: env c-index-test -code-completion-at=%s:1:5 %s | FileCheck -check-prefix=CHECK-NO-PATTERN %s +// CHECK-NO-PATTERN: {TypedText template} (1) +// RUN: env CINDEXTEST_CODE_COMPLETE_PATTERNS=1 c-index-test -code-completion-at=%s:1:5 %s | FileCheck -check-prefix=CHECK-PATTERN %s +// CHECK-PATTERN: {TypedText template}{LeftAngle <} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r344335 - [Tooling] Expose ExecutorName option.
Author: ioeric Date: Fri Oct 12 04:47:36 2018 New Revision: 344335 URL: http://llvm.org/viewvc/llvm-project?rev=344335=rev Log: [Tooling] Expose ExecutorName option. Modified: cfe/trunk/include/clang/Tooling/Execution.h cfe/trunk/lib/Tooling/Execution.cpp Modified: cfe/trunk/include/clang/Tooling/Execution.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Execution.h?rev=344335=344334=344335=diff == --- cfe/trunk/include/clang/Tooling/Execution.h (original) +++ cfe/trunk/include/clang/Tooling/Execution.h Fri Oct 12 04:47:36 2018 @@ -37,6 +37,8 @@ namespace clang { namespace tooling { +extern llvm::cl::opt ExecutorName; + /// An abstraction for the result of a tool execution. For example, the /// underlying result can be in-memory or on-disk. /// Modified: cfe/trunk/lib/Tooling/Execution.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Execution.cpp?rev=344335=344334=344335=diff == --- cfe/trunk/lib/Tooling/Execution.cpp (original) +++ cfe/trunk/lib/Tooling/Execution.cpp Fri Oct 12 04:47:36 2018 @@ -16,7 +16,7 @@ LLVM_INSTANTIATE_REGISTRY(clang::tooling namespace clang { namespace tooling { -static llvm::cl::opt +llvm::cl::opt ExecutorName("executor", llvm::cl::desc("The name of the executor to use."), llvm::cl::init("standalone")); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r344267 - Revert "[Lex] TokenConcatenation now takes const Preprocessor"
Author: ioeric Date: Thu Oct 11 10:50:04 2018 New Revision: 344267 URL: http://llvm.org/viewvc/llvm-project?rev=344267=rev Log: Revert "[Lex] TokenConcatenation now takes const Preprocessor" This reverts commit r344262. This was an unintentional commit. Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h?rev=344267=344266=344267=diff == --- cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h Thu Oct 11 10:50:04 2018 @@ -79,9 +79,9 @@ class FieldNode { protected: const FieldRegion *FR; - // TODO: This destructor shouldn't be virtual, but breaks buildbots with - // -Werror -Wnon-virtual-dtor. - virtual ~FieldNode() = default; + /// FieldNodes are never meant to be created on the heap, see + /// FindUninitializedFields::addFieldToUninits(). + /* non-virtual */ ~FieldNode() = default; public: FieldNode(const FieldRegion *FR) : FR(FR) {} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r344266 - clang-cl: set output of lit-test to a tmp file after r344234
Author: ioeric Date: Thu Oct 11 10:49:20 2018 New Revision: 344266 URL: http://llvm.org/viewvc/llvm-project?rev=344266=rev Log: clang-cl: set output of lit-test to a tmp file after r344234 Some test frameworks do not allow output file in CWD. Modified: cfe/trunk/test/Driver/cl-showfilenames.c Modified: cfe/trunk/test/Driver/cl-showfilenames.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-showfilenames.c?rev=344266=344265=344266=diff == --- cfe/trunk/test/Driver/cl-showfilenames.c (original) +++ cfe/trunk/test/Driver/cl-showfilenames.c Thu Oct 11 10:49:20 2018 @@ -1,8 +1,8 @@ -// RUN: %clang_cl /c /showFilenames -- %s 2>&1 | FileCheck -check-prefix=show %s -// RUN: %clang_cl /c /showFilenames -- %s %S/Inputs/wildcard*.c 2>&1 | FileCheck -check-prefix=multiple %s +// RUN: %clang_cl /c /o %t.obj /showFilenames -- %s 2>&1 | FileCheck -check-prefix=show %s +// RUN: %clang_cl /c /o %t.obj /showFilenames -- %s %S/Inputs/wildcard*.c 2>&1 | FileCheck -check-prefix=multiple %s -// RUN: %clang_cl /c -- %s 2>&1 | FileCheck -check-prefix=noshow %s -// RUN: %clang_cl /c /showFilenames /showFilenames- -- %s 2>&1 | FileCheck -check-prefix=noshow %s +// RUN: %clang_cl /c /o %t.obj -- %s 2>&1 | FileCheck -check-prefix=noshow %s +// RUN: %clang_cl /c /o %t.obj /showFilenames /showFilenames- -- %s 2>&1 | FileCheck -check-prefix=noshow %s #pragma message "Hello" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r344262 - [Lex] TokenConcatenation now takes const Preprocessor
Author: ioeric Date: Thu Oct 11 10:35:29 2018 New Revision: 344262 URL: http://llvm.org/viewvc/llvm-project?rev=344262=rev Log: [Lex] TokenConcatenation now takes const Preprocessor Differential Revision: https://reviews.llvm.org/D52502 Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h?rev=344262=344261=344262=diff == --- cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h Thu Oct 11 10:35:29 2018 @@ -79,9 +79,9 @@ class FieldNode { protected: const FieldRegion *FR; - /// FieldNodes are never meant to be created on the heap, see - /// FindUninitializedFields::addFieldToUninits(). - /* non-virtual */ ~FieldNode() = default; + // TODO: This destructor shouldn't be virtual, but breaks buildbots with + // -Werror -Wnon-virtual-dtor. + virtual ~FieldNode() = default; public: FieldNode(const FieldRegion *FR) : FR(FR) {} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r344055 - [clang-move] Fix broken json output.
Author: ioeric Date: Tue Oct 9 08:17:16 2018 New Revision: 344055 URL: http://llvm.org/viewvc/llvm-project?rev=344055=rev Log: [clang-move] Fix broken json output. Modified: clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp Modified: clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp?rev=344055=344054=344055=diff == --- clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp (original) +++ clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp Tue Oct 9 08:17:16 2018 @@ -128,7 +128,7 @@ int main(int argc, const char **argv) { InitialDirectory.str(), Style, DumpDecls}; move::DeclarationReporter Reporter; move::ClangMoveActionFactory Factory(, ); - + int CodeStatus = Tool.run(); if (CodeStatus) return CodeStatus; @@ -138,8 +138,9 @@ int main(int argc, const char **argv) { const auto = Reporter.getDeclarationList(); for (auto I = Declarations.begin(), E = Declarations.end(); I != E; ++I) { llvm::outs() << " {\n"; - llvm::outs() << "\"DeclarationName\": \"" << I->QualifiedName << "\",\n"; - llvm::outs() << "\"DeclarationType\": \"" << I->Kind << "\"\n"; + llvm::outs() << "\"DeclarationName\": \"" << I->QualifiedName + << "\",\n"; + llvm::outs() << "\"DeclarationType\": \"" << I->Kind << "\",\n"; llvm::outs() << "\"Templated\": " << (I->Templated ? "true" : "false") << "\n"; llvm::outs() << " }"; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r344024 - [clangd] Avoid cache main file status in preamble.
Author: ioeric Date: Tue Oct 9 01:27:31 2018 New Revision: 344024 URL: http://llvm.org/viewvc/llvm-project?rev=344024=rev Log: [clangd] Avoid cache main file status in preamble. Summary: Main file can certainly change when reusing preamble. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D52991 Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp clang-tools-extra/trunk/clangd/FS.cpp clang-tools-extra/trunk/clangd/FS.h clang-tools-extra/trunk/unittests/clangd/FSTests.cpp Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=344024=344023=344024=diff == --- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Tue Oct 9 01:27:31 2018 @@ -29,6 +29,7 @@ #include "clang/Serialization/ASTWriter.h" #include "clang/Tooling/CompilationDatabase.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Support/raw_ostream.h" @@ -336,7 +337,9 @@ std::shared_ptr clan // dirs. } - auto StatCache = llvm::make_unique(); + llvm::SmallString<32> AbsFileName(FileName); + Inputs.FS->makeAbsolute(AbsFileName); + auto StatCache = llvm::make_unique(AbsFileName); auto BuiltPreamble = PrecompiledPreamble::Build( CI, ContentsBuffer.get(), Bounds, *PreambleDiagsEngine, StatCache->getProducingFS(Inputs.FS), PCHs, StoreInMemory, Modified: clang-tools-extra/trunk/clangd/FS.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FS.cpp?rev=344024=344023=344024=diff == --- clang-tools-extra/trunk/clangd/FS.cpp (original) +++ clang-tools-extra/trunk/clangd/FS.cpp Tue Oct 9 01:27:31 2018 @@ -10,14 +10,23 @@ #include "FS.h" #include "clang/Basic/VirtualFileSystem.h" #include "llvm/ADT/None.h" +#include "llvm/Support/Path.h" namespace clang { namespace clangd { +PreambleFileStatusCache::PreambleFileStatusCache(llvm::StringRef MainFilePath) +: MainFilePath(MainFilePath) { + assert(llvm::sys::path::is_absolute(MainFilePath)); +} + void PreambleFileStatusCache::update(const vfs::FileSystem , vfs::Status S) { SmallString<32> PathStore(S.getName()); if (FS.makeAbsolute(PathStore)) return; + // Do not cache status for the main file. + if (PathStore == MainFilePath) +return; // Stores the latest status in cache as it can change in a preamble build. StatCache.insert({PathStore, std::move(S)}); } Modified: clang-tools-extra/trunk/clangd/FS.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FS.h?rev=344024=344023=344024=diff == --- clang-tools-extra/trunk/clangd/FS.h (original) +++ clang-tools-extra/trunk/clangd/FS.h Tue Oct 9 01:27:31 2018 @@ -17,10 +17,10 @@ namespace clang { namespace clangd { /// Records status information for files open()ed or stat()ed during preamble -/// build, so we can avoid stat()s on the underlying FS when reusing the -/// preamble. For example, code completion can re-stat files when getting FileID -/// for source locations stored in preamble (e.g. checking whether a location is -/// in the main file). +/// build (except for the main file), so we can avoid stat()s on the underlying +/// FS when reusing the preamble. For example, code completion can re-stat files +/// when getting FileID for source locations stored in preamble (e.g. checking +/// whether a location is in the main file). /// /// The cache is keyed by absolute path of file name in cached status, as this /// is what preamble stores. @@ -35,7 +35,12 @@ namespace clangd { /// Note that the cache is only valid when reusing preamble. class PreambleFileStatusCache { public: + /// \p MainFilePath is the absolute path of the main source file this preamble + /// corresponds to. The stat for the main file will not be cached. + PreambleFileStatusCache(llvm::StringRef MainFilePath); + void update(const vfs::FileSystem , vfs::Status S); + /// \p Path is a path stored in preamble. llvm::Optional lookup(llvm::StringRef Path) const; @@ -56,6 +61,7 @@ public: getConsumingFS(IntrusiveRefCntPtr FS) const; private: + std::string MainFilePath; llvm::StringMap StatCache; }; Modified: clang-tools-extra/trunk/unittests/clangd/FSTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/FSTests.cpp?rev=344024=344023=344024=diff == --- clang-tools-extra/trunk/unittests/clangd/FSTests.cpp (original) +++
[clang-tools-extra] r343982 - [clang-move] Dump whether a declaration is templated.
Author: ioeric Date: Mon Oct 8 10:22:50 2018 New Revision: 343982 URL: http://llvm.org/viewvc/llvm-project?rev=343982=rev Log: [clang-move] Dump whether a declaration is templated. Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp clang-tools-extra/trunk/clang-move/ClangMove.h clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.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=343982=343981=343982=diff == --- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original) +++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Mon Oct 8 10:22:50 2018 @@ -899,21 +899,21 @@ void ClangMoveTool::onEndOfTranslationUn assert(Reporter); for (const auto *Decl : UnremovedDeclsInOldHeader) { auto Kind = Decl->getKind(); + bool Templated = Decl->isTemplated(); const std::string QualifiedName = Decl->getQualifiedNameAsString(); if (Kind == Decl::Kind::Var) -Reporter->reportDeclaration(QualifiedName, "Variable"); +Reporter->reportDeclaration(QualifiedName, "Variable", Templated); else if (Kind == Decl::Kind::Function || Kind == Decl::Kind::FunctionTemplate) -Reporter->reportDeclaration(QualifiedName, "Function"); +Reporter->reportDeclaration(QualifiedName, "Function", Templated); else if (Kind == Decl::Kind::ClassTemplate || Kind == Decl::Kind::CXXRecord) -Reporter->reportDeclaration(QualifiedName, "Class"); +Reporter->reportDeclaration(QualifiedName, "Class", Templated); else if (Kind == Decl::Kind::Enum) -Reporter->reportDeclaration(QualifiedName, "Enum"); - else if (Kind == Decl::Kind::Typedef || - Kind == Decl::Kind::TypeAlias || +Reporter->reportDeclaration(QualifiedName, "Enum", Templated); + else if (Kind == Decl::Kind::Typedef || Kind == Decl::Kind::TypeAlias || Kind == Decl::Kind::TypeAliasTemplate) -Reporter->reportDeclaration(QualifiedName, "TypeAlias"); +Reporter->reportDeclaration(QualifiedName, "TypeAlias", Templated); } return; } Modified: clang-tools-extra/trunk/clang-move/ClangMove.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.h?rev=343982=343981=343982=diff == --- clang-tools-extra/trunk/clang-move/ClangMove.h (original) +++ clang-tools-extra/trunk/clang-move/ClangMove.h Mon Oct 8 10:22:50 2018 @@ -17,6 +17,7 @@ #include "clang/Tooling/Tooling.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" #include #include #include @@ -31,23 +32,30 @@ public: DeclarationReporter() = default; ~DeclarationReporter() = default; - void reportDeclaration(llvm::StringRef DeclarationName, - llvm::StringRef Type) { -DeclarationList.emplace_back(DeclarationName, Type); + void reportDeclaration(llvm::StringRef DeclarationName, llvm::StringRef Type, + bool Templated) { +DeclarationList.emplace_back(DeclarationName, Type, Templated); }; - // A pair. - // The DeclarationName is a fully qualified name for the declaration, like - // A::B::Foo. The DeclarationKind is a string represents the kind of the - // declaration, currently only "Function" and "Class" are supported. - typedef std::pair DeclarationPair; + struct Declaration { +Declaration(llvm::StringRef QName, llvm::StringRef Kind, bool Templated) +: QualifiedName(QName), Kind(Kind), Templated(Templated) {} + +friend bool operator==(const Declaration , const Declaration ) { + return std::tie(LHS.QualifiedName, LHS.Kind, LHS.Templated) == + std::tie(RHS.QualifiedName, RHS.Kind, RHS.Templated); +} +std::string QualifiedName; // E.g. A::B::Foo. +std::string Kind; // E.g. Function, Class +bool Templated = false;// Whether the declaration is templated. + }; - const std::vector getDeclarationList() const { + const std::vector getDeclarationList() const { return DeclarationList; } private: - std::vector DeclarationList; + std::vector DeclarationList; }; // Specify declarations being moved. It contains all information of the moved Modified: clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp?rev=343982=343981=343982=diff == --- clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp (original) +++ clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp Mon Oct 8 10:22:50
Re: [clang-tools-extra] r343576 - [clangd] Cache FS stat() calls when building preamble.
It didn't seem to work. I have temporarily disabled the test for windows (r343637). On Tue, Oct 2, 2018 at 10:05 PM Eric Liu wrote: > Hi Douglas, > > Thanks for letting me know! The test seemed to be too strict for windows. > r343623 is an attempt to fix. If it still doesn't work, feel free to revert > the commits, and I'll re-investigate on Thursday. > > - Eric > > On Tue, Oct 2, 2018 at 9:25 PM wrote: > >> Hi Eric, >> >> One of the tests you added in this commit is causing a failure on the PS4 >> Windows bot: >> >> >> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/20347/steps/test/logs/stdio >> : >> >> FAIL: Extra Tools Unit Tests :: >> clangd/./ClangdTests.exe/ClangdTests.PreambleVFSStatCache (87 of 344) >> TEST 'Extra Tools Unit Tests :: >> clangd/./ClangdTests.exe/ClangdTests.PreambleVFSStatCache' FAILED >> >> Note: Google Test filter = ClangdTests.PreambleVFSStatCache >> >> [==] Running 1 test from 1 test case. >> >> [--] Global test environment set-up. >> >> [--] 1 test from ClangdTests >> >> [ RUN ] ClangdTests.PreambleVFSStatCache >> >> C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\tools\extra\unittests\clangd\ClangdTests.cpp(1026): >> error: Expected: CountStats["foo.h"] >> >> Which is: 2 >> >> To be equal to: 1u >> >> Which is: 1 >> >> [ FAILED ] ClangdTests.PreambleVFSStatCache (441 ms) >> >> [--] 1 test from ClangdTests (441 ms total) >> >> >> >> [--] Global test environment tear-down >> >> [==] 1 test from 1 test case ran. (441 ms total) >> >> [ PASSED ] 0 tests. >> >> [ FAILED ] 1 test, listed below: >> >> [ FAILED ] ClangdTests.PreambleVFSStatCache >> >> >> >> 1 FAILED TEST >> >> Updating file C:\clangd-test\foo.cpp with command [C:\clangd-test] clang >> -ffreestanding C:\clangd-test\foo.cpp >> -resource-dir=C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.obj\tools\clang\tools\extra\unittests\clangd\..\lib\clang\8.0.0 >> >> Preamble for file C:\clangd-test\foo.cpp cannot be reused. Attempting to >> rebuild it. >> >> Built preamble of size 185492 for file C:\clangd-test\foo.cpp >> >> Code complete: sema context Statement, query scopes [] (AnyScope=false) >> >> Code complete: 1 results from Sema, 0 from Index, 0 matched, 1 returned. >> >> >> >> Can you please take a look? >> >> Douglas Yung >> >> > -Original Message- >> > From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf >> > Of Eric Liu via cfe-commits >> > Sent: Tuesday, October 02, 2018 3:44 >> > To: cfe-commits@lists.llvm.org >> > Subject: [clang-tools-extra] r343576 - [clangd] Cache FS stat() calls >> > when building preamble. >> > >> > Author: ioeric >> > Date: Tue Oct 2 03:43:55 2018 >> > New Revision: 343576 >> > >> > URL: http://llvm.org/viewvc/llvm-project?rev=343576=rev >> > Log: >> > [clangd] Cache FS stat() calls when building preamble. >> > >> > Summary: >> > The file stats can be reused when preamble is reused (e.g. code >> > completion). It's safe to assume that cached status is not outdated as >> > we >> > assume preamble files to remain unchanged. >> > >> > On real file system, this made code completion ~20% faster on a >> > measured file >> > (with big preamble). The preamble build time doesn't change much. >> > >> > Reviewers: sammccall, ilya-biryukov >> > >> > Reviewed By: sammccall >> > >> > Subscribers: mgorny, MaskRay, jkorous, arphaman, kadircet, cfe-commits >> > >> > Differential Revision: https://reviews.llvm.org/D52419 >> > >> > Added: >> > clang-tools-extra/trunk/clangd/FS.cpp >> > clang-tools-extra/trunk/clangd/FS.h >> > clang-tools-extra/trunk/unittests/clangd/FSTests.cpp >> > Modified: >> > clang-tools-extra/trunk/clangd/CMakeLists.txt >> > clang-tools-extra/trunk/clangd/ClangdServer.cpp >> > clang-tools-extra/trunk/clangd/ClangdUnit.cpp >> > clang-tools-extra/trunk/clangd/ClangdUnit.h >> > clang-tools-extra/trunk/clangd
[clang-tools-extra] r343637 - [clangd] Temporarily disable VFS stats cache test for windows.
Author: ioeric Date: Tue Oct 2 14:47:41 2018 New Revision: 343637 URL: http://llvm.org/viewvc/llvm-project?rev=343637=rev Log: [clangd] Temporarily disable VFS stats cache test for windows. Modified: clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp Modified: clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp?rev=343637=343636=343637=diff == --- clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp Tue Oct 2 14:47:41 2018 @@ -963,6 +963,8 @@ TEST_F(ClangdVFSTest, ChangedHeaderFromI Field(::Name, "baz"))); } +// FIXME(ioeric): make this work for windows again. +#ifndef _WIN32 // Check that running code completion doesn't stat() a bunch of files from the // preamble again. (They should be using the preamble's stat-cache) TEST(ClangdTests, PreambleVFSStatCache) { @@ -1028,6 +1030,7 @@ TEST(ClangdTests, PreambleVFSStatCache) EXPECT_THAT(Completions, ElementsAre(Field(::Name, "TestSym"))); } +#endif } // namespace } // namespace clangd ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [clang-tools-extra] r343576 - [clangd] Cache FS stat() calls when building preamble.
Hi Douglas, Thanks for letting me know! The test seemed to be too strict for windows. r343623 is an attempt to fix. If it still doesn't work, feel free to revert the commits, and I'll re-investigate on Thursday. - Eric On Tue, Oct 2, 2018 at 9:25 PM wrote: > Hi Eric, > > One of the tests you added in this commit is causing a failure on the PS4 > Windows bot: > > > http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/20347/steps/test/logs/stdio > : > > FAIL: Extra Tools Unit Tests :: > clangd/./ClangdTests.exe/ClangdTests.PreambleVFSStatCache (87 of 344) > TEST 'Extra Tools Unit Tests :: > clangd/./ClangdTests.exe/ClangdTests.PreambleVFSStatCache' FAILED > > Note: Google Test filter = ClangdTests.PreambleVFSStatCache > > [==] Running 1 test from 1 test case. > > [--] Global test environment set-up. > > [--] 1 test from ClangdTests > > [ RUN ] ClangdTests.PreambleVFSStatCache > > C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\tools\extra\unittests\clangd\ClangdTests.cpp(1026): > error: Expected: CountStats["foo.h"] > > Which is: 2 > > To be equal to: 1u > > Which is: 1 > > [ FAILED ] ClangdTests.PreambleVFSStatCache (441 ms) > > [--] 1 test from ClangdTests (441 ms total) > > > > [--] Global test environment tear-down > > [==] 1 test from 1 test case ran. (441 ms total) > > [ PASSED ] 0 tests. > > [ FAILED ] 1 test, listed below: > > [ FAILED ] ClangdTests.PreambleVFSStatCache > > > > 1 FAILED TEST > > Updating file C:\clangd-test\foo.cpp with command [C:\clangd-test] clang > -ffreestanding C:\clangd-test\foo.cpp > -resource-dir=C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.obj\tools\clang\tools\extra\unittests\clangd\..\lib\clang\8.0.0 > > Preamble for file C:\clangd-test\foo.cpp cannot be reused. Attempting to > rebuild it. > > Built preamble of size 185492 for file C:\clangd-test\foo.cpp > > Code complete: sema context Statement, query scopes [] (AnyScope=false) > > Code complete: 1 results from Sema, 0 from Index, 0 matched, 1 returned. > > > > Can you please take a look? > > Douglas Yung > > > -Original Message- > > From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf > > Of Eric Liu via cfe-commits > > Sent: Tuesday, October 02, 2018 3:44 > > To: cfe-commits@lists.llvm.org > > Subject: [clang-tools-extra] r343576 - [clangd] Cache FS stat() calls > > when building preamble. > > > > Author: ioeric > > Date: Tue Oct 2 03:43:55 2018 > > New Revision: 343576 > > > > URL: http://llvm.org/viewvc/llvm-project?rev=343576=rev > > Log: > > [clangd] Cache FS stat() calls when building preamble. > > > > Summary: > > The file stats can be reused when preamble is reused (e.g. code > > completion). It's safe to assume that cached status is not outdated as > > we > > assume preamble files to remain unchanged. > > > > On real file system, this made code completion ~20% faster on a > > measured file > > (with big preamble). The preamble build time doesn't change much. > > > > Reviewers: sammccall, ilya-biryukov > > > > Reviewed By: sammccall > > > > Subscribers: mgorny, MaskRay, jkorous, arphaman, kadircet, cfe-commits > > > > Differential Revision: https://reviews.llvm.org/D52419 > > > > Added: > > clang-tools-extra/trunk/clangd/FS.cpp > > clang-tools-extra/trunk/clangd/FS.h > > clang-tools-extra/trunk/unittests/clangd/FSTests.cpp > > Modified: > > clang-tools-extra/trunk/clangd/CMakeLists.txt > > clang-tools-extra/trunk/clangd/ClangdServer.cpp > > clang-tools-extra/trunk/clangd/ClangdUnit.cpp > > clang-tools-extra/trunk/clangd/ClangdUnit.h > > clang-tools-extra/trunk/clangd/CodeComplete.cpp > > clang-tools-extra/trunk/clangd/CodeComplete.h > > clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt > > clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp > > clang-tools-extra/trunk/unittests/clangd/TestFS.cpp > > > > Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt > > URL: http://llvm.org/viewvc/llvm-project/clang-tools- > > extra/trunk/clangd/CMakeLists.txt?rev=343576=343575=343576=d > > iff > > === > > === >
[clang-tools-extra] r343623 - [clangd] Try to fix windows buildbot after r343576
Author: ioeric Date: Tue Oct 2 13:00:32 2018 New Revision: 343623 URL: http://llvm.org/viewvc/llvm-project?rev=343623=rev Log: [clangd] Try to fix windows buildbot after r343576 http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/20347/steps/test/logs/stdio Modified: clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp Modified: clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp?rev=343623=343622=343623=diff == --- clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp Tue Oct 2 13:00:32 2018 @@ -1019,11 +1019,12 @@ TEST(ClangdTests, PreambleVFSStatCache) runAddDocument(Server, SourcePath, Code.code()); - EXPECT_EQ(CountStats["foo.h"], 1u); + unsigned Before = CountStats["foo.h"]; + EXPECT_GT(Before, 0u); auto Completions = cantFail(runCodeComplete(Server, SourcePath, Code.point(), clangd::CodeCompleteOptions())) .Completions; - EXPECT_EQ(CountStats["foo.h"], 1u); + EXPECT_EQ(CountStats["foo.h"], Before); EXPECT_THAT(Completions, ElementsAre(Field(::Name, "TestSym"))); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r343576 - [clangd] Cache FS stat() calls when building preamble.
Author: ioeric Date: Tue Oct 2 03:43:55 2018 New Revision: 343576 URL: http://llvm.org/viewvc/llvm-project?rev=343576=rev Log: [clangd] Cache FS stat() calls when building preamble. Summary: The file stats can be reused when preamble is reused (e.g. code completion). It's safe to assume that cached status is not outdated as we assume preamble files to remain unchanged. On real file system, this made code completion ~20% faster on a measured file (with big preamble). The preamble build time doesn't change much. Reviewers: sammccall, ilya-biryukov Reviewed By: sammccall Subscribers: mgorny, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D52419 Added: clang-tools-extra/trunk/clangd/FS.cpp clang-tools-extra/trunk/clangd/FS.h clang-tools-extra/trunk/unittests/clangd/FSTests.cpp Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt clang-tools-extra/trunk/clangd/ClangdServer.cpp clang-tools-extra/trunk/clangd/ClangdUnit.cpp clang-tools-extra/trunk/clangd/ClangdUnit.h clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/clangd/CodeComplete.h clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp clang-tools-extra/trunk/unittests/clangd/TestFS.cpp Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=343576=343575=343576=diff == --- clang-tools-extra/trunk/clangd/CMakeLists.txt (original) +++ clang-tools-extra/trunk/clangd/CMakeLists.txt Tue Oct 2 03:43:55 2018 @@ -21,6 +21,7 @@ add_clang_library(clangDaemon DraftStore.cpp FindSymbols.cpp FileDistance.cpp + FS.cpp FuzzyMatch.cpp GlobalCompilationDatabase.cpp Headers.cpp Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=343576=343575=343576=diff == --- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Oct 2 03:43:55 2018 @@ -181,8 +181,6 @@ void ClangdServer::codeComplete(PathRef if (isCancelled()) return CB(llvm::make_error()); -auto PreambleData = IP->Preamble; - llvm::Optional SpecFuzzyFind; if (CodeCompleteOpts.Index && CodeCompleteOpts.SpeculativeIndexRequest) { SpecFuzzyFind.emplace(); @@ -195,10 +193,8 @@ void ClangdServer::codeComplete(PathRef // 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 ? >Preamble : nullptr, -PreambleData ? PreambleData->Includes : IncludeStructure(), -IP->Contents, Pos, FS, PCHs, CodeCompleteOpts, -SpecFuzzyFind ? SpecFuzzyFind.getPointer() : nullptr); +File, IP->Command, IP->Preamble, IP->Contents, Pos, FS, PCHs, +CodeCompleteOpts, SpecFuzzyFind ? SpecFuzzyFind.getPointer() : nullptr); { clang::clangd::trace::Span Tracer("Completion results callback"); CB(std::move(Result)); @@ -231,9 +227,8 @@ void ClangdServer::signatureHelp(PathRef return CB(IP.takeError()); auto PreambleData = IP->Preamble; -CB(clangd::signatureHelp(File, IP->Command, - PreambleData ? >Preamble : nullptr, - IP->Contents, Pos, FS, PCHs, Index)); +CB(clangd::signatureHelp(File, IP->Command, PreambleData, IP->Contents, Pos, + FS, PCHs, Index)); }; // Unlike code completion, we wait for an up-to-date preamble here. Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=343576=343575=343576=diff == --- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Tue Oct 2 03:43:55 2018 @@ -246,9 +246,10 @@ const IncludeStructure ::getIn } PreambleData::PreambleData(PrecompiledPreamble Preamble, - std::vector Diags, IncludeStructure Includes) + std::vector Diags, IncludeStructure Includes, + std::unique_ptr StatCache) : Preamble(std::move(Preamble)), Diags(std::move(Diags)), - Includes(std::move(Includes)) {} + Includes(std::move(Includes)), StatCache(std::move(StatCache)) {} ParsedAST::ParsedAST(std::shared_ptr Preamble, std::unique_ptr Clang, @@ -334,9 +335,12 @@ std::shared_ptr clan // We proceed anyway, our
Re: r343573 - [Lex] TokenConcatenation now takes const Preprocessor
Sorry, I messed up my svn rebase somehow and committed and reverted this again (r343574) when landing r343575. On Tue, Oct 2, 2018 at 12:30 PM Eric Liu via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: ioeric > Date: Tue Oct 2 03:28:50 2018 > New Revision: 343573 > > URL: http://llvm.org/viewvc/llvm-project?rev=343573=rev > Log: > [Lex] TokenConcatenation now takes const Preprocessor > > Differential Revision: https://reviews.llvm.org/D52502 > > Modified: > > cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h > > Modified: > cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h?rev=343573=343572=343573=diff > > == > --- > cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h > (original) > +++ > cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h > Tue Oct 2 03:28:50 2018 > @@ -79,9 +79,9 @@ class FieldNode { > protected: >const FieldRegion *FR; > > - /// FieldNodes are never meant to be created on the heap, see > - /// FindUninitializedFields::addFieldToUninits(). > - /* non-virtual */ ~FieldNode() = default; > + // TODO: This destructor shouldn't be virtual, but breaks buildbots with > + // -Werror -Wnon-virtual-dtor. > + virtual ~FieldNode() = default; > > public: >FieldNode(const FieldRegion *FR) : FR(FR) {} > > > ___ > 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
r343573 - [Lex] TokenConcatenation now takes const Preprocessor
Author: ioeric Date: Tue Oct 2 03:28:50 2018 New Revision: 343573 URL: http://llvm.org/viewvc/llvm-project?rev=343573=rev Log: [Lex] TokenConcatenation now takes const Preprocessor Differential Revision: https://reviews.llvm.org/D52502 Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h?rev=343573=343572=343573=diff == --- cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h Tue Oct 2 03:28:50 2018 @@ -79,9 +79,9 @@ class FieldNode { protected: const FieldRegion *FR; - /// FieldNodes are never meant to be created on the heap, see - /// FindUninitializedFields::addFieldToUninits(). - /* non-virtual */ ~FieldNode() = default; + // TODO: This destructor shouldn't be virtual, but breaks buildbots with + // -Werror -Wnon-virtual-dtor. + virtual ~FieldNode() = default; public: FieldNode(const FieldRegion *FR) : FR(FR) {} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r343575 - [CodeComplete] Re-fix accessibilty of protected members from base class.
Author: ioeric Date: Tue Oct 2 03:29:00 2018 New Revision: 343575 URL: http://llvm.org/viewvc/llvm-project?rev=343575=rev Log: [CodeComplete] Re-fix accessibilty of protected members from base class. Summary: The initial fix (r337453) had bug and was partially reverted (r338255). This simplies the original fix by explicitly passing the naming class to the completion consumer. Reviewers: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52647 Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp cfe/trunk/lib/Sema/SemaLookup.cpp cfe/trunk/test/Index/complete-access-checks.cpp Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=343575=343574=343575=diff == --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original) +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue Oct 2 03:29:00 2018 @@ -10,6 +10,7 @@ // This file defines the code-completion semantic actions. // //===--===// +#include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/ExprCXX.h" @@ -1295,18 +1296,29 @@ namespace { ResultBuilder DeclContext *CurContext; std::vector FixIts; +// This is set to the record where the search starts, if this is a record +// member completion. +RecordDecl *MemberCompletionRecord = nullptr; public: CodeCompletionDeclConsumer( ResultBuilder , DeclContext *CurContext, -std::vector FixIts = std::vector()) -: Results(Results), CurContext(CurContext), FixIts(std::move(FixIts)) {} +std::vector FixIts = std::vector(), +RecordDecl *MemberCompletionRecord = nullptr) +: Results(Results), CurContext(CurContext), FixIts(std::move(FixIts)), + MemberCompletionRecord(MemberCompletionRecord) {} void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx, bool InBaseClass) override { bool Accessible = true; - if (Ctx) -Accessible = Results.getSema().IsSimplyAccessible(ND, Ctx); + if (Ctx) { +// Set the actual accessing context (i.e. naming class) to the record +// context where the search starts. When `InBaseClass` is true, `Ctx` +// will be the base class, which is not the actual naming class. +DeclContext *AccessingCtx = +MemberCompletionRecord ? MemberCompletionRecord : Ctx; +Accessible = Results.getSema().IsSimplyAccessible(ND, AccessingCtx); + } ResultBuilder::Result Result(ND, Results.getBasePriority(ND), nullptr, false, Accessible, FixIts); Results.AddResult(Result, CurContext, Hiding, InBaseClass); @@ -4101,7 +4113,8 @@ static void AddRecordMembersCompletionRe std::vector FixIts; if (AccessOpFixIt) FixIts.emplace_back(AccessOpFixIt.getValue()); - CodeCompletionDeclConsumer Consumer(Results, SemaRef.CurContext, std::move(FixIts)); + CodeCompletionDeclConsumer Consumer(Results, SemaRef.CurContext, + std::move(FixIts), RD); SemaRef.LookupVisibleDecls(RD, Sema::LookupMemberName, Consumer, SemaRef.CodeCompleter->includeGlobals(), /*IncludeDependentBases=*/true, Modified: cfe/trunk/lib/Sema/SemaLookup.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=343575=343574=343575=diff == --- cfe/trunk/lib/Sema/SemaLookup.cpp (original) +++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Oct 2 03:29:00 2018 @@ -3619,8 +3619,9 @@ static void LookupVisibleDecls(DeclConte // Find results in this base class (and its bases). ShadowContextRAII Shadow(Visited); - LookupVisibleDecls(RD, Result, QualifiedNameLookup, true, Consumer, - Visited, IncludeDependentBases, LoadExternal); + LookupVisibleDecls(RD, Result, QualifiedNameLookup, /*InBaseClass=*/true, + Consumer, Visited, IncludeDependentBases, + LoadExternal); } } Modified: cfe/trunk/test/Index/complete-access-checks.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-access-checks.cpp?rev=343575=343574=343575=diff == --- cfe/trunk/test/Index/complete-access-checks.cpp (original) +++ cfe/trunk/test/Index/complete-access-checks.cpp Tue Oct 2 03:29:00 2018 @@ -36,10 +36,10 @@ void Y::doSomething() { // CHECK-SUPER-ACCESS: CXXMethod:{ResultType void}{TypedText doSomething}{LeftParen (}{RightParen )} (34) // CHECK-SUPER-ACCESS: CXXMethod:{ResultType void}{Informative X::}{TypedText
r343574 - Revert untintentionally commited changes
Author: ioeric Date: Tue Oct 2 03:28:54 2018 New Revision: 343574 URL: http://llvm.org/viewvc/llvm-project?rev=343574=rev Log: Revert untintentionally commited changes Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h?rev=343574=343573=343574=diff == --- cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h Tue Oct 2 03:28:54 2018 @@ -79,9 +79,9 @@ class FieldNode { protected: const FieldRegion *FR; - // TODO: This destructor shouldn't be virtual, but breaks buildbots with - // -Werror -Wnon-virtual-dtor. - virtual ~FieldNode() = default; + /// FieldNodes are never meant to be created on the heap, see + /// FindUninitializedFields::addFieldToUninits(). + /* non-virtual */ ~FieldNode() = default; public: FieldNode(const FieldRegion *FR) : FR(FR) {} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r343448 - [clangd] Fix header mapping for std::string. NFC
Author: ioeric Date: Mon Oct 1 01:50:49 2018 New Revision: 343448 URL: http://llvm.org/viewvc/llvm-project?rev=343448=rev Log: [clangd] Fix header mapping for std::string. NFC Some implementation has std::string declared in . 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=343448=343447=343448=diff == --- clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp (original) +++ clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp Mon Oct 1 01:50:49 2018 @@ -143,6 +143,7 @@ void addSystemHeadersMapping(CanonicalIn {"std::basic_stringstream", ""}, {"std::istringstream", ""}, {"std::ostringstream", ""}, + {"std::string", ""}, {"std::stringbuf", ""}, {"std::stringstream", ""}, {"std::wistringstream", ""}, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r337453 - [CodeComplete] Fix accessibilty of protected members from base class.
PTAL: https://reviews.llvm.org/D52647 On Fri, Sep 28, 2018 at 2:13 PM Eric Liu wrote: > (Oops, forgot there was this thread. Pasting my response to r338255 here). > > > The code seemed obviously wrong there (calling accessibility checking, > passing a possibly unrelated class) and the tests didn't break after > reverting it. > It turns out that this was due to my lacking LIT test skill. LIT does > partial string match... so "something" would match both "something" and > "something (inaccessible)" XD > > I actually tried to pass the correct derived scope to > CodeCompletionDeclConsumer on construction, it was not a lot of code and I > think this should fix the problem you're describing. > > I'll send a patch. > Any luck on this? > > On Tue, Jul 31, 2018 at 12:24 PM Ilya Biryukov > wrote: > >> I actually tried to pass the correct derived scope to >> CodeCompletionDeclConsumer on construction, it was not a lot of code and I >> think this should fix the problem you're describing. >> I'll send a patch. >> >> On Tue, Jul 31, 2018 at 11:33 AM Eric Liu wrote: >> >>> 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=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=337452=337453=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/CXXInh
Re: r337453 - [CodeComplete] Fix accessibilty of protected members from base class.
(Oops, forgot there was this thread. Pasting my response to r338255 here). > The code seemed obviously wrong there (calling accessibility checking, passing a possibly unrelated class) and the tests didn't break after reverting it. It turns out that this was due to my lacking LIT test skill. LIT does partial string match... so "something" would match both "something" and "something (inaccessible)" XD > I actually tried to pass the correct derived scope to CodeCompletionDeclConsumer on construction, it was not a lot of code and I think this should fix the problem you're describing. > I'll send a patch. Any luck on this? On Tue, Jul 31, 2018 at 12:24 PM Ilya Biryukov wrote: > I actually tried to pass the correct derived scope to > CodeCompletionDeclConsumer on construction, it was not a lot of code and I > think this should fix the problem you're describing. > I'll send a patch. > > On Tue, Jul 31, 2018 at 11:33 AM Eric Liu wrote: > >> 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=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=337452=337453=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. >>>>
Re: r338255 - [CodeComplete] Fix the crash in code completion on access checking
On Mon, Jul 30, 2018 at 5:19 PM Ilya Biryukov via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: ibiryukov > Date: Mon Jul 30 08:19:05 2018 > New Revision: 338255 > > URL: http://llvm.org/viewvc/llvm-project?rev=338255=rev > Log: > [CodeComplete] Fix the crash in code completion on access checking > > Started crashing in r337453. See the added test case for the crash repro. > > The fix reverts part of r337453 that causes the crash and does > not actually break anything when reverted. > It turns out that this was due to lit's partial string match ... so "something" would match both "something" and "something (inaccessible)" XD The protected member bug came up again after the revert, but it was the right thing to do to fix the crash. I'll look into a proper fix. > > Added: > cfe/trunk/test/Index/complete-access-checks-crash.cpp > Modified: > cfe/trunk/lib/Sema/SemaCodeComplete.cpp > > Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=338255=338254=338255=diff > > == > --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original) > +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Mon Jul 30 08:19:05 2018 > @@ -1303,34 +1303,8 @@ namespace { > void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx, > bool InBaseClass) override { >bool Accessible = true; > - 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()) { > -if ((RC = dyn_cast(DC))) > - break; > - } > - if (RC) > -AccessingCtx = RC; > -} > -Accessible = Results.getSema().IsSimplyAccessible(ND, > AccessingCtx); > - } > - > + if (Ctx) > +Accessible = Results.getSema().IsSimplyAccessible(ND, Ctx); >ResultBuilder::Result Result(ND, Results.getBasePriority(ND), > nullptr, > false, Accessible, FixIts); >Results.AddResult(Result, CurContext, Hiding, InBaseClass); > > Added: cfe/trunk/test/Index/complete-access-checks-crash.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-access-checks-crash.cpp?rev=338255=auto > > == > --- cfe/trunk/test/Index/complete-access-checks-crash.cpp (added) > +++ cfe/trunk/test/Index/complete-access-checks-crash.cpp Mon Jul 30 > 08:19:05 2018 > @@ -0,0 +1,13 @@ > +struct Base { > +protected: > + bool bar(); > +}; > +struct Derived : Base { > +}; > + > +struct X { > + int foo() { > +Derived(). // RUN: c-index-test -code-completion-at=%s:10:15 %s | > FileCheck %s > +// CHECK: bar{{.*}}(inaccessible) > + } > +}; > > > ___ > 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] r343248 - [clangd] Initial supoprt for cross-namespace global code completion.
Author: ioeric Date: Thu Sep 27 11:46:00 2018 New Revision: 343248 URL: http://llvm.org/viewvc/llvm-project?rev=343248=rev Log: [clangd] Initial supoprt for cross-namespace global code completion. Summary: When no scope qualifier is specified, allow completing index symbols from any scope and insert proper automatically. This is still experimental and hidden behind a flag. Things missing: - Scope proximity based scoring. - FuzzyFind supports weighted scopes. Reviewers: sammccall Reviewed By: sammccall Subscribers: kbobyrev, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D52364 Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/clangd/CodeComplete.h clang-tools-extra/trunk/clangd/index/Index.h clang-tools-extra/trunk/clangd/index/MemIndex.cpp clang-tools-extra/trunk/clangd/index/dex/Dex.cpp clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp clang-tools-extra/trunk/unittests/clangd/DexTests.cpp Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=343248=343247=343248=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu Sep 27 11:46:00 2018 @@ -44,6 +44,7 @@ #include "clang/Sema/CodeCompleteConsumer.h" #include "clang/Sema/Sema.h" #include "clang/Tooling/Core/Replacement.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Error.h" @@ -330,6 +331,7 @@ struct ScoredBundleGreater { struct CodeCompletionBuilder { CodeCompletionBuilder(ASTContext , const CompletionCandidate , CodeCompletionString *SemaCCS, +llvm::ArrayRef QueryScopes, const IncludeInserter , StringRef FileName, CodeCompletionContext::Kind ContextKind, const CodeCompleteOptions ) @@ -374,6 +376,18 @@ struct CodeCompletionBuilder { Completion.Kind = toCompletionItemKind(C.IndexResult->SymInfo.Kind); if (Completion.Name.empty()) Completion.Name = C.IndexResult->Name; + // If the completion was visible to Sema, no qualifier is needed. This + // avoids unneeded qualifiers in cases like with `using ns::X`. + if (Completion.RequiredQualifier.empty() && !C.SemaResult) { +StringRef ShortestQualifier = C.IndexResult->Scope; +for (StringRef Scope : QueryScopes) { + StringRef Qualifier = C.IndexResult->Scope; + if (Qualifier.consume_front(Scope) && + Qualifier.size() < ShortestQualifier.size()) +ShortestQualifier = Qualifier; +} +Completion.RequiredQualifier = ShortestQualifier; + } Completion.Deprecated |= (C.IndexResult->Flags & Symbol::Deprecated); } @@ -604,9 +618,11 @@ struct SpecifiedScope { } }; -// Get all scopes that will be queried in indexes. -std::vector getQueryScopes(CodeCompletionContext , -const SourceManager ) { +// Get all scopes that will be queried in indexes and whether symbols from +// any scope is allowed. +std::pair, bool> +getQueryScopes(CodeCompletionContext , const SourceManager , + const CodeCompleteOptions ) { auto GetAllAccessibleScopes = [](CodeCompletionContext ) { SpecifiedScope Info; for (auto *Context : CCContext.getVisitedContexts()) { @@ -627,13 +643,15 @@ std::vector getQueryScopes( // FIXME: Capture scopes and use for scoring, for example, //"using namespace std; namespace foo {v^}" => //foo::value > std::vector > boost::variant -return GetAllAccessibleScopes(CCContext).scopesForIndexQuery(); +auto Scopes = GetAllAccessibleScopes(CCContext).scopesForIndexQuery(); +// Allow AllScopes completion only for there is no explicit scope qualifier. +return {Scopes, Opts.AllScopes}; } // Qualified completion ("std::vec^"), we have two cases depending on whether // the qualifier can be resolved by Sema. if ((*SS)->isValid()) { // Resolved qualifier. -return GetAllAccessibleScopes(CCContext).scopesForIndexQuery(); +return {GetAllAccessibleScopes(CCContext).scopesForIndexQuery(), false}; } // Unresolved qualifier. @@ -651,7 +669,7 @@ std::vector getQueryScopes( if (!Info.UnresolvedQualifier->empty()) *Info.UnresolvedQualifier += "::"; - return Info.scopesForIndexQuery(); + return {Info.scopesForIndexQuery(), false}; } // Should we perform index-based completion in a context of the specified kind? @@ -1262,8 +1280,10 @@ class CodeCompleteFlow { CompletionRecorder *Recorder = nullptr; int
[clang-tools-extra] r343247 - [clangd] Add more tracing to index queries. NFC
Author: ioeric Date: Thu Sep 27 11:23:23 2018 New Revision: 343247 URL: http://llvm.org/viewvc/llvm-project?rev=343247=rev Log: [clangd] Add more tracing to index queries. NFC Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D52611 Modified: clang-tools-extra/trunk/clangd/index/MemIndex.cpp clang-tools-extra/trunk/clangd/index/Merge.cpp clang-tools-extra/trunk/clangd/index/dex/Dex.cpp 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=343247=343246=343247=diff == --- clang-tools-extra/trunk/clangd/index/MemIndex.cpp (original) +++ clang-tools-extra/trunk/clangd/index/MemIndex.cpp Thu Sep 27 11:23:23 2018 @@ -11,6 +11,7 @@ #include "FuzzyMatch.h" #include "Logger.h" #include "Quality.h" +#include "Trace.h" namespace clang { namespace clangd { @@ -28,6 +29,7 @@ bool MemIndex::fuzzyFind( llvm::function_ref Callback) const { assert(!StringRef(Req.Query).contains("::") && "There must be no :: in query."); + trace::Span Tracer("MemIndex fuzzyFind"); TopN> Top( Req.Limit ? *Req.Limit : std::numeric_limits::max()); @@ -47,13 +49,16 @@ bool MemIndex::fuzzyFind( if (Top.push({*Score * quality(*Sym), Sym})) More = true; // An element with smallest score was discarded. } - for (const auto : std::move(Top).items()) + auto Results = std::move(Top).items(); + SPAN_ATTACH(Tracer, "results", static_cast(Results.size())); + for (const auto : Results) Callback(*Item.second); return More; } void MemIndex::lookup(const LookupRequest , llvm::function_ref Callback) const { + trace::Span Tracer("MemIndex lookup"); for (const auto : Req.IDs) { auto I = Index.find(ID); if (I != Index.end()) @@ -63,6 +68,7 @@ void MemIndex::lookup(const LookupReques void MemIndex::refs(const RefsRequest , llvm::function_ref Callback) const { + trace::Span Tracer("MemIndex refs"); for (const auto : Req.IDs) { auto SymRefs = Refs.find(ReqID); if (SymRefs == Refs.end()) 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=343247=343246=343247=diff == --- clang-tools-extra/trunk/clangd/index/Merge.cpp (original) +++ clang-tools-extra/trunk/clangd/index/Merge.cpp Thu Sep 27 11:23:23 2018 @@ -9,6 +9,7 @@ #include "Merge.h" #include "Logger.h" +#include "Trace.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/raw_ostream.h" @@ -38,19 +39,31 @@ class MergedIndex : public SymbolIndex { //a) if it's not in the dynamic slab, yield it directly //b) if it's in the dynamic slab, merge it and yield the result // 3) now yield all the dynamic symbols we haven't processed. + trace::Span Tracer("MergedIndex fuzzyFind"); bool More = false; // We'll be incomplete if either source was. SymbolSlab::Builder DynB; - More |= Dynamic->fuzzyFind(Req, [&](const Symbol ) { DynB.insert(S); }); + unsigned DynamicCount = 0; + unsigned StaticCount = 0; + unsigned MergedCount = 0; + More |= Dynamic->fuzzyFind(Req, [&](const Symbol ) { + ++DynamicCount; + DynB.insert(S); + }); SymbolSlab Dyn = std::move(DynB).build(); DenseSet SeenDynamicSymbols; More |= Static->fuzzyFind(Req, [&](const Symbol ) { auto DynS = Dyn.find(S.ID); + ++StaticCount; if (DynS == Dyn.end()) return Callback(S); + ++MergedCount; SeenDynamicSymbols.insert(S.ID); Callback(mergeSymbol(*DynS, S)); }); + SPAN_ATTACH(Tracer, "dynamic", DynamicCount); + SPAN_ATTACH(Tracer, "static", StaticCount); + SPAN_ATTACH(Tracer, "merged", MergedCount); for (const Symbol : Dyn) if (!SeenDynamicSymbols.count(S.ID)) Callback(S); @@ -60,6 +73,7 @@ class MergedIndex : public SymbolIndex { void lookup(const LookupRequest , llvm::function_ref Callback) const override { +trace::Span Tracer("MergedIndex lookup"); SymbolSlab::Builder B; Dynamic->lookup(Req, [&](const Symbol ) { B.insert(S); }); @@ -80,6 +94,7 @@ class MergedIndex : public SymbolIndex { void refs(const RefsRequest , llvm::function_ref Callback) const override { +trace::Span Tracer("MergedIndex refs"); // We don't want duplicated refs from the static/dynamic indexes, // and we can't reliably duplicate them because offsets may differ slightly. // We consider the dynamic index authoritative and report all its refs, Modified:
r343224 - [Tooling] Get rid of uses of llvm::Twine::str which is slow. NFC
Author: ioeric Date: Thu Sep 27 07:50:24 2018 New Revision: 343224 URL: http://llvm.org/viewvc/llvm-project?rev=343224=rev Log: [Tooling] Get rid of uses of llvm::Twine::str which is slow. NFC Modified: cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp Modified: cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp?rev=343224=343223=343224=diff == --- cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp (original) +++ cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp Thu Sep 27 07:50:24 2018 @@ -10,6 +10,7 @@ #include "clang/Tooling/Inclusions/HeaderIncludes.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/Lexer.h" +#include "llvm/Support/FormatVariadic.h" namespace clang { namespace tooling { @@ -181,7 +182,7 @@ bool IncludeCategoryManager::isMainHeade llvm::sys::path::stem(IncludeName.drop_front(1).drop_back(1)); if (FileStem.startswith(HeaderStem) || FileStem.startswith_lower(HeaderStem)) { -llvm::Regex MainIncludeRegex((HeaderStem + Style.IncludeIsMainRegex).str(), +llvm::Regex MainIncludeRegex(HeaderStem.str() + Style.IncludeIsMainRegex, llvm::Regex::IgnoreCase); if (MainIncludeRegex.match(FileStem)) return true; @@ -275,8 +276,8 @@ HeaderIncludes::insert(llvm::StringRef I if ((IsAngled && StringRef(Inc.Name).startswith("<")) || (!IsAngled && StringRef(Inc.Name).startswith("\""))) return llvm::None; - std::string Quoted = IsAngled ? ("<" + IncludeName + ">").str() -: ("\"" + IncludeName + "\"").str(); + std::string Quoted = + llvm::formatv(IsAngled ? "<{0}>" : "\"{0}\"", IncludeName); StringRef QuotedName = Quoted; int Priority = Categories.getIncludePriority( QuotedName, /*CheckMainHeader=*/FirstIncludeOffset < 0); @@ -293,7 +294,7 @@ HeaderIncludes::insert(llvm::StringRef I } } assert(InsertOffset <= Code.size()); - std::string NewInclude = ("#include " + QuotedName + "\n").str(); + std::string NewInclude = llvm::formatv("#include {0}\n", QuotedName); // When inserting headers at end of the code, also append '\n' to the code // if it does not end with '\n'. // FIXME: when inserting multiple #includes at the end of code, only one ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r343223 - [clangd] Make IncludeInserter less slow. NFC
Author: ioeric Date: Thu Sep 27 07:27:02 2018 New Revision: 343223 URL: http://llvm.org/viewvc/llvm-project?rev=343223=rev Log: [clangd] Make IncludeInserter less slow. NFC Modified: clang-tools-extra/trunk/clangd/Headers.cpp clang-tools-extra/trunk/clangd/Headers.h Modified: clang-tools-extra/trunk/clangd/Headers.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.cpp?rev=343223=343222=343223=diff == --- clang-tools-extra/trunk/clangd/Headers.cpp (original) +++ clang-tools-extra/trunk/clangd/Headers.cpp Thu Sep 27 07:27:02 2018 @@ -126,6 +126,12 @@ IncludeStructure::includeDepth(llvm::Str return Result; } +void IncludeInserter::addExisting(const Inclusion ) { + IncludedHeaders.insert(Inc.Written); + if (!Inc.Resolved.empty()) +IncludedHeaders.insert(Inc.Resolved); +} + /// FIXME(ioeric): we might not want to insert an absolute include path if the /// path is not shortened. bool IncludeInserter::shouldInsertInclude( @@ -133,12 +139,6 @@ bool IncludeInserter::shouldInsertInclud assert(DeclaringHeader.valid() && InsertedHeader.valid()); if (FileName == DeclaringHeader.File || FileName == InsertedHeader.File) return false; - llvm::StringSet<> IncludedHeaders; - for (const auto : Inclusions) { -IncludedHeaders.insert(Inc.Written); -if (!Inc.Resolved.empty()) - IncludedHeaders.insert(Inc.Resolved); - } auto Included = [&](llvm::StringRef Header) { return IncludedHeaders.find(Header) != IncludedHeaders.end(); }; Modified: clang-tools-extra/trunk/clangd/Headers.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.h?rev=343223=343222=343223=diff == --- clang-tools-extra/trunk/clangd/Headers.h (original) +++ clang-tools-extra/trunk/clangd/Headers.h Thu Sep 27 07:27:02 2018 @@ -97,7 +97,7 @@ public: HeaderSearchInfo(HeaderSearchInfo), Inserter(FileName, Code, Style.IncludeStyle) {} - void addExisting(Inclusion Inc) { Inclusions.push_back(std::move(Inc)); } + void addExisting(const Inclusion ); /// Checks whether to add an #include of the header into \p File. /// An #include will not be added if: @@ -134,8 +134,8 @@ private: StringRef Code; StringRef BuildDir; HeaderSearch - std::vector Inclusions; - tooling::HeaderIncludes Inserter; // Computers insertion replacement. + llvm::StringSet<> IncludedHeaders; // Both written and resolved. + tooling::HeaderIncludes Inserter; // Computers insertion replacement. }; } // namespace clangd ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [clang-tools-extra] r342730 - [clangd] Remember to serialize symbol origin in YAML.
I think it depends on how you interpret the origin. You could tie the origin to the index or to the producer of the symbol. The current model seems to be the later (origin is a configuration in SymbolCollector. MergeIndex manipulates the origin, but I would rather treat that as a special case). And I think it's conceptually simpler and more generic (origin can be more than dynamic vs static). The downside is probably that all symbols in yaml would have the same origin, which is a bit redundant but doesn't seem to matter much. Both models have their pros and cons, but I don't think it's worth spending much time figuring out which one is better when it seems like a non-issue. On Tue, Sep 25, 2018 at 6:58 PM Ilya Biryukov wrote: > > > Eric Liu schrieb am Di., 25. Sep. 2018, 01:22: > >> On Tue, Sep 25, 2018 at 6:34 AM Ilya Biryukov >> wrote: >> >>> Why would we want to serialize the origin? >>> >> We only serialize and deserialize for the static index, it does not seem >>> to be useful to serialize origin in that scenario. >>> >> We serialize Origin because it's a property of Symbol? The origin for the >> current YAML symbols is defaulted to "unknown". >> > My view would be that it's a property of a symbol living in memory, but > not the serialized one. E.g. all symbols read from the yaml index should > have the static origin. If we store an origin, we allow loading symbols > with non-static origin, it's hard to see how that would be useful. > > > > >> It's true that we *currently* only serialize symbols from static index, >> but there is nothing preventing us from doing it for other indexes with >> different origins. You could probably override origins when loading static >> index, but that doesn't seem to work in general. >> > The origin seems to be exactly the field that is set and manipulated by > index implementations, but they all have the knowledge on what their origin > is or how to combine origins of subindexes. > > Again, it seems there are two classes hiding in symbol. All other fields > provide useful information about C++ semantics of the symbol, while origin > provides some traceability when combining indexes. The former is something > we need to serialize, the latter is something we can infer when > deserializing. > > If we will have a use case for serializing the latter entity(with origin) > for any reason, we might add that separately. > > Not sure if it's worth the trouble changing it, just wanted to point out > that storing the origin for each symbol in the yaml index for the purpose > of indicating that the symbol is in the yaml index seems to be a bit off. > > > >> I checked this in without review as I thought this was a trivial fix. The >> binary serialization also serializes the Origin field. >> > LG to be consistent with binary serialization, the same question applies > to binary serialization. > > Again, the change itself seems fine, just nitpicking on whether putting > origin into a symbol at that level makes sense. > > > >>> Am I missing something? >>> >> >>> On Fri, Sep 21, 2018 at 3:06 PM Eric Liu via cfe-commits < >>> cfe-commits@lists.llvm.org> wrote: >>> >>>> Author: ioeric >>>> Date: Fri Sep 21 06:04:57 2018 >>>> New Revision: 342730 >>>> >>>> URL: http://llvm.org/viewvc/llvm-project?rev=342730=rev >>>> Log: >>>> [clangd] Remember to serialize symbol origin in YAML. >>>> >>>> Modified: >>>> clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp >>>> clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp >>>> >>>> Modified: clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp >>>> URL: >>>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp?rev=342730=342729=342730=diff >>>> >>>> == >>>> --- clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp (original) >>>> +++ clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp Fri Sep 21 >>>> 06:04:57 2018 >>>> @@ -27,6 +27,7 @@ namespace yaml { >>>> >>>> using clang::clangd::Symbol; >>>> using clang::clangd::SymbolID; >>>> +using clang::clangd::SymbolOrigin; >>>> using clang::clangd::SymbolLocation; >>>> using clang::index::SymbolInfo; >>>> using clang::index::SymbolKind; >>>> @@ -65,6 +66,17 @@ struct NormalizedSymbolFlag { >>>>uint8
r342976 - [VFS] Add a proxy FS that delegates calls to underlying FS by default.
Author: ioeric Date: Tue Sep 25 07:02:01 2018 New Revision: 342976 URL: http://llvm.org/viewvc/llvm-project?rev=342976=rev Log: [VFS] Add a proxy FS that delegates calls to underlying FS by default. Summary: This is useful when derived file systems want to override some calls and still proxy other calls. Reviewers: ilya-biryukov, sammccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52462 Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=342976=342975=342976=diff == --- cfe/trunk/include/clang/Basic/VirtualFileSystem.h (original) +++ cfe/trunk/include/clang/Basic/VirtualFileSystem.h Tue Sep 25 07:02:01 2018 @@ -335,6 +335,42 @@ public: const_iterator overlays_end() const { return FSList.rend(); } }; +/// By default, this delegates all calls to the underlying file system. This +/// is useful when derived file systems want to override some calls and still +/// proxy other calls. +class ProxyFileSystem : public FileSystem { +public: + explicit ProxyFileSystem(IntrusiveRefCntPtr FS) + : FS(std::move(FS)) {} + + llvm::ErrorOr status(const Twine ) override { +return FS->status(Path); + } + llvm::ErrorOr> + openFileForRead(const Twine ) override { +return FS->openFileForRead(Path); + } + directory_iterator dir_begin(const Twine , std::error_code ) override { +return FS->dir_begin(Dir, EC); + } + llvm::ErrorOr getCurrentWorkingDirectory() const override { +return FS->getCurrentWorkingDirectory(); + } + std::error_code setCurrentWorkingDirectory(const Twine ) override { +return FS->setCurrentWorkingDirectory(Path); + } + std::error_code getRealPath(const Twine , + SmallVectorImpl ) const override { +return FS->getRealPath(Path, Output); + } + +protected: + FileSystem () { return *FS; } + +private: + IntrusiveRefCntPtr FS; +}; + namespace detail { class InMemoryDirectory; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r342964 - [clangd] Fix build bot after r342961
Author: ioeric Date: Tue Sep 25 04:47:14 2018 New Revision: 342964 URL: http://llvm.org/viewvc/llvm-project?rev=342964=rev Log: [clangd] Fix build bot after r342961 Use llvm::isAlpha instead of std::isalpha etc. This should fix bot failure: http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/20180 Modified: clang-tools-extra/trunk/clangd/URI.cpp Modified: clang-tools-extra/trunk/clangd/URI.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/URI.cpp?rev=342964=342963=342964=diff == --- clang-tools-extra/trunk/clangd/URI.cpp (original) +++ clang-tools-extra/trunk/clangd/URI.cpp Tue Sep 25 04:47:14 2018 @@ -8,6 +8,7 @@ //===--===// #include "URI.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/Error.h" #include "llvm/Support/Format.h" @@ -15,7 +16,6 @@ #include "llvm/Support/Path.h" #include #include -#include #include LLVM_INSTANTIATE_REGISTRY(clang::clangd::URISchemeRegistry) @@ -134,11 +134,10 @@ std::string percentDecode(llvm::StringRe bool isValidScheme(llvm::StringRef Scheme) { if (Scheme.empty()) return false; - if (!std::isalpha(Scheme[0])) + if (!llvm::isAlpha(Scheme[0])) return false; return std::all_of(Scheme.begin() + 1, Scheme.end(), [](char C) { -return std::isalpha(C) || std::isdigit(C) || C == '+' || C == '.' || - C == '-'; +return llvm::isAlnum(C) || C == '+' || C == '.' || C == '-'; }); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r342961 - [clangd] Check that scheme is valid when parsing URI.
Author: ioeric Date: Tue Sep 25 03:47:46 2018 New Revision: 342961 URL: http://llvm.org/viewvc/llvm-project?rev=342961=rev Log: [clangd] Check that scheme is valid when parsing URI. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D52455 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=342961=342960=342961=diff == --- clang-tools-extra/trunk/clangd/URI.cpp (original) +++ clang-tools-extra/trunk/clangd/URI.cpp Tue Sep 25 03:47:46 2018 @@ -11,8 +11,11 @@ #include "llvm/ADT/Twine.h" #include "llvm/Support/Error.h" #include "llvm/Support/Format.h" +#include "llvm/Support/FormatVariadic.h" #include "llvm/Support/Path.h" +#include #include +#include #include LLVM_INSTANTIATE_REGISTRY(clang::clangd::URISchemeRegistry) @@ -128,6 +131,17 @@ std::string percentDecode(llvm::StringRe return Result; } +bool isValidScheme(llvm::StringRef Scheme) { + if (Scheme.empty()) +return false; + if (!std::isalpha(Scheme[0])) +return false; + return std::all_of(Scheme.begin() + 1, Scheme.end(), [](char C) { +return std::isalpha(C) || std::isdigit(C) || C == '+' || C == '.' || + C == '-'; + }); +} + } // namespace URI::URI(llvm::StringRef Scheme, llvm::StringRef Authority, @@ -158,9 +172,13 @@ llvm::Expected URI::parse(llvm::Str llvm::StringRef Uri = OrigUri; auto Pos = Uri.find(':'); - if (Pos == 0 || Pos == llvm::StringRef::npos) + if (Pos == llvm::StringRef::npos) return make_string_error("Scheme must be provided in URI: " + OrigUri); - U.Scheme = percentDecode(Uri.substr(0, Pos)); + auto SchemeStr = Uri.substr(0, Pos); + U.Scheme = percentDecode(SchemeStr); + if (!isValidScheme(U.Scheme)) +return make_string_error(llvm::formatv("Invalid scheme: {0} (decoded: {1})", + SchemeStr, U.Scheme)); Uri = Uri.substr(Pos + 1); if (Uri.consume_front("//")) { Pos = Uri.find('/'); 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=342961=342960=342961=diff == --- clang-tools-extra/trunk/unittests/clangd/URITests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/URITests.cpp Tue Sep 25 03:47:46 2018 @@ -51,9 +51,9 @@ TEST(PercentEncodingTest, Encode) { TEST(PercentEncodingTest, Decode) { EXPECT_EQ(parseOrDie("x:a/b/c").body(), "a/b/c"); - EXPECT_EQ(parseOrDie("%3a://%3a/%3").scheme(), ":"); - EXPECT_EQ(parseOrDie("%3a://%3a/%3").authority(), ":"); - EXPECT_EQ(parseOrDie("%3a://%3a/%3").body(), "/%3"); + EXPECT_EQ(parseOrDie("s%2b://%3a/%3").scheme(), "s+"); + EXPECT_EQ(parseOrDie("s%2b://%3a/%3").authority(), ":"); + EXPECT_EQ(parseOrDie("s%2b://%3a/%3").body(), "/%3"); EXPECT_EQ(parseOrDie("x:a%21b%3ac~").body(), "a!b:c~"); } @@ -132,6 +132,7 @@ TEST(URITest, ParseFailed) { // Empty. EXPECT_TRUE(FailedParse("")); EXPECT_TRUE(FailedParse(":/a/b/c")); + EXPECT_TRUE(FailedParse("\"/a/b/c\" IWYU pragma: abc")); } TEST(URITest, Resolve) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D52264: Deduplicate replacements from diagnostics.
I wasn't aware of the bug. I have just replied to the issue. Thanks for letting me know! On Tue, Sep 25, 2018 at 10:44 AM Stephen Kelly via Phabricator < revi...@reviews.llvm.org> wrote: > steveire added a comment. > > Was this motivated by https://bugs.llvm.org/show_bug.cgi?id=38910 ? > > > Repository: > rL LLVM > > https://reviews.llvm.org/D52264 > > > > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r342951 - Deduplicate replacements from diagnostics.
Author: ioeric Date: Tue Sep 25 01:24:07 2018 New Revision: 342951 URL: http://llvm.org/viewvc/llvm-project?rev=342951=rev Log: Deduplicate replacements from diagnostics. Summary: After r329813, clang-apply-replacements stopped deduplicating identical replacements; however, tools like clang-tidy relies on the deduplication of identical dignostics replacements from different TUs to apply fixes correctly. This change partially roll back the behavior by deduplicating changes from diagnostics. Ideally, we should deduplicate on diagnostics level, but we need to figure out an effecient way. Reviewers: bkramer Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52264 Added: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/identical/file2.yaml - copied, changed from r342903, clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/identical/file1.yaml Modified: clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/identical/file1.yaml clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/identical/identical.cpp clang-tools-extra/trunk/test/clang-apply-replacements/identical.cpp Modified: clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp?rev=342951=342950=342951=diff == --- clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp (original) +++ clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp Tue Sep 25 01:24:07 2018 @@ -125,7 +125,8 @@ std::error_code collectReplacementsFromD } /// \brief Extract replacements from collected TranslationUnitReplacements and -/// TranslationUnitDiagnostics and group them per file. +/// TranslationUnitDiagnostics and group them per file. Identical replacements +/// from diagnostics are deduplicated. /// /// \param[in] TUs Collection of all found and deserialized /// TranslationUnitReplacements. @@ -142,10 +143,20 @@ groupReplacements(const TUReplacements & llvm::DenseMap> GroupedReplacements; - auto AddToGroup = [&](const tooling::Replacement ) { + // Deduplicate identical replacements in diagnostics. + // FIXME: Find an efficient way to deduplicate on diagnostics level. + llvm::DenseMap> + DiagReplacements; + + auto AddToGroup = [&](const tooling::Replacement , bool FromDiag) { // Use the file manager to deduplicate paths. FileEntries are // automatically canonicalized. if (const FileEntry *Entry = SM.getFileManager().getFile(R.getFilePath())) { + if (FromDiag) { +auto = DiagReplacements[Entry]; +if (!Replaces.insert(R).second) + return; + } GroupedReplacements[Entry].push_back(R); } else if (Warned.insert(R.getFilePath()).second) { errs() << "Described file '" << R.getFilePath() @@ -155,13 +166,13 @@ groupReplacements(const TUReplacements & for (const auto : TUs) for (const tooling::Replacement : TU.Replacements) - AddToGroup(R); + AddToGroup(R, false); for (const auto : TUDs) for (const auto : TU.Diagnostics) for (const auto : D.Fix) for (const tooling::Replacement : Fix.second) - AddToGroup(R); + AddToGroup(R, true); // Sort replacements per file to keep consistent behavior when // clang-apply-replacements run on differents machine. Modified: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/identical/file1.yaml URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/identical/file1.yaml?rev=342951=342950=342951=diff == --- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/identical/file1.yaml (original) +++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/identical/file1.yaml Tue Sep 25 01:24:07 2018 @@ -10,9 +10,5 @@ Diagnostics: Offset: 12 Length: 0 ReplacementText: '0' - - FilePath:$(path)/identical.cpp -Offset: 12 -Length: 0 -ReplacementText: '0' ... Copied: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/identical/file2.yaml (from r342903, clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/identical/file1.yaml) URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/identical/file2.yaml?p2=clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/identical/file2.yaml=clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/identical/file1.yaml=342903=342951=342951=diff
Re: [clang-tools-extra] r342730 - [clangd] Remember to serialize symbol origin in YAML.
On Tue, Sep 25, 2018 at 6:34 AM Ilya Biryukov wrote: > Why would we want to serialize the origin? > We only serialize and deserialize for the static index, it does not seem to > be useful to serialize origin in that scenario. > We serialize Origin because it's a property of Symbol? The origin for the current YAML symbols is defaulted to "unknown". It's true that we *currently* only serialize symbols from static index, but there is nothing preventing us from doing it for other indexes with different origins. You could probably override origins when loading static index, but that doesn't seem to work in general. I checked this in without review as I thought this was a trivial fix. The binary serialization also serializes the Origin field. > > Am I missing something? > > On Fri, Sep 21, 2018 at 3:06 PM Eric Liu via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> Author: ioeric >> Date: Fri Sep 21 06:04:57 2018 >> New Revision: 342730 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=342730=rev >> Log: >> [clangd] Remember to serialize symbol origin in YAML. >> >> Modified: >> clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp >> clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp >> >> Modified: clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp?rev=342730=342729=342730=diff >> >> == >> --- clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp (original) >> +++ clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp Fri Sep 21 >> 06:04:57 2018 >> @@ -27,6 +27,7 @@ namespace yaml { >> >> using clang::clangd::Symbol; >> using clang::clangd::SymbolID; >> +using clang::clangd::SymbolOrigin; >> using clang::clangd::SymbolLocation; >> using clang::index::SymbolInfo; >> using clang::index::SymbolKind; >> @@ -65,6 +66,17 @@ struct NormalizedSymbolFlag { >>uint8_t Flag = 0; >> }; >> >> +struct NormalizedSymbolOrigin { >> + NormalizedSymbolOrigin(IO &) {} >> + NormalizedSymbolOrigin(IO &, SymbolOrigin O) { >> +Origin = static_cast(O); >> + } >> + >> + SymbolOrigin denormalize(IO &) { return >> static_cast(Origin); } >> + >> + uint8_t Origin = 0; >> +}; >> + >> template <> struct MappingTraits { >>static void mapping(IO , SymbolLocation::Position ) { >> IO.mapRequired("Line", Value.Line); >> @@ -102,6 +114,8 @@ template <> struct MappingTraits >> MappingNormalization NSymbolID(IO, >> Sym.ID); >> MappingNormalization >> NSymbolFlag( >> IO, Sym.Flags); >> +MappingNormalization >> NSymbolOrigin( >> +IO, Sym.Origin); >> IO.mapRequired("ID", NSymbolID->HexString); >> IO.mapRequired("Name", Sym.Name); >> IO.mapRequired("Scope", Sym.Scope); >> @@ -110,6 +124,7 @@ template <> struct MappingTraits >> SymbolLocation()); >> IO.mapOptional("Definition", Sym.Definition, SymbolLocation()); >> IO.mapOptional("References", Sym.References, 0u); >> +IO.mapOptional("Origin", NSymbolOrigin->Origin); >> IO.mapOptional("Flags", NSymbolFlag->Flag); >> IO.mapOptional("Signature", Sym.Signature); >> IO.mapOptional("CompletionSnippetSuffix", >> Sym.CompletionSnippetSuffix); >> >> Modified: clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp?rev=342730=342729=342730=diff >> >> == >> --- clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp >> (original) >> +++ clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp Fri >> Sep 21 06:04:57 2018 >> @@ -7,6 +7,7 @@ >> // >> >> >> //===--===// >> >> +#include "index/Index.h" >> #include "index/Serialization.h" >> #include "index/SymbolYAML.h" >> #include "llvm/Support/ScopedPrinter.h" >> @@ -35,6 +36,7 @@ CanonicalDeclaration: >>End: >> Line: 1 >> Column: 1 >> +Origin:4 >> Flags:1 >&
r342889 - [VFS] Use llvm::StringMap instead of std::map. NFC
Author: ioeric Date: Mon Sep 24 07:52:11 2018 New Revision: 342889 URL: http://llvm.org/viewvc/llvm-project?rev=342889=rev Log: [VFS] Use llvm::StringMap instead of std::map. NFC 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=342889=342888=342889=diff == --- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original) +++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Mon Sep 24 07:52:11 2018 @@ -566,7 +566,7 @@ public: class InMemoryDirectory : public InMemoryNode { Status Stat; - std::map> Entries; + llvm::StringMap> Entries; public: InMemoryDirectory(Status Stat) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r342730 - [clangd] Remember to serialize symbol origin in YAML.
Author: ioeric Date: Fri Sep 21 06:04:57 2018 New Revision: 342730 URL: http://llvm.org/viewvc/llvm-project?rev=342730=rev Log: [clangd] Remember to serialize symbol origin in YAML. Modified: clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp Modified: clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp?rev=342730=342729=342730=diff == --- clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp (original) +++ clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp Fri Sep 21 06:04:57 2018 @@ -27,6 +27,7 @@ namespace yaml { using clang::clangd::Symbol; using clang::clangd::SymbolID; +using clang::clangd::SymbolOrigin; using clang::clangd::SymbolLocation; using clang::index::SymbolInfo; using clang::index::SymbolKind; @@ -65,6 +66,17 @@ struct NormalizedSymbolFlag { uint8_t Flag = 0; }; +struct NormalizedSymbolOrigin { + NormalizedSymbolOrigin(IO &) {} + NormalizedSymbolOrigin(IO &, SymbolOrigin O) { +Origin = static_cast(O); + } + + SymbolOrigin denormalize(IO &) { return static_cast(Origin); } + + uint8_t Origin = 0; +}; + template <> struct MappingTraits { static void mapping(IO , SymbolLocation::Position ) { IO.mapRequired("Line", Value.Line); @@ -102,6 +114,8 @@ template <> struct MappingTraits MappingNormalization NSymbolID(IO, Sym.ID); MappingNormalization NSymbolFlag( IO, Sym.Flags); +MappingNormalization NSymbolOrigin( +IO, Sym.Origin); IO.mapRequired("ID", NSymbolID->HexString); IO.mapRequired("Name", Sym.Name); IO.mapRequired("Scope", Sym.Scope); @@ -110,6 +124,7 @@ template <> struct MappingTraits SymbolLocation()); IO.mapOptional("Definition", Sym.Definition, SymbolLocation()); IO.mapOptional("References", Sym.References, 0u); +IO.mapOptional("Origin", NSymbolOrigin->Origin); IO.mapOptional("Flags", NSymbolFlag->Flag); IO.mapOptional("Signature", Sym.Signature); IO.mapOptional("CompletionSnippetSuffix", Sym.CompletionSnippetSuffix); Modified: clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp?rev=342730=342729=342730=diff == --- clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp Fri Sep 21 06:04:57 2018 @@ -7,6 +7,7 @@ // //===--===// +#include "index/Index.h" #include "index/Serialization.h" #include "index/SymbolYAML.h" #include "llvm/Support/ScopedPrinter.h" @@ -35,6 +36,7 @@ CanonicalDeclaration: End: Line: 1 Column: 1 +Origin:4 Flags:1 Documentation:'Foo doc' ReturnType:'int' @@ -82,6 +84,7 @@ TEST(SerializationTest, YAMLConversions) EXPECT_EQ(Sym1.Documentation, "Foo doc"); EXPECT_EQ(Sym1.ReturnType, "int"); EXPECT_EQ(Sym1.CanonicalDeclaration.FileURI, "file:///path/foo.h"); + EXPECT_EQ(Sym1.Origin, SymbolOrigin::Static); EXPECT_TRUE(Sym1.Flags & Symbol::IndexedForCodeCompletion); EXPECT_FALSE(Sym1.Flags & Symbol::Deprecated); EXPECT_THAT(Sym1.IncludeHeaders, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r342529 - [clangd] Store preamble macros in dynamic index.
Author: ioeric Date: Wed Sep 19 02:35:04 2018 New Revision: 342529 URL: http://llvm.org/viewvc/llvm-project?rev=342529=rev Log: [clangd] Store preamble macros in dynamic index. Summary: Pros: o Loading macros from preamble for every completion is slow (see profile). o Calculating macro USR is also slow (see profile). o Sema can provide a lot of macro completion results (e.g. when filter is empty, 60k for some large TUs!). Cons: o Slight memory increase in dynamic index (~1%). o Some extra work during preamble build (should be fine as preamble build and indexAST is way slower). Before: {F7195645} After: {F7195646} Reviewers: ilya-biryukov, sammccall Reviewed By: sammccall Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D52078 Modified: clang-tools-extra/trunk/clangd/index/FileIndex.cpp clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp 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=342529=342528=342529=diff == --- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original) +++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Wed Sep 19 02:35:04 2018 @@ -14,6 +14,7 @@ #include "index/Index.h" #include "index/Merge.h" #include "clang/Index/IndexingAction.h" +#include "clang/Lex/MacroInfo.h" #include "clang/Lex/Preprocessor.h" #include @@ -41,10 +42,13 @@ indexSymbols(ASTContext , std::share IndexOpts.SystemSymbolFilter = index::IndexingOptions::SystemSymbolFilterKind::DeclarationsOnly; IndexOpts.IndexFunctionLocals = false; - - if (IsIndexMainAST) + if (IsIndexMainAST) { // We only collect refs when indexing main AST. CollectorOpts.RefFilter = RefKind::All; + }else { +IndexOpts.IndexMacrosInPreprocessor = true; +CollectorOpts.CollectMacro = true; + } SymbolCollector Collector(std::move(CollectorOpts)); Collector.setPreprocessor(PP); 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=342529=342528=342529=diff == --- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Wed Sep 19 02:35:04 2018 @@ -223,12 +223,13 @@ TEST(CompletionTest, Filter) { void TestAfterDotCompletion(clangd::CodeCompleteOptions Opts) { auto Results = completions( R"cpp( - #define MACRO X - int global_var; int global_func(); + // Make sure this is not in preamble. + #define MACRO X + struct GlobalClass {}; struct ClassWithMembers { @@ -276,11 +277,12 @@ void TestAfterDotCompletion(clangd::Code void TestGlobalScopeCompletion(clangd::CodeCompleteOptions Opts) { auto Results = completions( R"cpp( - #define MACRO X - int global_var; int global_func(); + // Make sure this is not in preamble. + #define MACRO X + struct GlobalClass {}; struct ClassWithMembers { @@ -430,10 +432,11 @@ TEST(CompletionTest, Snippets) { TEST(CompletionTest, Kinds) { auto Results = completions( R"cpp( - #define MACRO X int variable; struct Struct {}; int function(); + // make sure MACRO is not included in preamble. + #define MACRO 10 int X = ^ )cpp", {func("indexFunction"), var("indexVariable"), cls("indexClass")}); @@ -1921,6 +1924,21 @@ TEST(CompletionTest, MergeMacrosFromInde UnorderedElementsAre(Named("Clangd_Macro_Test"))); } +TEST(CompletionTest, NoMacroFromPreambleIfIndexIsSet) { + auto Results = completions( + R"cpp(#define CLANGD_PREAMBLE x + + int x = 0; + #define CLANGD_MAIN x + void f() { CLANGD_^ } + )cpp", + {func("CLANGD_INDEX")}); + // Index is overriden in code completion options, so the preamble symbol is + // not seen. + EXPECT_THAT(Results.Completions, UnorderedElementsAre(Named("CLANGD_MAIN"), + Named("CLANGD_INDEX"))); +} + TEST(CompletionTest, DeprecatedResults) { std::string Body = R"cpp( void TestClangd(); Modified: clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp?rev=342529=342528=342529=diff == --- clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp Wed
r342528 - [Sema] Do not load macros from preamble when LoadExternal is false.
Author: ioeric Date: Wed Sep 19 02:34:55 2018 New Revision: 342528 URL: http://llvm.org/viewvc/llvm-project?rev=342528=rev Log: [Sema] Do not load macros from preamble when LoadExternal is false. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52079 Modified: cfe/trunk/include/clang/Sema/CodeCompleteOptions.h cfe/trunk/lib/Sema/SemaCodeComplete.cpp cfe/trunk/test/Index/complete-pch-skip.cpp Modified: cfe/trunk/include/clang/Sema/CodeCompleteOptions.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteOptions.h?rev=342528=342527=342528=diff == --- cfe/trunk/include/clang/Sema/CodeCompleteOptions.h (original) +++ cfe/trunk/include/clang/Sema/CodeCompleteOptions.h Wed Sep 19 02:34:55 2018 @@ -36,7 +36,8 @@ public: unsigned IncludeBriefComments : 1; /// Hint whether to load data from the external AST to provide full results. - /// If false, namespace-level declarations from the preamble may be omitted. + /// If false, namespace-level declarations and macros from the preamble may be + /// omitted. unsigned LoadExternal : 1; /// Include results after corrections (small fix-its), e.g. change '.' to '->' Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=342528=342527=342528=diff == --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original) +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Wed Sep 19 02:34:55 2018 @@ -3304,14 +3304,14 @@ CXCursorKind clang::getCursorKindForDecl } static void AddMacroResults(Preprocessor , ResultBuilder , -bool IncludeUndefined, +bool LoadExternal, bool IncludeUndefined, bool TargetTypeIsPointer = false) { typedef CodeCompletionResult Result; Results.EnterNewScope(); - for (Preprocessor::macro_iterator M = PP.macro_begin(), - MEnd = PP.macro_end(); + for (Preprocessor::macro_iterator M = PP.macro_begin(LoadExternal), +MEnd = PP.macro_end(LoadExternal); M != MEnd; ++M) { auto MD = PP.getMacroDefinition(M->first); if (IncludeUndefined || MD) { @@ -3327,7 +3327,6 @@ static void AddMacroResults(Preprocessor } Results.ExitScope(); - } static void AddPrettyFunctionResults(const LangOptions , @@ -3611,7 +3610,7 @@ void Sema::CodeCompleteOrdinaryName(Scop } if (CodeCompleter->includeMacros()) -AddMacroResults(PP, Results, false); +AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false); HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); @@ -3749,7 +3748,8 @@ void Sema::CodeCompleteExpression(Scope AddPrettyFunctionResults(getLangOpts(), Results); if (CodeCompleter->includeMacros()) -AddMacroResults(PP, Results, false, PreferredTypeIsPointer); +AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false, +PreferredTypeIsPointer); HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } @@ -4372,7 +4372,7 @@ void Sema::CodeCompleteCase(Scope *S) { Results.ExitScope(); if (CodeCompleter->includeMacros()) { -AddMacroResults(PP, Results, false); +AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false); } HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); @@ -4688,7 +4688,7 @@ void Sema::CodeCompleteAfterIf(Scope *S) AddPrettyFunctionResults(getLangOpts(), Results); if (CodeCompleter->includeMacros()) -AddMacroResults(PP, Results, false); +AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false); HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); @@ -5722,7 +5722,7 @@ void Sema::CodeCompleteObjCPassingType(S CodeCompleter->loadExternal()); if (CodeCompleter->includeMacros()) -AddMacroResults(PP, Results, false); +AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false); HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); @@ -5951,10 +5951,9 @@ void Sema::CodeCompleteObjCMessageReceiv Results.ExitScope(); if (CodeCompleter->includeMacros()) -AddMacroResults(PP, Results, false); +AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false); HandleCodeCompleteResults(this,
[clang-tools-extra] r342473 - [clangd] Get rid of Decls parameter in indexMainDecls. NFC
Author: ioeric Date: Tue Sep 18 06:35:16 2018 New Revision: 342473 URL: http://llvm.org/viewvc/llvm-project?rev=342473=rev Log: [clangd] Get rid of Decls parameter in indexMainDecls. NFC It's already available in ParsedAST. Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp clang-tools-extra/trunk/clangd/index/FileIndex.cpp clang-tools-extra/trunk/clangd/index/FileIndex.h clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp clang-tools-extra/trunk/unittests/clangd/TestTU.cpp Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=342473=342472=342473=diff == --- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Sep 18 06:35:16 2018 @@ -83,7 +83,7 @@ std::unique_ptr makeUp } void onMainAST(PathRef Path, ParsedAST ) override { - FIndex->updateMain(Path, AST, AST.getLocalTopLevelDecls()); + FIndex->updateMain(Path, AST); } }; return llvm::make_unique(FIndex); 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=342473=342472=342473=diff == --- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original) +++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Tue Sep 18 06:35:16 2018 @@ -65,10 +65,9 @@ indexSymbols(ASTContext , std::share } std::pair -indexMainDecls(ParsedAST , llvm::ArrayRef TopLevelDecls, - llvm::ArrayRef URISchemes) { +indexMainDecls(ParsedAST , llvm::ArrayRef URISchemes) { return indexSymbols(AST.getASTContext(), AST.getPreprocessorPtr(), - TopLevelDecls, + AST.getLocalTopLevelDecls(), /*IsIndexMainAST=*/true, URISchemes); } @@ -163,9 +162,8 @@ void FileIndex::updatePreamble(PathRef P PreambleIndex.reset(PreambleSymbols.buildMemIndex()); } -void FileIndex::updateMain(PathRef Path, ParsedAST , - llvm::ArrayRef TopLevelDecls) { - auto Contents = indexMainDecls(AST, TopLevelDecls, URISchemes); +void FileIndex::updateMain(PathRef Path, ParsedAST ) { + auto Contents = indexMainDecls(AST, URISchemes); MainFileSymbols.update( Path, llvm::make_unique(std::move(Contents.first)), llvm::make_unique(std::move(Contents.second))); 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=342473=342472=342473=diff == --- clang-tools-extra/trunk/clangd/index/FileIndex.h (original) +++ clang-tools-extra/trunk/clangd/index/FileIndex.h Tue Sep 18 06:35:16 2018 @@ -73,9 +73,9 @@ public: void updatePreamble(PathRef Path, ASTContext , std::shared_ptr PP); - /// Update symbols from main file \p Path with symbols in \p TopLevelDecls. - void updateMain(PathRef Path, ParsedAST , - llvm::ArrayRef TopLevelDecls); + /// Update symbols and references from main file \p Path with + /// `indexMainDecls`. + void updateMain(PathRef Path, ParsedAST ); private: std::vector URISchemes; @@ -106,12 +106,12 @@ private: std::unique_ptr MergedIndex; // Merge preamble and main index. }; -/// Retrieves symbols and refs of \p Decls in \p AST. +/// Retrieves symbols and refs of local top level decls in \p AST (i.e. +/// `AST.getLocalTopLevelDecls()`). /// Exposed to assist in unit tests. /// If URISchemes is empty, the default schemes in SymbolCollector will be used. std::pair -indexMainDecls(ParsedAST , llvm::ArrayRef Decls, - llvm::ArrayRef URISchemes = {}); +indexMainDecls(ParsedAST , llvm::ArrayRef URISchemes = {}); /// Idex declarations from \p AST and macros from \p PP that are declared in /// included headers. Modified: clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp?rev=342473=342472=342473=diff == --- clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp Tue Sep 18 06:35:16 2018 @@ -314,14 +314,14 @@ TEST(FileIndexTest, Refs) { Test.Code = MainCode.code(); Test.Filename = "test.cc"; auto AST = Test.build(); - Index.updateMain(Test.Filename, AST, AST.getLocalTopLevelDecls()); + Index.updateMain(Test.Filename, AST); // Add test2.cc TestTU Test2; Test2.HeaderCode = HeaderCode; Test2.Code = MainCode.code();
[clang-tools-extra] r342460 - [clangd] Merge ClangdServer::DynamicIndex into FileIndex. NFC.
Author: ioeric Date: Tue Sep 18 03:30:44 2018 New Revision: 342460 URL: http://llvm.org/viewvc/llvm-project?rev=342460=rev Log: [clangd] Merge ClangdServer::DynamicIndex into FileIndex. NFC. Summary: FileIndex now provides explicit interfaces for preamble and main file updates. This avoids growing parameter list when preamble and main symbols diverge further (e.g. D52078). This also gets rid of the hack in `indexAST` that inferred main file index based on `TopLevelDecls`. Also separate `indexMainDecls` from `indexAST`. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D5 Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp clang-tools-extra/trunk/clangd/ClangdServer.h clang-tools-extra/trunk/clangd/index/FileIndex.cpp clang-tools-extra/trunk/clangd/index/FileIndex.h clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp clang-tools-extra/trunk/unittests/clangd/TestTU.cpp Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=342460=342459=342460=diff == --- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Sep 18 03:30:44 2018 @@ -14,6 +14,7 @@ #include "SourceCode.h" #include "Trace.h" #include "XRefs.h" +#include "index/FileIndex.h" #include "index/Merge.h" #include "clang/Format/Format.h" #include "clang/Frontend/CompilerInstance.h" @@ -70,59 +71,23 @@ public: }; } // namespace -/// The dynamic index tracks symbols visible in open files. -/// For boring reasons, it doesn't implement SymbolIndex directly - use index(). -class ClangdServer::DynamicIndex { -public: - DynamicIndex(std::vector URISchemes) - : PreambleIdx(URISchemes), MainFileIdx(URISchemes), -MergedIndex(mergeIndex(, )) {} - - const SymbolIndex () const { return *MergedIndex; } - - // Returns callbacks that can be used to update the index with new ASTs. - // Index() presents a merged view of the supplied main-file and preamble ASTs. - std::unique_ptr makeUpdateCallbacks() { -struct CB : public ParsingCallbacks { - CB(ClangdServer::DynamicIndex *This) : This(This) {} - DynamicIndex *This; - - void onPreambleAST(PathRef Path, ASTContext , - std::shared_ptr PP) override { -This->PreambleIdx.update(Path, , std::move(PP)); - } - - void onMainAST(PathRef Path, ParsedAST ) override { -This->MainFileIdx.update(Path, (), - AST.getPreprocessorPtr(), - AST.getLocalTopLevelDecls()); - } -}; -return llvm::make_unique(this); +// Returns callbacks that can be used to update the FileIndex with new ASTs. +std::unique_ptr makeUpdateCallbacks(FileIndex *FIndex) { + struct CB : public ParsingCallbacks { +CB(FileIndex *FIndex) : FIndex(FIndex) {} +FileIndex *FIndex; + +void onPreambleAST(PathRef Path, ASTContext , + std::shared_ptr PP) override { + FIndex->updatePreamble(Path, Ctx, std::move(PP)); +} + +void onMainAST(PathRef Path, ParsedAST ) override { + FIndex->updateMain(Path, AST, AST.getLocalTopLevelDecls()); +} }; - -private: - // Contains information from each file's preamble only. - // These are large, but update fairly infrequently (preambles are stable). - // Missing information: - // - symbol refs (these are always "from the main file") - // - definition locations in the main file - // - // FIXME: Because the preambles for different TUs have large overlap and - // FileIndex doesn't deduplicate, this uses lots of extra RAM. - // The biggest obstacle in fixing this: the obvious approach of partitioning - // by declaring file (rather than main file) fails if headers provide - // different symbols based on preprocessor state. - FileIndex PreambleIdx; - // Contains information from each file's main AST. - // These are updated frequently (on file change), but are relatively small. - // Mostly contains: - // - refs to symbols declared in the preamble and referenced from main - // - symbols declared both in the main file and the preamble - // (Note that symbols *only* in the main file are not indexed). - FileIndex MainFileIdx; - std::unique_ptr MergedIndex; -}; + return llvm::make_unique(FIndex); +} ClangdServer::Options ClangdServer::optsForTest() { ClangdServer::Options Opts; @@ -139,9 +104,8 @@ ClangdServer::ClangdServer(GlobalCompila : CDB(CDB), DiagConsumer(DiagConsumer), FSProvider(FSProvider), ResourceDir(Opts.ResourceDir ? Opts.ResourceDir->str() : getStandardResourceDir()), -
[clang-tools-extra] r342452 - [clangd] Adapt API change after 342451.
Author: ioeric Date: Tue Sep 18 01:52:14 2018 New Revision: 342452 URL: http://llvm.org/viewvc/llvm-project?rev=342452=rev Log: [clangd] Adapt API change after 342451. Modified: clang-tools-extra/trunk/clangd/FindSymbols.cpp clang-tools-extra/trunk/clangd/XRefs.cpp clang-tools-extra/trunk/clangd/index/FileIndex.cpp Modified: clang-tools-extra/trunk/clangd/FindSymbols.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FindSymbols.cpp?rev=342452=342451=342452=diff == --- clang-tools-extra/trunk/clangd/FindSymbols.cpp (original) +++ clang-tools-extra/trunk/clangd/FindSymbols.cpp Tue Sep 18 01:52:14 2018 @@ -270,8 +270,9 @@ getDocumentSymbols(ParsedAST ) { IndexOpts.SystemSymbolFilter = index::IndexingOptions::SystemSymbolFilterKind::DeclarationsOnly; IndexOpts.IndexFunctionLocals = false; - indexTopLevelDecls(AST.getASTContext(), AST.getLocalTopLevelDecls(), - DocumentSymbolsCons, IndexOpts); + indexTopLevelDecls(AST.getASTContext(), AST.getPreprocessor(), + AST.getLocalTopLevelDecls(), DocumentSymbolsCons, + IndexOpts); return DocumentSymbolsCons.takeSymbols(); } Modified: clang-tools-extra/trunk/clangd/XRefs.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=342452=342451=342452=diff == --- clang-tools-extra/trunk/clangd/XRefs.cpp (original) +++ clang-tools-extra/trunk/clangd/XRefs.cpp Tue Sep 18 01:52:14 2018 @@ -206,8 +206,8 @@ IdentifiedSymbol getSymbolAtPosition(Par IndexOpts.SystemSymbolFilter = index::IndexingOptions::SystemSymbolFilterKind::All; IndexOpts.IndexFunctionLocals = true; - indexTopLevelDecls(AST.getASTContext(), AST.getLocalTopLevelDecls(), - DeclMacrosFinder, IndexOpts); + indexTopLevelDecls(AST.getASTContext(), AST.getPreprocessor(), + AST.getLocalTopLevelDecls(), DeclMacrosFinder, IndexOpts); return {DeclMacrosFinder.getFoundDecls(), DeclMacrosFinder.takeMacroInfos()}; } @@ -414,8 +414,8 @@ findRefs(const std::vector IndexOpts.SystemSymbolFilter = index::IndexingOptions::SystemSymbolFilterKind::All; IndexOpts.IndexFunctionLocals = true; - indexTopLevelDecls(AST.getASTContext(), AST.getLocalTopLevelDecls(), - RefFinder, IndexOpts); + indexTopLevelDecls(AST.getASTContext(), AST.getPreprocessor(), + AST.getLocalTopLevelDecls(), RefFinder, IndexOpts); return std::move(RefFinder).take(); } 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=342452=342451=342452=diff == --- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original) +++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Tue Sep 18 01:52:14 2018 @@ -54,7 +54,7 @@ indexAST(ASTContext , std::shared_pt SymbolCollector Collector(std::move(CollectorOpts)); Collector.setPreprocessor(PP); - index::indexTopLevelDecls(AST, DeclsToIndex, Collector, IndexOpts); + index::indexTopLevelDecls(AST, *PP, DeclsToIndex, Collector, IndexOpts); const auto = AST.getSourceManager(); const auto *MainFileEntry = SM.getFileEntryForID(SM.getMainFileID()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r342451 - [Index] Add an option to collect macros from preprocesor.
Author: ioeric Date: Tue Sep 18 01:51:08 2018 New Revision: 342451 URL: http://llvm.org/viewvc/llvm-project?rev=342451=rev Log: [Index] Add an option to collect macros from preprocesor. Summary: Also added unit tests for the index library; lit+c-index-test is painful... Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D52098 Added: cfe/trunk/unittests/Index/ cfe/trunk/unittests/Index/CMakeLists.txt cfe/trunk/unittests/Index/IndexTests.cpp Modified: cfe/trunk/include/clang/Index/IndexingAction.h cfe/trunk/lib/Index/IndexingAction.cpp cfe/trunk/unittests/CMakeLists.txt Modified: cfe/trunk/include/clang/Index/IndexingAction.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexingAction.h?rev=342451=342450=342451=diff == --- cfe/trunk/include/clang/Index/IndexingAction.h (original) +++ cfe/trunk/include/clang/Index/IndexingAction.h Tue Sep 18 01:51:08 2018 @@ -12,6 +12,7 @@ #include "clang/Basic/LLVM.h" #include "clang/Lex/PPCallbacks.h" +#include "clang/Lex/Preprocessor.h" #include "llvm/ADT/ArrayRef.h" #include @@ -40,6 +41,10 @@ struct IndexingOptions { = SystemSymbolFilterKind::DeclarationsOnly; bool IndexFunctionLocals = false; bool IndexImplicitInstantiation = false; + // Whether to index macro definitions in the Preprocesor when preprocessor + // callback is not available (e.g. after parsing has finished). Note that + // macro references are not available in Proprocessor. + bool IndexMacrosInPreprocessor = false; }; /// Creates a frontend action that indexes all symbols (macros and AST decls). @@ -50,13 +55,12 @@ createIndexingAction(std::shared_ptr WrappedAction); /// Recursively indexes all decls in the AST. -/// Note that this does not index macros. void indexASTUnit(ASTUnit , IndexDataConsumer , IndexingOptions Opts); /// Recursively indexes \p Decls. -/// Note that this does not index macros. -void indexTopLevelDecls(ASTContext , ArrayRef Decls, +void indexTopLevelDecls(ASTContext , Preprocessor , +ArrayRef Decls, IndexDataConsumer , IndexingOptions Opts); /// Creates a PPCallbacks that indexes macros and feeds macros to \p Consumer. @@ -65,7 +69,6 @@ std::unique_ptr indexMacros IndexingOptions Opts); /// Recursively indexes all top-level decls in the module. -/// FIXME: make this index macros as well. void indexModuleFile(serialization::ModuleFile , ASTReader , IndexDataConsumer , IndexingOptions Opts); Modified: cfe/trunk/lib/Index/IndexingAction.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingAction.cpp?rev=342451=342450=342451=diff == --- cfe/trunk/lib/Index/IndexingAction.cpp (original) +++ cfe/trunk/lib/Index/IndexingAction.cpp Tue Sep 18 01:51:08 2018 @@ -215,23 +215,41 @@ static void indexTranslationUnit(ASTUnit Unit.visitLocalTopLevelDecls(, topLevelDeclVisitor); } +static void indexPreprocessorMacros(const Preprocessor , +IndexDataConsumer ) { + for (const auto : PP.macros()) +if (MacroDirective *MD = M.second.getLatest()) + DataConsumer.handleMacroOccurence( + M.first, MD->getMacroInfo(), + static_cast(index::SymbolRole::Definition), + MD->getLocation()); +} + void index::indexASTUnit(ASTUnit , IndexDataConsumer , IndexingOptions Opts) { IndexingContext IndexCtx(Opts, DataConsumer); IndexCtx.setASTContext(Unit.getASTContext()); DataConsumer.initialize(Unit.getASTContext()); DataConsumer.setPreprocessor(Unit.getPreprocessorPtr()); + + if (Opts.IndexMacrosInPreprocessor) +indexPreprocessorMacros(Unit.getPreprocessor(), DataConsumer); indexTranslationUnit(Unit, IndexCtx); DataConsumer.finish(); } -void index::indexTopLevelDecls(ASTContext , ArrayRef Decls, +void index::indexTopLevelDecls(ASTContext , Preprocessor , + ArrayRef Decls, IndexDataConsumer , IndexingOptions Opts) { IndexingContext IndexCtx(Opts, DataConsumer); IndexCtx.setASTContext(Ctx); DataConsumer.initialize(Ctx); + + if (Opts.IndexMacrosInPreprocessor) +indexPreprocessorMacros(PP, DataConsumer); + for (const Decl *D : Decls) IndexCtx.indexTopLevelDecl(D); DataConsumer.finish(); @@ -251,6 +269,9 @@ void index::indexModuleFile(serializatio IndexCtx.setASTContext(Ctx); DataConsumer.initialize(Ctx); + if (Opts.IndexMacrosInPreprocessor) +indexPreprocessorMacros(Reader.getPreprocessor(), DataConsumer); + for (const Decl *D : Reader.getModuleFileLevelDecls(Mod)) {
[clang-tools-extra] r342362 - [clangd] Get rid of AST matchers in SymbolCollector. NFC
Author: ioeric Date: Mon Sep 17 00:43:49 2018 New Revision: 342362 URL: http://llvm.org/viewvc/llvm-project?rev=342362=rev Log: [clangd] Get rid of AST matchers in SymbolCollector. NFC Reviewers: ilya-biryukov, kadircet Subscribers: MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D52089 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=342362=342361=342362=diff == --- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original) +++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Mon Sep 17 00:43:49 2018 @@ -15,12 +15,16 @@ #include "Logger.h" #include "SourceCode.h" #include "URI.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclBase.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclTemplate.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Basic/SourceManager.h" +#include "clang/Basic/Specifiers.h" #include "clang/Index/IndexSymbol.h" #include "clang/Index/USRGeneration.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" @@ -235,6 +239,13 @@ RefKind toRefKind(index::SymbolRoleSet R return static_cast(static_cast(RefKind::All) & Roles); } +template bool explicitTemplateSpecialization(const NamedDecl ) { + if (const auto *TD = llvm::dyn_cast()) +if (TD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) + return true; + return false; +} + } // namespace SymbolCollector::SymbolCollector(Options Opts) : Opts(std::move(Opts)) {} @@ -271,21 +282,33 @@ bool SymbolCollector::shouldCollectSymbo // FunctionDecl, BlockDecl, ObjCMethodDecl and OMPDeclareReductionDecl. // FIXME: Need a matcher for ExportDecl in order to include symbols declared // within an export. - auto InNonLocalContext = hasDeclContext(anyOf( - translationUnitDecl(), namespaceDecl(), linkageSpecDecl(), recordDecl(), - enumDecl(), objcProtocolDecl(), objcInterfaceDecl(), objcCategoryDecl(), - objcCategoryImplDecl(), objcImplementationDecl())); - // Don't index template specializations and expansions in main files. - auto IsSpecialization = - anyOf(functionDecl(isExplicitTemplateSpecialization()), -cxxRecordDecl(isExplicitTemplateSpecialization()), -varDecl(isExplicitTemplateSpecialization())); - if (match(decl(allOf(unless(isExpansionInMainFile()), InNonLocalContext, - unless(IsSpecialization))), -ND, ASTCtx) - .empty()) + const auto *DeclCtx = ND.getDeclContext(); + switch (DeclCtx->getDeclKind()) { + case Decl::TranslationUnit: + case Decl::Namespace: + case Decl::LinkageSpec: + case Decl::Enum: + case Decl::ObjCProtocol: + case Decl::ObjCInterface: + case Decl::ObjCCategory: + case Decl::ObjCCategoryImpl: + case Decl::ObjCImplementation: +break; + default: +// Record has a few derivations (e.g. CXXRecord, Class specialization), it's +// easier to cast. +if (!llvm::isa(DeclCtx)) + return false; + } + if (explicitTemplateSpecialization(ND) || + explicitTemplateSpecialization(ND) || + explicitTemplateSpecialization(ND)) return false; + const auto = ASTCtx.getSourceManager(); + // Skip decls in the main file. + if (SM.isInMainFile(SM.getExpansionLoc(ND.getBeginLoc( +return false; // Avoid indexing internal symbols in protobuf generated headers. if (isPrivateProtoDecl(ND)) return false; ___ 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=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=342133=342134=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
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
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=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=342027=342028=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
[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=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=341644=341645=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=341644=341645=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=341644=341645=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=341644=341645=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=341644=341645=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=341644=341645=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" +#include "RIFF.h" #include "llvm/Support/Compression.h" #include
[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=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=341575=341576=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=341575=341576=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=341575=341576=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=341575=341576=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 { /// themselves. std::vector additionalTextEdits; +
[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=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=341533=341534=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 , + const MacroInfo *MI, + const SourceManager ) { + 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=341533=341534=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 , + const MacroInfo *MI, + const SourceManager ); + } // 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=341533=341534=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 ) { +llvm::Optional getSymbolID(const CodeCompletionResult , + const SourceManager ) { 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 ) -> 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=341533=341534=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->getDefinitionLoc(), SM, - USR)) + auto ID =
[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=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=341487=341488=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