<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 exception handling: wrong IR generation for aggregated members' destructors calls during stack unwinding" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D23924&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=u015dOR1liescexOIyku2kceiOVmvmugKGeesNotR-E&s=6bL-JFgrweN3-zLjyHN2KIRon9Tud-Edc6ZqYi5lRj8&e=">23924</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Clang exception handling: wrong IR generation for aggregated members' destructors calls during stack unwinding
</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=14508" name="attach_14508" title="Generated IR code">attachment 14508</a> <a href="attachment.cgi?id=14508&action=edit" title="Generated IR code">[details]</a></span>
Generated IR code
When compiling the following test:
struct A {
int x;
A() { x = 10; }
~A() { x = 20; }
};
struct B {
int y;
B() { y = 15; }
B(const B &other) {
y = 25;
throw 1;
}
};
struct C {
int z; // memcpy-able member
A a; // memcpy-able member
B b; // explicit copy ctor
};
int main() {
try {
C c1;
C c2(c1);
} catch (...) {
return 1;
}
return 0;
}
Clang generates the following code for copy-constructor of C:
$ clang -cc1 -fexceptions -fcxx-exceptions -O0 test.cpp -emit-llvm -o test.ll
; Function Attrs: inlinehint
define linkonce_odr void @_ZN1CC2ERKS_(%struct.C* %this, %struct.C*
dereferenceable(12)) unnamed_addr #1 comdat align 2 personality i8* bitcast
(i32 (...)* @__gxx_personality_v0 to i8*) {
entry:
%this.addr = alloca %struct.C*, align 8
%.addr = alloca %struct.C*, align 8
%exn.slot = alloca i8*
%ehselector.slot = alloca i32
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
%z = getelementptr inbounds %struct.C, %struct.C* %this1, i32 0, i32 0
%1 = load %struct.C*, %struct.C** %.addr
%z2 = getelementptr inbounds %struct.C, %struct.C* %1, i32 0, i32 0
%2 = bitcast i32* %z to i8*
%3 = bitcast i32* %z2 to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %2, i8* %3, i64 8, i32 4, i1 false)
%b = getelementptr inbounds %struct.C, %struct.C* %this1, i32 0, i32 2
%4 = load %struct.C*, %struct.C** %.addr, align 8
%b3 = getelementptr inbounds %struct.C, %struct.C* %4, i32 0, i32 2
invoke void @_ZN1BC1ERKS_(%struct.B* %b, %struct.B* dereferenceable(4) %b3)
to label %invoke.cont unwind label %lpad
invoke.cont: ; preds = %entry
ret void
lpad: ; preds = %entry
%5 = landingpad { i8*, i32 }
cleanup
%6 = extractvalue { i8*, i32 } %5, 0
store i8* %6, i8** %exn.slot
%7 = extractvalue { i8*, i32 } %5, 1
store i32 %7, i32* %ehselector.slot
%8 = bitcast %struct.C* %this1 to %struct.A*
invoke void @_ZN1AD1Ev(%struct.A* %8)
to label %invoke.cont.4 unwind label %terminate.lpad
invoke.cont.4: ; preds = %lpad
br label %eh.resume
eh.resume: ; preds = %invoke.cont.4
%exn = load i8*, i8** %exn.slot
%sel = load i32, i32* %ehselector.slot
%lpad.val = insertvalue { i8*, i32 } undef, i8* %exn, 0
%lpad.val.5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel, 1
resume { i8*, i32 } %lpad.val.5
terminate.lpad: ; preds = %lpad
%9 = landingpad { i8*, i32 }
catch i8* null
%10 = extractvalue { i8*, i32 } %9, 0
call void @__clang_call_terminate(i8* %10) #5
unreachable
}
As you can see, there's an instruction in %lpad block "%8 = bitcast %struct.C*
%this1 to %struct.A*", which prepares the address of member C.a to call its
destructor and is incorrect, because I believe it must be a "getelementptr
inbounds" instruction for this purpose.
I will handle this case.
Denis Zobnin
=============
Software Engineer
Intel Compiler Team
Intel</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>