diff --git a/regression-tests/uninterpreted-predicates/Answers b/regression-tests/uninterpreted-predicates/Answers index 76af574..29daa0c 100644 --- a/regression-tests/uninterpreted-predicates/Answers +++ b/regression-tests/uninterpreted-predicates/Answers @@ -33,3 +33,11 @@ UNSAFE unint-pred-simple-true.c SAFE + +unint-pred-stack-ptr-unsupported.c +tricera.concurrency.ccreader.CCExceptions$TranslationException: 5:3 Unsupported operation: stack pointer argument to uninterpreted predicate. +(error "5:3 Unsupported operation: stack pointer argument to uninterpreted predicate.") +Other Error: 5:3 Unsupported operation: stack pointer argument to uninterpreted predicate. + +unint-pred-simple-ptr-true.c +SAFE diff --git a/regression-tests/uninterpreted-predicates/runtests b/regression-tests/uninterpreted-predicates/runtests index 305bf80..aa65b23 100755 --- a/regression-tests/uninterpreted-predicates/runtests +++ b/regression-tests/uninterpreted-predicates/runtests @@ -3,7 +3,8 @@ LAZABS=../../tri TESTS="pred-hint.c pred-hint-loop.c \ - unint-pred-simple-false.c unint-pred-simple-true.c" + unint-pred-simple-false.c unint-pred-simple-true.c \ + unint-pred-stack-ptr-unsupported.c unint-pred-simple-ptr-true.c" for name in $TESTS; do echo diff --git a/regression-tests/uninterpreted-predicates/unint-pred-simple-ptr-true.c b/regression-tests/uninterpreted-predicates/unint-pred-simple-ptr-true.c new file mode 100644 index 0000000..0a09c5c --- /dev/null +++ b/regression-tests/uninterpreted-predicates/unint-pred-simple-ptr-true.c @@ -0,0 +1,13 @@ +/*$ P(int *x) $*/ + +void main() { + int *x = malloc(sizeof(int)); + int t = _; + *x = t; + assert(P(x)); + + int *y; + assume(P(y)); + + assert(*y == t); +} diff --git a/regression-tests/uninterpreted-predicates/unint-pred-stack-ptr-unsupported.c b/regression-tests/uninterpreted-predicates/unint-pred-stack-ptr-unsupported.c new file mode 100644 index 0000000..6692f75 --- /dev/null +++ b/regression-tests/uninterpreted-predicates/unint-pred-stack-ptr-unsupported.c @@ -0,0 +1,11 @@ +/*$ P(int *x) $*/ + +void main() { + int x = 42; + assert(P(&x)); + + int *y; + assume(P(y)); + + assert(*y == 42); +} diff --git a/src/tricera/concurrency/CCReader.scala b/src/tricera/concurrency/CCReader.scala index be7f2cd..c6bd711 100644 --- a/src/tricera/concurrency/CCReader.scala +++ b/src/tricera/concurrency/CCReader.scala @@ -1418,11 +1418,10 @@ class CCReader private (prog : Program, for (ind <- decList.indices) yield { decList(ind) match { case t : OnlyType => { - if (t.listdeclaration_specifier_.exists(spec => !spec - .isInstanceOf[Type])) - throw new TranslationException("Only type specifiers" + - "are allowed inside predicate" + - "declarations.") + if (t.listdeclaration_specifier_.exists( + spec => !spec.isInstanceOf[Type])) + throw new TranslationException( + "Only type specifiers are allowed inside predicate declarations.") val argType = getType( t.listdeclaration_specifier_.map(_.asInstanceOf[Type] .type_specifier_).toIterator) @@ -1430,37 +1429,27 @@ class CCReader private (prog : Program, (argType, argName) } case argDec : TypeAndParam => { - val name = getName(argDec.declarator_) - val typ = getType(argDec.listdeclaration_specifier_) + val name = getName(argDec.declarator_) + val typ = getType(argDec.listdeclaration_specifier_) val actualType = argDec.declarator_ match { - case p : BeginPointer => - //createHeapPointer(p, typ) - throw new TranslationException("Pointers inside " + - "predicate declarations are " + - "not supported.") - case np : NoPointer => - np.direct_declarator_ match { - case _ : Incomplete => - //CCHeapArrayPointer(heap, typ, HeapArray) - throw new TranslationException("Arrays inside " + - "predicate declarations " + - "are not supported.") - case _ => typ - } + case p : BeginPointer => createHeapPointer(p, typ) + case np : NoPointer => np.direct_declarator_ match { + case _ : Incomplete => + //CCHeapArrayPointer(heap, typ, HeapArray) + throw new TranslationException( + "Arrays inside predicate declarations are not supported.") + case _ => typ + } case _ => typ } (actualType, name) } case argDec : TypeHintAndParam => { - val name = getName(argDec.declarator_) - val typ = getType(argDec.listdeclaration_specifier_) + val name = getName(argDec.declarator_) + val typ = getType(argDec.listdeclaration_specifier_) val actualType = argDec.declarator_ match { - case p : BeginPointer => - //createHeapPointer(p, typ) - throw new TranslationException("Pointers inside" + - "predicate declarations are " + - "not supported.") - case _ => typ + case p : BeginPointer => createHeapPointer(p, typ) + case _ => typ } processHints(argDec.listannotation_) // todo: does this work?? (actualType, name) @@ -3399,9 +3388,13 @@ private def collectVarDecls(dec : Dec, case a : Efunkpar if uninterpPredDecls contains(printer print a.exp_) => val args = a.listexp_.map(exp => atomicEval(exp, evalCtx)) - .map(_.toTerm) + if(args.exists(a => a.typ.isInstanceOf[CCStackPointer])) { + throw new TranslationException( + getLineStringShort(srcInfo) + " Unsupported operation: " + + "stack pointer argument to uninterpreted predicate.") + } val pred = uninterpPredDecls(printer print a.exp_) - atom(pred, args) + atom(pred, args.map(_.toTerm)) case interpPred : Efunkpar if interpPredDefs contains(printer print interpPred.exp_) => val args = interpPred.listexp_.map(