Skip to content

Commit e1fb019

Browse files
committed
Merge branch 'main' into next
2 parents 35c9fd2 + 64d17a9 commit e1fb019

15 files changed

+186
-64
lines changed

c/misra/test/rules/RULE-22-3/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void f8(void) {
4646
void f9(void) {
4747
char name[50] = "tmp9";
4848
char ext[] = "txt";
49-
char file[] = strcat(name, ext);
49+
char *file = strcat(name, ext);
5050
FILE *fw = fopen(file, "r+");
5151
FILE *fr = fopen(strcat(name, ext), "r"); // NON_COMPLIANT[FALSE_NEGATIVE]
5252
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- `A0-1-2`
2+
- Addressed false positives where the return values are cast to `void` in C-style or assigned to `std::ignore`.
3+
- `A0-1-4`
4+
- Addressed false positives where the parameters are marked with attribute `[[maybe_unused]]`, or either cast to `void` in C-style or assigned to `std::ignore` in the function body.

cpp/autosar/src/rules/A12-1-1/ExplicitConstructorBaseClassInitialization.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ where
3535
not init.isCompilerGenerated()
3636
) and
3737
// Must be a defined constructor
38-
c.isDefined() and
38+
c.hasDefinition() and
3939
// Not a compiler-generated constructor
4040
not c.isCompilerGenerated() and
4141
// Not a defaulted constructor

cpp/autosar/src/rules/A2-10-4/IdentifierNameOfStaticFunctionReusedInNamespace.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import codingstandards.cpp.autosar
1717

1818
class CandidateFunction extends Function {
1919
CandidateFunction() {
20-
isDefined() and
20+
hasDefinition() and
2121
isStatic() and
2222
not isMember() and
2323
not (

cpp/autosar/src/rules/A3-1-1/ViolationsOfOneDefinitionRule.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ where
6565
or
6666
//an non-const object defined in a header
6767
exists(GlobalOrNamespaceVariable object |
68-
object.isDefined() and
68+
object.hasDefinition() and
6969
not (
7070
object.isConstexpr()
7171
or

cpp/autosar/src/rules/M14-6-1/NameInDependentBase.qll

Lines changed: 92 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,112 @@ import cpp
22
import codingstandards.cpp.autosar
33

44
/**
5-
* Just the reverse of `Class.getABaseClass()`
5+
* Gets a dependent base type of the given template class.
6+
*
7+
* This returns the `TemplateClass` for the base type, rather than the `ClassTemplateInstantiation`,
8+
* as the instantiation does not appear to include any member declarations.
69
*/
7-
Class getParent(Class child) { child.getABaseClass() = result }
10+
TemplateClass getADependentBaseType(TemplateClass t) {
11+
exists(ClassTemplateInstantiation baseType |
12+
baseType = t.getABaseClass() and
13+
// Base type depends on at least one of the template parameters of class t
14+
baseType.getATemplateArgument() = t.getATemplateArgument() and
15+
// Return the template itself
16+
result = baseType.getTemplate()
17+
)
18+
}
819

920
/**
10-
* There is a `MemberFunction` in parent class with same name
11-
* as a `FunctionCall` that exists in a child `MemberFunction`
21+
* Helper predicate that ensures we do not join on function pairs by name early on, as that creates
22+
* a large dataset on big databases with lots of name duplication.
1223
*/
13-
FunctionCall parentMemberFunctionCall(Class child, Class parent) {
14-
exists(MemberFunction parentFunction, Function other |
15-
not other = parentFunction and
16-
parent.getAMember() = parentFunction and
17-
other.getName() = parentFunction.getName() and
18-
result = other.getACallToThisFunction() and
19-
result.getEnclosingFunction() = child.getAMemberFunction()
24+
pragma[nomagic]
25+
private FunctionCall helper_functioncall(
26+
TemplateClass t, TemplateClass dependentBaseType, Function target, string name
27+
) {
28+
dependentBaseType = getADependentBaseType(t) and
29+
// The target of the call is not declared in the dependent base type
30+
not target.getDeclaringType() = dependentBaseType and
31+
result = target.getACallToThisFunction() and
32+
result.getEnclosingFunction() = t.getAMemberFunction() and
33+
name = target.getName()
34+
}
35+
36+
/**
37+
* Gets a function call in `TemplateClass` `t` where the target function name exists in a dependent
38+
* base type and the call is to a function that is not declared in the dependent base type.
39+
*/
40+
FunctionCall getConfusingFunctionCall(
41+
TemplateClass t, string name, Function target, MemberFunction dependentTypeFunction
42+
) {
43+
exists(TemplateClass dependentBaseType |
44+
result = helper_functioncall(t, dependentBaseType, target, name) and
45+
// The dependentTypeFunction is declared on the dependent base type
46+
dependentBaseType.getAMember() = dependentTypeFunction and
47+
// And has the same name as the target of the function call in the child
48+
name = dependentTypeFunction.getName()
2049
)
2150
}
2251

2352
/**
24-
* There is a `MemberFunction` in parent class with same name
25-
* as a `FunctionAccess` that exists in a child `MemberFunction`
53+
* Helper predicate that ensures we do not join on function pairs by name early on, as that creates
54+
* a large dataset on big databases with lots of name duplication.
55+
*/
56+
pragma[nomagic]
57+
private FunctionAccess helper_functionaccess(
58+
TemplateClass t, TemplateClass dependentBaseType, Function target, string name
59+
) {
60+
dependentBaseType = getADependentBaseType(t) and
61+
// The target of the access is not declared in the dependent base type
62+
not target.getDeclaringType() = dependentBaseType and
63+
result = target.getAnAccess() and
64+
result.getEnclosingFunction() = t.getAMemberFunction() and
65+
name = target.getName()
66+
}
67+
68+
/**
69+
* Gets a function access in `TemplateClass` `t` where the target function name exists in a dependent
70+
* base type and the access is to a function declared outside the dependent base type.
2671
*/
27-
FunctionAccess parentMemberFunctionAccess(Class child, Class parent) {
28-
exists(MemberFunction parentFunction, Function other |
29-
not other = parentFunction and
30-
parent.getAMember() = parentFunction and
31-
other.getName() = parentFunction.getName() and
32-
result = other.getAnAccess() and
33-
result.getEnclosingFunction() = child.getAMemberFunction()
72+
FunctionAccess getConfusingFunctionAccess(
73+
TemplateClass t, string name, Function target, MemberFunction dependentTypeFunction
74+
) {
75+
exists(TemplateClass dependentBaseType |
76+
result = helper_functionaccess(t, dependentBaseType, target, name) and
77+
dependentBaseType.getAMember() = dependentTypeFunction and
78+
name = dependentTypeFunction.getName()
3479
)
3580
}
3681

3782
/**
38-
* There is a `MemberVariable` in parent class with same name
39-
* as a `VariableAccess` that exists in a child `MemberFunction`
83+
* Helper predicate that ensures we do not join on variable pairs by name early on, as that creates
84+
* a large dataset on big databases with lots of name duplication.
85+
*/
86+
pragma[nomagic]
87+
private VariableAccess helper_memberaccess(
88+
TemplateClass t, TemplateClass dependentBaseType, Variable target, string name
89+
) {
90+
dependentBaseType = getADependentBaseType(t) and
91+
// The target of the access is not declared in the dependent base type
92+
not target.getDeclaringType() = dependentBaseType and
93+
result = target.getAnAccess() and
94+
result.getEnclosingFunction() = t.getAMemberFunction() and
95+
name = target.getName() and
96+
// The target is not a local variable, which isn't subject to confusion
97+
not target instanceof LocalScopeVariable
98+
}
99+
100+
/**
101+
* Gets a memmber access in `TemplateClass` `t` where the target member name exists in a dependent
102+
* base type and the access is to a variable declared outside the dependent base type.
40103
*/
41-
Access parentMemberAccess(Class child, Class parent) {
42-
exists(MemberVariable parentMember, Variable other |
43-
not other = parentMember and
44-
parent.getAMemberVariable() = parentMember and
45-
other.getName() = parentMember.getName() and
46-
result = other.getAnAccess() and
47-
result.getEnclosingFunction() = child.getAMemberFunction()
104+
VariableAccess getConfusingMemberVariableAccess(
105+
TemplateClass t, string name, Variable target, MemberVariable dependentTypeMemberVariable
106+
) {
107+
exists(TemplateClass dependentBaseType |
108+
result = helper_memberaccess(t, dependentBaseType, target, name) and
109+
dependentBaseType.getAMemberVariable() = dependentTypeMemberVariable and
110+
name = dependentTypeMemberVariable.getName()
48111
)
49112
}
50113

cpp/autosar/src/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThis.ql

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,25 @@ import cpp
1818
import codingstandards.cpp.autosar
1919
import NameInDependentBase
2020

21-
from Class c, Class p, NameQualifiableElement fn
21+
from
22+
TemplateClass c, NameQualifiableElement fn, string targetName, Element actualTarget,
23+
Element dependentTypeMemberWithSameName
2224
where
2325
not isExcluded(fn, TemplatesPackage::nameNotReferredUsingAQualifiedIdOrThisQuery()) and
2426
not isCustomExcluded(fn) and
25-
p = getParent(c) and
2627
missingNameQualifier(fn) and
2728
(
28-
fn instanceof FunctionAccess and
29-
fn = parentMemberFunctionAccess(c, p)
29+
fn = getConfusingFunctionAccess(c, targetName, actualTarget, dependentTypeMemberWithSameName)
3030
or
31-
fn instanceof FunctionCall and
32-
fn = parentMemberFunctionCall(c, p) and
31+
fn = getConfusingFunctionCall(c, targetName, actualTarget, dependentTypeMemberWithSameName) and
3332
not exists(Expr e | e = fn.(FunctionCall).getQualifier())
3433
or
35-
fn instanceof VariableAccess and
36-
not fn.(VariableAccess).getTarget() instanceof Parameter and
37-
fn = parentMemberAccess(c, p) and
34+
fn =
35+
getConfusingMemberVariableAccess(c, targetName, actualTarget, dependentTypeMemberWithSameName) and
3836
not exists(Expr e | e = fn.(VariableAccess).getQualifier())
3937
) and
4038
not fn.isAffectedByMacro()
41-
select fn, "Use of identifier that also exists in a base class that is not fully qualified."
39+
select fn,
40+
"Use of unqualified identifier " + targetName +
41+
" targets $@ but a member with the name also exists $@.", actualTarget, targetName,
42+
dependentTypeMemberWithSameName, "in the dependent base class"

cpp/autosar/src/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThisAudit.ql

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,25 @@ import cpp
1818
import codingstandards.cpp.autosar
1919
import NameInDependentBase
2020

21-
from Class c, Class p, NameQualifiableElement fn
21+
from
22+
TemplateClass c, NameQualifiableElement fn, string targetName, Element actualTarget,
23+
Element dependentTypeMemberWithSameName
2224
where
2325
not isExcluded(fn, TemplatesPackage::nameNotReferredUsingAQualifiedIdOrThisAuditQuery()) and
2426
not isCustomExcluded(fn) and
25-
p = getParent(c) and
2627
missingNameQualifier(fn) and
2728
(
28-
fn instanceof FunctionAccess and
29-
fn = parentMemberFunctionAccess(c, p)
29+
fn = getConfusingFunctionAccess(c, targetName, actualTarget, dependentTypeMemberWithSameName)
3030
or
31-
fn instanceof FunctionCall and
32-
fn = parentMemberFunctionCall(c, p) and
31+
fn = getConfusingFunctionCall(c, targetName, actualTarget, dependentTypeMemberWithSameName) and
3332
not exists(Expr e | e = fn.(FunctionCall).getQualifier())
3433
or
35-
fn instanceof VariableAccess and
3634
not fn.(VariableAccess).getTarget() instanceof Parameter and
37-
fn = parentMemberAccess(c, p) and
35+
fn =
36+
getConfusingMemberVariableAccess(c, targetName, actualTarget, dependentTypeMemberWithSameName) and
3837
not exists(Expr e | e = fn.(VariableAccess).getQualifier())
3938
)
40-
select fn, "Use of identifier that also exists in a base class that is not fully qualified."
39+
select fn,
40+
"Use of unqualified identifier " + targetName +
41+
" targets $@ but a member with the name also exists $@.", actualTarget, targetName,
42+
dependentTypeMemberWithSameName, "in the dependent base class"
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| test.cpp:16:5:16:5 | m | Use of identifier that also exists in a base class that is not fully qualified. |
2-
| test.cpp:17:5:17:5 | call to g | Use of identifier that also exists in a base class that is not fully qualified. |
3-
| test.cpp:19:20:19:20 | g | Use of identifier that also exists in a base class that is not fully qualified. |
1+
| test.cpp:16:5:16:5 | m | Use of unqualified identifier m targets $@ but a member with the name also exists $@. | test.cpp:4:5:4:5 | m | m | test.cpp:10:7:10:7 | m | in the dependent base class |
2+
| test.cpp:17:5:17:5 | call to g | Use of unqualified identifier g targets $@ but a member with the name also exists $@. | test.cpp:2:6:2:6 | g | g | test.cpp:9:8:9:8 | g | in the dependent base class |
3+
| test.cpp:19:20:19:20 | g | Use of unqualified identifier g targets $@ but a member with the name also exists $@. | test.cpp:2:6:2:6 | g | g | test.cpp:9:8:9:8 | g | in the dependent base class |
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| test.cpp:16:5:16:5 | m | Use of identifier that also exists in a base class that is not fully qualified. |
2-
| test.cpp:17:5:17:5 | call to g | Use of identifier that also exists in a base class that is not fully qualified. |
3-
| test.cpp:19:20:19:20 | g | Use of identifier that also exists in a base class that is not fully qualified. |
1+
| test.cpp:16:5:16:5 | m | Use of unqualified identifier m targets $@ but a member with the name also exists $@. | test.cpp:4:5:4:5 | m | m | test.cpp:10:7:10:7 | m | in the dependent base class |
2+
| test.cpp:17:5:17:5 | call to g | Use of unqualified identifier g targets $@ but a member with the name also exists $@. | test.cpp:2:6:2:6 | g | g | test.cpp:9:8:9:8 | g | in the dependent base class |
3+
| test.cpp:19:20:19:20 | g | Use of unqualified identifier g targets $@ but a member with the name also exists $@. | test.cpp:2:6:2:6 | g | g | test.cpp:9:8:9:8 | g | in the dependent base class |

0 commit comments

Comments
 (0)