llvm - 提取 PointerType 中包含的值
问题描述
LLVM 红外
call void @llvm.dbg.declare(metadata i32* %z, metadata !24, metadata !DIExpression()), !dbg !25
%arraydecay1 = getelementptr inbounds [55 x i8], [55 x i8]* %input, i32 0, i32 0, !dbg !26
%call2 = call i64 @strlen(i8* %arraydecay1) #4, !dbg !28
strlen 文档https://www.cplusplus.com/reference/cstring/strlen/
%call2 是 strlen 函数的返回值,它是 size_t 类型。我以为它是结构类型,但结果是指针类型,它是 i64 (i8*)* 类型
我如何取消引用并获取指针值中包含的整数值。
编辑:我使用了错误的操作数,但问题还没有解决。它不是关于指针类型,我有问题的 int 64 类型转换。见下文
CallInst I; //passed by reference
CallSite cs(&I);
if(!cs.getInstruction()){
return;
} else {
for (User* user : cs.getInstruction()->users()) {
if (Instruction* i = dyn_cast<Instruction>(user)) {
Value *v1 = dyn_cast<Value>(i->getOperand(0));
errs() << "Type:==" << *(v1) << "\n";
errs() << "is integer type=" << (v1->getType()->isIntegerTy()) << "\n";
ConstantInt *cint = dyn_cast<ConstantInt>(v1);
if (cint) {
errs() << "constant int" << *cint << "\n";
} else {
errs() << "not a constant int??" << "\n";
}
}
}
}
Type:== %call2 = call i64 @strlen(i8* %arraydecay1) #4, !dbg !28
is integer type=1
not a constant int??
解决方案
如果你说%call2
的是 call 的返回值strlen
,那么它的类型就是i64
它所写的call i64 @strlen(...)
。
i64 (i8*)*
类型是指向接受i8*
和返回的函数的指针i64
。它对应&strlen
于 C 中的表达式类型。
因此,如果您想使用 的返回值strlen
,那么只需使用%call2
value.
推荐阅读
- android - 在 Android 应用程序中寻找 Kotlin 非空断言错误的解释?
- loops - 在 Ansible 中组合多个循环的输出
- c# - 如何转换验证
到成功时为空的字符串? - angular - Angular:保持 observable 活着,直到另一个发生
- javascript - 如何在没有 javascript 的情况下建立在线聊天?
- latex - Tex: wrapfig 包对齐文本的问题
- git - 哪个是处理从 SVN 切换 Git 的多个项目的最佳方式?
- scala - Spark CSV 读取忽略字符
- python - 高效地结合使用 Python 和 C++
- php - PHP MYSQLI AJAX 滚动加载不工作