changeset 83:339422268de1 trunk

[svn r87] Fixed some memory bloat when passing string literals as char[] params (double temporary before)
author lindquist
date Fri, 02 Nov 2007 02:03:13 +0100
parents d8dd47ef3973
children 169711a7126e
files gen/elem.c gen/elem.h gen/toir.c gen/tollvm.c
diffstat 4 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/gen/elem.c	Fri Nov 02 01:17:26 2007 +0100
+++ b/gen/elem.c	Fri Nov 02 02:03:13 2007 +0100
@@ -20,6 +20,7 @@
     callconv = (unsigned)-1;
     isthis = false;
     istypeinfo = false;
+    temp = false;
 
     vardecl = 0;
     funcdecl = 0;
--- a/gen/elem.h	Fri Nov 02 01:17:26 2007 +0100
+++ b/gen/elem.h	Fri Nov 02 02:03:13 2007 +0100
@@ -33,6 +33,7 @@
     unsigned callconv;
     bool isthis;
     bool istypeinfo;
+    bool temp;
 
     VarDeclaration* vardecl;
     FuncDeclaration* funcdecl;
--- a/gen/toir.c	Fri Nov 02 01:17:26 2007 +0100
+++ b/gen/toir.c	Fri Nov 02 02:03:13 2007 +0100
@@ -362,9 +362,10 @@
     if (dtype->ty == Tarray) {
         llvm::Constant* clen = llvm::ConstantInt::get(DtoSize_t(),len,false);
         if (!p->topexp() || p->topexp()->e2 != this) {
-            llvm::Value* tmpmem = new llvm::AllocaInst(DtoType(dtype),"tmp",p->topallocapoint());
+            llvm::Value* tmpmem = new llvm::AllocaInst(DtoType(dtype),"tempstring",p->topallocapoint());
             DtoSetArray(tmpmem, clen, arrptr);
             e->mem = tmpmem;
+            e->temp = true;
         }
         else if (p->topexp()->e2 == this) {
             llvm::Value* arr = p->topexp()->v;
--- a/gen/tollvm.c	Fri Nov 02 01:17:26 2007 +0100
+++ b/gen/tollvm.c	Fri Nov 02 02:03:13 2007 +0100
@@ -1196,6 +1196,9 @@
                     allocaInst = new llvm::AllocaInst(realtypell, "tmpparam", gIR->topallocapoint());
                     DtoSetArray(allocaInst, arg->arg, arg->mem);
                 }
+                else if (arg->temp) {
+                    allocaInst = arg->mem;
+                }
                 else {
                     allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", gIR->topallocapoint());
                     DtoArrayAssign(allocaInst,arg->mem);
@@ -1204,7 +1207,6 @@
             else
             assert(0);
 
-            assert(allocaInst != 0);
             retval = allocaInst;
         }
     }