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

Commitd3e1704

Browse files
Merge remote-tracking branch 'origin/main' into michaelrfairhurst/implement-missing-sin-precision-amendment
2 parents0a64609 +0fd4496 commitd3e1704

File tree

70 files changed

+3177
-1135
lines changed

Some content is hidden

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

70 files changed

+3177
-1135
lines changed

‎amendments.csv‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
language,standard,amendment,rule_id,supportable,implementation_category,implemented,difficulty
22
c,MISRA-C-2012,Amendment3,DIR-4-6,Yes,Expand,Yes,Easy
3-
c,MISRA-C-2012,Amendment3,DIR-4-9,Yes,Refine,No,Easy
3+
c,MISRA-C-2012,Amendment3,DIR-4-9,Yes,Refine,Yes,Easy
44
c,MISRA-C-2012,Amendment3,DIR-4-11,Yes,Refine,Yes,Import
5-
c,MISRA-C-2012,Amendment3,RULE-1-4,Yes,Replace,No,Easy
5+
c,MISRA-C-2012,Amendment3,RULE-1-4,Yes,Replace,Yes,Easy
66
c,MISRA-C-2012,Amendment3,RULE-10-1,Yes,Replace,Yes,Easy
77
c,MISRA-C-2012,Amendment3,RULE-10-3,Yes,Refine,Yes,Easy
88
c,MISRA-C-2012,Amendment3,RULE-10-4,Yes,Refine,Yes,Import
99
c,MISRA-C-2012,Amendment3,RULE-10-5,Yes,Expand,Yes,Easy
1010
c,MISRA-C-2012,Amendment3,RULE-10-7,Yes,Refine,Yes,Import
1111
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
13-
c,MISRA-C-2012,Amendment3,RULE-21-12,Yes,Replace,No,Easy
13+
c,MISRA-C-2012,Amendment3,RULE-21-12,Yes,Replace,Yes,Easy
1414
c,MISRA-C-2012,Amendment4,RULE-11-3,Yes,Expand,Yes,Easy
1515
c,MISRA-C-2012,Amendment4,RULE-11-8,Yes,Expand,Yes,Easy
1616
c,MISRA-C-2012,Amendment4,RULE-13-2,Yes,Expand,Yes,Very Hard
17-
c,MISRA-C-2012,Amendment4,RULE-18-6,Yes,Expand,No,Medium
17+
c,MISRA-C-2012,Amendment4,RULE-18-6,Yes,Expand,Yes,Medium
1818
c,MISRA-C-2012,Amendment4,RULE-18-8,Yes,Split,Yes,Easy
1919
c,MISRA-C-2012,Amendment4,RULE-2-2,Yes,Clarification,Yes,Import
2020
c,MISRA-C-2012,Amendment4,RULE-2-7,Yes,Clarification,Yes,Import
@@ -26,7 +26,6 @@ c,MISRA-C-2012,Amendment4,RULE-10-1,Yes,Clarification,Yes,Import
2626
c,MISRA-C-2012,Amendment4,RULE-18-3,Yes,Clarification,Yes,Import
2727
c,MISRA-C-2012,Amendment4,RULE-1-4,Yes,Replace,No,Easy
2828
c,MISRA-C-2012,Amendment4,RULE-9-1,Yes,Refine,Yes,Easy
29-
c,MISRA-C-2012,Amendment4,RULE-9-2,Yes,Refine,No,Import
3029
c,MISRA-C-2012,Corrigendum2,DIR-4-10,Yes,Clarification,Yes,Import
3130
c,MISRA-C-2012,Corrigendum2,RULE-7-4,Yes,Refine,Yes,Easy
3231
c,MISRA-C-2012,Corrigendum2,RULE-8-2,Yes,Clarification,Yes,Import
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/**
2+
* A library that expands upon the `Objects.qll` library, to support nested "Objects" such as
3+
* `x.y.z` or `x[i][j]` within an object `x`.
4+
*
5+
* Objects in C are values in memory, that have a type and a storage duration. In the case of
6+
* array objects and struct objects, the object will contain other objects. The these subobjects
7+
* will share properties of the root object such as storage duration. This library can be used to,
8+
* for instance, find all usages of a struct member to ensure that member is initialized before it
9+
* is used.
10+
*
11+
* To use this library, select `SubObject` and find its usages in the AST via `getAnAccess()` (to
12+
* find usages of the subobject by value) or `getAnAddressOfExpr()` (to find usages of the object
13+
* by address).
14+
*
15+
* Note that a struct or array object may contain a pointer. In this case, the pointer itself is
16+
* a subobject of the struct or array object, but the object that the pointer points to is not.
17+
* This is because the pointed-to object does not necessarily have the same storage duration,
18+
* lifetime, or linkage as the pointer and the object containing the pointer.
19+
*
20+
* Note as well that `getAnAccess()` on an array subobject will return all accesses to the array,
21+
* not just accesses to a particular index. For this reason, `SubObject` exposes the predicate
22+
* `isPrecise()`. If a subobject is precise, that means all results of `getAnAccess()` will
23+
* definitely refer to the same object in memory. If it is not precise, the different accesses
24+
* may refer to the same or different objects in memory. For instance, `x[i].y` and `x[j].y` are
25+
* the same object if `i` and `j` are the same, but they are different objects if `i` and `j` are
26+
* different.
27+
*/
28+
29+
import codingstandards.c.Objects
30+
31+
newtypeTSubObject=
32+
TObjectRoot(ObjectIdentityi)or
33+
TObjectMember(SubObjectstruct,MemberVariablem){
34+
m=struct.getType().(Struct).getAMemberVariable()
35+
}or
36+
TObjectIndex(SubObjectarray){array.getType()instanceofArrayType}
37+
38+
classSubObjectextendsTSubObject{
39+
stringtoString(){
40+
exists(ObjectIdentityi|
41+
this=TObjectRoot(i)and
42+
result=i.toString()
43+
)
44+
or
45+
exists(SubObjectstruct,Variablem|
46+
this=TObjectMember(struct,m)and
47+
result=struct.toString()+"."+m.getName()
48+
)
49+
or
50+
exists(SubObjectarray|
51+
this=TObjectIndex(array)and
52+
result=array.toString()
53+
)
54+
}
55+
56+
TypegetType(){
57+
exists(ObjectIdentityi|
58+
this=TObjectRoot(i)and
59+
result=i.getType()
60+
)
61+
or
62+
exists(Variablem|
63+
this=TObjectMember(_,m)and
64+
result=m.getType()
65+
)
66+
or
67+
exists(SubObjectarray|
68+
this=TObjectIndex(array)and
69+
result=array.getType().(ArrayType).getBaseType()
70+
)
71+
}
72+
73+
/**
74+
* Holds for object roots and for member accesses on that root, not for array accesses.
75+
*
76+
* This is useful for cases where we do not wish to treat `x[y]` and `x[z]` as the same object.
77+
*/
78+
predicateisPrecise(){notgetParent*()=TObjectIndex(_)}
79+
80+
SubObjectgetParent(){
81+
exists(SubObjectstruct,MemberVariablem|
82+
this=TObjectMember(struct,m)and
83+
result=struct
84+
)
85+
or
86+
exists(SubObjectarray|
87+
this=TObjectIndex(array)and
88+
result=array
89+
)
90+
}
91+
92+
ExprgetAnAccess(){
93+
exists(ObjectIdentityi|
94+
this=TObjectRoot(i)and
95+
result=i.getAnAccess()
96+
)
97+
or
98+
exists(MemberVariablem|
99+
this=TObjectMember(_,m)and
100+
result=m.getAnAccess()and
101+
// Only consider `DotFieldAccess`es, not `PointerFieldAccess`es, as the latter
102+
// are not subobjects of the root object:
103+
result.(DotFieldAccess).getQualifier()=getParent().getAnAccess()
104+
)
105+
or
106+
this=TObjectIndex(_)and
107+
result.(ArrayExpr).getArrayBase()=getParent().getAnAccess()
108+
}
109+
110+
AddressOfExprgetAnAddressOfExpr(){result.getOperand()=this.getAnAccess()}
111+
112+
/**
113+
* Get the "root" object identity to which this subobject belongs. For instance, in the
114+
* expression `x.y.z`, the root object is `x`. This subobject will share properties with the root
115+
* object such as storage duration, lifetime, and linkage.
116+
*/
117+
ObjectIdentitygetRootIdentity(){
118+
exists(ObjectIdentityi|
119+
this=TObjectRoot(i)and
120+
result=i
121+
)
122+
or
123+
result=getParent().getRootIdentity()
124+
}
125+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import cpp
2+
import codingstandards.c.Objects
3+
import codingstandards.cpp.Concurrency
4+
import codingstandards.cpp.Type
5+
6+
signaturemodule GlobalInitializationAnalysisConfigSig{
7+
/** A function which is not called or started as a thread */
8+
defaultpredicateisRootFunction(Functionf){
9+
notexists(Functionf2|f2.calls(f))and
10+
notfinstanceofThreadedFunctionand
11+
// Exclude functions which are used as function pointers.
12+
notexists(FunctionAccessaccess|f=access.getTarget())
13+
}
14+
15+
ObjectIdentitygetAnInitializedObject(Expre);
16+
17+
ObjectIdentitygetAUsedObject(Expre);
18+
}
19+
20+
module GlobalInitalizationAnalysis<GlobalInitializationAnalysisConfigSig Config>{
21+
finalclassFinalFunction=Function;
22+
23+
finalclassFinalExpr=Expr;
24+
25+
classRootFunctionextendsFinalFunction{
26+
RootFunction(){ Config::isRootFunction(this)}
27+
}
28+
29+
/** A function call which initializes a mutex or a condition */
30+
classObjectInitextendsFinalExpr{
31+
ObjectIdentityowningObject;
32+
33+
ObjectInit(){owningObject= Config::getAnInitializedObject(this)}
34+
35+
ObjectIdentitygetOwningObject(){result=owningObject}
36+
}
37+
38+
/**
39+
* A function argument where that argument is used as a mutex or condition object.
40+
*/
41+
classObjectUseextendsFinalExpr{
42+
ObjectIdentityowningObject;
43+
44+
ObjectUse(){owningObject= Config::getAUsedObject(this)}
45+
46+
ObjectIdentitygetOwningObject(){result=owningObject}
47+
}
48+
49+
predicaterequiresInitializedMutexObject(
50+
Functionfunc,ObjectUsemutexUse,ObjectIdentityowningObject
51+
){
52+
mutexUse.getEnclosingFunction()=funcand
53+
owningObject=mutexUse.getOwningObject()and
54+
notexists(ObjectInitinit|
55+
init.getEnclosingFunction()=funcand
56+
init.getOwningObject()=owningObjectand
57+
mutexUse.getAPredecessor+()=init
58+
)
59+
or
60+
exists(FunctionCallcall|
61+
func=call.getEnclosingFunction()and
62+
requiresInitializedMutexObject(call.getTarget(),mutexUse,owningObject)and
63+
notexists(ObjectInitinit|
64+
call.getAPredecessor*()=initand
65+
init.getOwningObject()=owningObject
66+
)
67+
)
68+
or
69+
exists(C11ThreadCreateCallcall|
70+
func=call.getEnclosingFunction()and
71+
notowningObject.getStorageDuration().isThread()and
72+
requiresInitializedMutexObject(call.getFunction(),mutexUse,owningObject)and
73+
notexists(ObjectInitinit|
74+
call.getAPredecessor*()=initand
75+
init.getOwningObject()=owningObject
76+
)
77+
)
78+
}
79+
80+
predicateuninitializedFrom(Expre,ObjectIdentityobj,FunctioncallRoot){
81+
exists(ObjectUseuse|use=e|
82+
obj=use.getOwningObject()and
83+
requiresInitializedMutexObject(callRoot,use,obj)and
84+
(
85+
ifobj.getStorageDuration().isAutomatic()
86+
thenobj.getEnclosingElement+()=callRoot
87+
else(
88+
obj.getStorageDuration().isThread()andcallRootinstanceofThreadedFunction
89+
or
90+
callRootinstanceofRootFunction
91+
)
92+
)
93+
)
94+
}
95+
}

‎c/common/test/includes/standard-library/stdlib.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ int at_quick_exit (void (*) (void));
4949
_Noreturnvoidquick_exit (int);
5050

5151
char*getenv (constchar*);
52+
char*getenv_s (size_t*restrictlen,char*restrictvalue,size_tvaluesz,constchar*restrictname);
5253

5354
intsystem (constchar*);
5455

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp