@@ -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,45 @@ 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
+ result = this .getParent ( ) .getChildSuccessor ( this , kind )
536
+ }
537
+
538
+ override Instruction getALastInstructionInternal ( ) {
539
+ result = this .getInstruction ( BoolToIntConversionTag ( ) )
540
+ }
541
+
542
+ override Instruction getChildSuccessorInternal ( TranslatedElement child , EdgeKind kind ) {
543
+ child = this .getOperand ( ) and
544
+ result = this .getInstruction ( BoolToIntConversionTag ( ) ) and
545
+ kind instanceof GotoEdge
546
+ }
547
+
548
+ override Instruction getResult ( ) { result = this .getInstruction ( BoolToIntConversionTag ( ) ) }
549
+
550
+ override Instruction getInstructionRegisterOperand ( InstructionTag tag , OperandTag operandTag ) {
551
+ tag = BoolToIntConversionTag ( ) and
552
+ operandTag instanceof UnaryOperandTag and
553
+ result = this .getOperand ( ) .getResult ( )
554
+ }
555
+ }
556
+
516
557
/**
517
558
* IR translation of an expression that simply returns its result. We generate an otherwise useless
518
559
* `CopyValue` instruction for these expressions so that there is at least one instruction
@@ -1794,20 +1835,6 @@ private Opcode binaryArithmeticOpcode(BinaryArithmeticOperation expr) {
1794
1835
expr instanceof PointerDiffExpr and result instanceof Opcode:: PointerDiff
1795
1836
}
1796
1837
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
1838
private Opcode spaceShipOpcode ( SpaceshipExpr expr ) {
1812
1839
exists ( expr ) and
1813
1840
result instanceof Opcode:: Spaceship
0 commit comments