changeset 26:99737f94abfb trunk

[svn r30] * Fixed static function-local variables. * Fixed CondExp - bool ? true : false
author lindquist
date Thu, 04 Oct 2007 10:57:26 +0200
parents 12fd8ce55d9c
children 92408a3a2bac
files gen/toir.c gen/toobj.c test/staticvars.d
diffstat 3 files changed, 35 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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;
--- 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);
 
--- /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);
+}