[llvm] 7603c77 - [IR][NFC] Assert that FunctionType::getParamType is in-bounds (#68887)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 12 07:26:54 PDT 2023


Author: Sebastian Neubauer
Date: 2023-10-12T16:26:48+02:00
New Revision: 7603c77f23767b97a587914d33a44061d8b7f9a7

URL: https://github.com/llvm/llvm-project/commit/7603c77f23767b97a587914d33a44061d8b7f9a7
DIFF: https://github.com/llvm/llvm-project/commit/7603c77f23767b97a587914d33a44061d8b7f9a7.diff

LOG: [IR][NFC] Assert that FunctionType::getParamType is in-bounds (#68887)

Like for Function::getArg, assert that the fetched argument is in-range
and not out-of-bounds.

Added: 
    

Modified: 
    llvm/include/llvm/IR/DerivedTypes.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/DerivedTypes.h b/llvm/include/llvm/IR/DerivedTypes.h
index 203a73067edc7b0..f7a09fda8ccb7ba 100644
--- a/llvm/include/llvm/IR/DerivedTypes.h
+++ b/llvm/include/llvm/IR/DerivedTypes.h
@@ -132,7 +132,10 @@ class FunctionType : public Type {
   }
 
   /// Parameter type accessors.
-  Type *getParamType(unsigned i) const { return ContainedTys[i+1]; }
+  Type *getParamType(unsigned i) const {
+    assert(i < getNumParams() && "getParamType() out of range!");
+    return ContainedTys[i + 1];
+  }
 
   /// Return the number of fixed parameters this function type requires.
   /// This does not consider varargs.


        


More information about the llvm-commits mailing list