This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH]: CALL_EXPR should set TREE_SIDE_EFFECTS
Mark Mitchell wrote:
I hate to ask you to go around on this yet again, but how about building
the node and then using "get_callee_fndecl"? (And then doing the tests
for const/pure?)
I think that would get one additional case at the moment; a call through
a const pointer-to-function whose initializer is known. And, if
get_callee_fndecl gets smarter, this code would automatically do better
too.
this is what I've installed - after testing
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
The voices in my head said this was stupid too
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2003-08-21 Nathan Sidwell <nathan@codesourcery.com>
* builtins.c (build_function_call_expr): Don't set
TREE_SIDE_EFFECTS here.
* expr.c (emit_block_move_via_libcall): Likewise.
(clear_storage_via_libcall): Likewise.
* tree.c (build): Set TREE_SIDE_EFFECTS for non-const, non-pure
CALL_EXPRs.
2003-08-21 Nathan Sidwell <nathan@codesourcery.com>
* call.c (build_call): Don't set TREE_SIDE_EFFECTS here.
(build_new_method_call): Add goto finish.
* semantics.c (simplify_aggr_init_exprs_r): Don't set
TREE_SIDE_EFFECTS on a call.
Index: builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.241
diff -c -3 -p -r1.241 builtins.c
*** builtins.c 26 Aug 2003 00:09:10 -0000 1.241
--- builtins.c 26 Aug 2003 08:41:01 -0000
*************** build_function_call_expr (tree fn, tree
*** 6242,6248 ****
call_expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (fn)), fn);
call_expr = build (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
call_expr, arglist);
- TREE_SIDE_EFFECTS (call_expr) = 1;
return fold (call_expr);
}
--- 6242,6247 ----
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expr.c,v
retrieving revision 1.578
diff -c -3 -p -r1.578 expr.c
*** expr.c 23 Aug 2003 21:18:47 -0000 1.578
--- expr.c 26 Aug 2003 08:41:23 -0000
*************** emit_block_move_via_libcall (rtx dst, rt
*** 2006,2012 ****
call_expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (fn)), fn);
call_expr = build (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
call_expr, arg_list, NULL_TREE);
- TREE_SIDE_EFFECTS (call_expr) = 1;
retval = expand_expr (call_expr, NULL_RTX, VOIDmode, 0);
--- 2006,2011 ----
*************** clear_storage_via_libcall (rtx object, r
*** 3120,3126 ****
call_expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (fn)), fn);
call_expr = build (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
call_expr, arg_list, NULL_TREE);
- TREE_SIDE_EFFECTS (call_expr) = 1;
retval = expand_expr (call_expr, NULL_RTX, VOIDmode, 0);
--- 3119,3124 ----
Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.326
diff -c -3 -p -r1.326 tree.c
*** tree.c 25 Aug 2003 16:58:31 -0000 1.326
--- tree.c 26 Aug 2003 08:41:33 -0000
*************** build (enum tree_code code, tree tt, ...
*** 2378,2383 ****
--- 2378,2394 ----
va_end (p);
TREE_CONSTANT (t) = constant;
+
+ if (code == CALL_EXPR && !TREE_SIDE_EFFECTS (t))
+ {
+ /* Calls have side-effects, except those to const or
+ pure functions. */
+ tree fn = get_callee_fndecl (t);
+
+ if (!fn || (!DECL_IS_PURE (fn) && !TREE_READONLY (fn)))
+ TREE_SIDE_EFFECTS (t) = 1;
+ }
+
return t;
}
Index: cp/call.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/call.c,v
retrieving revision 1.424
diff -c -3 -p -r1.424 call.c
*** cp/call.c 25 Aug 2003 15:47:37 -0000 1.424
--- cp/call.c 26 Aug 2003 08:41:53 -0000
*************** build_call (tree function, tree parms)
*** 303,312 ****
TREE_VALUE (tmp), t);
}
! function = build_nt (CALL_EXPR, function, parms, NULL_TREE);
TREE_HAS_CONSTRUCTOR (function) = is_constructor;
- TREE_TYPE (function) = result_type;
- TREE_SIDE_EFFECTS (function) = 1;
TREE_NOTHROW (function) = nothrow;
return function;
--- 303,310 ----
TREE_VALUE (tmp), t);
}
! function = build (CALL_EXPR, result_type, function, parms);
TREE_HAS_CONSTRUCTOR (function) = is_constructor;
TREE_NOTHROW (function) = nothrow;
return function;
*************** build_new_method_call (tree instance, tr
*** 4918,4924 ****
{
call = build_field_call (instance_ptr, fns, args);
if (call)
! return call;
error ("call to non-function `%D'", fns);
return error_mark_node;
}
--- 4916,4922 ----
{
call = build_field_call (instance_ptr, fns, args);
if (call)
! goto finish;
error ("call to non-function `%D'", fns);
return error_mark_node;
}
*************** build_new_method_call (tree instance, tr
*** 5079,5091 ****
if (!is_dummy_object (instance_ptr) && TREE_SIDE_EFFECTS (instance))
call = build (COMPOUND_EXPR, TREE_TYPE (call), instance, call);
}
!
if (processing_template_decl && call != error_mark_node)
! return build_min (CALL_EXPR,
! TREE_TYPE (call),
! build_min_nt (COMPONENT_REF,
! orig_instance,
! orig_fns),
orig_args);
return call;
}
--- 5077,5087 ----
if (!is_dummy_object (instance_ptr) && TREE_SIDE_EFFECTS (instance))
call = build (COMPOUND_EXPR, TREE_TYPE (call), instance, call);
}
! finish:;
!
if (processing_template_decl && call != error_mark_node)
! return build_min (CALL_EXPR, TREE_TYPE (call),
! build_min_nt (COMPONENT_REF, orig_instance, orig_fns),
orig_args);
return call;
}
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.350
diff -c -3 -p -r1.350 semantics.c
*** cp/semantics.c 21 Aug 2003 03:20:54 -0000 1.350
--- cp/semantics.c 26 Aug 2003 08:42:29 -0000
*************** simplify_aggr_init_expr (tree *tp)
*** 2796,2802 ****
call_expr = build (CALL_EXPR,
TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
fn, args, NULL_TREE);
- TREE_SIDE_EFFECTS (call_expr) = 1;
if (style == arg)
/* Tell the backend that we've added our return slot to the argument
--- 2796,2801 ----