<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - longjmp fails if no variable in calling thread in this ugly code"
   href="http://llvm.org/bugs/show_bug.cgi?id=21418">21418</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>longjmp fails if no variable in calling thread in this ugly code
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.4
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>tormod.hellen@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=13260" name="attach_13260" title="The bug-uncovering code - same as the one copy-pasted">attachment 13260</a> <a href="attachment.cgi?id=13260&action=edit" title="The bug-uncovering code - same as the one copy-pasted">[details]</a></span>
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;
}</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>