Skip to content

Add an implicit argument coercion check. - #43386

Merged
sandreenko merged 6 commits into
dotnet:masterfrom
sandreenko:implicitArgumentCoercionCheck
Nov 6, 2020
Merged

Add an implicit argument coercion check.#43386
sandreenko merged 6 commits into
dotnet:masterfrom
sandreenko:implicitArgumentCoercionCheck

Conversation

@sandreenko

@sandreenkosandreenko commented Oct 14, 2020

Copy link
Copy Markdown
Contributor

Check what types we are passing to a call and return BADCODE if such implicit conversion is not allowed by ECMA (Table III.9: Signature Matching ).

It fixes some undefined behavior (for example, passing long as int on x86 leads to a read of non-defined register).

The change includes fixes for tests where we used such IL and a fix for VM (thanks @jkoritzinsky, who was guiding me through VM changes).

Two implicit conventions, not allowed by ECMA, were tolerated:

  • int8->nint on x64, because we have tolerated it on desktop and because Jit's type system does not allow us to catch it, BADCODE on x86.
  • byref->nint, we had a discussion about it with @janvorli and @jkoritzinsky and decided to postpone this check (and fixes for it) for later so it does not block this PR (and arm64 work)

PTAL @CarolEidt @dotnet/jit-contrib

Note that it is a breaking change, cc @jkotas, @jeffschwMSFT

Fixes#43342, unblocks #43130

@sandreenkosandreenko added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Oct 14, 2020
@sandreenko
sandreenkoforce-pushed the implicitArgumentCoercionCheck branch from 86dc74e to 2959b74CompareOctober 14, 2020 23:28
@sandreenkosandreenko reopened this Oct 14, 2020
@sandreenko
sandreenko marked this pull request as ready for review October 15, 2020 00:09
@jkotas

Copy link
Copy Markdown
Member

byref->nint

This came up before. This mistake seems to be pretty prevalent in the code out there. I think we should keep allowing it.

@sandreenko

Copy link
Copy Markdown
ContributorAuthor

ci failures are caused by #43412

@jeffschwMSFTjeffschwMSFT added the breaking-change Issue or PR that represents a breaking API or functional change over a previous release. label Oct 15, 2020
@ghostghost added the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Oct 15, 2020
@sandreenko
sandreenkoforce-pushed the implicitArgumentCoercionCheck branch from 75a3b4a to ed005c3CompareOctober 28, 2020 19:20
@sandreenko

Copy link
Copy Markdown
ContributorAuthor

PTAL @dotnet/jit-contrib

I am not familiar with needs-breaking-change-doc-created label, could somebody please explain what is it for and what should be done?

@webczat

Copy link
Copy Markdown
Contributor

hmm, does that fix a case where you make a Dynamic method, trying to pass an int to a method expecting Object, and forget to box or box incorrectly?

@sandreenko

Copy link
Copy Markdown
ContributorAuthor

hmm, does that fix a case where you make a Dynamic method, trying to pass an int to a method expecting Object, and forget to box or box incorrectly?

Kind of... There are 2 issues:

ECMA tolerates passing a native int as byref:
image

and because JIT does not distinguish nint from int on 32-bit platforms such code will be accepted on x86, but rejected on x64.

@webczat

Copy link
Copy Markdown
Contributor

so probably not exactly my issue, I'm x64

@sandreenko

Copy link
Copy Markdown
ContributorAuthor

Could somebody please take a look, @dotnet/jit-contrib ?

@kunalspathakkunalspathak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment threadsrc/coreclr/src/jit/importer.cpp Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like these are generally useful and should be in a header somewhere?

@sandreenkosandreenkoNov 3, 2020

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have GenTree::TypeIs and it is usually sufficient, we don't have many places where we compare types not from tree nodes.
I did not want to make this function general available because it is a little confusing that the first argument is special there, but I am open to other opinions. I thought it would be nice to make it a member function, like var_types::TypeIs(this, types to compare this with) but var_types is not a class, it is an enum.

@sandreenko
sandreenkoforce-pushed the implicitArgumentCoercionCheck branch from 3213c95 to e63f15bCompareNovember 6, 2020 00:26
@sandreenko

Copy link
Copy Markdown
ContributorAuthor

I have fixed another test and rerun the tests, the failures are unrelated.

@sandreenko
sandreenko merged commit d7c4602 into dotnet:masterNov 6, 2020
@sandreenko
sandreenko deleted the implicitArgumentCoercionCheck branch November 6, 2020 05:32
tqiu8 pushed a commit to tqiu8/runtime that referenced this pull request Nov 9, 2020
author Stephen Toub <stoub@microsoft.com> 1604601164 -0500
committer Tammy Qiu <tammy.qiu@yahoo.com> 1604960878 -0500
Add stream conformance tests for TranscodingStream (dotnet#44248)
* Add stream conformance tests for TranscodingStream
* Special-case 0-length input buffers to TranscodingStream.Write{Async}
The base implementation of Encoder.Convert doesn't like empty inputs. Regardless, if the input is empty, we can avoid a whole bunch of unnecessary work.
JIT: minor inliner refactoring (dotnet#44215)
Extract out the budget check logic so it can vary by inlining policy.
Use this to exempt the FullPolicy from budget checking.
Fix inline xml to dump the proper (full name) hash for inlinees.
Update range dumper to dump ranges in hex.
Remove unused QCall for WinRTSupported (dotnet#44278)
ConcurrentQueueSegment allows spinning threads to sleep. (dotnet#44265)
* Allow threads to sleep when ConcurrentQueue has many enqueuers/dequeuers.
* Update src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueueSegment.cs
Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Apply suggestions from code review
Co-authored-by: Stephen Toub <stoub@microsoft.com>
Co-authored-by: AMD DAYTONA EPYC <amd@amd-DAYTONA-X0.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
File.Exists() is not null when true (dotnet#44310)
* File.Exists() is not null when true
* Fix compile
* Fix compile 2
[master][watchOS] Add simwatch64 support (dotnet#44303)
Xcode 12.2 removed 32 bits support for watchOS simulators, this PR helps to fixdotnet/macios#9949, we have tested the new binaries and they are working as expected
![unknown](https://user-images.githubusercontent.com/204671/98253709-64413200-1f49-11eb-9774-8c5aa416fc57.png)
Co-authored-by: dalexsoto <dalexsoto@users.noreply.github.com>
Implementing support to Debugger::Break. (dotnet#44305)
Set fgOptimizedFinally flag correctly (dotnet#44268)
- Initialize to 0 at compiler startup
- Set flag when finally cloning optimization kicks in
Fixes non-deterministic generation of nop opcodes into ARM32 code
Forbid `- byref cnst` -> `+ (byref -cnst)` transformation. (dotnet#44266)
* Add a repro test.
* Forbid the transformation for byrefs.
* Update src/coreclr/src/jit/morph.cpp
Co-authored-by: Andy Ayers <andya@microsoft.com>
* Update src/coreclr/src/jit/morph.cpp
* Fix the test return value.
WriteLine is just to make sure we don't delete the value.
* improve the test.
avoid a possible overflow and don't waste time on printing.
Co-authored-by: Andy Ayers <andya@microsoft.com>
Pick libmonosgen-2.0.so from cmake install directory instead of .libs (dotnet#44291)
This aligns Linux with what we already do for all the other platforms.
Update SharedPerformanceCounter assert (dotnet#44333)
Remove silly ToString in GetCLRInstanceString (dotnet#44335)
Use targetPlatformMoniker for net5.0 and newer tfms (dotnet#43965)
* Use targetPlatformMoniker for net5.0 and newer tfms
* disabling analyzer, update version to 0.0, and use new format.
* update the targetFramework.sdk
* removing supportedOS assembly level attribute
* fix linker errors and addressing feedback
* making _TargetFrameworkWithoutPlatform as private
[sgen] Add Ward annotations to sgen_get_total_allocated_bytes (dotnet#43833)
Attempt to fix https://jenkins.mono-project.com/job/test-mono-mainline-staticanalysis/
Co-authored-by: lambdageek <lambdageek@users.noreply.github.com>
[tests] Re-enable tests fixed by dotnet#44081 (dotnet#44212)
Fixesmono/mono#15030 and
fixesmono/mono#15031 and
fixesmono/mono#15032
Add an implicit argument coercion check. (dotnet#43386)
* Add `impCheckImplicitArgumentCoercion`.
* Fix tests with type mismatch.
* Try to fix VM signature.
* Allow to pass byref as native int.
* another fix.
* Fix another IL test.
[mono] Change CMakelists.txt "python" -> Python3_EXECUTABLE (dotnet#44340)
Debian doesn't install a "python" binary for python3.
Tweak StreamConformanceTests for cancellation (dotnet#44342)
- Avoid unnecessary timers
- Separate tests for precancellation, ReadAsync(byte[], ...) cancellation, and ReadAsync(Memory, ...) cancellation
Use Dictionary for underlying cache of ResourceSet (dotnet#44104)
Simplify catch-rethrow logic in NetworkStream (dotnet#44246)
A follow-up on dotnet#40772 (comment), simplifies and harmonizes the way we wrap exceptions into IOException. Having one catch block working with System.Exception seems to be enough here, no need for specific handling of SocketException.
Simple GT_NEG optimization for dotnet#13837 (dotnet#43921)
* Simple arithmetic optimization with GT_NEG
* Skip GT_NEG optimization when an operand is constant. Revert bitwise rotation pattern
* Fixed Value Numbering assert
* Cleaned up code and comments for simple GT_NEG optimization
* Formatting
Co-authored-by: Julie Lee <jeonlee@microsoft.com>
[master] Update dependencies from mono/linker (dotnet#44322)
* Update dependencies from https://github.com/mono/linker build 20201105.1
Microsoft.NET.ILLink.Tasks
From Version 6.0.0-alpha.1.20527.2 -> To Version 6.0.0-alpha.1.20555.1
* Update dependencies from https://github.com/mono/linker build 20201105.2
Microsoft.NET.ILLink.Tasks
From Version 6.0.0-alpha.1.20527.2 -> To Version 6.0.0-alpha.1.20555.2
* Disable new optimization for libraries mode (it cannot work in this mode)
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Marek Safar <marek.safar@gmail.com>
Tighten argument validation in StreamConformanceTests (dotnet#44326)
Add threshold on number of files / partition in SPMI collection (dotnet#44180)
* Add check for files count
* Fix the OS check
* decrese file limit to 1500:
* misc fix
* Do not upload to azure if mch files are zero size
Fix ELT profiler tests (dotnet#44285)
[master] Update dependencies from dotnet/arcade dotnet/llvm-project dotnet/icu (dotnet#44336)
[master] Update dependencies from dotnet/arcade dotnet/llvm-project dotnet/icu
- Merge branch 'master' into darc-master-2211df94-2a02-4c3c-abe1-e3534e896267
Fix Send_TimeoutResponseContent_Throws (dotnet#44356)
If the client times out too quickly, the server may never have a connection to accept and will hang forever.
Match CoreCLR behaviour on thread start failure (dotnet#44124)
Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com>
Add slash in Windows SoD tool build (dotnet#44359)
* Add slash in Windows SoD tool build
* Update SoD search path to match output dir
* Fixup dotnet version
* Remove merge commit headers
* Disable PRs
Co-authored-by: Drew Scoggins <andrew.g.scoggins@gmail>
Reflect test path changes in .gitattributes; remove nonexistent files (dotnet#44371)
Bootstrapping a test for R2RDump (dotnet#42150)
Improve performance of Enum's generic IsDefined / GetName / GetNames (dotnet#44355)
Eliminates the boxing in IsDefined/GetName/GetValues, and in GetNames avoids having to go through RuntimeType's GetEnumNames override.
clarify http version test (dotnet#44379)
Co-authored-by: Geoffrey Kizer <geoffrek@windows.microsoft.com>
Update dependencies from https://github.com/mono/linker build 20201106.1 (dotnet#44367)
Microsoft.NET.ILLink.Tasks
From Version 6.0.0-alpha.1.20555.2 -> To Version 6.0.0-alpha.1.20556.1
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Disable RunThreadLocalTest8_Values on Mono (dotnet#44357)
* Disable RunThreadLocalTest8_Values on Mono
It's failing on SLES
* fix typo
LongProcessNamesAreSupported: make test work on distros where sleep is a symlink/script (dotnet#44299)
* LongProcessNamesAreSupported: make test work on distros where sleep is a symlink/script
* PR feedback
Co-authored-by: Stephen Toub <stoub@microsoft.com>
* fix compilation
Co-authored-by: Stephen Toub <stoub@microsoft.com>
add missing constructor overloads (dotnet#44380)
Co-authored-by: Geoffrey Kizer <geoffrek@windows.microsoft.com>
change using in ConnectCallback_UseUnixDomainSocket_Success (dotnet#44366)
Clean up the samples (dotnet#44293)
Update dotnet/roslyn issue link
Delete stale comment about dotnet/roslyn#30797
Fix/remove TODO-NULLABLEs (dotnet#44300)
* Fix/remove TODO-NULLABLEs
* remove redundant !
* apply Jozkee's feedback
* address feedback
Update glossary (dotnet#44274)
Co-authored-by: Juan Hoyos <juan.hoyos@microsoft.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
Co-authored-by: Günther Foidl <gue@korporal.at>
Add files need for wasm executable relinking/aot to the wasm runtime pack. (dotnet#43785)
Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
Move some more UnmanagedCallersOnly tests to IL now that they're invalid C# (dotnet#43366)
Fix C++ build for mono/metadata/threads.c (dotnet#44413)
`throw` is a reserved keyword in C++.
Disable a failing test. (dotnet#44404)
Change async void System.Text.Json test to be async Task (dotnet#44418)
Improve crossgen2 comparison jobs (dotnet#44119)
- Fix compilation on unix platforms
- Wrap use of wildcard in quotes
- Print better display name into log
- Fix X86 constant comparison handling
- Add ability to compile specific overload via single method switches
Remove some unnecessary GetTypeInfo usage (dotnet#44414)
Fix MarshalTypedArrayByte and re-enable it. Re-enable TestFunctionApply
@ghostghost locked as resolved and limited conversation to collaborators Dec 7, 2020
@ericstjericstj added this to the 6.0.0 milestone Sep 29, 2021
@kunalspathakkunalspathak removed the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Oct 1, 2021
@kunalspathak

Copy link
Copy Markdown
Contributor

Added breaking change docs: dotnet/docs#26346

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIbreaking-changeIssue or PR that represents a breaking API or functional change over a previous release.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Incorrect IL is accepted by the Jit and leading to incorrect execution.

8 participants

@sandreenko@jkotas@webczat@kunalspathak@AndyAyersMS@ericstj@jeffschwMSFT@JulieLeeMSFT