Skip to content

[Driver][SYCL] Fix -fsycl-help output when redirected #4619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1938,15 +1938,12 @@ void Driver::PrintSYCLToolHelp(const Compilation &C) const {
llvm::outs() << "Emitting help information for " << std::get<1>(HA) << '\n'
<< "Use triple of '" << std::get<0>(HA).normalize() <<
"' to enable ahead of time compilation\n";
// Flush out the buffer before calling the external tool.
llvm::outs().flush();
std::vector<StringRef> ToolArgs = {std::get<1>(HA), std::get<2>(HA),
std::get<3>(HA)};
SmallString<128> ExecPath(
C.getDefaultToolChain().GetProgramPath(std::get<1>(HA).data()));
auto ToolBinary = llvm::sys::findProgramByName(ExecPath);
if (ToolBinary.getError()) {
C.getDriver().Diag(diag::err_drv_command_failure) << ExecPath;
continue;
}
// do not run the tools with -###.
if (C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
llvm::errs() << "\"" << ExecPath << "\" \"" << ToolArgs[1] << "\"";
Expand All @@ -1955,6 +1952,11 @@ void Driver::PrintSYCLToolHelp(const Compilation &C) const {
llvm::errs() << "\n";
continue;
}
auto ToolBinary = llvm::sys::findProgramByName(ExecPath);
if (ToolBinary.getError()) {
C.getDriver().Diag(diag::err_drv_command_failure) << ExecPath;
continue;
}
// Run the Tool.
llvm::sys::ExecuteAndWait(ToolBinary.get(), ToolArgs);
}
Expand Down
12 changes: 11 additions & 1 deletion clang/test/Driver/sycl.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,22 @@
// SYCL-HELP-BADARG: unsupported argument 'foo' to option 'fsycl-help='
// SYCL-HELP-GEN: Emitting help information for ocloc
// SYCL-HELP-GEN: Use triple of 'spir64_gen-unknown-unknown' to enable ahead of time compilation
// SYCL-HELP-FPGA-OUT: "[[DIR]]{{[/\\]+}}aoc" "-help" "-sycl"
// SYCL-HELP-FPGA: Emitting help information for aoc
// SYCL-HELP-FPGA: Use triple of 'spir64_fpga-unknown-unknown' to enable ahead of time compilation
// SYCL-HELP-FPGA-OUT: "[[DIR]]{{[/\\]+}}aoc" "-help" "-sycl"
// SYCL-HELP-CPU: Emitting help information for opencl-aot
// SYCL-HELP-CPU: Use triple of 'spir64_x86_64-unknown-unknown' to enable ahead of time compilation

// -fsycl-help redirect to file should retain proper information ordering
// RUN: %clang -### -fsycl-help %s > %t.help-out 2>&1
// RUN: FileCheck %s -check-prefix SYCL_HELP_ORDER --input-file=%t.help-out
// SYCL_HELP_ORDER: Emitting help information for ocloc
// SYCL_HELP_ORDER: ocloc{{(\.exe)?}}" "--help"
// SYCL_HELP_ORDER: Emitting help information for aoc
// SYCL_HELP_ORDER: aoc{{(\.exe)?}}" "-help" "-sycl"
// SYCL_HELP_ORDER: Emitting help information for opencl-aot
// SYCL_HELP_ORDER: opencl-aot{{(\.exe)?}}" "--help"

// -fsycl-id-queries-fit-in-int
// RUN: %clang -### -fsycl -fsycl-id-queries-fit-in-int %s 2>&1 | FileCheck %s --check-prefix=ID_QUERIES
// RUN: %clang_cl -### -fsycl -fsycl-id-queries-fit-in-int %s 2>&1 | FileCheck %s --check-prefix=ID_QUERIES
Expand Down