-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test with different field access on ambiguous pointer
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// PARAM: --disable sem.unknown_function.spawn --disable sem.unknown_function.invalidate.globals | ||
#include <assert.h> | ||
|
||
struct S1 { | ||
void (*f1)(void); | ||
}; | ||
|
||
struct S2 { | ||
void (*f2)(void); | ||
}; | ||
|
||
void foo() { | ||
assert(1); // reachable | ||
} | ||
|
||
void bar() { | ||
assert(1); // reachable | ||
} | ||
|
||
int main() { | ||
struct S1 s1 = {.f1 = &foo}; | ||
struct S2 s2 = {.f2 = &bar}; | ||
int r; // rand | ||
void *sp; | ||
|
||
if (r) | ||
sp = &s1; | ||
else | ||
sp = &s2; | ||
// simulate imprecision | ||
// in chrony this wouldn't be path-based but joined in the global invariant | ||
|
||
// one of these field accesses is randomly invalid | ||
void (*fp1)(void) = ((struct S1*)sp)->f1; | ||
void (*fp2)(void) = ((struct S2*)sp)->f2; | ||
// but we shouldn't forget &foo and &bar here and consider both dead | ||
fp1(); | ||
fp2(); | ||
return 0; | ||
} |