[Bug middle-end/38167] Accessor to stdin breaks on -O2 optimization
--- Comment #7 from aleksi dot nurmi at helsinki dot fi 2008-11-24 18:17 --- (In reply to comment #6) > This is most likely one of the aliasing bugs. Does -fno-strict-aliasing fix > the issue? Nope. I did a little research and it seems that -fno-tree-vrp fixes it. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38167
[Bug c/38167] Accessor to stdin breaks on -O2 optimization
--- Comment #5 from aleksi dot nurmi at helsinki dot fi 2008-11-17 15:53 --- GDB output showing that libc (debug) received a null pointer: Program received signal SIGSEGV, Segmentation fault. _IO_getc (fp=0x0) at getc.c:40 40_IO_acquire_lock (fp); (gdb) print fp $1 = (FILE *) 0x0 (gdb) up #1 0x0040051e in main () at fault.c:20 20 read_char(&our_stdin); (gdb) print our_stdin.f $2 = (FILE *) 0x7f75cc0c96a0 (gdb) print stdin $3 = (struct _IO_FILE *) 0x7f75cc0c96a0 -- aleksi dot nurmi at helsinki dot fi changed: What|Removed |Added Summary|Accessor to stdin is breaks |Accessor to stdin breaks on |on -O2 optimization |-O2 optimization http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38167
[Bug c/38167] Accessor to stdin is breaks on -O2 optimization
--- Comment #4 from aleksi dot nurmi at helsinki dot fi 2008-11-17 15:11 --- I found an even shorter way to make it segfault, with no inline functions at all. It's an -O2 problem, then. #include struct iostream { FILE *f; }; static struct iostream our_stdin = { 0 }; void read_char(struct iostream* ios) { if (ios->f == 0) if (ios == &our_stdin) ios->f = stdin; fgetc(ios->f); } int main() { read_char(&our_stdin); return 0; } -- aleksi dot nurmi at helsinki dot fi changed: What|Removed |Added Summary|Inline accessor to stdin is |Accessor to stdin is breaks |breaks on -O2 optimization |on -O2 optimization http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38167
[Bug c/38167] Inline accessor to stdin is breaks on -O2 optimization
--- Comment #3 from aleksi dot nurmi at helsinki dot fi 2008-11-17 14:06 --- Works for me on 4.1.3 20080308 (prerelease) (Ubuntu 4.1.2-21ubuntu1) and (Ubuntu 20081013-0ubuntu2) 4.3.3 20081014 (prerelease), too. But not in 4.2.4 (Ubuntu 4.2.4-1ubuntu3). -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38167
[Bug c/38167] Inline accessor to stdin is breaks on -O2 optimization
--- Comment #1 from aleksi dot nurmi at helsinki dot fi 2008-11-17 02:01 --- Created an attachment (id=16707) --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16707&action=view) preprocessed source -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38167
[Bug c/38167] New: Inline accessor to stdin is breaks on -O2 optimization
It appears that the following inline accessor function to stdin doesn't do it's job if -O2 optimization is turned on, thus letting a null pointer pass and causing a segfault. This doesn't happen if the function is not declared inline. Version: gcc (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu3) Command line: gcc -O2 -o fault fault.c GNU libc 2.7 is known for its non-constant stdin and is probably required to actually get a segfault. Code in readable format: #include struct iostream { FILE *f; }; static struct iostream our_stdin = { 0 }; inline void access_iostream(struct iostream* ios) { if (ios->f == 0) if (ios == &our_stdin) ios->f = stdin; } void read_char(struct iostream* ios) { access_iostream(ios); fgetc(ios->f); } int main() { read_char(&our_stdin); return 0; } -- Summary: Inline accessor to stdin is breaks on -O2 optimization Product: gcc Version: 4.2.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: aleksi dot nurmi at helsinki dot fi GCC host triplet: x86_64-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38167