[svn r124] Fixed another D vararg + return in ptr bug.

Fixed some nested function calls failed to resolve the context ptr.
This commit is contained in:
Tomas Lindquist Olsen
2007-11-26 07:26:21 +01:00
parent 282f60e4a0
commit 935dfae9c8
6 changed files with 53 additions and 6 deletions

View File

@@ -936,7 +936,7 @@ DValue* CallExp::toElem(IRState* p)
Logger::println("This Call");
if (dfn->vthis->getType() != argiter->get()) {
//Logger::cout() << *fn->thisparam << '|' << *argiter->get() << '\n';
llargs[j] = new llvm::BitCastInst(dfn->vthis, argiter->get(), "tmp", p->scopebb());
llargs[j] = DtoBitCast(dfn->vthis, argiter->get());
}
else {
llargs[j] = dfn->vthis;
@@ -956,8 +956,9 @@ DValue* CallExp::toElem(IRState* p)
else if (dfn && dfn->func && dfn->func->isNested()) {
Logger::println("Nested Call");
llvm::Value* contextptr = p->func()->decl->llvmNested;
assert(contextptr);
llargs[j] = p->ir->CreateBitCast(contextptr, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp");
if (!contextptr)
contextptr = llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty));
llargs[j] = DtoBitCast(contextptr, llvm::PointerType::get(llvm::Type::Int8Ty));
++j;
++argiter;
}
@@ -970,7 +971,7 @@ DValue* CallExp::toElem(IRState* p)
Argument* fnarg = Argument::getNth(tf->parameters, i);
Expression* exp = (Expression*)arguments->data[i];
DValue* expelem = exp->toElem(p);
llargs[j] = p->ir->CreateBitCast(expelem->getLVal(), llvm::PointerType::get(llvm::Type::Int8Ty), "tmp");
llargs[j] = DtoBitCast(expelem->getLVal(), llvm::PointerType::get(llvm::Type::Int8Ty));
}
}
// regular arguments
@@ -979,6 +980,8 @@ DValue* CallExp::toElem(IRState* p)
{
Logger::println("doing d-style variadic arguments");
size_t nimplicit = j;
std::vector<const llvm::Type*> vtypes;
std::vector<llvm::Value*> vvalues;
std::vector<llvm::Value*> vtypeinfos;
@@ -1020,7 +1023,7 @@ DValue* CallExp::toElem(IRState* p)
j++;
llargs[j] = p->ir->CreateBitCast(mem, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp");
j++;
llargs.resize(2);
llargs.resize(nimplicit+2);
}
else {
Logger::println("doing normal arguments");

View File

@@ -325,6 +325,8 @@ test/bug72.d
test/bug73.d
test/bug74.d
test/bug75.d
test/bug76.d
test/bug77.d
test/bug8.d
test/bug9.d
test/c.d
@@ -418,6 +420,7 @@ test/staticarrays.d
test/staticvars.d
test/stdiotest.d
test/strings1.d
test/strings2.d
test/structinit.d
test/structinit2.d
test/structs.d

View File

@@ -449,7 +449,7 @@ formattedPrint("The answer is %s:", x, 6);
------------------------
*/
void doFormat(void delegate(dchar) putc, TypeInfo[] arguments, va_list argptr)
void doFormat(void delegate(dchar) putc, TypeInfo[] arguments, void* argptr)
{ int j;
TypeInfo ti;
Mangle m;

9
test/bug76.d Normal file
View File

@@ -0,0 +1,9 @@
module bug76;
char[] fmt(...)
{
return "";
}
void main()
{
char[] s = fmt();
}

17
test/bug77.d Normal file
View File

@@ -0,0 +1,17 @@
module bug77;
import std.c.string;
void main()
{
size_t len;
void func2()
{
char* prefix = "";
void func()
{
len = strlen(prefix);
assert(len == 0);
}
}
func2();
}

15
test/strings2.d Normal file
View File

@@ -0,0 +1,15 @@
module strings2;
import std.string;
import std.stdio;
void main()
{
int i = 32;
auto str = format(i);
writefln(str);
long l = 123123;
str = format(l);
writefln(str);
}