|
| 1 | +/** |
| 2 | + * EXPERIMENTAL: The API of this module may change without notice. |
| 3 | + * |
| 4 | + * Provides a class for modeling `RangeSsaDefinition`s with a restricted range. |
| 5 | + */ |
| 6 | + |
| 7 | +import cpp |
| 8 | +import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis |
| 9 | + |
| 10 | +/** |
| 11 | + * EXPERIMENTAL: The API of this class may change without notice. |
| 12 | + * |
| 13 | + * An SSA definition for which a range can be deduced. As with |
| 14 | + * `RangeSsaDefinition` and `SsaDefinition`, instances of this class |
| 15 | + * correspond to points in the program where one or more variables are defined |
| 16 | + * or have their value constrained in some way. |
| 17 | + * |
| 18 | + * Extend this class to add functionality to the range analysis library. |
| 19 | + */ |
| 20 | +abstract class SimpleRangeAnalysisDefinition extends RangeSsaDefinition { |
| 21 | + /** |
| 22 | + * Holds if this `SimpleRangeAnalysisDefinition` adds range information for |
| 23 | + * `v`. Because a `SimpleRangeAnalysisDefinition` is just a point in the |
| 24 | + * program, it's possible that more than one variable might be defined at |
| 25 | + * this point. This predicate clarifies which variable(s) should get range |
| 26 | + * information from `this`. |
| 27 | + * |
| 28 | + * This predicate **must be overridden** to hold for any `v` that can show |
| 29 | + * up in the other members of `SimpleRangeAnalysisDefinition`. Conversely, |
| 30 | + * the other members **must be accurate** for any `v` in this predicate. |
| 31 | + */ |
| 32 | + abstract predicate hasRangeInformationFor(StackVariable v); |
| 33 | + |
| 34 | + /** |
| 35 | + * Holds if `(this, v)` depends on the range of the unconverted expression |
| 36 | + * `e`. This information is used to inform the range analysis about cyclic |
| 37 | + * dependencies. Without this information, range analysis might work for |
| 38 | + * simple cases but will go into infinite loops on complex code. |
| 39 | + * |
| 40 | + * For example, when modelling the definition by reference in a call to an |
| 41 | + * overloaded `operator=`, written as `v = e`, the definition of `(this, v)` |
| 42 | + * depends on `e`. |
| 43 | + */ |
| 44 | + abstract predicate dependsOnExpr(StackVariable v, Expr e); |
| 45 | + |
| 46 | + /** |
| 47 | + * Gets the lower bound of the variable `v` defined by this definition. |
| 48 | + * |
| 49 | + * Implementations of this predicate should use |
| 50 | + * `getFullyConvertedLowerBounds` and `getFullyConvertedUpperBounds` for |
| 51 | + * recursive calls to get the bounds of their dependencies. |
| 52 | + */ |
| 53 | + abstract float getLowerBounds(StackVariable v); |
| 54 | + |
| 55 | + /** |
| 56 | + * Gets the upper bound of the variable `v` defined by this definition. |
| 57 | + * |
| 58 | + * Implementations of this predicate should use |
| 59 | + * `getFullyConvertedLowerBounds` and `getFullyConvertedUpperBounds` for |
| 60 | + * recursive calls to get the bounds of their dependencies. |
| 61 | + */ |
| 62 | + abstract float getUpperBounds(StackVariable v); |
| 63 | +} |
| 64 | + |
| 65 | +import SimpleRangeAnalysisInternal |
0 commit comments