Browse code

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 authored on 04/05/2009 20:02:49
Showing 1 changed files
... ...
@@ -47,6 +47,8 @@
47 47
 
48 48
 #include "rvalue.h"
49 49
 
50
+#include <stdlib.h> /* abort() */
51
+
50 52
 /* minimum size alloc'ed for STR RVs (to accomodate
51 53
  * strops without reallocs) */
52 54
 #define RV_STR_EXTRA 80
... ...
@@ -2577,6 +2579,13 @@ static int rve_replace_with_val(struct rval_expr* rve, enum rval_type type,
2577 2577
 		if (rve_op_unary(rve->op)==0)
2578 2578
 			rve_destroy(rve->right.rve);
2579 2579
 	}else{
2580
+		if (rve->left.rval.refcnt!=1){
2581
+			BUG("trying to replace a referenced rval! (refcnt=%d)\n",
2582
+					rve->left.rval.refcnt);
2583
+			/* try to recover */
2584
+			refcnt=rve->left.rval.refcnt;
2585
+			abort(); /* find bugs quicker -- andrei */
2586
+		}
2580 2587
 		rval_destroy(&rve->left.rval);
2581 2588
 	}
2582 2589
 	rval_init(&rve->left.rval, type, v, flags);