re PR rtl-optimization/57451 (Incorrect debug ranges emitted for -freorder-blocks...
authorTeresa Johnson <tejohnson@google.com>
Tue, 20 Aug 2013 13:29:53 +0000 (13:29 +0000)
committerTeresa Johnson <tejohnson@gcc.gnu.org>
Tue, 20 Aug 2013 13:29:53 +0000 (13:29 +0000)
2013-08-20  Teresa Johnson  <tejohnson@google.com>

PR rtl-optimizations/57451
* final.c (reemit_insn_block_notes): Prevent lexical blocks
from crossing split section boundaries.

* testsuite/g++.dg/tree-prof/pr57451.C: New test.

From-SVN: r201883

gcc/ChangeLog
gcc/final.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/tree-prof/pr57451.C [new file with mode: 0644]

index c6a5893de33c5c8455d36db65f0893de3173b559..208b291a9c6c66bc2c4705bc3e484abc0fafb692 100644 (file)
@@ -1,3 +1,9 @@
+2013-08-20  Teresa Johnson  <tejohnson@google.com>
+
+       PR rtl-optimizations/57451
+       * final.c (reemit_insn_block_notes): Prevent lexical blocks
+       from crossing split section boundaries.
+
 2013-08-20  Matthew Gretton-Dann  <matthew.gretton-dann@linaro.org>
 
        * config/arm/linux-elf.h (MULTILIB_DEFAULTS): Remove definition.
index 31ced4f483be92157f34ce43b7ed358a563d6af7..4eaae0f2bc3a62f47fa428d88d28b40e6071c9a6 100644 (file)
@@ -1650,12 +1650,26 @@ reemit_insn_block_notes (void)
   rtx insn, note;
 
   insn = get_insns ();
-  if (!active_insn_p (insn))
-    insn = next_active_insn (insn);
-  for (; insn; insn = next_active_insn (insn))
+  for (; insn; insn = next_insn (insn))
     {
       tree this_block;
 
+      /* Prevent lexical blocks from straddling section boundaries.  */
+      if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_SWITCH_TEXT_SECTIONS)
+        {
+          for (tree s = cur_block; s != DECL_INITIAL (cfun->decl);
+               s = BLOCK_SUPERCONTEXT (s))
+            {
+              rtx note = emit_note_before (NOTE_INSN_BLOCK_END, insn);
+              NOTE_BLOCK (note) = s;
+              note = emit_note_after (NOTE_INSN_BLOCK_BEG, insn);
+              NOTE_BLOCK (note) = s;
+            }
+        }
+
+      if (!active_insn_p (insn))
+        continue;
+
       /* Avoid putting scope notes between jump table and its label.  */
       if (JUMP_TABLE_DATA_P (insn))
        continue;
index 3d2abb701fe980c5a097dc0d63bad4b1375adc49..f05e06808b010f20d8f823c51e23f3f20680e0d1 100644 (file)
@@ -1,3 +1,8 @@
+2013-08-20  Teresa Johnson  <tejohnson@google.com>
+
+       PR rtl-optimizations/57451
+       * g++.dg/tree-prof/pr57451.C: New test.
+
 2013-08-20  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/58190
diff --git a/gcc/testsuite/g++.dg/tree-prof/pr57451.C b/gcc/testsuite/g++.dg/tree-prof/pr57451.C
new file mode 100644 (file)
index 0000000..c69c130
--- /dev/null
@@ -0,0 +1,27 @@
+// { dg-do run }
+// { dg-require-effective-target freorder }
+// { dg-options "-O2 -freorder-blocks-and-partition -g" }
+
+extern "C" void abort (void);
+struct MyException {};
+struct Data {
+    int nr;
+    Data() : nr(66) {}
+};
+Data __attribute__((noinline,noclone)) getData(int i)
+{
+  if (i) throw MyException();
+  Data data;
+  data.nr = i;
+  return data;
+}
+int main(int, char **)
+{
+  Data data;
+  try {
+      data = getData(1);
+  } catch (MyException& e) {
+      if (data.nr != 66)
+       abort ();
+  }
+}