This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/34024] New: infinite loop on longjmp with optimization


When compiled with gcc 3.4.4 through 4.1.2 -O on x86_64 the program below never
terminates. I haven't checked the standard for possible undefined behavior in
this case but since the same program terminates when compiled with many (all?)
all other compilers we have available I'm making the assumption that that this
is a gcc bug. I'll gladly accept a pointer to the chapter and verse that allows
gcc to behave this way.

$ cat t.c && gcc -O t.c && ./a.out | head -n 10
#include <setjmp.h>
#include <stdio.h>

jmp_buf env;
void call_longjmp (int x) {
    printf ("test_longjmp(%d)\n", x);
    longjmp (env, x);
}

int main ()
{
    int x = 1;
    int y;

    y = setjmp (env);
    if (0 == y) call_longjmp (x);
    else if (y < 3)
        call_longjmp (++x);
}


test_longjmp(1)
test_longjmp(2)
test_longjmp(2)
test_longjmp(2)
test_longjmp(2)
test_longjmp(2)
test_longjmp(2)
test_longjmp(2)
test_longjmp(2)
test_longjmp(2)
^C


-- 
           Summary: infinite loop on longjmp with optimization
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sebor at roguewave dot com
 GCC build triplet: x86_64-redhat-linux
  GCC host triplet: x86_64-redhat-linux
GCC target triplet: x86_64-redhat-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34024


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]