Skip to content
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
4 changes: 4 additions & 0 deletions llvm/test/tools/yaml2obj/basic.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Test case when the input file does not exist.
RUN: not yaml2obj %t.blah 2>&1 | FileCheck -DMSG=%errc_ENOENT --check-prefix=ENOENT %s

ENOENT: yaml2obj: error: {{.*}}.blah: [[MSG]]
9 changes: 6 additions & 3 deletions llvm/tools/yaml2obj/yaml2obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ int main(int argc, char **argv) {
argc, argv, "Create an object file from a YAML description", nullptr,
nullptr, /*LongOptionsUseDoubleDash=*/true);

auto ErrHandler = [](const Twine &Msg) {
WithColor::error(errs(), "yaml2obj") << Msg << "\n";
constexpr StringRef ProgName = "yaml2obj";
auto ErrHandler = [&](const Twine &Msg) {
WithColor::error(errs(), ProgName) << Msg << "\n";
};

std::error_code EC;
Expand All @@ -131,8 +132,10 @@ int main(int argc, char **argv) {

ErrorOr<std::unique_ptr<MemoryBuffer>> Buf =
MemoryBuffer::getFileOrSTDIN(Input, /*IsText=*/true);
if (!Buf)
if (std::error_code EC = Buf.getError()) {
WithColor::error(errs(), ProgName) << Input << ": " << EC.message() << '\n';
return 1;
}

std::optional<std::string> Buffer =
preprocess(Buf.get()->getBuffer(), ErrHandler);
Expand Down
Loading