aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-03-03 17:49:34 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-03-03 17:49:34 -0800
commitdef43933e61ebc8531aed993a0abaa97f145b41d (patch)
treeb7ecf4b146e150d99596451a11cee2e6d18b1022
parenta34c9814492df18d7ceee3417e72de380df5cd08 (diff)
check argument and return types statically
-rw-r--r--lib/Target/JSBackend/CallHandlers.h19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/Target/JSBackend/CallHandlers.h b/lib/Target/JSBackend/CallHandlers.h
index 9ad89ee169..eefe491d16 100644
--- a/lib/Target/JSBackend/CallHandlers.h
+++ b/lib/Target/JSBackend/CallHandlers.h
@@ -53,7 +53,24 @@ DEF_CALL_HANDLER(__default__, {
errs().resetColor();
errs() << " unexpected number of arguments " << utostr(ActualNumArgs) << " in call to '" << F->getName() << "', should be " << utostr(TypeNumArgs) << "\n";
}
- // TODO: also check types of arguments, but must take into account JS types, not LLVM types
+ for (unsigned i = 0; i < std::min(TypeNumArgs, ActualNumArgs); i++) {
+ Type *TypeType = FT->getParamType(i);
+ Type *ActualType = CI->getOperand(i)->getType();
+ if (getFunctionSignatureLetter(TypeType) != getFunctionSignatureLetter(ActualType)) {
+ errs().changeColor(raw_ostream::YELLOW);
+ errs() << "warning:";
+ errs().resetColor();
+ errs() << " unexpected argument type " << *ActualType << " at index " << utostr(i) << " in call to '" << F->getName() << "', should be " << *TypeType << "\n";
+ }
+ }
+ Type *TypeType = FT->getReturnType();
+ Type *ActualType = CI->getType();
+ if (getFunctionSignatureLetter(TypeType) != getFunctionSignatureLetter(ActualType)) {
+ errs().changeColor(raw_ostream::YELLOW);
+ errs() << "warning:";
+ errs().resetColor();
+ errs() << " unexpected return type " << *ActualType << " in call to '" << F->getName() << "', should be " << *TypeType << "\n";
+ }
}
} else {
if (isAbsolute(CV)) return "abort(); /* segfault, call an absolute addr */";