From patchwork Wed Aug 12 20:32:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Bergner X-Patchwork-Id: 1343903 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: 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=SUXgcmvj; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BRhGD0JSVz9sRK for ; Thu, 13 Aug 2020 06:32:34 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A3DA384BC14; Wed, 12 Aug 2020 20:32:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A3DA384BC14 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1597264351; bh=KXDwz4Ut+tJIiOMg30FA8Vl+qj4eF6AX0xq6JLaphzc=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=SUXgcmvjJC6ABxX/gdobUPN5WNRCakRHWYfvo4ajKRJPFVr1m46VCuGoTlZ4KW1G/ IWDQRloPOypSGNbs5W3KpZjmsuRggXkRTkXdUi+unAnA5s6NvtL2q2nDwDGCNLY+p+ uK0Tj/N79KHCuPVHuxjx/Br1G7rfxqkwgaMx9aXU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id BB4E0385ED4D for ; Wed, 12 Aug 2020 20:32:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BB4E0385ED4D Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07CK4xvs137072; Wed, 12 Aug 2020 16:32:21 -0400 Received: from ppma04wdc.us.ibm.com (1a.90.2fa9.ip4.static.sl-reverse.com [169.47.144.26]) by mx0a-001b2d01.pphosted.com with ESMTP id 32vakps0b6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Aug 2020 16:32:21 -0400 Received: from pps.filterd (ppma04wdc.us.ibm.com [127.0.0.1]) by ppma04wdc.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 07CKOWC1011625; Wed, 12 Aug 2020 20:32:20 GMT Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by ppma04wdc.us.ibm.com with ESMTP id 32skp9cc73-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Aug 2020 20:32:20 +0000 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 07CKWJKU51773902 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Aug 2020 20:32:19 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B4D71B2067; Wed, 12 Aug 2020 20:32:19 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 31AAEB2064; Wed, 12 Aug 2020 20:32:19 +0000 (GMT) Received: from [9.160.79.236] (unknown [9.160.79.236]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 12 Aug 2020 20:32:19 +0000 (GMT) Subject: [PATCH v2] rs6000: ICE when using an MMA type as a function param or return value [PR96506] To: Segher Boessenkool References: <397d63db-9190-e875-44a9-b165964a5199@linux.ibm.com> <20200812020028.GP6753@gate.crashing.org> Message-ID: <0105dcce-8dc7-efe8-97a6-9f3afe10d6ff@linux.ibm.com> Date: Wed, 12 Aug 2020 15:32:18 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-08-12_16:2020-08-11, 2020-08-12 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 adultscore=0 impostorscore=0 phishscore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 spamscore=0 malwarescore=0 suspectscore=0 clxscore=1015 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008120125 X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Peter Bergner via Gcc-patches From: Peter Bergner Reply-To: Peter Bergner Cc: GCC Patches , Bill Schmidt Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" rs6000: ICE when using an MMA type as a function param or return value [PR96506] PR96506 shows a problem where we ICE on illegal usage, namely using MMA types for function arguments and return values. The solution is to flag these illegal usages as errors early, before we ICE. The patch below is functionally identical to the previous patch. The differences are that I've added more comments around the use of the static local variable and I added prototypes for the test case's extern bar* functions which allowed me to remove the now unneeded -w option. Ok for trunk now? Ok for GCC 10 after some bake in? Peter gcc/ PR target/96506 * config/rs6000/rs6000-call.c (rs6000_promote_function_mode): Disallow MMA types as return values. (rs6000_function_arg): Disallow MMA types as function arguments. gcc/testsuite/ PR target/96506 * gcc.target/powerpc/pr96506.c: New test. diff --git a/gcc/config/rs6000/rs6000-call.c b/gcc/config/rs6000/rs6000-call.c index 189497efb45..869e4973a16 100644 --- a/gcc/config/rs6000/rs6000-call.c +++ b/gcc/config/rs6000/rs6000-call.c @@ -6444,8 +6444,26 @@ machine_mode rs6000_promote_function_mode (const_tree type ATTRIBUTE_UNUSED, machine_mode mode, int *punsignedp ATTRIBUTE_UNUSED, - const_tree, int) + const_tree, int for_return) { + /* Warning: this is a static local variable and not always NULL! */ + static struct function *fn = NULL; + + /* We do not allow MMA types being used as return values. Only report + the invalid return value usage the first time we encounter it. */ + if (for_return + && fn != cfun + && (mode == POImode || mode == PXImode)) + { + /* Record we have now handled function CFUN, so the next time we + are called, we do not re-report the same error. */ + fn = cfun; + if (TYPE_CANONICAL (type) != NULL_TREE) + type = TYPE_CANONICAL (type); + error ("invalid use of MMA type %qs as a function return value", + IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)))); + } + PROMOTE_MODE (mode, *punsignedp, type); return mode; @@ -7396,6 +7414,16 @@ rs6000_function_arg (cumulative_args_t cum_v, const function_arg_info &arg) machine_mode elt_mode; int n_elts; + /* We do not allow MMA types being used as function arguments. */ + if (mode == POImode || mode == PXImode) + { + if (TYPE_CANONICAL (type) != NULL_TREE) + type = TYPE_CANONICAL (type); + error ("invalid use of MMA operand of type %qs as a function parameter", + IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)))); + return NULL_RTX; + } + /* Return a marker to indicate whether CR1 needs to set or clear the bit that V.4 uses to say fp args were passed in registers. Assume that we don't need the marker for software floating point, diff --git a/gcc/testsuite/gcc.target/powerpc/pr96506.c b/gcc/testsuite/gcc.target/powerpc/pr96506.c new file mode 100644 index 00000000000..b1b40c5a5c8 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr96506.c @@ -0,0 +1,66 @@ +/* PR target/96506 */ +/* { dg-do compile } */ +/* { dg-require-effective-target power10_ok } */ +/* { dg-options "-mdejagnu-cpu=power10 -O2" } */ + +extern void bar0(); +extern void bar1(); +extern void bar2(); +extern void bar3(); + +typedef __vector_pair vpair_t; +typedef __vector_quad vquad_t; + +/* Verify we flag errors on the following. */ + +void +foo0 (void) +{ + __vector_pair v; + bar0 (v); /* { dg-error "invalid use of MMA operand of type .__vector_pair. as a function parameter" } */ +} + +void +foo1 (void) +{ + vpair_t v; + bar1 (v); /* { dg-error "invalid use of MMA operand of type .__vector_pair. as a function parameter" } */ +} + +void +foo2 (void) +{ + __vector_quad v; + bar2 (v); /* { dg-error "invalid use of MMA operand of type .__vector_quad. as a function parameter" } */ +} + +void +foo3 (void) +{ + vquad_t v; + bar3 (v); /* { dg-error "invalid use of MMA operand of type .__vector_quad. as a function parameter" } */ +} + +__vector_pair +foo4 (__vector_pair *src) /* { dg-error "invalid use of MMA type .__vector_pair. as a function return value" } */ +{ + return *src; +} + +vpair_t +foo5 (vpair_t *src) /* { dg-error "invalid use of MMA type .__vector_pair. as a function return value" } */ +{ + return *src; +} + +__vector_quad +foo6 (__vector_quad *src) /* { dg-error "invalid use of MMA type .__vector_quad. as a function return value" } */ +{ + return *src; +} + +vquad_t +foo7 (vquad_t *src) /* { dg-error "invalid use of MMA type .__vector_quad. as a function return value" } */ +{ + return *src; +}