[llvm] r242330 - Handle the error of trying to convert a regular archive to a thin one.
Rafael Espindola
rafael.espindola at gmail.com
Wed Jul 15 13:45:56 PDT 2015
Author: rafael
Date: Wed Jul 15 15:45:56 2015
New Revision: 242330
URL: http://llvm.org/viewvc/llvm-project?rev=242330&view=rev
Log:
Handle the error of trying to convert a regular archive to a thin one.
While at it, test that we can add to a thin archive.
Modified:
llvm/trunk/include/llvm/Object/Archive.h
llvm/trunk/lib/Object/ArchiveWriter.cpp
llvm/trunk/test/Object/archive-update.test
llvm/trunk/tools/llvm-ar/llvm-ar.cpp
Modified: llvm/trunk/include/llvm/Object/Archive.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Archive.h?rev=242330&r1=242329&r2=242330&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/Archive.h (original)
+++ llvm/trunk/include/llvm/Object/Archive.h Wed Jul 15 15:45:56 2015
@@ -74,6 +74,7 @@ public:
return Data.begin() < other.Data.begin();
}
+ const Archive *getParent() const { return Parent; }
Child getNext() const;
ErrorOr<StringRef> getName() const;
Modified: llvm/trunk/lib/Object/ArchiveWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ArchiveWriter.cpp?rev=242330&r1=242329&r2=242330&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ArchiveWriter.cpp (original)
+++ llvm/trunk/lib/Object/ArchiveWriter.cpp Wed Jul 15 15:45:56 2015
@@ -318,6 +318,9 @@ llvm::writeArchive(StringRef ArcName,
MemberRef = Buffers.back()->getMemBufferRef();
} else {
object::Archive::child_iterator OldMember = Member.getOld();
+ assert(!Thin ||
+ OldMember->getParent()->isThin() &&
+ "Thin archives cannot refers to member of other archives");
ErrorOr<MemoryBufferRef> MemberBufferOrErr =
OldMember->getMemoryBufferRef();
if (auto EC = MemberBufferOrErr.getError())
Modified: llvm/trunk/test/Object/archive-update.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/archive-update.test?rev=242330&r1=242329&r2=242330&view=diff
==============================================================================
--- llvm/trunk/test/Object/archive-update.test (original)
+++ llvm/trunk/test/Object/archive-update.test Wed Jul 15 15:45:56 2015
@@ -34,3 +34,17 @@ RUN: llvm-ar p %t.a | FileCheck --check-
NEWER: newer
OLDER: older
+
+RUN: rm -f %t.a
+RUN: echo foo > foo
+RUN: echo bar > bar
+RUN: llvm-ar --format=gnu rcT %t.a foo
+RUN: llvm-ar --format=gnu rcT %t.a bar
+RUN: llvm-ar t %t.a | FileCheck --check-prefix=BOTH-FILES %s
+BOTH-FILES: foo
+BOTH-FILES: bar
+
+RUN: rm -f %t.a
+RUN: llvm-ar --format=gnu rc %t.a foo
+RUN: not llvm-ar --format=gnu rcT %t.a bar 2>&1 | FileCheck --check-prefix=ERROR %s
+ERROR: Cannot convert a regular archive to a thin one.
Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=242330&r1=242329&r2=242330&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Wed Jul 15 15:45:56 2015
@@ -436,9 +436,20 @@ static void performReadOperation(Archive
std::exit(1);
}
-template <typename T>
-void addMember(std::vector<NewArchiveIterator> &Members, T I, StringRef Name,
+void addMember(std::vector<NewArchiveIterator> &Members, StringRef FileName,
+ StringRef Name, int Pos = -1) {
+ NewArchiveIterator NI(FileName, Name);
+ if (Pos == -1)
+ Members.push_back(NI);
+ else
+ Members[Pos] = NI;
+}
+
+void addMember(std::vector<NewArchiveIterator> &Members,
+ object::Archive::child_iterator I, StringRef Name,
int Pos = -1) {
+ if (Thin && !I->getParent()->isThin())
+ fail("Cannot convert a regular archive to a thin one");
NewArchiveIterator NI(I, Name);
if (Pos == -1)
Members.push_back(NI);
More information about the llvm-commits
mailing list