Correct/improve maybe_emit_free_warning (PR middle-end/98166, PR c++/57111, PR middle...
authorMartin Sebor <msebor@redhat.com>
Mon, 14 Dec 2020 20:30:00 +0000 (13:30 -0700)
committerMartin Sebor <msebor@redhat.com>
Mon, 14 Dec 2020 20:30:00 +0000 (13:30 -0700)
commitfe7f75cf16783589eedbab597e6d0b8d35d7e470
tree7fec98daa8cd2d99d08d302f753fb7416f3e901c
parente63ae8c083a3218400206b80d4eedd9950fc5d3f
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.
20 files changed:
gcc/builtins.c
gcc/c-family/c-attribs.c
gcc/doc/extend.texi
gcc/testsuite/c-c++-common/Wfree-nonheap-object-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wfree-nonheap-object-3.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wfree-nonheap-object.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wmismatched-dealloc.c [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wfree-nonheap-object-3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wfree-nonheap-object-4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wmismatched-dealloc-2.C
gcc/testsuite/g++.dg/warn/Wmismatched-new-delete-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wmismatched-new-delete.C
gcc/testsuite/gcc.dg/Wmismatched-dealloc-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wmismatched-dealloc-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wmismatched-dealloc.c
gcc/tree-ssa-dce.c
gcc/tree.c
gcc/tree.h
libstdc++-v3/testsuite/ext/vstring/requirements/exception/basic.cc
libstdc++-v3/testsuite/ext/vstring/requirements/exception/propagation_consistent.cc