public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ipa/60062] New: wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode
@ 2014-02-04 19:13 su at cs dot ucdavis.edu
  2014-02-04 19:25 ` [Bug ipa/60062] [4.7/4.9 Regression] " mpolacek at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: su at cs dot ucdavis.edu @ 2014-02-04 19:13 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 60062
           Summary: wrong code (for code with the optimize attribute) at
                    -O1 and above on x86_64-linux-gnu in 32-bit mode
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: su at cs dot ucdavis.edu

The current gcc trunk miscompiles the following code that uses the optimize
attribute on x86_64-linux at -O1 and above in 32-bit mode (but not 64-bit). 

This is a regression from 4.8.x.

It also affects 4.7.x and 4.6.x. 

$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-trunk/configure --prefix=/usr/local/gcc-trunk
--enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
gcc version 4.9.0 20140204 (experimental) [trunk revision 207452] (GCC) 
$ 
$ gcc-trunk -m32 -O0 small.c; a.out
hello
$ gcc-trunk -m64 -O1 small.c; a.out
hello
$ gcc-4.8 -m32 -O1 small.c; a.out
hello
$
$ gcc-trunk -m32 -O1 small.c; a.out
Segmentation fault (core dumped) 
$ gcc-4.7 -m32 -O1 small.c; a.out
Segmentation fault (core dumped)
$ gcc-4.6 -m32 -O1 small.c; a.out
Segmentation fault (core dumped)
$ 


----------------------------------


int printf(const char *, ...);

int a;

static void 
foo(const char *p1, int p2) 
{ 
  printf("%s\n", p1); 
}

__attribute__((optimize(0))) 
int 
main() 
{
  foo("hello", a);
  return 0;
}


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

* [Bug ipa/60062] [4.7/4.9 Regression] wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode
  2014-02-04 19:13 [Bug ipa/60062] New: wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode su at cs dot ucdavis.edu
@ 2014-02-04 19:25 ` mpolacek at gcc dot gnu.org
  2014-02-05  8:23 ` [Bug target/60062] " jakub at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-02-04 19:25 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-02-04
                 CC|                            |mpolacek at gcc dot gnu.org
      Known to work|                            |4.8.3
   Target Milestone|---                         |4.9.0
            Summary|wrong code (for code with   |[4.7/4.9 Regression] wrong
                   |the optimize attribute) at  |code (for code with the
                   |-O1 and above on            |optimize attribute) at -O1
                   |x86_64-linux-gnu in 32-bit  |and above on
                   |mode                        |x86_64-linux-gnu in 32-bit
                   |                            |mode
     Ever confirmed|0                           |1

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed.


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

* [Bug target/60062] [4.7/4.9 Regression] wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode
  2014-02-04 19:13 [Bug ipa/60062] New: wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode su at cs dot ucdavis.edu
  2014-02-04 19:25 ` [Bug ipa/60062] [4.7/4.9 Regression] " mpolacek at gcc dot gnu.org
@ 2014-02-05  8:23 ` jakub at gcc dot gnu.org
  2014-02-05  9:17 ` jakub at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-02-05  8:23 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 32043
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32043&action=edit
gcc49-pr60062.patch

The problem is that !!optimize determines calling convention on i?86 -m32 in
some cases, but for calling conventions the caller and callee obviously have to
agree on that, but !!optimize when optimize attribute comes into the picture is
whether the current function is optimized.  So, on the testcase, it is true for
the callee and false for the caller.  The attached untested patch fixes that by
considering whether the callee is optimized instead.


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

* [Bug target/60062] [4.7/4.9 Regression] wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode
  2014-02-04 19:13 [Bug ipa/60062] New: wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode su at cs dot ucdavis.edu
  2014-02-04 19:25 ` [Bug ipa/60062] [4.7/4.9 Regression] " mpolacek at gcc dot gnu.org
  2014-02-05  8:23 ` [Bug target/60062] " jakub at gcc dot gnu.org
@ 2014-02-05  9:17 ` jakub at gcc dot gnu.org
  2014-02-05 15:43 ` su at cs dot ucdavis.edu
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-02-05  9:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
*** Bug 60072 has been marked as a duplicate of this bug. ***


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

* [Bug target/60062] [4.7/4.9 Regression] wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode
  2014-02-04 19:13 [Bug ipa/60062] New: wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode su at cs dot ucdavis.edu
                   ` (2 preceding siblings ...)
  2014-02-05  9:17 ` jakub at gcc dot gnu.org
@ 2014-02-05 15:43 ` su at cs dot ucdavis.edu
  2014-02-06 10:54 ` jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: su at cs dot ucdavis.edu @ 2014-02-05 15:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Zhendong Su <su at cs dot ucdavis.edu> ---
(In reply to Jakub Jelinek from comment #4)
> *** Bug 60072 has been marked as a duplicate of this bug. ***

The testcase below is most likely another dup as the only difference is that it
affects the trunk at -Os only. Just include it here for reference. Thanks. 


----------------------------------


int printf (const char *, ...);

int a;

int
fn1 (unsigned char p1)
{
  return p1 % p1;
}

static void
fn2 (char *p1, int p2)
{
  if (p2)
    printf (p1);
}

__attribute__ ((optimize (0)))
int fn3 (short p1, short p2)
{
  a = 0;
  return 0;
}

__attribute__ ((optimize (1)))
int fn4 ()
{
  fn3 (0, 0);
  if (fn1 (1))
    for (;;)
      ;
  return 1;
}

__attribute__ ((optimize (0)))
int main ()
{
  fn4 ();
  fn2 ("", 0);
  return 0;
}


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

* [Bug target/60062] [4.7/4.9 Regression] wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode
  2014-02-04 19:13 [Bug ipa/60062] New: wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode su at cs dot ucdavis.edu
                   ` (3 preceding siblings ...)
  2014-02-05 15:43 ` su at cs dot ucdavis.edu
@ 2014-02-06 10:54 ` jakub at gcc dot gnu.org
  2014-02-10  9:41 ` [Bug target/60062] [4.7/4.8 " rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-02-06 10:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Thu Feb  6 10:54:20 2014
New Revision: 207549

URL: http://gcc.gnu.org/viewcvs?rev=207549&root=gcc&view=rev
Log:
    PR target/60062
    * tree.h (opts_for_fn): New inline function.
    (opt_for_fn): Define.
    * config/i386/i386.c (ix86_function_regparm): Use
    opt_for_fn (decl, optimize) instead of optimize.

    * gcc.c-torture/execute/pr60062.c: New test.
    * gcc.c-torture/execute/pr60072.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr60062.c
    trunk/gcc/testsuite/gcc.c-torture/execute/pr60072.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree.h


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

* [Bug target/60062] [4.7/4.8 Regression] wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode
  2014-02-04 19:13 [Bug ipa/60062] New: wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode su at cs dot ucdavis.edu
                   ` (4 preceding siblings ...)
  2014-02-06 10:54 ` jakub at gcc dot gnu.org
@ 2014-02-10  9:41 ` rguenth at gcc dot gnu.org
  2014-02-10  9:42 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-02-10  9:41 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|4.8.3                       |4.9.0
   Target Milestone|4.9.0                       |4.7.4
            Summary|[4.7/4.9 Regression] wrong  |[4.7/4.8 Regression] wrong
                   |code (for code with the     |code (for code with the
                   |optimize attribute) at -O1  |optimize attribute) at -O1
                   |and above on                |and above on
                   |x86_64-linux-gnu in 32-bit  |x86_64-linux-gnu in 32-bit
                   |mode                        |mode

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed on trunk, latent on the branches (see duplicates).


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

* [Bug target/60062] [4.7/4.8 Regression] wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode
  2014-02-04 19:13 [Bug ipa/60062] New: wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode su at cs dot ucdavis.edu
                   ` (5 preceding siblings ...)
  2014-02-10  9:41 ` [Bug target/60062] [4.7/4.8 " rguenth at gcc dot gnu.org
@ 2014-02-10  9:42 ` rguenth at gcc dot gnu.org
  2014-03-06  7:57 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-02-10  9:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
*** Bug 60120 has been marked as a duplicate of this bug. ***


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

* [Bug target/60062] [4.7/4.8 Regression] wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode
  2014-02-04 19:13 [Bug ipa/60062] New: wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode su at cs dot ucdavis.edu
                   ` (6 preceding siblings ...)
  2014-02-10  9:42 ` rguenth at gcc dot gnu.org
@ 2014-03-06  7:57 ` jakub at gcc dot gnu.org
  2014-04-18  7:32 ` [Bug target/60062] [4.7 " jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-03-06  7:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Thu Mar  6 07:57:12 2014
New Revision: 208364

URL: http://gcc.gnu.org/viewcvs?rev=208364&root=gcc&view=rev
Log:
    Backport from mainline
    2014-02-08  Jakub Jelinek  <jakub@redhat.com>

    PR ipa/60026
    * ipa-cp.c (determine_versionability): Fail at -O0
    or __attribute__((optimize (0))) or -fno-ipa-cp functions.
    * tree-sra.c (ipa_sra_preliminary_function_checks): Similarly.

    2014-02-06  Jakub Jelinek  <jakub@redhat.com>

    PR target/60062
    * tree.h (opts_for_fn): New inline function.
    (opt_for_fn): Define.
    * config/i386/i386.c (ix86_function_regparm): Use
    opt_for_fn (decl, optimize) instead of optimize.

    * gcc.c-torture/execute/pr60062.c: New test.
    * gcc.c-torture/execute/pr60072.c: New test.

    2014-02-04  Jakub Jelinek  <jakub@redhat.com>

    PR ipa/60026
    * c-c++-common/torture/pr60026.c: New test.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/c-c++-common/torture/pr60026.c
    branches/gcc-4_8-branch/gcc/testsuite/gcc.c-torture/execute/pr60062.c
    branches/gcc-4_8-branch/gcc/testsuite/gcc.c-torture/execute/pr60072.c
Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/config/i386/i386.c
    branches/gcc-4_8-branch/gcc/ipa-cp.c
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_8-branch/gcc/tree-sra.c
    branches/gcc-4_8-branch/gcc/tree.h


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

* [Bug target/60062] [4.7 Regression] wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode
  2014-02-04 19:13 [Bug ipa/60062] New: wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode su at cs dot ucdavis.edu
                   ` (7 preceding siblings ...)
  2014-03-06  7:57 ` jakub at gcc dot gnu.org
@ 2014-04-18  7:32 ` jakub at gcc dot gnu.org
  2014-06-12 13:34 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-04-18  7:32 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mnp at agtmt dot com

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
*** Bug 60877 has been marked as a duplicate of this bug. ***


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

* [Bug target/60062] [4.7 Regression] wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode
  2014-02-04 19:13 [Bug ipa/60062] New: wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode su at cs dot ucdavis.edu
                   ` (8 preceding siblings ...)
  2014-04-18  7:32 ` [Bug target/60062] [4.7 " jakub at gcc dot gnu.org
@ 2014-06-12 13:34 ` rguenth at gcc dot gnu.org
  2021-08-08 22:22 ` pinskia at gcc dot gnu.org
  2021-08-30  1:36 ` pinskia at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-06-12 13:34 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|4.7.4                       |4.8.3
      Known to fail|                            |4.7.4

--- Comment #11 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed for 4.8.3.


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

* [Bug target/60062] [4.7 Regression] wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode
  2014-02-04 19:13 [Bug ipa/60062] New: wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode su at cs dot ucdavis.edu
                   ` (9 preceding siblings ...)
  2014-06-12 13:34 ` rguenth at gcc dot gnu.org
@ 2021-08-08 22:22 ` pinskia at gcc dot gnu.org
  2021-08-30  1:36 ` pinskia at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-08 22:22 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vogu00 at gmail dot com

--- Comment #12 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 54068 has been marked as a duplicate of this bug. ***

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

* [Bug target/60062] [4.7 Regression] wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode
  2014-02-04 19:13 [Bug ipa/60062] New: wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode su at cs dot ucdavis.edu
                   ` (10 preceding siblings ...)
  2021-08-08 22:22 ` pinskia at gcc dot gnu.org
@ 2021-08-30  1:36 ` pinskia at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-30  1:36 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vas.gurevich at gmail dot com

--- Comment #13 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 47457 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2021-08-30  1:36 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-04 19:13 [Bug ipa/60062] New: wrong code (for code with the optimize attribute) at -O1 and above on x86_64-linux-gnu in 32-bit mode su at cs dot ucdavis.edu
2014-02-04 19:25 ` [Bug ipa/60062] [4.7/4.9 Regression] " mpolacek at gcc dot gnu.org
2014-02-05  8:23 ` [Bug target/60062] " jakub at gcc dot gnu.org
2014-02-05  9:17 ` jakub at gcc dot gnu.org
2014-02-05 15:43 ` su at cs dot ucdavis.edu
2014-02-06 10:54 ` jakub at gcc dot gnu.org
2014-02-10  9:41 ` [Bug target/60062] [4.7/4.8 " rguenth at gcc dot gnu.org
2014-02-10  9:42 ` rguenth at gcc dot gnu.org
2014-03-06  7:57 ` jakub at gcc dot gnu.org
2014-04-18  7:32 ` [Bug target/60062] [4.7 " jakub at gcc dot gnu.org
2014-06-12 13:34 ` rguenth at gcc dot gnu.org
2021-08-08 22:22 ` pinskia at gcc dot gnu.org
2021-08-30  1:36 ` pinskia 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).