From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id B7DD63858D32; Sun, 15 Jan 2023 16:08:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B7DD63858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-x329.google.com with SMTP id g10so18396258wmo.1; Sun, 15 Jan 2023 08:08:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=/ELADoCtGgJO5/7c8VGPONbbeC8hxTHWB8gBmAyNkjM=; b=hueGQVIj8YQX9pJDgxr4D8I3M9LELzLj+9Lo5gSKNyMCJ/cmgeA47xw2oR59dLwOAg 9zHX7la4QUUJ0klnD6KuOcrZfu4TjvkXZNmEUswtr97zMVy+cDrkNDyvrFNYo+wQFRVG 9Tgnv9iBCWS2+GEPPLTFbJBC8AjnhVki4qSIFSkbZ1L9DqulJT6NwEbSsDM/u6TB6gCl vyJUaEiB7u3G8UMy+2esdIRCNi64kP0zpYKNMi2LHVNjUWiIZY+nGjdTZ/KEo7HrESl+ PLQsyCCQHsPOnIIxtw81hG0FGrBiXYorfI+m1BZ7bHSq9IS2BvqI0txk2tglQfLUX1Oz pMqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/ELADoCtGgJO5/7c8VGPONbbeC8hxTHWB8gBmAyNkjM=; b=AhAoeqO1ap1YEzboKkoZp5kbKvp2jQ851ihTpm+dIZipwZhyqcckyqfGTckahpaZar 0ruHzTDruJyEazIvyd2KilxwPS5a6v11ASLoqarWq5Py33AvZ73kOSul/ZTD+MSkX9RK qgbJ8ovQfCX01PimOj2aDBRRZlr/ikbqQjrL9pJZGRchnCduOw4z4AbQMcyml5vS/A0C LddZycA1QqUMqxVD7wP6RFWODNtp1OV57o5HHBUM+YoBdfk4Yp2csFFMdo7o3JpJBGEN unNLbFw/NfG+yl2ys2cThFaJgvBQ7qccVOQixkrsOKiDSrOvx1wXx9aNYOJx35idoSgV tu1Q== X-Gm-Message-State: AFqh2krBWLJXMyOXQNN+lVtKVZ1a3MjwJ+b9ZHHj/bxYnkz0O9OARg3q kqsGyP9AUSa4nBTJqZKx2yI= X-Google-Smtp-Source: AMrXdXsn3nbeVyK35ABg3HHcnxU5pEbqrmXqDI3KRHPoWfZ98vKmk9Q0tgcuvT3w2GASxyakt2AYrw== X-Received: by 2002:a1c:4b04:0:b0:3da:fc15:740c with SMTP id y4-20020a1c4b04000000b003dafc15740cmr300490wma.19.1673798903470; Sun, 15 Jan 2023 08:08:23 -0800 (PST) Received: from ?IPV6:2a01:e0a:1dc:b1c0:50cc:ea38:d594:a518? ([2a01:e0a:1dc:b1c0:50cc:ea38:d594:a518]) by smtp.googlemail.com with ESMTPSA id f12-20020a05600c154c00b003d9fba3c7a4sm18540254wmg.16.2023.01.15.08.08.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 15 Jan 2023 08:08:22 -0800 (PST) Message-ID: <518781a6-b7ea-e9f1-1aa9-ead1b9a8cf56@gmail.com> Date: Sun, 15 Jan 2023 17:08:22 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: libstdc++: Fix deadlock in debug iterator increment [PR108288] To: Jonathan Wakely Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org References: <20230106115402.178926-1-jwakely@redhat.com> <6f88e8e7-6771-d344-beb4-1ca37d79dd5c@gmail.com> Content-Language: fr From: =?UTF-8?Q?Fran=c3=a7ois_Dumont?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Committed with the idiomatic approach. I'll work on this additional check later. On 12/01/23 22:35, Jonathan Wakely wrote: > On Thu, 12 Jan 2023 at 18:25, François Dumont wrote: >> On 12/01/23 13:00, Jonathan Wakely wrote: >>> On Thu, 12 Jan 2023 at 05:52, François Dumont wrote: >>>> Small update for an obvious compilation issue and to review new test >>>> case that could have lead to an infinite loop if the increment issue was >>>> not detected. >>>> >>>> I also forgot to ask if there is more chance for the instantiation to be >>>> elided when it is implemented like in the _Safe_local_iterator: >>>> return { __cur, this->_M_sequence }; >>> No, that doesn't make any difference. >>> >>>> than in the _Safe_iterator: >>>> return _Safe_iterator(__cur, this->_M_sequence); >>>> >>>> In the case where the user code do not use it ? >>>> >>>> Fully tested now, ok to commit ? >>>> >>>> François >>>> >>>> On 11/01/23 07:03, François Dumont wrote: >>>>> Thanks for fixing this. >>>>> >>>>> Here is the extension of the fix to all post-increment/decrement >>>>> operators we have on _GLIBCXX_DEBUG iterator. >>> Thanks, I completely forgot we have other partial specializations, I >>> just fixed the one that showed a deadlock in the user's example! >>> >>>>> I prefer to restore somehow previous implementation to continue to >>>>> have _GLIBCXX_DEBUG post operators implemented in terms of normal post >>>>> operators. >>> Why? >>> >>> Implementing post-increment as: >>> >>> auto tmp = *this; >>> ++*this; >>> return tmp; >>> >>> is the idiomatic way to write it, and it works fine in this case. I >>> don't think it performs any more work than your version, does it? >>> Why not use the idiomatic form? >>> >>> Is it just so that post-inc of a debug iterator uses post-inc of the >>> underlying iterator? Why does that matter? >>> >> A little yes, but that's a minor reason that is just making me happy. >> >> Main reason is that this form could produce a __msg_init_copy_singular >> before the __msg_bad_inc. > Ah yes, I see. That's a shame. I find the idiomatic form much simpler > to read, and it will generate better code (because it just reuses > existing functions, instead of adding new ones). > > We could do this though, right? > > _GLIBCXX_DEBUG_VERIFY(this->_M_incrementable(), > _M_message(__msg_bad_inc) > ._M_iterator(*this, "this")); > _Safe_iterator __tmp = *this; > ++*this; > return __tmp; > > That does the VERIFY check twice though. > >> And moreover I plan to propose a patch later to skip any check in the >> call to _Safe_iterator(__cur, _M_sequence) as we already know that __cur >> is ok here like anywhere else in the lib. >> >> There will still be one in the constructor normally elided unless >> --no-elide-constructors but there is not much I can do about it. > Don't worry about it. Nobody should ever use -fno-elide-constructors > in any real cases (except maybe debugging some very strange corner > cases, and in that case the extra safe iterator checks are not going > to be their biggest problem). > > The patch is OK for trunk then. >