@@ -414,7 +414,7 @@ abstract class TranslatedCrementOperation extends TranslatedNonConstantExpr {
414
414
this .getOpcode ( ) instanceof Opcode:: PointerAdd or
415
415
this .getOpcode ( ) instanceof Opcode:: PointerSub
416
416
) and
417
- result = 4 //max( getResultType().(PointerType).getSize ())
417
+ result = Language :: getTypeSize ( this . getResultType ( ) .( PointerType ) .getReferentType ( ) )
418
418
}
419
419
420
420
final TranslatedExpr getOperand ( ) { result = getTranslatedExpr ( expr .getOperand ( ) ) }
@@ -578,7 +578,6 @@ class TranslatedArrayAccess extends TranslatedNonConstantExpr {
578
578
(
579
579
// The successor of a `PointerAdd` is an `ElementsAddress` if
580
580
// that `PointerAdd` is not the last `PointerAdd` instruction.
581
- index < getRank ( ) - 1 and
582
581
tag = PointerAddTag ( index ) and
583
582
result = this .getInstruction ( ElementsAddressTag ( index + 1 ) )
584
583
or
@@ -607,10 +606,7 @@ class TranslatedArrayAccess extends TranslatedNonConstantExpr {
607
606
result = this .getInstruction ( PointerAddTag ( child .getAST ( ) .getIndex ( ) ) )
608
607
}
609
608
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 ) ) }
614
610
615
611
override predicate hasInstruction (
616
612
Opcode opcode , InstructionTag tag , Type resultType , boolean isLValue
@@ -663,12 +659,14 @@ class TranslatedArrayAccess extends TranslatedNonConstantExpr {
663
659
}
664
660
665
661
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
+ )
669
667
}
670
668
671
- private TranslatedExpr getBaseOperand ( ) { result = getTranslatedExpr ( expr .getChild ( - 1 ) ) }
669
+ private TranslatedExpr getBaseOperand ( ) { result = getTranslatedExpr ( expr .getQualifier ( ) ) }
672
670
673
671
private TranslatedExpr getOffsetOperand ( int index ) {
674
672
this .inBounds ( index ) and
@@ -1248,16 +1246,14 @@ class TranslatedBinaryOperation extends TranslatedSingleInstructionExpr {
1248
1246
opcode instanceof Opcode:: PointerSub or
1249
1247
opcode instanceof Opcode:: PointerDiff
1250
1248
) and
1251
- result = 8 //max( getPointerOperand().getResultType().(PointerType).getReferentType().getSize()) TODO: SIZE AGAIN
1249
+ result = Language :: getTypeSize ( this . getPointerOperand ( ) .getResultType ( ) )
1252
1250
)
1253
1251
}
1254
1252
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
+
1261
1257
private predicate swapOperandsOnOp ( ) {
1262
1258
// Swap the operands on a pointer add 'i + p', so that the pointer operand
1263
1259
// always comes first. Note that we still evaluate the operands
@@ -1444,9 +1440,19 @@ class TranslatedAssignOperation extends TranslatedAssignment {
1444
1440
}
1445
1441
1446
1442
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
+ )
1448
1449
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
+ )
1450
1456
or
1451
1457
expr instanceof AssignMulExpr and result instanceof Opcode:: Mul
1452
1458
or
@@ -1462,10 +1468,7 @@ class TranslatedAssignOperation extends TranslatedAssignment {
1462
1468
or
1463
1469
expr instanceof AssignLShiftExpr and result instanceof Opcode:: ShiftLeft
1464
1470
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
1469
1472
}
1470
1473
1471
1474
override predicate hasInstruction (
@@ -1500,11 +1503,13 @@ class TranslatedAssignOperation extends TranslatedAssignment {
1500
1503
override int getInstructionElementSize ( InstructionTag tag ) {
1501
1504
tag = AssignOperationOpTag ( ) and
1502
1505
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
+ )
1506
1511
) and
1507
- result = 8 //max (getResultType().(PointerType).getReferentType().getSize()) TODO: DEAL WITH SIZE
1512
+ result = Language :: getTypeSize ( getResultType ( ) .( PointerType ) .getReferentType ( ) )
1508
1513
}
1509
1514
1510
1515
override Instruction getInstructionOperand ( InstructionTag tag , OperandTag operandTag ) {
0 commit comments