commit 45da2d1eff24fc3c0393d5ffbea087d1507b598c
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Thu Jan 7 23:15:51 2016 +0100
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Fri Jan 8 10:49:29 2016 +0100

    Convert chkternary() o use the new fields in type

diff --git a/cc1/expr.c b/cc1/expr.c
index dc59ea1..39e9096 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -126,51 +126,48 @@ set_p1_p2:
 }
 
 static Node *
-chkternary(Node *ifyes, Node *ifno)
+chkternary(Node *yes, Node *no)
 {
-       int arithy = 0, aithn = 0;
-       Type *tyes, *tno;
+       yes = decay(yes);
+       no = decay(no);
+
+       /*
+        * FIXME:
+        * We are ignoring type qualifiers here,
+        * but the standard has strong rules about this.
+        * take a look to 6.5.15
+        */
+
+       if (!eqtype(yes->type, no->type)) {
+               if (yes->type->arith && no->type->arith) {
+                       arithconv(&yes, &no);
+               } else if (yes->type->op != PTR && no->type->op != PTR) {
+                       goto wrong_type;
+               } else {
+                       if (yes->type->integer && cmpnode(yes, 0))
+                               yes = convert(yes, no->type, 0);
+                       if (no->type->integer && cmpnode(no, 0))
+                               no = convert(no, no->type, 0);
 
-       tyes = ifyes->type, tno = ifno->type;
+                       if (yes->type->op != PTR || no->type->op != PTR)
+                               goto wrong_type;
 
-       switch (tyes->op) {
-       case ENUM:
-       case INT:
-       case FLOAT:
-               switch (tno->op) {
-               case ENUM:
-               case INT:
-               case FLOAT:
-                       arithconv(&ifyes, &ifno);
-                       break;
-               default:
-                       goto wrong_type;
+                       if (yes->type == pvoidtype)
+                               yes = convert(yes, no->type, 0);
+                       if (no->type == pvoidtype)
+                               no = convert(no, no->type, 0);
+
+                       if (!eqtype(yes->type, no->type))
+                               goto wrong_type;
                }
-               break;
-       case ARY:
-       case FTN:
-                       ifyes = decay(ifyes);
-                       tyes = ifyes->type;
-                       ifno = decay(ifno);
-                       tno = ifno->type;
-       case PTR:
-               if ((ifno = convert(ifno, tyes, 0)) == NULL)
-                       goto wrong_type;
-               break;
-       case VOID:
-       case STRUCT:
-       case UNION:
-               if (!eqtype(tyes, tno))
-                       goto wrong_type;
-               break;
-       default:
-               abort();
        }
-       return node(OCOLON, ifyes->type, ifyes, ifno);
+       return node(OCOLON, yes->type, yes, yes);
 
 wrong_type:
        errorp("type mismatch in conditional expression");
-       return node(OCOLON, ifyes->type, ifyes, ifyes);
+       freetree(yes);
+       freetree(no);
+       return constnode(zero);
 }
 
 static void

Reply via email to