Skip to content

Commit

Permalink
fixing noreturn
Browse files Browse the repository at this point in the history
  • Loading branch information
thradams committed May 16, 2024
1 parent 226ac78 commit 3df2116
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 99 deletions.
9 changes: 4 additions & 5 deletions src/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
void free(void* _Owner _Opt p);
char* _Owner _Opt strdup(const char* s);
[[noreturn]] void exit( int exit_code );

#define NULL ((void*)0)
void f()
{
char * _Opt _Owner s = strdup("a");

if (s == nullptr)
{
exit(1);
}
if (s == NULL)
exit(1);

static_state(s, "not-null");
static_debug(s);
free(s);
}
48 changes: 30 additions & 18 deletions src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -30886,28 +30886,40 @@ struct secondary_block* owner secondary_block(struct parser_ctx* ctx)

bool unlabeled_statement_ends_with_jump(struct unlabeled_statement* p_unlabeled_statement)
{
struct expression* p_expression = NULL;

if (p_unlabeled_statement->expression_statement)
{
p_expression = p_unlabeled_statement->expression_statement->expression_opt;
}
else if (p_unlabeled_statement->jump_statement)
{
return true;
}
else if (p_unlabeled_statement->primary_block &&
p_unlabeled_statement->primary_block->compound_statement &&
p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail &&
p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail->unlabeled_statement &&
p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail->unlabeled_statement->expression_statement)
{
p_expression =
p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail->unlabeled_statement->expression_statement->expression_opt;
}

if (p_expression)
{
return p_expression->type.attributes_flags & STD_ATTRIBUTE_NORETURN;
}

if (p_unlabeled_statement->primary_block &&
p_unlabeled_statement->primary_block->compound_statement &&
p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail &&
p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail->unlabeled_statement)
{
if (p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail->unlabeled_statement->expression_statement &&
p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail->unlabeled_statement->expression_statement->expression_opt)
{
if (p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail->unlabeled_statement->expression_statement->expression_opt->expression_type == POSTFIX_FUNCTION_CALL)
{
//calling a function declared with [[noreturn]]
return p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail->unlabeled_statement->expression_statement->expression_opt->type.attributes_flags & STD_ATTRIBUTE_NORETURN;
}
}

return
p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail->unlabeled_statement->jump_statement != NULL;
}
else if (p_unlabeled_statement->jump_statement)
{
return true;
}

return false;
}

Expand Down Expand Up @@ -31059,16 +31071,16 @@ struct unlabeled_statement* owner unlabeled_statement(struct parser_ctx* ctx)
}
}
}
}
}
}
}
catch
{
unlabeled_statement_delete(p_unlabeled_statement);
p_unlabeled_statement = NULL;
}

return p_unlabeled_statement;
}
}

void label_delete(struct label* owner opt p)
{
Expand Down Expand Up @@ -32316,7 +32328,7 @@ void append_msvc_include_dir(struct preprocessor_ctx* prectx)
}
}
#endif
}
}

const char* owner format_code(struct options* options, const char* content)
{
Expand Down
48 changes: 30 additions & 18 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -6084,28 +6084,40 @@ struct secondary_block* owner secondary_block(struct parser_ctx* ctx)

bool unlabeled_statement_ends_with_jump(struct unlabeled_statement* p_unlabeled_statement)
{
struct expression* p_expression = NULL;

if (p_unlabeled_statement->expression_statement)
{
p_expression = p_unlabeled_statement->expression_statement->expression_opt;
}
else if (p_unlabeled_statement->jump_statement)
{
return true;
}
else if (p_unlabeled_statement->primary_block &&
p_unlabeled_statement->primary_block->compound_statement &&
p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail &&
p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail->unlabeled_statement &&
p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail->unlabeled_statement->expression_statement)
{
p_expression =
p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail->unlabeled_statement->expression_statement->expression_opt;
}

if (p_expression)
{
return p_expression->type.attributes_flags & STD_ATTRIBUTE_NORETURN;
}

if (p_unlabeled_statement->primary_block &&
p_unlabeled_statement->primary_block->compound_statement &&
p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail &&
p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail->unlabeled_statement)
{
if (p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail->unlabeled_statement->expression_statement &&
p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail->unlabeled_statement->expression_statement->expression_opt)
{
if (p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail->unlabeled_statement->expression_statement->expression_opt->expression_type == POSTFIX_FUNCTION_CALL)
{
//calling a function declared with [[noreturn]]
return p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail->unlabeled_statement->expression_statement->expression_opt->type.attributes_flags & STD_ATTRIBUTE_NORETURN;
}
}

return
p_unlabeled_statement->primary_block->compound_statement->block_item_list.tail->unlabeled_statement->jump_statement != NULL;
}
else if (p_unlabeled_statement->jump_statement)
{
return true;
}

return false;
}

Expand Down Expand Up @@ -6257,16 +6269,16 @@ struct unlabeled_statement* owner unlabeled_statement(struct parser_ctx* ctx)
}
}
}
}
}
}
}
catch
{
unlabeled_statement_delete(p_unlabeled_statement);
p_unlabeled_statement = NULL;
}

return p_unlabeled_statement;
}
}

void label_delete(struct label* owner opt p)
{
Expand Down Expand Up @@ -7514,7 +7526,7 @@ void append_msvc_include_dir(struct preprocessor_ctx* prectx)
}
}
#endif
}
}

const char* owner format_code(struct options* options, const char* content)
{
Expand Down
Loading

0 comments on commit 3df2116

Please sign in to comment.