Skip to content

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

@jkurdek

Description

@jkurdek

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 ();

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Codegen-AOT-monoin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions