Skip to content

Commit

Permalink
Check called functions with noexcept(unknown)
Browse files Browse the repository at this point in the history
  • Loading branch information
rak3-sh committed Dec 19, 2024
1 parent 6a0da2b commit f5394d0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion change_notes/2024-12-17-fix-fp-824-a15-4-4
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- `A15-4-4` - `MissingNoExcept.ql`:
- Reduce false positives by not reporting on functions that have a noexcept specification with a complex expression.
- Reduce false positives by not reporting on functions that have a noexcept specification with a complex expression or call other such functions.
33 changes: 33 additions & 0 deletions cpp/autosar/src/rules/A15-4-4/MissingNoExcept.ql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,36 @@ import codingstandards.cpp.autosar
import codingstandards.cpp.exceptions.ExceptionSpecifications
import codingstandards.cpp.exceptions.ExceptionFlow

// These functions have a noexcept specification that could not be resolved
// to noexcept(true). So either, they are noexcept(false) functions which
// means, they can throw an exception OR they have an expression which
// could not be resolved to "true" or "false". Even in this case, lets
// be more conservative and assume they may thrown an exception.
class FunctionWithUnknownNoExcept extends Function {
FunctionWithUnknownNoExcept() {
// Exists a noexcept specification but not noexcept(true)
exists(this.getADeclarationEntry().getNoExceptExpr()) and
not isNoExceptTrue(this)
}
}

// This predicate checks if a function can call to other functions
// that may have a noexcept specification which cannot be resolved to
// noexcept(true).
predicate mayCallThrowingFunctions(Function f) {
// Exists a call in this function
exists(Call fc |
fc.getEnclosingFunction() = f and
(
// Either this call is to a function with an unknown noexcept OR
fc.getTarget() instanceof FunctionWithUnknownNoExcept
or
// That function can further have calls to unknown noexcept functions.
mayCallThrowingFunctions(fc.getTarget())
)
)
}

from Function f
where
not isExcluded(f, Exceptions1Package::missingNoExceptQuery()) and
Expand All @@ -31,6 +61,9 @@ where
// Not having a noexcept specification that
// could not be computed as true or false above.
not exists(f.getADeclarationEntry().getNoExceptExpr()) and
// Not calling function(s) which have a noexcept specification that
// could not be computed as true.
not mayCallThrowingFunctions(f) and
// Not compiler generated
not f.isCompilerGenerated() and
// The function is defined in this database
Expand Down

0 comments on commit f5394d0

Please sign in to comment.