From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 88616 invoked by alias); 23 Jan 2020 22:03:03 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 88604 invoked by uid 89); 23 Jan 2020 22:03:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 spammy=H*Ad:D*googlemail.com X-HELO: mail.efficios.com Received: from mail.efficios.com (HELO mail.efficios.com) (167.114.26.124) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Jan 2020 22:03:01 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id CFC86244847; Thu, 23 Jan 2020 17:02:59 -0500 (EST) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 7V_CMGohKG36; Thu, 23 Jan 2020 17:02:59 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 6D096244846; Thu, 23 Jan 2020 17:02:59 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 6D096244846 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1579816979; bh=xT1N2X2W0bEwgjwVPEGCosaTTJfFxzGz2sjc/UzI/JQ=; h=From:To:Date:Message-Id:MIME-Version; b=HznNJ49Z7k+YoP3kh4cERANQjKOiVYMHeSPzirELAeFChHA0UYCQjM+6BimhHH4Ks UaaTUiLSv7uotriDvOgPkq7YCLPbv4BNzzZs7GsZpJ3D89wCqfudDVrg6LbMPHVt2A 3DrX9TbXoQqTRNYYWCkL6s49UKmNJHsPfDN1GlamMF4QkjUMSz26RX0nK8sy29s5vK JsjZ5JZG/lscm90KxcwIUeWLfMQqTKq3uxpRG061gZJEalOYRmUCR8DwvR0aFPeEqW 1gIf4VXxxEalOzSCjGtHhtx1L5btoZ0g1B15dMwSWcALkLnrjOyf+F8DF2LarUACxQ yU/4HuWTHxALg== Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id vwWjxYiaqZ6E; Thu, 23 Jan 2020 17:02:59 -0500 (EST) Received: from smarchi-efficios.internal.efficios.com (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) by mail.efficios.com (Postfix) with ESMTPSA id 3CC142446DF; Thu, 23 Jan 2020 17:02:59 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Iain Sandoe , Simon Marchi Subject: [PATCH] gdb: fix variable shadowing error in darwin-nat.c Date: Thu, 23 Jan 2020 22:03:00 -0000 Message-Id: <20200123220256.1293-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2020-01/txt/msg00761.txt.bz2 We encounter this error when building on macOS with GCC. CXX darwin-nat.o /src-local/binutils-gdb/gdb/darwin-nat.c: In member function 'ptid_t darwin= _nat_target::wait_1(ptid_t, target_waitstatus*)': /src-local/binutils-gdb/gdb/darwin-nat.c:1264:18: error: declaration of 'in= f' shadows a previous local [-Werror=3Dshadow=3Dcompatible-local] for (inferior *inf : all_inferiors (this)) ^~~ /src-local/binutils-gdb/gdb/darwin-nat.c:1205:20: note: shadowed declaratio= n is here struct inferior *inf; ^~~ Fix it by moving the declaration of `inf` in the specific scopes that need it. I think it's clearer this way anyway, as it shows that it's not the same `inf` that is used in these different scopes. Thanks to Iain Sandoe for reporting this. I did not see this error at first, because I compile with the default system compiler on macOS, which is clang. The compiler flag we try to enable for this is `-Wshadow=3Dlocal`, which is not one recognized by clang. I checked to see if there would a version of the -Wshadow* warnings [1] we could enable for clang, that would catch this, but the only one that would is `-Wshadow` itself, and this is too invasive for us (which is why we enabled just -Wshadow=3Dlocal in the first place). [1] https://clang.llvm.org/docs/DiagnosticsReference.html#wshadow gdb/ChangeLog: * darwin-nat.c (darwin_nat_target::wait_1): Move `inf` declaration to narrower scopes. --- gdb/darwin-nat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index 27677d16eae1..3bd8d8ce003d 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -1202,7 +1202,6 @@ darwin_nat_target::wait_1 (ptid_t ptid, struct target= _waitstatus *status) mach_msg_header_t *hdr =3D &msgin.hdr; ptid_t res; darwin_thread_t *thread; - struct inferior *inf; =20 inferior_debug (2, _("darwin_wait: waiting for a message pid=3D%d thread=3D%lx\n"), @@ -1211,7 +1210,7 @@ darwin_nat_target::wait_1 (ptid_t ptid, struct target= _waitstatus *status) /* Handle fake stop events at first. */ if (darwin_inf_fake_stop !=3D NULL) { - inf =3D darwin_inf_fake_stop; + inferior *inf =3D darwin_inf_fake_stop; darwin_inf_fake_stop =3D NULL; =20 darwin_inferior *priv =3D get_darwin_inferior (inf); @@ -1250,6 +1249,7 @@ darwin_nat_target::wait_1 (ptid_t ptid, struct target= _waitstatus *status) if (darwin_debug_flag > 10) darwin_dump_message (hdr, darwin_debug_flag > 11); =20 + inferior *inf; res =3D decode_message (hdr, &thread, &inf, status); if (res =3D=3D minus_one_ptid) continue; @@ -1290,6 +1290,7 @@ darwin_nat_target::wait_1 (ptid_t ptid, struct target= _waitstatus *status) if (darwin_debug_flag > 10) darwin_dump_message (hdr, darwin_debug_flag > 11); =20 + inferior *inf; ptid2 =3D decode_message (hdr, &thread, &inf, &status2); =20 if (inf !=3D NULL && thread !=3D NULL --=20 2.25.0