]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/17972 (const/pure functions result in bad asm)
authorEric Botcazou <ebotcazou@gcc.gnu.org>
Wed, 15 Dec 2004 19:14:55 +0000 (19:14 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Wed, 15 Dec 2004 19:14:55 +0000 (19:14 +0000)
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

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/inline9.C [new file with mode: 0644]
gcc/tree-inline.c

index 6b987df1fa4a25baad93aeaae36a3c0c9c89809e..fee46800edfb7ba41ee618ee786a549bd8a66151 100644 (file)
@@ -1,3 +1,9 @@
+2004-12-15  Eric Botcazou  <ebotcazou@libertysurf.fr>
+
+       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  <vmakarov@redhat.com>
             Steven Bosscher  <stevenb@suse.de>
        PR middle end/17340
index 58d4e787d15e889184826ff9dc75adfacbed53a5..06dd868513a0b0e76744019f3ef2c9f114c65d66 100644 (file)
@@ -1,3 +1,7 @@
+2004-12-15  Alan Modra  <amodra@bigpond.net.au>
+
+       * g++.dg/opt/inline9.C: New test.
+
 2004-12-15  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
 
        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 (file)
index 0000000..10ccb47
--- /dev/null
@@ -0,0 +1,29 @@
+// PR c++/17972
+// Origin: Michal Ostrowski <mostrows@watson.ibm.com>
+// Testcase by Alan Modra <amodra@bigpond.net.au>
+// { 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;
+}
index db2b2361874cbab83259787f640bd0a929fd7537..61fe66dbb085683acbc28ce87dedd2eb8f06a848 100644 (file)
@@ -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);