Skip to content

Commit

Permalink
[SYCL] Filter out the header and footer from the dependency output. (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
zahiraam authored Aug 6, 2024
1 parent 69a1add commit 536d89f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -7696,7 +7696,7 @@ def show_includes : Flag<["--"], "show-includes">,
HelpText<"Print cl.exe style /showIncludes to stdout">;
def dependency_filter : Separate<["-"], "dependency-filter">,
HelpText<"Filter dependencies with prefix from the dependency output.">,
MarshallingInfoString<DependencyOutputOpts<"DependencyFilter">>;
MarshallingInfoStringVector<DependencyOutputOpts<"DependencyFilter">>;

} // let Visibility = [CC1Option]

Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/Frontend/DependencyOutputOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class DependencyOutputOptions {
std::string ModuleDependencyOutputDir;

/// Dependency output which is prefixed with this string is filtered from
/// the dependency output.
std::string DependencyFilter;
/// the dependency output.
std::vector<std::string> DependencyFilter;

public:
DependencyOutputOptions()
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Frontend/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class DependencyFileGenerator : public DependencyCollector {
void outputDependencyFile(DiagnosticsEngine &Diags);

std::string OutputFile;
std::string DependencyFilter;
std::vector<std::string> DependencyFilter;
std::vector<std::string> Targets;
bool IncludeSystemHeaders;
bool PhonyTarget;
Expand Down
9 changes: 4 additions & 5 deletions clang/lib/Frontend/DependencyFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,10 @@ bool DependencyFileGenerator::sawDependency(StringRef Filename, bool FromModule,
if (isSpecialFilename(Filename))
return false;

if (DependencyFilter.size() &&
DependencyFilter.compare(0, DependencyFilter.size(), Filename.data(),
DependencyFilter.size()) == 0)
// Remove dependencies that are prefixed by the Filter string.
return false;
// Remove dependencies that are prefixed by the Filter string.
for (const std::string &FD : DependencyFilter)
if (FD.compare(0, FD.size(), Filename.data(), FD.size()) == 0)
return false;

if (IncludeSystemHeaders)
return true;
Expand Down
3 changes: 3 additions & 0 deletions clang/test/Frontend/Inputs/dependency.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int dep() {
return 0;
}
8 changes: 8 additions & 0 deletions clang/test/Frontend/dependency-gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@
// 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
// ONLY-USER-DEPS: dependency-gen.o:
// NOT-ONLY-USER-DEPS: ubsan_ignorelist.txt

// RUN: %clang -c -x c++ -fsycl \
// RUN: -MD -MF - %S/Inputs/dependency.cpp | FileCheck -check-prefix=FILTER %s

// FILTER: dependency.o:
// FILTER: {{.*}}dependency.cpp
// FILTER: dependency.o:
// FILTER: {{.*}}dependency.cpp

0 comments on commit 536d89f

Please sign in to comment.