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

Sebastian Neubauer via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 12 06:04:34 PDT 2023


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

>From 6a08d8c2c7ac2ad2ab138bae1ead58bf3937eda1 Mon Sep 17 00:00:00 2001
From: Sebastian Neubauer <Sebastian.Neubauer at amd.com>
Date: Thu, 12 Oct 2023 15:04:16 +0200
Subject: [PATCH] [IR][NFC] Assert that FunctionType::getParamType is in-bounds

Like for Function::getArg, assert that the fetched argument is in-range
and not out-of-bounds.
---
 llvm/include/llvm/IR/DerivedTypes.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

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