mirror of
https://github.com/github/codeql.git
synced 2026-04-25 08:45:14 +02:00
Merge pull request #4324 from tamasvajk/feature/unsigned-sign-analysis
Handle unsigned types in sign analysis (C# and Java)
This commit is contained in:
@@ -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
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user