array[5] = 20;
Run Code Online (Sandbox Code Playgroud)
等效 LLVM IR
%arrayidx = getelementptr inbounds i32, i32* %2, i64 5
store i32 20, i32* %arrayidx, align 4
Run Code Online (Sandbox Code Playgroud)
如何从 LLVM IR 中提取 5 ?
如果您有 a GetElementPtrInst* GEP,则可以使用访问索引GEP->getOperand(i)(操作数 0 是指针,其余操作数是索引)。要获取值 5,您可以检查索引是否为 a ConstantInt,如果是,则获取其值,如下所示:
if (ConstantInt *CI = dyn_cast<ConstantInt>(GEP->getOperand(1)) {
uint64_t Idx = CI->getZExtValue();
}
Run Code Online (Sandbox Code Playgroud)