@@ -11,6 +11,7 @@ private import semmle.code.cpp.ir.IR
11
11
private import semmle.code.cpp.controlflow.IRGuards
12
12
private import semmle.code.cpp.models.interfaces.DataFlow
13
13
private import DataFlowPrivate
14
+ private import DataFlowDispatch
14
15
private import SsaInternals as Ssa
15
16
16
17
cached
@@ -490,19 +491,53 @@ class ExprNode extends InstructionNode {
490
491
override string toString ( ) { result = this .asConvertedExpr ( ) .toString ( ) }
491
492
}
492
493
493
- /**
494
- * INTERNAL: do not use. Translates a parameter/argument index into a negative
495
- * number that denotes the index of its side effect (pointer indirection).
496
- */
497
- bindingset [ index]
498
- int getArgumentPosOfSideEffect ( int index ) {
499
- // -1 -> -2
500
- // 0 -> -3
501
- // 1 -> -4
502
- // ...
503
- result = - 3 - index
494
+ /** A parameter position represented by an integer. */
495
+ class ParameterPosition = Position ;
496
+
497
+ /** An argument position represented by an integer. */
498
+ class ArgumentPosition = Position ;
499
+
500
+ class Position extends TPosition {
501
+ abstract string toString ( ) ;
502
+ }
503
+
504
+ class ThisPosition extends TThisPosition {
505
+ string toString ( ) { result = "this" }
506
+ }
507
+
508
+ class ThisIndirectionPosition extends TThisIndirectionPosition {
509
+ string toString ( ) { result = "this" }
510
+ }
511
+
512
+ class Positional extends TPositional {
513
+ int index ;
514
+
515
+ Positional ( ) { this = TPositional ( index ) }
516
+
517
+ string toString ( ) { result = index .toString ( ) }
518
+
519
+ int getIndex ( ) {
520
+ result = index
521
+ }
504
522
}
505
523
524
+ class PositionalIndirection extends TPositionalIndirection {
525
+ int index ;
526
+
527
+ PositionalIndirection ( ) { this = TPositionalIndirection ( index ) }
528
+
529
+ string toString ( ) { result = index .toString ( ) }
530
+ int getIndex ( ) {
531
+ result = index
532
+ }
533
+ }
534
+
535
+ newtype TPosition =
536
+ TThisPosition ( ) or
537
+ TThisIndirectionPosition ( ) or
538
+ TPositional ( int index ) { exists ( any ( Call c ) .getArgument ( index ) ) } or
539
+ TPositionalIndirection ( int index ) { exists ( any ( Call c ) .getArgument ( index ) ) }
540
+
506
541
/**
507
542
* The value of a parameter at function entry, viewed as a node in a data
508
543
* flow graph. This includes both explicit parameters such as `x` in `f(x)`
@@ -525,7 +560,7 @@ class ParameterNode extends InstructionNode {
525
560
* implicit `this` parameter is considered to have position `-1`, and
526
561
* pointer-indirection parameters are at further negative positions.
527
562
*/
528
- predicate isParameterOf ( Function f , int pos ) { none ( ) } // overridden by subclasses
563
+ predicate isParameterOf ( Function f , ParameterPosition pos ) { none ( ) } // overridden by subclasses
529
564
}
530
565
531
566
/** An explicit positional parameter, not including `this` or `...`. */
@@ -534,8 +569,8 @@ private class ExplicitParameterNode extends ParameterNode {
534
569
535
570
ExplicitParameterNode ( ) { exists ( instr .getParameter ( ) ) }
536
571
537
- override predicate isParameterOf ( Function f , int pos ) {
538
- f .getParameter ( pos ) = instr .getParameter ( )
572
+ override predicate isParameterOf ( Function f , ParameterPosition pos ) {
573
+ f .getParameter ( pos . ( Positional ) . getIndex ( ) ) = instr .getParameter ( )
539
574
}
540
575
541
576
/** Gets the `Parameter` associated with this node. */
@@ -550,8 +585,8 @@ class ThisParameterNode extends ParameterNode {
550
585
551
586
ThisParameterNode ( ) { instr .getIRVariable ( ) instanceof IRThisVariable }
552
587
553
- override predicate isParameterOf ( Function f , int pos ) {
554
- pos = - 1 and instr .getEnclosingFunction ( ) = f
588
+ override predicate isParameterOf ( Function f , ParameterPosition pos ) {
589
+ pos instanceof ThisPosition and instr .getEnclosingFunction ( ) = f
555
590
}
556
591
557
592
override string toString ( ) { result = "this" }
@@ -561,13 +596,17 @@ class ThisParameterNode extends ParameterNode {
561
596
class ParameterIndirectionNode extends ParameterNode {
562
597
override InitializeIndirectionInstruction instr ;
563
598
564
- override predicate isParameterOf ( Function f , int pos ) {
599
+ override predicate isParameterOf ( Function f , ParameterPosition pos ) {
565
600
exists ( int index |
566
601
instr .getEnclosingFunction ( ) = f and
567
602
instr .hasIndex ( index )
568
603
|
569
- pos = getArgumentPosOfSideEffect ( index )
604
+ pos . ( PositionalIndirection ) . getIndex ( ) = index
570
605
)
606
+ or
607
+ instr .getEnclosingFunction ( ) = f and
608
+ instr .hasIndex ( - 1 ) and
609
+ pos instanceof ThisIndirectionPosition
571
610
}
572
611
573
612
override string toString ( ) { result = "*" + instr .getIRVariable ( ) .toString ( ) }
0 commit comments