issue35.t 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. $runperl .= " -Iblib/arch -Iblib/lib";
  18. my $b = $] > 5.008 ? "-qq,CC" : "CC";
  19. system "$runperl -MO=$b,-o$name.c $name.pl";
  20. unless (-e "$name.c") {
  21. print "not ok 1 #B::CC failed\n";
  22. exit;
  23. }
  24. system "$runperl blib/script/cc_harness -q -o $name $name.c";
  25. my $ok = -e $name or -e "$name.exe";
  26. if ($todo) {
  27. TODO: {
  28. local $TODO = $todo;
  29. ok($ok, 'CC same variable in different scope');
  30. }
  31. } else {
  32. ok($ok, 'CC same variable in different scope');
  33. }
  34. if ($ok) {
  35. unlink($name, "$name.c", "$name.pl", "$name.exe");
  36. }
  37. }
  38. # error: redeclaration of ‘d_x’ with no linkage
  39. my $script = <<'EOF';
  40. sub new {}
  41. sub test {
  42. { my $x = 1; my $y = $x + 1;}
  43. my $x = 2;
  44. if ($x != 3) { 4; }
  45. }
  46. EOF
  47. #fixed with B-C-1.28 r527 (B::CC 1.08)
  48. use B::CC;
  49. test(1, $script, $B::CC::VERSION < 1.08 ? "B::CC issue 35" : undef);
  50. # error: redeclaration of ‘d_tmp5’ with no linkage
  51. $script = <<'EOF';
  52. sub test {
  53. my $tmp5 = 1;
  54. my $x = $tmp5 + 1;
  55. if ($x != 3) { 4; }
  56. }
  57. EOF
  58. # passes non-threaded (5.8.9d-nt, perl5.10.1d-nt)
  59. test(2, $script, ($B::CC::VERSION < 1.08 and $ITHREADS) ? "B::CC issue 35 fail3.pl" : undef);