Skip to content

Commit

Permalink
Compare DataLayout by Value, not by pointer.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
espindola committed Feb 26, 2014
1 parent e356197 commit c4bdb93
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/llvm/IR/DataLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ class DataLayout {
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).
Expand Down
10 changes: 10 additions & 0 deletions lib/IR/DataLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Linker/LinkModules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
1 change: 1 addition & 0 deletions test/Linker/Inputs/datalayout-a.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target datalayout = "e"
1 change: 1 addition & 0 deletions test/Linker/Inputs/datalayout-b.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target datalayout = "E"
14 changes: 14 additions & 0 deletions test/Linker/datalayout.ll
Original file line number Diff line number Diff line change
@@ -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!

0 comments on commit c4bdb93

Please sign in to comment.