comparison gen/functions.cpp @ 262:88252a1af660 trunk

[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
author lindquist
date Sat, 14 Jun 2008 05:13:49 +0200
parents 8dbddae09152
children 665b81613475
comparison
equal deleted inserted replaced
261:5723b7385c25 262:88252a1af660
1 #include "gen/llvm.h" 1 #include "gen/llvm.h"
2 #include "llvm/Support/CFG.h"
2 3
3 #include "mtype.h" 4 #include "mtype.h"
4 #include "aggregate.h" 5 #include "aggregate.h"
5 #include "init.h" 6 #include "init.h"
6 #include "declaration.h" 7 #include "declaration.h"
733 734
734 // if the last block is empty now, it must be unreachable or it's a bug somewhere else 735 // if the last block is empty now, it must be unreachable or it's a bug somewhere else
735 // would be nice to figure out how to assert that this is correct 736 // would be nice to figure out how to assert that this is correct
736 llvm::BasicBlock* lastbb = &func->getBasicBlockList().back(); 737 llvm::BasicBlock* lastbb = &func->getBasicBlockList().back();
737 if (lastbb->empty()) { 738 if (lastbb->empty()) {
738 if (lastbb->getNumUses() == 0) 739 new llvm::UnreachableInst(lastbb);
739 lastbb->eraseFromParent(); 740 // if (llvm::pred_begin(lastbb) != llvm::pred_end(lastbb))
740 else { 741 // {
741 new llvm::UnreachableInst(lastbb); 742 // Logger::println("Erasing lastbb");
742 /*if (func->getReturnType() == LLType::VoidTy) { 743 // lastbb->eraseFromParent();
743 llvm::ReturnInst::Create(lastbb); 744 // }
744 } 745 // else {
745 else { 746 // new llvm::UnreachableInst(lastbb);
746 llvm::ReturnInst::Create(llvm::UndefValue::get(func->getReturnType()), lastbb); 747 // // if (func->getReturnType() == LLType::VoidTy) {
747 }*/ 748 // // llvm::ReturnInst::Create(lastbb);
748 } 749 // // }
750 // // else {
751 // // llvm::ReturnInst::Create(llvm::UndefValue::get(func->getReturnType()), lastbb);
752 // // }
753 // }
749 } 754 }
750 755
751 // if the last block is not terminated we return a null value or void 756 // if the last block is not terminated we return a null value or void
752 // for some unknown reason this is needed when a void main() has a inline asm block ... 757 // for some unknown reason this is needed when a void main() has a inline asm block ...
753 // this should be harmless for well formed code! 758 // this should be harmless for well formed code!