Skip to content

Commit

Permalink
more initialization fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thradams committed Nov 20, 2024
1 parent aabe2ff commit d0db6fa
Show file tree
Hide file tree
Showing 24 changed files with 111,294 additions and 110,458 deletions.
9 changes: 0 additions & 9 deletions src/cakeconfig.h

This file was deleted.

21 changes: 19 additions & 2 deletions src/file.c
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@

int a[2] = {1, 2, 3};
#pragma safety enable


_Owner int socket();
void close(_Owner int fd);

int main()
{
_Owner int fd;

fd = socket();
if (fd < 0)
{
static_set(fd, "null");
static_debug(fd);
return 1;
}
close(fd);
}
60 changes: 35 additions & 25 deletions src/flow_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ struct flow_object* _Opt make_object_core(struct flow_visit_ctx* ctx,
}
p_member_obj->parent = p_object;
objects_view_push_back(&p_object->members, p_member_obj);
}
}
}
p_member_declarator = p_member_declarator->next;
}
Expand Down Expand Up @@ -1912,7 +1912,7 @@ void object_get_name_core(
}
else if (p_member_declaration->specifier_qualifier_list != NULL)
{
// assert(false); //TODO
// assert(false); //TODO
}
p_member_declaration = p_member_declaration->next;
}
Expand Down Expand Up @@ -2258,7 +2258,8 @@ static void checked_read_object_core(struct flow_visit_ctx* ctx,
{
compiler_diagnostic_message(W_FLOW_UNINITIALIZED,
ctx->ctx,
position_token_opt, NULL,
position_token_opt,
p_marker_opt,
"uninitialized object '%s'",
previous_names);
}
Expand All @@ -2269,11 +2270,12 @@ static void checked_read_object_core(struct flow_visit_ctx* ctx,
//state somewhere!
if (p_visitor->p_object->current.state & FLOW_OBJECT_STATE_LIFE_TIME_ENDED)
{
//compiler_diagnostic_message(W_FLOW_UNINITIALIZED,
// ctx->ctx,
// position_token,
// "lifetime ended '%s'",
// previous_names);
compiler_diagnostic_message(W_FLOW_LIFETIME_ENDED,
ctx->ctx,
position_token_opt,
p_marker_opt,
"lifetime ended '%s'",
previous_names);
}


Expand Down Expand Up @@ -2518,25 +2520,33 @@ static void flow_end_of_block_visit_core(struct flow_visit_ctx* ctx,
{
if (p_visitor->p_type->storage_class_specifier_flags & STORAGE_SPECIFIER_PARAMETER)
{
//Visiting a pointer parameter. We check if we didn't mess a external object
if (type_is_any_owner(p_visitor->p_type))
{
//owner pointer parameters can point to deleted objects, so
//we cannot check this state inside checked_read_object
}
else
{
//Visiting a pointer parameter. We check if we didn't mess a external object
//TODO static flow_objects
struct type t2 = type_remove_pointer(p_visitor->p_type);
struct type t2 = type_remove_pointer(p_visitor->p_type);

if (p_visitor->p_object->current.pointed)
{
struct token* _Opt name_token = p_visitor->p_object->p_declarator_origin->name_opt ?
p_visitor->p_object->p_declarator_origin->name_opt :
p_visitor->p_object->p_declarator_origin->first_token_opt;

checked_read_object(ctx,
&t2,
false,
p_visitor->p_object->current.pointed,
name_token,
NULL,
true);
if (p_visitor->p_object->current.pointed)
{
struct token* _Opt name_token = p_visitor->p_object->p_declarator_origin->name_opt ?
p_visitor->p_object->p_declarator_origin->name_opt :
p_visitor->p_object->p_declarator_origin->first_token_opt;

checked_read_object(ctx,
&t2,
false,
p_visitor->p_object->current.pointed,
name_token,
NULL,
true);
}
type_destroy(&t2);
}
type_destroy(&t2);
}
}
else
Expand Down Expand Up @@ -2586,7 +2596,7 @@ static void flow_assignment_core(
struct object_visitor* p_visitor_a,
struct object_visitor* p_visitor_b,
bool* _Opt set_argument_to_unkown)
{
{
//const bool nullable_enabled = ctx->ctx->options.null_checks_enabled;

#ifdef _DEBUG
Expand Down
27 changes: 24 additions & 3 deletions src/flow_visit.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ static void flow_end_of_storage_visit(struct flow_visit_ctx* ctx,
struct flow_defer_scope* deferblock,
struct token* position_token)
{

struct flow_defer_scope* _Opt deferchild = deferblock->last_child;
while (deferchild != NULL)
{
Expand Down Expand Up @@ -3191,8 +3190,30 @@ static void flow_visit_jump_statement(struct flow_visit_ctx* ctx, struct jump_st
NULL
);

//WTF??
//p_dest_object->current.state = FLOW_OBJECT_STATE_LIFE_TIME_ENDED;
const int state_before_return = arena_add_copy_of_current_state(ctx, "before-return");

// Simulate the function's state as if it had already returned.
// This allows us to verify whether the returned object points to any
// local variables.

struct flow_defer_scope* _Opt p_defer = ctx->tail_block;
while (p_defer != NULL)
{
//TODO name like SET?
flow_end_of_storage_visit(ctx, p_defer, p_jump_statement->first_token);
p_defer = p_defer->previous;
}

checked_read_object(ctx,
ctx->p_return_type,
type_is_nullable(ctx->p_return_type, ctx->ctx->options.null_checks_enabled),
p_dest_object,
NULL,
&a_marker,
true);

//then we restore the state
arena_restore_current_state_from(ctx, state_before_return);
}

if (p_object && p_object->is_temporary)
Expand Down
16 changes: 8 additions & 8 deletions src/include/assert.h.include
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

47,42,13,10,32,42,32,32,84,104,105,115,32,102,105,108,101,32,105,115,32,112,97,114,116
,32,111,102,32,99,97,107,101,32,99,111,109,112,105,108,101,114,13,10,32,42,32,32,104,116
,116,112,115,58,47,47,103,105,116,104,117,98,46,99,111,109,47,116,104,114,97,100,97,109,115
,47,99,97,107,101,13,10,42,47,13,10,13,10,35,105,102,100,101,102,32,78,68,69,66,85
,71,13,10,35,100,101,102,105,110,101,32,97,115,115,101,114,116,40,46,46,46,41,32,40,40
,118,111,105,100,41,48,41,13,10,35,101,108,115,101,13,10,35,100,101,102,105,110,101,32,97
,115,115,101,114,116,40,46,46,46,41,32,97,115,115,101,114,116,40,95,95,86,65,95,65,82
,71,83,95,95,41,13,10,35,101,110,100,105,102,13,10
47,42,10,32,42,32,32,84,104,105,115,32,102,105,108,101,32,105,115,32,112,97,114,116,32
,111,102,32,99,97,107,101,32,99,111,109,112,105,108,101,114,10,32,42,32,32,104,116,116,112
,115,58,47,47,103,105,116,104,117,98,46,99,111,109,47,116,104,114,97,100,97,109,115,47,99
,97,107,101,10,42,47,10,10,35,105,102,100,101,102,32,78,68,69,66,85,71,10,35,100,101
,102,105,110,101,32,97,115,115,101,114,116,40,46,46,46,41,32,40,40,118,111,105,100,41,48
,41,10,35,101,108,115,101,10,35,100,101,102,105,110,101,32,97,115,115,101,114,116,40,46,46
,46,41,32,97,115,115,101,114,116,40,95,95,86,65,95,65,82,71,83,95,95,41,10,35,101
,110,100,105,102,10
Loading

0 comments on commit d0db6fa

Please sign in to comment.