Check return types of functions
authorChris Lattner <sabre@nondot.org>
Fri, 21 Nov 2003 22:32:23 +0000 (22:32 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 21 Nov 2003 22:32:23 +0000 (22:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10146 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AsmParser/llvmAsmParser.y
lib/VMCore/Function.cpp
lib/VMCore/Verifier.cpp

index 8e4450138e841b9298bf842a905b897993917bf3..ca2924bb49856c59cbade20e0446ff51ca207a42 100644 (file)
@@ -1395,6 +1395,9 @@ FunctionHeaderH : TypesV Name '(' ArgList ')' {
   UnEscapeLexed($2);
   std::string FunctionName($2);
   
+  if (!(*$1)->isFirstClassType() && *$1 != Type::VoidTy)
+    ThrowException("LLVM functions cannot return aggregate types!");
+
   std::vector<const Type*> ParamTypeList;
   if ($4) {   // If there are arguments...
     for (std::vector<std::pair<PATypeHolder*,char*> >::iterator I = $4->begin();
index 9a4ac6711ccb3f299d0c4faf21183a3781ed74fc..b5586721e8584ce7ba3ccaf5312dd5b9db96c942 100644 (file)
@@ -95,6 +95,9 @@ Function::Function(const FunctionType *Ty, LinkageTypes Linkage,
   ArgumentList.setParent(this);
   SymTab = new SymbolTable();
 
+  assert((getReturnType()->isFirstClassType() ||getReturnType() == Type::VoidTy)
+         && "LLVM functions cannot return aggregate values!");
+
   // Create the arguments vector, all arguments start out unnamed.
   for (unsigned i = 0, e = Ty->getNumParams(); i != e; ++i) {
     assert(Ty->getParamType(i) != Type::VoidTy &&
index 1d441d1dd5eccf0b9dbff4742a4096477dd76177..98288f414271ca7d9cb6c1509f3a9af7cfcdca02 100644 (file)
@@ -241,6 +241,9 @@ void Verifier::visitFunction(Function &F) {
   Assert2(FT->getNumParams() == NumArgs,
           "# formal arguments must match # of arguments for function type!",
           &F, FT);
+  Assert1(F.getReturnType()->isFirstClassType() ||
+          F.getReturnType() == Type::VoidTy,
+          "Functions cannot return aggregate values!", &F);
 
   // Check that the argument values match the function type for this function...
   unsigned i = 0;