<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/92421>92421</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Intrinsic LEN and C_SIZEOF returns incorrect result when the argument is a CFI_CDESC_T descriptor of character type.
        </td>
    </tr>

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

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

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

<pre>
    Consider the following code:
```
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "ISO_Fortran_binding.h"
void sub(CFI_cdesc_t* a);
int main()
{
 int rc;
    char *p = "12345";
    CFI_cdesc_t* a;
 CFI_CDESC_T(1) at1;
    a = (CFI_cdesc_t *) &at1;

    rc = CFI_establish(a, p, CFI_attribute_pointer, CFI_type_signed_char, 5, 0, 0);
    assert(rc == CFI_SUCCESS);
 sub(a);
}
```

Fortran subroutine `sub` is as:
```
 subroutine sub(c_arg2) bind(c)
        use, intrinsic :: iso_c_binding
 character(*) :: c_arg2!(*)
        print*, "LEN(c_arg2)=", LEN(c_arg2)
        print*, "c_sizeof(c_arg2)=", c_sizeof(c_arg2)
 end
```

The expected result is
```
 LEN(c_arg2)= 5
 c_sizeof(c_arg2)= 5
```

But Flang currently outputs
```
 LEN(c_arg2)= 1
 c_sizeof(c_arg2)= 1
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVE2P2zgM_TXyhWhg0x9xDj5knBgYoGgP6V72YsgSE2vhSIYktzv76xeyk0zSZrobBAqiR_KRjxS5c-qkiSqWv7B8F_HJ98ZWO64VDXXdk446I9-q2minJFnwPcHRDIP5ofQJhJHE0i2LdyzesiK-fJe_mCothkkSsLR2Xiqz6lm6f45apU8fwtw5sv4DGPH18LVtjPWW67ZTWi6hEBfb70ZJcFPHsKyb11ZIcqL1DLfAGW5Y-rKYKe3hzJVmWIbrhWZ9ASGgVtyMAQBEzy0w3I7A0l1II8E0ywPtvdUvlDcwIPVuf6jbbwzLhOEGuE8enPkl9H3igTLYMizuzd-drJi9ggs5z7tBuZ5hyRnWMIYjINx7q7rJUzsapT3ZK-DfRmrnmZBtqDDc5-GIL8fmMcO5MwzLhfVKfPijrveHw4P10oIHzdl693x05vPS0uBozeSVJmBFHMIUMSgH3H00evcuC61ouT1h0C0MSLi4NRkun8lRKFHpMItOhXq2LN2CcqYV17m6uARluJhlK6_9WKyvRMkNeWQZrdJ-BuowM5_3X-6zCxIiBuxn4HdBROvUP2SOzyM9RZdwpOVv9P_WE9DfIwlPEiy5afCg3HPBf60D8qtWz7O74k-pXyYPzcDDhpmsJe2HNzCTHyf___mT_-BPfooUySqVm3TDI6qSdZKX67zYrKO-KmWWdznPBObiWMgulgWtu7IQJI8Fii5SFcaYxXlSJEVcJuvVGnOOdMw2XMosizOWxXTmalgNw_fzythTpJybqNpghkk08I4GN29gxGOoOnQu30W2CvafuunkWBYPynn3HsErP8xre9aJ5Tt4vU3u5_0X4FpC3R5e_9x_bcCSn6x2oLQw1pLw137-6EnPO53b03Qm7eeHdb-bIKwdq0ZvLJjj--RD2BSraLJD1Xs_zm8RG4bNSfl-6lbCnBk2Id3Lz6fRmr9IeIbNXL1j2MwC_BsAAP__zEbXnw">