diff --git a/include/llvm/IR/Function.h b/include/llvm/IR/Function.h index 7fa61e12f43..cee8d6c973f 100644 --- a/include/llvm/IR/Function.h +++ b/include/llvm/IR/Function.h @@ -710,6 +710,12 @@ public: return Arguments + NumArgs; } + Argument* getArg(unsigned i) const { + assert (i < NumArgs && "getArg() out of range!"); + CheckLazyArguments(); + return Arguments + i; + } + iterator_range args() { return make_range(arg_begin(), arg_end()); } diff --git a/unittests/IR/FunctionTest.cpp b/unittests/IR/FunctionTest.cpp index 6f3e8f9beb1..b5662d2ca99 100644 --- a/unittests/IR/FunctionTest.cpp +++ b/unittests/IR/FunctionTest.cpp @@ -33,6 +33,14 @@ TEST(FunctionTest, hasLazyArguments) { // The argument list should be populated at first access. (void)F->arg_begin(); EXPECT_FALSE(F->hasLazyArguments()); + + // Checking that getArg gets the arguments from F1 in the correct order. + unsigned i = 0; + for (Argument &A : F->args()) { + EXPECT_EQ(&A, F->getArg(i)); + ++i; + } + EXPECT_FALSE(F->hasLazyArguments()); } TEST(FunctionTest, stealArgumentListFrom) {