Skip to content

Commit cc8b25d

Browse files
committed
Allow [U]LongInt bitfields on 64bit
Since 64bit Integer bitfields are allowed on 64bit already, it should be possible to allow LongInt too, on 64bit at least. Unfortunately, the test case shows that 64bit bitfields aren't working properly on 64bit yet, no matter whether using Integer or LongInt types. Allowing 64bit bitfields on 32bit is a different story though, because currently the bitfield access code always uses UInteger (thus can't handle bitfields > 32bit on 32bit). This helps supporting the new 64bit Windows API headers which contain such bitfields with LongInt type (but in the 64bit part of the API only).
1 parent 4270e09 commit cc8b25d

File tree

9 files changed

+174
-0
lines changed

9 files changed

+174
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Version 1.01.0
1111
- Constant 0 integers can now be assigned to pointers no matter what integer type it is. Previously it didn't work with [U]LongInts on 32bit and [U]Longs on 64bit.
1212
- Constant 0 pointers can now be assigned to any integer type. Previously this was only allowed with integer types matching the pointer size (32bit or 64bit).
1313
- #757: It's now possible to do UDT().field instead of (UDT()).field (field accesses on anonymous UDTs with constructors)
14+
- On 64bit, bitfields can now use the [U]LongInt type
1415
- Bindings (new/updated, including 64bit support):
1516
Allegro 4.4.2 (allegro.bi)
1617
algif 1.3 (allegro/algif.bi)

src/compiler/symb-struct.bas

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ function symbCheckBitField _
226226

227227
return TRUE
228228

229+
case FB_DATATYPE_LONGINT, FB_DATATYPE_ULONGINT
230+
'' Allow 64bit bitfields on 64bit
231+
'' TODO: 64bit bitfields on 32bit -- currently not supported
232+
'' because bitfield accesses are based on the default word size
233+
function = fbIs64bit( )
229234
case else
230235
return FALSE
231236
end select
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
' TEST_MODE : COMPILE_ONLY_FAIL
2+
3+
type UDT
4+
a : 9 as byte
5+
end type
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
' TEST_MODE : COMPILE_ONLY_FAIL
2+
3+
type UDT
4+
#ifdef __FB_64BIT__
5+
a : 65 as integer
6+
#else
7+
a : 33 as integer
8+
#endif
9+
end type
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
' TEST_MODE : COMPILE_ONLY_FAIL
2+
3+
type UDT
4+
a : 33 as short
5+
end type
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
' TEST_MODE : COMPILE_ONLY_FAIL
2+
3+
type UDT
4+
a : 65 as longint
5+
end type
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
' TEST_MODE : COMPILE_ONLY_FAIL
2+
3+
type UDT
4+
a : 17 as short
5+
end type

tests/structs/bitfield-types.bas

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# include "fbcu.bi"
2+
3+
namespace fbc_tests.structs.bitfield_types
4+
5+
type UDT
6+
b1 : 1 as byte
7+
b7 : 7 as byte
8+
b8 : 8 as byte
9+
ub1 : 1 as ubyte
10+
ub7 : 7 as ubyte
11+
ub8 : 8 as ubyte
12+
sh1 : 1 as short
13+
sh15 : 15 as short
14+
sh16 : 16 as short
15+
ush1 : 1 as ushort
16+
ush15 : 15 as ushort
17+
ush16 : 16 as ushort
18+
l1 : 1 as long
19+
l31 : 31 as long
20+
l32 : 32 as long
21+
ul1 : 1 as ulong
22+
ul31 : 31 as ulong
23+
ul32 : 32 as ulong
24+
#ifdef __FB_64BIT__
25+
ll1 : 1 as longint
26+
ll63 : 63 as longint
27+
ll64 : 64 as longint
28+
ull1 : 1 as ulongint
29+
ull63 : 63 as ulongint
30+
ull64 : 64 as ulongint
31+
i1 : 1 as integer
32+
i63 : 63 as integer
33+
i64 : 64 as integer
34+
ui1 : 1 as uinteger
35+
ui63 : 63 as uinteger
36+
ui64 : 64 as uinteger
37+
#else
38+
'' TODO: 64bit bitfields, once supported on 32bit
39+
i1 : 1 as integer
40+
i31 : 31 as integer
41+
i32 : 32 as integer
42+
ui1 : 1 as uinteger
43+
ui31 : 31 as uinteger
44+
ui32 : 32 as uinteger
45+
#endif
46+
end type
47+
48+
private sub test cdecl( )
49+
dim x as UDT
50+
x.b1 = 1
51+
x.b7 = &h7F
52+
x.b8 = &hFF
53+
x.ub1 = 1
54+
x.ub7 = &h7F
55+
x.ub8 = &hFF
56+
x.sh1 = 1
57+
x.sh15 = &h7FFF
58+
x.sh16 = &hFFFF
59+
x.ush1 = 1
60+
x.ush15 = &h7FFF
61+
x.ush16 = &hFFFF
62+
x.l1 = 1
63+
x.l31 = &h7FFFFFFF
64+
x.l32 = &hFFFFFFFFu
65+
x.ul1 = 1
66+
x.ul31 = &h7FFFFFFF
67+
x.ul32 = &hFFFFFFFFu
68+
#ifdef __FB_64BIT__
69+
x.ll1 = 1
70+
x.ll63 = &h7FFFFFFFFFFFFFFF
71+
x.ll64 = &hFFFFFFFFFFFFFFFFu
72+
x.ull1 = 1
73+
x.ull63 = &h7FFFFFFFFFFFFFFF
74+
x.ull64 = &hFFFFFFFFFFFFFFFFu
75+
x.i1 = 1
76+
x.i63 = &h7FFFFFFFFFFFFFFF
77+
x.i64 = &hFFFFFFFFFFFFFFFFu
78+
x.ui1 = 1
79+
x.ui63 = &h7FFFFFFFFFFFFFFF
80+
x.ui64 = &hFFFFFFFFFFFFFFFFu
81+
#else
82+
'' TODO: 64bit bitfields, once supported on 32bit
83+
x.i1 = 1
84+
x.i31 = &h7FFFFFFF
85+
x.i32 = &hFFFFFFFFu
86+
x.ui1 = 1
87+
x.ui31 = &h7FFFFFFF
88+
x.ui32 = &hFFFFFFFFu
89+
#endif
90+
91+
CU_ASSERT( x.b1 = 1 )
92+
CU_ASSERT( x.b7 = &h7F )
93+
CU_ASSERT( x.b8 = &hFF )
94+
CU_ASSERT( x.ub1 = 1 )
95+
CU_ASSERT( x.ub7 = &h7F )
96+
CU_ASSERT( x.ub8 = &hFF )
97+
CU_ASSERT( x.sh1 = 1 )
98+
CU_ASSERT( x.sh15 = &h7FFF )
99+
CU_ASSERT( x.sh16 = &hFFFF )
100+
CU_ASSERT( x.ush1 = 1 )
101+
CU_ASSERT( x.ush15 = &h7FFF )
102+
CU_ASSERT( x.ush16 = &hFFFF )
103+
CU_ASSERT( x.l1 = 1 )
104+
CU_ASSERT( x.l31 = &h7FFFFFFF )
105+
CU_ASSERT( x.l32 = &hFFFFFFFFu )
106+
CU_ASSERT( x.ul1 = 1 )
107+
CU_ASSERT( x.ul31 = &h7FFFFFFF )
108+
CU_ASSERT( x.ul32 = &hFFFFFFFFu )
109+
#ifdef __FB_64BIT__
110+
CU_ASSERT( x.ll1 = 1 )
111+
CU_ASSERT( x.ll63 = &h7FFFFFFFFFFFFFFF )
112+
CU_ASSERT( x.ll64 = &hFFFFFFFFFFFFFFFFu )
113+
CU_ASSERT( x.ull1 = 1 )
114+
CU_ASSERT( x.ull63 = &h7FFFFFFFFFFFFFFF )
115+
CU_ASSERT( x.ull64 = &hFFFFFFFFFFFFFFFFu )
116+
CU_ASSERT( x.i1 = 1 )
117+
CU_ASSERT( x.i63 = &h7FFFFFFFFFFFFFFF )
118+
CU_ASSERT( x.i64 = &hFFFFFFFFFFFFFFFFu )
119+
CU_ASSERT( x.ui1 = 1 )
120+
CU_ASSERT( x.ui63 = &h7FFFFFFFFFFFFFFF )
121+
CU_ASSERT( x.ui64 = &hFFFFFFFFFFFFFFFFu )
122+
#else
123+
'' TODO: 64bit bitfields, once supported on 32bit
124+
CU_ASSERT( x.i1 = 1 )
125+
CU_ASSERT( x.i31 = &h7FFFFFFF )
126+
CU_ASSERT( x.i32 = &hFFFFFFFFu )
127+
CU_ASSERT( x.ui1 = 1 )
128+
CU_ASSERT( x.ui31 = &h7FFFFFFF )
129+
CU_ASSERT( x.ui32 = &hFFFFFFFFu )
130+
#endif
131+
end sub
132+
133+
private sub ctor( ) constructor
134+
fbcu.add_suite( "tests/structs/bitfield-types" )
135+
fbcu.add_test( "test", @test )
136+
end sub
137+
138+
end namespace

todo.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ o 64bit
22
- FB includes must be adjusted for 64bit compatibility (if the corresponding
33
library even is available on 64bit)
44
- Windows port I/O driver? Can it be ported to 64bit? is it needed?
5+
- 64bit bitfields aren't working properly - see tests/structs/bitfield-types.bas
56

67
o LLVM backend
78
- Check whether F2I conversions work correctly for unsigned integers (compare

0 commit comments

Comments
 (0)