Skip to content

Commit

Permalink
Fixes in tri-pp, bump up its version
Browse files Browse the repository at this point in the history
  • Loading branch information
zafer-esen committed Feb 2, 2024
1 parent 89630b8 commit c7a6357
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ lazy val acslParser = (project in file("acsl-parser")).

lazy val pp = taskKey[Unit]("")
pp := {
val f = url("https://github.com/zafer-esen/tri-pp/releases/download/v0.1.2/tri-pp")
val f = url("https://github.com/zafer-esen/tri-pp/releases/download/v0.1.3/tri-pp")
f #> file("tri-pp") !
}
def addExecutePermissions(file : File) {
Expand Down
6 changes: 6 additions & 0 deletions regression-tests/horn-hcc-heap/Answers
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,9 @@ SAFE

stack-ptr-bug-1.c
UNKNOWN (Unsupported C fragment. 11:10 Stack pointers in combination with heap pointers)

sizeof-bug-1-true.c
SAFE

sizeof-bug-2-true.c
SAFE
2 changes: 1 addition & 1 deletion regression-tests/horn-hcc-heap/runtests
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ for name in $TESTS; do
$LAZABS -cex -abstract:off "$@" $name 2>&1 | grep -v 'at '
done

VALID_DEREF_TESTS="stack-ptr-bug-1.c"
VALID_DEREF_TESTS="stack-ptr-bug-1.c sizeof-bug-1-true.c sizeof-bug-2-true.c"

for name in $VALID_DEREF_TESTS; do
echo
Expand Down
19 changes: 19 additions & 0 deletions regression-tests/horn-hcc-heap/sizeof-bug-1-true.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdlib.h>

struct S1
{
struct S1* f1;
};

struct S2
{
struct S1* f2;
};

int main()
{
struct S2 s2;
s2.f2 = malloc(sizeof(*s2.f2));
s2.f2->f1 = s2.f2;
return 0;
}
21 changes: 21 additions & 0 deletions regression-tests/horn-hcc-heap/sizeof-bug-2-true.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdlib.h>

struct S1
{
struct S1* f1;
};

struct S2
{
struct S1* f2;
};

int main()
{
struct S2 s2;
struct S1 **p = malloc(sizeof(s2.f2)); // p is S1**, s2.f2 is S1*
*p = malloc(sizeof(*s2.f2)); // *p is S1*, *s2.f2 is S1
s2.f2 = *p;
s2.f2->f1 = *p; // lhs is S1*, rhs is also S1*
return 0;
}
33 changes: 23 additions & 10 deletions src/tricera/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class Main (args: Array[String]) {

if (logPPLevel > 0)
Console.withOut(outStream) {
println("=" * 80 + "\nPreprocessor warnings and errors\n")
println("=" * 80 + "\nTriCera's preprocessor (tri-pp) warnings and errors\n")
}

val pp = new TriCeraPreprocessor(cppFileName,
Expand All @@ -300,17 +300,16 @@ class Main (args: Array[String]) {
quiet = logPPLevel == 0,
entryFunction = TriCeraParameters.get.funcName)
if (logPPLevel > 0) Console.withOut(outStream) {
println("\n\nEnd of preprocessor warnings and errors")
println("\n\nEnd of TriCera's preprocessor (tri-pp) warnings and errors")
println("=" * 80)
}

if (pp.hasError && logPPLevel > 0)
Util.warn("The preprocessor (LLVM) reported an error in the" +
" input file, This might be due to TriCera accepting a non-standard" +
" subset of the C language, or due to an actual error in the " +
"input program. You can safely ignore this warning if it is" +
" the former. You can print preprocessor warnings and errors " +
"using the -warnPP option.")
Util.warn(
"""The preprocessor tri-pp (LLVM) reported an error in the input file, This might
|be due to TriCera accepting a non-standard subset of the C language, or
|due to an actual error in the input program. You can safely ignore this
|warning if it is the former.""".stripMargin)

if (printPP) {
val src = scala.io.Source.fromFile(preprocessedFile)
Expand All @@ -332,7 +331,16 @@ class Main (args: Array[String]) {
// Nil, false, 0, preprocessTimer.s)
//throw new MainException("Input file has unsupported C features " +
// "(e.g. varargs)") // todo: more detail
preprocessedFile.getAbsolutePath
if(preprocessedFile.length() == 0 && pp.hasError) {
Util.warn(
"""TriCera preprocessor (tri-pp) returned an empty file - attempting
|to continue without it. Use option -logPP:2 to display what went
|wrong, use option -noPP to disable the preprocessor and this warning.
|""".stripMargin)
cppFileName
} else {
preprocessedFile.getAbsolutePath
}
}
preprocessTimer.stop()

Expand Down Expand Up @@ -455,7 +463,12 @@ class Main (args: Array[String]) {
if (propertiesToCheck.forall(propertyToExpected.contains)) {
if (propertyToExpected.filter(
pair => propertiesToCheck.contains(pair._1)).forall(_._2)) "sat"
else "unsat"
else {
if (useMemCleanupForMemTrack &&
propertiesToCheck.contains(properties.MemValidTrack))
"unknown"
else "unsat"
}
} else "unknown"

val smtFileName = if (splitProperties) {
Expand Down
6 changes: 4 additions & 2 deletions src/tricera/concurrency/CCReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3466,14 +3466,16 @@ private def collectVarDecls(dec : Dec,
(getType(exp.exp_2.asInstanceOf[Ebytestype]), eval(e))
case _ =>
throw new UnsupportedCFragmentException(
"Unsupported alloc expression: " + (printer print exp))
getLineStringShort(srcInfo) +
" Unsupported alloc expression: " + (printer print exp))
}
//case exp : Evar => // allocation in bytes
case e : Econst => // allocation in bytes
(CCInt, eval(e)) // todo: add support for char?

case _ => throw new UnsupportedCFragmentException(
"Unsupported alloc expression: " + (printer print exp))
getLineStringShort(srcInfo) +
" Unsupported alloc expression: " + (printer print exp))
}

val arrayLoc = name match {
Expand Down
3 changes: 2 additions & 1 deletion src/tricera/params/TriCeraParameters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ class TriCeraParameters extends GlobalParameters {
|TriCera preprocessor:
|-printPP Print the output of the TriCera preprocessor to stdout
|-dumpPP Dump the output of the TriCera preprocessor to file (input file name + .tri)
|-logPP:n Display TriCera preprocessor warnings and errors with verbosity n (currently 0 <= n <= 2)
|-logPP:n Display TriCera preprocessor warnings and errors with verbosity n.
| (0 <= n <= 2, default: 0)
|-noPP Turn off the TriCera preprocessor (typedefs are not allowed in this mode)
|Debugging:
Expand Down

0 comments on commit c7a6357

Please sign in to comment.