diff mbox

[6/7] i386.c: make "sorry" message more amenable to translation (PR target/79926)

Message ID 1489081529-22256-7-git-send-email-dmalcolm@redhat.com
State New
Headers show

Commit Message

David Malcolm March 9, 2017, 5:45 p.m. UTC
PR target/79926 notes that in:

    sorry ("%s instructions aren't allowed in %s service routine",
           isa, (cfun->machine->func_type == TYPE_EXCEPTION
                 ? "exception" : "interrupt"));

the text from the second %s won't be translated, but should be.

This patch reworks the diagnostic by breaking it out into two messages
and marking them with G_() so they're seen by xgettext; a test run of
xgettext confirms that both messages make it into po/gcc.pot (in an
earlier version of the patch I attempted to do it without introducing
a local, but xgettext only picked up on one of the strings).

gcc/ChangeLog:
	PR target/79926
	* config/i386/i386.c (ix86_set_current_function): Make "sorry"
	message more amenable to translation.
---
 gcc/config/i386/i386.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Martin Sebor March 10, 2017, 4:22 a.m. UTC | #1
On 03/09/2017 10:45 AM, David Malcolm wrote:
> PR target/79926 notes that in:
>
>     sorry ("%s instructions aren't allowed in %s service routine",
>            isa, (cfun->machine->func_type == TYPE_EXCEPTION
>                  ? "exception" : "interrupt"));
>
> the text from the second %s won't be translated, but should be.
>
> This patch reworks the diagnostic by breaking it out into two messages
> and marking them with G_() so they're seen by xgettext; a test run of
> xgettext confirms that both messages make it into po/gcc.pot (in an
> earlier version of the patch I attempted to do it without introducing
> a local, but xgettext only picked up on one of the strings).
>
> gcc/ChangeLog:
> 	PR target/79926
> 	* config/i386/i386.c (ix86_set_current_function): Make "sorry"
> 	message more amenable to translation.
> ---
>  gcc/config/i386/i386.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> index e705a3e..b8688e3 100644
> --- a/gcc/config/i386/i386.c
> +++ b/gcc/config/i386/i386.c
> @@ -7271,9 +7271,15 @@ ix86_set_current_function (tree fndecl)
>        if (isa != NULL)
>  	{
>  	  if (cfun->machine->func_type != TYPE_NORMAL)
> -	    sorry ("%s instructions aren't allowed in %s service routine",
> -		   isa, (cfun->machine->func_type == TYPE_EXCEPTION
> -			 ? "exception" : "interrupt"));
> +	    {
> +	      const char *msgid
> +		= (cfun->machine->func_type == TYPE_EXCEPTION
> +		   ? G_("%s instructions aren't allowed in"
> +			" exception service routine")
> +		   : G_("%s instructions aren't allowed in"
> +			" interrupt service routine"));
> +	      sorry (msgid, isa);
> +	    }
>  	  else
>  	    sorry ("%s instructions aren't allowed in function with "
>  		   "no_caller_saved_registers attribute", isa);
>

Just a very minor point but I think one in line with the rest
of the problems addressed by these patches:  in the last sorry,
no_caller_saved_registers should be quoted in %< and %>.

(Also, although it's often left out, the other message above
seem like they could do with an article:

   instructions aren't allowed in <ins>an </ins>interrupt service
   routine)

Martin
Jakub Jelinek March 10, 2017, 6:33 a.m. UTC | #2
On Thu, Mar 09, 2017 at 12:45:28PM -0500, David Malcolm wrote:
> PR target/79926 notes that in:
> 
>     sorry ("%s instructions aren't allowed in %s service routine",
>            isa, (cfun->machine->func_type == TYPE_EXCEPTION
>                  ? "exception" : "interrupt"));
> 
> the text from the second %s won't be translated, but should be.
> 
> This patch reworks the diagnostic by breaking it out into two messages
> and marking them with G_() so they're seen by xgettext; a test run of
> xgettext confirms that both messages make it into po/gcc.pot (in an
> earlier version of the patch I attempted to do it without introducing
> a local, but xgettext only picked up on one of the strings).
> 
> gcc/ChangeLog:
> 	PR target/79926
> 	* config/i386/i386.c (ix86_set_current_function): Make "sorry"
> 	message more amenable to translation.
> ---
>  gcc/config/i386/i386.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> index e705a3e..b8688e3 100644
> --- a/gcc/config/i386/i386.c
> +++ b/gcc/config/i386/i386.c
> @@ -7271,9 +7271,15 @@ ix86_set_current_function (tree fndecl)
>        if (isa != NULL)
>  	{
>  	  if (cfun->machine->func_type != TYPE_NORMAL)
> -	    sorry ("%s instructions aren't allowed in %s service routine",
> -		   isa, (cfun->machine->func_type == TYPE_EXCEPTION
> -			 ? "exception" : "interrupt"));
> +	    {
> +	      const char *msgid
> +		= (cfun->machine->func_type == TYPE_EXCEPTION
> +		   ? G_("%s instructions aren't allowed in"
> +			" exception service routine")
> +		   : G_("%s instructions aren't allowed in"
> +			" interrupt service routine"));
> +	      sorry (msgid, isa);

1) aren't should be actually aren%'t
   (we should probably look through gcc.pot and patch all spots that
   have n't instead of n%'t in them and are in the gcc-internal-format)
2) I think it should be better to do:
	      sorry (cfun->machine->func_type == TYPE_EXCEPTION
		     ? G_("%s instructions aren%'t allowed in exception "
			  "service routine")
		     : G_("%s instructions aren%'t allowed in interrupt "
			  "service routine"));
   That way, you don't introduce another -Wformat-security issue
Ok for trunk with those changes.

	Jakub
diff mbox

Patch

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index e705a3e..b8688e3 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -7271,9 +7271,15 @@  ix86_set_current_function (tree fndecl)
       if (isa != NULL)
 	{
 	  if (cfun->machine->func_type != TYPE_NORMAL)
-	    sorry ("%s instructions aren't allowed in %s service routine",
-		   isa, (cfun->machine->func_type == TYPE_EXCEPTION
-			 ? "exception" : "interrupt"));
+	    {
+	      const char *msgid
+		= (cfun->machine->func_type == TYPE_EXCEPTION
+		   ? G_("%s instructions aren't allowed in"
+			" exception service routine")
+		   : G_("%s instructions aren't allowed in"
+			" interrupt service routine"));
+	      sorry (msgid, isa);
+	    }
 	  else
 	    sorry ("%s instructions aren't allowed in function with "
 		   "no_caller_saved_registers attribute", isa);