Message ID | 20231204164231.784822-1-hawkinsw@obs.cr |
---|---|
State | Committed |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 08FF0385E00F for <patchwork@sourceware.org>; Mon, 4 Dec 2023 16:42:57 +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-Google-Smtp-Source: AGHT+IFeB8efq0rWYuEP2IUIsBseOf90Nh8B7Ma+xAThWuJbLXyoRQEQwez7PHZfFAj5De1nkmIdyw== 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+patchwork=sourceware.org@gcc.gnu.org |
Series |
libstdc++: Add test for LWG Issue 3897
|
|
Checks
Context | Check | Description |
---|---|---|
linaro-tcwg-bot/tcwg_gcc_build--master-arm | success | Testing passed |
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 | success | Testing passed |
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 | success | Testing passed |
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); +}