@@ -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,45 @@ 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+ 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+
516557/**
517558 * IR translation of an expression that simply returns its result. We generate an otherwise useless
518559 * `CopyValue` instruction for these expressions so that there is at least one instruction
@@ -1794,20 +1835,6 @@ private Opcode binaryArithmeticOpcode(BinaryArithmeticOperation expr) {
17941835 expr instanceof PointerDiffExpr and result instanceof Opcode:: PointerDiff
17951836}
17961837
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-
18111838private Opcode spaceShipOpcode ( SpaceshipExpr expr ) {
18121839 exists ( expr ) and
18131840 result instanceof Opcode:: Spaceship
0 commit comments