From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13880 invoked by alias); 17 Nov 2008 15:12:33 -0000 Received: (qmail 8372 invoked by uid 48); 17 Nov 2008 15:11:09 -0000 Date: Mon, 17 Nov 2008 15:12:00 -0000 Message-ID: <20081117151109.8371.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug c/38167] Accessor to stdin is breaks on -O2 optimization In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "aleksi dot nurmi at helsinki dot fi" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-11/txt/msg01393.txt.bz2 ------- 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