Skip to content

Commit ea338e6

Browse files
committed
Fix M0-1-4 to ignore compiler-generated accesses
1 parent 65f4e25 commit ea338e6

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- `M0-1-4` - `SingleUsePODVariable.ql`
2+
- This rule no longer considers compiler-generated access to a variable when determining if the
3+
variable has a single use.

cpp/autosar/src/rules/M0-1-4/SingleUsePODVariable.qll

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ int getUseCount(Variable v) {
1010
// We enforce that it's a POD type variable, so if it has an initializer it is explicit
1111
(if v.hasInitializer() then initializers = 1 else initializers = 0) and
1212
result =
13-
initializers + count(v.getAnAccess()) +
14-
count(UserProvidedConstructorFieldInit cfi | cfi.getTarget() = v)
13+
initializers +
14+
count(VariableAccess access | access = v.getAnAccess() and not access.isCompilerGenerated())
15+
+ count(UserProvidedConstructorFieldInit cfi | cfi.getTarget() = v)
1516
)
1617
}
1718

@@ -23,7 +24,9 @@ Element getSingleUse(Variable v) {
2324
or
2425
result = any(UserProvidedConstructorFieldInit cfi | cfi.getTarget() = v)
2526
or
26-
result = v.getAnAccess()
27+
exists(VariableAccess access |
28+
access = v.getAnAccess() and not access.isCompilerGenerated() and result = access
29+
)
2730
)
2831
}
2932

0 commit comments

Comments
 (0)