summaryrefslogtreecommitdiff
path: root/gcc/c-typeck.c
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2005-02-10 12:18:52 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2005-02-10 12:18:52 +0000
commit79d3724289a817ad004fe7ed4d62aa43e71a0f4a (patch)
tree3de2bb26e3aa22fa9445518adfa866f637666dcc /gcc/c-typeck.c
parent29b0f4081851e4f73659411d393edfc0008bdb85 (diff)
downloadgcc-79d3724289a817ad004fe7ed4d62aa43e71a0f4a.tar.gz
PR c/19342
* c-typeck.c (common_type): New routine. Old common_type renamed to... (c_common_type): ...this. (build_conditional_expr, build_binary_op): Use c_common_type instead of common_type. * gcc.c-torture/execute/20050119-1.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@94803 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-typeck.c')
-rw-r--r--gcc/c-typeck.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index f04ba73ad75..3a202929e9f 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -470,8 +470,8 @@ common_pointer_type (tree t1, tree t2)
This is the type for the result of most arithmetic operations
if the operands have the given two types. */
-tree
-common_type (tree t1, tree t2)
+static tree
+c_common_type (tree t1, tree t2)
{
enum tree_code code1;
enum tree_code code2;
@@ -522,7 +522,7 @@ common_type (tree t1, tree t2)
{
tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
- tree subtype = common_type (subtype1, subtype2);
+ tree subtype = c_common_type (subtype1, subtype2);
if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
return t1;
@@ -592,6 +592,18 @@ common_type (tree t1, tree t2)
return t2;
}
+/* Wrapper around c_common_type that is used by c-common.c. ENUMERAL_TYPEs
+ are allowed here and are converted to their compatible integer types. */
+tree
+common_type (tree t1, tree t2)
+{
+ if (TREE_CODE (t1) == ENUMERAL_TYPE)
+ t1 = c_common_type_for_size (TYPE_PRECISION (t1), 1);
+ if (TREE_CODE (t2) == ENUMERAL_TYPE)
+ t2 = c_common_type_for_size (TYPE_PRECISION (t2), 1);
+ return c_common_type (t1, t2);
+}
+
/* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
or various other operations. Return 2 if they are compatible
but a warning may be needed if you use them together. */
@@ -2893,7 +2905,7 @@ build_conditional_expr (tree ifexp, tree op1, tree op2)
&& (code2 == INTEGER_TYPE || code2 == REAL_TYPE
|| code2 == COMPLEX_TYPE))
{
- result_type = common_type (type1, type2);
+ result_type = c_common_type (type1, type2);
/* If -Wsign-compare, warn here if type1 and type2 have
different signedness. We'll promote the signed to unsigned
@@ -7461,7 +7473,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
int none_complex = (code0 != COMPLEX_TYPE && code1 != COMPLEX_TYPE);
if (shorten || common || short_compare)
- result_type = common_type (type0, type1);
+ result_type = c_common_type (type0, type1);
/* For certain operations (which identify themselves by shorten != 0)
if both args were extended from the same smaller type,
@@ -7519,7 +7531,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
&& (unsigned0 || !uns))
result_type
= c_common_signed_or_unsigned_type
- (unsigned0, common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
+ (unsigned0, c_common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
else if (TREE_CODE (arg0) == INTEGER_CST
&& (unsigned1 || !uns)
&& (TYPE_PRECISION (TREE_TYPE (arg1))