@@ -187,19 +187,49 @@ class TranslatedValueCondition extends TranslatedCondition, TTranslatedValueCond
187187
188188 final override predicate handlesDestructorsExplicitly ( ) { none ( ) } // TODO: this needs to be revisted when we get unnamed destructors
189189
190+ private Type getValueExprType ( ) {
191+ result = this .getValueExpr ( ) .getExprType ( ) .getUnspecifiedType ( )
192+ }
193+
194+ predicate shouldGenerateCompareNE ( ) { not this .getValueExprType ( ) instanceof BoolType }
195+
190196 override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType resultType ) {
197+ this .shouldGenerateCompareNE ( ) and
198+ (
199+ tag = ValueConditionCompareTag ( ) and
200+ opcode instanceof Opcode:: CompareNE and
201+ resultType = getBoolType ( )
202+ or
203+ tag = ValueConditionConstantTag ( ) and
204+ opcode instanceof Opcode:: Constant and
205+ resultType = getTypeForPRValue ( this .getValueExprType ( ) )
206+ )
207+ or
191208 tag = ValueConditionConditionalBranchTag ( ) and
192209 opcode instanceof Opcode:: ConditionalBranch and
193210 resultType = getVoidType ( )
194211 }
195212
196213 override Instruction getChildSuccessorInternal ( TranslatedElement child , EdgeKind kind ) {
197214 child = this .getValueExpr ( ) and
198- result = this .getInstruction ( ValueConditionConditionalBranchTag ( ) ) and
199- kind instanceof GotoEdge
215+ kind instanceof GotoEdge and
216+ if this .shouldGenerateCompareNE ( )
217+ then result = this .getInstruction ( ValueConditionConstantTag ( ) )
218+ else result = this .getInstruction ( ValueConditionConditionalBranchTag ( ) )
200219 }
201220
202221 override Instruction getInstructionSuccessorInternal ( InstructionTag tag , EdgeKind kind ) {
222+ this .shouldGenerateCompareNE ( ) and
223+ (
224+ tag = ValueConditionConstantTag ( ) and
225+ kind instanceof GotoEdge and
226+ result = this .getInstruction ( ValueConditionCompareTag ( ) )
227+ or
228+ tag = ValueConditionCompareTag ( ) and
229+ kind instanceof GotoEdge and
230+ result = this .getInstruction ( ValueConditionConditionalBranchTag ( ) )
231+ )
232+ or
203233 tag = ValueConditionConditionalBranchTag ( ) and
204234 (
205235 kind instanceof TrueEdge and
@@ -211,9 +241,26 @@ class TranslatedValueCondition extends TranslatedCondition, TTranslatedValueCond
211241 }
212242
213243 override Instruction getInstructionRegisterOperand ( InstructionTag tag , OperandTag operandTag ) {
244+ this .shouldGenerateCompareNE ( ) and
245+ tag = ValueConditionCompareTag ( ) and
246+ (
247+ operandTag instanceof LeftOperandTag and
248+ result = this .getValueExpr ( ) .getResult ( )
249+ or
250+ operandTag instanceof RightOperandTag and
251+ result = this .getInstruction ( ValueConditionConstantTag ( ) )
252+ )
253+ or
214254 tag = ValueConditionConditionalBranchTag ( ) and
215255 operandTag instanceof ConditionOperandTag and
216- result = this .getValueExpr ( ) .getResult ( )
256+ if this .shouldGenerateCompareNE ( )
257+ then result = this .getInstruction ( ValueConditionCompareTag ( ) )
258+ else result = this .getValueExpr ( ) .getResult ( )
259+ }
260+
261+ override string getInstructionConstantValue ( InstructionTag tag ) {
262+ tag = ValueConditionConstantTag ( ) and
263+ result = "0"
217264 }
218265
219266 private TranslatedExpr getValueExpr ( ) { result = getTranslatedExpr ( expr ) }
0 commit comments