<html>
<head>
<base href="https://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 --- - Clang performs extra initialization of memcpy-able struct member" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D23911&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=bgLbtlKct2fs84IdkdltglTPcQ9gDlChfcmo0NT2rxQ&s=AANNsizg3BQ41Fl7s0vD50lNXgzhW0BaiqyqOrwZ4M8&e=">23911</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Clang performs extra initialization of memcpy-able struct member
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</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>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>d.zobnin.bugzilla@gmail.com
</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>Created <span class=""><a href="attachment.cgi?id=14502" name="attach_14502" title="Generated IR code">attachment 14502</a> <a href="attachment.cgi?id=14502&action=edit" title="Generated IR code">[details]</a></span>
Generated IR code
When compiling the following test:
int glob = 0;
struct A {
int x;
A() { x = 10; }
};
struct B {
B() { glob = 15; }
B(const B &other) { glob = 25; }
};
struct C {
A a; // memcpy-able member
B b; // non-trivial copy initialization
};
int main() {
C c1;
C c2(c1);
return 0;
}
Clang generates the following code for copy-constructor of C:
$ clang -cc1 -O0 test.cpp -emit-llvm -o -
; Function Attrs: inlinehint nounwind
define linkonce_odr void @_ZN1CC2ERKS_(%struct.C* %this, %struct.C*
dereferenceable(8)) unnamed_addr #1 com
dat align 2 {
entry:
%this.addr = alloca %struct.C*, align 8
%.addr = alloca %struct.C*, align 8
store %struct.C* %this, %struct.C** %this.addr, align 8
store %struct.C* %0, %struct.C** %.addr, align 8
%this1 = load %struct.C*, %struct.C** %this.addr
%a = getelementptr inbounds %struct.C, %struct.C* %this1, i32 0, i32 0
%1 = load %struct.C*, %struct.C** %.addr, align 8
%a2 = getelementptr inbounds %struct.C, %struct.C* %1, i32 0, i32 0
%2 = bitcast %struct.A* %a to i8*
%3 = bitcast %struct.A* %a2 to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %2, i8* %3, i64 4, i32 4, i1 false)
%b = getelementptr inbounds %struct.C, %struct.C* %this1, i32 0, i32 1
%4 = load %struct.C*, %struct.C** %.addr, align 8
%b3 = getelementptr inbounds %struct.C, %struct.C* %4, i32 0, i32 1
call void @_ZN1BC1ERKS_(%struct.B* %b, %struct.B* dereferenceable(1) %b3)
%a4 = getelementptr inbounds %struct.C, %struct.C* %this1, i32 0, i32 0
%5 = load %struct.C*, %struct.C** %.addr, align 8
%a5 = getelementptr inbounds %struct.C, %struct.C* %5, i32 0, i32 0
%6 = bitcast %struct.A* %a4 to i8*
%7 = bitcast %struct.A* %a5 to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %6, i8* %7, i64 4, i32 4, i1 false)
ret void
}
As you can see, there's an extra initialization of memcpy-able member C.a.</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>