From 982503f45786fa64a081b8a656eea7efaba10655 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Wed, 9 Jan 2013 18:56:00 +0100 Subject: [PATCH] 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. --- tools/matchcompiler.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/matchcompiler.py b/tools/matchcompiler.py index 29a1c7b7f..433822659 100755 --- a/tools/matchcompiler.py +++ b/tools/matchcompiler.py @@ -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 \n' header += '#include \n' + # header += '#include \n' code = '' for line in srclines: