<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 25, 2016 at 12:57 PM, Akira Hatanaka via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">ahatanak created this revision.<br>
ahatanak added a reviewer: rjmccall.<br>
ahatanak added a subscriber: cfe-commits.<br>
<br>
r246985 made changes to give a higher alignment for exception objects on the grounds that Itanium says _Unwind_Exception should be "double-word" aligned and the structure is normally declared with __attribute__((aligned)) guaranteeing 16-byte alignment. It turns out that libc++abi doesn't declare the structure with __attribute__((aligned)) and therefore only guarantees 8-byte alignment on 32-bit and 64-bit platforms. This caused a crash in some cases when the backend emitted SIMD store instructions that requires 16-byte alignment (such as movaps).<br>
<br>
This patch makes ItaniumCXXABI::getAlignmentOfExnObject return an 8-byte alignment on Darwin to fix the crash.<br>
<br>
<a href="http://reviews.llvm.org/D18479" rel="noreferrer" target="_blank">http://reviews.llvm.org/D18479</a><br>
<br>
Files:<br>
lib/CodeGen/ItaniumCXXABI.cpp<br>
test/CodeGenCXX/eh.cpp<br>
<br>
Index: test/CodeGenCXX/eh.cpp<br>
===================================================================<br>
--- test/CodeGenCXX/eh.cpp<br>
+++ test/CodeGenCXX/eh.cpp<br>
@@ -448,5 +448,27 @@<br>
}<br>
}<br>
<br>
+namespace test17 {<br>
+class BaseException {<br>
+private:<br>
+ int a[4];<br>
+public:<br>
+ BaseException() {};<br>
+};<br>
+<br>
+class DerivedException: public BaseException {<br>
+};<br>
+<br>
+int foo() {<br>
+ throw DerivedException();<br>
+ // The alignment passed to memset is 8, not 16, on Darwin.<br>
+<br>
+ // CHECK: [[T0:%.*]] = call i8* @__cxa_allocate_exception(i64 16)<br>
+ // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to %"class.test17::DerivedException"*<br>
+ // CHECK-NEXT: [[T2:%.*]] = bitcast %"class.test17::DerivedException"* [[T1]] to i8*<br>
+ // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T2]], i8 0, i64 16, i32 8, i1 false)<br>
+}<br>
+}<br>
+<br>
// CHECK: attributes [[NUW]] = { nounwind }<br>
// CHECK: attributes [[NR]] = { noreturn }<br>
Index: lib/CodeGen/ItaniumCXXABI.cpp<br>
===================================================================<br>
--- lib/CodeGen/ItaniumCXXABI.cpp<br>
+++ lib/CodeGen/ItaniumCXXABI.cpp<br>
@@ -163,8 +163,17 @@<br>
/// we assume that alignment here. (It's generally 16 bytes, but<br>
/// some targets overwrite it.)<br>
CharUnits getAlignmentOfExnObject() {<br>
- auto align = CGM.getContext().getTargetDefaultAlignForAttributeAligned();<br>
- return CGM.getContext().toCharUnitsFromBits(align);<br>
+ unsigned Align;<br>
+<br>
+ // Alignment is 8 for darwin since libc++abi doesn't declare<br>
+ // _Unwind_Exception with __attribute__((aligned)) and therefore doesn't<br>
+ // guarantee 16-byte alignment.<br>
+ if (CGM.getContext().getTargetInfo().getTriple().isOSDarwin())<br></blockquote><div><br></div><div>What about Linux/FreeBSD targets which use libc++abi?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ Align = 64;<br>
+ else<br>
+ Align = CGM.getContext().getTargetDefaultAlignForAttributeAligned();<br>
+<br>
+ return CGM.getContext().toCharUnitsFromBits(Align);<br>
}<br>
<br>
void emitRethrow(CodeGenFunction &CGF, bool isNoReturn) override;<br>
<br>
<br>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div></div>