Skip to content

Commit

Permalink
Merge pull request #723 from github/lcartey/address-perf-problems
Browse files Browse the repository at this point in the history
CERT/MISRA C - Address performance issues
  • Loading branch information
knewbury01 authored Oct 2, 2024
2 parents 7f62053 + 96d1715 commit c4dafe7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ import codingstandards.c.Signal
*/
class UnsafeSharedVariableAccess extends VariableAccess {
UnsafeSharedVariableAccess() {
// static or thread local storage duration
(
this.getTarget() instanceof StaticStorageDurationVariable or
this.getTarget().isThreadLocal()
) and
// excluding `volatile sig_atomic_t` type
not this.getType().(SigAtomicType).isVolatile() and
// excluding lock-free atomic objects
not exists(MacroInvocation mi, VariableAccess va |
mi.getMacroName() = "atomic_is_lock_free" and
mi.getExpr().getChild(0) = va.getEnclosingElement*() and
va.getTarget() = this.getTarget()
exists(Variable target | target = this.getTarget() |
// static or thread local storage duration
(
target instanceof StaticStorageDurationVariable or
target.isThreadLocal()
) and
// excluding lock-free atomic objects
not exists(MacroInvocation mi, VariableAccess va | va.getTarget() = target |
mi.getMacroName() = "atomic_is_lock_free" and
mi.getExpr().getChild(0) = va.getEnclosingElement*()
)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import codingstandards.c.misra
import codingstandards.c.misra.EssentialTypes
import codingstandards.c.misra.MisraExpressions

bindingset[essentialTypeLeft, essentialTypeRight]
pragma[inline_late]
predicate isSameEssentialTypeCategory(Type essentialTypeLeft, Type essentialTypeRight) {
getEssentialTypeCategory(essentialTypeLeft) = getEssentialTypeCategory(essentialTypeRight)
}

from
OperationWithUsualArithmeticConversions arith, CompositeExpression compositeOp, Expr otherOp,
Type compositeEssentialType, Type otherOpEssentialType
Expand All @@ -32,7 +38,7 @@ where
// Operands of a different type category in an operation with the usual arithmetic conversions is
// prohibited by Rule 10.4, so we only report cases here where the essential type categories are
// the same
getEssentialTypeCategory(compositeEssentialType) = getEssentialTypeCategory(otherOpEssentialType)
isSameEssentialTypeCategory(compositeEssentialType, otherOpEssentialType)
select arith,
"Implicit conversion of $@ from " + compositeEssentialType + " to " + otherOpEssentialType,
compositeOp, "composite op"
4 changes: 4 additions & 0 deletions change_notes/2024-10-02-c-perf-issues.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- `RULE-10-7` - `ImplicitConversionOfCompositeExpression.ql`:
- Improved performance on larger codebases.
- `SIG31-C` - `DoNotAccessSharedObjectsInSignalHandlers.ql`:
- Improved performance on larger codebases.

0 comments on commit c4dafe7

Please sign in to comment.