public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 2/3] vec: Silence -Wunused-function warnings on clang
  2017-06-25 17:45 [PATCH 0/3] Third series towards a warning-less clang build Simon Marchi
@ 2017-06-25 17:45 ` Simon Marchi
  2017-06-26  9:28   ` Pedro Alves
  2017-06-25 17:45 ` [PATCH 1/3] ada-lex: Ignore warnings about register keyword Simon Marchi
  2017-06-25 17:45 ` [PATCH 3/3] record-full: Remove unused function netorder16 Simon Marchi
  2 siblings, 1 reply; 15+ messages in thread
From: Simon Marchi @ 2017-06-25 17:45 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

clang has a too aggressive (or broken, depends on how you want to see
it) -Wunused-function warning, which is triggered by the functions
defined by DEF_VEC_* but not used in the current source file.  Normally,
it won't warn about unused static inline functions defined in header
files, because it's expected that a source file won't use all functions
defined in a header file it includes.  However, the DEF_VEC_* macros
define those functions in source files, which leads clang to think that
we should remove those functions.  It is therefore missing a check to
see whether those functions are resulting from macro expansion.  A bug
already exists for that:

  https://bugs.llvm.org//show_bug.cgi?id=22712

It's quite easy to silence this warning in a localized way, that is in
the DEF_VEC_* macros.

gdb/ChangeLog:

	* common/diagnostics.h (DIAGNOSTIC_IGNORE_UNUSED_FUNCTION): New
	macro.
	* common/vec.h: Include diagnostics.h.
	(DEF_VEC_I, DEF_VEC_P, DEF_VEC_O): Ignore -Wunused-function
	warning.
---
 gdb/common/diagnostics.h |  3 +++
 gdb/common/vec.h         | 11 +++++++++++
 2 files changed, 14 insertions(+)

diff --git a/gdb/common/diagnostics.h b/gdb/common/diagnostics.h
index 35bacf2..ee824a3 100644
--- a/gdb/common/diagnostics.h
+++ b/gdb/common/diagnostics.h
@@ -35,9 +35,12 @@
 # define DIAGNOSTIC_IGNORE_SELF_MOVE DIAGNOSTIC_IGNORE ("-Wself-move")
 # define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER \
   DIAGNOSTIC_IGNORE ("-Wdeprecated-register")
+# define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION \
+  DIAGNOSTIC_IGNORE ("-Wunused-function")
 #else
 # define DIAGNOSTIC_IGNORE_SELF_MOVE
 # define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER
+# define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION
 #endif
 
 #endif /* COMMON_DIAGNOSTICS_H */
diff --git a/gdb/common/vec.h b/gdb/common/vec.h
index 982f771..0221c88 100644
--- a/gdb/common/vec.h
+++ b/gdb/common/vec.h
@@ -20,6 +20,8 @@
 #if !defined (GDB_VEC_H)
 #define GDB_VEC_H
 
+#include "diagnostics.h"
+
 /* The macros here implement a set of templated vector types and
    associated interfaces.  These templates are implemented with
    macros, as we're not in C++ land.  The interface functions are
@@ -408,6 +410,8 @@ typedef struct VEC(T)							  \
 
 /* Vector of integer-like object.  */
 #define DEF_VEC_I(T)							  \
+DIAGNOSTIC_PUSH 							  \
+DIAGNOSTIC_IGNORE_UNUSED_FUNCTION					  \
 static inline void VEC_OP (T,must_be_integral_type) (void)		  \
 {									  \
   (void)~(T)0;								  \
@@ -416,10 +420,13 @@ static inline void VEC_OP (T,must_be_integral_type) (void)		  \
 VEC_T(T);								  \
 DEF_VEC_FUNC_P(T)							  \
 DEF_VEC_ALLOC_FUNC_I(T)							  \
+DIAGNOSTIC_POP								  \
 struct vec_swallow_trailing_semi
 
 /* Vector of pointer to object.  */
 #define DEF_VEC_P(T)							  \
+DIAGNOSTIC_PUSH 							  \
+DIAGNOSTIC_IGNORE_UNUSED_FUNCTION					  \
 static inline void VEC_OP (T,must_be_pointer_type) (void)		  \
 {									  \
   (void)((T)1 == (void *)1);						  \
@@ -428,13 +435,17 @@ static inline void VEC_OP (T,must_be_pointer_type) (void)		  \
 VEC_T(T);								  \
 DEF_VEC_FUNC_P(T)							  \
 DEF_VEC_ALLOC_FUNC_P(T)							  \
+DIAGNOSTIC_POP								  \
 struct vec_swallow_trailing_semi
 
 /* Vector of object.  */
 #define DEF_VEC_O(T)							  \
+DIAGNOSTIC_PUSH 							  \
+DIAGNOSTIC_IGNORE_UNUSED_FUNCTION					  \
 VEC_T(T);								  \
 DEF_VEC_FUNC_O(T)							  \
 DEF_VEC_ALLOC_FUNC_O(T)							  \
+DIAGNOSTIC_POP								  \
 struct vec_swallow_trailing_semi
 
 /* Avoid offsetof (or its usual C implementation) as it triggers
-- 
2.7.4

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 3/3] record-full: Remove unused function netorder16
  2017-06-25 17:45 [PATCH 0/3] Third series towards a warning-less clang build Simon Marchi
  2017-06-25 17:45 ` [PATCH 2/3] vec: Silence -Wunused-function warnings on clang Simon Marchi
  2017-06-25 17:45 ` [PATCH 1/3] ada-lex: Ignore warnings about register keyword Simon Marchi
@ 2017-06-25 17:45 ` Simon Marchi
  2017-06-26 10:43   ` Yao Qi
  2 siblings, 1 reply; 15+ messages in thread
From: Simon Marchi @ 2017-06-25 17:45 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

clang shows this warning:

  /home/emaisin/src/binutils-gdb/gdb/record-full.c:2344:1: error: unused function 'netorder16' [-Werror,-Wunused-function]
  netorder16 (uint16_t input)
  ^

Remove this function, which, AFAIK, has never been used.  Note that GCC
doesn't warn about this, because the function is marked as inline.
According to gcc's man page, it should ideed not warn:

  -Wunused-function
    Warn whenever a static function is declared but not defined or a non-inline static function is unused.  This warning is enabled by -Wall.

So it's probably not a GCC bug that it doesn't find this unused function, but a
different definition of "unused".

gdb/ChangeLog:

	* record-full.c (netorder16): Remove.
---
 gdb/record-full.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/gdb/record-full.c b/gdb/record-full.c
index 8e774a2..7f6ecc7 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -2340,16 +2340,6 @@ netorder32 (uint32_t input)
   return ret;
 }
 
-static inline uint16_t
-netorder16 (uint16_t input)
-{
-  uint16_t ret;
-
-  store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret), 
-			  BFD_ENDIAN_BIG, input);
-  return ret;
-}
-
 /* Restore the execution log from a core_bfd file.  */
 static void
 record_full_restore (void)
-- 
2.7.4

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 1/3] ada-lex: Ignore warnings about register keyword
  2017-06-25 17:45 [PATCH 0/3] Third series towards a warning-less clang build Simon Marchi
  2017-06-25 17:45 ` [PATCH 2/3] vec: Silence -Wunused-function warnings on clang Simon Marchi
@ 2017-06-25 17:45 ` Simon Marchi
  2017-06-26 13:13   ` Pedro Alves
  2017-06-25 17:45 ` [PATCH 3/3] record-full: Remove unused function netorder16 Simon Marchi
  2 siblings, 1 reply; 15+ messages in thread
From: Simon Marchi @ 2017-06-25 17:45 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Some older versions of flex (such as the one shipped with macOS) generate
code that use the register keyword, which clang warns about.  This patch
makes the compiler ignore those warnings for the portion of the code
generated by flex.

gdb/ChangeLog:

	* common/diagnostics.h (DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER):
	New macro.
	* ada-lex.l: Ignore deprecated register warnings.
---
 gdb/ada-lex.l            | 9 +++++++++
 gdb/common/diagnostics.h | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l
index 0825290..098272f 100644
--- a/gdb/ada-lex.l
+++ b/gdb/ada-lex.l
@@ -41,6 +41,13 @@ POSEXP  (e"+"?{NUM10})
 
 %{
 
+#include "common/diagnostics.h"
+
+/* Some older versions of flex generate code that uses the "register" keyword,
+   which clang warns about.  */
+DIAGNOSTIC_PUSH
+DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER
+
 #define NUMERAL_WIDTH 256
 #define LONGEST_SIGN ((ULONGEST) 1 << (sizeof(LONGEST) * HOST_CHAR_BIT - 1))
 
@@ -648,3 +655,5 @@ dummy_function ada_flex_use[] =
 { 
   (dummy_function) yyunput
 };
+
+DIAGNOSTIC_POP
diff --git a/gdb/common/diagnostics.h b/gdb/common/diagnostics.h
index 5a63bfd..35bacf2 100644
--- a/gdb/common/diagnostics.h
+++ b/gdb/common/diagnostics.h
@@ -33,8 +33,11 @@
 
 #ifdef __clang__
 # define DIAGNOSTIC_IGNORE_SELF_MOVE DIAGNOSTIC_IGNORE ("-Wself-move")
+# define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER \
+  DIAGNOSTIC_IGNORE ("-Wdeprecated-register")
 #else
 # define DIAGNOSTIC_IGNORE_SELF_MOVE
+# define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER
 #endif
 
 #endif /* COMMON_DIAGNOSTICS_H */
-- 
2.7.4

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 0/3] Third series towards a warning-less clang build
@ 2017-06-25 17:45 Simon Marchi
  2017-06-25 17:45 ` [PATCH 2/3] vec: Silence -Wunused-function warnings on clang Simon Marchi
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Simon Marchi @ 2017-06-25 17:45 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

This series fixes a few last issues we get when building with clang and
-Werror.  It was not as bad as I expected (especially the vec.h warnings).
Combined with this patch:

  https://sourceware.org/ml/gdb-patches/2017-06/msg00252.html

gdb itself builds cleanly with clang and -Werror (not the rest of the
binutils-gdb repo yet through).

Simon Marchi (3):
  ada-lex: Ignore warnings about register keyword
  vec: Silence -Wunused-function warnings on clang
  record-full: Remove unused function netorder16

 gdb/ada-lex.l            |  9 +++++++++
 gdb/common/diagnostics.h |  6 ++++++
 gdb/common/vec.h         | 11 +++++++++++
 gdb/record-full.c        | 10 ----------
 4 files changed, 26 insertions(+), 10 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 2/3] vec: Silence -Wunused-function warnings on clang
  2017-06-25 17:45 ` [PATCH 2/3] vec: Silence -Wunused-function warnings on clang Simon Marchi
@ 2017-06-26  9:28   ` Pedro Alves
  2017-06-26 12:28     ` Simon Marchi
  2017-06-26 12:46     ` [PATCH 2/3 v2] " Simon Marchi
  0 siblings, 2 replies; 15+ messages in thread
From: Pedro Alves @ 2017-06-26  9:28 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 06/25/2017 06:45 PM, Simon Marchi wrote:
> clang has a too aggressive (or broken, depends on how you want to see
> it) -Wunused-function warning, 

There's no way to avoid the warning in this use case, so I can't see
how to call it anything but the latter.

> which is triggered by the functions
> defined by DEF_VEC_* but not used in the current source file.  Normally,
> it won't warn about unused static inline functions defined in header
> files, because it's expected that a source file won't use all functions
> defined in a header file it includes.  However, the DEF_VEC_* macros
> define those functions in source files, which leads clang to think that
> we should remove those functions.  It is therefore missing a check to
> see whether those functions are resulting from macro expansion.  A bug
> already exists for that:
> 
>   https://bugs.llvm.org//show_bug.cgi?id=22712
> 
> It's quite easy to silence this warning in a localized way, that is in
> the DEF_VEC_* macros.
> 
> gdb/ChangeLog:
> 
> 	* common/diagnostics.h (DIAGNOSTIC_IGNORE_UNUSED_FUNCTION): New
> 	macro.
> 	* common/vec.h: Include diagnostics.h.
> 	(DEF_VEC_I, DEF_VEC_P, DEF_VEC_O): Ignore -Wunused-function
> 	warning.
> ---
>  gdb/common/diagnostics.h |  3 +++
>  gdb/common/vec.h         | 11 +++++++++++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/gdb/common/diagnostics.h b/gdb/common/diagnostics.h
> index 35bacf2..ee824a3 100644
> --- a/gdb/common/diagnostics.h
> +++ b/gdb/common/diagnostics.h
> @@ -35,9 +35,12 @@
>  # define DIAGNOSTIC_IGNORE_SELF_MOVE DIAGNOSTIC_IGNORE ("-Wself-move")
>  # define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER \
>    DIAGNOSTIC_IGNORE ("-Wdeprecated-register")
> +# define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION \
> +  DIAGNOSTIC_IGNORE ("-Wunused-function")

GCC also understands this warning.  So I think we should define
the ignore macro for GCC too.

Now that raises the question of whether you want to suppress the
warning in vec.h for GCC too.  But that's actually the point
that made me come here to comment:

Imagine that we'll want to suppress -Wunused-function with GCC
in some other source file, for some reason.  At that point we'll
naturally want to adjust diagnostics.h to define

 # define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION \
   DIAGNOSTIC_IGNORE ("-Wunused-function")

for GCC too instead of leaving DIAGNOSTIC_IGNORE_UNUSED_FUNCTION empty
for GCC.  But, that will make the existing (at that time) users
of DIAGNOSTIC_IGNORE_UNUSED_FUNCTION start suppressing the warning
on GCC too, and we may or not want that.

This, to me indicates that:

#1 - The common/diagnostics.h macros define the non-empty "ignore"
   macro on all compilers that understand it.  Then vec.h does:

DIAGNOSTIC_PUSH
#ifdef __clang__
DIAGNOSTIC_IGNORE_UNUSED_FUNCTION					  
#endif

#2 - We name the macro something else more targeted for this
specific use case, and define it to empty for GCC, and to
-Wunused-function on clang.  

#2.1 - If put on common/diagnostics.h, name it something
       generic, like:

/* Suppress -Wunused-function for functions defined in source files as
   result of expanding macros (that define the functions) defined
   in headers.  */
#ifdef __lang
# define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION_HEADER_MACRO_EXPANSION \
    DIAGNOSTIC_IGNORE_UNUSED_FUNCTION
#else
# define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION_HEADER_MACRO_EXPANSION
#endif

#2.2 - Otherwise, define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION
for for GCC and clang, and put something like this on
top of vec.h:

/* Comment describing issue and pointing to clang bug report.  */
#ifdef __clang__
 #define DIAGNOSTIC_IGNORE_UNUSED_VEC_FUNCTION \
    DIAGNOSTIC_IGNORE_UNUSED_FUNCTION
#else
 #define DIAGNOSTIC_IGNORE_UNUSED_VEC_FUNCTION
#endif

And use that instead of DIAGNOSTIC_IGNORE_FUNCTION.

I think I prefer #2.2, then #2.1, then #1.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 3/3] record-full: Remove unused function netorder16
  2017-06-25 17:45 ` [PATCH 3/3] record-full: Remove unused function netorder16 Simon Marchi
@ 2017-06-26 10:43   ` Yao Qi
  2017-06-26 14:54     ` Simon Marchi
  0 siblings, 1 reply; 15+ messages in thread
From: Yao Qi @ 2017-06-26 10:43 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

On Sun, Jun 25, 2017 at 6:45 PM, Simon Marchi <simon.marchi@ericsson.com> wrote:
> gdb/ChangeLog:
>
>         * record-full.c (netorder16): Remove.

Patch is good to me.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 2/3] vec: Silence -Wunused-function warnings on clang
  2017-06-26  9:28   ` Pedro Alves
@ 2017-06-26 12:28     ` Simon Marchi
  2017-06-26 12:47       ` Pedro Alves
  2017-06-26 12:46     ` [PATCH 2/3 v2] " Simon Marchi
  1 sibling, 1 reply; 15+ messages in thread
From: Simon Marchi @ 2017-06-26 12:28 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Simon Marchi, gdb-patches

On 2017-06-26 11:28, Pedro Alves wrote:
> On 06/25/2017 06:45 PM, Simon Marchi wrote:
>> clang has a too aggressive (or broken, depends on how you want to see
>> it) -Wunused-function warning,
> 
> There's no way to avoid the warning in this use case, so I can't see
> how to call it anything but the latter.
> 
>> which is triggered by the functions
>> defined by DEF_VEC_* but not used in the current source file.  
>> Normally,
>> it won't warn about unused static inline functions defined in header
>> files, because it's expected that a source file won't use all 
>> functions
>> defined in a header file it includes.  However, the DEF_VEC_* macros
>> define those functions in source files, which leads clang to think 
>> that
>> we should remove those functions.  It is therefore missing a check to
>> see whether those functions are resulting from macro expansion.  A bug
>> already exists for that:
>> 
>>   https://bugs.llvm.org//show_bug.cgi?id=22712
>> 
>> It's quite easy to silence this warning in a localized way, that is in
>> the DEF_VEC_* macros.
>> 
>> gdb/ChangeLog:
>> 
>> 	* common/diagnostics.h (DIAGNOSTIC_IGNORE_UNUSED_FUNCTION): New
>> 	macro.
>> 	* common/vec.h: Include diagnostics.h.
>> 	(DEF_VEC_I, DEF_VEC_P, DEF_VEC_O): Ignore -Wunused-function
>> 	warning.
>> ---
>>  gdb/common/diagnostics.h |  3 +++
>>  gdb/common/vec.h         | 11 +++++++++++
>>  2 files changed, 14 insertions(+)
>> 
>> diff --git a/gdb/common/diagnostics.h b/gdb/common/diagnostics.h
>> index 35bacf2..ee824a3 100644
>> --- a/gdb/common/diagnostics.h
>> +++ b/gdb/common/diagnostics.h
>> @@ -35,9 +35,12 @@
>>  # define DIAGNOSTIC_IGNORE_SELF_MOVE DIAGNOSTIC_IGNORE 
>> ("-Wself-move")
>>  # define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER \
>>    DIAGNOSTIC_IGNORE ("-Wdeprecated-register")
>> +# define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION \
>> +  DIAGNOSTIC_IGNORE ("-Wunused-function")
> 
> GCC also understands this warning.  So I think we should define
> the ignore macro for GCC too.
> 
> Now that raises the question of whether you want to suppress the
> warning in vec.h for GCC too.  But that's actually the point
> that made me come here to comment:
> 
> Imagine that we'll want to suppress -Wunused-function with GCC
> in some other source file, for some reason.  At that point we'll
> naturally want to adjust diagnostics.h to define
> 
>  # define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION \
>    DIAGNOSTIC_IGNORE ("-Wunused-function")
> 
> for GCC too instead of leaving DIAGNOSTIC_IGNORE_UNUSED_FUNCTION empty
> for GCC.  But, that will make the existing (at that time) users
> of DIAGNOSTIC_IGNORE_UNUSED_FUNCTION start suppressing the warning
> on GCC too, and we may or not want that.
> 
> This, to me indicates that:
> 
> #1 - The common/diagnostics.h macros define the non-empty "ignore"
>    macro on all compilers that understand it.  Then vec.h does:
> 
> DIAGNOSTIC_PUSH
> #ifdef __clang__
> DIAGNOSTIC_IGNORE_UNUSED_FUNCTION					
> #endif
> 
> #2 - We name the macro something else more targeted for this
> specific use case, and define it to empty for GCC, and to
> -Wunused-function on clang.
> 
> #2.1 - If put on common/diagnostics.h, name it something
>        generic, like:
> 
> /* Suppress -Wunused-function for functions defined in source files as
>    result of expanding macros (that define the functions) defined
>    in headers.  */
> #ifdef __lang
> # define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION_HEADER_MACRO_EXPANSION \
>     DIAGNOSTIC_IGNORE_UNUSED_FUNCTION
> #else
> # define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION_HEADER_MACRO_EXPANSION
> #endif
> 
> #2.2 - Otherwise, define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION
> for for GCC and clang, and put something like this on
> top of vec.h:
> 
> /* Comment describing issue and pointing to clang bug report.  */
> #ifdef __clang__
>  #define DIAGNOSTIC_IGNORE_UNUSED_VEC_FUNCTION \
>     DIAGNOSTIC_IGNORE_UNUSED_FUNCTION
> #else
>  #define DIAGNOSTIC_IGNORE_UNUSED_VEC_FUNCTION
> #endif
> 
> And use that instead of DIAGNOSTIC_IGNORE_FUNCTION.
> 
> I think I prefer #2.2, then #2.1, then #1.
> 
> Thanks,
> Pedro Alves

I wanted to keep it simple and easy to understand, so I didn't want to 
add to many layers of definitions.  I thought that even if we ignored 
-Wunused-function in the vector macro expansions when compiling with 
GCC, it wasn't a big deal.  But 2.2 is fine with me, I'll try it.  It's 
all temporary anyway (famous last words), since the days of vec.h are 
counted :).

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 2/3 v2] vec: Silence -Wunused-function warnings on clang
  2017-06-26  9:28   ` Pedro Alves
  2017-06-26 12:28     ` Simon Marchi
@ 2017-06-26 12:46     ` Simon Marchi
  2017-06-26 13:03       ` Pedro Alves
  1 sibling, 1 reply; 15+ messages in thread
From: Simon Marchi @ 2017-06-26 12:46 UTC (permalink / raw)
  To: gdb-patches; +Cc: Pedro Alves, Simon Marchi

New in v2:

 - Define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION for GCC too.
 - Define DIAGNOSTIC_IGNORE_UNUSED_VEC_FUNCTION on clang only and use it.

clang has a too aggressive (or broken, depends on how you want to see
it) -Wunused-function warning, which is triggered by the functions
defined by DEF_VEC_* but not used in the current source file.  Normally,
it won't warn about unused static inline functions defined in header
files, because it's expected that a source file won't use all functions
defined in a header file it includes.  However, if the DEF_VEC_* macro
is used in a source file, it considers those functions as defined in the
source file, which leads it to think that we should remove those
functions.  It is therefore missing a check to see whether those
functions are resulting from macro expansion.  A bug already exists for
that:

  https://bugs.llvm.org//show_bug.cgi?id=22712

It's quite easy to silence this warning in a localized way, that is in
the DEF_VEC_* macros.

gdb/ChangeLog:

	* common/diagnostics.h: Define macros for GCC.
	(DIAGNOSTIC_IGNORE_UNUSED_FUNCTION): New macro.
	* common/vec.h: Include diagnostics.h.
	(DIAGNOSTIC_IGNORE_UNUSED_VEC_FUNCTION): New macro.
	(DEF_VEC_I, DEF_VEC_P, DEF_VEC_O): Ignore -Wunused-function
	warning.
---
 gdb/common/diagnostics.h | 17 +++++++++++++++--
 gdb/common/vec.h         | 25 +++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/gdb/common/diagnostics.h b/gdb/common/diagnostics.h
index 35bacf2..d6ab698 100644
--- a/gdb/common/diagnostics.h
+++ b/gdb/common/diagnostics.h
@@ -31,13 +31,26 @@
 # define DIAGNOSTIC_IGNORE(option)
 #endif
 
-#ifdef __clang__
+#if defined (__clang__) /* clang */
+
 # define DIAGNOSTIC_IGNORE_SELF_MOVE DIAGNOSTIC_IGNORE ("-Wself-move")
 # define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER \
   DIAGNOSTIC_IGNORE ("-Wdeprecated-register")
-#else
+# define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION \
+  DIAGNOSTIC_IGNORE ("-Wunused-function")
+
+#elif defined (__GNUC__) /* GCC */
+
+# define DIAGNOSTIC_IGNORE_SELF_MOVE
+# define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER
+# define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION \
+  DIAGNOSTIC_IGNORE ("-Wunused-function")
+
+#else /* Other compilers */
+
 # define DIAGNOSTIC_IGNORE_SELF_MOVE
 # define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER
+# define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION
 #endif
 
 #endif /* COMMON_DIAGNOSTICS_H */
diff --git a/gdb/common/vec.h b/gdb/common/vec.h
index 982f771..98d4576 100644
--- a/gdb/common/vec.h
+++ b/gdb/common/vec.h
@@ -20,6 +20,22 @@
 #if !defined (GDB_VEC_H)
 #define GDB_VEC_H
 
+#include "diagnostics.h"
+
+/* clang has a bug that makes it warn (-Wunused-function) about unused functions
+   that are the result of the DEF_VEC_* macro expansion.  See:
+
+     https://bugs.llvm.org/show_bug.cgi?id=22712
+
+   We specifically ignore this warning for the vec functions when the compiler
+   is clang.  */
+#ifdef __clang__
+# define DIAGNOSTIC_IGNORE_UNUSED_VEC_FUNCTION \
+    DIAGNOSTIC_IGNORE_UNUSED_FUNCTION
+#else
+# define DIAGNOSTIC_IGNORE_UNUSED_VEC_FUNCTION
+#endif
+
 /* The macros here implement a set of templated vector types and
    associated interfaces.  These templates are implemented with
    macros, as we're not in C++ land.  The interface functions are
@@ -408,6 +424,8 @@ typedef struct VEC(T)							  \
 
 /* Vector of integer-like object.  */
 #define DEF_VEC_I(T)							  \
+DIAGNOSTIC_PUSH 							  \
+DIAGNOSTIC_IGNORE_UNUSED_VEC_FUNCTION					  \
 static inline void VEC_OP (T,must_be_integral_type) (void)		  \
 {									  \
   (void)~(T)0;								  \
@@ -416,10 +434,13 @@ static inline void VEC_OP (T,must_be_integral_type) (void)		  \
 VEC_T(T);								  \
 DEF_VEC_FUNC_P(T)							  \
 DEF_VEC_ALLOC_FUNC_I(T)							  \
+DIAGNOSTIC_POP								  \
 struct vec_swallow_trailing_semi
 
 /* Vector of pointer to object.  */
 #define DEF_VEC_P(T)							  \
+DIAGNOSTIC_PUSH 							  \
+DIAGNOSTIC_IGNORE_UNUSED_VEC_FUNCTION					  \
 static inline void VEC_OP (T,must_be_pointer_type) (void)		  \
 {									  \
   (void)((T)1 == (void *)1);						  \
@@ -428,13 +449,17 @@ static inline void VEC_OP (T,must_be_pointer_type) (void)		  \
 VEC_T(T);								  \
 DEF_VEC_FUNC_P(T)							  \
 DEF_VEC_ALLOC_FUNC_P(T)							  \
+DIAGNOSTIC_POP								  \
 struct vec_swallow_trailing_semi
 
 /* Vector of object.  */
 #define DEF_VEC_O(T)							  \
+DIAGNOSTIC_PUSH 							  \
+DIAGNOSTIC_IGNORE_UNUSED_VEC_FUNCTION					  \
 VEC_T(T);								  \
 DEF_VEC_FUNC_O(T)							  \
 DEF_VEC_ALLOC_FUNC_O(T)							  \
+DIAGNOSTIC_POP								  \
 struct vec_swallow_trailing_semi
 
 /* Avoid offsetof (or its usual C implementation) as it triggers
-- 
2.7.4

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 2/3] vec: Silence -Wunused-function warnings on clang
  2017-06-26 12:28     ` Simon Marchi
@ 2017-06-26 12:47       ` Pedro Alves
  2017-06-26 12:52         ` Simon Marchi
  0 siblings, 1 reply; 15+ messages in thread
From: Pedro Alves @ 2017-06-26 12:47 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Simon Marchi, gdb-patches

On 06/26/2017 01:28 PM, Simon Marchi wrote:

> I wanted to keep it simple and easy to understand, so I didn't want to
> add to many layers of definitions.  I thought that even if we ignored
> -Wunused-function in the vector macro expansions when compiling with
> GCC, it wasn't a big deal.

That's another option (and I think it should be fine, with a comment),
but it wasn't what the patch was doing, so you'd be leaving deciding
whether that's fine to whoever comes next and wants to make
DIAGNOSTICS_IGNORE_UNUSED_FUNCTION on gcc.  IMO, that's a form of
technical dept that we should avoid.

The point here I'm trying to convey is: avoid letting the specifics
of users of the DIAGNOSTICS_IGNORE users bleed into the conditionals
that are used to define the macros in diagnostics.h.  At least
for the macros that map directly to the warning name.

> But 2.2 is fine with me, I'll try it.  It's
> all temporary anyway (famous last words), since the days of vec.h are
> counted :).

True.  :-)

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 2/3] vec: Silence -Wunused-function warnings on clang
  2017-06-26 12:47       ` Pedro Alves
@ 2017-06-26 12:52         ` Simon Marchi
  0 siblings, 0 replies; 15+ messages in thread
From: Simon Marchi @ 2017-06-26 12:52 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Simon Marchi, gdb-patches

On 2017-06-26 14:47, Pedro Alves wrote:
> On 06/26/2017 01:28 PM, Simon Marchi wrote:
> 
>> I wanted to keep it simple and easy to understand, so I didn't want to
>> add to many layers of definitions.  I thought that even if we ignored
>> -Wunused-function in the vector macro expansions when compiling with
>> GCC, it wasn't a big deal.
> 
> That's another option (and I think it should be fine, with a comment),
> but it wasn't what the patch was doing, so you'd be leaving deciding
> whether that's fine to whoever comes next and wants to make
> DIAGNOSTICS_IGNORE_UNUSED_FUNCTION on gcc.  IMO, that's a form of
> technical dept that we should avoid.

You are right, and it was due to technical laziness :P.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 2/3 v2] vec: Silence -Wunused-function warnings on clang
  2017-06-26 12:46     ` [PATCH 2/3 v2] " Simon Marchi
@ 2017-06-26 13:03       ` Pedro Alves
  0 siblings, 0 replies; 15+ messages in thread
From: Pedro Alves @ 2017-06-26 13:03 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches


On 06/26/2017 01:45 PM, Simon Marchi wrote:
> New in v2:
> 
>  - Define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION for GCC too.
>  - Define DIAGNOSTIC_IGNORE_UNUSED_VEC_FUNCTION on clang only and use it.

Fine with me.  Thanks.

-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/3] ada-lex: Ignore warnings about register keyword
  2017-06-25 17:45 ` [PATCH 1/3] ada-lex: Ignore warnings about register keyword Simon Marchi
@ 2017-06-26 13:13   ` Pedro Alves
  2017-06-26 13:39     ` Simon Marchi
  2017-06-26 14:54     ` [pushed] " Simon Marchi
  0 siblings, 2 replies; 15+ messages in thread
From: Pedro Alves @ 2017-06-26 13:13 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 06/25/2017 06:45 PM, Simon Marchi wrote:
> Some older versions of flex (such as the one shipped with macOS) generate
> code that use the register keyword, which clang warns about.  This patch
> makes the compiler ignore those warnings for the portion of the code
> generated by flex.

This is fine with me, modulo the "old/older" in comments, since "old"
is a moving target.  Can you add some reference to the actual version
this was observed on?

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/3] ada-lex: Ignore warnings about register keyword
  2017-06-26 13:13   ` Pedro Alves
@ 2017-06-26 13:39     ` Simon Marchi
  2017-06-26 14:54     ` [pushed] " Simon Marchi
  1 sibling, 0 replies; 15+ messages in thread
From: Simon Marchi @ 2017-06-26 13:39 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Simon Marchi, gdb-patches

On 2017-06-26 15:13, Pedro Alves wrote:
> On 06/25/2017 06:45 PM, Simon Marchi wrote:
>> Some older versions of flex (such as the one shipped with macOS) 
>> generate
>> code that use the register keyword, which clang warns about.  This 
>> patch
>> makes the compiler ignore those warnings for the portion of the code
>> generated by flex.
> 
> This is fine with me, modulo the "old/older" in comments, since "old"
> is a moving target.  Can you add some reference to the actual version
> this was observed on?

Ok, will do.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [pushed] ada-lex: Ignore warnings about register keyword
  2017-06-26 13:13   ` Pedro Alves
  2017-06-26 13:39     ` Simon Marchi
@ 2017-06-26 14:54     ` Simon Marchi
  1 sibling, 0 replies; 15+ messages in thread
From: Simon Marchi @ 2017-06-26 14:54 UTC (permalink / raw)
  To: gdb-patches; +Cc: Pedro Alves, Simon Marchi

Some older versions of flex (such as the one shipped with macOS) generate
code that use the register keyword, which clang warns about.  This patch
makes the compiler ignore those warnings for the portion of the code
generated by flex.

gdb/ChangeLog:

	* common/diagnostics.h (DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER):
	New macro.
	* ada-lex.l: Ignore deprecated register warnings.
---
 gdb/ChangeLog            |  6 ++++++
 gdb/ada-lex.l            | 10 ++++++++++
 gdb/common/diagnostics.h |  3 +++
 3 files changed, 19 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e1ad84a..5b04862 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2017-06-26  Simon Marchi  <simon.marchi@ericsson.com>
+
+	* common/diagnostics.h (DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER):
+	New macro.
+	* ada-lex.l: Ignore deprecated register warnings.
+
 2017-06-25  Simon Marchi  <simon.marchi@ericsson.com>
 
 	* main.c (get_init_files): Replace "SYSTEM_GDBINIT +
diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l
index 0825290..fe97352 100644
--- a/gdb/ada-lex.l
+++ b/gdb/ada-lex.l
@@ -41,6 +41,14 @@ POSEXP  (e"+"?{NUM10})
 
 %{
 
+#include "common/diagnostics.h"
+
+/* Some old versions of flex generate code that uses the "register" keyword,
+   which clang warns about.  This was observed for example with flex 2.5.35,
+   as shipped with macOS 10.12.  */
+DIAGNOSTIC_PUSH
+DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER
+
 #define NUMERAL_WIDTH 256
 #define LONGEST_SIGN ((ULONGEST) 1 << (sizeof(LONGEST) * HOST_CHAR_BIT - 1))
 
@@ -648,3 +656,5 @@ dummy_function ada_flex_use[] =
 { 
   (dummy_function) yyunput
 };
+
+DIAGNOSTIC_POP
diff --git a/gdb/common/diagnostics.h b/gdb/common/diagnostics.h
index 5a63bfd..35bacf2 100644
--- a/gdb/common/diagnostics.h
+++ b/gdb/common/diagnostics.h
@@ -33,8 +33,11 @@
 
 #ifdef __clang__
 # define DIAGNOSTIC_IGNORE_SELF_MOVE DIAGNOSTIC_IGNORE ("-Wself-move")
+# define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER \
+  DIAGNOSTIC_IGNORE ("-Wdeprecated-register")
 #else
 # define DIAGNOSTIC_IGNORE_SELF_MOVE
+# define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER
 #endif
 
 #endif /* COMMON_DIAGNOSTICS_H */
-- 
2.7.4

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 3/3] record-full: Remove unused function netorder16
  2017-06-26 10:43   ` Yao Qi
@ 2017-06-26 14:54     ` Simon Marchi
  0 siblings, 0 replies; 15+ messages in thread
From: Simon Marchi @ 2017-06-26 14:54 UTC (permalink / raw)
  To: Yao Qi; +Cc: Simon Marchi, gdb-patches

On 2017-06-26 12:43, Yao Qi wrote:
> On Sun, Jun 25, 2017 at 6:45 PM, Simon Marchi 
> <simon.marchi@ericsson.com> wrote:
>> gdb/ChangeLog:
>> 
>>         * record-full.c (netorder16): Remove.
> 
> Patch is good to me.

Thanks, all patches are pushed in.

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2017-06-26 14:54 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-25 17:45 [PATCH 0/3] Third series towards a warning-less clang build Simon Marchi
2017-06-25 17:45 ` [PATCH 2/3] vec: Silence -Wunused-function warnings on clang Simon Marchi
2017-06-26  9:28   ` Pedro Alves
2017-06-26 12:28     ` Simon Marchi
2017-06-26 12:47       ` Pedro Alves
2017-06-26 12:52         ` Simon Marchi
2017-06-26 12:46     ` [PATCH 2/3 v2] " Simon Marchi
2017-06-26 13:03       ` Pedro Alves
2017-06-25 17:45 ` [PATCH 1/3] ada-lex: Ignore warnings about register keyword Simon Marchi
2017-06-26 13:13   ` Pedro Alves
2017-06-26 13:39     ` Simon Marchi
2017-06-26 14:54     ` [pushed] " Simon Marchi
2017-06-25 17:45 ` [PATCH 3/3] record-full: Remove unused function netorder16 Simon Marchi
2017-06-26 10:43   ` Yao Qi
2017-06-26 14:54     ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).