Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A99EC433EF for ; Mon, 15 Nov 2021 14:46:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B24861BFA for ; Mon, 15 Nov 2021 14:46:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231634AbhKOOs4 (ORCPT ); Mon, 15 Nov 2021 09:48:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231537AbhKOOsy (ORCPT ); Mon, 15 Nov 2021 09:48:54 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40B3BC061570 for ; Mon, 15 Nov 2021 06:45:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=RJ0qc3fmH3KFVL1D0cXSeUUzHAVOSUCqJwBgOsJM5ec=; b=YS3PfrvjsJFXgOlO1eTRnr7lTW XZqG5xz14sa32mguWZY/p/NB1Zkv8oCRb1f0ZcyWTg5uinjb4xFF8CYWp6PaAXY/rMcomtpYS3zgq RvHDBM0EAm9C/ofIFotwlA+r5YoLqXGXxVSkDrTAEpZ1TrnvwrFGKaS7/xWVqqla4n8aqSzW9ynxJ 0Sj3B9o7+pX90XHQiKs/pf+LBmlihLVQIqn9sgyJkcW9q+eLfIfdwiqmPEBKucfdHZGXYQ6vQwvqd D0pjhSjseEBC8mE+v7KsUXAhDKuJxSxWeY3SgVm+wbNU8O3u6xZH56SVAiuj8NVD8RfufRAAepdqw pzRqHsyA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mmdF0-005m4l-TV; Mon, 15 Nov 2021 14:45:51 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (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) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 7ED62300129; Mon, 15 Nov 2021 15:45:50 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 3F33C201AB700; Mon, 15 Nov 2021 15:45:50 +0100 (CET) Date: Mon, 15 Nov 2021 15:45:50 +0100 From: Peter Zijlstra To: Prathamesh Kulkarni Cc: David Malcolm , gcc-patches@gcc.gnu.org, linux-toolchains@vger.kernel.org Subject: Re: [PATCH 2/6] Add returns_zero_on_success/failure attributes Message-ID: References: <20211113203732.2098220-1-dmalcolm@redhat.com> <20211113203732.2098220-4-dmalcolm@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-toolchains@vger.kernel.org On Mon, Nov 15, 2021 at 12:33:16PM +0530, Prathamesh Kulkarni wrote: > On Sun, 14 Nov 2021 at 02:07, David Malcolm via Gcc-patches > > +/* Handle "returns_zero_on_failure" and "returns_zero_on_success" attributes; > > + arguments as in struct attribute_spec.handler. */ > > + > > +static tree > > +handle_returns_zero_on_attributes (tree *node, tree name, tree, int, > > + bool *no_add_attrs) > > +{ > > + if (!INTEGRAL_TYPE_P (TREE_TYPE (*node))) > > + { > > + error ("%qE attribute on a function not returning an integral type", > > + name); > > + *no_add_attrs = true; > > + } > > + return NULL_TREE; > Hi David, > Just curious if a warning should be emitted if the function is marked > with the attribute but it's return value isn't actually 0 ? > > There are other constants like -1 or 1 that are often used to indicate > error, so maybe tweak the attribute to > take the integer as an argument ? > Sth like returns_int_on_success(cst) / returns_int_on_failure(cst) ? > > Also, would it make sense to extend it for pointers too for returning > NULL on success / failure ? Please also consider that in Linux we use the 'last' page for error code returns. That is, a function returning a pointer could return '(void *)-EFAULT' also see linux/err.h