@@ -216,7 +216,8 @@ abstract class TranslatedCoreExpr extends TranslatedExpr {
216216 not hasTranslatedLoad ( expr ) and
217217 not hasTranslatedSyntheticTemporaryObject ( expr ) and
218218 // 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 )
220221 }
221222}
222223
@@ -358,11 +359,12 @@ class TranslatedConditionValue extends TranslatedCoreExpr, ConditionContext,
358359}
359360
360361/**
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.
362363 * One of:
363364 * - `TranslatedLoad` - Convert from glvalue to prvalue by loading from the location.
364365 * - `TranslatedSyntheticTemporaryObject` - Convert from prvalue to glvalue by storing to a
365366 * temporary variable.
367+ * - `TranslatedSyntheticBoolToIntConversion` - Convert a prvalue Boolean to a prvalue integer.
366368 */
367369abstract class TranslatedValueCategoryAdjustment extends TranslatedExpr {
368370 final override Instruction getFirstInstruction ( EdgeKind kind ) {
@@ -513,6 +515,46 @@ class TranslatedSyntheticTemporaryObject extends TranslatedValueCategoryAdjustme
513515 }
514516}
515517
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+
516558/**
517559 * IR translation of an expression that simply returns its result. We generate an otherwise useless
518560 * `CopyValue` instruction for these expressions so that there is at least one instruction
@@ -1794,20 +1836,6 @@ private Opcode binaryArithmeticOpcode(BinaryArithmeticOperation expr) {
17941836 expr instanceof PointerDiffExpr and result instanceof Opcode:: PointerDiff
17951837}
17961838
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-
18111839private Opcode spaceShipOpcode ( SpaceshipExpr expr ) {
18121840 exists ( expr ) and
18131841 result instanceof Opcode:: Spaceship
0 commit comments