Skip to content

Commit a498523

Browse files
committed
Rule 10.7: Avoid performance issues
The essential type categories were joined prematurely, causing a cross product of all results against all types of the same essential type category. Fixed by ensuring the essential type category join occurs late.
1 parent c3b4f5a commit a498523

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

c/misra/src/rules/RULE-10-7/ImplicitConversionOfCompositeExpression.ql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ import codingstandards.c.misra
1818
import codingstandards.c.misra.EssentialTypes
1919
import codingstandards.c.misra.MisraExpressions
2020

21+
bindingset[essentialTypeLeft, essentialTypeRight]
22+
pragma[inline_late]
23+
predicate isSameEssentialTypeCategory(Type essentialTypeLeft, Type essentialTypeRight) {
24+
getEssentialTypeCategory(essentialTypeLeft) = getEssentialTypeCategory(essentialTypeRight)
25+
}
26+
2127
from
2228
OperationWithUsualArithmeticConversions arith, CompositeExpression compositeOp, Expr otherOp,
2329
Type compositeEssentialType, Type otherOpEssentialType
@@ -32,7 +38,7 @@ where
3238
// Operands of a different type category in an operation with the usual arithmetic conversions is
3339
// prohibited by Rule 10.4, so we only report cases here where the essential type categories are
3440
// the same
35-
getEssentialTypeCategory(compositeEssentialType) = getEssentialTypeCategory(otherOpEssentialType)
41+
isSameEssentialTypeCategory(compositeEssentialType, otherOpEssentialType)
3642
select arith,
3743
"Implicit conversion of $@ from " + compositeEssentialType + " to " + otherOpEssentialType,
3844
compositeOp, "composite op"

0 commit comments

Comments
 (0)