2013/11/25 Guy Harris <guy@xxxxxxxxxxxx>:
>
> On Nov 24, 2013, at 2:59 PM, Guy Harris <guy@xxxxxxxxxxxx> wrote:
>
>> I've removed -ftrapv; we'll see what that does.
>
> That fixed it.
>
> Either Lemon is explicitly depending on wrap-around on signed integer overflow, or implicitly depending on a lack of trapping for signed integer overflow; in the latter case, perhaps it should be checked to see whether that's a bug.
I tried to trigger a crash using GCC and -ftrapv without success while
the clang-compiled binary crashed as expected:
test.c:
#include <limits.h>
#include <stdio.h>
int main () {
int i = INT_MAX - 1, b = 100;
#ifdef TEST
if ((i + b) < i) {
printf("overflow!\n");
return 1;
}
#endif
i += b;
printf("res:%d\n",i);
return 0;
}
$ gcc -ftrapv -o test.out test.c && ./test.out
res:-2147483550
$ gcc -DTEST -ftrapv -o test.out test.c && ./test.out
overflow!
$ clang -DTEST -ftrapv -o test.out test.c && ./test.out
Illegal instruction
$ clang -ftrapv -o test.out test.c && ./test.out
Illegal instruction
I agree that -ftrapv seems to be unreliable on GCC or at least it has
more complicated semantics than I expected.
The lemon crash is interesting anyway. Can we somehow obtain the core file?
Cheers,
Balint
PS: Thanks for removing -ftrapv, I think having the rest of the new
flags enabled make sense.