calling setjmp destruct a variable
Bug #1826820 reported by
Takakazu Satoh
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
gcc-7 (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
In Ubuntu 18.04 armhf with gcc-7, the following code, which compiles normally, gives incorrect result (on my machine, -964176505 instead of correct value 1).
#include <setjmp.h>
#include <stdio.h>
jmp_buf a[10] ;
jmp_buf * volatile sp = a ;
int main()
{
if (setjmp(*sp++) == 0) {
printf(
return 0 ;
}
return 1 ;
}
Additional information:
The above code gives correct answer on Ubuntu 16.04 x86_64 gcc 5.4.
If I replace '*sp++' with '*++sp', the program gives correct value 1.
affects: | ubuntu → gcc-7 (Ubuntu) |
tags: |
added: bionic removed: gcc |
To post a comment you must log in.
The command 'apt-get upgrade' upgraded gcc-7 from 7.3.0-27ubuntu1 ~18.04 to 7.4.0-1ubuntu1~ 18.04.
However, this bug still exists in gcc 7.4.0.
By the way, I found that a slightly simple code give rise to an internal compiler error as follows.
$ cat << EOF > foo.c
#include <setjmp.h>
#include <stdio.h>
jmp_buf a[10] ;
jmp_buf * volatile sp = a ;
int main() "diff=% td\n", sp-a) ;
{
setjmp(*sp++) ;
printf(
}
EOF
$ gcc foo.c //usr/share/ doc/gcc- 7/README. Bugs> for instructions.
foo.c: In function 'main':
foo.c:9:5: internal compiler error: Segmentation fault
setjmp(*sp++) ;
^
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:/