From 2b542969929499b2abc4ac70b21fdb2484133f89 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 26 Nov 2017 22:17:51 -0800 Subject: [PATCH] Specify nullptr for source_filename in clang_parseTranslationUnit2 so that we do not need to strip main source filename from args --- README.md | 2 +- src/clang_translation_unit.cc | 2 +- src/project.cc | 31 +++++++++---------------------- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index ca95ceab..60ef10cc 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ are skipped. Here's an example: ``` # Language --xc++ +clang++ -std=c++11 # Includes diff --git a/src/clang_translation_unit.cc b/src/clang_translation_unit.cc index d86fc266..0ba7e0d6 100644 --- a/src/clang_translation_unit.cc +++ b/src/clang_translation_unit.cc @@ -27,7 +27,7 @@ std::unique_ptr ClangTranslationUnit::Create( CXTranslationUnit cx_tu; CXErrorCode error_code = clang_parseTranslationUnit2FullArgv( - index->cx_index, filepath.c_str(), args.data(), (int)args.size(), + index->cx_index, nullptr, args.data(), (int)args.size(), unsaved_files.data(), (unsigned)unsaved_files.size(), flags, &cx_tu); switch (error_code) { diff --git a/src/project.cc b/src/project.cc index 1c52ff93..bfdb142e 100644 --- a/src/project.cc +++ b/src/project.cc @@ -53,9 +53,6 @@ static std::vector kBlacklistMulti = { // Blacklisted flags which are always removed from the command line. static std::vector kBlacklist = { "-c", "-MP", "-MD", "-MMD", "--fcolor-diagnostics", - - // This strips path-like args but is a bit hacky. - "/", "..", }; // Arguments which are followed by a potentially relative path. We need to make @@ -117,10 +114,6 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( return NormalizePathWithTestOptOut(entry.directory + "/" + path); }; - // Do not include path. - if (result.filename == cleanup_maybe_relative_path(arg)) - continue; - // If blacklist skip. if (!next_flag_is_path) { if (StartsWithAny(arg, kBlacklistMulti)) { @@ -174,14 +167,6 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( for (const auto& flag : config->extra_flags) result.args.push_back(flag); - // Clang does not have good hueristics for determining source language, we - // should explicitly specify it. - if (!AnyStartsWith(result.args, "-x")) { - if (IsCFile(entry.file)) - result.args.push_back("-xc"); - else - result.args.push_back("-xc++"); - } if (!AnyStartsWith(result.args, "-std=")) { if (IsCFile(entry.file)) result.args.push_back("-std=c11"); @@ -221,6 +206,7 @@ std::vector LoadFromDirectoryListing(ProjectConfig* config) { CompileCommandsEntry e; e.file = NormalizePathWithTestOptOut(file); e.args = args; + e.args.push_back(e.file); result.push_back(GetCompilationEntryFromCompileCommandEntry(config, e)); } } @@ -463,15 +449,15 @@ TEST_SUITE("Project") { TEST_CASE("strip meta-compiler invocations") { CheckFlags( /* raw */ {"clang", "-lstdc++", "myfile.cc"}, - /* expected */ {"clang", "-lstdc++", "myfile.cc", "-xc++", "-std=c++11", + /* expected */ {"clang", "-lstdc++", "myfile.cc", "-std=c++11", "-resource-dir=/w/resource_dir/"}); CheckFlags(/* raw */ {"goma", "clang"}, - /* expected */ {"clang", "-xc++", "-std=c++11", + /* expected */ {"clang", "-std=c++11", "-resource-dir=/w/resource_dir/"}); CheckFlags(/* raw */ {"goma", "clang", "--foo"}, - /* expected */ {"clang", "--foo", "-xc++", "-std=c++11", + /* expected */ {"clang", "--foo", "-std=c++11", "-resource-dir=/w/resource_dir/"}); } @@ -481,7 +467,7 @@ TEST_SUITE("Project") { "/home/user", "/home/user/foo/bar.c", /* raw */ {"cc", "-O0", "foo/bar.c"}, /* expected */ - {"cc", "-O0", "-xc", "-std=c11", "-resource-dir=/w/resource_dir/"}); + {"cc", "-O0", "foo/bar.c", "-std=c11", "-resource-dir=/w/resource_dir/"}); } // Checks flag parsing for a random chromium file in comparison to what @@ -825,7 +811,7 @@ TEST_SUITE("Project") { "debian_jessie_amd64-sysroot", "-fno-exceptions", "-fvisibility-inlines-hidden", - "-xc++", + "../../ash/login/ui/lock_screen_sanity_unittest.cc", "-resource-dir=/w/resource_dir/"}); } @@ -994,7 +980,8 @@ TEST_SUITE("Project") { "-isystem../../buildtools/third_party/libc++abi/trunk/include", "--sysroot=../../build/linux/debian_jessie_amd64-sysroot", "-fno-exceptions", - "-fvisibility-inlines-hidden"}, + "-fvisibility-inlines-hidden", + "../../apps/app_lifetime_monitor.cc"}, /* expected */ {"../../third_party/llvm-build/Release+Asserts/bin/clang++", @@ -1144,7 +1131,7 @@ TEST_SUITE("Project") { "debian_jessie_amd64-sysroot", "-fno-exceptions", "-fvisibility-inlines-hidden", - "-xc++", + "../../apps/app_lifetime_monitor.cc", "-resource-dir=/w/resource_dir/"}); }