emscripten-core / emscripten-core/emscripten
Possible bug in WASM: Pointer math issue when using Emscripten as backend for FreeBasic
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
I have found some weird issues that lead to code producing the exception "index out of bounds". The minimal code that produces the error is:
```
int arr[14];
int main(){
for (int i=0;i<=5;i++){
*(int*)(((int)(int*)arr + (-i << (2 & 31))) + 52) = i;
}
}
```
This code, that is very similar, seems to work with no problem:
```
int main(){
int arr[14];
for (int i=0;i<=5;i++){
*(int*)(((int)(int*)arr + (-i << (2 & 31))) + 52) = i;
}
}
```
What might cause it?
In case you wonder why I am using such a weird code, instead of a simple "arr[13-i]=i;", the reason is that the code is produced by the C emitter of the FreeBasic compiler (and it works perfectly with the GCC compiler on other platforms). More information is available on the FreeBasic forum, in this [thread](https://www.freebasic.net/forum/viewtopic.php?p=300465#p300465)
Contributor guide
Assessment
This issue has not been assessed yet.