Skip to content

Commit 8a76540

Browse files
authored
Merge pull request #82 from jayrm/boolean-no-neg
boolean: don't allow NEG unary op '-' on boolean data types
2 parents de9f500 + acaf6e3 commit 8a76540

29 files changed

+11892
-146
lines changed

changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Version 1.06.0
33
[changed]
44
- Adjusted warning text for "mixed bool/nonbool operands" warning
55
- test-suite uses libfbcunit for unit testing framework
6+
- SELECT CASE AS CONST respects data type and will show overflow warnings on out-of-range constants
7+
- boolean: don't allow NEG unary op '-' on boolean data types
68

79
[added]
810
- -noobjinfo option to disable the writing/reading of compile-time library and other linking options from/to .o and .a files. This also disables the use of fbextra.x (the supplemental linker script) for discarding the .fbctinf sections, which is useful when using the gold linker that doesn't support this kind of linker script.
@@ -56,6 +58,8 @@ Version 1.06.0
5658
- #876: ThreadCall does not support subroutine with [U]Long type parameter
5759
- #877: fix SLEEP behaviour in linux console and wait for key presses, and do not affect input buffer. Match linux SLEEP to behaviour on Windows.
5860
- Fixed inline asm procedure name mangling bug (missing underscore prefix) with -gen gcc -asm intel on dos/win32
61+
- #878: Fix fbc-64bit hangs on 'Case True' + 'Case False' inside 'Select Case As const'
62+
- Fix SELECT CASE AS CONST to allow both signed & unsigned case range values
5963

6064

6165
Version 1.05.0

src/compiler/ast-node-branch.bas

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ private function astNewJMPTB _
9090
byval labels1 as FBSYMBOL ptr ptr, _
9191
byval labelcount as integer, _
9292
byval deflabel as FBSYMBOL ptr, _
93-
byval minval as ulongint, _
94-
byval maxval as ulongint _
93+
byval bias as ulongint, _
94+
byval span as ulongint _
9595
) as ASTNODE ptr
9696

9797
dim as ASTNODE ptr n = any, tree = any
@@ -124,8 +124,8 @@ private function astNewJMPTB _
124124
n->jmptb.labels = labels
125125
n->jmptb.labelcount = labelcount
126126
n->jmptb.deflabel = deflabel
127-
n->jmptb.minval = minval
128-
n->jmptb.maxval = maxval
127+
n->jmptb.bias = bias
128+
n->jmptb.span = span
129129

130130
function = astNewLINK( tree, n )
131131
end function
@@ -139,7 +139,7 @@ function astLoadJMPTB( byval n as ASTNODE ptr ) as IRVREG ptr
139139
if( ast.doemit ) then
140140
irEmitJMPTB( v1, n->sym, n->jmptb.values, n->jmptb.labels, _
141141
n->jmptb.labelcount, n->jmptb.deflabel, _
142-
n->jmptb.minval, n->jmptb.maxval )
142+
n->jmptb.bias, n->jmptb.span )
143143
end if
144144

145145
deallocate( n->jmptb.values )
@@ -148,11 +148,11 @@ function astLoadJMPTB( byval n as ASTNODE ptr ) as IRVREG ptr
148148
function = NULL
149149
end function
150150

151-
'' Pre-calculate -minval * sizeof(ptr) as Long value, because the offset in an
151+
'' Pre-calculate -bias * sizeof(ptr) as Long value, because the offset in an
152152
'' x86 IDX expression is signed 32bit.
153-
private function hPrecalcMinvalOffset( byval minval as ulongint, byval dtype as integer ) as longint
153+
private function hPrecalcBiasOffset( byval bias as ulongint, byval dtype as integer ) as longint
154154
astBeginHideWarnings( )
155-
var t = astNewCONSTi( minval, dtype )
155+
var t = astNewCONSTi( bias, dtype )
156156
t = astNewUOP( AST_OP_NEG, t )
157157
t = astNewBOP( AST_OP_MUL, t, astNewCONSTi( env.pointersize, dtype ) )
158158
function = astConstFlushToInt( t, FB_DATATYPE_LONG )
@@ -166,8 +166,8 @@ function astBuildJMPTB _
166166
byval labels1 as FBSYMBOL ptr ptr, _
167167
byval labelcount as integer, _
168168
byval deflabel as FBSYMBOL ptr, _
169-
byval minval as ulongint, _
170-
byval maxval as ulongint _
169+
byval bias as ulongint, _
170+
byval span as ulongint _
171171
) as ASTNODE ptr
172172

173173
dim as ASTNODE ptr tree = any, l = any
@@ -219,26 +219,26 @@ function astBuildJMPTB _
219219

220220
'' if( expr < minval or expr > maxval ) then goto deflabel
221221
'' optimised to:
222-
'' if( cunsg(expr - minval) > (maxval - minval) ) then goto deflabel
222+
'' if( cunsg(expr - bias) > (span) ) then goto deflabel
223223
tree = astNewLINK( tree, _
224224
astNewBOP( AST_OP_GT, _
225225
astNewBOP( AST_OP_SUB, _
226226
astNewVAR( tempvar ), _
227-
astNewCONSTi( minval, dtype ) ), _
228-
astNewCONSTi( maxval - minval, dtype ), _
227+
astNewCONSTi( bias, dtype ) ), _
228+
astNewCONSTi( span, dtype ), _
229229
deflabel, AST_OPOPT_NONE ) )
230230

231231
'' Do
232-
'' goto table[expr - minval]
232+
'' goto table[expr - bias]
233233
'' by using an IDX
234-
'' goto [table + expr * sizeof(ptr) + -minval * sizeof(ptr)]
234+
'' goto [table + expr * sizeof(ptr) + -bias * sizeof(ptr)]
235235
'' goto [table + expr*4 + 16]
236236
'' goto [table + expr*4 - 16]
237237
'' instead of DEREF-BOP-ADDROF (IDX gives better code currently).
238238
tree = astNewLINK( tree, _
239239
astNewBRANCH( AST_OP_JUMPPTR, NULL, _
240240
astNewIDX( _
241-
astNewVAR( tbsym, hPrecalcMinvalOffset( minval, dtype ) ), _
241+
astNewVAR( tbsym, hPrecalcBiasOffset( bias, dtype ) ), _
242242
astNewBOP( AST_OP_MUL, _
243243
astNewVAR( tempvar ), _
244244
astNewCONSTi( env.pointersize, dtype ) ) ) ) )
@@ -248,7 +248,7 @@ function astBuildJMPTB _
248248

249249
tree = astNewLINK( tree, _
250250
astNewJMPTB( astNewVAR( tempvar ), tbsym, _
251-
values1, labels1, labelcount, deflabel, minval, maxval ) )
251+
values1, labels1, labelcount, deflabel, bias, span ) )
252252

253253
function = tree
254254
end function

src/compiler/ast-node-uop.bas

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ function astNewUOP _
182182
if( typeGetDtAndPtrOnly( o->dtype ) = FB_DATATYPE_BOOLEAN ) then
183183
if( op = AST_OP_NOT ) then
184184
do_promote = FALSE
185-
elseif( op = AST_OP_NEG ) then
186-
'' allow it or test suite can't compile
187185
else
188186
'' no other operation allowed with booleans
189187
exit function

src/compiler/ast.bi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ type AST_NODE_JMPTB
167167
labelcount as integer
168168

169169
deflabel as FBSYMBOL ptr
170-
minval as ulongint
171-
maxval as ulongint
170+
bias as ulongint
171+
span as ulongint
172172
end type
173173

174174
type AST_NODE_DBG
@@ -731,8 +731,8 @@ declare function astBuildJMPTB _
731731
byval labels1 as FBSYMBOL ptr ptr, _
732732
byval labelcount as integer, _
733733
byval deflabel as FBSYMBOL ptr, _
734-
byval minval as ulongint, _
735-
byval maxval as ulongint _
734+
byval bias as ulongint, _
735+
byval span as ulongint _
736736
) as ASTNODE ptr
737737

738738
declare function astNewLOOP _

src/compiler/emit.bas

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ sub emitFlush( )
190190
cast( EMIT_JTBCB, emit.opFnTb[EMIT_OP_JMPTB] )( n->jtb.tbsym, _
191191
n->jtb.values, n->jtb.labels, _
192192
n->jtb.labelcount, n->jtb.deflabel, _
193-
n->jtb.minval, n->jtb.maxval )
193+
n->jtb.bias, n->jtb.span )
194194

195195
deallocate( n->jtb.values )
196196
deallocate( n->jtb.labels )
@@ -1460,8 +1460,8 @@ function emitJMPTB _
14601460
byval labels1 as FBSYMBOL ptr ptr, _
14611461
byval labelcount as integer, _
14621462
byval deflabel as FBSYMBOL ptr, _
1463-
byval minval as ulongint, _
1464-
byval maxval as ulongint _
1463+
byval bias as ulongint, _
1464+
byval span as ulongint _
14651465
) as EMIT_NODE ptr
14661466

14671467
dim as EMIT_NODE ptr n = any
@@ -1485,8 +1485,8 @@ function emitJMPTB _
14851485
n->jtb.labels = labels
14861486
n->jtb.labelcount = labelcount
14871487
n->jtb.deflabel = deflabel
1488-
n->jtb.minval = minval
1489-
n->jtb.maxval = maxval
1488+
n->jtb.bias = bias
1489+
n->jtb.span = span
14901490

14911491
function = n
14921492
end function

src/compiler/emit.bi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ type EMIT_JTBNODE
183183
labelcount as integer
184184

185185
deflabel as FBSYMBOL ptr
186-
minval as ulongint
187-
maxval as ulongint
186+
bias as ulongint
187+
span as ulongint
188188
end type
189189

190190
type EMIT_MEMNODE
@@ -250,8 +250,8 @@ type EMIT_JTBCB as sub _
250250
byval labels1 as FBSYMBOL ptr ptr, _
251251
byval labelcount as integer, _
252252
byval deflabel as FBSYMBOL ptr, _
253-
byval minval as ulongint, _
254-
byval maxval as ulongint _
253+
byval bias as ulongint, _
254+
byval span as ulongint _
255255
)
256256

257257
type EMIT_MEMCB as sub( byval dvreg as IRVREG ptr, _
@@ -422,8 +422,8 @@ declare function emitJMPTB _
422422
byval labels1 as FBSYMBOL ptr ptr, _
423423
byval labelcount as integer, _
424424
byval deflabel as FBSYMBOL ptr, _
425-
byval minval as ulongint, _
426-
byval maxval as ulongint _
425+
byval bias as ulongint, _
426+
byval span as ulongint _
427427
) as EMIT_NODE ptr
428428

429429
declare function emitCALL _

src/compiler/emit_x86.bas

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,8 +1218,8 @@ private sub _emitJMPTB _
12181218
byval labels1 as FBSYMBOL ptr ptr, _
12191219
byval labelcount as integer, _
12201220
byval deflabel as FBSYMBOL ptr, _
1221-
byval minval as ulongint, _
1222-
byval maxval as ulongint _
1221+
byval bias as ulongint, _
1222+
byval span as ulongint _
12231223
)
12241224

12251225
dim as string deflabelname, tb
@@ -1231,7 +1231,9 @@ private sub _emitJMPTB _
12311231
tb = *symbGetMangledName( tbsym )
12321232

12331233
''
1234-
'' Emit entries for each value from minval to maxval.
1234+
'' Emit entries for each value from 0 to span.
1235+
'' minval = bias
1236+
'' maxval = register(bias+span)
12351237
'' Each value that is in the values1 array uses the corresponding label
12361238
'' from the labels1 array; all other values use the default label.
12371239
''
@@ -1244,27 +1246,26 @@ private sub _emitJMPTB _
12441246
''
12451247

12461248
outEx( tb + ":" + NEWLINE )
1247-
if( minval <= maxval ) then
1248-
var i = 0
1249-
var value = minval
1250-
do
1251-
assert( i < labelcount )
1252-
1253-
dim as FBSYMBOL ptr label
1254-
if( value = values1[i] ) then
1255-
label = labels1[i]
1256-
i += 1
1257-
else
1258-
label = deflabel
1259-
end if
1260-
outp( *_getTypeString( FB_DATATYPE_UINT ) + " " + *symbGetMangledName( label ) )
12611249

1262-
if( value = maxval ) then
1263-
exit do
1264-
end if
1265-
value += 1
1266-
loop
1267-
end if
1250+
var i = 0
1251+
var value = 0
1252+
do
1253+
assert( i < labelcount )
1254+
1255+
dim as FBSYMBOL ptr label
1256+
if( value = values1[i] ) then
1257+
label = labels1[i]
1258+
i += 1
1259+
else
1260+
label = deflabel
1261+
end if
1262+
outp( *_getTypeString( FB_DATATYPE_UINT ) + " " + *symbGetMangledName( label ) )
1263+
1264+
if( value = span ) then
1265+
exit do
1266+
end if
1267+
value += 1
1268+
loop
12681269

12691270
end sub
12701271

src/compiler/ir-hlc.bas

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3043,8 +3043,8 @@ private sub _emitJmpTb _
30433043
byval labels as FBSYMBOL ptr ptr, _
30443044
byval labelcount as integer, _
30453045
byval deflabel as FBSYMBOL ptr, _
3046-
byval minval as ulongint, _
3047-
byval maxval as ulongint _
3046+
byval bias as ulongint, _
3047+
byval span as ulongint _
30483048
)
30493049

30503050
dim as string tb, temp, ln
@@ -3068,50 +3068,44 @@ private sub _emitJmpTb _
30683068

30693069
tb = *symbUniqueId( )
30703070

3071-
l = exprNewIMMi( maxval - minval + 1 )
3071+
l = exprNewIMMi( span + 1 )
30723072
hWriteLine( "static const void* " + tb + "[" + exprFlush( l ) + "] = {", TRUE )
30733073
sectionIndent( )
30743074

3075-
if( minval <= maxval ) then
3076-
var i = 0
3077-
var value = minval
3078-
do
3079-
assert( i < labelcount )
3075+
var i = 0
3076+
var value = 0
3077+
do
3078+
assert( i < labelcount )
30803079

3081-
dim as FBSYMBOL ptr label
3082-
if( value = values[i] ) then
3083-
label = labels[i]
3084-
i += 1
3085-
else
3086-
label = deflabel
3087-
end if
3088-
hWriteLine( "&&" + *symbGetMangledName( label ) + ",", TRUE )
3080+
dim as FBSYMBOL ptr label
3081+
if( value = values[i] ) then
3082+
label = labels[i]
3083+
i += 1
3084+
else
3085+
label = deflabel
3086+
end if
3087+
hWriteLine( "&&" + *symbGetMangledName( label ) + ",", TRUE )
30893088

3090-
if( value = maxval ) then
3091-
exit do
3092-
end if
3093-
value += 1
3094-
loop
3095-
end if
3089+
if( value = span ) then
3090+
exit do
3091+
end if
3092+
value += 1
3093+
loop
30963094

30973095
sectionUnindent( )
30983096
hWriteLine( "};", TRUE )
30993097

3100-
if( minval > 0 ) then
3101-
'' if( temp < minval ) goto deflabel
3102-
l = exprNewTEXT( dtype, NULL, temp )
3103-
l = exprNewBOP( AST_OP_LT, l, exprNewIMMi( minval, dtype ) )
3104-
hWriteLine( "if( " + exprFlush( l ) + " ) goto " + *symbGetMangledName( deflabel ) + ";", TRUE )
3105-
end if
3106-
3107-
'' if( temp > maxval ) then goto deflabel
3098+
'' if( (temp-bias) > span ) then goto deflabel
31083099
l = exprNewTEXT( dtype, NULL, temp )
3109-
l = exprNewBOP( AST_OP_GT, l, exprNewIMMi( maxval, dtype ) )
3100+
if( bias <> 0 ) then
3101+
l = exprNewBOP( AST_OP_SUB, l, exprNewIMMi( bias, dtype ) )
3102+
end if
3103+
l = exprNewBOP( AST_OP_GT, l, exprNewIMMi( span, dtype ) )
31103104
hWriteLine( "if( " + exprFlush( l ) + " ) goto " + *symbGetMangledName( deflabel ) + ";", TRUE )
31113105

3112-
'' l = jumptable[l - minval]
3106+
'' l = jumptable[l - bias]
31133107
l = exprNewTEXT( dtype, NULL, temp )
3114-
l = exprNewBOP( AST_OP_SUB, l, exprNewIMMi( minval, dtype ) )
3108+
l = exprNewBOP( AST_OP_SUB, l, exprNewIMMi( bias, dtype ) )
31153109
hWriteLine( "goto *" + tb + "[" + exprFlush( l ) + "];", TRUE )
31163110

31173111
end sub

src/compiler/ir-llvm.bas

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,8 +1993,8 @@ private sub _emitJmpTb _
19931993
byval labels as FBSYMBOL ptr ptr, _
19941994
byval labelcount as integer, _
19951995
byval deflabel as FBSYMBOL ptr, _
1996-
byval minval as ulongint, _
1997-
byval maxval as ulongint _
1996+
byval bias as ulongint, _
1997+
byval span as ulongint _
19981998
)
19991999

20002000
hAstCommand( "jmptb " + vregPretty( v1 ) )
@@ -2013,7 +2013,7 @@ private sub _emitJmpTb _
20132013

20142014
ctx.indent += 1
20152015
for i as integer = 0 to labelcount - 1
2016-
ln = dtype + " " & values[i] & ", "
2016+
ln = dtype + " " & (values[i]+bias) & ", "
20172017
ln += "label %" + *symbGetMangledName( labels[i] )
20182018
hWriteLine( ln )
20192019
next

0 commit comments

Comments
 (0)