bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: warnings in unit tests


From: Dmitry V. Levin
Subject: Re: warnings in unit tests
Date: Wed, 9 Jun 2021 16:35:41 +0300

On Tue, Jun 08, 2021 at 09:42:55AM -0700, Paul Eggert wrote:
> For what it's worth I'm more with Bruno on this. For the tests, the cost 
> of these warnings outweighs the benefit.
> 
> It'd be OK with me to disable the troublesome warnings globally for the 
> tests subdirectory, using -Wno-missing-prototypes or whatever.
> 
> For the -Wnull-dereference issue it may be worthwhile to use a 
> circumlocution that fools GCC into not issuing the warning. After all, a 
> compiler smart enough to warn about '*(volatile int *) 0 = 42' might 
> also be smart enough to see that it's undefined behavior and therefore 
> omit the assignment's effect entirely. Perhaps something like the 
> attached (untested) patch?

> diff --git a/tests/test-sigsegv-catch-stackoverflow2.c 
> b/tests/test-sigsegv-catch-stackoverflow2.c
> index b94d1310b..bfd4617a3 100644
> --- a/tests/test-sigsegv-catch-stackoverflow2.c
> +++ b/tests/test-sigsegv-catch-stackoverflow2.c
> @@ -50,6 +50,7 @@ sigset_t mainsigset;
>  
>  volatile int pass = 0;
>  uintptr_t page;
> +int volatile *null_pointer_to_volatile;
>  
>  static void
>  stackoverflow_handler_continuation (void *arg1, void *arg2, void *arg3)
> @@ -183,7 +184,7 @@ main ()
>        *(volatile int *) (page + 0x678) = 42;
>        break;
>      case 3:
> -      *(volatile int *) 0 = 42;
> +      *null_pointer_to_volatile = 42;
>        break;
>      case 4:
>        break;

Thanks, this patch works, I'd definitely prefer applying it rather than
disabling -Wnull-dereference.


-- 
ldv



reply via email to

[Prev in Thread] Current Thread [Next in Thread]