Skip to content

Commit 09984a4

Browse files
committed
C++: The extractor already provides the getValue result when the variable is a local variable. Thus we can simplify the QL code.
1 parent e1942bb commit 09984a4

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

cpp/ql/src/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,23 @@ private float wideningUpperBounds(ArithmeticType t) {
9393

9494
/**
9595
* Gets the value of the expression `e`, if it is a constant.
96-
* This predicate also handles the case of constant variables initialized in compilation units,
97-
* which doesn't necessarily have a getValue() result from the extractor.
96+
* This predicate also handles the case of constant variables initialized in different
97+
* compilation units, which doesn't necessarily have a getValue() result from the extractor.
9898
*/
9999
private string getValue(Expr e) {
100100
if exists(e.getValue())
101101
then result = e.getValue()
102102
else
103-
exists(VariableAccess access, Variable v |
104-
/*
105-
* It should be safe to propagate the initialization value to a variable if:
106-
* The type of v is const, and
107-
* The type of v is not volatile, and
108-
* Either:
109-
* v is a local/global variable, or
110-
* v is a static member variable
111-
*/
103+
/*
104+
* It should be safe to propagate the initialization value to a variable if:
105+
* The type of v is const, and
106+
* The type of v is not volatile, and
107+
* Either:
108+
* v is a local/global variable, or
109+
* v is a static member variable
110+
*/
112111

113-
(v instanceof StaticStorageDurationVariable or v instanceof LocalVariable) and
112+
exists(VariableAccess access, StaticStorageDurationVariable v |
114113
not v.getUnderlyingType().isVolatile() and
115114
v.getUnderlyingType().isConst() and
116115
e = access and

0 commit comments

Comments
 (0)