【发布时间】:2020-09-08 19:59:57
【问题描述】:
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??
【问题讨论】:
-
如果你有指针value,你会得到使用
LoadInst指向的值。如果您只有指针type,则无法获取该值。在最高 9 的 LLVM 版本上,您可以通过调用 PointerType::getElementType() 来获取type。 -
getElementType 返回 i64 (i8*)*,如何取消引用?
标签: llvm llvm-ir llvm-c++-api