Without volatile, clang turns that statement into a call to abort. It is discussed here (Chris Lattner's blog from 2011) http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html
Here is the relevant paragraph If you're using an LLVM-based compiler, you can dereference a "volatile" null pointer to get a crash if that's what you're looking for, since volatile loads and stores are generally not touched by the optimizer. There is currently no flag that enables random NULL pointer loads to be treated as valid accesses or to make random loads know that their pointer is "allowed to be null". Taylor -----Original Message----- From: Alex Bennée <alex.ben...@linaro.org> Sent: Friday, November 15, 2019 6:17 AM To: Taylor Simpson <tsimp...@quicinc.com> Cc: qemu-devel@nongnu.org Subject: Re: [PATCH] Modify tests to work with clang ------------------------------------------------------------------------- CAUTION: This email originated from outside of the organization. ------------------------------------------------------------------------- Taylor Simpson <tsimp...@quicinc.com> writes: > Signed-off-by: Taylor Simpson <tsimp...@quicinc.com> > --- > tests/tcg/multiarch/float_helpers.c | 13 ++++++++++++- > tests/tcg/multiarch/linux-test.c | 2 +- > 2 files changed, 13 insertions(+), 2 deletions(-) > > diff --git a/tests/tcg/multiarch/float_helpers.c > b/tests/tcg/multiarch/float_helpers.c > index 8ee7903..437247c 100644 > --- a/tests/tcg/multiarch/float_helpers.c > +++ b/tests/tcg/multiarch/float_helpers.c <snip> > diff --git a/tests/tcg/multiarch/linux-test.c > b/tests/tcg/multiarch/linux-test.c > index 673d7c8..edfc02c 100644 > --- a/tests/tcg/multiarch/linux-test.c > +++ b/tests/tcg/multiarch/linux-test.c > @@ -485,7 +485,7 @@ static void test_signal(void) > act.sa_flags = SA_SIGINFO; > chk_error(sigaction(SIGSEGV, &act, NULL)); > if (setjmp(jmp_env) == 0) { > - *(uint8_t *)0 = 0; > + *(volatile uint8_t *)0 = 0; This looks suspicious - volatile is almost never the answer to a question. What are we trying to achieve here? > } > > act.sa_handler = SIG_DFL; -- Alex Bennée