public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Max Filippov <jcmvbkbc@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-3510] xtensa: Fix out-of-bounds array access in the movdi pattern
Date: Wed, 26 Oct 2022 17:03:39 +0000 (GMT)	[thread overview]
Message-ID: <20221026170339.AB742382DE00@sourceware.org> (raw)

https://gcc.gnu.org/g:f896c13489d22b30d01257bc8316ab97b3359d1c

commit r13-3510-gf896c13489d22b30d01257bc8316ab97b3359d1c
Author: Takayuki 'January June' Suwa <jjsuwa_sys3175@yahoo.co.jp>
Date:   Wed Oct 26 15:27:51 2022 +0900

    xtensa: Fix out-of-bounds array access in the movdi pattern
    
    The following new warnings were introduced in the commit
    4f3f0296acbb ("xtensa: Prepare the transition from Reload to LRA"):
    
    gcc/config/xtensa/xtensa.md:945:26: error: array subscript 3 is above
            array bounds of 'rtx_def* [2]' [-Werror=array-bounds]
      945 |           emit_move_insn (operands[2], operands[3]);
    gcc/config/xtensa/xtensa.md:945:26: error: array subscript 2 is above
            array bounds of 'rtx_def* [2]' [-Werror=array-bounds]
      945 |           emit_move_insn (operands[2], operands[3]);
    
    From gcc/insn-emit.cc (generated by building):
    
    > /* ../../gcc/config/xtensa/xtensa.md:932 */
    > rtx
    > gen_movdi (rtx operand0,
    >       rtx operand1)
    > {
    >   rtx_insn *_val = 0;
    >   start_sequence ();
    >   {
    >     rtx operands[2];                                  // only 2 elements
    >     operands[0] = operand0;
    >     operands[1] = operand1;
    > #define FAIL return (end_sequence (), _val)
    > #define DONE return (_val = get_insns (), end_sequence (), _val)
    > #line 936 "../../gcc/config/xtensa/xtensa.md"
    > {
    >   if (CONSTANT_P (operands[1]))
    >     {
    >       /* Split in halves if 64-bit Const-to-Reg moves
    >        because of offering further optimization opportunities.  */
    >       if (register_operand (operands[0], DImode))
    >       {
    >         xtensa_split_DI_reg_imm (operands);           // out-of-bounds!
    >         emit_move_insn (operands[0], operands[1]);
    >         emit_move_insn (operands[2], operands[3]);    // out-of-bounds!
    >         DONE;
    >       }
    
    gcc/ChangeLog:
    
            * config/xtensa/xtensa.md (movdi):
            Copy operands[0...1] to ops[0...3] and then use the latter before
            calling xtensa_split_DI_reg_imm() and emitting insns.

Diff:
---
 gcc/config/xtensa/xtensa.md | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md
index 2e7f76ada5c..de9bcbf24f7 100644
--- a/gcc/config/xtensa/xtensa.md
+++ b/gcc/config/xtensa/xtensa.md
@@ -940,9 +940,10 @@
 	 because of offering further optimization opportunities.  */
       if (register_operand (operands[0], DImode))
 	{
-	  xtensa_split_DI_reg_imm (operands);
-	  emit_move_insn (operands[0], operands[1]);
-	  emit_move_insn (operands[2], operands[3]);
+	  rtx ops[4] = { operands[0], operands[1] };
+	  xtensa_split_DI_reg_imm (ops);
+	  emit_move_insn (ops[0], ops[1]);
+	  emit_move_insn (ops[2], ops[3]);
 	  DONE;
 	}

                 reply	other threads:[~2022-10-26 17:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221026170339.AB742382DE00@sourceware.org \
    --to=jcmvbkbc@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).