From f7dedf2d85bdbf354fa3b336fc2637d55b7e37ae Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 23 Apr 2008 05:36:58 +0000 Subject: [PATCH] Validate that the result of a function type is valid using shared logic with vmcore. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50138 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AsmParser/llvmAsmParser.y | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index a1abae3a625..35dad259f6b 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -1349,12 +1349,10 @@ Types | Types '(' ArgTypeListI ')' OptFuncAttrs { // Allow but ignore attributes on function types; this permits auto-upgrade. // FIXME: remove in LLVM 3.0. - const Type* RetTy = *$1; - if (!(RetTy->isFirstClassType() || RetTy == Type::VoidTy || - isa(RetTy) || - isa(RetTy))) - GEN_ERROR("LLVM Functions cannot return aggregates"); - + const Type *RetTy = *$1; + if (!FunctionType::isValidReturnType(RetTy)) + GEN_ERROR("Invalid result type for LLVM function"); + std::vector Params; TypeWithAttrsList::iterator I = $3->begin(), E = $3->end(); for (; I != E; ++I ) { @@ -2255,6 +2253,9 @@ FunctionHeaderH : OptCallingConv ResultTypes GlobalName '(' ArgList ')' if (!CurFun.isDeclare && CurModule.TypeIsUnresolved($2)) GEN_ERROR("Reference to abstract result: "+ $2->get()->getDescription()); + if (!FunctionType::isValidReturnType(*$2)) + GEN_ERROR("Invalid result type for LLVM function"); + std::vector ParamTypeList; SmallVector Attrs; if ($7 != ParamAttr::None) @@ -2648,6 +2649,10 @@ BBTerminatorInst : GEN_ERROR("Short call syntax cannot be used with varargs"); ParamTypes.push_back(Ty); } + + if (!FunctionType::isValidReturnType(*$3)) + GEN_ERROR("Invalid result type for LLVM function"); + Ty = FunctionType::get($3->get(), ParamTypes, false); PFTy = PointerType::getUnqual(Ty); } @@ -2972,6 +2977,10 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { GEN_ERROR("Short call syntax cannot be used with varargs"); ParamTypes.push_back(Ty); } + + if (!FunctionType::isValidReturnType(*$3)) + GEN_ERROR("Invalid result type for LLVM function"); + Ty = FunctionType::get($3->get(), ParamTypes, false); PFTy = PointerType::getUnqual(Ty); } -- 2.34.1