Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MonoAOT] [x64] Return non-void in Function of void return type #106259

Closed
jkurdek opened this issue Aug 12, 2024 · 2 comments · Fixed by #106013
Closed

[MonoAOT] [x64] Return non-void in Function of void return type #106259

jkurdek opened this issue Aug 12, 2024 · 2 comments · Fixed by #106013
Labels
area-Codegen-AOT-mono in-pr There is an active PR which will close this issue when it is merged

Comments

@jkurdek
Copy link
Member

jkurdek commented Aug 12, 2024

Found while fixing #103628

Found return instr that returns non-void in Function of void return type!
  ret void undef, !dbg !23
 void

Mono IR:

*** Unoptimized LLVM IR for HelloWorld.Program:GetS1 () ***
define hidden monocc void @HelloWorld_Program_GetS1() #2 !dbg !4 {
BB0:
  %vreg_loc_19 = alloca %S1, align 1, !dbg !8
  %vreg_loc_16 = alloca %S1, align 1, !dbg !8
  %ret_buf = alloca ptr, align 8, !dbg !8
  br label %INIT_BB1, !dbg !8

INIT_BB1:                                         ; preds = %BB0
  br label %INITED_BB2, !dbg !8

INITED_BB2:                                       ; preds = %INIT_BB1
  br label %BB2, !dbg !8

BB2:                                              ; preds = %INITED_BB2
  call void @llvm.memset.p0.i32(ptr %vreg_loc_19, i8 0, i32 0, i1 false), !dbg !9
  br label %BB1, !dbg !9

BB1:                                              ; preds = %BB2
  call void @llvm.memset.p0.i32(ptr %ret_buf, i8 0, i32 ptrtoint (ptr getelementptr (void, ptr null, i32 1) to i32), i1 false), !dbg !8
  call void @llvm.memcpy.p0.p0.i32(ptr %ret_buf, ptr %vreg_loc_19, i32 0, i1 false), !dbg !8
  ret void undef, !dbg !8
}

***

Steps to reproduce:

Build the following program with mono aot:

using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential)]
public struct S1
{
}

namespace HelloWorld
{
    internal class Program
    {
        public static S1 GetS1() => new S1();
        private static void Main(string[] args)
        {
            S1 s1 = GetS1();
        }
    }
}

Error is most likely caused by wrong logic here

ret_type = LLVMVoidType ();

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Aug 12, 2024
@steveisok
Copy link
Member

Would LLVMStructType(NULL, 0, FALSE) fix it?

@jkurdek
Copy link
Member Author

jkurdek commented Aug 13, 2024

This look very hopeful. Thanks Steve! Added it to: #106013

@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Aug 13, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Aug 14, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Sep 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Codegen-AOT-mono in-pr There is an active PR which will close this issue when it is merged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants