From patchwork Wed Oct 19 08:02:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 4470 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp189645wrs; Wed, 19 Oct 2022 01:03:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4xTH6UsxGZDLq6LgG4hJ7kTVy1ycMY8fS0l38I+gucaAGYNjT78HAql7vIgCRTz/EXtNHA X-Received: by 2002:a17:907:2ceb:b0:78d:b765:c50d with SMTP id hz11-20020a1709072ceb00b0078db765c50dmr5593514ejc.73.1666166581824; Wed, 19 Oct 2022 01:03:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666166581; cv=none; d=google.com; s=arc-20160816; b=Nm0GKizZyKo4FblB8sMf2jUZBeyy4aKWeKG55qsWhU3tTY77mpqwa1TAE8S2p9GsAb rAJViHRYAkDCQ+kitGwDU4W1QExhPVlGa5aR6Ix50CH6VZ8mbgjPNOtcGI8eab4lS70x eqnbi3DoRvGwIEQjYtKoM1DJ8K0gz3cheu/5hEUhA58si7Ll+ZGtrim8hjKI4bIkFyTx 84XTTuYW+KXFizmlpzGkcMhSVMFykgjFFXahYQ8S8LnUWl/lXOFoxM8NlvOxSnENVhVA UXnG/E/wvHgYro1dHW5eoF1aN2iSrVFltXhnUGk2NyWmdU4IKDF2IkKgMrJfaDZk2KIq vsWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Cr5SVtCVJTnYo2EnNyWPsMWMfj3uTmPVJkcdOfM90Wo=; b=lT+WNO7Z0eUPJs7grMktGx6Y2m2rdNYiAIPDA5Xo+n4O5dy4/jsuazByOR78TmuSVe 3qcgFaG4r4YJCo1o7PDbUbQJP6UNYjswnA0XVbp+IqKP+JEgl5xOutRwRT0EpjmJYBl2 9gEw53uM224eTEJ4YfzDMOLePUcVOm7OJ+s9QWqqj3Rlm7Hj2ihMZRPjjaFoXCAvhEfr rn6OgCs5XjU9sqciQ5xqmjHAP2NnLn+JAcen8jOxeCh2a0imhPm1uRgF/hRMZ/3DEYoy wPz35wWll2uxgA339SB6YS4Gu1VZJuymZrzvok2SKgVv7i3uLK7CQDWah20s+DnmUXpM c2LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bPv1ZXln; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id sa28-20020a1709076d1c00b0078d42f9d0ddsi13496786ejc.477.2022.10.19.01.03.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 01:03:01 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=bPv1ZXln; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C4535385829F for ; Wed, 19 Oct 2022 08:03:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C4535385829F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666166580; bh=Cr5SVtCVJTnYo2EnNyWPsMWMfj3uTmPVJkcdOfM90Wo=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=bPv1ZXlnNG+BG87UuBiAjy5SuKL9SWF9yq8jdlKFkh5mMQDr7Ef1EIYJlppqjVfSu 3MNb9UXqmhJVynvfbKllLLGkrDNSXLuyW3MOdtutmFan1p9ac8/fCBuxbyglyc+80j DyWayLND7pnL++GuGvTRX306msHxSDx9Sl1oVhLE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 7C4103858D39 for ; Wed, 19 Oct 2022 08:02:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7C4103858D39 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-290-TjIQuxDkM8OdG1CYe6dHfg-1; Wed, 19 Oct 2022 04:02:15 -0400 X-MC-Unique: TjIQuxDkM8OdG1CYe6dHfg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8A269811E75; Wed, 19 Oct 2022 08:02:15 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.252]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 49F102024CBB; Wed, 19 Oct 2022 08:02:15 +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 29J82C0r3797147 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 19 Oct 2022 10:02:13 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 29J82BWd3797146; Wed, 19 Oct 2022 10:02:11 +0200 Date: Wed, 19 Oct 2022 10:02:11 +0200 To: Richard Biener Subject: [PATCH] match.pd: Add 2 TYPE_OVERFLOW_SANITIZED checks [PR106990] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.8 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747102289146979624?= X-GMAIL-MSGID: =?utf-8?q?1747102289146979624?= Hi! As requested in the PR, this adds 2 TYPE_OVERFLOW_SANITIZED checks and corresponding testcase. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-10-19 Jakub Jelinek PR tree-optimization/106990 * match.pd ((~X - ~Y) -> Y - X, -x & 1 -> x & 1): Guard with !TYPE_OVERFLOW_SANITIZED (type). * c-c++-common/ubsan/pr106990.c: New test. Jakub --- gcc/match.pd.jj 2022-10-13 15:51:08.928071208 +0200 +++ gcc/match.pd 2022-10-18 16:01:12.145705958 +0200 @@ -1331,8 +1331,9 @@ (define_operator_list SYNC_FETCH_AND_AND /* (~X - ~Y) -> Y - X. */ (simplify (minus (bit_not @0) (bit_not @1)) - (with { tree utype = unsigned_type_for (type); } - (convert (minus (convert:utype @1) (convert:utype @0))))) + (if (!TYPE_OVERFLOW_SANITIZED (type)) + (with { tree utype = unsigned_type_for (type); } + (convert (minus (convert:utype @1) (convert:utype @0)))))) /* ~(X - Y) -> ~X + Y. */ (simplify @@ -8176,5 +8177,6 @@ and, /* -x & 1 -> x & 1. */ (simplify - (bit_and (negate @0) integer_onep@1) - (bit_and @0 @1)) + (bit_and (negate @0) integer_onep@1) + (if (!TYPE_OVERFLOW_SANITIZED (type)) + (bit_and @0 @1))) --- gcc/testsuite/c-c++-common/ubsan/pr106990.c.jj 2022-10-18 15:56:20.260656260 +0200 +++ gcc/testsuite/c-c++-common/ubsan/pr106990.c 2022-10-18 16:17:37.295403933 +0200 @@ -0,0 +1,29 @@ +/* PR tree-optimization/106990 */ +/* { dg-do run { target int32 } } */ +/* { dg-options "-fsanitize=signed-integer-overflow" } */ + +__attribute__((noipa)) int +foo (void) +{ + int x = -1956816001; + int y = 1999200512; + return ~x - ~y; +} + +__attribute__((noipa)) int +bar (void) +{ + int x = -__INT_MAX__ - 1; + return -x & 1; +} + +int +main () +{ + foo (); + bar (); + return 0; +} + +/* { dg-output "signed integer overflow: 1956816000 - -1999200513 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself" } */