Skip to content

CERT/MISRA C - Address performance issues #723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading