<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - [Clang-optimization] wrong code for the optimization of static global variable with malloc."
href="https://bugs.llvm.org/show_bug.cgi?id=35760">35760</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[Clang-optimization] wrong code for the optimization of static global variable with malloc.
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>4.0
</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>yoshimatsu2000@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>#include <stdio.h>
#include <stdlib.h>
static int* g_i = NULL;
static void PutsSomething() {
if (g_i == NULL) {
g_i = (int*)malloc(sizeof(*g_i));
puts("0"); // -O0
} else {
puts("1"); // -O1, -O2
}
}
int main(void) {
g_i = NULL;
PutsSomething();
// free(g_i);
return EXIT_SUCCESS;
}
$ clang++-4.0 -O0 test.cpp; ./a.out
0
$ clang++-4.0 -O1 test.cpp; ./a.out
1
$ clang++-4.0 -O2 test.cpp; ./a.out
1
The output is different while the optimization is enabled.
When I cancel comment for free(g_i), this behavior is not seen.</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>