Skip to content

Avoid unnecessary temporary variable for initializers #163

@sim642

Description

@sim642

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions