Hi,

this is a regression present on mainline and 14 branch under the form of an 
ICE in seh_cfa_offset from config/i386/winnt.cc on the attached C++ testcase 
compiled with -O2 -fno-omit-frame-pointer.

The problem directly comes from the -ffold-mem-offsets pass messing up with 
the prologue and the frame-related instructions, which is a no-no with SEH, so 
the fix simply disconnects the pass in these circumstances, the question being 
whether this should be done unconditionally as in the fix or only with SEH.

Tested on x86-64/Linux, OK for the mainline and 14 branch?


2024-05-20  Eric Botcazou  <ebotca...@adacore.com>

        PR rtl-optimization/115038
        * fold-mem-offsets.cc (fold_offsets): Return 0 if the defining
        instruction of the register is frame related.


2024-05-20  Eric Botcazou  <ebotca...@adacore.com>

        * g++.dg/opt/fmo1.C: New test.

-- 
Eric Botcazou
diff --git a/gcc/fold-mem-offsets.cc b/gcc/fold-mem-offsets.cc
index 2e15b05529e..84b9623058b 100644
--- a/gcc/fold-mem-offsets.cc
+++ b/gcc/fold-mem-offsets.cc
@@ -491,7 +491,7 @@ fold_offsets (rtx_insn *insn, rtx reg, bool analyze, bitmap foldable_insns)
 {
   rtx_insn *def = get_single_def_in_bb (insn, reg);
 
-  if (!def || GET_CODE (PATTERN (def)) != SET)
+  if (!def || RTX_FRAME_RELATED_P (def) || GET_CODE (PATTERN (def)) != SET)
     return 0;
 
   rtx dest = SET_DEST (PATTERN (def));
// PR rtl-optimization/115038
// Reported by Christoph Reiter <reiter.christ...@gmail.com>

// { dg-do compile }
// { dg-options "-O2 -fno-omit-frame-pointer" }

struct d {
  d();
};

struct e {
  e() : c(1.0) {}
  float c;
};

class k {
  d g;
  e h;
};

class a {
  k f;
} a;

k b;

Reply via email to