diff gen/llvmhelpers.cpp @ 1643:8f121883bce8

Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
author Kelly Wilson <wilsonk cpsc.ucalgary.ca>
date Mon, 08 Mar 2010 23:37:40 -0700
parents b0dfdd5f6006
children 40bd4a0d4870
line wrap: on
line diff
--- a/gen/llvmhelpers.cpp	Mon Mar 08 23:10:26 2010 -0700
+++ b/gen/llvmhelpers.cpp	Mon Mar 08 23:37:40 2010 -0700
@@ -1572,3 +1572,36 @@
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
+
+LLValue* makeLValue(Loc& loc, DValue* value)
+{
+    Type* valueType = value->getType();
+    bool needsMemory;
+    LLValue* valuePointer;
+    if (value->isIm()) {
+        valuePointer = value->getRVal();
+        needsMemory = !DtoIsPassedByRef(valueType);
+    }
+    else if (DVarValue* var = value->isVar()) {
+        valuePointer = value->getLVal();
+        needsMemory = false;
+    }
+    else if (value->isConst()) {
+        valuePointer = value->getRVal();
+        needsMemory = true;
+    }
+    else {
+        valuePointer = DtoAlloca(valueType, ".makelvaluetmp");
+        DVarValue var(valueType, valuePointer);
+        DtoAssign(loc, &var, value);
+        needsMemory = false;
+    }
+
+    if (needsMemory) {
+        LLValue* tmp = DtoAlloca(valueType, ".makelvaluetmp");
+        DtoStore(valuePointer, tmp);
+        valuePointer = tmp;
+    }
+
+    return valuePointer;
+}