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

Commita74c8a9

Browse files
authored
Merge branch 'main' into lcartey/lambda-equivalence-performance
2 parents1bd7dab +4ac7c5c commita74c8a9

File tree

105 files changed

+3612
-830
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+3612
-830
lines changed

‎amendments.csv‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
language,standard,amendment,rule_id,supportable,implementation_category,implemented,difficulty
2-
c,MISRA-C-2012,Amendment3,DIR-4-6,Yes,Expand,No,Easy
2+
c,MISRA-C-2012,Amendment3,DIR-4-6,Yes,Expand,Yes,Easy
33
c,MISRA-C-2012,Amendment3,DIR-4-9,Yes,Refine,No,Easy
44
c,MISRA-C-2012,Amendment3,DIR-4-11,Yes,Refine,No,Import
55
c,MISRA-C-2012,Amendment3,RULE-1-4,Yes,Replace,No,Easy
6-
c,MISRA-C-2012,Amendment3,RULE-10-1,Yes,Replace,No,Easy
7-
c,MISRA-C-2012,Amendment3,RULE-10-3,Yes,Refine,No,Easy
8-
c,MISRA-C-2012,Amendment3,RULE-10-4,Yes,Refine,No,Import
9-
c,MISRA-C-2012,Amendment3,RULE-10-5,Yes,Expand,No,Easy
10-
c,MISRA-C-2012,Amendment3,RULE-10-7,Yes,Refine,No,Import
11-
c,MISRA-C-2012,Amendment3,RULE-10-8,Yes,Refine,No,Import
6+
c,MISRA-C-2012,Amendment3,RULE-10-1,Yes,Replace,Yes,Easy
7+
c,MISRA-C-2012,Amendment3,RULE-10-3,Yes,Refine,Yes,Easy
8+
c,MISRA-C-2012,Amendment3,RULE-10-4,Yes,Refine,Yes,Import
9+
c,MISRA-C-2012,Amendment3,RULE-10-5,Yes,Expand,Yes,Easy
10+
c,MISRA-C-2012,Amendment3,RULE-10-7,Yes,Refine,Yes,Import
11+
c,MISRA-C-2012,Amendment3,RULE-10-8,Yes,Refine,Yes,Import
1212
c,MISRA-C-2012,Amendment3,RULE-21-11,Yes,Clarification,Yes,Import
1313
c,MISRA-C-2012,Amendment3,RULE-21-12,Yes,Replace,No,Easy
1414
c,MISRA-C-2012,Amendment4,RULE-11-3,Yes,Expand,No,Easy

‎c/cert/src/rules/CON34-C/AppropriateThreadObjectStorageDurations.ql‎

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,43 @@
1414

1515
import cpp
1616
import codingstandards.c.cert
17+
import codingstandards.c.Objects
1718
import codingstandards.cpp.Concurrency
1819
import semmle.code.cpp.dataflow.DataFlow
1920
import semmle.code.cpp.commons.Alloc
2021

21-
fromC11ThreadCreateCalltcc,StackVariablesv,Exprarg,Expracc
22+
fromC11ThreadCreateCalltcc,Exprarg
2223
where
2324
notisExcluded(tcc, Concurrency4Package::appropriateThreadObjectStorageDurationsQuery())and
2425
tcc.getArgument(2)=argand
25-
sv.getAnAccess()=accand
26-
// a stack variable that is given as an argument to a thread
27-
TaintTracking::localTaint(DataFlow::exprNode(acc), DataFlow::exprNode(arg))and
28-
// or isn't one of the allowed usage patterns
29-
notexists(Exprmfc|
30-
isAllocationExpr(mfc)and
31-
sv.getAnAssignedValue()=mfcand
32-
acc.getAPredecessor*()=mfc
33-
)and
34-
notexists(TSSGetFunctionCalltsg,TSSSetFunctionCalltss, DataFlow::Nodesrc|
35-
sv.getAnAssignedValue()=tsgand
36-
acc.getAPredecessor*()=tsgand
37-
// there should be dataflow from somewhere (the same somewhere)
38-
// into each of the first arguments
39-
DataFlow::localFlow(src, DataFlow::exprNode(tsg.getArgument(0)))and
40-
DataFlow::localFlow(src, DataFlow::exprNode(tss.getArgument(0)))
26+
(
27+
exists(ObjectIdentityobj,Expracc|
28+
obj.getASubobjectAccess()=accand
29+
obj.getStorageDuration().isAutomatic()and
30+
exists(DataFlow::NodeaddrNode|
31+
(
32+
addrNode= DataFlow::exprNode(any(AddressOfExpre|e.getOperand()=acc))
33+
or
34+
addrNode= DataFlow::exprNode(acc)and
35+
exists(ArrayToPointerConversionc|c.getExpr()=acc)
36+
)and
37+
TaintTracking::localTaint(addrNode, DataFlow::exprNode(arg))
38+
)
39+
)
40+
or
41+
// TODO: This case is handling threadlocals in a useful way that's not intended to be covered
42+
// by the rule. See issue #801. The actual rule should expect no tss_t objects is used, and
43+
// this check that this is initialized doesn't seem to belong here. However, it is a useful
44+
// check in and of itself, so we should figure out if this is part of an optional rule we
45+
// haven't yet implemented and move this behavior there.
46+
exists(TSSGetFunctionCalltsg|
47+
TaintTracking::localTaint(DataFlow::exprNode(tsg), DataFlow::exprNode(arg))and
48+
notexists(TSSSetFunctionCalltss, DataFlow::Nodesrc|
49+
// there should be dataflow from somewhere (the same somewhere)
50+
// into each of the first arguments
51+
DataFlow::localFlow(src, DataFlow::exprNode(tsg.getArgument(0)))and
52+
DataFlow::localFlow(src, DataFlow::exprNode(tss.getArgument(0)))
53+
)
54+
)
4155
)
4256
selecttcc,"$@ not declared with appropriate storage duration",arg,"Shared object"

‎c/cert/src/rules/DCL30-C/AppropriateStorageDurationsFunctionReturn.ql‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@
1313

1414
import cpp
1515
import codingstandards.c.cert
16+
import codingstandards.c.Objects
1617
import semmle.code.cpp.dataflow.DataFlow
1718

18-
classSourceextendsStackVariable{
19-
Source(){notthisinstanceofParameter}
19+
classSourceextendsExpr{
20+
ObjectIdentityrootObject;
21+
22+
Source(){
23+
rootObject.getStorageDuration().isAutomatic()and
24+
this=rootObject.getASubobjectAddressExpr()
25+
}
2026
}
2127

2228
classSinkextends DataFlow::Node{
@@ -40,7 +46,7 @@ from DataFlow::Node src, DataFlow::Node sink
4046
where
4147
notisExcluded(sink.asExpr(),
4248
Declarations8Package::appropriateStorageDurationsFunctionReturnQuery())and
43-
exists(Sources|src.asExpr()=s.getAnAccess())and
49+
exists(Sources|src.asExpr()=s)and
4450
sinkinstanceofSinkand
4551
DataFlow::localFlow(src,sink)
4652
selectsink,"$@ with automatic storage may be accessible outside of its lifetime.",src,

‎c/cert/src/rules/EXP35-C/DoNotModifyObjectsWithTemporaryLifetime.ql‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@
1313

1414
import cpp
1515
import codingstandards.c.cert
16-
import codingstandards.cpp.lifetimes.CLifetimes
16+
import codingstandards.c.Objects
1717

1818
// Note: Undefined behavior is possible regardless of whether the accessed field from the returned
1919
// struct is an array or a scalar (i.e. arithmetic and pointer types) member, according to the standard.
20-
fromFieldAccessfa,FunctionCallfc
20+
fromFieldAccessfa,TemporaryObjectIdentitytempObject
2121
where
2222
notisExcluded(fa, InvalidMemory2Package::doNotModifyObjectsWithTemporaryLifetimeQuery())and
23-
notfa.getQualifier().isLValue()and
24-
fa.getQualifier().getUnconverted()=fcand
25-
fa.getQualifier().getUnconverted().getUnspecifiedType()instanceofStructOrUnionTypeWithArrayField
26-
selectfa,"Field access on $@ qualifier occurs after its temporary object lifetime.",fc,
27-
"function call"
23+
fa.getQualifier().getUnconverted()=tempObject
24+
selectfa,"Field access on $@ qualifier occurs after its temporary object lifetime.",tempObject,
25+
"temporary object"

‎c/cert/src/rules/MEM33-C/AllocStructsWithAFlexibleArrayMemberDynamically.ql‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
import cpp
1515
import codingstandards.c.cert
1616
import codingstandards.c.Variable
17+
import codingstandards.c.Objects
1718
import semmle.code.cpp.models.interfaces.Allocation
1819
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
1920

2021
abstractclassFlexibleArrayAllocextendsElement{
2122
/**
2223
* Returns the `Variable` being allocated.
2324
*/
24-
abstractVariablegetVariable();
25+
abstractElementgetReportElement();
2526
}
2627

2728
/**
@@ -53,18 +54,26 @@ class FlexibleArrayStructDynamicAlloc extends FlexibleArrayAlloc, FunctionCall {
5354
)
5455
}
5556

56-
overrideVariablegetVariable(){result=v}
57+
overrideElementgetReportElement(){result=v}
5758
}
5859

5960
/**
6061
* A `Variable` of type `FlexibleArrayStructType` that is not allocated dynamically.
6162
*/
62-
classFlexibleArrayNonDynamicAllocextendsFlexibleArrayAlloc,Variable{
63+
classFlexibleArrayNonDynamicAllocextendsFlexibleArrayAlloc{
64+
ObjectIdentityobject;
65+
6366
FlexibleArrayNonDynamicAlloc(){
64-
this.getUnspecifiedType().getUnspecifiedType()instanceofFlexibleArrayStructType
67+
this=objectand
68+
notobject.getStorageDuration().isAllocated()and
69+
// Exclude temporaries. Though they should violate this rule, in practice these results are
70+
// often spurious and redundant, such as (*x = *x) which creates an unused temporary object.
71+
notobject.hasTemporaryLifetime()and
72+
object.getType().getUnspecifiedType()instanceofFlexibleArrayStructTypeand
73+
notexists(Variablev|v.getInitializer().getExpr()=this)
6574
}
6675

67-
overrideVariablegetVariable(){result=this}
76+
overrideElementgetReportElement(){result=object}
6877
}
6978

7079
fromFlexibleArrayAllocalloc,stringmessage
@@ -77,4 +86,4 @@ where
7786
allocinstanceofFlexibleArrayNonDynamicAllocand
7887
message="$@ contains a flexible array member but is not dynamically allocated."
7988
)
80-
selectalloc,message,alloc.getVariable(),alloc.getVariable().getName()
89+
selectalloc,message,alloc.getReportElement(),alloc.getReportElement().toString()

‎c/cert/test/rules/CON34-C/AppropriateThreadObjectStorageDurations.expected‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:27,29-37)
2-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:27,54-62)
3-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:34,62-70)
4-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:39,5-13)
5-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:39,30-38)
6-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:40,5-13)
7-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:40,30-38)
8-
WARNING: module 'TaintTracking' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:27,3-16)
1+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:30,14-22)
2+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:32,22-30)
3+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:34,22-30)
4+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:37,45-53)
5+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:47,33-41)
6+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:47,58-66)
7+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:48,42-50)
8+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:51,9-17)
9+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:51,34-42)
10+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:52,9-17)
11+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:52,34-42)
12+
WARNING: module 'TaintTracking' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:37,9-22)
13+
WARNING: module 'TaintTracking' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:47,7-20)
914
| test.c:23:3:23:13 | call to thrd_create | $@ not declared with appropriate storage duration | test.c:23:24:23:29 | & ... | Shared object |
1015
| test.c:74:3:74:13 | call to thrd_create | $@ not declared with appropriate storage duration | test.c:74:24:74:24 | p | Shared object |
1116
| test.c:85:3:85:13 | call to thrd_create | $@ not declared with appropriate storage duration | test.c:85:24:85:24 | p | Shared object |
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateStorageDurationsFunctionReturn.ql:22,20-28)
2-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateStorageDurationsFunctionReturn.ql:26,31-39)
3-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateStorageDurationsFunctionReturn.ql:39,6-14)
4-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateStorageDurationsFunctionReturn.ql:39,26-34)
5-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateStorageDurationsFunctionReturn.ql:45,3-11)
1+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateStorageDurationsFunctionReturn.ql:28,20-28)
2+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateStorageDurationsFunctionReturn.ql:32,31-39)
3+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateStorageDurationsFunctionReturn.ql:45,6-14)
4+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateStorageDurationsFunctionReturn.ql:45,26-34)
5+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateStorageDurationsFunctionReturn.ql:51,3-11)
66
| test.c:3:10:3:10 | a | $@ with automatic storage may be accessible outside of its lifetime. | test.c:3:10:3:10 | a | a |
77
| test.c:15:4:15:8 | param [inner post update] | $@ with automatic storage may be accessible outside of its lifetime. | test.c:15:12:15:13 | a2 | a2 |
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| test.c:65:18:65:18 | a | Field access on $@ qualifier occurs after its temporary object lifetime. | test.c:65:9:65:14 | call to get_s1 |function call |
2-
| test.c:67:18:67:19 | s1 | Field access on $@ qualifier occurs after its temporary object lifetime. | test.c:67:9:67:14 | call to get_s3 |function call |
3-
| test.c:68:18:68:19 | i1 | Field access on $@ qualifier occurs after its temporary object lifetime. | test.c:68:9:68:14 | call to get_s3 |function call |
4-
| test.c:69:18:69:21 | af12 | Field access on $@ qualifier occurs after its temporary object lifetime. | test.c:69:9:69:14 | call to get_s4 |function call |
1+
| test.c:65:18:65:18 | a | Field access on $@ qualifier occurs after its temporary object lifetime. | test.c:65:9:65:14 | call to get_s1 |temporary object |
2+
| test.c:67:18:67:19 | s1 | Field access on $@ qualifier occurs after its temporary object lifetime. | test.c:67:9:67:14 | call to get_s3 |temporary object |
3+
| test.c:68:18:68:19 | i1 | Field access on $@ qualifier occurs after its temporary object lifetime. | test.c:68:9:68:14 | call to get_s3 |temporary object |
4+
| test.c:69:18:69:21 | af12 | Field access on $@ qualifier occurs after its temporary object lifetime. | test.c:69:9:69:14 | call to get_s4 |temporary object |
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import cpp
2+
3+
newtypeTIdentifierLinkage=
4+
TIdentifierLinkageExternal()or
5+
TIdentifierLinkageInternal()or
6+
TIdentifierLinkageNone()
7+
8+
/**
9+
* In C, identifiers have internal linkage, or external linkage, or no linkage (6.2.2.1).
10+
*
11+
* The linkage of an identifier is used to, among other things, determine the storage duration
12+
* and/or lifetime of that identifier. Storage durations and lifetimes are often used to define
13+
* rules in the various coding standards.
14+
*/
15+
classIdentifierLinkageextendsTIdentifierLinkage{
16+
predicateisExternal(){this=TIdentifierLinkageExternal()}
17+
18+
predicateisInternal(){this=TIdentifierLinkageInternal()}
19+
20+
predicateisNone(){this=TIdentifierLinkageNone()}
21+
22+
stringtoString(){
23+
this.isExternal()andresult="external linkage"
24+
or
25+
this.isInternal()andresult="internal linkage"
26+
or
27+
this.isNone()andresult="no linkage"
28+
}
29+
}
30+
31+
/**
32+
* Determine the linkage of a variable: external, or static, or none.
33+
*
34+
* The linkage of a variable is determined by its scope and storage class. Note that other types of
35+
* identifiers (e.g. functions) may also have linkage, but that behavior is not covered in this
36+
* predicate.
37+
*/
38+
IdentifierLinkagelinkageOfVariable(Variablev){
39+
// 6.2.2.3, file scope identifiers marked static have internal linkage.
40+
v.isTopLevel()andv.isStatic()andresult.isInternal()
41+
or
42+
// 6.2.2.4 describes generally non-static file scope identifiers, which have external linkage.
43+
v.isTopLevel()andnotv.isStatic()andresult.isExternal()
44+
or
45+
// Note: Not all identifiers have linkage, see 6.2.2.6
46+
notv.isTopLevel()andresult.isNone()
47+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp