public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/34768] New: [4.1/4.2/4.3 Regression] Wrong code with conditional function invocation Date: Sun, 13 Jan 2008 14:01:00 -0000 [thread overview] Message-ID: <bug-34768-10053@http.gcc.gnu.org/bugzilla/> (raw) int x; void __attribute__((noinline)) foo (void) { x = -x; } void __attribute__((const,noinline)) bar (void) { } int __attribute__((noinline)) test (int c) { int tmp = x; (c ? foo : bar) (); return tmp + x; } extern void abort (void); int main() { x = 1; if (test (1) != 0) abort (); return 0; } creates wrong code because the side-effect of the call to foo() is not accounted for. Since the merge of tree-ssa already gimplification removes the function call. Thus, the above fails with -O0. If you modify the testcase to use the return-value, you see that wrong alias information is created because we appearantly use the const attribute for the indirect call. int x; int __attribute__((noinline)) foo (void) { x = -x; return 0; } int __attribute__((const,noinline)) bar (void) { return 0; } int __attribute__((noinline)) test (int c) { int tmp = x; int res = (c ? foo : bar) (); return tmp + x + res; } extern void abort (void); int main() { x = 1; if (test (1) != 0) abort (); return 0; } alias produced is: test (c) { int res; int tmp; int D.1207; int x.3; int D.1205; int (*<T240>) (void) iftmp.2; <bb 2>: # VUSE <x_11(D)> tmp_2 = x; if (c_3(D) != 0) goto <bb 4>; else goto <bb 3>; <bb 3>: <bb 4>: # iftmp.2_1 = PHI <foo(2), bar(3)> res_6 = iftmp.2_1 (); # VUSE <x_11(D)> x.3_7 = x; D.1207_8 = tmp_2 + x.3_7; D.1205_9 = D.1207_8 + res_6; return D.1205_9; } and we happily CSE the load from x. This testcase requires -O to fail. -- Summary: [4.1/4.2/4.3 Regression] Wrong code with conditional function invocation Product: gcc Version: 4.3.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: middle-end AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: rguenth at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34768
next reply other threads:[~2008-01-13 13:23 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2008-01-13 14:01 rguenth at gcc dot gnu dot org [this message] 2008-01-13 14:04 ` [Bug middle-end/34768] " rguenth at gcc dot gnu dot org 2008-01-13 14:36 ` [Bug c/34768] " rguenth at gcc dot gnu dot org 2008-01-13 14:36 ` rguenth at gcc dot gnu dot org 2008-01-13 18:02 ` pinskia at gcc dot gnu dot org 2008-01-13 18:34 ` rguenth at gcc dot gnu dot org 2008-01-16 10:17 ` rguenth at gcc dot gnu dot org 2008-01-16 10:29 ` [Bug c/34768] [4.1/4.2 " rguenth at gcc dot gnu dot org 2008-01-22 14:48 ` rguenth at gcc dot gnu dot org 2008-01-22 14:57 ` [Bug c/34768] [4.1 " rguenth at gcc dot gnu dot org 2008-07-04 16:18 ` jsm28 at gcc dot gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-34768-10053@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).