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.
Mine. Probably also causes PR32139.
Um, this is a FE bug.
The bug is in common_pointer_type (), where we merge the function type qualifiers (TYPE_READONLY is used for 'const' functions): else if (TYPE_P (exp) && TYPE_READONLY (exp) && ! TREE_THIS_VOLATILE (exp)) flags |= ECF_CONST; volatile is used as 'noreturn'.
THis is related to PR 29382 and PR 13519. And I think this is exactly the same issue as PR 28289.
*** Bug 28289 has been marked as a duplicate of this bug. ***
Subject: Bug 34768 Author: rguenth Date: Wed Jan 16 09:44:23 2008 New Revision: 131568 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131568 Log: 2008-01-16 Richard Guenther <rguenther@suse.de> PR c/34768 * c-typeck.c (common_pointer_type): Do not merge inconsistent type qualifiers for function types. * gcc.c-torture/execute/pr34768-1.c: New testcase. * gcc.c-torture/execute/pr34768-2.c: Likewise. Added: trunk/gcc/testsuite/gcc.c-torture/execute/pr34768-1.c trunk/gcc/testsuite/gcc.c-torture/execute/pr34768-2.c Modified: trunk/gcc/ChangeLog trunk/gcc/c-typeck.c trunk/gcc/testsuite/ChangeLog
Fixed on the trunk.
Subject: Bug 34768 Author: rguenth Date: Tue Jan 22 14:45:56 2008 New Revision: 131723 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131723 Log: 2008-01-22 Richard Guenther <rguenther@suse.de> PR middle-end/34739 Backport from mainline 2008-01-16 Richard Guenther <rguenther@suse.de> PR c/34768 * c-typeck.c (common_pointer_type): Do not merge inconsistent type qualifiers for function types. 2007-11-12 Richard Guenther <rguenther@suse.de> PR middle-end/34070 * fold-const.c (fold_binary): If testing for non-negative operands with tree_expr_nonnegative_warnv_p make sure to use op0 which has all (sign) conversions retained. 2006-10-24 Richard Guenther <rguenther@suse.de> PR middle-end/28796 * builtins.c (fold_builtin_classify): Use HONOR_INFINITIES and HONOR_NANS instead of MODE_HAS_INFINITIES and MODE_HAS_NANS for deciding optimizations in consistency with fold-const.c (fold_builtin_unordered_cmp): Likewise. Added: branches/gcc-4_2-branch/gcc/testsuite/gcc.c-torture/execute/pr34070-1.c - copied unchanged from r130098, trunk/gcc/testsuite/gcc.c-torture/execute/pr34070-1.c branches/gcc-4_2-branch/gcc/testsuite/gcc.c-torture/execute/pr34070-2.c - copied unchanged from r130098, trunk/gcc/testsuite/gcc.c-torture/execute/pr34070-2.c branches/gcc-4_2-branch/gcc/testsuite/gcc.c-torture/execute/pr34768-1.c - copied unchanged from r131568, trunk/gcc/testsuite/gcc.c-torture/execute/pr34768-1.c branches/gcc-4_2-branch/gcc/testsuite/gcc.c-torture/execute/pr34768-2.c - copied unchanged from r131568, trunk/gcc/testsuite/gcc.c-torture/execute/pr34768-2.c branches/gcc-4_2-branch/gcc/testsuite/gcc.dg/pr28796-1.c - copied unchanged from r118001, trunk/gcc/testsuite/gcc.dg/pr28796-1.c branches/gcc-4_2-branch/gcc/testsuite/gcc.dg/pr28796-2.c - copied unchanged from r118001, trunk/gcc/testsuite/gcc.dg/pr28796-2.c Modified: branches/gcc-4_2-branch/gcc/ChangeLog branches/gcc-4_2-branch/gcc/builtins.c branches/gcc-4_2-branch/gcc/c-typeck.c branches/gcc-4_2-branch/gcc/fold-const.c branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
Fixed on the 4.2 branch.
Closing 4.1 branch.