From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id lDGaFmyyl2UmKDMAWB0awg (envelope-from ) for ; Fri, 05 Jan 2024 02:40:28 -0500 Received: by simark.ca (Postfix, from userid 112) id 507B91E0C3; Fri, 5 Jan 2024 02:40:28 -0500 (EST) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 3A8D11E092 for ; Fri, 5 Jan 2024 02:40:26 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 373AA3857BA4 for ; Fri, 5 Jan 2024 07:40:25 +0000 (GMT) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) by sourceware.org (Postfix) with ESMTP id 3B71238582AD for ; Fri, 5 Jan 2024 07:40:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3B71238582AD Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gentoo.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gentoo.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3B71238582AD Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=140.211.166.183 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704440403; cv=none; b=vrNIbaWzgVPiK0qOUM2wImBTz9os03IUGu96aaz6ADFSfDC7fbuLhoGEAlrCNcbnATOYAXQIaTq580liIL9BxbwCnTIStodjOKKFVIvQYvfhCqKmOQYn9cRccPSUjoC/aKLPwXelDzMeaR0AYNnLFkC5zYjFeLFz+rdusMHHIQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704440403; c=relaxed/simple; bh=8dpRd0pjF+iVLgH9uH7ChhZtKv3vmnQ3GIhq63UdEXQ=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=Lj+WsDrqZw5rm3CamgimeM0g9XcrNT2ovkewUxTxKpVN6HibRLl1vwAIw4EMNApgqJrg/cG6elqqd5xGxAdQmbTTAo4yNRuGxdBGLc6q24h2ISenUbtcpAIBuSnN+W2QIG1CljoHmz1Awgg9K8DTMkv+XFkbJO1ZZ2XJm68EtS8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by smtp.gentoo.org (Postfix, from userid 559) id DFF073430C6; Fri, 5 Jan 2024 07:40:00 +0000 (UTC) Date: Fri, 5 Jan 2024 02:40:00 -0500 From: Mike Frysinger To: Joseph Myers Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] sim: warnings: disable -Wshift-negative-value Message-ID: References: <20231224082639.18038-1-vapier@gentoo.org> <9b592c16-dc57-1bb7-5438-26c794d61d1c@codesourcery.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="V7CUA+jkvMyVdgIE" Content-Disposition: inline In-Reply-To: <9b592c16-dc57-1bb7-5438-26c794d61d1c@codesourcery.com> X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org --V7CUA+jkvMyVdgIE Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 29 Dec 2023 00:52, Joseph Myers wrote: > On Sun, 24 Dec 2023, Mike Frysinger wrote: > > The sim expects left shift operations on negative values to have two's > > compliment behavior, and right shift operations to sign extend. In C89, > > this was not explicitly mentioned. In C90, this was changed to undefin= ed > > behavior. In C23, this was settled as the behavior we want in N2412 [1= ]. >=20 > No, there has been no change in C23 to the rules for which shifts are=20 > undefined. The change made was to make *representations* of integer type= s=20 > defined as two's complement; there were no changes to semantics of=20 > *operations* on such types. thanks, i thought the meat of P0907 was adopted, albeit via a diff proposal. not that the final thing adopted was only about twos compliment representat= ion. looking closer at the source of the warnings, it seems to all come from the macro that creates a 64-bit value from 2 32-bit values, and specifically when shifting a negative constant into the upper 32-bits. but we don't need to make the upper 32-bits signed before shifting since we're going to throw away all of the initial upper 32-bits, so we can prob fix this with: -#define MAKEDI(hi, lo) ((((int64_t) (int32_t) (hi)) << 32) | ((uint64_t) = (uint32_t) (lo))) +#define MAKEDI(hi, lo) ((((int64_t) (uint32_t) (hi)) << 32) | ((uint64_t) = (uint32_t) (lo))) for clarity, i'm kind of inclined to do the operations only as unsigned, rely on the types to do the appropriate truncation/extension, and then convert to signed at the end. #define MAKEDI(hi, lo) ( \ (int64_t)( \ ((uint64_t)(hi) << 32)) | (uint32_t) (lo) \ ) \ ) there's prob more left shifting of negative values lurking in the tree, but none that trigger compile-time warnings, so i'm inclined to not audit. the harder part would be implementing sign extension with right shifts, so hopefully we never have to cross that bridge. -mike --V7CUA+jkvMyVdgIE Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEuQK1JxMl+JKsJRrUQWM7n+g39YEFAmWXslAACgkQQWM7n+g3 9YGnAxAAk5JL5e6bCYBM5IzDG2xSoSoTwUY9f/PlBgnCHu2SENNsch663exwRfQz 9zYZRkxqph+waf1P9WN3ZNJzUP37KrH1HtJ94k4ArfCGcsV7jW/SFOhShdbdmvlG ivwV6EKxCty7enlVAhZGaqG2QU4pFTCY3QpV5XELirLf2CFWbltz7pbaslmKzLhq 6v4MwMJnmKWIQ8YtPb98t51v4DBZMeHLne6QYp8LF8RNoyj/vwZHizl3KxXLPwy/ 8kRFsf8y8HRTMtKTDCmhx7nVezwmIzZKPx14RXiUDMpxHa46LiiIl/vQgZMGF+Rx IjJduZSxRppOPGTFzY4a6guJ4MyutbXn0/78J+wVGEPSk0wo79JB0a8rBMmdJ6AH 9sL3b4gFo4HqCB6BhCrRs1KDMN37dipe11CSAKgCMxp/Iph32l4SzM2Fw+jLY54T dg7al4AVDI7cN5meUUkXntaSqBwZSIVSMIVgovkf0A0yOYB89fRp+YN0IjdBgSbv pqpIdpJM8IE6p/kKymtGuFxCnWY0VlsD5H2xiDFAKjRfrqqlhHp/OO2fL0ZpoRYY r/Y2aLvDHaTcw1XbrZ1UloVEsuAYB5pHf1ReqZHT92dp53za+XU+Y17+xBhWy1YA lU03KJUUXoaLNnHfi2tbPsygCF+erd6CzaPBk5vfb+we9+boiZo= =KQaY -----END PGP SIGNATURE----- --V7CUA+jkvMyVdgIE--