Skip to content

Commit

Permalink
Avoid exception in SyntacticContextAnalysis (#699)
Browse files Browse the repository at this point in the history
Signed-off-by: Hernan Ponce de Leon <[email protected]>
Co-authored-by: Hernan Ponce de Leon <[email protected]>
  • Loading branch information
hernanponcedeleon and hernan-poncedeleon committed Aug 26, 2024
1 parent 6c492c4 commit 1c819d0
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.dat3m.dartagnan.program.event.metadata.SourceLocation;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -22,6 +24,8 @@
*/
public class SyntacticContextAnalysis {

private static final Logger logger = LogManager.getLogger(SyntacticContextAnalysis.class);

// ============================================================================
// ============================== Helper classes ==============================
// ============================================================================
Expand Down Expand Up @@ -165,8 +169,12 @@ private void run(Thread thread, LoopAnalysis loops) {
// FIXME: DCE can sometimes delete the end marker of functions if those never return
// (e.g., "reach_error() { abort(0); }").
// Here we try to also pop those calls that have missing markers.
assert curContextStack.peek() instanceof CallContext;
topCallCtx = (CallContext) curContextStack.pop();
if(curContextStack.peek() instanceof CallContext) {
topCallCtx = (CallContext) curContextStack.pop();
} else {
logger.warn("Found a FunCallMarker without a matching FunReturnMarker. Giving up the analysis");
break;
}
} while (!topCallCtx.funCallMarker.getFunctionName().equals(retMarker.getFunctionName()));
}

Expand All @@ -179,10 +187,14 @@ private void run(Thread thread, LoopAnalysis loops) {
curContextStack.push(new LoopContext(ev, iteration.getIterationNumber()));
}
if (end) {
assert curContextStack.peek() instanceof LoopContext c &&
if (curContextStack.peek() instanceof LoopContext c &&
c.loopMarker == iteration.getIterationStart() &&
c.iterationNumber == iteration.getIterationNumber();
curContextStack.pop();
c.iterationNumber == iteration.getIterationNumber()) {
curContextStack.pop();
} else {
logger.warn("Found a IterationStart without a matching IterationEnd. Giving up the analysis");
break;
}
}
}
}
Expand Down

0 comments on commit 1c819d0

Please sign in to comment.