Message ID | 20231204164231.784822-1-hawkinsw@obs.cr |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2927457vqy; Mon, 4 Dec 2023 09:46:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGZBMiEkCfwp3Bxow94XXpihE17Nc6zug+KXUIoxBLw5N7gSLSLV8KQwZwmNUfJSRVZTBJW X-Received: by 2002:a67:e957:0:b0:464:9c52:d69 with SMTP id p23-20020a67e957000000b004649c520d69mr869428vso.70.1701711983886; Mon, 04 Dec 2023 09:46:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701711983; cv=pass; d=google.com; s=arc-20160816; b=zs1HcOQ4JpwVcUeY2LKXeg9NHFdiXMSshKRqawZRmoVeXK6sElBObHb/nnNlw8kXAw ET/1UMONqN/j9HmIjxSf7xxHDogR9GufVOWv2JPnum3PICgBDyyKJmHGHReTOZ37r8SP koTzK7zNR7jW1KGmdirE69g81zELlcxiXAuJX5h5EwvwtftQ6E8WvhzAjuVAONHoK4wh T7IdOPIBrPV96DliUY2I6FXl4rSnVq/D2/NaGpWoI9ovx+WGcadqto1FsbmqPi0a+qZ2 EDsP0RmqdTcTjgwZp2URJSbBO3nP/1igbEurMfAS2VWeJrahZJ4qDLfgqgDM/cpiHs+H vL2A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=178LV0NLkYDadeNIga/3qUugyJpQdEBGICVmNynfG50=; fh=GRmz4w54poAedv2st2vS4tj+C4PKtqHc4Sqg0PkG7Wc=; b=R7xz8Ef/9INoU+cAyqvVgfEF36sZsbk/ykNldh0QFYDcfV2/dBw70J2tAbQz7W/Ma8 cyrT2bXnfmpDCwxWJkxXl4RSx0lp342fANHZhFSSvdv1U26m1HmcWAYMkPBElkeJTopT NGqO5Dwn4qAmKEbckn1rUnVTu4jfq3uMrcqIdmlUnnAhboETDhNdyu4DTdM/2XVZSwZs NUQdqNE8SXE3URwURF+IBwne684JNKKsbrBO6un4gqhr5GuPDBOuvo8npoLqbK28+FaK DrHDOES4ZXjyZ9K6NbkcNZ4TZtw0cH17HkBhcBjnTHJU0R5M43FsNlplFvhlo07C5E+M tmJQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@obs-cr.20230601.gappssmtp.com header.s=20230601 header.b=BQoyE1hZ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d9-20020a056102222900b0046445a21fbdsi1661471vsb.408.2023.12.04.09.46.23 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:46:23 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@obs-cr.20230601.gappssmtp.com header.s=20230601 header.b=BQoyE1hZ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0439238618F5 for <ouuuleilei@gmail.com>; Mon, 4 Dec 2023 16:43:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) by sourceware.org (Postfix) with ESMTPS id DE76B38582AC for <gcc-patches@gcc.gnu.org>; Mon, 4 Dec 2023 16:42:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE76B38582AC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=obs.cr Authentication-Results: sourceware.org; spf=none smtp.mailfrom=obs.cr ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DE76B38582AC Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701708162; cv=none; b=lQo0Np+AEbCGuRy1Ks+eqB2CQm2HPCPGloO3/mRhws69aU2X+Klc7Xop8ZIm67xCWKI0RG8YcT+sYgf8lbtLK7uqk1y9uvEdg8TuzLsSd05hS8dt7/oent1c9CB/nyGEvr0d594Um2KHt/Jw4yYVNWId663dAQP1X9L3m3hjlY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701708162; c=relaxed/simple; bh=m567vy7gm2DLKLIDeDa4zmseEPxawybYXGuD2lDQ07U=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=oAEefHl4vqd2/qWO8wYQZ612iP0ZtUn4JneCScr2rQpKgkHabcYQneRMSdoIoGgdw4g9uIxPak0gF5cyjmLo76xe4/PbG4WmGZ+OpKyiQ3PfBMcLi+E9je9GrKHo0C3KxbKRmwo2FLDb9o3P5wbflnB7dbfqtw3x9QcFK+xNsLc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-58dd3528497so3173241eaf.3 for <gcc-patches@gcc.gnu.org>; Mon, 04 Dec 2023 08:42:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=obs-cr.20230601.gappssmtp.com; s=20230601; t=1701708160; x=1702312960; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=178LV0NLkYDadeNIga/3qUugyJpQdEBGICVmNynfG50=; b=BQoyE1hZ8oVmLd3oLFKAy7OLTU0IL5CERnJU1UQh1uviie9L09EzC2jekjZtcZMQBY lp9DF3IFOvXuMmsGB20jQtG3gbHZlk32hzfqF951Y8IyJaz7wx0HZo4McUIVp3pnpEv5 Gl3LtcTk8GbaC1Mx0weFw+q70S7S+f+gPLzl710OxA1VFtj+1HbiaXFMC+EvA5Jic9Um Iui0RBwbNnaOctDNQl153WKzcYZm4boSmkUo6Q1PTrPAHdUT25Poy2Ec3AY6sbQbY9dB zlmvRwS+7boPr/WIfPtb8utJL9FqFxFJeo4L6wED7DTzOrRem8crUyRDu2z7RPecitlx rw9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701708160; x=1702312960; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=178LV0NLkYDadeNIga/3qUugyJpQdEBGICVmNynfG50=; b=etVIN3IVeuzmakLFEAgjSFooyCYDlJy+a7yo3dzLaol/xvsCk0xTMWyL6arC144A33 9/peCRxeB3gcV2QTEnLbjVNEt9mpcweJCoNiHP7guGxfWZXlxE/0hf7OZRzTSFPaVVot 6w6n4tacS7GER5Am7i/with6XS3mWu7q8WoIHePiEbxFeaGb3lQZjIww5S9RQY5tQg1M MQpj2sCHBgw0oJanYpy3RA2rab2lYUj5PLlHUNeqUkO0bX/HZn7H01R0H8sG1iEX/q2x cSOkFWnTxkplaq5sKhkzhEaBrb62dT8PRkGRH0O5ctX52FMSBsVNO3W2U4XqO77NCvlQ duCQ== X-Gm-Message-State: AOJu0YymdiT+hLVzQG3KcRSWeGHqHyMIFyK6brEk6e+7HrlmarDrx+Dg dAMACjaThhePnPfqMm1Gh53TxGMr6lDyzOvhoFI= X-Received: by 2002:a05:6358:50c6:b0:170:17ea:f4db with SMTP id m6-20020a05635850c600b0017017eaf4dbmr4835785rwm.40.1701708159706; Mon, 04 Dec 2023 08:42:39 -0800 (PST) Received: from borderland.rhod.uc.edu ([129.137.96.2]) by smtp.gmail.com with ESMTPSA id t27-20020a0cb39b000000b0067a788e258bsm4473312qve.133.2023.12.04.08.42.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 08:42:39 -0800 (PST) From: Will Hawkins <hawkinsw@obs.cr> To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Cc: Will Hawkins <hawkinsw@obs.cr> Subject: [PATCH] libstdc++: Add test for LWG Issue 3897 Date: Mon, 4 Dec 2023 11:42:31 -0500 Message-ID: <20231204164231.784822-1-hawkinsw@obs.cr> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784374345312324678 X-GMAIL-MSGID: 1784374345312324678 |
Series |
libstdc++: Add test for LWG Issue 3897
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Will Hawkins
Dec. 4, 2023, 4:42 p.m. UTC
Hello!
Thank you, as always, for the great work that you do on libstdc++. The
inout_ptr implementation properly handles the issue raised in LWG 3897
but it seems like having an explicit test might be a good idea.
I hope that this helps!
Will
-- >8 --
Add a test to verify that the implementation of inout_ptr is not
vulnerable to LWG Issue 3897.
libstdc++-v3/ChangeLog:
* testsuite/20_util/smartptr.adapt/inout_ptr/3.cc: New test
for LWG Issue 3897.
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
---
.../20_util/smartptr.adapt/inout_ptr/3.cc | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
create mode 100644 libstdc++-v3/testsuite/20_util/smartptr.adapt/inout_ptr/3.cc
Comments
On Mon, 4 Dec 2023 at 16:42, Will Hawkins wrote: > > Hello! > > Thank you, as always, for the great work that you do on libstdc++. The > inout_ptr implementation properly handles the issue raised in LWG 3897 > but it seems like having an explicit test might be a good idea. Thanks, Will, we should definitely have a test for this. I've tweaked it a bit to avoid leaking the pointer (in case anybody runs the tests under valgrind or ASan) and to add your new test to the existing file (to avoid the overhead of a separate test just for this one check). See attached ... commit c02f3696fdb07d1a06c1aa7b035be9a20d65b803 Author: Will Hawkins <hawkinsw@obs.cr> Date: Mon Dec 4 20:59:44 2023 libstdc++: Add test for LWG Issue 3897 Add a test to verify that the implementation of inout_ptr is not vulnerable to LWG Issue 3897. libstdc++-v3/ChangeLog: * testsuite/20_util/smartptr.adapt/inout_ptr/2.cc: Add check for LWG Issue 3897. Co-authored-by: Jonathan Wakely <jwakely@redhat.com> diff --git a/libstdc++-v3/testsuite/20_util/smartptr.adapt/inout_ptr/2.cc b/libstdc++-v3/testsuite/20_util/smartptr.adapt/inout_ptr/2.cc index ca6076209c2..b4a2d95227a 100644 --- a/libstdc++-v3/testsuite/20_util/smartptr.adapt/inout_ptr/2.cc +++ b/libstdc++-v3/testsuite/20_util/smartptr.adapt/inout_ptr/2.cc @@ -96,7 +96,22 @@ test_unique_ptr() VERIFY( upbd->id == 2 ); } +void +test_lwg3897() +{ + // Verify that implementation handles LWG Issue 3897 + auto nuller = [](int** p) { + delete *p; + *p = nullptr; + }; + int* i = new int{5}; + nuller(std::inout_ptr(i)); + + VERIFY( i == nullptr ); +} + int main() { test_unique_ptr(); + test_lwg3897(); }
On Tue, Dec 5, 2023 at 10:46 AM Jonathan Wakely <jwakely@redhat.com> wrote: > > On Mon, 4 Dec 2023 at 16:42, Will Hawkins wrote: > > > > Hello! > > > > Thank you, as always, for the great work that you do on libstdc++. The > > inout_ptr implementation properly handles the issue raised in LWG 3897 > > but it seems like having an explicit test might be a good idea. > > Thanks, Will, we should definitely have a test for this. > > I've tweaked it a bit to avoid leaking the pointer (in case anybody > runs the tests under valgrind or ASan) and to add your new test to the Of course ... how could I forget to delete the pointer? I'm a goofball. > existing file (to avoid the overhead of a separate test just for this > one check). Makes perfect sense. I wasn't sure how you typically handle that. I will know for the future. > > See attached ... Thank you for the feedback! I look forward to the next time I can help! Will
On Tue, 5 Dec 2023 at 15:57, Will Hawkins wrote: > > On Tue, Dec 5, 2023 at 10:46 AM Jonathan Wakely <jwakely@redhat.com> wrote: > > > > On Mon, 4 Dec 2023 at 16:42, Will Hawkins wrote: > > > > > > Hello! > > > > > > Thank you, as always, for the great work that you do on libstdc++. The > > > inout_ptr implementation properly handles the issue raised in LWG 3897 > > > but it seems like having an explicit test might be a good idea. > > > > Thanks, Will, we should definitely have a test for this. > > > > I've tweaked it a bit to avoid leaking the pointer (in case anybody > > runs the tests under valgrind or ASan) and to add your new test to the > > Of course ... how could I forget to delete the pointer? I'm a goofball. :-) > > existing file (to avoid the overhead of a separate test just for this > > one check). > > Makes perfect sense. I wasn't sure how you typically handle that. I > will know for the future. In principle it's better to have one test file per thing we want to check ... but libstdc++ has a lot of tests, and every one of them includes the bits/stdc++.h precompiled header which includes the entire library. And the way dejagnu works, every test runs multiple compilations, because it preprocesses or compiles various helper files to check the test conditions. And since I run every test about 20 times (with various combinations of options) it all adds up.
diff --git a/libstdc++-v3/testsuite/20_util/smartptr.adapt/inout_ptr/3.cc b/libstdc++-v3/testsuite/20_util/smartptr.adapt/inout_ptr/3.cc new file mode 100644 index 00000000000..f9114dc57b5 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/smartptr.adapt/inout_ptr/3.cc @@ -0,0 +1,17 @@ +// { dg-do run { target c++23 } } + +#include <memory> +#include <testsuite_hooks.h> + +// C++23 [inout.ptr.t] Class template inout_ptr_t +// Verify that implementation handles LWG Issue 3897 +void nuller(int **p) { + *p = nullptr; +} + +int main(int, char **) { + int *i = new int{5}; + nuller(std::inout_ptr(i)); + + VERIFY(i == nullptr); +}