PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - lcov_data/ext/opcache/Optimizer - pass1_5.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 0 312 0.0 %
Date: 2014-04-16 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* pass 1
       2             :  * - substitute persistent constants (true, false, null, etc)
       3             :  * - perform compile-time evaluation of constant binary and unary operations
       4             :  * - optimize series of ADD_STRING and/or ADD_CHAR
       5             :  * - convert CAST(IS_BOOL,x) into BOOL(x)
       6             :  * - pre-evaluate constant function calls
       7             :  */
       8             : 
       9             : #if ZEND_EXTENSION_API_NO > PHP_5_2_X_API_NO
      10             : # define ZEND_IS_CONSTANT_TYPE(t)       (((t) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT)
      11             : #else
      12             : # define ZEND_IS_CONSTANT_TYPE(t)       ((t) == IS_CONSTANT)
      13             : #endif
      14             : 
      15           0 : if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
      16           0 :         int i = 0;
      17           0 :         zend_op *opline = op_array->opcodes;
      18           0 :         zend_op *end = opline + op_array->last;
      19           0 :         zend_bool collect_constants = (op_array == &script->main_op_array);
      20             : 
      21           0 :         while (opline < end) {
      22           0 :                 switch (opline->opcode) {
      23             :                 case ZEND_ADD:
      24             :                 case ZEND_SUB:
      25             :                 case ZEND_MUL:
      26             :                 case ZEND_DIV:
      27             :                 case ZEND_MOD:
      28             :                 case ZEND_SL:
      29             :                 case ZEND_SR:
      30             :                 case ZEND_CONCAT:
      31             :                 case ZEND_IS_EQUAL:
      32             :                 case ZEND_IS_NOT_EQUAL:
      33             :                 case ZEND_IS_SMALLER:
      34             :                 case ZEND_IS_SMALLER_OR_EQUAL:
      35             :                 case ZEND_IS_IDENTICAL:
      36             :                 case ZEND_IS_NOT_IDENTICAL:
      37             :                 case ZEND_BW_OR:
      38             :                 case ZEND_BW_AND:
      39             :                 case ZEND_BW_XOR:
      40             :                 case ZEND_BOOL_XOR:
      41           0 :                         if (ZEND_OP1_TYPE(opline) == IS_CONST &&
      42           0 :                                 ZEND_OP2_TYPE(opline) == IS_CONST) {
      43             :                                 /* binary operation with constant operands */
      44           0 :                                 int (*binary_op)(zval *result, zval *op1, zval *op2 TSRMLS_DC) = get_binary_op(opline->opcode);
      45           0 :                                 zend_uint tv = ZEND_RESULT(opline).var;         /* temporary variable */
      46             :                                 zval result;
      47             :                                 int er;
      48             : 
      49           0 :                                 if (opline->opcode == ZEND_DIV &&
      50           0 :                                         Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_LONG &&
      51           0 :                                         Z_LVAL(ZEND_OP2_LITERAL(opline)) == 0) {
      52             :                                         /* div by 0 */
      53           0 :                                         break;
      54             :                                 }
      55           0 :                                 er = EG(error_reporting);
      56           0 :                                 EG(error_reporting) = 0;
      57             :                                 /* evaluate constant expression */
      58           0 :                                 if (binary_op(&result, &ZEND_OP1_LITERAL(opline), &ZEND_OP2_LITERAL(opline) TSRMLS_CC) != SUCCESS) {
      59           0 :                                         EG(error_reporting) = er;
      60           0 :                                         break;
      61             :                                 }
      62           0 :                                 EG(error_reporting) = er;
      63           0 :                                 PZ_SET_REFCOUNT_P(&result, 1);
      64             :                                 PZ_UNSET_ISREF_P(&result);
      65             : 
      66           0 :                                 literal_dtor(&ZEND_OP1_LITERAL(opline));
      67           0 :                                 literal_dtor(&ZEND_OP2_LITERAL(opline));
      68           0 :                                 MAKE_NOP(opline);
      69             : 
      70           0 :                                 replace_tmp_by_const(op_array, opline + 1, tv, &result TSRMLS_CC);
      71             :                         }
      72           0 :                         break;
      73             : 
      74             :                 case ZEND_CAST:
      75           0 :                         if (ZEND_OP1_TYPE(opline) == IS_CONST &&
      76           0 :                                 opline->extended_value != IS_ARRAY &&
      77           0 :                                 opline->extended_value != IS_OBJECT &&
      78           0 :                                 opline->extended_value != IS_RESOURCE) {
      79             :                                 /* cast of constant operand */
      80           0 :                                 zend_uint tv = ZEND_RESULT(opline).var;         /* temporary variable */
      81             :                                 zval res;
      82           0 :                                 res = ZEND_OP1_LITERAL(opline);
      83             :                                 zval_copy_ctor(&res);
      84           0 :                                 switch (opline->extended_value) {
      85             :                                         case IS_NULL:
      86           0 :                                                 convert_to_null(&res);
      87           0 :                                                 break;
      88             :                                         case IS_BOOL:
      89           0 :                                                 convert_to_boolean(&res);
      90           0 :                                                 break;
      91             :                                         case IS_LONG:
      92           0 :                                                 convert_to_long(&res);
      93           0 :                                                 break;
      94             :                                         case IS_DOUBLE:
      95           0 :                                                 convert_to_double(&res);
      96           0 :                                                 break;
      97             :                                         case IS_STRING:
      98           0 :                                                 convert_to_string(&res);
      99             :                                                 break;
     100             :                                 }
     101             : 
     102           0 :                                 literal_dtor(&ZEND_OP1_LITERAL(opline));
     103           0 :                                 MAKE_NOP(opline);
     104             : 
     105           0 :                                 replace_tmp_by_const(op_array, opline + 1, tv, &res TSRMLS_CC);
     106           0 :                         } else if (opline->extended_value == IS_BOOL) {
     107             :                                 /* T = CAST(X, IS_BOOL) => T = BOOL(X) */
     108           0 :                                 opline->opcode = ZEND_BOOL;
     109           0 :                                 opline->extended_value = 0;
     110             :                         }
     111           0 :                         break;
     112             : 
     113             :                 case ZEND_BW_NOT:
     114             :                 case ZEND_BOOL_NOT:
     115           0 :                         if (ZEND_OP1_TYPE(opline) == IS_CONST) {
     116             :                                 /* unary operation on constant operand */
     117           0 :                                 unary_op_type unary_op = get_unary_op(opline->opcode);
     118             :                                 zval result;
     119           0 :                                 zend_uint tv = ZEND_RESULT(opline).var;         /* temporary variable */
     120             :                                 int er;
     121             : 
     122           0 :                                 er = EG(error_reporting);
     123           0 :                                 EG(error_reporting) = 0;
     124             : #if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
     125             :                                 if (unary_op(&result, &ZEND_OP1_LITERAL(opline)) != SUCCESS) {
     126             : #else
     127           0 :                                 if (unary_op(&result, &ZEND_OP1_LITERAL(opline) TSRMLS_CC) != SUCCESS) {
     128             : #endif
     129           0 :                                         EG(error_reporting) = er;
     130           0 :                                         break;
     131             :                                 }
     132           0 :                                 EG(error_reporting) = er;
     133           0 :                                 PZ_SET_REFCOUNT_P(&result, 1);
     134             :                                 PZ_UNSET_ISREF_P(&result);
     135             : 
     136           0 :                                 literal_dtor(&ZEND_OP1_LITERAL(opline));
     137           0 :                                 MAKE_NOP(opline);
     138             : 
     139           0 :                                 replace_tmp_by_const(op_array, opline + 1, tv, &result TSRMLS_CC);
     140             :                         }
     141           0 :                         break;
     142             : 
     143             :                 case ZEND_ADD_STRING:
     144             :                 case ZEND_ADD_CHAR:
     145             :                         {
     146           0 :                                 zend_op *next_op = opline + 1;
     147           0 :                                 int requires_conversion = (opline->opcode == ZEND_ADD_CHAR? 1 : 0);
     148           0 :                                 size_t final_length = 0;
     149             :                                 char *ptr;
     150             :                                 zend_op *last_op;
     151             : 
     152             :                                 /* There is always a ZEND_RETURN at the end
     153             :                                 if (next_op>=end) {
     154             :                                         break;
     155             :                                 }
     156             :                                 */
     157           0 :                                 while (next_op->opcode == ZEND_ADD_STRING || next_op->opcode == ZEND_ADD_CHAR) {
     158           0 :                                         if (ZEND_RESULT(opline).var != ZEND_RESULT(next_op).var) {
     159           0 :                                                 break;
     160             :                                         }
     161           0 :                                         if (next_op->opcode == ZEND_ADD_CHAR) {
     162           0 :                                                 final_length += 1;
     163             :                                         } else { /* ZEND_ADD_STRING */
     164           0 :                                                 final_length += ZEND_OP2_LITERAL(next_op).value.str.len;
     165             :                                         }
     166           0 :                                         next_op++;
     167             :                                 }
     168           0 :                                 if (final_length == 0) {
     169           0 :                                         break;
     170             :                                 }
     171           0 :                                 last_op = next_op;
     172           0 :                                 final_length += (requires_conversion? 1 : ZEND_OP2_LITERAL(opline).value.str.len);
     173           0 :                                 ptr = (char *)emalloc(final_length + 1);
     174           0 :                                 ptr[final_length] = '\0';
     175           0 :                                 if (requires_conversion) { /* ZEND_ADD_CHAR */
     176           0 :                                         char chval = (char)ZEND_OP2_LITERAL(opline).value.lval;
     177             : 
     178           0 :                                         ZEND_OP2_LITERAL(opline).value.str.val = ptr;
     179           0 :                                         ptr[0] = chval;
     180           0 :                                         ZEND_OP2_LITERAL(opline).type = IS_STRING;
     181           0 :                                         opline->opcode = ZEND_ADD_STRING;
     182           0 :                                         ptr++;
     183             :                                 } else { /* ZEND_ADD_STRING */
     184           0 :                                         memcpy(ptr, Z_STRVAL(ZEND_OP2_LITERAL(opline)), Z_STRLEN(ZEND_OP2_LITERAL(opline)));
     185           0 :                                         if (!IS_INTERNED(Z_STRVAL(ZEND_OP2_LITERAL(opline)))) {
     186           0 :                                                 efree(Z_STRVAL(ZEND_OP2_LITERAL(opline)));
     187             :                                         }
     188           0 :                                         Z_STRVAL(ZEND_OP2_LITERAL(opline)) = ptr;
     189           0 :                                         ptr += Z_STRLEN(ZEND_OP2_LITERAL(opline));
     190             :                                 }
     191           0 :                                 ZEND_OP2_LITERAL(opline).value.str.len = final_length;
     192           0 :                                 next_op = opline + 1;
     193           0 :                                 while (next_op < last_op) {
     194           0 :                                         if (next_op->opcode == ZEND_ADD_STRING) {
     195           0 :                                                 memcpy(ptr, ZEND_OP2_LITERAL(next_op).value.str.val, ZEND_OP2_LITERAL(next_op).value.str.len);
     196           0 :                                                 ptr += ZEND_OP2_LITERAL(next_op).value.str.len;
     197           0 :                                                 literal_dtor(&ZEND_OP2_LITERAL(next_op));
     198             :                                         } else { /* ZEND_ADD_CHAR */
     199           0 :                                                 *ptr = (char)ZEND_OP2_LITERAL(next_op).value.lval;
     200           0 :                                                 ptr++;
     201             :                                         }
     202           0 :                                         MAKE_NOP(next_op);
     203           0 :                                         next_op++;
     204             :                                 }
     205           0 :                                 if (!((ZEND_OPTIMIZER_PASS_5|ZEND_OPTIMIZER_PASS_10) & OPTIMIZATION_LEVEL)) {
     206             :                                         /* NOP removal is disabled => insert JMP over NOPs */
     207           0 :                                         if (last_op-opline >= 3) { /* If we have more than 2 NOPS then JMP over them */
     208           0 :                                                 (opline + 1)->opcode = ZEND_JMP;
     209           0 :                                                 ZEND_OP1(opline + 1).opline_num = last_op - op_array->opcodes; /* that's OK even for ZE2, since opline_num's are resolved in pass 2 later */
     210             :                                         }
     211             :                                 }
     212             :                         }
     213           0 :                         break;
     214             : 
     215             :                 case ZEND_FETCH_CONSTANT:
     216           0 :                         if (ZEND_OP1_TYPE(opline) == IS_UNUSED &&
     217           0 :                                 ZEND_OP2_TYPE(opline) == IS_CONST &&
     218           0 :                                 Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_STRING &&
     219           0 :                                 Z_STRLEN(ZEND_OP2_LITERAL(opline)) == sizeof("__COMPILER_HALT_OFFSET__") - 1 &&
     220           0 :                                 memcmp(Z_STRVAL(ZEND_OP2_LITERAL(opline)), "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__") - 1) == 0) {
     221             :                                 /* substitute __COMPILER_HALT_OFFSET__ constant */
     222           0 :                                 zend_bool orig_in_execution = EG(in_execution);
     223           0 :                                 zend_op_array *orig_op_array = EG(active_op_array);
     224             :                                 zval offset;
     225             : 
     226           0 :                                 EG(in_execution) = 1;
     227           0 :                                 EG(active_op_array) = op_array;
     228           0 :                                 if (zend_get_constant("__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__") - 1, &offset TSRMLS_CC)) {
     229           0 :                                         zend_uint tv = ZEND_RESULT(opline).var;
     230             : 
     231           0 :                                         literal_dtor(&ZEND_OP2_LITERAL(opline));
     232           0 :                                         MAKE_NOP(opline);
     233           0 :                                         replace_tmp_by_const(op_array, opline, tv, &offset TSRMLS_CC);
     234             :                                 }
     235           0 :                                 EG(active_op_array) = orig_op_array;
     236           0 :                                 EG(in_execution) = orig_in_execution;
     237           0 :                                 break;
     238             :                         }
     239             : 
     240           0 :                         if (ZEND_OP1_TYPE(opline) == IS_UNUSED &&
     241           0 :                                 ZEND_OP2_TYPE(opline) == IS_CONST &&
     242           0 :                                 ZEND_OP2_LITERAL(opline).type == IS_STRING) {
     243             :                                 /* substitute persistent constants */
     244           0 :                                 zend_uint tv = ZEND_RESULT(opline).var;
     245             :                                 zval c;
     246             : 
     247           0 :                                 if (!zend_get_persistent_constant(Z_STRVAL(ZEND_OP2_LITERAL(opline)), Z_STRLEN(ZEND_OP2_LITERAL(opline)), &c, 1 TSRMLS_CC)) {
     248           0 :                                         if (!*constants || !zend_optimizer_get_collected_constant(*constants, &ZEND_OP2_LITERAL(opline), &c)) {
     249             :                                                 break;
     250             :                                         }
     251             :                                 }
     252           0 :                                 literal_dtor(&ZEND_OP2_LITERAL(opline));
     253           0 :                                 MAKE_NOP(opline);
     254           0 :                                 replace_tmp_by_const(op_array, opline, tv, &c TSRMLS_CC);
     255             :                         }
     256             : 
     257             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     258             :                         /* class constant */
     259           0 :                         if (ZEND_OP1_TYPE(opline) != IS_UNUSED &&
     260           0 :                             ZEND_OP2_TYPE(opline) == IS_CONST &&
     261           0 :                                 ZEND_OP2_LITERAL(opline).type == IS_STRING) {
     262             : 
     263           0 :                                 zend_class_entry **pce = NULL;
     264             : 
     265           0 :                                 if (ZEND_OP1_TYPE(opline) == IS_CONST &&
     266           0 :                                 ZEND_OP1_LITERAL(opline).type == IS_STRING) {
     267             :                                         /* for A::B */
     268           0 :                                         if (op_array->scope && 
     269           0 :                                                 !strncasecmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)),
     270           0 :                                                 op_array->scope->name, Z_STRLEN(ZEND_OP1_LITERAL(opline)) + 1)) {
     271           0 :                                                 pce = &op_array->scope;
     272             :                                         } else { 
     273           0 :                                                 if (zend_hash_quick_find(EG(class_table), 
     274           0 :                                                                 Z_STRVAL(op_array->literals[opline->op1.constant + 1].constant), 
     275           0 :                                                                 Z_STRLEN(op_array->literals[opline->op1.constant].constant) + 1, 
     276           0 :                                                                 Z_HASH_P(&op_array->literals[opline->op1.constant + 1].constant),
     277           0 :                                                                 (void **)&pce) == FAILURE ||
     278           0 :                                                                 ((*pce)->type == ZEND_INTERNAL_CLASS &&
     279           0 :                                                                  (*pce)->info.internal.module->type != MODULE_PERSISTENT) ||
     280           0 :                                                                 ((*pce)->type == ZEND_USER_CLASS &&
     281           0 :                                                                  ZEND_CE_FILENAME(*pce) != op_array->filename)) {
     282             :                                                         break;
     283             :                                                 }
     284             :                                         }
     285           0 :                                 } else if (op_array->scope &&
     286           0 :                                         ZEND_OP1_TYPE(opline) == IS_VAR &&
     287           0 :                                         (opline - 1)->opcode == ZEND_FETCH_CLASS && 
     288           0 :                                         (ZEND_OP1_TYPE(opline - 1) == IS_UNUSED &&
     289           0 :                                         ((opline - 1)->extended_value & ~ZEND_FETCH_CLASS_NO_AUTOLOAD) == ZEND_FETCH_CLASS_SELF) &&
     290           0 :                                         ZEND_RESULT((opline - 1)).var == ZEND_OP1(opline).var) {
     291             :                                         /* for self::B */
     292           0 :                                         pce = &op_array->scope;
     293             :                                 }
     294             : 
     295           0 :                                 if (pce) {
     296           0 :                                         zend_uint tv = ZEND_RESULT(opline).var;
     297             :                                         zval **c, t;
     298             : 
     299           0 :                                         if (zend_hash_find(&(*pce)->constants_table,
     300           0 :                                                         Z_STRVAL(ZEND_OP2_LITERAL(opline)),
     301           0 :                                                         Z_STRLEN(ZEND_OP2_LITERAL(opline)) + 1,
     302             :                                                         (void **) &c) == SUCCESS) {
     303           0 :                                                 if (ZEND_IS_CONSTANT_TYPE(Z_TYPE_PP(c))) { 
     304           0 :                                                         if (!zend_get_persistent_constant(Z_STRVAL_PP(c), Z_STRLEN_PP(c), &t, 1 TSRMLS_CC) ||
     305           0 :                                                             ZEND_IS_CONSTANT_TYPE(Z_TYPE(t))) {
     306             :                                                                 break;
     307             :                                                         }
     308             :                                                 } else {
     309           0 :                                                         t = **c;
     310             :                                                         zval_copy_ctor(&t);
     311             :                                                 }
     312             : 
     313           0 :                                                 if (ZEND_OP1_TYPE(opline) == IS_CONST) {
     314           0 :                                                         literal_dtor(&ZEND_OP1_LITERAL(opline));
     315             :                                                 } else {
     316           0 :                                                         MAKE_NOP((opline - 1));
     317             :                                                 }
     318           0 :                                                 literal_dtor(&ZEND_OP2_LITERAL(opline));
     319           0 :                                                 MAKE_NOP(opline);
     320           0 :                                                 replace_tmp_by_const(op_array, opline, tv, &t TSRMLS_CC);
     321             :                                         }
     322             :                                 }
     323             :                         }
     324             : #endif
     325           0 :                         break;
     326             : 
     327             :                 case ZEND_DO_FCALL:
     328             :                         /* define("name", scalar); */
     329           0 :                         if (collect_constants &&
     330           0 :                             opline->extended_value == 2 &&
     331           0 :                             ZEND_OP1_TYPE(opline) == IS_CONST &&
     332           0 :                             Z_TYPE(ZEND_OP1_LITERAL(opline)) == IS_STRING &&
     333           0 :                             Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("define")-1 &&
     334           0 :                             zend_binary_strcasecmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)), Z_STRLEN(ZEND_OP1_LITERAL(opline)), "define", sizeof("define")-1) == 0 &&
     335           0 :                             (opline-1)->opcode == ZEND_SEND_VAL &&
     336           0 :                             ZEND_OP1_TYPE(opline-1) == IS_CONST &&
     337           0 :                             (Z_TYPE(ZEND_OP1_LITERAL(opline-1)) <= IS_BOOL ||
     338           0 :                              Z_TYPE(ZEND_OP1_LITERAL(opline-1)) == IS_STRING) &&
     339           0 :                             (opline-2)->opcode == ZEND_SEND_VAL &&
     340           0 :                             ZEND_OP1_TYPE(opline-2) == IS_CONST &&
     341           0 :                             Z_TYPE(ZEND_OP1_LITERAL(opline-2)) == IS_STRING) {
     342           0 :                                 zend_optimizer_collect_constant(constants, &ZEND_OP1_LITERAL(opline-2), &ZEND_OP1_LITERAL(opline-1));
     343           0 :                                 break;
     344             :                         } else {
     345             :                                 /* don't colllect constants after any other function call */
     346           0 :                                 collect_constants = 0;
     347             :                         }
     348             : 
     349             :                         /* pre-evaluate constant functions:
     350             :                            defined(x)
     351             :                            constant(x)
     352             :                            function_exists(x)
     353             :                            is_callable(x)
     354             :                            extension_loaded(x)
     355             :                         */
     356           0 :                         if (opline->extended_value == 1 && (opline - 1)->opcode == ZEND_SEND_VAL &&
     357           0 :                                 ZEND_OP1_TYPE(opline - 1) == IS_CONST && ZEND_OP1_LITERAL(opline - 1).type == IS_STRING &&
     358           0 :                                 ZEND_OP1_TYPE(opline) == IS_CONST && ZEND_OP1_LITERAL(opline).type == IS_STRING) {
     359           0 :                                 if ((Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("function_exists")-1 &&
     360           0 :                                         !memcmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)),
     361             :                                                 "function_exists", sizeof("function_exists")-1)) ||
     362           0 :                                         (Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("is_callable")-1 &&
     363           0 :                                         !memcmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)),
     364             :                                                 "is_callable", sizeof("is_callable")))) {
     365             :                                         zend_internal_function *func;
     366           0 :                                         char *lc_name = zend_str_tolower_dup(
     367           0 :                                                         Z_STRVAL(ZEND_OP1_LITERAL(opline - 1)), Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)));
     368             :                                         
     369           0 :                                         if (zend_hash_find(EG(function_table), lc_name, Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)) + 1,
     370           0 :                                                                 (void *)&func) == SUCCESS &&
     371           0 :                                                         func->type == ZEND_INTERNAL_FUNCTION &&
     372           0 :                                                         func->module->type == MODULE_PERSISTENT) {
     373             :                                                 zval t;
     374           0 :                                                 ZVAL_BOOL(&t, 1);
     375           0 :                                                 if (replace_var_by_const(op_array, opline + 1, ZEND_RESULT(opline).var, &t TSRMLS_CC)) {
     376           0 :                                                         literal_dtor(&ZEND_OP1_LITERAL(opline - 1));
     377           0 :                                                         MAKE_NOP((opline - 1));
     378           0 :                                                         literal_dtor(&ZEND_OP1_LITERAL(opline));
     379           0 :                                                         MAKE_NOP(opline);
     380             :                                                 }
     381             :                                         }
     382           0 :                                         efree(lc_name);
     383           0 :                                 } else if (Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("extension_loaded")-1 &&
     384           0 :                                         !memcmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)),
     385             :                                                 "extension_loaded", sizeof("extension_loaded")-1)) {
     386             :                                         zval t;
     387             :                                         zend_module_entry *m;
     388           0 :                                         char *lc_name = zend_str_tolower_dup(
     389           0 :                                                         Z_STRVAL(ZEND_OP1_LITERAL(opline - 1)), Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)));
     390           0 :                                         int found = zend_hash_find(&module_registry,
     391           0 :                                                         lc_name, Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)) + 1, (void *)&m) == SUCCESS;
     392             : 
     393           0 :                                         efree(lc_name);
     394           0 :                                         if (!found) {
     395           0 :                                                 if (!PG(enable_dl)) {
     396           0 :                                                         break;
     397             :                                                 } else {
     398           0 :                                                         ZVAL_BOOL(&t, 0);
     399             :                                                 }
     400             :                                         } else {
     401           0 :                                                 if (m->type == MODULE_PERSISTENT) {
     402           0 :                                                         ZVAL_BOOL(&t, 1);
     403             :                                                 } else {
     404           0 :                                                         break;
     405             :                                                 }
     406             :                                         } 
     407             : 
     408           0 :                                         if (replace_var_by_const(op_array, opline + 1, ZEND_RESULT(opline).var, &t TSRMLS_CC)) {
     409           0 :                                                 literal_dtor(&ZEND_OP1_LITERAL(opline - 1));
     410           0 :                                                 MAKE_NOP((opline - 1));
     411           0 :                                                 literal_dtor(&ZEND_OP1_LITERAL(opline));
     412           0 :                                                 MAKE_NOP(opline);
     413             :                                         }
     414           0 :                                 } else if (Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("defined")-1 &&
     415           0 :                                         !memcmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)),
     416             :                                                 "defined", sizeof("defined")-1)) {
     417             :                                         zval t;
     418             : 
     419           0 :                                         if (zend_get_persistent_constant(Z_STRVAL(ZEND_OP1_LITERAL(opline - 1)),
     420           0 :                                                 Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)), &t, 0 TSRMLS_CC)) {
     421             : 
     422           0 :                                                 ZVAL_BOOL(&t, 1);
     423           0 :                                                 if (replace_var_by_const(op_array, opline + 1, ZEND_RESULT(opline).var, &t TSRMLS_CC)) {
     424           0 :                                                         literal_dtor(&ZEND_OP1_LITERAL(opline - 1));
     425           0 :                                                         MAKE_NOP((opline - 1));
     426           0 :                                                         literal_dtor(&ZEND_OP1_LITERAL(opline));
     427           0 :                                                         MAKE_NOP(opline);
     428             :                                                 }
     429             :                                         }
     430           0 :                                 } else if (Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("constant")-1 &&
     431           0 :                                         !memcmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)),
     432             :                                                 "constant", sizeof("constant")-1)) {
     433             :                                         zval t;
     434             :                                         
     435           0 :                                         if (zend_get_persistent_constant(Z_STRVAL(ZEND_OP1_LITERAL(opline - 1)),
     436           0 :                                                 Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)), &t, 1 TSRMLS_CC)) {
     437           0 :                                                 if (replace_var_by_const(op_array, opline + 1, ZEND_RESULT(opline).var, &t TSRMLS_CC)) {
     438           0 :                                                         literal_dtor(&ZEND_OP1_LITERAL(opline - 1));
     439           0 :                                                         MAKE_NOP((opline - 1));
     440           0 :                                                         literal_dtor(&ZEND_OP1_LITERAL(opline));
     441           0 :                                                         MAKE_NOP(opline);
     442             :                                                 }
     443             :                                         }
     444           0 :                                 } else if (Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("strlen")-1 &&
     445           0 :                                         !memcmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)),
     446             :                                                 "strlen", sizeof("strlen")-1)) {
     447             :                                         zval t;
     448             : 
     449           0 :                                         ZVAL_LONG(&t, Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)));
     450           0 :                                         if (replace_var_by_const(op_array, opline + 1, ZEND_RESULT(opline).var, &t TSRMLS_CC)) {
     451           0 :                                                 literal_dtor(&ZEND_OP1_LITERAL(opline - 1));
     452           0 :                                                 MAKE_NOP((opline - 1));
     453           0 :                                                 literal_dtor(&ZEND_OP1_LITERAL(opline));
     454           0 :                                                 MAKE_NOP(opline);
     455             :                                         }
     456             :                                 }
     457             :                         }                       
     458           0 :                         break;
     459             : #if ZEND_EXTENSION_API_NO > PHP_5_2_X_API_NO
     460             :                 case ZEND_DECLARE_CONST:
     461           0 :                         if (collect_constants &&
     462           0 :                             Z_TYPE(ZEND_OP1_LITERAL(opline)) == IS_STRING &&
     463           0 :                             (Z_TYPE(ZEND_OP2_LITERAL(opline)) <= IS_BOOL ||
     464           0 :                              Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_STRING)) {
     465           0 :                                 zend_optimizer_collect_constant(constants, &ZEND_OP1_LITERAL(opline), &ZEND_OP2_LITERAL(opline));
     466             :                         }
     467           0 :                         break;
     468             : #endif
     469             : 
     470             :                 case ZEND_RETURN:
     471             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     472             :                 case ZEND_RETURN_BY_REF:
     473             : #endif
     474             : #if ZEND_EXTENSION_API_NO > PHP_5_4_X_API_NO
     475             :                 case ZEND_GENERATOR_RETURN:
     476             : #endif
     477             :                 case ZEND_EXIT:
     478             :                 case ZEND_THROW:
     479             :                 case ZEND_CATCH:
     480             :                 case ZEND_BRK:
     481             :                 case ZEND_CONT:
     482             : #if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO
     483             :                 case ZEND_GOTO:
     484             : #endif
     485             : #if ZEND_EXTENSION_API_NO > PHP_5_4_X_API_NO
     486             :                 case ZEND_FAST_CALL:
     487             :                 case ZEND_FAST_RET:
     488             : #endif
     489             :                 case ZEND_JMP:
     490             :                 case ZEND_JMPZNZ:
     491             :                 case ZEND_JMPZ:
     492             :                 case ZEND_JMPNZ:
     493             :                 case ZEND_JMPZ_EX:
     494             :                 case ZEND_JMPNZ_EX:
     495             :                 case ZEND_FE_RESET:
     496             :                 case ZEND_FE_FETCH:
     497             :                 case ZEND_NEW:
     498             :                 case ZEND_DO_FCALL_BY_NAME:
     499             : #if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO
     500             :                 case ZEND_JMP_SET:
     501             : #endif
     502             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     503             :                 case ZEND_JMP_SET_VAR:
     504             : #endif
     505           0 :                         collect_constants = 0;
     506           0 :                         break;
     507             : 
     508             : #if ZEND_EXTENSION_API_NO >= PHP_5_5_X_API_NO
     509             :                 case ZEND_FETCH_R:
     510             :                 case ZEND_FETCH_W:
     511             :                 case ZEND_FETCH_RW:
     512             :                 case ZEND_FETCH_FUNC_ARG:
     513             :                 case ZEND_FETCH_IS:
     514             :                 case ZEND_FETCH_UNSET:
     515           0 :                         if (opline != op_array->opcodes &&
     516           0 :                             (opline-1)->opcode == ZEND_BEGIN_SILENCE &&
     517           0 :                             (opline->extended_value & ZEND_FETCH_TYPE_MASK) == ZEND_FETCH_LOCAL &&
     518           0 :                                 opline->op1_type == IS_CONST &&
     519           0 :                             opline->op2_type == IS_UNUSED &&
     520           0 :                             Z_TYPE(ZEND_OP1_LITERAL(opline)) == IS_STRING &&
     521           0 :                             (Z_STRLEN(ZEND_OP1_LITERAL(opline)) != sizeof("this")-1 ||
     522           0 :                              memcmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)), "this", sizeof("this") - 1) != 0)) {
     523             : 
     524           0 :                             int var = opline->result.var;
     525           0 :                             int level = 0;
     526           0 :                                 zend_op *op = opline + 1;
     527           0 :                                 zend_op *use = NULL;
     528             : 
     529           0 :                                 while (op < end) {
     530           0 :                                         if (op->opcode == ZEND_BEGIN_SILENCE) {
     531           0 :                                                 level++;
     532           0 :                                         } else if (op->opcode == ZEND_END_SILENCE) {
     533           0 :                                                 if (level == 0) {
     534           0 :                                                         break;
     535             :                                                 } else {
     536           0 :                                                         level--;
     537             :                                                 }
     538             :                                         }
     539           0 :                                         if (op->op1_type == IS_VAR && op->op1.var == var) {
     540           0 :                                                 if (use) {
     541             :                                                         /* used more than once */
     542           0 :                                                         use = NULL;
     543           0 :                                                         break;
     544             :                                                 }
     545           0 :                                                 use = op;
     546           0 :                                         } else if (op->op2_type == IS_VAR && op->op2.var == var) {
     547           0 :                                                 if (use) {
     548             :                                                         /* used more than once */
     549           0 :                                                         use = NULL;
     550           0 :                                                         break;
     551             :                                                 }
     552           0 :                                                 use = op;
     553             :                                         }
     554           0 :                                         op++;
     555             :                                 }
     556           0 :                                 if (use) {
     557           0 :                                         if (use->op1_type == IS_VAR && use->op1.var == var) {
     558           0 :                                                 use->op1_type = IS_CV;
     559           0 :                                                 use->op1.var = zend_optimizer_lookup_cv(op_array,
     560           0 :                                                         Z_STRVAL(ZEND_OP1_LITERAL(opline)),
     561           0 :                                                         Z_STRLEN(ZEND_OP1_LITERAL(opline)));
     562           0 :                                                 MAKE_NOP(opline);
     563           0 :                                         } else if (use->op2_type == IS_VAR && use->op2.var == var) {
     564           0 :                                                 use->op2_type = IS_CV;
     565           0 :                                                 use->op2.var = zend_optimizer_lookup_cv(op_array,
     566           0 :                                                         Z_STRVAL(ZEND_OP1_LITERAL(opline)),
     567           0 :                                                         Z_STRLEN(ZEND_OP1_LITERAL(opline)));
     568           0 :                                                 MAKE_NOP(opline);
     569             :                                         }
     570             :                                 }
     571             :                         }
     572             :                         break;
     573             : #endif
     574             :                 
     575             :                 }
     576           0 :                 opline++;
     577           0 :                 i++;
     578             :         }
     579             : }

Generated by: LCOV version 1.10

Generated at Wed, 16 Apr 2014 12:48:02 +0000 (8 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.