[LLVMbugs] [Bug 21418] New: longjmp fails if no variable in calling thread in this ugly code

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Oct 30 16:34:49 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=21418

            Bug ID: 21418
           Summary: longjmp fails if no variable in calling thread in this
                    ugly code
           Product: clang
           Version: 3.4
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: tormod.hellen at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 13260
  --> http://llvm.org/bugs/attachment.cgi?id=13260&action=edit
The bug-uncovering code - same as the one copy-pasted

This particular piece of malformed code created by mistake (I swear) will
segfault if the indicated and seemingly irrelevant line is removed. It will
segfault regardless when compiled with GCC. I thought you guys might find it
interesting, even if this is not an everyday scenario. The same piece of code
is both copy-pasted and attached for your convenience.

Sincerely,
Tormod Hellen

---------------------------------------------------------------

#include<stdio.h>
#include <setjmp.h>

jmp_buf environment1;
jmp_buf environment2;

void co2(jmp_buf *venvironment1, jmp_buf *venvironment2)
{
  int VAR = 5;   //segfault if this line removed <<<<<<<<<<<<<<<<<<<<<<
  jmp_buf * const environment1 = venvironment1;
  jmp_buf * const environment2 = venvironment2;
  printf("In function co2 place 1\n");

  int ret = setjmp(*environment2);
  if (ret == 0)
  {
    longjmp(*environment1, 1);
  }
  printf("In function co2 place 2\n");
  ret = setjmp(*environment2);
  if (ret == 0)
  {
    longjmp(*environment1, 1);
  }
  printf("In function co2 place 3\n");
  longjmp(*environment1, 1);
}

void co1()
{
  printf("In function co1 place 1\n");

  int ret = setjmp(environment1);
  if (ret == 0)
  {
    co2(&environment1, &environment2);
  }
  printf("In function co1 place 2\n");

  ret = setjmp(environment1);
  if (ret == 0)
  {
    longjmp(environment2, 1);
  }
  printf("In function co1 place 3\n");
  ret = setjmp(environment1);
  if (ret == 0)
  {
    longjmp(environment2, 1);
  }
  return;
}

int main()
{
    printf("Hello World\n");
    co1();
    return 0;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20141030/f9850ef1/attachment.html>


More information about the llvm-bugs mailing list