@@ -2957,18 +2957,42 @@ class TranslatedBinaryConditionalExpr extends TranslatedConditionalExpr {
2957
2957
result = this .getCondition ( ) .getFirstInstruction ( kind )
2958
2958
}
2959
2959
2960
+ private Type getConditionType ( ) { result = this .getCondition ( ) .getExprType ( ) }
2961
+
2960
2962
override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType resultType ) {
2961
2963
super .hasInstruction ( opcode , tag , resultType )
2962
2964
or
2963
2965
// For the binary variant, we create our own conditional branch.
2964
2966
tag = ValueConditionConditionalBranchTag ( ) and
2965
2967
opcode instanceof Opcode:: ConditionalBranch and
2966
2968
resultType = getVoidType ( )
2969
+ or
2970
+ not this .getConditionType ( ) instanceof BoolType and
2971
+ (
2972
+ tag = ValueConditionConditionalConstantTag ( ) and
2973
+ opcode instanceof Opcode:: Constant and
2974
+ resultType = getIntType ( )
2975
+ or
2976
+ tag = ValueConditionConditionalCompareTag ( ) and
2977
+ opcode instanceof Opcode:: CompareNE and
2978
+ resultType = getBoolType ( )
2979
+ )
2967
2980
}
2968
2981
2969
2982
override Instruction getInstructionSuccessorInternal ( InstructionTag tag , EdgeKind kind ) {
2970
2983
result = super .getInstructionSuccessorInternal ( tag , kind )
2971
2984
or
2985
+ not this .getConditionType ( ) instanceof BoolType and
2986
+ (
2987
+ tag = ValueConditionConditionalConstantTag ( ) and
2988
+ kind instanceof GotoEdge and
2989
+ result = this .getInstruction ( ValueConditionConditionalCompareTag ( ) )
2990
+ or
2991
+ tag = ValueConditionConditionalCompareTag ( ) and
2992
+ kind instanceof GotoEdge and
2993
+ result = this .getInstruction ( ValueConditionConditionalBranchTag ( ) )
2994
+ )
2995
+ or
2972
2996
tag = ValueConditionConditionalBranchTag ( ) and
2973
2997
(
2974
2998
kind instanceof TrueEdge and
@@ -2984,15 +3008,29 @@ class TranslatedBinaryConditionalExpr extends TranslatedConditionalExpr {
2984
3008
or
2985
3009
tag = ValueConditionConditionalBranchTag ( ) and
2986
3010
operandTag instanceof ConditionOperandTag and
2987
- result = this .getCondition ( ) .getResult ( )
3011
+ if this .getConditionType ( ) instanceof BoolType
3012
+ then result = this .getCondition ( ) .getResult ( )
3013
+ else result = this .getInstruction ( ValueConditionConditionalCompareTag ( ) )
3014
+ or
3015
+ not this .getConditionType ( ) instanceof BoolType and
3016
+ tag = ValueConditionConditionalCompareTag ( ) and
3017
+ (
3018
+ operandTag instanceof LeftOperandTag and
3019
+ result = this .getCondition ( ) .getResult ( )
3020
+ or
3021
+ operandTag instanceof RightOperandTag and
3022
+ result = this .getInstruction ( ValueConditionConditionalConstantTag ( ) )
3023
+ )
2988
3024
}
2989
3025
2990
3026
override Instruction getChildSuccessorInternal ( TranslatedElement child , EdgeKind kind ) {
2991
3027
result = super .getChildSuccessorInternal ( child , kind )
2992
3028
or
2993
3029
kind instanceof GotoEdge and
2994
3030
child = this .getCondition ( ) and
2995
- result = this .getInstruction ( ValueConditionConditionalBranchTag ( ) )
3031
+ if this .getConditionType ( ) instanceof BoolType
3032
+ then result = this .getInstruction ( ValueConditionConditionalBranchTag ( ) )
3033
+ else result = this .getInstruction ( ValueConditionConditionalConstantTag ( ) )
2996
3034
}
2997
3035
2998
3036
private TranslatedExpr getCondition ( ) {
@@ -3009,6 +3047,11 @@ class TranslatedBinaryConditionalExpr extends TranslatedConditionalExpr {
3009
3047
// always converting the "then" operand to `bool`, which is almost always the wrong type.
3010
3048
result = getTranslatedExpr ( expr .getThen ( ) .getExplicitlyConverted ( ) )
3011
3049
}
3050
+
3051
+ override string getInstructionConstantValue ( InstructionTag tag ) {
3052
+ tag = ValueConditionConditionalConstantTag ( ) and
3053
+ result = "0"
3054
+ }
3012
3055
}
3013
3056
3014
3057
/**
0 commit comments