comparison gen/statements.cpp @ 976:fe93215deb82

Fix for fix from [974].
author Christian Kamm <kamm incasoftware de>
date Tue, 17 Feb 2009 19:08:38 +0100
parents 815e1b8c6b00
children ae710cba0884
comparison
equal deleted inserted replaced
975:067bb8f19c36 976:fe93215deb82
91 Logger::cout() << "return value is '" <<*v << "'\n"; 91 Logger::cout() << "return value is '" <<*v << "'\n";
92 92
93 // can happen for classes and void main 93 // can happen for classes and void main
94 if (v->getType() != p->topfunc()->getReturnType()) 94 if (v->getType() != p->topfunc()->getReturnType())
95 { 95 {
96 // for main and a void expression: return 0 instead, else bitcast 96 // for the main function this only happens if it is declared as void
97 if (p->topfunc() == p->mainFunc && v->getType() == LLType::VoidTy) 97 // and then contains a return (exp); statement. Since the actual
98 // return type remains i32, we just throw away the exp value
99 // and return 0 instead
100 // if we're not in main, just bitcast
101 if (p->topfunc() == p->mainFunc)
98 v = llvm::Constant::getNullValue(p->mainFunc->getReturnType()); 102 v = llvm::Constant::getNullValue(p->mainFunc->getReturnType());
99 else 103 else
100 v = gIR->ir->CreateBitCast(v, p->topfunc()->getReturnType(), "tmp"); 104 v = gIR->ir->CreateBitCast(v, p->topfunc()->getReturnType(), "tmp");
101 105
102 if (Logger::enabled()) 106 if (Logger::enabled())