From patchwork Tue May 15 14:45:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 27269 Received: (qmail 126344 invoked by alias); 15 May 2018 14:45:35 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 126176 invoked by uid 89); 15 May 2018 14:45:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=H*r:0700 X-HELO: 9pmail.ess.barracuda.com Received: from 9pmail.ess.barracuda.com (HELO 9pmail.ess.barracuda.com) (64.235.154.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 15 May 2018 14:45:23 +0000 Received: from mipsdag02.mipstec.com (mail2.mips.com [12.201.5.32]) by mx1402.ess.rzc.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=NO); Tue, 15 May 2018 14:45:18 +0000 Received: from [10.20.78.107] (10.20.78.107) by mipsdag02.mipstec.com (10.20.40.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1415.2; Tue, 15 May 2018 07:45:46 -0700 Date: Tue, 15 May 2018 15:45:10 +0100 From: "Maciej W. Rozycki" To: CC: Andrew Burgess , Subject: [PATCH] gdb/x86: Fix `-Wstrict-overflow' build error in `i387_collect_xsave' Message-ID: User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 X-ClientProxiedBy: mipsdag02.mipstec.com (10.20.40.47) To mipsdag02.mipstec.com (10.20.40.47) X-BESS-ID: 1526395518-321458-2550-45053-1 X-BESS-VER: 2018.6-r1805102334 X-BESS-Apparent-Source-IP: 12.201.5.32 X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.193012 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS59374 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 Make `i' defined within `i387_collect_xsave' unsigned, removing a `-Werror=strict-overflow' compilation error: .../gdb/i387-tdep.c: In function 'void i387_collect_xsave(const regcache*, int, void*, int)': .../gdb/i387-tdep.c:1348:1: error: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Werror=strict-overflow] i387_collect_xsave (const struct regcache *regcache, int regnum, ^ cc1plus: all warnings being treated as errors Makefile:1610: recipe for target 'i387-tdep.o' failed make: *** [i387-tdep.o] Error 1 seen with GCC 5.4.0, a commit 8ee22052f690 ("gdb/x86: Handle kernels using compact xsave format") regression. While `regnum' can be -1 on entry to the function, to mean all registers, `i' is only used with non-negative register numbers. gdb/ * i387-tdep.c (i387_collect_xsave): Make `i' unsigned. --- Hi, I believe this comes from register numbers being retrieved from the `tdep' structure at run time and therefore making the compiler unable to statically determine in loop expression processing that the calculations made on `i' will not cause a signed overflow. NB the error message pointing at the function definition rather than the declaration of `i' makes it rather difficult to determine what the actual cause might be. I just hope it's only a peculiarity of the somewhat older version of the compiler and it has been fixed since. Could someone from the GCC mailing list please comment on that? OK to apply? Maciej --- gdb/i387-tdep.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) gdb-i387-collect-xsave-signed-overflow.diff Index: gdb/gdb/i387-tdep.c =================================================================== --- gdb.orig/gdb/i387-tdep.c 2018-05-10 22:13:05.000000000 +0100 +++ gdb/gdb/i387-tdep.c 2018-05-13 23:27:46.194412211 +0100 @@ -1354,7 +1354,7 @@ i387_collect_xsave (const struct regcach gdb_byte *p, *regs = (gdb_byte *) xsave; gdb_byte raw[I386_MAX_REGISTER_SIZE]; ULONGEST initial_xstate_bv, clear_bv, xstate_bv = 0; - int i; + unsigned int i; enum { x87_ctrl_or_mxcsr = 0x1,