Skip to content

Wrong value when passing "struct stat" as a parameter to a function #37

@xjtuwxg

Description

@xjtuwxg

Problem description

Hi I got this simple test file when debugging the issue 36:

#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>       // struct stat
#include <fcntl.h>          // O_RDONLY

void print_stat(struct stat sbuf)
//void print_stat(struct stat *sbuf)
{
    printf(">> stat sbuf.st_mode: 0x%x\n", sbuf.st_mode);
    //printf("stat sbuf.st_mode: 0x%x\n", sbuf->st_mode);
}

int main(int argc, char *argv[])
{
    struct stat sbuf;
    int fd = open("fstat.c", O_RDONLY, 0);
    if (fd < 0) {
        printf("error");
        return 1;
    }
    fstat(fd, &sbuf);
    printf("stat sbuf.st_mode: 0x%x\n", sbuf.st_mode);
    printf("sizeof(struct stat): %lu, %lu\n", sizeof(sbuf), sizeof(struct stat));
    print_stat(sbuf);
    //print_stat(&sbuf);
    close(fd);
    return 0;
}

For some reason, it has the following results (the value of st_mode is changed):

$ ./2_x86-64
stat sbuf.st_mode: 0x81a4
sizeof(struct stat): 128, 128
>> stat sbuf.st_mode: 0x3a297461

Environment

popcorn-compiler: from commit 4ffd16e, patched with the code from issue 36.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions