[cfe-commits] r146414 - in /cfe/trunk: lib/AST/RecordLayoutBuilder.cpp test/Sema/pragma-ms_struct.c

Fariborz Jahanian fjahanian at apple.com
Mon Dec 12 13:16:36 PST 2011


Author: fjahanian
Date: Mon Dec 12 15:16:36 2011
New Revision: 146414

URL: http://llvm.org/viewvc/llvm-project?rev=146414&view=rev
Log:
Fixes a bug in calculation of field offsets of ms_struct
fields by just following what comment says.
// rdar://10513599

Modified:
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
    cfe/trunk/test/Sema/pragma-ms_struct.c

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=146414&r1=146413&r2=146414&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Mon Dec 12 15:16:36 2011
@@ -1483,13 +1483,21 @@
         uint64_t TypeSize = FieldInfo.first;
         unsigned FieldAlign = FieldInfo.second;
         // This check is needed for 'long long' in -m32 mode.
-        if (TypeSize > FieldAlign)
+        if (TypeSize > FieldAlign &&
+            (Context.hasSameType(FD->getType(), 
+                                Context.UnsignedLongLongTy) 
+             ||Context.hasSameType(FD->getType(), 
+                                   Context.LongLongTy)))
           FieldAlign = TypeSize;
         FieldInfo = Context.getTypeInfo(LastFD->getType());
         uint64_t TypeSizeLastFD = FieldInfo.first;
         unsigned FieldAlignLastFD = FieldInfo.second;
         // This check is needed for 'long long' in -m32 mode.
-        if (TypeSizeLastFD > FieldAlignLastFD)
+        if (TypeSizeLastFD > FieldAlignLastFD &&
+            (Context.hasSameType(LastFD->getType(), 
+                                Context.UnsignedLongLongTy)
+             || Context.hasSameType(LastFD->getType(), 
+                                    Context.LongLongTy)))
           FieldAlignLastFD = TypeSizeLastFD;
         
         if (TypeSizeLastFD != TypeSize) {
@@ -1640,7 +1648,10 @@
   unsigned FieldAlign = FieldInfo.second;
   
   // This check is needed for 'long long' in -m32 mode.
-  if (IsMsStruct && (TypeSize > FieldAlign))
+  if (IsMsStruct && (TypeSize > FieldAlign) && 
+      (Context.hasSameType(D->getType(), 
+                           Context.UnsignedLongLongTy) 
+       || Context.hasSameType(D->getType(), Context.LongLongTy)))
     FieldAlign = TypeSize;
 
   if (ZeroLengthBitfield) {

Modified: cfe/trunk/test/Sema/pragma-ms_struct.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/pragma-ms_struct.c?rev=146414&r1=146413&r2=146414&view=diff
==============================================================================
--- cfe/trunk/test/Sema/pragma-ms_struct.c (original)
+++ cfe/trunk/test/Sema/pragma-ms_struct.c Mon Dec 12 15:16:36 2011
@@ -32,3 +32,24 @@
 } __attribute__((ms_struct)) t2;
 
 
+// rdar://10513599
+#pragma ms_struct on
+
+typedef struct
+{
+void *pv;
+int l;
+} Foo;
+
+typedef struct
+{
+void *pv1;
+Foo foo;
+unsigned short fInited : 1;
+void *pv2;		
+} PackOddity;		
+
+#pragma ms_struct off
+
+static int arr[sizeof(PackOddity) == 40 ? 1 : -1];
+





More information about the cfe-commits mailing list