Clang should error for all implicit function checks (#9165)

* compilers: improve docstring to `get_compiler_check_args()`

There was an incomplete list, which wasn't useful as it now takes an
enum anyway. Also add a new entry to the list of reasons to use this
function.

* clang: Add -Werror=implicit-function-declarations to check_args

Unlike GCC, clang warns but doesn't error when an implicit function
declaration happens. This means in checks like
`compiler.has_header_symbol('string.h', 'strlcat')` (on Linux, at least)
that GCC will fail, as there is no such function; clang will emit a
warning, but since it exists with a 0 status Meson interprets that as
success. To fix this, add `-Werror=implicit-function-declarations` to
clang's check arguments.

There seems to be something specific about functions that _may_ exist in
a header on a given system, as `cc.has_header_symbol('string.h',
'foobar')` will return false with clang, but `strlcat` will return true,
even though it's not defined. It is however, defined in some OSes, like
Solaris and the BSDs.

Fixes #9140
pull/9202/head
Dylan Baker 4 years ago committed by GitHub
parent 43302d3296
commit 9bf669a016
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      mesonbuild/compilers/compilers.py
  2. 6
      mesonbuild/compilers/mixins/clang.py

@ -1154,11 +1154,12 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
def get_compiler_check_args(self, mode: CompileCheckMode) -> T.List[str]:
"""Arguments to pass the compiler and/or linker for checks.
The default implementation turns off optimizations. mode should be
one of:
The default implementation turns off optimizations.
Examples of things that go here:
- extra arguments for error checking
- Arguments required to make the compiler exit with a non-zero status
when something is wrong.
"""
return self.get_no_optimization_args()

@ -81,7 +81,11 @@ class ClangCompiler(GnuLikeCompiler):
return ['-include-pch', os.path.join(pch_dir, self.get_pch_name(header))]
def get_compiler_check_args(self, mode: CompileCheckMode) -> T.List[str]:
myargs = [] # type: T.List[str]
# Clang is different than GCC, it will return True when a symbol isn't
# defined in a header. Specifically this seems ot have something to do
# with functions that may be in a header on some systems, but not all of
# them. `strlcat` specifically with can trigger this.
myargs: T.List[str] = ['-Werror=implicit-function-declaration']
if mode is CompileCheckMode.COMPILE:
myargs.extend(['-Werror=unknown-warning-option', '-Werror=unused-command-line-argument'])
if mesonlib.version_compare(self.version, '>=3.6.0'):

Loading…
Cancel
Save