【发布时间】:2016-10-30 02:02:18
【问题描述】:
我想获得嵌套结构/数组数据类型的确切字节表示。例如下面的 C 结构体:
typedef struct zTy {
int x;
char c[2];
struct { char d; } v;
} z;
它被转换为以下 LLVM IR:
%struct.zTy = type { i32, [2 x i8], %struct.anon }
%struct.anon = type { i8 }
%a = alloca %struct.zTy, align 4
从 alloca 指令可以看到对齐(4 字节)。但我不知道在哪里插入对齐或如何计算嵌套结构的对齐。 我使用 getTypeAllocSize() 获得目标三元组的结构的总大小:
AllocaInst* AI;
Module &M;
Type* T = AI->getAllocatedType();
int size = M.getDataLayout()->getTypeAllocSize(T) // 8 Byte
有没有办法通过 LLVM 通道确定目标架构的任意嵌套数据类型的确切布局?
【问题讨论】:
标签: struct alignment llvm llvm-c++-api