diff options
author | William R. Dieter <william.r.dieter@intel.com> | 2021-10-29 22:00:16 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-11-02 13:03:27 (GMT) |
commit | 7c90d00af9481250bf42f09db8c29dd5b1bec323 (patch) | |
tree | cf2ad38a74360942faa94433953e4e281d08bc1a /Tests/CTestTestCrash/crash.cxx | |
parent | 41907da8eaf7a6c64fd4db17f90be69c1eeb7eb9 (diff) | |
download | CMake-7c90d00af9481250bf42f09db8c29dd5b1bec323.zip CMake-7c90d00af9481250bf42f09db8c29dd5b1bec323.tar.gz CMake-7c90d00af9481250bf42f09db8c29dd5b1bec323.tar.bz2 |
Tests: Prevent compiler optimizing away test code in CTestTestCrash
The CTestTestCrash tries to force a crash by dereferencing a NULL
pointer. The oneAPI 2021.4 C compiler notices that the pointer and the
value fetched from the pointer are never used and optimizes away the
dereferencing of the NULL pointer, which prevents the crash, causing
the test to fail.
This change adds the `volatile` keyword the pointer to prevent the
compiler optimizing it away. Removing a reference to a `volatile`
variable is illegal because access to a `volatile` variable could have
side effects not observable by the compiler.
Signed-off-by: William R. Dieter <william.r.dieter@intel.com>
Diffstat (limited to 'Tests/CTestTestCrash/crash.cxx')
-rw-r--r-- | Tests/CTestTestCrash/crash.cxx | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Tests/CTestTestCrash/crash.cxx b/Tests/CTestTestCrash/crash.cxx index 370c3fb..88d4b1d 100644 --- a/Tests/CTestTestCrash/crash.cxx +++ b/Tests/CTestTestCrash/crash.cxx @@ -1,6 +1,6 @@ // causes a segfault int main() { - int* ptr = 0; + volatile int* ptr = 0; *ptr = 1; } |