aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ExecutionEngine/ExecutionEngine.cpp
diff options
context:
space:
mode:
authorAnton Korobeynikov <asl@math.spbu.ru>2007-06-03 19:17:35 +0000
committerAnton Korobeynikov <asl@math.spbu.ru>2007-06-03 19:17:35 +0000
commit499d8f0c3b212819515cdbcb98146fff6f9d877b (patch)
treec33ea8bfca1687b3a14a44ea49ace4392aceaa23 /lib/ExecutionEngine/ExecutionEngine.cpp
parentbec7647f985d54d2be2100e3813b85267cf1fe49 (diff)
downloadexternal_llvm-499d8f0c3b212819515cdbcb98146fff6f9d877b.zip
external_llvm-499d8f0c3b212819515cdbcb98146fff6f9d877b.tar.gz
external_llvm-499d8f0c3b212819515cdbcb98146fff6f9d877b.tar.bz2
Check arguments & return types of main(). Abort in case of no match.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37404 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/ExecutionEngine.cpp')
-rw-r--r--lib/ExecutionEngine/ExecutionEngine.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp
index d67fbb2..36582ee 100644
--- a/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/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) {