Browse Source

fixes for cppcheck warnings

Nathalie Furmento 6 years ago
parent
commit
a51e48733c

+ 7 - 7
include/starpu_util.h

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2008-2018                                Université de Bordeaux
  * Copyright (C) 2011,2012,2017                           Inria
- * Copyright (C) 2010-2017                                CNRS
+ * Copyright (C) 2010-2017, 2019                          CNRS
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -388,10 +388,10 @@ static __starpu_inline int starpu_get_env_number(const char *str)
 	{
 		/* the env variable was actually set */
 		long int val;
-		char *check;
+		char *pcheck;
 
-		val = strtol(strval, &check, 10);
-		if (*check) {
+		val = strtol(strval, &pcheck, 10);
+		if (*pcheck) {
 			fprintf(stderr,"The %s environment variable must contain an integer\n", str);
 			STARPU_ABORT();
 		}
@@ -425,10 +425,10 @@ static __starpu_inline float starpu_get_env_float_default(const char *str, float
 	{
 		/* the env variable was actually set */
 		float val;
-		char *check;
+		char *pcheck;
 
-		val = strtof(strval, &check);
-		if (*check) {
+		val = strtof(strval, &pcheck);
+		if (*pcheck) {
 			fprintf(stderr,"The %s environment variable must contain a float\n", str);
 			STARPU_ABORT();
 		}

+ 2 - 2
socl/src/cl_setkernelarg.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2012,2017                                CNRS
+ * Copyright (C) 2012,2017,2019                           CNRS
  * Copyright (C) 2010,2011,2013,2018                      Université de Bordeaux
  * Copyright (C) 2011                                     Inria
  *
@@ -76,7 +76,7 @@ soclSetKernelArg(cl_kernel  kernel,
 	kernel->arg_type[arg_index] = Null;
 	kernel->arg_size[arg_index] = arg_size;
 
-	DEBUG_MSG("[Kernel %d] Set argument %d: argsize %ld argvalue %p\n", kernel->id, arg_index, (long)arg_size, arg_value);
+	DEBUG_MSG("[Kernel %d] Set argument %u: argsize %ld argvalue %p\n", kernel->id, arg_index, (long)arg_size, arg_value);
 
 	/* Argument is not Null */
 	if (arg_value != NULL)

+ 2 - 3
socl/src/cl_waitforevents.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2012,2017                                CNRS
+ * Copyright (C) 2012,2017,2019                           CNRS
  * Copyright (C) 2010-2013,2018                           Université de Bordeaux
  * Copyright (C) 2011                                     Inria
  *
@@ -29,8 +29,7 @@ soclWaitForEvents(cl_uint           num_events,
 	DEBUG_MSG("Waiting for events: ");
 	for (i=0; i<num_events; i++)
 	{
-		char * sep = i == (num_events-1) ? "" : ", ";
-		DEBUG_MSG_NOHEAD("%d%s", event_list[i]->id, sep);
+		DEBUG_MSG_NOHEAD("%d%s", event_list[i]->id, i == (num_events-1) ? "" : ", ");
 	}
 	DEBUG_MSG_NOHEAD("\n");
 #endif

+ 2 - 3
src/common/utils.c

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2010-2017                                Université de Bordeaux
  * Copyright (C) 2012,2016,2017                           Inria
- * Copyright (C) 2010-2017                                CNRS
+ * Copyright (C) 2010-2017, 2019                          CNRS
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -79,9 +79,8 @@ int _starpu_mkpath(const char *s, mode_t mode)
 {
 	int olderrno;
 	char *q, *r = NULL, *path = NULL, *up = NULL;
-	int rv;
+	int rv = -1;
 
-	rv = -1;
 	if (strcmp(s, ".") == 0 || strcmp(s, "/") == 0
 #if defined(_WIN32)
 		/* C:/ or C:\ */

+ 6 - 5
src/core/dependencies/task_deps.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2018                                Université de Bordeaux
- * Copyright (C) 2010-2017                                CNRS
+ * Copyright (C) 2010-2017,2019                           CNRS
  * Copyright (C) 2014,2016                                Inria
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -85,12 +85,13 @@ void _starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, s
 
 	STARPU_PTHREAD_MUTEX_LOCK(&job->sync_mutex);
 	if (check)
-		STARPU_ASSERT_MSG(
-				!job->submitted || !task->destroy || task->detach
+	{
+		int ret = !job->submitted || !task->destroy || task->detach;
 #ifdef STARPU_OPENMP
-				|| job->continuation
+		ret = ret || job->continuation;
 #endif
-				, "Task dependencies have to be set before submission (submitted %u destroy %u detach %u)", job->submitted, task->destroy, task->detach);
+		STARPU_ASSERT_MSG(ret, "Task dependencies have to be set before submission (submitted %u destroy %u detach %u)", job->submitted, task->destroy, task->detach);
+	}
 	else
 		STARPU_ASSERT_MSG(job->terminated <= 1, "Task dependencies have to be set before termination (terminated %u)", job->terminated);
 

+ 2 - 3
src/core/detect_combined_workers.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2011-2014                                Inria
- * Copyright (C) 2011-2017                                CNRS
+ * Copyright (C) 2011-2017, 2019                          CNRS
  * Copyright (C) 2010-2016                                Université de Bordeaux
  * Copyright (C) 2013                                     Thibaut Lambert
  *
@@ -203,7 +203,7 @@ static void find_and_assign_combinations_with_hwloc(int *workerids, int nworkers
 static void assign_combinations_without_hwloc(struct starpu_worker_collection* worker_collection, int* workers, unsigned n, int min, int max)
 {
 
-	int size,i,count =0;
+	int size,i;
 	//if the maximun number of worker is already reached
 	if(worker_collection->nworkers >= STARPU_NMAXWORKERS - 1)
 		return;
@@ -224,7 +224,6 @@ static void assign_combinations_without_hwloc(struct starpu_worker_collection* w
 				int newworkerid;
 				newworkerid = starpu_combined_worker_assign_workerid(size, found_workerids);
 				STARPU_ASSERT(newworkerid >= 0);
-				count++;
 				worker_collection->add(worker_collection, newworkerid);
 				//if the maximun number of worker is reached, then return
 				if(worker_collection->nworkers >= STARPU_NMAXWORKERS - 1)

+ 4 - 5
src/core/perfmodel/perfmodel_bus.c

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2011-2014,2016,2017                      Inria
  * Copyright (C) 2009-2019                                Université de Bordeaux
- * Copyright (C) 2010-2017                                CNRS
+ * Copyright (C) 2010-2017,2019                           CNRS
  * Copyright (C) 2013                                     Corentin Salingue
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -155,8 +155,6 @@ static void measure_bandwidth_between_host_and_dev_on_numa_with_cuda(int dev, in
 	_starpu_bind_thread_on_cpu(cpu, STARPU_NOWORKERID, NULL);
 	size_t size = SIZE;
 
-	const unsigned nnuma_nodes = _starpu_topology_get_nnumanodes(config);
-
 	/* Initialize CUDA context on the device */
 	/* We do not need to enable OpenGL interoperability at this point,
 	 * since we cleanly shutdown CUDA before returning. */
@@ -191,6 +189,7 @@ static void measure_bandwidth_between_host_and_dev_on_numa_with_cuda(int dev, in
 	unsigned char *h_buffer;
 
 #if defined(STARPU_HAVE_HWLOC)
+	const unsigned nnuma_nodes = _starpu_topology_get_nnumanodes(config);
 	if (nnuma_nodes > 1)
 	{
 		/* NUMA mode activated */
@@ -415,8 +414,6 @@ static void measure_bandwidth_between_host_and_dev_on_numa_with_opencl(int dev,
 	struct _starpu_machine_config *config = _starpu_get_machine_config();
 	_starpu_bind_thread_on_cpu(cpu, STARPU_NOWORKERID, NULL);
 
-	const unsigned nnuma_nodes = _starpu_topology_get_nnumanodes(config);
-
 	/* Is the context already initialised ? */
 	starpu_opencl_get_context(dev, &context);
 	not_initialized = (context == NULL);
@@ -459,6 +456,8 @@ static void measure_bandwidth_between_host_and_dev_on_numa_with_opencl(int dev,
 	/* Allocate a buffer on the host */
 	unsigned char *h_buffer;
 #if defined(STARPU_HAVE_HWLOC)
+	const unsigned nnuma_nodes = _starpu_topology_get_nnumanodes(config);
+
 	if (nnuma_nodes > 1)
 	{
 		/* NUMA mode activated */

+ 2 - 2
src/core/workers.h

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2011-2017                                Inria
  * Copyright (C) 2008-2019                                Université de Bordeaux
- * Copyright (C) 2010-2018                                CNRS
+ * Copyright (C) 2010-2019                                CNRS
  * Copyright (C) 2013                                     Thibaut Lambert
  * Copyright (C) 2016                                     Uppsala University
  *
@@ -1131,7 +1131,7 @@ static inline int _starpu_worker_trylock(int workerid)
 		return ret;
 	if (workerid == cur_workerid)
 		/* We only needed to lock ourself */
-		return ret;
+		return 0;
 
 	/* Now try to lock the other worker */
 	ret = STARPU_PTHREAD_MUTEX_TRYLOCK_SCHED(&worker->sched_mutex);

+ 19 - 17
src/datawizard/malloc.c

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2011-2014,2016,2017                      Inria
  * Copyright (C) 2018                                     Federal University of Rio Grande do Sul (UFRGS)
- * Copyright (C) 2010-2017                                CNRS
+ * Copyright (C) 2010-2017, 2019                          CNRS
  * Copyright (C) 2009-2018                                Université de Bordeaux
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -724,11 +724,11 @@ _starpu_free_on_node_flags(unsigned dst_node, uintptr_t addr, size_t size, int f
 		case STARPU_CPU_RAM:
 			_starpu_free_flags_on_node(dst_node, (void*)addr, size,
 #if defined(STARPU_USE_CUDA) && !defined(STARPU_HAVE_CUDA_MEMCPY_PEER) && !defined(STARPU_SIMGRID)
-					flags & ~STARPU_MALLOC_PINNED
+						   flags & ~STARPU_MALLOC_PINNED
 #else
-					flags
+						   flags
 #endif
-					);
+				);
 			break;
 #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)
 		case STARPU_CUDA_RAM:
@@ -750,24 +750,26 @@ _starpu_free_on_node_flags(unsigned dst_node, uintptr_t addr, size_t size, int f
 			struct _starpu_worker *worker = _starpu_get_local_worker_key();
 			if (!worker || worker->arch != STARPU_CUDA_WORKER || worker->devid != devid)
 				STARPU_ASSERT_MSG(0, "CUDA peer access is not available with this version of CUDA");
-#endif
+#endif /* STARPU_HAVE_CUDA_MEMCPY_PEER */
 			err = cudaFree((void*)addr);
-			if (STARPU_UNLIKELY(err != cudaSuccess
 #ifdef STARPU_OPENMP
-		/* When StarPU is used as Open Runtime support,
-		 * starpu_omp_shutdown() will usually be called from a
-		 * destructor, in which case cudaThreadExit() reports a
-		 * cudaErrorCudartUnloading here. There should not
-		 * be any remaining tasks running at this point so
-		 * we can probably ignore it without much consequences. */
-		&& err != cudaErrorCudartUnloading
-#endif /* STARPU_OPENMP */
-						))
+			/* When StarPU is used as Open Runtime support,
+			 * starpu_omp_shutdown() will usually be called from a
+			 * destructor, in which case cudaThreadExit() reports a
+			 * cudaErrorCudartUnloading here. There should not
+			 * be any remaining tasks running at this point so
+			 * we can probably ignore it without much consequences. */
+			if (STARPU_UNLIKELY(err != cudaSuccess && err != cudaErrorCudartUnloading))
 				STARPU_CUDA_REPORT_ERROR(err);
-#endif
+#else
+			if (STARPU_UNLIKELY(err != cudaSuccess))
+				STARPU_CUDA_REPORT_ERROR(err);
+#endif /* STARPU_OPENMP */
+#endif /* STARPU_SIMGRID */
 			break;
 		}
-#endif
+#endif /* STARPU_USE_CUDA || STARPU_SIMGRID */
+
 #if defined(STARPU_USE_OPENCL) || defined(STARPU_SIMGRID)
                 case STARPU_OPENCL_RAM:
 		{

+ 12 - 11
src/drivers/cuda/driver_cuda.c

@@ -3,7 +3,7 @@
  * Copyright (C) 2011,2012,2014,2016,2017                 Inria
  * Copyright (C) 2008-2019                                Université de Bordeaux
  * Copyright (C) 2010                                     Mehdi Juhoor
- * Copyright (C) 2010-2017                                CNRS
+ * Copyright (C) 2010-2017,2019                           CNRS
  * Copyright (C) 2013                                     Thibaut Lambert
  * Copyright (C) 2011                                     Télécom-SudParis
  * Copyright (C) 2016                                     Uppsala University
@@ -276,18 +276,19 @@ void starpu_cuda_set_device(unsigned devid STARPU_ATTRIBUTE_UNUSED)
 #if !defined(STARPU_HAVE_CUDA_MEMCPY_PEER) && defined(HAVE_CUDA_GL_INTEROP_H)
 done:
 #endif
-	if (STARPU_UNLIKELY(cures
 #ifdef STARPU_OPENMP
-		/* When StarPU is used as Open Runtime support,
-		 * starpu_omp_shutdown() will usually be called from a
-		 * destructor, in which case cudaThreadExit() reports a
-		 * cudaErrorCudartUnloading here. There should not
-		 * be any remaining tasks running at this point so
-		 * we can probably ignore it without much consequences. */
-		&& cures != cudaErrorCudartUnloading
-#endif /* STARPU_OPENMP */
-				))
+	/* When StarPU is used as Open Runtime support,
+	 * starpu_omp_shutdown() will usually be called from a
+	 * destructor, in which case cudaThreadExit() reports a
+	 * cudaErrorCudartUnloading here. There should not
+	 * be any remaining tasks running at this point so
+	 * we can probably ignore it without much consequences. */
+	if (STARPU_UNLIKELY(cures && cures != cudaErrorCudartUnloading))
 		STARPU_CUDA_REPORT_ERROR(cures);
+#else
+	if (STARPU_UNLIKELY(cures))
+		STARPU_CUDA_REPORT_ERROR(cures);
+#endif /* STARPU_OPENMP */
 #endif
 }
 

+ 5 - 2
src/drivers/gordon/driver_gordon.c

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2008-2015,2017,2018                      Université de Bordeaux
  * Copyright (C) 2011,2012                                Inria
- * Copyright (C) 2010,2011,2013,2015-2017                 CNRS
+ * Copyright (C) 2010,2011,2013,2015-2017,2019            CNRS
  * Copyright (C) 2011                                     Télécom-SudParis
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -199,8 +199,9 @@ static void gordon_callback_list_func(void *arg)
 
 //	_STARPU_DEBUG("gordon callback : push job j %p\n", task_wrapper->j);
 
+#ifndef STARPU_SIMGRID
 	unsigned task_cnt = 0;
-
+#endif
 	/* XXX 0 was hardcoded */
 	while (!_starpu_job_list_empty(wrapper_list))
 	{
@@ -222,7 +223,9 @@ static void gordon_callback_list_func(void *arg)
 		_starpu_handle_job_termination(j);
 		//starpu_wake_all_blocked_workers();
 
+#ifndef STARPU_SIMGRID
 		task_cnt++;
+#endif
 	}
 
 	/* the job list was allocated by the gordon driver itself */

+ 11 - 11
starpurm/dev/chameleon_test/dgemm.c

@@ -130,7 +130,7 @@ static void test(void *_args)
 
 	const double alpha = (double)rand_r(&rand_seed) / ((double)rand_r(&rand_seed) + DBL_MIN);
 	const double beta  = (double)rand_r(&rand_seed) / ((double)rand_r(&rand_seed) + DBL_MIN);
- 
+
 	int i;
 	for (i = 0; i < m; i++)
 	{
@@ -142,10 +142,10 @@ static void test(void *_args)
 		}
 	}
 
-	int res = MORSE_dgemm(transA, transB, m, n, k, alpha, A, k, B, n, beta, C, n);
+	MORSE_dgemm(transA, transB, m, n, k, alpha, A, k, B, n, beta, C, n);
 #ifdef CHECK
 	/* Check */
-	cblas_dgemm( CblasColMajor, 
+	cblas_dgemm( CblasColMajor,
 			( CBLAS_TRANSPOSE ) transA,
 			( CBLAS_TRANSPOSE ) transB,
 			m, n, k,
@@ -208,7 +208,7 @@ void spawn_tests(int cpu_offset, int cpu_nb, int cuda_offset, int cuda_nb, void
 		char str2[strl2+1];
 		hwloc_bitmap_snprintf(str2, strl2+1, cuda_cpuset);
 		printf("all cpus cpuset = %s\n", str1);
-		
+
 		int strl3 = hwloc_bitmap_snprintf(NULL, 0, sel_cpuset);
 		char str3[strl3+1];
 		hwloc_bitmap_snprintf(str3, strl1+3, sel_cpuset);
@@ -242,17 +242,17 @@ int main( int argc, char const *argv[])
 	int k = atoi(argv[3]);
 	if (k < 1)
 		usage();
-	
-	if (strcmp(argv[4], "T") == 0) 
+
+	if (strcmp(argv[4], "T") == 0)
 		transA = MorseTrans;
-	else if (strcmp(argv[4], "N") == 0) 
+	else if (strcmp(argv[4], "N") == 0)
 		transA = MorseNoTrans;
 	else
 		usage();
-	
-	if (strcmp(argv[5], "T") == 0) 
+
+	if (strcmp(argv[5], "T") == 0)
 		transB = MorseTrans;
-	else if (strcmp(argv[5], "N") == 0) 
+	else if (strcmp(argv[5], "N") == 0)
 		transB = MorseNoTrans;
 	else
 		usage();
@@ -289,7 +289,7 @@ int main( int argc, char const *argv[])
 	}
 	{
 		int cpu_offset = rm_nb_cpu_units/2;
-		int cpu_nb = rm_nb_cpu_units/2;
+		int cpu_nb = cpu_offset;
 		if (cpu_nb == 0 && rm_nb_cpu_units > 0)
 		{
 			cpu_nb = 1;

+ 3 - 0
tools/dev/cppcheck/suppressions.txt

@@ -50,6 +50,7 @@ unreadVariable:tests/datawizard/variable_size.c
 uselessAssignmentPtrArg:mpi/src/starpu_mpi.c:171
 unreadVariable:mpi/src/starpu_mpi.c:971
 unusedVariable:mpi/src/starpu_mpi.c:972
+unreadVariable:mpi/src/load_balancer/policy/load_heat_propagation.c:578
 
 redundantAssignment:src/core/workers.c
 invalidPointerCast:src/core/perfmodel/perfmodel_nan.c:74
@@ -64,6 +65,7 @@ unreadVariable:src/datawizard/interfaces/*
 unreadVariable:src/drivers/driver_common/driver_common.c:493
 clarifyCondition:src/drivers/opencl/driver_opencl.c:945
 unreadVariable:src/drivers/opencl/driver_opencl.c:767
+redundantAssignment:src/drivers/opencl/driver_opencl.c:831
 clarifyCondition:src/drivers/cuda/driver_cuda.c:498
 arithOperationsOnVoidPointer:src/drivers/scc/*
 nullPointerRedundantCheck:src/sched_policies/deque_modeling_policy_data_aware.c:198
@@ -77,6 +79,7 @@ unreadVariable:gcc-plugin/tests/*
 negativeIndex:gcc-plugin/src/*
 
 pointerSize:socl/src/cl_getcontextinfo.c:33
+unreadVariable:socl/src/gc.c:193
 
 // the following warnings are weird and not understandable, let's ignore them
 ignoredReturnValue:socl/src/cl_createkernel.c:170