Match compiler: Workaround broken optimizations in verify mode

If the match compiler uses the 'verify' mode and we
compile with -O2, some tests comparing the on-the-fly-parser
to the compiled match fail.

Small functions are inlined by the -O2 compile flag.
If we disable function inlining and still compile with -O2,
everything is back to normal.

gdb didn't show anything useful during the mismatch
since the needed variables are optimized out. Once
we start printing them, the problem vanishes, too.
-> Can only be diagnosed at the x86 assembly level.

The problem vanished by switching the invocation order
of Token::Match() and the compiled match, so just swap them.

Also add commented out helper code
to better diagnose mismatch problems.
This commit is contained in:
Thomas Jarosch 2013-01-09 18:56:00 +01:00
parent 33619de072
commit 982503f457
1 changed files with 10 additions and 3 deletions

View File

@ -259,12 +259,12 @@ class MatchCompiler:
origMatchName = 'simpleMatch'
assert(varId == None)
ret += ' bool res_parsed_match = Token::' + origMatchName + '(tok, "' + pattern + '"'
ret += ' bool res_compiled_match = match'+str(patternNumber)+'(tok'
if varId:
ret += ', varid'
ret += ');\n'
ret += ' bool res_compiled_match = match'+str(patternNumber)+'(tok'
ret += ' bool res_parsed_match = Token::' + origMatchName + '(tok, "' + pattern + '"'
if varId:
ret += ', varid'
ret += ');\n'
@ -272,8 +272,14 @@ class MatchCompiler:
ret += '\n'
# Don't use assert() here, it's disabled for optimized builds.
# We also need to verify builds in 'release' mode
ret += ' if (res_parsed_match != res_compiled_match)\n'
ret += ' if (res_parsed_match != res_compiled_match) {\n'
# ret += ' std::cout << "res_parsed_match' + str(verifyNumber) + ': " << res_parsed_match << ", res_compiled_match: " << res_compiled_match << "\\n";\n'
# ret += ' if (tok)\n'
# ret += ' std::cout << "tok: " << tok->str();\n'
# ret += ' if (tok->next())\n'
# ret += ' std::cout << "tok next: " << tok->next()->str();\n'
ret += ' throw InternalError(tok, "Internal error. compiled match returned different result than parsed match");\n'
ret += ' }\n'
ret += ' return res_compiled_match;\n'
ret += '}\n'
@ -432,6 +438,7 @@ class MatchCompiler:
header += '#include "errorlogger.h"\n'
header += '#include <string>\n'
header += '#include <cstring>\n'
# header += '#include <iostream>\n'
code = ''
for line in srclines: