Skip to content

Commit c24c9a9

Browse files
committed
DeadCode: Exclude more generated statements
M0-1-9 now excludes more generated statements, including those marked as compiler generated, and DeclStmts generated from static_asserts.
1 parent 632e9df commit c24c9a9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
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."

0 commit comments

Comments
 (0)