aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/CppBackend/CPPBackend.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-11-29 09:56:48 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-11-29 09:57:27 -0800
commit00ee832c4bb5e4f70ac5423d094ea55bb4e3e5b7 (patch)
tree4ffcacf022e555d62e4b5c0eec69cef33239dadf /lib/Target/CppBackend/CPPBackend.cpp
parentc647ea4b19618e17e1610da3290ccfd512ef0b77 (diff)
add a final return if necessary
Diffstat (limited to 'lib/Target/CppBackend/CPPBackend.cpp')
-rw-r--r--lib/Target/CppBackend/CPPBackend.cpp36
1 files changed, 9 insertions, 27 deletions
diff --git a/lib/Target/CppBackend/CPPBackend.cpp b/lib/Target/CppBackend/CPPBackend.cpp
index 44af1e85f9..1c47ac7072 100644
--- a/lib/Target/CppBackend/CPPBackend.cpp
+++ b/lib/Target/CppBackend/CPPBackend.cpp
@@ -2022,20 +2022,6 @@ void CppWriter::printFunctionBody(const Function *F) {
UsedVars.clear();
- // Create all the argument values
- if (!is_inline) {
- for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
- AI != AE; ++AI) {
- if (AI->hasName()) {
- //Out << getCppName(AI) << "->setName(\"";
- //printEscapedString(AI->getName());
- //Out << "\");";
- //nl(Out);
- } else {
- }
- }
- }
-
// Prepare relooper TODO: resize buffer as needed
#define RELOOPER_BUFFER 10*1024*1024
static char *buffer = new char[RELOOPER_BUFFER];
@@ -2156,19 +2142,15 @@ void CppWriter::printFunctionBody(const Function *F) {
// Emit (relooped) code
nl(Out) << buffer;
- // Loop over the ForwardRefs and resolve them now that all instructions
- // are generated.
- if (!ForwardRefs.empty()) {
- nl(Out) << "// Resolve Forward References";
- nl(Out);
- }
-
- while (!ForwardRefs.empty()) {
- ForwardRefMap::iterator I = ForwardRefs.begin();
- Out << I->second << "->replaceAllUsesWith("
- << getCppName(I->first) << "); delete " << I->second << ";";
- nl(Out);
- ForwardRefs.erase(I);
+ // Ensure a final return if necessary
+ Type *RT = F->getFunctionType()->getReturnType();
+ if (!RT->isVoidTy()) {
+ char *LastCurly = strrchr(buffer, '}');
+ if (!LastCurly) LastCurly = buffer;
+ char *FinalReturn = strstr(LastCurly, "return ");
+ if (!FinalReturn) {
+ Out << " return " + getCast("0", RT) + ";\n";
+ }
}
}