public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/101829] New: problems with inline + __attribute__ ((malloc (deallocator)))
@ 2021-08-09 10:33 eggert at cs dot ucla.edu
  2021-08-09 12:52 ` [Bug middle-end/101829] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: eggert at cs dot ucla.edu @ 2021-08-09 10:33 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101829
           Summary: problems with inline + __attribute__ ((malloc
                    (deallocator)))
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at cs dot ucla.edu
  Target Milestone: ---

We've recently started using __attribute__ ((malloc (deallocator))) with Gnulib
and ran into the problem that the GCC documentation in doc/extend.texi says
this:

"Since inlining one of the associated functions but not the other could result
in apparent mismatches, this form of attribute @code{malloc} is not accepted on
inline functions."

This has caused problems for us, as many of our functions are naturally inline
and are allocators or deallocators. As Bruno Haible wrote in
<https://lists.gnu.org/r/bug-gnulib/2021-08/msg00092.html>:

"The GCC documentation [1] says that the attribute 'malloc (deallocator, 1)'
does not work on inline functions. IMO, this restriction is not tenable in the
long run (because the semantics of a function don't depend on whether it is
inline or not, and because in C++ the majority of all functions is inline)."


We have resorted to merely adding comments to the functions in question. It
would be better if we could add the attributes, and then GCC can ignore them
when applied to inline functions. Alternatively, GCC could refuse to inline
such functions. Either would be preferable to the current situation.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/101829] problems with inline + __attribute__ ((malloc (deallocator)))
  2021-08-09 10:33 [Bug middle-end/101829] New: problems with inline + __attribute__ ((malloc (deallocator))) eggert at cs dot ucla.edu
@ 2021-08-09 12:52 ` rguenth at gcc dot gnu.org
  2021-08-09 15:58 ` hubicka at ucw dot cz
  2021-08-12 20:32 ` msebor at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-08-09 12:52 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmalcolm at gcc dot gnu.org,
                   |                            |msebor at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-08-09

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
It might be possible to inline such functions by creating a "stub" call either
after or before the inlined function body where the "stub" would just be there
to represent the attributes.

Say, inline a 'deallocator' fn

  my_free (x);

as

  <inlined impl>
  .IFN_STUB_DEALLOCATE (x);

or sth like that where those stubs are removed after any diagnostics with
regard to pairing of malloc/free have been issued (not sure where that
currently
happens).

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/101829] problems with inline + __attribute__ ((malloc (deallocator)))
  2021-08-09 10:33 [Bug middle-end/101829] New: problems with inline + __attribute__ ((malloc (deallocator))) eggert at cs dot ucla.edu
  2021-08-09 12:52 ` [Bug middle-end/101829] " rguenth at gcc dot gnu.org
@ 2021-08-09 15:58 ` hubicka at ucw dot cz
  2021-08-12 20:32 ` msebor at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: hubicka at ucw dot cz @ 2021-08-09 15:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jan Hubicka <hubicka at ucw dot cz> ---
> It might be possible to inline such functions by creating a "stub" call either
> after or before the inlined function body where the "stub" would just be there
> to represent the attributes.
> 
> Say, inline a 'deallocator' fn
> 
>   my_free (x);
> 
> as
> 
>   <inlined impl>
>   .IFN_STUB_DEALLOCATE (x);
> 
> or sth like that where those stubs are removed after any diagnostics with
> regard to pairing of malloc/free have been issued (not sure where that
> currently
> happens).

We have similar issue with functions calling alloca (that we may inline
if was able to insert stack restore).  I was always lazy to implement
this since we need to also insert it on the EH cleanup edges, but
perhaps it is time to learn inliner about such tricks...

Honza

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/101829] problems with inline + __attribute__ ((malloc (deallocator)))
  2021-08-09 10:33 [Bug middle-end/101829] New: problems with inline + __attribute__ ((malloc (deallocator))) eggert at cs dot ucla.edu
  2021-08-09 12:52 ` [Bug middle-end/101829] " rguenth at gcc dot gnu.org
  2021-08-09 15:58 ` hubicka at ucw dot cz
@ 2021-08-12 20:32 ` msebor at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-08-12 20:32 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |99715
           Keywords|                            |diagnostic
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=100861

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
Agreed that the inlining restriction is a problem.  See also bug 100861 comment
#2 (the problem is even more severe in C++ because operators new and delete are
treated as if they had the attribute even if they don't).


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99715
[Bug 99715] [meta-bug] bogus/missing Wmismatched-dealloc warnings

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-12 20:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-09 10:33 [Bug middle-end/101829] New: problems with inline + __attribute__ ((malloc (deallocator))) eggert at cs dot ucla.edu
2021-08-09 12:52 ` [Bug middle-end/101829] " rguenth at gcc dot gnu.org
2021-08-09 15:58 ` hubicka at ucw dot cz
2021-08-12 20:32 ` msebor at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).