Message ID | ZbIYp9p5+xUM8lb8@tucnak |
---|---|
State | Unresolved |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1491559dyi; Thu, 25 Jan 2024 00:16:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFj0PGCHb0k/snOfTUZX6vxqFTPEXe2FRlJDJqOW3/kmt6Vqd+iR2P3rmcN01KaFCIPZJBC X-Received: by 2002:a05:622a:20a:b0:42a:20ab:3bf9 with SMTP id b10-20020a05622a020a00b0042a20ab3bf9mr604000qtx.89.1706170595565; Thu, 25 Jan 2024 00:16:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706170595; cv=pass; d=google.com; s=arc-20160816; b=hDo95ApXRjwOVRfd68e+33PthWIz9IWR9qEG0gfaR/8zb9yoArmib/TDULS3Wqt56H iod3nGIQRqTb2pzY5NpCKhmYvOjpGhj+3T6TfpVnYVZ4sX3V5OCgIiWqnLK78+Mf7Ox3 IWyFYx4ZTIHiyccXquHtXyvQmFnpG0O3I+aQw4X7Nw223PS0tUk4rfW2QcWWE5qcNnQG vpt1xVLCtVmt3osdcTVDIhvwAa3OrJXYzuhMnHemUsjuvIkAKWTDB/Xxowj/Lwp/uTRX vKMGGJleJmATdpjsFt9IKx2nt8amh7O3pCGtr0/OriRSV/beGuRhFrO7WpaPmlwoqgWv 1ZdA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=FBuSD9jrPa1Q2nYRJMCgwCdVpJJFeOehmwe4BxC0i4Q=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=GCgYSl0XsdmoZDHDlZ3l2oJaucPLHDNIMaTmhB15l8xg8heQ7zhQTVbtTcDU/2EiHo v1X8VGT9Jc0vpeB5s7O5Z+XBu3KyrjhFcFqNa6A1k0TjYdI7Z9lgYUYsttr8ttMskBGU p586lLBKmJq7KbPrhzaC3Ygwp5r596zGEeUrEUdXnLzEXKGROb6LJlLKT+Do90VGO43Y lvp55CdqDlGADhhqyu4cLo4OMJuyo/EzlOiriYvgdwNDUvBjp0Pdkar8mWSA6RWhUEVC 6PTzI513R6Qw/WgYAjoXT8OKSyzliNUCvyJhc48rm3T0AeBPtsIt8Shldei84gZwre0z 7iQw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=el4w0zEo; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 4-20020ac84e84000000b0042a5bd82617si3703621qtp.321.2024.01.25.00.16.35 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 00:16:35 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=el4w0zEo; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 45B593858C52 for <ouuuleilei@gmail.com>; Thu, 25 Jan 2024 08:16:35 +0000 (GMT) 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 98A213858D38 for <gcc-patches@gcc.gnu.org>; Thu, 25 Jan 2024 08:15:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 98A213858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 98A213858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706170545; cv=none; b=cNgh1dd4Z5uq85SprSNapBkx9GuXSu8/hC+0fQzuyH5Fha8NuhXHFXxMyBiU99wYBiUOldZ+QNkMZOD4iNBjgfX7oUDtWN5WckCtNIhGE0Edda7QToUbxNGxz4SZT+sJtNHVjlRWxnwLqV+uXHSHgpAhMlN5XbIc64T+eSCu96M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706170545; c=relaxed/simple; bh=X7BrUJc/9FNxxusKZcgZHk7zSA+j/yb8BMFrT58YzYU=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=UwQ9go+yX20H7WYDNHVO1iR8BhDxLaWsD9r7QjxdEKhMliwquORs/nbLFO4ZG3uTUMEtpZw9B3mcxVUcpa20K/2CRYuCtO1xaAYgEJKPCY70S/KO2Ch6tFDdX6u2S3stDvnX4FGA4yVJ7X9JUcIPjtZ1dF1M8IInSTznuzT74/I= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706170543; 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; bh=FBuSD9jrPa1Q2nYRJMCgwCdVpJJFeOehmwe4BxC0i4Q=; b=el4w0zEoLDu23clzu9QuBTBVdfOULf5hZPWH6Z6tl5TULmuD056IfLGojemlh1v1lJU7fO Ana3W+0oVhYstopj76LJWRrJLhcBfMI1mTcUtcP1kwWTpimayQP8+5WgO0I2auAt3CqC8M SSZGowaO+obEmJgCINiH7amiCXjaxCs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-216-WDiMlpF8NAuhM_BRHhuSTg-1; Thu, 25 Jan 2024 03:15:39 -0500 X-MC-Unique: WDiMlpF8NAuhM_BRHhuSTg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5B5A3185A785; Thu, 25 Jan 2024 08:15:39 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1F9DA2166B32; Thu, 25 Jan 2024 08:15:39 +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 40P8Faqx335036 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 25 Jan 2024 09:15:37 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 40P8FakL335035; Thu, 25 Jan 2024 09:15:36 +0100 Date: Thu, 25 Jan 2024 09:15:35 +0100 From: Jakub Jelinek <jakub@redhat.com> To: Richard Biener <rguenther@suse.de> Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] convert: Fix test for out of bounds shift count [PR113574] Message-ID: <ZbIYp9p5+xUM8lb8@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 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=-4.2 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_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.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> Reply-To: Jakub Jelinek <jakub@redhat.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789049538494271173 X-GMAIL-MSGID: 1789049538494271173 |
Series |
convert: Fix test for out of bounds shift count [PR113574]
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Jakub Jelinek
Jan. 25, 2024, 8:15 a.m. UTC
Hi! The following patch is miscompiled, because convert_to_integer_1 for LSHIFT_EXPR tests if the INTEGER_CST shift count is too high, but incorrectly compares it against TYPE_SIZE rather than TYPE_PRECISION. The type in question is unsigned _BitInt(1), which has TYPE_PRECISION 1, TYPE_SIZE 8, and the shift count is 2 in that case. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-01-25 Jakub Jelinek <jakub@redhat.com> PR middle-end/113574 * convert.cc (convert_to_integer_1) <case LSHIFT_EXPR>: Compare shift count against TYPE_PRECISION rather than TYPE_SIZE. * gcc.dg/torture/bitint-52.c: New test. Jakub
Comments
On Thu, 25 Jan 2024, Jakub Jelinek wrote: > Hi! > > The following patch is miscompiled, because convert_to_integer_1 for > LSHIFT_EXPR tests if the INTEGER_CST shift count is too high, but > incorrectly compares it against TYPE_SIZE rather than TYPE_PRECISION. > The type in question is unsigned _BitInt(1), which has TYPE_PRECISION 1, > TYPE_SIZE 8, and the shift count is 2 in that case. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? OK. > 2024-01-25 Jakub Jelinek <jakub@redhat.com> > > PR middle-end/113574 > * convert.cc (convert_to_integer_1) <case LSHIFT_EXPR>: Compare shift > count against TYPE_PRECISION rather than TYPE_SIZE. > > * gcc.dg/torture/bitint-52.c: New test. > > --- gcc/convert.cc.jj 2024-01-03 11:51:24.000000000 +0100 > +++ gcc/convert.cc 2024-01-24 17:29:56.328124611 +0100 > @@ -762,7 +762,8 @@ convert_to_integer_1 (tree type, tree ex > { > /* If shift count is less than the width of the truncated type, > really shift. */ > - if (tree_int_cst_lt (TREE_OPERAND (expr, 1), TYPE_SIZE (type))) > + if (wi::to_widest (TREE_OPERAND (expr, 1)) > + < TYPE_PRECISION (type)) > /* In this case, shifting is like multiplication. */ > goto trunc1; > else > --- gcc/testsuite/gcc.dg/torture/bitint-52.c.jj 2024-01-24 17:33:42.174986825 +0100 > +++ gcc/testsuite/gcc.dg/torture/bitint-52.c 2024-01-24 17:33:33.395108814 +0100 > @@ -0,0 +1,23 @@ > +/* PR middle-end/113574 */ > +/* { dg-do run { target bitint } } */ > +/* { dg-options "-std=c23 -pedantic-errors" } */ > +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ > +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ > + > +unsigned _BitInt(1) a; > +unsigned _BitInt(8) b; > + > +void > +foo (unsigned _BitInt(16) x) > +{ > + a += (x << 2) | b; > +} > + > +int > +main () > +{ > + foo (0xfef1uwb); > + if (a) > + __builtin_abort (); > + return 0; > +} > > Jakub > >
--- gcc/convert.cc.jj 2024-01-03 11:51:24.000000000 +0100 +++ gcc/convert.cc 2024-01-24 17:29:56.328124611 +0100 @@ -762,7 +762,8 @@ convert_to_integer_1 (tree type, tree ex { /* If shift count is less than the width of the truncated type, really shift. */ - if (tree_int_cst_lt (TREE_OPERAND (expr, 1), TYPE_SIZE (type))) + if (wi::to_widest (TREE_OPERAND (expr, 1)) + < TYPE_PRECISION (type)) /* In this case, shifting is like multiplication. */ goto trunc1; else --- gcc/testsuite/gcc.dg/torture/bitint-52.c.jj 2024-01-24 17:33:42.174986825 +0100 +++ gcc/testsuite/gcc.dg/torture/bitint-52.c 2024-01-24 17:33:33.395108814 +0100 @@ -0,0 +1,23 @@ +/* PR middle-end/113574 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c23 -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +unsigned _BitInt(1) a; +unsigned _BitInt(8) b; + +void +foo (unsigned _BitInt(16) x) +{ + a += (x << 2) | b; +} + +int +main () +{ + foo (0xfef1uwb); + if (a) + __builtin_abort (); + return 0; +}