From 0d08ec191bf3f15ae89dc243877d9295b3004bc6 Mon Sep 17 00:00:00 2001 From: qunyanm Date: Mon, 8 Feb 2016 15:22:06 -0800 Subject: Fix issue 120. Need to wrap operations that are "lit lifted" and turned into boogie function calls with "Lit" function. --- Source/Dafny/Translator.cs | 26 +++++++++++++++++--------- Test/dafny4/Bug120.dfy | 11 +++++++++++ Test/dafny4/Bug120.dfy.expect | 2 ++ 3 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 Test/dafny4/Bug120.dfy create mode 100644 Test/dafny4/Bug120.dfy.expect diff --git a/Source/Dafny/Translator.cs b/Source/Dafny/Translator.cs index 1208a83a..cfb77d84 100644 --- a/Source/Dafny/Translator.cs +++ b/Source/Dafny/Translator.cs @@ -11222,7 +11222,7 @@ namespace Microsoft.Dafny { bOpcode = BinaryOperator.Opcode.Lt; break; } else { - return translator.FunctionCall(expr.tok, "INTERNAL_lt_boogie", Bpl.Type.Int, e0, e1); + return TrToFunctionCall(expr.tok, "INTERNAL_lt_boogie", Bpl.Type.Int, e0, e1, liftLit); } case BinaryExpr.ResolvedOpcode.Le: @@ -11232,7 +11232,7 @@ namespace Microsoft.Dafny { bOpcode = BinaryOperator.Opcode.Le; break; } else { - return translator.FunctionCall(expr.tok, "INTERNAL_le_boogie", Bpl.Type.Int, e0, e1); + return TrToFunctionCall(expr.tok, "INTERNAL_le_boogie", Bpl.Type.Int, e0, e1, false); } case BinaryExpr.ResolvedOpcode.Ge: keepLits = true; @@ -11241,7 +11241,7 @@ namespace Microsoft.Dafny { bOpcode = BinaryOperator.Opcode.Ge; break; } else { - return translator.FunctionCall(expr.tok, "INTERNAL_ge_boogie", Bpl.Type.Int, e0, e1); + return TrToFunctionCall(expr.tok, "INTERNAL_ge_boogie", Bpl.Type.Int, e0, e1, false); } case BinaryExpr.ResolvedOpcode.Gt: if (isReal || !DafnyOptions.O.DisableNLarith) { @@ -11249,7 +11249,7 @@ namespace Microsoft.Dafny { bOpcode = BinaryOperator.Opcode.Gt; break; } else { - return translator.FunctionCall(expr.tok, "INTERNAL_gt_boogie", Bpl.Type.Int, e0, e1); + return TrToFunctionCall(expr.tok, "INTERNAL_gt_boogie", Bpl.Type.Int, e0, e1, liftLit); } case BinaryExpr.ResolvedOpcode.Add: if (!DafnyOptions.O.DisableNLarith) { @@ -11261,7 +11261,7 @@ namespace Microsoft.Dafny { bOpcode = BinaryOperator.Opcode.Add; break; } else { - return translator.FunctionCall(expr.tok, "INTERNAL_add_boogie", Bpl.Type.Int, e0, e1); + return TrToFunctionCall(expr.tok, "INTERNAL_add_boogie", Bpl.Type.Int, e0, e1, liftLit); } } case BinaryExpr.ResolvedOpcode.Sub: @@ -11274,7 +11274,7 @@ namespace Microsoft.Dafny { bOpcode = BinaryOperator.Opcode.Sub; break; } else { - return translator.FunctionCall(expr.tok, "INTERNAL_sub_boogie", Bpl.Type.Int, e0, e1); + return TrToFunctionCall(expr.tok, "INTERNAL_sub_boogie", Bpl.Type.Int, e0, e1, liftLit); } } case BinaryExpr.ResolvedOpcode.Mul: @@ -11287,7 +11287,7 @@ namespace Microsoft.Dafny { bOpcode = BinaryOperator.Opcode.Mul; break; } else { - return translator.FunctionCall(expr.tok, "INTERNAL_mul_boogie", Bpl.Type.Int, e0, e1); + return TrToFunctionCall(expr.tok, "INTERNAL_mul_boogie", Bpl.Type.Int, e0, e1, liftLit); } } @@ -11300,7 +11300,7 @@ namespace Microsoft.Dafny { typ = Bpl.Type.Int; bOpcode = BinaryOperator.Opcode.Div; break; } else { - return translator.FunctionCall(expr.tok, "INTERNAL_div_boogie", Bpl.Type.Int, e0, e1); + return TrToFunctionCall(expr.tok, "INTERNAL_div_boogie", Bpl.Type.Int, e0, e1, liftLit); } } case BinaryExpr.ResolvedOpcode.Mod: @@ -11313,7 +11313,7 @@ namespace Microsoft.Dafny { bOpcode = BinaryOperator.Opcode.Mod; break; } else { - return translator.FunctionCall(expr.tok, "INTERNAL_mod_boogie", Bpl.Type.Int, e0, e1); + return TrToFunctionCall(expr.tok, "INTERNAL_mod_boogie", Bpl.Type.Int, e0, e1, liftLit); } } @@ -11651,6 +11651,14 @@ namespace Microsoft.Dafny { } } + private Expr TrToFunctionCall(IToken tok, string function, Bpl.Type returnType, Bpl.Expr e0, Bpl.Expr e1, bool liftLit) { + Bpl.Expr re = translator.FunctionCall(tok, function, returnType, e0, e1); + if (liftLit) { + re = MaybeLit(re, returnType); + } + return re; + } + private Expr TrLambdaExpr(LambdaExpr e) { var bvars = new List(); var bargs = new List(); diff --git a/Test/dafny4/Bug120.dfy b/Test/dafny4/Bug120.dfy new file mode 100644 index 00000000..73553f2a --- /dev/null +++ b/Test/dafny4/Bug120.dfy @@ -0,0 +1,11 @@ +// RUN: %dafny /compile:0 /noNLarith "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +function G(n: nat): nat +{ + if n == 0 then 5 else G(n-1) +} + +method Test() { + assert G(10) == 5; +} \ No newline at end of file diff --git a/Test/dafny4/Bug120.dfy.expect b/Test/dafny4/Bug120.dfy.expect new file mode 100644 index 00000000..52595bf9 --- /dev/null +++ b/Test/dafny4/Bug120.dfy.expect @@ -0,0 +1,2 @@ + +Dafny program verifier finished with 3 verified, 0 errors -- cgit v1.2.3