summaryrefslogtreecommitdiff
path: root/lib/Tooling/InterpolatingCompilationDatabase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Tooling/InterpolatingCompilationDatabase.cpp')
-rw-r--r--lib/Tooling/InterpolatingCompilationDatabase.cpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/lib/Tooling/InterpolatingCompilationDatabase.cpp b/lib/Tooling/InterpolatingCompilationDatabase.cpp
index 4d0d84f660a2..53c8dd448fd9 100644
--- a/lib/Tooling/InterpolatingCompilationDatabase.cpp
+++ b/lib/Tooling/InterpolatingCompilationDatabase.cpp
@@ -1,9 +1,8 @@
//===- InterpolatingCompilationDatabase.cpp ---------------------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
@@ -151,7 +150,8 @@ struct TransferableCommand {
// spelling of each argument; re-rendering is lossy for aliased flags.
// E.g. in CL mode, /W4 maps to -Wall.
auto OptTable = clang::driver::createDriverOptTable();
- Cmd.CommandLine.emplace_back(OldArgs.front());
+ if (!OldArgs.empty())
+ Cmd.CommandLine.emplace_back(OldArgs.front());
for (unsigned Pos = 1; Pos < OldArgs.size();) {
using namespace driver::options;
@@ -206,10 +206,13 @@ struct TransferableCommand {
bool TypeCertain;
auto TargetType = guessType(Filename, &TypeCertain);
// If the filename doesn't determine the language (.h), transfer with -x.
- if (TargetType != types::TY_INVALID && !TypeCertain && Type) {
- TargetType = types::onlyPrecompileType(TargetType) // header?
- ? types::lookupHeaderTypeForSourceType(*Type)
- : *Type;
+ if ((!TargetType || !TypeCertain) && Type) {
+ // Use *Type, or its header variant if the file is a header.
+ // Treat no/invalid extension as header (e.g. C++ standard library).
+ TargetType =
+ (!TargetType || types::onlyPrecompileType(TargetType)) // header?
+ ? types::lookupHeaderTypeForSourceType(*Type)
+ : *Type;
if (ClangCLMode) {
const StringRef Flag = toCLFlag(TargetType);
if (!Flag.empty())
@@ -227,6 +230,7 @@ struct TransferableCommand {
LangStandard::getLangStandardForKind(Std).getName()).str());
}
Result.CommandLine.push_back(Filename);
+ Result.Heuristic = "inferred from " + Cmd.Filename;
return Result;
}
@@ -240,7 +244,8 @@ private:
}
// Otherwise just check the clang executable file name.
- return llvm::sys::path::stem(CmdLine.front()).endswith_lower("cl");
+ return !CmdLine.empty() &&
+ llvm::sys::path::stem(CmdLine.front()).endswith_lower("cl");
}
// Map the language from the --std flag to that of the -x flag.
@@ -473,8 +478,7 @@ private:
ArrayRef<SubstringAndIndex> Idx) const {
assert(!Idx.empty());
// Longest substring match will be adjacent to a direct lookup.
- auto It =
- std::lower_bound(Idx.begin(), Idx.end(), SubstringAndIndex{Key, 0});
+ auto It = llvm::lower_bound(Idx, SubstringAndIndex{Key, 0});
if (It == Idx.begin())
return *It;
if (It == Idx.end())