This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[PATCH] Support multiple BOOLEAN_TYPEs in fold


The following patch improves the middle-end's support for front-ends
with multiple Boolean types.  Currently, this only affects gfortran
which has LOGICAL*1, LOGICAL*2, LOGICAL*4, etc...  All of GCC's other
front-ends typically have a single Boolean type, boolean_type_node,
which explains the potential bug below, where Boolean constants are
always mapped to the default Boolean type (via the truthvalue_conversion
language hook), not necessarily the specified Boolean type.

For most languages, C/C++/Java/Ada, we no longer call this language
hook, as the earlier "if (type == boolean_type_node)" now catches this
for us.  For Ada, this is a good thing, as gnat_truthvalue_conversion
wouldn't convert the integer_one_node/integer_zero_node argument to
any BOOLEAN_TYPE(!).  With this change, constant_boolean_node is
now guaranteed to return a tree of the type specified by its type
argument.

The code to call truthvalue_conversion goes all the way back to 1998,
when front-ends probably only had a single BOOLEAN_TYPE.  The micro
optimization to check the common case of boolean_type_node, is much
more recent.

The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", all default languages, and regression tested with a
top-level "make -k check" with no new failures.

Any objections for mainline?


2005-02-18  Roger Sayle  <roger@eyesopen.com>

	* fold.c (constant_boolean_node): Always create values of the
	specified type, don't bother calling truthvalue_conversion.


Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.514
diff -c -3 -p -r1.514 fold-const.c
*** fold-const.c	17 Feb 2005 03:03:32 -0000	1.514
--- fold-const.c	18 Feb 2005 04:57:50 -0000
*************** constant_boolean_node (int value, tree t
*** 5381,5389 ****
      return value ? integer_one_node : integer_zero_node;
    else if (type == boolean_type_node)
      return value ? boolean_true_node : boolean_false_node;
-   else if (TREE_CODE (type) == BOOLEAN_TYPE)
-     return lang_hooks.truthvalue_conversion (value ? integer_one_node
- 						   : integer_zero_node);
    else
      return build_int_cst (type, value);
  }
--- 5381,5386 ----


Roger
--


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