Merge pull request #4324 from tamasvajk/feature/unsigned-sign-analysis

Handle unsigned types in sign analysis (C# and Java)
This commit is contained in:
Anders Schack-Mulligen
2020-10-01 15:11:49 +02:00
committed by GitHub
9 changed files with 122 additions and 41 deletions

View File

@@ -245,24 +245,30 @@ Sign ssaDefSign(SsaVariable v) {
/** Gets a possible sign for `e`. */
cached
Sign exprSign(Expr e) {
result = certainExprSign(e)
or
not exists(certainExprSign(e)) and
(
unknownSign(e)
exists(Sign s |
s = certainExprSign(e)
or
exists(SsaVariable v | getARead(v) = e | result = ssaVariableSign(v, e))
or
e =
any(VarAccess access |
not exists(SsaVariable v | getARead(v) = access) and
(
result = fieldSign(getField(access.(FieldAccess))) or
not access instanceof FieldAccess
not exists(certainExprSign(e)) and
(
unknownSign(e)
or
exists(SsaVariable v | getARead(v) = e | s = ssaVariableSign(v, e))
or
e =
any(VarAccess access |
not exists(SsaVariable v | getARead(v) = access) and
(
s = fieldSign(getField(access.(FieldAccess))) or
not access instanceof FieldAccess
)
)
)
or
result = specificSubExprSign(e)
or
s = specificSubExprSign(e)
)
|
if e.getType() instanceof UnsignedNumericType and s = TNeg()
then result = TPos()
else result = s
)
}

View File

@@ -53,6 +53,8 @@ private module Impl {
private import SignAnalysisCommon
private import SsaReadPositionCommon
class UnsignedNumericType = CharacterType;
float getNonIntegerValue(Expr e) {
result = e.(LongLiteral).getValue().toFloat() or
result = e.(FloatingPointLiteral).getValue().toFloat() or