[svn r30] * Fixed static function-local variables.

* Fixed CondExp - bool ? true : false
This commit is contained in:
Tomas Lindquist Olsen
2007-10-04 10:57:26 +02:00
parent 9fd43121db
commit c357c96471
3 changed files with 35 additions and 16 deletions

View File

@@ -46,19 +46,22 @@ elem* DeclarationExp::toElem(IRState* p)
{
Logger::println("VarDeclaration");
// handle const
// TODO probably not correct
bool isconst = (vd->storage_class & STCconst) != 0;
if (vd->isDataseg())
{
vd->toObjFile();
}
else
{
// allocate storage on the stack
Logger::println("vdtype = %s", vd->type->toChars());
const llvm::Type* lltype = LLVM_DtoType(vd->type);
llvm::AllocaInst* allocainst = new llvm::AllocaInst(lltype, vd->toChars(), p->topallocapoint());
//allocainst->setAlignment(vd->type->alignsize()); // TODO
vd->llvmValue = allocainst;
// e->val = really needed??
// allocate storage on the stack
Logger::println("vdtype = %s", vd->type->toChars());
const llvm::Type* lltype = LLVM_DtoType(vd->type);
llvm::AllocaInst* allocainst = new llvm::AllocaInst(lltype, vd->toChars(), p->topallocapoint());
//allocainst->setAlignment(vd->type->alignsize()); // TODO
vd->llvmValue = allocainst;
// e->val = really needed??
LLVM_DtoInitializer(vd->type, vd->init);
LLVM_DtoInitializer(vd->type, vd->init);
}
}
// struct declaration
else if (StructDeclaration* s = declaration->isStructDeclaration())
@@ -2209,7 +2212,6 @@ elem* CondExp::toElem(IRState* p)
p->scope() = IRScope(condtrue, condfalse);
elem* u = e1->toElem(p);
Logger::cout() << *u->val << '|' << *resval << '\n'; \
new llvm::StoreInst(u->getValue(),resval,p->scopebb());
new llvm::BranchInst(condend,p->scopebb());
delete u;

View File

@@ -505,9 +505,13 @@ void VarDeclaration::toObjFile()
if (isDataseg())
{
bool _isconst = isConst();
if (!_isconst)
_isconst = (storage_class & STCconst) ? true : false; // doesn't seem to work ):
llvm::GlobalValue::LinkageTypes _linkage = LLVM_DtoLinkage(protection, storage_class);
llvm::GlobalValue::LinkageTypes _linkage;
if (parent->isFuncDeclaration())
_linkage = llvm::GlobalValue::InternalLinkage;
else
_linkage = LLVM_DtoLinkage(protection, storage_class);
const llvm::Type* _type = LLVM_DtoType(type);
assert(_type);

13
test/staticvars.d Normal file
View File

@@ -0,0 +1,13 @@
module staticvars;
int func()
{
static int i;
return i++;
}
void main()
{
assert(func() == 0);
assert(func() == 1);
}