changeset 524:ca2dfe98036c

Binary ops had the wrong result type for real op imaginary. Fixes: run/creal_03
author Christian Kamm <kamm incasoftware de>
date Sun, 17 Aug 2008 12:21:53 +0200
parents c9a606d6e641
children b18b6135e54b
files gen/binops.cpp gen/llvmhelpers.h gen/toir.cpp
diffstat 3 files changed, 17 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/gen/binops.cpp	Sun Aug 17 11:39:36 2008 +0200
+++ b/gen/binops.cpp	Sun Aug 17 12:21:53 2008 +0200
@@ -24,15 +24,15 @@
 
 //////////////////////////////////////////////////////////////////////////////
 
-DValue* DtoBinMul(DValue* lhs, DValue* rhs)
+DValue* DtoBinMul(Type* targettype, DValue* lhs, DValue* rhs)
 {
     LLValue* v = gIR->ir->CreateMul(lhs->getRVal(), rhs->getRVal(), "tmp");
-    return new DImValue( lhs->getType(), v );
+    return new DImValue( targettype, v );
 }
 
 //////////////////////////////////////////////////////////////////////////////
 
-DValue* DtoBinDiv(DValue* lhs, DValue* rhs)
+DValue* DtoBinDiv(Type* targettype, DValue* lhs, DValue* rhs)
 {
     Type* t = lhs->getType();
     LLValue *l, *r;
@@ -45,12 +45,12 @@
         res = gIR->ir->CreateSDiv(l, r, "tmp");
     else
         res = gIR->ir->CreateUDiv(l, r, "tmp");
-    return new DImValue( lhs->getType(), res );
+    return new DImValue( targettype, res );
 }
 
 //////////////////////////////////////////////////////////////////////////////
 
-DValue* DtoBinRem(DValue* lhs, DValue* rhs)
+DValue* DtoBinRem(Type* targettype, DValue* lhs, DValue* rhs)
 {
     Type* t = lhs->getType();
     LLValue *l, *r;
@@ -63,5 +63,5 @@
         res = gIR->ir->CreateSRem(l, r, "tmp");
     else
         res = gIR->ir->CreateURem(l, r, "tmp");
-    return new DImValue( lhs->getType(), res );
+    return new DImValue( targettype, res );
 }
--- a/gen/llvmhelpers.h	Sun Aug 17 11:39:36 2008 +0200
+++ b/gen/llvmhelpers.h	Sun Aug 17 12:21:53 2008 +0200
@@ -95,9 +95,11 @@
 // binary operations
 DValue* DtoBinAdd(DValue* lhs, DValue* rhs);
 DValue* DtoBinSub(DValue* lhs, DValue* rhs);
-DValue* DtoBinMul(DValue* lhs, DValue* rhs);
-DValue* DtoBinDiv(DValue* lhs, DValue* rhs);
-DValue* DtoBinRem(DValue* lhs, DValue* rhs);
+// these binops need an explicit result type to handling
+// to give 'ifloat op float' and 'float op ifloat' the correct type
+DValue* DtoBinMul(Type* resulttype, DValue* lhs, DValue* rhs);
+DValue* DtoBinDiv(Type* resulttype, DValue* lhs, DValue* rhs);
+DValue* DtoBinRem(Type* resulttype, DValue* lhs, DValue* rhs);
 
 // target stuff
 void findDefaultTarget();
--- a/gen/toir.cpp	Sun Aug 17 11:39:36 2008 +0200
+++ b/gen/toir.cpp	Sun Aug 17 12:21:53 2008 +0200
@@ -653,7 +653,7 @@
         return DtoComplexMul(loc, type, l, r);
     }
 
-    return DtoBinMul(l,r);
+    return DtoBinMul(type, l, r);
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
@@ -671,7 +671,7 @@
         res = DtoComplexMul(loc, type, l, r);
     }
     else {
-        res = DtoBinMul(l,r);
+        res = DtoBinMul(type, l, r);
     }
     DtoAssign(loc, l, res);
 
@@ -692,7 +692,7 @@
         return DtoComplexDiv(loc, type, l, r);
     }
 
-    return DtoBinDiv(l, r);
+    return DtoBinDiv(type, l, r);
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
@@ -710,7 +710,7 @@
         res = DtoComplexDiv(loc, type, l, r);
     }
     else {
-        res = DtoBinDiv(l,r);
+        res = DtoBinDiv(type, l, r);
     }
     DtoAssign(loc, l, res);
 
@@ -727,7 +727,7 @@
     DValue* l = e1->toElem(p);
     DValue* r = e2->toElem(p);
 
-    return DtoBinRem(l, r);
+    return DtoBinRem(type, l, r);
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
@@ -740,7 +740,7 @@
     DValue* l = e1->toElem(p);
     DValue* r = e2->toElem(p);
 
-    DValue* res = DtoBinRem(l, r);
+    DValue* res = DtoBinRem(type, l, r);
     DtoAssign(loc, l, res);
 
     return res;