shadow-maint / shadow

Upstream shadow tree
Other
292 stars 228 forks source link

Modern C: porting to Clang 16, GCC 14, and ISO C23 #922

Closed alejandro-colomar closed 7 months ago

alejandro-colomar commented 7 months ago

CC: @thesamesam

Link: https://wiki.gentoo.org/wiki/Modern_C_porting#What_changed.3F

I've installed GCC 14 (from Debian RC-Buggy) and Clang 17, and started playing with these things.

The following flags can be added with no problems:

-Werror=implicit-int
-Werror=incompatible-pointer-types
-Werror=int-conversion
-Wno-unknown-warning

The following flags work with gcc-14, but don't work with gcc-13:

-Werror=declaration-missing-parameter-type:

checking for gcc... gcc-13
checking whether the C compiler works... no
configure: error: in `/home/alx/src/shadow/shadow/W':
configure: error: C compiler cannot create executables
See `config.log' for more details

-Werror=return-mismatch:

checking for gcc... gcc-13
checking whether the C compiler works... no
configure: error: in `/home/alx/src/shadow/shadow/W':
configure: error: C compiler cannot create executables
See `config.log' for more details

The following flags don't work with gcc-14 nor with gcc-13:

-Werror=deprecated-non-prototype:

checking for gcc... gcc-14
checking whether the C compiler works... no
configure: error: in `/home/alx/src/shadow/shadow/W':
configure: error: C compiler cannot create executables
See `config.log' for more details
checking for gcc... gcc-13
checking whether the C compiler works... no
configure: error: in `/home/alx/src/shadow/shadow/W':
configure: error: C compiler cannot create executables
See `config.log' for more details

-Werror=incompatible-function-pointer-types:

checking for gcc... gcc-14
checking whether the C compiler works... no
configure: error: in `/home/alx/src/shadow/shadow/W':
configure: error: C compiler cannot create executables
See `config.log' for more details
checking for gcc... gcc-13
checking whether the C compiler works... no
configure: error: in `/home/alx/src/shadow/shadow/W':
configure: error: C compiler cannot create executables
See `config.log' for more details

-Werror=strict-prototypes:

checking for posix_spawn... no
configure: error: posix_spawn is needed for nscd support
checking for posix_spawn... no
configure: error: posix_spawn is needed for nscd support
alejandro-colomar commented 7 months ago

@thesamesam Do you know if those issues are autotools problems or a problem in shadow? (Or maybe my problems?) Can you reproduce them in Gentoo?

thesamesam commented 7 months ago

Can you share config.log for each? It's possible they go away with the new autoconf-2.72.

alejandro-colomar commented 7 months ago

Maybe this is enough:

$ git diff -U0
diff --git a/autogen.sh b/autogen.sh
index 59f97247..5d3f2d8c 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -8 +8 @@ CFLAGS="$CFLAGS -Wextra"
-#CFLAGS="$CFLAGS -Werror=declaration-missing-parameter-type"
+CFLAGS="$CFLAGS -Werror=declaration-missing-parameter-type"
configure:4320: checking whether the C compiler works
configure:4342: gcc -O2 -Wall -Wextra -Werror=declaration-missing-parameter-type -Werror=implicit-function-declaration -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wno-expansion-to-defined -Wno-unknown-attributes -Wno-unknown-warning -Wno-unknown-warning-option   conftest.c  >&5
cc1: error: '-Werror=declaration-missing-parameter-type': no option '-Wdeclaration-missing-parameter-type'; did you mean '--warn-missing-parameter-type'?
cc1: note: unrecognized command-line option '-Wno-unknown-warning-option' may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option '-Wno-unknown-warning' may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option '-Wno-unknown-attributes' may have been intended to silence earlier diagnostics
configure:4346: $? = 1
configure:4386: result: no
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "shadow"
| #define PACKAGE_TARNAME "shadow"
| #define PACKAGE_VERSION "4.14.0"
| #define PACKAGE_STRING "shadow 4.14.0"
| #define PACKAGE_BUGREPORT "pkg-shadow-devel@lists.alioth.debian.org"
| #define PACKAGE_URL "https://github.com/shadow-maint/shadow"
| #define PACKAGE "shadow"
| #define VERSION "4.14.0"
| /* end confdefs.h.  */
| 
| int
| main (void)
| {
| 
|   ;
|   return 0;
| }
configure:4391: error: in `/home/alx/src/shadow/shadow/W':
configure:4393: error: C compiler cannot create executables
See `config.log' for more details

Suspect line:

cc1: note: unrecognized command-line option '-Wno-unknown-warning' may have been intended to silence earlier diagnostics

With gcc-13. But that's weird, because -Wno-unknown-warning is well documented in the manual page for gcc-13:

$ man gcc 2>/dev/null | tail -n-1
gcc‐13.2.0                            2023‐08‐04                                GCC(1)
$ man gcc 2>/dev/null | grep -A2 unknown-warning
     When an unrecognized warning option is requested (e.g.,  -Wunknown-warning),  GCC
     emits  a  diagnostic  stating that the option is not recognized.  However, if the
     -Wno- form is used, the behavior is slightly different: no diagnostic is produced
     for -Wno-unknown-warning unless  other  diagnostics  are  being  produced.   This
     allows  the  use  of  new -Wno- options with old compilers, but if something goes
     wrong, the compiler warns that an unrecognized option is present.
$ gcc --version
gcc (Debian 13.2.0-10) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
alejandro-colomar commented 7 months ago

I can reproduce that:

$ cat foo.c 
int
main (void)
{
  return 0;
}
$ gcc -Werror=declaration-missing-parameter-type -Wno-unknown-warning foo.c
cc1: error: ‘-Werror=declaration-missing-parameter-type’: no option ‘-Wdeclaration-missing-parameter-type’; did you mean ‘--warn-missing-parameter-type’?
cc1: note: unrecognized command-line option ‘-Wno-unknown-warning’ may have been intended to silence earlier diagnostics
$ gcc-14 -Werror=declaration-missing-parameter-type -Wno-unknown-warning foo.c
$ clang -Werror=declaration-missing-parameter-type -Wno-unknown-warning foo.c
warning: unknown warning option '-Werror=declaration-missing-parameter-type'; did you mean '-Werror=declaration-after-statement'? [-Wunknown-warning-option]
warning: unknown warning option '-Wno-unknown-warning'; did you mean '-Wno-unknown-argument'? [-Wunknown-warning-option]
2 warnings generated.
$ clang-17 -Werror=declaration-missing-parameter-type -Wno-unknown-warning foo.c
warning: unknown warning option '-Werror=declaration-missing-parameter-type'; did you mean '-Werror=declaration-after-statement'? [-Wunknown-warning-option]
warning: unknown warning option '-Wno-unknown-warning'; did you mean '-Wno-unknown-argument'? [-Wunknown-warning-option]
2 warnings generated.

Is this a GCC 13 bug?

alejandro-colomar commented 7 months ago

Ahhh, now I'm re-reading the manual page, and maybe -Wno-unknown-warning wasn't meant as a flag that disables warnings for unknown warning flags, but rather a placeholder such as -Wno-foo. :D