@@ -187,19 +187,49 @@ class TranslatedValueCondition extends TranslatedCondition, TTranslatedValueCond
187
187
188
188
final override predicate handlesDestructorsExplicitly ( ) { none ( ) } // TODO: this needs to be revisted when we get unnamed destructors
189
189
190
+ private Type getValueExprType ( ) {
191
+ result = this .getValueExpr ( ) .getExprType ( ) .getUnspecifiedType ( )
192
+ }
193
+
194
+ predicate shouldGenerateCompareNE ( ) { not this .getValueExprType ( ) instanceof BoolType }
195
+
190
196
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
191
208
tag = ValueConditionConditionalBranchTag ( ) and
192
209
opcode instanceof Opcode:: ConditionalBranch and
193
210
resultType = getVoidType ( )
194
211
}
195
212
196
213
override Instruction getChildSuccessorInternal ( TranslatedElement child , EdgeKind kind ) {
197
214
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 ( ) )
200
219
}
201
220
202
221
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
203
233
tag = ValueConditionConditionalBranchTag ( ) and
204
234
(
205
235
kind instanceof TrueEdge and
@@ -211,9 +241,26 @@ class TranslatedValueCondition extends TranslatedCondition, TTranslatedValueCond
211
241
}
212
242
213
243
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
214
254
tag = ValueConditionConditionalBranchTag ( ) and
215
255
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"
217
264
}
218
265
219
266
private TranslatedExpr getValueExpr ( ) { result = getTranslatedExpr ( expr ) }
0 commit comments