Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lewurm
Copy link
Contributor

@lewurm lewurm commented Oct 31, 2019

Fixes:

$ ./mono/mini/mono-sgen --interp=-all ./mono/mini/iltests.exe

This is the problematic trace:

(0x103e90130) Tests:i8_ptr_arithm_x64 -> IR_004e: ldc.i4.5        0:
(0x103e90130) Tests:i8_ptr_arithm_x64 -> IR_004f: ldc.i8     1229801703532086340  0:[0x5 (5)]
(0x103e90130) Tests:i8_ptr_arithm_x64 -> IR_0054: ldc.i4     -65536       0:[0x5 (5)] [0x1111222233334444 (1229801703532086340)]
(0x103e90130) Tests:i8_ptr_arithm_x64 -> IR_0057: call       2    0:[0x5 (5)] [0x1111222233334444 (1229801703532086340)] [0xffff0000 (4294901760)]
  (0x103e90130) Entering Tests:and_ptr_i8 ([0x1111222233334444] [{long} 4294901760/0xffff0000] )
  (0x103e90130) Tests:and_ptr_i8 -> IR_0000: safepoint    0:
  (0x103e90130) Tests:and_ptr_i8 -> IR_0001: ldarg.p0     0:
  (0x103e90130) Tests:and_ptr_i8 -> IR_0002: ldarg.i8   1 0:[0x1111222233334444 (1229801703532086340)]
  (0x103e90130) Tests:and_ptr_i8 -> IR_0004: and.i8       0:[0x1111222233334444 (1229801703532086340)] [0xffff0000 (4294901760)]
  (0x103e90130) Tests:and_ptr_i8 -> IR_0005: ret          0:[0x33330000 (858980352)]
  (0x103e90130) Leaving Tests:and_ptr_i8 => [{long} 858980352/0x33330000]
(0x103e90130) Tests:i8_ptr_arithm_x64 -> IR_0059: ldc.i8     1229801703532068864  0:[0x5 (5)] [0x33330000 (858980352)]

and_ptr_i8 expects a ptr and i8 on the stack. In the default configuration the interpreter inlines and_ptr_i8 and thus stores the arguments into some locals:

for (i = signature->param_count - 1; i >= 0; i--) {
local = create_interp_local (td, signature->params [i]);
arg_locals [i + !!signature->hasthis] = local;
store_local (td, local);
}

where store_local will take care of a proper i4->i8 conversion:

#if SIZEOF_VOID_P == 8
if (td->sp [-1].type == STACK_TYPE_I4 && stack_type [mt] == STACK_TYPE_I8) {
interp_add_ins (td, MINT_CONV_I8_I4);
td->sp [-1].type = STACK_TYPE_I8;
}
#endif

I'm not sure how to do that (effeciently) for regular calls. The suggested change here is a bit of a hack. Properly harmless on 64 bit systems, but potentially a performance penalty on 32 bit.

Maybe also addresses #17440 it's a different problem

@BrzVlad do you have a better suggestion how to fix this?

Fixes:
```console
$ ./mono/mini/mono-sgen --interp=-all ./mono/mini/iltests.exe
```

This is the problematic trace:
```
(0x103e90130) Tests:i8_ptr_arithm_x64 -> IR_004e: ldc.i4.5        0:
(0x103e90130) Tests:i8_ptr_arithm_x64 -> IR_004f: ldc.i8     1229801703532086340  0:[0x5 (5)]
(0x103e90130) Tests:i8_ptr_arithm_x64 -> IR_0054: ldc.i4     -65536       0:[0x5 (5)] [0x1111222233334444 (1229801703532086340)]
(0x103e90130) Tests:i8_ptr_arithm_x64 -> IR_0057: call       2    0:[0x5 (5)] [0x1111222233334444 (1229801703532086340)] [0xffff0000 (4294901760)]
  (0x103e90130) Entering Tests:and_ptr_i8 ([0x1111222233334444] [{long} 4294901760/0xffff0000] )
  (0x103e90130) Tests:and_ptr_i8 -> IR_0000: safepoint    0:
  (0x103e90130) Tests:and_ptr_i8 -> IR_0001: ldarg.p0     0:
  (0x103e90130) Tests:and_ptr_i8 -> IR_0002: ldarg.i8   1 0:[0x1111222233334444 (1229801703532086340)]
  (0x103e90130) Tests:and_ptr_i8 -> IR_0004: and.i8       0:[0x1111222233334444 (1229801703532086340)] [0xffff0000 (4294901760)]
  (0x103e90130) Tests:and_ptr_i8 -> IR_0005: ret          0:[0x33330000 (858980352)]
  (0x103e90130) Leaving Tests:and_ptr_i8 => [{long} 858980352/0x33330000]
(0x103e90130) Tests:i8_ptr_arithm_x64 -> IR_0059: ldc.i8     1229801703532068864  0:[0x5 (5)] [0x33330000 (858980352)]
```

`and_ptr_i8` expects a ptr and i8 on the stack. In the default configuration the interpreter inlines `and_ptr_i8` and thus stores the arguments into some locals:
https://github.com/mono/mono/blob/b484979aa9741673c2f820bdac7f5c925128ad9d/mono/mini/interp/transform.c#L3360-L3364

where `store_local` will take care of a proper i4->i8 conversion:
https://github.com/mono/mono/blob/b484979aa9741673c2f820bdac7f5c925128ad9d/mono/mini/interp/transform.c#L820-L825

I'm not sure how to do that (effeciently) for regular calls. The suggested change here is a bit of a hack. Properly harmless on 64 bit systems, but potentially a performance penalty on 32 bit.

Maybe also addresses mono#17440
@lewurm lewurm requested a review from BrzVlad as a code owner October 31, 2019 21:14
@BrzVlad
Copy link
Member

BrzVlad commented Oct 31, 2019

@lewurm I'm not convinced the il from the test is valid. Checking the ecma spec III.1.6 Implicit argument coercion, if I understand correctly, if the stack parameter is int32 but the signature expects int64 then this is an invalid CIL sequence. The runtime is free to insert appropriate conversion opcodes but I'd rather fix the test to be honest.

@jaykrell
Copy link
Contributor

jaykrell commented Nov 1, 2019

Obvious questions, inspired by Vlad:

  1. Does PEVerify accept it? (or mono's verifier?)
  2. Does CoreCLR/Desktop accept it? (I starting to wish there was a third CLR, alas).
  3. Can you get csc to generate it?
  4. History of the IL test?

@lewurm lewurm closed this Jan 7, 2020
lewurm added a commit to lewurm/mono that referenced this pull request Jan 7, 2020
@lewurm
Copy link
Contributor Author

lewurm commented Jan 7, 2020

Closing it for now. My attempt to fix it is obviously flawed. Not sure about the test, this needs further investigation as suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants