This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regex sets: fix Solaris optimiser bug (2nd attempt)
authorDavid Mitchell <davem@iabyn.com>
Fri, 18 Mar 2016 22:36:40 +0000 (22:36 +0000)
committerDavid Mitchell <davem@iabyn.com>
Fri, 18 Mar 2016 22:36:40 +0000 (22:36 +0000)
[perl #127455]

My first fix for this, (v5.23.7-586-gd9cb841) didn't actually fix it.
The diagnosis was correct, but somewhere during fixing and testing I went
wrong, and the optimiser bug was still being triggered without me spotting
it.

The new approach, based on a suggestion by Tony C, is simply to
declare the errant local var 'fence' to be volatile. This stops the
compiler from optimising away its value.

regcomp.c

index aae29f1..f8dc8a1 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -14547,7 +14547,9 @@ S_handle_regex_sets(pTHX_ RExC_state_t *pRExC_state, SV** return_invlist,
                                        'stack' of where the undealt-with left
                                        parens would be if they were actually
                                        put there */
-    IV fence = 0;                   /* Position of where most recent undealt-
+    /* The 'volatile' is a workaround for an optimiser bug
+     * in Solaris Studio 12.3. See RT #127455 */
+    volatile IV fence = 0;          /* Position of where most recent undealt-
                                        with left paren in stack is; -1 if none.
                                      */
     STRLEN len;                     /* Temporary */
@@ -15152,21 +15154,7 @@ redo_curchar:
              * may have altered the stack in the time since we earlier set
              * 'top_index'.  */
 
-            {
-                /* Work round an optimiser bug in Solaris Studio 12.3:
-                 * for some reason, the presence of the __assert() in
-                 * av_tindex_nomg() causes the value of fence to get
-                 * corrupted, even though the assert is never called. So
-                 * save the value then restore afterwards.
-                 * Note that in fact merely accessing the value of fence
-                 * prior to the statement containing the assert is enough
-                 * to make the bug go away.
-                 */
-                IV f = fence;
-                top_index = av_tindex_nomg(stack);
-                fence = f;
-            }
-
+            top_index = av_tindex_nomg(stack);
             if (top_index - fence >= 0) {
                 /* If the top entry on the stack is an operator, it had better
                  * be a '!', otherwise the entry below the top operand should