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

Wrong lift result for nested "for" loops. #169

Open
5c4lar opened this issue Mar 16, 2022 · 2 comments
Open

Wrong lift result for nested "for" loops. #169

5c4lar opened this issue Mar 16, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@5c4lar
Copy link

5c4lar commented Mar 16, 2022

For the following code

#include <stdio.h>
#include <stdlib.h>
void foo() {
    for(int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            printf("%d", i);
        }
    }
}
int main() {
    foo();
    return 0;
}

obtained following result:
image

For this one:

#include <stdio.h>
#include <stdlib.h>
void foo() {
    int ****a = malloc(10 * sizeof(int**));
    for (int i = 0; i < 10; i++) {
        a[i] = malloc(10 * sizeof(int**));
        for(int j = 0; j < 10; j++) {
            a[i][j] = malloc(sizeof(int*));
            *a[i][j] = malloc(sizeof(int));
            **a[i][j] = i;
            printf("%d", **a[i][j]);
        }
    }
}

int main() {
    foo();
    return 0;
}

lli can execute the output file, but the result is wrong
image
also, the function signature of foo is wrong, it has no return value, but in the lifted ir, it returns i8*.

@5c4lar 5c4lar changed the title Wrong lift result for nested for loops. Wrong lift result for nested "for" loops. Mar 16, 2022
@bharadwajy
Copy link
Contributor

Thanks for the bug report. I've reproduced them with the current tip of the repo.

Will look at it.

@bharadwajy bharadwajy added the bug Something isn't working label Mar 26, 2022
@bharadwajy
Copy link
Contributor

Pushed fix for first test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants