Skip to content

Commit a96a73f

Browse files
committed
[Driver][SYCL] Fix -fsycl-help output when redirected
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 6051fd6 commit a96a73f

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
@@ -1938,15 +1938,12 @@ void Driver::PrintSYCLToolHelp(const Compilation &C) const {
19381938
llvm::outs() << "Emitting help information for " << std::get<1>(HA) << '\n'
19391939
<< "Use triple of '" << std::get<0>(HA).normalize() <<
19401940
"' to enable ahead of time compilation\n";
1941+
// Flush out the buffer before calling the external tool.
1942+
llvm::outs().flush();
19411943
std::vector<StringRef> ToolArgs = {std::get<1>(HA), std::get<2>(HA),
19421944
std::get<3>(HA)};
19431945
SmallString<128> ExecPath(
19441946
C.getDefaultToolChain().GetProgramPath(std::get<1>(HA).data()));
1945-
auto ToolBinary = llvm::sys::findProgramByName(ExecPath);
1946-
if (ToolBinary.getError()) {
1947-
C.getDriver().Diag(diag::err_drv_command_failure) << ExecPath;
1948-
continue;
1949-
}
19501947
// do not run the tools with -###.
19511948
if (C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
19521949
llvm::errs() << "\"" << ExecPath << "\" \"" << ToolArgs[1] << "\"";
@@ -1955,6 +1952,11 @@ void Driver::PrintSYCLToolHelp(const Compilation &C) const {
19551952
llvm::errs() << "\n";
19561953
continue;
19571954
}
1955+
auto ToolBinary = llvm::sys::findProgramByName(ExecPath);
1956+
if (ToolBinary.getError()) {
1957+
C.getDriver().Diag(diag::err_drv_command_failure) << ExecPath;
1958+
continue;
1959+
}
19581960
// Run the Tool.
19591961
llvm::sys::ExecuteAndWait(ToolBinary.get(), ToolArgs);
19601962
}

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" "--help"
111+
// SYCL_HELP_ORDER: Emitting help information for aoc
112+
// SYCL_HELP_ORDER: aoc" "-help" "-sycl"
113+
// SYCL_HELP_ORDER: Emitting help information for opencl-aot
114+
// SYCL_HELP_ORDER: opencl-aot" "--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)