r313784 - Remove offset size check in nullptr arithmetic handling

Dimitry Andric via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 24 13:40:11 PDT 2018


On 20 Sep 2017, at 20:06, Andrew Kaylor via cfe-commits <cfe-commits at lists.llvm.org> wrote:
> 
> Author: akaylor
> Date: Wed Sep 20 11:06:44 2017
> New Revision: 313784
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=313784&view=rev
> Log:
> Remove offset size check in nullptr arithmetic handling
> 
> Differential Revision: https://reviews.llvm.org/D37042

Hi Andrew,

Interestingly, this change (and its related r313666) break PHP 5.6's opcache module, as reported in https://bugs.freebsd.org/227723.

PHP 5 uses a construct like to the following, to store multiple items in a 'variable' struct [1]:

    typedef struct TV {
      long tmp;
      char tmp3[30];
    } temp_variable;

    #define EX_TMP_VAR(ex, n)      ((temp_variable*)(((char*)(ex)) + ((int)(n))))
    #define EX_TMP_VAR_NUM(ex, n)  (EX_TMP_VAR(ex, 0) - (1 + (n)))
    #define VAR_NUM(v)             ((unsigned int)(EX_TMP_VAR_NUM(0, 0) - EX_TMP_VAR(0, v)))

Invoking the VAR_NUM() macro gives different answers before and after r313784, e.g. at r313783:

    VAR_NUM(-100) -> 1

At r313784:

   VAR_NUM(-100) -> 0xf999999c

I proposed a workaround which avoids the null pointer arithmetic, but can you shed any light as to why your changes seem to make matters worse for PHP, while they seem to have been intended to make this kind of construct work better instead?

-Dimitry

[1] See also: https://github.com/php/php-src/blob/PHP-5.6/Zend/zend_compile.h#L417
         and: https://github.com/php/php-src/blob/PHP-5.6/ext/opcache/Optimizer/zend_optimizer_internal.h#L28

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 223 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180424/92aa2ece/attachment.sig>


More information about the cfe-commits mailing list