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

memcpy Merges Regions Unnecessarily #749

Open
shaobo-he opened this issue Aug 12, 2021 · 1 comment
Open

memcpy Merges Regions Unnecessarily #749

shaobo-he opened this issue Aug 12, 2021 · 1 comment

Comments

@shaobo-he
Copy link
Contributor

shaobo-he commented Aug 12, 2021

Consider the following program,

typedef struct {
  int* x;
  int y;
} ST;

int main(void) {
  ST a, b;
  b.x = (int*)malloc(sizeof(int));
  *b.x = 1;
  memcpy(&a, &b, sizeof(ST));
  //a.x = b.x;
  //a.y = b.y;
  return *a.x;
}

a and b point to the same node. Converting them into assignments avoids this effect. This is because sea-dsa unifies the nodes pointed by memcpy's source and destination arguments if the element types contain pointers.

SeaHorn has a memcpy rewritten pass (https://github.com/seahorn/seahorn/blob/dev10/lib/Transforms/Scalar/PromoteMemcpy.cc), which we can borrow to avoid this issue.

@shaobo-he
Copy link
Contributor Author

shaobo-he commented Aug 31, 2021

After reading the sea-dsa paper, I think I have a better understanding of this. The consequence of memcpy on this example is not that bad because unifying the nodes does not collapse them. However, copying a structure into a byte array could cause node collapse, which further spreads all over the program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant