@@ -605,13 +605,28 @@ private PointerType getGLValueType(Type t, int indirectionIndex) {
605
605
}
606
606
607
607
bindingset [ isGLValue]
608
- private DataFlowType getType0 ( Type t , int indirectionIndex , boolean isGLValue ) {
608
+ private DataFlowType getTypeImpl ( Type t , int indirectionIndex , boolean isGLValue ) {
609
609
if isGLValue = true
610
610
then
611
611
result = getGLValueType ( t , indirectionIndex )
612
612
or
613
- // If the `PointerType` with the correct base type isn't in the database we cannot
614
- // return a correct type. So instead we'll return a value that has "one indirection too little".
613
+ // Ideally, the above case would cover all glvalue cases. However, consider the case where
614
+ // the database consists only of:
615
+ // ```
616
+ // void test() {
617
+ // int* x;
618
+ // x = nullptr;
619
+ // }
620
+ // ```
621
+ // and we want to compute the type of `*x` in the assignment `x = nullptr`. Here, `x` is an lvalue
622
+ // of type int* (which morally is an int**). So when we call `getTypeImpl` it will be with the
623
+ // parameters:
624
+ // - t = int*
625
+ // - indirectionIndex = 1 (when we want to model the dataflow node corresponding to *x)
626
+ // - isGLValue = true
627
+ // In this case, `getTypeImpl(t, indirectionIndex, isGLValue)` should give back `int**`. In this
628
+ // case, however, `int**` does not exist in the database. So instead we return int* (which is
629
+ // wrong, but at least we have a type).
615
630
not exists ( getGLValueType ( t , indirectionIndex ) ) and
616
631
result = stripPointers ( t , indirectionIndex - 1 )
617
632
else result = stripPointers ( t , indirectionIndex )
@@ -640,7 +655,7 @@ class IndirectOperand extends Node, TIndirectOperand {
640
655
641
656
override DataFlowType getType ( ) {
642
657
exists ( boolean isGLValue | if operand .isGLValue ( ) then isGLValue = true else isGLValue = false |
643
- result = getType0 ( operand .getType ( ) .getUnspecifiedType ( ) , indirectionIndex , isGLValue )
658
+ result = getTypeImpl ( operand .getType ( ) .getUnspecifiedType ( ) , indirectionIndex , isGLValue )
644
659
)
645
660
}
646
661
@@ -674,7 +689,7 @@ class IndirectInstruction extends Node, TIndirectInstruction {
674
689
675
690
override DataFlowType getType ( ) {
676
691
exists ( boolean isGLValue | if instr .isGLValue ( ) then isGLValue = true else isGLValue = false |
677
- result = getType0 ( instr .getResultType ( ) .getUnspecifiedType ( ) , indirectionIndex , isGLValue )
692
+ result = getTypeImpl ( instr .getResultType ( ) .getUnspecifiedType ( ) , indirectionIndex , isGLValue )
678
693
)
679
694
}
680
695
0 commit comments