]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix internal error in seh_cfa_offset with -O2 -fno-omit-frame-pointer
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 22 May 2024 16:10:39 +0000 (18:10 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Wed, 22 May 2024 16:13:54 +0000 (18:13 +0200)
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.

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

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

gcc/fold-mem-offsets.cc
gcc/testsuite/g++.dg/opt/fmo1.C [new file with mode: 0644]

index 2e15b05529edac70bddbf881c8ddf54685ddb055..84b9623058bd4cdb5c8f77d78d5d7c71571472d8 100644 (file)
@@ -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));
diff --git a/gcc/testsuite/g++.dg/opt/fmo1.C b/gcc/testsuite/g++.dg/opt/fmo1.C
new file mode 100644 (file)
index 0000000..f0ae624
--- /dev/null
@@ -0,0 +1,25 @@
+// PR rtl-optimization/115038
+// Reported by Christoph Reiter <reiter.christoph@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;