VirtualBox

Changeset 3658 in kBuild for trunk


Ignore:
Timestamp:
Nov 4, 2024 12:58:52 PM (6 months ago)
Author:
bird
Message:

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

File:
1 edited

Legend:

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

    r3532 r3658  
    12271227          if (backslash)
    12281228            goto normal_char;
     1229          /* kmk: cl v19.29.30139/amd64 messes this function up when optimizing
     1230             for speed, workaround is to optimize it for size instead. The
     1231             symptom is that the following SED expression fail to match:
     1232             s/^[0-9a-fA-F]\{1,\} \(00[0-9a-fA-F]*\) ABS *notype *External *| \([^.]\{1,\}\)\.\(.*$\)/ 1=\1 2=\2 3=\3/
     1233
     1234             Seems the exact problem is that it gets the indexing here wrong:
     1235                 dfa->lex.ptr[!(dfa->syntax.syntax_bits & RE_NO_BK_PARENS) & (dfa->lex.ptr[0] == '\\')]
     1236             It forgets to do the ` dfa->lex.ptr[0] == '\\' ` part and instead
     1237             ANDs with a register initialized to zero.  Rewriting the
     1238             expressions using the tinary operator works around the problem,
     1239             although the resulting code is a lot bulkier.
     1240             */
    12291241          if (dfa->syntax.syntax_bits & RE_CONTEXT_INDEP_ANCHORS
    12301242              || dfa->lex.left == 0
     1243#ifdef _MSC_VER /* see above */
     1244              || (!(dfa->syntax.syntax_bits & RE_NO_BK_PARENS)
     1245                  ? dfa->lex.left > 1 && dfa->lex.ptr[dfa->lex.ptr[0] == '\\'] == ')'
     1246                  : dfa->lex.left > 0 && dfa->lex.ptr[0]                       == ')')
     1247#else
    12311248              || ((dfa->lex.left
    12321249                   > !(dfa->syntax.syntax_bits & RE_NO_BK_PARENS))
     
    12341251                                   & (dfa->lex.ptr[0] == '\\')]
    12351252                      == ')'))
     1253#endif
     1254#ifdef _MSC_VER /* see above */
     1255              || (!(dfa->syntax.syntax_bits & RE_NO_BK_VBAR)
     1256                  ? dfa->lex.left > 1 && dfa->lex.ptr[dfa->lex.ptr[0] == '\\'] == '|'
     1257                  : dfa->lex.left > 0 && dfa->lex.ptr[0]                       == '|')
     1258#else
    12361259              || ((dfa->lex.left
    12371260                   > !(dfa->syntax.syntax_bits & RE_NO_BK_VBAR))
     
    12391262                                   & (dfa->lex.ptr[0] == '\\')]
    12401263                      == '|'))
     1264#endif
    12411265              || ((dfa->syntax.syntax_bits & RE_NEWLINE_ALT)
    12421266                  && dfa->lex.left > 0 && dfa->lex.ptr[0] == '\n'))
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette