Skip to content

Commit

Permalink
fbc/emscripten: array indexing regression
Browse files Browse the repository at this point in the history
- emscripten/fbc: don't cast to integer for array indexing
- possible regression of behaviour when fixing github #217
- since commit #44adf4f2794b790d308a022e6880038155964a61
  • Loading branch information
jayrm committed Oct 1, 2023
1 parent eede89e commit ab3afdf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 3 additions & 1 deletion changelog.txt
Expand Up @@ -4,7 +4,9 @@ Version 1.20.0
- internal: changes to all backends gcc/llvm/gas64/gas/gas+SSE for floating point comparison handling
- allow '-fpmode fast' command line option for any target (previously was SSE only) - this can be used augment floating point handling where some accuracy is sacrificed for smaller and faster code generation
- CBOOL(float-expression) returns false if and only if float-expression is zero (0), otherwise returns true (including NaN's)
- if (float-expression) then .. equivalent to if cbool(float-expression) ...
- if (float-expression) then .. equivalent to if cbool(float-expression) ...
- emscripten/fbc: don't cast to integer for array indexing (possible regression of behaviour when fixing github #217)


[added]
- x86_64: optimize SHL MOD INTDIV to use 32-bit operation when result will be converted to long/ulong
Expand Down
21 changes: 13 additions & 8 deletions src/compiler/ir-hlc.bas
Expand Up @@ -2708,16 +2708,21 @@ private function exprNewVREG _
l = exprNewUOP( AST_OP_ADDROF, l )
end if
if( have_offset ) then
if( is_c_array ) then
if( ( is_c_array ) andalso ( fbGetOption( FB_COMPOPT_TARGET ) <> FB_COMPTARGET_JS ) ) then
'' Cast to intptr_t to work around gcc out side of array bounds
'' warnings if we are casting from FBSTRING array to pointer
'' fbc uses a kind of virtual pointer for the an array's (0,..)
'' index; technically this is undefinded behaviour in C and is
'' impossible to cast away even when using pointer only casts
'' in the same expression. Some gcc optimizations cause a
'' warnings if we are casting from FBSTRING array to pointer.
'' fbc uses a kind of virtual pointer for the array's @(0,..)
'' index ptr; technically this is undefinded behaviour in C and
'' is impossible to cast away even when using pointer only casts
'' in the same expression. Some gcc's/compiler's cause a
'' a warning when setting a pointer for the array's virtual
'' index location. To fix this for compliant C code, would
'' need to rewrite the array descriptor to contain only the
'' index location.
''
'' However, this also seems to cause other issuse with
'' emscripten target, so don't when targeting asm.js
''
'' To fix this for compliant C code, should fix the design
'' and rewrite the array descriptor to contain only the
'' offset value from actual memory pointer and compute the
'' array access fully on each array element access.
l = exprNewCAST( FB_DATATYPE_INTEGER, NULL, l )
Expand Down

0 comments on commit ab3afdf

Please sign in to comment.