我使用 Clang 3.3 编译了 MUSL C 库,并转储了生成的 LLVM IR 文件。我发现 FILE 结构

struct __FILE_s {
    unsigned flags;
    unsigned char *rpos, *rend;
    int (*close)(FILE *);
    unsigned char *wend, *wpos;
    unsigned char *mustbezero_1;
    unsigned char *wbase;
    size_t (*read)(FILE *, unsigned char *, size_t);
    size_t (*write)(FILE *, const unsigned char *, size_t);
    off_t (*seek)(FILE *, off_t, int);
    unsigned char *buf;
    size_t buf_size;
    FILE *prev, *next;
    int fd;
    int pipe_pid;
    long lockcount;
    short dummy3;
    signed char mode;
    signed char lbf;
    int lock;
    int waiters;
    void *cookie;
    off_t off;
    char *getln_buf;
    void *mustbezero_2;
    unsigned char *shend;
    off_t shlim, shcnt;
};

被编译为
%struct.__FILE_s = type { i32, i8*, i8*,
i32 (%struct.__FILE_s*)*, i8*, i8*, i8*, i8*,
i64 (%struct.__FILE_s*, i8*, i64)*,
i64 (%struct.__FILE_s*, i8*, i64)*,
i64 (%struct.__FILE_s*, i64, i32)*,
i8*, i64, %struct.__FILE_s*, %struct.__FILE_s*,
i32, i32, i64, i16, i8, i8, i32, i32, i8*,
i64, i8*, i8*, i8*, i64, i64 }

在一些 IR 文件中,但被编译为
%struct.__FILE_s = type { i32, i8*, i8*,
i32 (%struct.__FILE_s*)*, i8*, i8*, i8*, i8*,
i64 (%struct.__FILE_s*, i8*, i64)*,
{}*,
i64 (%struct.__FILE_s*, i64, i32)*,
i8*, i64, %struct.__FILE_s*, %struct.__FILE_s*,
i32, i32, i64, i16, i8, i8, i32, i32, i8*,
i64, i8*, i8*, i8*, i64, i64 }

在其他源文件中。这两个 IR 结构之间的唯一区别是第一种形式中的函数指针类型字段被替换为 {}* 而不是其完整类型。谁能告诉我为什么会发生这种情况以及如何禁用 {}* 替换?

最佳答案

a known bug in Clang

但是,除了自己构建 Clang 和应用 the patch discussed at that bug 之外,我不知道如何解决它(但请注意,未提交补丁是有原因的)。

关于c - 为什么 LLVM IR 结构中的函数指针字段被 {}* 替换?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18730620/

10-13 08:44