diff --git a/changelog.txt b/changelog.txt index 31d4d7ec07..a49b1123b9 100644 --- a/changelog.txt +++ b/changelog.txt @@ -119,6 +119,7 @@ Version 1.04.0 - GET# didn't work with wstrings - Integer-only operations like AND, OR, \ and MOD converted non-integer operands to Integer, even if the other was a LongInt or UInteger. Now the conversion will use an integer type matching the integer operand (if any), to avoid truncating floating point values, and give more expected results. - ASM backend: Cross-compiling could give different results than native compilation with regards to the choice of whether to place string literals into .data or const (e.g. .rodata) sections +- Compiling a Select Case As Const block containing a Case with a huge range of values such as won't cause the compiler to "hang" anymore Version 1.03.0 diff --git a/src/compiler/parser-compound-select-const.bas b/src/compiler/parser-compound-select-const.bas index e629294640..a5ad30cc2b 100644 --- a/src/compiler/parser-compound-select-const.bas +++ b/src/compiler/parser-compound-select-const.bas @@ -225,7 +225,8 @@ sub cSelConstStmtNext( byval stk as FB_CMPSTMTSTK ptr ) tovalue = value end if - for value = value to tovalue + '' Add Case values in range unless it was something invalid like "1 to 0" + while( value <= tovalue ) if( value < minval ) then minval = value end if @@ -236,15 +237,23 @@ sub cSelConstStmtNext( byval stk as FB_CMPSTMTSTK ptr ) '' too big? if( (minval > maxval) or ((maxval - minval + 1) > FB_MAXJUMPTBSLOTS) ) then errReport( FB_ERRMSG_RANGETOOLARGE ) - '' error recovery: reset values + '' error recovery: reset values and abort, + '' to avoid excessive looping in case of code like "0 to 4294967295u" minval = stk->select.const_.minval maxval = stk->select.const_.maxval - else - if( hSelConstAddCase( swtbase, value, label ) = FALSE ) then - errReport( FB_ERRMSG_DUPDEFINITION ) - end if + exit while end if - next + + if( hSelConstAddCase( swtbase, value, label ) = FALSE ) then + errReport( FB_ERRMSG_DUPDEFINITION ) + end if + + '' "Early" exit check to avoid overflow problems + if( value = tovalue ) then + exit while + end if + value += 1 + wend stk->select.const_.minval = minval stk->select.const_.maxval = maxval diff --git a/tests/compound/select-const-huge-range.bas b/tests/compound/select-const-huge-range.bas new file mode 100644 index 0000000000..e10499927e --- /dev/null +++ b/tests/compound/select-const-huge-range.bas @@ -0,0 +1,5 @@ +' TEST_MODE : COMPILE_ONLY_FAIL + +select case as const 0 +case 0 to 4294967295u +end select