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

Fix infinite loop with self-referential global struct #403

Merged

Conversation

ekilmer
Copy link
Contributor

@ekilmer ekilmer commented Nov 14, 2023

The fix allows the following program to be lifted.

// gcc -O0 -g -gdwarf-4 self_refer.c -o self_refer

#include <stdio.h>

struct foo {
  int num;
  struct foo	*foo_next;
};

static struct foo foo0 = {
  .num = 3,
  .foo_next = &foo0
};

int main() {
  printf("Num: %d\n", foo0.foo_next->num);
}

This can be repeated with the following program

```c
// gcc -O0 -g -gdwarf-4 self_refer.c -o self_refer

\#include <stdio.h>

struct foo {
  int num;
  struct foo	*foo_next;
};

static struct foo foo0 = {
  .num = 3,
  .foo_next = &foo0
};

int main() {
  printf("Num: %d\n", foo0.foo_next->num);
}
```
@ekilmer ekilmer marked this pull request as ready for review November 14, 2023 20:15
@ekilmer ekilmer requested a review from Ninja3047 November 14, 2023 20:15
Copy link
Contributor

@Ninja3047 Ninja3047 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like a reasonable fix to me

@ekilmer ekilmer requested a review from 2over12 November 14, 2023 21:46
Copy link
Collaborator

@2over12 2over12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ekilmer ekilmer merged commit d569305 into patchable-ir-main Nov 17, 2023
6 checks passed
@ekilmer ekilmer deleted the ekilmer/fix-infinite-recursion-self-refer-global branch November 17, 2023 16:26
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

Successfully merging this pull request may close these issues.

3 participants