diff --git a/c/cert/src/rules/SIG31-C/DoNotAccessSharedObjectsInSignalHandlers.ql b/c/cert/src/rules/SIG31-C/DoNotAccessSharedObjectsInSignalHandlers.ql index 8f9e90701..2a7a6a77f 100644 --- a/c/cert/src/rules/SIG31-C/DoNotAccessSharedObjectsInSignalHandlers.ql +++ b/c/cert/src/rules/SIG31-C/DoNotAccessSharedObjectsInSignalHandlers.ql @@ -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*() + ) ) } } diff --git a/c/misra/src/rules/RULE-10-7/ImplicitConversionOfCompositeExpression.ql b/c/misra/src/rules/RULE-10-7/ImplicitConversionOfCompositeExpression.ql index 1cf20378f..3aa324b66 100644 --- a/c/misra/src/rules/RULE-10-7/ImplicitConversionOfCompositeExpression.ql +++ b/c/misra/src/rules/RULE-10-7/ImplicitConversionOfCompositeExpression.ql @@ -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 @@ -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" diff --git a/change_notes/2024-10-02-c-perf-issues.md b/change_notes/2024-10-02-c-perf-issues.md new file mode 100644 index 000000000..c9fcac1a0 --- /dev/null +++ b/change_notes/2024-10-02-c-perf-issues.md @@ -0,0 +1,4 @@ + - `RULE-10-7` - `ImplicitConversionOfCompositeExpression.ql`: + - Improved performance on larger codebases. + - `SIG31-C` - `DoNotAccessSharedObjectsInSignalHandlers.ql`: + - Improved performance on larger codebases. \ No newline at end of file