<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 - Incorrect optimization of assignment in present of memset"
href="https://bugs.llvm.org/show_bug.cgi?id=34088">34088</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Incorrect optimization of assignment in present of memset
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>5.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>LLVM Codegen
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>dpotapov@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=18914" name="attach_18914" title="An example to reproduce the problem.">attachment 18914</a> <a href="attachment.cgi?id=18914&action=edit" title="An example to reproduce the problem.">[details]</a></span>
An example to reproduce the problem.
During optimization clang removes assignments that should not be eliminated.
I have the following code:
Init(&foo);
buffer = foo.bar.buffer;
memset(&foo, 0xCD, sizeof (foo));
foo.bar.buffer = buffer;
Print(&foo);
and if optimization is enabled, it becomes like this:
Init(&foo);
memset(&foo, 0xCD, sizeof (foo));
Print(&foo);
The bug happens only with target: i386-pc-linux-gnu and for some layout of
structures. (Perhaps, it can happen on x86_64 too for different structures,
but I have not encountered it only on i386 architecture.)
I have attached a full example that demonstrates the problem. It includes
the following files:
test1.h - defines some structures.
test1.c - the main code that is incorrectly optimized
test2.c - defines Init() and Print()
Makefile - builds and runs the example code
If optimization is not enabled, the program prints as expected:
ptr=(nil) size=0x0
however when any level optimization is enabled, I get the following output:
ptr=0xcdcdcdcd size=0xcdcdcdcd
i.e. the initial value of 'buffer' set in Init() is overwritten by memset.
clang information:
$ clang-5.0 -m32 --version
clang version 5.0.0-svn309965-1~exp1 (branches/release_50)
Target: i386-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin</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>