[clang] [clang-tools-extra] [llvm] [LLVM][CLANG] Update signal-handling behavior to comply with POSIX (PR #169340)

Xing Xue via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 9 08:26:49 PST 2026


================
@@ -321,14 +323,23 @@ static void RegisterHandlers() { // Not signal-safe.
       NewHandler.sa_flags = SA_NODEFER | SA_RESETHAND | SA_ONSTACK | SA_SIGINFO;
       break;
     case SignalKind::IsInfo:
-      NewHandler.sa_handler = InfoSignalHandler;
+      if (NeedsPOSIXUtilitySignalHandling)
+        // If POSIX signal-handling semantics are followed, the signal handler
+        // resignal itself to terminate after handling the signal.
+        NewHandler.sa_handler = InfoSignalHandlerTerminate;
+      else
+        NewHandler.sa_handler = InfoSignalHandler;
       NewHandler.sa_flags = SA_ONSTACK;
       break;
     }
     sigemptyset(&NewHandler.sa_mask);
 
-    // Install the new handler, save the old one in RegisteredSignalInfo.
-    sigaction(Signal, &NewHandler, &RegisteredSignalInfo[Index].SA);
+    // Install the new handler if the signal disposition isn't SIG_IGN,
+    // save the old one in RegisteredSignalInfo.
+    struct sigaction act;
----------------
xingxue-ibm wrote:

I thought that if the signal disposition is explicitly set to `SIG_IGN`, it should be honored. I agree that this patch should change the behavior of `clang` only and not affect other utilities. Changed to guard the new behavior with `NeedsPOSIXUtilitySignalHandling`.

https://github.com/llvm/llvm-project/pull/169340


More information about the llvm-commits mailing list