public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/34921] New: Misalign stack variable referenced by nested function
@ 2008-01-22 7:52 Joey dot ye at intel dot com
2008-01-22 8:22 ` [Bug c/34921] " Joey dot ye at intel dot com
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: Joey dot ye at intel dot com @ 2008-01-22 7:52 UTC (permalink / raw)
To: gcc-bugs
> cat nested-2.c
#include <stdio.h>
#include <stdlib.h>
typedef int aligned __attribute__((aligned(16)));
int global;
void
check (int *i)
{
*i = 20;
if ((((int) i) & (__alignof__(aligned) - 1)) != 0)
{
printf("\nUnalign address (%d): %p!\n",
__alignof__(aligned), i);
abort ();
}
}
void
foo (void)
{
aligned jj;
void bar ()
{
jj = -20;
}
jj = 0;
bar ();
check (&jj);
}
int
main()
{
foo ();
return 0;
}
> gcc -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: /home/wlin5/gcc/src-daily/configure
--enable-languages=c,c++,fortran --disable-bootstrap
Thread model: posix
gcc version 4.3.0 20080106 (experimental) [trunk revision 131347] (GCC)
> gcc -m32 -o nested-2.exe nested-2.c
> ./nested-2.exe
Unalign address (16): 0xffa137dc!
Aborted
--
Summary: Misalign stack variable referenced by nested function
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: Joey dot ye at intel dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34921
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/34921] Misalign stack variable referenced by nested function
2008-01-22 7:52 [Bug c/34921] New: Misalign stack variable referenced by nested function Joey dot ye at intel dot com
@ 2008-01-22 8:22 ` Joey dot ye at intel dot com
2008-01-22 11:51 ` [Bug middle-end/34921] " pinskia at gcc dot gnu dot org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Joey dot ye at intel dot com @ 2008-01-22 8:22 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from Joey dot ye at intel dot com 2008-01-22 06:38 -------
This patch should fix it:
Index: gcc/tree-nested.c
===================================================================
--- gcc/tree-nested.c (revision 131342)
+++ gcc/tree-nested.c (working copy)
@@ -183,6 +183,10 @@
TREE_CHAIN (field) = *p;
*p = field;
+
+ /* Set correct alignment for frame struct type */
+ if (TYPE_ALIGN(type) < DECL_ALIGN (field))
+ TYPE_ALIGN(type) = DECL_ALIGN (field);
}
/* Build or return the RECORD_TYPE that describes the frame state that is
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34921
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/34921] Misalign stack variable referenced by nested function
2008-01-22 7:52 [Bug c/34921] New: Misalign stack variable referenced by nested function Joey dot ye at intel dot com
2008-01-22 8:22 ` [Bug c/34921] " Joey dot ye at intel dot com
@ 2008-01-22 11:51 ` pinskia at gcc dot gnu dot org
2008-01-22 13:58 ` hjl dot tools at gmail dot com
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-01-22 11:51 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2008-01-22 11:35 -------
I bet if you put jj in struct and don't have a nested function, this will be
the same issue.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pinskia at gcc dot gnu dot
| |org
Component|c |middle-end
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34921
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/34921] Misalign stack variable referenced by nested function
2008-01-22 7:52 [Bug c/34921] New: Misalign stack variable referenced by nested function Joey dot ye at intel dot com
2008-01-22 8:22 ` [Bug c/34921] " Joey dot ye at intel dot com
2008-01-22 11:51 ` [Bug middle-end/34921] " pinskia at gcc dot gnu dot org
@ 2008-01-22 13:58 ` hjl dot tools at gmail dot com
2008-01-22 14:47 ` hjl dot tools at gmail dot com
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: hjl dot tools at gmail dot com @ 2008-01-22 13:58 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from hjl dot tools at gmail dot com 2008-01-22 13:36 -------
*** Bug 34847 has been marked as a duplicate of this bug. ***
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34921
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/34921] Misalign stack variable referenced by nested function
2008-01-22 7:52 [Bug c/34921] New: Misalign stack variable referenced by nested function Joey dot ye at intel dot com
` (2 preceding siblings ...)
2008-01-22 13:58 ` hjl dot tools at gmail dot com
@ 2008-01-22 14:47 ` hjl dot tools at gmail dot com
2008-01-23 2:12 ` Joey dot ye at intel dot com
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: hjl dot tools at gmail dot com @ 2008-01-22 14:47 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from hjl dot tools at gmail dot com 2008-01-22 14:26 -------
(In reply to comment #2)
> I bet if you put jj in struct and don't have a nested function, this will be
> the same issue.
>
struct works for me:
bash-3.2$ cat x.c
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#ifndef ALIGNMENT
#define ALIGNMENT 16
#endif
int
check_int (int *i, int align)
{
*i = 20;
if ((((ptrdiff_t) i) & (align - 1)) != 0)
{
printf("\nUnalign address (%d): %p!\n", align, i);
abort ();
}
return *i;
}
void
foo (void)
{
struct i
{
int i;
} __attribute__((aligned(ALIGNMENT))) i;
if (check_int (&i.i, __alignof__(i.i)) != i.i)
abort ();
}
void
bar (void)
{
int __attribute__((aligned(ALIGNMENT))) i;
if (check_int (&i, __alignof__(i)) != i)
abort ();
}
int
main()
{
foo ();
bar ();
return 0;
}
bash-3.2$ /usr/gcc-4.3/bin/gcc -m32 x.c
bash-3.2$ ./a.out
bash-3.2$
--
hjl dot tools at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2008-01-22 14:26:12
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34921
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/34921] Misalign stack variable referenced by nested function
2008-01-22 7:52 [Bug c/34921] New: Misalign stack variable referenced by nested function Joey dot ye at intel dot com
` (3 preceding siblings ...)
2008-01-22 14:47 ` hjl dot tools at gmail dot com
@ 2008-01-23 2:12 ` Joey dot ye at intel dot com
2008-01-23 16:31 ` hjl dot tools at gmail dot com
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Joey dot ye at intel dot com @ 2008-01-23 2:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from Joey dot ye at intel dot com 2008-01-23 01:45 -------
(In reply to comment #2)
> I bet if you put jj in struct and don't have a nested function, this will be
> the same issue.
Not the same. In fact it passes if not referenced by a nested function. The
root is in tree-nested.c
$ cat nested-3.c
#include <stdio.h>
#include <stdlib.h>
typedef int aligned __attribute__((aligned(16)));
int global;
void
check (int *i)
{
*i = 20;
if ((((int) i) & (__alignof__(aligned) - 1)) != 0)
{
printf("\nUnalign address (%d): %p!\n",
__alignof__(aligned), i);
abort ();
}
}
void
foo (void)
{
aligned jj;
int j2;
void bar ()
{
j2 = -20;
}
jj = 0;
bar ();
check (&jj);
}
int
main()
{
foo ();
return 0;
}
$ diff -p nested-2.c nested-3.c
*** nested-2.c 2008-01-22 14:24:39.000000000 +0800
--- nested-3.c 2008-01-23 09:38:47.000000000 +0800
*************** void
*** 19,27 ****
foo (void)
{
aligned jj;
void bar ()
{
! jj = -20;
}
jj = 0;
bar ();
--- 19,28 ----
foo (void)
{
aligned jj;
+ int j2;
void bar ()
{
! j2 = -20;
}
jj = 0;
bar ();
$ gcc -m32 -o nested-3.exe nested-3.c
$ ./nested-3.exe
$
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34921
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/34921] Misalign stack variable referenced by nested function
2008-01-22 7:52 [Bug c/34921] New: Misalign stack variable referenced by nested function Joey dot ye at intel dot com
` (4 preceding siblings ...)
2008-01-23 2:12 ` Joey dot ye at intel dot com
@ 2008-01-23 16:31 ` hjl dot tools at gmail dot com
2008-02-06 15:24 ` hjl at gcc dot gnu dot org
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: hjl dot tools at gmail dot com @ 2008-01-23 16:31 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from hjl dot tools at gmail dot com 2008-01-23 15:47 -------
A patch is posted at
http://gcc.gnu.org/ml/gcc-patches/2008-01/msg01062.html
--
hjl dot tools at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
URL| |http://gcc.gnu.org/ml/gcc-
| |patches/2008-
| |01/msg01062.html
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34921
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/34921] Misalign stack variable referenced by nested function
2008-01-22 7:52 [Bug c/34921] New: Misalign stack variable referenced by nested function Joey dot ye at intel dot com
` (5 preceding siblings ...)
2008-01-23 16:31 ` hjl dot tools at gmail dot com
@ 2008-02-06 15:24 ` hjl at gcc dot gnu dot org
2008-02-18 23:44 ` hjl at gcc dot gnu dot org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: hjl at gcc dot gnu dot org @ 2008-02-06 15:24 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from hjl at gcc dot gnu dot org 2008-02-06 15:23 -------
Subject: Bug 34921
Author: hjl
Date: Wed Feb 6 15:22:35 2008
New Revision: 132148
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=132148
Log:
gcc/
2008-02-06 Joey Ye <joey.ye@intel.com>
PR middle-end/34921
* tree-nested.c (insert_field_into_struct): Set type alignment
to field alignment if the former is less than the latter.
gcc/testsuite/
2008-02-06 Joey Ye <joey.ye@intel.com>
H.J. Lu <hongjiu.lu@intel.com>
PR middle-end/34921
* gcc.c-torture/execute/nest-align-1.c: New test case.
Added:
branches/stack/gcc/ChangeLog.stackalign
branches/stack/gcc/testsuite/ChangeLog.stackalign
branches/stack/gcc/testsuite/gcc.c-torture/execute/nest-align-1.c
Modified:
branches/stack/gcc/tree-nested.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34921
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/34921] Misalign stack variable referenced by nested function
2008-01-22 7:52 [Bug c/34921] New: Misalign stack variable referenced by nested function Joey dot ye at intel dot com
` (6 preceding siblings ...)
2008-02-06 15:24 ` hjl at gcc dot gnu dot org
@ 2008-02-18 23:44 ` hjl at gcc dot gnu dot org
2008-08-06 8:07 ` Joey dot ye at intel dot com
2008-12-31 18:18 ` pinskia at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: hjl at gcc dot gnu dot org @ 2008-02-18 23:44 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from hjl at gcc dot gnu dot org 2008-02-18 23:44 -------
Subject: Bug 34921
Author: hjl
Date: Mon Feb 18 23:43:23 2008
New Revision: 132396
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=132396
Log:
gcc/
2008-02-18 Joey Ye <joey.ye@intel.com>
PR middle-end/34921
* tree-nested.c (insert_field_into_struct): Set type alignment
to field alignment if the former is less than the latter.
gcc/testsuite/
2008-02-18 Joey Ye <joey.ye@intel.com>
H.J. Lu <hongjiu.lu@intel.com>
PR middle-end/34921
* gcc.c-torture/execute/nest-align-1.c: New test case.
Added:
trunk/gcc/testsuite/gcc.c-torture/execute/nest-align-1.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/testsuite/ChangeLog
trunk/gcc/tree-nested.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34921
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/34921] Misalign stack variable referenced by nested function
2008-01-22 7:52 [Bug c/34921] New: Misalign stack variable referenced by nested function Joey dot ye at intel dot com
` (7 preceding siblings ...)
2008-02-18 23:44 ` hjl at gcc dot gnu dot org
@ 2008-08-06 8:07 ` Joey dot ye at intel dot com
2008-12-31 18:18 ` pinskia at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: Joey dot ye at intel dot com @ 2008-08-06 8:07 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from Joey dot ye at intel dot com 2008-08-06 08:05 -------
Fixed
--
Joey dot ye at intel dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34921
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/34921] Misalign stack variable referenced by nested function
2008-01-22 7:52 [Bug c/34921] New: Misalign stack variable referenced by nested function Joey dot ye at intel dot com
` (8 preceding siblings ...)
2008-08-06 8:07 ` Joey dot ye at intel dot com
@ 2008-12-31 18:18 ` pinskia at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-12-31 18:18 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from pinskia at gcc dot gnu dot org 2008-12-31 18:16 -------
*** Bug 33610 has been marked as a duplicate of this bug. ***
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |peter_schorn at yahoo dot
| |com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34921
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2008-12-31 18:18 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-22 7:52 [Bug c/34921] New: Misalign stack variable referenced by nested function Joey dot ye at intel dot com
2008-01-22 8:22 ` [Bug c/34921] " Joey dot ye at intel dot com
2008-01-22 11:51 ` [Bug middle-end/34921] " pinskia at gcc dot gnu dot org
2008-01-22 13:58 ` hjl dot tools at gmail dot com
2008-01-22 14:47 ` hjl dot tools at gmail dot com
2008-01-23 2:12 ` Joey dot ye at intel dot com
2008-01-23 16:31 ` hjl dot tools at gmail dot com
2008-02-06 15:24 ` hjl at gcc dot gnu dot org
2008-02-18 23:44 ` hjl at gcc dot gnu dot org
2008-08-06 8:07 ` Joey dot ye at intel dot com
2008-12-31 18:18 ` pinskia 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).