Bug 6252 - Compiler crashes when structs are used
Summary: Compiler crashes when structs are used
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: Reflection ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-07-24 10:35 UTC by randyficker
Modified: 2012-08-10 18:25 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description randyficker 2012-07-24 10:35:42 UTC
Compiling this C# code with smcs version 2.10.7.0:


struct SomeStruct1
{
       SomeStruct2 One;
       SomeStruct2 Two;
}
struct SomeStruct2
{
}
class SomeClass
{
       SomeStruct1? foo;
}


Gives this error:

* Assertion at ../../../../../mono/mono/metadata/class.c:1740, condition `class->image->dynamic || field->offset > 0' not met


/Users/user/Projects/Empty/Empty/Main.cs(24,21): warning CS0169: The private field `SomeStruct2.One' is never used
/Users/user/Projects/Empty/Empty/Main.cs(25,21): warning CS0169: The private field `SomeStruct2.Two' is never used
/Users/user/Projects/Empty/Empty/Main.cs(32,22): warning CS0169: The private field `SomeClass.foo' is never used
Stacktrace:

  at (wrapper managed-to-native) System.Reflection.Emit.TypeBuilder.create_runtime_class (System.Reflection.Emit.TypeBuilder,System.Reflection.Emit.TypeBuilder) <0xffffffff>
  at System.Reflection.Emit.TypeBuilder.CreateType () <0x0039f>
  at Mono.CSharp.TypeContainer.CloseType () <0x0019b>
  at Mono.CSharp.ModuleContainer.CloseType () <0x00080>
  at Mono.CSharp.Driver.Compile () <0x0047e>
  at Mono.CSharp.Driver.Main (string[]) <0x000af>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_int_object (object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

        0   mono                                0x000e1653 mono + 919123
        1   mono                                0x00155ccd mono + 1395917
        2   libsystem_c.dylib                   0x9355a59b _sigtramp + 43
        3   ???                                 0xffffffff 0x0 + 4294967295
        4   libsystem_c.dylib                   0x934f5bdd abort + 167
        5   mono                                0x002cd703 mono + 2934531
        6   mono                                0x002cd7b6 mono + 2934710
        7   mono                                0x0016bb4c mono + 1485644
        8   mono                                0x0016b321 mono + 1483553
        9   mono                                0x00174304 mono + 1520388
        10  mono                                0x0016b3d0 mono + 1483728
        11  mono                                0x0016b5bf mono + 1484223
        12  mono                                0x00255ba8 mono + 2444200
        13  mono                                0x00256db6 mono + 2448822
        14  ???                                 0x017fd6dc 0x0 + 25155292
        15  ???                                 0x017fcd78 0x0 + 25152888
        16  ???                                 0x017fc6fc 0x0 + 25151228
        17  ???                                 0x017fc3b9 0x0 + 25150393
        18  ???                                 0x007b1cef 0x0 + 8068335
        19  ???                                 0x0067cda8 0x0 + 6802856
        20  ???                                 0x0067d1a6 0x0 + 6803878
        21  mono                                0x00010c1f mono + 64543
        22  mono                                0x00223afa mono + 2239226
        23  mono                                0x002267dc mono + 2250716
        24  mono                                0x00225a41 mono + 2247233
        25  mono                                0x000ac8bf mono + 702655
        26  mono                                0x000acb10 mono + 703248
        27  mono                                0x000aef7f mono + 712575
        28  mono                                0x000021a4 mono + 4516
        29  mono                                0x00002238 mono + 4664
        30  mono                                0x00001f55 mono + 3925

Debug info from gdb:

/tmp/mono-gdb-commands.JDZu0K:1: Error in sourced command file:
Unable to attach to process-id 16404: No child processes (10)
Attaching to process 16404.

=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

/Developer/MonoTouch/usr/bin/smcs: line 3: 16404 Abort trap: 6           MONO_PATH=/Developer/MonoTouch/usr/lib/mono/2.1 /Developer/MonoTouch/usr/bin/mono /Developer/MonoTouch/usr/lib/mono/2.1/smcs.exe "$@"
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-07-24 11:36:04 UTC
Can you reorder your code so that SomeStruct2 comes before SomeStruct1? That makes it compile for me.
Comment 2 Rolf Bjarne Kvinge [MSFT] 2012-07-24 11:37:11 UTC
Also: this does not crash neither with 2.10 nor with master, only smcs.
Comment 3 randyficker 2012-07-24 11:54:53 UTC
Re-arranging the structs does seem to work around the issue.  At first I didn't think this would help me, as in my real project these are all different types in different files, and didn't have an order.

Then I realized that if I manually edit my .csproj file, I can re-order the sequence in which the files are mentioned, which has the same effect.  After playing with this for a while, I eventually found a sequence that allows my project to build.
Comment 4 Rolf Bjarne Kvinge [MSFT] 2012-08-10 18:25:57 UTC
This has been fixed in mono 2.12 - and it will be fixed in MonoTouch when we switch from mono 2.10 to 2.12 (which should happen later this year).

In the meantime there is a trivial workaround (please reopen this case if this assumption changes).