Fix bug when handling code with data type errors.
authorMario de Sousa <msousa@fe.up.pt>
Mon, 16 Apr 2012 20:13:58 +0100
changeset 515 fdef852a6565
parent 514 c2880eba49a1
child 516 8591746fa134
Fix bug when handling code with data type errors.
stage3/narrow_candidate_datatypes.cc
--- a/stage3/narrow_candidate_datatypes.cc	Mon Apr 16 15:40:12 2012 +0100
+++ b/stage3/narrow_candidate_datatypes.cc	Mon Apr 16 20:13:58 2012 +0100
@@ -96,6 +96,12 @@
 
 
 bool narrow_candidate_datatypes_c::is_widening_compatible(const struct widen_entry widen_table[], symbol_c *left_type, symbol_c *right_type, symbol_c *result_type, bool *deprecated_status) {
+	/* NOTE: According to our algorithm, left_type and right_type should never by NULL (if they are, we have an internal compiler error!
+	 *       However, result_type may be NULL if the code has a data type semantic error!
+	 */
+	if ((NULL == left_type) || (NULL == right_type) || (NULL == result_type))
+		return false;
+
 	for (int k = 0; NULL != widen_table[k].left;  k++) {
 		if        ((typeid(*left_type)   == typeid(*widen_table[k].left))
 		        && (typeid(*right_type)  == typeid(*widen_table[k].right))