diff options
author | Anton Korobeynikov <asl@math.spbu.ru> | 2007-06-03 19:17:35 +0000 |
---|---|---|
committer | Anton Korobeynikov <asl@math.spbu.ru> | 2007-06-03 19:17:35 +0000 |
commit | 8c32c1114fcd028874012d14b73fa6598c39ce4c (patch) | |
tree | 98fcd50a0f79737471677bb1bf82abd1cbc71b09 /llvm/lib/ExecutionEngine | |
parent | 0e8aa7b69af557c7c3dda7b5e3c5ec32b63fc311 (diff) | |
download | bcm5719-llvm-8c32c1114fcd028874012d14b73fa6598c39ce4c.tar.gz bcm5719-llvm-8c32c1114fcd028874012d14b73fa6598c39ce4c.zip |
Check arguments & return types of main(). Abort in case of no match.
llvm-svn: 37404
Diffstat (limited to 'llvm/lib/ExecutionEngine')
-rw-r--r-- | llvm/lib/ExecutionEngine/ExecutionEngine.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp index d67fbb2ce60..36582ee2ed9 100644 --- a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp @@ -231,7 +231,39 @@ int ExecutionEngine::runFunctionAsMain(Function *Fn, 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) { |