Backport gettext fixes to get rid of warnings on macOS

Message ID 1533135533-16471-1-git-send-email-simon.marchi@ericsson.com
State New, archived
Headers

Commit Message

Simon Marchi Aug. 1, 2018, 2:58 p.m. UTC
  This patch was tested to build binutils-gdb on GNU/Linux and macOS.  It can be
applied to the gcc repo too, after fixing some trivial merge conflicts (someone
else will need to do it, as I don't have push access to gcc).  Although I think
it is relatively low-risk, building gcc on macOS was not tested with this
patch, so if somebody that has already a macOS build can do it, it would be
appreciated.

Two fixes were committed recently to the gettext repo in order to make
gdb build warning-free on macOS.  This patch backports them both:

  - Make the format_arg attribute effective also in the case _INTL_REDIRECT_INLINE.
    113893dce80358a4ae0d9463ce73c5670c81cf0c
    http://git.savannah.gnu.org/cgit/gettext.git/commit/?id=113893dce80358a4ae0d9463ce73c5670c81cf0c

  - Enable the format_arg attribute also on clang on Mac OS X.
    bd6a52241c7c83c90e043ace2082a2508d273f55
    http://git.savannah.gnu.org/cgit/gettext.git/commit/?id=bd6a52241c7c83c90e043ace2082a2508d273f55

intl/ChangeLog:

	* libgnuintl.h (_INTL_MAY_RETURN_STRING_ARG, gettext, dgettext,
	dcgettext, ngettext, dngettext, dcngettext): Backport changes
	from upstream gettext.
---
 intl/libgnuintl.h | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)
  

Comments

Simon Marchi Aug. 1, 2018, 6:58 p.m. UTC | #1
On 2018-08-01 10:58, Simon Marchi wrote:
> This patch was tested to build binutils-gdb on GNU/Linux and macOS.  It 
> can be
> applied to the gcc repo too, after fixing some trivial merge conflicts 
> (someone
> else will need to do it, as I don't have push access to gcc).  Although 
> I think
> it is relatively low-risk, building gcc on macOS was not tested with 
> this
> patch, so if somebody that has already a macOS build can do it, it 
> would be
> appreciated.

Actually it can be applied cleanly in gcc too, I just forgot I had some 
local commits touching the same spots.

Simon
  
Tom Tromey Aug. 2, 2018, 5:44 p.m. UTC | #2
>>>>> "Simon" == Simon Marchi <simon.marchi@ericsson.com> writes:

Simon> intl/ChangeLog:

Simon> 	* libgnuintl.h (_INTL_MAY_RETURN_STRING_ARG, gettext, dgettext,
Simon> 	dcgettext, ngettext, dngettext, dcngettext): Backport changes
Simon> 	from upstream gettext.

Thanks, I think you should check this in.

Tom
  
Simon Marchi Aug. 2, 2018, 6:57 p.m. UTC | #3
On 2018-08-02 13:44, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@ericsson.com> writes:
> 
> Simon> intl/ChangeLog:
> 
> Simon> 	* libgnuintl.h (_INTL_MAY_RETURN_STRING_ARG, gettext, dgettext,
> Simon> 	dcgettext, ngettext, dngettext, dcngettext): Backport changes
> Simon> 	from upstream gettext.
> 
> Thanks, I think you should check this in.

I was hoping to get an approval from gcc and binutils first, but this is 
probably obvious enough, so I pushed it in.  Could somebody from gcc 
take care of merging it in gcc too?

Thanks,

Simon
  
Simon Marchi Sept. 6, 2018, 10:36 a.m. UTC | #4
On 2018-08-01 03:58 PM, Simon Marchi wrote:
> This patch was tested to build binutils-gdb on GNU/Linux and macOS.  It can be
> applied to the gcc repo too, after fixing some trivial merge conflicts (someone
> else will need to do it, as I don't have push access to gcc).  Although I think
> it is relatively low-risk, building gcc on macOS was not tested with this
> patch, so if somebody that has already a macOS build can do it, it would be
> appreciated.
> 
> Two fixes were committed recently to the gettext repo in order to make
> gdb build warning-free on macOS.  This patch backports them both:
> 
>   - Make the format_arg attribute effective also in the case _INTL_REDIRECT_INLINE.
>     113893dce80358a4ae0d9463ce73c5670c81cf0c
>     http://git.savannah.gnu.org/cgit/gettext.git/commit/?id=113893dce80358a4ae0d9463ce73c5670c81cf0c
> 
>   - Enable the format_arg attribute also on clang on Mac OS X.
>     bd6a52241c7c83c90e043ace2082a2508d273f55
>     http://git.savannah.gnu.org/cgit/gettext.git/commit/?id=bd6a52241c7c83c90e043ace2082a2508d273f55
> 
> intl/ChangeLog:
> 
> 	* libgnuintl.h (_INTL_MAY_RETURN_STRING_ARG, gettext, dgettext,
> 	dcgettext, ngettext, dngettext, dcngettext): Backport changes
> 	from upstream gettext.
> ---
>  intl/libgnuintl.h | 35 +++++++++++++++++++++++------------
>  1 file changed, 23 insertions(+), 12 deletions(-)
> 
> diff --git a/intl/libgnuintl.h b/intl/libgnuintl.h
> index acc9093..7616d6f 100644
> --- a/intl/libgnuintl.h
> +++ b/intl/libgnuintl.h
> @@ -115,7 +115,7 @@ extern "C" {
>  /* _INTL_MAY_RETURN_STRING_ARG(n) declares that the given function may return
>     its n-th argument literally.  This enables GCC to warn for example about
>     printf (gettext ("foo %y")).  */
> -#if __GNUC__ >= 3 && !(__APPLE_CC__ > 1 && defined __cplusplus)
> +#if defined __GNUC__ && __GNUC__ >= 3 && !(defined __APPLE_CC__ && __APPLE_CC__ > 1 && !(defined __clang__ && __clang__ && __clang_major__ >= 3) && defined __cplusplus)
>  # define _INTL_MAY_RETURN_STRING_ARG(n) __attribute__ ((__format_arg__ (n)))
>  #else
>  # define _INTL_MAY_RETURN_STRING_ARG(n)
> @@ -127,7 +127,9 @@ extern "C" {
>  #ifdef _INTL_REDIRECT_INLINE
>  extern char *libintl_gettext (const char *__msgid)
>         _INTL_MAY_RETURN_STRING_ARG (1);
> -static inline char *gettext (const char *__msgid)
> +static inline
> +_INTL_MAY_RETURN_STRING_ARG (1)
> +char *gettext (const char *__msgid)
>  {
>    return libintl_gettext (__msgid);
>  }
> @@ -145,7 +147,9 @@ extern char *gettext _INTL_PARAMS ((const char *__msgid))
>  #ifdef _INTL_REDIRECT_INLINE
>  extern char *libintl_dgettext (const char *__domainname, const char *__msgid)
>         _INTL_MAY_RETURN_STRING_ARG (2);
> -static inline char *dgettext (const char *__domainname, const char *__msgid)
> +static inline
> +_INTL_MAY_RETURN_STRING_ARG (2)
> +char *dgettext (const char *__domainname, const char *__msgid)
>  {
>    return libintl_dgettext (__domainname, __msgid);
>  }
> @@ -165,8 +169,9 @@ extern char *dgettext _INTL_PARAMS ((const char *__domainname,
>  extern char *libintl_dcgettext (const char *__domainname, const char *__msgid,
>  				int __category)
>         _INTL_MAY_RETURN_STRING_ARG (2);
> -static inline char *dcgettext (const char *__domainname, const char *__msgid,
> -			       int __category)
> +static inline
> +_INTL_MAY_RETURN_STRING_ARG (2)
> +char *dcgettext (const char *__domainname, const char *__msgid, int __category)
>  {
>    return libintl_dcgettext (__domainname, __msgid, __category);
>  }
> @@ -188,8 +193,10 @@ extern char *dcgettext _INTL_PARAMS ((const char *__domainname,
>  extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2,
>  			       unsigned long int __n)
>         _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2);
> -static inline char *ngettext (const char *__msgid1, const char *__msgid2,
> -			      unsigned long int __n)
> +static inline
> +_INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2)
> +char *ngettext (const char *__msgid1, const char *__msgid2,
> +		unsigned long int __n)
>  {
>    return libintl_ngettext (__msgid1, __msgid2, __n);
>  }
> @@ -210,8 +217,10 @@ extern char *ngettext _INTL_PARAMS ((const char *__msgid1,
>  extern char *libintl_dngettext (const char *__domainname, const char *__msgid1,
>  				const char *__msgid2, unsigned long int __n)
>         _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
> -static inline char *dngettext (const char *__domainname, const char *__msgid1,
> -			       const char *__msgid2, unsigned long int __n)
> +static inline
> +_INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3)
> +char *dngettext (const char *__domainname, const char *__msgid1,
> +		 const char *__msgid2, unsigned long int __n)
>  {
>    return libintl_dngettext (__domainname, __msgid1, __msgid2, __n);
>  }
> @@ -234,9 +243,11 @@ extern char *libintl_dcngettext (const char *__domainname,
>  				 const char *__msgid1, const char *__msgid2,
>  				 unsigned long int __n, int __category)
>         _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
> -static inline char *dcngettext (const char *__domainname,
> -				const char *__msgid1, const char *__msgid2,
> -				unsigned long int __n, int __category)
> +static inline
> +_INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3)
> +char *dcngettext (const char *__domainname,
> +		  const char *__msgid1, const char *__msgid2,
> +		  unsigned long int __n, int __category)
>  {
>    return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category);
>  }
> 

Could somebody from gcc take a look at and hopefully merge this?

Thanks,

Simon
  
Jeff Law Sept. 19, 2018, 4:09 a.m. UTC | #5
On 9/6/18 4:36 AM, Simon Marchi wrote:
> On 2018-08-01 03:58 PM, Simon Marchi wrote:
>> This patch was tested to build binutils-gdb on GNU/Linux and macOS.  It can be
>> applied to the gcc repo too, after fixing some trivial merge conflicts (someone
>> else will need to do it, as I don't have push access to gcc).  Although I think
>> it is relatively low-risk, building gcc on macOS was not tested with this
>> patch, so if somebody that has already a macOS build can do it, it would be
>> appreciated.
>>
>> Two fixes were committed recently to the gettext repo in order to make
>> gdb build warning-free on macOS.  This patch backports them both:
>>
>>   - Make the format_arg attribute effective also in the case _INTL_REDIRECT_INLINE.
>>     113893dce80358a4ae0d9463ce73c5670c81cf0c
>>     http://git.savannah.gnu.org/cgit/gettext.git/commit/?id=113893dce80358a4ae0d9463ce73c5670c81cf0c
>>
>>   - Enable the format_arg attribute also on clang on Mac OS X.
>>     bd6a52241c7c83c90e043ace2082a2508d273f55
>>     http://git.savannah.gnu.org/cgit/gettext.git/commit/?id=bd6a52241c7c83c90e043ace2082a2508d273f55
>>
>> intl/ChangeLog:
>>
>> 	* libgnuintl.h (_INTL_MAY_RETURN_STRING_ARG, gettext, dgettext,
>> 	dcgettext, ngettext, dngettext, dcngettext): Backport changes
>> 	from upstream gettext.
>> ---
>>  intl/libgnuintl.h | 35 +++++++++++++++++++++++------------
>>  1 file changed, 23 insertions(+), 12 deletions(-)
>>
>> diff --git a/intl/libgnuintl.h b/intl/libgnuintl.h
>> index acc9093..7616d6f 100644
>> --- a/intl/libgnuintl.h
>> +++ b/intl/libgnuintl.h
>> @@ -115,7 +115,7 @@ extern "C" {
>>  /* _INTL_MAY_RETURN_STRING_ARG(n) declares that the given function may return
>>     its n-th argument literally.  This enables GCC to warn for example about
>>     printf (gettext ("foo %y")).  */
>> -#if __GNUC__ >= 3 && !(__APPLE_CC__ > 1 && defined __cplusplus)
>> +#if defined __GNUC__ && __GNUC__ >= 3 && !(defined __APPLE_CC__ && __APPLE_CC__ > 1 && !(defined __clang__ && __clang__ && __clang_major__ >= 3) && defined __cplusplus)
>>  # define _INTL_MAY_RETURN_STRING_ARG(n) __attribute__ ((__format_arg__ (n)))
>>  #else
>>  # define _INTL_MAY_RETURN_STRING_ARG(n)
>> @@ -127,7 +127,9 @@ extern "C" {
>>  #ifdef _INTL_REDIRECT_INLINE
>>  extern char *libintl_gettext (const char *__msgid)
>>         _INTL_MAY_RETURN_STRING_ARG (1);
>> -static inline char *gettext (const char *__msgid)
>> +static inline
>> +_INTL_MAY_RETURN_STRING_ARG (1)
>> +char *gettext (const char *__msgid)
>>  {
>>    return libintl_gettext (__msgid);
>>  }
>> @@ -145,7 +147,9 @@ extern char *gettext _INTL_PARAMS ((const char *__msgid))
>>  #ifdef _INTL_REDIRECT_INLINE
>>  extern char *libintl_dgettext (const char *__domainname, const char *__msgid)
>>         _INTL_MAY_RETURN_STRING_ARG (2);
>> -static inline char *dgettext (const char *__domainname, const char *__msgid)
>> +static inline
>> +_INTL_MAY_RETURN_STRING_ARG (2)
>> +char *dgettext (const char *__domainname, const char *__msgid)
>>  {
>>    return libintl_dgettext (__domainname, __msgid);
>>  }
>> @@ -165,8 +169,9 @@ extern char *dgettext _INTL_PARAMS ((const char *__domainname,
>>  extern char *libintl_dcgettext (const char *__domainname, const char *__msgid,
>>  				int __category)
>>         _INTL_MAY_RETURN_STRING_ARG (2);
>> -static inline char *dcgettext (const char *__domainname, const char *__msgid,
>> -			       int __category)
>> +static inline
>> +_INTL_MAY_RETURN_STRING_ARG (2)
>> +char *dcgettext (const char *__domainname, const char *__msgid, int __category)
>>  {
>>    return libintl_dcgettext (__domainname, __msgid, __category);
>>  }
>> @@ -188,8 +193,10 @@ extern char *dcgettext _INTL_PARAMS ((const char *__domainname,
>>  extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2,
>>  			       unsigned long int __n)
>>         _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2);
>> -static inline char *ngettext (const char *__msgid1, const char *__msgid2,
>> -			      unsigned long int __n)
>> +static inline
>> +_INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2)
>> +char *ngettext (const char *__msgid1, const char *__msgid2,
>> +		unsigned long int __n)
>>  {
>>    return libintl_ngettext (__msgid1, __msgid2, __n);
>>  }
>> @@ -210,8 +217,10 @@ extern char *ngettext _INTL_PARAMS ((const char *__msgid1,
>>  extern char *libintl_dngettext (const char *__domainname, const char *__msgid1,
>>  				const char *__msgid2, unsigned long int __n)
>>         _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
>> -static inline char *dngettext (const char *__domainname, const char *__msgid1,
>> -			       const char *__msgid2, unsigned long int __n)
>> +static inline
>> +_INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3)
>> +char *dngettext (const char *__domainname, const char *__msgid1,
>> +		 const char *__msgid2, unsigned long int __n)
>>  {
>>    return libintl_dngettext (__domainname, __msgid1, __msgid2, __n);
>>  }
>> @@ -234,9 +243,11 @@ extern char *libintl_dcngettext (const char *__domainname,
>>  				 const char *__msgid1, const char *__msgid2,
>>  				 unsigned long int __n, int __category)
>>         _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
>> -static inline char *dcngettext (const char *__domainname,
>> -				const char *__msgid1, const char *__msgid2,
>> -				unsigned long int __n, int __category)
>> +static inline
>> +_INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3)
>> +char *dcngettext (const char *__domainname,
>> +		  const char *__msgid1, const char *__msgid2,
>> +		  unsigned long int __n, int __category)
>>  {
>>    return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category);
>>  }
>>
> 
> Could somebody from gcc take a look at and hopefully merge this?
Done.

jeff
  

Patch

diff --git a/intl/libgnuintl.h b/intl/libgnuintl.h
index acc9093..7616d6f 100644
--- a/intl/libgnuintl.h
+++ b/intl/libgnuintl.h
@@ -115,7 +115,7 @@  extern "C" {
 /* _INTL_MAY_RETURN_STRING_ARG(n) declares that the given function may return
    its n-th argument literally.  This enables GCC to warn for example about
    printf (gettext ("foo %y")).  */
-#if __GNUC__ >= 3 && !(__APPLE_CC__ > 1 && defined __cplusplus)
+#if defined __GNUC__ && __GNUC__ >= 3 && !(defined __APPLE_CC__ && __APPLE_CC__ > 1 && !(defined __clang__ && __clang__ && __clang_major__ >= 3) && defined __cplusplus)
 # define _INTL_MAY_RETURN_STRING_ARG(n) __attribute__ ((__format_arg__ (n)))
 #else
 # define _INTL_MAY_RETURN_STRING_ARG(n)
@@ -127,7 +127,9 @@  extern "C" {
 #ifdef _INTL_REDIRECT_INLINE
 extern char *libintl_gettext (const char *__msgid)
        _INTL_MAY_RETURN_STRING_ARG (1);
-static inline char *gettext (const char *__msgid)
+static inline
+_INTL_MAY_RETURN_STRING_ARG (1)
+char *gettext (const char *__msgid)
 {
   return libintl_gettext (__msgid);
 }
@@ -145,7 +147,9 @@  extern char *gettext _INTL_PARAMS ((const char *__msgid))
 #ifdef _INTL_REDIRECT_INLINE
 extern char *libintl_dgettext (const char *__domainname, const char *__msgid)
        _INTL_MAY_RETURN_STRING_ARG (2);
-static inline char *dgettext (const char *__domainname, const char *__msgid)
+static inline
+_INTL_MAY_RETURN_STRING_ARG (2)
+char *dgettext (const char *__domainname, const char *__msgid)
 {
   return libintl_dgettext (__domainname, __msgid);
 }
@@ -165,8 +169,9 @@  extern char *dgettext _INTL_PARAMS ((const char *__domainname,
 extern char *libintl_dcgettext (const char *__domainname, const char *__msgid,
 				int __category)
        _INTL_MAY_RETURN_STRING_ARG (2);
-static inline char *dcgettext (const char *__domainname, const char *__msgid,
-			       int __category)
+static inline
+_INTL_MAY_RETURN_STRING_ARG (2)
+char *dcgettext (const char *__domainname, const char *__msgid, int __category)
 {
   return libintl_dcgettext (__domainname, __msgid, __category);
 }
@@ -188,8 +193,10 @@  extern char *dcgettext _INTL_PARAMS ((const char *__domainname,
 extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2,
 			       unsigned long int __n)
        _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2);
-static inline char *ngettext (const char *__msgid1, const char *__msgid2,
-			      unsigned long int __n)
+static inline
+_INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2)
+char *ngettext (const char *__msgid1, const char *__msgid2,
+		unsigned long int __n)
 {
   return libintl_ngettext (__msgid1, __msgid2, __n);
 }
@@ -210,8 +217,10 @@  extern char *ngettext _INTL_PARAMS ((const char *__msgid1,
 extern char *libintl_dngettext (const char *__domainname, const char *__msgid1,
 				const char *__msgid2, unsigned long int __n)
        _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
-static inline char *dngettext (const char *__domainname, const char *__msgid1,
-			       const char *__msgid2, unsigned long int __n)
+static inline
+_INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3)
+char *dngettext (const char *__domainname, const char *__msgid1,
+		 const char *__msgid2, unsigned long int __n)
 {
   return libintl_dngettext (__domainname, __msgid1, __msgid2, __n);
 }
@@ -234,9 +243,11 @@  extern char *libintl_dcngettext (const char *__domainname,
 				 const char *__msgid1, const char *__msgid2,
 				 unsigned long int __n, int __category)
        _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
-static inline char *dcngettext (const char *__domainname,
-				const char *__msgid1, const char *__msgid2,
-				unsigned long int __n, int __category)
+static inline
+_INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3)
+char *dcngettext (const char *__domainname,
+		  const char *__msgid1, const char *__msgid2,
+		  unsigned long int __n, int __category)
 {
   return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category);
 }