Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Enumerated arrays with procedures in structs cause LLVM IR failure.

Open sduman opened this issue 3 years ago • 1 comments

Context

When trying to assign procedures into enumerated arrays, an LLVM IR dump is printed to the console with some kind of "invalid bitcast" error.

    Odin: dev-2022-01:c9bc7596
    OS:   Windows 10 17763.2029
    CPU:  AMD Ryzen 5 1600 Six-Core Processor
    RAM:  16335 MiB

Steps to Reproduce

Prop :: enum {
  Disabled,
  Selected,
}

Item :: struct {
  properties: Properties,
  callbacks: Change_Callbacks,
}

Properties :: bit_set[Prop]
Callback :: #type proc(item: ^Item)
Change_Callbacks :: [Prop]Callback

m := struct {
    cb: Change_Callbacks,
}{}

main :: proc() {
    a := Change_Callbacks {
        .Disabled = proc(item: ^Item) {
            return
            },
        }
    m.cb = a
}

Failure Logs

LLVM CODE GEN FAILED FOR PROCEDURE: scratch.main
define internal void @scratch.main(i8* noalias nocapture nonnull %__.context_ptr) {
decls:
  %0 = alloca [2 x void (%scratch.Item*, i8*)*], align 8
  %1 = alloca [2 x void (%scratch.Item*, i8*)*], align 8
  br label %entry

entry:                                            ; preds = %decls
  %2 = bitcast i8* %__.context_ptr to %runtime.Context*
  %3 = bitcast [2 x void (%scratch.Item*, i8*)*]* %0 to i8*
  call void @llvm.memset.p0i8.i64(i8* %3, i8 0, i64 16, i1 false)
  %4 = bitcast [2 x void (%scratch.Item*, i8*)*]* %1 to i8*
  call void @llvm.memset.p0i8.i64(i8* %4, i8 0, i64 16, i1 false)
  store [2 x void (%scratch.Item*, i8*)*] zeroinitializer, [2 x void (%scratch.Item*, i8*)*]* %1, align 8
  %5 = getelementptr [2 x void (%scratch.Item*, i8*)*], [2 x void (%scratch.Item*, i8*)*]* %1, i64 0, i64 0
  store void (%scratch.Item*, i8*)* @"scratch.main$anon-1", void (%scratch.Item*, i8*)** %5, align 8
  %6 = load [2 x void (%scratch.Item*, i8*)*], [2 x void (%scratch.Item*, i8*)*]* %1, align 8
  store [2 x void (%scratch.Item*, i8*)*] %6, [2 x void (%scratch.Item*, i8*)*]* %0, align 8
  %7 = load [2 x void (%scratch.Item*, i8*)*], [2 x void (%scratch.Item*, i8*)*]* %0, align 8
  %8 = bitcast [2 x void (%scratch.Item*, i8*)*] %7 to [2 x i8*]
  store [2 x i8*] %8, [2 x i8*]* getelementptr inbounds ({ [2 x i8*] }, { [2 x i8*] }* @scratch.m, i64 0, i32 0), align 8
  ret void
}

Invalid bitcast
  %8 = bitcast [2 x void (%scratch.Item*, i8*)*] %7 to [2 x i8*]

sduman avatar Jan 19 '22 00:01 sduman

Hello!

I am marking this issue as stale as it has not received any engagement from the community or maintainers 120 days. That does not imply that the issue has no merit! If you feel strongly about this issue

  • open a PR referencing and resolving the issue;
  • leave a comment on it and discuss ideas how you could contribute towards resolving it;
  • leave a comment and describe in detail why this issue is critical for your use case;
  • open a new issue with updated details and a plan on resolving the issue.

The motivation for this automation is to help prioritize issues in the backlog and not ignore, reject, or belittle anyone..

github-actions[bot] avatar Jul 24 '22 22:07 github-actions[bot]