<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 --- - correctness in localized global variable between setjmp and longjmp"
href="http://llvm.org/bugs/show_bug.cgi?id=19619">19619</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>correctness in localized global variable between setjmp and longjmp
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</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>Interprocedural Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>bmakam@codeaurora.org
</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>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);
cnt++;
longjmp(buffer, 2);
} else {
if (cnt == 1)
printf(" Pass var: %d, .count:%d \n",var, cnt);
else
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.</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>