Skip to content

Commit 2404d02

Browse files
authored
[Driver][SYCL] Fix -fsycl-help output when redirected (#4619)
When using -fsycl-help and redirecting the output, flush out the informational strings before the actual tool output so the output ordering is logical when viewed.
1 parent b5fe206 commit 2404d02

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,15 +1944,12 @@ void Driver::PrintSYCLToolHelp(const Compilation &C) const {
19441944
llvm::outs() << "Emitting help information for " << std::get<1>(HA) << '\n'
19451945
<< "Use triple of '" << std::get<0>(HA).normalize() <<
19461946
"' to enable ahead of time compilation\n";
1947+
// Flush out the buffer before calling the external tool.
1948+
llvm::outs().flush();
19471949
std::vector<StringRef> ToolArgs = {std::get<1>(HA), std::get<2>(HA),
19481950
std::get<3>(HA)};
19491951
SmallString<128> ExecPath(
19501952
C.getDefaultToolChain().GetProgramPath(std::get<1>(HA).data()));
1951-
auto ToolBinary = llvm::sys::findProgramByName(ExecPath);
1952-
if (ToolBinary.getError()) {
1953-
C.getDriver().Diag(diag::err_drv_command_failure) << ExecPath;
1954-
continue;
1955-
}
19561953
// do not run the tools with -###.
19571954
if (C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
19581955
llvm::errs() << "\"" << ExecPath << "\" \"" << ToolArgs[1] << "\"";
@@ -1961,6 +1958,11 @@ void Driver::PrintSYCLToolHelp(const Compilation &C) const {
19611958
llvm::errs() << "\n";
19621959
continue;
19631960
}
1961+
auto ToolBinary = llvm::sys::findProgramByName(ExecPath);
1962+
if (ToolBinary.getError()) {
1963+
C.getDriver().Diag(diag::err_drv_command_failure) << ExecPath;
1964+
continue;
1965+
}
19641966
// Run the Tool.
19651967
llvm::sys::ExecuteAndWait(ToolBinary.get(), ToolArgs);
19661968
}

clang/test/Driver/sycl.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,22 @@
9797
// SYCL-HELP-BADARG: unsupported argument 'foo' to option 'fsycl-help='
9898
// SYCL-HELP-GEN: Emitting help information for ocloc
9999
// SYCL-HELP-GEN: Use triple of 'spir64_gen-unknown-unknown' to enable ahead of time compilation
100-
// SYCL-HELP-FPGA-OUT: "[[DIR]]{{[/\\]+}}aoc" "-help" "-sycl"
101100
// SYCL-HELP-FPGA: Emitting help information for aoc
102101
// SYCL-HELP-FPGA: Use triple of 'spir64_fpga-unknown-unknown' to enable ahead of time compilation
102+
// SYCL-HELP-FPGA-OUT: "[[DIR]]{{[/\\]+}}aoc" "-help" "-sycl"
103103
// SYCL-HELP-CPU: Emitting help information for opencl-aot
104104
// SYCL-HELP-CPU: Use triple of 'spir64_x86_64-unknown-unknown' to enable ahead of time compilation
105105

106+
// -fsycl-help redirect to file should retain proper information ordering
107+
// RUN: %clang -### -fsycl-help %s > %t.help-out 2>&1
108+
// RUN: FileCheck %s -check-prefix SYCL_HELP_ORDER --input-file=%t.help-out
109+
// SYCL_HELP_ORDER: Emitting help information for ocloc
110+
// SYCL_HELP_ORDER: ocloc{{(\.exe)?}}" "--help"
111+
// SYCL_HELP_ORDER: Emitting help information for aoc
112+
// SYCL_HELP_ORDER: aoc{{(\.exe)?}}" "-help" "-sycl"
113+
// SYCL_HELP_ORDER: Emitting help information for opencl-aot
114+
// SYCL_HELP_ORDER: opencl-aot{{(\.exe)?}}" "--help"
115+
106116
// -fsycl-id-queries-fit-in-int
107117
// RUN: %clang -### -fsycl -fsycl-id-queries-fit-in-int %s 2>&1 | FileCheck %s --check-prefix=ID_QUERIES
108118
// RUN: %clang_cl -### -fsycl -fsycl-id-queries-fit-in-int %s 2>&1 | FileCheck %s --check-prefix=ID_QUERIES

0 commit comments

Comments
 (0)