[RFA,02/13] Unused variable fixes related to conditional compilation

Message ID 20180712205208.32646-3-tom@tromey.com
State Superseded
Headers show
Series
  • Add -Wunused-variable
Related show

Commit Message

Tom Tromey July 12, 2018, 8:51 p.m.
This patch fixes various unused variable warnings that are related to
conditional compilation.  In these cases, either the variable is now
protected by the same #if as its uses, or the declaration is simply
lowered into the conditionally-compiled block.

gdb/ChangeLog
2018-07-12  Tom Tromey  <tom@tromey.com>

	* windows-nat.c (saved_context): Conditionally define.
	* remote.c (remote_target::remote_btrace_maybe_reopen):
	Conditionally declare "warned".
	* inflow.c (sigquit_ours): Conditionally define.
	(new_tty): Move "tty" declaration inside #if.
	* guile/guile.c (guile_datadir): Conditionally define.
	* charset.c (set_be_le_names): Move some declarations inside #if.
	* btrace.c (parse_xml_btrace): Move "errcode" declaration inside
	#if.
	(parse_xml_btrace_conf): Likewise.
---
 gdb/ChangeLog     | 13 +++++++++++++
 gdb/btrace.c      |  6 ++----
 gdb/charset.c     |  6 +++---
 gdb/guile/guile.c |  2 ++
 gdb/inflow.c      |  6 ++++--
 gdb/remote.c      |  2 ++
 gdb/windows-nat.c |  2 ++
 7 files changed, 28 insertions(+), 9 deletions(-)

-- 
2.13.6

Comments

Simon Marchi July 14, 2018, 1:16 a.m. | #1
On 2018-07-12 04:51 PM, Tom Tromey wrote:
> This patch fixes various unused variable warnings that are related to

> conditional compilation.  In these cases, either the variable is now

> protected by the same #if as its uses, or the declaration is simply

> lowered into the conditionally-compiled block.


This LGTM.

Simon
Simon Marchi July 14, 2018, 9:50 p.m. | #2
On 2018-07-13 09:16 PM, Simon Marchi wrote:
> On 2018-07-12 04:51 PM, Tom Tromey wrote:

>> This patch fixes various unused variable warnings that are related to

>> conditional compilation.  In these cases, either the variable is now

>> protected by the same #if as its uses, or the declaration is simply

>> lowered into the conditionally-compiled block.

> 

> This LGTM.

> 

> Simon

> 


I found a few more in a cross-compilation build that has !HAVE_ELF, for
some reason.

From e590cfda6ccb63a5270e36c636fb7daa567aa781 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@polymtl.ca>

Date: Fri, 13 Jul 2018 21:44:52 -0400
Subject: [PATCH] conditional compilation

---
 gdb/arm-tdep.c    | 13 +++++++------
 gdb/rs6000-tdep.c |  5 ++---
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index b1a05bbeba2d..c3280ee211d1 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -8955,7 +8955,6 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 	  else if (ei_osabi == ELFOSABI_NONE || ei_osabi == ELFOSABI_GNU)
 	    {
 	      int eabi_ver = EF_ARM_EABI_VERSION (e_flags);
-	      int attr_arch, attr_profile;

 	      switch (eabi_ver)
 		{
@@ -9026,11 +9025,13 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 		 executable file includes build attributes; GCC does
 		 copy them to the executable, but e.g. RealView does
 		 not.  */
-	      attr_arch = bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_PROC,
-						    Tag_CPU_arch);
-	      attr_profile = bfd_elf_get_obj_attr_int (info.abfd,
-						       OBJ_ATTR_PROC,
-						       Tag_CPU_arch_profile);
+	      int attr_arch
+		= bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_PROC,
+					    Tag_CPU_arch);
+	      int attr_profile
+		= bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_PROC,
+					    Tag_CPU_arch_profile);
+
 	      /* GCC specifies the profile for v6-M; RealView only
 		 specifies the profile for architectures starting with
 		 V7 (as opposed to architectures with a tag
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index 45bf98267a99..e78de49b2e69 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -3558,7 +3558,6 @@ bfd_uses_spe_extensions (bfd *abfd)
   bfd_size_type size;
   gdb_byte *ptr;
   int success = 0;
-  int vector_abi;

   if (!abfd)
     return 0;
@@ -3567,8 +3566,8 @@ bfd_uses_spe_extensions (bfd *abfd)
   /* Using Tag_GNU_Power_ABI_Vector here is a bit of a hack, as the user
      could be using the SPE vector abi without actually using any spe
      bits whatsoever.  But it's close enough for now.  */
-  vector_abi = bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_GNU,
-					 Tag_GNU_Power_ABI_Vector);
+  int vector_abi = bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_GNU,
+					     Tag_GNU_Power_ABI_Vector);
   if (vector_abi == 3)
     return 1;
 #endif
-- 
2.18.0
Pedro Alves July 16, 2018, 1:45 p.m. | #3
On 07/14/2018 10:50 PM, Simon Marchi wrote:

> I found a few more in a cross-compilation build that has !HAVE_ELF, for

> some reason.


LGTM.

Thanks,
Pedro Alves
Simon Marchi July 22, 2018, 2:24 a.m. | #4
On 2018-07-16 09:45 AM, Pedro Alves wrote:
> On 07/14/2018 10:50 PM, Simon Marchi wrote:

> 

>> I found a few more in a cross-compilation build that has !HAVE_ELF, for

>> some reason.

> 

> LGTM.

> 

> Thanks,

> Pedro Alves

> 


I pushed this.

Simon

Patch

diff --git a/gdb/btrace.c b/gdb/btrace.c
index 35dc90e8e67..e25f047ce24 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -2202,10 +2202,9 @@  static const struct gdb_xml_element btrace_elements[] = {
 void
 parse_xml_btrace (struct btrace_data *btrace, const char *buffer)
 {
-  int errcode;
-
 #if defined (HAVE_LIBEXPAT)
 
+  int errcode;
   btrace_data result;
   result.format = BTRACE_FORMAT_NONE;
 
@@ -2303,10 +2302,9 @@  static const struct gdb_xml_element btrace_conf_elements[] = {
 void
 parse_xml_btrace_conf (struct btrace_config *conf, const char *xml)
 {
-  int errcode;
-
 #if defined (HAVE_LIBEXPAT)
 
+  int errcode;
   errcode = gdb_xml_parse_quick (_("btrace-conf"), "btrace-conf.dtd",
 				 btrace_conf_elements, xml, conf);
   if (errcode != 0)
diff --git a/gdb/charset.c b/gdb/charset.c
index fcb24a48823..8bb2b4d669f 100644
--- a/gdb/charset.c
+++ b/gdb/charset.c
@@ -295,9 +295,6 @@  static struct gdbarch *be_le_arch;
 static void
 set_be_le_names (struct gdbarch *gdbarch)
 {
-  int i, len;
-  const char *target_wide;
-
   if (be_le_arch == gdbarch)
     return;
   be_le_arch = gdbarch;
@@ -307,6 +304,9 @@  set_be_le_names (struct gdbarch *gdbarch)
   target_wide_charset_le_name = "UTF-32LE";
   target_wide_charset_be_name = "UTF-32BE";
 #else
+  int i, len;
+  const char *target_wide;
+
   target_wide_charset_le_name = NULL;
   target_wide_charset_be_name = NULL;
 
diff --git a/gdb/guile/guile.c b/gdb/guile/guile.c
index 0bbbf6eac1f..efb59e3d2c3 100644
--- a/gdb/guile/guile.c
+++ b/gdb/guile/guile.c
@@ -46,8 +46,10 @@  int gdbscm_guile_major_version;
 int gdbscm_guile_minor_version;
 int gdbscm_guile_micro_version;
 
+#ifdef HAVE_GUILE
 /* The guile subdirectory within gdb's data-directory.  */
 static const char *guile_datadir;
+#endif
 
 /* Declared constants and enum for guile exception printing.  */
 const char gdbscm_print_excp_none[] = "none";
diff --git a/gdb/inflow.c b/gdb/inflow.c
index a3b5ba8abef..caff6462070 100644
--- a/gdb/inflow.c
+++ b/gdb/inflow.c
@@ -138,7 +138,9 @@  private:
    to SIG_IGN.  */
 
 static sighandler_t sigint_ours;
+#ifdef SIGQUIT
 static sighandler_t sigquit_ours;
+#endif
 
 /* The name of the tty (from the `tty' command) that we're giving to
    the inferior when starting it up.  This is only (and should only
@@ -825,11 +827,11 @@  check_syscall (const char *msg, int result)
 void
 new_tty (void)
 {
-  int tty;
-
   if (inferior_thisrun_terminal == 0)
     return;
 #if !defined(__GO32__) && !defined(_WIN32)
+  int tty;
+
 #ifdef TIOCNOTTY
   /* Disconnect the child process from our controlling terminal.  On some
      systems (SVR4 for example), this may cause a SIGTTOU, so temporarily
diff --git a/gdb/remote.c b/gdb/remote.c
index a81d67e5ede..a61680d242c 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -13717,7 +13717,9 @@  remote_target::remote_btrace_maybe_reopen ()
   struct remote_state *rs = get_remote_state ();
   struct thread_info *tp;
   int btrace_target_pushed = 0;
+#if !defined (HAVE_LIBIPT)
   int warned = 0;
+#endif
 
   scoped_restore_current_thread restore_thread;
 
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 8f4646d1cca..f9870b8bd1e 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -146,8 +146,10 @@  static GetConsoleFontSize_ftype *GetConsoleFontSize;
 
 static int have_saved_context;	/* True if we've saved context from a
 				   cygwin signal.  */
+#ifdef __CYGWIN__
 static CONTEXT saved_context;	/* Containes the saved context from a
 				   cygwin signal.  */
+#endif
 
 /* If we're not using the old Cygwin header file set, define the
    following which never should have been in the generic Win32 API