Skip to content

Commit 2e106bc

Browse files
committed
ASM Backend: Fix comparisons involving OFFSETs and IMMediates
- Fix bad code generated for comparisons such as IF @globalvar = 0 THEN - add tests to /tests/expressions/address-comparison.bas
1 parent 4d16959 commit 2e106bc

File tree

4 files changed

+109
-110
lines changed

4 files changed

+109
-110
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Version 1.06.0
6262
- #878: Fix fbc-64bit hangs on 'Case True' + 'Case False' inside 'Select Case As const'
6363
- Fix SELECT CASE AS CONST to allow both signed & unsigned case range values
6464
- #822, #814, #842: Compiler crash when initializing static/shared reference (DIM SHARED/STATIC BYREF) with non-constant initializer (e.g. another reference, or dynamic array element)
65+
- ASM backend: Fix bad code generated for comparisons such as IF @globalvar = 0 THEN
6566

6667

6768
Version 1.05.0

src/compiler/ir-tac.bas

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,8 @@ private sub hFlushCOMP _
20192019
doload = TRUE
20202020
elseif( v1_typ = IR_VREGTYPE_IMM) then '' /
20212021
doload = TRUE
2022+
elseif( v1_typ = IR_VREGTYPE_OFS and v2_typ = IR_VREGTYPE_IMM ) then
2023+
doload = TRUE
20222024
elseif( v2_typ <> IR_VREGTYPE_REG ) then '' /
20232025
if( v2_typ <> IR_VREGTYPE_IMM ) then
20242026
doload = TRUE

tests/expressions/address-comparison.bas

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,113 @@
11
#include "fbcunit.bi"
22

3+
type T
4+
__ as integer
5+
end type
6+
7+
dim shared integer_shared as integer
8+
static shared integer_static_shared as integer
9+
10+
dim shared T_shared as T
11+
static shared T_static_shared as T
12+
313
SUITE( fbc_tests.expressions.address_comparison )
414

5-
TEST( testproc )
15+
'' test that address of globals generates valid code
16+
'' fbc 1.05.0 and earlier would generate invalid ASM for
17+
'' CMP instruction: CMP IMM, OFFSET
18+
19+
TEST( compare_shared_literal )
20+
21+
dim integer_local as integer
22+
static integer_static as integer
23+
24+
dim T_local as T
25+
static T_static as T
26+
27+
CU_ASSERT( @integer_shared <> 0 )
28+
29+
if( @integer_shared = 0 ) then
30+
CU_FAIL()
31+
end if
32+
33+
if( @integer_shared <> 0 ) then
34+
CU_PASS()
35+
end if
36+
37+
CU_ASSERT( @integer_static_shared <> 0 )
38+
39+
if( @integer_static_shared = 0 ) then
40+
CU_FAIL()
41+
end if
42+
43+
if( @integer_static_shared <> 0 ) then
44+
CU_PASS()
45+
end if
46+
47+
CU_ASSERT( @integer_local <> 0 )
48+
49+
if( @integer_local = 0 ) then
50+
CU_FAIL()
51+
end if
52+
53+
if( @integer_local <> 0 ) then
54+
CU_PASS()
55+
end if
56+
57+
CU_ASSERT( @integer_static <> 0 )
58+
59+
if( @integer_static = 0 ) then
60+
CU_FAIL()
61+
end if
62+
63+
if( @integer_static <> 0 ) then
64+
CU_PASS()
65+
end if
66+
67+
CU_ASSERT( @T_shared <> 0 )
68+
69+
if( @T_shared = 0 ) then
70+
CU_FAIL()
71+
end if
72+
73+
if( @T_shared <> 0 ) then
74+
CU_PASS()
75+
end if
76+
77+
CU_ASSERT( @T_static_shared <> 0 )
78+
79+
if( @T_static_shared = 0 ) then
80+
CU_FAIL()
81+
end if
82+
83+
if( @T_static_shared <> 0 ) then
84+
CU_PASS()
85+
end if
86+
87+
CU_ASSERT( @T_local <> 0 )
88+
89+
if( @T_local = 0 ) then
90+
CU_FAIL()
91+
end if
92+
93+
if( @T_local <> 0 ) then
94+
CU_PASS()
95+
end if
96+
97+
CU_ASSERT( @T_static <> 0 )
98+
99+
if( @T_static = 0 ) then
100+
CU_FAIL()
101+
end if
102+
103+
if( @T_static <> 0 ) then
104+
CU_PASS()
105+
end if
106+
107+
END_TEST
108+
109+
110+
TEST( compare_static_local )
6111
dim as integer i1, i2
7112
static as integer si1, si2
8113

tests/pointers/addrof.bas

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)