[svn r87] Fixed some memory bloat when passing string literals as char[] params (double temporary before)

This commit is contained in:
Tomas Lindquist Olsen
2007-11-02 02:03:13 +01:00
parent d58ce84169
commit 6cdf99f01e
4 changed files with 7 additions and 2 deletions

View File

@@ -20,6 +20,7 @@ elem::elem()
callconv = (unsigned)-1;
isthis = false;
istypeinfo = false;
temp = false;
vardecl = 0;
funcdecl = 0;

View File

@@ -33,6 +33,7 @@ public:
unsigned callconv;
bool isthis;
bool istypeinfo;
bool temp;
VarDeclaration* vardecl;
FuncDeclaration* funcdecl;

View File

@@ -362,9 +362,10 @@ elem* StringExp::toElem(IRState* p)
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;

View File

@@ -1196,6 +1196,9 @@ llvm::Value* DtoArgument(const llvm::Type* paramtype, Argument* fnarg, Expressio
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 @@ llvm::Value* DtoArgument(const llvm::Type* paramtype, Argument* fnarg, Expressio
else
assert(0);
assert(allocaInst != 0);
retval = allocaInst;
}
}