From patchwork Wed Jan 31 21:42:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 194968 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp41865dyc; Wed, 31 Jan 2024 13:44:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+poPc8DR5A6GvOB81AOx0ZNRFHkCSCi66UD8o1dnCgRoJBc2K+qE5uqdpu7OkbZmxvTtU X-Received: by 2002:a9d:7341:0:b0:6e0:fdc1:e66d with SMTP id l1-20020a9d7341000000b006e0fdc1e66dmr2753315otk.32.1706737439862; Wed, 31 Jan 2024 13:43:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706737439; cv=pass; d=google.com; s=arc-20160816; b=EP8lYz0LqxH8vN63iUhT0lraUnpmKTJz5eJ2Ew15SkX4Ft4/7dOI77E1NEkgHm0x0V /tbSfqD1zDBRznfiAlqKZ/SnTT6wDTQufOW1bR9Qbb+F+Tv9KB4eE+BZYeQNg84q/ytX 1xYZkDdQkgKijnk30HsO1h7WvB68vbeud00LyS9iUyCGKK7Vtvh11J7ly9ZV4DFyT3ff m9+SN+N2SumxoIz7DavU3mObkpSi7kLtqEo1FskK5TH5RcieTlytPUxo1Q6YMAmEExLJ RgkWYGILrRet4GM/AX/v2DBx5Wd2yNaC8TahcuX/v4Iz0PPh3GiOic8Txv0s+oGicqW8 723Q== 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:message-id:subject :to:from:date:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=VpMU9LdR/QYH5Vp5Ot0rrxwHVe4RjNgr/OriBSmUBso=; fh=UTJFA29GrVliLwnNZHV1ldjvCHfIvn798A4ShdXJmPI=; b=oc/96CSgx873VIevnisBZBq2553wsVO5thwLpm7cTUqYZeA8NpO4h8JnC1P7KmWBoE imdPWtNlnevyWr+Q9za+lsIBAjTOgqiB4138fNAjAbiQCB9oHJN68O79U9720MLLmQCw c8mEbjSyEQ+9Eqhl+NFl1ax3doPOme/UFxedJCzDYuWiOoDK9/EoyiT0uo+Db2DUTc6O rw6iWTPrXiBQrlWGwkmnswFy8HfZydH3+wwuaTOsA26+LjWp64xG45tMWiJY95Z7vVbf kwCkJB08lIqZihKpTnGY6lmE7bdwWx17gefwLVAwdoddU7pHnVccJhuokGDzOZUp/cqM lcZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="gyymkR3/"; 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=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCUSvj0L+XDh34tvI94/N62liB/cFY+fL08Z6uScmxW7wwCm4TOVRLLkJuTXS+WTpLt20GvPMRAEsb/5MJBGOEJ8V4I+dg== Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id v18-20020a05622a131200b0042beeffa954si1177192qtk.672.2024.01.31.13.43.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 13:43:59 -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=@redhat.com header.s=mimecast20190719 header.b="gyymkR3/"; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7721E3858D39 for ; Wed, 31 Jan 2024 21:43:59 +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 669D038582A9 for ; Wed, 31 Jan 2024 21:43:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 669D038582A9 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 669D038582A9 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=1706737400; cv=none; b=iiry+yg2KCrGVKYq3d4K8XsAAsMA5pO6Z6w8OKylS8j3dbGJnbhqmW4obr/+jA5ihpXchvNKyn858rDMA80hQ9jUGvuiQfm7lCBAIQWiKmars6k8lYUnxJss5l3cZ6PgtrKhibWknJPTdnEb5Ck+MWWcYv0h2MJAEeiHfVtqGSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706737400; c=relaxed/simple; bh=0pxqOvvF0Y4PL1r0nYIXvTyne4Fu9F74pCm/JRFloXo=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=SqpvulXf8zP+c1CzYZbA4ytLClHwLoG27+0CgN8gKZg5ExSi+aNwKoe8Ubb+/TlzUDgDFkSaaAn20AqVYSBcoiNsrHVS/V2QdUfohboP/kA0r7GuRKCVQVl2igzFhG7uzYIHrHvHuk/W78BSexp6MPSp49NBpF6XLU3VVJqDSyk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706737398; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=VpMU9LdR/QYH5Vp5Ot0rrxwHVe4RjNgr/OriBSmUBso=; b=gyymkR3/3qB3KPpPe2DWKCkU6BjDdYItW/wIw7xLjC+r7kk7oUc8FpOVVOTB/6iadMZk4r BQC/4xa10nQx1GNhOo+lopXsarlAf5wjFV/v44jc82SFJdMsUa7291qHlIy+sjJNMHYbRB BXoI+JuAkwM3oKKxJHdW/Fbbl4QSdI0= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-505-zrPRHfrGM6q86B9LjGuYvw-1; Wed, 31 Jan 2024 16:43:16 -0500 X-MC-Unique: zrPRHfrGM6q86B9LjGuYvw-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-33b0c264adbso105742f8f.0 for ; Wed, 31 Jan 2024 13:43:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706737395; x=1707342195; h=mime-version:message-id:subject:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=VpMU9LdR/QYH5Vp5Ot0rrxwHVe4RjNgr/OriBSmUBso=; b=lVv7/BCOjniYZ132pPEgdYtF1WGrjmN9qsHkcqV7MrRMveyrMFVMaVK4XxtW9H7LWz cCjXOO1akJ/PmgVSnVBE6Qj0sSLFV+lQZkD733H+Q7Wmv1HDcDf9VI2l6uvtdFqVYLJd pcFUeh6vGB4TEHhv1fqVC7/DNHc9kio0Z0xvUC2PyUamzn1ngZd8zbj7DrQidmQVwJuV rGfNr5ozyemFrKzaeqdN2NANy/uhGkEfA9e07sHr3v+OWJ56V4b8Wh+eijyMyKhAS7Tv u7/O2c4D1jmn3l1Vpyc3l2RhWRT4U6b+Dd4cnNtmU2JtJGaR0AuKmKvHNcn96nR6689M 2bEg== X-Gm-Message-State: AOJu0YyIYNNF+6g0gSJxBlAmS1MxttW42T8VXyJM/WqDWR3T+zBOv+Gk YsDM90jxlU84uBZFafL3+GAgHgw4eEleb4mraFXUj3tnIhiUSgZInfYk0eaLg4pv/0xbYXWz90v sKTq3nc+NeNRfuQzpgt8AOrKLEGOMYNGFC0suiEN/pMu4srDy7M2svS+n/4K1xQpPjpi9G6zVdF S4g2ZaKKWMTeFnX7yxWiFGYBnP0GvMBRErGsuhbrs= X-Received: by 2002:a5d:6442:0:b0:33b:eef:86bf with SMTP id d2-20020a5d6442000000b0033b0eef86bfmr718115wrw.25.1706737395398; Wed, 31 Jan 2024 13:43:15 -0800 (PST) X-Received: by 2002:a5d:6442:0:b0:33b:eef:86bf with SMTP id d2-20020a5d6442000000b0033b0eef86bfmr718108wrw.25.1706737394914; Wed, 31 Jan 2024 13:43:14 -0800 (PST) Received: from digraph.polyomino.org.uk (digraph.polyomino.org.uk. [2001:8b0:bf73:93f7::51bb:e332]) by smtp.gmail.com with ESMTPSA id r2-20020a05600c320200b0040ef04987e7sm2544935wmp.16.2024.01.31.13.43.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 13:43:14 -0800 (PST) Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.95) (envelope-from ) id 1rVILz-006N1Z-O6 for gcc-patches@gcc.gnu.org; Wed, 31 Jan 2024 21:42:43 +0000 Date: Wed, 31 Jan 2024 21:42:43 +0000 (UTC) From: Joseph Myers To: gcc-patches@gcc.gnu.org Subject: [committed] c: Fix ICE for nested enum redefinitions with/without fixed underlying type [PR112571] Message-ID: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789643917944389083 X-GMAIL-MSGID: 1789643917944389083 Bug 112571 reports an ICE-on-invalid for cases where an enum is defined, without a fixed underlying type, inside the enum type specifier for a definition of that same enum with a fixed underlying type. The ultimate cause is attempting to access ENUM_UNDERLYING_TYPE in a case where it is NULL. Avoid this by clearing ENUM_FIXED_UNDERLYING_TYPE_P in thie case of inconsistent definitions. Bootstrapped wth no regressions for x86_64-pc-linux-gnu. PR c/112571 gcc/c/ * c-decl.cc (start_enum): Clear ENUM_FIXED_UNDERLYING_TYPE_P when defining without a fixed underlying type an enumeration previously declared with a fixed underlying type. gcc/testsuite/ * gcc.dg/c23-enum-9.c, gcc.dg/c23-enum-10.c: New tests. --- Applied to mainline. Should also be backported to GCC 13 branch (the oldest version with support for enums with fixed underlying types), after waiting to see if any problems arise with the patch on mainline, subject to changing -std=c23 to -std=c2x for the older version and making sure the patch does indeed work on the older version (there have been significant changes renaming to redefinitions of tagged types in GCC 14 as part of Martin's tag compatibility work). diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 8d18a3e11f4..934e557dc3b 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -9905,8 +9905,11 @@ start_enum (location_t loc, struct c_enum_contents *the_enum, tree name, if (ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) && fixed_underlying_type == NULL_TREE) - error_at (loc, "% declared with but defined without " - "fixed underlying type"); + { + error_at (loc, "% declared with but defined without " + "fixed underlying type"); + ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = false; + } the_enum->enum_next_value = integer_zero_node; the_enum->enum_type = enumtype; diff --git a/gcc/testsuite/gcc.dg/c23-enum-10.c b/gcc/testsuite/gcc.dg/c23-enum-10.c new file mode 100644 index 00000000000..dd5f3453b1f --- /dev/null +++ b/gcc/testsuite/gcc.dg/c23-enum-10.c @@ -0,0 +1,6 @@ +/* PR c/112571. */ +/* { dg-do compile } */ +/* { dg-options "-std=c23" } */ + +enum X : typeof (enum X { A }); /* { dg-error "declared with but defined without fixed underlying type" } */ +/* { dg-error "invalid 'enum' underlying type" "invalid" { target *-*-* } .-1 } */ diff --git a/gcc/testsuite/gcc.dg/c23-enum-9.c b/gcc/testsuite/gcc.dg/c23-enum-9.c new file mode 100644 index 00000000000..10bb493ca3c --- /dev/null +++ b/gcc/testsuite/gcc.dg/c23-enum-9.c @@ -0,0 +1,8 @@ +/* PR c/112571. */ +/* { dg-do compile } */ +/* { dg-options "-std=c23" } */ + +enum h : typeof (enum h { D }) { D }; /* { dg-error "declared with but defined without fixed underlying type" } */ +/* { dg-error "invalid 'enum' underlying type" "invalid" { target *-*-* } .-1 } */ +/* { dg-error "nested redefinition" "nested" { target *-*-* } .-2 } */ +/* { dg-error "conflicting redefinition" "conflicting" { target *-*-* } .-3 } */