diff mbox series

[7/7] opeposix: pthread_barrierattr_getpshared/2-1: Simplify codeflow

Message ID 20220620092146.7604-8-chrubis@suse.cz
State Accepted
Headers show
Series openposix: Fix 'no return in nonvoid function' warnings | expand

Commit Message

Cyril Hrubis June 20, 2022, 9:21 a.m. UTC
This actually fixes a 'no return in nonvoid function' warning since gcc
may get confused during the codeflow analysis.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 .../interfaces/pthread_barrierattr_getpshared/2-1.c   | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Comments

Martin Doucha June 23, 2022, 12:38 p.m. UTC | #1
Hi,
one small suggestion below, otherwise for the whole patchset:

Reviewed-by: Martin Doucha <mdoucha@suse.cz>

On 20. 06. 22 11:21, Cyril Hrubis wrote:
> This actually fixes a 'no return in nonvoid function' warning since gcc
> may get confused during the codeflow analysis.
> 
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>  .../interfaces/pthread_barrierattr_getpshared/2-1.c   | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrierattr_getpshared/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrierattr_getpshared/2-1.c
> index a21a5a507..52c074173 100644
> --- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrierattr_getpshared/2-1.c
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrierattr_getpshared/2-1.c
> @@ -141,7 +141,9 @@ int main(void)
>  	if (pid == -1) {
>  		perror("Error at fork()");
>  		return PTS_UNRESOLVED;
> -	} else if (pid == 0) {
> +	}
> +
> +	if (pid == 0) {
>  		/* Child */
>  		/* Map the shared object to child's memory */
>  		barrier =
> @@ -209,10 +211,7 @@ int main(void)
>  
>  		printf("Test PASSED\n");
>  		return PTS_PASS;
> +	} else {
> +		return serial;

The return can be unconditional.

>  	}
> -
> -	if (pid == 0) {
> -		exit(serial);
> -	}
> -
>  }
Richard Palethorpe July 5, 2022, 5:35 a.m. UTC | #2
Hello,

Martin Doucha <mdoucha@suse.cz> writes:

> Hi,
> one small suggestion below, otherwise for the whole patchset:
>
> Reviewed-by: Martin Doucha <mdoucha@suse.cz>
>
> On 20. 06. 22 11:21, Cyril Hrubis wrote:
>> This actually fixes a 'no return in nonvoid function' warning since gcc
>> may get confused during the codeflow analysis.
>> 
>> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
>> ---
>>  .../interfaces/pthread_barrierattr_getpshared/2-1.c   | 11 +++++------
>>  1 file changed, 5 insertions(+), 6 deletions(-)
>> 
>> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrierattr_getpshared/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrierattr_getpshared/2-1.c
>> index a21a5a507..52c074173 100644
>> --- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrierattr_getpshared/2-1.c
>> +++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrierattr_getpshared/2-1.c
>> @@ -141,7 +141,9 @@ int main(void)
>>  	if (pid == -1) {
>>  		perror("Error at fork()");
>>  		return PTS_UNRESOLVED;
>> -	} else if (pid == 0) {
>> +	}
>> +
>> +	if (pid == 0) {
>>  		/* Child */
>>  		/* Map the shared object to child's memory */
>>  		barrier =
>> @@ -209,10 +211,7 @@ int main(void)
>>  
>>  		printf("Test PASSED\n");
>>  		return PTS_PASS;
>> +	} else {
>> +		return serial;
>
> The return can be unconditional.

And with that also:

Reviewed-by: Richard Palethorpe <rpalethorpe@suse.com>

>
>>  	}
>> -
>> -	if (pid == 0) {
>> -		exit(serial);
>> -	}
>> -
>>  }
>
>
> -- 
> Martin Doucha   mdoucha@suse.cz
> QA Engineer for Software Maintenance
> SUSE LINUX, s.r.o.
> CORSO IIa
> Krizikova 148/34
> 186 00 Prague 8
> Czech Republic
Cyril Hrubis July 14, 2022, 1:03 p.m. UTC | #3
Hi!
> > +	} else {
> > +		return serial;
> 
> The return can be unconditional.

I changed the code a bit more in the end to make it even more readable,
now it's structured as:

	if (pid == 0)
		return serial;

	/* parent */
	if (wait(&status) != pid) {
		...
	}
	...

	printf("Test PASSED\n");
	return PTS_PASS;
diff mbox series

Patch

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrierattr_getpshared/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrierattr_getpshared/2-1.c
index a21a5a507..52c074173 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrierattr_getpshared/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrierattr_getpshared/2-1.c
@@ -141,7 +141,9 @@  int main(void)
 	if (pid == -1) {
 		perror("Error at fork()");
 		return PTS_UNRESOLVED;
-	} else if (pid == 0) {
+	}
+
+	if (pid == 0) {
 		/* Child */
 		/* Map the shared object to child's memory */
 		barrier =
@@ -209,10 +211,7 @@  int main(void)
 
 		printf("Test PASSED\n");
 		return PTS_PASS;
+	} else {
+		return serial;
 	}
-
-	if (pid == 0) {
-		exit(serial);
-	}
-
 }