@@ -2965,18 +2965,46 @@ class TranslatedBinaryConditionalExpr extends TranslatedConditionalExpr {
29652965 result = this .getCondition ( ) .getFirstInstruction ( kind )
29662966 }
29672967
2968+ private Type getConditionType ( ) {
2969+ result = this .getCondition ( ) .getExprType ( ) .getUnspecifiedType ( )
2970+ }
2971+
29682972 override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType resultType ) {
29692973 super .hasInstruction ( opcode , tag , resultType )
29702974 or
29712975 // For the binary variant, we create our own conditional branch.
29722976 tag = ValueConditionConditionalBranchTag ( ) and
29732977 opcode instanceof Opcode:: ConditionalBranch and
29742978 resultType = getVoidType ( )
2979+ or
2980+ exists ( Type t |
2981+ t = this .getConditionType ( ) and
2982+ not t instanceof BoolType
2983+ |
2984+ tag = ValueConditionConditionalConstantTag ( ) and
2985+ opcode instanceof Opcode:: Constant and
2986+ resultType = getTypeForPRValue ( t )
2987+ or
2988+ tag = ValueConditionConditionalCompareTag ( ) and
2989+ opcode instanceof Opcode:: CompareNE and
2990+ resultType = getBoolType ( )
2991+ )
29752992 }
29762993
29772994 override Instruction getInstructionSuccessorInternal ( InstructionTag tag , EdgeKind kind ) {
29782995 result = super .getInstructionSuccessorInternal ( tag , kind )
29792996 or
2997+ not this .getConditionType ( ) instanceof BoolType and
2998+ (
2999+ tag = ValueConditionConditionalConstantTag ( ) and
3000+ kind instanceof GotoEdge and
3001+ result = this .getInstruction ( ValueConditionConditionalCompareTag ( ) )
3002+ or
3003+ tag = ValueConditionConditionalCompareTag ( ) and
3004+ kind instanceof GotoEdge and
3005+ result = this .getInstruction ( ValueConditionConditionalBranchTag ( ) )
3006+ )
3007+ or
29803008 tag = ValueConditionConditionalBranchTag ( ) and
29813009 (
29823010 kind instanceof TrueEdge and
@@ -2992,15 +3020,29 @@ class TranslatedBinaryConditionalExpr extends TranslatedConditionalExpr {
29923020 or
29933021 tag = ValueConditionConditionalBranchTag ( ) and
29943022 operandTag instanceof ConditionOperandTag and
2995- result = this .getCondition ( ) .getResult ( )
3023+ if this .getConditionType ( ) instanceof BoolType
3024+ then result = this .getCondition ( ) .getResult ( )
3025+ else result = this .getInstruction ( ValueConditionConditionalCompareTag ( ) )
3026+ or
3027+ not this .getConditionType ( ) instanceof BoolType and
3028+ tag = ValueConditionConditionalCompareTag ( ) and
3029+ (
3030+ operandTag instanceof LeftOperandTag and
3031+ result = this .getCondition ( ) .getResult ( )
3032+ or
3033+ operandTag instanceof RightOperandTag and
3034+ result = this .getInstruction ( ValueConditionConditionalConstantTag ( ) )
3035+ )
29963036 }
29973037
29983038 override Instruction getChildSuccessorInternal ( TranslatedElement child , EdgeKind kind ) {
29993039 result = super .getChildSuccessorInternal ( child , kind )
30003040 or
30013041 kind instanceof GotoEdge and
30023042 child = this .getCondition ( ) and
3003- result = this .getInstruction ( ValueConditionConditionalBranchTag ( ) )
3043+ if this .getConditionType ( ) instanceof BoolType
3044+ then result = this .getInstruction ( ValueConditionConditionalBranchTag ( ) )
3045+ else result = this .getInstruction ( ValueConditionConditionalConstantTag ( ) )
30043046 }
30053047
30063048 private TranslatedExpr getCondition ( ) {
@@ -3017,6 +3059,11 @@ class TranslatedBinaryConditionalExpr extends TranslatedConditionalExpr {
30173059 // always converting the "then" operand to `bool`, which is almost always the wrong type.
30183060 result = getTranslatedExpr ( expr .getThen ( ) .getExplicitlyConverted ( ) )
30193061 }
3062+
3063+ override string getInstructionConstantValue ( InstructionTag tag ) {
3064+ tag = ValueConditionConditionalConstantTag ( ) and
3065+ result = "0"
3066+ }
30203067}
30213068
30223069/**
0 commit comments