Fix `insertFunctionArguments()` block argument order.
authorChristian Sigg <csigg@google.com>
Thu, 4 Nov 2021 08:05:53 +0000 (09:05 +0100)
committerChristian Sigg <csigg@google.com>
Fri, 5 Nov 2021 09:08:20 +0000 (10:08 +0100)
Reviewed By: rriddle

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

mlir/lib/IR/FunctionSupport.cpp
mlir/test/IR/test-func-insert-arg.mlir

index 4f6f76c..d67d277 100644 (file)
@@ -164,7 +164,7 @@ void mlir::function_like_impl::insertFunctionArguments(
   // Update the function type and any entry block arguments.
   op->setAttr(getTypeAttrName(), TypeAttr::get(newType));
   for (unsigned i = 0, e = argIndices.size(); i < e; ++i)
-    entry.insertArgument(argIndices[i], argTypes[i],
+    entry.insertArgument(argIndices[i] + i, argTypes[i],
                          argLocs.empty() ? Optional<Location>{} : argLocs[i]);
 }
 
index 2de6c66..61308a1 100644 (file)
@@ -1,49 +1,49 @@
 // RUN: mlir-opt %s -test-func-insert-arg -split-input-file | FileCheck %s
 
-// CHECK: func @f(%arg0: f32 {test.A})
+// CHECK: func @f(%arg0: i1 {test.A})
 func @f() attributes {test.insert_args = [
-  [0, f32, {test.A}]]} {
+  [0, i1, {test.A}]]} {
   return
 }
 
 // -----
 
-// CHECK: func @f(%arg0: f32 {test.A}, %arg1: f32 {test.B})
-func @f(%arg0: f32 {test.B}) attributes {test.insert_args = [
-  [0, f32, {test.A}]]} {
+// CHECK: func @f(%arg0: i1 {test.A}, %arg1: i2 {test.B})
+func @f(%arg0: i2 {test.B}) attributes {test.insert_args = [
+  [0, i1, {test.A}]]} {
   return
 }
 
 // -----
 
-// CHECK: func @f(%arg0: f32 {test.A}, %arg1: f32 {test.B})
-func @f(%arg0: f32 {test.A}) attributes {test.insert_args = [
-  [1, f32, {test.B}]]} {
+// CHECK: func @f(%arg0: i1 {test.A}, %arg1: i2 {test.B})
+func @f(%arg0: i1 {test.A}) attributes {test.insert_args = [
+  [1, i2, {test.B}]]} {
   return
 }
 
 // -----
 
-// CHECK: func @f(%arg0: f32 {test.A}, %arg1: f32 {test.B}, %arg2: f32 {test.C})
-func @f(%arg0: f32 {test.A}, %arg1: f32 {test.C}) attributes {test.insert_args = [
-  [1, f32, {test.B}]]} {
+// CHECK: func @f(%arg0: i1 {test.A}, %arg1: i2 {test.B}, %arg2: i3 {test.C})
+func @f(%arg0: i1 {test.A}, %arg1: i3 {test.C}) attributes {test.insert_args = [
+  [1, i2, {test.B}]]} {
   return
 }
 
 // -----
 
-// CHECK: func @f(%arg0: f32 {test.A}, %arg1: f32 {test.B}, %arg2: f32 {test.C})
-func @f(%arg0: f32 {test.B}) attributes {test.insert_args = [
-  [0, f32, {test.A}],
-  [1, f32, {test.C}]]} {
+// CHECK: func @f(%arg0: i1 {test.A}, %arg1: i2 {test.B}, %arg2: i3 {test.C})
+func @f(%arg0: i2 {test.B}) attributes {test.insert_args = [
+  [0, i1, {test.A}],
+  [1, i3, {test.C}]]} {
   return
 }
 
 // -----
 
-// CHECK: func @f(%arg0: f32 {test.A}, %arg1: f32 {test.B}, %arg2: f32 {test.C})
-func @f(%arg0: f32 {test.C}) attributes {test.insert_args = [
-  [0, f32, {test.A}],
-  [0, f32, {test.B}]]} {
+// CHECK: func @f(%arg0: i1 {test.A}, %arg1: i2 {test.B}, %arg2: i3 {test.C})
+func @f(%arg0: i3 {test.C}) attributes {test.insert_args = [
+  [0, i1, {test.A}],
+  [0, i2, {test.B}]]} {
   return
 }