From b41e6a1f15f499dfd49ec43164fc833ad2ffc04c Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 2 Apr 2023 00:34:25 +0200 Subject: [PATCH] Ensure that the clang optimizer does not swallow the segfault I'm expecting Instead of actually dereferencing the null pointer (which drives the static analyzers nuts), simply send myself a SIGSEGV. --- teshsuite/mc/random-bug/random-bug.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/teshsuite/mc/random-bug/random-bug.cpp b/teshsuite/mc/random-bug/random-bug.cpp index 9bade15c0a..ba82292333 100644 --- a/teshsuite/mc/random-bug/random-bug.cpp +++ b/teshsuite/mc/random-bug/random-bug.cpp @@ -4,6 +4,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include +#include #include #include #include @@ -30,11 +31,8 @@ static void app() if (x == 3 && y == 4) abort(); } else if (behavior == Behavior::SEGV) { -#ifndef __clang_analyzer__ - int* A = nullptr; if (x == 3 && y == 4) - *A = 1; -#endif + kill(getpid(), SIGSEGV); // Simulate a segfault without displeasing the static analyzers } else { DIE_IMPOSSIBLE; } -- 2.20.1