@@ -39,8 +39,26 @@ Variable getAddressOfExprTargetBase(AddressOfExpr expr) {
39
39
result = expr .getOperand ( ) .( VariableAccess ) .getTarget ( )
40
40
}
41
41
42
+ /**
43
+ * A data-flow configuration for tracking flow from an assignment or initialization to
44
+ * an assignment to an `AssignmentOrInitializationToRestrictPtrValueExpr`.
45
+ */
46
+ class AssignedValueToRestrictPtrValueConfiguration extends DataFlow:: Configuration {
47
+ AssignedValueToRestrictPtrValueConfiguration ( ) {
48
+ this = "AssignmentOrInitializationToRestrictPtrValueConfiguration"
49
+ }
50
+
51
+ override predicate isSource ( DataFlow:: Node source ) {
52
+ exists ( Variable v | source .asExpr ( ) = v .getAnAssignedValue ( ) )
53
+ }
54
+
55
+ override predicate isSink ( DataFlow:: Node sink ) {
56
+ sink .asExpr ( ) instanceof AssignmentOrInitializationToRestrictPtrValueExpr
57
+ }
58
+ }
59
+
42
60
from
43
- AssignmentOrInitializationToRestrictPtrValueExpr source ,
61
+ AssignedValueToRestrictPtrValueConfiguration config , DataFlow :: Node sourceValue ,
44
62
AssignmentOrInitializationToRestrictPtrValueExpr expr ,
45
63
AssignmentOrInitializationToRestrictPtrValueExpr pre_expr
46
64
where
@@ -49,23 +67,14 @@ where
49
67
// If the same expressions flows to two unique `AssignmentOrInitializationToRestrictPtrValueExpr`
50
68
// in the same block, then the two variables point to the same (overlapping) object
51
69
expr .getEnclosingBlock ( ) = pre_expr .getEnclosingBlock ( ) and
52
- strictlyDominates ( pre_expr , expr ) and
53
70
(
54
- dominates ( source , pre_expr ) and
55
- DataFlow:: localExprFlow ( source , expr ) and
56
- DataFlow:: localExprFlow ( source , pre_expr )
71
+ config .hasFlow ( sourceValue , DataFlow:: exprNode ( pre_expr ) ) and
72
+ config .hasFlow ( sourceValue , DataFlow:: exprNode ( expr ) )
57
73
or
58
74
// Expressions referring to the address of the same variable can also result in aliasing
59
- getAddressOfExprTargetBase ( expr ) = getAddressOfExprTargetBase ( pre_expr ) and
60
- source =
61
- any ( AddressOfExpr ao | getAddressOfExprTargetBase ( ao ) = getAddressOfExprTargetBase ( expr ) )
75
+ getAddressOfExprTargetBase ( expr ) = getAddressOfExprTargetBase ( pre_expr )
62
76
) and
63
- // But only if there is no intermediate assignment that could change the value of one of the variables
64
- not exists ( AssignmentOrInitializationToRestrictPtrValueExpr mid |
65
- strictlyDominates ( mid , expr ) and
66
- strictlyDominates ( pre_expr , mid ) and
67
- not DataFlow:: localExprFlow ( source , mid )
68
- )
77
+ strictlyDominates ( pragma [ only_bind_out ] ( pre_expr ) , pragma [ only_bind_out ] ( expr ) )
69
78
or
70
79
// Two restrict-qualified pointers in the same scope assigned to each other
71
80
expr .( VariableAccess ) .getTarget ( ) .getType ( ) .hasSpecifier ( "restrict" ) and
0 commit comments