[llvm] r250222 - Tweak to r250117 and change to use ErrorOr and drop isSizeValid for
Kevin Enderby via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 13 13:48:05 PDT 2015
Author: enderby
Date: Tue Oct 13 15:48:04 2015
New Revision: 250222
URL: http://llvm.org/viewvc/llvm-project?rev=250222&view=rev
Log:
Tweak to r250117 and change to use ErrorOr and drop isSizeValid for
ArchiveMemberHeader, suggestion by Rafael EspĂndola.
Also The clang-x86-win2008-selfhost bot still does not like the
malformed-machos 00000031.a test, so removing it for now. All
the other bots are fine with it however.
Modified:
llvm/trunk/include/llvm/Object/Archive.h
llvm/trunk/lib/Object/Archive.cpp
llvm/trunk/test/tools/llvm-objdump/X86/malformed-machos.test
Modified: llvm/trunk/include/llvm/Object/Archive.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Archive.h?rev=250222&r1=250221&r2=250222&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/Archive.h (original)
+++ llvm/trunk/include/llvm/Object/Archive.h Tue Oct 13 15:48:04 2015
@@ -37,8 +37,7 @@ struct ArchiveMemberHeader {
llvm::StringRef getName() const;
/// Members are not larger than 4GB.
- uint32_t getSize() const;
- bool isSizeValid() const;
+ ErrorOr<uint32_t> getSize() const;
sys::fs::perms getAccessMode() const;
sys::TimeValue getLastModified() const;
Modified: llvm/trunk/lib/Object/Archive.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Archive.cpp?rev=250222&r1=250221&r2=250222&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Archive.cpp (original)
+++ llvm/trunk/lib/Object/Archive.cpp Tue Oct 13 15:48:04 2015
@@ -43,20 +43,13 @@ StringRef ArchiveMemberHeader::getName()
return llvm::StringRef(Name, end);
}
-uint32_t ArchiveMemberHeader::getSize() const {
+ErrorOr<uint32_t> ArchiveMemberHeader::getSize() const {
uint32_t Ret;
if (llvm::StringRef(Size, sizeof(Size)).rtrim(" ").getAsInteger(10, Ret))
- llvm_unreachable("Size is not a decimal number.");
+ return object_error::parse_failed;
return Ret;
}
-bool ArchiveMemberHeader::isSizeValid() const {
- uint32_t Ret;
- if (llvm::StringRef(Size, sizeof(Size)).rtrim(" ").getAsInteger(10, Ret))
- return false;
- return true;
-}
-
sys::fs::perms ArchiveMemberHeader::getAccessMode() const {
unsigned Ret;
if (StringRef(AccessMode, sizeof(AccessMode)).rtrim(" ").getAsInteger(8, Ret))
@@ -96,11 +89,6 @@ Archive::Child::Child(const Archive *Par
uint64_t Size = sizeof(ArchiveMemberHeader);
Data = StringRef(Start, Size);
- // Check to make sure the size is valid.
- const ArchiveMemberHeader *Header =
- reinterpret_cast<const ArchiveMemberHeader *>(Data.data());
- if (!Header->isSizeValid())
- return;
if (!isThinMember()) {
Size += getRawSize();
Data = StringRef(Start, Size);
@@ -119,13 +107,20 @@ Archive::Child::Child(const Archive *Par
}
uint64_t Archive::Child::getSize() const {
- if (Parent->IsThin)
- return getHeader()->getSize();
+ if (Parent->IsThin) {
+ ErrorOr<uint32_t> Size = getHeader()->getSize();
+ if (Size.getError())
+ return 0;
+ return Size.get();
+ }
return Data.size() - StartOfFile;
}
uint64_t Archive::Child::getRawSize() const {
- return getHeader()->getSize();
+ ErrorOr<uint32_t> Size = getHeader()->getSize();
+ if (Size.getError())
+ return 0;
+ return Size.get();
}
bool Archive::Child::isThinMember() const {
Modified: llvm/trunk/test/tools/llvm-objdump/X86/malformed-machos.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/malformed-machos.test?rev=250222&r1=250221&r2=250222&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/X86/malformed-machos.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/X86/malformed-machos.test Tue Oct 13 15:48:04 2015
@@ -39,10 +39,3 @@
# RUN: | FileCheck -check-prefix=m0337 %s
# m0337: subq $16, %rsp
-
-# RUN: llvm-objdump -arch x86_64 -macho -disassemble \
-# RUN: %p/Inputs/malformed-machos/00000031.a \
-# RUN: | FileCheck -check-prefix=0031a %s
-
-# 0031a: Archive
-
More information about the llvm-commits
mailing list