aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xemcc2
-rw-r--r--tests/test_other.py65
2 files changed, 64 insertions, 3 deletions
diff --git a/emcc b/emcc
index 942ea1b3..2d45bd37 100755
--- a/emcc
+++ b/emcc
@@ -1206,7 +1206,7 @@ try:
fastcomp_opts = []
if shared.Settings.NO_EXIT_RUNTIME:
- fastcomp_opts += ['-emscripten-no-exit-runtime', '-globaldce']
+ fastcomp_opts += ['-emscripten-no-exit-runtime', '-globalopt']
fastcomp_opts += ['-pnacl-abi-simplify-preopt', '-pnacl-abi-simplify-postopt']
if shared.Settings.DISABLE_EXCEPTION_CATCHING != 1:
fastcomp_opts += ['-enable-emscripten-cxx-exceptions']
diff --git a/tests/test_other.py b/tests/test_other.py
index d12374dd..49b9dcd1 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -2417,9 +2417,9 @@ int main(int argc, char **argv) {
''')
for no_exit in [0, 1]:
- for opts in [0, 1]:
+ for opts in [[], ['-O1'], ['-O2', '-g2']]:
print no_exit, opts
- Popen([PYTHON, EMCC, '-O' + str(opts), 'code.cpp', '-s', 'NO_EXIT_RUNTIME=' + str(no_exit)]).communicate()
+ Popen([PYTHON, EMCC] + opts + ['code.cpp', '-s', 'NO_EXIT_RUNTIME=' + str(no_exit)]).communicate()
output = run_js(os.path.join(self.get_dir(), 'a.out.js'), stderr=PIPE, full_output=True, engine=NODE_JS)
src = open('a.out.js').read()
exit = 1-no_exit
@@ -2446,3 +2446,64 @@ int main(int argc, char **argv) {
finally:
del os.environ['EMCC_DEBUG']
+ def test_global_inits(self):
+ open('inc.h', 'w').write(r'''
+#include <stdio.h>
+
+template<int x>
+struct Waste {
+ int state;
+ Waste() : state(10) {}
+ void test(int a) {
+ printf("%d\n", a + state);
+ }
+ ~Waste() {
+ printf("going away %d\n", x);
+ }
+};
+
+Waste<3> *getMore();
+
+''')
+ open('main.cpp', 'w').write(r'''
+#include "inc.h"
+
+Waste<1> mw1;
+Waste<2> mw2;
+
+int main(int argc, char **argv) {
+ printf("argc: %d\n", argc);
+ mw1.state += argc;
+ mw2.state += argc;
+ mw1.test(5);
+ mw2.test(6);
+ getMore()->test(0);
+ return 0;
+}
+''')
+
+ open('side.cpp', 'w').write(r'''
+#include "inc.h"
+
+Waste<3> sw3;
+
+Waste<3> *getMore() {
+ return &sw3;
+}
+''')
+
+ for opts, has_global in [
+ (['-O2', '-g'], True),
+ (['-O2', '-g', '-s', 'NO_EXIT_RUNTIME=1'], False), # no-exit-runtime removes the atexits, and then globalgce can work it's magic to remove the global initializer entirely
+ (['-Os', '-g'], True),
+ (['-Os', '-g', '-s', 'NO_EXIT_RUNTIME=1'], False), # no-exit-runtime removes the atexits, and then globalgce can work it's magic to remove the global initializer entirely
+ ]:
+ print opts, has_global
+ Popen([PYTHON, EMCC, 'main.cpp', '-c'] + opts).communicate()
+ Popen([PYTHON, EMCC, 'side.cpp', '-c'] + opts).communicate()
+ Popen([PYTHON, EMCC, 'main.o', 'side.o'] + opts).communicate()
+ output = run_js(os.path.join(self.get_dir(), 'a.out.js'), stderr=PIPE, full_output=True, engine=NODE_JS)
+ src = open('a.out.js').read()
+ self.assertContained('argc: 1\n16\n17\n10\n', run_js('a.out.js'))
+ assert ('_GLOBAL_' in src) == has_global
+