# HG changeset patch # User lindquist # Date 1191488246 -7200 # Node ID 99737f94abfbe3cd42df0f0fec69eae1ddd82906 # Parent 12fd8ce55d9c2135f20508737198e9c386319f33 [svn r30] * Fixed static function-local variables. * Fixed CondExp - bool ? true : false diff -r 12fd8ce55d9c -r 99737f94abfb gen/toir.c --- a/gen/toir.c Thu Oct 04 10:22:56 2007 +0200 +++ b/gen/toir.c Thu Oct 04 10:57:26 2007 +0200 @@ -46,19 +46,22 @@ { 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 @@ 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; diff -r 12fd8ce55d9c -r 99737f94abfb gen/toobj.c --- a/gen/toobj.c Thu Oct 04 10:22:56 2007 +0200 +++ b/gen/toobj.c Thu Oct 04 10:57:26 2007 +0200 @@ -505,9 +505,13 @@ 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); diff -r 12fd8ce55d9c -r 99737f94abfb test/staticvars.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/staticvars.d Thu Oct 04 10:57:26 2007 +0200 @@ -0,0 +1,13 @@ +module staticvars; + +int func() +{ + static int i; + return i++; +} + +void main() +{ + assert(func() == 0); + assert(func() == 1); +}