OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc2/] [gcc/] [testsuite/] [gcc.misc-tests/] [gcov-4b.c] - Diff between revs 299 and 384

Only display areas with differences | Details | Blame | View Log

Rev 299 Rev 384
/* Check that execution counts for various C constructs are reported
/* Check that execution counts for various C constructs are reported
   correctly by gcov. */
   correctly by gcov. */
 
 
/* { dg-options "-fprofile-arcs -ftest-coverage" } */
/* { dg-options "-fprofile-arcs -ftest-coverage" } */
/* { dg-do run { target native } } */
/* { dg-do run { target native } } */
 
 
extern void abort (void);
extern void abort (void);
 
 
int do_something (int i)
int do_something (int i)
{
{
  return i;
  return i;
}
}
 
 
/* Check for loops. */
/* Check for loops. */
 
 
int for_val1;
int for_val1;
int for_val2;
int for_val2;
int for_temp;
int for_temp;
 
 
int
int
test_for1 (int n)
test_for1 (int n)
{
{
  int i;
  int i;
  for_temp = 1;
  for_temp = 1;
  for (i = 0; i < n; i++)                /* branch(25) */
  for (i = 0; i < n; i++)                /* branch(25) */
                                        /* branch(end) */
                                        /* branch(end) */
    for_temp++;
    for_temp++;
  return for_temp;
  return for_temp;
}
}
 
 
int
int
test_for2 (int m, int n, int o)
test_for2 (int m, int n, int o)
{
{
  int i, j, k;
  int i, j, k;
  for_temp = 1;
  for_temp = 1;
  for (i = 0; i < n; i++)                /* branch(30) */
  for (i = 0; i < n; i++)                /* branch(30) */
                                        /* branch(end) */
                                        /* branch(end) */
    for (j = 0; j < m; j++)              /* branch(32) */
    for (j = 0; j < m; j++)              /* branch(32) */
                                        /* branch(end) */
                                        /* branch(end) */
      for (k = 0; k < o; k++)            /* branch(27) */
      for (k = 0; k < o; k++)            /* branch(27) */
                                        /* branch(end) */
                                        /* branch(end) */
        for_temp++;
        for_temp++;
  return for_temp;
  return for_temp;
}
}
 
 
void
void
call_for ()
call_for ()
{
{
  for_val1 += test_for1 (0);
  for_val1 += test_for1 (0);
  for_val1 += test_for1 (2);
  for_val1 += test_for1 (2);
  for_val1 += test_for1 (7);
  for_val1 += test_for1 (7);
 
 
  for_val2 += test_for2 (0, 0, 0);
  for_val2 += test_for2 (0, 0, 0);
  for_val2 += test_for2 (1, 0, 0);
  for_val2 += test_for2 (1, 0, 0);
  for_val2 += test_for2 (1, 3, 0);
  for_val2 += test_for2 (1, 3, 0);
  for_val2 += test_for2 (1, 3, 1);
  for_val2 += test_for2 (1, 3, 1);
  for_val2 += test_for2 (3, 1, 5);
  for_val2 += test_for2 (3, 1, 5);
  for_val2 += test_for2 (3, 7, 3);
  for_val2 += test_for2 (3, 7, 3);
}
}
 
 
/* Check the use of goto. */
/* Check the use of goto. */
 
 
int goto_val;
int goto_val;
 
 
int
int
test_goto1 (int f)
test_goto1 (int f)
{
{
  if (f)                                /* branch(50) */
  if (f)                                /* branch(50) */
                                        /* branch(end) */
                                        /* branch(end) */
    goto lab1;
    goto lab1;
  return 1;
  return 1;
lab1:
lab1:
  return 2;
  return 2;
}
}
 
 
int
int
test_goto2 (int f)
test_goto2 (int f)
{
{
  int i;
  int i;
  for (i = 0; i < 10; i++)               /* branch(7) */
  for (i = 0; i < 10; i++)               /* branch(7) */
                                        /* branch(end) */
                                        /* branch(end) */
    if (i == f) goto lab2;
    if (i == f) goto lab2;
  return 4;
  return 4;
lab2:
lab2:
  return 8;
  return 8;
}
}
 
 
void
void
call_goto ()
call_goto ()
{
{
  goto_val += test_goto1 (0);
  goto_val += test_goto1 (0);
  goto_val += test_goto1 (1);
  goto_val += test_goto1 (1);
  goto_val += test_goto2 (3);
  goto_val += test_goto2 (3);
  goto_val += test_goto2 (30);
  goto_val += test_goto2 (30);
}
}
 
 
/* Check nested if-then-else statements. */
/* Check nested if-then-else statements. */
 
 
int ifelse_val1;
int ifelse_val1;
int ifelse_val2;
int ifelse_val2;
int ifelse_val3;
int ifelse_val3;
 
 
int
int
test_ifelse1 (int i, int j)
test_ifelse1 (int i, int j)
{
{
  int result = 0;
  int result = 0;
  if (i)                                /* branch(40) */
  if (i)                                /* branch(40) */
                                        /* branch(end) */
                                        /* branch(end) */
    if (j)                              /* branch(0) */
    if (j)                              /* branch(0) */
                                        /* branch(end) */
                                        /* branch(end) */
      result = do_something (4);
      result = do_something (4);
    else
    else
      result = do_something (1024);
      result = do_something (1024);
  else
  else
    if (j)                              /* branch(50) */
    if (j)                              /* branch(50) */
                                        /* branch(end) */
                                        /* branch(end) */
      result = do_something (1);
      result = do_something (1);
    else
    else
      result = do_something (2);
      result = do_something (2);
  if (i > j)                            /* branch(80) */
  if (i > j)                            /* branch(80) */
                                        /* branch(end) */
                                        /* branch(end) */
    result = do_something (result*2);
    result = do_something (result*2);
  if (i > 10)                           /* branch(80) */
  if (i > 10)                           /* branch(80) */
                                        /* branch(end) */
                                        /* branch(end) */
    if (j > 10)                         /* branch(100) */
    if (j > 10)                         /* branch(100) */
      result = do_something (result*4);
      result = do_something (result*4);
  return result;
  return result;
}
}
 
 
int
int
test_ifelse2 (int i)
test_ifelse2 (int i)
{
{
  int result = 0;
  int result = 0;
  if (!i)                               /* branch(83) */
  if (!i)                               /* branch(83) */
                                        /* branch(end) */
                                        /* branch(end) */
    result = do_something (1);
    result = do_something (1);
  if (i == 1)                           /* branch(100) */
  if (i == 1)                           /* branch(100) */
                                        /* branch(end) */
                                        /* branch(end) */
    result = do_something (1024);
    result = do_something (1024);
  if (i == 2)                           /* branch(50) */
  if (i == 2)                           /* branch(50) */
                                        /* branch(end) */
                                        /* branch(end) */
    result = do_something (2);
    result = do_something (2);
  if (i == 3)                           /* branch(67) */
  if (i == 3)                           /* branch(67) */
                                        /* branch(end) */
                                        /* branch(end) */
    return do_something (8);
    return do_something (8);
  if (i == 4)                           /* branch(100) */
  if (i == 4)                           /* branch(100) */
                                        /* branch(end) */
                                        /* branch(end) */
    return do_something (2048);
    return do_something (2048);
  return result;
  return result;
}
}
 
 
int
int
test_ifelse3 (int i, int j)
test_ifelse3 (int i, int j)
{
{
  int result = 1;
  int result = 1;
  if (i > 10 && j > i && j < 20)        /* branch(27 50 75) */
  if (i > 10 && j > i && j < 20)        /* branch(27 50 75) */
                                        /* branch(end) */
                                        /* branch(end) */
    result = do_something (16);
    result = do_something (16);
  if (i > 20)                           /* branch(55) */
  if (i > 20)                           /* branch(55) */
                                        /* branch(end) */
                                        /* branch(end) */
    if (j > i)                          /* branch(60) */
    if (j > i)                          /* branch(60) */
                                        /* branch(end) */
                                        /* branch(end) */
      if (j < 30)                       /* branch(50) */
      if (j < 30)                       /* branch(50) */
                                        /* branch(end) */
                                        /* branch(end) */
        result = do_something (32);
        result = do_something (32);
  if (i == 3 || j == 47 || i == j)      /* branch(9 10 89) */
  if (i == 3 || j == 47 || i == j)      /* branch(9 10 89) */
                                        /* branch(end) */
                                        /* branch(end) */
    result = do_something (64);
    result = do_something (64);
  return result;
  return result;
}
}
 
 
void
void
call_ifelse ()
call_ifelse ()
{
{
  ifelse_val1 += test_ifelse1 (0, 2);
  ifelse_val1 += test_ifelse1 (0, 2);
  ifelse_val1 += test_ifelse1 (0, 0);
  ifelse_val1 += test_ifelse1 (0, 0);
  ifelse_val1 += test_ifelse1 (1, 2);
  ifelse_val1 += test_ifelse1 (1, 2);
  ifelse_val1 += test_ifelse1 (10, 2);
  ifelse_val1 += test_ifelse1 (10, 2);
  ifelse_val1 += test_ifelse1 (11, 11);
  ifelse_val1 += test_ifelse1 (11, 11);
 
 
  ifelse_val2 += test_ifelse2 (0);
  ifelse_val2 += test_ifelse2 (0);
  ifelse_val2 += test_ifelse2 (2);
  ifelse_val2 += test_ifelse2 (2);
  ifelse_val2 += test_ifelse2 (2);
  ifelse_val2 += test_ifelse2 (2);
  ifelse_val2 += test_ifelse2 (2);
  ifelse_val2 += test_ifelse2 (2);
  ifelse_val2 += test_ifelse2 (3);
  ifelse_val2 += test_ifelse2 (3);
  ifelse_val2 += test_ifelse2 (3);
  ifelse_val2 += test_ifelse2 (3);
 
 
  ifelse_val3 += test_ifelse3 (11, 19);
  ifelse_val3 += test_ifelse3 (11, 19);
  ifelse_val3 += test_ifelse3 (25, 27);
  ifelse_val3 += test_ifelse3 (25, 27);
  ifelse_val3 += test_ifelse3 (11, 22);
  ifelse_val3 += test_ifelse3 (11, 22);
  ifelse_val3 += test_ifelse3 (11, 10);
  ifelse_val3 += test_ifelse3 (11, 10);
  ifelse_val3 += test_ifelse3 (21, 32);
  ifelse_val3 += test_ifelse3 (21, 32);
  ifelse_val3 += test_ifelse3 (21, 20);
  ifelse_val3 += test_ifelse3 (21, 20);
  ifelse_val3 += test_ifelse3 (1, 2);
  ifelse_val3 += test_ifelse3 (1, 2);
  ifelse_val3 += test_ifelse3 (32, 31);
  ifelse_val3 += test_ifelse3 (32, 31);
  ifelse_val3 += test_ifelse3 (3, 0);
  ifelse_val3 += test_ifelse3 (3, 0);
  ifelse_val3 += test_ifelse3 (0, 47);
  ifelse_val3 += test_ifelse3 (0, 47);
  ifelse_val3 += test_ifelse3 (65, 65);
  ifelse_val3 += test_ifelse3 (65, 65);
}
}
 
 
/* Check switch statements. */
/* Check switch statements. */
 
 
int switch_val, switch_m;
int switch_val, switch_m;
 
 
int
int
test_switch (int i, int j)
test_switch (int i, int j)
{
{
  int result = 0;
  int result = 0;
 
 
  switch (i)                            /* branch(20 0 60 20) */
  switch (i)                            /* branch(20 0 60 20) */
                                        /* branch(end) */
                                        /* branch(end) */
    {
    {
      case 1:
      case 1:
        result = do_something (2);
        result = do_something (2);
        break;
        break;
      case 2:
      case 2:
        result = do_something (1024);
        result = do_something (1024);
        break;
        break;
      case 3:
      case 3:
      case 4:
      case 4:
        if (j == 2)                     /* branch(67) */
        if (j == 2)                     /* branch(67) */
                                        /* branch(end) */
                                        /* branch(end) */
          return do_something (4);
          return do_something (4);
        result = do_something (8);
        result = do_something (8);
        break;
        break;
      default:
      default:
        result = do_something (32);
        result = do_something (32);
        switch_m++;
        switch_m++;
        break;
        break;
    }
    }
  return result;
  return result;
}
}
 
 
void
void
call_switch ()
call_switch ()
{
{
  switch_val += test_switch (1, 0);
  switch_val += test_switch (1, 0);
  switch_val += test_switch (3, 0);
  switch_val += test_switch (3, 0);
  switch_val += test_switch (3, 2);
  switch_val += test_switch (3, 2);
  switch_val += test_switch (4, 0);
  switch_val += test_switch (4, 0);
  switch_val += test_switch (16, 0);
  switch_val += test_switch (16, 0);
  switch_val += switch_m;
  switch_val += switch_m;
}
}
 
 
int
int
main()
main()
{
{
  call_for ();
  call_for ();
  call_goto ();
  call_goto ();
  call_ifelse ();
  call_ifelse ();
  call_switch ();
  call_switch ();
  if ((for_val1 != 12)
  if ((for_val1 != 12)
      || (for_val2 != 87)
      || (for_val2 != 87)
      || (goto_val != 15)
      || (goto_val != 15)
      || (ifelse_val1 != 31)
      || (ifelse_val1 != 31)
      || (ifelse_val2 != 23)
      || (ifelse_val2 != 23)
      || (ifelse_val3 != 246)
      || (ifelse_val3 != 246)
      || (switch_val != 55))
      || (switch_val != 55))
    abort ();
    abort ();
  return 0;
  return 0;
}
}
 
 
/* { dg-final { run-gcov branches { -b gcov-4b.c } } } */
/* { dg-final { run-gcov branches { -b gcov-4b.c } } } */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.