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

Commit42c2b88

Browse files
authored
Merge pull request#781 from github/lcartey/2-37-0-performance-improvements
Performance improvements since upgrade to 2.16.6
2 parents18a3f35 +10b84ec commit42c2b88

File tree

6 files changed

+63
-40
lines changed

6 files changed

+63
-40
lines changed

‎c/cert/src/rules/DCL40-C/IncompatibleFunctionDeclarations.ql

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,32 @@
1616

1717
import cpp
1818
import codingstandards.c.cert
19+
import codingstandards.cpp.Compatible
1920
import ExternalIdentifiers
2021

21-
//checks if they are incompatible based on return type, number of parameters and parameter types
22-
predicatecheckMatchingFunction(FunctionDeclarationEntryd,FunctionDeclarationEntryd2){
23-
notd.getType()=d2.getType()
24-
or
25-
notd.getNumberOfParameters()=d2.getNumberOfParameters()
26-
or
27-
exists(ParameterDeclarationEntryp,ParameterDeclarationEntryp2,inti|
28-
d.getParameterDeclarationEntry(i)=pand
29-
d2.getParameterDeclarationEntry(i)=p2and
30-
notp.getType()=p2.getType()
31-
)
32-
}
33-
3422
fromExternalIdentifiersd,FunctionDeclarationEntryf1,FunctionDeclarationEntryf2
3523
where
3624
notisExcluded(f1, Declarations2Package::incompatibleFunctionDeclarationsQuery())and
3725
notisExcluded(f2, Declarations2Package::incompatibleFunctionDeclarationsQuery())and
38-
f1=d.getADeclarationEntry()and
39-
f2=d.getADeclarationEntry()and
4026
notf1=f2and
41-
f1.getLocation().getStartLine()>=f2.getLocation().getStartLine()and
27+
f1.getDeclaration()=dand
28+
f2.getDeclaration()=dand
4229
f1.getName()=f2.getName()and
43-
checkMatchingFunction(f1,f2)
30+
(
31+
//return type check
32+
nottypesCompatible(f1.getType(),f2.getType())
33+
or
34+
//parameter type check
35+
parameterTypesIncompatible(f1,f2)
36+
or
37+
notf1.getNumberOfParameters()=f2.getNumberOfParameters()
38+
)and
39+
// Apply ordering on start line, trying to avoid the optimiser applying this join too early
40+
// in the pipeline
41+
exists(intf1Line,intf2Line|
42+
f1.getLocation().hasLocationInfo(_,f1Line, _, _, _)and
43+
f2.getLocation().hasLocationInfo(_,f2Line, _, _, _)and
44+
f1Line>=f2Line
45+
)
4446
selectf1,"The object $@ is not compatible with re-declaration $@",f1,f1.getName(),f2,
4547
f2.getName()

‎c/cert/src/rules/MSC39-C/DoNotCallVaArgOnAVaListThatHasAnIndeterminateValue.ql

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,19 @@ predicate sameSource(VaAccess e1, VaAccess e2) {
7171
)
7272
}
7373

74+
/**
75+
* Extracted to avoid poor magic join ordering on the `isExcluded` predicate.
76+
*/
77+
predicatequery(VaAccessva_acc,VaArgArgva_arg,FunctionCallfc){
78+
sameSource(va_acc,va_arg)and
79+
fc=preceedsFC(va_acc)and
80+
fc.getTarget().calls*(va_arg.getEnclosingFunction())
81+
}
82+
7483
fromVaAccessva_acc,VaArgArgva_arg,FunctionCallfc
7584
where
7685
notisExcluded(va_acc,
7786
Contracts7Package::doNotCallVaArgOnAVaListThatHasAnIndeterminateValueQuery())and
78-
sameSource(va_acc,va_arg)and
79-
fc=preceedsFC(va_acc)and
80-
fc.getTarget().calls*(va_arg.getEnclosingFunction())
87+
query(va_acc,va_arg,fc)
8188
selectva_acc,"The value of "+va_acc.toString()+" is indeterminate after the $@.",fc,
8289
fc.toString()

‎c/misra/src/rules/RULE-9-4/RepeatedInitializationOfAggregateObjectElement.ql

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,33 +62,31 @@ int getMaxDepth(ArrayAggregateLiteral al) {
6262

6363
// internal recursive predicate for `hasMultipleInitializerExprsForSameIndex`
6464
predicatehasMultipleInitializerExprsForSameIndexInternal(
65-
ArrayAggregateLiteralal1,ArrayAggregateLiteralal2,Exprout_al1_expr,Exprout_al2_expr
65+
ArrayAggregateLiteralroot,Expre1,Expre2
6666
){
67-
exists(intshared_index,Expral1_expr,Expral2_expr|
68-
// an `Expr` initializing an element of the same index in both `al1` and `al2`
69-
shared_index=[0 ..al1.getArraySize()-1]and
70-
al1_expr=al1.getAnElementExpr(shared_index)and
71-
al2_expr=al2.getAnElementExpr(shared_index)and
72-
// but not the same `Expr`
73-
notal1_expr=al2_exprand
74-
(
75-
// case A - the children are not aggregate literals
76-
// holds if `al1` and `al2` both hold for .getElement[sharedIndex]
77-
notal1_exprinstanceofArrayAggregateLiteraland
78-
out_al1_expr=al1_exprand
79-
out_al2_expr=al2_expr
80-
or
81-
// case B - `al1` and `al2` both have an aggregate literal child at the same index, so recurse
82-
hasMultipleInitializerExprsForSameIndexInternal(al1_expr,al2_expr,out_al1_expr,out_al2_expr)
83-
)
67+
root=e1androot=e2
68+
or
69+
exists(ArrayAggregateLiteralparent1,ArrayAggregateLiteralparent2,intshared_index|
70+
hasMultipleInitializerExprsForSameIndexInternal(root,parent1,parent2)and
71+
shared_index=[0 ..parent1.getArraySize()-1]and
72+
e1=parent1.getAnElementExpr(shared_index)and
73+
e2=parent2.getAnElementExpr(shared_index)
8474
)
8575
}
8676

8777
/**
8878
* Holds if `expr1` and `expr2` both initialize the same array element of `root`.
8979
*/
9080
predicatehasMultipleInitializerExprsForSameIndex(ArrayAggregateLiteralroot,Exprexpr1,Exprexpr2){
91-
hasMultipleInitializerExprsForSameIndexInternal(root,root,expr1,expr2)
81+
hasMultipleInitializerExprsForSameIndexInternal(root,expr1,expr2)and
82+
notroot=expr1and
83+
notroot=expr2and
84+
notexpr1=expr2and
85+
(
86+
notexpr1instanceofArrayAggregateLiteral
87+
or
88+
notexpr2instanceofArrayAggregateLiteral
89+
)
9290
}
9391

9492
/**
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-`DCL40-C` -`IncompatibleFunctionDeclarations.ql`:
2+
- Reduce false positives by identifying compatible integer arithmetic types (e.g. "signed int" and "int").

‎cpp/common/src/codingstandards/cpp/Compatible.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import cpp
22

3+
pragma[noinline]
4+
pragma[nomagic]
35
predicatetypesCompatible(Typet1,Typet2){
46
t1=t2
57
or
@@ -8,6 +10,7 @@ predicate typesCompatible(Type t1, Type t2) {
810
}
911

1012
predicateparameterTypesIncompatible(FunctionDeclarationEntryf1,FunctionDeclarationEntryf2){
13+
f1.getDeclaration()=f2.getDeclaration()and
1114
exists(ParameterDeclarationEntryp1,ParameterDeclarationEntryp2,inti|
1215
p1=f1.getParameterDeclarationEntry(i)and
1316
p2=f2.getParameterDeclarationEntry(i)
@@ -17,6 +20,7 @@ predicate parameterTypesIncompatible(FunctionDeclarationEntry f1, FunctionDeclar
1720
}
1821

1922
predicateparameterNamesIncompatible(FunctionDeclarationEntryf1,FunctionDeclarationEntryf2){
23+
f1.getDeclaration()=f2.getDeclaration()and
2024
exists(ParameterDeclarationEntryp1,ParameterDeclarationEntryp2,inti|
2125
p1=f1.getParameterDeclarationEntry(i)and
2226
p2=f2.getParameterDeclarationEntry(i)

‎cpp/common/src/codingstandards/cpp/rules/notdistinctidentifier/NotDistinctIdentifier.qll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ abstract class NotDistinctIdentifierSharedQuery extends Query { }
1212

1313
QuerygetQuery(){resultinstanceofNotDistinctIdentifierSharedQuery}
1414

15+
bindingset[d, d2]
16+
pragma[inline_late]
17+
privatepredicateafter(ExternalIdentifiersd,ExternalIdentifiersd2){
18+
exists(intdStartLine,intd2StartLine|
19+
d.getLocation().hasLocationInfo(_,dStartLine, _, _, _)and
20+
d2.getLocation().hasLocationInfo(_,d2StartLine, _, _, _)and
21+
dStartLine>=d2StartLine
22+
)
23+
}
24+
1525
querypredicateproblems(
1626
ExternalIdentifiersd,stringmessage,ExternalIdentifiersd2,stringnameplaceholder
1727
){
@@ -20,10 +30,10 @@ query predicate problems(
2030
d.getName().length()>=31and
2131
d2.getName().length()>=31and
2232
notd=d2and
23-
d.getLocation().getStartLine()>=d2.getLocation().getStartLine()and
2433
d.getSignificantName()=d2.getSignificantName()and
2534
notd.getName()=d2.getName()and
2635
nameplaceholder=d2.getName()and
36+
after(d,d2)and
2737
message=
2838
"External identifer "+d.getName()+
2939
" is nondistinct in characters at or over 31 limit, compared to $@"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp