microsoft / llvm-mctoll

llvm-mctoll
Other
806 stars 123 forks source link

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

Open 5c4lar opened 2 years ago

5c4lar commented 2 years ago

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*.

bharadwajy commented 2 years ago

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

Will look at it.

bharadwajy commented 2 years ago

Pushed fix for first test.