calling setjmp destruct a variable

Bug #1826820 reported by Takakazu Satoh
6
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("diff=%td\n", sp-a) ;
 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.

Paul White (paulw2u)
affects: ubuntu → gcc-7 (Ubuntu)
tags: added: bionic
removed: gcc
Revision history for this message
Takakazu Satoh (takakazu) wrote :

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()
{
    setjmp(*sp++) ;
    printf("diff=%td\n", sp-a) ;
}
EOF

$ gcc foo.c
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:///usr/share/doc/gcc-7/README.Bugs> for instructions.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.