Subject: bug#78473: 30.1; feature/igc: multiple crashes with pgtk_handle_selection_*

From: Paul Eggert <[email-masked]>
Date: Tue, 20 May 2025 11:31:04 -0700

On 2025-05-20 09:20, Pip Cet wrote:
> Thanks for confirming this, Oliver.  I've added Paul Eggert and Po Lu to
> CC.

Thanks, this looks pretty serious and I see no easy workaround in Emacs. 
Let's disable tree-sra in GCC until the GCC bug is fixed. Proposed patch 
to Emacs master attached.
From fc642fc8ec24a6d256d0e46f9964920c0be3cb5d Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Tue, 20 May 2025 11:28:49 -0700
Subject: [PATCH] Work around GCC bug 117423

Problem reported by Oliver Reiter and Pip Cet (Emacs bug#78473).
It looks like GCC tree-sra is trouble in general with how Emacs
uses unions, so disable tree-sra until the GCC bug is fixed.
* configure.ac (C_SWITCH_MACHINE): Also work around GCC bug 117423.
---
 configure.ac | 85 ++++++++++++++++++++++++++--------------------------
 1 file changed, 43 insertions(+), 42 deletions(-)

diff --git a/configure.ac b/configure.ac
index fddb2b9be3c..bafbb748149 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2209,49 +2209,50 @@ AC_DEFUN
 
 C_SWITCH_MACHINE=
 
-AC_CACHE_CHECK([for flags to work around GCC bug 58416],
-  [emacs_cv_gcc_bug_58416_CFLAGS],
-  [emacs_cv_gcc_bug_58416_CFLAGS='none needed'
-   AS_CASE([$canonical],
-     [[i[3456]86-* | x86_64-*]],
-       [AS_IF([test "$GCC" = yes],
-	  [old_CFLAGS=$CFLAGS
-	   # If no flags are needed (e.g., not GCC 4+), don't use any.
-	   # Otherwise, use -mfpmath=sse if already assuming SSE2.
-	   # Otherwise, use -fno-tree-sra.
-	   for emacs_cv_gcc_bug_58416_CFLAGS in \
-	       'none needed' -mfpmath=sse -fno-tree-sra
-	   do
-	     AS_CASE([$emacs_cv_gcc_bug_58416_CFLAGS],
-	       ['none needed'], [],
-	       [-fno-tree-sra], [break],
-	       [CFLAGS="$old_CFLAGS $emacs_cv_gcc_bug_58416_CFLAGS"])
-	     AC_COMPILE_IFELSE(
-	       [AC_LANG_DEFINES_PROVIDED
-		[/* Work around GCC bug with double in unions on x86,
-		    where the generated insns copy non-floating-point data
-		    via fldl/fstpl instruction pairs.  This can misbehave if
-		    the data's bit pattern looks like a NaN.  See, e.g.:
-		       https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58416#c10
-		       https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71460
-		       https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93271
-		       https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114659
-		    Problem observed with 'gcc -m32' with GCC 14.1.1
-		    20240607 (Red Hat 14.1.1-5) on x86-64.  */
-		 #include <float.h>
-		 #if \
-		     (4 <= __GNUC__ && __GNUC__ <= 14 && !defined __clang__ \
-		      && (defined __i386__ || defined __x86_64__) \
-		      && ! (0 <= FLT_EVAL_METHOD && FLT_EVAL_METHOD <= 1))
-		 # error "GCC bug 58416 is possibly present"
-		 #endif
-	       ]],
-	       [break])
-	   done
-	   CFLAGS=$old_CFLAGS])])])
-AS_CASE([$emacs_cv_gcc_bug_58416_CFLAGS],
+AC_CACHE_CHECK([for flag to work around GCC bug 117423],
+  [emacs_cv_gcc_bug_117423_CFLAGS],
+  [emacs_cv_gcc_bug_117423_CFLAGS='none needed'
+   AS_IF([test "$GCC" = yes],
+     [old_CFLAGS=$CFLAGS
+      # If no flags are needed (e.g., not GCC 4+), don't use any.
+      # Otherwise, use -fno-tree-sra.
+      for emacs_cv_gcc_bug_117423_CFLAGS in \
+	  'none needed' -fno-tree-sra
+      do
+	AS_CASE([$emacs_cv_gcc_bug_117423_CFLAGS],
+	  ['none needed'], [],
+	  [-fno-tree-sra], [break],
+	  [CFLAGS="$old_CFLAGS $emacs_cv_gcc_bug_117423_CFLAGS"])
+	AC_COMPILE_IFELSE(
+	  [AC_LANG_DEFINES_PROVIDED
+	   [/* Work around GCC bug 117423 with unions containing holes:
+	       https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117423
+	       https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119085
+	       GCC bug 117423 is present even in GCC 15.1,
+	       the current version as of this writing; for now,
+	       assume it is present in all GCC versions starting with GCC 4.
+
+	       Working wround GCC bug 117423 also works around GCC bug 58416
+	       with double in unions on x86, where the generated insns
+	       copy non-floating-point data via fldl/fstpl instruction pairs.
+	       This can misbehave if the data's bit pattern looks like a NaN.
+	       See, e.g.:
+		 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58416#c10
+		 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71460
+		 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93271
+		 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114659
+	       Although GCC bug 58416 is fixed in GCC 15.1,
+	       GCC bug 117423 is still present there.  */
+	    #if 4 <= __GNUC__ && !defined __clang__
+	    # error "GCC bug 117423 possibly present"
+	    #endif
+	  ]],
+	  [break])
+      done
+      CFLAGS=$old_CFLAGS])])
+AS_CASE([$emacs_cv_gcc_bug_117423_CFLAGS],
   [-*],
-    [C_SWITCH_MACHINE="$C_SWITCH_MACHINE $emacs_cv_gcc_bug_58416_CFLAGS"])
+    [C_SWITCH_MACHINE="$C_SWITCH_MACHINE $emacs_cv_gcc_bug_117423_CFLAGS"])
 
 AC_SUBST([C_SWITCH_MACHINE])
 
-- 
2.48.1