aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-03-02 19:58:52 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-03-02 19:58:52 -0800
commitf46b3d8c5787c895510277c9ab0e2faf646f05ea (patch)
tree571c3b3658d421f64b97cffecccf733ea39362d5
parentee4b996cd331212686ecbbd03da79bf87b121512 (diff)
fix ASSERTIONS output on bad function pointer calls
-rwxr-xr-xemscripten.py8
-rw-r--r--tests/test_other.py6
2 files changed, 8 insertions, 6 deletions
diff --git a/emscripten.py b/emscripten.py
index caf5b7ce..37e1c83f 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -924,7 +924,6 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None,
debug_tables = {}
def make_table(sig, raw):
- Counter.pre = ''
params = ','.join(['p%d' % p for p in range(len(sig)-1)])
coerced_params = ','.join([shared.JS.make_coercion('p%d', unfloat(sig[p+1]), settings) % p for p in range(len(sig)-1)])
coercions = ';'.join(['p%d = %s' % (p, shared.JS.make_coercion('p%d' % p, sig[p+1], settings)) for p in range(len(sig)-1)]) + ';'
@@ -943,7 +942,10 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None,
code += 'return %s' % shared.JS.make_initializer(sig[0], settings) + ';'
return name, make_func(name, code)
bad, bad_func = make_bad() # the default bad func
- Counter.pre = [bad_func]
+ if settings['ASSERTIONS'] <= 1:
+ Counter.pre = [bad_func]
+ else:
+ Counter.pre = []
start = raw.index('[')
end = raw.rindex(']')
body = raw[start+1:end].split(',')
@@ -959,7 +961,7 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None,
if settings['ASSERTIONS'] <= 1:
return bad if not newline else (bad + '\n')
else:
- specific_bad, specific_bad_func = make_bad(Counter.j)
+ specific_bad, specific_bad_func = make_bad(Counter.j-1)
Counter.pre.append(specific_bad_func)
return specific_bad if not newline else (specific_bad + '\n')
if item not in implemented_functions:
diff --git a/tests/test_other.py b/tests/test_other.py
index b86af5cc..9f7d2eeb 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -560,8 +560,8 @@ f.close()
test(['-O1', '-s', 'ASSERTIONS=1'], '''Invalid function pointer called with signature 'v'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)
Build with ASSERTIONS=2 for more info.
''') # some useful text
- test(['-O1', '-s', 'ASSERTIONS=2'], '''Invalid function pointer '1' called with signature 'v'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)
-This pointer might make sense in another type signature: i: _my_func
+ test(['-O1', '-s', 'ASSERTIONS=2'], '''Invalid function pointer '0' called with signature 'v'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)
+This pointer might make sense in another type signature: i: 0
''') # actually useful identity of the bad pointer, with comparisons to what it would be in other types/tables
def test_l_link(self):
@@ -2524,7 +2524,7 @@ int main()
for opts, expected, compile_expected in [
([], ['abort()', 'it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this'], []),
- (['-s', 'ASSERTIONS=2'], ['abort()', 'This pointer might make sense in another type signature: ii: _strnlen'], []),
+ (['-s', 'ASSERTIONS=2'], ['abort()', 'This pointer might make sense in another type signature'], []),
(['-O1'], ['hello 2\nhello 5\n'], []), # invalid output - second arg is sent as varargs, but needs to be int. llvm optimizer avoided the crash silently, caused undefined behavior... at least people can debug this by running an -O0 build.
]:
print opts, expected