# HG changeset patch # User lindquist # Date 1212784231 -7200 # Node ID 74701ba40398a2d654fdd6808c7654ee338273f0 # Parent 116cc012409bac47b078452c3cff9678d501b82f [svn r241] Fixed missing terminator for void main() with inline asm block. diff -r 116cc012409b -r 74701ba40398 gen/asmstmt.cpp --- a/gen/asmstmt.cpp Fri Jun 06 22:04:41 2008 +0200 +++ b/gen/asmstmt.cpp Fri Jun 06 22:30:31 2008 +0200 @@ -76,18 +76,18 @@ const LLType* ret = LLType::VoidTy; if (!output_values.empty()) { - std::cout << "memory outputs" << std::endl; assert(output_values.size() == 1); const LLType* llty = DtoType(output_values[0]->getType()); + std::cout << "out: " << *llty << '\n'; params.push_back(llty); } // inputs if (!input_values.empty()) { - std::cout << "inputs" << std::endl; assert(input_values.size() == 1); const LLType* llty = DtoType(input_values[0]->getType()); + std::cout << "in: " << *llty << '\n'; params.push_back(llty); } diff -r 116cc012409b -r 74701ba40398 gen/functions.cpp --- a/gen/functions.cpp Fri Jun 06 22:04:41 2008 +0200 +++ b/gen/functions.cpp Fri Jun 06 22:30:31 2008 +0200 @@ -694,6 +694,19 @@ } } + // 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() == llvm::Type::VoidTy) + llvm::ReturnInst::Create(lastbb); + else + llvm::ReturnInst::Create(llvm::Constant::getNullValue(func->getReturnType()), lastbb); + } + gIR->functions.pop_back(); } } diff -r 116cc012409b -r 74701ba40398 llvmdc.kdevelop.filelist --- a/llvmdc.kdevelop.filelist Fri Jun 06 22:04:41 2008 +0200 +++ b/llvmdc.kdevelop.filelist Fri Jun 06 22:30:31 2008 +0200 @@ -752,6 +752,7 @@ tangotests/arrays1.d tangotests/asm1.d tangotests/asm2.d +tangotests/asm3.d tangotests/b.d tangotests/byval1.d tangotests/c.d diff -r 116cc012409b -r 74701ba40398 tangotests/asm2.d --- a/tangotests/asm2.d Fri Jun 06 22:04:41 2008 +0200 +++ b/tangotests/asm2.d Fri Jun 06 22:30:31 2008 +0200 @@ -5,10 +5,12 @@ int main() { int i = 40; + int j = 2; asm { mov EAX, i; - add EAX, 2; + mov EBX, j; + add EAX, EBX; mov i, EAX; } printf("42 = %d\n", i);