Check return types of functions


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10146 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y
index 8e44501..ca2924b 100644
--- a/lib/AsmParser/llvmAsmParser.y
+++ b/lib/AsmParser/llvmAsmParser.y
@@ -1395,6 +1395,9 @@
   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();
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index 9a4ac67..b558672 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -95,6 +95,9 @@
   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 &&
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index 1d441d1..98288f4 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -241,6 +241,9 @@
   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;