llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.8k stars 11.45k forks source link

Builtin prototypes are implicitly defined #33905

Open jsonn opened 6 years ago

jsonn commented 6 years ago
Bugzilla Link 34557
Version unspecified
OS All

Extended Description

A common way to do autoconf-style tests for declarations in headers uses the following approach:

int main(void) { (void)strlcpy; return 0; }

This should fail with unknown identifier errors, but currently passes with a implicit prototype warning for GNUish language modes (i.e. gnu89, gnu99 etc). It fails for "unknown" identifiers like strlcpy2. This is a pretty bad error as it can lead to incorrect autodetection of system headers.

Karlson2k commented 3 months ago

This bug is still present in the latest llvm/clang builds/code.

The constructs like

  (void) stpncpy;

trigger incorrect clang warning error: call to undeclared library function 'stpncpy' with type 'char *(char *, const char *, unsigned long)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration], while there is no implicit function declaration in the code.

This happens only when the compiler has built-in replacement for used functions.

The same for the constructs like

  (void) &stpncpy;

See also:

cor3ntin commented 3 months ago

You can add -fno-builtin to disable this behavior

Karlson2k commented 3 months ago

You can add -fno-builtin to disable this behavior

Yes, thanks. This workaround is used by autoconf.

However, the warning itself is still incorrect and should be fixed.