Skip to content

Commit a568b88

Browse files
committed
A5-1-9: Filter blocks to lambdas in hash cons calc
Move the exclusion of non-lambda blocks to the calculation of HC_BlockStmt, to avoid generating newtype instances for non-lambda instances.
1 parent 92f5d5b commit a568b88

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

cpp/autosar/src/rules/A5-1-9/LambdaEquivalence.qll

+21-6
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,21 @@ private module HashCons {
624624
strictcount(access.getTarget()) = 1
625625
}
626626

627+
/**
628+
* Gets the name of a variable.
629+
*
630+
* Extracted for performance reasons, to avoid magic, which was causing performance issues in getParameter(int i).
631+
*/
632+
pragma[nomagic]
633+
private string getVariableName(Variable v) { result = v.getName() }
634+
627635
/* Note: This changed from the original HashCons module to be able to find structural equivalent expression. */
628636
private predicate mk_Variable(Type t, string name, VariableAccess access) {
629637
analyzableVariable(access) and
630638
exists(Variable v |
631-
v = access.getTarget() and t = v.getUnspecifiedType() and name = v.getName()
639+
v = access.getTarget() and
640+
t = v.getUnspecifiedType() and
641+
name = getVariableName(v)
632642
)
633643
}
634644

@@ -1104,7 +1114,14 @@ private module HashCons {
11041114
nee.getExpr().getFullyConverted() = child.getAnExpr()
11051115
}
11061116

1107-
private predicate mk_StmtCons(HashConsStmt hc, int i, HC_Stmts list, BlockStmt block) {
1117+
private class LambdaBlockStmt extends BlockStmt {
1118+
LambdaBlockStmt() {
1119+
// Restricting to statements inside a lambda expressions.
1120+
this.getParentScope*() = any(LambdaExpression le).getLambdaFunction()
1121+
}
1122+
}
1123+
1124+
private predicate mk_StmtCons(HashConsStmt hc, int i, HC_Stmts list, LambdaBlockStmt block) {
11081125
hc = hashConsStmt(block.getStmt(i)) and
11091126
(
11101127
exists(HashConsStmt head, HC_Stmts tail |
@@ -1118,13 +1135,13 @@ private module HashCons {
11181135
}
11191136

11201137
private predicate mk_StmtConsInner(
1121-
HashConsStmt head, HC_Stmts tail, int i, HC_Stmts list, BlockStmt block
1138+
HashConsStmt head, HC_Stmts tail, int i, HC_Stmts list, LambdaBlockStmt block
11221139
) {
11231140
list = HC_StmtCons(head, i, tail) and
11241141
mk_StmtCons(head, i, tail, block)
11251142
}
11261143

1127-
private predicate mk_BlockStmtCons(HC_Stmts hc, BlockStmt s) {
1144+
private predicate mk_BlockStmtCons(HC_Stmts hc, LambdaBlockStmt s) {
11281145
if s.getNumStmt() > 0
11291146
then
11301147
exists(HashConsStmt head, HC_Stmts tail |
@@ -1487,8 +1504,6 @@ private module HashCons {
14871504

14881505
cached
14891506
HashConsStmt hashConsStmt(Stmt s) {
1490-
// Restricting to statements inside a lambda expressions.
1491-
s.getParentScope*() = any(LambdaExpression le).getLambdaFunction() and
14921507
exists(HC_Stmts list |
14931508
mk_BlockStmtCons(list, s) and
14941509
result = HC_BlockStmt(list)

0 commit comments

Comments
 (0)