[cfe-commits] r80964 - in /cfe/trunk: lib/CodeGen/CGRecordLayoutBuilder.cpp test/CodeGen/pragma-pack-3.c
Anders Carlsson
andersca at mac.com
Thu Sep 3 15:56:02 PDT 2009
Author: andersca
Date: Thu Sep 3 17:56:02 2009
New Revision: 80964
URL: http://llvm.org/viewvc/llvm-project?rev=80964&view=rev
Log:
If the alignment of the chosen field in a union is greater than the alignment of the union, we need to use a packed LLVM struct. Fixes <rdar://problem/7184250>.
Added:
cfe/trunk/test/CodeGen/pragma-pack-3.c
Modified:
cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=80964&r1=80963&r2=80964&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Thu Sep 3 17:56:02 2009
@@ -199,8 +199,15 @@
}
// Now add our field.
- if (Ty)
+ if (Ty) {
AppendField(0, Ty);
+
+ if (getTypeAlignment(Ty) > Layout.getAlignment() / 8) {
+ // We need a packed struct.
+ Packed = true;
+ Align = 1;
+ }
+ }
// Append tail padding.
if (Layout.getSize() / 8 > Size)
Added: cfe/trunk/test/CodeGen/pragma-pack-3.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/pragma-pack-3.c?rev=80964&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/pragma-pack-3.c (added)
+++ cfe/trunk/test/CodeGen/pragma-pack-3.c Thu Sep 3 17:56:02 2009
@@ -0,0 +1,19 @@
+// RUN: clang-cc -triple i386-apple-darwin9 %s -emit-llvm -o - | FileCheck -check-prefix X32 %s &&
+// CHECK-X32: %struct.menu = type <{ i8*, i8, i8 }>
+// CHECK-X32: %union.command = type <{ i8*, [2 x i8] }>
+
+// RUN: clang-cc -triple x86_64-apple-darwin9 %s -emit-llvm -o - | FileCheck -check-prefix X64 %s
+// CHECK-X64: %struct.menu = type <{ i8*, i8, i8 }>
+// CHECK-X64: %union.command = type <{ i8*, [2 x i8] }>
+
+// <rdar://problem/7184250>
+#pragma pack(push, 2)
+typedef union command {
+ void *windowRef;
+ struct menu {
+ void *menuRef;
+ unsigned char menuItemIndex;
+ } menu;
+} command;
+
+command c;
More information about the cfe-commits
mailing list