Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
thradams committed Feb 25, 2024
1 parent e378bba commit 66b07e8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
13 changes: 5 additions & 8 deletions src/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@ void* _Owner malloc(unsigned long size);
void free(void* _Owner ptr);

struct X {
char* _Owner text;
char* _Owner name;
};

void x_delete(struct X* _Owner p);

int main() {
struct X* _Owner p = malloc(sizeof(struct X));
x_delete(p); /*uninitialized*/
int main()
{
struct X* p = (struct X* _Owner) malloc(1);
}


void dummy()
{
}

//flow analyze
#pragma cake diagnostic check "-Wmaybe-uninitialized"
#pragma cake diagnostic check "-Wmissing-owner-qualifier"

22 changes: 16 additions & 6 deletions src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -21538,7 +21538,7 @@ void object_assignment(struct parser_ctx* ctx,
}
*/

compiler_diagnostic_message(W_ANALYZER_OWNERSHIP_FLOW_MISSING_DTOR,
compiler_diagnostic_message(W_OWNERSHIP_MISSING_OWNER_QUALIFIER,
ctx,
error_position,
"Object must be owner qualified.");
Expand Down Expand Up @@ -37559,14 +37559,24 @@ void discarding_owner()
"void free(void* _Owner ptr);\n"
"\n"
"struct X {\n"
" char *_Owner name;\n"
" char* _Owner name;\n"
"};\n"
"\n"
"int main()\n"
"{ \n"
" struct X * p = (struct X * _Owner) malloc(1);\n"
"}";
assert(compile_with_errors(true, false, source));
"{\n"
" struct X* p = (struct X* _Owner) malloc(1);\n"
"}\n"
"\n"
"void dummy()\n"
"{\n"
"} \n"
"\n"
"//flow analyze\n"
"#pragma cake diagnostic check \"-Wmissing-owner-qualifier\"\n"
"\n"
"";

assert(compile_without_errors(true, false, source));
}

void using_uninitialized()
Expand Down
2 changes: 1 addition & 1 deletion src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,7 @@ void object_assignment(struct parser_ctx* ctx,
}
*/

compiler_diagnostic_message(W_ANALYZER_OWNERSHIP_FLOW_MISSING_DTOR,
compiler_diagnostic_message(W_OWNERSHIP_MISSING_OWNER_QUALIFIER,
ctx,
error_position,
"Object must be owner qualified.");
Expand Down
20 changes: 15 additions & 5 deletions src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -2490,14 +2490,24 @@ void discarding_owner()
"void free(void* _Owner ptr);\n"
"\n"
"struct X {\n"
" char *_Owner name;\n"
" char* _Owner name;\n"
"};\n"
"\n"
"int main()\n"
"{ \n"
" struct X * p = (struct X * _Owner) malloc(1);\n"
"}";
assert(compile_with_errors(true, false, source));
"{\n"
" struct X* p = (struct X* _Owner) malloc(1);\n"
"}\n"
"\n"
"void dummy()\n"
"{\n"
"} \n"
"\n"
"//flow analyze\n"
"#pragma cake diagnostic check \"-Wmissing-owner-qualifier\"\n"
"\n"
"";

assert(compile_without_errors(true, false, source));
}

void using_uninitialized()
Expand Down

0 comments on commit 66b07e8

Please sign in to comment.