@@ -146,14 +146,56 @@ private newtype TDefOrUseImpl =
146
146
)
147
147
}
148
148
149
+ /**
150
+ * Holds if `fa` flows to a the address of a `StoreInstruction`, or flows to
151
+ * the qualifier of another field address that transitively flows to a `StoreInstruction`.
152
+ */
153
+ private predicate fieldFlowsToStore ( FieldAddress fa ) {
154
+ numberOfLoadsFromOperand ( fa , any ( StoreInstruction store ) .getDestinationAddressOperand ( ) , _, _)
155
+ or
156
+ exists ( FieldAddress mid |
157
+ numberOfLoadsFromOperand ( fa , mid .getObjectAddressOperand ( ) , _, _)
158
+ or
159
+ fieldFlowsToStore ( mid )
160
+ )
161
+ }
162
+
163
+ private predicate isGlobalUseIndirectDefCand ( GlobalLikeVariable v , IRFunction f , CppType type ) {
164
+ exists ( VariableAddressInstruction vai , Operand op |
165
+ vai .getEnclosingIRFunction ( ) = f and
166
+ vai .getAstVariable ( ) = v and
167
+ numberOfLoadsFromOperand ( vai .getAUse ( ) , op , _, _) and
168
+ type = getResultLanguageType ( vai )
169
+ |
170
+ // Either this operand is used as the qualifier of a field that flows to
171
+ // a `StoreInstruction`
172
+ op = any ( FieldAddress fa | fieldFlowsToStore ( fa ) ) .getObjectAddressOperand ( )
173
+ or
174
+ // Or the operand is potentially modified by a function call
175
+ isModifiableByCall ( op , _)
176
+ )
177
+ }
178
+
149
179
private predicate isGlobalUse (
150
180
GlobalLikeVariable v , IRFunction f , int indirection , int indirectionIndex
151
181
) {
182
+ // Generate a "global use" at the end of the function body if there's a
183
+ // direct definition somewhere in the body of the function
152
184
exists ( VariableAddressInstruction vai |
153
185
vai .getEnclosingIRFunction ( ) = f and
154
186
vai .getAstVariable ( ) = v and
155
187
isDef ( _, _, _, vai , indirection , indirectionIndex )
156
188
)
189
+ or
190
+ // Generate a "global use" at the end of the function body if the
191
+ // global variable is used for field-flow, or is passed as an argument
192
+ // to a function that may change its value.
193
+ exists ( CppType type , int upper |
194
+ isGlobalUseIndirectDefCand ( v , f , type ) and
195
+ upper = countIndirectionsForCppType ( type ) and
196
+ indirection = [ 1 .. upper ] and
197
+ indirectionIndex = indirection - 1
198
+ )
157
199
}
158
200
159
201
private predicate isGlobalDefImpl (
0 commit comments