From c3eec458ab40128ebf1e3d379b067825bb72dd71 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 14 Jul 2015 16:02:40 +0000 Subject: [PATCH] llvm-ar: print an error when the requested member is not found. llvm-svn: 242156 --- llvm/test/Object/archive-extract.test | 4 ++++ llvm/tools/llvm-ar/llvm-ar.cpp | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/llvm/test/Object/archive-extract.test b/llvm/test/Object/archive-extract.test index 4da2180eff36..606fc753c335 100644 --- a/llvm/test/Object/archive-extract.test +++ b/llvm/test/Object/archive-extract.test @@ -41,3 +41,7 @@ ; RUN: env TZ=GMT llvm-ar tv %t.a | FileCheck %s CHECK: 1465 2004-11-19 03:01:31.000000000 very_long_bytecode_file_name.bc + + +RUN: not llvm-ar x %p/Inputs/GNU.a foo.o 2>&1 | FileCheck --check-prefix=NOTFOUND %s +NOTFOUND: foo.o was not found diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp index b3e5043d5008..50ddf598efee 100644 --- a/llvm/tools/llvm-ar/llvm-ar.cpp +++ b/llvm/tools/llvm-ar/llvm-ar.cpp @@ -391,14 +391,18 @@ static bool shouldCreateArchive(ArchiveOperation Op) { static void performReadOperation(ArchiveOperation Operation, object::Archive *OldArchive) { + bool Filter = !Members.empty(); for (const object::Archive::Child &C : OldArchive->children()) { ErrorOr NameOrErr = C.getName(); failIfError(NameOrErr.getError()); StringRef Name = NameOrErr.get(); - if (!Members.empty() && - std::find(Members.begin(), Members.end(), Name) == Members.end()) - continue; + if (Filter) { + auto I = std::find(Members.begin(), Members.end(), Name); + if (I == Members.end()) + continue; + Members.erase(I); + } switch (Operation) { default: @@ -414,6 +418,11 @@ static void performReadOperation(ArchiveOperation Operation, break; } } + if (Members.empty()) + return; + for (StringRef Name : Members) + errs() << Name << " was not found\n"; + std::exit(1); } template