Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"stmt if BAREWORD" bypasses strict 'subs' checks #7047

Closed
p5pRT opened this issue Jan 20, 2004 · 7 comments
Closed

"stmt if BAREWORD" bypasses strict 'subs' checks #7047

p5pRT opened this issue Jan 20, 2004 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented Jan 20, 2004

Migrated from rt.perl.org#25147 (status was 'resolved')

Searchable as RT25147$

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2004

From chip@tytlal

Created by chip@pobox.com

The strict 'subs' checks that make barewords illegal are apparently
run *after* constant folding, because this doesn't die​:

  perl -Mstrict=subs -e 'print if foo'

while this does die​:

  perl -Mstrict=subs -e 'print if $a = foo'

Only slightly embarrassing....

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl v5.8.2:

Configured by Debian Project at Sat Nov 15 18:33:34 EST 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 2) configuration:
  Platform:
    osname=linux, osvers=2.4.22-xfs+ti1211, archname=i386-linux-thread-multi
    uname='linux kosh 2.4.22-xfs+ti1211 #1 sat oct 25 10:11:37 est 2003 i686 gnulinux '
    config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i386-linux -Dprefix=/usr -Dprivlib=/usr/share/perl/5.8.2 -Darchlib=/usr/lib/perl/5.8.2 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.8.2 -Dsitearch=/usr/local/lib/perl/5.8.2 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Uusesfio -Uusenm -Duseshrplib -Dlibperl=libperl.so.5.8.2 -Dd_dosuid -des'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O3',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='3.3.2 (Debian)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
    perllibs=-ldl -lm -lpthread -lc -lcrypt
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=true, libperl=libperl.so.5.8.2
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.8.2:
    /u/projects/hms/dat
    /etc/perl
    /usr/local/lib/perl/5.8.2
    /usr/local/share/perl/5.8.2
    /usr/lib/perl5
    /usr/share/perl5
    /usr/lib/perl/5.8.2
    /usr/share/perl/5.8.2
    /usr/local/lib/site_perl
    /usr/local/lib/perl/5.8.1
    /usr/local/share/perl/5.8.1
    /usr/local/share/perl/5.8.0
    .


Environment for perl v5.8.2:
    HOME=/u/home/chip
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/u/home/chip/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/u/projects/hms/dat
    PERL5LIB=:/u/projects/hms/dat
    PERL_BADLANG (unset)
    SHELL=/bin/zsh

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2004

From @rgs

chip@​tytlal (via RT) wrote​:

The strict 'subs' checks that make barewords illegal are apparently
run *after* constant folding, because this doesn't die​:

perl -Mstrict=subs -e 'print if foo'

while this does die​:

perl -Mstrict=subs -e 'print if $a = foo'

as does :

$ bleadperl -Mstrict=subs -we 'print if foo'
Bareword "foo" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.

But :

$ perl5.8.0 -Mstrict=subs -we 'print if foo'
Bareword found in conditional at -e line 1.
Use of uninitialized value in print at -e line 1.

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2004

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2004

From @gisle

Why would running with -w trigger the "Execution aborted due to
compilation errors." message. If it dies it should die just as well
without. And why should it matter whether the condition is "if" or
"unless".

[gisle@​ask gisle]$ perl5.8.3 -e 'use strict; print if foo'

[gisle@​ask gisle]$ perl5.8.3 -we 'use strict; print if foo'
Bareword "foo" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.

[gisle@​ask gisle]$ perl5.8.3 -e 'use strict; print unless foo'
Bareword "foo" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.

[gisle@​ask gisle]$ perl5.8.3 -we 'use strict; print unless foo'
Bareword "foo" not allowed while "strict subs" in use at -e line 1.
Bareword "foo" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.

@p5pRT
Copy link
Author

p5pRT commented Jan 22, 2004

From @iabyn

On Mon, Jan 19, 2004 at 11​:50​:46PM -0800, Gisle Aas wrote​:

Why would running with -w trigger the "Execution aborted due to
compilation errors." message. If it dies it should die just as well
without. And why should it matter whether the condition is "if" or
"unless".

[gisle@​ask gisle]$ perl5.8.3 -e 'use strict; print if foo'

[gisle@​ask gisle]$ perl5.8.3 -we 'use strict; print if foo'
Bareword "foo" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.

[gisle@​ask gisle]$ perl5.8.3 -e 'use strict; print unless foo'
Bareword "foo" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.

[gisle@​ask gisle]$ perl5.8.3 -we 'use strict; print unless foo'
Bareword "foo" not allowed while "strict subs" in use at -e line 1.
Bareword "foo" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.

Fixed by the change below. One code branch was incorrectly protected by
an 'only if warnings enabled' condition.

Anyone know of a good place to add tests for this? A grep of
'Bareword' in all the .t files didn't turn up anything, so possibly
this particular error type is under-tested?

Finally, even with the patch, you still get the duplicate error​:

  $ ./perl -Ilib -we 'use strict; print unless foo'
  Bareword "foo" not allowed while "strict subs" in use at -e line 1.
  Bareword "foo" not allowed while "strict subs" in use at -e line 1.
  Execution of -e aborted due to compilation errors.

This is due to the fact that C<X unless Y> is parsed as C<Y && X>;
the first warning is generated while processing this conditional; then
since Y is a true constant, C<Y && X> is reduced to C<Y>. Then when peep
is called on the whole program in newPROG, the bare constant is seen and
warned about again. I don't know how to fix this. I don't even know
whether it's worth bothering trying to fix it.

Dave

--
"Foul and greedy Dwarf - you have eaten the last candle."
  -- "Hoardes of the Things", BBC Radio.

Change 22194 by davem@​davem-percy on 2004/01/22 00​:24​:51

  [perl #25147] C<use strict; print if foo> didn't give the
  "Bareword not allowed" error unless warnings were enabled

Affected files ...

... //depot/perl/op.c#598 edit

Differences ...

==== //depot/perl/op.c#598 (text) ====

@​@​ -3343,12 +3343,10 @​@​
  }
  }
  if (first->op_type == OP_CONST) {
- if (ckWARN(WARN_BAREWORD) && (first->op_private & OPpCONST_BARE)) {
- if (first->op_private & OPpCONST_STRICT)
- no_bareword_allowed(first);
- else
+ if (first->op_private & OPpCONST_STRICT)
+ no_bareword_allowed(first);
+ else if (ckWARN(WARN_BAREWORD) && (first->op_private & OPpCONST_BARE))
  Perl_warner(aTHX_ packWARN(WARN_BAREWORD), "Bareword found in conditional");
- }
  if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
  op_free(first);
  *firstp = Nullop;

@p5pRT
Copy link
Author

p5pRT commented Jan 25, 2004

From @rgs

Dave Mitchell wrote​:

Anyone know of a good place to add tests for this? A grep of
'Bareword' in all the .t files didn't turn up anything, so possibly
this particular error type is under-tested?

Maybe t/lib/strict/subs ?

@p5pRT p5pRT closed this as completed Feb 1, 2004
@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2004

@iabyn - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant