@@ -605,13 +605,28 @@ private PointerType getGLValueType(Type t, int indirectionIndex) {
605605}
606606
607607bindingset [ isGLValue]
608- private DataFlowType getType0 ( Type t , int indirectionIndex , boolean isGLValue ) {
608+ private DataFlowType getTypeImpl ( Type t , int indirectionIndex , boolean isGLValue ) {
609609 if isGLValue = true
610610 then
611611 result = getGLValueType ( t , indirectionIndex )
612612 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).
615630 not exists ( getGLValueType ( t , indirectionIndex ) ) and
616631 result = stripPointers ( t , indirectionIndex - 1 )
617632 else result = stripPointers ( t , indirectionIndex )
@@ -640,7 +655,7 @@ class IndirectOperand extends Node, TIndirectOperand {
640655
641656 override DataFlowType getType ( ) {
642657 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 )
644659 )
645660 }
646661
@@ -674,7 +689,7 @@ class IndirectInstruction extends Node, TIndirectInstruction {
674689
675690 override DataFlowType getType ( ) {
676691 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 )
678693 )
679694 }
680695
0 commit comments