Index: llvm/trunk/include/llvm/IR/Function.h =================================================================== --- llvm/trunk/include/llvm/IR/Function.h +++ llvm/trunk/include/llvm/IR/Function.h @@ -710,6 +710,12 @@ 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()); } Index: llvm/trunk/unittests/IR/FunctionTest.cpp =================================================================== --- llvm/trunk/unittests/IR/FunctionTest.cpp +++ llvm/trunk/unittests/IR/FunctionTest.cpp @@ -33,6 +33,14 @@ // 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) {