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

[PATCH] Add -DO option to disable optimizations and disable constant folding and the peephole optimizer when used. #11606

Closed
p5pRT opened this issue Aug 28, 2011 · 13 comments

Comments

@p5pRT
Copy link

p5pRT commented Aug 28, 2011

Migrated from rt.perl.org#97942 (status was 'open')

Searchable as RT97942$

@p5pRT
Copy link
Author

p5pRT commented Aug 28, 2011

From gerard@ggoossen.net

This is a bug report for perl from gerard@​ggoossen.net,
generated with the help of perlbug 1.39 running under perl 5.15.2.

From aa47563c38380baa2e72acca68124d8b796a4b9e Mon Sep 17 00​:00​:00 2001
From​: Gerard Goossen <gerard@​ggoossen.net>
Date​: Sat, 27 Aug 2011 16​:48​:38 +0200
Subject​: [PATCH] Add -DO option to disable optimizations and disable constant
folding and the peephole optimizer when used.

Running the tests with PERL5OPT_TEST=-DOq reveals the following
problems​:
- overloaded <> causes strange error
- deref type detection in derefed lvalue subs goes wrong.
- constant expressions produce modifiable temporaries instead of
  read-only constants
- for (revert @​a) does no longer alias the elements of @​a
- warnings about uninitialized values miss some variable names
- limits $[ assignments which are possible
- problem with line numbers in coresubs errors


op.c | 4 ++++
perl.c | 5 +++--
perl.h | 8 +++++++-
pod/perlrun.pod | 1 +
4 files changed, 15 insertions(+), 3 deletions(-)

Inline Patch
diff --git a/op.c b/op.c
index 73dccf8..c292b7b 100644
--- a/op.c
+++ b/op.c
@@ -2948,6 +2948,8 @@ S_fold_constants(pTHX_ register OP *o)
 	break;
     }
 
+    DEBUG_O( goto nope );
+
     if (PL_parser && PL_parser->error_count)
 	goto nope;		/* Don't try to run w/ errors */
 
@@ -9726,6 +9728,8 @@ Perl_rpeep(pTHX_ register OP *o)
     int defer_base = 0;
     int defer_ix = -1;
 
+    DEBUG_O( return );
+
     if (!o || o->op_opt)
 	return;
     ENTER;
diff --git a/perl.c b/perl.c
index 9ebb3d2..a5bbf41 100644
--- a/perl.c
+++ b/perl.c
@@ -2949,7 +2949,8 @@ Perl_get_debug_opts(pTHX_ const char **s, bool givehelp)
       "  A  Consistency checks on internal structures\n"
       "  q  quiet - currently only suppresses the 'EXECUTING' message\n"
       "  M  trace smart match resolution\n"
-      "  B  dump suBroutine definitions, including special Blocks like BEGIN\n",
+      "  B  dump suBroutine definitions, including special Blocks like BEGIN\n"
+      "  O  Disable optimizations\n",
       NULL
     };
     int i = 0;
@@ -2958,7 +2959,7 @@ Perl_get_debug_opts(pTHX_ const char **s, bool givehelp)
 
     if (isALPHA(**s)) {
 	/* if adding extra options, remember to update DEBUG_MASK */
-	static const char debopts[] = "psltocPmfrxuUHXDSTRJvCAqMB";
+	static const char debopts[] = "psltocPmfrxuUHXDSTRJvCAqMBO";
 
 	for (; isALNUM(**s); (*s)++) {
 	    const char * const d = strchr(debopts,**s);
diff --git a/perl.h b/perl.h
index 30bee51..86e0b96 100644
--- a/perl.h
+++ b/perl.h
@@ -3675,7 +3675,8 @@ Gid_t getegid (void);
 #define DEBUG_q_FLAG		0x00800000 /*8388608 */
 #define DEBUG_M_FLAG		0x01000000 /*16777216*/
 #define DEBUG_B_FLAG		0x02000000 /*33554432*/
-#define DEBUG_MASK		0x03FEEFFF /* mask of all the standard flags */
+#define DEBUG_O_FLAG		0x04000000 /*67108864*/
+#define DEBUG_MASK		0x07FEEFFF /* mask of all the standard flags */
 
 #define DEBUG_DB_RECURSE_FLAG	0x40000000
 #define DEBUG_TOP_FLAG		0x80000000 /* XXX what's this for ??? Signal
@@ -3706,6 +3707,7 @@ Gid_t getegid (void);
 #  define DEBUG_q_TEST_ (PL_debug & DEBUG_q_FLAG)
 #  define DEBUG_M_TEST_ (PL_debug & DEBUG_M_FLAG)
 #  define DEBUG_B_TEST_ (PL_debug & DEBUG_B_FLAG)
+#  define DEBUG_O_TEST_ (PL_debug & DEBUG_O_FLAG)
 #  define DEBUG_Xv_TEST_ (DEBUG_X_TEST_ && DEBUG_v_TEST_)
 #  define DEBUG_Uv_TEST_ (DEBUG_U_TEST_ && DEBUG_v_TEST_)
 #  define DEBUG_Pv_TEST_ (DEBUG_P_TEST_ && DEBUG_v_TEST_)
@@ -3737,6 +3739,7 @@ Gid_t getegid (void);
 #  define DEBUG_q_TEST DEBUG_q_TEST_
 #  define DEBUG_M_TEST DEBUG_M_TEST_
 #  define DEBUG_B_TEST DEBUG_B_TEST_
+#  define DEBUG_O_TEST DEBUG_O_TEST_
 #  define DEBUG_Xv_TEST DEBUG_Xv_TEST_
 #  define DEBUG_Uv_TEST DEBUG_Uv_TEST_
 #  define DEBUG_Pv_TEST DEBUG_Pv_TEST_
@@ -3787,6 +3790,7 @@ Gid_t getegid (void);
 #  define DEBUG_q(a) DEBUG__(DEBUG_q_TEST, a)
 #  define DEBUG_M(a) DEBUG__(DEBUG_M_TEST, a)
 #  define DEBUG_B(a) DEBUG__(DEBUG_B_TEST, a)
+#  define DEBUG_O(a) DEBUG__(DEBUG_O_TEST, a)
 
 #else /* DEBUGGING */
 
@@ -3815,6 +3819,7 @@ Gid_t getegid (void);
 #  define DEBUG_q_TEST (0)
 #  define DEBUG_M_TEST (0)
 #  define DEBUG_B_TEST (0)
+#  define DEBUG_O_TEST (0)
 #  define DEBUG_Xv_TEST (0)
 #  define DEBUG_Uv_TEST (0)
 #  define DEBUG_Pv_TEST (0)
@@ -3845,6 +3850,7 @@ Gid_t getegid (void);
 #  define DEBUG_q(a)
 #  define DEBUG_M(a)
 #  define DEBUG_B(a)
+#  define DEBUG_O(a)
 #  define DEBUG_Xv(a)
 #  define DEBUG_Uv(a)
 #  define DEBUG_Pv(a)
diff --git a/pod/perlrun.pod b/pod/perlrun.pod
index 22f50cc..d257d71 100644
--- a/pod/perlrun.pod
+++ b/pod/perlrun.pod
@@ -412,6 +412,7 @@ B<-D14> is equivalent to B<-Dtls>):
  16777216  M  trace smart match resolution
  33554432  B  dump suBroutine definitions, including special Blocks
               like BEGIN
+ 67108864  O  Disable optimizations
 
 All these flags require B<-DDEBUGGING> when you compile the Perl
 executable (but see C<:opd> in L<Devel::Peek> or L<re/'debug' mode>
-- 
1.7.5.4

Flags​:
  category=core
  severity=low


Site configuration information for perl 5.15.2​:

Configured by gerard at Sun Aug 28 16​:17​:23 CEST 2011.

Summary of my perl5 (revision 5 version 15 subversion 2) configuration​:
  Commit id​: c0c395809b8aa0c7e04dcad158a717b895d61c51
  Platform​:
  osname=linux, osvers=3.0.0-1-686-pae, archname=i686-linux-thread-multi
  uname='linux zeus 3.0.0-1-686-pae #1 smp sun jul 24 14​:27​:32 utc 2011 i686 gnulinux '
  config_args='-des -Dusethreads -Dnoextensions= -Doptimize=-O3 -g3 -DDEBUGGING -Dusedevel -Dprefix=/home/gerard/perl/inst/blead-codegen'
  hint=recommended, useposix=true, d_sigaction=define
  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 -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-O3 -g3',
  cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
  ccversion='', gccversion='4.6.1', 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 =' -fstack-protector -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib /usr/lib/i386-linux-gnu /usr/lib64
  libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
  perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
  libc=, so=so, useshrplib=false, libperl=libperl.a
  gnulibc_version='2.13'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
  cccdlflags='-fPIC', lddlflags='-shared -O3 -g3 -L/usr/local/lib -fstack-protector'

Locally applied patches​:
 


@​INC for perl 5.15.2​:
  lib
  /home/gerard/perl/inst/blead-codegen/lib/site_perl/5.15.2/i686-linux-thread-multi
  /home/gerard/perl/inst/blead-codegen/lib/site_perl/5.15.2
  /home/gerard/perl/inst/blead-codegen/lib/5.15.2/i686-linux-thread-multi
  /home/gerard/perl/inst/blead-codegen/lib/5.15.2
  /home/gerard/perl/inst/blead-codegen/lib/site_perl
  .


Environment for perl 5.15.2​:
  HOME=/home/gerard
  LANG=en_US.UTF-8
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/home/gerard/bin​:/usr/local/bin​:/usr/bin​:/bin​:/usr/games
  PERL_BADLANG (unset)
  SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Aug 29, 2011

From @cpansprout

On Sun Aug 28 07​:48​:48 2011, ggoossen wrote​:

This is a bug report for perl from gerard@​ggoossen.net,
generated with the help of perlbug 1.39 running under perl 5.15.2.

From aa47563c38380baa2e72acca68124d8b796a4b9e Mon Sep 17 00​:00​:00 2001
From​: Gerard Goossen <gerard@​ggoossen.net>
Date​: Sat, 27 Aug 2011 16​:48​:38 +0200
Subject​: [PATCH] Add -DO option to disable optimizations and disable
constant
folding and the peephole optimizer when used.

Running the tests with PERL5OPT_TEST=-DOq reveals the following
problems​:
- overloaded <> causes strange error
- deref type detection in derefed lvalue subs goes wrong.
- constant expressions produce modifiable temporaries instead of
read-only constants
- for (revert @​a) does no longer alias the elements of @​a
- warnings about uninitialized values miss some variable names
- limits $[ assignments which are possible
- problem with line numbers in coresubs errors

If it still has problems, do we really want to apply it yet?

@p5pRT
Copy link
Author

p5pRT commented Aug 29, 2011

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

@p5pRT
Copy link
Author

p5pRT commented Aug 29, 2011

From @obra

On Sun, Aug 28, 2011 at 06​:12​:25PM -0700, Father Chrysostomos via RT wrote​:

On Sun Aug 28 07​:48​:48 2011, ggoossen wrote​:

This is a bug report for perl from gerard@​ggoossen.net,
generated with the help of perlbug 1.39 running under perl 5.15.2.

From aa47563c38380baa2e72acca68124d8b796a4b9e Mon Sep 17 00​:00​:00 2001
From​: Gerard Goossen <gerard@​ggoossen.net>
Date​: Sat, 27 Aug 2011 16​:48​:38 +0200
Subject​: [PATCH] Add -DO option to disable optimizations and disable
constant
folding and the peephole optimizer when used.

Running the tests with PERL5OPT_TEST=-DOq reveals the following
problems​:
- overloaded <> causes strange error
- deref type detection in derefed lvalue subs goes wrong.
- constant expressions produce modifiable temporaries instead of
read-only constants
- for (revert @​a) does no longer alias the elements of @​a
- warnings about uninitialized values miss some variable names
- limits $[ assignments which are possible
- problem with line numbers in coresubs errors

If it still has problems, do we really want to apply it yet?

I'd certainly prefer that we not apply such patches to blead.

--

@p5pRT
Copy link
Author

p5pRT commented Aug 29, 2011

@cpansprout - Status changed from 'open' to 'rejected'

@p5pRT p5pRT closed this as completed Aug 29, 2011
@p5pRT
Copy link
Author

p5pRT commented Sep 1, 2011

@cpansprout - Status changed from 'rejected' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Sep 1, 2011

From @cpansprout

I’m reopening this, as Gerard is actively working on fixing the issues.

@p5pRT
Copy link
Author

p5pRT commented Nov 27, 2011

From @cpansprout

On Sun Aug 28 07​:48​:48 2011, ggoossen wrote​:

This is a bug report for perl from gerard@​ggoossen.net,
generated with the help of perlbug 1.39 running under perl 5.15.2.

From aa47563c38380baa2e72acca68124d8b796a4b9e Mon Sep 17 00​:00​:00 2001
From​: Gerard Goossen <gerard@​ggoossen.net>
Date​: Sat, 27 Aug 2011 16​:48​:38 +0200
Subject​: [PATCH] Add -DO option to disable optimizations and disable
constant
folding and the peephole optimizer when used.

Running the tests with PERL5OPT_TEST=-DOq reveals the following
problems​:
- overloaded <> causes strange error
- deref type detection in derefed lvalue subs goes wrong.
- constant expressions produce modifiable temporaries instead of
read-only constants
- for (revert @​a) does no longer alias the elements of @​a
- warnings about uninitialized values miss some variable names
- limits $[ assignments which are possible
- problem with line numbers in coresubs errors
---
op.c | 4 ++++
perl.c | 5 +++--
perl.h | 8 +++++++-
pod/perlrun.pod | 1 +
4 files changed, 15 insertions(+), 3 deletions(-)

I tried applying this patch again, but it still causes test failures
under the new option. Were you planning to address those?

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Jul 18, 2013

From @nthykier

Hi,

Some of these failures are caused by the mere presence of "-D" or "-Dq"
in PERL5OPT(_TEST). I have attached a patch for these tests.

I also rebased the original patch against the current blead.

~Niels

@p5pRT
Copy link
Author

p5pRT commented Jul 18, 2013

From @nthykier

0001-Add-DO-option-to-disable-optimizations-and-disable-c.patch
From eb119268bed14aedc648d1ffde8453885ddc8c4f Mon Sep 17 00:00:00 2001
From: Gerard Goossen <gerard@ggoossen.net>
Date: Sat, 27 Aug 2011 16:48:38 +0200
Subject: [PATCH] Add -DO option to disable optimizations and disable constant
 folding and the peephole optimizer when used.

Running the tests with PERL5OPT_TEST=-DOq reveals the following
problems:
- overloaded <> causes strange error
- deref type detection in derefed lvalue subs goes wrong.
- constant expressions produce modifiable temporaries instead of
  read-only constants
- for (revert @a) does no longer alias the elements of @a
- warnings about uninitialized values miss some variable names
- limits $[ assignments which are possible
- problem with line numbers in coresubs errors
---
 op.c            |    4 ++++
 perl.c          |    5 +++--
 perl.h          |    8 +++++++-
 pod/perlrun.pod |    1 +
 4 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/op.c b/op.c
index d5323a0..6822f5c 100644
--- a/op.c
+++ b/op.c
@@ -3259,6 +3259,8 @@ S_fold_constants(pTHX_ OP *o)
 	if (o->op_private & OPpREPEAT_DOLIST) goto nope;
     }
 
+    DEBUG_O( goto nope );
+
     if (PL_parser && PL_parser->error_count)
 	goto nope;		/* Don't try to run w/ errors */
 
@@ -10846,6 +10848,8 @@ Perl_rpeep(pTHX_ OP *o)
     int defer_base = 0;
     int defer_ix = -1;
 
+    DEBUG_O( return );
+
     if (!o || o->op_opt)
 	return;
     ENTER;
diff --git a/perl.c b/perl.c
index ee36fd1..b6145e5 100644
--- a/perl.c
+++ b/perl.c
@@ -3115,7 +3115,8 @@ Perl_get_debug_opts(pTHX_ const char **s, bool givehelp)
       "  A  Consistency checks on internal structures\n"
       "  q  quiet - currently only suppresses the 'EXECUTING' message\n"
       "  M  trace smart match resolution\n"
-      "  B  dump suBroutine definitions, including special Blocks like BEGIN\n",
+      "  B  dump suBroutine definitions, including special Blocks like BEGIN\n"
+      "  O  Disable optimizations\n",
       NULL
     };
     int i = 0;
@@ -3124,7 +3125,7 @@ Perl_get_debug_opts(pTHX_ const char **s, bool givehelp)
 
     if (isALPHA(**s)) {
 	/* if adding extra options, remember to update DEBUG_MASK */
-	static const char debopts[] = "psltocPmfrxuUHXDSTRJvCAqMB";
+	static const char debopts[] = "psltocPmfrxuUHXDSTRJvCAqMBO";
 
 	for (; isWORDCHAR(**s); (*s)++) {
 	    const char * const d = strchr(debopts,**s);
diff --git a/perl.h b/perl.h
index cfcf871..8a7055d 100644
--- a/perl.h
+++ b/perl.h
@@ -3543,7 +3543,8 @@ Gid_t getegid (void);
 #define DEBUG_q_FLAG		0x00800000 /*8388608 */
 #define DEBUG_M_FLAG		0x01000000 /*16777216*/
 #define DEBUG_B_FLAG		0x02000000 /*33554432*/
-#define DEBUG_MASK		0x03FFEFFF /* mask of all the standard flags */
+#define DEBUG_O_FLAG		0x04000000 /*67108864*/
+#define DEBUG_MASK		0x07FFEFFF /* mask of all the standard flags */
 
 #define DEBUG_DB_RECURSE_FLAG	0x40000000
 #define DEBUG_TOP_FLAG		0x80000000 /* XXX what's this for ??? Signal
@@ -3575,6 +3576,7 @@ Gid_t getegid (void);
 #  define DEBUG_q_TEST_ (PL_debug & DEBUG_q_FLAG)
 #  define DEBUG_M_TEST_ (PL_debug & DEBUG_M_FLAG)
 #  define DEBUG_B_TEST_ (PL_debug & DEBUG_B_FLAG)
+#  define DEBUG_O_TEST_ (PL_debug & DEBUG_O_FLAG)
 #  define DEBUG_Xv_TEST_ (DEBUG_X_TEST_ && DEBUG_v_TEST_)
 #  define DEBUG_Uv_TEST_ (DEBUG_U_TEST_ && DEBUG_v_TEST_)
 #  define DEBUG_Pv_TEST_ (DEBUG_P_TEST_ && DEBUG_v_TEST_)
@@ -3607,6 +3609,7 @@ Gid_t getegid (void);
 #  define DEBUG_q_TEST DEBUG_q_TEST_
 #  define DEBUG_M_TEST DEBUG_M_TEST_
 #  define DEBUG_B_TEST DEBUG_B_TEST_
+#  define DEBUG_O_TEST DEBUG_O_TEST_
 #  define DEBUG_Xv_TEST DEBUG_Xv_TEST_
 #  define DEBUG_Uv_TEST DEBUG_Uv_TEST_
 #  define DEBUG_Pv_TEST DEBUG_Pv_TEST_
@@ -3658,6 +3661,7 @@ Gid_t getegid (void);
 #  define DEBUG_q(a) DEBUG__(DEBUG_q_TEST, a)
 #  define DEBUG_M(a) DEBUG__(DEBUG_M_TEST, a)
 #  define DEBUG_B(a) DEBUG__(DEBUG_B_TEST, a)
+#  define DEBUG_O(a) DEBUG__(DEBUG_O_TEST, a)
 
 #else /* DEBUGGING */
 
@@ -3687,6 +3691,7 @@ Gid_t getegid (void);
 #  define DEBUG_q_TEST (0)
 #  define DEBUG_M_TEST (0)
 #  define DEBUG_B_TEST (0)
+#  define DEBUG_O_TEST (0)
 #  define DEBUG_Xv_TEST (0)
 #  define DEBUG_Uv_TEST (0)
 #  define DEBUG_Pv_TEST (0)
@@ -3718,6 +3723,7 @@ Gid_t getegid (void);
 #  define DEBUG_q(a)
 #  define DEBUG_M(a)
 #  define DEBUG_B(a)
+#  define DEBUG_O(a)
 #  define DEBUG_Xv(a)
 #  define DEBUG_Uv(a)
 #  define DEBUG_Pv(a)
diff --git a/pod/perlrun.pod b/pod/perlrun.pod
index 05dea4e..749eb23 100644
--- a/pod/perlrun.pod
+++ b/pod/perlrun.pod
@@ -414,6 +414,7 @@ B<-D14> is equivalent to B<-Dtls>):
  16777216  M  trace smart match resolution
  33554432  B  dump suBroutine definitions, including special Blocks
               like BEGIN
+ 67108864  O  Disable optimizations
 
 All these flags require B<-DDEBUGGING> when you compile the Perl
 executable (but see C<:opd> in L<Devel::Peek> or L<re/'debug' mode>
-- 
1.7.10.4

@p5pRT
Copy link
Author

p5pRT commented Jul 18, 2013

From @nthykier

fix-test-failure-with-D-in-PERL5OPT.diff
diff --git a/t/op/split.t b/t/op/split.t
index 7e0008e..125840f 100644
--- a/t/op/split.t
+++ b/t/op/split.t
@@ -78,9 +78,18 @@ $_ = "1 2 3 4";
 $_ = join(':', split);
 is($_ , '1:2:3:4', "Split and join without specifying a split pattern");
 
-# Does assignment to a list imply split to one more field than that?
-$foo = runperl( switches => ['-Dt'], stderr => 1, prog => '($a,$b)=split;' );
-ok($foo =~ /DEBUGGING/ || $foo =~ /const\n?\Q(IV(3))\E/);
+{
+    my @env_Dopts;
+    if (exists $ENV{'PERL5OPT'}) {
+        while ($ENV{'PERL5OPT'} =~ s/-D([^ :]*)//) {
+            push @env_Dopts, "-D$1";
+        }
+    }
+
+    # Does assignment to a list imply split to one more field than that?
+    $foo = runperl( switches => [@env_Dopts, '-Dt'], stderr => 1, prog => '($a,$b)=split;' );
+    ok($foo =~ /DEBUGGING/ || $foo =~ /const\n?\Q(IV(3))\E/);
+}
 
 # Can we say how many fields to split to when assigning to a list?
 ($a,$b) = split(' ','1 2 3 4 5 6', 2);
diff --git a/t/re/pat_re_eval.t b/t/re/pat_re_eval.t
index e47aaf3..0e9f86e 100644
--- a/t/re/pat_re_eval.t
+++ b/t/re/pat_re_eval.t
@@ -991,6 +991,12 @@ sub run_tests {
 
     {
 	my $out;
+        my @env_Dopts;
+        if (exists $ENV{'PERL5OPT'}) {
+            while ($ENV{'PERL5OPT'} =~ s/-D([^ :]*)//) {
+                push @env_Dopts, "-D$1";
+            }
+        }
 	for my $prog (
 	    '/(?{$a[0]})/',
 	    'q() =~ qr/(?{$a[0]})/',
@@ -998,9 +1004,9 @@ sub run_tests {
 	    'use re q(eval); $c = q{(?{$a[0]})}; /$c/',
 	    'use re q(eval); $c = q{(?{$a[0]})}; /(?{1;})$c/',
 	) {
-	    $out = runperl(switches => ["-Dt"], prog => $prog, stderr => 1);
+	    $out = runperl(switches => [@env_Dopts, "-Dt"], prog => $prog, stderr => 1);
 	    like($out, qr/aelemfast|Recompile perl with -DDEBUGGING/,
-		"optimise: '$prog'");
+		"optimise: '$prog' ... @env_Dopts");
 	}
     }
 
diff --git a/t/re/recompile.t b/t/re/recompile.t
index 63a7068..dce07ad 100644
--- a/t/re/recompile.t
+++ b/t/re/recompile.t
@@ -24,6 +24,7 @@ BEGIN {
 
 plan tests => 38;
 
+my @env_Dopts;
 my $results = runperl(
 			switches => [ '-Dr' ],
 			prog => '1',
@@ -33,6 +34,11 @@ my $has_Dr = $results !~ /Recompile perl with -DDEBUGGING/;
 
 my $tmpfile = tempfile();
 
+if ($has_Dr && exists $ENV{'PERL5OPT'}) {
+    while ($ENV{'PERL5OPT'} =~ s/-D([^ :]*)//) {
+        push @env_Dopts, "-D$1";
+    }
+}
 
 # Check that a pattern triggers a regex compilation exactly N times,
 # using either -Dr or 'use re debug'
@@ -42,7 +48,7 @@ sub _comp_n {
     my ($use_Dr, $n, $prog, $desc) = @_;
     open my $tf, ">$tmpfile" or die "Cannot open $tmpfile: $!";
 
-    my $switches = [];
+    my $switches = [@env_Dopts];
     if ($use_Dr) {
 	push @$switches, '-Dr';
     }

@p5pRT
Copy link
Author

p5pRT commented Jul 26, 2013

From @cpansprout

On Thu Jul 18 07​:01​:20 2013, niels@​thykier.net wrote​:

Hi,

Some of these failures are caused by the mere presence of "-D" or "-Dq"
in PERL5OPT(_TEST). I have attached a patch for these tests.

I also rebased the original patch against the current blead.

Thank you.

Why does adding -DO to the runperl command line make things pass in the
presence of PERL5OPT=-DO? Would not the runperl output be the same
either way?

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 2013

From @nthykier

On Thu Jul 18 07​:01​:20 2013, niels@​thykier.net wrote​:

Hi,

Some of these failures are caused by the mere presence of "-D" or "-Dq"
in PERL5OPT(_TEST). I have attached a patch for these tests.

I also rebased the original patch against the current blead.

Thank you.

Why does adding -DO to the runperl command line make things pass in the
presence of PERL5OPT=-DO? Would not the runperl output be the same
either way?

--

To be honest, I have no clue why the tests breaks with containing -D
PERL5OPT when they are also passed a "-D" on the command line (or why
relocating them to cmd-line seem to "fix" it).

~Niels

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