[PATCH] D86542: [llvm/Object] - Make dyn_cast<XCOFFObjectFile> work as it should.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 26 03:51:48 PDT 2020
grimar updated this revision to Diff 287907.
grimar marked an inline comment as done.
grimar edited the summary of this revision.
grimar added a comment.
This revision is now accepted and ready to land.
- Added unit test.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D86542/new/
https://reviews.llvm.org/D86542
Files:
llvm/include/llvm/Object/XCOFFObjectFile.h
llvm/unittests/Object/XCOFFObjectFileTest.cpp
Index: llvm/unittests/Object/XCOFFObjectFileTest.cpp
===================================================================
--- llvm/unittests/Object/XCOFFObjectFileTest.cpp
+++ llvm/unittests/Object/XCOFFObjectFileTest.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Object/XCOFFObjectFile.h"
#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"
@@ -13,6 +14,24 @@
using namespace llvm;
using namespace llvm::object;
+TEST(XCOFFObjectFileTest, XCOFFObjectType) {
+ // Create an arbitrary object of a non-XCOFF type and test that
+ // dyn_cast<XCOFFObjectFile> returns null for it.
+ char Buf[sizeof(typename ELF64LE::Ehdr)] = {};
+ memcpy(Buf, "\177ELF", 4);
+
+ auto *EHdr = reinterpret_cast<typename ELF64LE::Ehdr *>(Buf);
+ EHdr->e_ident[llvm::ELF::EI_CLASS] = llvm::ELF::ELFCLASS64;
+ EHdr->e_ident[llvm::ELF::EI_DATA] = llvm::ELF::ELFDATA2LSB;
+
+ MemoryBufferRef Source(StringRef(Buf, sizeof(Buf)), "non-XCOFF");
+ Expected<std::unique_ptr<ObjectFile>> ObjOrErr =
+ ObjectFile::createObjectFile(Source);
+ ASSERT_THAT_EXPECTED(ObjOrErr, Succeeded());
+
+ EXPECT_TRUE(dyn_cast<XCOFFObjectFile>((*ObjOrErr).get()) == nullptr);
+}
+
TEST(XCOFFObjectFileTest, doesXCOFFTracebackTableBegin) {
EXPECT_TRUE(doesXCOFFTracebackTableBegin({0, 0, 0, 0}));
EXPECT_TRUE(doesXCOFFTracebackTableBegin({0, 0, 0, 0, 1}));
Index: llvm/include/llvm/Object/XCOFFObjectFile.h
===================================================================
--- llvm/include/llvm/Object/XCOFFObjectFile.h
+++ llvm/include/llvm/Object/XCOFFObjectFile.h
@@ -372,6 +372,8 @@
Expected<ArrayRef<XCOFFRelocation32>>
relocations(const XCOFFSectionHeader32 &) const;
+
+ static bool classof(const Binary *B) { return B->isXCOFF(); }
}; // XCOFFObjectFile
class XCOFFSymbolRef {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86542.287907.patch
Type: text/x-patch
Size: 1909 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200826/6ced4cc8/attachment.bin>
More information about the llvm-commits
mailing list