[llvm] r367576 - [IR] Add getArg() method to Function class

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 1 08:31:41 PDT 2019


Author: tejohnson
Date: Thu Aug  1 08:31:40 2019
New Revision: 367576

URL: http://llvm.org/viewvc/llvm-project?rev=367576&view=rev
Log:
[IR] Add getArg() method to Function class

Adds a method which, when called with function.getArg(i), returns an
Argument* to the i'th argument.

Patch by Henry Wildermuth

Differential Revision: https://reviews.llvm.org/D64925

Modified:
    llvm/trunk/include/llvm/IR/Function.h
    llvm/trunk/unittests/IR/FunctionTest.cpp

Modified: llvm/trunk/include/llvm/IR/Function.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Function.h?rev=367576&r1=367575&r2=367576&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Function.h (original)
+++ llvm/trunk/include/llvm/IR/Function.h Thu Aug  1 08:31:40 2019
@@ -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<arg_iterator> args() {
     return make_range(arg_begin(), arg_end());
   }

Modified: llvm/trunk/unittests/IR/FunctionTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/FunctionTest.cpp?rev=367576&r1=367575&r2=367576&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/FunctionTest.cpp (original)
+++ llvm/trunk/unittests/IR/FunctionTest.cpp Thu Aug  1 08:31:40 2019
@@ -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) {




More information about the llvm-commits mailing list