]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[compare-debug] use call loc for nop_endbr
authorAlexandre Oliva <aoliva@redhat.com>
Thu, 14 Dec 2017 15:03:09 +0000 (15:03 +0000)
committerAlexandre Oliva <aoliva@gcc.gnu.org>
Thu, 14 Dec 2017 15:03:09 +0000 (15:03 +0000)
We skip debug insns and notes after a call that needs a nop_endbr, but
since a debug insn could be the last in a block, it may affect the loc
in the emitted nop_endbr insn.  Although this has no effect on
codegen, it does mess with debug info a bit, and it causes
-fcompare-debug to fail for e.g. libsanitizer's
tsan/tsan_platform_linux.cc on x86_64.

So, pick the location of the call insn for the nop_endbr insn, to
avoid the line number differences in dumps, including -fcompare-debug
ones.

Also, we don't need to determine what the insert point would be unless
we're actually emitting the nop_endbr insn after the call, so
rearrange the code to avoid wasting cycles.

Finally, it seems like testing for barriers is a mistake.  We probably
never actually pass that test, for the barriers would hit BB_END
first.  If we did, we'd end up emitting the nop_endbr outside any BB,
even after the end of the function!  That would be Very Bad (TM).
Now, since the test as it is can't hurt, I figured I wouldn't change
the logic right now, just add a comment so that someone involved in
endbr stuff can have a second look and hopefully fix it.

for  gcc/ChangeLog

* config/i386/i386.c (rest_of_insert_endbranch): Use call loc
for its nop_endbr.

From-SVN: r255639

gcc/ChangeLog
gcc/config/i386/i386.c

index 4d7f67ccb8f2fdddf7263518f0637c8268ea4f69..5805e116ff5e61bd1a4c6a551afcedce7599a8d9 100644 (file)
@@ -1,5 +1,8 @@
 2017-12-14  Alexandre Oliva <aoliva@redhat.com>
 
+       * config/i386/i386.c (rest_of_insert_endbranch): Use call loc
+       for its nop_endbr.
+
        PR bootstrap/83396
        * config/arc/arc.c (hwloop_optimize): Skip debug insns.
        * config/sh/sh-protos.h (sh_find_set_of_reg): Adjust.
index 051c3e56d8219636f5d35103bb10a1a7e9856811..35037434bf50ec26bd254e444542b29e4f04360e 100644 (file)
@@ -2609,21 +2609,25 @@ rest_of_insert_endbranch (void)
        {
          if (INSN_P (insn) && GET_CODE (insn) == CALL_INSN)
            {
-             rtx_insn *next_insn = insn;
+             if (find_reg_note (insn, REG_SETJMP, NULL) == NULL)
+               continue;
+             /* Generate ENDBRANCH after CALL, which can return more than
+                twice, setjmp-like functions.  */
 
+             /* Skip notes and debug insns that must be next to the
+                call insn.  ??? This might skip a lot more than
+                that...  ??? Skipping barriers and emitting code
+                after them surely looks like a mistake; we probably
+                won't ever hit it, for we'll hit BB_END first.  */
+             rtx_insn *next_insn = insn;
              while ((next_insn != BB_END (bb))
                      && (DEBUG_INSN_P (NEXT_INSN (next_insn))
                          || NOTE_P (NEXT_INSN (next_insn))
                          || BARRIER_P (NEXT_INSN (next_insn))))
                next_insn = NEXT_INSN (next_insn);
 
-             /* Generate ENDBRANCH after CALL, which can return more than
-                twice, setjmp-like functions.  */
-             if (find_reg_note (insn, REG_SETJMP, NULL) != NULL)
-               {
-                 cet_eb = gen_nop_endbr ();
-                 emit_insn_after (cet_eb, next_insn);
-               }
+             cet_eb = gen_nop_endbr ();
+             emit_insn_after_setloc (cet_eb, next_insn, INSN_LOCATION (insn));
              continue;
            }