[PATCH 3/3] fix: add missing degenerate() for logical not

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Expressions involving the logical-not '!' does not
call degenerate().

Since the result type is always 'int' and thus independent
of the expression being negated, this has no effect on the
type-checking but the linearization is wrong.
For example, code like:
	int foo(void)
	{
		if (!arr) return 1;
		return 0;
	}
generates:
	foo:
		load        %r6 <- 0[arr]
		seteq.32    %r7 <- VOID, $0
		ret.32      %r7
The 'load' being, obviously wrong.

Fix this by adding the missing degenerate().

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 evaluate.c                        | 1 +
 validation/linear/degen-log-not.c | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/evaluate.c b/evaluate.c
index 4bca13542..6b3e2c257 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -1914,6 +1914,7 @@ static struct symbol *evaluate_preop(struct expression *expr)
 		return evaluate_postop(expr);
 
 	case '!':
+		ctype = degenerate(expr->unop);
 		expr->flags = expr->unop->flags & ~CEF_CONST_MASK;
 		/*
 		 * A logical negation never yields an address constant
diff --git a/validation/linear/degen-log-not.c b/validation/linear/degen-log-not.c
index baa7d5366..a982e34b2 100644
--- a/validation/linear/degen-log-not.c
+++ b/validation/linear/degen-log-not.c
@@ -33,7 +33,6 @@ int test_fun_degen(int i)
 /*
  * check-name: degenerate logical-not
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-excludes: load
-- 
2.15.0

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux