如何解决提取PointerType中包含的值
LLVM IR
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,!dbg !26
%call2 = call i64 @strlen(i8* %arraydecay1) #4,!dbg !28
strlen doc https://www.cplusplus.com/reference/cstring/strlen/
%call2是strlen函数的返回值,它是size_t类型。我认为它是一种struct类型,但事实证明它是一个指针类型,类型为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
调用的返回值strlen
,则其类型为i64
,就像它写在call i64 @strlen(...)
中一样。
i64 (i8*)*
类型是指向接受i8*
并返回i64
的函数的指针。它对应于C语言中&strlen
表达式的类型。
因此,如果要使用strlen
的返回值,则只需使用%call2
的值。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。