diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-03-01 13:47:16 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-03-01 13:47:16 -0800 |
commit | df1f1c1455fe84b081e3d8a8e556e48363b372fa (patch) | |
tree | 9036499a3b89f3674bca3d8d0d399fec0265a1c8 | |
parent | 84b9b8f7f154b03aeea2b738ec48942ea309741b (diff) |
add test for #2175
-rwxr-xr-x | emscripten.py | 2 | ||||
-rw-r--r-- | tests/test_other.py | 25 |
2 files changed, 27 insertions, 0 deletions
diff --git a/emscripten.py b/emscripten.py index eeb53bf7..26c7d6ef 100755 --- a/emscripten.py +++ b/emscripten.py @@ -780,6 +780,8 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, table_sizes = {} for k, v in metadata['tables'].iteritems(): table_sizes[k] = str(v.count(',')) # undercounts by one, but that is what we want + #if settings['ASSERTIONS'] >= 2 and table_sizes[k] == 0: + # print >> sys.stderr, 'warning: no function pointers with signature ' + k + ', but there is a call, which will abort if it occurs (this can result from undefined behavior, check for compiler warnings on your source files and consider -Werror)' funcs = re.sub(r"#FM_(\w+)#", lambda m: table_sizes[m.groups(0)[0]], funcs) # fix +float into float.0, if not running js opts diff --git a/tests/test_other.py b/tests/test_other.py index 18a64c85..5959e56d 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -2509,3 +2509,28 @@ Waste<3> *getMore() { self.assertContained('argc: 1\n16\n17\n10\n', run_js('a.out.js')) assert ('_GLOBAL_' in src) == has_global + def test_implicit_func(self): + open('src.c', 'w').write(r''' +#include <stdio.h> +int main() +{ + printf("hello %d\n", strnlen("waka", 2)); // Implicit declaration, no header, for strnlen + int (*my_strnlen)(char*, ...) = strnlen; + printf("hello %d\n", my_strnlen("shaka", 2)); + return 0; +} +''') + + 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'], []), + (['-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 + stdout, stderr = Popen([PYTHON, EMCC, 'src.c'] + opts, stderr=PIPE).communicate() + output = run_js(os.path.join(self.get_dir(), 'a.out.js'), stderr=PIPE, full_output=True) + for e in expected: + self.assertContained(e, output) + for ce in compile_expected + ['''warning: implicit declaration of function 'strnlen' is invalid in C99''', '''warning: incompatible pointer types''']: + self.assertContained(ce, stderr) + |