Skip to content

Commit c4dafe7

Browse files
authored
Merge pull request #723 from github/lcartey/address-perf-problems
CERT/MISRA C - Address performance issues
2 parents 7f62053 + 96d1715 commit c4dafe7

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

c/cert/src/rules/SIG31-C/DoNotAccessSharedObjectsInSignalHandlers.ql

+11-10
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@ import codingstandards.c.Signal
2121
*/
2222
class UnsafeSharedVariableAccess extends VariableAccess {
2323
UnsafeSharedVariableAccess() {
24-
// static or thread local storage duration
25-
(
26-
this.getTarget() instanceof StaticStorageDurationVariable or
27-
this.getTarget().isThreadLocal()
28-
) and
2924
// excluding `volatile sig_atomic_t` type
3025
not this.getType().(SigAtomicType).isVolatile() and
31-
// excluding lock-free atomic objects
32-
not exists(MacroInvocation mi, VariableAccess va |
33-
mi.getMacroName() = "atomic_is_lock_free" and
34-
mi.getExpr().getChild(0) = va.getEnclosingElement*() and
35-
va.getTarget() = this.getTarget()
26+
exists(Variable target | target = this.getTarget() |
27+
// static or thread local storage duration
28+
(
29+
target instanceof StaticStorageDurationVariable or
30+
target.isThreadLocal()
31+
) and
32+
// excluding lock-free atomic objects
33+
not exists(MacroInvocation mi, VariableAccess va | va.getTarget() = target |
34+
mi.getMacroName() = "atomic_is_lock_free" and
35+
mi.getExpr().getChild(0) = va.getEnclosingElement*()
36+
)
3637
)
3738
}
3839
}

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

+7-1
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"
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- `RULE-10-7` - `ImplicitConversionOfCompositeExpression.ql`:
2+
- Improved performance on larger codebases.
3+
- `SIG31-C` - `DoNotAccessSharedObjectsInSignalHandlers.ql`:
4+
- Improved performance on larger codebases.

0 commit comments

Comments
 (0)