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: 84900 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B06B43858291 for ; Tue, 30 Jan 2024 08:03:13 +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+patchwork=sourceware.org@gcc.gnu.org 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); +}