Issue 128026
Summary Clang fails to allow malloc attribute to accept arguments.
Labels clang
Assignees
Reporter scamp-nvidia
    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. 
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to