From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id AD51D3858419; Thu, 22 Feb 2024 17:29:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD51D3858419 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708622976; bh=8YTFR5Urm3JFSEZF/OJQmPX/cV34wnBL6kUPngX6LiA=; h=From:To:Subject:Date:From; b=kSK43R/PiCn3q4lQD3BQoR99uWNyfcuDI5Olho0B6eoOkNyTeSURkh1TZJ1dCTl+b 0sWQxTi4+BtHtLebfg7p3i9kJuNXXDy4zGz3Dap3qafcYUnGrNzegWXhAnQIl3ekqV AEUnk07/iWhxWdMajfF9pFEmyumpKNnGsyLEBb7k= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Pinski To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-9138] warn-access: Fix handling of unnamed types [PR109804] X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 7d8585c0c0e5934780281abdee256ae6553e56e8 X-Git-Newrev: 1076ffda6ce5e6d5fc9577deaf8233e549e5787a Message-Id: <20240222172936.AD51D3858419@sourceware.org> Date: Thu, 22 Feb 2024 17:29:36 +0000 (GMT) List-Id: https://gcc.gnu.org/g:1076ffda6ce5e6d5fc9577deaf8233e549e5787a commit r14-9138-g1076ffda6ce5e6d5fc9577deaf8233e549e5787a Author: Andrew Pinski Date: Wed Feb 21 20:12:21 2024 -0800 warn-access: Fix handling of unnamed types [PR109804] This looks like an oversight of handling DEMANGLE_COMPONENT_UNNAMED_TYPE. DEMANGLE_COMPONENT_UNNAMED_TYPE only has the u.s_number.number set while the code expected newc.u.s_binary.left would be valid. So this treats DEMANGLE_COMPONENT_UNNAMED_TYPE like we treat function paramaters (DEMANGLE_COMPONENT_FUNCTION_PARAM) and template paramaters (DEMANGLE_COMPONENT_TEMPLATE_PARAM). Note the code in the demangler does this when it sets DEMANGLE_COMPONENT_UNNAMED_TYPE: ret->type = DEMANGLE_COMPONENT_UNNAMED_TYPE; ret->u.s_number.number = num; Committed as obvious after bootstrap/test on x86_64-linux-gnu PR tree-optimization/109804 gcc/ChangeLog: * gimple-ssa-warn-access.cc (new_delete_mismatch_p): Handle DEMANGLE_COMPONENT_UNNAMED_TYPE. gcc/testsuite/ChangeLog: * g++.dg/warn/Wmismatched-new-delete-8.C: New test. Signed-off-by: Andrew Pinski Diff: --- gcc/gimple-ssa-warn-access.cc | 1 + .../g++.dg/warn/Wmismatched-new-delete-8.C | 42 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc index cd083ab22377..dedaae27b31c 100644 --- a/gcc/gimple-ssa-warn-access.cc +++ b/gcc/gimple-ssa-warn-access.cc @@ -1701,6 +1701,7 @@ new_delete_mismatch_p (const demangle_component &newc, case DEMANGLE_COMPONENT_FUNCTION_PARAM: case DEMANGLE_COMPONENT_TEMPLATE_PARAM: + case DEMANGLE_COMPONENT_UNNAMED_TYPE: return newc.u.s_number.number != delc.u.s_number.number; case DEMANGLE_COMPONENT_CHARACTER: diff --git a/gcc/testsuite/g++.dg/warn/Wmismatched-new-delete-8.C b/gcc/testsuite/g++.dg/warn/Wmismatched-new-delete-8.C new file mode 100644 index 000000000000..0ddc056c6df2 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wmismatched-new-delete-8.C @@ -0,0 +1,42 @@ +/* PR tree-optimization/109804 */ +/* { dg-do compile { target c++11 } } */ +/* { dg-options "-Wall" } */ + +/* Here we used to ICE in new_delete_mismatch_p because + we didn't handle unnamed types from the demangler (DEMANGLE_COMPONENT_UNNAMED_TYPE). */ + +template +static inline T * construct_at(void *at, ARGS && args) +{ + struct Placeable : T + { + Placeable(ARGS && args) : T(args) { } + void * operator new (long unsigned int, void *ptr) { return ptr; } + void operator delete (void *, void *) { } + }; + return new (at) Placeable(static_cast(args)); +} +template +struct Reconstructible +{ + char _space[sizeof(MT)]; + Reconstructible() { } +}; +template +struct Constructible : Reconstructible +{ + Constructible(){} +}; +struct A { }; +struct B +{ + Constructible a { }; + B(int) { } +}; +Constructible b { }; +void f() +{ + enum { ENUM_A = 1 }; + enum { ENUM_B = 1 }; + construct_at(b._space, ENUM_B); +}