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]

[C PATCH] Make unsigned_conversion_warning static


As part of the TREE_OVERFLOW clean-up, I'll shortly be rewriting/deleting
c-common.c's unsigned_conversion_warning.  To limit the impact of that
change, this patch removes the one use of unsigned_conversion_warning
outside of c-common.c, and allows it to be made a local "static" function.

The single external use is in parser_build_binary_op, where in 1993
RMS added two calls to check that the operands of a binary function
didn't overflow when converted to the result_type of a binary operator.
I'm not sure this could ever happen with C's promotion/common_type
rules.  However, a better way to achieve this same checking is to
instead use convert_and_check, rather than just convert, in the
function build_binary_op.  Conceptually, any overflow/truncation occurs
when the operands are converted to the type of the binary operator.
It makes sense to check for overflow then, using the API for that
purpose, rather than check for a subset (unsigned truncation) after
the fact.

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.

Ok for mainline, as part of the continuing TREE_OVERFLOW reorg?



2006-04-30  Roger Sayle  <roger@eyesopen.com>

	* c-typeck.c (parser_build_binary_op): Don't call the function
	unsigned_conversion_warning to spot operand/result type overflow.
	(build_binary_op): Instead, call convert_and_check instead of
	convert to report the problem when the operands are promoted.
	* c-common.c (unsigned_conversion_warning): Make static.
	* c-common.h (unsigned_conversion_warning): Delete prototype.


Index: c-typeck.c
===================================================================
*** c-typeck.c	(revision 113318)
--- c-typeck.c	(working copy)
*************** parser_build_binary_op (enum tree_code c
*** 2629,2636 ****
      warning (OPT_Wstring_literal_comparison,
  	     "comparison with string literal");

-   unsigned_conversion_warning (result.value, arg1.value);
-   unsigned_conversion_warning (result.value, arg2.value);
    overflow_warning (result.value);

    return result;
--- 2629,2634 ----
*************** build_binary_op (enum tree_code code, tr
*** 8368,8376 ****
    if (!converted)
      {
        if (TREE_TYPE (op0) != result_type)
! 	op0 = convert (result_type, op0);
        if (TREE_TYPE (op1) != result_type)
! 	op1 = convert (result_type, op1);

        /* This can happen if one operand has a vector type, and the other
  	 has a different type.  */
--- 8366,8374 ----
    if (!converted)
      {
        if (TREE_TYPE (op0) != result_type)
! 	op0 = convert_and_check (result_type, op0);
        if (TREE_TYPE (op1) != result_type)
! 	op1 = convert_and_check (result_type, op1);

        /* This can happen if one operand has a vector type, and the other
  	 has a different type.  */
Index: c-common.c
===================================================================
*** c-common.c	(revision 113318)
--- c-common.c	(working copy)
*************** overflow_warning (tree value)
*** 951,957 ****
     Invoke this function on every expression that might be implicitly
     converted to an unsigned type.  */

! void
  unsigned_conversion_warning (tree result, tree operand)
  {
    tree type = TREE_TYPE (result);
--- 951,957 ----
     Invoke this function on every expression that might be implicitly
     converted to an unsigned type.  */

! static void
  unsigned_conversion_warning (tree result, tree operand)
  {
    tree type = TREE_TYPE (result);
Index: c-common.h
===================================================================
*** c-common.h	(revision 113318)
--- c-common.h	(working copy)
*************** extern void strict_aliasing_warning(tree
*** 659,665 ****
  extern void empty_body_warning (tree, tree);
  extern tree convert_and_check (tree, tree);
  extern void overflow_warning (tree);
- extern void unsigned_conversion_warning (tree, tree);
  extern bool c_determine_visibility (tree);
  extern bool same_scalar_type_ignoring_signedness (tree, tree);

--- 659,664 ----


Roger
--


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