[PATCH] D64925: [IR] Add getArg() method to Function class

Henry Wildermuth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 25 07:50:23 PDT 2019


hmwildermuth updated this revision to Diff 211751.
hmwildermuth added a comment.

Add test


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64925/new/

https://reviews.llvm.org/D64925

Files:
  llvm/include/llvm/IR/Function.h
  llvm/unittests/IR/FunctionTest.cpp


Index: llvm/unittests/IR/FunctionTest.cpp
===================================================================
--- llvm/unittests/IR/FunctionTest.cpp
+++ llvm/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) {
Index: llvm/include/llvm/IR/Function.h
===================================================================
--- llvm/include/llvm/IR/Function.h
+++ llvm/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<arg_iterator> args() {
     return make_range(arg_begin(), arg_end());
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64925.211751.patch
Type: text/x-patch
Size: 1092 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190725/f2dce2f7/attachment.bin>


More information about the llvm-commits mailing list