From patchwork Sat Jan 20 18:37:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Uecker X-Patchwork-Id: 189754 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp1755337dyb; Sat, 20 Jan 2024 10:38:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGd6c752zPmj+VmJEvRetr8G3w5XCxS41GowWcVAjwf7znNsyCb3c0SCG1CtjxohMOK9Xu6 X-Received: by 2002:a05:6808:1915:b0:3bb:cffe:d893 with SMTP id bf21-20020a056808191500b003bbcffed893mr1624560oib.48.1705775903098; Sat, 20 Jan 2024 10:38:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705775903; cv=pass; d=google.com; s=arc-20160816; b=L0FfOnNF2yIWz0DgafGJn67YhaBtJ6vuWZUK2Aw/874kUlDtX73aVk3MiIPZMmyJzM KfVP8KDT1RQERy2bZbv1Hm8R04LFbuop+rvv0g9A3maDybLRNTCY6KL3e7RvJWDdBfod poikX6TzG4HfpS4CB+b6XNgPUp0nuD07OFurMgQ0EFvXiBRvij0bLyEQnXgqmfhrCh9V iZNG+hOffo1OEvfg6SxNYjn8tbFA2Ffuq6reDDDK6bsEc4lq4PFN6ud07pqABg2c5Fgk DHDTs+j7sY69o/wV8NhB2kkaPq6cnuqrBKEcY6c8CDUilm+k0NmsOscq+7sDIScofrfR u/gA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent :content-transfer-encoding:date:cc:to:from:subject:message-id :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=0Etswa9YXrDU24d1CEljxkWDofTTE8f3J5xoVy9aODI=; fh=k5BQ3iYuwFTza1Z/H+kMrb8l2Z70j0hdnX84UNatFtM=; b=sCkFFwotUDzItGBZphn4qpvq7z/uXjGKof8HrDzCY88+nA+qCZ79SJ73vKp7mmQTOo hc56WDGNkFb2TPigsS10tyboPQ6yROawCgFpUKAyZuRtz4uK8pRsYbM9AM2L3edWlS/h PnEklqPDgWRuzyZP/YWbRHy+X09vaXtU2Mxx8HlNQOFMzCzwKjm9uqxWuwjF+7ZIaMnl iQvi8zfBcNgz8YMvNdktzmt1+hwfjGsjkXW8qtzWNvyUNWtx4/QdeUcwyZwWrGDhm6DK 9Ymu86+3yAKcPbF91t59ohhhv1m9Hsosy9lzWF0NRKjZRZPayXOf/rG5euRirQRrUdNP Wvbw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tugraz.at header.s=mailrelay header.b=heOHlAIc; arc=pass (i=1); 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=QUARANTINE sp=NONE dis=NONE) header.from=tugraz.at Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w17-20020ac857d1000000b00429c9669e43si1975467qta.755.2024.01.20.10.38.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 10:38:23 -0800 (PST) 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=@tugraz.at header.s=mailrelay header.b=heOHlAIc; arc=pass (i=1); 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=QUARANTINE sp=NONE dis=NONE) header.from=tugraz.at Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C96873858428 for ; Sat, 20 Jan 2024 18:38:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mailrelay.tugraz.at (mailrelay.tugraz.at [129.27.2.202]) by sourceware.org (Postfix) with ESMTPS id BECFB3858D39 for ; Sat, 20 Jan 2024 18:37:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BECFB3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=tugraz.at Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tugraz.at ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BECFB3858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=129.27.2.202 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705775863; cv=none; b=Au7h+HkIwrSDJJRnt/BjgCiZENOYor0UVxCzJWSPkHfLPJbhzkczYlhJKDzvnNWzVKJCZuCHUt9VXPMDSCz7EgvzhRhV8QSVdt1mlQWdAd78XB7Sup8ld9wyfxCF31N1KoP0a1Xw/e3d3qteiMoiTgzj2T5waOk/R5P25R5r5Fo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705775863; c=relaxed/simple; bh=uTlQ4qC6RaBPhm3G+U7dkpmSkx4qeeaLSy+WZlUepj4=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=tD0UFmG/T3dKmd6OSXlJCeUA2XUVPj6CkjskU22JKO51FdJ/GKbrBp8hFDnJXA4PGlEb7mxQ9B+CiNl2MmtzCgeeHPShlP9YNHYNkBBLTkGaZAOP7a7AyjziI06t/+2ye0hhCJVPxEhtJhkNH5MNdq80Xi875+PXVq+bwCWgjYY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from vra-174-249.tugraz.at (vra-174-249.tugraz.at [129.27.174.249]) by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4THQFk1Qpbz3wD1; Sat, 20 Jan 2024 19:37:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tugraz.at; s=mailrelay; t=1705775850; bh=0Etswa9YXrDU24d1CEljxkWDofTTE8f3J5xoVy9aODI=; h=Subject:From:To:Cc:Date; b=heOHlAIcFUFs6AqvXOlE/G9q0jhKdX09hB6hT2a6q1W/BRDnvk772xz8da5uwCxUC KyDP4A3GZ31uIJQGX6BRMQCfGtH/bZM9RDXiWSgTQaQEWAPtt1/Va+Yr+p1rXPguJJ cZtjiAe2Cj1V4X8PoBdISWW1G6NFLt10UvQct1TM= Message-ID: <75930f8a30c3de6c45988fb0f8762ef07cad23a9.camel@tugraz.at> Subject: [C PATCH] Fix ICE for composite type for structs with unsigned bitfields [PR113492] From: Martin Uecker To: gcc-patches@gcc.gnu.org Cc: Joseph Myers Date: Sat, 20 Jan 2024 19:37:29 +0100 User-Agent: Evolution 3.46.4-2 MIME-Version: 1.0 X-TUG-Backscatter-control: G/VXY7/6zeyuAY/PU2/0qw X-Spam-Scanner: SpamAssassin 3.003001 X-Spam-Score-relay: -1.9 X-Scanned-By: MIMEDefang 2.74 on 129.27.10.117 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788635673401969657 X-GMAIL-MSGID: 1788635673401969657 C23: Fix ICE for composite type for structs with unsigned bitfields [PR113492] This patch fixes a bug when forming a composite type from structs that contain an unsigned bitfield declared with int while using -funsigned-bitfields. In such structs the unsigned integer type was not compatible to the regular unsigned integer type used elsewhere in the C FE. PR c/113492 gcc/c: * c-decl.cc (grokdeclarator): Use c_common_unsigned_type instead of unsigned_type_for to create the unsigned type for bitfields declared with int when using -funsigned-bitfields. gcc/testsuite: * gcc.dg/pr113492.c: New test. diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 4029bbc59fe..8d18a3e11f4 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -6947,7 +6947,7 @@ grokdeclarator (const struct c_declarator *declarator, "signed". */ if (bitfield && !flag_signed_bitfields && !declspecs->explicit_signed_p && TREE_CODE (type) == INTEGER_TYPE) - type = unsigned_type_for (type); + type = c_common_unsigned_type (type); /* Figure out the type qualifiers for the declaration. There are two ways a declaration can become qualified. One is something diff --git a/gcc/testsuite/gcc.dg/pr113492.c b/gcc/testsuite/gcc.dg/pr113492.c new file mode 100644 index 00000000000..56296c51072 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr113492.c @@ -0,0 +1,43 @@ +/* PR 113492 + * { dg-do compile } + * { dg-options "-std=c23 -funsigned-bitfields" } */ + +struct foo { + int i : 3; +} i; + +void test() +{ + struct foo { + unsigned i : 3; + } u; + + 1 ? i : u; + 1 ? u : i; +} + +struct bar { + unsigned i : 3; +} u; + +void test2() +{ + struct bar { + int i : 3; + } i; + + 1 ? i : u; + 1 ? u : i; +} + +void test3() +{ + typedef int myint; + struct bar { + myint i : 3; + } i; + + 1 ? i : u; + 1 ? u : i; +} +