[llvm] r202276 - Compare DataLayout by Value, not by pointer.
Rafael Espindola
rafael.espindola at gmail.com
Wed Feb 26 09:02:09 PST 2014
Author: rafael
Date: Wed Feb 26 11:02:08 2014
New Revision: 202276
URL: http://llvm.org/viewvc/llvm-project?rev=202276&view=rev
Log:
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!
Added:
llvm/trunk/test/Linker/Inputs/datalayout-a.ll
llvm/trunk/test/Linker/Inputs/datalayout-b.ll
llvm/trunk/test/Linker/datalayout.ll
Modified:
llvm/trunk/include/llvm/IR/DataLayout.h
llvm/trunk/lib/IR/DataLayout.cpp
llvm/trunk/lib/Linker/LinkModules.cpp
Modified: llvm/trunk/include/llvm/IR/DataLayout.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DataLayout.h?rev=202276&r1=202275&r2=202276&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DataLayout.h (original)
+++ llvm/trunk/include/llvm/IR/DataLayout.h Wed Feb 26 11:02:08 2014
@@ -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).
Modified: llvm/trunk/lib/IR/DataLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DataLayout.cpp?rev=202276&r1=202275&r2=202276&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DataLayout.cpp (original)
+++ llvm/trunk/lib/IR/DataLayout.cpp Wed Feb 26 11:02:08 2014
@@ -354,6 +354,16 @@ DataLayout::DataLayout(const Module *M)
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) {
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=202276&r1=202275&r2=202276&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Wed Feb 26 11:02:08 2014
@@ -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";
}
Added: llvm/trunk/test/Linker/Inputs/datalayout-a.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/datalayout-a.ll?rev=202276&view=auto
==============================================================================
--- llvm/trunk/test/Linker/Inputs/datalayout-a.ll (added)
+++ llvm/trunk/test/Linker/Inputs/datalayout-a.ll Wed Feb 26 11:02:08 2014
@@ -0,0 +1 @@
+target datalayout = "e"
Added: llvm/trunk/test/Linker/Inputs/datalayout-b.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/datalayout-b.ll?rev=202276&view=auto
==============================================================================
--- llvm/trunk/test/Linker/Inputs/datalayout-b.ll (added)
+++ llvm/trunk/test/Linker/Inputs/datalayout-b.ll Wed Feb 26 11:02:08 2014
@@ -0,0 +1 @@
+target datalayout = "E"
Added: llvm/trunk/test/Linker/datalayout.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/datalayout.ll?rev=202276&view=auto
==============================================================================
--- llvm/trunk/test/Linker/datalayout.ll (added)
+++ llvm/trunk/test/Linker/datalayout.ll Wed Feb 26 11:02:08 2014
@@ -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!
More information about the llvm-commits
mailing list