summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-02-26 17:02:08 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-02-26 17:02:08 +0000
commitc4bdb93d6a4d8eb40584554e0cc4fc3e3732f707 (patch)
tree25c6a5fb60aefed9e2f8e77e751c3e4b915a8e9b
parente3561972d45633cee705084ce1e26c4ecbbe8d43 (diff)
downloadllvm-c4bdb93d6a4d8eb40584554e0cc4fc3e3732f707.tar.gz
llvm-c4bdb93d6a4d8eb40584554e0cc4fc3e3732f707.tar.bz2
llvm-c4bdb93d6a4d8eb40584554e0cc4fc3e3732f707.tar.xz
Compare DataLayout by Value, not by pointer.
This fixes spurious warnings in llvm-link about the datalayout not matching. Thanks to Zalman Stern for reporting the bug! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202276 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/IR/DataLayout.h3
-rw-r--r--lib/IR/DataLayout.cpp10
-rw-r--r--lib/Linker/LinkModules.cpp2
-rw-r--r--test/Linker/Inputs/datalayout-a.ll1
-rw-r--r--test/Linker/Inputs/datalayout-b.ll1
-rw-r--r--test/Linker/datalayout.ll14
6 files changed, 30 insertions, 1 deletions
diff --git a/include/llvm/IR/DataLayout.h b/include/llvm/IR/DataLayout.h
index e26dd026bd..cfed302e65 100644
--- a/include/llvm/IR/DataLayout.h
+++ b/include/llvm/IR/DataLayout.h
@@ -193,6 +193,9 @@ public:
return *this;
}
+ bool operator==(const DataLayout &Other) const;
+ bool operator!=(const DataLayout &Other) const { return !(*this == Other); }
+
~DataLayout(); // Not virtual, do not subclass this class
/// Parse a data layout string (with fallback to default values).
diff --git a/lib/IR/DataLayout.cpp b/lib/IR/DataLayout.cpp
index 7089b7b85f..162f3d3ac3 100644
--- a/lib/IR/DataLayout.cpp
+++ b/lib/IR/DataLayout.cpp
@@ -354,6 +354,16 @@ DataLayout::DataLayout(const Module *M) : LayoutMap(0) {
reset("");
}
+bool DataLayout::operator==(const DataLayout &Other) const {
+ bool Ret = LittleEndian == Other.LittleEndian &&
+ StackNaturalAlign == Other.StackNaturalAlign &&
+ ManglingMode == Other.ManglingMode &&
+ LegalIntWidths == Other.LegalIntWidths &&
+ Alignments == Other.Alignments && Pointers == Pointers;
+ assert(Ret == (getStringRepresentation() == Other.getStringRepresentation()));
+ return Ret;
+}
+
void
DataLayout::setAlignment(AlignTypeEnum align_type, unsigned abi_align,
unsigned pref_align, uint32_t bit_width) {
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp
index f1b8cb7610..9160e2661b 100644
--- a/lib/Linker/LinkModules.cpp
+++ b/lib/Linker/LinkModules.cpp
@@ -1208,7 +1208,7 @@ bool ModuleLinker::run() {
DstM->setTargetTriple(SrcM->getTargetTriple());
if (SrcM->getDataLayout() && DstM->getDataLayout() &&
- SrcM->getDataLayout() != DstM->getDataLayout()) {
+ *SrcM->getDataLayout() != *DstM->getDataLayout()) {
if (!SuppressWarnings) {
errs() << "WARNING: Linking two modules of different data layouts!\n";
}
diff --git a/test/Linker/Inputs/datalayout-a.ll b/test/Linker/Inputs/datalayout-a.ll
new file mode 100644
index 0000000000..e78478e6df
--- /dev/null
+++ b/test/Linker/Inputs/datalayout-a.ll
@@ -0,0 +1 @@
+target datalayout = "e"
diff --git a/test/Linker/Inputs/datalayout-b.ll b/test/Linker/Inputs/datalayout-b.ll
new file mode 100644
index 0000000000..59cdb68a3f
--- /dev/null
+++ b/test/Linker/Inputs/datalayout-b.ll
@@ -0,0 +1 @@
+target datalayout = "E"
diff --git a/test/Linker/datalayout.ll b/test/Linker/datalayout.ll
new file mode 100644
index 0000000000..3ee96eb547
--- /dev/null
+++ b/test/Linker/datalayout.ll
@@ -0,0 +1,14 @@
+; RUN: llvm-link %s %S/Inputs/datalayout-a.ll -S -o - 2>%t.a.err | FileCheck %s
+; RUN: cat %t.a.err | not FileCheck %s 2>&1 | FileCheck --check-prefix=WARN-A %s
+
+; RUN: llvm-link %s %S/Inputs/datalayout-b.ll -S -o - 2>%t.b.err | FileCheck %s
+; RUN: cat %t.b.err | FileCheck --check-prefix=WARN-B %s
+
+target datalayout = "e"
+
+; CHECK: target datalayout = "e"
+
+; this is a hack to check that llvm-link printed no warnings.
+; WARN-A: FileCheck error: '-' is empty.
+
+; WARN-B: WARNING: Linking two modules of different data layouts!