[llvm-commits] CVS: llvm/lib/ExecutionEngine/ExecutionEngine.cpp
Anton Korobeynikov
asl at math.spbu.ru
Sun Jun 3 12:18:02 PDT 2007
Changes in directory llvm/lib/ExecutionEngine:
ExecutionEngine.cpp updated: 1.115 -> 1.116
---
Log message:
Check arguments & return types of main(). Abort in case of no match.
---
Diffs of the changes: (+32 -0)
ExecutionEngine.cpp | 32 ++++++++++++++++++++++++++++++++
1 files changed, 32 insertions(+)
Index: llvm/lib/ExecutionEngine/ExecutionEngine.cpp
diff -u llvm/lib/ExecutionEngine/ExecutionEngine.cpp:1.115 llvm/lib/ExecutionEngine/ExecutionEngine.cpp:1.116
--- llvm/lib/ExecutionEngine/ExecutionEngine.cpp:1.115 Thu May 24 10:03:18 2007
+++ llvm/lib/ExecutionEngine/ExecutionEngine.cpp Sun Jun 3 14:17:35 2007
@@ -231,7 +231,39 @@
std::vector<GenericValue> GVArgs;
GenericValue GVArgc;
GVArgc.IntVal = APInt(32, argv.size());
+
+ // Check main() type
unsigned NumArgs = Fn->getFunctionType()->getNumParams();
+ const FunctionType *FTy = Fn->getFunctionType();
+ const Type* PPInt8Ty = PointerType::get(PointerType::get(Type::Int8Ty));
+ switch (NumArgs) {
+ case 3:
+ if (FTy->getParamType(2) != PPInt8Ty) {
+ cerr << "Invalid type for third argument of main() supplied\n";
+ abort();
+ }
+ case 2:
+ if (FTy->getParamType(1) != PPInt8Ty) {
+ cerr << "Invalid type for second argument of main() supplied\n";
+ abort();
+ }
+ case 1:
+ if (FTy->getParamType(0) != Type::Int32Ty) {
+ cerr << "Invalid type for first argument of main() supplied\n";
+ abort();
+ }
+ case 0:
+ if (FTy->getReturnType() != Type::Int32Ty &&
+ FTy->getReturnType() != Type::VoidTy) {
+ cerr << "Invalid return type of main() supplied\n";
+ abort();
+ }
+ break;
+ default:
+ cerr << "Invalid number of arguments of main() supplied\n";
+ abort();
+ }
+
if (NumArgs) {
GVArgs.push_back(GVArgc); // Arg #0 = argc.
if (NumArgs > 1) {
More information about the llvm-commits
mailing list