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.133.124]) by sourceware.org (Postfix) with ESMTPS id B78413858D33 for ; Thu, 9 Mar 2023 13:10:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B78413858D33 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=1678367418; h=from:from:reply-to: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=0/dtsd0sPhJhuJA6r4LwBu6V69KmPwnyQiTgohghf6k=; b=FXfZ3SufgQblSY6anhAZ1F7xoPe3WxOjJ2QSjahsgOf/EdEVOetPNL3dtCtsf364nBgTAA 2jeHKUVD8uxzKPtT+KNe83+Z1g5b/Xe+AKmLgIoCukrzvmS02sFYWn7sEUu/JQynjsK/6L MYvzOs1MfGMmGDrS31jteAQ2VGK5lyA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-390-dx7hgUwKMFGNNmEVZWIWVQ-1; Thu, 09 Mar 2023 08:10:14 -0500 X-MC-Unique: dx7hgUwKMFGNNmEVZWIWVQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8E01829AB40A; Thu, 9 Mar 2023 13:10:14 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4CC31140EBF4; Thu, 9 Mar 2023 13:10:14 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 329DABKU706077 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 9 Mar 2023 14:10:11 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 329DAAh1706076; Thu, 9 Mar 2023 14:10:10 +0100 Date: Thu, 9 Mar 2023 14:10:10 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] middle-end/108995 - avoid folding when sanitizing overflow Message-ID: Reply-To: Jakub Jelinek References: <20230308093849.51C183858C62@sourceware.org> MIME-Version: 1.0 In-Reply-To: <20230308093849.51C183858C62@sourceware.org> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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=-3.7 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 Wed, Mar 08, 2023 at 09:38:43AM +0000, Richard Biener via Gcc-patches wrote: > The following plugs one place in extract_muldiv where it should avoid > folding when sanitizing overflow. > > I'm unsure about the testcase, I didn't find any that tests for > a runtime sanitizer error ... > > Bootstrapped and tested on x86_64-unknown-linux-gnu. > > OK? > > PR middle-end/108995 > * fold-const.cc (extract_muldiv_1): Avoid folding > (CST * b) / CST2 when sanitizing overflow and we rely on > overflow being undefined. This is ok. > > * gcc.dg/ubsan/pr108995.c: New testcase. As for testcase, there are many testcases that test for runtime sanitizer errors. For ubsan, it is more common to test -fsanitize-recover= and just dg-output scan the output for expected diagnostics (many examples in that directory). Another possibility is to test for the no recovery, see e.g. gcc.dg/ubsan/bounds-3.c. In that case there should be /* { dg-do run } */ and /* { dg-shouldfail "ubsan" } */ but dg-output checking for the exact wording is still highly desirable. The test also relies on 32-bit ints, so it should be dg-do run { target int32 } I think. > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/ubsan/pr108995.c > @@ -0,0 +1,15 @@ > +/* { dg-do run { xfail *-*-* } } */ > +/* With optimization we constant fold and diagnose the overflow and do > + not sanitize anything. */ > +/* { dg-skip-if "" { *-*-* } { "*" } { ! "-O0" } } */ > +/* { dg-options "-fsanitize=undefined -fno-sanitize-recover=undefined" } */ > + > +int a; > +const int b = 44514; > +int *c = &a; > + > +int main () > +{ > + *c = 65526 * b / 6; > + return 0; > +} > -- > 2.35.3 Jakub