Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-add pointer dec tests #73

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/example-archive/c-testsuite/broken/error-proof/00073.err1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
cn: internal error, uncaught exception:
Failure("todo")
*/
// Cause: `-=` assignment operator

int
main()
{
int arr[2];
int *p;

p = &arr[1];
p -= 1;
*p = 123;

if(arr[0] != 123)
return 1;
return 0;
}
35 changes: 35 additions & 0 deletions src/example-archive/c-testsuite/working/00032.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Crash: caused by pointer decrement

int
main()
/*@ ensures return == 0i32; @*/
{
int arr[2];
int *p;

/*@ extract Block<int>, 0u64; @*/
arr[0] = 2;
/*@ extract Block<int>, 1u64; @*/
arr[1] = 3;
p = &arr[0];
if(*(p++) != 2)
return 1;
if(*(p++) != 3)
return 2;

p = &arr[1];
if(*(p--) != 3)
return 1;
if(*(p--) != 2)
return 2;

p = &arr[0];
if(*(++p) != 3)
return 1;

p = &arr[1];
if(*(--p) != 2) // <-- cause of the crash
return 1;

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Crash

void
pointerdec_crash_3()
{
int arr[2];
int *p = &arr[1];
*(--p);
}
5 changes: 5 additions & 0 deletions src/example-archive/simple-examples/working/pointer_dec1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
int a;
void b() {
int *c = &a;
c -= 1;
}
7 changes: 7 additions & 0 deletions src/example-archive/simple-examples/working/pointer_dec2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Derived from src/example-archive/c-testsuite/broken/error-proof/00032.err1.c

int a;
void b() {
int *c = &a;
--c;
}