MallocWithAnnotations should support annotating a realloc-like function
| Bugzilla Link | 15790 |
| Version | trunk |
| OS | Linux |
| Reporter | LLVM Bugzilla Contributor |
| CC | @belkadan |
Extended Description
I'd expect something like the following to be possible (wrapping realloc). It seems not to work.
#include <stdlib.h>
void *my_realloc(void *ptr, size_t size)
__attribute__((ownership_takes(malloc,1)))
__attribute__((ownership_returns(malloc,2)));
void
test()
{
void *ptr = malloc(10);
ptr = my_realloc(ptr, 11);
free(ptr);
}
Specifically, unix.MismatchedDeallocator doesn't recognize the ownership attributes, though there may be other problems. (From a brief code inspection, it looks like having two attributes will actually bifurcate the state rather than applying one effect after the other. This could be checked using the alpha bounds checker.)
assigned to @tkremenek
No longer reproduces. Bisects to 9fd7ce7f4449619bc85ab4d2643e656836a2d5e2 NFC commit.
It's not NFC because it adds a NE->isArray() guard condition for processNewAllocation. The following code should demonstrate the behavior change, as before the linked change it reports, and after it does not.
This commit didn't fix this issue. Needs further investigation.
@benedekaibas could you have a look at this and judge if we should add a test for this?
5. @benedekaibas could you have a look at this and judge if we should add a test for this?
Thanks for asking! Yes, we should add a test/tests for this. This is not covered in any of the existing test files. malloc-annotations have similar cases, but none of them cover this case.