[llvm-dev] Help to understand LoadValueFromMemory

Alberto Barbaro via llvm-dev llvm-dev at lists.llvm.org
Wed Jul 17 12:44:15 PDT 2019


Hi all,
sorry I forgot to mention that I understood that the LoadValueFromMemory
would execute only:

case Type::PointerTyID:
    Result.PointerVal = *((PointerTy*)Ptr);
    break;

I think this should not be the case considering that Type I think is a
Vector.

Thanks

Il giorno mer 17 lug 2019 alle ore 20:41 Alberto Barbaro <
barbaro.alberto at gmail.com> ha scritto:

> Hi all,
> I'm trying to print to screen the value read by the fread function. I'm at
> the point where source refers to the GetElementPtrInst ( pointer to the
> buffer where fread stored the data - %5 in my case ) and the fread() has
> been already called.
>
> I thought the correct approach to achieve what I need was:
>
> ExecutionContext& SF = ECStack.back();
>    GenericValue SRC = getOperandValue(source, SF);
>    GenericValue* Ptr = (GenericValue*)GVTOP(SRC);
>    GenericValue Result;
>
> source->getPointerOperand()->getType()->dump(); //[40 x i8]*
>
> LoadValueFromMemory(Result, Ptr, source->getPointerOperand()->getType());
>
> and use Result.PointerVal ...
>
> In the end I have the first 4 bytes within Result.PointrVal but I cannot
> see the other bytes.. Unfortunately also Result.AggregateVal has size 0.
>
> Could you help me to understand why please?
>
> The core part of the .ll is the following:
>
> define i32 @main() #0 {
>   %1 = alloca i32, align 4
>   %2 = alloca %struct._IO_FILE*, align 8
>   %3 = alloca [40 x i8], align 16
>   store i32 0, i32* %1, align 4
>   %4 = call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([51 x
> i8], [51 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8],
> [3 x i8]* @.str.1, i32 0, i32 0))
>   store %struct._IO_FILE* %4, %struct._IO_FILE** %2, align 8
>  * %5 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i32 0, i32 0*
>   %6 = load %struct._IO_FILE*, %struct._IO_FILE** %2, align 8
>   *%7 = call i64 @fread(i8* %5, i64 30, i64 1, %struct._IO_FILE* %6)*
>   %8 = load %struct._IO_FILE*, %struct._IO_FILE** %2, align 8
>   %9 = call i32 @fclose(%struct._IO_FILE* %8)
>   %10 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
>   %11 = load i8, i8* %10, align 16
>   %12 = sext i8 %11 to i32
>   %13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8],
> [9 x i8]* @.str.2, i32 0, i32 0), i32 %12)
>   %14 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
>   %15 = load i8, i8* %14, align 16
>   %16 = sext i8 %15 to i32
>   ret i32 %16
> }
>
> Thanks
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190717/f251288e/attachment-0001.html>


More information about the llvm-dev mailing list