@@ -113,22 +113,12 @@ private newtype TDefOrUseImpl =
113
113
TGlobalUse ( GlobalLikeVariable v , IRFunction f , int indirectionIndex ) {
114
114
// Represents a final "use" of a global variable to ensure that
115
115
// the assignment to a global variable isn't ruled out as dead.
116
- exists ( VariableAddressInstruction vai , int defIndex |
117
- vai .getEnclosingIRFunction ( ) = f and
118
- vai .getAstVariable ( ) = v and
119
- isDef ( _, _, _, vai , _, defIndex ) and
120
- indirectionIndex = [ 0 .. defIndex ] + 1
121
- )
116
+ isGlobalUse ( v , f , _, indirectionIndex )
122
117
} or
123
118
TGlobalDefImpl ( GlobalLikeVariable v , IRFunction f , int indirectionIndex ) {
124
119
// Represents the initial "definition" of a global variable when entering
125
120
// a function body.
126
- exists ( VariableAddressInstruction vai |
127
- vai .getEnclosingIRFunction ( ) = f and
128
- vai .getAstVariable ( ) = v and
129
- isUse ( _, _, vai , _, indirectionIndex ) and
130
- not isDef ( _, _, vai .getAUse ( ) , _, _, _)
131
- )
121
+ isGlobalDefImpl ( v , f , _, indirectionIndex )
132
122
} or
133
123
TIteratorDef (
134
124
Operand iteratorDerefAddress , BaseSourceVariableInstruction container , int indirectionIndex
@@ -150,6 +140,28 @@ private newtype TDefOrUseImpl =
150
140
)
151
141
}
152
142
143
+ private predicate isGlobalUse (
144
+ GlobalLikeVariable v , IRFunction f , int indirection , int indirectionIndex
145
+ ) {
146
+ exists ( VariableAddressInstruction vai , int defIndex |
147
+ vai .getEnclosingIRFunction ( ) = f and
148
+ vai .getAstVariable ( ) = v and
149
+ isDef ( _, _, _, vai , indirection , defIndex ) and
150
+ indirectionIndex = [ 0 .. defIndex ] + 1
151
+ )
152
+ }
153
+
154
+ private predicate isGlobalDefImpl (
155
+ GlobalLikeVariable v , IRFunction f , int indirection , int indirectionIndex
156
+ ) {
157
+ exists ( VariableAddressInstruction vai |
158
+ vai .getEnclosingIRFunction ( ) = f and
159
+ vai .getAstVariable ( ) = v and
160
+ isUse ( _, _, vai , indirection , indirectionIndex ) and
161
+ not isDef ( _, _, vai .getAUse ( ) , _, _, _)
162
+ )
163
+ }
164
+
153
165
private predicate unspecifiedTypeIsModifiableAt ( Type unspecified , int indirectionIndex ) {
154
166
indirectionIndex = [ 1 .. getIndirectionForUnspecifiedType ( unspecified ) .getNumberOfIndirections ( ) ] and
155
167
exists ( CppType cppType |
@@ -438,7 +450,7 @@ class GlobalUse extends UseImpl, TGlobalUse {
438
450
439
451
override FinalGlobalValue getNode ( ) { result .getGlobalUse ( ) = this }
440
452
441
- override int getIndirection ( ) { result = ind + 1 }
453
+ override int getIndirection ( ) { isGlobalUse ( global , f , result , ind ) }
442
454
443
455
/** Gets the global variable associated with this use. */
444
456
GlobalLikeVariable getVariable ( ) { result = global }
0 commit comments