changeset 482:aa8c050dfd19

Move zero init of padding to DtoInitializer in order to respect void initializers.
author Christian Kamm <kamm incasoftware de>
date Thu, 07 Aug 2008 18:15:27 +0200
parents 18480579dc04
children d86af825e8d9
files gen/llvmhelpers.cpp gen/llvmhelpers.h
diffstat 2 files changed, 28 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/gen/llvmhelpers.cpp	Tue Aug 05 20:23:44 2008 +0200
+++ b/gen/llvmhelpers.cpp	Thu Aug 07 18:15:27 2008 +0200
@@ -20,6 +20,8 @@
 #include "gen/typeinf.h"
 #include "gen/todebug.h"
 
+#include <stack>
+
 /****************************************************************************************/
 /*////////////////////////////////////////////////////////////////////////////////////////
 // DYNAMIC MEMORY HELPERS
@@ -91,22 +93,11 @@
 
 llvm::AllocaInst* DtoAlloca(const LLType* lltype, const std::string& name)
 {
-    if(lltype == LLType::X86_FP80Ty)
-    {
-        llvm::AllocaInst* alloca = new llvm::AllocaInst(lltype, name, gIR->topallocapoint());
-        LLValue* castv = DtoBitCast(alloca, getPtrToType(LLType::Int16Ty), "fp80toi16");
-        LLValue* padding = DtoGEPi1(castv, 5, "fp80padding");
-        DtoStore(llvm::Constant::getNullValue(LLType::Int16Ty), padding);
-
-        return alloca;
-    }
-
     return new llvm::AllocaInst(lltype, name, gIR->topallocapoint());
 }
 
 llvm::AllocaInst* DtoAlloca(const LLType* lltype, LLValue* arraysize, const std::string& name)
 {
-    assert(lltype != LLType::X86_FP80Ty && "Zero-init of fp80 padding for array allocas not yet implemented");
     return new llvm::AllocaInst(lltype, arraysize, name, gIR->topallocapoint());
 }
 
@@ -887,7 +878,7 @@
     LLValue* cond = gIR->ir->CreateICmpEQ(gIR->ir->CreateLoad(gflag,"tmp"),DtoConstBool(false));
     gIR->ir->CreateCondBr(cond, initbb, endinitbb);
     gIR->scope() = IRScope(initbb,endinitbb);
-    DValue* ie = DtoInitializer(init);
+    DValue* ie = DtoInitializer(gvar, init);
     if (!ie->inPlace()) {
         DValue* dst = new DVarValue(t, gvar, true);
         DtoAssign(init->loc, dst, ie);
@@ -1252,7 +1243,7 @@
             }
 
             Logger::cout() << "llvm value for decl: " << *vd->ir.irLocal->value << '\n';
-            DValue* ie = DtoInitializer(vd->init);
+            DValue* ie = DtoInitializer(vd->ir.irLocal->value, vd->init);
         }
 
         return new DVarValue(vd->type, vd, vd->ir.getIrValue(), true);
@@ -1427,7 +1418,7 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-DValue* DtoInitializer(Initializer* init)
+DValue* DtoInitializer(LLValue* target, Initializer* init)
 {
     if (!init)
         return 0;
@@ -1435,7 +1426,28 @@
     {
         Logger::println("expression initializer");
         assert(ex->exp);
-        return ex->exp->toElem(gIR);
+        DValue* res = ex->exp->toElem(gIR);
+
+        assert(llvm::isa<llvm::PointerType>(target->getType()) && "init target must be ptr");
+        const LLType* targetty = target->getType()->getContainedType(0);
+        if(targetty == LLType::X86_FP80Ty)
+        {
+            Logger::println("setting fp80 padding to zero");
+
+            LLValue* castv = DtoBitCast(target, getPtrToType(LLType::Int16Ty));
+            LLValue* padding = DtoGEPi1(castv, 5);
+            DtoStore(llvm::Constant::getNullValue(LLType::Int16Ty), padding);
+        }
+        else if(targetty == DtoComplexType(Type::tcomplex80))
+        {
+            Logger::println("setting complex fp80 padding to zero");
+
+            LLValue* castv = DtoBitCast(target, getPtrToType(LLType::Int16Ty));
+            LLValue* padding = DtoGEPi1(castv, 5);
+            DtoStore(llvm::Constant::getNullValue(LLType::Int16Ty), padding);
+            padding = DtoGEPi1(castv, 11);
+            DtoStore(llvm::Constant::getNullValue(LLType::Int16Ty), padding);
+        }
     }
     else if (init->isVoidInitializer())
     {
--- a/gen/llvmhelpers.h	Tue Aug 05 20:23:44 2008 +0200
+++ b/gen/llvmhelpers.h	Thu Aug 07 18:15:27 2008 +0200
@@ -81,7 +81,7 @@
 // initializer helpers
 LLConstant* DtoConstInitializer(Type* type, Initializer* init);
 LLConstant* DtoConstFieldInitializer(Type* type, Initializer* init);
-DValue* DtoInitializer(Initializer* init);
+DValue* DtoInitializer(LLValue* target, Initializer* init);
 
 // annotation generator
 void DtoAnnotation(const char* str);