<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/66448>66448</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`-Wuninitialized` does not take `malloc` function attribute into account
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kees
</td>
</tr>
</table>
<pre>
The `malloc` function attribute indicates that the newly allocated memory is uninitialized. This doesn't appear to be informing the `-Wuninitialized` diagnostics, though:
```
#include <stdio.h>
#include <stdlib.h>
void foo(void)
{
int *p = malloc(sizeof(*p));
printf("%d\n", *p);
}
```
Building with `-Wall`, Clang produces no warnings, but GCC does:
https://godbolt.org/z/K8Ga18KoM
It looks like the IR does know that `malloc` is `allockind("alloc,uninitialized")`, so I imagine something isn't fully wired up:
```
; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0)
memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3
...
attributes #3 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0)
memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "no-trapping-math"="true" "stack-protector-buffer-size"="8"
"target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
```
@nickdesaulniers @isanbard
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVV-v2rgT_TTmZQQKTgjhgYcCP6qq-r2sKu1j5cSTZBbHjuxxubeffuUksL1X290-LkLhmPnjmZPjsQqBOot4FLuT2F1WKnLv_PGGGFa106_HLz2CKLNBGeMaUWbQRtswOQuK2VMdGYGspkYxBuBeMXCPYPFuXmEKUowaBhycfwUKEC1ZYlKGvqPewJeeAmiHwQq5Z1DjiMoDO6hT3tb5gWw3pRRltv79TXQqR5PqrAtMTRDyDNy72P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