From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by sourceware.org (Postfix) with ESMTP id C450B3858403 for ; Mon, 1 Nov 2021 18:59:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C450B3858403 Received: by smtp.gentoo.org (Postfix, from userid 559) id 218CE342E29; Mon, 1 Nov 2021 18:59:55 +0000 (UTC) Date: Mon, 1 Nov 2021 14:59:57 -0400 From: Mike Frysinger To: Christian Biesinger via Gdb-patches Subject: Re: [PATCH] sim: mn10300: clean up pointer casts Message-ID: Mail-Followup-To: Christian Biesinger via Gdb-patches , Christian Biesinger References: <20211101034519.29154-1-vapier@gentoo.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="4IE3H2RDrtL2S/nc" Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Nov 2021 18:59:57 -0000 --4IE3H2RDrtL2S/nc Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 01 Nov 2021 14:28, Christian Biesinger via Gdb-patches wrote: > On Mon, Nov 1, 2021 at 12:22 PM Mike Frysinger wrote: > > On 01 Nov 2021 12:07, Christian Biesinger wrote: > > > On Sun, Oct 31, 2021 at 11:45 PM Mike Frysinger via Gdb-patches > > > wrote: > > > > --- a/sim/mn10300/dv-mn103ser.c > > > > +++ b/sim/mn10300/dv-mn103ser.c > > > > @@ -238,7 +238,7 @@ do_polling_event (struct hw *me, > > > > { > > > > SIM_DESC sd =3D hw_system (me); > > > > struct mn103ser *serial =3D hw_data(me); > > > > - long serial_reg =3D (long) data; > > > > + long serial_reg =3D (uintptr_t) data; > > > > > > Shouldn't you change the variable type too? > > > > the types are already confused, but long here is fine as any other. ui= ntptr_t > > is not really any more correct. serial_reg comes in as an unsigned_wor= d via > > the memory read/write callbacks, (encoded) cast to void*, and (decoded)= cast > > to long. the memory read/write callbacks verify the values are always = within > > the serial_register_types enum range which looks like [0,16] range, so = any of > > these types work. > > > > > Otherwise this patch seems to be somewhat pointless? > > > if ( nr_bytes =3D=3D 1 ) > > > > i don't know which one you mean, or why you think any of them are point= less. > > the nr_bytes checks are in the read/write code paths of the memory mapp= ed > > register callbacks. so nr_bytes is needed & correct there. >=20 > I forgot to delete that nr_bytes line; the pointless comment was about > casting to uintprtr_t but still storing the result in a long. Why not > keep it as a cast to long then? that was the point of the patch in the first place :). i prob should have included the compiler errors in the log, but basically any target where the sizeof(long) !=3D sizeof(void*) will generate an error. LLP64 systems is w= here you'll find this, and most notably, 64-bit Windows does it. warning: cast from pointer to integer of different size [-Wpointer-to-int-c= ast] since sizeof(uintptr_t) is guaranteed to equal sizeof(void*), it's the "rig= ht" way to convert integers to/from pointers. in this case, the event framework is using void* as an opaque storage, and this particular model is (ab)using that to pass values rather than pointers to larger storage. -mike --4IE3H2RDrtL2S/nc Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEuQK1JxMl+JKsJRrUQWM7n+g39YEFAmGAOS0ACgkQQWM7n+g3 9YGP/g//aPpZrs5hhMhUEF03bR8vyD3N80zVgS0OZlN5ydi6c7DgfwrxKwlRgUvx HVJ+RL2fQ2UyWbhEpc/Tra1geoPrYILztWxgSnI1iYSkcCUztcsXjuS/ODIws/bR pNCdawxTOOF5qJ8FzhhmME3olZe0rGBVDmd6kaM7W0xmE09g/yTiGL7ffmBWP9R+ x6lwcWAtnkBdR582YZky+HFSausxPZE+F3vqMiY1sV91You1QXkMeYu+9RW+vKkf hwMOcX3frLy5C7ZwQlbckW1hQM43Ayeercw9YuiVRpBtKEYX0lrZDrMzFXeeByBi xzHybVXQ2sDHsdE7qekl2s09grCu4TErmGSP7w3j3bwyRKxf1i9ENz8DabnUrM6a B6677g5ZjUQR+k55eCmvq05efJQhH+RND4IxcKmS+MtB20GeUgz7SsfApNk8gKtw yp6bL7QibMmGDw0wVCbB4iQIWd+PGSW3qK8WEqfW53be7DdVGskM/b/HEkFi3YYS RKcOZIzwv4//6eRa8H/7aFdsRoR427vlXuVFULWJT/OT4SO4nQGbNSX/lfR/psKs zi89ocx6Iqk89p1FqYJt07Ox2FEub/pG17RVgk+giuUMqyQKstIbiDbpEx1XCtU/ mXD5mf38c5engRQzLaErN+RiRXOBnK4tJQv3E0EsOqE0MTG1/Ng= =XX9K -----END PGP SIGNATURE----- --4IE3H2RDrtL2S/nc--