@@ -216,7 +216,8 @@ abstract class TranslatedCoreExpr extends TranslatedExpr {
216
216
not hasTranslatedLoad ( expr ) and
217
217
not hasTranslatedSyntheticTemporaryObject ( expr ) and
218
218
// If there's a result copy, then this expression's result is the copy.
219
- not exprNeedsCopyIfNotLoaded ( expr )
219
+ not exprNeedsCopyIfNotLoaded ( expr ) and
220
+ not hasTranslatedSyntheticBoolToIntConversion ( expr )
220
221
}
221
222
}
222
223
@@ -358,11 +359,12 @@ class TranslatedConditionValue extends TranslatedCoreExpr, ConditionContext,
358
359
}
359
360
360
361
/**
361
- * The IR translation of a node synthesized to adjust the value category of its operand.
362
+ * The IR translation of a node synthesized to adjust the value category or type of its operand.
362
363
* One of:
363
364
* - `TranslatedLoad` - Convert from glvalue to prvalue by loading from the location.
364
365
* - `TranslatedSyntheticTemporaryObject` - Convert from prvalue to glvalue by storing to a
365
366
* temporary variable.
367
+ * - `TranslatedSyntheticBoolToIntConversion` - Convert a prvalue Boolean to a prvalue integer.
366
368
*/
367
369
abstract class TranslatedValueCategoryAdjustment extends TranslatedExpr {
368
370
final override Instruction getFirstInstruction ( EdgeKind kind ) {
@@ -513,6 +515,46 @@ class TranslatedSyntheticTemporaryObject extends TranslatedValueCategoryAdjustme
513
515
}
514
516
}
515
517
518
+ class TranslatedSyntheticBoolToIntConversion extends TranslatedValueCategoryAdjustment ,
519
+ TTranslatedSyntheticBoolToIntConversion
520
+ {
521
+ TranslatedSyntheticBoolToIntConversion ( ) { this = TTranslatedSyntheticBoolToIntConversion ( expr ) }
522
+
523
+ override string toString ( ) { result = "Bool-to-int conversion of " + expr .toString ( ) }
524
+
525
+ override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType resultType ) {
526
+ opcode instanceof Opcode:: Convert and
527
+ tag = BoolToIntConversionTag ( ) and
528
+ resultType = getIntType ( )
529
+ }
530
+
531
+ override predicate isResultGLValue ( ) { none ( ) }
532
+
533
+ override Instruction getInstructionSuccessorInternal ( InstructionTag tag , EdgeKind kind ) {
534
+ tag = BoolToIntConversionTag ( ) and
535
+ kind instanceof GotoEdge and
536
+ result = this .getParent ( ) .getChildSuccessor ( this , kind )
537
+ }
538
+
539
+ override Instruction getALastInstructionInternal ( ) {
540
+ result = this .getInstruction ( BoolToIntConversionTag ( ) )
541
+ }
542
+
543
+ override Instruction getChildSuccessorInternal ( TranslatedElement child , EdgeKind kind ) {
544
+ child = this .getOperand ( ) and
545
+ result = this .getInstruction ( BoolToIntConversionTag ( ) ) and
546
+ kind instanceof GotoEdge
547
+ }
548
+
549
+ override Instruction getResult ( ) { result = this .getInstruction ( BoolToIntConversionTag ( ) ) }
550
+
551
+ override Instruction getInstructionRegisterOperand ( InstructionTag tag , OperandTag operandTag ) {
552
+ tag = BoolToIntConversionTag ( ) and
553
+ operandTag instanceof UnaryOperandTag and
554
+ result = this .getOperand ( ) .getResult ( )
555
+ }
556
+ }
557
+
516
558
/**
517
559
* IR translation of an expression that simply returns its result. We generate an otherwise useless
518
560
* `CopyValue` instruction for these expressions so that there is at least one instruction
@@ -1794,20 +1836,6 @@ private Opcode binaryArithmeticOpcode(BinaryArithmeticOperation expr) {
1794
1836
expr instanceof PointerDiffExpr and result instanceof Opcode:: PointerDiff
1795
1837
}
1796
1838
1797
- private Opcode comparisonOpcode ( ComparisonOperation expr ) {
1798
- expr instanceof EQExpr and result instanceof Opcode:: CompareEQ
1799
- or
1800
- expr instanceof NEExpr and result instanceof Opcode:: CompareNE
1801
- or
1802
- expr instanceof LTExpr and result instanceof Opcode:: CompareLT
1803
- or
1804
- expr instanceof GTExpr and result instanceof Opcode:: CompareGT
1805
- or
1806
- expr instanceof LEExpr and result instanceof Opcode:: CompareLE
1807
- or
1808
- expr instanceof GEExpr and result instanceof Opcode:: CompareGE
1809
- }
1810
-
1811
1839
private Opcode spaceShipOpcode ( SpaceshipExpr expr ) {
1812
1840
exists ( expr ) and
1813
1841
result instanceof Opcode:: Spaceship
0 commit comments