Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdd86a4e

Browse files
authored
Merge branch 'main' into michaelrfairhurst/fix-resource-leak-analysis-qll-performance-issue
2 parents5a5f8b7 +7317d11 commitdd86a4e

File tree

7 files changed

+58
-22
lines changed

7 files changed

+58
-22
lines changed

‎c/cert/src/rules/PRE31-C/SideEffectsInArgumentsToUnsafeMacros.ql‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import cpp
1515
import codingstandards.c.cert
1616
import codingstandards.cpp.Macro
1717
import codingstandards.cpp.SideEffect
18-
import codingstandards.cpp.StructuralEquivalence
1918
import codingstandards.cpp.sideeffect.DefaultEffects
2019
import codingstandards.cpp.sideeffect.Customizations
2120
import semmle.code.cpp.valuenumbering.HashCons
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-`A5-1-9` -`IdenticalLambdaExpressions.ql`:
2+
- Performance has been improved.
3+
- False positives due to repeated invocation of macros containing lambdas have been excluded.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-`A27-0-3`,`FIO309-C`,`FIO50-CPP`,`RULE-30-0-2` -`InterleavedInputOutputWithoutFlush.ql`,`DoNotAlternatelyIOFromStreamWithoutPositioning.ql`,`InterleavedInputOutputWithoutPosition.ql`,`ReadsAndWritesOnStreamNotSeparatedByPositioning.ql`:
2+
- Reduce evaluation time on complex codebases.

‎cpp/autosar/src/rules/A5-1-9/IdenticalLambdaExpressions.ql‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ where
2424
notlambdaExpression=otherLambdaExpressionand
2525
notlambdaExpression.isFromTemplateInstantiation(_)and
2626
nototherLambdaExpression.isFromTemplateInstantiation(_)and
27-
getLambdaHashCons(lambdaExpression)=getLambdaHashCons(otherLambdaExpression)
27+
getLambdaHashCons(lambdaExpression)=getLambdaHashCons(otherLambdaExpression)and
28+
// Do not report lambdas produced by the same macro in different invocations
29+
notexists(Macrom,MacroInvocationm1,MacroInvocationm2|
30+
m1=m.getAnInvocation()and
31+
m2=m.getAnInvocation()and
32+
notm1=m2and// Lambdas in the same macro can be reported
33+
m1.getAnExpandedElement()=lambdaExpressionand
34+
m2.getAnExpandedElement()=otherLambdaExpression
35+
)
2836
selectlambdaExpression,"Lambda expression is identical to $@ lambda expression.",
2937
otherLambdaExpression,"this"

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

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private module HashCons {
211211

212212
privatenewtypeHC_Params=
213213
HC_NoParams()or
214-
HC_ParamCons(HashConsExprhc,inti,HC_Paramslist){mk_ParamCons(hc,i,list, _)}
214+
HC_ParamCons(Typet,stringname,inti,HC_Paramslist){mk_ParamCons(t,name,i,list, _)}
215215

216216
/**
217217
* HashConsExpr is the hash-cons of an expression. The relationship between `Expr`
@@ -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+
privatestringgetVariableName(Variablev){result=v.getName()}
634+
627635
/* Note: This changed from the original HashCons module to be able to find structural equivalent expression. */
628636
privatepredicatemk_Variable(Typet,stringname,VariableAccessaccess){
629637
analyzableVariable(access)and
630638
exists(Variablev|
631-
v=access.getTarget()andt=v.getUnspecifiedType()andname=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-
privatepredicatemk_StmtCons(HashConsStmthc,inti,HC_Stmtslist,BlockStmtblock){
1117+
privateclassLambdaBlockStmtextendsBlockStmt{
1118+
LambdaBlockStmt(){
1119+
// Restricting to statements inside a lambda expressions.
1120+
this.getParentScope*()=any(LambdaExpressionle).getLambdaFunction()
1121+
}
1122+
}
1123+
1124+
privatepredicatemk_StmtCons(HashConsStmthc,inti,HC_Stmtslist,LambdaBlockStmtblock){
11081125
hc=hashConsStmt(block.getStmt(i))and
11091126
(
11101127
exists(HashConsStmthead,HC_Stmtstail|
@@ -1118,13 +1135,13 @@ private module HashCons {
11181135
}
11191136

11201137
privatepredicatemk_StmtConsInner(
1121-
HashConsStmthead,HC_Stmtstail,inti,HC_Stmtslist,BlockStmtblock
1138+
HashConsStmthead,HC_Stmtstail,inti,HC_Stmtslist,LambdaBlockStmtblock
11221139
){
11231140
list=HC_StmtCons(head,i,tail)and
11241141
mk_StmtCons(head,i,tail,block)
11251142
}
11261143

1127-
privatepredicatemk_BlockStmtCons(HC_Stmtshc,BlockStmts){
1144+
privatepredicatemk_BlockStmtCons(HC_Stmtshc,LambdaBlockStmts){
11281145
ifs.getNumStmt()>0
11291146
then
11301147
exists(HashConsStmthead,HC_Stmtstail|
@@ -1275,24 +1292,25 @@ private module HashCons {
12751292
mk_DeclConsInner(_, _,s.getNumDeclarations()-1,hc,s)
12761293
}
12771294

1278-
privatepredicatemk_ParamCons(HashConsExprhc,inti,HC_Paramslist,Functionf){
1279-
hc=hashConsExpr(f.getParameter(i).getAnAccess())and
1280-
(
1281-
exists(HashConsExprhead,HC_Paramstail|
1282-
mk_ParamConsInner(head,tail,i-1,list,f)and
1283-
i>0
1284-
)
1295+
privatepredicatemk_ParamCons(Typet,stringname,inti,HC_Paramslist,Functionf){
1296+
exists(Parameterp|
1297+
p=f.getParameter(i)and
1298+
t=p.getType()and
1299+
name=p.getName()
1300+
|
1301+
mk_ParamConsInner(_, _, _,i-1,list,f)and
1302+
i>0
12851303
or
12861304
i=0and
12871305
list=HC_NoParams()
12881306
)
12891307
}
12901308

12911309
privatepredicatemk_ParamConsInner(
1292-
HashConsExprhead,HC_Paramstail,inti,HC_Paramslist,Functionf
1310+
Typet,stringname,HC_Paramstail,inti,HC_Paramslist,Functionf
12931311
){
1294-
list=HC_ParamCons(head,i,tail)and
1295-
mk_ParamCons(head,i,tail,f)
1312+
list=HC_ParamCons(t,name,i,tail)and
1313+
mk_ParamCons(t,name,i,tail,f)
12961314
}
12971315

12981316
privatepredicatemk_FunctionCons(
@@ -1302,7 +1320,7 @@ private module HashCons {
13021320
name=f.getName()and
13031321
body=hashConsStmt(f.getBlock())and
13041322
iff.getNumberOfParameters()>0
1305-
thenmk_ParamConsInner(_, _,f.getNumberOfParameters()-1,params,f)
1323+
thenmk_ParamConsInner(_, _,_,f.getNumberOfParameters()-1,params,f)
13061324
elseparams=HC_NoParams()
13071325
}
13081326

@@ -1486,8 +1504,6 @@ private module HashCons {
14861504

14871505
cached
14881506
HashConsStmthashConsStmt(Stmts){
1489-
// Restricting to statements inside a lambda expressions.
1490-
s.getParentScope*()=any(LambdaExpressionle).getLambdaFunction()and
14911507
exists(HC_Stmtslist|
14921508
mk_BlockStmtCons(list,s)and
14931509
result=HC_BlockStmt(list)

‎cpp/autosar/test/rules/A5-1-9/test.cpp‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,10 @@ class Test_issue468 {
104104
LogError("Error");
105105
LogFatal("Fatal");
106106
}
107-
};
107+
};
108+
109+
#defineMACRO() [](int i) ->int {return i +3; }
110+
voidtest_macros() {
111+
MACRO();// COMPLIANT
112+
MACRO();// COMPLIANT - no duplication
113+
}

‎cpp/common/src/codingstandards/cpp/rules/iofstreammissingpositioning/IOFstreamMissingPositioning.qll‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,19 @@ predicate sameSource(FunctionCall a, FunctionCall b) {
5757
sameFileSource(a,b)
5858
}
5959

60+
bindingset[a, b]
6061
predicatesameAccessDirection(ReadWriteCalla,ReadWriteCallb){
6162
a.getAccessDirection()=b.getAccessDirection()
6263
}
6364

65+
bindingset[a, b]
6466
predicateoppositeAccessDirection(ReadWriteCalla,ReadWriteCallb){
6567
notsameAccessDirection(a,b)
6668
}
6769

6870
/**
6971
* A write operation reaching a read and vice versa
70-
* without interveningfilepositioning
72+
* without interveningfile positioning calls.
7173
*/
7274
ControlFlowNodereachesInExOperator(ReadWriteCallop){
7375
result=op

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp