Skip to content

Commit

Permalink
preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
thradams committed Mar 24, 2024
1 parent 8fe5176 commit f14d069
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
15 changes: 10 additions & 5 deletions src/file.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
void* _Owner malloc(int i);
void free(void* _Owner p);

struct X {
char* _Owner p;
char* _Owner name;
};
void x_destroy(struct X* _Obj_owner p);
void f(struct X* x)

void x_delete(struct X* _Owner p)
{
x_destroy(x);
if (p) {
//free(p->name);
free(p);
}
}

#pragma cake diagnostic check "-Wmust-use-address-of"
#pragma cake diagnostic check "-Wmissing-destructor"
18 changes: 10 additions & 8 deletions src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -22281,18 +22281,20 @@ void checked_empty(struct parser_ctx* ctx,

if (type_is_any_owner(p_type))
{
if ((p_object->state & OBJECT_STATE_MOVED) ||
(p_object->state & OBJECT_STATE_UNINITIALIZED) ||
(p_object->state & OBJECT_STATE_NULL))
if ((p_object->state == OBJECT_STATE_MOVED) ||
(p_object->state == OBJECT_STATE_UNINITIALIZED) ||
(p_object->state == OBJECT_STATE_NULL))
{
}
else if (p_object->state & OBJECT_STATE_NOT_NULL)
{
struct type t = type_remove_pointer(p_type);
struct object* pointed = object_get_pointed_object(p_object);
if (pointed)
checked_empty(ctx, &t, pointed, position_token);
type_destroy(&t);
char name[200] = { 0 };
object_get_name(p_type, p_object, name, sizeof name);
compiler_diagnostic_message(W_OWNERSHIP_FLOW_MISSING_DTOR,
ctx,
position_token,
"object '%s' is not empty",
name);
}
else
{
Expand Down
18 changes: 10 additions & 8 deletions src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1333,18 +1333,20 @@ void checked_empty(struct parser_ctx* ctx,

if (type_is_any_owner(p_type))
{
if ((p_object->state & OBJECT_STATE_MOVED) ||
(p_object->state & OBJECT_STATE_UNINITIALIZED) ||
(p_object->state & OBJECT_STATE_NULL))
if ((p_object->state == OBJECT_STATE_MOVED) ||
(p_object->state == OBJECT_STATE_UNINITIALIZED) ||
(p_object->state == OBJECT_STATE_NULL))
{
}
else if (p_object->state & OBJECT_STATE_NOT_NULL)
{
struct type t = type_remove_pointer(p_type);
struct object* pointed = object_get_pointed_object(p_object);
if (pointed)
checked_empty(ctx, &t, pointed, position_token);
type_destroy(&t);
char name[200] = { 0 };
object_get_name(p_type, p_object, name, sizeof name);
compiler_diagnostic_message(W_OWNERSHIP_FLOW_MISSING_DTOR,
ctx,
position_token,
"object '%s' is not empty",
name);
}
else
{
Expand Down

0 comments on commit f14d069

Please sign in to comment.