[Top][All Lists]

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

Re: warnings in unit tests

From: Bruno Haible
Subject: Re: warnings in unit tests
Date: Wed, 09 Jun 2021 21:38:12 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-210-generic; KDE/5.18.0; x86_64; ; )

Paul Eggert wrote:
> 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.

Good point. Yes, when GCC "recognizes" undefined behaviour, it likes
to omit the entire code branch (basic block). Even if it does not do so
today, it might do so in the future. I've applied your patch like this
(here and in libsigsegv):

2021-06-09  Bruno Haible  <bruno@clisp.org>

        sigsegv tests: Hide a null pointer from the compiler's optimizations.
        Patch by Paul Eggert.
        * tests/test-sigsegv-catch-stackoverflow2.c
        (null_pointer_to_volatile_int): New variable.
        (main): Use it.

diff --git a/tests/test-sigsegv-catch-stackoverflow2.c 
index b94d131..a491fd2 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;
+volatile int *null_pointer_to_volatile_int /* = NULL */;
 static void
 stackoverflow_handler_continuation (void *arg1, void *arg2, void *arg3)
@@ -183,7 +184,7 @@ main ()
       *(volatile int *) (page + 0x678) = 42;
     case 3:
-      *(volatile int *) 0 = 42;
+      *null_pointer_to_volatile_int = 42;
     case 4:

reply via email to

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