Skip to content

Commit

Permalink
Don't create a cycle when translating IL break to IR. (mono/mono#14980
Browse files Browse the repository at this point in the history
)

Don't create a cycle when translating IL `break` to IR.

`mono_emit_jit_icall` adds the instruction it generates to the current
basic block, and the redundant use of `MONO_ADD_INS` on an instruction
that has already been added to a BB will create a cycle in the `prev`
link chain.

Fixes mono/mono#9706.


Commit migrated from mono/mono@e6e9d5f
  • Loading branch information
imhameed authored and monojenkins committed Jun 13, 2019
1 parent c0eb0ff commit c2c7d82
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/mono/mono/mini/method-to-ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -6539,8 +6539,8 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
ins = mono_emit_jit_icall (cfg, mono_debugger_agent_user_break, NULL);
} else {
MONO_INST_NEW (cfg, ins, OP_NOP);
MONO_ADD_INS (cfg->cbb, ins);
}
MONO_ADD_INS (cfg->cbb, ins);
break;
case MONO_CEE_LDARG_0:
case MONO_CEE_LDARG_1:
Expand Down
3 changes: 2 additions & 1 deletion src/mono/mono/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,8 @@ TESTS_IL_SRC= \
custom-modifiers-append.1.il \
gh-13056_mono_local_cprop_av.il \
gh-13057_mono_local_emulate_ops_av.il \
module-cctor-entrypoint.il
module-cctor-entrypoint.il \
bug-gh-9706.il

# This test crashes the runtime, even with recent fixes.
# incorrect-ldvirtftn-read-behind-for-dup.il
Expand Down
46 changes: 46 additions & 0 deletions src/mono/mono/tests/bug-gh-9706.il
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.assembly extern mscorlib { }

.assembly test
{
.hash algorithm 0x00008004
.ver 0:0:0:0
}

.class private auto ansi beforefieldinit test.Test extends [mscorlib]System.Object
{
.field private static int32 modreq([mscorlib]System.Runtime.CompilerServices.IsVolatile) non_constant

.method private hidebysig specialname rtspecialname static void '.cctor' () cil managed
{
.maxstack 8
ldc.i4.0
volatile.
stsfld int32 modreq([mscorlib]System.Runtime.CompilerServices.IsVolatile) test.Test::non_constant
ret
}

.method public specialname rtspecialname instance default void '.ctor' () cil managed
{
.maxstack 8
ldarg.0
call instance void object::'.ctor'()
ret
}

// If this test succeeds, it should run to completion.
// If it fails, mono will hang in an infinite loop while doing DCE.
.method public static hidebysig default void Main () cil managed
{
.maxstack 8
.entrypoint
volatile.
ldsfld int32 modreq([mscorlib]System.Runtime.CompilerServices.IsVolatile) test.Test::non_constant
ldc.i4.0
cgt
brfalse.s end
break // Should not be executed; merely needs to be present in the instruction stream.
end:
ret
}
}

0 comments on commit c2c7d82

Please sign in to comment.