@@ -39,8 +39,26 @@ Variable getAddressOfExprTargetBase(AddressOfExpr expr) {
3939 result = expr .getOperand ( ) .( VariableAccess ) .getTarget ( )
4040}
4141
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+
4260from
43- AssignmentOrInitializationToRestrictPtrValueExpr source ,
61+ AssignedValueToRestrictPtrValueConfiguration config , DataFlow :: Node sourceValue ,
4462 AssignmentOrInitializationToRestrictPtrValueExpr expr ,
4563 AssignmentOrInitializationToRestrictPtrValueExpr pre_expr
4664where
@@ -49,23 +67,14 @@ where
4967 // If the same expressions flows to two unique `AssignmentOrInitializationToRestrictPtrValueExpr`
5068 // in the same block, then the two variables point to the same (overlapping) object
5169 expr .getEnclosingBlock ( ) = pre_expr .getEnclosingBlock ( ) and
52- strictlyDominates ( pre_expr , expr ) and
5370 (
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 ) )
5773 or
5874 // 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 )
6276 ) 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 ) )
6978 or
7079 // Two restrict-qualified pointers in the same scope assigned to each other
7180 expr .( VariableAccess ) .getTarget ( ) .getType ( ) .hasSpecifier ( "restrict" ) and
0 commit comments