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

Avoid unnecessary temporary variable for initializers #163

Open
sim642 opened this issue Jan 24, 2024 · 0 comments
Open

Avoid unnecessary temporary variable for initializers #163

sim642 opened this issue Jan 24, 2024 · 0 comments

Comments

@sim642
Copy link
Member

sim642 commented Jan 24, 2024

CIL transforms

int foo() {
  return 42;
}

int main() {
  int x = foo();
  int y;
  y = foo();
  return 0;
}

into

int foo(void) 
{ 
  {
  return (42);
}
}

int main(void) 
{ 
  int x ;
  int tmp ;
  int y ;
  {
  tmp = foo();
  x = tmp;
  y = foo();
  return (0);
}
}

For x a temporary variable tmp is added, which is extra clutter compared to the equivalent code for y.
The temporary might be needed in general for initializers, but we should find a way to avoid it in such simple cases because this is counterproductive: writing neater code (e.g. for Goblint tests) causes uglier CIL output (and CFGs). To get more compact Goblint representations, one has to explicitly split initializers into assignments.

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

No branches or pull requests

1 participant