public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/64533] New: [5 Regression] [SH] alloca generates unsafe code
@ 2015-01-08  1:41 kkojima at gcc dot gnu.org
  2015-01-08  9:05 ` [Bug target/64533] " kkojima at gcc dot gnu.org
  2015-01-08 10:01 ` kkojima at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: kkojima at gcc dot gnu.org @ 2015-01-08  1:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64533

            Bug ID: 64533
           Summary: [5 Regression] [SH] alloca generates unsafe code
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kkojima at gcc dot gnu.org
            Target: sh*-*-*

The trunk compiler compiles

  void *foo() { return alloca (0x400);}

to

foo:
        mov.l   r14,@-r15
        mov     r15,r1
        mov     r15,r14
        mov.w   .L2,r15        (*)
        add     r1,r15
        mov     r15,r0
        mov     r14,r15
        rts
        mov.l   @r15+,r14
        .align 1
.L2:
        .short  -1028

with -O2.
r15 has been set -1028 at (*) which isn't always safe.  For example
sh-linux uses the negative stack values for software roll-back and
I've got a few sporadic and unreproducible errors on libjava testsuite
because of this.  I've introduced a splitter which splits rA := rB + N
to rA := N and rA := rA + rB for LRA's register elimination phase.
It should take rA=r15 case into account.  I'm testing the patch below.

--- config/sh/sh.md
+++ config/sh/sh.md
@@ -2061,9 +2061,10 @@
 ;; The problem is that LRA expects something like
 ;;    (set rA (plus rB (const_int N)))
 ;; to work.  We can do that, but we have to split out an additional reg-reg
-;; copy before the actual add insn.
+;; copy before the actual add insn.  Use u constraint for that case to avoid
+;; the invalid value in the stack pointer.
 (define_insn_and_split "*addsi3_compact"
-  [(set (match_operand:SI 0 "arith_reg_dest" "=r,&r")
+  [(set (match_operand:SI 0 "arith_reg_dest" "=r,&u")
     (plus:SI (match_operand:SI 1 "arith_operand" "%0,r")
          (match_operand:SI 2 "arith_or_int_operand" "rI08,rn")))]
   "TARGET_SH1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug target/64533] [5 Regression] [SH] alloca generates unsafe code
  2015-01-08  1:41 [Bug target/64533] New: [5 Regression] [SH] alloca generates unsafe code kkojima at gcc dot gnu.org
@ 2015-01-08  9:05 ` kkojima at gcc dot gnu.org
  2015-01-08 10:01 ` kkojima at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: kkojima at gcc dot gnu.org @ 2015-01-08  9:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64533

--- Comment #1 from Kazumoto Kojima <kkojima at gcc dot gnu.org> ---
Author: kkojima
Date: Thu Jan  8 09:05:06 2015
New Revision: 219338

URL: https://gcc.gnu.org/viewcvs?rev=219338&root=gcc&view=rev
Log:
PR target/64533
* config/sh/sh.md (*addsi3_compact): Use u constraint instead
of r for the second alternative of the destination operand.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/sh/sh.md


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug target/64533] [5 Regression] [SH] alloca generates unsafe code
  2015-01-08  1:41 [Bug target/64533] New: [5 Regression] [SH] alloca generates unsafe code kkojima at gcc dot gnu.org
  2015-01-08  9:05 ` [Bug target/64533] " kkojima at gcc dot gnu.org
@ 2015-01-08 10:01 ` kkojima at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: kkojima at gcc dot gnu.org @ 2015-01-08 10:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64533

Kazumoto Kojima <kkojima at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #2 from Kazumoto Kojima <kkojima at gcc dot gnu.org> ---
Fixed.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-01-08 10:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-08  1:41 [Bug target/64533] New: [5 Regression] [SH] alloca generates unsafe code kkojima at gcc dot gnu.org
2015-01-08  9:05 ` [Bug target/64533] " kkojima at gcc dot gnu.org
2015-01-08 10:01 ` kkojima at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).