From patchwork Wed Sep 2 18:55:25 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Pinski X-Patchwork-Id: 142752 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0766D4BA903E for ; Wed, 2 Sep 2026 18:56:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0766D4BA903E Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=Hbwdkdcl; dkim=pass (2048-bit key, unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=G/L8RUf3 X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by sourceware.org (Postfix) with ESMTPS id 3BC884BA2E36 for ; Wed, 2 Sep 2026 18:55:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3BC884BA2E36 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=oss.qualcomm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oss.qualcomm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3BC884BA2E36 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788375334; cv=none; b=UHLuxAev6Gj6HPKmhD4Zkaseilc3Wsp5Jn4FjcYL7XQ3KrFCjSTMmbU32k7t1Br8Z7iw9DypRSZ/I+I5QS/8+6y1HY/HJOXF+FrmsMYLxd25cQPGd23UE4GcCIvAzFPO/GTsqP/EF6pSnURq6ffYRFijhZN009v3kzlBq76upCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788375334; c=relaxed/simple; bh=oxhmZAq3kANyLG6HurrNDxyEFpKOCnsk4fvJg6QXkR4=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=xZzimEiCQfcyYpSvfcR0vGrEdQ03SSwmiOFA9ykXY/QE5lHsYLjk+rldEGat7laD3g/fpjr9y1y65E9A9u3XfTZamzK6oKg8mxYMFUYaEUbNd6lcaFHi6iGuzNUGXcqgM63FDKlCz9l3brohMMgfkj/cIAzYO3GTuSplOb10EVk= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=Hbwdkdcl; dkim=pass (2048-bit key, unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=G/L8RUf3 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3BC884BA2E36 Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 682HrcXn2483955 for ; Wed, 2 Sep 2026 18:55:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=qcppdkim1; bh=6jbmcxe5PWX5dxhOiTdoFAFLeXzXMT63ZWp byAG2bgo=; b=Hbwdkdcl169st69yjtCYyQrR/4x1uTs6yC71PwHekNoxoEL890G Opok/MqMuIpEtWHJymEXBJ4BqgJnDE7veKOoC7LUgF02HhaYXDE9XUFhjthuj29F v7xk8zd2d8bDX64pK4dZgZL121FNHd2y9OGyxrvhrvpAgiYogHImZZFtonqbXVJL L8HOiZtJmEKPif9nPsD1mkLo90wE8/qvVPNOiqHyoSJctI5UjIBjlXTxLxUzYW75 MxraOW9Wb10gKrEJLCTg8TvY/xtS/aqewE4AZqyf6ml7xIM12PnyJsAbXqgo1oNc trdDWf4jYccc61mLzK48X+Q8ntLRw3Ykvuw== Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4gemjh9dj3-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 02 Sep 2026 18:55:33 +0000 (GMT) Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-39af92138f9so320537a91.0 for ; Wed, 02 Sep 2026 11:55:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1788375332; x=1788980132; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=6jbmcxe5PWX5dxhOiTdoFAFLeXzXMT63ZWpbyAG2bgo=; b=G/L8RUf330iPZ+kZs6uFqPtemfZoWFCDrdV5u9sHBGlofbQahSvgVBXfDQkkPCwfF8 GC5LCmuoHB3a3MyLzE0umrsXE1Zxab+4Z3+uPHGwidcEeKx8lm8N+tdHIgYwMWBSRCFa s1RgsogEFlABXYsR5RcAOapVmsD76l6BMDQcJRm1LsyYIzYgceKNAfKSobZ8n8qGjiXh vNKjMUbl4lFnpoeCg5AtmvneyJz+B6kCymVvYXRSCY2/r/FBxg3pDDhfYVVyfZjICeuO Ho651+lGQ6/ILGgvoh4z0Irf6croMJF7Ef7Tzjd8eHAjfaU1Hs/Asn49Y0Znxq3lZ8i2 X9YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788375332; x=1788980132; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=6jbmcxe5PWX5dxhOiTdoFAFLeXzXMT63ZWpbyAG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 Sep 2026 11:55:32 -0700 (PDT) X-Received: by 2002:a17:90a:1101:b0:38e:42f5:d096 with SMTP id 98e67ed59e1d1-39b076e2d2fmr643231a91.0.1788375331726; Wed, 02 Sep 2026 11:55:31 -0700 (PDT) Received: from xeond2.wrightpinski.org ([98.97.36.224]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39b0875ce14sm849151a91.13.2026.09.02.11.55.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2026 11:55:31 -0700 (PDT) From: Andrea Pinski To: gcc-patches@gcc.gnu.org Cc: Andrea Pinski Subject: [PATCH] eh: Use tree_could_throw_1/lhs_could_trap_p for lhs in non-call exception case [PR127183] Date: Wed, 2 Sep 2026 11:55:25 -0700 Message-ID: <20260902185525.1780541-1-andrew.pinski@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Proofpoint-GUID: mV2gIBOaNvOb8NmGQo70gJrYMECmKLk0 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTAyMDE2NiBTYWx0ZWRfX74wqy+ZTyJv9 h3K127KUMXy1zb3zUjBtJy5nV7jT95d00dZk4u0zgadrl3aYoUcsLtmUSV8u8KG9+OY+jIPvMoL Dbu8HqTEku9G8BAT2X7N/gcgiy/sRnTnbQxcGTnf7oJUiQ1ecSYaHGBBv/aWY/+S/jD+Oj6zDPm LWUJJp7DBqTQyImewSs0+njGum+eJ6h7Mi8LcQ/WKUYWnmZoWisu6zx4Xae5+zsne+dRGAY7jyz Ke0iFlzDRfD28uihV2aApy2zYjk5ASJAE/hSKd4D6zx+rSf2DkBQABjMhlnhrtNQeQ+z/0S85zs KqIjRN5ReawaMrI8/dPcWtUAMYH5GNv2FLQOO/LkEVUk08Tropscw6qDMjI51TlplSJ81difWZJ 6ixbuo8uyoymH7Ts8sN4vtmaisZzFEnV5fa13BQRMT3zT4XItOv1oOUqGPopyA4A7QR6N9xPqpQ DnU1r1bSCbFPyBZxv3w== X-Proofpoint-Spam-Info: AW1haW4tMjYwOTAyMDE2NiBTYWx0ZWRfX44i9Cu9Uwbbz wHEb6stcmWixjwqnj3pa6MxE3RXoCE+mTwirqkv3QZKnbG81rYFdpIGFmwaVcIFneHEYSTIl6/+ S0gi+9gNGh0FRSqsUxpO9zvAZmN0WPM= X-Authority-Analysis: v=2.4 cv=ErHiaycA c=1 sm=1 tr=0 ts=6a987125 cx=c_pps a=UNFcQwm+pnOIJct1K4W+Mw==:117 a=1ch7nK4tQSiZUNEyOOQPUg==:17 a=VdqzKS8jKosA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_glEPmIy2e8OvE2BGh3C:22 a=EUspDBNiAAAA:8 a=EODObv-xwzmIaxutAfsA:9 a=uKXjsCUrEbL0IQVhDsJ9:22 X-Proofpoint-ORIG-GUID: mV2gIBOaNvOb8NmGQo70gJrYMECmKLk0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-09-02_04,2026-09-02_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 bulkscore=0 adultscore=0 malwarescore=0 spamscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2609020166 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Since `this` argument was added as a non-trapping, we incorrectly had thought it would not cause an non-call exception when it was on the LHS. With the fix for PR127133, we can change the places which were checking for trapping on the lhs to use lhs_could_trap_p/tree_could_throw_1 instead of using tree_could_throw_p. That fixes the non-call exceptions on the lhs of assignments with respect to this argument. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/127183 gcc/ChangeLog: * tree-eh.cc (lower_eh_constructs_2): Use lhs_could_trap_p for lhs. (stmt_could_throw_1_p): Use tree_could_throw_1 for lhs. (tree_could_throw_p): Likewise. gcc/testsuite/ChangeLog: * g++.dg/eh/noncall-this-method-1.C: New test. Signed-off-by: Andrea Pinski --- .../g++.dg/eh/noncall-this-method-1.C | 25 +++++++++++++++++++ gcc/tree-eh.cc | 6 ++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/eh/noncall-this-method-1.C diff --git a/gcc/testsuite/g++.dg/eh/noncall-this-method-1.C b/gcc/testsuite/g++.dg/eh/noncall-this-method-1.C new file mode 100644 index 00000000000..544bf0396b8 --- /dev/null +++ b/gcc/testsuite/g++.dg/eh/noncall-this-method-1.C @@ -0,0 +1,25 @@ +// PR tree-optimization/127183 +// { dg-do compile } +// { dg-options "-O2 -fnon-call-exceptions -fdump-tree-optimized" } + +struct s1 +{ + int f(); + int a; +}; + +int s1::f() +{ + try { + this->a = 1; + }catch(...) + { + __builtin_trap (); + } + return 0; +} + +// An write access to this should be still considered as trapping +// and an throwable for non-call exceptions. + +// { dg-final { scan-tree-dump "__builtin_trap " "optimized" } } */ diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc index 2d2d391f0a9..d2c2f3b3157 100644 --- a/gcc/tree-eh.cc +++ b/gcc/tree-eh.cc @@ -2118,7 +2118,7 @@ lower_eh_constructs_2 (struct leh_state *state, gimple_stmt_iterator *gsi) if (stmt_could_throw_p (cfun, stmt) && gimple_has_lhs (stmt) && gimple_stmt_may_fallthru (stmt) - && !tree_could_throw_p (gimple_get_lhs (stmt)) + && !lhs_could_trap_p (gimple_get_lhs (stmt)) && is_gimple_reg_type (TREE_TYPE (gimple_get_lhs (stmt)))) { tree lhs = gimple_get_lhs (stmt); @@ -3057,7 +3057,7 @@ stmt_could_throw_1_p (gassign *stmt) } /* First check the LHS. */ - if (tree_could_trap_p (gimple_assign_lhs (stmt))) + if (tree_could_trap_1 (gimple_assign_lhs (stmt), true)) return true; /* Check if the main expression may trap. */ @@ -3144,7 +3144,7 @@ tree_could_throw_p (tree t) if (TREE_CODE (t) == MODIFY_EXPR) { if (cfun->can_throw_non_call_exceptions - && tree_could_trap_p (TREE_OPERAND (t, 0))) + && tree_could_trap_1 (TREE_OPERAND (t, 0), true)) return true; t = TREE_OPERAND (t, 1); }