void test() {
  if (cond("if1") /*comment*/) do_something("same-line");

  if (cond("if2"))
    do_something("single-line");
  // CHECK-MESSAGES: :[[@LINE-2]]:19: warning: statement should be inside braces
  // CHECK-FIXES: if (cond("if2")) {
  // CHECK-FIXES: }

  if (cond("if3") /*comment*/)
    // some comment
    do_something("three"
                 "lines");
  // CHECK-MESSAGES: :[[@LINE-4]]:31: warning: statement should be inside braces
  // CHECK-FIXES: if (cond("if3") /*comment*/) {
  // CHECK-FIXES: }

  if (cond("if4") /*comment*/)
    // some comment
    do_something("many"
                 "many"
                 "many"
                 "many"
                 "lines");
  // CHECK-MESSAGES: :[[@LINE-7]]:31: warning: statement should be inside braces
  // CHECK-FIXES: if (cond("if4") /*comment*/) {
  // CHECK-FIXES: }
}
Esempio n. 2
0
int main(int argc,char *argv[])
{
    int rank, num_of_processes;
    int i;

    MPI_Comm comm = MPI_COMM_WORLD;

    MPI_Init(&argc,&argv);
    MPI_Comm_size( comm, &num_of_processes);
    MPI_Comm_rank( comm, &rank);

    int localsum = 0;
    int globalsum = 0;
    int expectedsum = 0;
    
    if(rank == 0) {
        printf("Checking mpi_scan(sum)... (if you see no output then you are good)\n");
    }

    localsum = do_something(rank, 2);
    globalsum = 0;
    MPI_Scan(&localsum,&globalsum,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD);

    expectedsum = 0;
    // count upto my rank and verify that that was the return from scan
    for(i=0; i<rank+1; i++) {
        expectedsum = expectedsum + do_something(i, 2);
    }
        
    if (globalsum != expectedsum) {
        printf("ERROR: Expected %d got %d [rank:%d]\n", expectedsum, globalsum, rank);
    }
        
    MPI_Finalize();
}
Esempio n. 3
0
int
test_switch (int i, int j)
{
  int result = 0;			/* count(5) */

  switch (i)				/* count(5) */
    {
      case 1:
        result = do_something (2);	/* count(1) */
        break;
      case 2:
        result = do_something (1024);
        break;
      case 3:
      case 4:
        if (j == 2)			/* count(3) */
          return do_something (4);	/* count(1) */
        result = do_something (8);	/* count(2) */
        break;
      default:
	result = do_something (32);	/* count(1) */
	switch_m++;			/* count(1) */
        break;
    }
  return result;			/* count(4) */
}
int
main(int argc, const char* argv[])
{
    printf("--> main()\n");
    do_something();

    hrt_tstamp t0, t1;
    hrt_tnull(&t0);
    hrt_tnull(&t1);

    printf("\nmarking time...\n");
    int r;
    if ((r = hrt_tnow(&t0)) != 0) {
        fprintf(stderr, "error: hrt_now(&t0) returned %d\n", r);
    }
    hrt_tprint(&t0);

    do_something();

    printf("\nmarking time...\n");
    if ((r = hrt_tnow(&t1)) != 0) {
        fprintf(stderr, "error: hrt_now(&t1) returned %d\n", r);
    }
    hrt_tprint(&t1);

    printf("\namount of times:\n");
    double rtmicros = hrt_rtmicros(&t1.rtstamp, &t0.rtstamp);
    double ctmicros = hrt_ctmicros(&t1.ctstamp, &t0.ctstamp);
    printf("real   = %.3f us\n", rtmicros);
    printf("cpu    = %.3f us\n", ctmicros);
    
    printf("\n<-- main()\n");
    return 0;
}
Esempio n. 5
0
int
test_switch (int i, int j)
{
    int result = 0;

    switch (i)				/* branch(80 25) */
        /* branch(end) */
    {
    case 1:
        result = do_something (2);
        break;
    case 2:
        result = do_something (1024);
        break;
    case 3:
    case 4:
        if (j == 2)			/* branch(67) */
            /* branch(end) */
            return do_something (4);
        result = do_something (8);
        break;
    default:
        result = do_something (32);
        switch_m++;
        break;
    }
    return result;
}
int
pack_unpack (char *s, char *p)
{
  char *send, *pend;
  char type;
  int integer_size;

  send = s + strlen (s);
  pend = p + strlen (p);

  while (p < pend)
    {
      type = *p++;

      switch (type)
 {
 case 's':
   integer_size = 2;
   goto unpack_integer;

 case 'l':
   integer_size = 4;
   goto unpack_integer;

 unpack_integer:
   switch (integer_size)
     {
     case 2:
       {
  union
  {
    int16_t i;
    char a[sizeof (int16_t)];
  }
  v;
  memcpy (v.a, s, sizeof (int16_t));
  s += sizeof (int16_t);
  do_something (v.i);
       }
       break;

     case 4:
       {
  union
  {
    int32_t i;
    char a[sizeof (int32_t)];
  }
  v;
  memcpy (v.a, s, sizeof (int32_t));
  s += sizeof (int32_t);
  do_something (v.i);
       }
       break;
     }
   break;
 }
    }
  return (int) *s;
}
Esempio n. 7
0
int
main()
{
  do_something (2);
  do_something (3);
  do_something (5);
  do_something (70);
}
Esempio n. 8
0
File: main.cpp Progetto: CCJY/coliru
int main () {
    std::function<void(int, int)> lamarck = [&](int a, int b){ std::cout << a << b; };

    auto func = make_function([](){}); // lambda
    auto func2 = make_function(abc); // free function
    auto func3 = make_function(fo_abc()); // function object
    do_something(func);
    do_something(func2);
    do_something(func3);
}
Esempio n. 9
0
int
test_ifelse3 (int i, int j)
{
  int result = 1;
  if (i > 10 && j > i && j < 20)	/* count(11) */
    result = do_something (16);		/* count(1) */
  if (i > 20)				/* count(11) */
    if (j > i)				/* count(5) */
      if (j < 30)			/* count(2) */
	result = do_something (32);	/* count(1) */
  if (i == 3 || j == 47 || i == j)	/* count(11) */
    result = do_something (64);		/* count(3) */
  return result;			/* count(11) */
}
Esempio n. 10
0
int main()
{
    do_something(A());
    do_something(A(10));
    
    // this will cause error
//    do_something(20);

    // call explicit conversion
    do_something(static_cast<A>(20));

    // not recommanded
    do_something((A)30);
    return 0;
}
Esempio n. 11
0
void foo(struct obj1 *op) {
	TESLA_WITHIN(context,
/*
 * TODO: use CHECK-DAG once we switch to LLVM 3.4:
 *
 * First, we need to look up op->child_of_1->child_of_2:
 * CHECK: [[PTR:%[_a-zA-Z0-9\.]+]] = getelementptr inbounds %struct.obj1* %op
 * CHECK: [[C:%[_a-zA-Z0-9\.]+]] = load %struct.obj2** [[PTR]]
 *
 * CHECK: [[PTR:%[_a-zA-Z0-9\.]+]] = getelementptr inbounds %struct.obj2* [[C]]
 * CHECK: [[CHILD:%[_a-zA-Z0-9\.]+]] = load %struct.obj1** [[PTR]]
 *
 * Next, we look up op->child_of_1->value:
 * CHECK: [[PTR:%[_a-zA-Z0-9\.]+]] = getelementptr inbounds %struct.obj1* %op
 * CHECK: [[C:%[_a-zA-Z0-9\.]+]] = load %struct.obj2** [[PTR]]
 *
 * CHECK: [[PTR:%[_a-zA-Z0-9\.]+]] = getelementptr inbounds %struct.obj2* [[C]]
 * CHECK: [[VALUE:%[_a-zA-Z0-9\.]+]] = load i32* [[PTR]]
 *
 * CHECK: call void [[INSTR:@.*_tesla_instr.*assert.*]](%struct.obj1* [[CHILD]], [[INT:i[3264]+]] [[VALUE]])
 */
		eventually(
			do_something(
				op->child_of_1->child_of_2,
				op->child_of_1->value) == 0
		)
	);
}
Esempio n. 12
0
	void process_data()
	{
		std::unique_lock<std::mutex> lk( get_lock() ); /* (1) */
		do_something();

		std::cout << "owns_lock : " << lk.owns_lock() << std::endl;
	} 
Esempio n. 13
0
int
test_ifelse2 (int i)
{
  int result = 0;
  if (!i)				/* count(6) */
    result = do_something (1);		/* count(1) */
  if (i == 1)				/* count(6) */
    result = do_something (1024);
  if (i == 2)				/* count(6) */
    result = do_something (2);		/* count(3) */
  if (i == 3)				/* count(6) */
    return do_something (8);		/* count(2) */
  if (i == 4)				/* count(4) */
    return do_something (2048);
  return result;			/* count(4) */
}
void mainPlustHeaderCallAndReturnPlusMain() {
  int i = 0;
  i++;
  do_something(i);
  causeDivByZeroInMain2(i);
  i++;
}
Esempio n. 15
0
main() 
{
	int s, t;
	if ((s = establish(PORTNUM)) < 0) 
	{													 				/* plug in the phone */
		perror("establish");
		exit(1);
	} 
																		/* how a concurrent server looks like */
	for (;;) 
	{																	/* loop for phone calls */
		if ((t= get_connection(s)) < 0) 
		{																/* get a connection */
			perror("accept"); 											/* bad */
			exit(1);	
		}
		switch( fork() ) 
		{																/* try to handle connection */
			case -1 : 													/* bad news. scream and die */
				perror("fork");
				close(s);
				close(t);
				exit(1);
			case 0 : 													/* we're the child, do something */
				close(s);
				do_something(t);
				close(t);
				exit(0);
			default : 													/* we're the parent so look for */
				close(t); 												/* another connection */
				continue;
		}
	}
}														 				/* end of main */
Esempio n. 16
0
main(int argc, char* argv[],char ** environ)
{
      int child_proc_number = MAX_CHILD_NUMBER; 
      int i, ch; 
      pid_t  child_pid; 
      pid_t pid[10]={0};
     if (argc > 1)
     {
         child_proc_number = atoi(argv[1]); 
         child_proc_number= (child_proc_number > 10) ? 10 :
                                                    child_proc_number;
     } 
    for (i=0; i<child_proc_number; i++) {
        child_pid=fork();
        switch(child_pid){
          case -1:exit(1);

          case 0:proc_number=i;
                 do_something();
                 exit(1);
          default:pid[i]=child_pid;break;
        
      }
    }
      /* 让用户选择杀死进程,数字表示杀死该进程,q退出 */
   while ((ch = getchar()) != 'q'){ 
        if (isdigit(ch)){
                 kill(pid[ch-'0'],SIGTERM);
                 wait();
        }
   }
   kill(0,SIGTERM);
   return;
}
Esempio n. 17
0
main()
{
 int s, t, i; 
 if ((s= establish(34835)) < 0) { /* plug in the phone */ 
 	perror("establish error");
 	exit(-1); 
 } 
  //signal(SIGCHLD, fireman); /* this eliminates zombies */ 

   for (i=0;i=1;i++)   { /* loop for phone calls */ 
	  if ((t= get_connection(s)) < 0) { /* get a connection */ 
	  	if (errno == EINTR) /* EINTR might happen on accept(), */ 
	  	continue; /* try again */ 
	  	perror("accept"); /* bad */ 
	  	exit(1);
	  } 
	   switch(fork()) { /* try to handle connection */ 
	  	  case -1 : /* bad news. scream and die */ 
	   		perror("fork");
	   		close(s);
	  		close(t); 
	   		exit(1); 
	 	  case 0 : /* we're the child, do something */ 
		   close(s); 
		   do_something(t); 
		   exit(0); 
	  	  default : /* we're the parent so look for */ 
		   close(t); /* another connection */ 
		  continue; 
        } 
   } 
} 
Esempio n. 18
0
	void operator()()
	{
		for (unsigned j = 0; j < 1000000; ++j)
		{
			do_something(i);
		}
	}
Esempio n. 19
0
void * child_main(void *args)
{
    sarg * arg = (void *)args;
    int listenfd = arg->listenfd;
    int addrlen = arg->addrlen;
    int connfd;
    socklen_t clilen;
    struct sockaddr *cliaddr;

    cliaddr = malloc(addrlen);
    printf("thread %lu starting...\n", pthread_self());
    for (;;)
    {
        sleep(3);
        clilen = addrlen;
        connfd = accept(listenfd, cliaddr, &clilen);
        if (connfd == -1)
        {
            err_exit("accept failed");
        }
        do_something(getpid(), pthread_self(), connfd);
        close(connfd);
    }
    return NULL;
}
Esempio n. 20
0
void f (int m, int n)
{
  int j;
 
  for (j = m; j	< m + 10 && j <	n; j ++)
    do_something (j);
}
/***********************************************************
* Student No: 12815482									   *	
* Student Name: Tirthankar Bhaumik                         *
* Course: MSc Computing for Financial Services             *
* Assignment: Final Assignment 4        				   *
* Objective: Demo of CPPCHECK tool - Null Pointer Exception*
************************************************************/
void f1(struct fred_t *p)
{
    // dereference p and then check if it's NULL
    int x = p->x;
    if (p)
        do_something(x);
}
Esempio n. 22
0
int Parent::funcOne (int delim) const
{
  int i;
  for (i = 0; i < delim; i++)
    do_something(data, i);

  return 1;
}
void bar2(int i, int j)
{
  struct X x;

  x.i = i;
  x.j = j;
  do_something (x);
}
Esempio n. 24
0
int
main (void)
{
  new_integer_type toto = 30;

  do_something(&toto);
  return 0;
}
Esempio n. 25
0
int main(int argc, char **argv)
{
    startup_checks();
    parseargs(argc, argv);
    connect_to_server();
    gethandle();
    while (1)
	do_something();
}
Esempio n. 26
0
int main(void)
{
#if _DEBUG
	freopen("input.txt","r", stdin);
#endif
	input_proc();
	do_something();
	output_proc();
	return 0;
}
Esempio n. 27
0
	int ZPClient::test_callback(do_something_callback cb)
	{
		printf("client - test_cb - \n");
		sp<ProcessState> proc(ProcessState::self()); 
		add_cb(cb);
		do_something();
		ProcessState::self()->startThreadPool();
		IPCThreadState::self()->joinThreadPool();
		return 0;
	}
Esempio n. 28
0
int
test_ifelse3 (int i, int j)
{
    int result = 1;
    if (i > 10 && j > i && j < 20)	/* branch(27 50 75) */
        /* branch(end) */
        result = do_something (16);
    if (i > 20)				/* branch(55) */
        /* branch(end) */
        if (j > i)				/* branch(60) */
            /* branch(end) */
            if (j < 30)			/* branch(50) */
                /* branch(end) */
                result = do_something (32);
    if (i == 3 || j == 47 || i == j)	/* branch(9 10 89) */
        /* branch(end) */
        result = do_something (64);
    return result;
}
int main()
{
  do_something();

  std::copy(std::cbegin(my_array),
            std::cend  (my_array),
            std::ostream_iterator<unsigned int>(std::cout, ","));

  std::cout << std::endl;
}
Esempio n. 30
0
int main()
{
	std::ios::sync_with_stdio(false);
	extern void* __dso_handle __attribute__ ((__weak__));
	__cxa_atexit((void (*) (void *)) __libc_freeres, NULL,
			&__dso_handle ? __dso_handle : NULL);
	do_something();

	return 0;
}