diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp @@ -36,6 +36,8 @@ llvm::sys::path::remove_dots(CanonPath, /*remove_dot_dot=*/true); C.handleFileDependency(*Opts, CanonPath); } + for (const auto& ExtraDep : Opts->ExtraDeps) + C.handleFileDependency(*Opts, ExtraDep); } private: diff --git a/clang/test/ClangScanDeps/Inputs/non-header-dependency.json b/clang/test/ClangScanDeps/Inputs/non-header-dependency.json new file mode 100644 --- /dev/null +++ b/clang/test/ClangScanDeps/Inputs/non-header-dependency.json @@ -0,0 +1,7 @@ +[ + { + "directory": "DIR", + "command": "clang -E DIR/non-header-dependency_input.cpp -fsanitize=bounds -fsanitize-blacklist=DIR/Inputs/sanitize-blacklist.txt", + "file": "DIR/non-header-dependency_input.cpp" + } +] diff --git a/clang/test/ClangScanDeps/Inputs/sanitize-blacklist.txt b/clang/test/ClangScanDeps/Inputs/sanitize-blacklist.txt new file mode 100644 --- /dev/null +++ b/clang/test/ClangScanDeps/Inputs/sanitize-blacklist.txt @@ -0,0 +1 @@ +fun:* diff --git a/clang/test/ClangScanDeps/non-header-dependency.cpp b/clang/test/ClangScanDeps/non-header-dependency.cpp new file mode 100644 --- /dev/null +++ b/clang/test/ClangScanDeps/non-header-dependency.cpp @@ -0,0 +1,14 @@ +// RUN: rm -rf %t.dir +// RUN: rm -rf %t.cdb +// RUN: mkdir -p %t.dir +// RUN: cp %s %t.dir/non-header-dependency_input.cpp +// RUN: mkdir %t.dir/Inputs +// RUN: cp %S/Inputs/sanitize-blacklist.txt %t.dir/Inputs/sanitize-blacklist.txt +// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/non-header-dependency.json > %t.cdb +// +// RUN: clang-scan-deps -compilation-database %t.cdb -j 1 | FileCheck %s + +#define FOO "foo" + +// CHECK: Inputs{{/|\\}}sanitize-blacklist.txt +// CHECK-NEXT: non-header-dependency_input.cpp diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp --- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp +++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp @@ -17,6 +17,7 @@ #include "llvm/Support/Signals.h" #include "llvm/Support/Threading.h" #include +#include #include using namespace clang; @@ -66,7 +67,7 @@ StringRef File) override { if (!this->Opts) this->Opts = std::make_unique(Opts); - Dependencies.push_back(File); + Dependencies.insert(File); } void printDependencies(std::string &S) { @@ -76,7 +77,7 @@ class DependencyPrinter : public DependencyFileGenerator { public: DependencyPrinter(DependencyOutputOptions &Opts, - ArrayRef Dependencies) + std::set &Dependencies) : DependencyFileGenerator(Opts) { for (const auto &Dep : Dependencies) addDependency(Dep); @@ -94,7 +95,7 @@ private: std::unique_ptr Opts; - std::vector Dependencies; + std::set Dependencies; }; DependencyPrinterConsumer Consumer;