From c4982165bae33bdb7dd975081758b815fd6c7484 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Sun, 13 Jul 2008 04:27:02 +0200 Subject: [PATCH] [svn r366] Fixed identity exprs for structs was comparing addresses, not content! --- gen/structs.cpp | 2 +- gen/toir.cpp | 4 ++++ tests/mini/structs8.d | 54 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/mini/structs8.d diff --git a/gen/structs.cpp b/gen/structs.cpp index 565c4bff..8ae58e35 100644 --- a/gen/structs.cpp +++ b/gen/structs.cpp @@ -389,7 +389,7 @@ LLValue* DtoStructEquals(TOK op, DValue* lhs, DValue* rhs) // set predicate llvm::ICmpInst::Predicate cmpop; - if (op == TOKequal) + if (op == TOKequal || op == TOKidentity) cmpop = llvm::ICmpInst::ICMP_EQ; else cmpop = llvm::ICmpInst::ICMP_NE; diff --git a/gen/toir.cpp b/gen/toir.cpp index 1bfdc193..e48d58ac 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -2260,7 +2260,11 @@ DValue* IdentityExp::toElem(IRState* p) // handle dynarray specially if (t1->ty == Tarray) return new DImValue(type, DtoDynArrayIs(op,u,v)); + // also structs + else if (t1->ty == Tstruct) + return new DImValue(type, DtoStructEquals(op,u,v)); + // FIXME this stuff isn't pretty LLValue* l = u->getRVal(); LLValue* r = v->getRVal(); LLValue* eval = 0; diff --git a/tests/mini/structs8.d b/tests/mini/structs8.d new file mode 100644 index 00000000..c8e707c7 --- /dev/null +++ b/tests/mini/structs8.d @@ -0,0 +1,54 @@ +module test.structs8; + +struct S +{ + int a,b; +} + +void main() +{ + S a = S(1,2); + S b = S(2,3); + S c = S(3,4); + S d = S(2,3); + + assert(a == a); + assert(a != b); + assert(a != c); + assert(a != d); + + assert(b != a); + assert(b == b); + assert(b != c); + assert(b == d); + + assert(c != a); + assert(c != b); + assert(c == c); + assert(c != d); + + assert(d != a); + assert(d == b); + assert(d != c); + assert(d == d); + + assert(a is a); + assert(a !is b); + assert(a !is c); + assert(a !is d); + + assert(b !is a); + assert(b is b); + assert(b !is c); + assert(b is d); + + assert(c !is a); + assert(c !is b); + assert(c is c); + assert(c !is d); + + assert(d !is a); + assert(d is b); + assert(d !is c); + assert(d is d); +}