Skip to contentSkip to conversation

Fix incorrect linearization of "x && y && z"

PATCH In review Daniel De Graaf 2 participants 2 messages Oct 27, 2009 – Oct 28, 2009 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix incorrect linearization of "x && y && z"

This fixes an incorrect assumption that results in && using shortcut logic on the true branch instead of the false branch.

---
 linearize.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
linearize.c +4 -1
index 238ee5d..9247409 100644
@@ -1389,7 +1389,10 @@ static pseudo_t linearize_logical(struct entrypoint *ep, struct expression *expr
 
 	shortcut = alloc_const_expression(expr->pos, expr->op == SPECIAL_LOGICAL_OR);
 	shortcut->ctype = expr->ctype;
-	return  linearize_conditional(ep, expr, expr->left, shortcut, expr->right);
+	if (expr->op == SPECIAL_LOGICAL_OR)
+		return linearize_conditional(ep, expr, expr->left, shortcut, expr->right);
+	else
+		return linearize_conditional(ep, expr, expr->left, expr->right, shortcut);
 }
 
 static pseudo_t linearize_compare(struct entrypoint *ep, struct expression *expr)
Signature · 1 line
1.6.5
maintainer
#1 lore raw
Quoted 2 lines · Daniel De Graaf

This fixes an incorrect assumption that results in && using shortcut logic on the true branch instead of the false branch.

Good catch. Thanks!
I applied it without the "else" line.

Chris

PS. I almost miss this email because it is send to "unlisted-recipients". My patch tool catches it though.