scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 7ab3e04d0e3943e2f70bec9579b606a80357dbe6
parent 1e257a4aedd7fe98c0f59750b26807da432d326b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 18 Apr 2014 19:41:46 +0200

Add checkof equal type in typeconv()

This function must convert two expressions to the same type, but
it faulted when they have the same type.

Diffstat:
expr.c | 8+++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/expr.c b/expr.c @@ -46,6 +46,8 @@ typeconv(Node **p1, Node **p2) tp1 = UNQUAL(np1->type); tp2 = UNQUAL(np2->type); + if (tp1 == tp2) + return; new1 = new2 = NULL; n = tp1->u.size - tp2->u.size; @@ -697,17 +699,13 @@ static Node * ternary(void) { Node *np, *ifyes, *ifno; - Type *tp1, *tp2; np = or(); while (accept('?')) { ifyes = promote(expr()); expect(':'); ifno = promote(ternary()); - tp1 = UNQUAL(ifyes->type); - tp2 = UNQUAL(ifno->type); - if (tp1 != tp2) - typeconv(&ifyes, &ifno); + typeconv(&ifyes, &ifno); np = ternarycode(iszero(np), ifyes, ifno); } return np;