From patchwork Sat Jun 29 15:04:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Uecker X-Patchwork-Id: 1954264 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=tugraz.at header.i=@tugraz.at header.a=rsa-sha256 header.s=mailrelay header.b=dYFfOvzn; 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 4WBFwC0yyMz20Xg for ; Sun, 30 Jun 2024 01:04:57 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A4AE381576B for ; Sat, 29 Jun 2024 15:04:55 +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 2455C389941C for ; Sat, 29 Jun 2024 15:04:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2455C389941C 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 2455C389941C 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=1719673478; cv=none; b=Fsg2yt/ugjmgMJcTGrvjOLSWXSBKCLcm9IQ9lEiXb324KqRU7OG2Rzf4goqKLkCDCFFGXRAaftVXJZsr2IW+LEr+rwjvjBGHpqA5d2W1xvxVDDvyPjMG/KZn1YCoyDjY8pbvpO1Cr9D4E6r/Koz3ckHosy62OMmuWCxYMyn5ex0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719673478; c=relaxed/simple; bh=AltZONPsELqF6KEa7123BK1jmBCebVBlk23euwek81o=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=Z9/M7k/WKEZh6IVJU8syPRvPtNCJlvrXu4afB8ONHrPfpCWJ7wV+HLi/PeDG+f2I+wVzE3lzHP0iHy/Egs+/1LbdO7ULvBe7MqWW5/etXC1PIgSt7LtrhMfCHM7VY78yOv1FGbLz109LVvSu+99gV0/QYd4br5iwLubKh0DcnNk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from vra-170-35.tugraz.at (vra-170-35.tugraz.at [129.27.170.35]) by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4WBFvY4h2bz1LLF5; Sat, 29 Jun 2024 17:04:24 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 mailrelay.tugraz.at 4WBFvY4h2bz1LLF5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tugraz.at; s=mailrelay; t=1719673465; bh=KS/THBq85hoiWrRDtKsWc4Ynj7hogVXU0+R0aIuYpdg=; h=Subject:From:To:Cc:Date:From; b=dYFfOvznSFo6yS3Ywn5dT+Gf1L4cB0h/F+xOk6RVddAkDY+ktwWEy05DEui8yvt6u 2rF2V7Gc149IgMXuAFsvKTibYzIukcC55DuVJA7prTJH0AyloZG6J7drYT7hPwX2ok G3m09Sl6MszWvLcY/gz//Vfvk6QnJjSWrCJ9mUh8= Message-ID: Subject: [PATCH] c: Fix ICE for redeclaration of structs with different alignment [PR114727] From: Martin Uecker To: gcc-patches@gcc.gnu.org Cc: Joseph Myers , Marek Polacek Date: Sat, 29 Jun 2024 17:04:24 +0200 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.1 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 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 This fixes an ICE when redeclaring a struct and having an aligned attribute in one version in C23. Bootstrapped and regression tested on x86_64. c: Fix ICE for redeclaration of structs with different alignment [PR114727] For redeclarations of struct in C23, if one has an alignment attribute that makes the alignment different, we later get an ICE in verify_types. This patches disallows such redeclarations by declaring such types to be different. PR c/114727 gcc/c/ * c-typeck.cc (tagged_types_tu_compatible): Add test. gcc/testsuite/ * gcc.dg/pr114727.c: New test. diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index e486ac04f9c..455dc374b48 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -1603,6 +1603,9 @@ tagged_types_tu_compatible_p (const_tree t1, const_tree t2, != TYPE_REVERSE_STORAGE_ORDER (t2))) return false; + if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2)) + data->different_types_p = true; + /* For types already being looked at in some active invocation of this function, assume compatibility. The cache is built as a linked list on the stack diff --git a/gcc/testsuite/gcc.dg/pr114727.c b/gcc/testsuite/gcc.dg/pr114727.c new file mode 100644 index 00000000000..12949590ce0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr114727.c @@ -0,0 +1,6 @@ +/* { dg-do compile } + * { dg-options "-std=c23 -g" } */ + +#define Y [[gnu::aligned(128)]] +extern struct Y foo { int x; } x; +struct foo { int x; }; /* { dg-error "redefinition" } */