Skip to content

Commit

Permalink
fixing _Obj_Owner
Browse files Browse the repository at this point in the history
  • Loading branch information
thradams committed Apr 23, 2024
1 parent 7a1b7b8 commit 28a070e
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 305 deletions.
20 changes: 4 additions & 16 deletions src/file.c
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@

#pragma nullable enable
#pragma ownership enable

char * _Owner _Opt strdup(const char* s);
void free(void * _Opt _Owner p);
#pragma nullable enable

struct X {
char *_Owner name;
};

void x_destroy(_Opt struct X x)
void x_destroy(_Opt struct X * _Obj_owner x)
{
free(x.name);
}

int main() {
_Opt struct X x = {0};
x.name = strdup("a");
x_destroy(x);
}


//free(x.name);
}
61 changes: 10 additions & 51 deletions src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -23811,7 +23811,7 @@ void visit_object(struct parser_ctx* ctx,

static void end_of_storage_visit_core(struct parser_ctx* ctx,
struct type* p_type,
bool type_is_view,
bool b_type_is_view,
struct object* p_object,
const struct token* position_token,
const char* previous_names,
Expand Down Expand Up @@ -23883,7 +23883,7 @@ static void end_of_storage_visit_core(struct parser_ctx* ctx,

end_of_storage_visit_core(ctx,
&p_member_declarator->declarator->type,
type_is_view,
b_type_is_view,
p_object->members.data[member_index],
position_token,
buffer,
Expand Down Expand Up @@ -23926,11 +23926,10 @@ static void end_of_storage_visit_core(struct parser_ctx* ctx,
the reference is not referring an object, the value could be -1 for instance.
*/
if (type_is_pointer(p_type) &&
!type_is_view &&
!b_type_is_view &&
type_is_owner(p_type) &&
p_object->state & OBJECT_STATE_NOT_NULL)
{

if (compiler_diagnostic_message(W_FLOW_MISSING_DTOR,
ctx,
position,
Expand All @@ -23941,58 +23940,18 @@ static void end_of_storage_visit_core(struct parser_ctx* ctx,
position_token,
"end of lifetime");
}
#if 0
}
else if (!b_type_is_view && type_is_obj_owner(p_type) && type_is_pointer(p_type))
{
char buffer[100] = { 0 };
snprintf(buffer, sizeof buffer, "%s", previous_names);
struct type t2 = type_remove_pointer(p_type);
if (p_object->ref.size == 0)

for (int i = 0; i < p_object->ref.size; i++)
{
if (position)
{
compiler_diagnostic_message(W_OWNERSHIP_FLOW_MISSING_DTOR,
ctx,
position,
"memory pointed by owner pointer '%s' not deleted", name);
}
end_of_storage_visit_core(ctx, &t2, b_type_is_view, p_object->ref.data[i], position, buffer, visit_number);
}
else
{
for (int i = 0; i < p_object->ref.size; i++)
{
if (p_object->ref.data[i]->state & OBJECT_STATE_LIFE_TIME_ENDED)
{
}
else
{
bool memory_deleted = false;
if (type_is_struct_or_union(&t2))
{
if (p_object->ref.data[i]->members.size > 0)
{
if (p_object->ref.data[i]->members.data[0]->state & OBJECT_STATE_LIFE_TIME_ENDED)
{
memory_deleted = true;
}
}
}
else
{
memory_deleted = p_object->ref.data[i]->state & OBJECT_STATE_LIFE_TIME_ENDED;
}

if (!memory_deleted)
{
compiler_diagnostic_message(W_OWNERSHIP_FLOW_MISSING_DTOR,
ctx,
position,
"memory pointed by owner pointer '%s' not deleted", name);
}
}
}

type_destroy(&t2);
}
#endif
type_destroy(&t2);
}
else if (type_is_owner(p_type) && !type_is_pointer(p_type))
{
Expand Down
61 changes: 10 additions & 51 deletions src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2632,7 +2632,7 @@ void visit_object(struct parser_ctx* ctx,

static void end_of_storage_visit_core(struct parser_ctx* ctx,
struct type* p_type,
bool type_is_view,
bool b_type_is_view,
struct object* p_object,
const struct token* position_token,
const char* previous_names,
Expand Down Expand Up @@ -2704,7 +2704,7 @@ static void end_of_storage_visit_core(struct parser_ctx* ctx,

end_of_storage_visit_core(ctx,
&p_member_declarator->declarator->type,
type_is_view,
b_type_is_view,
p_object->members.data[member_index],
position_token,
buffer,
Expand Down Expand Up @@ -2747,11 +2747,10 @@ static void end_of_storage_visit_core(struct parser_ctx* ctx,
the reference is not referring an object, the value could be -1 for instance.
*/
if (type_is_pointer(p_type) &&
!type_is_view &&
!b_type_is_view &&
type_is_owner(p_type) &&
p_object->state & OBJECT_STATE_NOT_NULL)
{

if (compiler_diagnostic_message(W_FLOW_MISSING_DTOR,
ctx,
position,
Expand All @@ -2762,58 +2761,18 @@ static void end_of_storage_visit_core(struct parser_ctx* ctx,
position_token,
"end of lifetime");
}
#if 0
}
else if (!b_type_is_view && type_is_obj_owner(p_type) && type_is_pointer(p_type))
{
char buffer[100] = { 0 };
snprintf(buffer, sizeof buffer, "%s", previous_names);
struct type t2 = type_remove_pointer(p_type);
if (p_object->ref.size == 0)

for (int i = 0; i < p_object->ref.size; i++)
{
if (position)
{
compiler_diagnostic_message(W_OWNERSHIP_FLOW_MISSING_DTOR,
ctx,
position,
"memory pointed by owner pointer '%s' not deleted", name);
}
end_of_storage_visit_core(ctx, &t2, b_type_is_view, p_object->ref.data[i], position, buffer, visit_number);
}
else
{
for (int i = 0; i < p_object->ref.size; i++)
{
if (p_object->ref.data[i]->state & OBJECT_STATE_LIFE_TIME_ENDED)
{
}
else
{
bool memory_deleted = false;
if (type_is_struct_or_union(&t2))
{
if (p_object->ref.data[i]->members.size > 0)
{
if (p_object->ref.data[i]->members.data[0]->state & OBJECT_STATE_LIFE_TIME_ENDED)
{
memory_deleted = true;
}
}
}
else
{
memory_deleted = p_object->ref.data[i]->state & OBJECT_STATE_LIFE_TIME_ENDED;
}

if (!memory_deleted)
{
compiler_diagnostic_message(W_OWNERSHIP_FLOW_MISSING_DTOR,
ctx,
position,
"memory pointed by owner pointer '%s' not deleted", name);
}
}
}

type_destroy(&t2);
}
#endif
type_destroy(&t2);
}
else if (type_is_owner(p_type) && !type_is_pointer(p_type))
{
Expand Down
Loading

0 comments on commit 28a070e

Please sign in to comment.