Skip to content

Commit ef3c406

Browse files
[SYCL] Fix error handling and add more failure info to syclbin-dump (#19427)
This commit fixes an issue with unhandled LLVM errors and prints additional information for some error-conditions in syclbin-dump. Fixes #19404 --------- Signed-off-by: Larsen, Steffen <[email protected]>
1 parent d15c70e commit ef3c406

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

sycl/test/syclbin/input_files.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// RUN: not syclbin-dump nonexistent.syclbin 2>&1 | FileCheck %s --check-prefix CHECK-NONEXISTENT-FILE
22
// RUN: not syclbin-dump %S/Inputs/malformed.syclbin 2>&1 | FileCheck %s --check-prefix CHECK-MALFORMED-FILE
3-
// UNSUPPORTED: linux
4-
// UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/19404
5-
// CHECK-NONEXISTENT-FILE: Failed to open or read file nonexistent.syclbin
6-
// CHECK-MALFORMED-FILE: Invalid data was encountered while parsing the file
3+
// CHECK-NONEXISTENT-FILE: Failed to open or read file nonexistent.syclbin:
4+
// CHECK-MALFORMED-FILE: Failed to parse SYCLBIN file: Incorrect SYCLBIN magic number.

sycl/tools/syclbin-dump/syclbin-dump.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ int main(int argc, char **argv) {
100100

101101
auto FileMemBufferOrError = llvm::MemoryBuffer::getFileOrSTDIN(
102102
TargetFilename, /*IsText=*/false, /*RequiresNullTerminator=*/false);
103-
if (!FileMemBufferOrError) {
104-
errs() << "Failed to open or read file " << TargetFilename << "\n";
103+
if (std::error_code EC = FileMemBufferOrError.getError()) {
104+
errs() << "Failed to open or read file " << TargetFilename << ": "
105+
<< EC.message() << "\n";
105106
return 1;
106107
}
107108

@@ -116,19 +117,25 @@ int main(int argc, char **argv) {
116117

117118
std::unique_ptr<llvm::object::OffloadBinary> ParsedOffloadBinary;
118119
MemoryBufferRef SYCLBINImageBuffer = [&]() {
119-
// If we failed to load as an offload binary, it may still be a SYCLBIN at
120-
// an outer level.
121-
if (llvm::object::OffloadBinary::create(**FileMemBufferOrError)
122-
.moveInto(ParsedOffloadBinary))
120+
if (llvm::Error E =
121+
llvm::object::OffloadBinary::create(**FileMemBufferOrError)
122+
.moveInto(ParsedOffloadBinary)) {
123+
// If we failed to load as an offload binary, it may still be a SYCLBIN at
124+
// an outer level.
125+
std::ignore = (bool)llvm::handleErrors(
126+
std::move(E),
127+
[](std::unique_ptr<ECError>) -> Error { return Error::success(); });
123128
return MemoryBufferRef(**FileMemBufferOrError);
124-
else
129+
} else {
125130
return MemoryBufferRef(ParsedOffloadBinary->getImage(), "");
131+
}
126132
}();
127133

128134
std::unique_ptr<llvm::object::SYCLBIN> ParsedSYCLBIN;
129-
if (llvm::object::SYCLBIN::read(SYCLBINImageBuffer).moveInto(ParsedSYCLBIN)) {
130-
errs() << "Failed to parse SYCLBIN file.\n";
131-
return 1;
135+
if (llvm::Error E = llvm::object::SYCLBIN::read(SYCLBINImageBuffer)
136+
.moveInto(ParsedSYCLBIN)) {
137+
errs() << "Failed to parse SYCLBIN file: " << E << "\n";
138+
std::abort();
132139
}
133140

134141
OS << "Version: " << ParsedSYCLBIN->Version << "\n";

0 commit comments

Comments
 (0)