public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/38364]  New: -ftrapv triggers integer miscompilation
@ 2008-12-02  3:45 regehr at cs dot utah dot edu
  2008-12-02  3:47 ` [Bug c/38364] " regehr at cs dot utah dot edu
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: regehr at cs dot utah dot edu @ 2008-12-02  3:45 UTC (permalink / raw)
  To: gcc-bugs

Seen on Ubuntu Hardy using r142342.

regehr@john-home:~/volatile/tmp73$ current-gcc -O2 -Wall small.c -o small
regehr@john-home:~/volatile/tmp73$ ./small
0
regehr@john-home:~/volatile/tmp73$ current-gcc -O2 -ftrapv -Wall small.c -o
small
regehr@john-home:~/volatile/tmp73$ ./small
1
regehr@john-home:~/volatile/tmp73$ current-gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../configure --program-prefix=current-
--enable-languages=c,c++ --prefix=/home/regehr : (reconfigured) ../configure
--program-prefix=current- --enable-languages=c,c++ --prefix=/home/regehr :
(reconfigured) ../configure --program-prefix=current- --enable-languages=c,c++
--prefix=/home/regehr : (reconfigured) ../configure --program-prefix=current-
--prefix=/home/regehr --enable-languages=c,c++ --no-create --no-recursion
Thread model: posix
gcc version 4.4.0 20081202 (experimental) (GCC) 
regehr@john-home:~/volatile/tmp73$ cat small.c
#include <stdio.h>
#include <stdint.h>

static inline int16_t
safe_mul_int16_t_s_s (int16_t si1, int16_t si2)
{
  if (si1 > 0)
    {
      if (si2 > 0)
        {
          if (si1 > ((32767) / si2))
            {
              return si1;
            }
        }
      else
        {
          if (si2 < ((-32767 - 1) / si1))
            {
              return si1;
            }
        }
    }
  else
    {
      if (si2 > 0)
        {
          if (si1 < ((-32767 - 1) / si2))
            {
              return si1;
            }
        }
      else
        {
          if ((si1 != 0) && (si2 < ((32767) / si1)))
            {
              return si1;
            }
        }
    }
  return si1 * si2;
}

static inline int8_t
safe_sub_int8_t_s_s (int8_t si1, int8_t si2)
{
  if (((si1 ^ si2) &
       (((si1 ^ ((si1 ^ si2) & (1 << (sizeof (int8_t) * 8 - 1)))) -
         si2) ^ si2)) < 0)
    {
      return si1;
    }
  return si1 - si2;
}

uint32_t g_38;

int32_t func_53 (int32_t p_54, uint32_t p_55);
int32_t func_53 (int32_t p_54, uint32_t p_55)
{
  safe_mul_int16_t_s_s (1, 1);
  return 1;
}

int32_t func_97 (uint16_t p_99);
int32_t func_97 (uint16_t p_99)
{
  g_38 = p_99;
  return 1;
}

int32_t func_120 (int32_t p_124);
int32_t func_120 (int32_t p_124)
{
  if (safe_sub_int8_t_s_s (p_124, 1))
    safe_mul_int16_t_s_s (1, func_97 (1));
  return p_124;
}

int32_t func_14 (uint32_t p_16);
int32_t func_14 (uint32_t p_16)
{
  uint32_t l_438 = 0;
  func_97 (p_16 < (1 != func_120 (l_438)));
  return p_16;
}

int main (void)
{
  func_14 (1);
  printf ("%d\n", g_38);
  return 0;
}


-- 
           Summary: -ftrapv triggers integer miscompilation
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: regehr at cs dot utah dot edu
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38364


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

* [Bug c/38364] -ftrapv triggers integer miscompilation
  2008-12-02  3:45 [Bug c/38364] New: -ftrapv triggers integer miscompilation regehr at cs dot utah dot edu
@ 2008-12-02  3:47 ` regehr at cs dot utah dot edu
  2008-12-02 11:18 ` [Bug c/38364] [4.4 Regression] " rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: regehr at cs dot utah dot edu @ 2008-12-02  3:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from regehr at cs dot utah dot edu  2008-12-02 03:46 -------
Bizarrely, deleting the unused func_53() makes the problem go away.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38364


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

* [Bug c/38364] [4.4 Regression] -ftrapv triggers integer miscompilation
  2008-12-02  3:45 [Bug c/38364] New: -ftrapv triggers integer miscompilation regehr at cs dot utah dot edu
  2008-12-02  3:47 ` [Bug c/38364] " regehr at cs dot utah dot edu
@ 2008-12-02 11:18 ` rguenth at gcc dot gnu dot org
  2008-12-02 17:33 ` jakub at gcc dot gnu dot org
  2008-12-02 17:48 ` jakub at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-12-02 11:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2008-12-02 11:15 -------
Confirmed.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
      Known to fail|                            |4.4.0
      Known to work|                            |4.3.2
   Last reconfirmed|0000-00-00 00:00:00         |2008-12-02 11:15:54
               date|                            |
            Summary|-ftrapv triggers integer    |[4.4 Regression] -ftrapv
                   |miscompilation              |triggers integer
                   |                            |miscompilation
   Target Milestone|---                         |4.4.0
            Version|unknown                     |4.4.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38364


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

* [Bug c/38364] [4.4 Regression] -ftrapv triggers integer miscompilation
  2008-12-02  3:45 [Bug c/38364] New: -ftrapv triggers integer miscompilation regehr at cs dot utah dot edu
  2008-12-02  3:47 ` [Bug c/38364] " regehr at cs dot utah dot edu
  2008-12-02 11:18 ` [Bug c/38364] [4.4 Regression] " rguenth at gcc dot gnu dot org
@ 2008-12-02 17:33 ` jakub at gcc dot gnu dot org
  2008-12-02 17:48 ` jakub at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu dot org @ 2008-12-02 17:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jakub at gcc dot gnu dot org  2008-12-02 17:31 -------
Created an attachment (id=16812)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16812&action=view)
pr38364.c

Deobfuscated testcase.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38364


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

* [Bug c/38364] [4.4 Regression] -ftrapv triggers integer miscompilation
  2008-12-02  3:45 [Bug c/38364] New: -ftrapv triggers integer miscompilation regehr at cs dot utah dot edu
                   ` (2 preceding siblings ...)
  2008-12-02 17:33 ` jakub at gcc dot gnu dot org
@ 2008-12-02 17:48 ` jakub at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu dot org @ 2008-12-02 17:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jakub at gcc dot gnu dot org  2008-12-02 17:46 -------
This is a dup of PR38245, again, DCE removes the only call in the function, but
not the argument push, so that push clobbers slot where caller's %ebx is
preserved.

Either:
--- config/i386/i386.c.i386   2008-11-27 17:08:28.000000000 +0100
+++ config/i386/i386.c        2008-12-02 18:26:24.000000000 +0100
@@ -7566,14 +7566,8 @@ ix86_compute_frame_layout (struct ix86_f

   offset += size;

-  /* Add outgoing arguments area.  Can be skipped if we eliminated
-     all the function calls as dead code.
-     Skipping is however impossible when function calls alloca.  Alloca
-     expander assumes that last crtl->outgoing_args_size
-     of stack frame are unused.  */
-  if (ACCUMULATE_OUTGOING_ARGS
-      && (!current_function_is_leaf || cfun->calls_alloca
-          || ix86_current_function_calls_tls_descriptor))
+  /* Add outgoing arguments area.  */
+  if (ACCUMULATE_OUTGOING_ARGS)
     {
       offset += crtl->outgoing_args_size;
       frame->outgoing_arguments_size = crtl->outgoing_args_size;

fixes this (and other targets would need to be checked for this too), or
DCE needs to be taught to remove also the arguments (if that is at all
possible,
for ACCUMULATE_OUTGOING_ARGS that shouldn't be that hard, but for
-mno-accumulate-outgoing-args it would be much harder).

*** This bug has been marked as a duplicate of 38245 ***


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38364


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

end of thread, other threads:[~2008-12-02 17:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-02  3:45 [Bug c/38364] New: -ftrapv triggers integer miscompilation regehr at cs dot utah dot edu
2008-12-02  3:47 ` [Bug c/38364] " regehr at cs dot utah dot edu
2008-12-02 11:18 ` [Bug c/38364] [4.4 Regression] " rguenth at gcc dot gnu dot org
2008-12-02 17:33 ` jakub at gcc dot gnu dot org
2008-12-02 17:48 ` jakub at gcc dot gnu dot 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).