Skip to content

Commit ec0e4bc

Browse files
committed
A0-4-4: Convert into shared query
Enable sharing with FLP32-C.
1 parent c6c8788 commit ec0e4bc

File tree

7 files changed

+86
-65
lines changed

7 files changed

+86
-65
lines changed

cpp/autosar/src/rules/A0-4-4/UncheckedRangeDomainPoleErrors.ql

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -15,69 +15,10 @@
1515

1616
import cpp
1717
import codingstandards.cpp.autosar
18-
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
18+
import codingstandards.cpp.rules.uncheckedrangedomainpoleerrors.UncheckedRangeDomainPoleErrors
1919

20-
bindingset[name]
21-
Function getMathVariants(string name) { result.hasGlobalOrStdName([name, name + "f", name + "l"]) }
22-
23-
predicate hasDomainError(FunctionCall fc, string description) {
24-
exists(Function functionWithDomainError | fc.getTarget() = functionWithDomainError |
25-
functionWithDomainError = [getMathVariants(["acos", "asin", "atanh"])] and
26-
not (
27-
upperBound(fc.getArgument(0)) <= 1.0 and
28-
lowerBound(fc.getArgument(0)) >= -1.0
29-
) and
30-
description =
31-
"the argument has a range " + lowerBound(fc.getArgument(0)) + "..." +
32-
upperBound(fc.getArgument(0)) + " which is outside the domain of this function (-1.0...1.0)"
33-
or
34-
functionWithDomainError = getMathVariants(["atan2", "pow"]) and
35-
(
36-
fc.getArgument(0).getValue().toFloat() = 0 and
37-
fc.getArgument(1).getValue().toFloat() = 0 and
38-
description = "both arguments are equal to zero"
39-
)
40-
or
41-
functionWithDomainError = getMathVariants("pow") and
42-
(
43-
upperBound(fc.getArgument(0)) < 0.0 and
44-
upperBound(fc.getArgument(1)) < 0.0 and
45-
description = "both arguments are less than zero"
46-
)
47-
or
48-
functionWithDomainError = getMathVariants("acosh") and
49-
upperBound(fc.getArgument(0)) < 1.0 and
50-
description = "argument is less than 1"
51-
or
52-
functionWithDomainError = getMathVariants(["ilogb", "logb", "tgamma"]) and
53-
fc.getArgument(0).getValue().toFloat() = 0 and
54-
description = "argument is equal to zero"
55-
or
56-
functionWithDomainError = getMathVariants(["log", "log10", "log2", "sqrt"]) and
57-
upperBound(fc.getArgument(0)) < 0.0 and
58-
description = "argument is negative"
59-
or
60-
functionWithDomainError = getMathVariants("log1p") and
61-
upperBound(fc.getArgument(0)) < -1.0 and
62-
description = "argument is less than 1"
63-
)
20+
class UncheckedRangeDomainPoleErrorsQuery extends UncheckedRangeDomainPoleErrorsSharedQuery {
21+
UncheckedRangeDomainPoleErrorsQuery() {
22+
this = TypeRangesPackage::uncheckedRangeDomainPoleErrorsQuery()
23+
}
6424
}
65-
66-
/*
67-
* Domain cases not covered by this query:
68-
* - pow - x is finite and negative and y is finite and not an integer value.
69-
* - tgamma - negative integer can't be covered.
70-
* - lrint/llrint/lround/llround - no domain errors checked
71-
* - fmod - no domain errors checked.
72-
* - remainder - no domain errors checked.
73-
* - remquo - no domain errors checked.
74-
*
75-
* Implementations may also define their own domain errors (as per the C99 standard), which are not
76-
* covered by this query.
77-
*/
78-
79-
from FunctionCall fc, string description
80-
where
81-
not isExcluded(fc, TypeRangesPackage::uncheckedRangeDomainPoleErrorsQuery()) and
82-
hasDomainError(fc, description)
83-
select fc, "Domain error in call to " + fc.getTarget().getName() + ": " + description + "."

cpp/autosar/test/rules/A0-4-4/UncheckedRangeDomainPoleErrors.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/uncheckedrangedomainpoleerrors/UncheckedRangeDomainPoleErrors.ql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Provides a library which includes a `problems` predicate for reporting unchecked range, domain and pole errors.
3+
*/
4+
5+
import cpp
6+
import codingstandards.cpp.CodingStandards
7+
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
8+
9+
abstract class UncheckedRangeDomainPoleErrorsSharedQuery extends Query { }
10+
11+
Query getQuery() { result instanceof UncheckedRangeDomainPoleErrorsSharedQuery }
12+
13+
bindingset[name]
14+
Function getMathVariants(string name) { result.hasGlobalOrStdName([name, name + "f", name + "l"]) }
15+
16+
predicate hasDomainError(FunctionCall fc, string description) {
17+
exists(Function functionWithDomainError | fc.getTarget() = functionWithDomainError |
18+
functionWithDomainError = [getMathVariants(["acos", "asin", "atanh"])] and
19+
not (
20+
upperBound(fc.getArgument(0)) <= 1.0 and
21+
lowerBound(fc.getArgument(0)) >= -1.0
22+
) and
23+
description =
24+
"the argument has a range " + lowerBound(fc.getArgument(0)) + "..." +
25+
upperBound(fc.getArgument(0)) + " which is outside the domain of this function (-1.0...1.0)"
26+
or
27+
functionWithDomainError = getMathVariants(["atan2", "pow"]) and
28+
(
29+
fc.getArgument(0).getValue().toFloat() = 0 and
30+
fc.getArgument(1).getValue().toFloat() = 0 and
31+
description = "both arguments are equal to zero"
32+
)
33+
or
34+
functionWithDomainError = getMathVariants("pow") and
35+
(
36+
upperBound(fc.getArgument(0)) < 0.0 and
37+
upperBound(fc.getArgument(1)) < 0.0 and
38+
description = "both arguments are less than zero"
39+
)
40+
or
41+
functionWithDomainError = getMathVariants("acosh") and
42+
upperBound(fc.getArgument(0)) < 1.0 and
43+
description = "argument is less than 1"
44+
or
45+
functionWithDomainError = getMathVariants(["ilogb", "logb", "tgamma"]) and
46+
fc.getArgument(0).getValue().toFloat() = 0 and
47+
description = "argument is equal to zero"
48+
or
49+
functionWithDomainError = getMathVariants(["log", "log10", "log2", "sqrt"]) and
50+
upperBound(fc.getArgument(0)) < 0.0 and
51+
description = "argument is negative"
52+
or
53+
functionWithDomainError = getMathVariants("log1p") and
54+
upperBound(fc.getArgument(0)) < -1.0 and
55+
description = "argument is less than 1"
56+
)
57+
}
58+
59+
/*
60+
* Domain cases not covered by this query:
61+
* - pow - x is finite and negative and y is finite and not an integer value.
62+
* - tgamma - negative integer can't be covered.
63+
* - lrint/llrint/lround/llround - no domain errors checked
64+
* - fmod - no domain errors checked.
65+
* - remainder - no domain errors checked.
66+
* - remquo - no domain errors checked.
67+
*
68+
* Implementations may also define their own domain errors (as per the C99 standard), which are not
69+
* covered by this query.
70+
*/
71+
72+
query predicate problems(FunctionCall fc, string message) {
73+
not isExcluded(fc, getQuery()) and
74+
exists(string description |
75+
hasDomainError(fc, description) and
76+
message = "Domain error in call to " + fc.getTarget().getName() + ": " + description + "."
77+
)
78+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.uncheckedrangedomainpoleerrors.UncheckedRangeDomainPoleErrors

0 commit comments

Comments
 (0)