public override void Verify(string fileName, TransHelper.TransEnv env, Microsoft.FSharp.Collections.FSharpList <CAST.Top> decls) { // this really only dumps the code to the .bpl file Init(env, fileName); decls = env.ApplyTransformers(decls); if (options.NoVerification) { return; } if (env.ShouldContinue) { if (env.Options.AggressivePruning && env.Options.Functions.Count() > 0) { decls = TransUtil.pruneBy(env, env.Options.Functions.First(), decls); } var boogieDecls = Translator.translate(null, env, () => VccCommandLineHost.StandardPrelude(options), decls); var p = TranslateToBoogie(boogieDecls); if (env.ShouldContinue) { try { swSaveBPL.Start(); CommandLineOptions.Install(new CommandLineOptions()); using (var writer = new TokenTextWriter(AddOutputDirIfRequested(Path.ChangeExtension(fileName, ".bpl")))) { p.Emit(writer); } } finally { swSaveBPL.Stop(); } } } }
public ErrorReporter(VccOptions opts, string name, IToken tok, double startTime, VerificationErrorHandler errorHandler) { this.name = name; this.startTime = startTime; this.prevTime = VccCommandLineHost.GetTime(); this.commandLineOptions = opts; this.proverWarnings = new List <string>(); this.errorHandler = errorHandler; this.tok = tok; }
internal Boogie.Program GetBoogieProgram(Microsoft.FSharp.Collections.FSharpList <BoogieAST.Decl> boogieDecls) { var p = BoogieAST.trProgram(boogieDecls); try { swBoogie.Start(); var pp = new Boogie.Program(); pp.TopLevelDeclarations.AddRange(VccCommandLineHost.StandardPrelude(options).TopLevelDeclarations); pp.TopLevelDeclarations.AddRange(p.TopLevelDeclarations); return(pp); } finally { swBoogie.Stop(); } }
public void ReportOutcomeMethodSummary(string methodName, IToken tok, VC.ConditionGeneration.Outcome outcome, string addInfo, double startTime, IEnumerable <string> proverWarnings) { if (outcome != VC.ConditionGeneration.Outcome.Correct) { VccCommandLineHost.IncreaseErrorCount(); } Logger.Instance.LogMethodSummary(methodName, tok.ToLocation(), (Outcome)(int)outcome, addInfo, GetTime() - startTime); if (!commandLineOptions.RunTestSuite) { foreach (var proverWarning in proverWarnings) { Logger.Instance.Warning("Prover warning: {0}", proverWarning); } } }
public override void OnProgress(string phase, int step, int totalSteps, double progressEst) { if (phase == "done") { return; } if (double.IsNaN(progressEst)) { return; } if (commandLineOptions != null && commandLineOptions.TimeStats) { double now = VccCommandLineHost.GetTime(); double length = now - this.prevTime; if (length < 0.5) { return; // don't even bother reporting } this.prevTime = now; string progressMsg; if (phase == "VCprove") { progressMsg = String.Format("({0}/{1}/{2:0.00}%) ", step, totalSteps - step, progressEst * 100); } else if (step != totalSteps || phase != "smoke") { progressMsg = String.Format("({0}/{1}) ", step, totalSteps); } else { progressMsg = String.Format("({0})", step); } Logger.Instance.LogProgress(name, phase, progressMsg); } }
public override void DumpInternalsToFile(string fn, bool generate) { Boogie.Program boogieToDump; if (generate) { var boogieDecls = Translator.translate(null, env, () => VccCommandLineHost.StandardPrelude(parent.options), currentDecls); boogieToDump = PrepareBoogie(boogieDecls); } else { boogieToDump = currentBoogie; } fn = Path.ChangeExtension(fn, (bplFileCounter++) + ".bpl"); if (parent.options.OutputDir != null) { fn = Path.Combine(parent.options.OutputDir, Path.GetFileName(fn)); } CommandLineOptions.Install(new CommandLineOptions()); using (TokenTextWriter writer = new TokenTextWriter(fn)) boogieToDump.Emit(writer); }
public void HandleErrors(object sender, Microsoft.Cci.ErrorEventArgs args) { foreach (IErrorMessage error in args.Errors) { ISourceLocation /*?*/ sourceLocation = error.Location as ISourceLocation; if (sourceLocation == null) { continue; } if (this.DebugOnWarningOrError) { System.Diagnostics.Debugger.Launch(); } bool isError = !error.IsWarning || WarningsAsErrors; if (!isError && GetWarningLevel(error.Code) > WarningLevel) { continue; } if (isError) { VccCommandLineHost.IncreaseErrorCount(); } CompositeSourceDocument /*?*/ compositeDocument = sourceLocation.SourceDocument as CompositeSourceDocument; if (compositeDocument != null) { foreach (ISourceLocation sl in compositeDocument.GetFragmentLocationsFor(sourceLocation)) { sourceLocation = sl; break; } } IPrimarySourceLocation /*?*/ primarySourceLocation = sourceLocation as IPrimarySourceLocation; if (primarySourceLocation == null) { Logger.Instance.Error(error.Message); continue; } string docName = primarySourceLocation.SourceDocument.Location ?? primarySourceLocation.SourceDocument.Name.Value; int startLine = primarySourceLocation.StartLine; int startColumn = primarySourceLocation.StartColumn; IncludedSourceLocation /*?*/ includedSourceLocation = primarySourceLocation as IncludedSourceLocation; if (includedSourceLocation != null) { docName = includedSourceLocation.OriginalSourceDocumentName; if (docName != null) { docName = docName.Replace("\\\\", "\\"); } startLine = includedSourceLocation.OriginalStartLine; } long id = error.IsWarning ? ErrorToId(error.Code) : error.Code; if (WarningIsDisabled(id)) { return; } Logger.Instance.LogWithLocation(String.Format("VC{0:0000}", id), error.Message, new Location(docName, startLine, startColumn), isError ? LogKind.Error : LogKind.Warning, false); string firstErrFile = docName; int firstErrLine = startLine; foreach (ILocation relatedLocation in error.RelatedLocations) { ISourceLocation /*?*/ sloc = relatedLocation as ISourceLocation; if (sloc != null) { compositeDocument = sloc.SourceDocument as CompositeSourceDocument; if (compositeDocument != null) { foreach (ISourceLocation sl in compositeDocument.GetFragmentLocationsFor(sloc)) { sloc = sl; break; } } primarySourceLocation = sloc as IPrimarySourceLocation; if (primarySourceLocation == null) { continue; } docName = primarySourceLocation.SourceDocument.Location ?? primarySourceLocation.SourceDocument.Name.Value; startLine = primarySourceLocation.StartLine; startColumn = primarySourceLocation.StartColumn; includedSourceLocation = primarySourceLocation as IncludedSourceLocation; if (includedSourceLocation != null) { docName = includedSourceLocation.OriginalSourceDocumentName; if (docName != null) { docName = docName.Replace("\\\\", "\\"); } startLine = includedSourceLocation.OriginalStartLine; } if (docName != firstErrFile || firstErrLine != startLine) { Logger.Instance.LogWithLocation( null, String.Format("(Location of symbol related to previous {0}.)", isError ? "error" : "warning"), new Location(docName, startLine, startColumn), isError ? LogKind.Error : LogKind.Warning, true); } } //TODO: deal with non source locations } } }
private Program PrepareBoogie(Microsoft.FSharp.Collections.FSharpList <BoogieAST.Decl> boogieDecls) { var boogieProgram = parent.GetBoogieProgram(boogieDecls); CloseVcGen(); CommandLineOptions.Clo.Parse(standardBoogieOptions); IErrorSink errorSink = new BoogieErrorSink(parent.options.NoPreprocessor); int numErrors; try { parent.swBoogieResolve.Start(); numErrors = boogieProgram.Resolve(errorSink); } finally { parent.swBoogieResolve.Stop(); } if (numErrors == 0) { try { parent.swBoogieTypecheck.Start(); numErrors = boogieProgram.Typecheck(errorSink); } finally { parent.swBoogieTypecheck.Stop(); } } if (numErrors == 0) { try { parent.swBoogieAI.Start(); AbstractInterpretation.RunAbstractInterpretation(boogieProgram); } finally { parent.swBoogieAI.Stop(); } } if (Boogie.CommandLineOptions.Clo.ExpandLambdas && numErrors == 0) { Boogie.LambdaHelper.ExpandLambdas(boogieProgram); } if (numErrors != 0) { VccCommandLineHost.IncreaseErrorCount(); if (!parent.options.RunTestSuite) { Logger.Instance.Error("attempting to dump BPL to buggy.bpl"); var filename = "buggy.bpl"; if (parent.options.OutputDir != null) { filename = Path.Combine(parent.options.OutputDir, filename); } CommandLineOptions.Install(new CommandLineOptions()); using (TokenTextWriter writer = new TokenTextWriter(filename)) boogieProgram.Emit(writer); } errorMode = true; } return(boogieProgram); }
public override VerificationResult Verify(string funcName) { double start = VccCommandLineHost.GetTime(); // Match replacement in Boogie names string sanitizedFuncName = funcName.Replace('\\', '#'); bool restartProver = false; bool isolateProof = HasIsolateProofAttribute(funcName); if (isolateProof) { CloseVcGen(); } if (parent.options.AggressivePruning || isolateProof) { restartProver = true; // this needs to be done before pruning; otherwise call cycles might get hidden Termination.checkCallCycles(env, currentDecls); var decls = TransUtil.pruneBy(env, funcName, currentDecls); var boogieDecls = Translator.translate(funcName, env, () => VccCommandLineHost.StandardPrelude(parent.options), decls); if (!env.ShouldContinue) { return(VerificationResult.UserError); } currentBoogie = PrepareBoogie(boogieDecls); mustRegenerateBoogie = true; } else { if (mustRegenerateBoogie || currentBoogie == null) { var boogieDecls = Translator.translate(null, env, () => VccCommandLineHost.StandardPrelude(parent.options), currentDecls); if (!env.ShouldContinue) { return(VerificationResult.UserError); } currentBoogie = PrepareBoogie(boogieDecls); mustRegenerateBoogie = false; } } Implementation impl = null; foreach (Declaration decl in currentBoogie.TopLevelDeclarations) { impl = decl as Implementation; if (impl != null && impl.Name == sanitizedFuncName) { break; } impl = null; } if (impl == null) { Logger.Instance.Error("cannot find function: {0}", funcName); return(VerificationResult.UserError); } if (this.errorMode || !env.ShouldContinue) { return(VerificationResult.UserError); } if (impl.SkipVerification) { return(VerificationResult.Skipped); } Logger.Instance.LogMethodStart(funcName); string logPath = CommandLineOptions.Clo.SimplifyLogFilePath; if (logPath != null) { logPath = logPath.Replace("@VCCFILE@", TestRunner.currentTestcaseName); } if (logPath != null && logPath.Contains("@VCCFUNC@")) { logPath = logPath.Replace("@VCCFUNC@", funcName.Replace("$", "_").Replace("^", "_")); CloseVcGen(); } string extraFunctionOptions = null; bool isBvLemmaCheck = IsBvLemmaCheck(impl); bool skipSmoke = HasSkipSmokeAttr(impl); if ((parent.options.RunInBatchMode && (extraFunctionOptions = GetExtraFunctionOptions(impl)) != null) || isBvLemmaCheck || skipSmoke) { CloseVcGen(); extraFunctionOptions = extraFunctionOptions ?? ""; // this prevents parsing errors in case of bv_lemma checks and will also cause the VcGen to be closed later VccOptions extraCommandLineOptions = OptionParser.ParseCommandLineArguments(VccCommandLineHost.dummyHostEnvironment, extraFunctionOptions.Split(' ', '\t'), false); List <string> effectiveOptions = new List <string>(extraCommandLineOptions.BoogieOptions); effectiveOptions.AddRange(extraCommandLineOptions.Z3Options.Select(z3option => "/z3opt:" + z3option)); effectiveOptions.AddRange(options); if (isBvLemmaCheck) { effectiveOptions.Add("/proverOpt:OPTIMIZE_FOR_BV=true"); effectiveOptions.RemoveAll(opt => opt == "/z3opt:CASE_SPLIT"); effectiveOptions.Add("/z3opt:CASE_SPLIT=1"); } if (skipSmoke) { effectiveOptions.RemoveAll(opt => opt == "/smoke"); } if (restartProver) { effectiveOptions.Add("/restartProver"); } if (!ReParseBoogieOptions(effectiveOptions, parent.options.RunningFromCommandLine)) { Logger.Instance.Error("Error parsing extra options '{0}' for function '{1}'", extraFunctionOptions, impl.Name); return(VerificationResult.UserError); } try { parent.swBoogie.Start(); vcgen = new VC.VCGen(currentBoogie, logPath, CommandLineOptions.Clo.SimplifyLogFileAppend); } finally { parent.swBoogie.Stop(); } } else if (vcgen == null) { // run with default options ReParseBoogieOptions(options, parent.options.RunningFromCommandLine); try { parent.swBoogie.Start(); vcgen = new VC.VCGen(currentBoogie, logPath, CommandLineOptions.Clo.SimplifyLogFileAppend); } finally { parent.swBoogie.Stop(); } } var reporter = new ErrorReporter(parent.options, impl.Proc.Name, impl.Proc.tok, start, VccCommandLineHost.ErrorHandler); try { parent.swVcOpt.Start(); } finally { parent.swVcOpt.Stop(); } VC.ConditionGeneration.Outcome outcome; string extraInfo = null; try { parent.swVerifyImpl.Start(); VCGenPlugin plugin = parent.plugin; outcome = plugin != null?plugin.VerifyImpl(env, vcgen, impl, currentBoogie, reporter) : vcgen.VerifyImplementation(impl, currentBoogie, reporter); } catch (UnexpectedProverOutputException exc) { outcome = VC.ConditionGeneration.Outcome.OutOfMemory; extraInfo = "caused an exception \"" + exc.Message + "\""; } finally { parent.swVerifyImpl.Stop(); } if (extraFunctionOptions != null) { CloseVcGen(); } reporter.PrintSummary(outcome, extraInfo); modelCount += reporter.modelCount; switch (outcome) { case VC.ConditionGeneration.Outcome.Correct: return(VerificationResult.Succeeded); case VC.ConditionGeneration.Outcome.Errors: return(VerificationResult.Failed); case VC.ConditionGeneration.Outcome.Inconclusive: return(VerificationResult.Inconclusive); case VC.ConditionGeneration.Outcome.OutOfMemory: return(VerificationResult.Crashed); case VC.ConditionGeneration.Outcome.TimedOut: return(VerificationResult.Crashed); default: return(VerificationResult.Crashed); } }
private static int RunTest(CciErrorHandler errorHandler, string suiteName, string fileNameWithoutExt, string test, VccOptions commandLineOptions, List <string> compilerParameters) { VccCommandLineHost.ResetErrorCount(); string fileNameC = fileNameWithoutExt + ".c"; string fileNameI = fileNameWithoutExt + ".i"; StreamWriter tempStreamWriter = new StreamWriter(fileNameC); tempStreamWriter.Write(test); tempStreamWriter.Close(); VccOptions options = new VccOptions(); options.CopyFrom(commandLineOptions); if (compilerParameters != null) { options = OptionParser.ParseCommandLineArguments(VccCommandLineHost.dummyHostEnvironment, compilerParameters, options); } options.NoPreprocessor = false; options.CheckedArithmetic = true; options.RunTestSuite = true; options.FileNames = new List <string> { fileNameC }; HostEnvironment hostEnvironment = new HostEnvironment(options.PointerSize); hostEnvironment.Errors += errorHandler.HandleErrors; bool errorsInPreprocessor; var f = CCompilerHelper.Preprocess(options, out errorsInPreprocessor); if (errorsInPreprocessor) { return(-1); } var st = f.First(); test = st.ReadToEnd(); st.Close(); File.Delete(fileNameC); // if (!options.KeepPreprocessorFiles) File.Delete(fileNameI); IName name = hostEnvironment.NameTable.GetNameFor(suiteName); List <IAssemblyReference> assemblyReferences = new List <IAssemblyReference>(); List <IModuleReference> moduleReferences = new List <IModuleReference>(); assemblyReferences.Add(hostEnvironment.LoadAssembly(hostEnvironment.CoreAssemblySymbolicIdentity)); assemblyReferences.Add(hostEnvironment.LoadAssembly(hostEnvironment.VccRuntimeAssemblyIdentity)); VccAssembly /*?*/ assem = null; if (hostEnvironment.previousDocument == null || compilerParameters == null || !compilerParameters.Contains("/incremental")) { List <VccSourceDocument> programSources = new List <VccSourceDocument>(1); assem = new VccAssembly(name, "", hostEnvironment, options, assemblyReferences, moduleReferences, programSources); var helper = new VccCompilationHelper(assem.Compilation); programSources.Add(hostEnvironment.previousDocument = new VccSourceDocument(helper, name, name.ToString(), test)); } VccCommandLineHost.ResetStartTime(); return(VccCommandLineHost.Felt2Cast2Plugin("testcase", options, hostEnvironment, assem)); }