diff --git a/llvm/test/tools/llvm-ar/invalid-object-file.test b/llvm/test/tools/llvm-ar/invalid-object-file.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-ar/invalid-object-file.test @@ -0,0 +1,8 @@ +## Test that we get a proper error message with a file that is not a recognized object file. + +RUN: rm -f %t1.txt +RUN: touch %t1.txt +RUN: not llvm-ar sc %t1.txt 2>&1 > /dev/null | FileCheck %s + +CHECK: llvm-ar{{(.exe|.EXE)?}}: error: unable to load '{{[^']+}}': File too small to be an archive. +CHECK-NOT: {{.}} diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp --- a/llvm/tools/llvm-ar/llvm-ar.cpp +++ b/llvm/tools/llvm-ar/llvm-ar.cpp @@ -927,9 +927,7 @@ if (!EC) { Error Err = Error::success(); object::Archive Archive(Buf.get()->getMemBufferRef(), Err); - EC = errorToErrorCode(std::move(Err)); - failIfError(EC, - "error loading '" + ArchiveName + "': " + EC.message() + "!"); + failIfError(std::move(Err), "unable to load '" + ArchiveName + "'"); if (Archive.isThin()) CompareFullPath = true; performOperation(Operation, &Archive, std::move(Buf.get()), NewMembers);