aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-03-03 16:33:38 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-03-03 16:33:38 -0800
commita34c9814492df18d7ceee3417e72de380df5cd08 (patch)
tree3ed52f8f6dc2515e58ff7b3d5c04fb8dac9cd851
parent1d33f493d6a107012e667ee9046a15510088f6f3 (diff)
forward assertions setting into backend, and use it to check for invalid # of args in static calls
-rw-r--r--lib/Target/JSBackend/CallHandlers.h11
-rw-r--r--lib/Target/JSBackend/JSBackend.cpp5
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/Target/JSBackend/CallHandlers.h b/lib/Target/JSBackend/CallHandlers.h
index 93275b9637..9ad89ee169 100644
--- a/lib/Target/JSBackend/CallHandlers.h
+++ b/lib/Target/JSBackend/CallHandlers.h
@@ -44,6 +44,17 @@ DEF_CALL_HANDLER(__default__, {
if (F) {
NeedCasts = F->isDeclaration(); // if ffi call, need casts
FT = F->getFunctionType();
+ if (EmscriptenAssertions) {
+ unsigned TypeNumArgs = FT->getNumParams();
+ unsigned ActualNumArgs = getNumArgOperands(CI);
+ if (TypeNumArgs != ActualNumArgs) {
+ errs().changeColor(raw_ostream::YELLOW);
+ errs() << "warning:";
+ 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
+ }
} else {
if (isAbsolute(CV)) return "abort(); /* segfault, call an absolute addr */";
// function pointer call
diff --git a/lib/Target/JSBackend/JSBackend.cpp b/lib/Target/JSBackend/JSBackend.cpp
index b0a4b496ac..6ed2632441 100644
--- a/lib/Target/JSBackend/JSBackend.cpp
+++ b/lib/Target/JSBackend/JSBackend.cpp
@@ -76,6 +76,11 @@ ReservedFunctionPointers("emscripten-reserved-function-pointers",
cl::desc("Number of reserved slots in function tables for functions to be added at runtime (see emscripten RESERVED_FUNCTION_POINTERS option)"),
cl::init(0));
+static cl::opt<int>
+EmscriptenAssertions("emscripten-assertions",
+ cl::desc("Additional JS-specific assertions (see emscripten ASSERTIONS)"),
+ cl::init(0));
+
extern "C" void LLVMInitializeJSBackendTarget() {
// Register the target.
RegisterTargetMachine<JSTargetMachine> X(TheJSBackendTarget);