Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Ensure that the clang optimizer does not swallow the segfault I'm expecting
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 1 Apr 2023 22:34:25 +0000 (00:34 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 1 Apr 2023 22:44:25 +0000 (00:44 +0200)
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

index 9bade15..ba82292 100644 (file)
@@ -4,6 +4,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include <cstring>
+#include <signal.h>
 #include <simgrid/modelchecker.h>
 #include <simgrid/s4u.hpp>
 #include <xbt/log.h>
@@ -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;
   }