Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
dbccb1c
Merge pull request #6641 from Microsoft/merges/dev16.1-to-dev16.2
Apr 27, 2019
e3e148c
update vs minor version (#6649)
brettfo Apr 29, 2019
046491a
Merge pull request #6642 from Microsoft/merges/master-to-dev16.2
brettfo Apr 29, 2019
34c27d3
Merge pull request #6651 from Microsoft/merges/master-to-dev16.2
Apr 30, 2019
ef3fc2e
Merge remote-tracking branch 'upstream/master' into merges/master-to-…
brettfo Apr 30, 2019
35c5f78
Merge pull request #6658 from Microsoft/merges/master-to-dev16.2
May 1, 2019
267fa06
Merge pull request #6663 from Microsoft/merges/master-to-dev16.2
May 2, 2019
1185538
Merge pull request #6670 from Microsoft/merges/master-to-dev16.2
May 3, 2019
0f93a32
Merge pull request #6683 from Microsoft/merges/master-to-dev16.2
May 3, 2019
485db82
Merge pull request #6682 from Microsoft/merges/dev16.1-to-dev16.2
May 4, 2019
8cc3c7e
Merge pull request #6692 from microsoft/merges/master-to-dev16.2
May 7, 2019
bdf1bec
Merge pull request #6696 from microsoft/merges/master-to-dev16.2
May 7, 2019
2f7ce9e
Merge pull request #6704 from microsoft/merges/master-to-dev16.2
May 10, 2019
1e6bb28
Merge pull request #6708 from microsoft/merges/master-to-dev16.2
May 10, 2019
732b6d0
Merge pull request #6713 from microsoft/merges/master-to-dev16.2
May 13, 2019
5ade74b
Merge pull request #6719 from microsoft/merges/master-to-dev16.2
May 13, 2019
d697eac
Merge pull request #6720 from microsoft/merges/master-to-dev16.2
May 13, 2019
e8102e4
Merge pull request #6726 from microsoft/merges/master-to-dev16.2
May 14, 2019
52c75b3
Update Versions.props
KevinRansom May 14, 2019
90895fd
Merge remote-tracking branch 'upstream/master' into merges/master-to-…
brettfo May 15, 2019
62e9d32
Merge pull request #6736 from microsoft/merges/master-to-release/dev16.2
May 15, 2019
a45d839
Merge pull request #6743 from dotnet/merges/master-to-release/dev16.2
May 16, 2019
eab5ba5
Merge pull request #6757 from dotnet/merges/master-to-release/dev16.2
May 17, 2019
c865d96
Merge pull request #6762 from dotnet/merges/master-to-release/dev16.2
May 17, 2019
0b12961
Merge pull request #6773 from dotnet/merges/master-to-release/dev16.2
May 18, 2019
12313b2
Merge pull request #6787 from dotnet/merges/master-to-release/dev16.2
May 21, 2019
22ecba8
Merge pull request #6792 from dotnet/merges/master-to-release/dev16.2
brettfo May 21, 2019
ca554b0
Merge pull request #6798 from dotnet/merges/master-to-release/dev16.2
May 22, 2019
d6da7ce
Merge pull request #6821 from dotnet/merges/master-to-release/dev16.2
May 23, 2019
808f232
Merge pull request #6834 from dotnet/merges/master-to-release/dev16.2
May 24, 2019
6b02b74
Merge pull request #6852 from dotnet/merges/master-to-release/dev16.2
May 25, 2019
cb51737
Merge branch 'release/dev16.2' into merges/master-to-release/dev16.2
KevinRansom May 27, 2019
42c125e
Merge pull request #6878 from dotnet/merges/master-to-release/dev16.2
May 27, 2019
00cbd3f
Fixed uninitialized mutable locals inside loops (#6899)
TIHan May 31, 2019
f96a2f6
Merge branch 'release/dev16.2' into merges/master-to-release/dev16.2
brettfo Jun 1, 2019
c31566c
Merge pull request #6894 from dotnet/merges/master-to-release/dev16.2
Jun 1, 2019
431fdea
Merge pull request #6918 from dotnet/merges/master-to-release/dev16.2
Jun 2, 2019
3de631a
Stop calling GetHierarchy in FSharpProjectOptionsReactor (#6946)
TIHan Jun 6, 2019
3040aa2
Merge pull request #6982 from dotnet/merges/master-to-release/dev16.2
brettfo Jun 12, 2019
bff4fff
don't ship LSP in VS in `release/dev16.2` (#6983)
brettfo Jun 12, 2019
0aeb4a0
Roslyn Shim - Round 2 (#6734)
TIHan Jun 13, 2019
a24d94e
LOC CHECKIN | Microsoft/visualfsharp release/dev16.2 | 20190620 (#7022)
v-zbsail Jun 20, 2019
a67156b
Merge branch 'master' into merges/release/dev16.2-to-master
brettfo Jul 24, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed uninitialized mutable locals inside loops (#6899)
* Fixed uninitialized mutable locals inside loops

* Update ForInDoMutableRegressionTest.fs
  • Loading branch information
TIHan authored and KevinRansom committed May 31, 2019
commit 00cbd3f82a73f86fec123d78d4b0b3f998f1c4d6
17 changes: 14 additions & 3 deletions src/fsharp/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,15 @@ and IlxGenEnv =

/// Are we under the scope of a try, catch or finally? If so we can't tailcall. SEH = structured exception handling
withinSEH: bool

/// Are we inside of a recursive let binding, while loop, or a for loop?
isInLoop: bool
}

let SetIsInLoop isInLoop eenv =
if eenv.isInLoop = isInLoop then eenv
else { eenv with isInLoop = isInLoop }

let ReplaceTyenv tyenv (eenv: IlxGenEnv) = {eenv with tyenv = tyenv }

let EnvForTypars tps eenv = {eenv with tyenv = TypeReprEnv.ForTypars tps }
Expand Down Expand Up @@ -3369,6 +3376,7 @@ and GenTryFinally cenv cgbuf eenv (bodyExpr, handlerExpr, m, resty, spTry, spFin
//--------------------------------------------------------------------------

and GenForLoop cenv cgbuf eenv (spFor, v, e1, dir, e2, loopBody, m) sequel =
let eenv = SetIsInLoop true eenv
let g = cenv.g

// The JIT/NGen eliminate array-bounds checks for C# loops of form:
Expand Down Expand Up @@ -3459,6 +3467,7 @@ and GenForLoop cenv cgbuf eenv (spFor, v, e1, dir, e2, loopBody, m) sequel =
//--------------------------------------------------------------------------

and GenWhileLoop cenv cgbuf eenv (spWhile, e1, e2, m) sequel =
let eenv = SetIsInLoop true eenv
let finish = CG.GenerateDelayMark cgbuf "while_finish"
let startTest = CG.GenerateMark cgbuf "startTest"

Expand Down Expand Up @@ -5083,6 +5092,7 @@ and GenLetRecFixup cenv cgbuf eenv (ilxCloSpec: IlxClosureSpec, e, ilField: ILFi

/// Generate letrec bindings
and GenLetRecBindings cenv (cgbuf: CodeGenBuffer) eenv (allBinds: Bindings, m) =
let eenv = SetIsInLoop true eenv
// Fix up recursion for non-toplevel recursive bindings
let bindsPossiblyRequiringFixup =
allBinds |> List.filter (fun b ->
Expand Down Expand Up @@ -5324,8 +5334,8 @@ and GenBindingAfterSequencePoint cenv cgbuf eenv sp (TBind(vspec, rhsExpr, _)) s
| _ ->
let storage = StorageForVal cenv.g m vspec eenv
match storage, rhsExpr with
// locals are zero-init, no need to initialize them
| Local (_, realloc, _), Expr.Const (Const.Zero, _, _) when not realloc ->
// locals are zero-init, no need to initialize them, except if you are in a loop and the local is mutable.
| Local (_, realloc, _), Expr.Const (Const.Zero, _, _) when not realloc && not (eenv.isInLoop && vspec.IsMutable) ->
CommitStartScope cgbuf startScopeMarkOpt
| _ ->
GenBindingRhs cenv cgbuf eenv SPSuppress vspec rhsExpr
Expand Down Expand Up @@ -7463,7 +7473,8 @@ let GetEmptyIlxGenEnv (ilg: ILGlobals) ccu =
liveLocals=IntMap.empty()
innerVals = []
sigToImplRemapInfo = [] (* "module remap info" *)
withinSEH = false }
withinSEH = false
isInLoop = false }

type IlxGenResults =
{ ilTypeDefs: ILTypeDef list
Expand Down
73 changes: 73 additions & 0 deletions tests/fsharp/Compiler/Regressions/ForInDoMutableRegressionTest.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.UnitTests

open System
open NUnit.Framework

[<TestFixture()>]
module ForInDoMutableRegressionTest =

/// This test is to ensure we initialize locals inside loops.
[<Test>]
let Script_ForInDoMutableRegressionTest() =
let script =
"""
open System.Collections.Generic

let bug() =
for a in [1;2;3;4] do
let mutable x = null
if x = null then
x <- HashSet<int>()
x.Add a |> ignore
let expected = [a]
let actual = List.ofSeq x
if expected <> actual then
failwith "Bug"

let not_a_bug() =
for a in [1;2;3;4] do
let x = ref null
if (!x) = null then
x := HashSet<int>()
(!x).Add a |> ignore
let expected = [a]
let actual = List.ofSeq (!x)
if expected <> actual then
failwith "Bug"

let rec test_rec xs =
let mutable x = null
match xs with
| [] -> ()
| a :: xs ->
if x = null then
x <- HashSet<int>()
x.Add a |> ignore
let expected = [a]
let actual = List.ofSeq x
if expected <> actual then
failwith "Bug"
test_rec xs

let test_for_loop () =
let xs = [|1;2;3;4|]
for i = 0 to xs.Length - 1 do
let a = xs.[i]
let mutable x = null
if x = null then
x <- HashSet<int>()
x.Add a |> ignore
let expected = [a]
let actual = List.ofSeq x
if expected <> actual then
failwith "Bug"

bug ()
not_a_bug ()
test_rec [1;2;3;4]
test_for_loop ()
"""

CompilerAssert.RunScript script []
1 change: 1 addition & 0 deletions tests/fsharp/FSharpSuite.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Compile Include="Compiler\Language\SpanOptimizationTests.fs" />
<Compile Include="Compiler\Language\SpanTests.fs" />
<Compile Include="Compiler\Language\StringConcatOptimizationTests.fs" />
<Compile Include="Compiler\Regressions\ForInDoMutableRegressionTest.fs" />
<Content Include="packages.config" />
<None Include="app.config" />
<None Include="update.base.line.with.actuals.fsx" />
Expand Down