diff options
author | David Mitchell <davem@iabyn.com> | 2021-10-07 17:15:47 +0100 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2021-10-07 17:31:33 +0100 |
commit | 07a6208729c01c230010594c3e08a946ab0ccbef (patch) | |
tree | c22730559b0cda43ef9ea337f896c6aeb0f2eb1e | |
parent | 2b0c7afada71b2d42dd50ec342a0e9878e4e2ef2 (diff) | |
download | perl-07a6208729c01c230010594c3e08a946ab0ccbef.tar.gz |
add OPpUSEINT op_private flag bit
The bitwise ops, such as a '<<', have an op_private flag that is set
when compiled within the scope of 'use integer;'.
Unfortunately, due to historical reasons, the defined flag that
indicates this bit (bit 0) is HINT_INTEGER rather than an OPpfoo define.
But HINT_INTEGER is supposed to represent a bit within PL_hints, not a bit
within op_private. If someone reorganised the flags in PL_hints at some
point, it would mess up bitwise ops.
So this commit:
1) adds a new flag, OPpUSEINT, to indicate the bit within op_private.
2) Changes this flag's value from 0x1 to 0x4 to force it to be different
than HINT_INTEGER - thus potentially flushing out any misuse of this
flag anywhere (in core or XS code).
3) tells regen/op_private that the lower two bits of op_private in bitwise
ops don't contain the argument count. They never did, but not
specifying that in regen/op_private meant that the debugging code in
op_free() never spotted the unknown bit 0 sometimes being set.
4) Also tell that debugging code to skip the test if the op is banned.
This fixes a new fail in dist/Safe/t/safeops.t which was croaking
about a banned op having an unrecognised op_private flag bit set
before ck_bitop() had a chance to delete the arg count in op_private.
-rw-r--r-- | lib/B/Op_private.pm | 17 | ||||
-rw-r--r-- | op.c | 11 | ||||
-rw-r--r-- | opcode.h | 240 | ||||
-rw-r--r-- | perl.h | 3 | ||||
-rw-r--r-- | pp.c | 16 | ||||
-rw-r--r-- | regen/op_private | 17 |
6 files changed, 160 insertions, 144 deletions
diff --git a/lib/B/Op_private.pm b/lib/B/Op_private.pm index 4c0018a35e..265a9e334f 100644 --- a/lib/B/Op_private.pm +++ b/lib/B/Op_private.pm @@ -158,6 +158,7 @@ $bits{$_}{2} = 'OPpTRANS_IDENTICAL' for qw(trans transr); $bits{$_}{3} = 'OPpTRANS_SQUASH' for qw(trans transr); $bits{$_}{1} = 'OPpTRANS_USE_SVOP' for qw(trans transr); $bits{$_}{5} = 'OPpTRUEBOOL' for qw(grepwhile index length padav padhv pos ref rindex rv2av rv2hv subst); +$bits{$_}{2} = 'OPpUSEINT' for qw(bit_and bit_or bit_xor complement left_shift nbit_and nbit_or nbit_xor ncomplement right_shift sbit_and sbit_or sbit_xor); my @bf = ( { @@ -270,9 +271,6 @@ $bits{avalues}{0} = $bf[0]; $bits{backtick}{0} = $bf[0]; @{$bits{bind}}{3,2,1,0} = ($bf[4], $bf[4], $bf[4], $bf[4]); @{$bits{binmode}}{3,2,1,0} = ($bf[4], $bf[4], $bf[4], $bf[4]); -@{$bits{bit_and}}{1,0} = ($bf[1], $bf[1]); -@{$bits{bit_or}}{1,0} = ($bf[1], $bf[1]); -@{$bits{bit_xor}}{1,0} = ($bf[1], $bf[1]); @{$bits{bless}}{3,2,1,0} = ($bf[4], $bf[4], $bf[4], $bf[4]); @{$bits{caller}}{3,2,1,0} = ($bf[4], $bf[4], $bf[4], $bf[4]); $bits{catch}{0} = $bf[0]; @@ -287,7 +285,6 @@ $bits{chroot}{0} = $bf[0]; $bits{closedir}{0} = $bf[0]; $bits{cmpchain_and}{0} = $bf[0]; $bits{cmpchain_dup}{0} = $bf[0]; -$bits{complement}{0} = $bf[0]; @{$bits{concat}}{6,1,0} = ('OPpCONCAT_NESTED', $bf[1], $bf[1]); $bits{cond_expr}{0} = $bf[0]; @{$bits{connect}}{3,2,1,0} = ($bf[4], $bf[4], $bf[4], $bf[4]); @@ -418,7 +415,6 @@ $bits{leavesub}{0} = $bf[0]; $bits{leavesublv}{0} = $bf[0]; $bits{leavewhen}{0} = $bf[0]; $bits{leavewrite}{0} = $bf[0]; -@{$bits{left_shift}}{1,0} = ($bf[1], $bf[1]); $bits{length}{0} = $bf[0]; @{$bits{link}}{3,2,1,0} = ($bf[4], $bf[4], $bf[4], $bf[4]); $bits{list}{6} = 'OPpLIST_GUESSED'; @@ -447,11 +443,7 @@ $bits{method_super}{0} = $bf[0]; @{$bits{multiconcat}}{6,5,3,0} = ('OPpMULTICONCAT_APPEND', 'OPpMULTICONCAT_FAKE', 'OPpMULTICONCAT_STRINGIFY', $bf[0]); @{$bits{multideref}}{5,4,0} = ('OPpMULTIDEREF_DELETE', 'OPpMULTIDEREF_EXISTS', $bf[0]); @{$bits{multiply}}{1,0} = ($bf[1], $bf[1]); -@{$bits{nbit_and}}{1,0} = ($bf[1], $bf[1]); -@{$bits{nbit_or}}{1,0} = ($bf[1], $bf[1]); -@{$bits{nbit_xor}}{1,0} = ($bf[1], $bf[1]); @{$bits{ncmp}}{1,0} = ($bf[1], $bf[1]); -$bits{ncomplement}{0} = $bf[0]; @{$bits{ne}}{1,0} = ($bf[1], $bf[1]); $bits{negate}{0} = $bf[0]; $bits{next}{0} = $bf[0]; @@ -499,7 +491,6 @@ $bits{require}{0} = $bf[0]; @{$bits{reset}}{3,2,1,0} = ($bf[4], $bf[4], $bf[4], $bf[4]); @{$bits{reverse}}{3,0} = ('OPpREVERSE_INPLACE', $bf[0]); $bits{rewinddir}{0} = $bf[0]; -@{$bits{right_shift}}{1,0} = ($bf[1], $bf[1]); @{$bits{rindex}}{3,2,1,0} = ($bf[4], $bf[4], $bf[4], $bf[4]); $bits{rmdir}{0} = $bf[0]; $bits{rv2av}{0} = $bf[0]; @@ -508,9 +499,6 @@ $bits{rv2av}{0} = $bf[0]; $bits{rv2hv}{0} = 'OPpRV2HV_ISKEYS'; @{$bits{rv2sv}}{5,4,0} = ($bf[8], $bf[8], $bf[0]); @{$bits{sassign}}{7,6,1,0} = ('OPpASSIGN_CV_TO_GV', 'OPpASSIGN_BACKWARDS', $bf[1], $bf[1]); -@{$bits{sbit_and}}{1,0} = ($bf[1], $bf[1]); -@{$bits{sbit_or}}{1,0} = ($bf[1], $bf[1]); -@{$bits{sbit_xor}}{1,0} = ($bf[1], $bf[1]); $bits{scalar}{0} = $bf[0]; $bits{schomp}{0} = $bf[0]; $bits{schop}{0} = $bf[0]; @@ -698,6 +686,7 @@ our %defines = ( OPpTRANS_SQUASH => 8, OPpTRANS_USE_SVOP => 2, OPpTRUEBOOL => 32, + OPpUSEINT => 4, ); our %labels = ( @@ -799,6 +788,7 @@ our %labels = ( OPpTRANS_SQUASH => 'SQUASH', OPpTRANS_USE_SVOP => 'USE_SVOP', OPpTRUEBOOL => 'BOOL', + OPpUSEINT => 'USEINT', ); @@ -850,6 +840,7 @@ our %ops_using = ( OPpTARGET_MY => [qw(abs add atan2 chdir chmod chomp chown chr chroot concat cos crypt divide exec exp flock getpgrp getppid getpriority hex i_add i_divide i_modulo i_multiply i_subtract index int kill left_shift length link log mkdir modulo multiconcat multiply nbit_and nbit_or nbit_xor ncomplement oct ord pow push rand rename right_shift rindex rmdir schomp scomplement setpgrp setpriority sin sleep sqrt srand stringify subtract symlink system time unlink unshift utime wait waitpid)], OPpTRANS_CAN_FORCE_UTF8 => [qw(trans transr)], OPpTRUEBOOL => [qw(grepwhile index length padav padhv pos ref rindex rv2av rv2hv subst)], + OPpUSEINT => [qw(bit_and bit_or bit_xor complement left_shift nbit_and nbit_or nbit_xor ncomplement right_shift sbit_and sbit_or sbit_xor)], ); $ops_using{OPpASSIGN_COMMON_RC1} = $ops_using{OPpASSIGN_COMMON_AGG}; @@ -946,11 +946,15 @@ Perl_op_free(pTHX_ OP *o) * inconsistent state then. Note that an error when * compiling the main program leaves PL_parser NULL, so * we can't spot faults in the main code, only - * evaled/required code */ + * evaled/required code; + * * it's a banned op - we may be croaking before the op is + * fully formed. - see CHECKOP. */ #ifdef DEBUGGING if ( o->op_ppaddr == PL_ppaddr[type] && PL_parser - && !PL_parser->error_count) + && !PL_parser->error_count + && !(PL_op_mask && PL_op_mask[type]) + ) { assert(!(o->op_private & ~PL_op_private_valid[type])); } @@ -12569,7 +12573,8 @@ Perl_ck_bitop(pTHX_ OP *o) { PERL_ARGS_ASSERT_CK_BITOP; - o->op_private = (U8)(PL_hints & HINT_INTEGER); + /* get rid of arg count and indicate if in the scope of 'use integer' */ + o->op_private = (PL_hints & HINT_INTEGER) ? OPpUSEINT : 0; if (!(o->op_flags & OPf_STACKED) /* Not an assignment */ && OP_IS_INFIX_BIT(o->op_type)) @@ -2246,6 +2246,7 @@ END_EXTERN_C #define OPpSORT_REVERSE 0x04 #define OPpSPLIT_IMPLIM 0x04 #define OPpTRANS_IDENTICAL 0x04 +#define OPpUSEINT 0x04 #define OPpARGELEM_MASK 0x06 #define OPpARG3_MASK 0x07 #define OPpPADRANGE_COUNTSHIFT 0x07 @@ -2432,6 +2433,7 @@ EXTCONST char PL_op_private_labels[] = { 'T','A','R','G','\0', 'T','A','R','G','M','Y','\0', 'U','N','I','\0', + 'U','S','E','I','N','T','\0', 'U','S','E','_','S','V','O','P','\0', 'U','T','F','\0', 'k','e','y','\0', @@ -2455,11 +2457,11 @@ EXTCONST char PL_op_private_labels[] = { EXTCONST I16 PL_op_private_bitfields[] = { 0, 8, -1, 0, 8, -1, - 0, 581, -1, + 0, 588, -1, 0, 8, -1, 0, 8, -1, - 0, 588, -1, - 0, 577, -1, + 0, 595, -1, + 0, 584, -1, 1, -1, 0, 545, 1, 30, 2, 295, -1, 4, -1, 1, 176, 2, 183, 3, 190, -1, 4, -1, 0, 545, 1, 30, 2, 295, 3, 122, -1, @@ -2540,8 +2542,8 @@ EXTCONST I16 PL_op_private_bitdef_ix[] = { 84, /* concat */ 87, /* multiconcat */ 93, /* stringify */ - 80, /* left_shift */ - 80, /* right_shift */ + 95, /* left_shift */ + 95, /* right_shift */ 12, /* lt */ 12, /* i_lt */ 12, /* gt */ @@ -2563,20 +2565,20 @@ EXTCONST I16 PL_op_private_bitdef_ix[] = { 12, /* seq */ 12, /* sne */ 12, /* scmp */ - 12, /* bit_and */ - 12, /* bit_xor */ - 12, /* bit_or */ - 80, /* nbit_and */ - 80, /* nbit_xor */ - 80, /* nbit_or */ - 12, /* sbit_and */ - 12, /* sbit_xor */ - 12, /* sbit_or */ + 97, /* bit_and */ + 97, /* bit_xor */ + 97, /* bit_or */ + 95, /* nbit_and */ + 95, /* nbit_xor */ + 95, /* nbit_or */ + 97, /* sbit_and */ + 97, /* sbit_xor */ + 97, /* sbit_or */ 0, /* negate */ 0, /* i_negate */ 0, /* not */ - 0, /* complement */ - 75, /* ncomplement */ + 97, /* complement */ + 95, /* ncomplement */ 75, /* scomplement */ 12, /* smartmatch */ 93, /* atan2 */ @@ -2591,11 +2593,11 @@ EXTCONST I16 PL_op_private_bitdef_ix[] = { 75, /* hex */ 75, /* oct */ 75, /* abs */ - 95, /* length */ - 98, /* substr */ - 101, /* vec */ - 103, /* index */ - 103, /* rindex */ + 98, /* length */ + 101, /* substr */ + 104, /* vec */ + 106, /* index */ + 106, /* rindex */ 52, /* sprintf */ 52, /* formline */ 75, /* ord */ @@ -2606,30 +2608,30 @@ EXTCONST I16 PL_op_private_bitdef_ix[] = { 0, /* uc */ 0, /* lc */ 0, /* quotemeta */ - 107, /* rv2av */ - 114, /* aelemfast */ - 114, /* aelemfast_lex */ - 115, /* aelem */ - 120, /* aslice */ - 123, /* kvaslice */ + 110, /* rv2av */ + 117, /* aelemfast */ + 117, /* aelemfast_lex */ + 118, /* aelem */ + 123, /* aslice */ + 126, /* kvaslice */ 0, /* aeach */ 0, /* avalues */ 40, /* akeys */ 0, /* each */ 40, /* values */ 40, /* keys */ - 124, /* delete */ - 128, /* exists */ - 130, /* rv2hv */ - 115, /* helem */ - 120, /* hslice */ - 123, /* kvhslice */ - 138, /* multideref */ + 127, /* delete */ + 131, /* exists */ + 133, /* rv2hv */ + 118, /* helem */ + 123, /* hslice */ + 126, /* kvhslice */ + 141, /* multideref */ 52, /* unpack */ 52, /* pack */ - 145, /* split */ + 148, /* split */ 52, /* join */ - 150, /* list */ + 153, /* list */ 12, /* lslice */ 52, /* anonlist */ 52, /* anonhash */ @@ -2638,50 +2640,50 @@ EXTCONST I16 PL_op_private_bitdef_ix[] = { 0, /* pop */ 0, /* shift */ 93, /* unshift */ - 152, /* sort */ - 157, /* reverse */ + 155, /* sort */ + 160, /* reverse */ 0, /* grepstart */ - 159, /* grepwhile */ + 162, /* grepwhile */ 0, /* mapstart */ 0, /* mapwhile */ 0, /* range */ - 161, /* flip */ - 161, /* flop */ + 164, /* flip */ + 164, /* flop */ 0, /* and */ 0, /* or */ 12, /* xor */ 0, /* dor */ - 163, /* cond_expr */ + 166, /* cond_expr */ 0, /* andassign */ 0, /* orassign */ 0, /* dorassign */ - 165, /* entersub */ - 172, /* leavesub */ - 172, /* leavesublv */ + 168, /* entersub */ + 175, /* leavesub */ + 175, /* leavesublv */ 0, /* argcheck */ - 174, /* argelem */ + 177, /* argelem */ 0, /* argdefelem */ - 176, /* caller */ + 179, /* caller */ 52, /* warn */ 52, /* die */ 52, /* reset */ -1, /* lineseq */ - 178, /* nextstate */ - 178, /* dbstate */ + 181, /* nextstate */ + 181, /* dbstate */ -1, /* unstack */ -1, /* enter */ - 179, /* leave */ + 182, /* leave */ -1, /* scope */ - 181, /* enteriter */ - 185, /* iter */ + 184, /* enteriter */ + 188, /* iter */ -1, /* enterloop */ - 186, /* leaveloop */ + 189, /* leaveloop */ -1, /* return */ - 188, /* last */ - 188, /* next */ - 188, /* redo */ - 188, /* dump */ - 188, /* goto */ + 191, /* last */ + 191, /* next */ + 191, /* redo */ + 191, /* dump */ + 191, /* goto */ 52, /* exit */ 0, /* method */ 0, /* method_named */ @@ -2694,7 +2696,7 @@ EXTCONST I16 PL_op_private_bitdef_ix[] = { 0, /* leavewhen */ -1, /* break */ -1, /* continue */ - 190, /* open */ + 193, /* open */ 52, /* close */ 52, /* pipe_op */ 52, /* fileno */ @@ -2710,7 +2712,7 @@ EXTCONST I16 PL_op_private_bitdef_ix[] = { 52, /* getc */ 52, /* read */ 52, /* enterwrite */ - 172, /* leavewrite */ + 175, /* leavewrite */ -1, /* prtf */ -1, /* print */ -1, /* say */ @@ -2740,33 +2742,33 @@ EXTCONST I16 PL_op_private_bitdef_ix[] = { 0, /* getpeername */ 0, /* lstat */ 0, /* stat */ - 195, /* ftrread */ - 195, /* ftrwrite */ - 195, /* ftrexec */ - 195, /* fteread */ - 195, /* ftewrite */ - 195, /* fteexec */ - 200, /* ftis */ - 200, /* ftsize */ - 200, /* ftmtime */ - 200, /* ftatime */ - 200, /* ftctime */ - 200, /* ftrowned */ - 200, /* fteowned */ - 200, /* ftzero */ - 200, /* ftsock */ - 200, /* ftchr */ - 200, /* ftblk */ - 200, /* ftfile */ - 200, /* ftdir */ - 200, /* ftpipe */ - 200, /* ftsuid */ - 200, /* ftsgid */ - 200, /* ftsvtx */ - 200, /* ftlink */ - 200, /* fttty */ - 200, /* fttext */ - 200, /* ftbinary */ + 198, /* ftrread */ + 198, /* ftrwrite */ + 198, /* ftrexec */ + 198, /* fteread */ + 198, /* ftewrite */ + 198, /* fteexec */ + 203, /* ftis */ + 203, /* ftsize */ + 203, /* ftmtime */ + 203, /* ftatime */ + 203, /* ftctime */ + 203, /* ftrowned */ + 203, /* fteowned */ + 203, /* ftzero */ + 203, /* ftsock */ + 203, /* ftchr */ + 203, /* ftblk */ + 203, /* ftfile */ + 203, /* ftdir */ + 203, /* ftpipe */ + 203, /* ftsuid */ + 203, /* ftsgid */ + 203, /* ftsvtx */ + 203, /* ftlink */ + 203, /* fttty */ + 203, /* fttext */ + 203, /* ftbinary */ 93, /* chdir */ 93, /* chown */ 75, /* chroot */ @@ -2786,17 +2788,17 @@ EXTCONST I16 PL_op_private_bitdef_ix[] = { 0, /* rewinddir */ 0, /* closedir */ -1, /* fork */ - 204, /* wait */ + 207, /* wait */ 93, /* waitpid */ 93, /* system */ 93, /* exec */ 93, /* kill */ - 204, /* getppid */ + 207, /* getppid */ 93, /* getpgrp */ 93, /* setpgrp */ 93, /* getpriority */ 93, /* setpriority */ - 204, /* time */ + 207, /* time */ -1, /* tms */ 0, /* localtime */ 52, /* gmtime */ @@ -2816,8 +2818,8 @@ EXTCONST I16 PL_op_private_bitdef_ix[] = { 0, /* require */ 0, /* dofile */ -1, /* hintseval */ - 205, /* entereval */ - 172, /* leaveeval */ + 208, /* entereval */ + 175, /* leaveeval */ 0, /* entertry */ -1, /* leavetry */ 0, /* ghbyname */ @@ -2855,18 +2857,18 @@ EXTCONST I16 PL_op_private_bitdef_ix[] = { 0, /* lock */ 0, /* once */ -1, /* custom */ - 211, /* coreargs */ - 215, /* avhvswitch */ + 214, /* coreargs */ + 218, /* avhvswitch */ 3, /* runcv */ 0, /* fc */ -1, /* padcv */ -1, /* introcv */ -1, /* clonecv */ - 217, /* padrange */ - 219, /* refassign */ - 225, /* lvref */ - 231, /* lvrefslice */ - 232, /* lvavref */ + 220, /* padrange */ + 222, /* refassign */ + 228, /* lvref */ + 234, /* lvrefslice */ + 235, /* lvavref */ 0, /* anonconst */ 12, /* isa */ 0, /* cmpchain_and */ @@ -2894,13 +2896,13 @@ EXTCONST I16 PL_op_private_bitdef_ix[] = { */ EXTCONST U16 PL_op_private_bitdefs[] = { - 0x0003, /* scalar, prototype, refgen, srefgen, readline, regcmaybe, regcreset, regcomp, substcont, chop, schop, defined, undef, study, preinc, i_preinc, predec, i_predec, postinc, i_postinc, postdec, i_postdec, negate, i_negate, not, complement, ucfirst, lcfirst, uc, lc, quotemeta, aeach, avalues, each, pop, shift, grepstart, mapstart, mapwhile, range, and, or, dor, andassign, orassign, dorassign, argcheck, argdefelem, method, method_named, method_super, method_redir, method_redir_super, entergiven, leavegiven, enterwhen, leavewhen, untie, tied, dbmclose, getsockname, getpeername, lstat, stat, readlink, readdir, telldir, rewinddir, closedir, localtime, alarm, require, dofile, entertry, ghbyname, gnbyname, gpbyname, shostent, snetent, sprotoent, sservent, gpwnam, gpwuid, ggrnam, ggrgid, lock, once, fc, anonconst, cmpchain_and, cmpchain_dup, entertrycatch, catch, pushdefer */ + 0x0003, /* scalar, prototype, refgen, srefgen, readline, regcmaybe, regcreset, regcomp, substcont, chop, schop, defined, undef, study, preinc, i_preinc, predec, i_predec, postinc, i_postinc, postdec, i_postdec, negate, i_negate, not, ucfirst, lcfirst, uc, lc, quotemeta, aeach, avalues, each, pop, shift, grepstart, mapstart, mapwhile, range, and, or, dor, andassign, orassign, dorassign, argcheck, argdefelem, method, method_named, method_super, method_redir, method_redir_super, entergiven, leavegiven, enterwhen, leavewhen, untie, tied, dbmclose, getsockname, getpeername, lstat, stat, readlink, readdir, telldir, rewinddir, closedir, localtime, alarm, require, dofile, entertry, ghbyname, gnbyname, gpbyname, shostent, snetent, sprotoent, sservent, gpwnam, gpwuid, ggrnam, ggrgid, lock, once, fc, anonconst, cmpchain_and, cmpchain_dup, entertrycatch, catch, pushdefer */ 0x2fdc, 0x40d9, /* pushmark */ 0x00bd, /* wantarray, runcv */ 0x0438, 0x1a50, 0x418c, 0x3d28, 0x3505, /* const */ 0x2fdc, 0x3659, /* gvsv */ 0x18b5, /* gv */ - 0x0067, /* gelem, lt, i_lt, gt, i_gt, le, i_le, ge, i_ge, eq, i_eq, ne, i_ne, ncmp, i_ncmp, slt, sgt, sle, sge, seq, sne, scmp, bit_and, bit_xor, bit_or, sbit_and, sbit_xor, sbit_or, smartmatch, lslice, xor, isa */ + 0x0067, /* gelem, lt, i_lt, gt, i_gt, le, i_le, ge, i_ge, eq, i_eq, ne, i_ne, ncmp, i_ncmp, slt, sgt, sle, sge, seq, sne, scmp, smartmatch, lslice, xor, isa */ 0x2fdc, 0x40d8, 0x03d7, /* padsv */ 0x2fdc, 0x40d8, 0x05b4, 0x30cc, 0x3ea9, /* padav */ 0x2fdc, 0x40d8, 0x05b4, 0x0650, 0x30cc, 0x3ea8, 0x2b41, /* padhv */ @@ -2912,16 +2914,18 @@ EXTCONST U16 PL_op_private_bitdefs[] = { 0x018f, /* bless, glob, sprintf, formline, unpack, pack, join, anonlist, anonhash, splice, warn, die, reset, exit, close, pipe_op, fileno, umask, binmode, tie, dbmopen, sselect, select, getc, read, enterwrite, sysopen, sysseek, sysread, syswrite, eof, tell, seek, truncate, fcntl, ioctl, send, recv, socket, sockpair, bind, connect, listen, accept, shutdown, gsockopt, ssockopt, open_dir, seekdir, gmtime, shmget, shmctl, shmread, shmwrite, msgget, msgctl, msgsnd, msgrcv, semop, semget, semctl, ghbyaddr, gnbyaddr, gpbynumber, gsbyname, gsbyport, syscall */ 0x383c, 0x3758, 0x2894, 0x27d0, 0x0003, /* backtick */ 0x05b5, /* subst */ - 0x117c, 0x21b8, 0x09b4, 0x3fec, 0x2548, 0x4684, 0x07c1, /* trans, transr */ + 0x117c, 0x21b8, 0x09b4, 0x3fec, 0x2548, 0x4764, 0x07c1, /* trans, transr */ 0x0fbc, 0x04d8, 0x0067, /* sassign */ 0x0c78, 0x0b74, 0x0a70, 0x30cc, 0x05a8, 0x0067, /* aassign */ - 0x4530, 0x0003, /* chomp, schomp, ncomplement, scomplement, sin, cos, exp, log, sqrt, int, hex, oct, abs, ord, chr, chroot, rmdir */ + 0x4530, 0x0003, /* chomp, schomp, scomplement, sin, cos, exp, log, sqrt, int, hex, oct, abs, ord, chr, chroot, rmdir */ 0x05b4, 0x30cc, 0x0003, /* pos */ - 0x4530, 0x0067, /* pow, multiply, i_multiply, divide, i_divide, modulo, i_modulo, add, i_add, subtract, i_subtract, left_shift, right_shift, nbit_and, nbit_xor, nbit_or */ + 0x4530, 0x0067, /* pow, multiply, i_multiply, divide, i_divide, modulo, i_modulo, add, i_add, subtract, i_subtract */ 0x1538, 0x0067, /* repeat */ 0x32b8, 0x4530, 0x0067, /* concat */ 0x2fdc, 0x0218, 0x1c34, 0x4530, 0x426c, 0x0003, /* multiconcat */ 0x4530, 0x018f, /* stringify, atan2, rand, srand, crypt, push, unshift, flock, chdir, chown, unlink, chmod, utime, rename, link, symlink, mkdir, waitpid, system, exec, kill, getpgrp, setpgrp, getpriority, setpriority, sleep */ + 0x4530, 0x4689, /* left_shift, right_shift, nbit_and, nbit_xor, nbit_or, ncomplement */ + 0x4689, /* bit_and, bit_xor, bit_or, sbit_and, sbit_xor, sbit_or, complement */ 0x05b4, 0x4530, 0x0003, /* length */ 0x3a90, 0x30cc, 0x012b, /* substr */ 0x30cc, 0x0067, /* vec */ @@ -2951,7 +2955,7 @@ EXTCONST U16 PL_op_private_bitdefs[] = { 0x2fdc, 0x3658, 0x10ec, 0x3c05, /* enteriter */ 0x3c05, /* iter */ 0x2e7c, 0x0067, /* leaveloop */ - 0x47bc, 0x0003, /* last, next, redo, dump, goto */ + 0x489c, 0x0003, /* last, next, redo, dump, goto */ 0x383c, 0x3758, 0x2894, 0x27d0, 0x018f, /* open */ 0x1df0, 0x204c, 0x1f08, 0x1cc4, 0x0003, /* ftrread, ftrwrite, ftrexec, fteread, ftewrite, fteexec */ 0x1df0, 0x204c, 0x1f08, 0x0003, /* ftis, ftsize, ftmtime, ftatime, ftctime, ftrowned, fteowned, ftzero, ftsock, ftchr, ftblk, ftfile, ftdir, ftpipe, ftsuid, ftsgid, ftsvtx, ftlink, fttty, fttext, ftbinary */ @@ -3041,8 +3045,8 @@ EXTCONST U8 PL_op_private_valid[] = { /* CONCAT */ (OPpARG2_MASK|OPpTARGET_MY|OPpCONCAT_NESTED), /* MULTICONCAT */ (OPpARG1_MASK|OPpMULTICONCAT_STRINGIFY|OPpTARGET_MY|OPpMULTICONCAT_FAKE|OPpMULTICONCAT_APPEND|OPpLVAL_INTRO), /* STRINGIFY */ (OPpARG4_MASK|OPpTARGET_MY), - /* LEFT_SHIFT */ (OPpARG2_MASK|OPpTARGET_MY), - /* RIGHT_SHIFT */ (OPpARG2_MASK|OPpTARGET_MY), + /* LEFT_SHIFT */ (OPpUSEINT|OPpTARGET_MY), + /* RIGHT_SHIFT */ (OPpUSEINT|OPpTARGET_MY), /* LT */ (OPpARG2_MASK), /* I_LT */ (OPpARG2_MASK), /* GT */ (OPpARG2_MASK), @@ -3064,20 +3068,20 @@ EXTCONST U8 PL_op_private_valid[] = { /* SEQ */ (OPpARG2_MASK), /* SNE */ (OPpARG2_MASK), /* SCMP */ (OPpARG2_MASK), - /* BIT_AND */ (OPpARG2_MASK), - /* BIT_XOR */ (OPpARG2_MASK), - /* BIT_OR */ (OPpARG2_MASK), - /* NBIT_AND */ (OPpARG2_MASK|OPpTARGET_MY), - /* NBIT_XOR */ (OPpARG2_MASK|OPpTARGET_MY), - /* NBIT_OR */ (OPpARG2_MASK|OPpTARGET_MY), - /* SBIT_AND */ (OPpARG2_MASK), - /* SBIT_XOR */ (OPpARG2_MASK), - /* SBIT_OR */ (OPpARG2_MASK), + /* BIT_AND */ (OPpUSEINT), + /* BIT_XOR */ (OPpUSEINT), + /* BIT_OR */ (OPpUSEINT), + /* NBIT_AND */ (OPpUSEINT|OPpTARGET_MY), + /* NBIT_XOR */ (OPpUSEINT|OPpTARGET_MY), + /* NBIT_OR */ (OPpUSEINT|OPpTARGET_MY), + /* SBIT_AND */ (OPpUSEINT), + /* SBIT_XOR */ (OPpUSEINT), + /* SBIT_OR */ (OPpUSEINT), /* NEGATE */ (OPpARG1_MASK), /* I_NEGATE */ (OPpARG1_MASK), /* NOT */ (OPpARG1_MASK), - /* COMPLEMENT */ (OPpARG1_MASK), - /* NCOMPLEMENT */ (OPpARG1_MASK|OPpTARGET_MY), + /* COMPLEMENT */ (OPpUSEINT), + /* NCOMPLEMENT */ (OPpUSEINT|OPpTARGET_MY), /* SCOMPLEMENT */ (OPpARG1_MASK|OPpTARGET_MY), /* SMARTMATCH */ (OPpARG2_MASK), /* ATAN2 */ (OPpARG4_MASK|OPpTARGET_MY), @@ -5482,8 +5482,7 @@ typedef enum { #define KEY_sigvar 0xFFFF /* fake keyword representing a signature var */ /* Hints are now stored in a dedicated U32, so the bottom 8 bits are no longer - special and there is no need for HINT_PRIVATE_MASK for COPs - However, bitops store HINT_INTEGER in their op_private. + special and there is no need for HINT_PRIVATE_MASK for COPs. NOTE: The typical module using these has the bit value hard-coded, so don't blindly change the values of these. @@ -2038,7 +2038,7 @@ PP(pp_left_shift) svl = TOPs; { const int shift = S_shift_amount(aTHX_ svr); - if (PL_op->op_private & HINT_INTEGER) { + if (PL_op->op_private & OPpUSEINT) { SETi(IV_LEFT_SHIFT(SvIV_nomg(svl), shift)); } else { @@ -2056,7 +2056,7 @@ PP(pp_right_shift) svl = TOPs; { const int shift = S_shift_amount(aTHX_ svr); - if (PL_op->op_private & HINT_INTEGER) { + if (PL_op->op_private & OPpUSEINT) { SETi(IV_RIGHT_SHIFT(SvIV_nomg(svl), shift)); } else { @@ -2361,7 +2361,7 @@ PP(pp_bit_and) if (SvNIOKp(left) || SvNIOKp(right)) { const bool left_ro_nonnum = !SvNIOKp(left) && SvREADONLY(left); const bool right_ro_nonnum = !SvNIOKp(right) && SvREADONLY(right); - if (PL_op->op_private & HINT_INTEGER) { + if (PL_op->op_private & OPpUSEINT) { const IV i = SvIV_nomg(left) & SvIV_nomg(right); SETi(i); } @@ -2386,7 +2386,7 @@ PP(pp_nbit_and) tryAMAGICbin_MG(band_amg, AMGf_assign|AMGf_numarg); { dATARGET; dPOPTOPssrl; - if (PL_op->op_private & HINT_INTEGER) { + if (PL_op->op_private & OPpUSEINT) { const IV i = SvIV_nomg(left) & SvIV_nomg(right); SETi(i); } @@ -2422,7 +2422,7 @@ PP(pp_bit_or) if (SvNIOKp(left) || SvNIOKp(right)) { const bool left_ro_nonnum = !SvNIOKp(left) && SvREADONLY(left); const bool right_ro_nonnum = !SvNIOKp(right) && SvREADONLY(right); - if (PL_op->op_private & HINT_INTEGER) { + if (PL_op->op_private & OPpUSEINT) { const IV l = (USE_LEFT(left) ? SvIV_nomg(left) : 0); const IV r = SvIV_nomg(right); const IV result = op_type == OP_BIT_OR ? (l | r) : (l ^ r); @@ -2456,7 +2456,7 @@ PP(pp_nbit_or) AMGf_assign|AMGf_numarg); { dATARGET; dPOPTOPssrl; - if (PL_op->op_private & HINT_INTEGER) { + if (PL_op->op_private & OPpUSEINT) { const IV l = (USE_LEFT(left) ? SvIV_nomg(left) : 0); const IV r = SvIV_nomg(right); const IV result = op_type == OP_NBIT_OR ? (l | r) : (l ^ r); @@ -2608,7 +2608,7 @@ PP(pp_complement) { dTOPss; if (SvNIOKp(sv)) { - if (PL_op->op_private & HINT_INTEGER) { + if (PL_op->op_private & OPpUSEINT) { const IV i = ~SvIV_nomg(sv); SETi(i); } @@ -2631,7 +2631,7 @@ PP(pp_ncomplement) tryAMAGICun_MG(compl_amg, AMGf_numeric|AMGf_numarg); { dTARGET; dTOPss; - if (PL_op->op_private & HINT_INTEGER) { + if (PL_op->op_private & OPpUSEINT) { const IV i = ~SvIV_nomg(sv); SETi(i); } diff --git a/regen/op_private b/regen/op_private index ea24474308..357b4a1a32 100644 --- a/regen/op_private +++ b/regen/op_private @@ -201,6 +201,13 @@ use strict; $args0{$_} = 1 for qw(entersub avhvswitch rv2hv); # UNOPs that usurp bit 0 + # Historically, bit ops used bit 0 to indicate 'use integer' in scope; + # For now, ban use of bits 0..1 as an arg count, in order to detect + # any residual code which conflates use of the HINT_INTEGER and + # OPpUSEINT flags + + $args0{$_} = 1 for ops_with_check('ck_bitop'); + $args1{$_} = 1 for ( qw(reverse), # ck_fun(), but most bits stolen qw(mapstart grepstart), # set in ck_fun, but @@ -281,6 +288,16 @@ use strict; } +# Are these bit ops in the scope of 'use integer'? +# +# Note that historically they used to use bit 0, which corresponded to +# HINT_INTEGER (a bit flags within PL_hints). We deliberately choose +# a value (2) different than that flag, and different to the two bits used +# to store the argument count, to flush out any residual code which +# conflates the two. + +addbits($_, 2 => qw(OPpUSEINT USEINT)) + for ops_with_check('ck_bitop'); # if NATIVE_HINTS is defined, op_private on cops holds the top 8 bits # of PL_hints, although only bits 6 & 7 are officially used for that |