From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id 14454385482F for ; Mon, 14 Jun 2021 05:56:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 14454385482F Received: by mail-ej1-x630.google.com with SMTP id ho18so14531449ejc.8 for ; Sun, 13 Jun 2021 22:56:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:references:mime-version :content-transfer-encoding:subject:to:from:message-id; bh=Gl1Cn60hOsEbiL92PvCvR1aSr9d5VNmHfL2q9PtEkUo=; b=Jfy2HyeUcc0gYLD9zCXaAnV6PgcNTNxPxyYRfBtzfgdJC9qoI4W3wIqux64NeFFjt5 Y8BR+6nKUMXHiOp/XAnR+UlvVg8Po872M1ZtGT8A5OOFpmysujxOICtvO79Y7mfOsXhi +4CXaq7rOJ8ipLX7kSxpI9BwC7KYxzSgf7Bbfe4Cm+kE9tvJ7ILI4mi8O3XR3ntfrmlX E2GJ+aXqtdY5Wu+qHFEZtTcRgbEYfXP5inVywZvfZ4MflKtU7wMT77N+yvs2IMeSzVB2 MDgUvDiF0jw8TUfzredTvKQ5/v1EgHkE1QAepsew/M7EnMwGdWiLeQcKd8jXGvdP1558 dFwg== X-Gm-Message-State: AOAM532QqstJ7I207SxJobE1fkn6yIK5l+oCcN8k1cC75kxhm3OPvAgd 7Aacr09eq80CrYJqECCDv9M= X-Google-Smtp-Source: ABdhPJyidRXRB6IZkxcyPuaAeDj7ywSuB6w1XbhStP2ikporw6to3NdgiraRJ/OOP0LnGruViCpmWw== X-Received: by 2002:a17:906:b308:: with SMTP id n8mr13849418ejz.93.1623650203155; Sun, 13 Jun 2021 22:56:43 -0700 (PDT) Received: from ?IPv6:2001:4bb8:10d:ad97:1:0:aaa6:a523? ([2001:4bb8:10d:ad97:1:0:aaa6:a523]) by smtp.gmail.com with ESMTPSA id o21sm6386053ejg.49.2021.06.13.22.56.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 13 Jun 2021 22:56:42 -0700 (PDT) Date: Mon, 14 Jun 2021 07:56:38 +0200 In-Reply-To: <477cf633-6a0b-b4d9-5505-47a6a665bb70@gmail.com> References: <6ccb6e6b-61b4-822b-d291-d2712192758e@gmail.com> <477cf633-6a0b-b4d9-5505-47a6a665bb70@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH] teach compute_objsize about placement new (PR 100876) To: Jeff Law , Jeff Law via Gcc-patches , Martin Sebor , gcc-patches From: Bernhard Reutner-Fischer Message-ID: <2AF1D8F4-FB17-40EC-A482-C41BFD14BB70@gmail.com> X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Jun 2021 05:56:45 -0000 On 14 June 2021 01:45:36 CEST, Jeff Law via Gcc-patches wrote: > > >On 6/2/2021 3:40 PM, Martin Sebor via Gcc-patches wrote: >> The two forms of placement operator new defined in return their >> pointer argument and may not be displaced by user-defined functions=2E >> But because they are ordinary (not built-in) functions this property >> isn't reflected in their declarations alone, and there's no user- >> level attribute to annotate them with=2E=C2=A0 When they are inlined >> the property is transparent in the IL but when they are not (without >> inlining such as -O0), calls to the operators appear in the IL and >> cause -Wmismatched-new-delete to try to match them with the functions >> called to deallocate memory=2E=C2=A0 When the pointer to the memory was >> obtained from a function that matches the deallocator but not >> the placement new, the warning falsely triggers=2E >> >> The attached patch solves this by detecting calls to placement new >> and treating them the same as those to other pass-through calls (such >> as memset)=2E=C2=A0 In addition, it also teaches -Wfree-nonheap-object = about >> placement delete, for a similar reason as above=2E=C2=A0 Finally, it al= so >> adds a test for attribute fn spec indicating a function returns its >> argument=2E=C2=A0 It's not necessary for the fix (I had initially thoug= h >> placement new might have the attribute) but it seems appropriate >> to check=2E >> >> Tested on x86_64-linux=2E >> >> Martin >> >> gcc-100876=2Ediff >> >> PR c++/100876 - -Wmismatched-new-delete should understand placement >new when it's not inlined >> >> gcc/ChangeLog: >> >> PR c++/100876 >> * builtins=2Ec (gimple_call_return_array): Check for attribute fn >spec=2E >> Handle calls to placement new=2E >> (ndecl_dealloc_argno): Avoid placement delete=2E >> >> gcc/testsuite/ChangeLog: >> >> PR c++/100876 >> * g++=2Edg/warn/Wmismatched-new-delete-4=2EC: New test=2E >> * g++=2Edg/warn/Wmismatched-new-delete-5=2EC: New test=2E >> * g++=2Edg/warn/Wstringop-overflow-7=2EC: New test=2E >> * g++=2Edg/warn/Wfree-nonheap-object-6=2EC: New test=2E >> * g++=2Edg/analyzer/placement-new=2EC: Prune out expected warning=2E >> >> diff --git a/gcc/builtins=2Ec b/gcc/builtins=2Ec >> index af1fe49bb48=2E=2Efb0717a0248 100644 >> --- a/gcc/builtins=2Ec >> +++ b/gcc/builtins=2Ec >> @@ -5159,11 +5159,43 @@ static tree >> gimple_call_return_array (gimple *stmt, offset_int offrng[2], >> range_query *rvals) >> { >> - if (!gimple_call_builtin_p (stmt, BUILT_IN_NORMAL) >> - || gimple_call_num_args (stmt) < 1) >> + { >> + /* Check for attribute fn spec to see if the function returns >one >> + of its arguments=2E */ >> + attr_fnspec fnspec =3D gimple_call_fnspec (as_a (stmt)); >> + unsigned int argno; >> + if (fnspec=2Ereturns_arg (&argno)) >> + { >> + offrng[0] =3D offrng[1] =3D 0; >> + return gimple_call_arg (stmt, argno); >> + } >> + } >> + >> + if (gimple_call_num_args (stmt) < 1) >> return NULL_TREE; >Nit=2E=C2=A0 You've got an unnecessary {} at the outer level of this hunk= =2E if (unsigned int =3D 1 && fnspec=2Ereturns_arg (&argno)) doesn't look too appealing though, I'd leave the curly braces, no? cheers, > >OK with the nit fixed=2E > >THanks, >Jeff