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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 83FD7CDB482 for ; Thu, 19 Oct 2023 09:07:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.619006.963458 (Exim 4.92) (envelope-from ) id 1qtP00-00068D-Fg; Thu, 19 Oct 2023 09:07:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 619006.963458; Thu, 19 Oct 2023 09:07:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qtP00-000686-Cr; Thu, 19 Oct 2023 09:07:24 +0000 Received: by outflank-mailman (input) for mailman id 619006; Thu, 19 Oct 2023 09:07:22 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qtOzy-00067t-TA for xen-devel@lists.xenproject.org; Thu, 19 Oct 2023 09:07:22 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e96be22d-6e5e-11ee-98d5-6d05b1d4d9a1; Thu, 19 Oct 2023 11:07:21 +0200 (CEST) Received: from [192.168.1.9] (net-188-218-250-245.cust.vodafonedsl.it [188.218.250.245]) by support.bugseng.com (Postfix) with ESMTPSA id 4B6884EE0743; Thu, 19 Oct 2023 11:07:21 +0200 (CEST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e96be22d-6e5e-11ee-98d5-6d05b1d4d9a1 Message-ID: <915d14c8-31fe-4381-bce6-3213da284115@bugseng.com> Date: Thu, 19 Oct 2023 11:07:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [XEN PATCH 3/4] xen/include: add pure and const attributes Content-Language: en-US To: Stefano Stabellini Cc: xen-devel@lists.xenproject.org, consulting@bugseng.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Wei Liu References: From: Simone Ballarin Organization: BUGSENG In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 19/10/23 03:02, Stefano Stabellini wrote: > On Wed, 18 Oct 2023, Simone Ballarin wrote: >> Add const and pure attributes to address reports >> of MISRA C:2012 Rule 13.1: Initializer lists shall >> not contain persistent side effects >> >> Add pure attribute to function pdx_to_pfn. >> Add const attribute to functions generated by TYPE_SAFE. >> >> These functions are used in initializer lists: adding >> the attributes ensures that no effect will be performed >> by them. >> >> Signed-off-by: Simone Ballarin > > Reviewed-by: Stefano Stabellini > > However one comment below... > >> --- >> Function attributes pure and const do not need to be added as GCC >> attributes, they can be added using ECLAIR configurations. >> --- >> xen/include/xen/pdx.h | 2 +- >> xen/include/xen/typesafe.h | 4 ++-- >> 2 files changed, 3 insertions(+), 3 deletions(-) >> >> diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h >> index f3fbc4273a..5d1050967a 100644 >> --- a/xen/include/xen/pdx.h >> +++ b/xen/include/xen/pdx.h >> @@ -164,7 +164,7 @@ static inline unsigned long pfn_to_pdx(unsigned long pfn) >> * @param pdx Page index >> * @return Obtained pfn after decompressing the pdx >> */ >> -static inline unsigned long pdx_to_pfn(unsigned long pdx) >> +static inline __attribute_pure__ unsigned long pdx_to_pfn(unsigned long pdx) >> { >> return (pdx & pfn_pdx_bottom_mask) | >> ((pdx << pfn_pdx_hole_shift) & pfn_top_mask); >> diff --git a/xen/include/xen/typesafe.h b/xen/include/xen/typesafe.h >> index 7ecd3b4a8d..615df6f944 100644 >> --- a/xen/include/xen/typesafe.h >> +++ b/xen/include/xen/typesafe.h >> @@ -21,8 +21,8 @@ >> >> #define TYPE_SAFE(_type, _name) \ >> typedef struct { _type _name; } _name##_t; \ >> - static inline _name##_t _##_name(_type n) { return (_name##_t) { n }; } \ >> - static inline _type _name##_x(_name##_t n) { return n._name; } >> + static inline __attribute_const__ _name##_t _##_name(_type n) { return (_name##_t) { n }; } \ >> + static inline __attribute_const__ _type _name##_x(_name##_t n) { return n._name; } >> >> #else > > I think we should also add __attribute_const__ in the NDEBUG definitions > just below. Ok. -- Simone Ballarin, M.Sc. Field Application Engineer, BUGSENG (https://bugseng.com)