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 8a4e017 commit fc596ef
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 21 deletions.
17 changes: 12 additions & 5 deletions src/file.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
void* f();
int main() {
void* _Owner p = f();
#pragma cake diagnostic check "-Wmissing-owner-qualifier"
void* _Owner malloc(unsigned long size);
void free(void* _Owner ptr);

struct X {
char* _Owner name;
};

int main()
{
struct X* p = (struct X* _Owner) malloc(1);
}

#pragma cake diagnostic check "-Wmissing-destructor"
//flow analyze
#pragma cake diagnostic check "-Wmissing-owner-qualifier"
32 changes: 22 additions & 10 deletions src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -11158,10 +11158,6 @@ void object_destroy(struct object* obj_owner p);
void object_delete(struct object* owner opt p);
void object_swap(struct object* a, struct object* b);
struct object* object_get_pointed_object(const struct object* p);
//void checked_empty(struct parser_ctx* ctx,
// struct type* p_type,
// struct object* p_object,
// const struct token* position_token);
struct declarator;
struct object make_object(struct type* p_type,
const struct declarator* p_declarator_opt,
Expand Down Expand Up @@ -23317,11 +23313,11 @@ void object_assignment3(struct parser_ctx* ctx,
{
return;
}
printf("line %d ", error_position->line);
type_print(p_a_type);
printf(" = ");
type_print(p_b_type);
printf("\n");
//printf("line %d ", error_position->line);
//type_print(p_a_type);
//printf(" = ");
//type_print(p_b_type);
//printf("\n");

/*general check for copying uninitialized object*/
if (check_uninitialized_b && p_b_object->state & OBJECT_STATE_UNINITIALIZED)
Expand Down Expand Up @@ -23420,7 +23416,7 @@ void object_assignment3(struct parser_ctx* ctx,
object_set_uninitialized(p_b_type, p_b_object);
else
{

object_set_moved(p_b_type, p_b_object);
}

Expand Down Expand Up @@ -23500,6 +23496,22 @@ void object_assignment3(struct parser_ctx* ctx,
}
else
{
if (!type_is_owner(p_a_type))
{
if (type_is_owner(p_b_type) &&
p_b_type->storage_class_specifier_flags & STORAGE_SPECIFIER_FUNCTION_RETURN)
{
/*
This situation
struct X* p = (struct X* _Owner) malloc(1);
*/
compiler_diagnostic_message(W_OWNERSHIP_MISSING_OWNER_QUALIFIER,
ctx,
error_position,
"owner object has short lifetime");
}
}

if (assigment_type == ASSIGMENT_TYPE_PARAMETER)
{
struct type t = type_remove_pointer(p_a_type);
Expand Down
28 changes: 22 additions & 6 deletions src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2369,11 +2369,11 @@ void object_assignment3(struct parser_ctx* ctx,
{
return;
}
printf("line %d ", error_position->line);
type_print(p_a_type);
printf(" = ");
type_print(p_b_type);
printf("\n");
//printf("line %d ", error_position->line);
//type_print(p_a_type);
//printf(" = ");
//type_print(p_b_type);
//printf("\n");

/*general check for copying uninitialized object*/
if (check_uninitialized_b && p_b_object->state & OBJECT_STATE_UNINITIALIZED)
Expand Down Expand Up @@ -2472,7 +2472,7 @@ void object_assignment3(struct parser_ctx* ctx,
object_set_uninitialized(p_b_type, p_b_object);
else
{

object_set_moved(p_b_type, p_b_object);
}

Expand Down Expand Up @@ -2552,6 +2552,22 @@ void object_assignment3(struct parser_ctx* ctx,
}
else
{
if (!type_is_owner(p_a_type))
{
if (type_is_owner(p_b_type) &&
p_b_type->storage_class_specifier_flags & STORAGE_SPECIFIER_FUNCTION_RETURN)
{
/*
This situation
struct X* p = (struct X* _Owner) malloc(1);
*/
compiler_diagnostic_message(W_OWNERSHIP_MISSING_OWNER_QUALIFIER,
ctx,
error_position,
"owner object has short lifetime");
}
}

if (assigment_type == ASSIGMENT_TYPE_PARAMETER)
{
struct type t = type_remove_pointer(p_a_type);
Expand Down

0 comments on commit fc596ef

Please sign in to comment.