From 684045e9e843ed9b8be30728482ce3d69d63b527 Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Thu, 4 Oct 2012 17:11:33 +1000 Subject: Lets keep trying with this here equation system. Still not there, but more non-functional code is there. Splitting blocks into sub-blocks now works, as does some of the guard stuff and the general "shape" of the resulting equation system. --- .../Analyses/IntervalSolver/.#EquationSystem.hpp | 1 - .../IntervalSolver/.#EquationSystem_flymake.hpp | 1 - .../Analyses/IntervalSolver/.#Expression.hpp | 1 - .../IntervalSolver/.#Expression_flymake.hpp | 1 - .../Analyses/IntervalSolver/.#Operator_flymake.hpp | 1 - .../Analyses/IntervalSolver/EquationSystem.hpp | 21 ++++++++++----------- .../Analysis/Analyses/IntervalSolver/Expression.hpp | 5 +++-- .../Analysis/Analyses/IntervalSolver/IdMap.hpp | 2 +- .../Analysis/Analyses/IntervalSolver/Operator.hpp | 7 ++++++- .../Analyses/IntervalSolver/VariableAssignment.hpp | 2 ++ clang/include/clang/Frontend/Analyses.def | 1 + .../Core/PathSensitive/ConstraintManager.h | 2 ++ 12 files changed, 25 insertions(+), 20 deletions(-) delete mode 120000 clang/include/clang/Analysis/Analyses/IntervalSolver/.#EquationSystem.hpp delete mode 120000 clang/include/clang/Analysis/Analyses/IntervalSolver/.#EquationSystem_flymake.hpp delete mode 120000 clang/include/clang/Analysis/Analyses/IntervalSolver/.#Expression.hpp delete mode 120000 clang/include/clang/Analysis/Analyses/IntervalSolver/.#Expression_flymake.hpp delete mode 120000 clang/include/clang/Analysis/Analyses/IntervalSolver/.#Operator_flymake.hpp (limited to 'clang/include') diff --git a/clang/include/clang/Analysis/Analyses/IntervalSolver/.#EquationSystem.hpp b/clang/include/clang/Analysis/Analyses/IntervalSolver/.#EquationSystem.hpp deleted file mode 120000 index 56b9060..0000000 --- a/clang/include/clang/Analysis/Analyses/IntervalSolver/.#EquationSystem.hpp +++ /dev/null @@ -1 +0,0 @@ -carlo@pc-4w14-0.cs.usyd.edu.au.4300:1348200365 \ No newline at end of file diff --git a/clang/include/clang/Analysis/Analyses/IntervalSolver/.#EquationSystem_flymake.hpp b/clang/include/clang/Analysis/Analyses/IntervalSolver/.#EquationSystem_flymake.hpp deleted file mode 120000 index 4dc56be..0000000 --- a/clang/include/clang/Analysis/Analyses/IntervalSolver/.#EquationSystem_flymake.hpp +++ /dev/null @@ -1 +0,0 @@ -carlo@pc-4w14-0.cs.usyd.edu.au.9390:1348126501 \ No newline at end of file diff --git a/clang/include/clang/Analysis/Analyses/IntervalSolver/.#Expression.hpp b/clang/include/clang/Analysis/Analyses/IntervalSolver/.#Expression.hpp deleted file mode 120000 index 4dc56be..0000000 --- a/clang/include/clang/Analysis/Analyses/IntervalSolver/.#Expression.hpp +++ /dev/null @@ -1 +0,0 @@ -carlo@pc-4w14-0.cs.usyd.edu.au.9390:1348126501 \ No newline at end of file diff --git a/clang/include/clang/Analysis/Analyses/IntervalSolver/.#Expression_flymake.hpp b/clang/include/clang/Analysis/Analyses/IntervalSolver/.#Expression_flymake.hpp deleted file mode 120000 index 4dc56be..0000000 --- a/clang/include/clang/Analysis/Analyses/IntervalSolver/.#Expression_flymake.hpp +++ /dev/null @@ -1 +0,0 @@ -carlo@pc-4w14-0.cs.usyd.edu.au.9390:1348126501 \ No newline at end of file diff --git a/clang/include/clang/Analysis/Analyses/IntervalSolver/.#Operator_flymake.hpp b/clang/include/clang/Analysis/Analyses/IntervalSolver/.#Operator_flymake.hpp deleted file mode 120000 index 4dc56be..0000000 --- a/clang/include/clang/Analysis/Analyses/IntervalSolver/.#Operator_flymake.hpp +++ /dev/null @@ -1 +0,0 @@ -carlo@pc-4w14-0.cs.usyd.edu.au.9390:1348126501 \ No newline at end of file diff --git a/clang/include/clang/Analysis/Analyses/IntervalSolver/EquationSystem.hpp b/clang/include/clang/Analysis/Analyses/IntervalSolver/EquationSystem.hpp index 701da7c..d95366d 100644 --- a/clang/include/clang/Analysis/Analyses/IntervalSolver/EquationSystem.hpp +++ b/clang/include/clang/Analysis/Analyses/IntervalSolver/EquationSystem.hpp @@ -91,22 +91,18 @@ struct EquationSystem { void indexMaxExpressions() { _expr_to_var = new IdMap,Variable*>(maxExpressionCount(), NULL); for (unsigned int i = 0, length = _right_sides.size(); i < length; ++i) { - _right_sides[i]->mapTo(*_variables[i], *_expr_to_var); + if (_right_sides[i]) + _right_sides[i]->mapTo(*_variables[i], *_expr_to_var); } } Variable* varFromExpr(const Expression& expr) const { - if (_expr_to_var) { // we've indexed: - const MaxExpression* maxExpr = expr.toMaxExpression();//dynamic_cast*>(&expr); - if (maxExpr) { - return (*_expr_to_var)[*maxExpr]; - } else { - return NULL; - } + assert(_expr_to_var != NULL); // ensure we've indexed + const MaxExpression* maxExpr = expr.toMaxExpression();//dynamic_cast*>(&expr); + if (maxExpr) { + return (*_expr_to_var)[*maxExpr]; } else { - std::cout << "throw exception" << *(char*)NULL; return NULL; - //throw "Must index max expressions before attempting lookup"; } } @@ -125,7 +121,10 @@ struct EquationSystem { for (unsigned int i = 0, length = _variables.size(); i < length; ++i) { - cout << *_variables[i] << " = " << *_right_sides[i] << std::endl; + if (_right_sides[i]) + cout << *_variables[i] << " = " << *_right_sides[i] << std::endl; + else + cout << *_variables[i] << " = NULL" << std::endl; } } diff --git a/clang/include/clang/Analysis/Analyses/IntervalSolver/Expression.hpp b/clang/include/clang/Analysis/Analyses/IntervalSolver/Expression.hpp index 7b0f2cf..c4ee4c0 100644 --- a/clang/include/clang/Analysis/Analyses/IntervalSolver/Expression.hpp +++ b/clang/include/clang/Analysis/Analyses/IntervalSolver/Expression.hpp @@ -84,7 +84,9 @@ struct Variable : public Expression { template struct OperatorExpression : public Expression { OperatorExpression(const Operator& op, const std::vector*>& arguments) - : _operator(op), _arguments(arguments) { } + : _operator(op), _arguments(arguments) { + assert(!arguments.empty()); + } virtual Domain eval(const VariableAssignment& rho) const { std::vector argumentValues; @@ -145,7 +147,6 @@ struct MaxExpression : public OperatorExpression { MaxExpression(const unsigned int& id, const Maximum& op, const std::vector*>& arguments) : OperatorExpression(op, arguments), _id(id) { } - const MaxExpression* toMaxExpression() const { return this; } diff --git a/clang/include/clang/Analysis/Analyses/IntervalSolver/IdMap.hpp b/clang/include/clang/Analysis/Analyses/IntervalSolver/IdMap.hpp index 27c0806..5e3aa3b 100644 --- a/clang/include/clang/Analysis/Analyses/IntervalSolver/IdMap.hpp +++ b/clang/include/clang/Analysis/Analyses/IntervalSolver/IdMap.hpp @@ -7,7 +7,7 @@ template struct IdMap { IdMap(unsigned int length, V initial) : _length(length), _assignment(new V[length]) { - for (unsigned int i = 0; i < _length; ++i) { + for (unsigned int i = 0; i < length; ++i) { _assignment[i] = initial; } } diff --git a/clang/include/clang/Analysis/Analyses/IntervalSolver/Operator.hpp b/clang/include/clang/Analysis/Analyses/IntervalSolver/Operator.hpp index b67591f..08c66ff 100644 --- a/clang/include/clang/Analysis/Analyses/IntervalSolver/Operator.hpp +++ b/clang/include/clang/Analysis/Analyses/IntervalSolver/Operator.hpp @@ -28,6 +28,11 @@ struct Maximum : public Operator { } }; + +template +T minimum(const T& l, const T& r) { + return (l < r ? l : r); +} template struct Minimum : public Operator { virtual Domain eval(const std::vector& arguments) const { @@ -35,7 +40,7 @@ struct Minimum : public Operator { for (typename std::vector::const_iterator it = arguments.begin(); it != arguments.end(); ++it) { - result = (*it < result ? *it : result); + result = minimum(*it, result); //*it < result ? *it : result); } return result; } diff --git a/clang/include/clang/Analysis/Analyses/IntervalSolver/VariableAssignment.hpp b/clang/include/clang/Analysis/Analyses/IntervalSolver/VariableAssignment.hpp index d2adff5..0bbebfc 100644 --- a/clang/include/clang/Analysis/Analyses/IntervalSolver/VariableAssignment.hpp +++ b/clang/include/clang/Analysis/Analyses/IntervalSolver/VariableAssignment.hpp @@ -47,6 +47,8 @@ private: solver_log::fixpoint << indent() << "Stabilise " << x << std::endl; stack_depth++; + if (!_system[x]) + return; Domain val = _system[x]->eval(DependencyAssignment(*this, x), _strategy); stack_depth--; diff --git a/clang/include/clang/Frontend/Analyses.def b/clang/include/clang/Frontend/Analyses.def index b5b9394..902575f 100644 --- a/clang/include/clang/Frontend/Analyses.def +++ b/clang/include/clang/Frontend/Analyses.def @@ -23,6 +23,7 @@ ANALYSIS_STORE(RegionStore, "region", "Use region-based analyzer store", CreateR ANALYSIS_CONSTRAINTS(BasicConstraints, "basic", "Use basic constraint tracking", CreateBasicConstraintManager) ANALYSIS_CONSTRAINTS(RangeConstraints, "range", "Use constraint tracking of concrete value ranges", CreateRangeConstraintManager) +ANALYSIS_CONSTRAINTS(IntervalConstraints, "interval", "Use constraint tracking of intervals", CreateIntervalConstraintManager) #ifndef ANALYSIS_DIAGNOSTICS #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN, AUTOCREATE) diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h index 631858d..4051cfc 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h @@ -73,6 +73,8 @@ ConstraintManager* CreateBasicConstraintManager(ProgramStateManager& statemgr, SubEngine &subengine); ConstraintManager* CreateRangeConstraintManager(ProgramStateManager& statemgr, SubEngine &subengine); +ConstraintManager* CreateIntervalConstraintManager(ProgramStateManager& statemgr, + SubEngine &subengine); } // end GR namespace -- cgit v1.2.3