Skip to content

Commit 49b1ae1

Browse files
authored
Merge pull request #275 from plum-umd/BigRefactor
Merging Context sensitive bounds fix
2 parents f099459 + 1036b6e commit 49b1ae1

15 files changed

Lines changed: 411 additions & 104 deletions

clang/include/clang/CConv/AVarBoundsInfo.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ class AvarBoundsInference {
9797

9898
// Infer bounds for the given key from the set of given ARR atoms.
9999
// The flag FromPB requests the inference to use potential length variables.
100-
bool inferBounds(BoundsKey K, bool FromPB = false);
100+
bool inferBounds(BoundsKey K, AVarGraph &BKGraph, bool FromPB = false);
101101
private:
102102
bool inferPossibleBounds(BoundsKey K, ABounds *SB,
103+
AVarGraph &BKGraph,
103104
std::set<ABounds *> &EB);
104105

105106
bool intersectBounds(std::set<ProgramVar *> &ProgVars,
@@ -110,6 +111,7 @@ class AvarBoundsInference {
110111
std::set<ABounds *> &ResBounds);
111112

112113
bool predictBounds(BoundsKey K, std::set<BoundsKey> &Neighbours,
114+
AVarGraph &BKGraph,
113115
ABounds **KB);
114116

115117

@@ -120,7 +122,7 @@ class AvarBoundsInference {
120122

121123
class AVarBoundsInfo {
122124
public:
123-
AVarBoundsInfo() : ProgVarGraph(this) {
125+
AVarBoundsInfo() : ProgVarGraph(this), CtxSensProgVarGraph(this) {
124126
BCount = 1;
125127
PVarInfo.clear();
126128
InProgramArrPtrBoundsKeys.clear();
@@ -208,7 +210,8 @@ class AVarBoundsInfo {
208210
// Create context sensitive BoundsKey variables for the given set of
209211
// ConstraintVariables.
210212
bool contextualizeCVar(CallExpr *CE,
211-
const std::set<ConstraintVariable *> &CV);
213+
const std::set<ConstraintVariable *> &CV,
214+
ASTContext *C);
212215
// Get the context sensitive BoundsKey for the given key.
213216
// If there exists no context-sensitive bounds key, we just return
214217
// the provided key.
@@ -269,6 +272,9 @@ class AVarBoundsInfo {
269272

270273
// Graph of all program variables.
271274
AVarGraph ProgVarGraph;
275+
// Graph that contains only edges between context-sensitive
276+
// BoundsKey and corresponding original BoundsKey.
277+
AVarGraph CtxSensProgVarGraph;
272278
// Stats on techniques used to find length for various variables.
273279
AVarBoundsStats BoundsInferStats;
274280
// This is the map of pointer variable bounds key and set of bounds key
@@ -293,6 +299,9 @@ class AVarBoundsInfo {
293299

294300
void insertProgramVar(BoundsKey NK, ProgramVar *PV);
295301

302+
void insertCtxSensBoundsKey(ProgramVar *OldPV, BoundsKey NK,
303+
const CtxFunctionArgScope *CFAS);
304+
296305
// Check if the provided bounds key corresponds to function return.
297306
bool isFunctionReturn(BoundsKey BK);
298307

@@ -303,9 +312,11 @@ class AVarBoundsInfo {
303312
// returns true if any thing changed, else false.
304313
bool keepHighestPriorityBounds(std::set<BoundsKey> &ArrPtrs);
305314

306-
// Perform worklist based inference on the requested array variables.
315+
// Perform worklist based inference on the requested array variables using
316+
// the provided graph.
307317
// The flag FromPB requests the algorithm to use potential length variables.
308318
bool performWorkListInference(std::set<BoundsKey> &ArrNeededBounds,
319+
AVarGraph &BKGraph,
309320
bool FromPB = false);
310321

311322
void insertParamKey(ParamDeclType ParamDecl, BoundsKey NK);

clang/include/clang/CConv/ConstraintVariables.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,20 @@ enum ConsAction {
173173
void constrainConsVarGeq(const std::set<ConstraintVariable *> &LHS,
174174
const std::set<ConstraintVariable *> &RHS,
175175
Constraints &CS, PersistentSourceLoc *PL,
176-
ConsAction CA, bool doEqType, ProgramInfo *Info);
176+
ConsAction CA, bool doEqType,
177+
ProgramInfo *Info,
178+
bool HandleBoundsKey = true);
177179
void constrainConsVarGeq(ConstraintVariable *LHS, const CVarSet &RHS,
178180
Constraints &CS, PersistentSourceLoc *PL,
179-
ConsAction CA, bool doEqType, ProgramInfo *Info);
180-
void constrainConsVarGeq(ConstraintVariable *LHS, ConstraintVariable *RHS,
181+
ConsAction CA, bool doEqType,
182+
ProgramInfo *Info,
183+
bool HandleBoundsKey = true);
184+
void constrainConsVarGeq(ConstraintVariable *LHS,
185+
ConstraintVariable *RHS,
181186
Constraints &CS, PersistentSourceLoc *PL,
182-
ConsAction CA, bool doEqType, ProgramInfo *Info);
187+
ConsAction CA, bool doEqType,
188+
ProgramInfo *Info,
189+
bool HandleBoundsKey = true);
183190

184191
// True if [C] is a PVConstraint that contains at least one Atom (i.e.,
185192
// it represents a C pointer)

clang/include/clang/CConv/PersistentSourceLoc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class PersistentSourceLoc {
6868
static
6969
PersistentSourceLoc mkPSL(const clang::Stmt *S, clang::ASTContext &Context);
7070

71+
static
72+
PersistentSourceLoc mkPSL(const clang::Expr *E, clang::ASTContext &Context);
73+
7174
private:
7275
// Create a PersistentSourceLoc based on absolute file path
7376
// from the given SourceRange and SourceLocation.

0 commit comments

Comments
 (0)