aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-01-06 10:14:38 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-01-06 10:14:38 -0800
commita04e87629b6548d2be2a99fab4644ccad6ee6fc8 (patch)
tree7c6716de12307756637cedb3b85fd884ef14ec19
parent887963b047d69e19649749fb426a9f35e5f2eaad (diff)
handle the case where llvm casts a void function so it appears to return a value
-rw-r--r--lib/Target/JSBackend/CallHandlers.h17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/Target/JSBackend/CallHandlers.h b/lib/Target/JSBackend/CallHandlers.h
index c6f16e6a78..08111cc435 100644
--- a/lib/Target/JSBackend/CallHandlers.h
+++ b/lib/Target/JSBackend/CallHandlers.h
@@ -28,11 +28,13 @@ const Value *getActuallyCalledValue(const CallInst *CI) {
DEF_CALL_HANDLER(__default__, {
const Value *CV = getActuallyCalledValue(CI);
bool NeedCasts;
+ FunctionType *FT;
if (const Function *F = dyn_cast<const Function>(CV)) {
NeedCasts = F->isDeclaration(); // if ffi call, need casts
+ FT = F->getFunctionType();
} else {
// function pointer call
- FunctionType *FT = dyn_cast<FunctionType>(dyn_cast<PointerType>(CV->getType())->getElementType());
+ FT = dyn_cast<FunctionType>(dyn_cast<PointerType>(CV->getType())->getElementType());
std::string Sig = getFunctionSignature(FT);
Name = std::string("FUNCTION_TABLE_") + Sig + "[" + Name + " & #FM_" + Sig + "#]";
ensureFunctionTable(FT);
@@ -49,9 +51,16 @@ DEF_CALL_HANDLER(__default__, {
if (i < NumArgs - 1) text += ", ";
}
text += ")";
- Type *RT = CI->getType();
- if (!RT->isVoidTy()) {
- text = getAssign(getJSName(CI), RT) + getCast(text, RT, ASM_NONSPECIFIC);
+ // handle return value
+ Type *InstRT = CI->getType();
+ Type *ActualRT = FT->getReturnType();
+ if (!InstRT->isVoidTy() && ActualRT->isVoidTy()) {
+ // the function we are calling was cast to something returning a value, but it really
+ // does not return a value
+ getAssign(getJSName(CI), InstRT); // ensure the variable is defined, but do not emit it here
+ // it should have 0 uses, but just to be safe
+ } else if (!ActualRT->isVoidTy()) {
+ text = getAssign(getJSName(CI), ActualRT) + getCast(text, ActualRT, ASM_NONSPECIFIC);
}
return text;
})