Skip to content

Commit

Permalink
Enable clangDriver in project.cc
Browse files Browse the repository at this point in the history
https://bugs.llvm.org/show_bug.cgi?id=37695 is not fixed. But since we have eliminated libclang for indexing and completion the bug no longer bothers us.
  • Loading branch information
MaskRay committed Jul 15, 2018
1 parent df72a9e commit eea1b92
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 27 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ a C/C++/Objective-C language server.

It makes use of C++17 features, has less third-party dependencies and slimmed-down code base. Cross reference features are strenghened, (see [wiki/FAQ](../../wiki/FAQ). It currently uses libclang to index C++ code but will switch to Clang C++ API. Refactoring and formatting are non-goals as they can be provided by clang-format, clang-include-fixer and other Clang based tools.

The comparison with cquery as noted on 2018-07-09:
The comparison with cquery as noted on 2018-07-15:

| | cquery | ccls |
|------------ |--------------------------------|------------------------------|
| third_party | more | fewer |
| C++ | C++14 | C++17 |
| clang API | libclang (C) | libclang + clang/llvm C++ |
| clang API | libclang (C) | clang/llvm C++ |
| Filesystem | AbsolutePath + custom routines | llvm/Support |
| index | libclang | clangIndex, some enhancement |
| pipeline | index merge+id remapping | simpler and more robust |

cquery has system include path detection (through running the compiler driver) while ccls does not.
cquery has system include path detection (through running the compiler driver) while ccls uses clangDriver.

# >>> [Getting started](../../wiki/Getting-started) (CLICK HERE) <<<

Expand Down
5 changes: 4 additions & 1 deletion src/clang_complete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "clang/Frontend/FrontendDiagnostic.h"
#include <clang/Sema/CodeCompleteConsumer.h>
#include <llvm/ADT/Twine.h>
#include <llvm/Config/llvm-config.h>
#include <llvm/Support/Threading.h>
using namespace clang;
using namespace llvm;
Expand Down Expand Up @@ -444,8 +445,10 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) {
CodeCompleteOptions Opts;
LangOptions LangOpts;
Opts.IncludeBriefComments = true;
Opts.LoadExternal = false;
#if LLVM_VERSION_MAJOR >= 7
Opts.LoadExternal = true;
Opts.IncludeFixIts = true;
#endif
CaptureCompletionResults capture(Opts);
tu->Unit->CodeComplete(session->file.filename, request->position.line + 1,
request->position.character + 1, Remapped,
Expand Down
7 changes: 6 additions & 1 deletion src/clang_tu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ ClangTranslationUnit::Create(const std::string &filepath,
/*CaptureDiagnostics=*/true, Remapped,
/*RemappedFilesKeepOriginalName=*/true, 1, TU_Prefix,
/*CacheCodeCompletionResults=*/true, true,
/*AllowPCHWithCompilerErrors=*/true, SkipFunctionBodiesScope::None,
/*AllowPCHWithCompilerErrors=*/true,
#if LLVM_VERSION_MAJOR >= 7
SkipFunctionBodiesScope::None,
#else
false,
#endif
/*SingleFileParse=*/false,
/*UserFilesAreVolatile=*/true, false,
ret->PCHCO->getRawReader().getFormat(), &ErrUnit));
Expand Down
5 changes: 5 additions & 0 deletions src/clang_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "utils.h"

#include <clang/AST/Type.h>
#include <llvm/Config/llvm-config.h>
using namespace clang;
using namespace llvm;

Expand Down Expand Up @@ -66,6 +67,7 @@ const char* ClangBuiltinTypeName(int kind) {
return "double";
case BuiltinType::LongDouble:
return "long double";
#if LLVM_VERSION_MAJOR >= 7
case BuiltinType::ShortAccum:
return "short _Accum";
case BuiltinType::Accum:
Expand Down Expand Up @@ -114,15 +116,18 @@ const char* ClangBuiltinTypeName(int kind) {
return "_Sat unsigned _Fract";
case BuiltinType::BuiltinType::SatULongFract:
return "_Sat unsigned long _Fract";
#endif
case BuiltinType::Float16:
return "_Float16";
case BuiltinType::Float128:
return "__float128";
case BuiltinType::WChar_S:
case BuiltinType::WChar_U:
return "wchar_t";
#if LLVM_VERSION_MAJOR >= 7
case BuiltinType::Char8:
return "char8_t";
#endif
case BuiltinType::Char16:
return "char16_t";
case BuiltinType::Char32:
Expand Down
24 changes: 2 additions & 22 deletions src/project.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ using namespace ccls;

#include <clang/Driver/Compilation.h>
#include <clang/Driver/Driver.h>
#include <clang/Driver/Options.h>
#include <clang/Frontend/CompilerInstance.h>
#include <clang/Tooling/CompilationDatabase.h>
#include <llvm/ADT/ArrayRef.h>
#include <llvm/Option/ArgList.h>
#include <llvm/Option/OptTable.h>
#include <llvm/Support/MemoryBuffer.h>
#include <llvm/Support/LineIterator.h>
using namespace clang;
Expand Down Expand Up @@ -99,22 +96,6 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
args.insert(args.end(), config->extra_flags.begin(),
config->extra_flags.end());

#if 1
std::unique_ptr<OptTable> Opts = driver::createDriverOptTable();
unsigned MissingArgIndex, MissingArgCount;
std::vector<const char*> cargs;
for (auto& arg : args)
cargs.push_back(arg.c_str());
InputArgList Args =
Opts->ParseArgs(makeArrayRef(cargs), MissingArgIndex, MissingArgCount,
driver::options::CC1Option);
using namespace clang::driver::options;
for (const auto* A : Args.filtered(OPT_I, OPT_c_isystem, OPT_cxx_isystem,
OPT_isystem, OPT_idirafter))
config->angle_dirs.insert(entry.ResolveIfRelative(A->getValue()));
for (const auto* A : Args.filtered(OPT_I, OPT_iquote))
config->quote_dirs.insert(entry.ResolveIfRelative(A->getValue()));
#else
// a weird C++ deduction guide heap-use-after-free causes libclang to crash.
IgnoringDiagConsumer DiagC;
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
Expand Down Expand Up @@ -164,7 +145,6 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
break;
}
}
#endif

for (size_t i = 1; i < args.size(); i++)
// This is most likely the file path we will be passing to clang. The
Expand All @@ -176,9 +156,9 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
continue;
}

// if (HeaderOpts.ResourceDir.empty() && HeaderOpts.UseBuiltinIncludes)
if (HeaderOpts.ResourceDir.empty() && HeaderOpts.UseBuiltinIncludes)
args.push_back("-resource-dir=" + g_config->clang.resourceDir);
// if (CI->getFileSystemOpts().WorkingDir.empty())
if (CI->getFileSystemOpts().WorkingDir.empty())
args.push_back("-working-directory=" + entry.directory);

// There could be a clang version mismatch between what the project uses and
Expand Down

0 comments on commit eea1b92

Please sign in to comment.