Ignore:
Timestamp:
Nov 4, 2024, 1:57:24 PM (9 months ago)
Author:
bird
Message:

sed/dfa.c: Workaround for Visual C++ 2022 (amd64) optimizer bug.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sed/lib/dfa.c

    r3613 r3657  
    12231223          if (backslash)
    12241224            goto normal_char;
     1225          /* kmk: cl v19.29.30139/amd64 messes this function up when optimizing
     1226             for speed, workaround is to optimize it for size instead. The
     1227             symptom is that the following SED expression fail to match:
     1228             s/^[0-9a-fA-F]\{1,\} \(00[0-9a-fA-F]*\) ABS *notype *External *| \([^.]\{1,\}\)\.\(.*$\)/ 1=\1 2=\2 3=\3/
     1229
     1230             Seems the exact problem is that it gets the indexing here wrong:
     1231                 dfa->lex.ptr[!(dfa->syntax.syntax_bits & RE_NO_BK_PARENS) & (dfa->lex.ptr[0] == '\\')]
     1232             It forgets to do the ` dfa->lex.ptr[0] == '\\' ` part and instead
     1233             ANDs with a register initialized to zero.  Rewriting the
     1234             expressions using the tinary operator works around the problem,
     1235             although the resulting code is a lot bulkier.
     1236             */
    12251237          if (dfa->syntax.syntax_bits & RE_CONTEXT_INDEP_ANCHORS
    12261238              || dfa->lex.left == 0
     1239#ifdef _MSC_VER /* see above */
     1240              || (!(dfa->syntax.syntax_bits & RE_NO_BK_PARENS)
     1241                  ? dfa->lex.left > 1 && dfa->lex.ptr[dfa->lex.ptr[0] == '\\'] == ')'
     1242                  : dfa->lex.left > 0 && dfa->lex.ptr[0]                       == ')')
     1243#else
    12271244              || ((dfa->lex.left
    12281245                   > !(dfa->syntax.syntax_bits & RE_NO_BK_PARENS))
     
    12301247                                   & (dfa->lex.ptr[0] == '\\')]
    12311248                      == ')'))
     1249#endif
     1250#ifdef _MSC_VER /* see above */
     1251              || (!(dfa->syntax.syntax_bits & RE_NO_BK_VBAR)
     1252                  ? dfa->lex.left > 1 && dfa->lex.ptr[dfa->lex.ptr[0] == '\\'] == '|'
     1253                  : dfa->lex.left > 0 && dfa->lex.ptr[0]                       == '|')
     1254#else
    12321255              || ((dfa->lex.left
    12331256                   > !(dfa->syntax.syntax_bits & RE_NO_BK_VBAR))
     
    12351258                                   & (dfa->lex.ptr[0] == '\\')]
    12361259                      == '|'))
     1260#endif
    12371261              || ((dfa->syntax.syntax_bits & RE_NEWLINE_ALT)
    12381262                  && dfa->lex.left > 0 && dfa->lex.ptr[0] == '\n'))
Note: See TracChangeset for help on using the changeset viewer.