From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4FD21A0C47; Fri, 11 Jun 2021 11:19:09 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7C332410F0; Fri, 11 Jun 2021 11:19:08 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 1985C410E5 for ; Fri, 11 Jun 2021 11:19:07 +0200 (CEST) X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Date: Fri, 11 Jun 2021 11:19:03 +0200 Message-ID: <98CBD80474FA8B44BF855DF32C47DC35C6183D@smartserver.smartshare.dk> In-Reply-To: <20210610143604.48278bcc@hermes.local> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [dpdk-dev] Define statement with UB prevents compilation using UBSAN Thread-Index: AddeQKavMfG77I4jRwq1HJg4SjILiwAXGIew References: <20210610143604.48278bcc@hermes.local> From: =?iso-8859-1?Q?Morten_Br=F8rup?= To: "Owen Hilyard" Cc: "Aaron Conole" , "David Marchand" , "dev" , "Stephen Hemminger" Subject: Re: [dpdk-dev] Define statement with UB prevents compilation using UBSAN X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Stephen Hemminger > Sent: Thursday, 10 June 2021 23.36 >=20 > On Thu, 10 Jun 2021 16:51:37 -0400 > Owen Hilyard wrote: >=20 > > Working backward to the define > > statement, AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY is defined > as > > > > #define AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY (0x1 << 31) >=20 > Why not (1u << 31)? Yes, this is better. You want the type of the defined constant to be = uint32_t. It can also be defined in hexadecimal form as (0x1u << 31), or (0b1u << = 31) in binary form. On the CPUs/compilers supported by DPDK, the exact type of an unsigned = integer is uint32_t. If the CPU/compiler used 64 bits for integers, you = would need additional type casting to get it down from 64 to 32 bits. If we were to be really pedantic, the other defined constants that fit = in a signed integer, e.g. (1 << 30) should also be defined as (1u << 30) = if they are supposed to be unsigned integers. However, not many people = worry about signedness when writing code, especially if an unsigned = value fits into a signed variable or constant. Thank you for your effort on this, Owen. Keep up the good work! :-)