diff gen/tocall.cpp @ 715:30b42a283c8e

Removed TypeOpaque from DMD. Changed runtime functions taking opaque[] to void[]. Implemented proper type painting, to avoid "resizing" array casts in runtime calls that previously took opaque[]. Implemented dynamic arrays as first class types, this implements proper ABI for these types on x86. Added dwarf region end after call to assert function, fixes some problems with llvm not allowing this to be missing. Reverted change to WithStatement from rev [704] it breaks MiniD, mini/with2.d needs to be fixed some other way... Fixed tango bug 1339 in runtime, problem with _adReverseChar on invalid UTF-8. Disabled .bc generation in the compiler runtime part, genobj.d triggers some llvm bug when using debug info. the .o seems to work fine.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Wed, 22 Oct 2008 14:55:33 +0200
parents df196c8dea26
children 7261ff0f95ff
line wrap: on
line diff
--- a/gen/tocall.cpp	Wed Oct 22 13:48:54 2008 +0200
+++ b/gen/tocall.cpp	Wed Oct 22 14:55:33 2008 +0200
@@ -175,7 +175,7 @@
         true, llvm::GlobalValue::InternalLinkage, tiinits, "._arguments.array", gIR->module);
 
     // specify arguments
-    args.push_back(typeinfoarrayparam);
+    args.push_back(DtoLoad(typeinfoarrayparam));
     ++argidx;
     args.push_back(gIR->ir->CreateBitCast(mem, getPtrToType(LLType::Int8Ty), "tmp"));
     ++argidx;
@@ -319,11 +319,11 @@
             LLValue* arg = argval->getRVal();
             if (fnarg) // can fnarg ever be null in this block?
             {
-//                 if (Logger::enabled())
-//                 {
-//                     Logger::cout() << "arg:     " << *arg << '\n';
-//                     Logger::cout() << "expects: " << *callableTy->getParamType(j) << '\n';
-//                 }
+                if (Logger::enabled())
+                {
+                    Logger::cout() << "arg:     " << *arg << '\n';
+                    Logger::cout() << "expects: " << *callableTy->getParamType(j) << '\n';
+                }
                 if (arg->getType() != callableTy->getParamType(j))
                     arg = DtoBitCast(arg, callableTy->getParamType(j));
                 if (fnarg->llvmAttrs)
@@ -355,9 +355,33 @@
     // get return value
     LLValue* retllval = (retinptr) ? args[0] : call->get();
 
-    // if the type of retllval is abstract, refine to concrete
-    if (retllval->getType()->isAbstract())
-        retllval = DtoBitCast(retllval, getPtrToType(DtoType(resulttype)), "retval");
+    // repaint the type if necessary
+    if (resulttype)
+    {
+        Type* rbase = resulttype->toBasetype();
+        Type* nextbase = tf->next->toBasetype();
+        if (!rbase->equals(nextbase))
+        {
+            Logger::println("repainting return value from '%s' to '%s'", tf->next->toChars(), rbase->toChars());
+            switch(rbase->ty)
+            {
+            case Tarray:
+                retllval = DtoAggrPaint(retllval, DtoType(rbase));
+                break;
+
+            case Tclass:
+            case Taarray:
+            case Tpointer:
+                retllval = DtoBitCast(retllval, DtoType(rbase));
+                break;
+
+            default:
+                assert(0 && "unhandled repainting of return value");
+            }
+            if (Logger::enabled())
+                Logger::cout() << "final return value: " << *retllval << '\n';
+        }
+    }
 
     // set calling convention and parameter attributes
     if (dfnval && dfnval->func)