M2-Planet
M2-Planet copied to clipboard
Problem with global arrays
Steps to reproduce
-
make
- Using example code main.c:
int my_spoon_is_too_big [0xFFFFFFFFFFFFFFFF
Compile it as: time ./bin/M2-Planet -f ./test/test_hang/main.c
Observed behavior:
- Compilation time is 17 seconds - instead of blazing fast compilation for inside function case.
- Compiler tries to allocate large chunk of memory and than get killed by OS.
Expected behavior:
As with gcc for original file:
time gcc ./test/test_hang/main.c
./test/test_hang/main.c:1:44: error: expected ‘]’ at end of input
1 | int my_spoon_is_too_big [0xFFFFFFFFFFFFFFFF
| ^
| ]
real 0m0.017s
user 0m0.012s
sys 0m0.005s
And for file main.c:
int my_spoon_is_too_big [0xFFFFFFFFFFFFFFFF];
time gcc ./test/test_hang/main.c
./test/test_hang/main.c:1:5: error: size of array ‘my_spoon_is_too_big’ is too large
1 | int my_spoon_is_too_big [0xFFFFFFFFFFFFFFFF];
| ^~~~~~~~~~~~~~~~~~~
real 0m0.017s
user 0m0.011s
sys 0m0.006s
In fix commit 8bc09f2b2ee9d3f78bb48d7b8129898ab037b5f6 - i think you should change order of checks or make them more sophisticated, because now when i compile, for example:
int my_spoon_is_too_big [-1];
int main () {
return my_spoon_is_too_big[0];
}
I get wrong error message:
./test/test_memory/main.c:1:missing close bracket
And when i build:
int my_spoon_is_too_big [1000000000000000];
int main () {
return my_spoon_is_too_big[0];
}
I get:
Negative values are not supported
Even though there is now negative values in original code.
Plus some of messages contain link to source code line, and new one - don't.