public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/40305] New: strict aliasing and inlining
@ 2009-05-30 13:21 arnaud dot lb at gmail dot com
2009-05-30 13:22 ` [Bug c/40305] " arnaud dot lb at gmail dot com
2009-05-30 13:50 ` jakub at gcc dot gnu dot org
0 siblings, 2 replies; 3+ messages in thread
From: arnaud dot lb at gmail dot com @ 2009-05-30 13:21 UTC (permalink / raw)
To: gcc-bugs
The following code (attaching preprocessed one) crashes with gcc 4.3.3 and gcc
4.4.1 (20090529).
Adding noinline attribute to pop() avoids the crash.
Declaring pop(strict foo *f, void** a) as pop(strict foo *f, int **a) avoids
the crash.
Adding -fno-strict-aliasing avoids the crash.
I'm not sure it does breaks strict aliasing (not the same as casting a "void*"
to a "int*" and dereferencing it). gcc does not prints any warning about strict
aliasing.
Compiled with "gcc-4.4.1 -o out test.c -O3", ran with "./out".
#include <string.h>
#include <assert.h>
struct foo {
int *a;
void **top;
void *storage[1];
};
void crash(struct foo *f);
int main() {
struct foo f;
int i = 0;
memset(&f, 0, sizeof(f));
f.top = &f.storage[1];
f.a = &i;
crash(&f);
assert(f.top == &f.storage[0]);
assert(f.a == f.storage[0]);
assert(f.a == NULL);
}
void pop(struct foo *f, void **a) {
*a = *(--f->top);
}
__attribute__((noinline))
void crash(struct foo *f) {
while (f->a) {
pop(f, (void**)&f->a);
}
}
--
Summary: strict aliasing and inlining
Product: gcc
Version: 4.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: arnaud dot lb at gmail dot com
GCC build triplet: x86_64-unknown-linux-gnu
GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40305
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/40305] strict aliasing and inlining
2009-05-30 13:21 [Bug c/40305] New: strict aliasing and inlining arnaud dot lb at gmail dot com
@ 2009-05-30 13:22 ` arnaud dot lb at gmail dot com
2009-05-30 13:50 ` jakub at gcc dot gnu dot org
1 sibling, 0 replies; 3+ messages in thread
From: arnaud dot lb at gmail dot com @ 2009-05-30 13:22 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from arnaud dot lb at gmail dot com 2009-05-30 13:22 -------
Created an attachment (id=17936)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17936&action=view)
preprocessed code
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40305
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/40305] strict aliasing and inlining
2009-05-30 13:21 [Bug c/40305] New: strict aliasing and inlining arnaud dot lb at gmail dot com
2009-05-30 13:22 ` [Bug c/40305] " arnaud dot lb at gmail dot com
@ 2009-05-30 13:50 ` jakub at gcc dot gnu dot org
1 sibling, 0 replies; 3+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-05-30 13:50 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from jakub at gcc dot gnu dot org 2009-05-30 13:50 -------
It is invalid. f->a is accessed through an incompatible type (void * rather
than int *). And gcc even warns about it, with -Wstrict-aliasing=2 or
-Wstrict-aliasing=1.
--
jakub at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40305
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-05-30 13:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-30 13:21 [Bug c/40305] New: strict aliasing and inlining arnaud dot lb at gmail dot com
2009-05-30 13:22 ` [Bug c/40305] " arnaud dot lb at gmail dot com
2009-05-30 13:50 ` 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).