From 2c8d9fda28786a57c640d8b4805d187f6daf6412 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Fri, 1 Mar 2024 17:43:07 -0800 Subject: [PATCH] Warn when setting used on the command line more than once See #19938 --- ChangeLog.md | 3 +++ emcc.py | 3 +++ test/common.py | 2 +- test/test_browser.py | 2 +- test/test_core.py | 3 ++- test/test_other.py | 18 ++++++++++++------ 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index a875400210aa0..75f7d15036dfa 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -20,6 +20,9 @@ See docs/process.md for more on how version tagging works. 3.1.56 (in development) ----------------------- +- emscripten will now generate an `unused-command-line-argument` warning if + a `-s` setting is specified more than once on the command line with + conflicting values. In this case the first setting is ignored. (#21464) 3.1.55 - 03/01/24 ----------------- diff --git a/emcc.py b/emcc.py index f551c64fa2cce..0b1a963707719 100644 --- a/emcc.py +++ b/emcc.py @@ -684,6 +684,9 @@ def phase_parse_arguments(state): for s in settings_changes: key, value = s.split('=', 1) key, value = normalize_boolean_setting(key, value) + old_value = user_settings.get(key) + if old_value and old_value != value: + diagnostics.warning('unused-command-line-argument', f'-s{key} specified multiple times. Ignoring previous value (`{old_value}`)') user_settings[key] = value # STRICT is used when applying settings so it needs to be applied first before diff --git a/test/common.py b/test/common.py index fc74c360ef741..78bbd5d591ab9 100644 --- a/test/common.py +++ b/test/common.py @@ -868,7 +868,7 @@ def setUp(self): # For historical reasons emcc compiles and links as C++ by default. # However we want to run our tests in a more strict manner. We can # remove this if the issue above is ever fixed. - self.set_setting('NO_DEFAULT_TO_CXX') + self.set_setting('DEFAULT_TO_CXX', 0) self.ldflags = [] # Increate stack trace limit to maximise usefulness of test failure reports self.node_args = ['--stack-trace-limit=50'] diff --git a/test/test_browser.py b/test/test_browser.py index eb24332cb8613..5be6fe0374986 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -4866,7 +4866,7 @@ def test_pthread_hello_thread(self, opts, modularize): 'modularize': (['-sMODULARIZE', '-sEXPORT_NAME=MyModule'],), 'O3': (['-O3'],), 'O3_modularize': (['-O3', '-sMODULARIZE', '-sEXPORT_NAME=MyModule'],), - 'O3_modularize_MINIMAL_RUNTIME_2': (['-O3', '-sMODULARIZE', '-sEXPORT_NAME=MyModule', '-sMINIMAL_RUNTIME=2'],), + 'O3_modularize_MINIMAL_RUNTIME_2': (['-O3', '-sMODULARIZE', '-sEXPORT_NAME=MyModule', '-sMINIMAL_RUNTIME=2', '-Wno-unused-command-line-argument'],), }) def test_minimal_runtime_hello_thread(self, opts): self.btest_exit('pthread/hello_thread.c', args=['--closure=1', '-sMINIMAL_RUNTIME', '-pthread'] + opts) diff --git a/test/test_core.py b/test/test_core.py index 2622dd04f39f6..428dd4b33a98a 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -9157,8 +9157,9 @@ def test_pthread_create_embind_stack_check(self): # embind should work with stack overflow checks (see #12356) self.set_setting('STACK_OVERFLOW_CHECK', 2) self.set_setting('EXIT_RUNTIME') + self.set_setting('DEFAULT_TO_CXX') self.emcc_args += ['-lembind'] - self.do_run_in_out_file_test('core/pthread/create.c', emcc_args=['-sDEFAULT_TO_CXX']) + self.do_run_in_out_file_test('core/pthread/create.c') @node_pthreads def test_pthread_exceptions(self): diff --git a/test/test_other.py b/test/test_other.py index 506d87f35e42d..ffe94b165173c 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -7811,6 +7811,10 @@ def test_dash_s_bad_json_types(self): err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sEXPORTED_FUNCTIONS=[{"a":1}]']) self.assertContained("list members in settings must be strings (not $)", err) + def test_dash_s_repeated(self): + err = self.expect_fail([EMCC, '-Werror', test_file('hello_world.c'), '-sEXPORTED_FUNCTIONS=foo', '-sEXPORTED_FUNCTIONS=bar']) + self.assertContained('emcc: error: -sEXPORTED_FUNCTIONS specified multiple times. Ignoring previous value (`foo`) [-Wunused-command-line-argument]', err) + def test_zeroinit(self): create_file('src.c', r''' #include @@ -12017,21 +12021,23 @@ def test_default_to_cxx(self): @parameterized({ '': ([],), - 'minimal': (['-sMINIMAL_RUNTIME', '-sSUPPORT_ERRNO'],), + 'minimal': (['-sMINIMAL_RUNTIME'],), }) def test_support_errno(self, args): self.emcc_args += args + ['-sEXPORTED_FUNCTIONS=_main,___errno_location', '-Wno-deprecated'] - self.do_other_test('test_support_errno.c') - size_default = os.path.getsize('test_support_errno.js') + self.do_other_test('test_support_errno.c', emcc_args=['-sSUPPORT_ERRNO']) + size_enabled = os.path.getsize('test_support_errno.js') # Run the same test again but with SUPPORT_ERRNO disabled. This time we don't expect errno # to be set after the failing syscall. - self.emcc_args += ['-sSUPPORT_ERRNO=0'] - self.do_other_test('test_support_errno.c', out_suffix='_disabled') + self.do_other_test('test_support_errno.c', emcc_args=['-sSUPPORT_ERRNO=0'], out_suffix='_disabled') # Verify the JS output was smaller - self.assertLess(os.path.getsize('test_support_errno.js'), size_default) + size_disabled = os.path.getsize('test_support_errno.js') + print(size_enabled) + print(size_disabled) + self.assertLess(size_disabled, size_enabled) def test_assembly(self): self.run_process([EMCC, '-c', test_file('other/test_asm.s'), '-o', 'foo.o'])