tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

macOS clang has enabled -Werror=implicit-int



The recent yacc-shave thread was about a problem introduced only with the latest macOS Command Line Tools, not with the latest full Xcode. We've solved that well enough for the moment in pkgsrc-current.

This thread is about a problem that I believe exists in both. Yay!

My tools, for reference:

$ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep ^version:
    version: 15.3.0.0.1.1708646388

    $ /usr/bin/clang --version
    Apple clang version 15.0.0 (clang-1500.3.9.4)

Example of a new failure in the "build" phase:

    $ ( cd textproc/xmlto && bmake )
    [...]
xmlif/xmlif.l:46:8: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int] static ifsense; /* sense of last `if' or unless seen */
    ~~~~~~ ^
    int
xmlif/xmlif.l:243:1: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
    main(int argc, char *argv[])
    ^
    int
    2 errors generated.
    *** Error code 1

    Stop.

Example of a new failure in the "configure" phase:

    $ ( cd www/links && bmake; tail -14 work*/*/config.log | head -8 )
    [...]
    checking for gcc... clang
checking whether the C compiler (clang -pipe -O2 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk -I/opt/pkg/include -L/opt/pkg/lib) works... no configure: error: installation or configuration problem: C compiler cannot create executables.
    *** Error code 1

    Stop.
    configure:878: checking for gcc
configure:991: checking whether the C compiler (clang -pipe -O2 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk -I/opt/pkg/include -L/opt/pkg/lib) works configure:1007: clang -o conftest -pipe -O2 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk -I/opt/pkg/include -I/opt/pkg/include -L/opt/pkg/lib conftest.c 1>&5 configure:1004:1: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
    main(){return(0);}
    ^
    int
    1 error generated.

How many packages are broken by this new default? Hard to say without a bulk build, but seems like a lot. Quite possibly far too many to fix before our next stable branch.

It's not just Apple's clang that turns these kinds of warnings into errors. Upstream clang 16 does too: https://www.redhat.com/en/blog/new-warnings-and-errors-clang-16 Apple has been pulling some of these defaults into earlier versions of their vendor-provided clang.

(And it's not just clang that's tightening these defaults. A Gentoo developer who has done quite a lot of work on this stuff pointed us at their findings, which also mention gcc 14 making similar changes: https://wiki.gentoo.org/wiki/Modern_C_porting So whatever we figure out here, we'll want to apply to gcc 14 when we get it.)

When Apple default-enabled -Werror=implicit-function-declaration in Xcode 12, with similar impact, we defaulted it back off: https://github.com/NetBSD/pkgsrc/commit/36b0b26e1779e663ebcc8569956637ff1f8e68a6

We can't handle this case the exact same way, unfortunately, because -Werror=implicit-int doesn't show up in `clang -###` output. The following patch causes -Wno-error=implicit-int to be passed to any clang where doing so doesn't cause an error. It fixes both of the above package failures.

Index: mk/compiler/clang.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/compiler/clang.mk,v
retrieving revision 1.42
diff -u -p -r1.42 clang.mk
--- mk/compiler/clang.mk	18 Oct 2023 08:48:51 -0000	1.42
+++ mk/compiler/clang.mk	11 Mar 2024 18:36:28 -0000
@@ -90,6 +90,17 @@ _NOERROR_IMPLICIT_cmd=	${CCPATH} -\#\#\#
 CWRAPPERS_PREPEND.cc+=	${_NOERROR_IMPLICIT_cmd:sh}
 .endif

+# Xcode 15 and Clang 16 have another zealous new default that the wide
+# world of random upstream software isn't ready for. We can't turn it
+# off as precisely (it doesn't show up in `clang -###` output), so we
+# simply turn it off for every clang that doesn't complain. As before,
+# packages and users can override via CFLAGS/CPPFLAGS.
+_NOERROR_IMPLICIT2_cmd= ${CCPATH} -\#\#\# -Wno-error=implicit-int -x c /dev/null \
+			>/dev/null 2>&1 \
+			&& ${ECHO} -Wno-error=implicit-int \
+			|| ${TRUE}
+CWRAPPERS_PREPEND.cc+=	${_NOERROR_IMPLICIT2_cmd:sh}
+
 .for _version_ in ${_CXX_STD_VERSIONS}
 _CXX_STD_FLAG.${_version_}?=	-std=${_version_}
 .endfor


Home | Main Index | Thread Index | Old Index