Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit def4393

Browse files
committed
check argument and return types statically
1 parent a34c981 commit def4393

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/Target/JSBackend/CallHandlers.h

+18-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,24 @@ DEF_CALL_HANDLER(__default__, {
5353
errs().resetColor();
5454
errs() << " unexpected number of arguments " << utostr(ActualNumArgs) << " in call to '" << F->getName() << "', should be " << utostr(TypeNumArgs) << "\n";
5555
}
56-
// TODO: also check types of arguments, but must take into account JS types, not LLVM types
56+
for (unsigned i = 0; i < std::min(TypeNumArgs, ActualNumArgs); i++) {
57+
Type *TypeType = FT->getParamType(i);
58+
Type *ActualType = CI->getOperand(i)->getType();
59+
if (getFunctionSignatureLetter(TypeType) != getFunctionSignatureLetter(ActualType)) {
60+
errs().changeColor(raw_ostream::YELLOW);
61+
errs() << "warning:";
62+
errs().resetColor();
63+
errs() << " unexpected argument type " << *ActualType << " at index " << utostr(i) << " in call to '" << F->getName() << "', should be " << *TypeType << "\n";
64+
}
65+
}
66+
Type *TypeType = FT->getReturnType();
67+
Type *ActualType = CI->getType();
68+
if (getFunctionSignatureLetter(TypeType) != getFunctionSignatureLetter(ActualType)) {
69+
errs().changeColor(raw_ostream::YELLOW);
70+
errs() << "warning:";
71+
errs().resetColor();
72+
errs() << " unexpected return type " << *ActualType << " in call to '" << F->getName() << "', should be " << *TypeType << "\n";
73+
}
5774
}
5875
} else {
5976
if (isAbsolute(CV)) return "abort(); /* segfault, call an absolute addr */";

0 commit comments

Comments
 (0)