This repository was archived by the owner on Nov 1, 2020. It is now read-only.
[CppCodeGen] Passing reference of structure to native method doesn't work #6408
Open
Description
Following example isn't compiled in cppgen mode:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices;
namespace Hello
{
internal class Program
{
internal struct Structure
{
public string field;
}
[DllImport("libtest", EntryPoint = "func")]
internal static extern int Func(ref Structure s);
private static void Main(string[] args)
{
Structure s;
s.field = "123";
Func(ref s);
}
}
}
$ ./tests/runtest.sh -test Hello
/media/kbaladurin/data/dotnet/forked/corert_1/corert/tests/../Tools/msbuild.sh /ds /m /p:IlcPath=/media/kbaladurin/data/dotnet/forked/corert_1/corert/tests/../bin/Linux.x64.Debug /p:Configuration=Debug /p:Platform=x64 /p:OSGroup=Linux /p:RepoLocalBuild=true /p:FrameworkLibPath=/media/kbaladurin/data/dotnet/forked/corert_1/corert/tests/../bin/Linux.x64.Debug/lib /p:FrameworkObjPath=/media/kbaladurin/data/dotnet/forked/corert_1/corert/tests/../bin/obj/Linux.x64.Debug/Framework /p:NativeCodeGen=cpp /media/kbaladurin/data/dotnet/forked/corert_1/corert/tests/src/Simple/Hello/Hello.csproj
Microsoft (R) Build Engine version 15.8.166+gd4e8d81a88 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
/usr/bin/clang
Generating native code
Assertion Failed
at ILCompiler.DependencyAnalysis.NodeFactory.NecessaryTypeSymbol(TypeDesc type) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/NodeFactory.cs:line 511
at ILCompiler.DependencyAnalysis.EETypeNode.CheckCanGenerateEEType(NodeFactory factory, TypeDesc type) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/EETypeNode.cs:line 1162
at ILCompiler.DependencyAnalysis.EETypeNode..ctor(NodeFactory factory, TypeDesc type) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/EETypeNode.cs:line 79
at ILCompiler.DependencyAnalysis.NodeFactory.<CreateNodeCaches>b__36_0(TypeDesc type) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/NodeFactory.cs:line 175
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at ILCompiler.DependencyAnalysis.NodeFactory.NodeCache`2.GetOrAdd(TKey key) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/NodeFactory.cs:line 150
at ILCompiler.DependencyAnalysis.NodeFactory.NecessaryTypeSymbol(TypeDesc type) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/NodeFactory.cs:line 513
at Internal.IL.ILImporter.AddTypeDependency(TypeDesc type, Boolean constructed) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.CppCodeGen/src/CppCodeGen/ILToCppImporter.cs:line 2704
at Internal.IL.ILImporter.AddTypeReference(TypeDesc type, Boolean constructed) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.CppCodeGen/src/CppCodeGen/ILToCppImporter.cs:line 2683
at Internal.IL.ILImporter.GetSignatureTypeNameAndAddReference(TypeDesc type, Boolean constructed) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.CppCodeGen/src/CppCodeGen/ILToCppImporter.cs:line 2748
at Internal.IL.ILImporter.GetStackValueKindCPPTypeName(StackValueKind kind, TypeDesc type) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.CppCodeGen/src/CppCodeGen/ILToCppImporter.cs:line 240
at Internal.IL.ILImporter.PushTemp(StackEntry entry) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.CppCodeGen/src/CppCodeGen/ILToCppImporter.cs:line 287
at Internal.IL.ILImporter.PushTemp(StackValueKind kind, TypeDesc type) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.CppCodeGen/src/CppCodeGen/ILToCppImporter.cs:line 274
at Internal.IL.ILImporter.ImportAddressOfVar(Int32 index, Boolean argument) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.CppCodeGen/src/CppCodeGen/ILToCppImporter.cs:line 861
at Internal.IL.ILImporter.ImportBasicBlock(BasicBlock basicBlock) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/Common/src/TypeSystem/IL/ILImporter.cs:line 395
at Internal.IL.ILImporter.ImportBasicBlocks() in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/Common/src/TypeSystem/IL/ILImporter.cs:line 327
at Internal.IL.ILImporter.Compile(CppMethodCodeNode methodCodeNodeNeedingCode) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.CppCodeGen/src/CppCodeGen/ILToCppImporter.cs:line 651
at ILCompiler.CppCodeGen.CppWriter.CompileMethod(CppMethodCodeNode methodCodeNodeNeedingCode) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.CppCodeGen/src/CppCodeGen/CppWriter.cs:line 449
at ILCompiler.CppCodegenCompilation.ComputeDependencyNodeDependencies(List`1 obj) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.CppCodeGen/src/Compiler/CppCodegenCompilation.cs:line 58
at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeDependencies(List`1 deferredStaticDependencies) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.DependencyAnalysisFramework/src/DependencyAnalyzer.cs:line 139
at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.DependencyAnalysisFramework/src/DependencyAnalyzer.cs:line 262
at ILCompiler.CppCodegenCompilation.CompileInternal(String outputFile, ObjectDumper dumper) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.CppCodeGen/src/Compiler/CppCodegenCompilation.cs:line 47
at ILCompiler.Compilation.ILCompiler.ICompilation.Compile(String outputFile, ObjectDumper dumper) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler.Compiler/src/Compiler/Compilation.cs:line 333
at ILCompiler.Program.Run(String[] args) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler/src/Program.cs:line 514
at ILCompiler.Program.Main(String[] args) in /media/kbaladurin/data/dotnet/forked/corert_1/corert/src/ILCompiler/src/Program.cs:line 670
Aborted (core dumped)
Compiler crashes when we try to add dependency to [S.P.CompilerGenerated]Internal.CompilerGenerated.__NativeType__Structure&
type.