Compiler doesn't terminate for a specific small program
After over 6 minutes, the compiler crashes with some memory error:
malloc(): invalid size (unsorted)
/bin/bash: line 1: 46062 Aborted sac2c lim.sac
real 6m47.740s
user 6m47.561s
sys 0m0.161s
shell returned 134
The culprit is this program (note that the loop version works fine, only the recursive version makes the compiler crash:
use StdIO: all;
use Array: all;
int[*] dup(int[*]a)
{
return reshape(shape(a)++shape(a), a);
}
int[*] bonkrec(int i, int[*] a)
{
if (i == 0) {
res = a;
} else {
res = bonkrec(i-1, dup(a));
}
return res;
}
int[*] bonkloop(int i, int[*] a)
{
res = a;
for (j = 0; j<i; j++) {
res = dup(res);
}
return res;
}
int main()
{
// results in a 32D array with one element 4
print(bonkloop(5, [4]));
// same but the compiler never terminates
print(bonkrec(5, [4]));
return 0;
}