-
Notifications
You must be signed in to change notification settings - Fork 830
Closed
Closed
Copy link
Labels
Milestone
Description
The combination of a struct, a measure type and no optimization can create incorrect programs which fail verification by peverify, and raise InvalidProgramException when run.
Repro steps
-
Take the following code:
type AStruct<[<Measure>]'u> = struct end [<EntryPoint>] let main argv = let x = AStruct() 0
-
Compile the code without optimization using version 4.1 of the F# compiler:
PS> &"C:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0\Fsc.exe" --optimize- .\Program.fs Microsoft (R) F# Compiler version 4.1 Copyright (c) Microsoft Corporation. All Rights Reserved. -
Run the code:
PS> .\Program.exe Unhandled Exception: System.InvalidProgramException: Common Language Runtime detected an invalid program. at [email protected]() at Program.main(String[] argv) -
Verify the code:
PS> peverify.exe Program.exe Microsoft (R) .NET Framework PE Verifier. Version 4.0.30319.0 Copyright (c) Microsoft Corporation. All rights reserved. [IL]: Error: [...\Program.exe : Program::main][offset 0x00000005][found ref 'Program+x@7'][expected value 'Program+AStruct'] Unexpected type on the stack. [IL]: Error: [...\Program.exe : Program+x@7::.ctor][offset 0x00000009] Return from .ctor when this is uninitialized. 2 Error(s) Verifying Program.exe
Expected behavior
Program runs without crashing, and verification with peverify completes without reporting any errors.
Actual behavior
The program crashes with an InvalidProgramException, and verification with peverify reports 2 errors.
Known workarounds
Either:
- Use a class instead of a struct
- don't use a measure type
- Turn on optimization
Related information
- Operating system: Windows 10 (Anniversary Update)
- .NET Runtime, CoreCLR or Mono Version: .Net 4.6.2
- Indications of severity: prevents use of measure types with structs