[LLVMbugs] [Bug 19619] New: correctness in localized global variable between setjmp and longjmp

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Apr 30 14:59:43 PDT 2014


            Bug ID: 19619
           Summary: correctness in localized global variable between
                    setjmp and longjmp
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Interprocedural Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: bmakam at codeaurora.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

I noticed that c code below failed with -O3 : 

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

static int cnt;

int main(){
  int var;
  jmp_buf buffer;
  cnt = 0;

  if ((var = setjmp(buffer)) == 0) {
    printf(" if true, var: %d, .count:%d , increase count !\n",var, cnt);
    longjmp(buffer, 2);
  } else {
    if (cnt == 1)
      printf(" Pass      var: %d, .count:%d \n",var, cnt);
      printf(" Fail !!!  var: %d, .count:%d \n",var, cnt);
  return 0;

The documentation of setjmp/longjmp says that the values of objects of
automatic storage duration which are local to the function containing the
invocation of the corresponding setjmp() which do not have volatile-qualified
type and which are changed between the setjmp() invocation and longjmp() call
are indeterminate.

Even though “cnt” is a global variable, above c code failed because the
globalopt pass localizes the global value (cnt) in main(), causing that the
value of the global variable becomes indeterminate between setjmp() and
longjmp. I believe the globalopt pass need to check this case before localizing
global variables.

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/20140430/53706345/attachment.html>

More information about the llvm-bugs mailing list