Commit 80a46699 authored by Sergio Costas's avatar Sergio Costas

Now doesn't use specific code for CRUST_POINTER == NULL or CRUST_POINTER != NULL

parent de0217f2
......@@ -840,39 +840,39 @@ class crust(object):
return retvals
if (statement.type == "EQ_OP") or (statement.type == "NE_OP"):
# check CRUST_POINTER == NULL, CRUST_POINTER != NULL
param1 = statement.child1[0]
param2 = statement.child2[0]
if param1.t_null and (param2.type == "IDENTIFIER"):
param1 = statement.child2[0]
param2 = statement.child1[0]
if param2.t_null and (param1.type == "IDENTIFIER"):
# check cases of CRUST_VAR == NULL or NULL == CRUST_VAR
var_data = self._find_variable(thread_status, param1.name, statement.line)
if var_data["crust"] or (((var_data["pointer"] != 0) or ((var_data["function_params"] is not None) and (var_data["value"] != self.VALUE_FUNCTION))) and (param1.right is None) and (param1.arrays is None)):
if statement.type == "EQ_OP":
cd1 = self.CONDITION_FALSE
cd2 = self.CONDITION_TRUE
else:
cd2 = self.CONDITION_FALSE
cd1 = self.CONDITION_TRUE
status = var_data["value"]
if status == crust.VALUE_UNINITIALIZED:
self._add_error(thread_status, self.MSG_ERROR, "Using uninitialized variable '{:s}' at line {:d}", param1.name, param1.line)
return [ {"thread_status":thread_status, "value":self.VALUE_NOT_NULL_OR_NULL, "type":self.TYPE_NO_CRUST, "condition":self.CONDITION_FALSE_TRUE, "node":None, "pure": True} ]
if status == crust.VALUE_NULL:
return [ {"thread_status":thread_status, "value":self.VALUE_NULL, "type":self.TYPE_NO_CRUST, "condition":cd2, "node":None, "pure": True} ]
if status == crust.VALUE_NOT_NULL:
return [ {"thread_status":thread_status, "value":self.VALUE_NOT_NULL, "type":self.TYPE_NO_CRUST, "condition":cd1, "node":None, "pure": True} ]
# status == crust.VALUE_NOT_NULL_OR_NULL or STATUS == crust.VALUE_GLOBAL
var1 = self._copy_status(thread_status)
var2 = thread_status
if status == crust.VALUE_NOT_NULL_OR_NULL:
# Only set the status if it is NOT_NULL_OR_NULL; but keep it if it is FREED
self._set_var_value(var1, param1.name, crust.VALUE_NULL, 0, True)
self._set_var_value(var2, param1.name, crust.VALUE_NOT_NULL, 0, True)
return [ {"thread_status":var1, "value":self.VALUE_NULL, "type":self.TYPE_NO_CRUST, "condition":cd2, "node":None, "pure": True}, {"thread_status":var2, "value":self.VALUE_NOT_NULL, "type":self.TYPE_NO_CRUST, "condition":cd1, "node":None, "pure": True} ]
# if (statement.type == "EQ_OP") or (statement.type == "NE_OP"):
# # check CRUST_POINTER == NULL, CRUST_POINTER != NULL
# param1 = statement.child1[0]
# param2 = statement.child2[0]
# if param1.t_null and (param2.type == "IDENTIFIER"):
# param1 = statement.child2[0]
# param2 = statement.child1[0]
# if param2.t_null and (param1.type == "IDENTIFIER"):
# # check cases of CRUST_VAR == NULL or NULL == CRUST_VAR
# var_data = self._find_variable(thread_status, param1.name, statement.line)
# if var_data["crust"] or (((var_data["pointer"] != 0) or ((var_data["function_params"] is not None) and (var_data["value"] != self.VALUE_FUNCTION))) and (param1.right is None) and (param1.arrays is None)):
# if statement.type == "EQ_OP":
# cd1 = self.CONDITION_FALSE
# cd2 = self.CONDITION_TRUE
# else:
# cd2 = self.CONDITION_FALSE
# cd1 = self.CONDITION_TRUE
# status = var_data["value"]
# if status == crust.VALUE_UNINITIALIZED:
# self._add_error(thread_status, self.MSG_ERROR, "Using uninitialized variable '{:s}' at line {:d}", param1.name, param1.line)
# return [ {"thread_status":thread_status, "value":self.VALUE_NOT_NULL_OR_NULL, "type":self.TYPE_NO_CRUST, "condition":self.CONDITION_FALSE_TRUE, "node":None, "pure": True} ]
# if status == crust.VALUE_NULL:
# return [ {"thread_status":thread_status, "value":self.VALUE_NULL, "type":self.TYPE_NO_CRUST, "condition":cd2, "node":None, "pure": True} ]
# if status == crust.VALUE_NOT_NULL:
# return [ {"thread_status":thread_status, "value":self.VALUE_NOT_NULL, "type":self.TYPE_NO_CRUST, "condition":cd1, "node":None, "pure": True} ]
# # status == crust.VALUE_NOT_NULL_OR_NULL or STATUS == crust.VALUE_GLOBAL
# var1 = self._copy_status(thread_status)
# var2 = thread_status
# if status == crust.VALUE_NOT_NULL_OR_NULL:
# # Only set the status if it is NOT_NULL_OR_NULL; but keep it if it is FREED
# self._set_var_value(var1, param1.name, crust.VALUE_NULL, 0, True)
# self._set_var_value(var2, param1.name, crust.VALUE_NOT_NULL, 0, True)
# return [ {"thread_status":var1, "value":self.VALUE_NULL, "type":self.TYPE_NO_CRUST, "condition":cd2, "node":None, "pure": True}, {"thread_status":var2, "value":self.VALUE_NOT_NULL, "type":self.TYPE_NO_CRUST, "condition":cd1, "node":None, "pure": True} ]
if (statement.type == "EQ_OP") or (statement.type == "NE_OP"):
......
......@@ -841,7 +841,7 @@ class Test(unittest.TestCase):
self._generic_test("unitest/test192.c", [ (crust.crust.MSG_ERROR, "At exit point in line {:d}, global variable '{:s}' points to a block freed at line {:d}.", 14, "var1", 12) ])
def test193GlobalVariableFreedAtExit(self):
lib = self._generic_test("unitest/test193.c", [ (crust.crust.MSG_ERROR, "At exit point in line {:d}, global variable '{:s}' points to the same block than global variable '{:s}'.", 18, "var1", "var2") ])
lib = self._generic_test("unitest/test193.c", [ (crust.crust.MSG_ERROR, "At exit point in line {:d}, global variable '{:s}' points to the same block than global variable '{:s}'.", 15, "var1", "var2") ])
self._check_block_id_is_the_same(lib, "arg1", "var1")
self._check_block_id_is_the_same(lib, "arg1", "var2")
......
......@@ -5,7 +5,6 @@ void function2(crust_t param);
void function() {
crust_t param4 = NULL;
function2(param4);
int retval = (param4 == NULL) ? 1 : 0; // It is fine to just check if the variable is NULL or not NULL; if it is used after this, it will fail there
function2(param4);
}
......@@ -3,16 +3,13 @@ typedef __crust__ unsigned char *crust_t;
crust_t var1;
crust_t var2;
void function(crust_t);
void main(crust_t __crust_not_null__ arg1) {
if ((var1 == NULL) && (var2 == NULL)) {
var1 = arg1;
var2 = arg1;
} else {
function(arg1);
}
__crust_set_null__(var1);
__crust_set_null__(var2);
var1 = arg1;
var2 = arg1;
__crust_debug__
// ERROR: there are two global variables pointing to the same block
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment