<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJzFVVtvq0YQ_jX4ZWQLQxzHD37I5Vi1lKNWzdHpY7XAANvALtpLHPrrO7MQcJycqlUfKiFgdy478803s5ku-v0xSrYtKO3AeoMgS3C1tECPgMxXUXIP2oB0pGYBXzvMHRaQYS1eJAmEKqDtQarOOzj-ynbsS3Sd0Z2RwuEqih-i-HZ4P_mu0xbhCGSPdBRCqZtGn6SqgrkCh9at2kaa0e46Hp-wbHXhG4RoezesAUqvcoiu4lZIFSU3UbIRpoqj9BZabA2WUXq_fpVpEqVf2Cy451e0feDkBv31O_3ktQz6UbKDZbBLbibhLDoLAthPDFH6MHpZCcoqD_GQ4rnz0X4yNOi8UW_2P1TkcD8DZHhzGY5gvPocNEJzqTs3YwvLZa7VCxq3tK5YOr1smpeWwsdWumW-PBmqIBr7qbsjVOguaofG6M8rRsRh3yuuE_2D7kYaEcNM5VtURBfnjMy8Q9oyogcyJtnvvG3pH5ye-WJFi6B8m6EBXQI2yC7ImQ3iWcIHOqnVdIzlelfEzoR_6LiZz-nfYPu1h7rvNDm3Q2O4WgzpX4Y5pzG2QYaMje8K6oMiSg6WcMu1MXRo08OpRgW5QeFYix3ewwj8FPwK4Dc6LnRfzSLFuudBXFoE1SllOk5R2PSjy6DuFUMyLrSRlVSimYzt2MmzPTOLVUeaTgIK7ElfIH52ai1Uhaz0kz4h8YwRF6UjPZoKKiRsNRXSOl9SqWiSFEjjpgrZKUaW8zpo8-WVjCjEe2ooHGCmrqqd6yx1C2FKTyVd7bNVrltaBCIPnyUNoT8Ia1pmjc7oMwyJQxgvpCN57z40gg3QHZ4cJSxM8U0_Pn7_-mFjlXddlKSP25T7-kiB-4DPWIt3UAQ62JDbmA6V6UBA_9xxFtLOdCbu0lb5JmOwAjlYoaHqEfqUfg-21r4phl6QiqljibyEl5V_IneJE88soT-R5xTbGBaePtSVwGKsS6Pb8_r-iBjvpvgddUKBdiolx8v3yAuOgFge88aF3MN1ctZAWQ8Etyz7gfTCjUfzknqm5u9Jm2dCTiqiN9WWwbkcTFOP_s_3w7tLYMjkw8gGuJygA1iisXoAQ-LIIp4afLUSCEKdDRRGMjTMXEE5IuS0pvqrHCfaCNVPBAzmPBCQyoWWLFkN287153Ke6KIoOAw9jCjbaRVW84lcC-3PxrV9R4tbOpYVqppGbXoA-EZT4JlHCrl-ERThalHs02KX7sRCeFI1e2tyGvl0jSy8afb_uq2ltR5prh826SZOF_Ues43I1uIm22bXYpOur9J1sRUi3l1vrrY3BS4akWFj99HmLto8LP77kXKfxEkSr9M1v5Kr1XqzwV2GcZ5td0UW50Q9JO41q3ALalMtzD64pHFnScj9bWehsFZWCvEtQiddg_tfNG1nRGwyGmrsLXPkH13ig8F0Hdbis5vXLkJi-5DVX6--UNI>53503</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Possible bug when using convert-std-to-llvm=emit-c-wrappers when function has argument attributes
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          srcarroll
      </td>
    </tr>
</table>

<pre>
    I'm not sure if this is a bug, or it's expected behavior and my input IR is not appropriate.

Suppose I have the following IR in test.mlir
```
module {
  func @main(%arg0: memref<1xi32> {test.test}, %arg1: memref<2xf32>) -> (memref<f32>) {
    %0 = memref.alloc() : memref<f32>
    return %0 : memref<f32>
  }
```

and I run
```
mlir-opt test.mlir --convert-std-to-llvm=emit-c-wrappers
```
I get the following error
```
'llvm.func' op expects argument attribute array `arg_attrs` to have the same number of elements as the number of function arguments, got 2, but expected 3
```

My hypothesis is that the `arg_attrs` attribute is not being updated/set correctly when creating the C wrapper function.  What's happening is that the wrapper function's arguments consists of the union of the original functions input arguments and the return arguments.  So the number of arguments changes.  However, after printing some stuff for debugging in `wrapForExternalCallers` (https://github.com/llvm/llvm-project/blob/main/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp#L73) I found that the number of arg attrs for `wrapperFuncOp` is the same as `funcOp`, when the list really should have increased in size to take into account the new input arguments coming from the return of the original function.

Besides printing, I've found support for this hypothesis by verifying that returning nothing works fine with `emit-c-wrappers`
```
module {
  func @main(%arg0: memref<1xi32> {test.test}, %arg1: memref<2xf32>) {
    return
  }
  ```
I've also verified that not having an attribute for some arguments is fine too since, when any arg attributes are present, empty attributes get added to correspond to arguments without attributes.

Any thoughts?  Thanks in advance.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFVU1v4zYQ_TXyhbAhS3EcH3zIxxo1kEWLZtEeC0oaSWwkUiCpOO6v7xtKkR0nW-yeCggSqfngzJs3w8wUx-0-Stat0MYL11sSqhS-Vk7gkSLrqyi5F8YK5aHmBL12lHsqREa1fFEQSF2I9iiU7nov9r-zHfuSXWdNZ5X0tIjihyi-Hd5PfdcZR2IvYE84ikRpmsYclK6CuRaenF-0jbKj3XU8PmHbmqJvSETru2EvRNnrXERXcSuVjpKbKFlJW8VReitaai2VUXq_fFVpEqVf2Cy451e0fuDkBv3lO_3ktQz6UbIR82CX3EzCk-gsCMF-YhGlD6OXhURWeYgHiufOR_vJ0JLvrX6z_64ih_sZIMOby7AXttefgwY056bzJ2zFfJ4b_ULWz50v5t7Mm-alRfjUKj_P5weLCpJ1n7rbi4r8Re3IWvN5xUAc9r3gOmEtTDfSCAyzVd-SBl28tyrrPeGXlUcBY8j-4t8Oa-HNiS9OtiR032ZkhSkFNcQu4MwF8UnCB3pl9HSM43pXYGfCCxx34nP6H9h-PYr62Bk4d0Nj-FoO6V-GeUpjbIOMGJu-K9AHRZTsHHDLjbU4tDmKQ01a5JakZy12eC9G4KfgF0L8ieNC99Us0qx7HsSlRVCdUsZxGmFjYcqg3muGZNwYqyqlZTMZu7GTT_bMLFYdaToJENiTuUD87NRa6opY6RdzIPCMEZelhx6mgg4JO4NCOt-XKBUmSUEYN1XITjOynNfO2C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