Skip to content

Commit

Permalink
safeguards to prevent stack overfloaw
Browse files Browse the repository at this point in the history
  • Loading branch information
pruemmer committed Nov 19, 2020
1 parent c0de0b1 commit 2efb21b
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/lazabs/horn/preprocessor/ClauseInliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,30 @@ import ap.util.Seqs
import scala.collection.mutable.{HashSet => MHashSet, HashMap => MHashMap,
LinkedHashSet, ArrayBuffer}

object ClauseInliner {

val DAG_SIZE_LIMIT = 100
val CONSTRAINT_SIZE_LIMIT = 10000

}

/**
* Inline linear definitions.
*/
class ClauseInliner extends HornPreprocessor {
import HornPreprocessor._
import ClauseInliner._

val name : String = "clause inlining"

def process(clauses : Clauses, hints : VerificationHints)
: (Clauses, VerificationHints, BackTranslator) = {
for (clause <- clauses)
if (SizeVisitor(clause.constraint) > CONSTRAINT_SIZE_LIMIT)
blockedPreds ++= clause.predicates

blockedPreds += HornClauses.FALSE

val (newClauses, newHints) = elimLinearDefs(clauses, hints)

val translator = new BackTranslator {
Expand Down Expand Up @@ -222,6 +236,7 @@ class ClauseInliner extends HornPreprocessor {

originalInlinedClauses.clear
clauseBackMapping.clear
blockedPreds.clear

(newClauses, newHints, translator)
}
Expand All @@ -234,6 +249,9 @@ class ClauseInliner extends HornPreprocessor {
// mapping from the newly produced clauses to trees of the orginal clauses
private val clauseBackMapping = new MHashMap[Clause, Dag[Option[Clause]]]

// predicates that will never be considered for inlining
private val blockedPreds = new MHashSet[Predicate]

private def defaultBackMapping(c : Clause) = {
val N = c.body.size
DagNode(Some(c), (1 to N).toList,
Expand Down Expand Up @@ -279,7 +297,7 @@ class ClauseInliner extends HornPreprocessor {
private def extractUniqueDefs(clauses : Iterable[Clause]) = {
val uniqueDefs = new MHashMap[Predicate, Clause]
val badHeads = new MHashSet[Predicate]
badHeads += FALSE
badHeads ++= blockedPreds

for (clause@Clause(head, body, _) <- clauses)
if (!(badHeads contains head.pred)) {
Expand Down Expand Up @@ -385,6 +403,11 @@ class ClauseInliner extends HornPreprocessor {
(leafIndexes.iterator zip inlinedClauses.iterator).toMap)

clauseBackMapping.put(res, newMapping)

if (newMapping.size > DAG_SIZE_LIMIT ||
SizeVisitor(res.constraint) > CONSTRAINT_SIZE_LIMIT)
blockedPreds ++= res.predicates

res
} else {
clause
Expand Down

0 comments on commit 2efb21b

Please sign in to comment.