Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Ensure that the clang optimizer does not swallow the segfault I'm expecting
[simgrid.git] / teshsuite / mc / random-bug / random-bug.cpp
index 7d987d2..ba82292 100644 (file)
@@ -1,9 +1,10 @@
-/* Copyright (c) 2014-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2014-2023. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * 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,9 +31,8 @@ static void app()
     if (x == 3 && y == 4)
       abort();
   } else if (behavior == Behavior::SEGV) {
-    int* A = 0;
     if (x == 3 && y == 4)
-      *A = 1;
+      kill(getpid(), SIGSEGV); // Simulate a segfault without displeasing the static analyzers
   } else {
     DIE_IMPOSSIBLE;
   }
@@ -56,13 +56,12 @@ int main(int argc, char* argv[])
     XBT_INFO("Behavior: segv");
     behavior = Behavior::SEGV;
   } else {
-    xbt_die("Please use either 'abort', 'assert', 'printf', or 'segv' as first parameter, to specify what to do when "
-            "the error "
-            "is found.");
+    xbt_die("Please use either 'abort', 'assert', 'printf', or 'segv' as first parameter,"
+            " to specify what to do when the error is found.");
   }
 
   e.load_platform(argv[2]);
 
-  simgrid::s4u::Actor::create("app", simgrid::s4u::Host::by_name("Fafard"), &app);
+  simgrid::s4u::Actor::create("app", e.host_by_name("Fafard"), &app);
   e.run();
 }