Commit 755093b0 authored by Sergio Costas's avatar Sergio Costas

Simplified the detection of the use of a borrowed block in an assignment

Now detects better when using a member of an struct block
parent 9e01a6be
This diff is collapsed.
......@@ -277,10 +277,14 @@ class Test(unittest.TestCase):
self._generic_test("unitest/test68.c",[(crusty.crusty.MSG_ERROR,"Overwritting a borrowed block ('{:s}' at line {:d}) with a new block is not allowed", "param", 7), (crusty.crusty.MSG_ERROR,"Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "param", 7, 5)])
def testAssignmentFromBorrowBlock(self):
self._generic_test("unitest/test69.c",[ (crusty.crusty.MSG_ERROR,"Assigning a borrowed block into a local variable is not allowed (assignment to '{:s}' at line {:d})","var2",13) ])
self._generic_test("unitest/test69.c",[ (crusty.crusty.MSG_ERROR,"Assigning a borrowed block into a local variable is not allowed (assigning '{:s}' at line {:d})","param",13) ])
def testAssignmentFromBorrowBlock2(self):
self._generic_test("unitest/test70.c",[ (crusty.crusty.MSG_ERROR,"Assigning a borrowed block into a local variable is not allowed (assignment to '{:s}' at line {:d})","var2",13) ])
self._generic_test("unitest/test70.c",[ (crusty.crusty.MSG_ERROR,"Assigning a borrowed block into a local variable is not allowed (assigning '{:s}' at line {:d})","param",13) ])
def testAssignmentToAndFromMemberOfBorrowBlock(self):
self._all_fine_test("unitest/test71.c")
if __name__ == '__main__':
unittest.main()
#define NULL ((void *)0)
typedef __crust_t__ unsigned char *crust_t;
typedef __crust_t__ struct {
int member;
int p1;
int p2;
} *crust_t;
__crust_t__ unsigned char * calling(__crust_t__ unsigned char *param1, __crust_recycle__ unsigned char *param2, crust_t param3);
__crust_t__ unsigned char * calling2();
......@@ -13,6 +17,15 @@ void calling4(crust_t param) {
calling4(param); // a trick to free param and trigger only one error
}
void calling5(crust_t __crust_borrow__ param) {
int a = 5;
int b = a > 6 ? param->p1 : param->p2;
}
void calling6(int v) {
}
void main() {
int a = 1 ? 3 : 0;
......@@ -21,6 +34,10 @@ void main() {
crust_t param2 = (crust_t) "hello world";
crust_t param3 = NULL;
calling6(param2->member);
int tmp = param2->member;
crust_t param4;
param4 = calling(param1,param2,param3);
......
......@@ -4,11 +4,8 @@ typedef __crust_t__ struct {
#define NULL ((void *)0)
void function(crust_t param) {
function(param); // a trick to free param and trigger only one error
}
void main(crust_t __crust_borrow__ param) {
int var2 = param->element;
param->element = var2;
}
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