From patchwork Sun Dec 24 08:26:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 82812 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D48D63858D3C for ; Sun, 24 Dec 2023 08:27:37 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) by sourceware.org (Postfix) with ESMTP id 58C3C3858D3C for ; Sun, 24 Dec 2023 08:26:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 58C3C3858D3C 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 58C3C3858D3C 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=1703406415; cv=none; b=XRW3cOIIJPLuoBgZOtjW/2P17/hZj2+3Ky1ZNlQkXlBD3RrwG+fYfCXPA+3wo16vkuuSaY8txkaLiu0WEuWUZbRdWDql2WUhacbYkduBPPbyLRCuqv3HFoHt+HqMRwthO8awRBLz0r7Wm4VLu2OOd18sIREjth48lMgnDVknSbk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703406415; c=relaxed/simple; bh=sVLkChICos+IH7+/sOR5wgl7KmIr7R/R92avOLpdbcU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=MfuMFasZlmYreEH6YLDQg5NclVWVMHOyg4c0nSRLhpXx686IxIi+dem9sCVa6YrSVARF7V5fEbh47YfXbD3qoTrSypxdhqor4kBbPggiNJ/PiDRYQNGAau/eq4FF487/ZShVvo8sj3M77zYCjVQcF6ODu62xveWUMhN19sgGzXw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by smtp.gentoo.org (Postfix, from userid 559) id A7C9033D9AD; Sun, 24 Dec 2023 08:26:52 +0000 (UTC) From: Mike Frysinger To: gdb-patches@sourceware.org Subject: [PATCH] sim: warnings: disable -Wshift-negative-value Date: Sun, 24 Dec 2023 03:26:39 -0500 Message-ID: <20231224082639.18038-1-vapier@gentoo.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham 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+patchwork=sourceware.org@sourceware.org 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 undefined behavior. In C23, this was settled as the behavior we want in N2412 [1]. One C23 proposal documented that GCC, LLVM, and MSVC already behaved this way [2], as did every known hardware, and GCC guarantees it behaves this way in all C standards as an extension. So disable the warning in case a compiler automatically turns it on when running in C11 mode (which is our required minimum version). From the GCC manual (4.5 Integers): > https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html > The results of some bitwise operations on signed integers (C90 6.3, C99 and C11 6.5). > > Bitwise operators act on the representation of the value including > both the sign and value bits, where the sign bit is considered > immediately above the highest-value value bit. Signed ‘>>’ acts on > negative numbers by sign extension. > > As an extension to the C language, GCC does not use the latitude given > in C99 and C11 only to treat certain aspects of signed ‘<<’ as undefined. > However, -fsanitize=shift (and -fsanitize=undefined) will diagnose such > cases. They are also diagnosed where constant expressions are required. [1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2412.pdf [2] https://wg21.link/P0907R4 (not adopted, but has relevant research) --- sim/configure | 1 + sim/m4/sim_ac_option_warnings.m4 | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/sim/m4/sim_ac_option_warnings.m4 b/sim/m4/sim_ac_option_warnings.m4 index 8a54e563bad2..41a7c5c8c0d6 100644 --- a/sim/m4/sim_ac_option_warnings.m4 +++ b/sim/m4/sim_ac_option_warnings.m4 @@ -74,6 +74,10 @@ build_warnings="$build_warnings dnl The cgen virtual insn logic involves enum conversions. dnl Disable until we can figure out how to make this work. -Wno-enum-conversion +dnl The sim expects left shift operations on negative values to have two's +dnl compliment behavior, and right shift operations to sign extend. In +dnl practice, all compilers do this, and C23 settled it, so disable the warning. +-Wno-shift-negative-value " case "${host}" in