@@ -414,7 +414,7 @@ abstract class TranslatedCrementOperation extends TranslatedNonConstantExpr {
414414 this .getOpcode ( ) instanceof Opcode:: PointerAdd or
415415 this .getOpcode ( ) instanceof Opcode:: PointerSub
416416 ) and
417- result = 4 //max( getResultType().(PointerType).getSize ())
417+ result = Language :: getTypeSize ( this . getResultType ( ) .( PointerType ) .getReferentType ( ) )
418418 }
419419
420420 final TranslatedExpr getOperand ( ) { result = getTranslatedExpr ( expr .getOperand ( ) ) }
@@ -578,7 +578,6 @@ class TranslatedArrayAccess extends TranslatedNonConstantExpr {
578578 (
579579 // The successor of a `PointerAdd` is an `ElementsAddress` if
580580 // that `PointerAdd` is not the last `PointerAdd` instruction.
581- index < getRank ( ) - 1 and
582581 tag = PointerAddTag ( index ) and
583582 result = this .getInstruction ( ElementsAddressTag ( index + 1 ) )
584583 or
@@ -607,10 +606,7 @@ class TranslatedArrayAccess extends TranslatedNonConstantExpr {
607606 result = this .getInstruction ( PointerAddTag ( child .getAST ( ) .getIndex ( ) ) )
608607 }
609608
610- override Instruction getResult ( ) {
611- result = this .getInstruction ( PointerAddTag ( getRank ( ) - 1 ) ) //and
612- //result.getResultType() = expr.getType()
613- }
609+ override Instruction getResult ( ) { result = this .getInstruction ( PointerAddTag ( getRank ( ) - 1 ) ) }
614610
615611 override predicate hasInstruction (
616612 Opcode opcode , InstructionTag tag , Type resultType , boolean isLValue
@@ -663,12 +659,14 @@ class TranslatedArrayAccess extends TranslatedNonConstantExpr {
663659 }
664660
665661 override int getInstructionElementSize ( InstructionTag tag ) {
666- tag = PointerAddTag ( _) and
667- // TODO: Fix sizes once we have type sizes
668- result = 4
662+ exists ( int index |
663+ inBounds ( index ) and
664+ tag = PointerAddTag ( index ) and
665+ result = Language:: getTypeSize ( expr .getQualifier ( ) .getType ( ) .( ArrayType ) .getElementType ( ) )
666+ )
669667 }
670668
671- private TranslatedExpr getBaseOperand ( ) { result = getTranslatedExpr ( expr .getChild ( - 1 ) ) }
669+ private TranslatedExpr getBaseOperand ( ) { result = getTranslatedExpr ( expr .getQualifier ( ) ) }
672670
673671 private TranslatedExpr getOffsetOperand ( int index ) {
674672 this .inBounds ( index ) and
@@ -1248,16 +1246,14 @@ class TranslatedBinaryOperation extends TranslatedSingleInstructionExpr {
12481246 opcode instanceof Opcode:: PointerSub or
12491247 opcode instanceof Opcode:: PointerDiff
12501248 ) and
1251- result = 8 //max( getPointerOperand().getResultType().(PointerType).getReferentType().getSize()) TODO: SIZE AGAIN
1249+ result = Language :: getTypeSize ( this . getPointerOperand ( ) .getResultType ( ) )
12521250 )
12531251 }
12541252
1255- // private TranslatedExpr getPointerOperand() {
1256- // if swapOperandsOnOp() then
1257- // result = this.getRightOperand()
1258- // else
1259- // result = this.getLeftOperand()
1260- // }
1253+ private TranslatedExpr getPointerOperand ( ) {
1254+ if swapOperandsOnOp ( ) then result = this .getRightOperand ( ) else result = this .getLeftOperand ( )
1255+ }
1256+
12611257 private predicate swapOperandsOnOp ( ) {
12621258 // Swap the operands on a pointer add 'i + p', so that the pointer operand
12631259 // always comes first. Note that we still evaluate the operands
@@ -1444,9 +1440,19 @@ class TranslatedAssignOperation extends TranslatedAssignment {
14441440 }
14451441
14461442 private Opcode getOpcode ( ) {
1447- expr instanceof AssignAddExpr and result instanceof Opcode:: Add
1443+ expr instanceof AssignAddExpr and
1444+ (
1445+ if expr .getRValue ( ) .getType ( ) instanceof PointerType
1446+ then result instanceof Opcode:: PointerAdd
1447+ else result instanceof Opcode:: Add
1448+ )
14481449 or
1449- expr instanceof AssignSubExpr and result instanceof Opcode:: Sub
1450+ expr instanceof AssignSubExpr and
1451+ (
1452+ if expr .getRValue ( ) .getType ( ) instanceof PointerType
1453+ then result instanceof Opcode:: PointerSub
1454+ else result instanceof Opcode:: Sub
1455+ )
14501456 or
14511457 expr instanceof AssignMulExpr and result instanceof Opcode:: Mul
14521458 or
@@ -1462,10 +1468,7 @@ class TranslatedAssignOperation extends TranslatedAssignment {
14621468 or
14631469 expr instanceof AssignLShiftExpr and result instanceof Opcode:: ShiftLeft
14641470 or
1465- expr instanceof AssignRShiftExpr and result instanceof Opcode:: ShiftRight // or
1466- // TODO: THE CASES ABOVE DEAL WITH POINTERS
1467- // expr instanceof AssignPointerAddExpr and result instanceof Opcode::PointerAdd or
1468- // expr instanceof AssignPointerSubExpr and result instanceof Opcode::PointerSub
1471+ expr instanceof AssignRShiftExpr and result instanceof Opcode:: ShiftRight
14691472 }
14701473
14711474 override predicate hasInstruction (
@@ -1500,11 +1503,13 @@ class TranslatedAssignOperation extends TranslatedAssignment {
15001503 override int getInstructionElementSize ( InstructionTag tag ) {
15011504 tag = AssignOperationOpTag ( ) and
15021505 exists ( Opcode opcode |
1503- opcode = getOpcode ( ) and
1504- // TODO: ADD AND SUB FOR POITNER ARITH (WAS POINTERADD AND POINTERSUB)
1505- ( opcode instanceof Opcode:: Add or opcode instanceof Opcode:: Sub )
1506+ opcode = this .getOpcode ( ) and
1507+ (
1508+ opcode instanceof Opcode:: PointerAdd or
1509+ opcode instanceof Opcode:: PointerSub
1510+ )
15061511 ) and
1507- result = 8 //max (getResultType().(PointerType).getReferentType().getSize()) TODO: DEAL WITH SIZE
1512+ result = Language :: getTypeSize ( getResultType ( ) .( PointerType ) .getReferentType ( ) )
15081513 }
15091514
15101515 override Instruction getInstructionOperand ( InstructionTag tag , OperandTag operandTag ) {
0 commit comments