@@ -2965,18 +2965,46 @@ class TranslatedBinaryConditionalExpr extends TranslatedConditionalExpr {
2965
2965
result = this .getCondition ( ) .getFirstInstruction ( kind )
2966
2966
}
2967
2967
2968
+ private Type getConditionType ( ) {
2969
+ result = this .getCondition ( ) .getExprType ( ) .getUnspecifiedType ( )
2970
+ }
2971
+
2968
2972
override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType resultType ) {
2969
2973
super .hasInstruction ( opcode , tag , resultType )
2970
2974
or
2971
2975
// For the binary variant, we create our own conditional branch.
2972
2976
tag = ValueConditionConditionalBranchTag ( ) and
2973
2977
opcode instanceof Opcode:: ConditionalBranch and
2974
2978
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
+ )
2975
2992
}
2976
2993
2977
2994
override Instruction getInstructionSuccessorInternal ( InstructionTag tag , EdgeKind kind ) {
2978
2995
result = super .getInstructionSuccessorInternal ( tag , kind )
2979
2996
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
2980
3008
tag = ValueConditionConditionalBranchTag ( ) and
2981
3009
(
2982
3010
kind instanceof TrueEdge and
@@ -2992,15 +3020,29 @@ class TranslatedBinaryConditionalExpr extends TranslatedConditionalExpr {
2992
3020
or
2993
3021
tag = ValueConditionConditionalBranchTag ( ) and
2994
3022
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
+ )
2996
3036
}
2997
3037
2998
3038
override Instruction getChildSuccessorInternal ( TranslatedElement child , EdgeKind kind ) {
2999
3039
result = super .getChildSuccessorInternal ( child , kind )
3000
3040
or
3001
3041
kind instanceof GotoEdge and
3002
3042
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 ( ) )
3004
3046
}
3005
3047
3006
3048
private TranslatedExpr getCondition ( ) {
@@ -3017,6 +3059,11 @@ class TranslatedBinaryConditionalExpr extends TranslatedConditionalExpr {
3017
3059
// always converting the "then" operand to `bool`, which is almost always the wrong type.
3018
3060
result = getTranslatedExpr ( expr .getThen ( ) .getExplicitlyConverted ( ) )
3019
3061
}
3062
+
3063
+ override string getInstructionConstantValue ( InstructionTag tag ) {
3064
+ tag = ValueConditionConditionalConstantTag ( ) and
3065
+ result = "0"
3066
+ }
3020
3067
}
3021
3068
3022
3069
/**
0 commit comments