@@ -371,7 +371,7 @@ private class PrimaryArgumentNode extends ArgumentNode, OperandNode {
371
371
PrimaryArgumentNode ( ) { exists ( CallInstruction call | op = call .getAnArgumentOperand ( ) ) }
372
372
373
373
override predicate argumentOf ( DataFlowCall call , ArgumentPosition pos ) {
374
- op = call .getArgumentOperand ( pos .( DirectPosition ) .getIndex ( ) )
374
+ op = call .getArgumentOperand ( pos .( DirectPosition ) .getArgumentIndex ( ) )
375
375
}
376
376
}
377
377
@@ -410,8 +410,16 @@ class ParameterPosition = Position;
410
410
class ArgumentPosition = Position ;
411
411
412
412
abstract class Position extends TPosition {
413
+ /** Gets a textual representation of this position. */
413
414
abstract string toString ( ) ;
414
415
416
+ /**
417
+ * Gets the argument index of this position. The qualifier of a call has
418
+ * argument index `-1`.
419
+ */
420
+ abstract int getArgumentIndex ( ) ;
421
+
422
+ /** Gets the indirection index of this position. */
415
423
abstract int getIndirectionIndex ( ) ;
416
424
}
417
425
@@ -428,7 +436,7 @@ class DirectPosition extends Position, TDirectPosition {
428
436
result = index .toString ( )
429
437
}
430
438
431
- int getIndex ( ) { result = index }
439
+ override int getArgumentIndex ( ) { result = index }
432
440
433
441
final override int getIndirectionIndex ( ) { result = 0 }
434
442
}
@@ -445,16 +453,29 @@ class IndirectionPosition extends Position, TIndirectionPosition {
445
453
else result = repeatStars ( indirectionIndex ) + argumentIndex .toString ( )
446
454
}
447
455
448
- int getArgumentIndex ( ) { result = argumentIndex }
456
+ override int getArgumentIndex ( ) { result = argumentIndex }
449
457
450
458
final override int getIndirectionIndex ( ) { result = indirectionIndex }
451
459
}
452
460
453
461
newtype TPosition =
454
- TDirectPosition ( int argumentIndex ) { exists ( any ( CallInstruction c ) .getArgument ( argumentIndex ) ) } or
462
+ TDirectPosition ( int argumentIndex ) {
463
+ exists ( any ( CallInstruction c ) .getArgument ( argumentIndex ) )
464
+ or
465
+ // Handle the rare case where there is a function definition but no call to
466
+ // the function.
467
+ exists ( any ( Cpp:: Function f ) .getParameter ( argumentIndex ) )
468
+ } or
455
469
TIndirectionPosition ( int argumentIndex , int indirectionIndex ) {
456
470
Ssa:: hasIndirectOperand ( any ( CallInstruction call ) .getArgumentOperand ( argumentIndex ) ,
457
471
indirectionIndex )
472
+ or
473
+ // Handle the rare case where there is a function definition but no call to
474
+ // the function.
475
+ exists ( Cpp:: Function f , Cpp:: Parameter p |
476
+ p = f .getParameter ( argumentIndex ) and
477
+ indirectionIndex = [ 1 .. Ssa:: getMaxIndirectionsForType ( p .getUnspecifiedType ( ) ) - 1 ]
478
+ )
458
479
}
459
480
460
481
private newtype TReturnKind =
@@ -501,6 +522,15 @@ class ReturnKind extends TReturnKind {
501
522
502
523
/** Gets a textual representation of this return kind. */
503
524
abstract string toString ( ) ;
525
+
526
+ /** Holds if this `ReturnKind` is generated from a `return` statement. */
527
+ abstract predicate isNormalReturn ( ) ;
528
+
529
+ /**
530
+ * Holds if this `ReturnKind` is generated from a write to the parameter with
531
+ * index `argumentIndex`
532
+ */
533
+ abstract predicate isIndirectReturn ( int argumentIndex ) ;
504
534
}
505
535
506
536
/**
@@ -514,6 +544,10 @@ class NormalReturnKind extends ReturnKind, TNormalReturnKind {
514
544
override int getIndirectionIndex ( ) { result = indirectionIndex }
515
545
516
546
override string toString ( ) { result = "indirect return" }
547
+
548
+ override predicate isNormalReturn ( ) { any ( ) }
549
+
550
+ override predicate isIndirectReturn ( int argumentIndex ) { none ( ) }
517
551
}
518
552
519
553
/**
@@ -528,6 +562,10 @@ private class IndirectReturnKind extends ReturnKind, TIndirectReturnKind {
528
562
override int getIndirectionIndex ( ) { result = indirectionIndex }
529
563
530
564
override string toString ( ) { result = "indirect outparam[" + argumentIndex .toString ( ) + "]" }
565
+
566
+ override predicate isNormalReturn ( ) { none ( ) }
567
+
568
+ override predicate isIndirectReturn ( int argumentIndex_ ) { argumentIndex_ = argumentIndex }
531
569
}
532
570
533
571
/** A data flow node that occurs as the result of a `ReturnStmt`. */
0 commit comments