diff mbox

[6/7] fix evaluation of a function or array symbol in conditionals

Message ID 20170322173257.63019-7-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show

Commit Message

Luc Van Oostenryck March 22, 2017, 5:32 p.m. UTC
Functions and arrays degenerate as pointers in most context
but this wasn't done in the case of conditionals.

As a result the value of the conditional after linearization
was invalid.

Fix this by calling degenerate() in evaluate_conditional().

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 evaluate.c                |  1 +
 validation/cond-address.c | 14 ++++++++++++++
 2 files changed, 15 insertions(+)
 create mode 100644 validation/cond-address.c
diff mbox

Patch

diff --git a/evaluate.c b/evaluate.c
index f2d95c79d..976857915 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -881,6 +881,7 @@  static struct symbol *evaluate_conditional(struct expression *expr, int iterator
 			ctype = NULL;
 		}
 	}
+	ctype = degenerate(expr);
 
 	return ctype;
 }
diff --git a/validation/cond-address.c b/validation/cond-address.c
new file mode 100644
index 000000000..2a69f4b92
--- /dev/null
+++ b/validation/cond-address.c
@@ -0,0 +1,14 @@ 
+extern void f(void);
+extern int a[];
+
+int foo(void) { if (f) return 1; return 0; }
+int bar(void) { if (a) return 1; return 0; }
+int qux(void) { if (f && a) return 1; return 0; }
+
+/*
+ * check-name: cond-address.c
+ * check-command: test-linearize -Wno-decl $file
+ * check-output-ignore
+ *
+ * check-excludes: VOID
+ */