Skip to content
Snippets Groups Projects
Commit d12b44a6 authored by Regis Blanc's avatar Regis Blanc
Browse files

more aliasing restrictions

parent 6518d924
No related branches found
No related tags found
No related merge requests found
...@@ -332,8 +332,11 @@ object AntiAliasingPhase extends TransformationPhase { ...@@ -332,8 +332,11 @@ object AntiAliasingPhase extends TransformationPhase {
def checkAliasing(fd: FunDef)(ctx: LeonContext): Unit = { def checkAliasing(fd: FunDef)(ctx: LeonContext): Unit = {
def checkReturnValue(body: Expr, bindings: Set[Identifier]): Unit = { def checkReturnValue(body: Expr, bindings: Set[Identifier]): Unit = {
getReturnedExpr(body).foreach{ getReturnedExpr(body).foreach{
case IsTyped(v@Variable(id), tpe) if isMutableType(tpe) && bindings.contains(id) => case expr if isMutableType(expr.getType) =>
ctx.reporter.fatalError(v.getPos, "Cannot return a shared reference to a mutable object: " + v) findReceiverId(expr).foreach(id =>
if(bindings.contains(id))
ctx.reporter.fatalError(expr.getPos, "Cannot return a shared reference to a mutable object: " + expr)
)
case _ => () case _ => ()
} }
} }
......
import leon.lang._
object ObjectAliasing5 {
case class A(var x: Int)
case class B(a: A)
def f1(b: B): A = {
b.a
}
}
import leon.lang._
object ObjectAliasing6 {
case class A(var x: Int)
case class B(a: A)
def f1(b: B): Int = {
val a = b.a
a.x = 12
b.a.x
} ensuring(_ == 12)
}
package test.resources.regression.xlang.error
import leon.lang._
object ObjectAliasing7 {
case class A(var x: Int)
case class B(a: A)
def f1(a1: A, a2: A): Int = {
val tmp = a1.x
a2.x = a1.x
a1.x = tmp
a1.x + a2.x
}
def f(): Int = {
val b = B(A(10))
f1(b.a, b.a)
} ensuring(_ == 20)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment