void pMBUfactHandler::writeResults(CFG& cfg, FILE * outf) { { //- write p-MBU results suco_iterator<AO *> aoi(pMBUfactHandler::results); while(aoi.Iterate()){ fprintf(outf, "M "); aoi.Current()->write_string_rep(outf, flag_readable_output); fprintf(outf, "\n"); } } { //- write p-MBU unsafe aos suco_iterator<AO *> aoi(pMBUfactHandler::unsafe); while(aoi.Iterate()){ fprintf(outf, "U "); aoi.Current()->write_string_rep(outf, flag_readable_output); fprintf(outf, "\n"); } } { //- write p-MBU tracked aos suco_iterator<AO *> aoi(pMBUfactHandler::tracked); while(aoi.Iterate()){ fprintf(outf, "T "); aoi.Current()->write_string_rep(outf, flag_readable_output); fprintf(outf, "\n"); } } }
//- collect PMBU unsafe and tracked aos: // unsafe = all (safe) deref aos affected by something in pmbu_results // tracked = all (untracked) locs aliased by a (newly-)unsafe ao void pMBUfactHandler::collectUnsafeTracked(AO& ao) { if(ao.isRef() && (ao.getTSC() > AO::TSC_POSS_INVALID) && (pMBUfactHandler::readwrite || ao.isAssigned())){ suco_set<ECR *> affecrs; ao.getECR().collectAliasECRs(affecrs, true); //- using this, because getAliasECRs filters loc/argret suco_iterator<ECR *> afecri(affecrs); while(afecri.Iterate()){ if(afecri.Current()->getAOset().Intersects(pMBUfactHandler::results)){ //- found pmbu-unsafe ao pMBUfactHandler::unsafe.Insert(&ao); //- collect pmbu-tracked = loc aliases suco_iterator<ECR *> alecri(ao.getECR().getAliasECRs()); while(alecri.Iterate()){ suco_iterator<AO *> aoi(alecri.Current()->getAOset()); while(aoi.Iterate()){ if(aoi.Current()->isLocArgRet() && aoi.Current()->getTSC() == AO::TSC_SAFE){ pMBUfactHandler::tracked.Insert(aoi.Current()); } } } return; } } } }
//- for intra-procedural analysis: initialize fact df for entry node cn // - MBU: fact will be IMOD or GREF set, depending on flag_compute_iref // (i.e., conservatively assume all IREF/GREF variables may be uninitialized) // - NOTE: in IREF mode, it is unsafe at a callsite to correctly check // a called function's GREF against the current fact, which may yield // significantly-improved results --- doesn't seem to happen in practice. // See intraProcHandleCall(). void MBUfactHandler::intraProcInitializeEntryFact(DFAfact& df, CFGnode& cn) { MBUfact& mf = (MBUfact&) df; if(flag_compute_iref){ cn.getParentFunction().getIREF().addToAOset(mf.aoset); } else { cn.getParentFunction().getGREF().addToAOset(mf.aoset); } if(flag_gmodref_skip_locals){ mf.aoset.Union((suco_set<AO *>&)cn.getParentFunction().getLocalVars()); } //-optimization: keep only "relevant" aos: suco_iterator<AO *> aoi(mf.aoset); while(aoi.Iterate()){ AO& ao = *aoi.Current(); if(!ao.dfa_relevant || ((flag_may_be_uninit == 4) && (ao.getEnclosingStruct().isZeroed())) //- if not handling assignments, filter out zeroed aos || (ao.getStaticType() && (ao.getStaticType()->getKind() == TCtype::tcStruct || ao.getStaticType()->getKind() == TCtype::tcUnion))){ //TODO: filter out structs aoi.DeleteCurrent(); } } }
void MBUfactHandler::filterCallsiteFacts(PExprCall& dc, DFAfact& df, DFAfact& df_local) { MBUfact& mbf = (MBUfact&) df; MBUfact& mbf_local = (MBUfact&) df_local; //- 1. move all facts to mbf_local mbf_local.meet(mbf, false); //- 2. filter GREF elements back into mbf //TODO: filter also MayFreed pointers? suco_iterator<CFGfunction *> tfi(dc.getTargetFns()); while(tfi.Iterate()){ suco_iterator<AO *> aoi(mbf_local.aoset); while(aoi.Iterate()){ AO * tao = aoi.Current(); if(tfi.Current()->getGREF().Contains(*tao)){ aoi.DeleteCurrent(); mbf.aoset.Insert(tao); } } } //- 3. specially handle call arguments // for(int i = 1; dc.getArg(i); ++i) // mbf_local.filterInto(dc.getArg(i)->getDesc().getAOs(), mbf); //TODO: migrate to interProcHandleCallArgs below }
QgsPointLocator* QgsSnappingUtils::locatorForLayerUsingStrategy( QgsVectorLayer* vl, const QgsPoint& pointMap, double tolerance ) { QgsRectangle aoi( pointMap.x() - tolerance, pointMap.y() - tolerance, pointMap.x() + tolerance, pointMap.y() + tolerance ); if ( isIndexPrepared( vl, aoi ) ) return locatorForLayer( vl ); else return temporaryLocatorForLayer( vl, pointMap, tolerance ); }
bool MBUc1factHandler::handleVerify(DFAfact& df, PExprVerify& dv) { MBUfact& mf = (MBUfact&) df; //- diagnostic data { int mfsize = mf.length(); TCstats::mbuc_verify_visit_factsizes += mfsize; if(TCstats::mbuc_verify_visit_max_factsize < mfsize) TCstats::mbuc_verify_visit_max_factsize = mfsize; TCstats::mbuc_verify_visits++; } switch(dv.getVtKind()){ case PExprVerify::vtTag: case PExprVerify::vtRhs: { if(mf.intersectsAliases(dv.getAOs())){ //-- include in results // - A. each AO in dv (so their aliases can be marked exposed) // - B. each AO in mf that intersects with dv's AOs (so their delta will be examined) // - A. collect dv's AOs suco_iterator<AO *> aoi(dv.getAOs()); while(aoi.Iterate()){ AO& ao = *aoi.Current(); if(ao.dfa_relevant && ao.getTSC() >= AO::TSC_EXPOSED){ this->results.addFact(ao, &dv); } } // - B. collect AOs in mf that intersect with dv's AOs // - B1. collect dv ECRs suco_set<ECR *> dv_ecrs; suco_iterator<AO *> dvaoi(dv.getAOs()); while(dvaoi.Iterate()){ AO& dvao = *dvaoi.Current(); if(!dvao.isVal()){ dv_ecrs.Insert(&dvao.getECR()); } } // - B2. traverse dv ECRs; helper collectFact will do the work MBUc1factHandler::cf_mf = &mf; MBUc1factHandler::cf_res = &this->results; ECR::traverseSetAliases(dv_ecrs, MBUc1factHandler::collectFact); } } break; case PExprVerify::vtNone: default: break; } // MBUfactHandler::handler.handleVerify(mf, dv); // NOP anyways return false; //- not useless }
bool QgsSnappingUtils::isIndexPrepared( QgsVectorLayer *vl, const QgsRectangle &areaOfInterest ) { if ( vl->geometryType() == QgsWkbTypes::NullGeometry || mStrategy == IndexNeverFull ) return false; QgsPointLocator *loc = locatorForLayer( vl ); if ( mStrategy == IndexAlwaysFull && loc->hasIndex() ) return true; QgsRectangle aoi( areaOfInterest ); aoi.scale( 0.999 ); return ( mStrategy == IndexHybrid || mStrategy == IndexExtent ) && loc->hasIndex() && ( !loc->extent() || loc->extent()->contains( aoi ) ); // the index - even if it exists - is not suitable }
//-- traverse aliases of aoset, add safe and exposed locs // to this. void MBUfact::addRelevantAliasLocs(suco_set<AO *>& laoset) { //-- collect aoset's ecrset suco_set<ECR *> ecrset; suco_iterator<AO *> aoi(laoset); while(aoi.Iterate()) ecrset.Insert(&aoi.Current()->getECR()); //-- set aual_fact MBUfact::aual_fact = this; //-- do traversal ECR::traverseSetAliases(ecrset, MBUfact::add_locs_to_aual_fact); }
bool CHttpServer::parse_route(String const &line, Route &route) { if (line.empty()) return false; const char *s = line.c_str(); if (*s == '/') ++s; const char *application_begin = s; for(; *s != '/' && *s != '\0'; ++s); if (*s == '\0') return false; const char *application_end = s; const char *model_begin = ++s; for(; *s != '/' && *s != '\0'; ++s); const char *model_end = s; route.application.assign(application_begin, application_end); route.model.assign(model_begin, model_end); if (*s == '\0') return true; const char *actionorid_begin = ++s; for (; *s != '/' && *s != '\0'; ++s); const char *actionorid_end = s; if (*s == '/') ++s; String aoi(actionorid_begin, actionorid_end); if (isid(aoi)) { route.id = aoi; route.action = s; } else { route.id = s; route.action = aoi; } //const char* frag = strrchr(route.action.c_str(), '#'); //if (frag) // route.action = route.action.substr(0, frag-route.action.c_str()); return true; }
bool RDAfactHandler::handleWeakAssign(DFAfact& df, ExpDescr& lhs, ExpDescr& /*ignored*/, PExprAssign& dnode) { RDAfact& rf = (RDAfact&) df; //-- collect lhs's ecrset suco_set<ECR *> ecrset; suco_iterator<AO *> aoi(lhs.getAOs()); while(aoi.Iterate()) ecrset.Insert(&aoi.Current()->getECR()); //-- set aual_fact, aual_assign_node RDAfactHandler::aual_fact = &rf; RDAfactHandler::aual_assign_node = &dnode; //-- do traversal ECR::traverseSetAliases(ecrset, RDAfactHandler::add_locs_to_aual_fact); return false; //- not useless }
void MBUfact::debug_dump(FILE * outf, bool brief) { if(is_bot){ fprintf(outf, "bot\n"); } else if(brief){ fprintf(outf, " %d aos\n", this->length()); } else { fprintf(outf, "\n"); suco_iterator<AO *> aoi(aoset); while(aoi.Iterate()){ fprintf(outf, "\t[ "); aoi.Current()->write_string_rep(outf, true); fprintf(outf, " ]\n"); } } }
bool pMBUfactHandler::collectStartingPoints(PgmExpr& pe) { if(pe.getKind() == PgmExpr::fVerify){ PExprVerify& pv = (PExprVerify &)pe; if((pv.getVpKind() == PExprVerify::vpPtrW) || (pMBUfactHandler::readwrite && (pv.getVpKind() == PExprVerify::vpPtr))){ suco_iterator<AO *> aoi(pv.getDesc().getAOs()); while(aoi.Iterate()){ if(aoi.Current()->getTSC() > AO::TSC_POSS_INVALID){ AO * ao = aoi.Current()->derefOneLevel(); if(ao && !ao->isVal()){ pMBUfactHandler::relevant_ecrs.Union(ao->getECR().getAliasECRs()); } } } } } return true; //- continue traversal }
void pMBUfactHandler::doInsensitiveAnalysis(CFG& cfg) { //- 1. collect starting points (into relevant_ecrs) cfg.traverseRootNodes(pMBUfactHandler::collectStartingPoints); //- 2. follow assignment edges backwards suco_set<ECR *> worklist; worklist.Union(pMBUfactHandler::relevant_ecrs); while(!worklist.IsEmpty()){ ECR& ecr = *worklist.RemoveHead(); //- for each ecr in worklist: traverse its aos suco_iterator<AO *> aoi(ecr.getAOset()); while(aoi.Iterate()){ // 1. collect locs in results if(aoi.Current()->isLocArgRet()){ pMBUfactHandler::results.Insert(aoi.Current()); } // 2. follow incl-edges backwards //NOTE: technically, only want to follow "copy" edges, // and skip assignments from a (+) node; but the existence // of such a node would've rendered the starting point // "unsafe", so it should never be encountered!? suco_iterator<TCassignEdge *> edi(aoi.Current()->getIncomingAssignEdges()); while(edi.Iterate()){ ECR& fecr = edi.Current()->getFrom().getECR(); if(!pMBUfactHandler::relevant_ecrs.Contains(&fecr)){ suco_set<ECR *> fecr_aliases; fecr.collectAliasECRs(fecr_aliases); //- using this because getAliasECRs filters loc/arg/ret // fecr_aliases.Subtract(pMBUfactHandler::relevant_ecrs); //-TODO: avoid repetition pMBUfactHandler::relevant_ecrs.Union(fecr_aliases); worklist.UnionConsume(fecr_aliases); } } } } }