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

    <tr>
        <th>Summary</th>
        <td>
            Clang fails to allow malloc attribute to accept arguments.
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          scamp-nvidia
      </td>
    </tr>
</table>

<pre>
    It appears that Clang fails to allow malloc attribute to accept arguments. 

Sample code: 

test.c:
```
typedef long unsigned int size_t;

extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size);
extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__ (reallocarray, 1)));
```

Compiling with gcc version 14.1 and NVHPC's nvc version 25.1 works fine, but building with latest clang fails.

```
 scamp@dev-sky5:~$ gcc test.c -c
 scamp@dev-sky5:~$ nvc test.c -c
 scamp@dev-sky5:~$ clang test.c -c
 test.c:5:63: error: '__malloc__' attribute takes no arguments
     5 |      __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__ (reallocarray, 1)));
 |                                                               ^
 1 error generated.
```
For reference:

```
scamp@dev-sky5:~$ clang --version
clang version 21.0.0git (https://github.com/llvm/llvm-project 557628dbe6a935b1ad5e1bcfd51ac3a65e35d874)
```


We have recently run into this error in trying to get a large weather code ported to running with Clang. 
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEVcGuqzYQ_RpnMwoyJoawYMFLG7WbqlKldomMPQH3GhvZJrfpot9eGXKTe5_Up_ZJ1UORQMPM8eHMmYkIQQ8WsSH8E-Hf7cQSR-ebIMU07-1VKy12vVO35scIYp5R-ABxFBFORtgBLkKbANGBMMa9wpRuEkSMXvdLxPWNlDhHEH5YJrQxZEBoS2j7i5hmgyCdQlK092DEEDNJivRMSnr_0TbeZlR4AePsAItdOSvQNkLQf2IXSfFpA8A_InoLV6cVENZ6XBkJ78UNCDu-xbtujp6w070cus5OOPUfIumBsHqD_h9waQvp6rqHXF2XsAg7dp11cfTudY2coOsMikvXpTJW_0PJJv4WeM8vAeRb5eNz3mtLaHty06yNtgO86jjCICVc0QftLOSHLAdhFfz06w8_nwirAtjr8zXjWQ6vzr8EuGiL6ax-idAv2qgHnhGpryCflsm2c9_TgNVz5EAVXvfh5cZJ0f5F2GFls_kC9vJLiYnXv0rciHxIfRgvJZVFciR67_xqTVY91SWseu9v8YIBrHva-62tHEh1gm_X4efxX30R_n0CyjclYECLXkRU2WedOzsPHi_o0Uq8z-7HjC83Yr-_u4nQdos83JVnNKODjumLxxjnkODZmbDzoOO49Jl0E2FnY65vt_3s3e8oI3BeleyoeixFXfA-F4pj3suL4rmQhSg5Flwdq8M2ip8NBKHtbwijuCJ4lGijuYFfbNo4DuKow10TbSH6WzJ6dDBgBAFG-AHhFUUc0a_rDWbnI6qU4hdrH2OxrtAMdqopVF3UYodNXh0oLWtW8N3YSCVoKUXVV6wqaS1y7LFnXPG6L8rygjvdMMo4ZYzmZVFwnmGOfa2qui9UKZk4kgPFSWiTJWUy54edDmHBJmdHysqdET2asK5-xlblCWPpX8A3q5T9MgRyoEaHGJ4QUUeDzdfv_93iTfPfmknYeSUeCDvfuV8b9ncAAAD__2N5GU0">