https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117315

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #18 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Sam James from comment #14)
> Looking at this again, wmem_tree_new_autoreset has __attribute__((malloc))
> which promises that the memory returned isn't aliased by anything else
> ("fresh").
> 
> In wmem_test_tree, we birth 'tree' with wmem_tree_new_autoreset, but tree is
> a pointer to freshly allocated memory, while tree->data_allocator is a
> pointer to one of its arguments. I think we assume it can't be null as a
> result later on which is why -fno-delete-null-pointer-checks works.
> 
> Is this like a 'lifetime-dse' thing? Is it legal for wmem_tree_new_autoreset
> to modify 'tree' before it's returned like that for the malloc attribute?

Nope.  That's invalid.  The docs are quite explicit:

Attribute @code{malloc} indicates that a function is @code{malloc}-like,
i.e., that the pointer @var{P} returned by the function cannot alias any
other pointer valid when the function returns, <em>and moreover no
pointers to valid objects occur in any storage addressed by @var{P}</em>.

Clearly

wmem_tree_t *wmem_tree_new_autoreset(wmem_allocator_t *metadata_scope,
                                     wmem_allocator_t *data_scope) {
  wmem_tree_t *tree = __builtin_memset(
      wmem_alloc(metadata_scope, sizeof(wmem_tree_t)), 0, sizeof(wmem_tree_t));
  if (!tree) {
    __builtin_abort();
  }

  tree->data_allocator = data_scope;
  wmem_register_callback(data_scope, wmem_tree_reset_cb, tree);
  return tree;
}

is not suitable for 'malloc' and GCC assumes that the returned 'tree' does
_not_ point to storage referencing 'data_scope'.

Reply via email to