aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Henderson <rth@redhat.com>2001-04-30 16:59:10 -0700
committerRichard Henderson <rth@gcc.gnu.org>2001-04-30 16:59:10 -0700
commitd72040f508bfc01489f0fca666cbb6e8ddfae896 (patch)
tree1e7389002ae91d660ddd3c0a718444a33765d0ae
parent901d43bcd00712e558ce9d408c788980b6823c13 (diff)
downloadgcc-d72040f508bfc01489f0fca666cbb6e8ddfae896.zip
gcc-d72040f508bfc01489f0fca666cbb6e8ddfae896.tar.gz
gcc-d72040f508bfc01489f0fca666cbb6e8ddfae896.tar.bz2
c-common.c (c_promoting_integer_type_p): New function, from the corpse of old macro.
* c-common.c (c_promoting_integer_type_p): New function, from the corpse of old macro. Properly promote too-small enumerations and booleans. Adjust all callers. * c-common.h (C_PROMOTING_INTEGER_TYPE_P): Remove. (c_promoting_integer_type_p): Declare. * c-decl.c: Adjust C_PROMOTING_INTEGER_TYPE_P invocations. * c-typeck.c: Likewise. (default_conversion): Remove now redundant boolean check. * cvt.c: Downcase C_PROMOTING_INTEGER_TYPE_P invocations. * decl.c: Likewise. From-SVN: r41709
-rw-r--r--gcc/ChangeLog11
-rw-r--r--gcc/c-common.c34
-rw-r--r--gcc/c-common.h12
-rw-r--r--gcc/c-decl.c2
-rw-r--r--gcc/c-typeck.c7
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/cvt.c2
-rw-r--r--gcc/cp/decl.c2
8 files changed, 54 insertions, 21 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ba3fc47..1835a46 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,14 @@
+2001-04-30 Richard Henderson <rth@redhat.com>
+
+ * c-common.c (c_promoting_integer_type_p): New function, from the
+ corpse of old macro. Properly promote too-small enumerations and
+ booleans. Adjust all callers.
+ * c-common.h (C_PROMOTING_INTEGER_TYPE_P): Remove.
+ (c_promoting_integer_type_p): Declare.
+ * c-decl.c: Adjust C_PROMOTING_INTEGER_TYPE_P invocations.
+ * c-typeck.c: Likewise.
+ (default_conversion): Remove now redundant boolean check.
+
2001-04-30 Jan Hubicka <jh@suse.cz>
Richard Henderson <rth@redhat.com>
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 8727503..a87ad7e 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -3690,6 +3690,36 @@ builtin_function_2 (builtin_name, name, builtin_type, type, function_code,
return (bdecl != 0 ? bdecl : decl);
}
+/* Nonzero if the type T promotes to int. This is (nearly) the
+ integral promotions defined in ISO C99 6.3.1.1/2. */
+
+bool
+c_promoting_integer_type_p (t)
+ tree t;
+{
+ switch (TREE_CODE (t))
+ {
+ case INTEGER_TYPE:
+ return (TYPE_MAIN_VARIANT (t) == char_type_node
+ || TYPE_MAIN_VARIANT (t) == signed_char_type_node
+ || TYPE_MAIN_VARIANT (t) == unsigned_char_type_node
+ || TYPE_MAIN_VARIANT (t) == short_integer_type_node
+ || TYPE_MAIN_VARIANT (t) == short_unsigned_type_node);
+
+ case ENUMERAL_TYPE:
+ /* ??? Technically all enumerations not larger than an int
+ promote to an int. But this is used along code paths
+ that only want to notice a size change. */
+ return TYPE_PRECISION (t) < TYPE_PRECISION (integer_type_node);
+
+ case BOOLEAN_TYPE:
+ return 1;
+
+ default:
+ return 0;
+ }
+}
+
/* Given a type, apply default promotions wrt unnamed function arguments
and return the new type. Return NULL_TREE if no change. */
/* ??? There is a function of the same name in the C++ front end that
@@ -3704,7 +3734,7 @@ simple_type_promotes_to (type)
if (TYPE_MAIN_VARIANT (type) == float_type_node)
return double_type_node;
- if (C_PROMOTING_INTEGER_TYPE_P (type))
+ if (c_promoting_integer_type_p (type))
{
/* Traditionally, unsignedness is preserved in default promotions.
Also preserve unsignedness if not really getting any wider. */
@@ -3739,7 +3769,7 @@ self_promoting_args_p (parms)
if (TYPE_MAIN_VARIANT (type) == float_type_node)
return 0;
- if (C_PROMOTING_INTEGER_TYPE_P (type))
+ if (c_promoting_integer_type_p (type))
return 0;
}
return 1;
diff --git a/gcc/c-common.h b/gcc/c-common.h
index b9a7a9d..32d7ec9 100644
--- a/gcc/c-common.h
+++ b/gcc/c-common.h
@@ -533,17 +533,7 @@ extern tree build_va_arg PARAMS ((tree, tree));
extern void c_common_lang_init PARAMS ((void));
-/* Nonzero if the type T promotes to itself.
- ANSI C states explicitly the list of types that promote;
- in particular, short promotes to int even if they have the same width. */
-#define C_PROMOTING_INTEGER_TYPE_P(t) \
- (TREE_CODE ((t)) == INTEGER_TYPE \
- && (TYPE_MAIN_VARIANT (t) == char_type_node \
- || TYPE_MAIN_VARIANT (t) == signed_char_type_node \
- || TYPE_MAIN_VARIANT (t) == unsigned_char_type_node \
- || TYPE_MAIN_VARIANT (t) == short_integer_type_node \
- || TYPE_MAIN_VARIANT (t) == short_unsigned_type_node))
-
+extern bool c_promoting_integer_type_p PARAMS ((tree));
extern int self_promoting_args_p PARAMS ((tree));
extern tree simple_type_promotes_to PARAMS ((tree));
extern tree strip_array_types PARAMS ((tree));
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index a386ecd..9d63d06 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -5999,7 +5999,7 @@ start_function (declspecs, declarator, prefix_attributes, attributes)
restype = TREE_TYPE (TREE_TYPE (current_function_decl));
/* Promote the value to int before returning it. */
- if (C_PROMOTING_INTEGER_TYPE_P (restype))
+ if (c_promoting_integer_type_p (restype))
{
/* It retains unsignedness if traditional
or if not really getting wider. */
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index baf5fed..f05422c 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -954,14 +954,14 @@ default_conversion (exp)
if (TREE_CODE (exp) == COMPONENT_REF
&& DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1))
/* If it's thinner than an int, promote it like a
- C_PROMOTING_INTEGER_TYPE_P, otherwise leave it alone. */
+ c_promoting_integer_type_p, otherwise leave it alone. */
&& 0 > compare_tree_int (DECL_SIZE (TREE_OPERAND (exp, 1)),
TYPE_PRECISION (integer_type_node)))
return convert (flag_traditional && TREE_UNSIGNED (type)
? unsigned_type_node : integer_type_node,
exp);
- if (C_PROMOTING_INTEGER_TYPE_P (type))
+ if (c_promoting_integer_type_p (type))
{
/* Traditionally, unsignedness is preserved in default promotions.
Also preserve unsignedness if not really getting any wider. */
@@ -973,9 +973,6 @@ default_conversion (exp)
return convert (integer_type_node, exp);
}
- if (code == BOOLEAN_TYPE)
- return convert (integer_type_node, exp);
-
if (flag_traditional && !flag_allow_single_precision
&& TYPE_MAIN_VARIANT (type) == float_type_node)
return convert (double_type_node, exp);
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 1d0f7ce..e952168 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2001-04-30 Richard Henderson <rth@redhat.com>
+
+ * cvt.c: Downcase C_PROMOTING_INTEGER_TYPE_P invocations.
+ * decl.c: Likewise.
+
2001-04-30 Mark Mitchell <mark@codesourcery.com>
* gxxint.texi: Remove.
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 1f74eb4..f247699 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -1258,7 +1258,7 @@ type_promotes_to (type)
else
type = totype;
}
- else if (C_PROMOTING_INTEGER_TYPE_P (type))
+ else if (c_promoting_integer_type_p (type))
{
/* Retain unsignedness if really not getting bigger. */
if (TREE_UNSIGNED (type)
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 246cbd7..da63679 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -13602,7 +13602,7 @@ start_function (declspecs, declarator, attrs, flags)
cplus_decl_attributes (decl1, NULL_TREE, attrs);
/* Promote the value to int before returning it. */
- if (C_PROMOTING_INTEGER_TYPE_P (restype))
+ if (c_promoting_integer_type_p (restype))
restype = type_promotes_to (restype);
if (DECL_RESULT (decl1) == NULL_TREE)