Filetest ops don't always expect an op on the stack, so we should use
TOPs only if we're sure that we're not stat'ing the _ filehandle.
This is indicated by OPf_KIDS (as checked in ck_ftst).
#define tryAMAGICftest(chr) \
STMT_START { \
assert(chr != '?'); \
- if (SvAMAGIC(TOPs)) { \
+ if ((PL_op->op_flags & OPf_KIDS) \
+ && SvAMAGIC(TOPs)) { \
const char tmpchr = (chr); \
SV * const tmpsv = amagic_call(TOPs, \
newSVpvn_flags(&tmpchr, 1, SVs_TEMP), \