From patchwork Thu Sep 8 05:53:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 1675435 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=) Authentication-Results: legolas.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=nK2+DRrp; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MNSxF06fbz1yhR for ; Thu, 8 Sep 2022 15:54:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 88BBD3858407 for ; Thu, 8 Sep 2022 05:54:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 88BBD3858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662616442; bh=IxdQg/uc3uWJ1eOFU69WQ8gxPJIAiK17IygsFm4bNZA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=nK2+DRrpnC/zrm/73a03qRfU8QJL3sZl1ljmJVPFaNY2bEhAiBXzdCOpVviGWQM4F 3ITxcqsHlJ/+ORxIFAtoL2XfZZxeT3prUTJ3b4rXHe05HXcHGUar2Zwhu+x+qzGeei lcBnYea44H29Dd8QNz2X8b9R7DDgx30+LNs1965A= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 14D0F3858D1E for ; Thu, 8 Sep 2022 05:53:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 14D0F3858D1E Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2885hEUo018589; Thu, 8 Sep 2022 05:53:41 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jfag609k4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Sep 2022 05:53:41 +0000 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2885mhQ3039233; Thu, 8 Sep 2022 05:53:40 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jfag609jc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Sep 2022 05:53:40 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2885oEQT014516; Thu, 8 Sep 2022 05:53:38 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04ams.nl.ibm.com with ESMTP id 3jbxj8x37w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Sep 2022 05:53:38 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2885o49639059940 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 8 Sep 2022 05:50:04 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4F239A405B; Thu, 8 Sep 2022 05:53:36 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BE066A4054; Thu, 8 Sep 2022 05:53:34 +0000 (GMT) Received: from [9.197.247.218] (unknown [9.197.247.218]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 8 Sep 2022 05:53:34 +0000 (GMT) Message-ID: Date: Thu, 8 Sep 2022 13:53:33 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Content-Language: en-US To: GCC Patches Subject: [PATCH] Handle OPAQUE_TYPE specially in verify_type [PR106833] X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: aT3j0fVYxuoAWJhoq3br93-1Mfue3WiB X-Proofpoint-GUID: pfkNk_acZvjOWTQ2z_b5oL2eV5uoZQCy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-08_03,2022-09-07_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 malwarescore=0 suspectscore=0 bulkscore=0 clxscore=1015 adultscore=0 mlxscore=0 mlxlogscore=999 spamscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209080019 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H2, 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: 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: "Kewen.Lin via Gcc-patches" From: "Kewen.Lin" Reply-To: "Kewen.Lin" Cc: Peter Bergner , Segher Boessenkool Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, As PR106833 shows, cv-qualified opaque type can cause ICE during LTO. It exposes that we missd to handle OPAQUE_TYPE well in type verification. As Richi pointed out, also assuming that target will always define TYPE_MAIN_VARIANT and TYPE_CANONICAL for opaque type, this patch is to check both are OPAQUE_TYPE_P. Besides, it also checks the only available size and alignment information as well as type mode for TYPE_MAIN_VARIANT. Bootstrapped and regtested on powerpc64-linux-gnu P7 and powerpc64le-linux-gnu P9 and P10. Is it ok for trunk? BR, Kewen ----- PR middle-end/106833 gcc/ChangeLog: * tree.cc (verify_opaque_type): New function. (verify_match): New macro. (verify_type): Call verify_opaque_type for OPAQUE_TYPE. gcc/testsuite/ChangeLog: * gcc.target/powerpc/pr106833.c: New test. --- gcc/testsuite/gcc.target/powerpc/pr106833.c | 14 +++++++ gcc/tree.cc | 45 ++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/pr106833.c -- 2.27.0 diff --git a/gcc/testsuite/gcc.target/powerpc/pr106833.c b/gcc/testsuite/gcc.target/powerpc/pr106833.c new file mode 100644 index 00000000000..968d75184ff --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr106833.c @@ -0,0 +1,14 @@ +/* { dg-do link } */ +/* { dg-require-effective-target power10_ok } */ +/* { dg-require-effective-target lto } */ +/* { dg-options "-flto -mdejagnu-cpu=power10" } */ + +/* Verify there is no ICE in LTO mode. */ + +int main () +{ + float *b; + const __vector_quad c; + __builtin_mma_disassemble_acc (b, &c); + return 0; +} diff --git a/gcc/tree.cc b/gcc/tree.cc index fed1434d141..e67caa8f85d 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -13670,6 +13670,42 @@ gimple_canonical_types_compatible_p (const_tree t1, const_tree t2, } } +/* For OPAQUE_TYPE T, it has only size and alignment information, so verify + these properties of T match TV which is the main variant of T. Also + verify the type of TC, which is the canonical of T, is OPAQUE_TYPE. */ + +static void +verify_opaque_type (const_tree t, tree tv, tree tc) +{ + gcc_assert (OPAQUE_TYPE_P (t)); + gcc_assert (tv && tv == TYPE_MAIN_VARIANT (tv)); + gcc_assert (tc && tc == TYPE_CANONICAL (tc)); + +#define verify_match(flag, t, tv) \ + do \ + { \ + if (flag (t) != flag (tv)) \ + { \ + error ("opaque type differs by %s", #flag); \ + debug_tree (tv); \ + } \ + } \ + while (false) + + if (t != tv) + { + verify_match (TREE_CODE, t, tv); + verify_match (TYPE_MODE, t, tv); + verify_match (TYPE_SIZE, t, tv); + verify_match (TYPE_ALIGN, t, tv); + verify_match (TYPE_USER_ALIGN, t, tv); + } + + if (t != tc) + verify_match (TREE_CODE, t, tc); +#undef verify_match +} + /* Verify type T. */ void @@ -13677,6 +13713,14 @@ verify_type (const_tree t) { bool error_found = false; tree mv = TYPE_MAIN_VARIANT (t); + tree ct = TYPE_CANONICAL (t); + + if (OPAQUE_TYPE_P (t)) + { + verify_opaque_type (t, mv, ct); + return; + } + if (!mv) { error ("main variant is not defined"); @@ -13691,7 +13735,6 @@ verify_type (const_tree t) else if (t != mv && !verify_type_variant (t, mv)) error_found = true; - tree ct = TYPE_CANONICAL (t); if (!ct) ; else if (TYPE_CANONICAL (ct) != ct)