zend_jit_helpers.c 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend JIT |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | https://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Dmitry Stogov <dmitry@php.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. #include "Zend/zend_API.h"
  19. static ZEND_COLD void undef_result_after_exception(void) {
  20. const zend_op *opline = EG(opline_before_exception);
  21. ZEND_ASSERT(EG(exception));
  22. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  23. zend_execute_data *execute_data = EG(current_execute_data);
  24. ZVAL_UNDEF(EX_VAR(opline->result.var));
  25. }
  26. }
  27. static ZEND_COLD void zend_jit_illegal_offset(void)
  28. {
  29. zend_type_error("Illegal offset type");
  30. }
  31. static ZEND_COLD void zend_jit_illegal_string_offset(zval *offset)
  32. {
  33. zend_type_error("Cannot access offset of type %s on string", zend_zval_type_name(offset));
  34. }
  35. static zend_never_inline zend_function* ZEND_FASTCALL _zend_jit_init_func_run_time_cache(const zend_op_array *op_array) /* {{{ */
  36. {
  37. void **run_time_cache;
  38. run_time_cache = zend_arena_alloc(&CG(arena), op_array->cache_size);
  39. memset(run_time_cache, 0, op_array->cache_size);
  40. ZEND_MAP_PTR_SET(op_array->run_time_cache, run_time_cache);
  41. return (zend_function*)op_array;
  42. }
  43. /* }}} */
  44. static zend_never_inline zend_op_array* ZEND_FASTCALL zend_jit_init_func_run_time_cache_helper(zend_op_array *op_array) /* {{{ */
  45. {
  46. void **run_time_cache;
  47. if (!RUN_TIME_CACHE(op_array)) {
  48. run_time_cache = zend_arena_alloc(&CG(arena), op_array->cache_size);
  49. memset(run_time_cache, 0, op_array->cache_size);
  50. ZEND_MAP_PTR_SET(op_array->run_time_cache, run_time_cache);
  51. }
  52. return op_array;
  53. }
  54. /* }}} */
  55. static zend_function* ZEND_FASTCALL zend_jit_find_func_helper(zend_string *name, void **cache_slot)
  56. {
  57. zval *func = zend_hash_find_known_hash(EG(function_table), name);
  58. zend_function *fbc;
  59. if (UNEXPECTED(func == NULL)) {
  60. return NULL;
  61. }
  62. fbc = Z_FUNC_P(func);
  63. if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
  64. fbc = _zend_jit_init_func_run_time_cache(&fbc->op_array);
  65. }
  66. *cache_slot = fbc;
  67. return fbc;
  68. }
  69. static zend_function* ZEND_FASTCALL zend_jit_find_ns_func_helper(zval *func_name, void **cache_slot)
  70. {
  71. zval *func = zend_hash_find_known_hash(EG(function_table), Z_STR_P(func_name + 1));
  72. zend_function *fbc;
  73. if (func == NULL) {
  74. func = zend_hash_find_known_hash(EG(function_table), Z_STR_P(func_name + 2));
  75. if (UNEXPECTED(func == NULL)) {
  76. return NULL;
  77. }
  78. }
  79. fbc = Z_FUNC_P(func);
  80. if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
  81. fbc = _zend_jit_init_func_run_time_cache(&fbc->op_array);
  82. }
  83. *cache_slot = fbc;
  84. return fbc;
  85. }
  86. static ZEND_COLD void ZEND_FASTCALL zend_jit_invalid_method_call(zval *object)
  87. {
  88. zend_execute_data *execute_data = EG(current_execute_data);
  89. const zend_op *opline = EX(opline);
  90. zval *function_name = function_name = RT_CONSTANT(opline, opline->op2);;
  91. if (Z_TYPE_P(object) == IS_UNDEF && opline->op1_type == IS_CV) {
  92. zend_string *cv = EX(func)->op_array.vars[EX_VAR_TO_NUM(opline->op1.var)];
  93. zend_error(E_WARNING, "Undefined variable $%s", ZSTR_VAL(cv));
  94. if (UNEXPECTED(EG(exception) != NULL)) {
  95. return;
  96. }
  97. object = &EG(uninitialized_zval);
  98. }
  99. zend_throw_error(NULL, "Call to a member function %s() on %s",
  100. Z_STRVAL_P(function_name), zend_zval_type_name(object));
  101. }
  102. static ZEND_COLD void ZEND_FASTCALL zend_jit_invalid_method_call_tmp(zval *object)
  103. {
  104. zend_execute_data *execute_data = EG(current_execute_data);
  105. const zend_op *opline = EX(opline);
  106. zend_jit_invalid_method_call(object);
  107. zval_ptr_dtor_nogc(EX_VAR(opline->op1.var));
  108. }
  109. static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_undefined_method(const zend_class_entry *ce, const zend_string *method)
  110. {
  111. zend_throw_error(NULL, "Call to undefined method %s::%s()", ZSTR_VAL(ce->name), ZSTR_VAL(method));
  112. }
  113. static void ZEND_FASTCALL zend_jit_unref_helper(zval *zv)
  114. {
  115. zend_reference *ref;
  116. ZEND_ASSERT(Z_ISREF_P(zv));
  117. ref = Z_REF_P(zv);
  118. ZVAL_COPY_VALUE(zv, &ref->val);
  119. if (GC_DELREF(ref) == 0) {
  120. efree_size(ref, sizeof(zend_reference));
  121. } else {
  122. Z_TRY_ADDREF_P(zv);
  123. }
  124. }
  125. static zend_function* ZEND_FASTCALL zend_jit_find_method_helper(zend_object *obj, zval *function_name, zend_object **obj_ptr)
  126. {
  127. zend_execute_data *execute_data = EG(current_execute_data);
  128. const zend_op *opline = EX(opline);
  129. zend_class_entry *called_scope = obj->ce;
  130. zend_function *fbc;
  131. fbc = obj->handlers->get_method(obj_ptr, Z_STR_P(function_name), function_name + 1);
  132. if (UNEXPECTED(fbc == NULL)) {
  133. if (EXPECTED(!EG(exception))) {
  134. zend_undefined_method(called_scope, Z_STR_P(function_name));
  135. }
  136. return NULL;
  137. }
  138. if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
  139. zend_init_func_run_time_cache(&fbc->op_array);
  140. }
  141. if (UNEXPECTED(obj != *obj_ptr)) {
  142. return fbc;
  143. }
  144. if (EXPECTED(!(fbc->common.fn_flags & (ZEND_ACC_CALL_VIA_TRAMPOLINE|ZEND_ACC_NEVER_CACHE)))) {
  145. CACHE_POLYMORPHIC_PTR(opline->result.num, called_scope, fbc);
  146. }
  147. return fbc;
  148. }
  149. static zend_function* ZEND_FASTCALL zend_jit_find_method_tmp_helper(zend_object *obj, zval *function_name, zend_object **obj_ptr)
  150. {
  151. zend_function *fbc;
  152. fbc = zend_jit_find_method_helper(obj, function_name, obj_ptr);
  153. if (!fbc) {
  154. if (GC_DELREF(obj) == 0) {
  155. zend_objects_store_del(obj);
  156. }
  157. } else if (obj != *obj_ptr) {
  158. GC_ADDREF(*obj_ptr);
  159. if (GC_DELREF(obj) == 0) {
  160. zend_objects_store_del(obj);
  161. }
  162. }
  163. return fbc;
  164. }
  165. static zend_execute_data* ZEND_FASTCALL zend_jit_push_static_metod_call_frame(zend_object *obj, zend_function *fbc, uint32_t num_args)
  166. {
  167. zend_class_entry *scope = obj->ce;
  168. return zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION, fbc, num_args, scope);
  169. }
  170. static zend_execute_data* ZEND_FASTCALL zend_jit_push_static_metod_call_frame_tmp(zend_object *obj, zend_function *fbc, uint32_t num_args)
  171. {
  172. zend_class_entry *scope = obj->ce;
  173. if (GC_DELREF(obj) == 0) {
  174. zend_objects_store_del(obj);
  175. if (UNEXPECTED(EG(exception))) {
  176. return NULL;
  177. }
  178. }
  179. return zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION, fbc, num_args, scope);
  180. }
  181. static zend_execute_data* ZEND_FASTCALL zend_jit_extend_stack_helper(uint32_t used_stack, zend_function *fbc)
  182. {
  183. zend_execute_data *call = (zend_execute_data*)zend_vm_stack_extend(used_stack);
  184. call->func = fbc;
  185. ZEND_CALL_INFO(call) = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_ALLOCATED;
  186. return call;
  187. }
  188. static zend_execute_data* ZEND_FASTCALL zend_jit_int_extend_stack_helper(uint32_t used_stack)
  189. {
  190. zend_execute_data *call = (zend_execute_data*)zend_vm_stack_extend(used_stack);
  191. ZEND_CALL_INFO(call) = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_ALLOCATED;
  192. return call;
  193. }
  194. static zval* ZEND_FASTCALL zend_jit_symtable_find(HashTable *ht, zend_string *str)
  195. {
  196. zend_ulong idx;
  197. register const char *tmp = str->val;
  198. do {
  199. if (*tmp > '9') {
  200. break;
  201. } else if (*tmp < '0') {
  202. if (*tmp != '-') {
  203. break;
  204. }
  205. tmp++;
  206. if (*tmp > '9' || *tmp < '0') {
  207. break;
  208. }
  209. }
  210. if (_zend_handle_numeric_str_ex(str->val, str->len, &idx)) {
  211. return zend_hash_index_find(ht, idx);
  212. }
  213. } while (0);
  214. return zend_hash_find(ht, str);
  215. }
  216. static zval* ZEND_FASTCALL zend_jit_hash_index_lookup_rw_no_packed(HashTable *ht, zend_long idx)
  217. {
  218. zval *retval = NULL;
  219. if (!HT_IS_PACKED(ht)) {
  220. retval = _zend_hash_index_find(ht, idx);
  221. }
  222. if (!retval) {
  223. retval = zend_undefined_offset_write(ht, idx);
  224. }
  225. return retval;
  226. }
  227. static zval* ZEND_FASTCALL zend_jit_hash_index_lookup_rw(HashTable *ht, zend_long idx)
  228. {
  229. zval *retval = zend_hash_index_find(ht, idx);
  230. if (!retval) {
  231. retval = zend_undefined_offset_write(ht, idx);
  232. }
  233. return retval;
  234. }
  235. static zval* ZEND_FASTCALL zend_jit_hash_lookup_rw(HashTable *ht, zend_string *str)
  236. {
  237. zval *retval = zend_hash_find_known_hash(ht, str);
  238. if (!retval) {
  239. /* Key may be released while throwing the undefined index warning. */
  240. retval = zend_undefined_index_write(ht, str);
  241. }
  242. return retval;
  243. }
  244. static zval* ZEND_FASTCALL zend_jit_symtable_lookup_rw(HashTable *ht, zend_string *str)
  245. {
  246. zend_ulong idx;
  247. register const char *tmp = str->val;
  248. zval *retval;
  249. do {
  250. if (*tmp > '9') {
  251. break;
  252. } else if (*tmp < '0') {
  253. if (*tmp != '-') {
  254. break;
  255. }
  256. tmp++;
  257. if (*tmp > '9' || *tmp < '0') {
  258. break;
  259. }
  260. }
  261. if (_zend_handle_numeric_str_ex(str->val, str->len, &idx)) {
  262. retval = zend_hash_index_find(ht, idx);
  263. if (!retval) {
  264. retval = zend_undefined_offset_write(ht, idx);
  265. }
  266. return retval;
  267. }
  268. } while (0);
  269. retval = zend_hash_find(ht, str);
  270. if (!retval) {
  271. /* Key may be released while throwing the undefined index warning. */
  272. retval = zend_undefined_index_write(ht, str);
  273. }
  274. return retval;
  275. }
  276. static zval* ZEND_FASTCALL zend_jit_symtable_lookup_w(HashTable *ht, zend_string *str)
  277. {
  278. zend_ulong idx;
  279. register const char *tmp = str->val;
  280. do {
  281. if (*tmp > '9') {
  282. break;
  283. } else if (*tmp < '0') {
  284. if (*tmp != '-') {
  285. break;
  286. }
  287. tmp++;
  288. if (*tmp > '9' || *tmp < '0') {
  289. break;
  290. }
  291. }
  292. if (_zend_handle_numeric_str_ex(str->val, str->len, &idx)) {
  293. return zend_hash_index_lookup(ht, idx);
  294. }
  295. } while (0);
  296. return zend_hash_lookup(ht, str);
  297. }
  298. static int ZEND_FASTCALL zend_jit_undefined_op_helper(uint32_t var)
  299. {
  300. const zend_execute_data *execute_data = EG(current_execute_data);
  301. zend_string *cv = EX(func)->op_array.vars[EX_VAR_TO_NUM(var)];
  302. zend_error(E_WARNING, "Undefined variable $%s", ZSTR_VAL(cv));
  303. return EG(exception) == NULL;
  304. }
  305. static int ZEND_FASTCALL zend_jit_undefined_op_helper_write(HashTable *ht, uint32_t var)
  306. {
  307. const zend_execute_data *execute_data = EG(current_execute_data);
  308. zend_string *cv = EX(func)->op_array.vars[EX_VAR_TO_NUM(var)];
  309. /* The array may be destroyed while throwing the notice.
  310. * Temporarily increase the refcount to detect this situation. */
  311. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
  312. GC_ADDREF(ht);
  313. }
  314. zend_error(E_WARNING, "Undefined variable $%s", ZSTR_VAL(cv));
  315. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
  316. if (!GC_REFCOUNT(ht)) {
  317. zend_array_destroy(ht);
  318. }
  319. return 0;
  320. }
  321. return EG(exception) == NULL;
  322. }
  323. static void ZEND_FASTCALL zend_jit_fetch_dim_r_helper(zend_array *ht, zval *dim, zval *result)
  324. {
  325. zend_ulong hval;
  326. zend_string *offset_key;
  327. zval *retval;
  328. zend_execute_data *execute_data;
  329. const zend_op *opline;
  330. if (Z_TYPE_P(dim) == IS_REFERENCE) {
  331. dim = Z_REFVAL_P(dim);
  332. }
  333. switch (Z_TYPE_P(dim)) {
  334. case IS_LONG:
  335. hval = Z_LVAL_P(dim);
  336. goto num_index;
  337. case IS_STRING:
  338. offset_key = Z_STR_P(dim);
  339. goto str_index;
  340. case IS_UNDEF:
  341. /* The array may be destroyed while throwing the notice.
  342. * Temporarily increase the refcount to detect this situation. */
  343. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
  344. GC_ADDREF(ht);
  345. }
  346. execute_data = EG(current_execute_data);
  347. opline = EX(opline);
  348. zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
  349. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
  350. zend_array_destroy(ht);
  351. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  352. if (EG(exception)) {
  353. ZVAL_UNDEF(EX_VAR(opline->result.var));
  354. } else {
  355. ZVAL_NULL(EX_VAR(opline->result.var));
  356. }
  357. }
  358. return;
  359. }
  360. if (EG(exception)) {
  361. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  362. ZVAL_UNDEF(EX_VAR(opline->result.var));
  363. }
  364. return;
  365. }
  366. ZEND_FALLTHROUGH;
  367. case IS_NULL:
  368. offset_key = ZSTR_EMPTY_ALLOC();
  369. goto str_index;
  370. case IS_DOUBLE:
  371. hval = zend_dval_to_lval(Z_DVAL_P(dim));
  372. if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
  373. /* The array may be destroyed while throwing the notice.
  374. * Temporarily increase the refcount to detect this situation. */
  375. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
  376. GC_ADDREF(ht);
  377. }
  378. execute_data = EG(current_execute_data);
  379. opline = EX(opline);
  380. zend_incompatible_double_to_long_error(Z_DVAL_P(dim));
  381. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
  382. zend_array_destroy(ht);
  383. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  384. if (EG(exception)) {
  385. ZVAL_UNDEF(EX_VAR(opline->result.var));
  386. } else {
  387. ZVAL_NULL(EX_VAR(opline->result.var));
  388. }
  389. }
  390. return;
  391. }
  392. if (EG(exception)) {
  393. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  394. ZVAL_UNDEF(EX_VAR(opline->result.var));
  395. }
  396. return;
  397. }
  398. }
  399. goto num_index;
  400. case IS_RESOURCE:
  401. /* The array may be destroyed while throwing the notice.
  402. * Temporarily increase the refcount to detect this situation. */
  403. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
  404. GC_ADDREF(ht);
  405. }
  406. execute_data = EG(current_execute_data);
  407. opline = EX(opline);
  408. zend_use_resource_as_offset(dim);
  409. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
  410. zend_array_destroy(ht);
  411. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  412. if (EG(exception)) {
  413. ZVAL_UNDEF(EX_VAR(opline->result.var));
  414. } else {
  415. ZVAL_NULL(EX_VAR(opline->result.var));
  416. }
  417. }
  418. return;
  419. }
  420. if (EG(exception)) {
  421. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  422. ZVAL_UNDEF(EX_VAR(opline->result.var));
  423. }
  424. return;
  425. }
  426. hval = Z_RES_HANDLE_P(dim);
  427. goto num_index;
  428. case IS_FALSE:
  429. hval = 0;
  430. goto num_index;
  431. case IS_TRUE:
  432. hval = 1;
  433. goto num_index;
  434. default:
  435. zend_jit_illegal_offset();
  436. undef_result_after_exception();
  437. return;
  438. }
  439. str_index:
  440. if (ZEND_HANDLE_NUMERIC(offset_key, hval)) {
  441. goto num_index;
  442. }
  443. retval = zend_hash_find(ht, offset_key);
  444. if (!retval) {
  445. zend_error(E_WARNING, "Undefined array key \"%s\"", ZSTR_VAL(offset_key));
  446. ZVAL_NULL(result);
  447. return;
  448. }
  449. ZVAL_COPY_DEREF(result, retval);
  450. return;
  451. num_index:
  452. ZEND_HASH_INDEX_FIND(ht, hval, retval, num_undef);
  453. ZVAL_COPY_DEREF(result, retval);
  454. return;
  455. num_undef:
  456. zend_error(E_WARNING, "Undefined array key " ZEND_LONG_FMT, hval);
  457. ZVAL_NULL(result);
  458. }
  459. static void ZEND_FASTCALL zend_jit_fetch_dim_is_helper(zend_array *ht, zval *dim, zval *result)
  460. {
  461. zend_ulong hval;
  462. zend_string *offset_key;
  463. zval *retval;
  464. zend_execute_data *execute_data;
  465. const zend_op *opline;
  466. if (Z_TYPE_P(dim) == IS_REFERENCE) {
  467. dim = Z_REFVAL_P(dim);
  468. }
  469. switch (Z_TYPE_P(dim)) {
  470. case IS_LONG:
  471. hval = Z_LVAL_P(dim);
  472. goto num_index;
  473. case IS_STRING:
  474. offset_key = Z_STR_P(dim);
  475. goto str_index;
  476. case IS_UNDEF:
  477. /* The array may be destroyed while throwing the notice.
  478. * Temporarily increase the refcount to detect this situation. */
  479. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
  480. GC_ADDREF(ht);
  481. }
  482. execute_data = EG(current_execute_data);
  483. opline = EX(opline);
  484. zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
  485. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
  486. zend_array_destroy(ht);
  487. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  488. if (EG(exception)) {
  489. ZVAL_UNDEF(EX_VAR(opline->result.var));
  490. } else {
  491. ZVAL_NULL(EX_VAR(opline->result.var));
  492. }
  493. }
  494. return;
  495. }
  496. if (EG(exception)) {
  497. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  498. ZVAL_UNDEF(EX_VAR(opline->result.var));
  499. }
  500. return;
  501. }
  502. ZEND_FALLTHROUGH;
  503. case IS_NULL:
  504. offset_key = ZSTR_EMPTY_ALLOC();
  505. goto str_index;
  506. case IS_DOUBLE:
  507. hval = zend_dval_to_lval(Z_DVAL_P(dim));
  508. if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
  509. /* The array may be destroyed while throwing the notice.
  510. * Temporarily increase the refcount to detect this situation. */
  511. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
  512. GC_ADDREF(ht);
  513. }
  514. execute_data = EG(current_execute_data);
  515. opline = EX(opline);
  516. zend_incompatible_double_to_long_error(Z_DVAL_P(dim));
  517. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
  518. zend_array_destroy(ht);
  519. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  520. if (EG(exception)) {
  521. ZVAL_UNDEF(EX_VAR(opline->result.var));
  522. } else {
  523. ZVAL_NULL(EX_VAR(opline->result.var));
  524. }
  525. }
  526. return;
  527. }
  528. if (EG(exception)) {
  529. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  530. ZVAL_UNDEF(EX_VAR(opline->result.var));
  531. }
  532. return;
  533. }
  534. }
  535. goto num_index;
  536. case IS_RESOURCE:
  537. /* The array may be destroyed while throwing the notice.
  538. * Temporarily increase the refcount to detect this situation. */
  539. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
  540. GC_ADDREF(ht);
  541. }
  542. execute_data = EG(current_execute_data);
  543. opline = EX(opline);
  544. zend_use_resource_as_offset(dim);
  545. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
  546. zend_array_destroy(ht);
  547. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  548. if (EG(exception)) {
  549. ZVAL_UNDEF(EX_VAR(opline->result.var));
  550. } else {
  551. ZVAL_NULL(EX_VAR(opline->result.var));
  552. }
  553. }
  554. return;
  555. }
  556. if (EG(exception)) {
  557. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  558. ZVAL_UNDEF(EX_VAR(opline->result.var));
  559. }
  560. return;
  561. }
  562. hval = Z_RES_HANDLE_P(dim);
  563. goto num_index;
  564. case IS_FALSE:
  565. hval = 0;
  566. goto num_index;
  567. case IS_TRUE:
  568. hval = 1;
  569. goto num_index;
  570. default:
  571. zend_jit_illegal_offset();
  572. undef_result_after_exception();
  573. return;
  574. }
  575. str_index:
  576. if (ZEND_HANDLE_NUMERIC(offset_key, hval)) {
  577. goto num_index;
  578. }
  579. retval = zend_hash_find(ht, offset_key);
  580. if (!retval) {
  581. ZVAL_NULL(result);
  582. return;
  583. }
  584. ZVAL_COPY_DEREF(result, retval);
  585. return;
  586. num_index:
  587. ZEND_HASH_INDEX_FIND(ht, hval, retval, num_undef);
  588. ZVAL_COPY_DEREF(result, retval);
  589. return;
  590. num_undef:
  591. ZVAL_NULL(result);
  592. }
  593. static int ZEND_FASTCALL zend_jit_fetch_dim_isset_helper(zend_array *ht, zval *dim)
  594. {
  595. zend_ulong hval;
  596. zend_string *offset_key;
  597. zval *retval;
  598. if (Z_TYPE_P(dim) == IS_REFERENCE) {
  599. dim = Z_REFVAL_P(dim);
  600. }
  601. switch (Z_TYPE_P(dim)) {
  602. case IS_LONG:
  603. hval = Z_LVAL_P(dim);
  604. goto num_index;
  605. case IS_STRING:
  606. offset_key = Z_STR_P(dim);
  607. goto str_index;
  608. case IS_UNDEF:
  609. /* The array may be destroyed while throwing the notice.
  610. * Temporarily increase the refcount to detect this situation. */
  611. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
  612. GC_ADDREF(ht);
  613. }
  614. zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
  615. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
  616. zend_array_destroy(ht);
  617. return 0;
  618. }
  619. if (EG(exception)) {
  620. return 0;
  621. }
  622. ZEND_FALLTHROUGH;
  623. case IS_NULL:
  624. offset_key = ZSTR_EMPTY_ALLOC();
  625. goto str_index;
  626. case IS_DOUBLE:
  627. hval = zend_dval_to_lval(Z_DVAL_P(dim));
  628. if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
  629. /* The array may be destroyed while throwing the notice.
  630. * Temporarily increase the refcount to detect this situation. */
  631. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
  632. GC_ADDREF(ht);
  633. }
  634. zend_incompatible_double_to_long_error(Z_DVAL_P(dim));
  635. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
  636. zend_array_destroy(ht);
  637. return 0;
  638. }
  639. if (EG(exception)) {
  640. return 0;
  641. }
  642. }
  643. goto num_index;
  644. case IS_RESOURCE:
  645. /* The array may be destroyed while throwing the notice.
  646. * Temporarily increase the refcount to detect this situation. */
  647. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
  648. GC_ADDREF(ht);
  649. }
  650. zend_use_resource_as_offset(dim);
  651. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
  652. zend_array_destroy(ht);
  653. return 0;
  654. }
  655. if (EG(exception)) {
  656. return 0;
  657. }
  658. hval = Z_RES_HANDLE_P(dim);
  659. goto num_index;
  660. case IS_FALSE:
  661. hval = 0;
  662. goto num_index;
  663. case IS_TRUE:
  664. hval = 1;
  665. goto num_index;
  666. default:
  667. zend_type_error("Illegal offset type in isset or empty");
  668. return 0;
  669. }
  670. str_index:
  671. if (ZEND_HANDLE_NUMERIC(offset_key, hval)) {
  672. goto num_index;
  673. }
  674. retval = zend_hash_find(ht, offset_key);
  675. if (!retval) {
  676. return 0;
  677. }
  678. if (UNEXPECTED(Z_TYPE_P(retval) == IS_REFERENCE)) {
  679. retval = Z_REFVAL_P(retval);
  680. }
  681. return Z_TYPE_P(retval) > IS_NULL;
  682. num_index:
  683. ZEND_HASH_INDEX_FIND(ht, hval, retval, num_undef);
  684. if (UNEXPECTED(Z_TYPE_P(retval) == IS_REFERENCE)) {
  685. retval = Z_REFVAL_P(retval);
  686. }
  687. return (Z_TYPE_P(retval) > IS_NULL);
  688. num_undef:
  689. return 0;
  690. }
  691. static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *dim)
  692. {
  693. zend_ulong hval;
  694. zend_string *offset_key;
  695. zval *retval;
  696. zend_execute_data *execute_data;
  697. const zend_op *opline;
  698. if (Z_TYPE_P(dim) == IS_REFERENCE) {
  699. dim = Z_REFVAL_P(dim);
  700. }
  701. switch (Z_TYPE_P(dim)) {
  702. case IS_LONG:
  703. hval = Z_LVAL_P(dim);
  704. goto num_index;
  705. case IS_STRING:
  706. offset_key = Z_STR_P(dim);
  707. goto str_index;
  708. case IS_UNDEF:
  709. execute_data = EG(current_execute_data);
  710. opline = EX(opline);
  711. if (UNEXPECTED(opline->opcode == ZEND_HANDLE_EXCEPTION)) {
  712. opline = EG(opline_before_exception);
  713. }
  714. if (!zend_jit_undefined_op_helper_write(ht, opline->op2.var)) {
  715. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  716. if (EG(exception)) {
  717. ZVAL_UNDEF(EX_VAR(opline->result.var));
  718. } else {
  719. ZVAL_NULL(EX_VAR(opline->result.var));
  720. }
  721. }
  722. return NULL;
  723. }
  724. ZEND_FALLTHROUGH;
  725. case IS_NULL:
  726. offset_key = ZSTR_EMPTY_ALLOC();
  727. goto str_index;
  728. case IS_DOUBLE:
  729. hval = zend_dval_to_lval(Z_DVAL_P(dim));
  730. if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
  731. /* The array may be destroyed while throwing the notice.
  732. * Temporarily increase the refcount to detect this situation. */
  733. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
  734. GC_ADDREF(ht);
  735. }
  736. execute_data = EG(current_execute_data);
  737. opline = EX(opline);
  738. zend_incompatible_double_to_long_error(Z_DVAL_P(dim));
  739. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
  740. if (!GC_REFCOUNT(ht)) {
  741. zend_array_destroy(ht);
  742. }
  743. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  744. if (EG(exception)) {
  745. ZVAL_UNDEF(EX_VAR(opline->result.var));
  746. } else {
  747. ZVAL_NULL(EX_VAR(opline->result.var));
  748. }
  749. }
  750. return NULL;
  751. }
  752. if (EG(exception)) {
  753. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  754. ZVAL_UNDEF(EX_VAR(opline->result.var));
  755. }
  756. return NULL;
  757. }
  758. }
  759. goto num_index;
  760. case IS_RESOURCE:
  761. /* The array may be destroyed while throwing the notice.
  762. * Temporarily increase the refcount to detect this situation. */
  763. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
  764. GC_ADDREF(ht);
  765. }
  766. execute_data = EG(current_execute_data);
  767. opline = EX(opline);
  768. zend_use_resource_as_offset(dim);
  769. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
  770. if (!GC_REFCOUNT(ht)) {
  771. zend_array_destroy(ht);
  772. }
  773. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  774. if (EG(exception)) {
  775. ZVAL_UNDEF(EX_VAR(opline->result.var));
  776. } else {
  777. ZVAL_NULL(EX_VAR(opline->result.var));
  778. }
  779. }
  780. return NULL;
  781. }
  782. if (EG(exception)) {
  783. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  784. ZVAL_UNDEF(EX_VAR(opline->result.var));
  785. }
  786. return NULL;
  787. }
  788. hval = Z_RES_HANDLE_P(dim);
  789. goto num_index;
  790. case IS_FALSE:
  791. hval = 0;
  792. goto num_index;
  793. case IS_TRUE:
  794. hval = 1;
  795. goto num_index;
  796. default:
  797. zend_jit_illegal_offset();
  798. undef_result_after_exception();
  799. return NULL;
  800. }
  801. str_index:
  802. if (ZEND_HANDLE_NUMERIC(offset_key, hval)) {
  803. goto num_index;
  804. }
  805. retval = zend_hash_find(ht, offset_key);
  806. if (!retval) {
  807. /* Key may be released while throwing the undefined index warning. */
  808. retval = zend_undefined_index_write(ht, offset_key);
  809. }
  810. return retval;
  811. num_index:
  812. ZEND_HASH_INDEX_FIND(ht, hval, retval, num_undef);
  813. return retval;
  814. num_undef:
  815. return zend_undefined_offset_write(ht, hval);
  816. }
  817. static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim)
  818. {
  819. zend_ulong hval;
  820. zend_string *offset_key;
  821. zval *retval;
  822. zend_execute_data *execute_data;
  823. const zend_op *opline;
  824. if (Z_TYPE_P(dim) == IS_REFERENCE) {
  825. dim = Z_REFVAL_P(dim);
  826. }
  827. switch (Z_TYPE_P(dim)) {
  828. case IS_LONG:
  829. hval = Z_LVAL_P(dim);
  830. goto num_index;
  831. case IS_STRING:
  832. offset_key = Z_STR_P(dim);
  833. goto str_index;
  834. case IS_UNDEF:
  835. execute_data = EG(current_execute_data);
  836. opline = EX(opline);
  837. if (!zend_jit_undefined_op_helper_write(ht, opline->op2.var)) {
  838. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  839. if (EG(exception)) {
  840. ZVAL_UNDEF(EX_VAR(opline->result.var));
  841. } else {
  842. ZVAL_NULL(EX_VAR(opline->result.var));
  843. }
  844. }
  845. if (opline->opcode == ZEND_ASSIGN_DIM
  846. && ((opline+1)->op1_type & (IS_VAR | IS_TMP_VAR))) {
  847. zval_ptr_dtor_nogc(EX_VAR((opline+1)->op1.var));
  848. }
  849. return NULL;
  850. }
  851. ZEND_FALLTHROUGH;
  852. case IS_NULL:
  853. offset_key = ZSTR_EMPTY_ALLOC();
  854. goto str_index;
  855. case IS_DOUBLE:
  856. hval = zend_dval_to_lval(Z_DVAL_P(dim));
  857. if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
  858. /* The array may be destroyed while throwing the notice.
  859. * Temporarily increase the refcount to detect this situation. */
  860. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
  861. GC_ADDREF(ht);
  862. }
  863. execute_data = EG(current_execute_data);
  864. opline = EX(opline);
  865. zend_incompatible_double_to_long_error(Z_DVAL_P(dim));
  866. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
  867. if (!GC_REFCOUNT(ht)) {
  868. zend_array_destroy(ht);
  869. }
  870. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  871. if (EG(exception)) {
  872. ZVAL_UNDEF(EX_VAR(opline->result.var));
  873. } else {
  874. ZVAL_NULL(EX_VAR(opline->result.var));
  875. }
  876. }
  877. return NULL;
  878. }
  879. if (EG(exception)) {
  880. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  881. ZVAL_UNDEF(EX_VAR(opline->result.var));
  882. }
  883. return NULL;
  884. }
  885. }
  886. goto num_index;
  887. case IS_RESOURCE:
  888. /* The array may be destroyed while throwing the notice.
  889. * Temporarily increase the refcount to detect this situation. */
  890. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
  891. GC_ADDREF(ht);
  892. }
  893. execute_data = EG(current_execute_data);
  894. opline = EX(opline);
  895. zend_use_resource_as_offset(dim);
  896. if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
  897. if (!GC_REFCOUNT(ht)) {
  898. zend_array_destroy(ht);
  899. }
  900. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  901. if (EG(exception)) {
  902. ZVAL_UNDEF(EX_VAR(opline->result.var));
  903. } else {
  904. ZVAL_NULL(EX_VAR(opline->result.var));
  905. }
  906. }
  907. return NULL;
  908. }
  909. if (EG(exception)) {
  910. if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
  911. ZVAL_UNDEF(EX_VAR(opline->result.var));
  912. }
  913. return NULL;
  914. }
  915. hval = Z_RES_HANDLE_P(dim);
  916. goto num_index;
  917. case IS_FALSE:
  918. hval = 0;
  919. goto num_index;
  920. case IS_TRUE:
  921. hval = 1;
  922. goto num_index;
  923. default:
  924. zend_jit_illegal_offset();
  925. undef_result_after_exception();
  926. if ((EG(opline_before_exception)+1)->opcode == ZEND_OP_DATA
  927. && ((EG(opline_before_exception)+1)->op1_type & (IS_VAR|IS_TMP_VAR))) {
  928. zend_execute_data *execute_data = EG(current_execute_data);
  929. zval_ptr_dtor_nogc(EX_VAR((EG(opline_before_exception)+1)->op1.var));
  930. }
  931. return NULL;
  932. }
  933. str_index:
  934. if (ZEND_HANDLE_NUMERIC(offset_key, hval)) {
  935. goto num_index;
  936. }
  937. return zend_hash_lookup(ht, offset_key);
  938. num_index:
  939. ZEND_HASH_INDEX_LOOKUP(ht, hval, retval);
  940. return retval;
  941. }
  942. static zend_never_inline zend_long zend_check_string_offset(zval *dim/*, int type*/)
  943. {
  944. zend_long offset;
  945. try_again:
  946. switch(Z_TYPE_P(dim)) {
  947. case IS_LONG:
  948. return Z_LVAL_P(dim);
  949. case IS_STRING:
  950. {
  951. bool trailing_data = false;
  952. /* For BC reasons we allow errors so that we can warn on leading numeric string */
  953. if (IS_LONG == is_numeric_string_ex(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL,
  954. /* allow errors */ true, NULL, &trailing_data)) {
  955. if (UNEXPECTED(trailing_data)
  956. && EG(current_execute_data)->opline->opcode != ZEND_FETCH_DIM_UNSET) {
  957. zend_error(E_WARNING, "Illegal string offset \"%s\"", Z_STRVAL_P(dim));
  958. }
  959. return offset;
  960. }
  961. zend_jit_illegal_string_offset(dim);
  962. return 0;
  963. }
  964. case IS_UNDEF:
  965. zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
  966. ZEND_FALLTHROUGH;
  967. case IS_DOUBLE:
  968. case IS_NULL:
  969. case IS_FALSE:
  970. case IS_TRUE:
  971. zend_error(E_WARNING, "String offset cast occurred");
  972. break;
  973. case IS_REFERENCE:
  974. dim = Z_REFVAL_P(dim);
  975. goto try_again;
  976. default:
  977. zend_jit_illegal_string_offset(dim);
  978. return 0;
  979. }
  980. return zval_get_long_func(dim, /* is_strict */ false);
  981. }
  982. static zend_always_inline zend_string* zend_jit_fetch_dim_str_offset(zend_string *str, zend_long offset)
  983. {
  984. if (UNEXPECTED((zend_ulong)offset >= (zend_ulong)ZSTR_LEN(str))) {
  985. if (EXPECTED(offset < 0)) {
  986. /* Handle negative offset */
  987. zend_long real_offset = (zend_long)ZSTR_LEN(str) + offset;
  988. if (EXPECTED(real_offset >= 0)) {
  989. return ZSTR_CHAR((zend_uchar)ZSTR_VAL(str)[real_offset]);
  990. }
  991. }
  992. zend_error(E_WARNING, "Uninitialized string offset " ZEND_LONG_FMT, offset);
  993. return ZSTR_EMPTY_ALLOC();
  994. } else {
  995. return ZSTR_CHAR((zend_uchar)ZSTR_VAL(str)[offset]);
  996. }
  997. }
  998. static zend_string* ZEND_FASTCALL zend_jit_fetch_dim_str_offset_r_helper(zend_string *str, zend_long offset)
  999. {
  1000. return zend_jit_fetch_dim_str_offset(str, offset);
  1001. }
  1002. static zend_string* ZEND_FASTCALL zend_jit_fetch_dim_str_r_helper(zend_string *str, zval *dim)
  1003. {
  1004. zend_long offset;
  1005. if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
  1006. if (!(GC_FLAGS(str) & IS_STR_INTERNED)) {
  1007. GC_ADDREF(str);
  1008. }
  1009. offset = zend_check_string_offset(dim/*, BP_VAR_R*/);
  1010. if (!(GC_FLAGS(str) & IS_STR_INTERNED) && UNEXPECTED(GC_DELREF(str) == 0)) {
  1011. zend_string *ret = zend_jit_fetch_dim_str_offset(str, offset);
  1012. zend_string_efree(str);
  1013. return ret;
  1014. }
  1015. } else {
  1016. offset = Z_LVAL_P(dim);
  1017. }
  1018. return zend_jit_fetch_dim_str_offset(str, offset);
  1019. }
  1020. static void ZEND_FASTCALL zend_jit_fetch_dim_str_is_helper(zend_string *str, zval *dim, zval *result)
  1021. {
  1022. zend_long offset;
  1023. try_string_offset:
  1024. if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
  1025. switch (Z_TYPE_P(dim)) {
  1026. /* case IS_LONG: */
  1027. case IS_STRING:
  1028. if (IS_LONG == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), NULL, NULL, false)) {
  1029. break;
  1030. }
  1031. ZVAL_NULL(result);
  1032. return;
  1033. case IS_UNDEF:
  1034. zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
  1035. case IS_DOUBLE:
  1036. case IS_NULL:
  1037. case IS_FALSE:
  1038. case IS_TRUE:
  1039. break;
  1040. case IS_REFERENCE:
  1041. dim = Z_REFVAL_P(dim);
  1042. goto try_string_offset;
  1043. default:
  1044. zend_jit_illegal_string_offset(dim);
  1045. break;
  1046. }
  1047. offset = zval_get_long_func(dim, /* is_strict */ false);
  1048. } else {
  1049. offset = Z_LVAL_P(dim);
  1050. }
  1051. if ((zend_ulong)offset >= (zend_ulong)ZSTR_LEN(str)) {
  1052. if (offset < 0) {
  1053. /* Handle negative offset */
  1054. zend_long real_offset = (zend_long)ZSTR_LEN(str) + offset;
  1055. if (real_offset >= 0) {
  1056. ZVAL_CHAR(result, (zend_uchar)ZSTR_VAL(str)[real_offset]);
  1057. return;
  1058. }
  1059. }
  1060. ZVAL_NULL(result);
  1061. } else {
  1062. ZVAL_CHAR(result, (zend_uchar)ZSTR_VAL(str)[offset]);
  1063. }
  1064. }
  1065. static void ZEND_FASTCALL zend_jit_fetch_dim_obj_r_helper(zval *container, zval *dim, zval *result)
  1066. {
  1067. zval *retval;
  1068. zend_object *obj = Z_OBJ_P(container);
  1069. GC_ADDREF(obj);
  1070. if (UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) {
  1071. zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
  1072. dim = &EG(uninitialized_zval);
  1073. }
  1074. retval = obj->handlers->read_dimension(obj, dim, BP_VAR_R, result);
  1075. if (retval) {
  1076. if (result != retval) {
  1077. ZVAL_COPY_DEREF(result, retval);
  1078. } else if (UNEXPECTED(Z_ISREF_P(retval))) {
  1079. zend_unwrap_reference(retval);
  1080. }
  1081. } else {
  1082. ZVAL_NULL(result);
  1083. }
  1084. if (UNEXPECTED(GC_DELREF(obj) == 0)) {
  1085. zend_objects_store_del(obj);
  1086. }
  1087. }
  1088. static void ZEND_FASTCALL zend_jit_fetch_dim_obj_is_helper(zval *container, zval *dim, zval *result)
  1089. {
  1090. zval *retval;
  1091. zend_object *obj = Z_OBJ_P(container);
  1092. GC_ADDREF(obj);
  1093. if (UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) {
  1094. zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
  1095. dim = &EG(uninitialized_zval);
  1096. }
  1097. retval = obj->handlers->read_dimension(obj, dim, BP_VAR_IS, result);
  1098. if (retval) {
  1099. if (result != retval) {
  1100. ZVAL_COPY_DEREF(result, retval);
  1101. } else if (UNEXPECTED(Z_ISREF_P(retval))) {
  1102. zend_unwrap_reference(result);
  1103. }
  1104. } else {
  1105. ZVAL_NULL(result);
  1106. }
  1107. if (UNEXPECTED(GC_DELREF(obj) == 0)) {
  1108. zend_objects_store_del(obj);
  1109. }
  1110. }
  1111. static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim, zval *value, zval *result)
  1112. {
  1113. zend_uchar c;
  1114. size_t string_len;
  1115. zend_long offset;
  1116. zend_string *s;
  1117. /* separate string */
  1118. if (Z_REFCOUNTED_P(str) && Z_REFCOUNT_P(str) == 1) {
  1119. s = Z_STR_P(str);
  1120. } else {
  1121. s = zend_string_init(Z_STRVAL_P(str), Z_STRLEN_P(str), 0);
  1122. ZSTR_H(s) = ZSTR_H(Z_STR_P(str));
  1123. if (Z_REFCOUNTED_P(str)) {
  1124. GC_DELREF(Z_STR_P(str));
  1125. }
  1126. ZVAL_NEW_STR(str, s);
  1127. }
  1128. if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
  1129. /* The string may be destroyed while throwing the notice.
  1130. * Temporarily increase the refcount to detect this situation. */
  1131. GC_ADDREF(s);
  1132. offset = zend_check_string_offset(dim/*, BP_VAR_W*/);
  1133. if (UNEXPECTED(GC_DELREF(s) == 0)) {
  1134. zend_string_efree(s);
  1135. if (result) {
  1136. ZVAL_NULL(result);
  1137. }
  1138. return;
  1139. }
  1140. if (UNEXPECTED(EG(exception) != NULL)) {
  1141. if (UNEXPECTED(result)) {
  1142. ZVAL_UNDEF(result);
  1143. }
  1144. return;
  1145. }
  1146. } else {
  1147. offset = Z_LVAL_P(dim);
  1148. }
  1149. if (offset < -(zend_long)ZSTR_LEN(s)) {
  1150. /* Error on negative offset */
  1151. zend_error(E_WARNING, "Illegal string offset " ZEND_LONG_FMT, offset);
  1152. if (result) {
  1153. ZVAL_NULL(result);
  1154. }
  1155. return;
  1156. }
  1157. if (Z_TYPE_P(value) != IS_STRING) {
  1158. zend_string *tmp;
  1159. /* The string may be destroyed while throwing the notice.
  1160. * Temporarily increase the refcount to detect this situation. */
  1161. GC_ADDREF(s);
  1162. if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
  1163. const zend_op *op_data = EG(current_execute_data)->opline + 1;
  1164. ZEND_ASSERT(op_data->opcode == ZEND_OP_DATA && op_data->op1_type == IS_CV);
  1165. zend_jit_undefined_op_helper(op_data->op1.var);
  1166. value = &EG(uninitialized_zval);
  1167. }
  1168. /* Convert to string, just the time to pick the 1st byte */
  1169. tmp = zval_try_get_string_func(value);
  1170. if (UNEXPECTED(GC_DELREF(s) == 0)) {
  1171. zend_string_efree(s);
  1172. if (tmp) {
  1173. zend_string_release_ex(tmp, 0);
  1174. }
  1175. if (result) {
  1176. ZVAL_NULL(result);
  1177. }
  1178. return;
  1179. }
  1180. if (UNEXPECTED(!tmp)) {
  1181. if (result) {
  1182. ZVAL_UNDEF(result);
  1183. }
  1184. return;
  1185. }
  1186. if (UNEXPECTED(!tmp)) {
  1187. if (result) {
  1188. ZVAL_UNDEF(result);
  1189. }
  1190. return;
  1191. }
  1192. string_len = ZSTR_LEN(tmp);
  1193. c = (zend_uchar)ZSTR_VAL(tmp)[0];
  1194. zend_string_release(tmp);
  1195. } else {
  1196. string_len = Z_STRLEN_P(value);
  1197. c = (zend_uchar)Z_STRVAL_P(value)[0];
  1198. }
  1199. if (string_len != 1) {
  1200. if (string_len == 0) {
  1201. /* Error on empty input string */
  1202. zend_throw_error(NULL, "Cannot assign an empty string to a string offset");
  1203. if (result) {
  1204. ZVAL_NULL(result);
  1205. }
  1206. return;
  1207. }
  1208. /* The string may be destroyed while throwing the notice.
  1209. * Temporarily increase the refcount to detect this situation. */
  1210. GC_ADDREF(s);
  1211. zend_error(E_WARNING, "Only the first byte will be assigned to the string offset");
  1212. if (UNEXPECTED(GC_DELREF(s) == 0)) {
  1213. zend_string_efree(s);
  1214. if (result) {
  1215. ZVAL_NULL(result);
  1216. }
  1217. return;
  1218. }
  1219. /* Illegal offset assignment */
  1220. if (UNEXPECTED(EG(exception) != NULL)) {
  1221. if (result) {
  1222. ZVAL_UNDEF(result);
  1223. }
  1224. return;
  1225. }
  1226. }
  1227. if (offset < 0) { /* Handle negative offset */
  1228. offset += (zend_long)ZSTR_LEN(s);
  1229. }
  1230. if ((size_t)offset >= ZSTR_LEN(s)) {
  1231. /* Extend string if needed */
  1232. zend_long old_len = ZSTR_LEN(s);
  1233. ZVAL_NEW_STR(str, zend_string_extend(s, (size_t)offset + 1, 0));
  1234. memset(Z_STRVAL_P(str) + old_len, ' ', offset - old_len);
  1235. Z_STRVAL_P(str)[offset+1] = 0;
  1236. } else {
  1237. zend_string_forget_hash_val(Z_STR_P(str));
  1238. }
  1239. Z_STRVAL_P(str)[offset] = c;
  1240. if (result) {
  1241. /* Return the new character */
  1242. ZVAL_CHAR(result, c);
  1243. }
  1244. }
  1245. static zend_always_inline void ZEND_FASTCALL zend_jit_fetch_dim_obj_helper(zval *object_ptr, zval *dim, zval *result, int type)
  1246. {
  1247. zval *retval;
  1248. if (EXPECTED(Z_TYPE_P(object_ptr) == IS_OBJECT)) {
  1249. zend_object *obj = Z_OBJ_P(object_ptr);
  1250. GC_ADDREF(obj);
  1251. if (dim && UNEXPECTED(Z_ISUNDEF_P(dim))) {
  1252. const zend_op *opline = EG(current_execute_data)->opline;
  1253. zend_jit_undefined_op_helper(opline->op2.var);
  1254. dim = &EG(uninitialized_zval);
  1255. }
  1256. retval = obj->handlers->read_dimension(obj, dim, type, result);
  1257. if (UNEXPECTED(retval == &EG(uninitialized_zval))) {
  1258. zend_class_entry *ce = obj->ce;
  1259. ZVAL_NULL(result);
  1260. zend_error(E_NOTICE, "Indirect modification of overloaded element of %s has no effect", ZSTR_VAL(ce->name));
  1261. } else if (EXPECTED(retval && Z_TYPE_P(retval) != IS_UNDEF)) {
  1262. if (!Z_ISREF_P(retval)) {
  1263. if (result != retval) {
  1264. ZVAL_COPY(result, retval);
  1265. retval = result;
  1266. }
  1267. if (Z_TYPE_P(retval) != IS_OBJECT) {
  1268. zend_class_entry *ce = obj->ce;
  1269. zend_error(E_NOTICE, "Indirect modification of overloaded element of %s has no effect", ZSTR_VAL(ce->name));
  1270. }
  1271. } else if (UNEXPECTED(Z_REFCOUNT_P(retval) == 1)) {
  1272. ZVAL_UNREF(retval);
  1273. }
  1274. if (result != retval) {
  1275. ZVAL_INDIRECT(result, retval);
  1276. }
  1277. } else {
  1278. ZEND_ASSERT(EG(exception) && "read_dimension() returned NULL without exception");
  1279. ZVAL_UNDEF(result);
  1280. }
  1281. if (UNEXPECTED(GC_DELREF(obj) == 0)) {
  1282. zend_objects_store_del(obj);
  1283. }
  1284. } else if (EXPECTED(Z_TYPE_P(object_ptr) == IS_STRING)) {
  1285. if (!dim) {
  1286. zend_throw_error(NULL, "[] operator not supported for strings");
  1287. } else {
  1288. if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
  1289. zend_check_string_offset(dim/*, BP_VAR_RW*/);
  1290. }
  1291. zend_wrong_string_offset_error();
  1292. }
  1293. ZVAL_UNDEF(result);
  1294. } else if (Z_TYPE_P(object_ptr) == IS_FALSE) {
  1295. zend_array *arr = zend_new_array(0);
  1296. ZVAL_ARR(object_ptr, arr);
  1297. GC_ADDREF(arr);
  1298. zend_false_to_array_deprecated();
  1299. if (UNEXPECTED(GC_DELREF(arr) == 0)) {
  1300. zend_array_destroy(arr);
  1301. ZVAL_NULL(result);
  1302. return;
  1303. }
  1304. SEPARATE_ARRAY(object_ptr);
  1305. arr = Z_ARRVAL_P(object_ptr);
  1306. zval *var;
  1307. if (dim) {
  1308. if (type == BP_VAR_W) {
  1309. var = zend_jit_fetch_dim_w_helper(arr, dim);
  1310. } else {
  1311. ZEND_ASSERT(type == BP_VAR_RW);
  1312. var = zend_jit_fetch_dim_rw_helper(arr, dim);
  1313. }
  1314. } else {
  1315. var = zend_hash_next_index_insert_new(arr, &EG(uninitialized_zval));
  1316. }
  1317. if (var) {
  1318. ZVAL_INDIRECT(result, var);
  1319. } else {
  1320. ZVAL_UNDEF(result);
  1321. }
  1322. } else {
  1323. if (type == BP_VAR_UNSET) {
  1324. zend_throw_error(NULL, "Cannot unset offset in a non-array variable");
  1325. ZVAL_UNDEF(result);
  1326. } else {
  1327. zend_throw_error(NULL, "Cannot use a scalar value as an array");
  1328. ZVAL_UNDEF(result);
  1329. }
  1330. }
  1331. }
  1332. static void ZEND_FASTCALL zend_jit_fetch_dim_obj_w_helper(zval *object_ptr, zval *dim, zval *result)
  1333. {
  1334. zend_jit_fetch_dim_obj_helper(object_ptr, dim, result, BP_VAR_W);
  1335. }
  1336. static void ZEND_FASTCALL zend_jit_fetch_dim_obj_rw_helper(zval *object_ptr, zval *dim, zval *result)
  1337. {
  1338. zend_jit_fetch_dim_obj_helper(object_ptr, dim, result, BP_VAR_RW);
  1339. }
  1340. //static void ZEND_FASTCALL zend_jit_fetch_dim_obj_unset_helper(zval *object_ptr, zval *dim, zval *result)
  1341. //{
  1342. // zend_jit_fetch_dim_obj_helper(object_ptr, dim, result, BP_VAR_UNSET);
  1343. //}
  1344. static void ZEND_FASTCALL zend_jit_assign_dim_helper(zval *object_ptr, zval *dim, zval *value, zval *result)
  1345. {
  1346. if (EXPECTED(Z_TYPE_P(object_ptr) == IS_OBJECT)) {
  1347. zend_object *obj = Z_OBJ_P(object_ptr);
  1348. GC_ADDREF(obj);
  1349. if (dim && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) {
  1350. const zend_op *opline = EG(current_execute_data)->opline;
  1351. zend_jit_undefined_op_helper(opline->op2.var);
  1352. dim = &EG(uninitialized_zval);
  1353. }
  1354. if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
  1355. const zend_op *op_data = EG(current_execute_data)->opline + 1;
  1356. ZEND_ASSERT(op_data->opcode == ZEND_OP_DATA && op_data->op1_type == IS_CV);
  1357. zend_jit_undefined_op_helper(op_data->op1.var);
  1358. value = &EG(uninitialized_zval);
  1359. } else {
  1360. ZVAL_DEREF(value);
  1361. }
  1362. obj->handlers->write_dimension(obj, dim, value);
  1363. if (result) {
  1364. if (EXPECTED(!EG(exception))) {
  1365. ZVAL_COPY(result, value);
  1366. } else {
  1367. ZVAL_UNDEF(result);
  1368. }
  1369. }
  1370. if (UNEXPECTED(GC_DELREF(obj) == 0)) {
  1371. zend_objects_store_del(obj);
  1372. }
  1373. return;
  1374. } else if (EXPECTED(Z_TYPE_P(object_ptr) == IS_STRING) && EXPECTED(dim != NULL)) {
  1375. zend_assign_to_string_offset(object_ptr, dim, value, result);
  1376. return;
  1377. }
  1378. if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
  1379. const zend_op *op_data = EG(current_execute_data)->opline + 1;
  1380. ZEND_ASSERT(op_data->opcode == ZEND_OP_DATA && op_data->op1_type == IS_CV);
  1381. zend_jit_undefined_op_helper(op_data->op1.var);
  1382. value = &EG(uninitialized_zval);
  1383. }
  1384. if (EXPECTED(Z_TYPE_P(object_ptr) == IS_STRING)) {
  1385. zend_throw_error(NULL, "[] operator not supported for strings");
  1386. if (result) {
  1387. ZVAL_UNDEF(result);
  1388. }
  1389. } else if (Z_TYPE_P(object_ptr) == IS_FALSE) {
  1390. zend_array *arr = zend_new_array(0);
  1391. ZVAL_ARR(object_ptr, arr);
  1392. GC_ADDREF(arr);
  1393. zend_false_to_array_deprecated();
  1394. if (UNEXPECTED(GC_DELREF(arr) == 0)) {
  1395. zend_array_destroy(arr);
  1396. if (result) {
  1397. ZVAL_NULL(result);
  1398. }
  1399. return;
  1400. }
  1401. SEPARATE_ARRAY(object_ptr);
  1402. arr = Z_ARRVAL_P(object_ptr);
  1403. zval *var = dim
  1404. ? zend_jit_fetch_dim_w_helper(arr, dim)
  1405. : zend_hash_next_index_insert_new(arr, &EG(uninitialized_zval));
  1406. if (!var) {
  1407. if (result) {
  1408. ZVAL_UNDEF(result);
  1409. }
  1410. return;
  1411. }
  1412. ZVAL_COPY_DEREF(var, value);
  1413. if (result) {
  1414. ZVAL_COPY(result, var);
  1415. }
  1416. } else {
  1417. if (dim && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) {
  1418. const zend_op *opline = EG(current_execute_data)->opline;
  1419. zend_jit_undefined_op_helper(opline->op2.var);
  1420. dim = &EG(uninitialized_zval);
  1421. }
  1422. zend_throw_error(NULL, "Cannot use a scalar value as an array");
  1423. if (result) {
  1424. ZVAL_UNDEF(result);
  1425. }
  1426. }
  1427. }
  1428. static void ZEND_FASTCALL zend_jit_assign_dim_op_helper(zval *container, zval *dim, zval *value, binary_op_type binary_op)
  1429. {
  1430. if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
  1431. zend_object *obj = Z_OBJ_P(container);
  1432. zval *z;
  1433. zval rv, res;
  1434. GC_ADDREF(obj);
  1435. if (dim && UNEXPECTED(Z_ISUNDEF_P(dim))) {
  1436. const zend_op *opline = EG(current_execute_data)->opline;
  1437. zend_jit_undefined_op_helper(opline->op2.var);
  1438. dim = &EG(uninitialized_zval);
  1439. }
  1440. z = obj->handlers->read_dimension(obj, dim, BP_VAR_R, &rv);
  1441. if (z != NULL) {
  1442. if (binary_op(&res, Z_ISREF_P(z) ? Z_REFVAL_P(z) : z, value) == SUCCESS) {
  1443. obj->handlers->write_dimension(obj, dim, &res);
  1444. }
  1445. if (z == &rv) {
  1446. zval_ptr_dtor(&rv);
  1447. }
  1448. zval_ptr_dtor(&res);
  1449. } else {
  1450. zend_error(E_WARNING, "Attempt to assign property of non-object");
  1451. }
  1452. if (UNEXPECTED(GC_DELREF(obj) == 0)) {
  1453. zend_objects_store_del(obj);
  1454. //??? if (retval) {
  1455. //??? ZVAL_NULL(retval);
  1456. //??? }
  1457. }
  1458. } else if (UNEXPECTED(Z_TYPE_P(container) == IS_STRING)) {
  1459. if (!dim) {
  1460. zend_throw_error(NULL, "[] operator not supported for strings");
  1461. } else {
  1462. if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
  1463. zend_check_string_offset(dim/*, BP_VAR_RW*/);
  1464. }
  1465. zend_wrong_string_offset_error();
  1466. }
  1467. } else if (Z_TYPE_P(container) == IS_FALSE) {
  1468. zend_array *arr = zend_new_array(0);
  1469. ZVAL_ARR(container, arr);
  1470. GC_ADDREF(arr);
  1471. zend_false_to_array_deprecated();
  1472. if (UNEXPECTED(GC_DELREF(arr) == 0)) {
  1473. zend_array_destroy(arr);
  1474. return;
  1475. }
  1476. SEPARATE_ARRAY(container);
  1477. arr = Z_ARRVAL_P(container);
  1478. zval *var = dim
  1479. ? zend_jit_fetch_dim_rw_helper(arr, dim)
  1480. : zend_hash_next_index_insert_new(arr, &EG(uninitialized_zval));
  1481. if (var) {
  1482. binary_op(var, var, value);
  1483. }
  1484. } else {
  1485. zend_throw_error(NULL, "Cannot use a scalar value as an array");
  1486. }
  1487. }
  1488. static void ZEND_FASTCALL zend_jit_fast_assign_concat_helper(zval *op1, zval *op2)
  1489. {
  1490. size_t op1_len = Z_STRLEN_P(op1);
  1491. size_t op2_len = Z_STRLEN_P(op2);
  1492. size_t result_len = op1_len + op2_len;
  1493. zend_string *result_str;
  1494. if (UNEXPECTED(op1_len > SIZE_MAX - op2_len)) {
  1495. zend_throw_error(NULL, "String size overflow");
  1496. return;
  1497. }
  1498. do {
  1499. if (Z_REFCOUNTED_P(op1)) {
  1500. if (GC_REFCOUNT(Z_STR_P(op1)) == 1) {
  1501. result_str = perealloc(Z_STR_P(op1), ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(result_len)), 0);
  1502. ZSTR_LEN(result_str) = result_len;
  1503. zend_string_forget_hash_val(result_str);
  1504. if (UNEXPECTED(Z_STR_P(op1) == Z_STR_P(op2))) {
  1505. ZVAL_NEW_STR(op2, result_str);
  1506. }
  1507. break;
  1508. }
  1509. GC_DELREF(Z_STR_P(op1));
  1510. }
  1511. result_str = zend_string_alloc(result_len, 0);
  1512. memcpy(ZSTR_VAL(result_str), Z_STRVAL_P(op1), op1_len);
  1513. } while(0);
  1514. ZVAL_NEW_STR(op1, result_str);
  1515. memcpy(ZSTR_VAL(result_str) + op1_len, Z_STRVAL_P(op2), op2_len);
  1516. ZSTR_VAL(result_str)[result_len] = '\0';
  1517. }
  1518. static void ZEND_FASTCALL zend_jit_fast_concat_helper(zval *result, zval *op1, zval *op2)
  1519. {
  1520. size_t op1_len = Z_STRLEN_P(op1);
  1521. size_t op2_len = Z_STRLEN_P(op2);
  1522. size_t result_len = op1_len + op2_len;
  1523. zend_string *result_str;
  1524. if (UNEXPECTED(op1_len > SIZE_MAX - op2_len)) {
  1525. zend_throw_error(NULL, "String size overflow");
  1526. return;
  1527. }
  1528. result_str = zend_string_alloc(result_len, 0);
  1529. memcpy(ZSTR_VAL(result_str), Z_STRVAL_P(op1), op1_len);
  1530. ZVAL_NEW_STR(result, result_str);
  1531. memcpy(ZSTR_VAL(result_str) + op1_len, Z_STRVAL_P(op2), op2_len);
  1532. ZSTR_VAL(result_str)[result_len] = '\0';
  1533. }
  1534. static void ZEND_FASTCALL zend_jit_fast_concat_tmp_helper(zval *result, zval *op1, zval *op2)
  1535. {
  1536. zend_string *op1_str = Z_STR_P(op1);
  1537. size_t op1_len = ZSTR_LEN(op1_str);
  1538. size_t op2_len = Z_STRLEN_P(op2);
  1539. size_t result_len = op1_len + op2_len;
  1540. zend_string *result_str;
  1541. if (UNEXPECTED(op1_len > SIZE_MAX - op2_len)) {
  1542. zend_throw_error(NULL, "String size overflow");
  1543. return;
  1544. }
  1545. do {
  1546. if (!ZSTR_IS_INTERNED(op1_str)) {
  1547. if (GC_REFCOUNT(op1_str) == 1) {
  1548. Z_STR_P(op1) = result_str =
  1549. perealloc(op1_str, ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(result_len)), 0);
  1550. ZSTR_LEN(result_str) = result_len;
  1551. zend_string_forget_hash_val(result_str);
  1552. break;
  1553. }
  1554. GC_DELREF(op1_str);
  1555. }
  1556. result_str = zend_string_alloc(result_len, 0);
  1557. memcpy(ZSTR_VAL(result_str), ZSTR_VAL(op1_str), op1_len);
  1558. } while (0);
  1559. ZVAL_NEW_STR(result, result_str);
  1560. memcpy(ZSTR_VAL(result_str) + op1_len, Z_STRVAL_P(op2), op2_len);
  1561. ZSTR_VAL(result_str)[result_len] = '\0';
  1562. }
  1563. static int ZEND_FASTCALL zend_jit_isset_dim_helper(zval *container, zval *offset)
  1564. {
  1565. if (UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) {
  1566. zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
  1567. offset = &EG(uninitialized_zval);
  1568. }
  1569. if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
  1570. return Z_OBJ_HT_P(container)->has_dimension(Z_OBJ_P(container), offset, 0);
  1571. } else if (EXPECTED(Z_TYPE_P(container) == IS_STRING)) { /* string offsets */
  1572. zend_long lval;
  1573. if (EXPECTED(Z_TYPE_P(offset) == IS_LONG)) {
  1574. lval = Z_LVAL_P(offset);
  1575. isset_str_offset:
  1576. if (UNEXPECTED(lval < 0)) { /* Handle negative offset */
  1577. lval += (zend_long)Z_STRLEN_P(container);
  1578. }
  1579. if (EXPECTED(lval >= 0) && (size_t)lval < Z_STRLEN_P(container)) {
  1580. return 1;
  1581. }
  1582. } else {
  1583. ZVAL_DEREF(offset);
  1584. if (Z_TYPE_P(offset) < IS_STRING /* simple scalar types */
  1585. || (Z_TYPE_P(offset) == IS_STRING /* or numeric string */
  1586. && IS_LONG == is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), NULL, NULL, false))) {
  1587. lval = zval_get_long_ex(offset, /* is_strict */ true);
  1588. goto isset_str_offset;
  1589. }
  1590. }
  1591. }
  1592. return 0;
  1593. }
  1594. static void ZEND_FASTCALL zend_jit_free_call_frame(zend_execute_data *call)
  1595. {
  1596. zend_vm_stack_free_call_frame(call);
  1597. }
  1598. static zend_reference* ZEND_FASTCALL zend_jit_fetch_global_helper(zend_string *varname, void **cache_slot)
  1599. {
  1600. zval *value;
  1601. uintptr_t idx;
  1602. zend_reference *ref;
  1603. /* We store "hash slot index" + 1 (NULL is a mark of uninitialized cache slot) */
  1604. idx = (uintptr_t)CACHED_PTR_EX(cache_slot) - 1;
  1605. if (EXPECTED(idx < EG(symbol_table).nNumUsed * sizeof(Bucket))) {
  1606. Bucket *p = (Bucket*)((char*)EG(symbol_table).arData + idx);
  1607. if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF) &&
  1608. (EXPECTED(p->key == varname) ||
  1609. (EXPECTED(p->h == ZSTR_H(varname)) &&
  1610. EXPECTED(p->key != NULL) &&
  1611. EXPECTED(zend_string_equal_content(p->key, varname))))) {
  1612. value = (zval*)p; /* value = &p->val; */
  1613. goto check_indirect;
  1614. }
  1615. }
  1616. value = zend_hash_find_known_hash(&EG(symbol_table), varname);
  1617. if (UNEXPECTED(value == NULL)) {
  1618. value = zend_hash_add_new(&EG(symbol_table), varname, &EG(uninitialized_zval));
  1619. idx = (char*)value - (char*)EG(symbol_table).arData;
  1620. /* Store "hash slot index" + 1 (NULL is a mark of uninitialized cache slot) */
  1621. CACHE_PTR_EX(cache_slot, (void*)(idx + 1));
  1622. } else {
  1623. idx = (char*)value - (char*)EG(symbol_table).arData;
  1624. /* Store "hash slot index" + 1 (NULL is a mark of uninitialized cache slot) */
  1625. CACHE_PTR_EX(cache_slot, (void*)(idx + 1));
  1626. check_indirect:
  1627. /* GLOBAL variable may be an INDIRECT pointer to CV */
  1628. if (UNEXPECTED(Z_TYPE_P(value) == IS_INDIRECT)) {
  1629. value = Z_INDIRECT_P(value);
  1630. if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
  1631. ZVAL_NULL(value);
  1632. }
  1633. }
  1634. }
  1635. if (UNEXPECTED(!Z_ISREF_P(value))) {
  1636. ZVAL_MAKE_REF_EX(value, 2);
  1637. ref = Z_REF_P(value);
  1638. } else {
  1639. ref = Z_REF_P(value);
  1640. GC_ADDREF(ref);
  1641. }
  1642. return ref;
  1643. }
  1644. static bool ZEND_FASTCALL zend_jit_verify_arg_slow(zval *arg, zend_arg_info *arg_info)
  1645. {
  1646. zend_execute_data *execute_data = EG(current_execute_data);
  1647. const zend_op *opline = EX(opline);
  1648. void **cache_slot = CACHE_ADDR(opline->extended_value);
  1649. bool ret = zend_check_user_type_slow(
  1650. &arg_info->type, arg, /* ref */ NULL, cache_slot, /* is_return_type */ false);
  1651. if (UNEXPECTED(!ret)) {
  1652. zend_verify_arg_error(EX(func), arg_info, opline->op1.num, arg);
  1653. return 0;
  1654. }
  1655. return ret;
  1656. }
  1657. static void ZEND_FASTCALL zend_jit_verify_return_slow(zval *arg, const zend_op_array *op_array, zend_arg_info *arg_info, void **cache_slot)
  1658. {
  1659. if (UNEXPECTED(!zend_check_user_type_slow(
  1660. &arg_info->type, arg, /* ref */ NULL, cache_slot, /* is_return_type */ true))) {
  1661. zend_verify_return_error((zend_function*)op_array, arg);
  1662. }
  1663. }
  1664. static void ZEND_FASTCALL zend_jit_fetch_obj_r_slow(zend_object *zobj)
  1665. {
  1666. zval *retval;
  1667. zend_execute_data *execute_data = EG(current_execute_data);
  1668. const zend_op *opline = EX(opline);
  1669. zend_string *name = Z_STR_P(RT_CONSTANT(opline, opline->op2));
  1670. zval *result = EX_VAR(opline->result.var);
  1671. void **cache_slot = CACHE_ADDR(opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS);
  1672. retval = zobj->handlers->read_property(zobj, name, BP_VAR_R, cache_slot, result);
  1673. if (retval != result) {
  1674. ZVAL_COPY_DEREF(result, retval);
  1675. } else if (UNEXPECTED(Z_ISREF_P(retval))) {
  1676. zend_unwrap_reference(retval);
  1677. }
  1678. }
  1679. static void ZEND_FASTCALL zend_jit_fetch_obj_r_dynamic(zend_object *zobj, intptr_t prop_offset)
  1680. {
  1681. if (zobj->properties) {
  1682. zval *retval;
  1683. zend_execute_data *execute_data = EG(current_execute_data);
  1684. const zend_op *opline = EX(opline);
  1685. zend_string *name = Z_STR_P(RT_CONSTANT(opline, opline->op2));
  1686. zval *result = EX_VAR(opline->result.var);
  1687. void **cache_slot = CACHE_ADDR(opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS);
  1688. if (!IS_UNKNOWN_DYNAMIC_PROPERTY_OFFSET(prop_offset)) {
  1689. intptr_t idx = ZEND_DECODE_DYN_PROP_OFFSET(prop_offset);
  1690. if (EXPECTED(idx < zobj->properties->nNumUsed * sizeof(Bucket))) {
  1691. Bucket *p = (Bucket*)((char*)zobj->properties->arData + idx);
  1692. if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF) &&
  1693. (EXPECTED(p->key == name) ||
  1694. (EXPECTED(p->h == ZSTR_H(name)) &&
  1695. EXPECTED(p->key != NULL) &&
  1696. EXPECTED(ZSTR_LEN(p->key) == ZSTR_LEN(name)) &&
  1697. EXPECTED(memcmp(ZSTR_VAL(p->key), ZSTR_VAL(name), ZSTR_LEN(name)) == 0)))) {
  1698. ZVAL_COPY_DEREF(result, &p->val);
  1699. return;
  1700. }
  1701. }
  1702. CACHE_PTR_EX(cache_slot + 1, (void*)ZEND_DYNAMIC_PROPERTY_OFFSET);
  1703. }
  1704. retval = zend_hash_find_known_hash(zobj->properties, name);
  1705. if (EXPECTED(retval)) {
  1706. intptr_t idx = (char*)retval - (char*)zobj->properties->arData;
  1707. CACHE_PTR_EX(cache_slot + 1, (void*)ZEND_ENCODE_DYN_PROP_OFFSET(idx));
  1708. ZVAL_COPY_DEREF(result, retval);
  1709. return;
  1710. }
  1711. }
  1712. zend_jit_fetch_obj_r_slow(zobj);
  1713. }
  1714. static void ZEND_FASTCALL zend_jit_fetch_obj_is_slow(zend_object *zobj)
  1715. {
  1716. zval *retval;
  1717. zend_execute_data *execute_data = EG(current_execute_data);
  1718. const zend_op *opline = EX(opline);
  1719. zend_string *name = Z_STR_P(RT_CONSTANT(opline, opline->op2));
  1720. zval *result = EX_VAR(opline->result.var);
  1721. void **cache_slot = CACHE_ADDR(opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS);
  1722. retval = zobj->handlers->read_property(zobj, name, BP_VAR_IS, cache_slot, result);
  1723. if (retval != result) {
  1724. ZVAL_COPY_DEREF(result, retval);
  1725. } else if (UNEXPECTED(Z_ISREF_P(retval))) {
  1726. zend_unwrap_reference(retval);
  1727. }
  1728. }
  1729. static void ZEND_FASTCALL zend_jit_fetch_obj_is_dynamic(zend_object *zobj, intptr_t prop_offset)
  1730. {
  1731. if (zobj->properties) {
  1732. zval *retval;
  1733. zend_execute_data *execute_data = EG(current_execute_data);
  1734. const zend_op *opline = EX(opline);
  1735. zend_string *name = Z_STR_P(RT_CONSTANT(opline, opline->op2));
  1736. zval *result = EX_VAR(opline->result.var);
  1737. void **cache_slot = CACHE_ADDR(opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS);
  1738. if (!IS_UNKNOWN_DYNAMIC_PROPERTY_OFFSET(prop_offset)) {
  1739. intptr_t idx = ZEND_DECODE_DYN_PROP_OFFSET(prop_offset);
  1740. if (EXPECTED(idx < zobj->properties->nNumUsed * sizeof(Bucket))) {
  1741. Bucket *p = (Bucket*)((char*)zobj->properties->arData + idx);
  1742. if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF) &&
  1743. (EXPECTED(p->key == name) ||
  1744. (EXPECTED(p->h == ZSTR_H(name)) &&
  1745. EXPECTED(p->key != NULL) &&
  1746. EXPECTED(ZSTR_LEN(p->key) == ZSTR_LEN(name)) &&
  1747. EXPECTED(memcmp(ZSTR_VAL(p->key), ZSTR_VAL(name), ZSTR_LEN(name)) == 0)))) {
  1748. ZVAL_COPY_DEREF(result, &p->val);
  1749. return;
  1750. }
  1751. }
  1752. CACHE_PTR_EX(cache_slot + 1, (void*)ZEND_DYNAMIC_PROPERTY_OFFSET);
  1753. }
  1754. retval = zend_hash_find_known_hash(zobj->properties, name);
  1755. if (EXPECTED(retval)) {
  1756. intptr_t idx = (char*)retval - (char*)zobj->properties->arData;
  1757. CACHE_PTR_EX(cache_slot + 1, (void*)ZEND_ENCODE_DYN_PROP_OFFSET(idx));
  1758. ZVAL_COPY(result, retval);
  1759. return;
  1760. }
  1761. }
  1762. zend_jit_fetch_obj_is_slow(zobj);
  1763. }
  1764. static zend_always_inline bool promotes_to_array(zval *val) {
  1765. return Z_TYPE_P(val) <= IS_FALSE
  1766. || (Z_ISREF_P(val) && Z_TYPE_P(Z_REFVAL_P(val)) <= IS_FALSE);
  1767. }
  1768. static zend_always_inline bool check_type_array_assignable(zend_type type) {
  1769. if (!ZEND_TYPE_IS_SET(type)) {
  1770. return 1;
  1771. }
  1772. return (ZEND_TYPE_FULL_MASK(type) & (MAY_BE_ITERABLE|MAY_BE_ARRAY)) != 0;
  1773. }
  1774. static zend_property_info *zend_object_fetch_property_type_info(
  1775. zend_object *obj, zval *slot)
  1776. {
  1777. if (EXPECTED(!ZEND_CLASS_HAS_TYPE_HINTS(obj->ce))) {
  1778. return NULL;
  1779. }
  1780. /* Not a declared property */
  1781. if (UNEXPECTED(slot < obj->properties_table ||
  1782. slot >= obj->properties_table + obj->ce->default_properties_count)) {
  1783. return NULL;
  1784. }
  1785. return zend_get_typed_property_info_for_slot(obj, slot);
  1786. }
  1787. static zend_never_inline ZEND_COLD void zend_throw_auto_init_in_prop_error(zend_property_info *prop, const char *type) {
  1788. zend_string *type_str = zend_type_to_string(prop->type);
  1789. zend_type_error(
  1790. "Cannot auto-initialize an %s inside property %s::$%s of type %s",
  1791. type,
  1792. ZSTR_VAL(prop->ce->name), zend_get_unmangled_property_name(prop->name),
  1793. ZSTR_VAL(type_str)
  1794. );
  1795. zend_string_release(type_str);
  1796. }
  1797. static zend_never_inline ZEND_COLD void zend_throw_access_uninit_prop_by_ref_error(
  1798. zend_property_info *prop) {
  1799. zend_throw_error(NULL,
  1800. "Cannot access uninitialized non-nullable property %s::$%s by reference",
  1801. ZSTR_VAL(prop->ce->name),
  1802. zend_get_unmangled_property_name(prop->name));
  1803. }
  1804. static zend_never_inline bool zend_handle_fetch_obj_flags(
  1805. zval *result, zval *ptr, zend_object *obj, zend_property_info *prop_info, uint32_t flags)
  1806. {
  1807. switch (flags) {
  1808. case ZEND_FETCH_DIM_WRITE:
  1809. if (promotes_to_array(ptr)) {
  1810. if (!prop_info) {
  1811. prop_info = zend_object_fetch_property_type_info(obj, ptr);
  1812. if (!prop_info) {
  1813. break;
  1814. }
  1815. }
  1816. if (!check_type_array_assignable(prop_info->type)) {
  1817. zend_throw_auto_init_in_prop_error(prop_info, "array");
  1818. if (result) ZVAL_ERROR(result);
  1819. return 0;
  1820. }
  1821. }
  1822. break;
  1823. case ZEND_FETCH_REF:
  1824. if (Z_TYPE_P(ptr) != IS_REFERENCE) {
  1825. if (!prop_info) {
  1826. prop_info = zend_object_fetch_property_type_info(obj, ptr);
  1827. if (!prop_info) {
  1828. break;
  1829. }
  1830. }
  1831. if (Z_TYPE_P(ptr) == IS_UNDEF) {
  1832. if (!ZEND_TYPE_ALLOW_NULL(prop_info->type)) {
  1833. zend_throw_access_uninit_prop_by_ref_error(prop_info);
  1834. if (result) ZVAL_ERROR(result);
  1835. return 0;
  1836. }
  1837. ZVAL_NULL(ptr);
  1838. }
  1839. ZVAL_NEW_REF(ptr, ptr);
  1840. ZEND_REF_ADD_TYPE_SOURCE(Z_REF_P(ptr), prop_info);
  1841. }
  1842. break;
  1843. EMPTY_SWITCH_DEFAULT_CASE()
  1844. }
  1845. return 1;
  1846. }
  1847. static void ZEND_FASTCALL zend_jit_fetch_obj_w_slow(zend_object *zobj)
  1848. {
  1849. zval *retval;
  1850. zend_execute_data *execute_data = EG(current_execute_data);
  1851. const zend_op *opline = EX(opline);
  1852. zend_string *name = Z_STR_P(RT_CONSTANT(opline, opline->op2));
  1853. zval *result = EX_VAR(opline->result.var);
  1854. void **cache_slot = CACHE_ADDR(opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS);
  1855. retval = zobj->handlers->get_property_ptr_ptr(zobj, name, BP_VAR_W, cache_slot);
  1856. if (NULL == retval) {
  1857. retval = zobj->handlers->read_property(zobj, name, BP_VAR_W, cache_slot, result);
  1858. if (retval == result) {
  1859. if (UNEXPECTED(Z_ISREF_P(retval) && Z_REFCOUNT_P(retval) == 1)) {
  1860. ZVAL_UNREF(retval);
  1861. }
  1862. return;
  1863. }
  1864. if (UNEXPECTED(EG(exception))) {
  1865. ZVAL_ERROR(result);
  1866. return;
  1867. }
  1868. } else if (UNEXPECTED(Z_ISERROR_P(retval))) {
  1869. ZVAL_ERROR(result);
  1870. return;
  1871. }
  1872. ZVAL_INDIRECT(result, retval);
  1873. /* Support for typed properties */
  1874. do {
  1875. uint32_t flags = opline->extended_value & ZEND_FETCH_OBJ_FLAGS;
  1876. if (flags) {
  1877. zend_property_info *prop_info = NULL;
  1878. if (opline->op2_type == IS_CONST) {
  1879. prop_info = CACHED_PTR_EX(cache_slot + 2);
  1880. if (!prop_info) {
  1881. break;
  1882. }
  1883. }
  1884. if (UNEXPECTED(!zend_handle_fetch_obj_flags(result, retval, zobj, prop_info, flags))) {
  1885. return;
  1886. }
  1887. }
  1888. } while (0);
  1889. if (UNEXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) {
  1890. ZVAL_NULL(retval);
  1891. }
  1892. }
  1893. static void ZEND_FASTCALL zend_jit_check_array_promotion(zval *val, zend_property_info *prop)
  1894. {
  1895. zend_execute_data *execute_data = EG(current_execute_data);
  1896. const zend_op *opline = execute_data->opline;
  1897. zval *result = EX_VAR(opline->result.var);
  1898. if ((Z_TYPE_P(val) <= IS_FALSE
  1899. || (Z_ISREF_P(val) && Z_TYPE_P(Z_REFVAL_P(val)) <= IS_FALSE))
  1900. && ZEND_TYPE_IS_SET(prop->type)
  1901. && (ZEND_TYPE_FULL_MASK(prop->type) & (MAY_BE_ITERABLE|MAY_BE_ARRAY)) == 0) {
  1902. zend_string *type_str = zend_type_to_string(prop->type);
  1903. zend_type_error(
  1904. "Cannot auto-initialize an array inside property %s::$%s of type %s",
  1905. ZSTR_VAL(prop->ce->name), zend_get_unmangled_property_name(prop->name),
  1906. ZSTR_VAL(type_str)
  1907. );
  1908. zend_string_release(type_str);
  1909. ZVAL_ERROR(result);
  1910. } else {
  1911. ZVAL_INDIRECT(result, val);
  1912. }
  1913. }
  1914. static void ZEND_FASTCALL zend_jit_create_typed_ref(zval *val, zend_property_info *prop, zval *result)
  1915. {
  1916. if (!Z_ISREF_P(val)) {
  1917. ZVAL_NEW_REF(val, val);
  1918. ZEND_REF_ADD_TYPE_SOURCE(Z_REF_P(val), prop);
  1919. }
  1920. ZVAL_INDIRECT(result, val);
  1921. }
  1922. static void ZEND_FASTCALL zend_jit_extract_helper(zend_refcounted *garbage)
  1923. {
  1924. zend_execute_data *execute_data = EG(current_execute_data);
  1925. const zend_op *opline = execute_data->opline;
  1926. zval *zv = EX_VAR(opline->result.var);
  1927. if (EXPECTED(Z_TYPE_P(zv) == IS_INDIRECT)) {
  1928. ZVAL_COPY(zv, Z_INDIRECT_P(zv));
  1929. }
  1930. rc_dtor_func(garbage);
  1931. }
  1932. static void ZEND_FASTCALL zend_jit_vm_stack_free_args_helper(zend_execute_data *call)
  1933. {
  1934. zend_vm_stack_free_args(call);
  1935. }
  1936. static zend_always_inline zval* zend_jit_assign_to_typed_ref_helper(zend_reference *ref, zval *value, zend_uchar value_type)
  1937. {
  1938. zval variable;
  1939. ZVAL_REF(&variable, ref);
  1940. return zend_assign_to_variable(&variable, value, value_type, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data)));
  1941. }
  1942. static zval* ZEND_FASTCALL zend_jit_assign_const_to_typed_ref(zend_reference *ref, zval *value)
  1943. {
  1944. return zend_jit_assign_to_typed_ref_helper(ref, value, IS_CONST);
  1945. }
  1946. static zval* ZEND_FASTCALL zend_jit_assign_tmp_to_typed_ref(zend_reference *ref, zval *value)
  1947. {
  1948. return zend_jit_assign_to_typed_ref_helper(ref, value, IS_TMP_VAR);
  1949. }
  1950. static zval* ZEND_FASTCALL zend_jit_assign_var_to_typed_ref(zend_reference *ref, zval *value)
  1951. {
  1952. return zend_jit_assign_to_typed_ref_helper(ref, value, IS_VAR);
  1953. }
  1954. static zval* ZEND_FASTCALL zend_jit_assign_cv_to_typed_ref(zend_reference *ref, zval *value)
  1955. {
  1956. if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
  1957. const zend_op *opline = EG(current_execute_data)->opline;
  1958. uint32_t var;
  1959. if (opline->opcode == ZEND_ASSIGN) {
  1960. var = opline->op2.var;
  1961. } else {
  1962. ZEND_ASSERT((opline + 1)->opcode == ZEND_OP_DATA);
  1963. var = (opline + 1)->op1.var;
  1964. }
  1965. zend_jit_undefined_op_helper(var);
  1966. value = &EG(uninitialized_zval);
  1967. }
  1968. return zend_jit_assign_to_typed_ref_helper(ref, value, IS_CV);
  1969. }
  1970. static zend_property_info *zend_jit_get_prop_not_accepting_double(zend_reference *ref)
  1971. {
  1972. zend_property_info *prop;
  1973. ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) {
  1974. if (!(ZEND_TYPE_FULL_MASK(prop->type) & MAY_BE_DOUBLE)) {
  1975. return prop;
  1976. }
  1977. } ZEND_REF_FOREACH_TYPE_SOURCES_END();
  1978. return NULL;
  1979. }
  1980. static ZEND_COLD void zend_jit_throw_inc_ref_error(zend_reference *ref, zend_property_info *error_prop)
  1981. {
  1982. zend_string *type_str = zend_type_to_string(error_prop->type);
  1983. zend_type_error(
  1984. "Cannot increment a reference held by property %s::$%s of type %s past its maximal value",
  1985. ZSTR_VAL(error_prop->ce->name),
  1986. zend_get_unmangled_property_name(error_prop->name),
  1987. ZSTR_VAL(type_str));
  1988. zend_string_release(type_str);
  1989. }
  1990. static ZEND_COLD void zend_jit_throw_dec_ref_error(zend_reference *ref, zend_property_info *error_prop)
  1991. {
  1992. zend_string *type_str = zend_type_to_string(error_prop->type);
  1993. zend_type_error(
  1994. "Cannot decrement a reference held by property %s::$%s of type %s past its minimal value",
  1995. ZSTR_VAL(error_prop->ce->name),
  1996. zend_get_unmangled_property_name(error_prop->name),
  1997. ZSTR_VAL(type_str));
  1998. zend_string_release(type_str);
  1999. }
  2000. static void ZEND_FASTCALL zend_jit_pre_inc_typed_ref(zend_reference *ref, zval *ret)
  2001. {
  2002. zval *var_ptr = &ref->val;
  2003. zval tmp;
  2004. ZVAL_COPY(&tmp, var_ptr);
  2005. increment_function(var_ptr);
  2006. if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE(tmp) == IS_LONG) {
  2007. zend_property_info *error_prop = zend_jit_get_prop_not_accepting_double(ref);
  2008. if (UNEXPECTED(error_prop)) {
  2009. zend_jit_throw_inc_ref_error(ref, error_prop);
  2010. ZVAL_LONG(var_ptr, ZEND_LONG_MAX);
  2011. }
  2012. } else if (UNEXPECTED(!zend_verify_ref_assignable_zval(ref, var_ptr, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
  2013. zval_ptr_dtor(var_ptr);
  2014. ZVAL_COPY_VALUE(var_ptr, &tmp);
  2015. } else {
  2016. zval_ptr_dtor(&tmp);
  2017. }
  2018. if (ret) {
  2019. ZVAL_COPY(ret, var_ptr);
  2020. }
  2021. }
  2022. static void ZEND_FASTCALL zend_jit_pre_dec_typed_ref(zend_reference *ref, zval *ret)
  2023. {
  2024. zval *var_ptr = &ref->val;
  2025. zval tmp;
  2026. ZVAL_COPY(&tmp, var_ptr);
  2027. decrement_function(var_ptr);
  2028. if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE(tmp) == IS_LONG) {
  2029. zend_property_info *error_prop = zend_jit_get_prop_not_accepting_double(ref);
  2030. if (UNEXPECTED(error_prop)) {
  2031. zend_jit_throw_dec_ref_error(ref, error_prop);
  2032. ZVAL_LONG(var_ptr, ZEND_LONG_MIN);
  2033. }
  2034. } else if (UNEXPECTED(!zend_verify_ref_assignable_zval(ref, var_ptr, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
  2035. zval_ptr_dtor(var_ptr);
  2036. ZVAL_COPY_VALUE(var_ptr, &tmp);
  2037. } else {
  2038. zval_ptr_dtor(&tmp);
  2039. }
  2040. if (ret) {
  2041. ZVAL_COPY(ret, var_ptr);
  2042. }
  2043. }
  2044. static void ZEND_FASTCALL zend_jit_post_inc_typed_ref(zend_reference *ref, zval *ret)
  2045. {
  2046. zval *var_ptr = &ref->val;
  2047. ZVAL_COPY(ret, var_ptr);
  2048. increment_function(var_ptr);
  2049. if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE_P(ret) == IS_LONG) {
  2050. zend_property_info *error_prop = zend_jit_get_prop_not_accepting_double(ref);
  2051. if (UNEXPECTED(error_prop)) {
  2052. zend_jit_throw_inc_ref_error(ref, error_prop);
  2053. ZVAL_LONG(var_ptr, ZEND_LONG_MAX);
  2054. }
  2055. } else if (UNEXPECTED(!zend_verify_ref_assignable_zval(ref, var_ptr, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
  2056. zval_ptr_dtor(var_ptr);
  2057. ZVAL_COPY_VALUE(var_ptr, ret);
  2058. }
  2059. }
  2060. static void ZEND_FASTCALL zend_jit_post_dec_typed_ref(zend_reference *ref, zval *ret)
  2061. {
  2062. zval *var_ptr = &ref->val;
  2063. ZVAL_COPY(ret, var_ptr);
  2064. decrement_function(var_ptr);
  2065. if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE_P(ret) == IS_LONG) {
  2066. zend_property_info *error_prop = zend_jit_get_prop_not_accepting_double(ref);
  2067. if (UNEXPECTED(error_prop)) {
  2068. zend_jit_throw_dec_ref_error(ref, error_prop);
  2069. ZVAL_LONG(var_ptr, ZEND_LONG_MIN);
  2070. }
  2071. } else if (UNEXPECTED(!zend_verify_ref_assignable_zval(ref, var_ptr, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
  2072. zval_ptr_dtor(var_ptr);
  2073. ZVAL_COPY_VALUE(var_ptr, ret);
  2074. }
  2075. }
  2076. static void ZEND_FASTCALL zend_jit_assign_op_to_typed_ref(zend_reference *ref, zval *val, binary_op_type binary_op)
  2077. {
  2078. zval z_copy;
  2079. /* Make sure that in-place concatenation is used if the LHS is a string. */
  2080. if (binary_op == concat_function && Z_TYPE(ref->val) == IS_STRING) {
  2081. concat_function(&ref->val, &ref->val, val);
  2082. ZEND_ASSERT(Z_TYPE(ref->val) == IS_STRING && "Concat should return string");
  2083. return;
  2084. }
  2085. binary_op(&z_copy, &ref->val, val);
  2086. if (EXPECTED(zend_verify_ref_assignable_zval(ref, &z_copy, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
  2087. zval_ptr_dtor(&ref->val);
  2088. ZVAL_COPY_VALUE(&ref->val, &z_copy);
  2089. } else {
  2090. zval_ptr_dtor(&z_copy);
  2091. }
  2092. }
  2093. static void ZEND_FASTCALL zend_jit_assign_op_to_typed_ref_tmp(zend_reference *ref, zval *val, binary_op_type binary_op)
  2094. {
  2095. zval z_copy;
  2096. binary_op(&z_copy, &ref->val, val);
  2097. if (EXPECTED(zend_verify_ref_assignable_zval(ref, &z_copy, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
  2098. zval_ptr_dtor(&ref->val);
  2099. ZVAL_COPY_VALUE(&ref->val, &z_copy);
  2100. } else {
  2101. zval_ptr_dtor(&z_copy);
  2102. }
  2103. zval_ptr_dtor_nogc(val);
  2104. }
  2105. static void ZEND_FASTCALL zend_jit_only_vars_by_reference(zval *arg)
  2106. {
  2107. ZVAL_NEW_REF(arg, arg);
  2108. zend_error(E_NOTICE, "Only variables should be passed by reference");
  2109. }
  2110. static void ZEND_FASTCALL zend_jit_invalid_array_access(zval *container)
  2111. {
  2112. zend_error(E_WARNING, "Trying to access array offset on value of type %s", zend_zval_type_name(container));
  2113. }
  2114. static void ZEND_FASTCALL zend_jit_invalid_property_read(zval *container, const char *property_name)
  2115. {
  2116. zend_error(E_WARNING, "Attempt to read property \"%s\" on %s", property_name, zend_zval_type_name(container));
  2117. }
  2118. static void ZEND_FASTCALL zend_jit_invalid_property_write(zval *container, const char *property_name)
  2119. {
  2120. zend_throw_error(NULL,
  2121. "Attempt to modify property \"%s\" on %s",
  2122. property_name, zend_zval_type_name(container));
  2123. }
  2124. static void ZEND_FASTCALL zend_jit_invalid_property_incdec(zval *container, const char *property_name)
  2125. {
  2126. zend_execute_data *execute_data = EG(current_execute_data);
  2127. const zend_op *opline = EX(opline);
  2128. if (Z_TYPE_P(container) == IS_UNDEF && opline->op1_type == IS_CV) {
  2129. zend_string *cv = EX(func)->op_array.vars[EX_VAR_TO_NUM(opline->op1.var)];
  2130. zend_error(E_WARNING, "Undefined variable $%s", ZSTR_VAL(cv));
  2131. }
  2132. if (opline->result_type & (IS_VAR|IS_TMP_VAR)) {
  2133. ZVAL_UNDEF(EX_VAR(opline->result.var));
  2134. }
  2135. zend_throw_error(NULL,
  2136. "Attempt to increment/decrement property \"%s\" on %s",
  2137. property_name, zend_zval_type_name(container));
  2138. if (opline->op1_type == IS_VAR) {
  2139. zval_ptr_dtor_nogc(EX_VAR(opline->op1.var));
  2140. }
  2141. }
  2142. static void ZEND_FASTCALL zend_jit_invalid_property_assign(zval *container, const char *property_name)
  2143. {
  2144. zend_throw_error(NULL,
  2145. "Attempt to assign property \"%s\" on %s",
  2146. property_name, zend_zval_type_name(container));
  2147. }
  2148. static void ZEND_FASTCALL zend_jit_invalid_property_assign_op(zval *container, const char *property_name)
  2149. {
  2150. if (Z_TYPE_P(container) == IS_UNDEF) {
  2151. const zend_execute_data *execute_data = EG(current_execute_data);
  2152. zend_jit_undefined_op_helper(EX(opline)->op1.var);
  2153. }
  2154. zend_jit_invalid_property_assign(container, property_name);
  2155. }
  2156. static zval * ZEND_FASTCALL zend_jit_prepare_assign_dim_ref(zval *ref) {
  2157. zval *val = Z_REFVAL_P(ref);
  2158. if (Z_TYPE_P(val) <= IS_FALSE) {
  2159. if (ZEND_REF_HAS_TYPE_SOURCES(Z_REF_P(ref))
  2160. && !zend_verify_ref_array_assignable(Z_REF_P(ref))) {
  2161. return NULL;
  2162. }
  2163. if (Z_TYPE_P(val) == IS_FALSE) {
  2164. ZVAL_ARR(val, zend_new_array(8));
  2165. zend_false_to_array_deprecated();
  2166. if (EG(exception)) {
  2167. return NULL;
  2168. }
  2169. } else {
  2170. ZVAL_ARR(val, zend_new_array(8));
  2171. }
  2172. }
  2173. return val;
  2174. }
  2175. static void ZEND_FASTCALL zend_jit_pre_inc(zval *var_ptr, zval *ret)
  2176. {
  2177. increment_function(var_ptr);
  2178. ZVAL_COPY(ret, var_ptr);
  2179. }
  2180. static void ZEND_FASTCALL zend_jit_pre_dec(zval *var_ptr, zval *ret)
  2181. {
  2182. decrement_function(var_ptr);
  2183. ZVAL_COPY(ret, var_ptr);
  2184. }
  2185. #define HT_POISONED_PTR ((HashTable *) (intptr_t) -1)
  2186. static zend_never_inline void ZEND_FASTCALL _zend_hash_iterators_remove(HashTable *ht)
  2187. {
  2188. HashTableIterator *iter = EG(ht_iterators);
  2189. HashTableIterator *end = iter + EG(ht_iterators_used);
  2190. while (iter != end) {
  2191. if (iter->ht == ht) {
  2192. iter->ht = HT_POISONED_PTR;
  2193. }
  2194. iter++;
  2195. }
  2196. }
  2197. static void ZEND_FASTCALL zend_jit_array_free(HashTable *ht)
  2198. {
  2199. GC_REMOVE_FROM_BUFFER(ht);
  2200. if (UNEXPECTED(HT_HAS_ITERATORS(ht))) {
  2201. _zend_hash_iterators_remove(ht);
  2202. }
  2203. if (!(EXPECTED(HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED))) {
  2204. efree(HT_GET_DATA_ADDR(ht));
  2205. }
  2206. FREE_HASHTABLE(ht);
  2207. }
  2208. static HashTable *ZEND_FASTCALL zend_jit_zval_array_dup(zval *arr)
  2209. {
  2210. HashTable *ht;
  2211. Z_TRY_DELREF_P(arr);
  2212. ht = Z_ARRVAL_P(arr);
  2213. ht = zend_array_dup(ht);
  2214. ZVAL_ARR(arr, ht);
  2215. return ht;
  2216. }
  2217. static zend_array *ZEND_FASTCALL zend_jit_add_arrays_helper(zend_array *op1, zend_array *op2)
  2218. {
  2219. zend_array *res;
  2220. res = zend_array_dup(op1);
  2221. zend_hash_merge(res, op2, zval_add_ref, 0);
  2222. return res;
  2223. }
  2224. static void ZEND_FASTCALL zend_jit_assign_obj_helper(zend_object *zobj, zend_string *name, zval *value, void **cache_slot, zval *result)
  2225. {
  2226. if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
  2227. const zend_op *op_data = EG(current_execute_data)->opline + 1;
  2228. ZEND_ASSERT(op_data->opcode == ZEND_OP_DATA && op_data->op1_type == IS_CV);
  2229. zend_jit_undefined_op_helper(op_data->op1.var);
  2230. value = &EG(uninitialized_zval);
  2231. }
  2232. ZVAL_DEREF(value);
  2233. value = zobj->handlers->write_property(zobj, name, value, cache_slot);
  2234. if (result) {
  2235. ZVAL_COPY_DEREF(result, value);
  2236. }
  2237. }
  2238. static void ZEND_FASTCALL zend_jit_assign_to_typed_prop(zval *property_val, zend_property_info *info, zval *value, zval *result)
  2239. {
  2240. zend_execute_data *execute_data = EG(current_execute_data);
  2241. zval tmp;
  2242. if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
  2243. const zend_op *op_data = execute_data->opline + 1;
  2244. ZEND_ASSERT(op_data->opcode == ZEND_OP_DATA && op_data->op1_type == IS_CV);
  2245. zend_jit_undefined_op_helper(op_data->op1.var);
  2246. value = &EG(uninitialized_zval);
  2247. }
  2248. if (UNEXPECTED(info->flags & ZEND_ACC_READONLY)) {
  2249. zend_readonly_property_modification_error(info);
  2250. if (result) {
  2251. ZVAL_UNDEF(result);
  2252. }
  2253. return;
  2254. }
  2255. ZVAL_DEREF(value);
  2256. ZVAL_COPY(&tmp, value);
  2257. if (UNEXPECTED(!zend_verify_property_type(info, &tmp, EX_USES_STRICT_TYPES()))) {
  2258. zval_ptr_dtor(&tmp);
  2259. if (result) {
  2260. ZVAL_NULL(result);
  2261. }
  2262. return;
  2263. }
  2264. value = zend_assign_to_variable(property_val, &tmp, IS_TMP_VAR, EX_USES_STRICT_TYPES());
  2265. if (result) {
  2266. ZVAL_COPY_DEREF(result, value);
  2267. }
  2268. }
  2269. static zend_never_inline void _zend_jit_assign_op_overloaded_property(zend_object *object, zend_string *name, void **cache_slot, zval *value, binary_op_type binary_op)
  2270. {
  2271. zval *z;
  2272. zval rv, res;
  2273. GC_ADDREF(object);
  2274. z = object->handlers->read_property(object, name, BP_VAR_R, cache_slot, &rv);
  2275. if (UNEXPECTED(EG(exception))) {
  2276. OBJ_RELEASE(object);
  2277. //??? if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
  2278. //??? ZVAL_UNDEF(EX_VAR(opline->result.var));
  2279. //??? }
  2280. return;
  2281. }
  2282. if (binary_op(&res, z, value) == SUCCESS) {
  2283. object->handlers->write_property(object, name, &res, cache_slot);
  2284. }
  2285. //??? if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
  2286. //??? ZVAL_COPY(EX_VAR(opline->result.var), &res);
  2287. //??? }
  2288. if (z == &rv) {
  2289. zval_ptr_dtor(z);
  2290. }
  2291. zval_ptr_dtor(&res);
  2292. OBJ_RELEASE(object);
  2293. }
  2294. static void ZEND_FASTCALL zend_jit_assign_op_to_typed_prop(zval *zptr, zend_property_info *prop_info, zval *value, binary_op_type binary_op)
  2295. {
  2296. zend_execute_data *execute_data = EG(current_execute_data);
  2297. zval z_copy;
  2298. if (UNEXPECTED(prop_info->flags & ZEND_ACC_READONLY)) {
  2299. zend_readonly_property_modification_error(prop_info);
  2300. return;
  2301. }
  2302. ZVAL_DEREF(zptr);
  2303. /* Make sure that in-place concatenation is used if the LHS is a string. */
  2304. if (binary_op == concat_function && Z_TYPE_P(zptr) == IS_STRING) {
  2305. concat_function(zptr, zptr, value);
  2306. ZEND_ASSERT(Z_TYPE_P(zptr) == IS_STRING && "Concat should return string");
  2307. return;
  2308. }
  2309. binary_op(&z_copy, zptr, value);
  2310. if (EXPECTED(zend_verify_property_type(prop_info, &z_copy, EX_USES_STRICT_TYPES()))) {
  2311. zval_ptr_dtor(zptr);
  2312. ZVAL_COPY_VALUE(zptr, &z_copy);
  2313. } else {
  2314. zval_ptr_dtor(&z_copy);
  2315. }
  2316. }
  2317. static void ZEND_FASTCALL zend_jit_assign_obj_op_helper(zend_object *zobj, zend_string *name, zval *value, void **cache_slot, binary_op_type binary_op)
  2318. {
  2319. zval *zptr;
  2320. zend_property_info *prop_info;
  2321. if (EXPECTED((zptr = zobj->handlers->get_property_ptr_ptr(zobj, name, BP_VAR_RW, cache_slot)) != NULL)) {
  2322. if (UNEXPECTED(Z_ISERROR_P(zptr))) {
  2323. //??? if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
  2324. //??? ZVAL_NULL(EX_VAR(opline->result.var));
  2325. //??? }
  2326. } else {
  2327. //??? zval *orig_zptr = zptr;
  2328. zend_reference *ref;
  2329. do {
  2330. if (UNEXPECTED(Z_ISREF_P(zptr))) {
  2331. ref = Z_REF_P(zptr);
  2332. zptr = Z_REFVAL_P(zptr);
  2333. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) {
  2334. zend_jit_assign_op_to_typed_ref(ref, value, binary_op);
  2335. break;
  2336. }
  2337. }
  2338. //??? if (OP2_TYPE == IS_CONST) {
  2339. prop_info = (zend_property_info*)CACHED_PTR_EX(cache_slot + 2);
  2340. //??? } else {
  2341. //??? prop_info = zend_object_fetch_property_type_info(Z_OBJ_P(object), orig_zptr);
  2342. //??? }
  2343. if (UNEXPECTED(prop_info)) {
  2344. /* special case for typed properties */
  2345. zend_jit_assign_op_to_typed_prop(zptr, prop_info, value, binary_op);
  2346. } else {
  2347. binary_op(zptr, zptr, value);
  2348. }
  2349. } while (0);
  2350. //??? if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
  2351. //??? ZVAL_COPY(EX_VAR(opline->result.var), zptr);
  2352. //??? }
  2353. }
  2354. } else {
  2355. _zend_jit_assign_op_overloaded_property(zobj, name, cache_slot, value, binary_op);
  2356. }
  2357. }
  2358. static ZEND_COLD zend_long _zend_jit_throw_inc_prop_error(zend_property_info *prop)
  2359. {
  2360. zend_string *type_str = zend_type_to_string(prop->type);
  2361. zend_type_error("Cannot increment property %s::$%s of type %s past its maximal value",
  2362. ZSTR_VAL(prop->ce->name),
  2363. zend_get_unmangled_property_name(prop->name),
  2364. ZSTR_VAL(type_str));
  2365. zend_string_release(type_str);
  2366. return ZEND_LONG_MAX;
  2367. }
  2368. static ZEND_COLD zend_long _zend_jit_throw_dec_prop_error(zend_property_info *prop)
  2369. {
  2370. zend_string *type_str = zend_type_to_string(prop->type);
  2371. zend_type_error("Cannot decrement property %s::$%s of type %s past its minimal value",
  2372. ZSTR_VAL(prop->ce->name),
  2373. zend_get_unmangled_property_name(prop->name),
  2374. ZSTR_VAL(type_str));
  2375. zend_string_release(type_str);
  2376. return ZEND_LONG_MIN;
  2377. }
  2378. static void ZEND_FASTCALL zend_jit_inc_typed_prop(zval *var_ptr, zend_property_info *prop_info)
  2379. {
  2380. zend_execute_data *execute_data = EG(current_execute_data);
  2381. zval tmp;
  2382. ZVAL_DEREF(var_ptr);
  2383. ZVAL_COPY(&tmp, var_ptr);
  2384. increment_function(var_ptr);
  2385. if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE(tmp) == IS_LONG) {
  2386. if (!(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
  2387. zend_long val = _zend_jit_throw_inc_prop_error(prop_info);
  2388. ZVAL_LONG(var_ptr, val);
  2389. }
  2390. } else if (UNEXPECTED(!zend_verify_property_type(prop_info, var_ptr, EX_USES_STRICT_TYPES()))) {
  2391. zval_ptr_dtor(var_ptr);
  2392. ZVAL_COPY_VALUE(var_ptr, &tmp);
  2393. } else {
  2394. zval_ptr_dtor(&tmp);
  2395. }
  2396. }
  2397. static void ZEND_FASTCALL zend_jit_dec_typed_prop(zval *var_ptr, zend_property_info *prop_info)
  2398. {
  2399. zend_execute_data *execute_data = EG(current_execute_data);
  2400. zval tmp;
  2401. ZVAL_DEREF(var_ptr);
  2402. ZVAL_COPY(&tmp, var_ptr);
  2403. decrement_function(var_ptr);
  2404. if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE(tmp) == IS_LONG) {
  2405. if (!(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
  2406. zend_long val = _zend_jit_throw_dec_prop_error(prop_info);
  2407. ZVAL_LONG(var_ptr, val);
  2408. }
  2409. } else if (UNEXPECTED(!zend_verify_property_type(prop_info, var_ptr, EX_USES_STRICT_TYPES()))) {
  2410. zval_ptr_dtor(var_ptr);
  2411. ZVAL_COPY_VALUE(var_ptr, &tmp);
  2412. } else {
  2413. zval_ptr_dtor(&tmp);
  2414. }
  2415. }
  2416. static void ZEND_FASTCALL zend_jit_pre_inc_typed_prop(zval *var_ptr, zend_property_info *prop_info, zval *result)
  2417. {
  2418. ZVAL_DEREF(var_ptr);
  2419. zend_jit_inc_typed_prop(var_ptr, prop_info);
  2420. ZVAL_COPY(result, var_ptr);
  2421. }
  2422. static void ZEND_FASTCALL zend_jit_pre_dec_typed_prop(zval *var_ptr, zend_property_info *prop_info, zval *result)
  2423. {
  2424. ZVAL_DEREF(var_ptr);
  2425. zend_jit_dec_typed_prop(var_ptr, prop_info);
  2426. ZVAL_COPY(result, var_ptr);
  2427. }
  2428. static void ZEND_FASTCALL zend_jit_post_inc_typed_prop(zval *var_ptr, zend_property_info *prop_info, zval *result)
  2429. {
  2430. zend_execute_data *execute_data = EG(current_execute_data);
  2431. ZVAL_DEREF(var_ptr);
  2432. ZVAL_COPY(result, var_ptr);
  2433. increment_function(var_ptr);
  2434. if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE_P(result) == IS_LONG) {
  2435. if (!(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
  2436. zend_long val = _zend_jit_throw_inc_prop_error(prop_info);
  2437. ZVAL_LONG(var_ptr, val);
  2438. }
  2439. } else if (UNEXPECTED(!zend_verify_property_type(prop_info, var_ptr, EX_USES_STRICT_TYPES()))) {
  2440. zval_ptr_dtor(var_ptr);
  2441. ZVAL_COPY_VALUE(var_ptr, result);
  2442. ZVAL_UNDEF(result);
  2443. }
  2444. }
  2445. static void ZEND_FASTCALL zend_jit_post_dec_typed_prop(zval *var_ptr, zend_property_info *prop_info, zval *result)
  2446. {
  2447. zend_execute_data *execute_data = EG(current_execute_data);
  2448. ZVAL_DEREF(var_ptr);
  2449. ZVAL_COPY(result, var_ptr);
  2450. decrement_function(var_ptr);
  2451. if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE_P(result) == IS_LONG) {
  2452. if (!(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
  2453. zend_long val = _zend_jit_throw_dec_prop_error(prop_info);
  2454. ZVAL_LONG(var_ptr, val);
  2455. }
  2456. } else if (UNEXPECTED(!zend_verify_property_type(prop_info, var_ptr, EX_USES_STRICT_TYPES()))) {
  2457. zval_ptr_dtor(var_ptr);
  2458. ZVAL_COPY_VALUE(var_ptr, result);
  2459. ZVAL_UNDEF(result);
  2460. }
  2461. }
  2462. static void ZEND_FASTCALL zend_jit_pre_inc_obj_helper(zend_object *zobj, zend_string *name, void **cache_slot, zval *result)
  2463. {
  2464. zval *prop;
  2465. if (EXPECTED((prop = zobj->handlers->get_property_ptr_ptr(zobj, name, BP_VAR_RW, cache_slot)) != NULL)) {
  2466. if (UNEXPECTED(Z_ISERROR_P(prop))) {
  2467. if (UNEXPECTED(result)) {
  2468. ZVAL_NULL(result);
  2469. }
  2470. } else {
  2471. zend_property_info *prop_info = (zend_property_info *) CACHED_PTR_EX(cache_slot + 2);
  2472. if (EXPECTED(Z_TYPE_P(prop) == IS_LONG)) {
  2473. fast_long_increment_function(prop);
  2474. if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && UNEXPECTED(prop_info)
  2475. && !(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
  2476. zend_long val = _zend_jit_throw_inc_prop_error(prop_info);
  2477. ZVAL_LONG(prop, val);
  2478. }
  2479. } else {
  2480. do {
  2481. if (Z_ISREF_P(prop)) {
  2482. zend_reference *ref = Z_REF_P(prop);
  2483. prop = Z_REFVAL_P(prop);
  2484. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) {
  2485. zend_jit_pre_inc_typed_ref(ref, result);
  2486. break;
  2487. }
  2488. }
  2489. if (UNEXPECTED(prop_info)) {
  2490. zend_jit_inc_typed_prop(prop, prop_info);
  2491. } else {
  2492. increment_function(prop);
  2493. }
  2494. } while (0);
  2495. }
  2496. if (UNEXPECTED(result)) {
  2497. ZVAL_COPY(result, prop);
  2498. }
  2499. }
  2500. } else {
  2501. zval rv;
  2502. zval *z;
  2503. zval z_copy;
  2504. GC_ADDREF(zobj);
  2505. z = zobj->handlers->read_property(zobj, name, BP_VAR_R, cache_slot, &rv);
  2506. if (UNEXPECTED(EG(exception))) {
  2507. OBJ_RELEASE(zobj);
  2508. if (UNEXPECTED(result)) {
  2509. ZVAL_NULL(result);
  2510. }
  2511. return;
  2512. }
  2513. ZVAL_COPY_DEREF(&z_copy, z);
  2514. increment_function(&z_copy);
  2515. if (UNEXPECTED(result)) {
  2516. ZVAL_COPY(result, &z_copy);
  2517. }
  2518. zobj->handlers->write_property(zobj, name, &z_copy, cache_slot);
  2519. OBJ_RELEASE(zobj);
  2520. zval_ptr_dtor(&z_copy);
  2521. if (z == &rv) {
  2522. zval_ptr_dtor(z);
  2523. }
  2524. }
  2525. }
  2526. static void ZEND_FASTCALL zend_jit_pre_dec_obj_helper(zend_object *zobj, zend_string *name, void **cache_slot, zval *result)
  2527. {
  2528. zval *prop;
  2529. if (EXPECTED((prop = zobj->handlers->get_property_ptr_ptr(zobj, name, BP_VAR_RW, cache_slot)) != NULL)) {
  2530. if (UNEXPECTED(Z_ISERROR_P(prop))) {
  2531. if (UNEXPECTED(result)) {
  2532. ZVAL_NULL(result);
  2533. }
  2534. } else {
  2535. zend_property_info *prop_info = (zend_property_info *) CACHED_PTR_EX(cache_slot + 2);
  2536. if (EXPECTED(Z_TYPE_P(prop) == IS_LONG)) {
  2537. fast_long_decrement_function(prop);
  2538. if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && UNEXPECTED(prop_info)
  2539. && !(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
  2540. zend_long val = _zend_jit_throw_dec_prop_error(prop_info);
  2541. ZVAL_LONG(prop, val);
  2542. }
  2543. } else {
  2544. do {
  2545. if (Z_ISREF_P(prop)) {
  2546. zend_reference *ref = Z_REF_P(prop);
  2547. prop = Z_REFVAL_P(prop);
  2548. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) {
  2549. zend_jit_pre_dec_typed_ref(ref, result);
  2550. break;
  2551. }
  2552. }
  2553. if (UNEXPECTED(prop_info)) {
  2554. zend_jit_dec_typed_prop(prop, prop_info);
  2555. } else {
  2556. decrement_function(prop);
  2557. }
  2558. } while (0);
  2559. }
  2560. if (UNEXPECTED(result)) {
  2561. ZVAL_COPY(result, prop);
  2562. }
  2563. }
  2564. } else {
  2565. zval rv;
  2566. zval *z;
  2567. zval z_copy;
  2568. GC_ADDREF(zobj);
  2569. z = zobj->handlers->read_property(zobj, name, BP_VAR_R, cache_slot, &rv);
  2570. if (UNEXPECTED(EG(exception))) {
  2571. OBJ_RELEASE(zobj);
  2572. if (UNEXPECTED(result)) {
  2573. ZVAL_NULL(result);
  2574. }
  2575. return;
  2576. }
  2577. ZVAL_COPY_DEREF(&z_copy, z);
  2578. decrement_function(&z_copy);
  2579. if (UNEXPECTED(result)) {
  2580. ZVAL_COPY(result, &z_copy);
  2581. }
  2582. zobj->handlers->write_property(zobj, name, &z_copy, cache_slot);
  2583. OBJ_RELEASE(zobj);
  2584. zval_ptr_dtor(&z_copy);
  2585. if (z == &rv) {
  2586. zval_ptr_dtor(z);
  2587. }
  2588. }
  2589. }
  2590. static void ZEND_FASTCALL zend_jit_post_inc_obj_helper(zend_object *zobj, zend_string *name, void **cache_slot, zval *result)
  2591. {
  2592. zval *prop;
  2593. if (EXPECTED((prop = zobj->handlers->get_property_ptr_ptr(zobj, name, BP_VAR_RW, cache_slot)) != NULL)) {
  2594. if (UNEXPECTED(Z_ISERROR_P(prop))) {
  2595. ZVAL_NULL(result);
  2596. } else {
  2597. zend_property_info *prop_info = (zend_property_info*)CACHED_PTR_EX(cache_slot + 2);
  2598. if (EXPECTED(Z_TYPE_P(prop) == IS_LONG)) {
  2599. ZVAL_LONG(result, Z_LVAL_P(prop));
  2600. fast_long_increment_function(prop);
  2601. if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && UNEXPECTED(prop_info)
  2602. && !(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
  2603. zend_long val = _zend_jit_throw_inc_prop_error(prop_info);
  2604. ZVAL_LONG(prop, val);
  2605. }
  2606. } else {
  2607. if (Z_ISREF_P(prop)) {
  2608. zend_reference *ref = Z_REF_P(prop);
  2609. prop = Z_REFVAL_P(prop);
  2610. if (ZEND_REF_HAS_TYPE_SOURCES(ref)) {
  2611. zend_jit_post_inc_typed_ref(ref, result);
  2612. return;
  2613. }
  2614. }
  2615. if (UNEXPECTED(prop_info)) {
  2616. zend_jit_post_inc_typed_prop(prop, prop_info, result);
  2617. } else {
  2618. ZVAL_COPY(result, prop);
  2619. increment_function(prop);
  2620. }
  2621. }
  2622. }
  2623. } else {
  2624. zval rv;
  2625. zval *z;
  2626. zval z_copy;
  2627. GC_ADDREF(zobj);
  2628. z = zobj->handlers->read_property(zobj, name, BP_VAR_R, cache_slot, &rv);
  2629. if (UNEXPECTED(EG(exception))) {
  2630. OBJ_RELEASE(zobj);
  2631. ZVAL_UNDEF(result);
  2632. return;
  2633. }
  2634. ZVAL_COPY_DEREF(&z_copy, z);
  2635. ZVAL_COPY(result, &z_copy);
  2636. increment_function(&z_copy);
  2637. zobj->handlers->write_property(zobj, name, &z_copy, cache_slot);
  2638. OBJ_RELEASE(zobj);
  2639. zval_ptr_dtor(&z_copy);
  2640. if (z == &rv) {
  2641. zval_ptr_dtor(z);
  2642. }
  2643. }
  2644. }
  2645. static void ZEND_FASTCALL zend_jit_post_dec_obj_helper(zend_object *zobj, zend_string *name, void **cache_slot, zval *result)
  2646. {
  2647. zval *prop;
  2648. if (EXPECTED((prop = zobj->handlers->get_property_ptr_ptr(zobj, name, BP_VAR_RW, cache_slot)) != NULL)) {
  2649. if (UNEXPECTED(Z_ISERROR_P(prop))) {
  2650. ZVAL_NULL(result);
  2651. } else {
  2652. zend_property_info *prop_info = (zend_property_info*)CACHED_PTR_EX(cache_slot + 2);
  2653. if (EXPECTED(Z_TYPE_P(prop) == IS_LONG)) {
  2654. ZVAL_LONG(result, Z_LVAL_P(prop));
  2655. fast_long_decrement_function(prop);
  2656. if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && UNEXPECTED(prop_info)
  2657. && !(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
  2658. zend_long val = _zend_jit_throw_dec_prop_error(prop_info);
  2659. ZVAL_LONG(prop, val);
  2660. }
  2661. } else {
  2662. if (Z_ISREF_P(prop)) {
  2663. zend_reference *ref = Z_REF_P(prop);
  2664. prop = Z_REFVAL_P(prop);
  2665. if (ZEND_REF_HAS_TYPE_SOURCES(ref)) {
  2666. zend_jit_post_dec_typed_ref(ref, result);
  2667. return;
  2668. }
  2669. }
  2670. if (UNEXPECTED(prop_info)) {
  2671. zend_jit_post_dec_typed_prop(prop, prop_info, result);
  2672. } else {
  2673. ZVAL_COPY(result, prop);
  2674. decrement_function(prop);
  2675. }
  2676. }
  2677. }
  2678. } else {
  2679. zval rv;
  2680. zval *z;
  2681. zval z_copy;
  2682. GC_ADDREF(zobj);
  2683. z = zobj->handlers->read_property(zobj, name, BP_VAR_R, cache_slot, &rv);
  2684. if (UNEXPECTED(EG(exception))) {
  2685. OBJ_RELEASE(zobj);
  2686. ZVAL_UNDEF(result);
  2687. return;
  2688. }
  2689. ZVAL_COPY_DEREF(&z_copy, z);
  2690. ZVAL_COPY(result, &z_copy);
  2691. decrement_function(&z_copy);
  2692. zobj->handlers->write_property(zobj, name, &z_copy, cache_slot);
  2693. OBJ_RELEASE(zobj);
  2694. zval_ptr_dtor(&z_copy);
  2695. if (z == &rv) {
  2696. zval_ptr_dtor(z);
  2697. }
  2698. }
  2699. }
  2700. #if (PHP_VERSION_ID <= 80100) && (SIZEOF_SIZE_T == 4)
  2701. static zend_result ZEND_FASTCALL zval_jit_update_constant_ex(zval *p, zend_class_entry *scope)
  2702. {
  2703. if (Z_TYPE_P(p) == IS_CONSTANT_AST) {
  2704. zend_ast *ast = Z_ASTVAL_P(p);
  2705. if (ast->kind == ZEND_AST_CONSTANT) {
  2706. zend_string *name = zend_ast_get_constant_name(ast);
  2707. zval *zv = zend_get_constant_ex(name, scope, ast->attr);
  2708. if (UNEXPECTED(zv == NULL)) {
  2709. return FAILURE;
  2710. }
  2711. zval_ptr_dtor_nogc(p);
  2712. ZVAL_COPY_OR_DUP(p, zv);
  2713. } else {
  2714. zval tmp;
  2715. if (UNEXPECTED(zend_ast_evaluate(&tmp, ast, scope) != SUCCESS)) {
  2716. return FAILURE;
  2717. }
  2718. zval_ptr_dtor_nogc(p);
  2719. ZVAL_COPY_VALUE(p, &tmp);
  2720. }
  2721. }
  2722. return SUCCESS;
  2723. }
  2724. #endif
  2725. static void ZEND_FASTCALL zend_jit_free_trampoline_helper(zend_function *func)
  2726. {
  2727. ZEND_ASSERT(func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE);
  2728. zend_string_release_ex(func->common.function_name, 0);
  2729. zend_free_trampoline(func);
  2730. }
  2731. static void ZEND_FASTCALL zend_jit_exception_in_interrupt_handler_helper(void)
  2732. {
  2733. if (EG(exception)) {
  2734. /* We have to UNDEF result, because ZEND_HANDLE_EXCEPTION is going to free it */
  2735. const zend_op *throw_op = EG(opline_before_exception);
  2736. if (throw_op
  2737. && throw_op->result_type & (IS_TMP_VAR|IS_VAR)
  2738. && throw_op->opcode != ZEND_ADD_ARRAY_ELEMENT
  2739. && throw_op->opcode != ZEND_ADD_ARRAY_UNPACK
  2740. && throw_op->opcode != ZEND_ROPE_INIT
  2741. && throw_op->opcode != ZEND_ROPE_ADD) {
  2742. ZVAL_UNDEF(ZEND_CALL_VAR(EG(current_execute_data), throw_op->result.var));
  2743. }
  2744. }
  2745. }
  2746. static zend_string* ZEND_FASTCALL zend_jit_rope_end(zend_string **rope, uint32_t count)
  2747. {
  2748. zend_string *ret;
  2749. uint32_t i;
  2750. size_t len = 0;
  2751. char *target;
  2752. for (i = 0; i <= count; i++) {
  2753. len += ZSTR_LEN(rope[i]);
  2754. }
  2755. ret = zend_string_alloc(len, 0);
  2756. target = ZSTR_VAL(ret);
  2757. for (i = 0; i <= count; i++) {
  2758. memcpy(target, ZSTR_VAL(rope[i]), ZSTR_LEN(rope[i]));
  2759. target += ZSTR_LEN(rope[i]);
  2760. zend_string_release_ex(rope[i], 0);
  2761. }
  2762. *target = '\0';
  2763. return ret;
  2764. }