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,9 @@ +## Test that we get a proper error message with a file that is not a recognized object file. + +RUN: touch %t1.txt +RUN: not llvm-ar sc %t1.txt 2>&1 > /dev/null | FileCheck -allow-empty %s + +CHECK: llvm-ar{{(.exe|.EXE)?}}: error: error loading '{{[^']+}}': File too small to be an archive. +CHECK-NOT: {{.}} + +RUN: rm %t1.txt 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), "error loading '" + ArchiveName + "'"); if (Archive.isThin()) CompareFullPath = true; performOperation(Operation, &Archive, std::move(Buf.get()), NewMembers);