public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "zsojka at seznam dot cz" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/105368] [10/11/12 Regression] ICE: SIGSEGV in powi_lookup_cost (tree-ssa-math-opts.cc:1441) with -Ofast and __builtin_powf()
Date: Mon, 25 Apr 2022 08:06:43 +0000	[thread overview]
Message-ID: <bug-105368-4-4NnG4P0r2O@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-105368-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #2 from Zdenek Sojka <zsojka at seznam dot cz> ---
(gdb) disas
Dump of assembler code for function powi_cost(long):
   0x0000000001538160 <+0>:       push   %r14
   0x0000000001538162 <+2>:       mov    $0x20,%ecx
   0x0000000001538167 <+7>:       push   %r13
   0x0000000001538169 <+9>:       push   %r12
   0x000000000153816b <+11>:      push   %rbp
   0x000000000153816c <+12>:      push   %rbx
   0x000000000153816d <+13>:      mov    %rdi,%rbx
   0x0000000001538170 <+16>:      sub    $0x100,%rsp
   0x0000000001538177 <+23>:      neg    %rbx
   0x000000000153817a <+26>:      cmovs  %rdi,%rbx
   0x000000000153817e <+30>:      mov    %rsp,%r13
   0x0000000001538181 <+33>:      xor    %eax,%eax
   0x0000000001538183 <+35>:      xor    %r12d,%r12d
   0x0000000001538186 <+38>:      mov    %r13,%rdi
   0x0000000001538189 <+41>:      rep stos %rax,%es:(%rdi)
   0x000000000153818c <+44>:      movb   $0x1,0x1(%rsp)
=> 0x0000000001538191 <+49>:      cmp    $0xff,%rbx
   0x0000000001538198 <+56>:      jg     0x15381b0 <powi_cost(long)+80>
   0x000000000153819a <+58>:      jmp    0x1538207 <powi_cost(long)+167>

1463    
1464      /* Ignore the reciprocal when calculating the cost.  */
1465      val = (n < 0) ? -n : n;
   0x000000000153816d <+13>:      mov    %rdi,%rbx

1454    powi_cost (HOST_WIDE_INT n)
   0x0000000001538170 <+16>:      sub    $0x100,%rsp

1455    {
1456      bool cache[POWI_TABLE_SIZE];
1457      unsigned HOST_WIDE_INT digit;
1458      unsigned HOST_WIDE_INT val;
1459      int result;
1460    
1461      if (n == 0)
1462        return 0;
--Type <RET> for more, q to quit, c to continue without paging--
1463    
1464      /* Ignore the reciprocal when calculating the cost.  */
1465      val = (n < 0) ? -n : n;
   0x0000000001538177 <+23>:      neg    %rbx
   0x000000000153817a <+26>:      cmovs  %rdi,%rbx

...

/repo/gcc-trunk/gcc/tree-ssa-math-opts.cc:
1469      cache[1] = true;
   0x000000000153818c <+44>:      movb   $0x1,0x1(%rsp)

1472    
1473      while (val >= POWI_TABLE_SIZE)
=> 0x0000000001538191 <+49>:      cmp    $0xff,%rbx
   0x0000000001538198 <+56>:      jg     0x15381b0 <powi_cost(long)+80>
   0x000000000153819a <+58>:      jmp    0x1538207 <powi_cost(long)+167>


(gdb) p/x n
$19 = 0x8000000000000000
(gdb) p/x val
$20 = 0x8000000000000000
(gdb) p/x $rbx
$22 = 0x8000000000000000

The "while (val >= POWI_TABLE_SIZE)" check seems to be done in signed
arithmetics ("jg" conditional jump), so the value is not reduced and cache[i]
accesses out of bounds.

This happens with both boostrapped and non-bootstrapped compiler (using host
gcc-11.3.0)

  parent reply	other threads:[~2022-04-25  8:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-24 19:07 [Bug tree-optimization/105368] New: " zsojka at seznam dot cz
2022-04-25  7:08 ` [Bug tree-optimization/105368] " rguenth at gcc dot gnu.org
2022-04-25  8:06 ` zsojka at seznam dot cz [this message]
2022-04-25  8:46 ` zsojka at seznam dot cz
2022-04-25  8:54 ` rguenth at gcc dot gnu.org
2022-04-25  8:55 ` pinskia at gcc dot gnu.org
2022-04-25  9:47 ` cvs-commit at gcc dot gnu.org
2022-04-25 10:00 ` zsojka at seznam dot cz
2022-04-25 10:31 ` [Bug tree-optimization/105368] [10/11 " rguenth at gcc dot gnu.org
2022-04-25 10:32 ` rguenth at gcc dot gnu.org
2022-05-19 14:03 ` cvs-commit at gcc dot gnu.org
2022-05-27 13:15 ` [Bug tree-optimization/105368] [10 " cvs-commit at gcc dot gnu.org
2022-05-27 13:17 ` rguenth at gcc dot gnu.org

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=bug-105368-4-4NnG4P0r2O@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).