From patchwork Tue Jan 30 08:02:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 193874 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1064289dyb; Tue, 30 Jan 2024 00:03:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IG5syX6H87QhrraLhLh7j9HViG+rUMdSSpHHZua9+RSYZHRKHzMjRcyfPJXLwXVQ7l4vOzE X-Received: by 2002:a05:622a:28b:b0:42a:b1a8:6277 with SMTP id z11-20020a05622a028b00b0042ab1a86277mr1612049qtw.53.1706601813243; Tue, 30 Jan 2024 00:03:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706601813; cv=pass; d=google.com; s=arc-20160816; b=RyO9GKKAk+avl5+yMww8l6Ga3mwDGXI/tYQ0tU/H2r71bzGPaYdJr+FEHbsnCqjiNy cV+yuW/Io/3e1rxGWg8+DXxS40t45Z1kvw1MEhFgbC2DP7jZ40mfzfM2XbjnK8blkU4a gicH59Z1scJSODfBlBOEYI+n7BCyOx3cPXNULWFhpRe7NRE5oKBQWJ7NMppHTVFwjqDC ErvchHKE6nmSDCVNNT91TNZHpO0KUI0fMm0JbgTDnf3eizedYsXYBUjW8NOq8AbAoH/J wAjU3f9PEK0LgsMhTYPgn3gd+5jD/p50CLAXUyxIAZ63s7wJye+4paPUPcIDGBl+BqIv 8IKg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=d81dlQLBbnhdooCEK980OZcNGVVwqMNbN8fijGfLUe8=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=iKLxh6GwHBwFGTsK4Bksca4ddaBNhBVQpx8XheJxndel4L35NTZOG2GmS9wqAWZQ2v uKXSrt8Tl1cEwAVydx+E0skD1Ft7VOg7ri+2og88faeA8ZXhE11reyejlVaNOcvJQYWN +1QKBQepOd9GxaLf3QzGmvGOp5F3wZG5XLi2xw9FBnzD5XbigkOXFYTl1GXeMiV408ht tvDHndONyNsLCU8WnSJzwPnSfmWD3StRjTh3AJ9Gw53FP3ZAaxJ94XTgf4uOf+DQE2sM IJstA1ZR397dCV41pMnWLlnjk1aSuOg60iHC8EzWSfZy5r4vrA+EDtaVHKeu2fgb4Fjx 8doA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KIeT75Af; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id n25-20020ac86759000000b0042a86d45e41si7624152qtp.560.2024.01.30.00.03.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 00:03:33 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KIeT75Af; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E5D573858436 for ; Tue, 30 Jan 2024 08:03:32 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id E1B143858CDA for ; Tue, 30 Jan 2024 08:02:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E1B143858CDA 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 E1B143858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706601751; cv=none; b=TAtUBkQgftiFx8skwrJUG5Swj2i8CmUIihqijaxWbn57DSWM4+m4Dkx8j8ZL97Se/nSdGgoJvIav68DkLSJeqROrKU63R+YSnc6qUj/EnBFbjUZTmTtmuqUXaP6xn62sbKcChh1TVr4C6BbiIBeyo/l+04x+gHVH22j4GCC7G4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706601751; c=relaxed/simple; bh=179/U6aqf/x7sOvPtgjRjArQa5ZDxnItt/wqyr9E7ps=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=D41IsZn+VGCf4T+IEqKyk5jtJEnVXNzyABxOp0f0Tqa5hM56jer31UT/U134Jn15KoykLz+qi1AyZct4nQjbRdZscUtrfiajORlfMwRnKUL+AUdJ/UJ1mmf1+2ISdWO64LWJ0Z9Pwj5Q0b0VqcZK9+auNYxb1BpxpuMccApHFWw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706601748; 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=d81dlQLBbnhdooCEK980OZcNGVVwqMNbN8fijGfLUe8=; b=KIeT75AfcoeQhoOP7DwBxObBNtx2Zfk4tRBc5a07UVmiw6xp6asEN+V+5aVBjiPY22ezfH cBPm+5VfCv1Ecf55VOnynkdpGJFsvson+gcIGnmyZ6K94vomuh8LHEhki+3NTvWeeBFv06 1SFALV8WA8Qy/DFXUV6cyQYP/yywl50= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-258-_z6xJ599OxePeEsvgL552g-1; Tue, 30 Jan 2024 03:02:24 -0500 X-MC-Unique: _z6xJ599OxePeEsvgL552g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 68B44383CCE6; Tue, 30 Jan 2024 08:02:24 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2BD91C38; Tue, 30 Jan 2024 08:02:24 +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 40U82LZk1616618 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 30 Jan 2024 09:02:21 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 40U82FK21616617; Tue, 30 Jan 2024 09:02:15 +0100 Date: Tue, 30 Jan 2024 09:02:15 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] except: Fix __builtin_eh_return_data_regno (-42) expansion [PR101195] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.3 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_H3, RCVD_IN_MSPIKE_WL, 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789501702999628541 X-GMAIL-MSGID: 1789501702999628541 Hi! The expansion of this builtin emits an error if the argument is not INTEGER_CST, otherwise uses tree_to_uhwi on the argument (which is declared int) and then uses EH_RETURN_DATA_REGNO macro which on most targets returns INVALID_REGNUM for all values but some small number (2 or 4); if it returns INVALID_REGNUM, we silently expand to -1. Now, I think the error for non-INTEGER_CST makes sense to catch when people unintentionally don't call it with a constant (but, users shouldn't really use this builtin anyway, it is for the unwinder only). Initially I thought about emitting an error for the negative values as well on which tree_to_uhwi otherwise ICEs, but given that the function will silently expand to -1 for INT_MAX - 1 or INT_MAX - 3 other values, I think treating the negatives the same silently is fine too. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-01-30 Jakub Jelinek PR middle-end/101195 * except.cc (expand_builtin_eh_return_data_regno): If which doesn't fit into unsigned HOST_WIDE_INT, return constm1_rtx. * gcc.dg/pr101195.c: New test. Jakub --- gcc/except.cc.jj 2024-01-03 11:51:37.552647625 +0100 +++ gcc/except.cc 2024-01-29 09:46:09.385299324 +0100 @@ -2167,6 +2167,9 @@ expand_builtin_eh_return_data_regno (tre return constm1_rtx; } + if (!tree_fits_uhwi_p (which)) + return constm1_rtx; + iwhich = tree_to_uhwi (which); iwhich = EH_RETURN_DATA_REGNO (iwhich); if (iwhich == INVALID_REGNUM) --- gcc/testsuite/gcc.dg/pr101195.c.jj 2024-01-29 09:48:15.969510457 +0100 +++ gcc/testsuite/gcc.dg/pr101195.c 2024-01-29 09:48:08.626614220 +0100 @@ -0,0 +1,8 @@ +/* PR middle-end/101195 */ +/* { dg-do compile } */ + +int +foo (void) +{ + return __builtin_eh_return_data_regno (-42); +}