From 47ac84b223518c091d93e503117db64c246ad813 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Fri, 6 Jun 2008 22:30:31 +0200 Subject: [PATCH] [svn r241] Fixed missing terminator for void main() with inline asm block. --- gen/asmstmt.cpp | 4 ++-- gen/functions.cpp | 13 +++++++++++++ llvmdc.kdevelop.filelist | 1 + tangotests/asm2.d | 4 +++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gen/asmstmt.cpp b/gen/asmstmt.cpp index be5d356e..674a2b17 100644 --- a/gen/asmstmt.cpp +++ b/gen/asmstmt.cpp @@ -76,18 +76,18 @@ d_build_asm_stmt(std::string code, std::deque const& output_values, std 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 --git a/gen/functions.cpp b/gen/functions.cpp index 486dca00..3db4ce42 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -694,6 +694,19 @@ void DtoDefineFunc(FuncDeclaration* fd) } } + // 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 --git a/llvmdc.kdevelop.filelist b/llvmdc.kdevelop.filelist index 828ee1da..cff1f502 100644 --- a/llvmdc.kdevelop.filelist +++ b/llvmdc.kdevelop.filelist @@ -752,6 +752,7 @@ tangotests/align1.d tangotests/arrays1.d tangotests/asm1.d tangotests/asm2.d +tangotests/asm3.d tangotests/b.d tangotests/byval1.d tangotests/c.d diff --git a/tangotests/asm2.d b/tangotests/asm2.d index 124d9109..fc135010 100644 --- a/tangotests/asm2.d +++ b/tangotests/asm2.d @@ -5,10 +5,12 @@ extern(C) int printf(char*, ...); 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);