Fix Intrinsic::getType not working with vararg
authorSteven Wu <stevenwu@apple.com>
Mon, 20 Oct 2014 15:47:24 +0000 (15:47 +0000)
committerSteven Wu <stevenwu@apple.com>
Mon, 20 Oct 2014 15:47:24 +0000 (15:47 +0000)
VarArg Intrinsic functions are encoded with "void" type as the last
argument. Now Intrinsic::getType can correctly return all the intrinsic
function type.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220205 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/Function.cpp

index 83f71a891627ee63eb41d4a33b302a0b66d66061..13747cafec9c1b333e36b7252e68b78fb8018d48 100644 (file)
@@ -739,6 +739,12 @@ FunctionType *Intrinsic::getType(LLVMContext &Context,
   while (!TableRef.empty())
     ArgTys.push_back(DecodeFixedType(TableRef, Tys, Context));
 
+  // DecodeFixedType returns Void for IITDescriptor::Void and IITDescriptor::VarArg
+  // If we see void type as the type of the last argument, it is vararg intrinsic
+  if (!ArgTys.empty() && ArgTys.back()->isVoidTy()) {
+    ArgTys.pop_back();
+    return FunctionType::get(ResultTy, ArgTys, true);
+  }
   return FunctionType::get(ResultTy, ArgTys, false);
 }