Skip to content

Commit

Permalink
Add test with different field access on ambiguous pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed May 2, 2022
1 parent 0de1a33 commit ab70c9b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/regression/01-cpa/56-ambig-field.c
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;
}

0 comments on commit ab70c9b

Please sign in to comment.