From cb99b3778eb77e98ec1465711107147c8422bb48 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 31 Jan 2021 08:52:50 -0600 Subject: [PATCH] Flag that conversions may not set CPU flags usable for a subsequent comparison. There are several conversions that do not set the necessary flags, so they must be set separately before doing a comparison. Without this fix, comparisons of a value that was just converted might be mis-evaluated. This led to bugs where the wrong side of an "if" could be followed in some cases, as in the below examples: #include int g(void) {return 50;} signed char h(void) {return 50;} long lf(void) {return 50;} int main(void) { signed char sc = 50; if ((int)(signed char)g()) puts("OK1"); if ((int)h()) puts("OK2"); if ((int)sc) puts("OK3"); if ((int)lf()) puts("OK4"); } --- Gen.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gen.pas b/Gen.pas index 4d808ef..78a9457 100644 --- a/Gen.pas +++ b/Gen.pas @@ -405,7 +405,7 @@ NeedsCondition := opcode in [pc_and,pc_ior,pc_cui,pc_cup,pc_lor,pc_lnd,pc_ldl,pc_lil,pc_lld, pc_lli,pc_gil,pc_gli,pc_gdl,pc_gld,pc_iil,pc_ili,pc_idl,pc_ild, pc_cop,pc_cpo,pc_cpi,pc_dvi,pc_mpi,pc_adi,pc_sbi,pc_mod,pc_bno, - pc_udi,pc_uim,pc_umi]; + pc_udi,pc_uim,pc_umi,pc_cnv]; end; {NeedsCondition}