From: Eric Botcazou Date: Wed, 15 Dec 2004 19:14:55 +0000 (+0000) Subject: re PR c++/17972 (const/pure functions result in bad asm) X-Git-Tag: releases/gcc-4.0.0~2136 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=774a9b00ca266a7ce1abbd4d59d6470598256401;p=thirdparty%2Fgcc.git re PR c++/17972 (const/pure functions result in bad asm) PR c++/17972 * tree-inline.c (expand_call_inline): Set TREE_SIDE_EFFECTS on the STMT_EXPR wrapping up the inlined body. From-SVN: r92210 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6b987df1fa4a..fee46800edfb 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2004-12-15 Eric Botcazou + + PR c++/17972 + * tree-inline.c (expand_call_inline): Set TREE_SIDE_EFFECTS + on the STMT_EXPR wrapping up the inlined body. + 2004-12-15 Vladimir Makarov Steven Bosscher PR middle end/17340 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 58d4e787d15e..06dd868513a0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2004-12-15 Alan Modra + + * g++.dg/opt/inline9.C: New test. + 2004-12-15 Tobias Schlueter PR fortran/18993 diff --git a/gcc/testsuite/g++.dg/opt/inline9.C b/gcc/testsuite/g++.dg/opt/inline9.C new file mode 100644 index 000000000000..10ccb47dc79f --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/inline9.C @@ -0,0 +1,29 @@ +// PR c++/17972 +// Origin: Michal Ostrowski +// Testcase by Alan Modra +// { dg-do run } +// { dg-options "-O" } +// { dg-options "-O -mtune=i686" { target i?86-*-* } } + +struct thread_info +{ + short preempt_count; +} x; + +static inline struct thread_info *cti (void) __attribute__ ((const)); +static inline struct thread_info *cti (void) +{ + return &x; +} + +void fn (void) __attribute__ ((noinline)); +void fn (void) +{ + ++cti()->preempt_count; +} + +int main (void) +{ + fn (); + return 0; +} diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index db2b2361874c..61fe66dbb085 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1625,8 +1625,11 @@ expand_call_inline (tree *tp, int *walk_subtrees, void *data) splay_tree_delete (id->decl_map); id->decl_map = st; - /* The new expression has side-effects if the old one did. */ - TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (t); + /* Although, from the semantic viewpoint, the new expression has + side-effects only if the old one did, it is not possible, from + the technical viewpoint, to evaluate the body of a function + multiple times without serious havoc. */ + TREE_SIDE_EFFECTS (expr) = 1; tsi_link_before (&id->tsi, expr, TSI_SAME_STMT);