Stream: beginners

Topic: Invalid InsertValueInst operands


view this post on Zulip Johan Lindskogen (Jan 05 2024 at 16:37):

I got a crazy error today:

Invalid InsertValueInst operands!
  %set_result = insertvalue { double, i1 } zeroinitializer, float %sub_float, 0, !dbg !1135
Function return type does not match operand type of return inst!
  ret { double, i1 } %set_is_infinite, !dbg !1135
 { float, i1 }

Function "Num_subCheckedLowlevel_f57b151e8a6dfbc520c29ccc134c8fb5357cdd96058ecd185f0787f48b7a6" failed LLVM verification in NON-OPTIMIZED build. Its content was:

define internal fastcc { float, i1 } @Num_subCheckedLowlevel_f57b151e8a6dfbc520c29ccc134c8fb5357cdd96058ecd185f0787f48b7a6(float %"#arg1", float %"#arg2") !dbg !1134 {
entry:
  %sub_float = fsub float %"#arg1", %"#arg2", !dbg !1135
  %call_builtin = call i1 @roc_builtins.num.is_finite.f32(float %sub_float), !dbg !1135
  %negate = xor i1 %call_builtin, true, !dbg !1135
  %set_result = insertvalue { double, i1 } zeroinitializer, float %sub_float, 0, !dbg !1135
  %set_is_infinite = insertvalue { double, i1 } %set_result, i1 %negate, 1, !dbg !1135
  ret { double, i1 } %set_is_infinite, !dbg !1135
}
thread 'main' panicked at '😱 LLVM errors when defining function "Num_subCheckedLowlevel_f57b151e8a6dfbc520c29ccc134c8fb5357cdd96058ecd185f0787f48b7a6"; I wrote the full LLVM IR to "main.ll"', crates/compiler/gen_llvm/src/llvm/build.rs:5805:21

This is a simplified version of my code:

app "test"
    packages {
        pf: "https://github.com/roc-lang/basic-cli/releases/download/0.7.0/bkGby8jb0tmZYsy2hg1E_B2QrCgcSTxdUlHtETwm5m4.tar.br",
    }
    imports [
        pf.Stdout,
    ]
    provides [main] to pf


main =
    _ = List.range { start: At 0, end: Before 11 }
        |> List.map \a ->
            a + 0.5f32

    Stdout.line "done"

I fixed the error by changing a to (Num.toF32 a). I tried searching for the issus but couldn't find an open one with the same message, do you want me to open a new issue?

view this post on Zulip Anton (Jan 05 2024 at 16:40):

Yes please :)

view this post on Zulip Brendan Hansknecht (Jan 05 2024 at 16:43):

Interesting. That would suggest that the code somehow passed type checking.

view this post on Zulip Brendan Hansknecht (Jan 05 2024 at 16:43):

Maybe just a bug in our specification of List.range

view this post on Zulip Johan Lindskogen (Jan 05 2024 at 16:46):

Yea, roc check reports no issues :blush:

view this post on Zulip Johan Lindskogen (Jan 05 2024 at 16:46):

I opened issue #6351 for this


Last updated: Jul 06 2025 at 12:14 UTC