This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Fortran] PR22375: Promote arguments to __builtin_expect


The following patch resolves PR middle-end/22375 which is a type
mismatch problem with Andrew Pinski's strict type checking patches.
The problem is that the gfortran front-ends is generating calls
to the __builtin_expect instrinsic in gfc_trans_runtime_check
without correctly promoting the function arguments to the expected
type, or casting the result back to a boolean_type_node.  This is
fixed by the patch below.

The following patch has been tested on x86_64-unknown-linux-gnu
with a full "make bootstrap", including fortran, and regression
tested with a top-level "make -k check" with no new failures.

Ok for mainline?



2006-03-29  Roger Sayle  <roger@eyesopen.com>

	PR middle-end/22375
	* trans.c (gfc_trans_runtime_check): Promote the arguments of
	__builtin_expect to the correct types, and the result back to
	boolean_type_node.


Index: trans.c
===================================================================
*** trans.c	(revision 112052)
--- trans.c	(working copy)
*************** gfc_trans_runtime_check (tree cond, tree
*** 340,348 ****
    else
      {
        /* Tell the compiler that this isn't likely.  */
        tmp = gfc_chainon_list (NULL_TREE, cond);
!       tmp = gfc_chainon_list (tmp, integer_zero_node);
        cond = build_function_call_expr (built_in_decls[BUILT_IN_EXPECT], tmp);

        tmp = build3_v (COND_EXPR, cond, body, build_empty_stmt ());
        gfc_add_expr_to_block (pblock, tmp);
--- 340,350 ----
    else
      {
        /* Tell the compiler that this isn't likely.  */
+       cond = fold_convert (long_integer_type_node, cond);
        tmp = gfc_chainon_list (NULL_TREE, cond);
!       tmp = gfc_chainon_list (tmp, build_int_cst (long_integer_type_node, 0));
        cond = build_function_call_expr (built_in_decls[BUILT_IN_EXPECT], tmp);
+       cond = fold_convert (boolean_type_node, cond);

        tmp = build3_v (COND_EXPR, cond, body, build_empty_stmt ());
        gfc_add_expr_to_block (pblock, tmp);


Roger
--


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]