Skip to content

Commit 61c9bd2

Browse files
authored
Remove injection of -Werror=implicit-function-declaration (#23465)
I believe this change in the defaults was probably don't back in the day when mismatched function pointers were not otherwise will reported and could lead to hard-to-debug crashes. These days the linker will five a clear error about function signature mistmatches between object files so I think the deviation is no longer worth it. This change only effect C and not C++. Note: Adding this extra warning actually has some cost because it requires us to understand if the compiler is running C or C++ mode. This is more complicated than is can seem because its possible to specify more than one language mode on the command line. e.g: clang -x c++ myfile.cpp -x c myfile.c We don't currently have great support for this method, and its obviously not common.
1 parent 996793f commit 61c9bd2

File tree

3 files changed

+2
-33
lines changed

3 files changed

+2
-33
lines changed

emcc.py

+2-14
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def get_clang_flags(user_args):
424424
cflags = None
425425

426426

427-
def get_cflags(user_args, is_cxx):
427+
def get_cflags(user_args):
428428
global cflags
429429
if cflags:
430430
return cflags
@@ -448,17 +448,6 @@ def get_cflags(user_args, is_cxx):
448448
# in strict mode. Code should use the define __EMSCRIPTEN__ instead.
449449
cflags.append('-DEMSCRIPTEN')
450450

451-
# Changes to default clang behavior
452-
453-
# Implicit functions can cause horribly confusing function pointer type errors, see #2175
454-
# If your codebase really needs them - very unrecommended! - you can disable the error with
455-
# -Wno-error=implicit-function-declaration
456-
# or disable even a warning about it with
457-
# -Wno-implicit-function-declaration
458-
# This is already an error in C++ so we don't need to inject extra flags.
459-
if not is_cxx:
460-
cflags += ['-Werror=implicit-function-declaration']
461-
462451
ports.add_cflags(cflags, settings)
463452

464453
def array_contains_any_of(hay, needles):
@@ -984,10 +973,9 @@ def get_language_mode(args):
984973
return ''
985974

986975
language_mode = get_language_mode(newargs)
987-
use_cxx = 'c++' in language_mode or shared.run_via_emxx
988976

989977
def get_clang_command():
990-
return compiler + get_cflags(state.orig_args, use_cxx)
978+
return compiler + get_cflags(state.orig_args)
991979

992980
def get_clang_command_preprocessed():
993981
return compiler + get_clang_flags(state.orig_args)

test/other/test_implicit_func.c

-7
This file was deleted.

test/test_other.py

-12
Original file line numberDiff line numberDiff line change
@@ -5368,18 +5368,6 @@ def test_global_inits(self):
53685368
self.assertContained('argc: 1\n16\n17\n10\n', self.run_js('a.out.js'))
53695369
self.assertContainedIf('globalCtors', src, has_global)
53705370

5371-
def test_implicit_func(self):
5372-
# EMCC makes -Wimplicit-function-declaration an error by default in all modes. Upstream LLVM
5373-
# emits a warning in gnu89 mode, but otherwise emcc's behavior is identical to upstream.
5374-
IMPLICIT_C89 = "error: implicit declaration of function 'strnlen'"
5375-
# Also check for -Wincompatible-function-pointer-types (it became an error in LLVM 16)
5376-
INCOMPATIBLE = ': incompatible function pointer types'
5377-
5378-
stderr = self.expect_fail(
5379-
[EMCC, path_from_root('test/other/test_implicit_func.c'), '-c', '-o', 'implicit_func.o', '-std=gnu89'])
5380-
self.assertContained(IMPLICIT_C89, stderr)
5381-
self.assertContained(INCOMPATIBLE, stderr)
5382-
53835371
@requires_native_clang
53845372
@crossplatform
53855373
def test_bad_triple(self):

0 commit comments

Comments
 (0)