Skip to content

Commit

Permalink
EssentialType: Add maxRank predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
lcartey committed Jan 12, 2025
1 parent cd8ea67 commit 7a465dd
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions c/misra/src/codingstandards/c/misra/EssentialTypes.qll
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ class EssentialUnaryMinusExpr extends EssentialExpr, UnaryMinusExpr {
}
}

bindingset[essentialTypeA, essentialTypeB]
private Type maxRankType(Type essentialTypeA, Type essentialTypeB) {
if essentialTypeA.getSize() > essentialTypeB.getSize()
then result = essentialTypeA
else result = essentialTypeB
}

class EssentialConditionalExpr extends EssentialExpr, ConditionalExpr {
override Type getEssentialType() {
exists(Type thenEssentialType, Type elseEssentialType |
Expand All @@ -269,10 +276,7 @@ class EssentialConditionalExpr extends EssentialExpr, ConditionalExpr {
if
getEssentialTypeCategory(thenEssentialType) = getEssentialTypeCategory(elseEssentialType) and
getEssentialTypeCategory(thenEssentialType) instanceof EssentiallySignedOrUnsignedType
then
if thenEssentialType.getSize() > elseEssentialType.getSize()
then result = thenEssentialType
else result = elseEssentialType
then result = maxRankType(thenEssentialType, elseEssentialType)
else result = this.getStandardType()
)
}
Expand Down Expand Up @@ -316,15 +320,11 @@ class EssentialBinaryOperationSubjectToUsualConversions extends EssentialExpr, B
leftEssentialTypeCategory instanceof EssentiallySignedOrUnsignedType
then
if exists(getValue())
then (
then
leftEssentialTypeCategory = EssentiallySignedType() and result = stlr(this)
or
leftEssentialTypeCategory = EssentiallyUnsignedType() and result = utlr(this)
) else (
if leftEssentialType.getSize() > rightEssentialType.getSize()
then result = leftEssentialType
else result = rightEssentialType
)
else result = maxRankType(leftEssentialType, rightEssentialType)
else result = this.getStandardType()
)
}
Expand Down

0 comments on commit 7a465dd

Please sign in to comment.