Extracting value contained in PointerType

Viewed 151

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, i32 0, !dbg !26
  %call2 = call i64 @strlen(i8* %arraydecay1) #4, !dbg !28

strlen doc https://www.cplusplus.com/reference/cstring/strlen/

%call2 is the return value of strlen function which is of size_t type. I thought its a struct type but it turned out to be a pointer type, which is of type i64 (i8*)*

How do i de-reference and get the integer value contained in the pointer value.

Edit: I was using wrong operand but the problem is not solved yet. Its not about pointer type, int 64 type conversion that i have issues. See below

 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??
1 Answers

If you are talking about %call2, the return value of strlen call, then its type is i64 as it is written in call i64 @strlen(...).

The i64 (i8*)* type is a pointer to a function that accepts i8* and returns i64. It corresponds to the type of &strlen expression in C.

So, if you want to work with the return value of strlen, then just use %call2 value.

Related