diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-06-11 11:29:19 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-06-11 11:29:19 -0700 |
commit | 8e6f0e536b9fb15280e0c1bb74ced421a5072696 (patch) | |
tree | c11127a4249a090741e092546199d82c8086e955 | |
parent | ccab86082893ff9120bdfbe8be490cd43ecf2cf3 (diff) |
fix operator precedence bug with overflow correction, improve dlmalloc test
-rw-r--r-- | src/parseTools.js | 2 | ||||
-rw-r--r-- | tests/dlmalloc.c | 24 | ||||
-rw-r--r-- | tests/runner.py | 11 |
3 files changed, 28 insertions, 9 deletions
diff --git a/src/parseTools.js b/src/parseTools.js index 167ba074..34187a68 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -989,7 +989,7 @@ function handleOverflow(text, bits) { ) + ')'; if (!correct) return text; if (bits <= 32) { - return '(' + text + ')&' + (Math.pow(2, bits) - 1); + return '((' + text + ')&' + (Math.pow(2, bits) - 1) + ')'; } else { return text; // We warned about this earlier } diff --git a/tests/dlmalloc.c b/tests/dlmalloc.c index c8fce144..e55e1f84 100644 --- a/tests/dlmalloc.c +++ b/tests/dlmalloc.c @@ -5700,15 +5700,31 @@ History: // Emscripten tests -int main() { - #define NUM 10 +int main(int ac, char **av) +{ + int NUM = ac > 1 ? atoi(av[1]) : 0; char* allocations[NUM]; - for (int i = 0; i < NUM; i++) { + for (int i = 0; i < NUM/2; i++) { + allocations[i] = (char*)malloc((11*i)%1024 + 256); + assert(allocations[i]); + if (i > 10 && i%4 == 1 && allocations[i-10]) { + free(allocations[i-10]); + allocations[i-10] = NULL; + } + } + for (int i = NUM/2; i < NUM; i++) { allocations[i] = (char*)malloc(1024*(i+1)); + assert(allocations[i]); + if (i > 10 && i%4 != 1 && allocations[i-10]) { + free(allocations[i-10]); + allocations[i-10] = NULL; + } } char* first = allocations[0]; for (int i = 0; i < NUM; i++) { - free(allocations[i]); + if (allocations[i]) { + free(allocations[i]); + } } char *last = (char*)malloc(512); // should be identical, as we free'd it all char *newer = (char*)malloc(512); // should be different diff --git a/tests/runner.py b/tests/runner.py index a1985df7..fdb0f899 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -1784,12 +1784,15 @@ if 'benchmark' not in sys.argv: self.do_test(src, j, [str(i)], lambda x: x.replace('\n', '*'), no_build=i>1) def test_dlmalloc(self): - #global COMPILER_TEST_OPTS; COMPILER_TEST_OPTS = ['-g'] - global CORRECT_SIGNS; CORRECT_SIGNS = 1 - #global CORRECT_SIGNS_LINES; CORRECT_SIGNS_LINES = ['src.cpp:4816', 'src.cpp:4191'] + global COMPILER_TEST_OPTS; COMPILER_TEST_OPTS = ['-g'] + #global CHECK_SIGNS; CHECK_SIGNS = 1 + #global CHECK_OVERFLOWS; CHECK_OVERFLOWS = 1 # Why work with this? XXX + global CORRECT_SIGNS; CORRECT_SIGNS = 2 + global CORRECT_SIGNS_LINES; CORRECT_SIGNS_LINES = ['src.cpp:' + str(i) for i in [4816, 4191, 4246, 4199, 4205, 4235, 4227]] + #global AUTO_OPTIMIZE; AUTO_OPTIMIZE = 1 src = open(path_from_root('tests', 'dlmalloc.c'), 'r').read() - self.do_test(src, '*1,0*', ['100']) + self.do_test(src, '*1,0*', ['100'])#, build_ll_hook=self.do_autodebug) def zzztest_gl(self): # Switch to gcc from g++ - we don't compile properly otherwise (why?) |