Odin icon indicating copy to clipboard operation
Odin copied to clipboard

LLVM code gen fails for @(deferred_out/in_out) procedures in ternaries.

Open elusivePorpoise opened this issue 3 years ago • 3 comments

Context

Odin: dev-2022-01-nightly:fb86c23d OS: Windows 10 Home Basic (version: 20H2), build 19042.1466

Expected Behavior

Don't fail.

Current Behavior

Fails.

Failure Information (for bugs)

This bug also applies to for-loop post statements.

Steps to Reproduce

Test :: proc(i: int){
  fmt.println("in Test");
}
@(deferred_out=Test)
TestThese :: proc()->int{
  fmt.println("In TestThese");
  return 3;
}
main :: proc(){
    if true{
        oof := TestThese() if true else 0;
    }
}

Failure Logs

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

entry:                                            ; preds = %decls
  %5 = bitcast i8* %__.context_ptr to %runtime.Context*
  br label %if.then

if.then:                                          ; preds = %entry
  store i64 0, i64* %0, align 8
  br i1 true, label %if.then1, label %if.else

if.then1:                                         ; preds = %if.then
  %6 = bitcast %runtime.Context* %5 to i8*
  %7 = call i64 @main.TestThese(i8* %6)
  br label %if.done

if.else:                                          ; preds = %if.then
  br label %if.done

if.done:                                          ; preds = %if.else, %if.then1
  %8 = phi i64 [ %7, %if.then1 ], [ 0, %if.else ]
  store i64 %8, i64* %0, align 8
  %9 = load i64, i64* %0, align 8
  %10 = bitcast %..any* %1 to i8*
  call void @llvm.memset.p0i8.i64(i8* %10, i8 0, i64 16, i1 false)
  %11 = bitcast i64* %0 to i8*
  %12 = getelementptr inbounds %..any, %..any* %1, i32 0, i32 0
  %13 = getelementptr inbounds %..any, %..any* %1, i32 0, i32 1
  store i8* %11, i8** %12, align 8
  store i64 4683743612465315841, i64* %13, align 8
  %14 = load %..any, %..any* %1, align 8
  %15 = bitcast { %..any*, i64 }* %2 to i8*
  call void @llvm.memset.p0i8.i64(i8* %15, i8 0, i64 16, i1 false)
  %16 = bitcast [1 x %..any]* %3 to i8*
  call void @llvm.memset.p0i8.i64(i8* %16, i8 0, i64 16, i1 false)
  %17 = getelementptr [1 x %..any], [1 x %..any]* %3, i64 0, i64 0
  store %..any %14, %..any* %17, align 8
  %18 = getelementptr [1 x %..any], [1 x %..any]* %3, i64 0, i64 0
  %19 = getelementptr inbounds { %..any*, i64 }, { %..any*, i64 }* %2, i32 0, i32 0
  store %..any* %18, %..any** %19, align 8
  %20 = getelementptr inbounds { %..any*, i64 }, { %..any*, i64 }* %2, i32 0, i32 1
  store i64 1, i64* %20, align 8
  %21 = load { %..any*, i64 }, { %..any*, i64 }* %2, align 8
  store %..string { i8* getelementptr inbounds ([2 x i8], [2 x i8]* @"csbs$7c", i64 0, i64 0), i64 1 }, %..string* %4, align 8
  %22 = bitcast %runtime.Context* %5 to i8*
  %23 = call i64 @fmt.println({ %..any*, i64 }* %2, %..string* %4, i8* %22)
  br label %defer

defer:                                            ; preds = %if.done
  %24 = bitcast %runtime.Context* %5 to i8*
  call void @main.Test(i64 %7, i8* %24)
  br label %if.done2

if.done2:                                         ; preds = %defer
  ret void
}




Instruction does not dominate all uses!
  %7 = call i64 @main.TestThese(i8* %6)
  call void @main.Test(i64 %7, i8* %24)

elusivePorpoise avatar Jan 26 '22 06:01 elusivePorpoise

"This bug also applies to for-loop post statements." <- This also affects procs with @(deferred_in).

elusivePorpoise avatar Jan 26 '22 06:01 elusivePorpoise

On a somewhat related note, @(deferred_in_out=foo) does not have an error message when foo has 0 parameters.

elusivePorpoise avatar Jan 26 '22 06:01 elusivePorpoise

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]