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

From: Date: Tue, 12 Jan 2021 09:02:21 +0000
Subject: Bug #80617 [Opn]: 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-231505@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 Type: Bug Package: Compile Warning Operating System: Linux PHP Version: 8.0.1 Block user comment: N Private report: N New Comment: Did you try modifying the header to verify that adding the "u" does avoid the warning? Previous Comments: ------------------------------------------------------------------------ [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 (#231505) next »