Skip to content

Commit 4de3634

Browse files
authored
Merge pull request #63 from lcartey/lcartey/dead-code-static-asserts
`M0-1-9`: Exclude more compiler generated statements
2 parents be6d8a7 + b477747 commit 4de3634

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `M0-1-9` - `DeadCode.ql`:
2+
- More compiler generated statements are now excluded from being reported as dead code, including compiler generated statements for `static_assert` calls.

cpp/autosar/src/rules/M0-1-9/DeadCode.ql

+6-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ predicate isDeadStmt(Stmt s) {
5151
// - The initializers for each of the variables are pure
5252
exists(DeclStmt ds |
5353
ds = s and
54-
forall(Declaration d | d = ds.getADeclaration() |
54+
// Use forex so that we don't flag "fake" generated `DeclStmt`s (e.g. those generated by the
55+
// extractor for static_asserts) with no actual declarations
56+
forex(Declaration d | d = ds.getADeclaration() |
5557
exists(LocalScopeVariable v |
5658
d = v and
5759
v.getInitializer().getExpr().isPure() and
@@ -123,5 +125,7 @@ where
123125
// output". We therefore exclude unreachable statements as they are, by definition, not executed.
124126
not s.getBasicBlock() = any(UnreachableBasicBlock ubb).getABasicBlock() and
125127
// Exclude code generated by macros, because the code may be "live" in other instantiations
126-
not s.isAffectedByMacro()
128+
not s.isAffectedByMacro() and
129+
// Exclude compiler generated statements
130+
not s.isCompilerGenerated()
127131
select s, "This statement is dead code."

cpp/autosar/test/rules/M0-1-9/test.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,7 @@ int test_dead_code(int x) {
7676
} catch (...) { // NON_COMPLIANT
7777
}
7878

79+
static_assert(1); // COMPLIANT
80+
7981
return live5 + live6; // COMPLIANT
8082
}

0 commit comments

Comments
 (0)