C++: The extractor already provides the getValue result when the variable is a local variable. Thus we can simplify the QL code.

This commit is contained in:
Mathias Vorreiter Pedersen 2020-03-13 17:57:01 +01:00
Родитель e1942bbee1
Коммит 09984a4068
1 изменённых файлов: 11 добавлений и 12 удалений

Просмотреть файл

@ -93,24 +93,23 @@ private float wideningUpperBounds(ArithmeticType t) {
/**
* Gets the value of the expression `e`, if it is a constant.
* This predicate also handles the case of constant variables initialized in compilation units,
* which doesn't necessarily have a getValue() result from the extractor.
* This predicate also handles the case of constant variables initialized in different
* compilation units, which doesn't necessarily have a getValue() result from the extractor.
*/
private string getValue(Expr e) {
if exists(e.getValue())
then result = e.getValue()
else
exists(VariableAccess access, Variable v |
/*
* It should be safe to propagate the initialization value to a variable if:
* The type of v is const, and
* The type of v is not volatile, and
* Either:
* v is a local/global variable, or
* v is a static member variable
*/
/*
* It should be safe to propagate the initialization value to a variable if:
* The type of v is const, and
* The type of v is not volatile, and
* Either:
* v is a local/global variable, or
* v is a static member variable
*/
(v instanceof StaticStorageDurationVariable or v instanceof LocalVariable) and
exists(VariableAccess access, StaticStorageDurationVariable v |
not v.getUnderlyingType().isVolatile() and
v.getUnderlyingType().isConst() and
e = access and