@@ -105,8 +105,8 @@ predicate hasRawIndirectInstruction(Instruction instr, int indirectionIndex) {
105
105
cached
106
106
private newtype TDefImpl =
107
107
TDefAddressImpl ( BaseIRVariable v ) or
108
- TDirectDefImpl ( BaseSourceVariableInstruction base , Operand address , int indirectionIndex ) {
109
- isDef ( _, _, address , base , _, indirectionIndex )
108
+ TDirectDefImpl ( Operand address , int indirectionIndex ) {
109
+ isDef ( _, _, address , _ , _, indirectionIndex )
110
110
} or
111
111
TGlobalDefImpl ( GlobalLikeVariable v , IRFunction f , int indirectionIndex ) {
112
112
// Represents the initial "definition" of a global variable when entering
@@ -116,8 +116,8 @@ private newtype TDefImpl =
116
116
117
117
cached
118
118
private newtype TUseImpl =
119
- TDirectUseImpl ( BaseSourceVariableInstruction base , Operand operand , int indirectionIndex ) {
120
- isUse ( _, operand , base , _, indirectionIndex ) and
119
+ TDirectUseImpl ( Operand operand , int indirectionIndex ) {
120
+ isUse ( _, operand , _ , _, indirectionIndex ) and
121
121
not isDef ( true , _, operand , _, _, _)
122
122
} or
123
123
TGlobalUse ( GlobalLikeVariable v , IRFunction f , int indirectionIndex ) {
@@ -211,19 +211,11 @@ abstract class DefImpl extends TDefImpl {
211
211
*/
212
212
abstract int getIndirection ( ) ;
213
213
214
- /**
215
- * Gets the instruction that computes the base of this definition or use.
216
- * This is always a `VariableAddressInstruction` or an `CallInstruction`.
217
- */
218
- abstract BaseSourceVariableInstruction getBase ( ) ;
219
-
220
214
/**
221
215
* Gets the base source variable (i.e., the variable without
222
216
* any indirection) of this definition or use.
223
217
*/
224
- final BaseSourceVariable getBaseSourceVariable ( ) {
225
- this .getBase ( ) .getBaseSourceVariable ( ) = result
226
- }
218
+ abstract BaseSourceVariable getBaseSourceVariable ( ) ;
227
219
228
220
/** Gets the variable that is defined or used. */
229
221
SourceVariable getSourceVariable ( ) {
@@ -283,19 +275,11 @@ abstract class UseImpl extends TUseImpl {
283
275
/** Gets the indirection index of this use. */
284
276
final int getIndirectionIndex ( ) { result = indirectionIndex }
285
277
286
- /**
287
- * Gets the instruction that computes the base of this definition or use.
288
- * This is always a `VariableAddressInstruction` or an `CallInstruction`.
289
- */
290
- abstract BaseSourceVariableInstruction getBase ( ) ;
291
-
292
278
/**
293
279
* Gets the base source variable (i.e., the variable without
294
280
* any indirection) of this definition or use.
295
281
*/
296
- final BaseSourceVariable getBaseSourceVariable ( ) {
297
- this .getBase ( ) .getBaseSourceVariable ( ) = result
298
- }
282
+ abstract BaseSourceVariable getBaseSourceVariable ( ) ;
299
283
300
284
/** Gets the variable that is defined or used. */
301
285
SourceVariable getSourceVariable ( ) {
@@ -377,14 +361,13 @@ private class DefAddressImpl extends DefImpl, TDefAddressImpl {
377
361
result .getIndirection ( ) = 0
378
362
}
379
363
380
- final override BaseSourceVariableInstruction getBase ( ) { none ( ) }
364
+ final override BaseSourceVariable getBaseSourceVariable ( ) { result = v }
381
365
}
382
366
383
367
private class DirectDef extends DefImpl , TDirectDefImpl {
384
368
Operand address ;
385
- BaseSourceVariableInstruction base ;
386
369
387
- DirectDef ( ) { this = TDirectDefImpl ( base , address , indirectionIndex ) }
370
+ DirectDef ( ) { this = TDirectDefImpl ( address , indirectionIndex ) }
388
371
389
372
override Cpp:: Location getLocation ( ) { result = this .getAddressOperand ( ) .getUse ( ) .getLocation ( ) }
390
373
@@ -396,30 +379,36 @@ private class DirectDef extends DefImpl, TDirectDefImpl {
396
379
397
380
override Operand getAddressOperand ( ) { result = address }
398
381
399
- override BaseSourceVariableInstruction getBase ( ) { result = base }
382
+ private BaseSourceVariableInstruction getBase ( ) {
383
+ isDef ( _, _, address , result , _, indirectionIndex )
384
+ }
400
385
401
- override int getIndirection ( ) { isDef ( _, _, address , base , result , indirectionIndex ) }
386
+ override BaseSourceVariable getBaseSourceVariable ( ) {
387
+ result = this .getBase ( ) .getBaseSourceVariable ( )
388
+ }
389
+
390
+ override int getIndirection ( ) { isDef ( _, _, address , _, result , indirectionIndex ) }
402
391
403
- override Node0Impl getValue ( ) { isDef ( _, result , address , base , _, _) }
392
+ override Node0Impl getValue ( ) { isDef ( _, result , address , _ , _, _) }
404
393
405
- override predicate isCertain ( ) { isDef ( true , _, address , base , _, indirectionIndex ) }
394
+ override predicate isCertain ( ) { isDef ( true , _, address , _ , _, indirectionIndex ) }
406
395
}
407
396
408
397
private class DirectUseImpl extends UseImpl , TDirectUseImpl {
409
398
Operand operand ;
410
- BaseSourceVariableInstruction base ;
411
399
412
- DirectUseImpl ( ) { this = TDirectUseImpl ( base , operand , indirectionIndex ) }
400
+ DirectUseImpl ( ) { this = TDirectUseImpl ( operand , indirectionIndex ) }
413
401
414
402
override string toString ( ) { result = "Use of " + this .getSourceVariable ( ) }
415
403
416
404
final override predicate hasIndexInBlock ( IRBlock block , int index ) {
417
405
// See the comment in `ssa0`'s `OperandBasedUse` for an explanation of this
418
406
// predicate's implementation.
419
- if base .getAst ( ) = any ( Cpp:: PostfixCrementOperation c ) .getOperand ( )
407
+ if this . getBase ( ) .getAst ( ) = any ( Cpp:: PostfixCrementOperation c ) .getOperand ( )
420
408
then
421
- exists ( Operand op , int indirection |
409
+ exists ( Operand op , int indirection , Instruction base |
422
410
indirection = this .getIndirection ( ) and
411
+ base = this .getBase ( ) and
423
412
op =
424
413
min ( Operand cand , int i |
425
414
isUse ( _, cand , base , indirection , indirectionIndex ) and
@@ -432,15 +421,19 @@ private class DirectUseImpl extends UseImpl, TDirectUseImpl {
432
421
else operand .getUse ( ) = block .getInstruction ( index )
433
422
}
434
423
435
- final override BaseSourceVariableInstruction getBase ( ) { result = base }
424
+ private BaseSourceVariableInstruction getBase ( ) { isUse ( _, operand , result , _, indirectionIndex ) }
425
+
426
+ override BaseSourceVariable getBaseSourceVariable ( ) {
427
+ result = this .getBase ( ) .getBaseSourceVariable ( )
428
+ }
436
429
437
430
final Operand getOperand ( ) { result = operand }
438
431
439
432
final override Cpp:: Location getLocation ( ) { result = operand .getLocation ( ) }
440
433
441
- override int getIndirection ( ) { isUse ( _, operand , base , result , indirectionIndex ) }
434
+ override int getIndirection ( ) { isUse ( _, operand , _ , result , indirectionIndex ) }
442
435
443
- override predicate isCertain ( ) { isUse ( true , operand , base , _, indirectionIndex ) }
436
+ override predicate isCertain ( ) { isUse ( true , operand , _ , _, indirectionIndex ) }
444
437
445
438
override Node getNode ( ) { nodeHasOperand ( result , operand , indirectionIndex ) }
446
439
}
@@ -499,13 +492,7 @@ class FinalParameterUse extends UseImpl, TFinalParameterUse {
499
492
result instanceof UnknownDefaultLocation
500
493
}
501
494
502
- override BaseSourceVariableInstruction getBase ( ) {
503
- exists ( InitializeParameterInstruction init |
504
- init .getParameter ( ) = p and
505
- // This is always a `VariableAddressInstruction`
506
- result = init .getAnOperand ( ) .getDef ( )
507
- )
508
- }
495
+ override BaseIRVariable getBaseSourceVariable ( ) { result .getIRVariable ( ) .getAst ( ) = p }
509
496
}
510
497
511
498
/**
@@ -591,8 +578,8 @@ class GlobalUse extends UseImpl, TGlobalUse {
591
578
)
592
579
}
593
580
594
- override SourceVariable getSourceVariable ( ) {
595
- sourceVariableIsGlobal ( result , global , f , this . getIndirection ( ) )
581
+ override BaseSourceVariable getBaseSourceVariable ( ) {
582
+ baseSourceVariableIsGlobal ( result , global , f )
596
583
}
597
584
598
585
final override Cpp:: Location getLocation ( ) { result = f .getLocation ( ) }
@@ -609,8 +596,6 @@ class GlobalUse extends UseImpl, TGlobalUse {
609
596
Type getUnderlyingType ( ) { result = global .getUnderlyingType ( ) }
610
597
611
598
override predicate isCertain ( ) { any ( ) }
612
-
613
- override BaseSourceVariableInstruction getBase ( ) { none ( ) }
614
599
}
615
600
616
601
/**
@@ -640,8 +625,8 @@ class GlobalDefImpl extends DefImpl, TGlobalDefImpl {
640
625
}
641
626
642
627
/** Gets the global variable associated with this definition. */
643
- override SourceVariable getSourceVariable ( ) {
644
- sourceVariableIsGlobal ( result , global , f , this . getIndirection ( ) )
628
+ override BaseSourceVariable getBaseSourceVariable ( ) {
629
+ baseSourceVariableIsGlobal ( result , global , f )
645
630
}
646
631
647
632
override int getIndirection ( ) { result = indirectionIndex }
@@ -664,8 +649,6 @@ class GlobalDefImpl extends DefImpl, TGlobalDefImpl {
664
649
override string toString ( ) { result = "Def of " + this .getSourceVariable ( ) }
665
650
666
651
override Location getLocation ( ) { result = f .getLocation ( ) }
667
-
668
- override BaseSourceVariableInstruction getBase ( ) { none ( ) }
669
652
}
670
653
671
654
/**
@@ -978,11 +961,10 @@ predicate fromPhiNode(SsaPhiNode nodeFrom, Node nodeTo) {
978
961
)
979
962
}
980
963
981
- private predicate sourceVariableIsGlobal (
982
- SourceVariable sv , GlobalLikeVariable global , IRFunction func , int indirectionIndex
964
+ private predicate baseSourceVariableIsGlobal (
965
+ BaseIRVariable base , GlobalLikeVariable global , IRFunction func
983
966
) {
984
- exists ( IRVariable irVar , BaseIRVariable base |
985
- sourceVariableHasBaseAndIndex ( sv , base , indirectionIndex ) and
967
+ exists ( IRVariable irVar |
986
968
irVar = base .getIRVariable ( ) and
987
969
irVar .getEnclosingIRFunction ( ) = func and
988
970
global = irVar .getAst ( ) and
0 commit comments