bool SemanticRelationData::addRelations(AnalysisContent& analysis) { #ifdef DEBUG_LP SEMANTICANALYSISLOGINIT; #endif auto annotationData = static_cast< AnnotationData* >( analysis.getData("AnnotationData")); if (annotationData->dumpFunction("SemanticRelation") == 0) { annotationData->dumpFunction("SemanticRelation", new DumpSemanticRelation()); } auto recoData=static_cast<RecognizerData*>( analysis.getData("RecognizerData")); for (auto i = m_relations.begin(); i != m_relations.end(); i++) { LinguisticGraphVertex vertex1 = i->get<0>(); LinguisticGraphVertex vertex2 = i->get<1>(); auto matchesVtx1 = annotationData->matches(recoData->getGraphId(), vertex1, "annot"); auto matchesVtx2 = annotationData->matches(recoData->getGraphId(), vertex2, "annot"); if (!annotationData->hasAnnotation(*(matchesVtx1.begin()), *(matchesVtx2.begin()), "SemanticRelation")) { SemanticRelationAnnotation annot(i->get<2>()); GenericAnnotation ga(annot); annotationData->annotate(*(matchesVtx1.begin()), *(matchesVtx2.begin()), "SemanticRelation", ga); } else { auto annot = annotationData->annotation(*(matchesVtx1.begin()), *(matchesVtx2.begin()), "SemanticRelation").pointerValue<SemanticRelationAnnotation>(); SEMANTICANALYSISLOGINIT; LWARN << "SemanticRelationData::addRelations There is already a SemanticRelation between" << *(matchesVtx1.begin()) << "and" << *(matchesVtx2.begin()) << annot->type(); LWARN << "Adding new type" << i->get<2>(); QString type = QString::fromUtf8(annot->type().c_str()); QStringList typeList = type.split(','); typeList << i->get<2>().c_str(); typeList.sort(); typeList.removeDuplicates(); annot->type(typeList.join(',').toUtf8().constData()); LWARN << "Adding type is now" << annot->type(); } } m_relations.clear(); return true; }
void TaskDebugBranchCheck::addFunctionSummaries(BasicBlock* from_bb, BasicBlock* to_bb, Instruction* first_inst) { //errs() << "++++++++++++++++++++DETECTED BRANCHES++++++++++++++++++++++\n"; //errs() << "BB 1 First inst: " << *(from_bb->getFirstNonPHI()) << "\n"; //TerminatorInst *TInst = from_bb->getTerminator(); //errs() << "BB 1 Last inst: " << *TInst << "\n\n"; //errs() << "BB 2 First inst: " << *(to_bb->getFirstNonPHI()) << "\n"; //TInst = to_bb->getTerminator(); //errs() << "BB 2 Last inst: " << *TInst << "\n\n"; //errs() << "++++++++++++++++++++DETECTED BRANCHES++++++++++++++++++++++\n"; std::vector<Value*> locks_acq; std::vector<Value*> locks_rel; bool startInst = false; for (BasicBlock::iterator i = from_bb->begin(); i != from_bb->end(); ++i) { if (startInst == false) { if (first_inst == dyn_cast<Instruction>(i)) { startInst = true; } else { continue; } } switch (i->getOpcode()) { case Instruction::Call: { CallInst* callInst = dyn_cast<CallInst>(i); if(callInst->getCalledFunction() != NULL) { if(callInst->getCalledFunction() == lockAcquire) { locks_acq.push_back(callInst->getArgOperand(1)); } else if (callInst->getCalledFunction() == lockRelease) { locks_rel.push_back(callInst->getArgOperand(1)); } } break; } case Instruction::Load: { //errs() << "LOAD INST " << *i << "\n"; Value* op_l = i->getOperand(0); if (hasAnnotation(i, op_l, "check_av", 1)) { Constant* read = ConstantInt::get(Type::getInt32Ty(to_bb->getContext()), 0); instrument_access(to_bb->getFirstNonPHI(), op_l, read, locks_acq, locks_rel); } break; } case Instruction::Store: { //errs() << "STR INST " << *i << "\n"; Value* op_s = i->getOperand(1); if (hasAnnotation(i, op_s, "check_av", 1)) { Constant* write = ConstantInt::get(Type::getInt32Ty(to_bb->getContext()), 1); instrument_access(to_bb->getFirstNonPHI(), op_s, write, locks_acq, locks_rel); } break; } } } }