diff --git a/llvm/test/tools/llvm-ar/invalid-binary-file.test b/llvm/test/tools/llvm-ar/invalid-binary-file.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-ar/invalid-binary-file.test @@ -0,0 +1,7 @@ +Test if we get a proper error message with a file that is not a proper binary. + +RUN: touch %t1.txt +RUN: not llvm-ar r %t1.txt 2>&1 | FileCheck %s + +CHECK: llvm-ar{{(.exe|.EXE)?}}: error: error loading '{{[^']+}}': The file was not recognized as a valid object file. +CHECK-NOT: The file 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 @@ -929,7 +929,7 @@ object::Archive Archive(Buf.get()->getMemBufferRef(), Err); EC = errorToErrorCode(std::move(Err)); failIfError(EC, - "error loading '" + ArchiveName + "': " + EC.message() + "!"); + "error loading '" + ArchiveName + "'"); if (Archive.isThin()) CompareFullPath = true; performOperation(Operation, &Archive, std::move(Buf.get()), NewMembers);