Skip to content

Add some compiler flags which aren't included in -Wall or -Wextra #6199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Sep 23, 2020

This adds -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wformat-truncation and -fno-common compiler flags.

-Wlogical-op did seem to find some legit bugs.

EDIT: Need to figure out a way to get around Windows for the GCC pragma

@Girgias
Copy link
Member Author

Girgias commented Sep 24, 2020

@dstogov could you just confirm that the changes in FFI, SOAP and the JIT are correct as some seem to be bugs and IIRC you are the maintainer of FFI and SOAP.

@nikic nikic added this to the PHP 8.1 milestone Sep 24, 2020
@Girgias Girgias force-pushed the add-sensible-compiler-flags branch from 3e5e0a4 to e93f8d4 Compare September 24, 2020 13:24
@nikic
Copy link
Member

nikic commented Sep 24, 2020

I've moved this to the 8.1 milestone, to avoid additional disruption for PECL extensions this late.

} else if (sym == YY___CONST) {
sym = get_sym();
} else {
} else { /* sym == YY_CONST || sym == YY___CONST || something else */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is auto generated. It shouldn't be edited directly.

@dstogov
Copy link
Member

dstogov commented Sep 30, 2020

@dstogov could you just confirm that the changes in FFI, SOAP and the JIT are correct as some seem to be bugs and IIRC you are the maintainer of FFI and SOAP.

FFI, SOAP and JIT looks proper except direct ext/ffi/ffi_parser.c update.

I'll merge these fixes.

@dstogov
Copy link
Member

dstogov commented Sep 30, 2020

@dstogov could you just confirm that the changes in FFI, SOAP and the JIT are correct as some seem to be bugs and IIRC you are the maintainer of FFI and SOAP.

@dstogov could you just confirm that the changes in FFI, SOAP and the JIT are correct as some seem to be bugs and IIRC you are the maintainer of FFI and SOAP.

FFI, SOAP and JIT looks proper except direct ext/ffi/ffi_parser.c update.

I'll merge these fixes.

FFI, SOAP and JIT fixes are merged into PHP-7.3 and above.
Thanks for catching this.

@Girgias Girgias force-pushed the add-sensible-compiler-flags branch 5 times, most recently from 69cf664 to 2e37b20 Compare September 30, 2020 14:20
@twose
Copy link
Member

twose commented Sep 30, 2020

How about this way:

#if defined(EWOULDBLOCK) && EAGAIN != EWOULDBLOCK
#define IS_TRANSIENT_ERROR(err) (err == EAGAIN || err == EWOULDBLOCK)
#else
#define IS_TRANSIENT_ERROR(err) (err == EAGAIN)
#endif

@twose
Copy link
Member

twose commented Sep 30, 2020

I found the same solution in libevent, but libuv not
https://github.com/libevent/libevent/blob/master/util-internal.h#L110

and it looks it's unnecessary to check if EWOULDBLOCK was defined

@Girgias Girgias force-pushed the add-sensible-compiler-flags branch 2 times, most recently from 660c2df to 89763bb Compare October 1, 2020 18:04
Comment on lines 47 to 53
/* This is a work around for GCC bug 69602: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69602 */
#if defined(EWOULDBLOCK) && EAGAIN != EWOULDBLOCK
# define IS_TRANSIENT_ERROR(err) (err == EAGAIN || err == EWOULDBLOCK)
#else
# define IS_TRANSIENT_ERROR(err) (err == EAGAIN)
#endif

Copy link
Member

@twose twose Oct 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could put the code here, it also works on ext/sockets

#ifdef PHP_WIN32
# ifdef EWOULDBLOCK
# undef EWOULDBLOCK
# endif
# ifdef EINPROGRESS
# undef EINPROGRESS
# endif
# define EWOULDBLOCK WSAEWOULDBLOCK
# define EINPROGRESS WSAEWOULDBLOCK
# define fsync _commit
# define ftruncate(a, b) chsize(a, b)
#endif /* defined(PHP_WIN32) */
#ifndef EWOULDBLOCK
# define EWOULDBLOCK EAGAIN
#endif

BTW, the name is inspired by libuv, it defined on the C source file instead of a header file, so it's better to add a prefix on it, or named like ZEND_IS_EAGAIN (I am not sure, naming is not my strength...)

@Girgias Girgias force-pushed the add-sensible-compiler-flags branch 2 times, most recently from 1682685 to 5a18e29 Compare October 2, 2020 17:47
@@ -2746,7 +2746,7 @@ PHP_FUNCTION(imap_sort)
}

array_init(return_value);
if (slst != NIL && slst != 0) {
if (slst != 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should either be != NIL or != NULL, as it is a pointer.

Zend/Zend.m4 Outdated
@@ -212,9 +212,12 @@ else
AC_DEFINE(ZEND_DEBUG,0,[ ])
fi

test -n "$GCC" && CFLAGS="-Wall -Wextra -Wno-strict-aliasing -Wno-implicit-fallthrough -Wno-unused-parameter -Wno-sign-compare $CFLAGS"
test -n "$GCC" && CFLAGS="-Wall -Wextra -Wno-strict-aliasing -Wno-implicit-fallthrough -Wno-unused-parameter -Wno-sign-compare -fno-common $CFLAGS"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the -fno-common here?

#if EAGAIN != EWOULDBLOCK
# define IS_TRANSIENT_ERROR(err) (err == EAGAIN || err == EWOULDBLOCK)
#else
# define IS_TRANSIENT_ERROR(err) (err == EAGAIN)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a PHP_ prefix?

@Girgias Girgias force-pushed the add-sensible-compiler-flags branch from 5a18e29 to d527a00 Compare October 9, 2020 20:18
@@ -61,7 +61,6 @@ steps:
--with-imap \
--with-kerberos \
--with-imap-ssl \
--enable-werror \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop these now, or is there still something left?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one remaining failure on 32bits:

/home/vsts/work/1/s/ext/sodium/libsodium.c: In function ‘zif_sodium_crypto_secretstream_xchacha20poly1305_push’:
/home/vsts/work/1/s/ext/sodium/libsodium.c:3181:71: warning: logical ‘or’ of equal expressions [-Wlogical-op]
 3181 |  if (msg_len > crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX ||
      |     

@Girgias Girgias force-pushed the add-sensible-compiler-flags branch from d527a00 to fc67f11 Compare October 10, 2020 13:57
Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG assuming CI happy.

Adds the following compiler flags:
 . -Wduplicated-cond
 . -Wlogical-op
 . -Wformat-truncation
 . -fno-common
@Girgias Girgias force-pushed the add-sensible-compiler-flags branch from fc67f11 to ab5b59f Compare October 10, 2020 15:09
@php-pulls php-pulls closed this in 49783e3 Oct 10, 2020
@Girgias Girgias deleted the add-sensible-compiler-flags branch October 10, 2020 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants