Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVFIRBuilder.cpp
Go to the documentation of this file.
1//===- SVFIRBuilder.cpp -- SVFIR builder-----------------------------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-2017> <Yulei Sui>
6//
7
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Affero General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===----------------------------------------------------------------------===//
22
23/*
24 * SVFIRBuilder.cpp
25 *
26 * Created on: Nov 1, 2013
27 * Author: Yulei Sui
28 * Refactored on: Jan 25, 2024
29 * Author: Xiao Cheng, Yulei Sui
30 */
31
33#include "SVF-LLVM/BasicTypes.h"
34#include "SVF-LLVM/CHGBuilder.h"
35#include "SVF-LLVM/CppUtil.h"
37#include "SVF-LLVM/LLVMUtil.h"
41#include "Graphs/CallGraph.h"
42#include "Util/Options.h"
43#include "Util/SVFUtil.h"
44
45using namespace std;
46using namespace SVF;
47using namespace SVFUtil;
48using namespace LLVMUtil;
49
50
55{
56 double startTime = SVFStat::getClk(true);
57
58 DBOUT(DGENERAL, outs() << pasMsg("\t Building SVFIR ...\n"));
59
60 // If the SVFIR has been built before, then we return the unique SVFIR of the program
62 return pag;
63
64
66
69 pag->icfg = icfgbuilder.build();
70
78
79
80
83 std::vector<const FunObjVar*> funset;
84 for (const auto& item: llvmModuleSet()->getFunctionSet())
85 {
87 }
88 pag->callGraph = callGraphBuilder.buildSVFIRCallGraph(funset);
89
90 CHGraph* chg = new CHGraph();
92 chgbuilder.buildCHG();
93 pag->setCHG(chg);
94
97 {
98 for (Module::const_iterator F = M.begin(), E = M.end(); F != E; ++F)
99 {
100 const Function& fun = *F;
101 const FunObjVar* svffun = llvmModuleSet()->getFunObjVar(&fun);
103 if(!fun.isDeclaration())
104 {
110 if (fun.doesNotReturn() == false &&
111 fun.getReturnType()->isVoidTy() == false)
112 {
115 }
116
119 for (Function::const_arg_iterator I = fun.arg_begin(), E = fun.arg_end();
120 I != E; ++I)
121 {
122 setCurrentLocation(&*I,&fun.getEntryBlock());
124 // if this is the function does not have caller (e.g. main)
125 // or a dead function, shall we create a black hole address edge for it?
126 // it is (1) too conservative, and (2) make FormalParmVFGNode defined at blackhole address PAGEdge.
127 // if(SVFUtil::ArgInNoCallerFunction(&*I)) {
128 // if(I->getType()->isPointerTy())
129 // addBlackHoleAddrEdge(argValNodeId);
130 //}
132 }
133 }
134 for (Function::const_iterator bit = fun.begin(), ebit = fun.end();
135 bit != ebit; ++bit)
136 {
137 const BasicBlock& bb = *bit;
138 for (BasicBlock::const_iterator it = bb.begin(), eit = bb.end();
139 it != eit; ++it)
140 {
141 const Instruction& inst = *it;
142 setCurrentLocation(&inst,&bb);
143 visit(const_cast<Instruction&>(inst));
144 }
145 }
146 }
147 }
148
149 sanityCheck();
150
152
154
155 // dump SVFIR
157 pag->dump("svfir_initial");
158
159 // print to command line of the SVFIR graph
160 if (Options::PAGPrint())
161 pag->print();
162
163 // dump ICFG
164 if (Options::DumpICFG())
165 pag->getICFG()->dump("icfg_initial");
166
168 {
171 }
172
173 // dump SVFIR as JSON
174 if (!Options::DumpJson().empty())
175 {
176 assert(false && "please implement SVFIRWriter::writeJsonToPath");
177 }
178
179 double endTime = SVFStat::getClk(true);
180 SVFStat::timeOfBuildingSVFIR = (endTime - startTime) / TIMEINTERVAL;
181
182 return pag;
183}
184
186{
188 {
190 for (const Function& f : mod.functions())
191 {
194
195 if (!LLVMUtil::isExtCall(&f))
196 {
198 }
201 svffun->setRelDefFun(realfun == nullptr ? nullptr : llvmModuleSet()->getFunObjVar(realfun));
202 }
203 }
204
205 // Store annotations of functions in extapi.bc
206 for (const auto& pair : llvmModuleSet()->ExtFun2Annotations)
207 {
209 }
210
211}
212
214{
216 for (Function::const_iterator bit = func->begin(), ebit = func->end(); bit != ebit; ++bit)
217 {
218 const BasicBlock* bb = &*bit;
221 {
224 }
226 {
229 }
230
232 if (svfbb->getSuccessors().empty())
233 {
235 {
237 SVFUtil::isa<ReturnInst>(bb->back())) &&
238 "last inst must be return inst");
239 svfFun->setExitBlock(svfbb);
240 }
241 }
242 }
243 // For no return functions, we set the last block as exit BB
244 // This ensures that each function that has definition must have an exit BB
245 if (svfFun->hasBasicBlock() && svfFun->exitBlock == nullptr)
246 {
247 SVFBasicBlock* retBB = const_cast<SVFBasicBlock*>(svfFun->back());
249 SVFUtil::isa<ReturnInst>(&func->back().back())) &&
250 "last inst must be return inst");
251 svfFun->setExitBlock(retBB);
252 }
253}
254
255
257{
258 if (fun->isDeclaration())
259 return;
260 //process and stored dt & df
263 df.analyze(dt);
265 PostDominatorTree pdt = PostDominatorTree(const_cast<Function&>(*fun));
266 SVFLoopAndDomInfo* ld = svffun->getLoopAndDomInfo();
267
269 for (DominanceFrontierBase::const_iterator dfIter = df.begin(), eDfIter = df.end(); dfIter != eDfIter; dfIter++)
270 {
271 const BasicBlock* keyBB = dfIter->first;
272 const std::set<BasicBlock* >& domSet = dfIter->second;
274 for (const BasicBlock* bbValue:domSet)
275 {
277 }
278 }
279 std::vector<const SVFBasicBlock*> reachableBBs;
280 LLVMUtil::getFunReachableBBs(fun, reachableBBs);
281 ld->setReachableBBs(reachableBBs);
282
283 for (Function::const_iterator bit = fun->begin(), beit = fun->end(); bit!=beit; ++bit)
284 {
285 const BasicBlock &bb = *bit;
287 if (DomTreeNode* dtNode = dt.getNode(&bb))
288 {
289 SVFLoopAndDomInfo::BBSet& bbSet = ld->getDomTreeMap()[svfBB];
290 for (const auto domBB : *dtNode)
291 {
292 const auto* domSVFBB = llvmModuleSet()->getSVFBasicBlock(domBB->getBlock());
293 bbSet.insert(domSVFBB);
294 }
295 }
296
297 if (DomTreeNode* pdtNode = pdt.getNode(&bb))
298 {
299 u32_t level = pdtNode->getLevel();
300 ld->getBBPDomLevel()[svfBB] = level;
301 BasicBlock* idomBB = pdtNode->getIDom()->getBlock();
303 ld->getBB2PIdom()[svfBB] = idom;
304
305 SVFLoopAndDomInfo::BBSet& bbSet = ld->getPostDomTreeMap()[svfBB];
306 for (const auto domBB : *pdtNode)
307 {
308 const auto* domSVFBB = llvmModuleSet()->getSVFBasicBlock(domBB->getBlock());
309 bbSet.insert(domSVFBB);
310 }
311 }
312
313 if (const Loop* loop = loopInfo.getLoopFor(&bb))
314 {
315 for (const BasicBlock* loopBlock : loop->getBlocks())
316 {
318 ld->addToBB2LoopMap(svfBB, loopbb);
319 }
320 }
321 }
322}
323
325{
326 std::vector<FunObjVar*> funset;
327 // Iterate over all object symbols in the symbol table
328 for (const auto* fun: llvmModuleSet()->getFunctionSet())
329 {
330 u32_t id = llvmModuleSet()->objSyms()[fun];
331 // Debug output for adding object node
332 DBOUT(DPAGBuild, outs() << "add obj node " << id << "\n");
333
334 // Check if the value is a function and add a function object node
335 pag->addFunObjNode(id, pag->getObjTypeInfo(id), nullptr);
337
338 FunObjVar *funObjVar = SVFUtil::cast<FunObjVar>(pag->getGNode(id));
339 funset.push_back(funObjVar);
340
341 funObjVar->initFunObjVar(fun->isDeclaration(), LLVMUtil::isIntrinsicFun(fun), fun->hasAddressTaken(),
343 SVFUtil::cast<SVFFunctionType>(llvmModuleSet()->getSVFType(fun->getFunctionType())),
344 new SVFLoopAndDomInfo, nullptr, nullptr,
345 {}, nullptr);
346 BasicBlockGraph* bbGraph = new BasicBlockGraph();
347 funObjVar->setBasicBlockGraph(bbGraph);
348
349
350 for (const BasicBlock& bb : *fun)
351 {
352 llvmModuleSet()->addBasicBlock(funObjVar, &bb);
353 }
354
356 for (auto& bb: *funObjVar->bbGraph)
357 {
358 bb.second->setFun(funObjVar);
359 }
361 }
362
364}
365
367{
368 // Iterate over all object symbols in the symbol table
369 for (LLVMModuleSet::ValueToIDMapTy::iterator iter =
370 llvmModuleSet()->objSyms().begin(); iter != llvmModuleSet()->objSyms().end();
371 ++iter)
372 {
373 // Debug output for adding object node
374 DBOUT(DPAGBuild, outs() << "add obj node " << iter->second << "\n");
375
376 // Skip blackhole and constant symbols
377 if(iter->second == pag->blackholeSymID() || iter->second == pag->constantSymID())
378 continue;
379
380 // Get the LLVM value corresponding to the symbol
381 const Value* llvmValue = iter->first;
382
383 const ICFGNode* icfgNode = nullptr;
384 if (const Instruction* inst = SVFUtil::dyn_cast<Instruction>(llvmValue))
385 {
386 if(llvmModuleSet()->hasICFGNode(inst))
387 icfgNode = llvmModuleSet()->getICFGNode(inst);
388 }
389
390 // Check if the value is a function and add a function object node
391 if (SVFUtil::dyn_cast<Function>(llvmValue))
392 {
393 // already one
394 }
395 // Check if the value is a heap object and add a heap object node
397 {
398 NodeID id = llvmModuleSet()->getObjectNode(iter->first);
399 pag->addHeapObjNode(iter->second, pag->getObjTypeInfo(id), icfgNode);
400 }
401 // Check if the value is an alloca instruction and add a stack object node
403 {
404 NodeID id = llvmModuleSet()->getObjectNode(iter->first);
405 pag->addStackObjNode(iter->second, pag->getObjTypeInfo(id), icfgNode);
406 }
407 else if (auto fpValue = SVFUtil::dyn_cast<ConstantFP>(llvmValue))
408 {
409 NodeID id = llvmModuleSet()->getObjectNode(iter->first);
411 }
412 else if (auto intValue = SVFUtil::dyn_cast<ConstantInt>(llvmValue))
413 {
414 NodeID id = llvmModuleSet()->getObjectNode(iter->first);
416 }
417 else if (SVFUtil::isa<ConstantPointerNull>(llvmValue))
418 {
419 NodeID id = llvmModuleSet()->getObjectNode(iter->first);
420 pag->addConstantNullPtrObjNode(iter->second, pag->getObjTypeInfo(id), icfgNode);
421 }
422 else if (SVFUtil::isa<GlobalValue>(llvmValue))
423 {
424 NodeID id = llvmModuleSet()->getObjectNode(iter->first);
425 pag->addGlobalObjNode(iter->second, pag->getObjTypeInfo(id), icfgNode);
426 }
427 else if (SVFUtil::isa<ConstantData, MetadataAsValue, BlockAddress>(llvmValue))
428 {
429 NodeID id = llvmModuleSet()->getObjectNode(iter->first);
430 pag->addConstantDataObjNode(iter->second, pag->getObjTypeInfo(id), icfgNode);
431 }
432 else if (SVFUtil::isa<ConstantAggregate>(llvmValue))
433 {
434 NodeID id = llvmModuleSet()->getObjectNode(iter->first);
435 pag->addConstantAggObjNode(iter->second, pag->getObjTypeInfo(id), icfgNode);
436 }
437 // Add a generic object node for other types of values
438 else
439 {
440 NodeID id = llvmModuleSet()->getObjectNode(iter->first);
441 pag->addObjNode(iter->second, pag->getObjTypeInfo(id), icfgNode);
442 }
444 }
445
446}
447
449{
450 // Iterate over all value symbols in the symbol table
451 for (LLVMModuleSet::ValueToIDMapTy::iterator iter =
452 llvmModuleSet()->valSyms().begin(); iter != llvmModuleSet()->valSyms().end();
453 ++iter)
454 {
455 // Debug output for adding value node
456 DBOUT(DPAGBuild, outs() << "add val node " << iter->second << "\n");
457
458 // Skip blackhole and null pointer symbols
459 if(iter->second == pag->blkPtrSymID() || iter->second == pag->nullPtrSymID())
460 continue;
461
462 const ICFGNode* icfgNode = nullptr;
463 auto llvmValue = iter->first;
464 if (const Instruction* inst =
465 SVFUtil::dyn_cast<Instruction>(llvmValue))
466 {
467 if (llvmModuleSet()->hasICFGNode(inst))
468 {
469 icfgNode = llvmModuleSet()->getICFGNode(inst);
470 }
471 }
472
473 // Check if the value is a function and get its call graph node
474 if (const Function* func = SVFUtil::dyn_cast<Function>(llvmValue))
475 {
476 // add value node representing the function
477 pag->addFunValNode(iter->second, icfgNode, llvmModuleSet()->getFunObjVar(func), llvmModuleSet()->getSVFType(llvmValue->getType()));
478 }
479 else if (auto argval = SVFUtil::dyn_cast<Argument>(llvmValue))
480 {
482 iter->second, argval->getArgNo(), icfgNode,
483 llvmModuleSet()->getFunObjVar(argval->getParent()),llvmModuleSet()->getSVFType(llvmValue->getType()));
484 if (!argval->hasName())
485 pag->getGNode(iter->second)->setName("arg_" + std::to_string(argval->getArgNo()));
486 }
487 else if (auto fpValue = SVFUtil::dyn_cast<ConstantFP>(llvmValue))
488 {
489 pag->addConstantFPValNode(iter->second, LLVMUtil::getDoubleValue(fpValue), icfgNode, llvmModuleSet()->getSVFType(llvmValue->getType()));
490 }
491 else if (auto intValue = SVFUtil::dyn_cast<ConstantInt>(llvmValue))
492 {
493 pag->addConstantIntValNode(iter->second, LLVMUtil::getIntegerValue(intValue), icfgNode, llvmModuleSet()->getSVFType(llvmValue->getType()));
494 }
495 else if (SVFUtil::isa<ConstantPointerNull>(llvmValue))
496 {
497 pag->addConstantNullPtrValNode(iter->second, icfgNode, llvmModuleSet()->getSVFType(llvmValue->getType()));
498 }
499 else if (SVFUtil::isa<GlobalValue>(llvmValue))
500 {
501 pag->addGlobalValNode(iter->second, icfgNode,
502 llvmModuleSet()->getSVFType(llvmValue->getType()));
503 }
504 else if (SVFUtil::isa<ConstantData, MetadataAsValue, BlockAddress>(llvmValue))
505 {
506 pag->addConstantDataValNode(iter->second, icfgNode, llvmModuleSet()->getSVFType(llvmValue->getType()));
507 }
508 else if (SVFUtil::isa<ConstantAggregate>(llvmValue))
509 {
510 pag->addConstantAggValNode(iter->second, icfgNode, llvmModuleSet()->getSVFType(llvmValue->getType()));
511 }
512 else
513 {
514 // Add value node to PAG
515 pag->addValNode(iter->second, llvmModuleSet()->getSVFType(llvmValue->getType()), icfgNode);
516 }
518 pag->getGNode(iter->second));
519 }
520}
521
522
523/*
524 * Initial all the nodes from symbol table
525 */
527{
528 DBOUT(DPAGBuild, outs() << "Initialise SVFIR Nodes ...\n");
529
530
535
538
539 for (LLVMModuleSet::FunToIDMapTy::iterator iter =
540 llvmModuleSet()->retSyms().begin(); iter != llvmModuleSet()->retSyms().end();
541 ++iter)
542 {
543 const Value* llvmValue = iter->first;
544 const ICFGNode* icfgNode = nullptr;
545 if (const Instruction* inst = SVFUtil::dyn_cast<Instruction>(llvmValue))
546 {
547 if(llvmModuleSet()->hasICFGNode(inst))
548 icfgNode = llvmModuleSet()->getICFGNode(inst);
549 }
550 DBOUT(DPAGBuild, outs() << "add ret node " << iter->second << "\n");
551 pag->addRetNode(iter->second,
552 llvmModuleSet()->getFunObjVar(SVFUtil::cast<Function>(llvmValue)),
553 llvmModuleSet()->getSVFType(iter->first->getType()), icfgNode);
555 const FunObjVar* funObjVar = llvmModuleSet()->getFunObjVar(SVFUtil::cast<Function>(llvmValue));
556 pag->returnFunObjSymMap[funObjVar] = iter->second;
557 }
558
559 for (LLVMModuleSet::FunToIDMapTy::iterator iter =
560 llvmModuleSet()->varargSyms().begin();
561 iter != llvmModuleSet()->varargSyms().end(); ++iter)
562 {
563 const Value* llvmValue = iter->first;
564
565 const ICFGNode *icfgNode = nullptr;
566 if (const Instruction *inst = SVFUtil::dyn_cast<Instruction>(llvmValue))
567 {
568 if (llvmModuleSet()->hasICFGNode(inst))
569 icfgNode = llvmModuleSet()->getICFGNode(inst);
570 }
571 DBOUT(DPAGBuild, outs() << "add vararg node " << iter->second << "\n");
572 pag->addVarargNode(iter->second,
573 llvmModuleSet()->getFunObjVar(SVFUtil::cast<Function>(llvmValue)),
574 llvmModuleSet()->getSVFType(iter->first->getType()), icfgNode);
576 const FunObjVar* funObjVar = llvmModuleSet()->getFunObjVar(SVFUtil::cast<Function>(llvmValue));
577 pag->varargFunObjSymMap[funObjVar] = iter->second;
578 }
579
581 for (LLVMModuleSet::ValueToIDMapTy::iterator iter =
582 llvmModuleSet()->objSyms().begin(); iter != llvmModuleSet()->objSyms().end(); ++iter)
583 {
584 DBOUT(DPAGBuild, outs() << "add address edges for constant node " << iter->second << "\n");
585 const Value* val = iter->first;
587 {
589 if(ptr!= pag->getBlkPtr() && ptr!= pag->getNullPtr())
590 {
592 addAddrEdge(iter->second, ptr);
593 }
594 }
595 }
596
598 && "not all node have been initialized!!!");
599
601 for (auto& fun: llvmModuleSet()->getFunctionSet())
602 {
603 for (const Argument& arg : fun->args())
604 {
605 const_cast<FunObjVar*>(llvmModuleSet()->getFunObjVar(fun))->addArgument(SVFUtil::cast<ArgValVar>(
607 }
608 }
609
610}
611
612/*
613 https://github.com/SVF-tools/SVF/issues/524
614 Handling single value types, for constant index, including pointer, integer, etc
615 e.g. field_idx = getelementptr i8, %i8* %p, i64 -4
616 We can obtain the field index by inferring the byteoffset if %p is casted from a pointer to a struct
617 For another example, the following can be an array access.
618 e.g. field_idx = getelementptr i8, %struct_type %p, i64 1
619
620*/
622{
623 return 0;
624}
625
633{
634 assert(V);
635
636 const llvm::GEPOperator *gepOp = SVFUtil::dyn_cast<const llvm::GEPOperator>(V);
637 DataLayout * dataLayout = getDataLayout(llvmModuleSet()->getMainLLVMModule());
638 llvm::APInt byteOffset(dataLayout->getIndexSizeInBits(gepOp->getPointerAddressSpace()),0,true);
639 if(gepOp && dataLayout && gepOp->accumulateConstantOffset(*dataLayout,byteOffset))
640 {
641 //s32_t bo = byteOffset.getSExtValue();
642 }
643
644 bool isConst = true;
645
646 bool prevPtrOperand = false;
647 for (bridge_gep_iterator gi = bridge_gep_begin(*V), ge = bridge_gep_end(*V);
648 gi != ge; ++gi)
649 {
650 const Type* gepTy = *gi;
652
653 assert((prevPtrOperand && svfGepTy->isPointerTy()) == false &&
654 "Expect no more than one gep operand to be of a pointer type");
655 if(!prevPtrOperand && svfGepTy->isPointerTy()) prevPtrOperand = true;
656 const Value* offsetVal = gi.getOperand();
657 assert(gepTy != offsetVal->getType() && "iteration and operand have the same type?");
659
660 //The int value of the current index operand
661 const ConstantInt* op = SVFUtil::dyn_cast<ConstantInt>(offsetVal);
662
663 // if Options::ModelConsts() is disabled. We will treat whole array as one,
664 // but we can distinguish different field of an array of struct, e.g. s[1].f1 is different from s[0].f2
665 if(const ArrayType* arrTy = SVFUtil::dyn_cast<ArrayType>(gepTy))
666 {
667 if(!op || (arrTy->getArrayNumElements() <= (u32_t)LLVMUtil::getIntegerValue(op).first))
668 continue;
672 }
673 else if (const StructType *ST = SVFUtil::dyn_cast<StructType>(gepTy))
674 {
675 assert(op && "non-const offset accessing a struct");
676 //The actual index
680 }
681 else if (gepTy->isSingleValueType())
682 {
683 // If it's a non-constant offset access
684 // If its point-to target is struct or array, it's likely an array accessing (%result = gep %struct.A* %a, i32 %non-const-index)
685 // If its point-to target is single value (pointer arithmetic), then it's a variant gep (%result = gep i8* %p, i32 %non-const-index)
686 if(!op && gepTy->isPointerTy() && gepOp->getSourceElementType()->isSingleValueType())
687 {
688 isConst = false;
689 }
690
691 // The actual index
692 //s32_t idx = op->getSExtValue();
693
694 // For pointer arithmetic we ignore the byte offset
695 // consider using inferFieldIdxFromByteOffset(geopOp,dataLayout,ap,idx)?
696 // ap.setFldIdx(ap.getConstantFieldIdx() + inferFieldIdxFromByteOffset(geopOp,idx));
697 }
698 }
699 return isConst;
700}
701
706{
707 if (const Constant* ref = SVFUtil::dyn_cast<Constant>(val))
708 {
710 {
711 DBOUT(DPAGBuild, outs() << "handle gep constant expression " << llvmModuleSet()->getSVFValue(ref)->toString() << "\n");
712 const Constant* opnd = gepce->getOperand(0);
713 // handle recursive constant express case (gep (bitcast (gep X 1)) 1)
715 auto &GEPOp = llvm::cast<llvm::GEPOperator>(*gepce);
716 Type *pType = GEPOp.getSourceElementType();
717 AccessPath ap(0, llvmModuleSet()->getSVFType(pType));
718 bool constGep = computeGepOffset(gepce, ap);
719 // must invoke pag methods here, otherwise it will be a dead recursion cycle
720 const Value* cval = getCurrentValue();
721 const SVFBasicBlock* cbb = getCurrentBB();
723 /*
724 * The gep edge created are like constexpr (same edge may appear at multiple callsites)
725 * so bb/inst of this edge may be rewritten several times, we treat it as global here.
726 */
729 }
730 else if (const ConstantExpr* castce = isCastConstantExpr(ref))
731 {
732 DBOUT(DPAGBuild, outs() << "handle cast constant expression " << llvmModuleSet()->getSVFValue(ref)->toString() << "\n");
733 const Constant* opnd = castce->getOperand(0);
735 const Value* cval = getCurrentValue();
736 const SVFBasicBlock* cbb = getCurrentBB();
740 }
742 {
743 DBOUT(DPAGBuild, outs() << "handle select constant expression " << llvmModuleSet()->getSVFValue(ref)->toString() << "\n");
744 const Constant* src1 = selectce->getOperand(1);
745 const Constant* src2 = selectce->getOperand(2);
748 const Value* cval = getCurrentValue();
749 const SVFBasicBlock* cbb = getCurrentBB();
751 NodeID cond = llvmModuleSet()->getValueNode(selectce->getOperand(0));
757 }
758 // if we meet a int2ptr, then it points-to black hole
760 {
761 const Constant* opnd = int2Ptrce->getOperand(0);
763 const SVFBasicBlock* cbb = getCurrentBB();
764 const Value* cval = getCurrentValue();
768 }
770 {
771 const Constant* opnd = ptr2Intce->getOperand(0);
773 const SVFBasicBlock* cbb = getCurrentBB();
774 const Value* cval = getCurrentValue();
778 }
780 {
781 // we don't handle trunc and cmp instruction for now
782 const Value* cval = getCurrentValue();
783 const SVFBasicBlock* cbb = getCurrentBB();
788 }
789 else if (isBinaryConstantExpr(ref))
790 {
791 // we don't handle binary constant expression like add(x,y) now
792 const Value* cval = getCurrentValue();
793 const SVFBasicBlock* cbb = getCurrentBB();
798 }
799 else if (isUnaryConstantExpr(ref))
800 {
801 // we don't handle unary constant expression like fneg(x) now
802 const Value* cval = getCurrentValue();
803 const SVFBasicBlock* cbb = getCurrentBB();
808 }
809 else if (SVFUtil::isa<ConstantAggregate>(ref))
810 {
811 // we don't handle constant aggregate like constant vectors
812 }
813 else if (SVFUtil::isa<BlockAddress>(ref))
814 {
815 // blockaddress instruction (e.g. i8* blockaddress(@run_vm, %182))
816 // is treated as constant data object for now, see LLVMUtil.h:397, SymbolTableInfo.cpp:674 and SVFIRBuilder.cpp:183-194
817 const Value* cval = getCurrentValue();
818 const SVFBasicBlock* cbb = getCurrentBB();
823 }
824 else
825 {
826 if(SVFUtil::isa<ConstantExpr>(val))
827 assert(false && "we don't handle all other constant expression for now!");
828 }
829 }
830}
837{
838
839 // if the global variable do not have any field needs to be initialized
840 if (offset == 0 && gvar->getInitializer()->getType()->isSingleValueType())
841 {
842 return getValueNode(gvar);
843 }
846 else
847 {
849 }
850}
851
852/*For global variable initialization
853 * Give a simple global variable
854 * int x = 10; // store 10 x (constant, non pointer) |
855 * int *y = &x; // store x y (pointer type)
856 * Given a struct
857 * struct Z { int s; int *t;};
858 * Global initialization:
859 * struct Z z = {10,&x}; // store x z.t (struct type)
860 * struct Z *m = &z; // store z m (pointer type)
861 * struct Z n = {10,&z.s}; // store z.s n , &z.s constant expression (constant expression)
862 */
865{
866 DBOUT(DPAGBuild, outs() << "global " << llvmModuleSet()->getSVFValue(gvar)->toString() << " constant initializer: " << llvmModuleSet()->getSVFValue(C)->toString() << "\n");
867 if (C->getType()->isSingleValueType())
868 {
869 NodeID src = getValueNode(C);
870 // get the field value if it is available, otherwise we create a dummy field node.
872 NodeID field = getGlobalVarField(gvar, offset, llvmModuleSet()->getSVFType(C->getType()));
873
874 if (SVFUtil::isa<GlobalVariable, Function>(C))
875 {
877 addStoreEdge(src, field);
878 }
879 else if (SVFUtil::isa<ConstantExpr>(C))
880 {
881 // add gep edge of C1 itself is a constant expression
882 processCE(C);
884 addStoreEdge(src, field);
885 }
886 else if (SVFUtil::isa<BlockAddress>(C))
887 {
888 // blockaddress instruction (e.g. i8* blockaddress(@run_vm, %182))
889 // is treated as constant data object for now, see LLVMUtil.h:397, SymbolTableInfo.cpp:674 and SVFIRBuilder.cpp:183-194
890 processCE(C);
893 }
894 else
895 {
897 addStoreEdge(src, field);
899 if (C->getType()->isPtrOrPtrVectorTy() && src != pag->getNullPtr())
901 }
902 }
903 else if (SVFUtil::isa<ConstantArray, ConstantStruct>(C))
904 {
906 return;
907 for (u32_t i = 0, e = C->getNumOperands(); i != e; i++)
908 {
910 InitialGlobal(gvar, SVFUtil::cast<Constant>(C->getOperand(i)), offset + off);
911 }
912 }
913 else if(ConstantData* data = SVFUtil::dyn_cast<ConstantData>(C))
914 {
916 {
917 if(ConstantDataSequential* seq = SVFUtil::dyn_cast<ConstantDataSequential>(data))
918 {
919 for(u32_t i = 0; i < seq->getNumElements(); i++)
920 {
921 u32_t off = pag->getFlattenedElemIdx(llvmModuleSet()->getSVFType(C->getType()), i);
922 Constant* ct = seq->getElementAsConstant(i);
924 }
925 }
926 else
927 {
928 assert((SVFUtil::isa<ConstantAggregateZero, UndefValue>(data)) && "Single value type data should have been handled!");
929 }
930 }
931 }
932 else
933 {
934 //TODO:assert(SVFUtil::isa<ConstantVector>(C),"what else do we have");
935 }
936}
937
942{
943
946 {
947 for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
948 {
949 GlobalVariable *gvar = &*I;
952
955
956 if (gvar->hasInitializer())
957 {
958 Constant *C = gvar->getInitializer();
959 DBOUT(DPAGBuild, outs() << "add global var node " << llvmModuleSet()->getSVFValue(gvar)->toString() << "\n");
960 InitialGlobal(gvar, C, 0);
961 }
962 }
963
964
966 for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I)
967 {
968 const Function* fun = &*I;
969 NodeID idx = getValueNode(fun);
970 NodeID obj = getObjectNode(fun);
971
972 DBOUT(DPAGBuild, outs() << "add global function node " << fun->getName().str() << "\n");
973 setCurrentLocation(fun, (SVFBasicBlock*) nullptr);
975 }
976
977 // Handle global aliases (due to linkage of multiple bc files), e.g., @x = internal alias @y. We need to add a copy from y to x.
978 for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end(); I != E; I++)
979 {
980 const GlobalAlias* alias = &*I;
981 NodeID dst = llvmModuleSet()->getValueNode(alias);
982 NodeID src = llvmModuleSet()->getValueNode(alias->getAliasee());
983 processCE(alias->getAliasee());
984 setCurrentLocation(alias, (SVFBasicBlock*) nullptr);
986 }
987 }
988}
989
995{
996
997 // AllocaInst should always be a pointer type
998 assert(SVFUtil::isa<PointerType>(inst.getType()));
999
1000 DBOUT(DPAGBuild, outs() << "process alloca " << llvmModuleSet()->getSVFValue(&inst)->toString() << " \n");
1001 NodeID dst = getValueNode(&inst);
1002
1003 NodeID src = getObjectNode(&inst);
1004
1005 addAddrWithStackArraySz(src, dst, inst);
1006
1007}
1008
1013{
1014
1015 DBOUT(DPAGBuild, outs() << "process phi " << llvmModuleSet()->getSVFValue(&inst)->toString() << " \n");
1016
1017 NodeID dst = getValueNode(&inst);
1018
1019 for (u32_t i = 0; i < inst.getNumIncomingValues(); ++i)
1020 {
1021 const Value* val = inst.getIncomingValue(i);
1022 const Instruction* incomingInst = SVFUtil::dyn_cast<Instruction>(val);
1023 bool matched = (incomingInst == nullptr ||
1024 incomingInst->getFunction() == inst.getFunction());
1025 (void) matched; // Suppress warning of unused variable under release build
1026 assert(matched && "incomingInst's Function incorrect");
1027 const Instruction* predInst = &inst.getIncomingBlock(i)->back();
1028 const ICFGNode* icfgNode = llvmModuleSet()->getICFGNode(predInst);
1029 NodeID src = getValueNode(val);
1030 addPhiStmt(dst,src,icfgNode);
1031 }
1032}
1033
1034/*
1035 * Visit load instructions
1036 */
1038{
1039 DBOUT(DPAGBuild, outs() << "process load " << llvmModuleSet()->getSVFValue(&inst)->toString() << " \n");
1040
1041 NodeID dst = getValueNode(&inst);
1042
1043 NodeID src = getValueNode(inst.getPointerOperand());
1044
1045 addLoadEdge(src, dst);
1046}
1047
1052{
1053 // StoreInst itself should always not be a pointer type
1054 assert(!SVFUtil::isa<PointerType>(inst.getType()));
1055
1056 DBOUT(DPAGBuild, outs() << "process store " << llvmModuleSet()->getSVFValue(&inst)->toString() << " \n");
1057
1058 NodeID dst = getValueNode(inst.getPointerOperand());
1059
1060 NodeID src = getValueNode(inst.getValueOperand());
1061
1062 addStoreEdge(src, dst);
1063
1064}
1065
1070{
1071
1072 NodeID dst = getValueNode(&inst);
1073 // GetElementPtrInst should always be a pointer or a vector contains pointers
1074 // for now we don't handle vector type here
1075 if(SVFUtil::isa<VectorType>(inst.getType()))
1076 {
1078 return;
1079 }
1080
1081 assert(SVFUtil::isa<PointerType>(inst.getType()));
1082
1083 DBOUT(DPAGBuild, outs() << "process gep " << llvmModuleSet()->getSVFValue(&inst)->toString() << " \n");
1084
1085 NodeID src = getValueNode(inst.getPointerOperand());
1086
1087 AccessPath ap(0, llvmModuleSet()->getSVFType(inst.getSourceElementType()));
1088 bool constGep = computeGepOffset(&inst, ap);
1089 addGepEdge(src, dst, ap, constGep);
1090}
1091
1092/*
1093 * Visit cast instructions
1094 */
1096{
1097
1098 DBOUT(DPAGBuild, outs() << "process cast " << llvmModuleSet()->getSVFValue(&inst)->toString() << " \n");
1099 NodeID dst = getValueNode(&inst);
1100
1101 const Value* opnd = inst.getOperand(0);
1102 NodeID src = getValueNode(opnd);
1103 addCopyEdge(src, dst, getCopyKind(&inst));
1104}
1105
1110{
1111 NodeID dst = getValueNode(&inst);
1112 assert(inst.getNumOperands() == 2 && "not two operands for BinaryOperator?");
1113 Value* op1 = inst.getOperand(0);
1115 Value* op2 = inst.getOperand(1);
1117 u32_t opcode = inst.getOpcode();
1118 addBinaryOPEdge(op1Node, op2Node, dst, opcode);
1119}
1120
1125{
1126 NodeID dst = getValueNode(&inst);
1127 assert(inst.getNumOperands() == 1 && "not one operand for Unary instruction?");
1128 Value* opnd = inst.getOperand(0);
1129 NodeID src = getValueNode(opnd);
1130 u32_t opcode = inst.getOpcode();
1131 addUnaryOPEdge(src, dst, opcode);
1132}
1133
1138{
1139 NodeID dst = getValueNode(&inst);
1140 assert(inst.getNumOperands() == 2 && "not two operands for compare instruction?");
1141 Value* op1 = inst.getOperand(0);
1143 Value* op2 = inst.getOperand(1);
1145 u32_t predicate = inst.getPredicate();
1146 addCmpEdge(op1Node, op2Node, dst, predicate);
1147}
1148
1149
1154{
1155
1156 DBOUT(DPAGBuild, outs() << "process select " << llvmModuleSet()->getSVFValue(&inst)->toString() << " \n");
1157
1158 NodeID dst = getValueNode(&inst);
1159 NodeID src1 = getValueNode(inst.getTrueValue());
1160 NodeID src2 = getValueNode(inst.getFalseValue());
1161 NodeID cond = getValueNode(inst.getCondition());
1163 addSelectStmt(dst,src1,src2, cond);
1164}
1165
1170
1175
1180
1181/*
1182 * Visit callsites
1183 */
1185{
1186
1187 // skip llvm intrinsics
1188 if(isIntrinsicInst(cs))
1189 return;
1190
1192 outs() << "process callsite " << svfcall->valueOnlyToString() << "\n");
1193
1194
1195 CallICFGNode* callBlockNode = llvmModuleSet()->getCallICFGNode(cs);
1197
1198 pag->addCallSite(callBlockNode);
1199
1201 for (u32_t i = 0; i < cs->arg_size(); i++)
1203 callBlockNode,
1204 SVFUtil::cast<ValVar>(pag->getGNode(getValueNode(cs->getArgOperand(i)))));
1205
1206 if(!cs->getType()->isVoidTy())
1208
1209 if (callBlockNode->isVirtualCall())
1210 {
1211 const Value* value = cppUtil::getVCallVtblPtr(cs);
1212 callBlockNode->setVtablePtr(pag->getGNode(getValueNode(value)));
1213 }
1214 if (const Function *callee = LLVMUtil::getCallee(cs))
1215 {
1217 {
1218 handleExtCall(cs, callee);
1219 }
1220 else
1221 {
1223 }
1224 }
1225 else
1226 {
1227 //If the callee was not identified as a function (null F), this is indirect.
1228 handleIndCall(cs);
1229 }
1230}
1231
1236{
1237
1238 // ReturnInst itself should always not be a pointer type
1239 assert(!SVFUtil::isa<PointerType>(inst.getType()));
1240
1241 DBOUT(DPAGBuild, outs() << "process return " << llvmModuleSet()->getSVFValue(&inst)->toString() << " \n");
1242
1243 if(Value* src = inst.getReturnValue())
1244 {
1245 const FunObjVar *F = llvmModuleSet()->getFunObjVar(inst.getParent()->getParent());
1246
1248 NodeID vnS = getValueNode(src);
1249 const ICFGNode* icfgNode = llvmModuleSet()->getICFGNode(&inst);
1250 //vnS may be null if src is a null ptr
1251 addPhiStmt(rnF,vnS,icfgNode);
1252 }
1253}
1254
1255
1269
1283
1289{
1290 NodeID brinst = getValueNode(&inst);
1291 NodeID cond;
1292 if (inst.isConditional())
1293 cond = getValueNode(inst.getCondition());
1294 else
1295 cond = pag->getNullPtr();
1296
1297 assert(inst.getNumSuccessors() <= 2 && "if/else has more than two branches?");
1298
1300 std::vector<const Instruction*> nextInsts;
1302 u32_t branchID = 0;
1303 for (const Instruction* succInst : nextInsts)
1304 {
1305 assert(branchID <= 1 && "if/else has more than two branches?");
1306 const ICFGNode* icfgNode = llvmModuleSet()->getICFGNode(succInst);
1307 successors.push_back(std::make_pair(icfgNode, 1-branchID));
1308 branchID++;
1309 }
1310 addBranchStmt(brinst, cond, successors);
1312 if (inst.isConditional())
1313 {
1314 for (auto& edge : llvmModuleSet()->getICFGNode(&inst)->getOutEdges())
1315 {
1316 if (IntraCFGEdge* intraEdge = SVFUtil::dyn_cast<IntraCFGEdge>(edge))
1317 {
1318 intraEdge->setConditionVar(pag->getGNode(cond));
1319 }
1320 }
1321 }
1322}
1323
1324
1368
1371{
1372 NodeID brinst = getValueNode(&inst);
1373 NodeID cond = getValueNode(inst.getCondition());
1374
1376 std::vector<const Instruction*> nextInsts;
1378 for (const Instruction* succInst : nextInsts)
1379 {
1381 const ConstantInt* condVal = inst.findCaseDest(const_cast<BasicBlock*>(succInst->getParent()));
1383 s64_t val = -1;
1384 if (condVal && condVal->getBitWidth() <= 64)
1386 const ICFGNode* icfgNode = llvmModuleSet()->getICFGNode(succInst);
1387 successors.push_back(std::make_pair(icfgNode, val));
1388 }
1389 addBranchStmt(brinst, cond, successors);
1391 for (auto& edge : llvmModuleSet()->getICFGNode(&inst)->getOutEdges())
1392 {
1393 if (IntraCFGEdge* intraEdge = SVFUtil::dyn_cast<IntraCFGEdge>(edge))
1394 {
1395 intraEdge->setConditionVar(pag->getGNode(cond));
1396 }
1397 }
1398}
1399
1400
1407{
1408 NodeID dst = getValueNode(&inst);
1409 Value* opnd = inst.getPointerOperand();
1410 NodeID src = getValueNode(opnd);
1411 addCopyEdge(src, dst, CopyStmt::COPYVAL);
1412}
1413
1419{
1420 NodeID dst = getValueNode(&inst);
1421 for (u32_t i = 0; i < inst.getNumOperands(); i++)
1422 {
1423 Value* opnd = inst.getOperand(i);
1424 NodeID src = getValueNode(opnd);
1425 addCopyEdge(src, dst, CopyStmt::COPYVAL);
1426 }
1427}
1428
1429
1434{
1435
1436 assert(F);
1440 outs() << "handle direct call " << LLVMUtil::dumpValue(cs) << " callee " << F->getName().str() << "\n");
1441
1442 //Only handle the ret.val. if it's used as a ptr.
1444 //Does it actually return a ptr?
1445 if (!cs->getType()->isVoidTy())
1446 {
1450 }
1451 //Iterators for the actual and formal parameters
1452 u32_t itA = 0, ieA = cs->arg_size();
1453 Function::const_arg_iterator itF = F->arg_begin(), ieF = F->arg_end();
1454 //Go through the fixed parameters.
1455 DBOUT(DPAGBuild, outs() << " args:");
1456 for (; itF != ieF; ++itA, ++itF)
1457 {
1458 //Some programs (e.g. Linux kernel) leave unneeded parameters empty.
1459 if (itA == ieA)
1460 {
1461 DBOUT(DPAGBuild, outs() << " !! not enough args\n");
1462 break;
1463 }
1464 const Value* AA = cs->getArgOperand(itA), *FA = &*itF; //current actual/formal arg
1465
1466 DBOUT(DPAGBuild, outs() << "process actual parm " << llvmModuleSet()->getSVFValue(AA)->toString() << " \n");
1467
1472 }
1473 //Any remaining actual args must be varargs.
1474 if (F->isVarArg())
1475 {
1477 DBOUT(DPAGBuild, outs() << "\n varargs:");
1478 for (; itA != ieA; ++itA)
1479 {
1480 const Value* AA = cs->getArgOperand(itA);
1484 }
1485 }
1486 if(itA != ieA)
1487 {
1490 writeWrnMsg("too many args to non-vararg func.");
1491 writeWrnMsg("(" + callICFGNode->getSourceLoc() + ")");
1492
1493 }
1494}
1495
1528{
1529 const Value* value = stripAllCasts(V);
1530 assert(value && "null ptr?");
1531 if(const GetElementPtrInst* gep = SVFUtil::dyn_cast<GetElementPtrInst>(value))
1532 {
1533 APOffset totalidx = 0;
1534 for (bridge_gep_iterator gi = bridge_gep_begin(gep), ge = bridge_gep_end(gep); gi != ge; ++gi)
1535 {
1536 if(const ConstantInt* op = SVFUtil::dyn_cast<ConstantInt>(gi.getOperand()))
1538 }
1539 if(totalidx == 0 && !SVFUtil::isa<StructType>(value->getType()))
1540 value = gep->getPointerOperand();
1541 }
1542 else if (const LoadInst* load = SVFUtil::dyn_cast<LoadInst>(value))
1543 {
1544 const Value* loadP = load->getPointerOperand();
1545 if (const GetElementPtrInst* gep = SVFUtil::dyn_cast<GetElementPtrInst>(loadP))
1546 {
1547 APOffset totalidx = 0;
1548 for (bridge_gep_iterator gi = bridge_gep_begin(gep), ge = bridge_gep_end(gep); gi != ge; ++gi)
1549 {
1550 if(const ConstantInt* op = SVFUtil::dyn_cast<ConstantInt>(gi.getOperand()))
1552 }
1553 const Value * pointer_operand = gep->getPointerOperand();
1554 if (auto *glob = SVFUtil::dyn_cast<GlobalVariable>(pointer_operand))
1555 {
1556 if (glob->hasInitializer())
1557 {
1558 if (auto *initializer = SVFUtil::dyn_cast<
1559 ConstantStruct>(glob->getInitializer()))
1560 {
1561 /*
1562 *@conststruct = internal global <{ [40 x i8], [4 x i8], [4 x i8], [2512 x i8] }>
1563 <{ [40 x i8] undef, [4 x i8] zeroinitializer, [4 x i8] undef, [2512 x i8] zeroinitializer }>, align 8
1564
1565 %0 = load ptr, ptr getelementptr inbounds (<{ [40 x i8], [4 x i8], [4 x i8], [2512 x i8] }>,
1566 ptr @conststruct, i64 0, i32 0, i64 16)
1567 in this case, totalidx is 16 while initializer->getNumOperands() is 4, so we return value as the base
1568 */
1569 if (totalidx >= initializer->getNumOperands()) return value;
1570 auto *ptrField = initializer->getOperand(totalidx);
1571 if (auto *ptrValue = SVFUtil::dyn_cast<llvm::GlobalVariable>(ptrField))
1572 {
1573 return ptrValue;
1574 }
1575 }
1576 }
1577 }
1578 }
1579 }
1580
1581 return value;
1582}
1583
1588{
1590 NodeID indFunPtrId = llvmModuleSet()->getValueNode(cs->getCalledOperand());
1591 const_cast<CallICFGNode*>(cbn)->setIndFunPtr(pag->getGNode(indFunPtrId));
1593}
1594
1596{
1597 CallGraph::CallEdgeMap::const_iterator iter = callgraph->getIndCallMap().begin();
1598 CallGraph::CallEdgeMap::const_iterator eiter = callgraph->getIndCallMap().end();
1599 for (; iter != eiter; iter++)
1600 {
1601 const CallICFGNode* callBlock = iter->first;
1602 const CallBase* callbase = SVFUtil::cast<CallBase>(llvmModuleSet()->getLLVMValue(callBlock));
1603 assert(callBlock->isIndirectCall() && "this is not an indirect call?");
1604 const CallGraph::FunctionSet& functions = iter->second;
1605 for (CallGraph::FunctionSet::const_iterator func_iter = functions.begin(); func_iter != functions.end(); func_iter++)
1606 {
1607 const Function* callee = SVFUtil::cast<Function>(llvmModuleSet()->getLLVMValue(*func_iter));
1608
1609 if (isExtCall(*func_iter))
1610 {
1611 setCurrentLocation(callee, callee->empty() ? nullptr : &callee->getEntryBlock());
1613 }
1614 else
1615 {
1616 setCurrentLocation(llvmModuleSet()->getLLVMValue(callBlock), callBlock->getBB());
1617 handleDirectCall(const_cast<CallBase*>(callbase), callee);
1618 }
1619 }
1620 }
1621
1622 // dump SVFIR
1624 pag->dump("svfir_final");
1625}
1626
1627/*
1628 * TODO: more sanity checks might be needed here
1629 */
1631{
1632 for (SVFIR::iterator nIter = pag->begin(); nIter != pag->end(); ++nIter)
1633 {
1634 (void) pag->getGNode(nIter->first);
1635 //TODO::
1636 // (1) every source(root) node of a pag tree should be object node
1637 // if a node has no incoming edge, but has outgoing edges
1638 // then it has to be an object node.
1639 // (2) make sure every variable should be initialized
1640 // otherwise it causes the a null pointer, the aliasing relation may not be captured
1641 // when loading a pointer value should make sure
1642 // some value has been store into this pointer before
1643 // q = load p, some value should stored into p first like store w p;
1644 // (3) make sure PAGNode should not have a const expr value (pointer should have unique def)
1645 // (4) look closely into addComplexConsForExt, make sure program locations(e.g.,inst bb)
1646 // are set correctly for dummy gepval node
1647 // (5) reduce unnecessary copy edge (const casts) and ensure correctness.
1648 }
1649}
1650
1651
1657{
1658 NodeID base = getValueNode(val);
1660 if (gepval==UINT_MAX)
1661 {
1662 assert(((int) UINT_MAX)==-1 && "maximum limit of unsigned int is not -1?");
1663 /*
1664 * getGepValVar can only be called from two places:
1665 * 1. SVFIRBuilder::addComplexConsForExt to handle external calls
1666 * 2. SVFIRBuilder::getGlobalVarField to initialize global variable
1667 * so curVal can only be
1668 * 1. Instruction
1669 * 2. GlobalVariable
1670 */
1671 assert(
1672 (SVFUtil::isa<Instruction>(curVal) || SVFUtil::isa<GlobalVariable>(curVal)) && "curVal not an instruction or a globalvariable?");
1673
1674 // We assume every GepValNode and its GepEdge to the baseNode are unique across the whole program
1675 // We preserve the current BB information to restore it after creating the gepNode
1676 const Value* cval = getCurrentValue();
1677 const SVFBasicBlock* cbb = getCurrentBB();
1680 const ICFGNode* node = nullptr;
1681 if (const Instruction* inst = SVFUtil::dyn_cast<Instruction>(curVal))
1682 if (llvmmodule->hasICFGNode(inst))
1683 {
1684 node = llvmmodule->getICFGNode(inst);
1685 }
1687 NodeIDAllocator::get()->allocateValueId(),
1688 llvmmodule->getSVFType(PointerType::getUnqual(llvmmodule->getContext())), node);
1689 addGepEdge(base, gepNode, ap, true);
1691 return gepNode;
1692 }
1693 else
1694 return gepval;
1695}
1696
1697
1698/*
1699 * curVal <--------> PAGEdge
1700 * Instruction Any Edge
1701 * Argument CopyEdge (SVFIR::addFormalParamBlackHoleAddrEdge)
1702 * ConstantExpr CopyEdge (Int2PtrConstantExpr CastConstantExpr SVFIRBuilder::processCE)
1703 * GepEdge (GepConstantExpr SVFIRBuilder::processCE)
1704 * ConstantPointerNull CopyEdge (3-->2 NullPtr-->BlkPtr SVFIR::addNullPtrNode)
1705 * AddrEdge (0-->2 BlkObj-->BlkPtr SVFIR::addNullPtrNode)
1706 * GlobalVariable AddrEdge (SVFIRBuilder::visitGlobal)
1707 * GepEdge (SVFIRBuilder::getGlobalVarField)
1708 * Function AddrEdge (SVFIRBuilder::visitGlobal)
1709 * Constant StoreEdge (SVFIRBuilder::InitialGlobal)
1710 */
1712{
1714 return;
1715
1716 assert(curVal && "current Val is nullptr?");
1717 edge->setBB(curBB!=nullptr ? curBB : nullptr);
1719 ICFGNode* icfgNode = pag->getICFG()->getGlobalICFGNode();
1721 if (const Instruction* curInst = SVFUtil::dyn_cast<Instruction>(curVal))
1722 {
1723 const FunObjVar* srcFun = edge->getSrcNode()->getFunction();
1724 const FunObjVar* dstFun = edge->getDstNode()->getFunction();
1725 if(srcFun!=nullptr && !SVFUtil::isa<RetPE>(edge) && !SVFUtil::isa<FunValVar>(edge->getSrcNode()) && !SVFUtil::isa<FunObjVar>(edge->getSrcNode()))
1726 {
1727 assert(srcFun==llvmMS->getFunObjVar(curInst->getFunction()) && "SrcNode of the PAGEdge not in the same function?");
1728 }
1729 if(dstFun!=nullptr && !SVFUtil::isa<CallPE>(edge) && !SVFUtil::isa<RetValPN>(edge->getDstNode()))
1730 {
1731 assert(dstFun==llvmMS->getFunObjVar(curInst->getFunction()) && "DstNode of the PAGEdge not in the same function?");
1732 }
1733
1735 if (!(SVFUtil::isa<GepStmt>(edge) && SVFUtil::isa<GepValVar>(edge->getDstNode())))
1736 assert(curBB && "instruction does not have a basic block??");
1737
1739 if(SVFUtil::isa<ReturnInst>(curInst))
1740 {
1741 icfgNode = pag->getICFG()->getFunExitICFGNode(llvmMS->getFunObjVar(curInst->getFunction()));
1742 }
1743 else
1744 {
1745 if(SVFUtil::isa<RetPE>(edge))
1746 icfgNode = llvmMS->getRetICFGNode(SVFUtil::cast<Instruction>(curInst));
1747 else
1748 icfgNode = llvmMS->getICFGNode(SVFUtil::cast<Instruction>(curInst));
1749 }
1750 }
1751 else if (const Argument* arg = SVFUtil::dyn_cast<Argument>(curVal))
1752 {
1754 icfgNode = pag->getICFG()->getFunEntryICFGNode(
1755 llvmModuleSet()->getFunObjVar(SVFUtil::cast<Function>(arg->getParent())));
1756 }
1757 else if (SVFUtil::isa<Constant>(curVal) ||
1758 SVFUtil::isa<Function>(curVal) ||
1759 SVFUtil::isa<MetadataAsValue>(curVal))
1760 {
1761 if (!curBB)
1763 else
1764 {
1765 icfgNode = const_cast<ICFGNode*>(curBB->front());
1766 }
1767 }
1768 else
1769 {
1770 assert(false && "what else value can we have?");
1771 }
1772
1773 pag->addToSVFStmtList(icfgNode,edge);
1774 icfgNode->addSVFStmt(edge);
1775 if(const CallPE* callPE = SVFUtil::dyn_cast<CallPE>(edge))
1776 {
1777 CallICFGNode* callNode = const_cast<CallICFGNode*>(callPE->getCallSite());
1778 FunEntryICFGNode* entryNode = const_cast<FunEntryICFGNode*>(callPE->getFunEntryICFGNode());
1780 SVFUtil::cast<CallCFGEdge>(edge)->addCallPE(callPE);
1781 }
1782 else if(const RetPE* retPE = SVFUtil::dyn_cast<RetPE>(edge))
1783 {
1784 RetICFGNode* retNode = const_cast<RetICFGNode*>(retPE->getCallSite()->getRetICFGNode());
1785 FunExitICFGNode* exitNode = const_cast<FunExitICFGNode*>(retPE->getFunExitICFGNode());
1787 SVFUtil::cast<RetCFGEdge>(edge)->addRetPE(retPE);
1788 }
1789}
1790
1791
1799{
1800 SVFVar* node = pag->getGNode(nodeId);
1803 if(geps.empty())
1804 return AccessPath(0);
1805
1806 assert(geps.size()==1 && "one node can only be connected by at most one gep edge!");
1807 SVFVar::iterator it = geps.begin();
1808 const GepStmt* gepEdge = SVFUtil::cast<GepStmt>(*it);
1809 if(gepEdge->isVariantFieldGep())
1810 return AccessPath(0);
1811 else
1812 return gepEdge->getAccessPath();
1813}
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition SVFType.h:593
#define TIMEINTERVAL
Definition SVFType.h:621
#define DGENERAL
Definition SVFType.h:599
#define DPAGBuild
Definition SVFType.h:601
buffer offset
Definition cJSON.cpp:1113
cJSON * item
Definition cJSON.h:222
bool addOffsetVarAndGepTypePair(const SVFVar *var, const SVFType *gepIterType)
APOffset getConstantStructFldIdx() const
Get methods.
Definition AccessPath.h:97
void setFldIdx(APOffset idx)
Definition AccessPath.h:101
std::vector< std::pair< const ICFGNode *, s32_t > > SuccAndCondPairVec
CallEdgeMap & getIndCallMap()
Get callees from an indirect callsite.
Definition CallGraph.h:331
Set< const FunObjVar * > FunctionSet
Definition CallGraph.h:247
bool isVirtualCall() const
Definition ICFGNode.h:509
void setVtablePtr(SVFVar *v)
Definition ICFGNode.h:514
static ExtAPI * getExtAPI()
Definition ExtAPI.cpp:44
void setExtFuncAnnotations(const FunObjVar *fun, const std::vector< std::string > &funcAnnotations)
Definition ExtAPI.cpp:223
virtual const FunObjVar * getFunction() const
Get containing function, or null for globals/constants.
const SVFBasicBlock * getEntryBlock() const
void setBasicBlockGraph(BasicBlockGraph *graph)
void initFunObjVar(bool decl, bool intrinc, bool addr, bool uncalled, bool notret, bool vararg, const SVFFunctionType *ft, SVFLoopAndDomInfo *ld, const FunObjVar *real, BasicBlockGraph *bbg, const std::vector< const ArgValVar * > &allarg, const SVFBasicBlock *exit)
BasicBlockGraph * bbGraph
the definition of a function across multiple modules
iterator begin()
Iterators.
u32_t getTotalNodeNum() const
Get total number of node/edge.
IDToNodeMapTy::iterator iterator
Node Iterators.
NodeType * getGNode(NodeID id) const
Get a node.
GEdgeSetTy::iterator iterator
const GEdgeSetTy & getOutEdges() const
void addSVFStmt(const SVFStmt *edge)
Definition ICFGNode.h:110
FunExitICFGNode * getFunExitICFGNode(const FunObjVar *fun)
Add a function exit node.
Definition ICFG.cpp:249
ICFGEdge * hasInterICFGEdge(ICFGNode *src, ICFGNode *dst, ICFGEdge::ICFGEdgeK kind)
Definition ICFG.cpp:276
void dump(const std::string &file, bool simple=false)
Dump graph into dot file.
Definition ICFG.cpp:411
FunEntryICFGNode * getFunEntryICFGNode(const FunObjVar *fun)
Add a function entry node.
Definition ICFG.cpp:242
GlobalICFGNode * getGlobalICFGNode() const
Definition ICFG.h:244
NodeID constantSymID() const
Definition IRGraph.h:188
u32_t getFlattenedElemIdx(const SVFType *T, u32_t origId)
Flattened element idx of an array or struct by considering stride.
Definition IRGraph.cpp:144
u32_t getNodeNumAfterPAGBuild() const
Definition IRGraph.h:322
void dump(std::string name)
Dump SVFIR.
Definition IRGraph.cpp:316
NodeID getBlkPtr() const
Definition IRGraph.h:255
NodeID blkPtrSymID() const
Definition IRGraph.h:178
NodeID getNullPtr() const
Definition IRGraph.h:259
NodeID nullPtrSymID() const
Definition IRGraph.h:183
u32_t getTotalSymNum() const
Statistics.
Definition IRGraph.h:200
FunObjVarToIDMapTy varargFunObjSymMap
vararg map
Definition IRGraph.h:86
NodeID getReturnNode(const FunObjVar *func) const
GetReturnNode - Return the unique node representing the return value of a function.
Definition IRGraph.cpp:60
void setNodeNumAfterPAGBuild(u32_t num)
Definition IRGraph.h:326
NodeID blackholeSymID() const
Definition IRGraph.h:193
ObjTypeInfo * getObjTypeInfo(NodeID id) const
Definition IRGraph.h:234
NodeID getConstantNode() const
Definition IRGraph.h:251
FunObjVarToIDMapTy returnFunObjSymMap
return map
Definition IRGraph.h:85
virtual void build(ICFG *icfg)
Start from here.
NodeID getValueNode(const Value *V)
ValueToIDMapTy & valSyms()
Definition LLVMModule.h:207
FunToIDMapTy & retSyms()
Definition LLVMModule.h:274
const FunObjVar * getFunObjVar(const Function *fun) const
Definition LLVMModule.h:267
SVFBasicBlock * getSVFBasicBlock(const BasicBlock *bb)
Definition LLVMModule.h:298
DominatorTree & getDomTree(const Function *fun)
void addToSVFVar2LLVMValueMap(const Value *val, SVFValue *svfBaseNode)
LLVMFun2FunObjVarMap LLVMFun2FunObjVar
Map an LLVM Function to an SVF Funobjvar.
Definition LLVMModule.h:99
SVFType * getSVFType(const Type *T)
Get or create SVFType and typeinfo.
bool hasICFGNode(const Instruction *inst)
ICFGNode * getICFGNode(const Instruction *inst)
Get a basic block ICFGNode.
CallICFGNode * getCallICFGNode(const Instruction *cs)
get a call node
Fun2AnnoMap ExtFun2Annotations
Record annotations of function in extapi.bc.
Definition LLVMModule.h:91
NodeID getObjectNode(const Value *V)
RetICFGNode * getRetICFGNode(const Instruction *cs)
get a return node
const std::vector< std::reference_wrapper< Module > > & getLLVMModules() const
Definition LLVMModule.h:157
const Function * getRealDefFun(const Function *fun) const
Definition LLVMModule.h:185
ValueToIDMapTy & objSyms()
Definition LLVMModule.h:212
void addBasicBlock(FunObjVar *fun, const BasicBlock *bb)
Definition LLVMModule.h:232
FunToIDMapTy & varargSyms()
Definition LLVMModule.h:279
const FunctionSet & getFunctionSet() const
Definition LLVMModule.h:192
static NodeIDAllocator * get(void)
Return (singleton) allocator.
static const Option< bool > PAGDotGraph
Definition Options.h:118
static const Option< std::string > DumpJson
Definition Options.h:121
static Option< bool > ModelConsts
Definition Options.h:184
static const Option< bool > PAGPrint
Definition Options.h:124
static const Option< bool > VtableInSVFIR
Definition Options.h:214
static const Option< bool > LoopAnalysis
Definition Options.h:239
static const Option< bool > DumpICFG
Definition Options.h:120
const FunObjVar * getParent() const
void addPredBasicBlock(const SVFBasicBlock *pred2)
void addSuccBasicBlock(const SVFBasicBlock *succ2)
const ICFGNode * front() const
u32_t inferFieldIdxFromByteOffset(const llvm::GEPOperator *gepOp, DataLayout *dl, AccessPath &ap, APOffset idx)
Infer field index from byteoffset.
CopyStmt::CopyKind getCopyKind(const Value *val)
void sanityCheck()
Sanity check for SVFIR.
SVFIR * getPAG() const
Return SVFIR.
void setCurrentLocation(const Value *val, const BasicBlock *bb)
Set current basic block in order to keep track of control flow information.
NodeID addNullPtrNode()
Add NullPtr PAGNode.
void visitLoadInst(LoadInst &I)
NodeID getVarargNode(const FunObjVar *func)
getVarargNode - Return the node representing the unique variadic argument of a function.
void addPhiStmt(NodeID res, NodeID opnd, const ICFGNode *pred)
Add Copy edge.
void updateCallGraph(CallGraph *callgraph)
connect PAG edges based on callgraph
void initSVFBasicBlock(const Function *func)
void addStoreEdge(NodeID src, NodeID dst)
Add Store edge.
AddrStmt * addAddrEdge(NodeID src, NodeID dst)
Add Address edge.
void visitInvokeInst(InvokeInst &II)
void handleDirectCall(CallBase *cs, const Function *F)
Handle direct call.
void addBinaryOPEdge(NodeID op1, NodeID op2, NodeID dst, u32_t opcode)
Add Copy edge.
void visitCallInst(CallInst &I)
void addLoadEdge(NodeID src, NodeID dst)
Add Load edge.
virtual void handleExtCall(const CallBase *cs, const Function *callee)
void visitGetElementPtrInst(GetElementPtrInst &I)
void visitBranchInst(BranchInst &I)
virtual void visitAllocaInst(AllocaInst &AI)
Our visit overrides.
void addGepEdge(NodeID src, NodeID dst, const AccessPath &ap, bool constGep)
Add Gep edge.
void addCmpEdge(NodeID op1, NodeID op2, NodeID dst, u32_t predict)
Add Copy edge.
LLVMModuleSet * llvmModuleSet()
void visitStoreInst(StoreInst &I)
NodeID getReturnNode(const FunObjVar *func)
getReturnNode - Return the node representing the unique return value of a function.
NodeID getObjectNode(const Value *V)
GetObject - Return the object node (stack/global/heap/function) according to a LLVM Value.
void visitCallSite(CallBase *cs)
void processCE(const Value *val)
Process constant expression.
void handleIndCall(CallBase *cs)
Handle indirect call.
const Value * curVal
Current Value during SVFIR construction when visiting the module.
void addSelectStmt(NodeID res, NodeID op1, NodeID op2, NodeID cond)
Add SelectStmt.
void addBranchStmt(NodeID br, NodeID cond, const BranchStmt::SuccAndCondPairVec &succs)
Add Branch statement.
virtual SVFIR * build()
Start building SVFIR here.
void visitCallBrInst(CallBrInst &I)
void visitExtractValueInst(ExtractValueInst &EVI)
AccessPath getAccessPathFromBaseNode(NodeID nodeId)
const SVFBasicBlock * curBB
Current basic block during SVFIR construction when visiting the module.
void visitSwitchInst(SwitchInst &I)
The following implementation follows ICFGBuilder::processFunBody.
void visitFreezeInst(FreezeInst &I)
const Value * getBaseValueForExtArg(const Value *V)
Get the base value of (i8* src and i8* dst) for external argument (e.g. memcpy(i8* dst,...
void initDomTree(FunObjVar *func, const Function *f)
void addRetEdge(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Return edge.
void addBlackHoleAddrEdge(NodeID node)
void visitGlobal()
Handle globals including (global variable and functions)
void addUnaryOPEdge(NodeID src, NodeID dst, u32_t opcode)
Add Unary edge.
const SVFBasicBlock * getCurrentBB() const
void visitPHINode(PHINode &I)
CopyStmt * addCopyEdge(NodeID src, NodeID dst, CopyStmt::CopyKind kind)
void addCallEdge(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Call edge.
void setCurrentBBAndValueForPAGEdge(PAGEdge *edge)
void visitSelectInst(SelectInst &I)
void visitVAArgInst(VAArgInst &)
void visitCmpInst(CmpInst &I)
void visitExtractElementInst(ExtractElementInst &I)
bool computeGepOffset(const User *V, AccessPath &ap)
Compute offset of a gep instruction or gep constant expression.
void visitReturnInst(ReturnInst &I)
const Value * getCurrentValue() const
NodeID getValueNode(const Value *V)
Get different kinds of node.
void visitCastInst(CastInst &I)
AddrStmt * addAddrWithStackArraySz(NodeID src, NodeID dst, llvm::AllocaInst &inst)
Add Address edge from allocinst with arraysize like "%4 = alloca i8, i64 3".
NodeID getGepValVar(const Value *val, const AccessPath &ap, const SVFType *elementType)
void InitialGlobal(const GlobalVariable *gvar, Constant *C, u32_t offset)
void visitUnaryOperator(UnaryOperator &I)
void visitBinaryOperator(BinaryOperator &I)
void initialiseNodes()
Initialize nodes and edges.
NodeID getGlobalVarField(const GlobalVariable *gvar, u32_t offset, SVFType *tpy)
NodeID addGlobalValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *svfType)
Definition SVFIR.h:630
NodeID getGepValVar(NodeID curInst, NodeID base, const AccessPath &ap) const
Due to constraint expression, curInst is used to distinguish different instructions (e....
Definition SVFIR.cpp:597
void print()
Print SVFIR.
Definition SVFIR.cpp:632
NodeID addConstantAggObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:706
NodeID addBlackholePtrNode()
Definition SVFIR.h:772
NodeID addBlackholeObjNode()
Definition SVFIR.h:764
NodeID addGlobalObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:701
void addFunArgs(const FunObjVar *fun, const SVFVar *arg)
Get/set method for function/callsite arguments and returns.
Definition SVFIR.h:544
NodeID addGepValNode(NodeID curInst, const ValVar *base, const AccessPath &ap, NodeID i, const SVFType *type, const ICFGNode *node)
Add a temp field value node, this method can only invoked by getGepValVar.
Definition SVFIR.cpp:471
NodeID addConstantDataObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:711
NodeID addConstantFPObjNode(NodeID i, ObjTypeInfo *ti, double dval, const ICFGNode *node)
Definition SVFIR.h:680
void addFunRet(const FunObjVar *fun, const SVFVar *ret)
Add function returns.
Definition SVFIR.h:556
NodeID addObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Add a memory obj node.
Definition SVFIR.h:650
NodeID addConstantNullPtrValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:624
NodeID addHeapObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:658
static bool pagReadFromTXT()
Definition SVFIR.h:212
CallGraph * callGraph
all the callsites of a program
Definition SVFIR.h:99
void addToSVFStmtList(ICFGNode *inst, SVFStmt *edge)
Add a SVFStmt into instruction map.
Definition SVFIR.h:260
NodeID addConstantNullPtrObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:695
void addCallSiteRets(RetICFGNode *retBlockNode, const SVFVar *arg)
Add callsite returns.
Definition SVFIR.h:574
NodeID addConstantDataValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:642
void addCallSiteArgs(CallICFGNode *callBlockNode, const ValVar *arg)
Add callsite arguments.
Definition SVFIR.h:568
NodeID addStackObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:667
NodeID addConstantIntValNode(NodeID i, const std::pair< s64_t, u64_t > &intValue, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:617
ICFG * getICFG() const
Definition SVFIR.h:163
NodeID addFunValNode(NodeID i, const ICFGNode *icfgNode, const FunObjVar *funObjVar, const SVFType *type)
Definition SVFIR.h:597
NodeID addConstantFPValNode(const NodeID i, double dval, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:610
NodeID addConstantAggValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *svfType)
Definition SVFIR.h:636
void addCallSite(const CallICFGNode *call)
Add callsites.
Definition SVFIR.h:799
NodeID addValNode(NodeID i, const SVFType *type, const ICFGNode *icfgNode)
add node into SVFIR
Definition SVFIR.h:591
NodeID addVarargNode(NodeID i, const FunObjVar *val, const SVFType *type, const ICFGNode *n)
Add a unique vararg node for a procedure.
Definition SVFIR.h:724
void setCHG(CommonCHGraph *c)
Set/Get CHG.
Definition SVFIR.h:169
NodeID addFunObjNode(NodeID id, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:673
ICFG * icfg
Definition SVFIR.h:96
NodeID addConstantIntObjNode(NodeID i, ObjTypeInfo *ti, const std::pair< s64_t, u64_t > &intValue, const ICFGNode *node)
Definition SVFIR.h:687
void addGlobalPAGEdge(const SVFStmt *edge)
Add global PAGEdges (not in a procedure)
Definition SVFIR.h:794
void addIndirectCallsites(const CallICFGNode *cs, NodeID funPtr)
Add indirect callsites.
Definition SVFIR.h:580
void initialiseCandidatePointers()
Initialize candidate pointers.
Definition SVFIR.cpp:717
NodeID addRetNode(NodeID i, const FunObjVar *callGraphNode, const SVFType *type, const ICFGNode *icn)
Add a unique return node for a procedure.
Definition SVFIR.h:718
NodeID addArgValNode(NodeID i, u32_t argNo, const ICFGNode *icfgNode, const FunObjVar *callGraphNode, const SVFType *type)
Definition SVFIR.h:603
NodeID addConstantObjNode()
Definition SVFIR.h:768
const Map< const SVFBasicBlock *, BBSet > & getDomFrontierMap() const
Set< const SVFBasicBlock * > BBSet
static double getClk(bool mark=false)
Definition SVFStat.cpp:48
static double timeOfBuildingSVFIR
Definition SVFStat.h:95
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
virtual void setName(const std::string &nameInfo)
Definition SVFValue.h:176
SVFStmt::SVFStmtSetTy & getIncomingEdges(SVFStmt::PEDGEK kind)
Edge accessors and checkers.
#define NULL
Definition extapi.c:5
bool isIntrinsicInst(const Instruction *inst)
Return true if it is an intrinsic instruction.
Definition LLVMUtil.cpp:202
const ConstantExpr * isBinaryConstantExpr(const Value *val)
Definition LLVMUtil.h:290
bool isUncalledFunction(const Function *fun)
whether this is a function without any possible caller?
Definition LLVMUtil.cpp:157
double getDoubleValue(const ConstantFP *fpValue)
Definition LLVMUtil.h:54
bool isConstantObjSym(const Value *val)
Check whether this value points-to a constant object.
Definition CppUtil.cpp:743
const Value * stripAllCasts(const Value *val)
Strip off the all casts.
Definition LLVMUtil.cpp:249
const ConstantExpr * isInt2PtrConstantExpr(const Value *val)
Definition LLVMUtil.h:225
const ConstantExpr * isSelectConstantExpr(const Value *val)
Definition LLVMUtil.h:255
bool isIntrinsicFun(const Function *func)
Definition LLVMUtil.cpp:189
bool functionDoesNotRet(const Function *fun)
Definition LLVMUtil.cpp:122
const ConstantExpr * isTruncConstantExpr(const Value *val)
Definition LLVMUtil.h:265
std::pair< s64_t, u64_t > getIntegerValue(const ConstantInt *intValue)
Definition LLVMUtil.h:82
void getNextInsts(const Instruction *curInst, std::vector< const Instruction * > &instList)
Get the next instructions following control flow.
Definition LLVMUtil.cpp:573
const ConstantExpr * isPtr2IntConstantExpr(const Value *val)
Definition LLVMUtil.h:235
bool isHeapObj(const Value *val)
Definition LLVMUtil.cpp:682
const ConstantExpr * isUnaryConstantExpr(const Value *val)
Definition LLVMUtil.h:301
void getFunReachableBBs(const Function *svfFun, std::vector< const SVFBasicBlock * > &bbs)
Get reachable basic block from function entry.
Definition LLVMUtil.cpp:74
const ConstantExpr * isCastConstantExpr(const Value *val)
Definition LLVMUtil.h:245
bool isExtCall(const Function *fun)
Definition LLVMUtil.cpp:383
bool basicBlockHasRetInst(const BasicBlock *bb)
Return true if the function has a return instruction.
Definition LLVMUtil.cpp:108
bool isStackObj(const Value *val)
Definition LLVMUtil.cpp:704
const ConstantExpr * isGepConstantExpr(const Value *val)
Return corresponding constant expression, otherwise return nullptr.
Definition LLVMUtil.h:215
static DataLayout * getDataLayout(Module *mod)
Definition LLVMUtil.h:313
const Function * getCallee(const CallBase *cs)
Definition LLVMUtil.h:97
const FunObjVar * getFunObjVar(const std::string &name)
Definition LLVMUtil.cpp:435
std::string dumpValue(const Value *val)
Definition LLVMUtil.cpp:600
const ConstantExpr * isCmpConstantExpr(const Value *val)
Definition LLVMUtil.h:279
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
Definition SVFUtil.cpp:101
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
Definition SVFUtil.cpp:68
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:52
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
Definition Casting.h:405
const Value * getVCallVtblPtr(const CallBase *cs)
Definition CppUtil.cpp:608
bool isValVtbl(const Value *val)
Definition CppUtil.cpp:336
for isBitcode
Definition BasicTypes.h:68
llvm::DataLayout DataLayout
Definition BasicTypes.h:108
llvm::GlobalVariable GlobalVariable
Definition BasicTypes.h:130
llvm::GlobalAlias GlobalAlias
Definition BasicTypes.h:128
llvm::ArrayType ArrayType
Definition BasicTypes.h:95
llvm::Type Type
Definition BasicTypes.h:83
llvm::CallBase CallBase
Definition BasicTypes.h:146
llvm::BasicBlock BasicBlock
Definition BasicTypes.h:86
llvm::UnaryOperator UnaryOperator
Definition BasicTypes.h:180
llvm::ConstantStruct ConstantStruct
Definition BasicTypes.h:106
llvm::StructType StructType
LLVM types.
Definition BasicTypes.h:94
llvm::succ_const_iterator succ_const_iterator
LLVM Iterators.
Definition BasicTypes.h:276
llvm::AllocaInst AllocaInst
Definition BasicTypes.h:150
llvm::SwitchInst SwitchInst
Definition BasicTypes.h:155
u32_t NodeID
Definition GeneralType.h:56
llvm::InvokeInst InvokeInst
Definition BasicTypes.h:163
llvm::Argument Argument
Definition BasicTypes.h:145
llvm::LoadInst LoadInst
Definition BasicTypes.h:149
s64_t APOffset
Definition GeneralType.h:60
llvm::const_pred_iterator const_pred_iterator
Definition BasicTypes.h:254
llvm::CmpInst CmpInst
Definition BasicTypes.h:159
llvm::Function Function
Definition BasicTypes.h:85
llvm::ConstantData ConstantData
Definition BasicTypes.h:116
llvm::LoopInfo LoopInfo
Definition BasicTypes.h:141
llvm::Instruction Instruction
Definition BasicTypes.h:87
llvm::Constant Constant
Definition BasicTypes.h:124
llvm::DomTreeNode DomTreeNode
Definition BasicTypes.h:134
llvm::ConstantDataSequential ConstantDataSequential
Definition BasicTypes.h:119
llvm::Value Value
LLVM Basic classes.
Definition BasicTypes.h:82
llvm::ConstantExpr ConstantExpr
Definition BasicTypes.h:120
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
llvm::CastInst CastInst
Definition BasicTypes.h:158
llvm::FreezeInst FreezeInst
Definition BasicTypes.h:169
llvm::Module Module
Definition BasicTypes.h:84
llvm::BinaryOperator BinaryOperator
Definition BasicTypes.h:179
llvm::PostDominatorTree PostDominatorTree
Definition BasicTypes.h:136
llvm::DominanceFrontier DominanceFrontier
Definition BasicTypes.h:135
llvm::StoreInst StoreInst
Definition BasicTypes.h:148
llvm::SelectInst SelectInst
Definition BasicTypes.h:174
llvm::VAArgInst VAArgInst
Definition BasicTypes.h:175
llvm::Loop Loop
LLVM Loop.
Definition BasicTypes.h:140
llvm::GetElementPtrInst GetElementPtrInst
Definition BasicTypes.h:162
llvm::CallBrInst CallBrInst
Definition BasicTypes.h:156
llvm::ReturnInst ReturnInst
Definition BasicTypes.h:157
llvm::PHINode PHINode
Definition BasicTypes.h:165
llvm::BranchInst BranchInst
Definition BasicTypes.h:154
llvm::ExtractValueInst ExtractValueInst
Definition BasicTypes.h:160
unsigned u32_t
Definition GeneralType.h:47
signed long long s64_t
Definition GeneralType.h:50
llvm::CallInst CallInst
Definition BasicTypes.h:147
llvm::ConstantInt ConstantInt
Definition BasicTypes.h:125
llvm::DominatorTree DominatorTree
LLVM Dominators.
Definition BasicTypes.h:133
llvm::ExtractElementInst ExtractElementInst
Definition BasicTypes.h:161
llvm::User User
Definition BasicTypes.h:142