diff gen/functions.cpp @ 945:03d7c4aac654

SWITCHED TO LLVM 2.5 ! Applied patch from ticket #129 to compile against latest LLVM. Thanks Frits van Bommel. Fixed implicit return by asm block at the end of a function on x86-32. Other architectures will produce an error at the moment. Adding support for new targets is fairly simple. Fixed return calling convention for complex numbers, ST and ST(1) were switched around. Added some testcases. I've run a dstress test and there are no regressions. However, the runtime does not seem to compile with symbolic debug information. -O3 -release -inline works well and is what I used for the dstress run. Tango does not compile, a small workaround is needed in tango.io.digest.Digest.Digest.hexDigest. See ticket #206 .
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Sun, 08 Feb 2009 05:26:54 +0100
parents 39519a1ff603
children 1714836f2c0b
line wrap: on
line diff
--- a/gen/functions.cpp	Sun Feb 08 05:14:24 2009 +0100
+++ b/gen/functions.cpp	Sun Feb 08 05:26:54 2009 +0100
@@ -907,6 +907,10 @@
     // output function body
     fd->fbody->toIR(gIR);
 
+    // TODO: clean up this mess
+
+//     std::cout << *func << std::endl;
+
     // llvm requires all basic blocks to end with a TerminatorInst but DMD does not put a return statement
     // in automatically, so we do it here.
     if (!gIR->scopereturned()) {
@@ -917,12 +921,23 @@
         }
         else {
             if (!fd->isMain())
-                llvm::ReturnInst::Create(llvm::UndefValue::get(func->getReturnType()), gIR->scopebb());
+            {
+                AsmBlockStatement* asmb = fd->fbody->endsWithAsm();
+                if (asmb) {
+                    assert(asmb->abiret);
+                    llvm::ReturnInst::Create(asmb->abiret, gIR->scopebb());
+                }
+                else {
+                    llvm::ReturnInst::Create(llvm::UndefValue::get(func->getReturnType()), gIR->scopebb());
+                }
+            }
             else
                 llvm::ReturnInst::Create(llvm::Constant::getNullValue(func->getReturnType()), gIR->scopebb());
         }
     }
 
+//     std::cout << *func << std::endl;
+
     // erase alloca point
     allocaPoint->eraseFromParent();
     allocaPoint = 0;
@@ -934,28 +949,9 @@
     assert(!func->getBasicBlockList().empty());
     func->getBasicBlockList().pop_back();
 
-    // if the last block is empty now, it must be unreachable or it's a bug somewhere else
-    // would be nice to figure out how to assert that this is correct
-    llvm::BasicBlock* lastbb = &func->getBasicBlockList().back();
-    if (lastbb->empty())
-    {
-        new llvm::UnreachableInst(lastbb);
-    }
+    gIR->functions.pop_back();
 
-    // if the last block is not terminated we return a null value or void
-    // for some unknown reason this is needed when a void main() has a inline asm block ...
-    // this should be harmless for well formed code!
-    lastbb = &func->getBasicBlockList().back();
-    if (!lastbb->getTerminator())
-    {
-        Logger::println("adding missing return statement");
-        if (func->getReturnType() == LLType::VoidTy)
-            llvm::ReturnInst::Create(lastbb);
-        else
-            llvm::ReturnInst::Create(llvm::Constant::getNullValue(func->getReturnType()), lastbb);
-    }
-
-    gIR->functions.pop_back();
+//     std::cout << *func << std::endl;
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////