From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 845EF3858436 for ; Fri, 10 Mar 2023 18:09:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 845EF3858436 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678471799; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=HAi1TBgC12C8C6cWO3jLZSFWbPKqpf66nxFjq48TWS0=; b=ENg7TLG5A+HzZgP6j5Jvs2TlVFJ1+h89ukZ6JnjAIq2ZTJw8sGcv2NZ1Ta8N5VqLPtpxwu lDKM7eHRTlyjN8MBEApPzQqqzjxg6h94GGyv/gyXSXhWxLDDXClXVV9Ax7/SGyCZnS9c7+ 15VBFtp9XoevZY8l2IOfVwzAoptwUcI= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-675-VnjqPHyuNve5W6DZHaQ0qw-1; Fri, 10 Mar 2023 13:09:57 -0500 X-MC-Unique: VnjqPHyuNve5W6DZHaQ0qw-1 Received: by mail-qk1-f197.google.com with SMTP id ea22-20020a05620a489600b00742cec04043so3546746qkb.7 for ; Fri, 10 Mar 2023 10:09:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678471797; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HAi1TBgC12C8C6cWO3jLZSFWbPKqpf66nxFjq48TWS0=; b=Lf5Y0FnCzHBElO2d1dwUoEkycGXXnJzoAEgiHzZ1ri2XZv8uLARz2zdqs8n4KXuLAx ThLjdVljo1vBtUiF7xaWrttZErkYl9QBOcgzZ8BKF8xQuCxJiOrKe7rfbxtbefH7YkZ6 77om4L0eflYs9XTPGgaMHNzM3jM3VXKDs/w7uZGfdUqrcYlDV5QeKwD2/7wRahnbcVEA 4RhVD6yu6NYyV17P0Wih2ZCeK9Dfs/dvV+5e9rp7/gcytZ8NiMJu3MNz7co5N0bXRWGW Si5tzAgxyYp3jh1eJ7rf9dCHkglkfVSjjjZgfpCo92w5PFsDpjtvppt3RbbKzyfr80Da wE3Q== X-Gm-Message-State: AO0yUKUjOffigbX8IuZObuaSVs922J1KTQOJr9Wxn8Pa8uIT/daQSf9U SlwokswFrDs8YD/03ymnTv3TXlSPvU4wm3UnYWbWoOUsviiq9FQZ8rJCm9UVva8QXchgakCKU/I JM6b7APGFTa1pQtUOgw== X-Received: by 2002:a05:6214:2246:b0:56e:afe2:ebca with SMTP id c6-20020a056214224600b0056eafe2ebcamr12151771qvc.30.1678471797307; Fri, 10 Mar 2023 10:09:57 -0800 (PST) X-Google-Smtp-Source: AK7set+LsPM/a4wsjOTp5LK1l/Hqh65iSzQbVs279hO+XpsrH0q45mIWCZkhU2VOnlUYEePHuw3DPA== X-Received: by 2002:a05:6214:2246:b0:56e:afe2:ebca with SMTP id c6-20020a056214224600b0056eafe2ebcamr12151730qvc.30.1678471796972; Fri, 10 Mar 2023 10:09:56 -0800 (PST) Received: from redhat.com (2603-7000-9500-34a5-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:34a5::1db4]) by smtp.gmail.com with ESMTPSA id 11-20020a05620a048b00b00743592b4745sm198897qkr.109.2023.03.10.10.09.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 10:09:56 -0800 (PST) Date: Fri, 10 Mar 2023 13:09:54 -0500 From: Marek Polacek To: Jakub Jelinek Cc: Richard Biener , GCC Patches Subject: Re: [PATCH v2] ubsan: missed -fsanitize=bounds for compound ops [PR108060] Message-ID: References: <20230308210930.128620-1-polacek@redhat.com> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/2.2.9 (2022-11-12) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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: On Fri, Mar 10, 2023 at 07:07:36PM +0100, Jakub Jelinek wrote: > On Thu, Mar 09, 2023 at 07:44:53PM -0500, Marek Polacek wrote: > > On Thu, Mar 09, 2023 at 09:44:49AM +0100, Jakub Jelinek wrote: > > > On Thu, Mar 09, 2023 at 08:12:47AM +0000, Richard Biener wrote: > > > > I think this is a reasonable way to address the regression, so OK. > > > > > > It is true that both C and C++ (including c++14_down and c++17 and later > > > where the latter have different ordering rules) evaluate the lhs of > > > MODIFY_EXPR after rhs, so conceptually this patch makes sense. > > > > Thank you both for taking a look. > > > > > But I wonder why we do in ubsan_maybe_instrument_array_ref: > > > if (e != NULL_TREE) > > > { > > > tree t = copy_node (*expr_p); > > > TREE_OPERAND (t, 1) = build2 (COMPOUND_EXPR, TREE_TYPE (op1), > > > e, op1); > > > *expr_p = t; > > > } > > > rather than modification of the ARRAY_REF's operand in place. If we > > > did that, we wouldn't really care about the order, shared tree would > > > be instrumented once, with SAVE_EXPR in there making sure we don't > > > compute that multiple times. Is that because the 2 copies could > > > have side-effects and we do want to evaluate those multiple times? > > > > I'd assumed that that was the point of the copy_node. But now that > > I'm actually experimenting with it, I can't trigger any problems > > without the copy_node. So maybe we can use the following patch, which > > also adds a new test, bounds-21.c, to check that side-effects are > > evaluated correctly. I didn't bother writing a description for this > > patch yet because I sort of think we should apply both patches at the > > same time. > > Perhaps it would be safer to apply for GCC 13 just your first patch > and maybe the testsuite coverage from this one and defer this change > for GCC 14? That sounds good, I'll push the original patch with the new test now. Thanks. > > Regtested on x86_64-pc-linux-gnu. > > > > -- >8 -- > > PR sanitizer/108060 > > PR sanitizer/109050 > > > > gcc/c-family/ChangeLog: > > > > * c-ubsan.cc (ubsan_maybe_instrument_array_ref): Don't copy_node. > > > > gcc/testsuite/ChangeLog: > > > > * c-c++-common/ubsan/bounds-17.c: New test. > > * c-c++-common/ubsan/bounds-18.c: New test. > > * c-c++-common/ubsan/bounds-19.c: New test. > > * c-c++-common/ubsan/bounds-20.c: New test. > > * c-c++-common/ubsan/bounds-21.c: New test. > > Jakub > Marek