Skip to content

Commit 536d89f

Browse files
authored
[SYCL] Filter out the header and footer from the dependency output. (#14933)
`Cmake` uses dependency information generated by the use of the` -MD` option to decide if a file needs to be rebuilt. Currently the header and footer are not filtered out from the dependency output. This leads to the issue that `Cmake` thinks the source file needs to always be rebuilt. This is a patch to fix the issue. See #14798 for more details.
1 parent 69a1add commit 536d89f

File tree

6 files changed

+19
-9
lines changed

6 files changed

+19
-9
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7696,7 +7696,7 @@ def show_includes : Flag<["--"], "show-includes">,
76967696
HelpText<"Print cl.exe style /showIncludes to stdout">;
76977697
def dependency_filter : Separate<["-"], "dependency-filter">,
76987698
HelpText<"Filter dependencies with prefix from the dependency output.">,
7699-
MarshallingInfoString<DependencyOutputOpts<"DependencyFilter">>;
7699+
MarshallingInfoStringVector<DependencyOutputOpts<"DependencyFilter">>;
77007700

77017701
} // let Visibility = [CC1Option]
77027702

clang/include/clang/Frontend/DependencyOutputOptions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ class DependencyOutputOptions {
8787
std::string ModuleDependencyOutputDir;
8888

8989
/// Dependency output which is prefixed with this string is filtered from
90-
/// the dependency output.
91-
std::string DependencyFilter;
90+
/// the dependency output.
91+
std::vector<std::string> DependencyFilter;
9292

9393
public:
9494
DependencyOutputOptions()

clang/include/clang/Frontend/Utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class DependencyFileGenerator : public DependencyCollector {
121121
void outputDependencyFile(DiagnosticsEngine &Diags);
122122

123123
std::string OutputFile;
124-
std::string DependencyFilter;
124+
std::vector<std::string> DependencyFilter;
125125
std::vector<std::string> Targets;
126126
bool IncludeSystemHeaders;
127127
bool PhonyTarget;

clang/lib/Frontend/DependencyFile.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,10 @@ bool DependencyFileGenerator::sawDependency(StringRef Filename, bool FromModule,
255255
if (isSpecialFilename(Filename))
256256
return false;
257257

258-
if (DependencyFilter.size() &&
259-
DependencyFilter.compare(0, DependencyFilter.size(), Filename.data(),
260-
DependencyFilter.size()) == 0)
261-
// Remove dependencies that are prefixed by the Filter string.
262-
return false;
258+
// Remove dependencies that are prefixed by the Filter string.
259+
for (const std::string &FD : DependencyFilter)
260+
if (FD.compare(0, FD.size(), Filename.data(), FD.size()) == 0)
261+
return false;
263262

264263
if (IncludeSystemHeaders)
265264
return true;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int dep() {
2+
return 0;
3+
}

clang/test/Frontend/dependency-gen.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,11 @@
4747
// RUN: %clang -MMD -MF - %s -fsyntax-only -resource-dir=%S/Inputs/resource_dir_with_sanitizer_ignorelist -fsanitize=undefined -flto -fvisibility=hidden -I ./ | FileCheck -check-prefix=ONLY-USER-DEPS %s
4848
// ONLY-USER-DEPS: dependency-gen.o:
4949
// NOT-ONLY-USER-DEPS: ubsan_ignorelist.txt
50+
51+
// RUN: %clang -c -x c++ -fsycl \
52+
// RUN: -MD -MF - %S/Inputs/dependency.cpp | FileCheck -check-prefix=FILTER %s
53+
54+
// FILTER: dependency.o:
55+
// FILTER: {{.*}}dependency.cpp
56+
// FILTER: dependency.o:
57+
// FILTER: {{.*}}dependency.cpp

0 commit comments

Comments
 (0)