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

Tingyuan LIANG via llvm-dev llvm-dev at lists.llvm.org
Sat Jun 29 22:36:02 PDT 2019

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 {
  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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190630/c228ad67/attachment.html>

More information about the llvm-dev mailing list