Home > Software engineering >  How to correctly access a non-constant index in an LLVM array?
How to correctly access a non-constant index in an LLVM array?

Time:01-31

I've been trying to tackle arrays in LLVM, but I am not able to access elements at a non-constant index. Constant indexing works correctly. When I run my program, it just immediately exits. In my specific example, I am trying to use a for loop to set the elements for 0 to 5 to their respective value. This is what LLVM outputs (with optimizations disabled):

Read function definition:define double @main() {
entry:
  %i = alloca double, align 8
  %test = alloca [100 x double]*, align 8
  store double 0.000000e 00, [100 x double]* %test, align 8
  store double 0.000000e 00, double %i, align 8
  br label %loop

loop:                                             ; preds = %latch, %entry
  %i1 = phi double [ 0.000000e 00, %entry ], [ %nextvar, %latch ]
  %i2 = load double, double %i, align 8
  %cmptmp = fcmp ult double %i2, 5.000000e 00
  %booltmp = uitofp i1 %cmptmp to double
  %loopcond = fcmp one double %booltmp, 0.000000e 00
  br i1 %loopcond, label %body, label            
  •  Tags:  
  • Related