diff --git a/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/FloatDelta.qll b/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/FloatDelta.qll index f6004cdaa80..d112cac1a75 100644 --- a/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/FloatDelta.qll +++ b/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/FloatDelta.qll @@ -21,7 +21,7 @@ module FloatDelta implements DeltaSig { } module FloatOverflow implements OverflowSig { - predicate semExprDoesntOverflow(boolean positively, SemExpr expr) { + predicate semExprDoesNotOverflow(boolean positively, SemExpr expr) { exists(float lb, float ub, float delta | typeBounds(expr.getSemType(), lb, ub) and ConstantStage::initialBounded(expr, any(ConstantBounds::SemZeroBound b), delta, positively, _, _, _) @@ -31,17 +31,8 @@ module FloatOverflow implements OverflowSig { positively = false and delta > lb ) } -/* - predicate semExprOverflow(float delta, boolean upper, SemExpr expr) { - exists(float lb, float ub | typeBounds(expr.getSemType(), lb, ub) | - upper = false and delta < lb - or - upper = true and delta > ub - ) - } - */ - predicate typeBounds(SemType t, float lb, float ub) { + additional predicate typeBounds(SemType t, float lb, float ub) { exists(SemIntegerType integralType, float limit | integralType = t and limit = 2.pow(8 * integralType.getByteSize()) | diff --git a/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisSpecific.qll b/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisConstantSpecific.qll similarity index 98% rename from cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisSpecific.qll rename to cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisConstantSpecific.qll index 2ddc20c8a33..42edb904c3f 100644 --- a/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisSpecific.qll +++ b/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisConstantSpecific.qll @@ -6,7 +6,7 @@ private import semmle.code.cpp.rangeanalysis.new.internal.semantic.Semantic private import RangeAnalysisStage private import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.FloatDelta -module CppLangImpl implements LangSig { +module CppLangImplConstant implements LangSig { /** * Holds if the specified expression should be excluded from the result of `ssaRead()`. * diff --git a/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisImpl.qll b/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisImpl.qll index 2026a21c652..a8613efe7a3 100644 --- a/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisImpl.qll +++ b/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisImpl.qll @@ -1,5 +1,6 @@ private import RangeAnalysisStage -private import RangeAnalysisSpecific +private import RangeAnalysisConstantSpecific +private import RangeAnalysisRelativeSpecific private import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.FloatDelta private import RangeUtils private import semmle.code.cpp.rangeanalysis.new.internal.semantic.SemanticBound as SemanticBound @@ -47,10 +48,10 @@ module RelativeBounds implements BoundSig { } module ConstantStage = - RangeStage>; + RangeStage>; module RelativeStage = - RangeStage>; + RangeStage>; private newtype TSemReason = TSemNoReason() or diff --git a/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisSpecific2.qll b/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisRelativeSpecific.qll similarity index 98% rename from cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisSpecific2.qll rename to cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisRelativeSpecific.qll index e4955e0ee8b..20fe2603078 100644 --- a/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisSpecific2.qll +++ b/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisRelativeSpecific.qll @@ -9,7 +9,7 @@ private import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.IntD private import RangeAnalysisImpl private import semmle.code.cpp.rangeanalysis.RangeAnalysisUtils -module CppLangImpl2 implements LangSig { +module CppLangImplRelative implements LangSig { /** * Holds if the specified expression should be excluded from the result of `ssaRead()`. * diff --git a/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisStage.qll b/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisStage.qll index 2554f999c8b..ef47ab79b0e 100644 --- a/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisStage.qll +++ b/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisStage.qll @@ -242,7 +242,7 @@ signature module BoundSig { } signature module OverflowSig { - predicate semExprDoesntOverflow(boolean positively, SemExpr expr); + predicate semExprDoesNotOverflow(boolean positively, SemExpr expr); } module RangeStage< @@ -935,12 +935,10 @@ module RangeStage< ) { initialBounded(e, b, delta, upper, fromBackEdge, origdelta, reason) and ( - semExprDoesntOverflow(upper.booleanNot(), e) + semExprDoesNotOverflow(upper.booleanNot(), e) or not potentiallyOverflowingExpr(upper.booleanNot(), e) or - initialBounded(e, any(SemZeroBound z), _, upper.booleanNot(), _, _, _) - or exists(D::Delta otherDelta | initialBounded(e, _, otherDelta, upper.booleanNot(), _, _, _) and ( diff --git a/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeUtils.qll b/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeUtils.qll index 7eeed5d7975..32510409ae2 100644 --- a/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeUtils.qll +++ b/cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeUtils.qll @@ -3,7 +3,7 @@ */ private import semmle.code.cpp.rangeanalysis.new.internal.semantic.Semantic -private import RangeAnalysisSpecific +private import RangeAnalysisRelativeSpecific private import RangeAnalysisStage as Range private import ConstantAnalysis