issue35.t 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #! /usr/bin/env perl
  2. # http://code.google.com/p/perl-compiler/issues/detail?id=35
  3. # B::CC generates wrong C code for same variable in different scope
  4. use Test::More tests => 2;
  5. use strict;
  6. use Config;
  7. my $ITHREADS = $Config{useithreads};
  8. my $base = "ccode35i";
  9. sub test {
  10. my ($num, $script, $todo) = @_;
  11. my $name = $base."_$num";
  12. unlink($name, "$name.c", "$name.pl", "$name.exe");
  13. open F, ">", "$name.pl";
  14. print F $script;
  15. close F;
  16. my $runperl = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
  17. my $b = $] > 5.008 ? "-qq,CC" : "CC";
  18. system "$runperl -Mblib -MO=$b,-o$name.c $name.pl";
  19. unless (-e "$name.c") {
  20. print "not ok 1 #B::CC failed\n";
  21. exit;
  22. }
  23. system "$runperl -Mblib blib/script/cc_harness -q -o $name $name.c";
  24. my $ok = -e $name or -e "$name.exe";
  25. if ($todo) {
  26. TODO: {
  27. local $TODO = $todo;
  28. ok($ok, 'CC same variable in different scope');
  29. }
  30. } else {
  31. ok($ok, 'CC same variable in different scope');
  32. }
  33. if ($ok) {
  34. unlink($name, "$name.c", "$name.pl", "$name.exe");
  35. }
  36. }
  37. # error: redeclaration of ‘d_x’ with no linkage
  38. my $script = <<'EOF';
  39. sub new {}
  40. sub test {
  41. { my $x = 1; my $y = $x + 1;}
  42. my $x = 2;
  43. if ($x != 3) { 4; }
  44. }
  45. EOF
  46. #fixed with B-C-1.28 r527 (B::CC 1.08)
  47. use B::CC;
  48. test(1, $script, $B::CC::VERSION < 1.08 ? "B::CC issue 35" : undef);
  49. # error: redeclaration of ‘d_tmp5’ with no linkage
  50. $script = <<'EOF';
  51. sub test {
  52. my $tmp5 = 1;
  53. my $x = $tmp5 + 1;
  54. if ($x != 3) { 4; }
  55. }
  56. EOF
  57. # passes non-threaded (5.8.9d-nt, perl5.10.1d-nt)
  58. test(2, $script, ($B::CC::VERSION < 1.08 and $ITHREADS) ? "B::CC issue 35 fail3.pl" : undef);