public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/98166] New: bogus -Wmismatched-dealloc on user-defined allocator and inlining
@ 2020-12-07  1:03 msebor at gcc dot gnu.org
  2020-12-07  1:04 ` [Bug middle-end/98166] " msebor at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-12-07  1:03 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98166
           Summary: bogus -Wmismatched-dealloc on user-defined allocator
                    and inlining
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Designating using attribute malloc a pair of functions as an allocator and
deallocator and defining one of them inline to call another allocator or
deallocator not associated with the former pair leads to false positive
warnings.

The test case below (inspired by the one in pr98160) shows how this could
happen.  The two pairs of allocators are independent with one another

$ cat a.c && gcc -O2 -S -Wall a.c
void dealloc_shrt (short *p) { __builtin_free (p - 1); }
void dealloc_int (int*);

__attribute__ ((malloc (dealloc_shrt)))
short* alloc_shrt (int);

__attribute__ ((malloc (dealloc_int)))
int* alloc_int (int n) { return (int*)__builtin_malloc (n) + 1; }

void f (int n)
{
  {
    short *p = alloc_shrt (n);
    dealloc_shrt (p);
  }

  {
    int *p = alloc_int (n);
    dealloc_int (p);
  }
}
In function ‘dealloc_shrt’,
    inlined from ‘f’ at a.c:14:5:
a.c:1:32: warning: ‘__builtin_free’ called on pointer returned from a
mismatched allocation function [-Wmismatched-dealloc]
    1 | void dealloc_shrt (short *p) { __builtin_free (p - 1); }
      |                                ^~~~~~~~~~~~~~~~~~~~~~
a.c: In function ‘f’:
a.c:13:16: note: returned from a call to ‘alloc_shrt’
   13 |     short *p = alloc_shrt (n);
      |                ^~~~~~~~~~~~~~
a.c:19:5: warning: ‘dealloc_int’ called on pointer returned from a mismatched
allocation function [-Wmismatched-dealloc]
   19 |     dealloc_int (p);
      |     ^~~~~~~~~~~~~~~
a.c:8:39: note: returned from a call to ‘__builtin_malloc’
    8 | int* alloc_int (int n) { return (int*)__builtin_malloc (n) + 1; }
      |                                       ^~~~~~~~~~~~~~~~~~~~

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

* [Bug middle-end/98166] bogus -Wmismatched-dealloc on user-defined allocator and inlining
  2020-12-07  1:03 [Bug middle-end/98166] New: bogus -Wmismatched-dealloc on user-defined allocator and inlining msebor at gcc dot gnu.org
@ 2020-12-07  1:04 ` msebor at gcc dot gnu.org
  2020-12-08 20:48 ` msebor at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-12-07  1:04 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=98160
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED
   Target Milestone|---                         |11.0
           Keywords|                            |diagnostic
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot gnu.org
   Last reconfirmed|                            |2020-12-07

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

* [Bug middle-end/98166] bogus -Wmismatched-dealloc on user-defined allocator and inlining
  2020-12-07  1:03 [Bug middle-end/98166] New: bogus -Wmismatched-dealloc on user-defined allocator and inlining msebor at gcc dot gnu.org
  2020-12-07  1:04 ` [Bug middle-end/98166] " msebor at gcc dot gnu.org
@ 2020-12-08 20:48 ` msebor at gcc dot gnu.org
  2020-12-14 20:31 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-12-08 20:48 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unknown                     |11.0
           Keywords|                            |patch

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Patch: https://gcc.gnu.org/pipermail/gcc-patches/2020-December/561378.html

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

* [Bug middle-end/98166] bogus -Wmismatched-dealloc on user-defined allocator and inlining
  2020-12-07  1:03 [Bug middle-end/98166] New: bogus -Wmismatched-dealloc on user-defined allocator and inlining msebor at gcc dot gnu.org
  2020-12-07  1:04 ` [Bug middle-end/98166] " msebor at gcc dot gnu.org
  2020-12-08 20:48 ` msebor at gcc dot gnu.org
@ 2020-12-14 20:31 ` cvs-commit at gcc dot gnu.org
  2021-04-27 11:39 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-12-14 20:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:fe7f75cf16783589eedbab597e6d0b8d35d7e470

commit r11-6028-gfe7f75cf16783589eedbab597e6d0b8d35d7e470
Author: Martin Sebor <msebor@redhat.com>
Date:   Mon Dec 14 13:30:00 2020 -0700

    Correct/improve maybe_emit_free_warning (PR middle-end/98166, PR c++/57111,
PR middle-end/98160).

    Resolves:
    PR middle-end/98166 - bogus -Wmismatched-dealloc on user-defined allocator
and inlining
    PR c++/57111 - 57111 - Generalize -Wfree-nonheap-object to delete
    PR middle-end/98160 - ICE in default_tree_printer at
gcc/tree-diagnostic.c:270

    gcc/ChangeLog:

            PR middle-end/98166
            PR c++/57111
            PR middle-end/98160
            * builtins.c (check_access): Call tree_inlined_location
            fndecl_alloc_p): Handle BUILT_IN_ALIGNED_ALLOC and
            BUILT_IN_GOMP_ALLOC.
            call_dealloc_p): Remove unused function.
            (new_delete_mismatch_p): Call valid_new_delete_pair_p and rework.
            (matching_alloc_calls_p): Handle built-in deallocation functions.
            (warn_dealloc_offset): Corrct the handling of user-defined
operators
            delete.
            (maybe_emit_free_warning): Avoid assuming expression is a decl.
            Simplify.
            * doc/extend.texi (attribute malloc): Update.
            * tree-ssa-dce.c (valid_new_delete_pair_p): Factor code out into
            valid_new_delete_pair_p in tree.c.
            * tree.c (tree_inlined_location): Define new function.
            (valid_new_delete_pair_p): Define.
            * tree.h (tree_inlined_location): Declare.
            (valid_new_delete_pair_p): Declare.

    gcc/c-family/ChangeLog:

            PR middle-end/98166
            PR c++/57111
            PR middle-end/98160
            * c-attribs.c (maybe_add_noinline): New function.
            (handle_malloc_attribute): Call it.  Use ATTR_FLAG_INTERNAL.
            Implicitly add attribute noinline to functions not declared inline
            and warn on those.

    libstdc++-v3/ChangeLog:
            * testsuite/ext/vstring/requirements/exception/basic.cc: Suppress
            a false positive warning.
            *
testsuite/ext/vstring/requirements/exception/propagation_consistent.cc:
              Same.

    gcc/testsuite/ChangeLog:

            PR middle-end/98166
            PR c++/57111
            PR middle-end/98160
            * g++.dg/warn/Wmismatched-dealloc-2.C: Adjust test of expected
warning.
            * g++.dg/warn/Wmismatched-new-delete.C: Same.
            * gcc.dg/Wmismatched-dealloc.c: Same.
            * c-c++-common/Wfree-nonheap-object-2.c: New test.
            * c-c++-common/Wfree-nonheap-object-3.c: New test.
            * c-c++-common/Wfree-nonheap-object.c: New test.
            * c-c++-common/Wmismatched-dealloc.c: New test.
            * g++.dg/warn/Wfree-nonheap-object-3.C: New test.
            * g++.dg/warn/Wfree-nonheap-object-4.C: New test.
            * g++.dg/warn/Wmismatched-dealloc-2.C: New test.
            * g++.dg/warn/Wmismatched-new-delete-2.C: New test.
            * g++.dg/warn/Wmismatched-new-delete.C: New test.
            * gcc.dg/Wmismatched-dealloc-2.c: New test.
            * gcc.dg/Wmismatched-dealloc-3.c: New test.
            * gcc.dg/Wmismatched-dealloc.c: New test.

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

* [Bug middle-end/98166] bogus -Wmismatched-dealloc on user-defined allocator and inlining
  2020-12-07  1:03 [Bug middle-end/98166] New: bogus -Wmismatched-dealloc on user-defined allocator and inlining msebor at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2020-12-14 20:31 ` cvs-commit at gcc dot gnu.org
@ 2021-04-27 11:39 ` jakub at gcc dot gnu.org
  2021-07-28  7:05 ` rguenth at gcc dot gnu.org
  2021-12-15 15:50 ` msebor at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-04-27 11:39 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.0                        |11.2

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 11.1 has been released, retargeting bugs to GCC 11.2.

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

* [Bug middle-end/98166] bogus -Wmismatched-dealloc on user-defined allocator and inlining
  2020-12-07  1:03 [Bug middle-end/98166] New: bogus -Wmismatched-dealloc on user-defined allocator and inlining msebor at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-04-27 11:39 ` jakub at gcc dot gnu.org
@ 2021-07-28  7:05 ` rguenth at gcc dot gnu.org
  2021-12-15 15:50 ` msebor at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-28  7:05 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.2                        |11.3

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 11.2 is being released, retargeting bugs to GCC 11.3

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

* [Bug middle-end/98166] bogus -Wmismatched-dealloc on user-defined allocator and inlining
  2020-12-07  1:03 [Bug middle-end/98166] New: bogus -Wmismatched-dealloc on user-defined allocator and inlining msebor at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2021-07-28  7:05 ` rguenth at gcc dot gnu.org
@ 2021-12-15 15:50 ` msebor at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-12-15 15:50 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
Fixed in GCC 11.

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

end of thread, other threads:[~2021-12-15 15:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-07  1:03 [Bug middle-end/98166] New: bogus -Wmismatched-dealloc on user-defined allocator and inlining msebor at gcc dot gnu.org
2020-12-07  1:04 ` [Bug middle-end/98166] " msebor at gcc dot gnu.org
2020-12-08 20:48 ` msebor at gcc dot gnu.org
2020-12-14 20:31 ` cvs-commit at gcc dot gnu.org
2021-04-27 11:39 ` jakub at gcc dot gnu.org
2021-07-28  7:05 ` rguenth at gcc dot gnu.org
2021-12-15 15:50 ` 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).