[PATCH] D14304: [IR] add bounds checking to paramHasAttr

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 4 12:36:10 PST 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL252073: [IR] Add bounds checking to paramHasAttr (authored by sanjoy).

Changed prior to commit:
  http://reviews.llvm.org/D14304?vs=39160&id=39240#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D14304

Files:
  llvm/trunk/lib/IR/Instructions.cpp
  llvm/trunk/lib/Target/X86/X86FastISel.cpp

Index: llvm/trunk/lib/IR/Instructions.cpp
===================================================================
--- llvm/trunk/lib/IR/Instructions.cpp
+++ llvm/trunk/lib/IR/Instructions.cpp
@@ -331,6 +331,8 @@
 }
 
 bool CallInst::paramHasAttr(unsigned i, Attribute::AttrKind A) const {
+  assert(i < (getNumArgOperands() + 1) && "Param index out of bounds!");
+
   if (AttributeList.hasAttribute(i, A))
     return true;
   if (const Function *F = getCalledFunction())
@@ -575,6 +577,8 @@
 }
 
 bool InvokeInst::paramHasAttr(unsigned i, Attribute::AttrKind A) const {
+  assert(i < (getNumArgOperands() + 1) && "Param index out of bounds!");
+
   if (AttributeList.hasAttribute(i, A))
     return true;
   if (const Function *F = getCalledFunction())
Index: llvm/trunk/lib/Target/X86/X86FastISel.cpp
===================================================================
--- llvm/trunk/lib/Target/X86/X86FastISel.cpp
+++ llvm/trunk/lib/Target/X86/X86FastISel.cpp
@@ -2817,10 +2817,12 @@
   if (CC == CallingConv::Fast || CC == CallingConv::GHC ||
       CC == CallingConv::HiPE)
     return 0;
-  if (CS && !CS->paramHasAttr(1, Attribute::StructRet))
-    return 0;
-  if (CS && CS->paramHasAttr(1, Attribute::InReg))
-    return 0;
+
+  if (CS)
+    if (CS->arg_empty() || !CS->paramHasAttr(1, Attribute::StructRet) ||
+        CS->paramHasAttr(1, Attribute::InReg))
+      return 0;
+
   return 4;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14304.39240.patch
Type: text/x-patch
Size: 1401 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151104/49e9e52a/attachment.bin>


More information about the llvm-commits mailing list