From patchwork Thu Feb 29 12:10:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 86587 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 E7A353858416 for ; Thu, 29 Feb 2024 12:11:29 +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 30C6E3858C52 for ; Thu, 29 Feb 2024 12:10:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 30C6E3858C52 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 30C6E3858C52 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=1709208665; cv=none; b=oU5ENZMMKVl8T5siEJWlm0DXu1pAFxx7DD120EJdrFfusAMUPyXNQbQCMv0z7XjIpuZbv0+pPVXsQjDIMIqAMTU5nVHjN4impepYhjBedVSv2N26hArU3geJQmSG7UjB1cP5Id182bcB2LjHnaXAZtAhS0G5ikr3ppEDVadJf+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709208665; c=relaxed/simple; bh=OoeXFjptslBO/0awDdnYv190mMU70F4/0GUiNBnBXtA=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=IgDEqzk4QI7o7j5EKAK3MqDTnco3uzRjEbC5GVnKEJBaUkin5iSjJZIw7ueaU0XnvhZfwc73apSlCHxGSQLVqBlsc4hPDtIzJCm8FgcI6NnG1M7zRNfTVmXQzU8oJTpLpjlyDuFwOmWwlkjV9npa+IS9FWS1ytKWCNRpeh2g9+U= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709208655; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=8DDiQGvQaPkQ98pQ79aEBX/AckQUyESi/TBmFeW/X2w=; b=dAZYALarnDbMMMnnfRawMSvdIeSNgbpQRb1+IxxiwdOsMjCqFnZhMMp/H0KiA0LujgnHEs bt8JfhOYeIcFgUdJxNXPKIKMNkA6L46JhsJpreP+jrKM1mIUF8Jd7jUdLTvWv7qEjmPswX i2k40U61guIVQXp+7nyZpakoSTD+yhU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-101-GbB2gAZWOsiheffvsz_0UA-1; Thu, 29 Feb 2024 07:10:54 -0500 X-MC-Unique: GbB2gAZWOsiheffvsz_0UA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EC09A10B7263 for ; Thu, 29 Feb 2024 12:10:53 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B08C21121312; Thu, 29 Feb 2024 12:10:53 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 41TCAp4N1804827 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 29 Feb 2024 13:10:51 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 41TCApvb1804826; Thu, 29 Feb 2024 13:10:51 +0100 Date: Thu, 29 Feb 2024 13:10:50 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] dwarf2out: Don't move variable sized aggregates to comdat [PR114015] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Hi! The following testcase ICEs, because we decide to move that struct { char a[n]; } DW_TAG_structure_type into .debug_types section / DW_UT_type DWARF5 unit, but refer from there to a DW_TAG_variable (created artificially for the array bounds). Even with non-bitint, I think it is just wrong to use .debug_types section / DW_UT_type for something that uses DW_OP_fbreg and similar in it, things clearly dependent on a particular function. In most cases, is_nested_in_subprogram (die) check results in such aggregates not being moved, but in the function parameter type case that is not the case. The following patch fixes it by returning false from should_move_die_to_comdat for non-constant sized aggregate types, i.e. when either we gave up on adding DW_AT_byte_size for it because it wasn't expressable, or when it is something non-constant (location description, reference, ...). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-02-29 Jakub Jelinek PR debug/114015 * dwarf2out.cc (should_move_die_to_comdat): Return false for aggregates without DW_AT_byte_size attribute or with non-constant DW_AT_byte_size. * gcc.dg/debug/dwarf2/pr114015.c: New test. Jakub --- gcc/dwarf2out.cc.jj 2024-02-17 01:14:48.157790666 +0100 +++ gcc/dwarf2out.cc 2024-02-28 17:11:44.259252850 +0100 @@ -8215,6 +8215,15 @@ should_move_die_to_comdat (dw_die_ref di || is_nested_in_subprogram (die) || contains_subprogram_definition (die)) return false; + if (die->die_tag != DW_TAG_enumeration_type) + { + /* Don't move non-constant size aggregates. */ + dw_attr_node *sz = get_AT (die, DW_AT_byte_size); + if (sz == NULL + || (AT_class (sz) != dw_val_class_unsigned_const + && AT_class (sz) != dw_val_class_unsigned_const_implicit)) + return false; + } return true; case DW_TAG_array_type: case DW_TAG_interface_type: --- gcc/testsuite/gcc.dg/debug/dwarf2/pr114015.c.jj 2024-02-28 17:22:33.206221495 +0100 +++ gcc/testsuite/gcc.dg/debug/dwarf2/pr114015.c 2024-02-28 17:21:49.357831730 +0100 @@ -0,0 +1,14 @@ +/* PR debug/114015 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-g -fvar-tracking-assignments -fdebug-types-section -w" } */ + +#if __BITINT_MAXWIDTH__ >= 236 +typedef _BitInt(236) B; +#else +typedef _BitInt(63) B; +#endif + +int +foo (B n, struct { char a[n]; } o) +{ +}