llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

MallocWithAnnotations should support annotating a realloc-like function

Open llvmbot opened this issue 13 years ago • 5 comments

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);
}

llvmbot avatar Apr 19 '13 12:04 llvmbot

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.)

belkadan avatar Apr 19 '13 18:04 belkadan

assigned to @tkremenek

llvmbot avatar Apr 19 '13 12:04 llvmbot

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.

steakhal avatar Nov 04 '26 18:11 steakhal

@benedekaibas could you have a look at this and judge if we should add a test for this?

steakhal avatar Nov 04 '26 19:11 steakhal

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.

benedekaibas avatar Nov 04 '26 22:11 benedekaibas