Bug #80617 [Opn->Csd]: GCC throws warning about type narrowing in ZEND_TYPE_INIT_CODE

From: Date: Thu, 14 Jan 2021 09:09:26 +0000
Subject: Bug #80617 [Opn->Csd]: GCC throws warning about type narrowing in ZEND_TYPE_INIT_CODE
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231556@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80617&edit=1 ID: 80617 Updated by: nikic@php.net Reported by: nathanael at prolegis dot ca Summary: GCC throws warning about type narrowing in ZEND_TYPE_INIT_CODE -Status: Open +Status: Closed Type: Bug Package: Compile Warning Operating System: Linux PHP Version: 8.0.1 Block user comment: N Private report: N New Comment: Automatic comment on behalf of nikita.ppv@gmail.com Revision: http://git.php.net/?p=php-src.git;a=commit;h=880bf6222415f5bb87a73bc830bfa98ef30c267a Log: Fixed bug #80617: Type narrowing warning in ZEND_TYPE_INIT_CODE Previous Comments: ------------------------------------------------------------------------ [2021-01-12 16:22:46] nathanael at prolegis dot ca Yes, if I edit Zend/zend_types.h and change _ZEND_TYPE_NULLABLE_BIT to 0x2u I can compile the extension without any warnings. ------------------------------------------------------------------------ [2021-01-12 09:02:21] nikic@php.net Did you try modifying the header to verify that adding the "u" does avoid the warning? ------------------------------------------------------------------------ [2021-01-11 23:52:19] nathanael at prolegis dot ca Description: ------------ When compiling a php extension with GCC we're getting a warning with gcc which is a fatal error with clang. When compiling we get the following warning/output: /usr/include/php/Zend/zend_types.h:264:50: warning: narrowing conversion of '((((12 == 17) ? ((1 << 2) | (1 << 3)) : ((12 == 16) ? (((((((((1 << 1) | (1 << 2)) | (1 << 3)) | (1 << 4)) | (1 << 5)) | (1 << 6)) | (1 << 7)) | (1 << 8)) | (1 << 9)) : (1 << 12))) | ((& arg)->Php::Argument::allowNull() ? 2 : 0)) | 0)' from 'int' to 'uint32_t {aka unsigned int}' inside { } [-Wnarrowing] | ((allow_null) ? _ZEND_TYPE_NULLABLE_BIT : 0) | (extra_flags)) ^ /usr/include/php/Zend/zend_types.h:260:11: note: in definition of macro 'ZEND_TYPE_INIT_MASK' { NULL, (_type_mask) } ^~~~~~~~~~ zend/callable.h:217:62: note: in expansion of macro 'ZEND_TYPE_INIT_CODE' case Type::Callable: info->type = (zend_type) ZEND_TYPE_INIT_CODE(IS_CALLABLE, arg.allowNull(), 0); break; // anything that can be invoke the issue is arg.allowNull() it returns an int, even though its 0 or 1 there's an the warning is there. If I just pass a 0, there is no warning. Another user commented as follows: https://github.com/CopernicaMarketingSoftware/PHP-CPP/pull/471#discussion_r553716780 Basically saying the issue was "The problem is because the zend_type struct takes a uint32_t, but they defined _ZEND_TYPE_NULLABLE_BIT as 0x2, and in C/C++ constants are signed by default. " Is this correct? If so can the _ZEND_TYPE_NULLABLE_BIT be defined as 0x2u instead? I've also tried casting the result of arg.allowNull to uint32_t to no avail. Test script: --------------- info->type = (zend_type) ZEND_TYPE_INIT_CODE(IS_UNDEF, arg.allowNull(), 0); Expected result: ---------------- No warnings about type narrowing when passing an int. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80617&edit=1

« previous php.bugs (#231556) next »