+ {
+ dA_MAP_THX;
+ const a_op_info *oi = a_map_fetch(PL_op);
+ XSH_ASSERT(oi);
+ flags = a_do_multideref(PL_op, oi->flags);
+ if (!flags)
+ return oi->old_pp(aTHX);
+ }
+
+ items = cUNOP_AUXx(PL_op)->op_aux;
+ actions = items->uv;
+
+ PL_multideref_pc = items;
+
+ while (1) {
+ switch (actions & MDEREF_ACTION_MASK) {
+ case MDEREF_reload:
+ actions = (++items)->uv;
+ continue;
+ case MDEREF_AV_padav_aelem: /* $lex[...] */
+ sv = PAD_SVl((++items)->pad_offset);
+ if (a_undef(sv))
+ goto ret_undef;
+ goto do_AV_aelem;
+ case MDEREF_AV_gvav_aelem: /* $pkg[...] */
+ sv = UNOP_AUX_item_sv(++items);
+ XSH_ASSERT(isGV_with_GP(sv));
+ sv = (SV *) GvAVn((GV *) sv);
+ if (a_undef(sv))
+ goto ret_undef;
+ goto do_AV_aelem;
+ case MDEREF_AV_pop_rv2av_aelem: /* expr->[...] */
+ sv = POPs;
+ if (a_undef(sv))
+ goto ret_undef;
+ goto do_AV_rv2av_aelem;
+ case MDEREF_AV_gvsv_vivify_rv2av_aelem: /* $pkg->[...] */
+ sv = UNOP_AUX_item_sv(++items);
+ XSH_ASSERT(isGV_with_GP(sv));
+ sv = GvSVn((GV *) sv);
+ if (a_undef(sv))
+ goto ret_undef;
+ goto do_AV_vivify_rv2av_aelem;
+ case MDEREF_AV_padsv_vivify_rv2av_aelem: /* $lex->[...] */
+ sv = PAD_SVl((++items)->pad_offset);
+ /* FALLTHROUGH */
+ case MDEREF_AV_vivify_rv2av_aelem: /* vivify, ->[...] */
+ if (a_undef(sv))
+ goto ret_undef;
+do_AV_vivify_rv2av_aelem:
+ sv = a_vivify_ref(sv, 0);
+do_AV_rv2av_aelem:
+ sv = a_do_pp_rv2av(sv);
+do_AV_aelem:
+ {
+ SV *esv;
+ XSH_ASSERT(SvTYPE(sv) == SVt_PVAV);
+ switch (actions & MDEREF_INDEX_MASK) {
+ case MDEREF_INDEX_none:
+ goto finish;
+ case MDEREF_INDEX_const:
+ esv = sv_2mortal(newSViv((++items)->iv));
+ break;
+ case MDEREF_INDEX_padsv:
+ esv = PAD_SVl((++items)->pad_offset);
+ goto check_elem;
+ case MDEREF_INDEX_gvsv:
+ esv = UNOP_AUX_item_sv(++items);
+ XSH_ASSERT(isGV_with_GP(esv));
+ esv = GvSVn((GV *) esv);
+check_elem:
+ if (UNLIKELY(SvROK(esv) && !SvGAMAGIC(esv) && ckWARN(WARN_MISC)))
+ Perl_warner(aTHX_ packWARN(WARN_MISC),
+ "Use of reference \"%"SVf"\" as array index",
+ SVfARG(esv));
+ break;
+ }
+ PL_multideref_pc = items;
+ if (actions & MDEREF_FLAG_last) {
+ switch (flags & A_HINT_DO) {
+ case A_HINT_FETCH:
+ sv = a_do_pp_afetch(sv, esv);
+ break;
+ case A_HINT_STORE:
+ sv = a_do_pp_afetch_lv(sv, esv);
+ break;
+ case A_HINT_EXISTS:
+ sv = a_do_pp_aexists(sv, esv);
+ break;
+ case A_HINT_DELETE:
+ sv = a_do_pp_adelete(sv, esv);
+ break;
+ }
+ goto finish;
+ }
+ sv = a_do_pp_afetch(sv, esv);
+ break;
+ }
+ case MDEREF_HV_padhv_helem: /* $lex{...} */
+ sv = PAD_SVl((++items)->pad_offset);
+ if (a_undef(sv))
+ goto ret_undef;
+ goto do_HV_helem;
+ case MDEREF_HV_gvhv_helem: /* $pkg{...} */
+ sv = UNOP_AUX_item_sv(++items);
+ XSH_ASSERT(isGV_with_GP(sv));
+ sv = (SV *) GvHVn((GV *) sv);
+ if (a_undef(sv))
+ goto ret_undef;
+ goto do_HV_helem;
+ case MDEREF_HV_pop_rv2hv_helem: /* expr->{...} */
+ sv = POPs;
+ if (a_undef(sv))
+ goto ret_undef;
+ goto do_HV_rv2hv_helem;
+ case MDEREF_HV_gvsv_vivify_rv2hv_helem: /* $pkg->{...} */
+ sv = UNOP_AUX_item_sv(++items);
+ XSH_ASSERT(isGV_with_GP(sv));
+ sv = GvSVn((GV *) sv);
+ if (a_undef(sv))
+ goto ret_undef;
+ goto do_HV_vivify_rv2hv_helem;
+ case MDEREF_HV_padsv_vivify_rv2hv_helem: /* $lex->{...} */
+ sv = PAD_SVl((++items)->pad_offset);
+ /* FALLTHROUGH */
+ case MDEREF_HV_vivify_rv2hv_helem: /* vivify, ->{...} */
+ if (a_undef(sv))
+ goto ret_undef;
+do_HV_vivify_rv2hv_helem:
+ sv = a_vivify_ref(sv, 1);
+do_HV_rv2hv_helem:
+ sv = a_do_pp_rv2hv(sv);
+do_HV_helem:
+ {
+ SV *key;
+ XSH_ASSERT(SvTYPE(sv) == SVt_PVHV);
+ switch (actions & MDEREF_INDEX_MASK) {
+ case MDEREF_INDEX_none:
+ goto finish;
+ case MDEREF_INDEX_const:
+ key = UNOP_AUX_item_sv(++items);
+ break;
+ case MDEREF_INDEX_padsv:
+ key = PAD_SVl((++items)->pad_offset);
+ break;
+ case MDEREF_INDEX_gvsv:
+ key = UNOP_AUX_item_sv(++items);
+ XSH_ASSERT(isGV_with_GP(key));
+ key = GvSVn((GV *) key);
+ break;
+ }
+ PL_multideref_pc = items;
+ if (actions & MDEREF_FLAG_last) {
+ switch (flags & A_HINT_DO) {
+ case A_HINT_FETCH:
+ sv = a_do_pp_hfetch(sv, key);
+ break;
+ case A_HINT_STORE:
+ sv = a_do_pp_hfetch_lv(sv, key);
+ break;
+ case A_HINT_EXISTS:
+ sv = a_do_pp_hexists(sv, key);
+ break;
+ case A_HINT_DELETE:
+ sv = a_do_pp_hdelete(sv, key);
+ break;
+ default:
+ break;
+ }
+ goto finish;
+ }
+ sv = a_do_pp_hfetch(sv, key);
+ break;
+ }
+ }
+
+ actions >>= MDEREF_SHIFT;
+ }
+
+ret_undef:
+ if (flags & (A_HINT_NOTIFY|A_HINT_STORE))
+ a_cannot_vivify(flags);
+ if (flags & A_HINT_EXISTS)
+ sv = &PL_sv_no;
+ else
+ sv = &PL_sv_undef;
+finish:
+ XPUSHs(sv);
+ RETURN;
+}
+
+#endif /* A_HAS_MULTIDEREF */
+
+/* --- Check functions ----------------------------------------------------- */
+
+static void a_recheck_rv2xv(pTHX_ OP *o, OPCODE type, OP *(*new_pp)(pTHX)) {
+#define a_recheck_rv2xv(O, T, PP) a_recheck_rv2xv(aTHX_ (O), (T), (PP))
+
+ if (o->op_type == type && o->op_ppaddr != new_pp
+ && cUNOPo->op_first->op_type != OP_GV) {
+ dA_MAP_THX;
+ const a_op_info *oi = a_map_fetch(o);
+ if (oi) {
+ a_map_store(o, o->op_ppaddr, oi->next, oi->flags);
+ o->op_ppaddr = new_pp;
+ }
+ }
+
+ return;
+}
+
+/* ... ck_pad{any,sv} ...................................................... */
+
+/* Sadly, the padsv OPs we are interested in don't trigger the padsv check
+ * function, but are instead manually mutated from a padany. So we store
+ * the op entry in the op map in the padany check function, and we set their
+ * op_ppaddr member in our peephole optimizer replacement below. */
+
+static OP *(*a_old_ck_padany)(pTHX_ OP *) = 0;