mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-22 07:43:18 +01:00
[svn r30] * Fixed static function-local variables.
* Fixed CondExp - bool ? true : false
This commit is contained in:
28
gen/toir.c
28
gen/toir.c
@@ -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;
|
||||
|
||||
10
gen/toobj.c
10
gen/toobj.c
@@ -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
13
test/staticvars.d
Normal file
@@ -0,0 +1,13 @@
|
||||
module staticvars;
|
||||
|
||||
int func()
|
||||
{
|
||||
static int i;
|
||||
return i++;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
assert(func() == 0);
|
||||
assert(func() == 1);
|
||||
}
|
||||
Reference in New Issue
Block a user