[LLVMdev] built-in longjmp and setjmp

Akira Hatanaka ahatanak at gmail.com
Wed Apr 27 11:38:45 PDT 2011


I have another basic question about setjmp/longjmp.

When I compile and run the following program, is it expected that global
variable gi2 will be incremented twice? It seems that the code generated
with clang and llc increments it only once (line 37-43 of attached file).

$ clang setjmp6.c -o setjmp6.arm.ll -emit-llvm -O3 -S -ccc-host-triple
arm-unknown-darwin -ccc-clang-archs arm
$ llc setjmp6.arm.ll -o setjmp6.arm.s

#include <stdio.h>
#include <stdlib.h>
void *buf[20];

int gi2 = 0;

void __attribute__ ((noinline)) sub2 (void)
{
  __builtin_longjmp (buf, 1);
}

int
main (int argc, char **argv)
{
  int n = atoi (argv[1]);
  int r = __builtin_setjmp (buf);
  ++gi2;

  if (r)
    {
      printf ("setjmp %d\n", n + gi2);
      return 0;
    }

  sub2 ();

  return 0;
}


On Wed, Apr 13, 2011 at 10:05 AM, Jakob Stoklund Olesen <stoklund at 2pi.dk>wrote:

>
> On Apr 13, 2011, at 9:51 AM, Akira Hatanaka wrote:
>
> > int
> > main (int argc, char** argv)
> > {
> >   int n = atoi(argv[1]), r;
> >
> >   if ((r = setjmp (buf)))
> >     {
> >       printf("n = %d\n", n);
> >       return 0;
> >     }
>
>
> /jakob
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110427/b16136dd/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: setjmp6.arm.s
Type: application/octet-stream
Size: 1765 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110427/b16136dd/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dag.main.dot
Type: application/msword
Size: 8653 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110427/b16136dd/attachment.dot>


More information about the llvm-dev mailing list