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

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 12 06:02:58 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Sebastian Neubauer (Flakebi)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/68887.diff


1 Files Affected:

- (modified) llvm/include/llvm/IR/DerivedTypes.h (+4-1) 


``````````diff
diff --git a/llvm/include/llvm/IR/DerivedTypes.h b/llvm/include/llvm/IR/DerivedTypes.h
index 203a73067edc7b0..2a81f9b999ce8d6 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.

``````````

</details>


https://github.com/llvm/llvm-project/pull/68887


More information about the llvm-commits mailing list