From patchwork Fri Mar 15 08:40:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1912417 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HhVYLdg+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TwyRH6kSKz23rx for ; Fri, 15 Mar 2024 19:42:03 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1C8BA3858D28 for ; Fri, 15 Mar 2024 08:42:01 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 974CB3858D28 for ; Fri, 15 Mar 2024 08:41:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 974CB3858D28 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 974CB3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710492066; cv=none; b=CYTA/+c8fV/CKaL51SyCdlRqLTCw2rp3oNPA1V7SbbS3hLpsn3fUR1oEJWnOJrhLgN0Le1Rhcqr5CGvvfRnMzUb2LPZgQln7UhhRMuEY6fzP0wY+/2+dlOZegWyM/RIKUoMU42lIsf74HVSDqxX3FPi6FKspcLQnjg3PytW+fv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710492066; c=relaxed/simple; bh=Ds3vNSx8kP7KN1q8wBCROmrBkj9rBB5981R/4XkaFXQ=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=Bm+Vs0+dtuli7H5ASkGvXeEoo0sqOVKSjD0yH1By02ELdCCD6CpUJgWviNBVfF3MePG7hZhz0VEqHH2Yq9uNREyR3NJsxNfG8OPlK60ItBgAG9gRmpRhQ+AOs9SThA4IVFxbomxQxgjBmyvvR3gzfeVQMbd8/ZzHrkT19b51zPw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710492060; 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=FS7qpfsjXvi2DX/oX7f57RGX4bVzztgTzxvak1GEPPI=; b=HhVYLdg+ZCiXAG2vLQl2X/6DqQLb91y6mY1Z4AZnMlWwpps62EvtBAKhn0nxVON//Pdo6A ruSNUgHMlHFyz0isGNK6Yhh0d5r6bHzOlmj9n+Q4motvbWGSU9HEABffcpf37XZ4/CyBE+ lW40VWLWdtRvxAP8zyCiAoyFatjLoL8= 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-19-bp_50Q3VNFOT63r4CNL5vA-1; Fri, 15 Mar 2024 04:40:55 -0400 X-MC-Unique: bp_50Q3VNFOT63r4CNL5vA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 C80F4185A783; Fri, 15 Mar 2024 08:40:54 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.225.36]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8D3C7492BD0; Fri, 15 Mar 2024 08:40:54 +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 42F8eqZI2930817 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 15 Mar 2024 09:40:52 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 42F8equo2930816; Fri, 15 Mar 2024 09:40:52 +0100 Date: Fri, 15 Mar 2024 09:40:52 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] expand: EXTEND_BITINT CALL_EXPR results [PR114332] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.9 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_H4, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! The x86-64 and aarch64 psABIs (and the unwritten ia64 psABI part) say that the padding bits of _BitInt are undefined, while the expansion internally typically assumes that non-mode precision integers are sign/zero extended and extends after operations. We handle that mismatch with EXTEND_BITINT done when reading from untrusted sources like function arguments, reading _BitInt from memory etc. but otherwise keep relying on stuff being extended internally (say in pseudos). The return value of a function is an ABI boundary though too and we need to extend that too. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-03-15 Jakub Jelinek PR middle-end/114332 * expr.cc (expand_expr_real_1): EXTEND_BITINT also CALL_EXPR results. Jakub --- gcc/expr.cc.jj 2024-03-04 19:20:27.120200885 +0100 +++ gcc/expr.cc 2024-03-14 19:22:50.623550538 +0100 @@ -12350,7 +12350,8 @@ expand_expr_real_1 (tree exp, rtx target return expand_builtin (exp, target, subtarget, tmode, ignore); } } - return expand_call (exp, target, ignore); + temp = expand_call (exp, target, ignore); + return EXTEND_BITINT (temp); case VIEW_CONVERT_EXPR: op0 = NULL_RTX; --- gcc/testsuite/gcc.dg/torture/bitint-64.c.jj 2024-03-14 19:50:41.051311949 +0100 +++ gcc/testsuite/gcc.dg/torture/bitint-64.c 2024-03-14 19:50:05.480806808 +0100 @@ -0,0 +1,22 @@ +/* PR middle-end/114332 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c23 -fwrapv" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +enum E { E22 = 22 } e = E22; + +_BitInt (5) +foo (void) +{ + _Atomic _BitInt (5) b = 0; + b += e; + return b; +} + +int +main () +{ + if (foo () != -10) + __builtin_abort (); +}