From patchwork Thu Feb 29 22:44:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 86616 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 98DB23858C39 for ; Thu, 29 Feb 2024 22:45:16 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta36.uswest2.a.cloudfilter.net (omta36.uswest2.a.cloudfilter.net [35.89.44.35]) by sourceware.org (Postfix) with ESMTPS id 386173858D34 for ; Thu, 29 Feb 2024 22:44:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 386173858D34 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 386173858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709246692; cv=none; b=RT5UtO5Hl/T92fVyovf7WKAmRz+ZlFLpSVfF+rqmcCG8Bz1u2u70F6FIjmMChvkzucreHiAIeSZUEL9tgMiOpW0ulMwJGU0HAAGsfi2JGnopQIJlUqWOGq6G/DkZqFHRqiA8gOsCF+MiGuDqMUVy3EFj9NbHdA28FFSIIw4b+l4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709246692; c=relaxed/simple; bh=d00Zdve/17qSpZwP+Dgf1a06INRqp3TlntEPcI0bztM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=gDw75F1mlgQf/dsuWdDF5dfsOdZgfD4rYXTvdOFRZ1fBqoIDpUmsOYi8ZG7XWe5UVYP9BqKmH+o55T3vTI1IQdNSB0zosEhHrOfbCpDzCJ2I47TCJ4l6vNqJHDrMctu/HblIMQBkfOP61zQLeaN46AYR78EI5srCjWETqS2rmeo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5008a.ext.cloudfilter.net ([10.0.29.246]) by cmsmtp with ESMTPS id fc5DrwOzEtf2Qfp8zrkP1w; Thu, 29 Feb 2024 22:44:49 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id fp8yrUFLvfEbyfp8yr2ACs; Thu, 29 Feb 2024 22:44:48 +0000 X-Authority-Analysis: v=2.4 cv=Uv1lNfwB c=1 sm=1 tr=0 ts=65e108e0 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=k7vzHIieQBIA:10 a=Qbun_eYptAEA:10 a=CCpqsmhAAAAA:8 a=v2HQjTBZQE6l1kAc5SYA:9 a=ul9cdbp4aOFLsgKbc677:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=QbvxjpRxqe9/3JS2oalcqflUixXo/Oln/JbqJmvUoKk=; b=aEJmCxHjiCgCG4xwJB++bDq1Pf u+qawYBbPZTYw1zDEMyshtXWzrkxv/7zxbuvEk/lY+V0lEYttbX4KGQ9EuMcEckNTMIR8m0ouCMZx n8tJOxjjGJ8m5S5E4wHY1LtJ/; Received: from 71-211-170-195.hlrn.qwest.net ([71.211.170.195]:57584 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1rfp8x-001PsJ-36; Thu, 29 Feb 2024 15:44:48 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Pass alignment when using GCC_C_FE_VERSION_2 Date: Thu, 29 Feb 2024 15:44:38 -0700 Message-ID: <20240229224438.2263524-1-tom@tromey.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.170.195 X-Source-L: No X-Exim-ID: 1rfp8x-001PsJ-36 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-170-195.hlrn.qwest.net (localhost.localdomain) [71.211.170.195]:57584 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfM4Py4dt0dDwtMxEORyxv/7uDvVEUFG+/3NDAHf2WNNgP8ynJBZifgzyC2Bu7gOy4LqDO4WjPWvGmgbSWteLoJFe8BPTyldFOB+FJiFfrc9SxGrIkB5C exqekVu+fLaBzViuejy8bM3Fr3UdCeNFnYVhNMa033P84HH8ue+Za9m0mZ54q34YG016CqJxy9uhsTdLUMKk24yH4AHyQZMWlGU= X-Spam-Status: No, score=-3021.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_NUMSUBJECT, 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: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org When the GCC compiler plugin responds with GCC_C_FE_VERSION_2, gdb can use the new 'finish_record_with_alignment' method. This lets gdb pass alignment information to the compiler, which in turn fixes the test case included in this patch. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31397 --- gdb/compile/compile-c-types.c | 6 +++++- gdb/testsuite/gdb.compile/compile.c | 7 +++++++ gdb/testsuite/gdb.compile/compile.exp | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c index 1bfaefc4933..1243be369f8 100644 --- a/gdb/compile/compile-c-types.c +++ b/gdb/compile/compile-c-types.c @@ -118,7 +118,11 @@ convert_struct_or_union (compile_c_instance *context, struct type *type) type->field (i).loc_bitpos ()); } - context->plugin ().finish_record_or_union (result, type->length ()); + if (context->plugin ().version () >= GCC_C_FE_VERSION_2) + context->plugin ().finish_record_with_alignment (result, type->length (), + type_align (type)); + else + context->plugin ().finish_record_or_union (result, type->length ()); return result; } diff --git a/gdb/testsuite/gdb.compile/compile.c b/gdb/testsuite/gdb.compile/compile.c index 8170a3af5ab..04beae823c8 100644 --- a/gdb/testsuite/gdb.compile/compile.c +++ b/gdb/testsuite/gdb.compile/compile.c @@ -100,6 +100,13 @@ int globalshadow = 10; static int staticshadow = 20; int externed = 7; +struct struct_with_array +{ + char val[7]; +}; + +static struct struct_with_array swa; + int main (void) { diff --git a/gdb/testsuite/gdb.compile/compile.exp b/gdb/testsuite/gdb.compile/compile.exp index fed7b04a4c3..f522a84d5dd 100644 --- a/gdb/testsuite/gdb.compile/compile.exp +++ b/gdb/testsuite/gdb.compile/compile.exp @@ -397,3 +397,6 @@ gdb_test "p globalvar" " = 1" "expect 1" gdb_test_no_output "compile code shlibvar += 5;" "modify shared library variable" gdb_test "p shlibvar" " = 15" "expect 15" + +# This used to fail due to alignment. PR compile/31397. +gdb_test_no_output "compile code swa.val\[0\] = 1"