Message ID | cover.1712086444.git.sergey_v_kaplun@mail.ru |
---|---|
Headers |
Return-Path: <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> 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 09D023864C69 for <patchwork@sourceware.org>; Tue, 2 Apr 2024 20:19:07 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp33.i.mail.ru (smtp33.i.mail.ru [95.163.41.74]) by sourceware.org (Postfix) with ESMTPS id 71DB7386EC42 for <gdb-patches@sourceware.org>; Tue, 2 Apr 2024 20:18:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 71DB7386EC42 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=mail.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mail.ru ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 71DB7386EC42 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=95.163.41.74 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712089085; cv=none; b=ZQV8O0HTDSuY0lCFBWwCp03gLEVwgaCel/arNJE0XTcKMEKO8eFg3VsnrAxNUnBV125g8SaNP7grTzX3RMZEduBQ9pyFzpoULmduJy2Xr9wrCPQTa90EwHcjyRNazgTIJLlrU2/OnDgqb33OZi6F6FXxVJUX8KoJCPx7hNwIzYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712089085; c=relaxed/simple; bh=s+PpzmYAgd17pREBzCNo2d/oKRTyNSZpI0sb8uS09gA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=c33NGYFCnucL1iI0DR7Q8qamd3uNS0rhlFx7ru3BB9VnawlsdpMcPE1MCPt9RXGyka5x2aC+zPw5YB8JHbBAS8LH+KsB9NNwmyq3iapoqCEujPcdLGyVzNQqwUsXOvFtIAMbRCyMgTQyI4gBcaUQhvDf6tPdfkW+WhVNRFHMBmM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail4; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:Cc: To:From:From:Sender:Reply-To:To:Cc:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive: X-Cloud-Ids:Disposition-Notification-To; bh=+DjHuRP1sy3CyhGevj4N1/LMixBRZxl/KoRU0QWT/Lw=; t=1712089082; x=1712179082; b=EisNpFem0ZPtF8gOMyu6E/n+f1NcbBTyAxq2zrU77NGUBbZnEZR0sQU4JLZBSYgCDfuy5HVtLrW gzYIe9OTEvrV2iMxrrX4BobfToFxeH/88WXsS6hA7MNE+hH12ivSfiRNoP2of2bLtVCrksP0lNwbp 9ULzmu5d0JgAcYX6c5L9gxI6EQqEv8+KgzjVw2DEzut+1/KStOQxlFMBN4tObQRwI5ygzFA+71UzI D6xOpgxfoEZW0Fl0qq7dj/sqj8EOveB4hWiPG8SAuPYKyWYfZ5XpT8KmZDMl37n4O+6yWvTTPO7cF G+w4kl9/PzLiSt3rnNBzn+Bxz5ecMDu7lUPg==; Received: by smtp33.i.mail.ru with esmtpa (envelope-from <sergey_v_kaplun@mail.ru>) id 1rrka0-00000001qSd-08Ss; Tue, 02 Apr 2024 23:18:00 +0300 From: Sergey Kaplun <sergey_v_kaplun@mail.ru> To: gdb-patches@sourceware.org Cc: Sergey Kaplun <sergey_v_kaplun@mail.ru> Subject: [PATCH v1 0/2] Fix the right shift of negative numbers Date: Tue, 2 Apr 2024 23:17:56 +0300 Message-ID: <cover.1712086444.git.sergey_v_kaplun@mail.ru> X-Mailer: git-send-email 2.43.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Authentication-Results: smtp33.i.mail.ru; auth=pass smtp.auth=sergey_v_kaplun@mail.ru smtp.mailfrom=sergey_v_kaplun@mail.ru X-Mailru-Src: smtp X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9D135BF24EC7C3B8405773392EF6D97B24CD954A2B046A5F8182A05F538085040CF647765DB39BAC89487ABAC94A94B544D595C6D42C5B2BB4D6197B2AB0C9E227AE8E57E538EEBEE X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE79145AB6E9E75F07EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006371758572763D318798638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8E6F16A774BF26BB29DA389CB1A35E6983E7F3DD52C51277520879F7C8C5043D14489FFFB0AA5F4BF176DF2183F8FC7C0EF2A066DDA19BA868941B15DA834481FA18204E546F3947C457EE4B4996FC546F6B57BC7E64490618DEB871D839B7333395957E7521B51C2DFABB839C843B9C08941B15DA834481F8AA50765F790063798EAA0EED4DE4A60389733CBF5DBD5E9B5C8C57E37DE458BD9DD9810294C998ED8FC6C240DEA76428AA50765F7900637E8ADDA8C03BE2A56D81D268191BDAD3DBD4B6F7A4D31EC0BE2F48590F00D11D6D81D268191BDAD3D78DA827A17800CE7A796459EA1476E08EC76A7562686271ED91E3A1F190DE8FD2E808ACE2090B5E14AD6D5ED66289B5278DA827A17800CE76631511D42670FFE2EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE783573928F8DF1ADB731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A57C0ECFC0A6E409085002B1117B3ED696C6F45AAD8BBC75A8B91D2EB2DEE3878C823CB91A9FED034534781492E4B8EEAD303003AC7AA20DD0C79554A2A72441328621D336A7BC284946AD531847A6065A535571D14F44ED41 X-C8649E89: 1C3962B70DF3F0ADBF74143AD284FC7177DD89D51EBB7742DC8270968E61249B1004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D348E5EF936B2E46EBA48A42F27E01905858B3EDC9F733C98AB7FBDE2A96CD152A05E0786B4BC8620871D7E09C32AA3244C72778F4D056B5E98A9A6C043C55A4F63A9CFA21C32CF8E09EA455F16B58544A2E30DDF7C44BCB90DA5AE236DF995FB596876D1437B5458BC08F8711F4D97DF1124A389F0E278DBF4 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojmSy8L1hSZUNhMmEkXdFhnw== X-Mailru-Sender: 583F1D7ACE8F49BD4747F3DF20327BFB67A454E5EA3F803784F268382E0D6913347CBAF925AEE957226EF6DE27EFC373160348CE3D9367842C22B24405C8F0CC0C99F7F8EF33C0CE4F0A872F021F90597E6EE165445FBF8EC77752E0C033A69E3453F38A29522196 X-Mras: Ok X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, PDS_BTC_ID, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, TXREP 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 <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org |
Series |
Fix the right shift of negative numbers
|
|
Message
Sergey Kaplun
April 2, 2024, 8:17 p.m. UTC
The original issue is the incorrect truncated result of the right shift for negative values: ``` (gdb) p /t -3 $1 = 11111111111111111111111111111101 (gdb) p /t -3 >> 1 $2 = 11111111111111111111111111111111 ``` Where 11111111111111111111111111111110 is expected. This is due to the use of `mpz_tdiv_q_2exp()` instead of `mpz_fdiv_q_2exp()` for the right shift calculation. According to the documentation of gmplib [1]: ``` For positive n both mpz_fdiv_q_2exp and mpz_tdiv_q_2exp are simple bitwise right shifts. For negative n, mpz_fdiv_q_2exp is effectively an arithmetic right shift treating n as twos complement the same as the bitwise logical functions do, whereas mpz_tdiv_q_2exp effectively treats n as sign and magnitude. ``` The second patch fixes the behaviour and adds the testcase above to gdb.base/bitshift.exp. But when I tried to add the test, I've noticed that all test cases from this file are skipped due to using `return` instead of `continue` for the skip list of unhandled languages. So, I've enabled this test back in the first patch and fixed the behaviour for the negative shift of negative values. Unfortunately, some test cases for "opencl" still fail, so I've added it to the skip list for this version of the patch since I'm not very familiar with it (I need some guidance here): | make check TESTS="gdb.base/bitshift.exp" | grep FAIL | WARNING: Couldn't find the global config file. | FAIL: gdb.base/bitshift.exp: lang=opencl: 8-bit, promoted: print /x (signed char) 0x0f << 8 | FAIL: gdb.base/bitshift.exp: lang=opencl: 8-bit, promoted: print (signed char) 0x0f << 8 | FAIL: gdb.base/bitshift.exp: lang=opencl: 8-bit, invalid: print (signed char) 0x7f << -1 | FAIL: gdb.base/bitshift.exp: lang=opencl: 8-bit, invalid: print (signed char) 0x7f >> -1 | FAIL: gdb.base/bitshift.exp: lang=opencl: 8-bit, invalid: print/x (signed char) 0x7f << 8 | FAIL: gdb.base/bitshift.exp: lang=opencl: 8-bit, invalid: print/x (signed char) 0x7f >> 8 | FAIL: gdb.base/bitshift.exp: lang=opencl: 8-bit, invalid: print (signed char) 0x7f << 32 | FAIL: gdb.base/bitshift.exp: lang=opencl: 8-bit, invalid: print (signed char) 0x7f >> 32 | FAIL: gdb.base/bitshift.exp: lang=opencl: 8-bit, invalid: print (signed char) 0x7f << 33 | FAIL: gdb.base/bitshift.exp: lang=opencl: 8-bit, invalid: print (signed char) 0x7f >> 33 For other tests, I see no regressions (some 3 tests are flaky on master): | -# of expected passes 112908 | -# of unexpected failures 1791 | +# of expected passes 112011 | +# of unexpected failures 1788 | # of expected failures 219 | # of known failures 122 | # of untested testcases 22 Within enabled back gdb.base/bitshift.exp (and disabled opencl): | make check TESTS="gdb.base/bitshift.exp" | ... | === gdb Summary === | | # of expected passes 921 Tested on Linux 6.1.57-gentoo-x86_64 x86_64. Configure command flags: | --enable-build-warnings --enable-ubsan --enable-unit-tests=yes [1]: https://gmplib.org/gmp-man-6.2.1.pdf#Integer%20Division Sergey Kaplun (2): gdb/testsuite: enable back gdb.base/bitshift.exp Fix the right shift of negative numbers gdb/gmp-utils.h | 4 ++-- gdb/testsuite/gdb.base/bitshift.exp | 7 +++++-- gdb/valarith.c | 11 ++++++++++- 3 files changed, 17 insertions(+), 5 deletions(-)
Comments
Hi, guys! I see that my patch fixes the 31590 issue [1]. [1]: https://sourceware.org/bugzilla/show_bug.cgi?id=31590
>>>>> "Sergey" == Sergey Kaplun <sergey_v_kaplun@mail.ru> writes:
Sergey> Hi, guys!
Sergey> I see that my patch fixes the 31590 issue [1].
Sergey> [1]: https://sourceware.org/bugzilla/show_bug.cgi?id=31590
Hi. Do you have a copyright assignment in place?
I think we'll probably need one for this series.
Tom
On 23.04.24, Tom Tromey wrote: > >>>>> "Sergey" == Sergey Kaplun <sergey_v_kaplun@mail.ru> writes: > > Sergey> Hi, guys! > Sergey> I see that my patch fixes the 31590 issue [1]. > > Sergey> [1]: https://sourceware.org/bugzilla/show_bug.cgi?id=31590 > > Hi. Do you have a copyright assignment in place? > I think we'll probably need one for this series. > > Tom Hi, Tom. No, I don't have a copyright assignment yet. What do I need to do?