Open kees opened 12 months ago
Hm, it's not a false positive, it's a false negative. :)
& generally clang's diagnostics can't handle dynamic/indirect memory like this - so I wouldn't expect this to be covered by a compiler warning - /maybe/ by a static analysis tool, but even then, that's going to be challenging.
So, can we compromise to warning just for malloc
? I think malloc
is a special function.
Is easy to impl? Maybe I can do it.
It's not so much a question of special casing malloc, but tracking memory that's pointed to by a pointer. That's outside the scope of the sort of analysis we can do at compile time.
The
malloc
function attribute indicates that the newly allocated memory is uninitialized. This doesn't appear to be informing the-Wuninitialized
diagnostics, though:Building with
-Wall
, Clang produces no warnings, but GCC does:https://godbolt.org/z/K8Ga18KoM
It looks like the IR does know that
malloc
isallockind("alloc,uninitialized")
, so I imagine something isn't fully wired up:@nickdesaulniers @isanbard