[llvm-dev] Information Loss of Array Type in Function Interface in IR Generated by Clang

David Blaikie via llvm-dev llvm-dev at lists.llvm.org
Sat Jun 29 22:40:53 PDT 2019


LLVM IR doesn't maintain a lot of information present in the source. What
were you hoping to do with that information? Perhaps you'd be best off
doing something up in clang/using the AST uinstead of LLVM IR?

On Sat, Jun 29, 2019 at 10:36 PM Tingyuan LIANG via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Dear all,
>
>     Hi! Recently, I notice a situation where I cannot infer the size of
> the outermost dimension of array in the function interface.
>     To concretely depict the problem, I show the C source code and the
> generated IR code at the end. The array size of A[] is 51 but this
> information is lost in the generated IR.
>     How can I maintain such information in IR? Should I set some argument
> for Clang so it can do so?
>     The Clang command I used is :
>
>      clang -O1 -emit-llvm -S -g tmp.cc -o tmp.bc
>
>     Thanks in advance for your time and suggestion! ^_^
>
> C source code:
> int f ( int A[51], int x)
> {
>     return A[x];
> }
>
> ===========================
> generated IR:
> ; Function Attrs: norecurse nounwind readonly uwtable
> define dso_local i32 @_Z1fPii(i32* nocapture readonly %A, i32 %x)
> local_unnamed_addr #0 !dbg !7 {
> entry:
>   call void @llvm.dbg.value(metadata i32* %A, metadata !13, metadata
> !DIExpression()), !dbg !15
>   call void @llvm.dbg.value(metadata i32 %x, metadata !14, metadata
> !DIExpression()), !dbg !16
>   %idxprom = sext i32 %x to i64, !dbg !17
>   %arrayidx = getelementptr inbounds i32, i32* %A, i64 %idxprom, !dbg !17
>   %0 = load i32, i32* %arrayidx, align 4, !dbg !17, !tbaa !18
>   ret i32 %0, !dbg !22
> }
>
>
> Best regards,
> ------------------------------------------
> Tingyuan LIANG
> MPhil Student
> Department of Electronic and Computer Engineering
> The Hong Kong University of Science and Technology
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190629/056c7d78/attachment.html>


More information about the llvm-dev mailing list