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: 1893662 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=gyymkR3/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4TQFsS1nfmz23fD for ; Thu, 1 Feb 2024 08:43:40 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 11F9338582B4 for ; Wed, 31 Jan 2024 21:43:38 +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-Google-Smtp-Source: AGHT+IHM+5p3mgvhFHyTUOX+JcmmXhdH7mnZmN2eozirdLqSiN5UUry9JaFtl1UxX6aImZaKkr1A9w== 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 } */