Skip to content

Commit 7c934af

Browse files
authored
Merge pull request #3198 from apple/jan_svoboda/cherry-pick_0
[clang][driver][tooling] Cherry-pick some commits related to dependency scanning
2 parents 76c42ab + 04e9520 commit 7c934af

35 files changed

+206
-68
lines changed

clang/include/clang/Basic/SourceLocation.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ class FileEntry;
363363
/// A SourceLocation and its associated SourceManager.
364364
///
365365
/// This is useful for argument passing to functions that expect both objects.
366+
///
367+
/// This class does not guarantee the presence of either the SourceManager or
368+
/// a valid SourceLocation. Clients should use `isValid()` and `hasManager()`
369+
/// before calling the member functions.
366370
class FullSourceLoc : public SourceLocation {
367371
const SourceManager *SrcMgr = nullptr;
368372

@@ -373,13 +377,10 @@ class FullSourceLoc : public SourceLocation {
373377
explicit FullSourceLoc(SourceLocation Loc, const SourceManager &SM)
374378
: SourceLocation(Loc), SrcMgr(&SM) {}
375379

376-
bool hasManager() const {
377-
bool hasSrcMgr = SrcMgr != nullptr;
378-
assert(hasSrcMgr == isValid() && "FullSourceLoc has location but no manager");
379-
return hasSrcMgr;
380-
}
380+
/// Checks whether the SourceManager is present.
381+
bool hasManager() const { return SrcMgr != nullptr; }
381382

382-
/// \pre This FullSourceLoc has an associated SourceManager.
383+
/// \pre hasManager()
383384
const SourceManager &getManager() const {
384385
assert(SrcMgr && "SourceManager is NULL.");
385386
return *SrcMgr;

clang/lib/Driver/InputInfo.h renamed to clang/include/clang/Driver/InputInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_CLANG_LIB_DRIVER_INPUTINFO_H
10-
#define LLVM_CLANG_LIB_DRIVER_INPUTINFO_H
9+
#ifndef LLVM_CLANG_DRIVER_INPUTINFO_H
10+
#define LLVM_CLANG_DRIVER_INPUTINFO_H
1111

1212
#include "clang/Driver/Action.h"
1313
#include "clang/Driver/Types.h"

clang/include/clang/Driver/Job.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_CLANG_DRIVER_JOB_H
1111

1212
#include "clang/Basic/LLVM.h"
13+
#include "clang/Driver/InputInfo.h"
1314
#include "llvm/ADT/ArrayRef.h"
1415
#include "llvm/ADT/Optional.h"
1516
#include "llvm/ADT/SmallVector.h"
@@ -121,8 +122,8 @@ class Command {
121122
/// argument, which will be the executable).
122123
llvm::opt::ArgStringList Arguments;
123124

124-
/// The list of program arguments which are inputs.
125-
llvm::opt::ArgStringList InputFilenames;
125+
/// The list of program inputs.
126+
std::vector<InputInfo> InputInfoList;
126127

127128
/// The list of program arguments which are outputs. May be empty.
128129
std::vector<std::string> OutputFilenames;
@@ -209,9 +210,7 @@ class Command {
209210

210211
const llvm::opt::ArgStringList &getArguments() const { return Arguments; }
211212

212-
const llvm::opt::ArgStringList &getInputFilenames() const {
213-
return InputFilenames;
214-
}
213+
const std::vector<InputInfo> &getInputInfos() const { return InputInfoList; }
215214

216215
const std::vector<std::string> &getOutputFilenames() const {
217216
return OutputFilenames;

clang/include/clang/Tooling/Tooling.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ namespace tooling {
6666

6767
class CompilationDatabase;
6868

69+
/// Retrieves the flags of the `-cc1` job in `Compilation` that has only source
70+
/// files as its inputs.
71+
/// Returns nullptr if there are no such jobs or multiple of them. Note that
72+
/// offloading jobs are ignored.
73+
const llvm::opt::ArgStringList *
74+
getCC1Arguments(DiagnosticsEngine *Diagnostics,
75+
driver::Compilation *Compilation);
76+
6977
/// Interface to process a clang::CompilerInvocation.
7078
///
7179
/// If your tool is based on FrontendAction, you should be deriving from

clang/lib/Driver/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "clang/Driver/Driver.h"
10-
#include "InputInfo.h"
1110
#include "ToolChains/AIX.h"
1211
#include "ToolChains/AMDGPU.h"
1312
#include "ToolChains/AMDGPUOpenMP.h"
@@ -54,6 +53,7 @@
5453
#include "clang/Driver/Action.h"
5554
#include "clang/Driver/Compilation.h"
5655
#include "clang/Driver/DriverDiagnostic.h"
56+
#include "clang/Driver/InputInfo.h"
5757
#include "clang/Driver/Job.h"
5858
#include "clang/Driver/Options.h"
5959
#include "clang/Driver/SanitizerArgs.h"

clang/lib/Driver/Job.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "clang/Driver/Job.h"
10-
#include "InputInfo.h"
1110
#include "clang/Basic/LLVM.h"
1211
#include "clang/Driver/Driver.h"
1312
#include "clang/Driver/DriverDiagnostic.h"
13+
#include "clang/Driver/InputInfo.h"
1414
#include "clang/Driver/Tool.h"
1515
#include "clang/Driver/ToolChain.h"
1616
#include "llvm/ADT/ArrayRef.h"
@@ -43,7 +43,7 @@ Command::Command(const Action &Source, const Tool &Creator,
4343
Executable(Executable), Arguments(Arguments) {
4444
for (const auto &II : Inputs)
4545
if (II.isFilename())
46-
InputFilenames.push_back(II.getFilename());
46+
InputInfoList.push_back(II);
4747
for (const auto &II : Outputs)
4848
if (II.isFilename())
4949
OutputFilenames.push_back(II.getFilename());
@@ -242,9 +242,10 @@ void Command::Print(raw_ostream &OS, const char *Terminator, bool Quote,
242242
}
243243
}
244244

245-
auto Found = llvm::find_if(InputFilenames,
246-
[&Arg](StringRef IF) { return IF == Arg; });
247-
if (Found != InputFilenames.end() &&
245+
auto Found = llvm::find_if(InputInfoList, [&Arg](const InputInfo &II) {
246+
return II.getFilename() == Arg;
247+
});
248+
if (Found != InputInfoList.end() &&
248249
(i == 0 || StringRef(Args[i - 1]) != "-main-file-name")) {
249250
// Replace the input file name with the crashinfo's file name.
250251
OS << ' ';
@@ -325,8 +326,8 @@ void Command::setEnvironment(llvm::ArrayRef<const char *> NewEnvironment) {
325326

326327
void Command::PrintFileNames() const {
327328
if (PrintInputFilenames) {
328-
for (const char *Arg : InputFilenames)
329-
llvm::outs() << llvm::sys::path::filename(Arg) << "\n";
329+
for (const auto &Arg : InputInfoList)
330+
llvm::outs() << llvm::sys::path::filename(Arg.getFilename()) << "\n";
330331
llvm::outs().flush();
331332
}
332333
}

clang/lib/Driver/Tool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "clang/Driver/Tool.h"
10-
#include "InputInfo.h"
10+
#include "clang/Driver/InputInfo.h"
1111

1212
using namespace clang::driver;
1313

clang/lib/Driver/ToolChain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "clang/Driver/ToolChain.h"
10-
#include "InputInfo.h"
1110
#include "ToolChains/Arch/ARM.h"
1211
#include "ToolChains/Clang.h"
1312
#include "ToolChains/InterfaceStubs.h"
@@ -18,6 +17,7 @@
1817
#include "clang/Driver/Action.h"
1918
#include "clang/Driver/Driver.h"
2019
#include "clang/Driver/DriverDiagnostic.h"
20+
#include "clang/Driver/InputInfo.h"
2121
#include "clang/Driver/Job.h"
2222
#include "clang/Driver/Options.h"
2323
#include "clang/Driver/SanitizerArgs.h"

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
#include "AMDGPU.h"
1010
#include "CommonArgs.h"
11-
#include "InputInfo.h"
1211
#include "clang/Basic/TargetID.h"
1312
#include "clang/Driver/Compilation.h"
1413
#include "clang/Driver/DriverDiagnostic.h"
14+
#include "clang/Driver/InputInfo.h"
1515
#include "clang/Driver/Options.h"
1616
#include "llvm/Option/ArgList.h"
1717
#include "llvm/Support/Error.h"

clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
#include "AMDGPUOpenMP.h"
1010
#include "AMDGPU.h"
1111
#include "CommonArgs.h"
12-
#include "InputInfo.h"
1312
#include "clang/Basic/DiagnosticDriver.h"
1413
#include "clang/Driver/Compilation.h"
1514
#include "clang/Driver/Driver.h"
1615
#include "clang/Driver/DriverDiagnostic.h"
16+
#include "clang/Driver/InputInfo.h"
1717
#include "clang/Driver/Options.h"
1818
#include "llvm/Support/FileSystem.h"
1919
#include "llvm/Support/FormatAdapters.h"

clang/lib/Driver/ToolChains/AVR.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
#include "AVR.h"
1010
#include "CommonArgs.h"
11-
#include "InputInfo.h"
1211
#include "clang/Driver/Compilation.h"
1312
#include "clang/Driver/DriverDiagnostic.h"
13+
#include "clang/Driver/InputInfo.h"
1414
#include "clang/Driver/Options.h"
1515
#include "llvm/ADT/Optional.h"
1616
#include "llvm/ADT/StringExtras.h"

clang/lib/Driver/ToolChains/AVR.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_AVR_H
1111

1212
#include "Gnu.h"
13-
#include "InputInfo.h"
13+
#include "clang/Driver/InputInfo.h"
1414
#include "clang/Driver/ToolChain.h"
1515
#include "clang/Driver/Tool.h"
1616

clang/lib/Driver/ToolChains/Ananas.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "Ananas.h"
10-
#include "InputInfo.h"
1110
#include "CommonArgs.h"
1211
#include "clang/Driver/Compilation.h"
1312
#include "clang/Driver/Driver.h"
13+
#include "clang/Driver/InputInfo.h"
1414
#include "clang/Driver/Options.h"
1515
#include "llvm/ADT/SmallString.h"
1616
#include "llvm/Option/ArgList.h"

clang/lib/Driver/ToolChains/BareMetal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include "BareMetal.h"
1010

1111
#include "CommonArgs.h"
12-
#include "InputInfo.h"
1312
#include "Gnu.h"
13+
#include "clang/Driver/InputInfo.h"
1414

1515
#include "Arch/RISCV.h"
1616
#include "clang/Driver/Compilation.h"

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "Arch/X86.h"
2121
#include "CommonArgs.h"
2222
#include "Hexagon.h"
23-
#include "InputInfo.h"
2423
#include "MSP430.h"
2524
#include "PS4CPU.h"
2625
#include "clang/Basic/CharInfo.h"
@@ -30,6 +29,7 @@
3029
#include "clang/Basic/Version.h"
3130
#include "clang/Driver/Distro.h"
3231
#include "clang/Driver/DriverDiagnostic.h"
32+
#include "clang/Driver/InputInfo.h"
3333
#include "clang/Driver/Options.h"
3434
#include "clang/Driver/SanitizerArgs.h"
3535
#include "clang/Driver/XRayArgs.h"

clang/lib/Driver/ToolChains/CloudABI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "CloudABI.h"
10-
#include "InputInfo.h"
1110
#include "CommonArgs.h"
1211
#include "clang/Driver/Compilation.h"
1312
#include "clang/Driver/Driver.h"
13+
#include "clang/Driver/InputInfo.h"
1414
#include "clang/Driver/Options.h"
1515
#include "llvm/ADT/SmallString.h"
1616
#include "llvm/Option/ArgList.h"

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "Arch/X86.h"
1818
#include "HIP.h"
1919
#include "Hexagon.h"
20-
#include "InputInfo.h"
2120
#include "clang/Basic/CharInfo.h"
2221
#include "clang/Basic/LangOptions.h"
2322
#include "clang/Basic/ObjCRuntime.h"
@@ -27,6 +26,7 @@
2726
#include "clang/Driver/Compilation.h"
2827
#include "clang/Driver/Driver.h"
2928
#include "clang/Driver/DriverDiagnostic.h"
29+
#include "clang/Driver/InputInfo.h"
3030
#include "clang/Driver/Job.h"
3131
#include "clang/Driver/Options.h"
3232
#include "clang/Driver/SanitizerArgs.h"

clang/lib/Driver/ToolChains/CommonArgs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
1010
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
1111

12-
#include "InputInfo.h"
1312
#include "clang/Driver/Driver.h"
13+
#include "clang/Driver/InputInfo.h"
1414
#include "clang/Driver/Multilib.h"
1515
#include "clang/Driver/Tool.h"
1616
#include "clang/Driver/ToolChain.h"

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
#include "Cuda.h"
1010
#include "CommonArgs.h"
11-
#include "InputInfo.h"
1211
#include "clang/Basic/Cuda.h"
1312
#include "clang/Config/config.h"
1413
#include "clang/Driver/Compilation.h"
1514
#include "clang/Driver/Distro.h"
1615
#include "clang/Driver/Driver.h"
1716
#include "clang/Driver/DriverDiagnostic.h"
17+
#include "clang/Driver/InputInfo.h"
1818
#include "clang/Driver/Options.h"
1919
#include "llvm/ADT/Optional.h"
2020
#include "llvm/Option/ArgList.h"

clang/lib/Driver/ToolChains/HIP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
#include "HIP.h"
1010
#include "AMDGPU.h"
1111
#include "CommonArgs.h"
12-
#include "InputInfo.h"
1312
#include "clang/Basic/Cuda.h"
1413
#include "clang/Basic/TargetID.h"
1514
#include "clang/Driver/Compilation.h"
1615
#include "clang/Driver/Driver.h"
1716
#include "clang/Driver/DriverDiagnostic.h"
17+
#include "clang/Driver/InputInfo.h"
1818
#include "clang/Driver/Options.h"
1919
#include "llvm/Support/Alignment.h"
2020
#include "llvm/Support/FileSystem.h"

clang/lib/Driver/ToolChains/Hexagon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
#include "Hexagon.h"
1010
#include "CommonArgs.h"
11-
#include "InputInfo.h"
1211
#include "clang/Driver/Compilation.h"
1312
#include "clang/Driver/Driver.h"
1413
#include "clang/Driver/DriverDiagnostic.h"
14+
#include "clang/Driver/InputInfo.h"
1515
#include "clang/Driver/Options.h"
1616
#include "llvm/ADT/StringExtras.h"
1717
#include "llvm/Option/ArgList.h"

clang/lib/Driver/ToolChains/MSP430.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include "MSP430.h"
1010
#include "CommonArgs.h"
1111
#include "Gnu.h"
12-
#include "InputInfo.h"
1312
#include "clang/Driver/Compilation.h"
13+
#include "clang/Driver/InputInfo.h"
1414
#include "clang/Driver/Multilib.h"
1515
#include "clang/Driver/Options.h"
1616
#include "llvm/Option/ArgList.h"

clang/lib/Driver/ToolChains/MSP430.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSP430_H
1111

1212
#include "Gnu.h"
13-
#include "InputInfo.h"
1413
#include "clang/Driver/Driver.h"
1514
#include "clang/Driver/DriverDiagnostic.h"
15+
#include "clang/Driver/InputInfo.h"
1616
#include "clang/Driver/Tool.h"
1717
#include "clang/Driver/ToolChain.h"
1818
#include "llvm/ADT/StringRef.h"

clang/lib/Driver/ToolChains/MinGW.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "MinGW.h"
10-
#include "InputInfo.h"
1110
#include "CommonArgs.h"
1211
#include "clang/Config/config.h"
1312
#include "clang/Driver/Compilation.h"
1413
#include "clang/Driver/Driver.h"
1514
#include "clang/Driver/DriverDiagnostic.h"
15+
#include "clang/Driver/InputInfo.h"
1616
#include "clang/Driver/Options.h"
1717
#include "clang/Driver/SanitizerArgs.h"
1818
#include "llvm/Option/ArgList.h"

clang/lib/Driver/ToolChains/Minix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
#include "Minix.h"
1010
#include "CommonArgs.h"
11-
#include "InputInfo.h"
1211
#include "clang/Driver/Compilation.h"
1312
#include "clang/Driver/Driver.h"
13+
#include "clang/Driver/InputInfo.h"
1414
#include "clang/Driver/Options.h"
1515
#include "llvm/Option/ArgList.h"
1616
#include "llvm/Support/VirtualFileSystem.h"

clang/lib/Driver/ToolChains/NaCl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "NaCl.h"
10-
#include "InputInfo.h"
1110
#include "CommonArgs.h"
1211
#include "clang/Driver/Compilation.h"
1312
#include "clang/Driver/Driver.h"
1413
#include "clang/Driver/DriverDiagnostic.h"
14+
#include "clang/Driver/InputInfo.h"
1515
#include "clang/Driver/Options.h"
1616
#include "llvm/Option/ArgList.h"
1717
#include "llvm/Support/Path.h"

0 commit comments

Comments
 (0)