Skip to content

Commit 0ad3bf8

Browse files
authored
Make unused main warning suppressable (#20969)
Fixes: #20967
1 parent 95dd047 commit 0ad3bf8

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

test/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,7 @@ def test_emscripten_api(self):
18541854
# Sanitizers are not compatible with LINKABLE (dynamic linking.
18551855
if not is_sanitizing(self.emcc_args) and not self.is_wasm64():
18561856
# test EXPORT_ALL
1857-
self.set_setting('EXPORTED_FUNCTIONS', [])
1857+
self.clear_setting('EXPORTED_FUNCTIONS')
18581858
self.set_setting('EXPORT_ALL')
18591859
self.set_setting('LINKABLE')
18601860
self.do_core_test('test_emscripten_api.cpp')

test/test_other.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7924,10 +7924,10 @@ def test(contents, expected, args=[], assert_returncode=0): # noqa
79247924
test("Module['print']('print'); Module['printErr']('err'); ", 'print\nerr', ['-sEXPORTED_RUNTIME_METHODS=print,printErr', '-Wno-js-compiler'])
79257925

79267926
def test_warn_unexported_main(self):
7927-
WARNING = 'main() is in the input files, but "_main" is not in EXPORTED_FUNCTIONS, which means it may be eliminated as dead code. Export it if you want main() to run.'
7927+
warning = 'emcc: warning: `main` is defined in the input files, but `_main` is not in `EXPORTED_FUNCTIONS`, which means it may be eliminated as dead code. Export it if you want `main` to run. [-Wunused-main]'
79287928

79297929
proc = self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORTED_FUNCTIONS=[]'], stderr=PIPE)
7930-
self.assertContained(WARNING, proc.stderr)
7930+
self.assertContained(warning, proc.stderr)
79317931

79327932
def test_source_file_with_fixed_language_mode(self):
79337933
create_file('src_tmp_fixed_lang', '''

tools/emscripten.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,8 @@ def finalize_wasm(infile, outfile, js_syms):
568568
unexpected_exports = [e for e in metadata.all_exports if treat_as_user_export(e)]
569569
unexpected_exports = [asmjs_mangle(e) for e in unexpected_exports]
570570
unexpected_exports = [e for e in unexpected_exports if e not in expected_exports]
571-
if '_main' in unexpected_exports:
572-
logger.warning('main() is in the input files, but "_main" is not in EXPORTED_FUNCTIONS, which means it may be eliminated as dead code. Export it if you want main() to run.')
571+
if not settings.STANDALONE_WASM and '_main' in unexpected_exports:
572+
diagnostics.warning('unused-main', '`main` is defined in the input files, but `_main` is not in `EXPORTED_FUNCTIONS`, which means it may be eliminated as dead code. Export it if you want `main` to run.')
573573
unexpected_exports.remove('_main')
574574

575575
building.user_requested_exports.update(unexpected_exports)

tools/shared.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
diagnostics.add_warning('js-compiler')
9292
diagnostics.add_warning('compatibility')
9393
diagnostics.add_warning('unsupported')
94+
diagnostics.add_warning('unused-main')
9495
# Closure warning are not (yet) enabled by default
9596
diagnostics.add_warning('closure', enabled=False)
9697

0 commit comments

Comments
 (0)