public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/36093]  New: __align__ produces incorrect results in certain cases
@ 2008-05-01  2:44 zhirsch at vmware dot com
  2008-05-01  9:45 ` [Bug c/36093] " rguenth at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: zhirsch at vmware dot com @ 2008-05-01  2:44 UTC (permalink / raw)
  To: gcc-bugs

Hi,

The following code produces incorrect results under -O1 (or higher), but works
fine under -O0 for gcc 4.1.2 and 4.2.3. gcc 3.4.6 produces the correct result
for all optimization levels.

# 1 "t.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "t.c"
extern int printf(const char *format, ...);

typedef struct Bar {
      char c[129];
} Bar __attribute__((__aligned__(128)));

typedef struct Foo {
      Bar bar[4];
} Foo;

Foo foo[4];

int main()
{
   int i, j;
   Foo *foop = &foo[0];

   for (i=0; i < 4; i++) {
      Bar *bar = &foop->bar[i];
      for (j=0; j < 129; j++) {
         bar->c[j] = 'a' + i;
      }
   }

   printf("foo[0].bar[3].c[128] = %c\n", foo[0].bar[3].c[128]);
   return 0;
}

The expected behavior when the resulting program is run is:

 foo[0].bar[3].c[128] = d

The actual behavior is:

 foo[0].bar[3].c[128] = 

Output from gcc -v:

Using built-in specs.
Target: i686-linux
Configured with: ../gcc-4.1.2/configure
--prefix=/build/toolchain/lin32/gcc-4.1.2-2 --disable-nls --enable-shared
--enable-threads=posix --enable-languages=c,c++ --with-gnu-as --with-gnu-ld
--target=i686-linux
--with-as=/build/toolchain/lin32/binutils-2.17.50.0.15/bin/i686-linux-as
--with-ld=/build/toolchain/lin32/binutils-2.17.50.0.15/bin/i686-linux-ld
--enable-__cxa_atexit --with-sysroot=/build/toolchain/lin32/glibc-2.2.5-44
--disable-tls --enable-clocale=gnu
Thread model: posix
gcc version 4.1.2


and

Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)

Thanks for taking a look.


-- 
           Summary: __align__ produces incorrect results in certain cases
           Product: gcc
           Version: 4.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: zhirsch at vmware dot com


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


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

* [Bug c/36093] __align__ produces incorrect results in certain cases
  2008-05-01  2:44 [Bug c/36093] New: __align__ produces incorrect results in certain cases zhirsch at vmware dot com
@ 2008-05-01  9:45 ` rguenth at gcc dot gnu dot org
  2008-05-01  9:50 ` [Bug middle-end/36093] [4.1/4.2 Regression] " rguenth at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-05-01  9:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2008-05-01 09:44 -------
GCC 4.3 works for me.  I can confirm this with 4.2.3 and 4.1.2.

The problem is we end up with

  ivtmp.64 = (unsigned int) &foo[0].bar[(unsigned int) i]{lb: 0 sz: 128}.c[0];

(note the element size of 128, which is wrong -- it should be 256).  Probably
fixed with the gimplify.c/tree-ssa-ccp.c hunks of

2007-04-12  Richard Guenther  <rguenther@suse.de>

        PR tree-optimization/24689
        PR tree-optimization/31307
        * fold-const.c (operand_equal_p): Compare INTEGER_CST array
        indices by value.
        * gimplify.c (canonicalize_addr_expr): To be consistent with
        gimplify_compound_lval only set operands two and three of
        ARRAY_REFs if they are not gimple_min_invariant.  This makes
        it never at this place.
        * tree-ssa-ccp.c (maybe_fold_offset_to_array_ref): Likewise.

Yep.  I just confirmed that.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |rguenth at gcc dot gnu dot
                   |dot org                     |org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
      Known to fail|                            |4.2.3 4.1.2
      Known to work|                            |4.0.4 4.3.0
   Last reconfirmed|0000-00-00 00:00:00         |2008-05-01 09:44:57
               date|                            |


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


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

* [Bug middle-end/36093] [4.1/4.2 Regression] __align__ produces incorrect results in certain cases
  2008-05-01  2:44 [Bug c/36093] New: __align__ produces incorrect results in certain cases zhirsch at vmware dot com
  2008-05-01  9:45 ` [Bug c/36093] " rguenth at gcc dot gnu dot org
@ 2008-05-01  9:50 ` rguenth at gcc dot gnu dot org
  2008-05-01 11:17 ` rguenth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-05-01  9:50 UTC (permalink / raw)
  To: gcc-bugs



-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |middle-end
           Keywords|                            |wrong-code
            Summary|__align__ produces incorrect|[4.1/4.2 Regression]
                   |results in certain cases    |__align__ produces incorrect
                   |                            |results in certain cases
   Target Milestone|---                         |4.1.3


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


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

* [Bug middle-end/36093] [4.1/4.2 Regression] __align__ produces incorrect results in certain cases
  2008-05-01  2:44 [Bug c/36093] New: __align__ produces incorrect results in certain cases zhirsch at vmware dot com
  2008-05-01  9:45 ` [Bug c/36093] " rguenth at gcc dot gnu dot org
  2008-05-01  9:50 ` [Bug middle-end/36093] [4.1/4.2 Regression] " rguenth at gcc dot gnu dot org
@ 2008-05-01 11:17 ` rguenth at gcc dot gnu dot org
  2008-05-01 11:21 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-05-01 11:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2008-05-01 11:16 -------
Subject: Bug 36093

Author: rguenth
Date: Thu May  1 11:15:32 2008
New Revision: 134849

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=134849
Log:
2008-05-01  Richard Guenther  <rguenther@suse.de>

        PR middle-end/36093
        Backport from mainline
        2007-04-12  Richard Guenther  <rguenther@suse.de>

        * gimplify.c (canonicalize_addr_expr): To be consistent with
        gimplify_compound_lval only set operands two and three of
        ARRAY_REFs if they are not gimple_min_invariant.  This makes
        it never at this place.
        * tree-ssa-ccp.c (maybe_fold_offset_to_array_ref): Likewise.

        * gcc.c-torture/execute/pr36093.c: New testcase.

Added:
    branches/gcc-4_2-branch/gcc/testsuite/gcc.c-torture/execute/pr36093.c
Modified:
    branches/gcc-4_2-branch/gcc/ChangeLog
    branches/gcc-4_2-branch/gcc/gimplify.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_2-branch/gcc/tree-ssa-ccp.c


-- 


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


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

* [Bug middle-end/36093] [4.1/4.2 Regression] __align__ produces incorrect results in certain cases
  2008-05-01  2:44 [Bug c/36093] New: __align__ produces incorrect results in certain cases zhirsch at vmware dot com
                   ` (2 preceding siblings ...)
  2008-05-01 11:17 ` rguenth at gcc dot gnu dot org
@ 2008-05-01 11:21 ` rguenth at gcc dot gnu dot org
  2008-05-01 11:24 ` [Bug middle-end/36093] [4.1 " rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-05-01 11:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2008-05-01 11:20 -------
Subject: Bug 36093

Author: rguenth
Date: Thu May  1 11:19:36 2008
New Revision: 134850

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=134850
Log:
2008-05-01  Richard Guenther  <rguenther@suse.de>

        PR middle-end/36093
        * gcc.c-torture/execute/pr36093.c: New testcase.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gcc.c-torture/execute/pr36093.c
Modified:
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug middle-end/36093] [4.1 Regression] __align__ produces incorrect results in certain cases
  2008-05-01  2:44 [Bug c/36093] New: __align__ produces incorrect results in certain cases zhirsch at vmware dot com
                   ` (3 preceding siblings ...)
  2008-05-01 11:21 ` rguenth at gcc dot gnu dot org
@ 2008-05-01 11:24 ` rguenth at gcc dot gnu dot org
  2008-05-01 11:24 ` [Bug middle-end/36093] [4.1/4.2 " rguenth at gcc dot gnu dot org
  2008-07-04 16:20 ` [Bug middle-end/36093] [4.1 " jsm28 at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-05-01 11:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2008-05-01 11:23 -------
Fixed for 4.2.4.  Unassigning.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|rguenth at gcc dot gnu dot  |unassigned at gcc dot gnu
                   |org                         |dot org
             Status|ASSIGNED                    |NEW
      Known to work|4.0.4 4.3.0                 |4.0.4 4.2.4 4.3.0
            Summary|[4.1/4.2 Regression]        |[4.1 Regression] __align__
                   |__align__ produces incorrect|produces incorrect results
                   |results in certain cases    |in certain cases


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


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

* [Bug middle-end/36093] [4.1/4.2 Regression] __align__ produces incorrect results in certain cases
  2008-05-01  2:44 [Bug c/36093] New: __align__ produces incorrect results in certain cases zhirsch at vmware dot com
                   ` (4 preceding siblings ...)
  2008-05-01 11:24 ` [Bug middle-end/36093] [4.1 " rguenth at gcc dot gnu dot org
@ 2008-05-01 11:24 ` rguenth at gcc dot gnu dot org
  2008-07-04 16:20 ` [Bug middle-end/36093] [4.1 " jsm28 at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-05-01 11:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2008-05-01 11:23 -------
Subject: Bug 36093

Author: rguenth
Date: Thu May  1 11:22:33 2008
New Revision: 134851

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=134851
Log:
2008-05-01  Richard Guenther  <rguenther@suse.de>

        PR middle-end/36093
        * gcc.c-torture/execute/pr36093.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr36093.c
Modified:
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug middle-end/36093] [4.1 Regression] __align__ produces incorrect results in certain cases
  2008-05-01  2:44 [Bug c/36093] New: __align__ produces incorrect results in certain cases zhirsch at vmware dot com
                   ` (5 preceding siblings ...)
  2008-05-01 11:24 ` [Bug middle-end/36093] [4.1/4.2 " rguenth at gcc dot gnu dot org
@ 2008-07-04 16:20 ` jsm28 at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2008-07-04 16:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jsm28 at gcc dot gnu dot org  2008-07-04 16:19 -------
Closing 4.1 branch.


-- 

jsm28 at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
      Known to fail|4.2.3 4.1.2                 |4.2.3 4.1.2 4.1.3
         Resolution|                            |FIXED
   Target Milestone|4.1.3                       |4.2.4


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


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

end of thread, other threads:[~2008-07-04 16:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-01  2:44 [Bug c/36093] New: __align__ produces incorrect results in certain cases zhirsch at vmware dot com
2008-05-01  9:45 ` [Bug c/36093] " rguenth at gcc dot gnu dot org
2008-05-01  9:50 ` [Bug middle-end/36093] [4.1/4.2 Regression] " rguenth at gcc dot gnu dot org
2008-05-01 11:17 ` rguenth at gcc dot gnu dot org
2008-05-01 11:21 ` rguenth at gcc dot gnu dot org
2008-05-01 11:24 ` [Bug middle-end/36093] [4.1 " rguenth at gcc dot gnu dot org
2008-05-01 11:24 ` [Bug middle-end/36093] [4.1/4.2 " rguenth at gcc dot gnu dot org
2008-07-04 16:20 ` [Bug middle-end/36093] [4.1 " jsm28 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).