[RFA,12/13] Add ATTRIBUTE_UNUSED to regdat.sh output

Message ID 20180712205208.32646-13-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey July 12, 2018, 8:52 p.m. UTC
  This changes regdat.sh to emit ATTRIBUTE_UNUSED for the
xmltarget_${name} variable.  This seemed simpler than trying to figure
out under exactly which circumstances each one was in fact used.

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

	* regformats/regdat.sh: Mark xmltarget_${name} with
	ATTRIBUTE_UNUSED.
---
 gdb/ChangeLog            | 5 +++++
 gdb/regformats/regdat.sh | 8 ++++----
 2 files changed, 9 insertions(+), 4 deletions(-)
  

Comments

Pedro Alves July 16, 2018, 3:11 p.m. UTC | #1
On 07/12/2018 09:52 PM, Tom Tromey wrote:
> This changes regdat.sh to emit ATTRIBUTE_UNUSED for the
> xmltarget_${name} variable.  This seemed simpler than trying to figure
> out under exactly which circumstances each one was in fact used.

Can you give an example configuration where you got a warning?

Thanks,
Pedro Alves

> 
> 2018-07-12  Tom Tromey  <tom@tromey.com>
> 
> 	* regformats/regdat.sh: Mark xmltarget_${name} with
> 	ATTRIBUTE_UNUSED.
> ---
>  gdb/ChangeLog            | 5 +++++
>  gdb/regformats/regdat.sh | 8 ++++----
>  2 files changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/gdb/regformats/regdat.sh b/gdb/regformats/regdat.sh
> index 5a8564ac50c..7868e757582 100755
> --- a/gdb/regformats/regdat.sh
> +++ b/gdb/regformats/regdat.sh
> @@ -164,12 +164,12 @@ done
>  echo
>  echo "static const char *expedite_regs_${name}[] = { \"`echo ${expedite} | sed 's/,/", "/g'`\", 0 };"
>  if test "${feature}" != x; then
> -  echo "static const char *xmltarget_${name} = 0;"
> +  echo "static const char *xmltarget_${name} ATTRIBUTE_UNUSED = 0;"
>  elif test "${xmltarget}" = x; then
>    if test "${xmlarch}" = x && test "${xmlosabi}" = x; then
> -    echo "static const char *xmltarget_${name} = 0;"
> +    echo "static const char *xmltarget_${name} ATTRIBUTE_UNUSED = 0;"
>    else
> -    echo "static const char *xmltarget_${name} = \"@<target>\\"
> +    echo "static const char *xmltarget_${name} ATTRIBUTE_UNUSED = \"@<target>\\"
>      if test "${xmlarch}" != x; then
>        echo "<architecture>${xmlarch}</architecture>\\"
>      fi
> @@ -179,7 +179,7 @@ elif test "${xmltarget}" = x; then
>      echo "</target>\";"
>    fi
>  else
> -  echo "static const char *xmltarget_${name} = \"${xmltarget}\";"
> +  echo "static const char *xmltarget_${name} ATTRIBUTE_UNUSED = \"${xmltarget}\";"
>  fi
>  echo
>  
>
  
Tom Tromey July 16, 2018, 4:40 p.m. UTC | #2
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> On 07/12/2018 09:52 PM, Tom Tromey wrote:
>> This changes regdat.sh to emit ATTRIBUTE_UNUSED for the
>> xmltarget_${name} variable.  This seemed simpler than trying to figure
>> out under exactly which circumstances each one was in fact used.

Pedro> Can you give an example configuration where you got a warning?

I only found this one via the buildbot:

https://gdb-build.sergiodj.net/builders/Fedora-s390x-m64/builds/9085


It fails like so:

s390-linux32-generated.c: In function ‘void init_registers_s390_linux32()’:
s390-linux32-generated.c:141:20: error: unused variable ‘xmltarget_s390_linux32’ [-Werror=unused-variable]
 static const char *xmltarget_s390_linux32 = "s390-linux32.xml";
                    ^~~~~~~~~~~~~~~~~~~~~~
s390-linux32v1-generated.c: In function ‘void init_registers_s390_linux32v1()’:
s390-linux32v1-generated.c:143:20: error: unused variable ‘xmltarget_s390_linux32v1’ [-Werror=unused-variable]
 static const char *xmltarget_s390_linux32v1 = "s390-linux32v1.xml";
                    ^~~~~~~~~~~~~~~~~~~~~~~~
s390-linux32-generated.c: At global scope:
s390-linux32-generated.c:141:20: error: ‘xmltarget_s390_linux32’ defined but not used [-Werror=unused-variable]
s390-linux32v1-generated.c: At global scope:
s390-linux32v1-generated.c:143:20: error: ‘xmltarget_s390_linux32v1’ defined but not used [-Werror=unused-variable]

Tom
  
Pedro Alves July 16, 2018, 5:54 p.m. UTC | #3
On 07/16/2018 05:40 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
> 
> Pedro> On 07/12/2018 09:52 PM, Tom Tromey wrote:
>>> This changes regdat.sh to emit ATTRIBUTE_UNUSED for the
>>> xmltarget_${name} variable.  This seemed simpler than trying to figure
>>> out under exactly which circumstances each one was in fact used.
> 
> Pedro> Can you give an example configuration where you got a warning?
> 
> I only found this one via the buildbot:
> 
> https://gdb-build.sergiodj.net/builders/Fedora-s390x-m64/builds/9085
> 
> 
> It fails like so:
> 
> s390-linux32-generated.c: In function ‘void init_registers_s390_linux32()’:
> s390-linux32-generated.c:141:20: error: unused variable ‘xmltarget_s390_linux32’ [-Werror=unused-variable]
>  static const char *xmltarget_s390_linux32 = "s390-linux32.xml";
>                     ^~~~~~~~~~~~~~~~~~~~~~
> s390-linux32v1-generated.c: In function ‘void init_registers_s390_linux32v1()’:
> s390-linux32v1-generated.c:143:20: error: unused variable ‘xmltarget_s390_linux32v1’ [-Werror=unused-variable]
>  static const char *xmltarget_s390_linux32v1 = "s390-linux32v1.xml";
>                     ^~~~~~~~~~~~~~~~~~~~~~~~
> s390-linux32-generated.c: At global scope:
> s390-linux32-generated.c:141:20: error: ‘xmltarget_s390_linux32’ defined but not used [-Werror=unused-variable]
> s390-linux32v1-generated.c: At global scope:
> s390-linux32v1-generated.c:143:20: error: ‘xmltarget_s390_linux32v1’ defined but not used [-Werror=unused-variable]

This is building an ipa object:

 s390-linux32-generated.c: In function ‘void init_registers_s390_linux32()’:
 s390-linux32-generated.c:141:20: error: unused variable ‘xmltarget_s390_linux32’ [-Werror=unused-variable]
  static const char *xmltarget_s390_linux32 = "s390-linux32.xml";
                     ^~~~~~~~~~~~~~~~~~~~~~
 s390-linux32v1-generated.c: In function ‘void init_registers_s390_linux32v1()’:
 s390-linux32v1-generated.c:143:20: error: unused variable ‘xmltarget_s390_linux32v1’ [-Werror=unused-variable]
  static const char *xmltarget_s390_linux32v1 = "s390-linux32v1.xml";
                     ^~~~~~~~~~~~~~~~~~~~~~~~
 s390-linux32-generated.c: At global scope:
 s390-linux32-generated.c:141:20: error: ‘xmltarget_s390_linux32’ defined but not used [-Werror=unused-variable]
 s390-linux32v1-generated.c: At global scope:
 s390-linux32v1-generated.c:143:20: error: ‘xmltarget_s390_linux32v1’ defined but not used [-Werror=unused-variable]
 cc1plus: all warnings being treated as errors
 make[4]: *** [Makefile:576: s390-linux32-ipa.o] Error 1

The generated files look something like this (here for x86-64):

 static const char *expedite_regs_amd64_linux[] = { "rbp", "rsp", "rip", 0 };
 static const char *xmltarget_amd64_linux = 0;
 
 #ifndef IN_PROCESS_AGENT
   result->xmltarget = xmltarget_amd64_linux;
 #endif
 
So the xmltarget_foo variable is defined unconditionally, but
used only when #ifndef IN_PROCESS_AGENT.  So if we wrap the variable
definition in !IN_PROCESS_AGENT too, the warning should go away.

I guess that getting warning or not is most likely dependent on
GCC version.

Thanks,
Pedro Alves
  
Tom Tromey July 16, 2018, 7:05 p.m. UTC | #4
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> So the xmltarget_foo variable is defined unconditionally, but
Pedro> used only when #ifndef IN_PROCESS_AGENT.  So if we wrap the variable
Pedro> definition in !IN_PROCESS_AGENT too, the warning should go away.

Thanks for looking into this.
I'm testing a series with this update.

Tom
  
Tom Tromey July 16, 2018, 9:12 p.m. UTC | #5
>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
Pedro> So the xmltarget_foo variable is defined unconditionally, but
Pedro> used only when #ifndef IN_PROCESS_AGENT.  So if we wrap the variable
Pedro> definition in !IN_PROCESS_AGENT too, the warning should go away.

Tom> Thanks for looking into this.
Tom> I'm testing a series with this update.

To my surprise this turned out amazingly badly.
I don't know why yet.

Tom
  

Patch

diff --git a/gdb/regformats/regdat.sh b/gdb/regformats/regdat.sh
index 5a8564ac50c..7868e757582 100755
--- a/gdb/regformats/regdat.sh
+++ b/gdb/regformats/regdat.sh
@@ -164,12 +164,12 @@  done
 echo
 echo "static const char *expedite_regs_${name}[] = { \"`echo ${expedite} | sed 's/,/", "/g'`\", 0 };"
 if test "${feature}" != x; then
-  echo "static const char *xmltarget_${name} = 0;"
+  echo "static const char *xmltarget_${name} ATTRIBUTE_UNUSED = 0;"
 elif test "${xmltarget}" = x; then
   if test "${xmlarch}" = x && test "${xmlosabi}" = x; then
-    echo "static const char *xmltarget_${name} = 0;"
+    echo "static const char *xmltarget_${name} ATTRIBUTE_UNUSED = 0;"
   else
-    echo "static const char *xmltarget_${name} = \"@<target>\\"
+    echo "static const char *xmltarget_${name} ATTRIBUTE_UNUSED = \"@<target>\\"
     if test "${xmlarch}" != x; then
       echo "<architecture>${xmlarch}</architecture>\\"
     fi
@@ -179,7 +179,7 @@  elif test "${xmltarget}" = x; then
     echo "</target>\";"
   fi
 else
-  echo "static const char *xmltarget_${name} = \"${xmltarget}\";"
+  echo "static const char *xmltarget_${name} ATTRIBUTE_UNUSED = \"${xmltarget}\";"
 fi
 echo