From patchwork Sat Apr 2 10:53:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 1612518 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=wiuIgAyN; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KVv7V5ZKNz9sFv for ; Sat, 2 Apr 2022 21:54:45 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ABB39389942C for ; Sat, 2 Apr 2022 10:54:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ABB39389942C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1648896881; bh=BwgNVTZX2mJkmfD/gJDMXLvrDaXdUuIvFDy5EqhQSzs=; h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=wiuIgAyNInZngC/J/Is4mHOTV7J398OibR4EEnd/I01ABvKxuveOVIUPr3p3N/lsm ULwWgD/9GZxW8Ed1v5793ivn8QdxojUsO4tlrrdZRcvOLuJA2imOKGo3qofbahOoyC Lz621XR/kZuO6I/G9sYbGo4RlPdl4jJQUVtm8NV0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mengyan1223.wang (mengyan1223.wang [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 592B33858418; Sat, 2 Apr 2022 10:54:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 592B33858418 Received: from localhost.localdomain (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@mengyan1223.wang) by mengyan1223.wang (Postfix) with ESMTPSA id 924DA65A02; Sat, 2 Apr 2022 06:53:57 -0400 (EDT) Message-ID: Subject: [PATCH] mips: Fix an ICE caused by r12-7962 To: gcc-patches@gcc.gnu.org Date: Sat, 02 Apr 2022 18:53:55 +0800 User-Agent: Evolution 3.44.0 MIME-Version: 1.0 X-Spam-Status: No, score=-3037.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_NUMSUBJECT, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Xi Ruoyao via Gcc-patches From: Xi Ruoyao Reply-To: Xi Ruoyao Cc: Richard Sandiford , Jakub Jelinek , YunQiang Su Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" I made a mistake in r12-7962 and it causes an ICE running g++.dg-struct- layout-1 tests. The fix and a reduced test are included in this patch. Ok for trunk? -------------------- DECL_SIZE(x) is NULL if x is a flexible array member, but I forgot to check it in r12-7962. Then if we increase the size of a struct with flexible array member (by using aligned attribute), the code will dereference NULL trying to use the "size" of the flexible array member. gcc/ * config/mips/mips.cc (mips_function_arg): Check if DECL_SIZE is NULL before dereferencing it. gcc/testsuite/ * gcc.target/mips/pr102024-4.c: New test. --- gcc/config/mips/mips.cc | 3 ++- gcc/testsuite/gcc.target/mips/pr102024-4.c | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/mips/pr102024-4.c diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc index a6dd1e9e7b6..079bb03968a 100644 --- a/gcc/config/mips/mips.cc +++ b/gcc/config/mips/mips.cc @@ -6082,7 +6082,8 @@ mips_function_arg (cumulative_args_t cum_v, const function_arg_info &arg) an ABI change. */ if (DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (field)) continue; - if (integer_zerop (DECL_SIZE (field))) + if (DECL_SIZE (field) + && integer_zerop (DECL_SIZE (field))) { zero_width_field_abi_change = true; continue; diff --git a/gcc/testsuite/gcc.target/mips/pr102024-4.c b/gcc/testsuite/gcc.target/mips/pr102024-4.c new file mode 100644 index 00000000000..2147cc769d0 --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/pr102024-4.c @@ -0,0 +1,10 @@ +// { dg-do compile } +// { dg-options "-mabi=64 -mhard-float" } + +struct __attribute__((aligned(16))) test { + int x[0]; + double b; + int f[]; +}; + +void check(struct test) {} // { dg-message "the ABI for passing a value containing zero-width fields before an adjacent 64-bit floating-point field was changed in GCC 12.1" }