Преглед изворни кода

core expr. eval: added bug catcher

Added code for catching an easy to overlook bug (replacing in-line
a referenced rval during optimizing).
Andrei Pelinescu-Onciul пре 16 година
родитељ
комит
087be8daf0
1 измењених фајлова са 9 додато и 0 уклоњено
  1. 9 0
      rvalue.c

+ 9 - 0
rvalue.c

@@ -47,6 +47,8 @@
 
 
 #include "rvalue.h"
 #include "rvalue.h"
 
 
+#include <stdlib.h> /* abort() */
+
 /* minimum size alloc'ed for STR RVs (to accomodate
 /* minimum size alloc'ed for STR RVs (to accomodate
  * strops without reallocs) */
  * strops without reallocs) */
 #define RV_STR_EXTRA 80
 #define RV_STR_EXTRA 80
@@ -2577,6 +2579,13 @@ static int rve_replace_with_val(struct rval_expr* rve, enum rval_type type,
 		if (rve_op_unary(rve->op)==0)
 		if (rve_op_unary(rve->op)==0)
 			rve_destroy(rve->right.rve);
 			rve_destroy(rve->right.rve);
 	}else{
 	}else{
+		if (rve->left.rval.refcnt!=1){
+			BUG("trying to replace a referenced rval! (refcnt=%d)\n",
+					rve->left.rval.refcnt);
+			/* try to recover */
+			refcnt=rve->left.rval.refcnt;
+			abort(); /* find bugs quicker -- andrei */
+		}
 		rval_destroy(&rve->left.rval);
 		rval_destroy(&rve->left.rval);
 	}
 	}
 	rval_init(&rve->left.rval, type, v, flags);
 	rval_init(&rve->left.rval, type, v, flags);