SVF
CPPUtil.h
Go to the documentation of this file.
1 //===- CPPUtil.h -- Base class of pointer analyses ---------------------------//
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 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 General Public License for more details.
17 
18 // You should have received a copy of the GNU General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 //
21 //===----------------------------------------------------------------------===//
22 
23 /*
24  * CPPUtil.h
25  *
26  * Created on: Apr 13, 2016
27  * Author: Xiaokang Fan
28  */
29 
30 #ifndef CPPUtil_H_
31 #define CPPUtil_H_
32 
33 #include "Util/BasicTypes.h"
34 
35 namespace SVF
36 {
37 
38 class CHGraph;
39 /*
40  * Util class to assist pointer analysis for cpp programs
41  */
42 
43 namespace cppUtil
44 {
45 
47 {
48  std::string className;
49  std::string funcName;
51 };
52 
53 struct DemangledName demangle(const std::string &name);
54 
55 std::string getBeforeBrackets(const std::string &name);
56 bool isValVtbl(const Value *val);
57 bool isLoadVtblInst(const LoadInst *loadInst);
58 bool isVirtualCallSite(CallSite cs);
59 bool isConstructor(const Function *F);
60 bool isDestructor(const Function *F);
61 bool isCPPThunkFunction(const Function *F);
62 const Function *getThunkTarget(const Function *F);
63 
64 /*
65  * VtableA = {&A::foo}
66  * A::A(this){
67  * *this = &VtableA;
68  * }
69  *
70  *
71  * A* p = new A;
72  * cs: p->foo(...)
73  * ==>
74  * vtptr = *p;
75  * vfn = &vtptr[i]
76  * %funp = *vfn
77  * call %funp(p,...)
78  * getConstructorThisPtr(A) return "this" pointer
79  * getVCallThisPtr(cs) return p (this pointer)
80  * getVCallVtblPtr(cs) return vtptr
81  * getVCallIdx(cs) return i
82  * getClassNameFromVtblObj(VtableA) return
83  * getClassNameFromType(type of p) return type A
84  */
85 const Argument* getConstructorThisPtr(const Function* fun);
86 const Value *getVCallThisPtr(CallSite cs);
87 const Value *getVCallVtblPtr(CallSite cs);
88 u64_t getVCallIdx(CallSite cs);
89 std::string getClassNameFromVtblObj(const Value *value);
90 std::string getClassNameFromType(const Type *ty);
91 std::string getClassNameOfThisPtr(CallSite cs);
92 std::string getFunNameOfVCallSite(CallSite cs);
93 bool VCallInCtorOrDtor(CallSite cs);
94 
95 /*
96  * A(A* this){
97  * store this this.addr;
98  * tmp = load this.addr;
99  * this1 = bitcast(tmp);
100  * B(this1);
101  * }
102  * this and this1 are the same thisPtr in the constructor
103  */
104 bool isSameThisPtrInConstructor(const Argument* thisPtr1, const Value* thisPtr2);
105 
108 namespace ctir
109 {
113 const std::string derefMDName = "ctir";
116 const std::string vtMDName = "ctir.vt";
119 const std::string vtInitMDName = "ctir.vt.init";
120 
122 const uint32_t moduleFlagValue = 1;
123 }
124 
125 } // End namespace cppUtil
126 
127 } // End namespace SVF
128 
129 #endif /* CPPUtil_H_ */
u64_t getVCallIdx(CallSite cs)
Definition: CPPUtil.cpp:389
const std::string vtInitMDName
Definition: CPPUtil.h:119
bool isVirtualCallSite(CallSite cs)
Definition: CPPUtil.cpp:256
bool isConstructor(const Function *F)
Definition: CPPUtil.cpp:451
std::string getClassNameFromType(const Type *ty)
Definition: CPPUtil.cpp:409
bool isDestructor(const Function *F)
Definition: CPPUtil.cpp:479
const std::string derefMDName
Definition: CPPUtil.h:113
bool isSameThisPtrInConstructor(const Argument *thisPtr1, const Value *thisPtr2)
Definition: CPPUtil.cpp:337
bool isCPPThunkFunction(const Function *F)
Definition: CPPUtil.cpp:288
bool VCallInCtorOrDtor(CallSite cs)
Definition: CPPUtil.cpp:552
const Argument * getConstructorThisPtr(const Function *fun)
Definition: CPPUtil.cpp:363
bool isLoadVtblInst(const LoadInst *loadInst)
Definition: CPPUtil.cpp:225
const Function * getThunkTarget(const Function *F)
Definition: CPPUtil.cpp:293
std::string getClassNameFromVtblObj(const Value *value)
Definition: CPPUtil.cpp:432
const std::string vtMDName
Definition: CPPUtil.h:116
llvm::Function Function
Definition: BasicTypes.h:76
const Value * getVCallThisPtr(CallSite cs)
Definition: CPPUtil.cpp:313
const uint32_t moduleFlagValue
Value we expect a ctir-annotated module to have.
Definition: CPPUtil.h:122
llvm::Argument Argument
LLVM Aliases and constants.
Definition: BasicTypes.h:122
bool isValVtbl(const Value *val)
Definition: CPPUtil.cpp:123
std::string getBeforeBrackets(const std::string &name)
const Value * getVCallVtblPtr(CallSite cs)
Definition: CPPUtil.cpp:378
std::string getClassNameOfThisPtr(CallSite cs)
Definition: CPPUtil.cpp:509
struct DemangledName demangle(const std::string &name)
for isBitcode
Definition: ContextDDA.h:15
std::string getFunNameOfVCallSite(CallSite cs)
Definition: CPPUtil.cpp:536
llvm::Value Value
Definition: BasicTypes.h:78
unsigned long long u64_t
Definition: SVFBasicTypes.h:76