[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] Misoptimisation: _"A" "B" to _"AB"
From: |
arnold |
Subject: |
Re: [bug-gawk] Misoptimisation: _"A" "B" to _"AB" |
Date: |
Sat, 21 Oct 2017 11:57:41 -0600 |
User-agent: |
Heirloom mailx 12.4 7/29/08 |
Hi.
Harald van Dijk <address@hidden> wrote:
> Hi all,
>
> Trying the new gawk 4.2.0 where optimisations are enabled by default, I
> spot a test failure in the gettext test suite, which can be reduced
> simply to
>
> { print _"A" "B" }
>
> When optimisations are disabled, this translates "A", and adds "B" to it.
>
> When optimisations are enabled, this first adds "B" to "A", and then
> translates "AB". Which is likely to fail.
>
> The previous version of gawk behaved the same way, but because
> optimisations were disabled by default, it didn't really come up.
>
> awkgram.y contains code to disable early concatenation if either operand
> is a number. I believe this should be extended to also disable early
> concatenation if either operand is translatable.
>
> Cheers,
> Harald van Dijk
Here is the patch.
Thanks,
arnold
-----------------------------------------------------
--- a/awkgram.y
+++ b/awkgram.y
@@ -1589,7 +1589,8 @@ common_exp
// 1.5 "" # can't fold this if program mucks with CONV
FMT.
// See test #12 in test/posix.awk.
- if ((n1->flags & (NUMBER|NUMINT)) != 0 || (n2->flags &
(NUMBER|NUMINT)) != 0)
+ // Also can't fold if one or the other is translatable.
+ if ((n1->flags & (NUMBER|NUMINT|INTLSTR)) != 0 ||
(n2->flags & (NUMBER|NUMINT|INTLSTR)) != 0)
goto plain_concat;
n1 = force_string(n1);